argos/dmp-frontend/src/app/datasets/dataset.component.ts

216 lines
5.6 KiB
TypeScript
Raw Normal View History

2017-10-30 15:56:50 +01:00
import { Component, OnInit, Input, ViewChild, NgZone, Output, EventEmitter } from '@angular/core';
import { GoogleSignInSuccess } from 'angular-google-signin';
2017-10-18 18:30:39 +02:00
import { Router, ActivatedRoute } from '@angular/router';
import { ServerService } from '../../app/services/server.service';
import { Project } from '../entities/model/project';
import { Dataset } from '../entities/model/dataset';
2017-10-27 10:34:05 +02:00
import { Dmp } from '../entities/model/dmp';
import {DataTable} from 'angular2-datatable';
2017-10-27 16:08:10 +02:00
import { DropdownField } from '../../app/form/fields/dropdown/field-dropdown';
import { Param } from '../entities/model/param';
2017-11-03 18:57:06 +01:00
import { StatusToString } from '../pipes/various/status-to-string';
2017-10-18 18:30:39 +02:00
2017-10-30 15:56:50 +01:00
declare var $: any;
2017-10-27 18:38:31 +02:00
2017-10-18 18:30:39 +02:00
@Component({
selector: 'datasets-table',
2017-10-18 18:30:39 +02:00
templateUrl: 'dataset.html',
styleUrls: ['./dataset.component.css'],
2017-10-30 15:56:50 +01:00
providers: [ServerService]
2017-10-18 18:30:39 +02:00
})
2017-10-30 15:56:50 +01:00
export class DatasetsComponent implements OnInit {
// Start ALTERNATIVE
//whole dmp data model
tableData : any[] = new Array();
//organisation editor data model
editingOrganisation: any = {};
organisationEditorForm : any;
//required by the table
public filterQuery = "";
public rowsOnPage = 10;
2017-11-01 13:01:14 +01:00
public sortBy = "label";
public sortOrder = "asc";
//visibility rules for containers
tableVisible: boolean = true;
editorVisible: boolean = false;
// for tableIds
showIDs : boolean = false;
// END ALTERNATIVE
2017-10-18 18:30:39 +02:00
returnUrl: string;
@Input() datasets: Dataset[];
2017-10-27 16:08:10 +02:00
@Input() datasetProfileDropDown: DropdownField;
@Input() datasetCount = 0;
2017-10-27 16:08:10 +02:00
@Input() dmpIdforDatasets: string;
@Input() dmpLabelforDatasets: string;
2017-11-01 13:01:14 +01:00
@Input() statusDropDown: DropdownField;
2017-10-30 15:56:50 +01:00
dataset: any;
saveAndDescribe:boolean;
2017-11-01 13:01:14 +01:00
2017-10-18 18:30:39 +02:00
2017-10-30 15:56:50 +01:00
dataSetValue: boolean
@Input()
2017-10-30 15:56:50 +01:00
get dataSetVisibe() {
return this.dataSetValue;
}
@Output()
public dataSetValueChange = new EventEmitter();
2017-10-30 15:56:50 +01:00
set dataSetVisibe(value: any) {
this.dataSetValue = value
this.dataSetValueChange.emit(this.dataSetValue)
}
2017-10-30 15:56:50 +01:00
constructor(
2017-10-18 18:30:39 +02:00
private serverService: ServerService,
private route: ActivatedRoute,
private router: Router,
2017-10-30 15:56:50 +01:00
private ngZone: NgZone) {
2017-11-07 11:13:54 +01:00
this.dataset = this.createEmptyDataset();
2017-10-30 15:56:50 +01:00
this.datasetProfileDropDown = new DropdownField();
this.datasetProfileDropDown.options = [];
this.saveAndDescribe = false;
2017-11-01 13:01:14 +01:00
this.statusDropDown = new DropdownField();
2017-11-06 14:11:03 +01:00
this.statusDropDown.options= [{key:'', value:null},{key:'0', value:"Active"},{key:'1', value:"Inactive"}]
2017-10-18 18:30:39 +02:00
}
2017-11-02 15:19:12 +01:00
ngOnInit() {
2017-10-18 18:30:39 +02:00
//this.projects = this.serverService.getDummyProjects();
this.datasets = [];
2017-11-02 15:19:12 +01:00
console.log(this.dmpIdforDatasets);
2017-10-30 15:56:50 +01:00
this.serverService.getDatasetForDmp({ "id": this.dmpIdforDatasets }).subscribe(
2017-10-18 18:30:39 +02:00
response => {
this.tableData = response;
2017-10-30 15:56:50 +01:00
}
);
2017-10-27 16:08:10 +02:00
this.serverService.getAllDatsetsProfile().subscribe(
response => {
response.forEach((datasetprofile) => {
let params = new Param();
params.key = datasetprofile.id;
params.value = datasetprofile.label;
this.datasetProfileDropDown.options.push(params);
});
}
)
2017-10-18 18:30:39 +02:00
}
2017-11-07 11:13:54 +01:00
createEmptyDataset(){
return {
id: null,
label: '',
reference: '',
uri: '',
properties: '',
profile: { "id": '' },
dmp: { "id": '' }
}
}
2017-11-06 14:11:03 +01:00
SaveDataset(){
2017-11-01 16:07:51 +01:00
if(this.dataset.id ==null){
this.dataset.dmp = { "id": this.dmpIdforDatasets }
this.dataset.profile = { "id": this.dataset.profile }
this.serverService.createDatasetForDmp(this.dataset).subscribe(
response => {
console.log(response);
this.getDatasets();
if (this.saveAndDescribe == true)
this.describeDataset(response);
}
)
$("#newDatasetModal").modal("hide");
}
else{
this.dataset.dmp = { "id": this.dmpIdforDatasets }
this.dataset.profile = { "id": this.dataset.profile }
this.serverService.updateDatsetsProfile(this.dataset).subscribe(
response => {
console.log(response);
this.getDatasets();
if (this.saveAndDescribe == true)
this.describeDataset(response);
}
)
$("#newDatasetModal").modal("hide");
}
2017-10-30 17:37:17 +01:00
}
2017-11-01 16:07:51 +01:00
getDatasets(){
2017-10-30 17:37:17 +01:00
this.serverService.getDatasetForDmp({ "id": this.dmpIdforDatasets }).subscribe(
2017-11-01 16:07:51 +01:00
response => {
this.tableData = response;
2017-10-30 15:56:50 +01:00
}
);
}
2017-10-30 17:37:17 +01:00
2017-10-18 18:30:39 +02:00
2017-10-30 15:56:50 +01:00
getDatasetForDmpMethod(dmpid) {
this.serverService.getDatasetForDmp({ "id": dmpid }).subscribe(
response => {
2017-11-01 16:54:14 +01:00
this.tableData = response;
2017-10-30 15:56:50 +01:00
}
);
}
2017-11-02 17:39:05 +01:00
editRow(item, event) {
2017-11-01 16:07:51 +01:00
if (event.toElement.id == "editDataset"){
2017-11-06 14:11:03 +01:00
this.dataset = item;
2017-11-01 16:07:51 +01:00
this.dataset.label = item.label;
this.dataset.uri = item.uri;
//this.dataset.dmp = item.dmp;
2017-11-06 14:11:03 +01:00
this.dataset.profile = item.profile==null ? null : item.profile.id;
2017-11-01 16:07:51 +01:00
this.dataset.id = item.id;
$("#newDatasetModal").modal("show");
}
else if(event.toElement.id == "describeDataset"){
this.describeDataset(item);
}
2017-10-30 15:56:50 +01:00
}
newDataset() {
2017-11-07 11:13:54 +01:00
this.dataset = this.createEmptyDataset();
this.dataset.dmp =this.dmpLabelforDatasets;
2017-11-07 11:13:54 +01:00
this.dataset.status = 0;
2017-10-30 15:56:50 +01:00
$("#newDatasetModal").modal("show");
}
2017-10-18 18:30:39 +02:00
SaveDescribeDataset(){
this.saveAndDescribe = true;
this.SaveDataset();
}
2017-11-06 17:25:23 +01:00
describeDataset(item) {
2017-11-01 16:07:51 +01:00
this.ngZone.run(() => this.router.navigate(['dynamic-form', {id: item.profile.id, datasetId:item.id}]));
}
2017-11-06 14:11:03 +01:00
deleteRow(dataset, $event){
this.serverService.deleteDataset(dataset).subscribe(
response => {
console.log("Deleted Successfully the dataset")
},
err => {
console.log("Could not delete the dataset")
}
);
this.getDatasets();
}
2017-10-18 18:30:39 +02:00
}