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

132 lines
2.9 KiB
TypeScript

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