2017-10-16 17:05:25 +02:00
|
|
|
import { Component, OnInit, ViewChild } from '@angular/core';
|
|
|
|
import { DmpProfileService } from '../../services/dmpprofile-service';
|
|
|
|
import { ContextMenuComponent } from 'ngx-contextmenu';
|
|
|
|
import { ReactiveFormsModule } from '@angular/forms';
|
|
|
|
import { FormBuilder, FormGroup, Validators } from '@angular/forms';
|
|
|
|
|
|
|
|
import '../../../assets/custom.js';
|
|
|
|
declare function simple_notifier(type: string, title: string, message:string): any;
|
|
|
|
|
|
|
|
|
|
|
|
@Component({
|
|
|
|
selector: 'app-dmp-profile-editor',
|
|
|
|
templateUrl: './dmp-profile-editor.component.html',
|
|
|
|
styleUrls: ['./dmp-profile-editor.component.css']
|
|
|
|
})
|
|
|
|
export class DmpProfileEditorComponent implements OnInit {
|
|
|
|
|
|
|
|
constructor(private dmpProfileService : DmpProfileService, private fb: FormBuilder) {
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
//whole dmp data model
|
|
|
|
tableData : any[] = new Array();
|
|
|
|
|
|
|
|
//editor's data model
|
|
|
|
editingDmpProfile: any = {};
|
|
|
|
dmpProfileEditorForm : any;
|
|
|
|
|
|
|
|
//required by the table
|
|
|
|
public filterQuery = "";
|
|
|
|
public rowsOnPage = 10;
|
|
|
|
//public sortBy = "email";
|
|
|
|
public sortOrder = "asc";
|
|
|
|
|
|
|
|
//visibility rules for containers
|
|
|
|
tableVisible: boolean = true;
|
|
|
|
editorVisible: boolean = false;
|
|
|
|
|
|
|
|
|
|
|
|
// for tableIds
|
|
|
|
showIDs : boolean = false;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ngOnInit() {
|
|
|
|
this.getAllDmpProfiles(false);
|
|
|
|
this.createDmpProfileEditorForm();
|
|
|
|
}
|
|
|
|
|
|
|
|
createDmpProfileEditorForm(){
|
|
|
|
this.dmpProfileEditorForm = this.fb.group({
|
|
|
|
id: null,
|
|
|
|
label: ['', Validators.required ],
|
|
|
|
definition: ''
|
|
|
|
});
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
switchToTable(){
|
|
|
|
this.tableVisible = true;
|
|
|
|
this.editorVisible = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
switchToEditor(dmpProfileID){
|
|
|
|
|
|
|
|
this.tableVisible = false;
|
|
|
|
this.editorVisible = true;
|
|
|
|
if(dmpProfileID == null){
|
|
|
|
this.editingDmpProfile = {id: null, label: "", definition: "" };
|
|
|
|
}
|
|
|
|
else{
|
|
|
|
this.editingDmpProfile = this.tableData.filter((dmpProfile) => dmpProfile.id === dmpProfileID)[0];
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
getAllDmpProfiles(showNotification : boolean){
|
|
|
|
this.dmpProfileService.getAllDmpProfiles().subscribe( (data) => {
|
|
|
|
this.tableData = data;
|
|
|
|
if(showNotification)
|
|
|
|
simple_notifier("info",null,"Refreshed the table");
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
editDmpProfile(dmpProfile){
|
|
|
|
this.switchToEditor(dmpProfile);
|
|
|
|
}
|
|
|
|
|
|
|
|
newDmpProfile(){
|
|
|
|
this.switchToEditor(null);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
save(mouseEvent){
|
|
|
|
this.dmpProfileService.create(this.dmpProfileEditorForm.value).subscribe(
|
|
|
|
response => {
|
|
|
|
simple_notifier("success",null,"Saved DMP Profile");
|
|
|
|
this.getAllDmpProfiles(false);
|
|
|
|
},
|
|
|
|
err => {
|
|
|
|
simple_notifier("danger",null,"Could not save DMP Profile");
|
|
|
|
}
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
delete(dmpProfile){
|
|
|
|
this.dmpProfileService.delete(dmpProfile).subscribe(
|
|
|
|
(response) => {
|
|
|
|
simple_notifier("success",null,"Deleted DMP Profile");
|
2017-10-17 12:33:52 +02:00
|
|
|
this.getAllDmpProfiles(false);
|
|
|
|
this.switchToTable();
|
2017-10-16 17:05:25 +02:00
|
|
|
},
|
|
|
|
(err) => {
|
2017-10-17 12:33:52 +02:00
|
|
|
simple_notifier("danger",null,"Could not delete DMP Profile");
|
2017-10-16 17:05:25 +02:00
|
|
|
}
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
refreshTable($event){
|
|
|
|
this.getAllDmpProfiles(true);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@ViewChild(ContextMenuComponent) public basicMenu: ContextMenuComponent;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|