argos/dmp-admin/src/app/managers/registry-editor/registry-editor.component.ts

141 lines
3.1 KiB
TypeScript

import { Component, OnInit, ViewChild } from '@angular/core';
import { RegistryService } from '../../services/registry-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-registry-editor',
templateUrl: './registry-editor.component.html',
styleUrls: ['./registry-editor.component.css']
})
export class RegistryEditorComponent implements OnInit {
//whole dmp data model
tableData : any[] = new Array();
//project editor data model
editingRegistry: any = {};
registryEditorForm : 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;
constructor(private registryService : RegistryService, private fb: FormBuilder) {
}
ngOnInit() {
this.getAllRegistries(false);
this.createRegistrytEditorForm();
}
createRegistrytEditorForm(){
this.registryEditorForm = this.fb.group({
id: null,
label: ['', Validators.required ],
abbreviation: '',
reference: '',
uri: '',
definition: ''
});
}
switchToTable(){
this.tableVisible = true;
this.editorVisible = false;
}
switchToEditor(registryID){
this.tableVisible = false;
this.editorVisible = true;
if(registryID == null){
this.editingRegistry = {id: null, label: "", abbreviation: "", reference: "", uri: "", definition: "" };
}
else{
this.editingRegistry = this.tableData.filter((registry) => registry.id === registryID)[0];
}
}
getAllRegistries(showNotification : boolean){
this.registryService.getAllRegistries().subscribe( (data) => {
this.tableData = data;
if(showNotification)
simple_notifier("info",null,"Refreshed the table");
});
}
editRegistry(registry){
this.switchToEditor(registry);
}
newProject(){
this.switchToEditor(null);
}
save(mouseEvent){
this.registryService.create(this.registryEditorForm.value).subscribe(
response => {
simple_notifier("success",null,"Saved registry");
this.getAllRegistries(false);
this.switchToTable();
},
err => {
simple_notifier("danger",null,"Could not save registry");
}
);
}
delete(registry){
this.registryService.delete(registry).subscribe(
(response) => {
simple_notifier("success",null,"Deleted registry");
this.getAllRegistries(false);
this.switchToTable();
},
(err) => {
simple_notifier("danger",null,"Could not delete registry");
}
)
}
refreshTable($event){
this.getAllRegistries(true);
}
@ViewChild(ContextMenuComponent) public basicMenu: ContextMenuComponent;
}