228 lines
6.1 KiB
TypeScript
228 lines
6.1 KiB
TypeScript
import { Component, OnInit, Input, ViewChild, NgZone, Output, EventEmitter } from '@angular/core';
|
|
import { GoogleSignInSuccess } from 'angular-google-signin';
|
|
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';
|
|
import { Dmp } from '../entities/model/dmp';
|
|
//import { DataTable, DataTableTranslations, DataTableResource } from 'angular-4-data-table-bootstrap-4';
|
|
import {DataTable} from 'angular2-datatable';
|
|
import { DropdownField } from '../../app/form/fields/dropdown/field-dropdown';
|
|
import { Param } from '../entities/model/param';
|
|
|
|
declare var $: any;
|
|
|
|
@Component({
|
|
selector: 'datasets-table',
|
|
templateUrl: 'dataset.html',
|
|
styleUrls: ['./dataset.component.css'],
|
|
providers: [ServerService]
|
|
})
|
|
|
|
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;
|
|
public sortBy = "label";
|
|
public sortOrder = "asc";
|
|
|
|
//visibility rules for containers
|
|
tableVisible: boolean = true;
|
|
editorVisible: boolean = false;
|
|
|
|
|
|
// for tableIds
|
|
showIDs : boolean = false;
|
|
// END ALTERNATIVE
|
|
|
|
returnUrl: string;
|
|
@Input() datasets: Dataset[];
|
|
@Input() datasetProfileDropDown: DropdownField;
|
|
@Input() datasetCount = 0;
|
|
@Input() dmpIdforDatasets: string;
|
|
@Input() dmpLabelforDatasets: string;
|
|
@Input() statusDropDown: DropdownField;
|
|
dataset: any;
|
|
saveAndDescribe:boolean;
|
|
|
|
|
|
dataSetValue: boolean
|
|
@Input()
|
|
get dataSetVisibe() {
|
|
return this.dataSetValue;
|
|
}
|
|
@Output()
|
|
public dataSetValueChange = new EventEmitter();
|
|
|
|
set dataSetVisibe(value: any) {
|
|
this.dataSetValue = value
|
|
this.dataSetValueChange.emit(this.dataSetValue)
|
|
}
|
|
|
|
constructor(
|
|
private serverService: ServerService,
|
|
private route: ActivatedRoute,
|
|
private router: Router,
|
|
private ngZone: NgZone) {
|
|
this.dataset = {
|
|
id: null,
|
|
label: '',
|
|
reference: '',
|
|
uri: '',
|
|
properties: '',
|
|
profile: { "id": '' },
|
|
dmp: { "id": '' }
|
|
}
|
|
|
|
this.datasetProfileDropDown = new DropdownField();
|
|
this.datasetProfileDropDown.options = [];
|
|
this.saveAndDescribe = false;
|
|
this.statusDropDown = new DropdownField();
|
|
this.statusDropDown.options =[];
|
|
this.statusDropDown.options= [{key:'0', value:"active"},{key:'1', value:"inactive"}]
|
|
|
|
}
|
|
|
|
ngOnInit() { debugger;
|
|
//this.projects = this.serverService.getDummyProjects();
|
|
this.datasets = [];
|
|
console.log(this.dmpIdforDatasets);debugger;
|
|
this.serverService.getDatasetForDmp({ "id": this.dmpIdforDatasets }).subscribe(
|
|
response => {
|
|
this.tableData = response;
|
|
}
|
|
);
|
|
|
|
this.serverService.getAllDatsetsProfile().subscribe(
|
|
response => {
|
|
console.log("response");
|
|
console.log(response);
|
|
//let params = new Param();
|
|
response.forEach((datasetprofile) => {
|
|
let params = new Param();
|
|
params.key = datasetprofile.id;
|
|
params.value = datasetprofile.label;
|
|
this.datasetProfileDropDown.options.push(params);
|
|
});
|
|
|
|
}
|
|
)
|
|
}
|
|
|
|
selectDataset(item) {
|
|
this.ngZone.run(() => this.router.navigate(['dynamic-form', {id: item.profileId, datasetId:item.id, datasetProperties:item.properties}]));
|
|
}
|
|
|
|
SaveNewDataset() {
|
|
this.dataset.dmp = { "id": this.dmpIdforDatasets }
|
|
this.dataset.profile = { "id": this.dataset.profile }
|
|
this.serverService.createDatasetForDmp(this.dataset).subscribe(
|
|
response => {
|
|
console.log(response);
|
|
//if (this.saveAndDescribe == true)
|
|
//this.describeDataset(); PWS THA VRISKOUME TO ITEM GIA NA ANOIGEI TO SWSTO DATASET???
|
|
}
|
|
)
|
|
$("#newDatasetModal").modal("hide");
|
|
this.CallDatasets();
|
|
}
|
|
|
|
SaveEditedDataset(){
|
|
this.dataset.dmp = { "id": this.dmpIdforDatasets }
|
|
this.dataset.profile = { "id": this.dataset.profile }
|
|
this.serverService.updateDatsetsProfile(this.dataset).subscribe(
|
|
response => {
|
|
console.log(response);
|
|
|
|
}
|
|
)
|
|
$("#newDatasetModal").modal("hide");
|
|
this.CallDatasets();
|
|
}
|
|
|
|
SaveDataset(){
|
|
if(this.dataset.id ==null)
|
|
this.SaveNewDataset();
|
|
else
|
|
this.SaveEditedDataset();
|
|
}
|
|
|
|
CallDatasets(){
|
|
this.serverService.getDatasetForDmp({ "id": this.dmpIdforDatasets }).subscribe(
|
|
response => {
|
|
|
|
console.log("response");
|
|
console.log(response);
|
|
this.datasets = [];
|
|
response.forEach(resp => {
|
|
|
|
let dt = new Dataset();
|
|
dt.id = resp.id;
|
|
dt.name = resp.label;
|
|
dt.uriDataset = resp.uri;
|
|
dt.dmp = resp.dmp.label;
|
|
dt.profile = resp.profile.label;
|
|
dt.profileId = resp.profile.id;
|
|
this.datasets.push(dt);
|
|
});
|
|
}
|
|
);
|
|
}
|
|
|
|
|
|
getDatasetForDmpMethod(dmpid) {
|
|
this.serverService.getDatasetForDmp({ "id": dmpid }).subscribe(
|
|
response => {
|
|
|
|
console.log("response");
|
|
console.log(response);
|
|
this.datasets = [];
|
|
response.forEach(resp => {
|
|
|
|
let dt = new Dataset();
|
|
dt.id = resp.id;
|
|
dt.name = resp.label;
|
|
dt.uriDataset = resp.uri;
|
|
this.datasets.push(dt);
|
|
});
|
|
}
|
|
);
|
|
}
|
|
|
|
editRow(item) { debugger;
|
|
this.dataset.label = item.label;
|
|
this.dataset.uri = item.uri;
|
|
//this.dataset.dmp = item.dmp;
|
|
this.dataset.profile = item.profile.id;
|
|
this.dataset.id = item.id;
|
|
$("#newDatasetModal").modal("show");
|
|
}
|
|
|
|
newDataset() {
|
|
this.dataset.label = "";
|
|
this.dataset.uri = "";
|
|
this.dataset.dmp =this.dmpLabelforDatasets;
|
|
this.dataset.profile = "";
|
|
$("#newDatasetModal").modal("show");
|
|
}
|
|
|
|
SaveDescribeDataset(){
|
|
this.saveAndDescribe = true;
|
|
this.SaveDataset();
|
|
}
|
|
|
|
describeDataset(item) {
|
|
this.ngZone.run(() => this.router.navigate(['dynamic-form', {id: item.profileId, datasetId:item.id, datasetProperties:item.properties}]));
|
|
}
|
|
|
|
}
|