import { Component, OnInit, ViewChild } from '@angular/core'; import { DatasetProfileService } from '../../services/dataset-profile.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-datasetprofile-editor', templateUrl: './datasetprofile-editor.component.html', styleUrls: ['./datasetprofile-editor.component.css'] }) export class DatasetprofileEditorComponent implements OnInit { constructor(private datasetProfileService : DatasetProfileService, private fb: FormBuilder) { } //whole dmp data model tableData : any[] = new Array(); //DatasetProfile editor data model editingDatasetProfile: any = {}; datasetProfileEditorForm : 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.getAllDatasetProfiles(false); this.createDatasetProfileEditorForm(); } createDatasetProfileEditorForm(){ this.datasetProfileEditorForm = this.fb.group({ id: '', label: ['', Validators.required ], ruleset: '', viewstyle: '', definition: '' }); } switchToTable(){ this.tableVisible = true; this.editorVisible = false; } switchToEditor(datasetProfileID){ this.tableVisible = false; this.editorVisible = true; if(datasetProfileID == null){ this.editingDatasetProfile = {id: null, label: "", created: "", description: "", status: "" }; } else{ this.editingDatasetProfile = this.tableData.filter((datasetProfile) => datasetProfile.id === datasetProfileID)[0]; } } getAllDatasetProfiles(showNotification : boolean){ this.datasetProfileService.fetchAllDatasetProfiles().subscribe( (data) => { this.tableData = data.payload; if(showNotification) simple_notifier("info",null,"Refreshed the table"); }); } edit(data){ this.switchToEditor(data); } new(){ this.switchToEditor(null); } save(mouseEvent){ this.datasetProfileService.createDatasetProfile(this.datasetProfileEditorForm.value).subscribe( response => { simple_notifier("success",null,"Saved dataset Profile"); this.getAllDatasetProfiles(false); this.switchToTable(); }, err => { simple_notifier("danger",null,"Could not save dataset Profile"); } ); } delete(data){ console.log(data); this.datasetProfileService.delete(data).subscribe( (response) => { simple_notifier("success",null,"Deleted dataset profile"); this.getAllDatasetProfiles(false); this.switchToTable(); }, (err) => { simple_notifier("danger",null,"Could not delete dataset profile"); } ) } refreshTable($event){ this.getAllDatasetProfiles(true); } @ViewChild(ContextMenuComponent) public basicMenu: ContextMenuComponent; }