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';
|
2017-10-18 20:30:55 +02:00
|
|
|
import { Dataset } from '../entities/model/dataset';
|
2017-10-27 10:34:05 +02:00
|
|
|
import { Dmp } from '../entities/model/dmp';
|
2017-10-18 18:30:39 +02:00
|
|
|
import { DataTable, DataTableTranslations, DataTableResource } from 'angular-4-data-table-bootstrap-4';
|
2017-10-27 16:08:10 +02:00
|
|
|
import { DropdownField } from '../../app/form/fields/dropdown/field-dropdown';
|
|
|
|
import { Param } from '../entities/model/param';
|
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({
|
2017-10-23 15:09:50 +02:00
|
|
|
selector: 'datasets-table',
|
2017-10-18 18:30:39 +02:00
|
|
|
templateUrl: 'dataset.html',
|
2017-10-30 15:56:50 +01:00
|
|
|
// template: `
|
|
|
|
// <h1 class="title">Projects</h1>
|
|
|
|
|
|
|
|
// <ul class="list-group col-md-4">
|
|
|
|
// <li *ngFor="let project of projects"
|
|
|
|
// class="list-group-item">
|
|
|
|
// <a [routerLink]="['/dynamic-form', project.id]" >
|
|
|
|
// {{ project.name }}
|
|
|
|
// </a>
|
|
|
|
// </li>
|
|
|
|
// </ul>
|
|
|
|
|
|
|
|
// <router-outlet></router-outlet>
|
|
|
|
// `,
|
|
|
|
providers: [ServerService]
|
2017-10-18 18:30:39 +02:00
|
|
|
})
|
|
|
|
|
2017-10-30 15:56:50 +01:00
|
|
|
export class DatasetsComponent implements OnInit {
|
2017-10-18 20:30:55 +02:00
|
|
|
|
2017-10-18 18:30:39 +02:00
|
|
|
returnUrl: string;
|
2017-10-18 20:30:55 +02:00
|
|
|
@Input() datasets: Dataset[];
|
2017-10-27 16:08:10 +02:00
|
|
|
@Input() datasetProfileDropDown: DropdownField;
|
2017-10-30 15:56:50 +01:00
|
|
|
datasetResource: DataTableResource<Dataset>;
|
2017-10-18 20:30:55 +02:00
|
|
|
@Input() datasetCount = 0;
|
2017-10-27 16:08:10 +02:00
|
|
|
@Input() dmpIdforDatasets: string;
|
2017-10-31 11:19:16 +01:00
|
|
|
@Input() dmpLabelforDatasets: string;
|
2017-10-30 15:56:50 +01:00
|
|
|
dataset: any;
|
|
|
|
|
2017-10-27 18:38:31 +02:00
|
|
|
//@ViewChild(DataTable) projectsTable;
|
2017-10-18 18:30:39 +02:00
|
|
|
|
2017-10-30 15:56:50 +01:00
|
|
|
dataSetValue: boolean
|
2017-10-25 15:17:16 +02:00
|
|
|
@Input()
|
2017-10-30 15:56:50 +01:00
|
|
|
get dataSetVisibe() {
|
2017-10-25 15:17:16 +02:00
|
|
|
return this.dataSetValue;
|
|
|
|
}
|
|
|
|
@Output()
|
|
|
|
public dataSetValueChange = new EventEmitter();
|
2017-10-30 15:56:50 +01:00
|
|
|
|
|
|
|
set dataSetVisibe(value: any) {
|
|
|
|
this.dataSetValue = value
|
2017-10-25 15:17:16 +02:00
|
|
|
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,
|
2017-10-18 20:30:55 +02:00
|
|
|
private router: Router,
|
2017-10-30 15:56:50 +01:00
|
|
|
private ngZone: NgZone) {
|
|
|
|
this.dataset = {
|
|
|
|
id: null,
|
|
|
|
label: '',
|
|
|
|
reference: '',
|
|
|
|
uri: '',
|
|
|
|
properties: '',
|
|
|
|
profile: { "id": '' },
|
|
|
|
dmp: { "id": '' }
|
|
|
|
}
|
|
|
|
|
|
|
|
this.datasetProfileDropDown = new DropdownField();
|
|
|
|
this.datasetProfileDropDown.options = [];
|
2017-10-18 18:30:39 +02:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2017-10-30 15:56:50 +01:00
|
|
|
ngOnInit() {
|
2017-10-18 18:30:39 +02:00
|
|
|
//this.projects = this.serverService.getDummyProjects();
|
2017-10-18 20:30:55 +02:00
|
|
|
this.datasets = [];
|
2017-10-27 16:08:10 +02: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 => {
|
|
|
|
|
|
|
|
console.log("response");
|
|
|
|
console.log(response);
|
|
|
|
response.forEach(resp => {
|
2017-10-18 20:30:55 +02:00
|
|
|
|
|
|
|
let dt = new Dataset();
|
|
|
|
dt.id = resp.id;
|
|
|
|
dt.name = resp.label;
|
|
|
|
dt.uriDataset = resp.uri;
|
2017-10-31 11:19:16 +01:00
|
|
|
dt.dmp = this.dmpLabelforDatasets; //to pairnw apo to datatable tou dmp
|
2017-10-30 15:56:50 +01:00
|
|
|
dt.profile = resp.profile.label;
|
|
|
|
dt.profileId = resp.profile.id;
|
2017-10-18 20:30:55 +02:00
|
|
|
this.datasets.push(dt);
|
2017-10-30 15:56:50 +01:00
|
|
|
var params = { limit: 8, offset: 0, sortAsc: false }
|
|
|
|
this.afterLoad();
|
|
|
|
this.datasetResource.query(params).then(datasets => this.datasets = datasets);
|
2017-10-18 18:30:39 +02:00
|
|
|
});
|
2017-10-30 15:56:50 +01:00
|
|
|
}
|
|
|
|
);
|
|
|
|
|
2017-10-27 16:08:10 +02:00
|
|
|
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);
|
|
|
|
});
|
|
|
|
|
|
|
|
}
|
|
|
|
)
|
2017-10-18 18:30:39 +02:00
|
|
|
}
|
|
|
|
|
2017-10-18 20:30:55 +02:00
|
|
|
reloadDatasets(params) {
|
2017-10-30 17:37:17 +01:00
|
|
|
// this.datasetResource = new DataTableResource(this.datasets);
|
2017-10-27 18:38:31 +02:00
|
|
|
this.datasetResource.query(params).then(datasets => this.datasets = datasets);
|
2017-10-30 15:56:50 +01:00
|
|
|
}
|
2017-10-18 18:30:39 +02:00
|
|
|
|
2017-10-30 15:56:50 +01:00
|
|
|
afterLoad() {
|
|
|
|
this.datasetResource = new DataTableResource(this.datasets);
|
|
|
|
this.datasetResource.count().then(count => this.datasetCount = count);
|
|
|
|
}
|
2017-10-18 20:30:55 +02:00
|
|
|
|
2017-10-30 17:37:17 +01:00
|
|
|
selectDataset(item) {
|
2017-10-30 16:35:11 +01:00
|
|
|
this.ngZone.run(() => this.router.navigate(['dynamic-form', {id: item.profileId, datasetId:item.id, datasetProperties:item.properties}]));
|
2017-10-30 15:56:50 +01:00
|
|
|
}
|
2017-10-18 18:30:39 +02:00
|
|
|
|
2017-10-30 17:37:17 +01:00
|
|
|
SaveNewDataset() {
|
2017-10-30 15:56:50 +01:00
|
|
|
this.dataset.dmp = { "id": this.dmpIdforDatasets }
|
|
|
|
this.dataset.profile = { "id": this.dataset.profile }
|
|
|
|
this.serverService.createDatasetForDmp(this.dataset).subscribe(
|
|
|
|
response => {
|
|
|
|
console.log(response);
|
|
|
|
|
|
|
|
}
|
|
|
|
)
|
|
|
|
$("#newDatasetModal").modal("hide");
|
2017-10-30 17:37:17 +01:00
|
|
|
this.CallDatasets();
|
|
|
|
}
|
|
|
|
|
|
|
|
SaveEditedDataset(){
|
|
|
|
this.dataset.dmp = { "id": this.dmpIdforDatasets }
|
|
|
|
this.dataset.profile = { "id": this.dataset.profile }
|
|
|
|
this.serverService.updateDatsetsProfile(this.dataset).subscribe(
|
2017-10-30 15:56:50 +01:00
|
|
|
response => {
|
2017-10-30 17:37:17 +01:00
|
|
|
console.log(response);
|
2017-10-30 15:56:50 +01:00
|
|
|
|
2017-10-30 17:37:17 +01:00
|
|
|
}
|
|
|
|
)
|
|
|
|
$("#newDatasetModal").modal("hide");
|
|
|
|
this.CallDatasets();
|
|
|
|
}
|
|
|
|
|
2017-10-30 18:08:33 +01:00
|
|
|
SaveDataset(){debugger;
|
|
|
|
if(this.dataset.id ==null)
|
2017-10-30 17:37:17 +01:00
|
|
|
this.SaveNewDataset();
|
|
|
|
else
|
|
|
|
this.SaveEditedDataset();
|
|
|
|
}
|
|
|
|
|
|
|
|
CallDatasets(){
|
|
|
|
this.serverService.getDatasetForDmp({ "id": this.dmpIdforDatasets }).subscribe(
|
|
|
|
response => {
|
|
|
|
|
2017-10-30 15:56:50 +01:00
|
|
|
console.log("response");
|
|
|
|
console.log(response);
|
|
|
|
this.datasets = [];
|
|
|
|
response.forEach(resp => {
|
2017-10-30 17:37:17 +01:00
|
|
|
|
2017-10-30 15:56:50 +01:00
|
|
|
let dt = new Dataset();
|
|
|
|
dt.id = resp.id;
|
|
|
|
dt.name = resp.label;
|
|
|
|
dt.uriDataset = resp.uri;
|
2017-10-30 17:37:17 +01:00
|
|
|
dt.dmp = resp.dmp.label;
|
|
|
|
dt.profile = resp.profile.label;
|
|
|
|
dt.profileId = resp.profile.id;
|
2017-10-30 15:56:50 +01:00
|
|
|
this.datasets.push(dt);
|
|
|
|
var params = { limit: 8, offset: 0, sortAsc: false }
|
|
|
|
this.afterLoad();
|
|
|
|
this.datasetResource.query(params).then(datasets => this.datasets = datasets);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
);
|
|
|
|
}
|
2017-10-30 17:37:17 +01:00
|
|
|
|
2017-10-18 18:30:39 +02:00
|
|
|
// special params:
|
|
|
|
translations = <DataTableTranslations>{
|
|
|
|
indexColumn: 'Index column',
|
|
|
|
expandColumn: 'Expand column',
|
|
|
|
selectColumn: 'Select column',
|
|
|
|
paginationLimit: 'Max results',
|
|
|
|
paginationRange: 'Result range'
|
2017-10-30 15:56:50 +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-10-18 18:30:39 +02:00
|
|
|
|
2017-10-30 15:56:50 +01:00
|
|
|
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);
|
|
|
|
var params = { limit: 8, offset: 0, sortAsc: false }
|
|
|
|
this.afterLoad();
|
|
|
|
this.datasetResource.query(params).then(datasets => this.datasets = datasets);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2017-10-30 17:37:17 +01:00
|
|
|
editRow(item) { debugger;
|
|
|
|
this.dataset.label = item.name;
|
2017-10-30 15:56:50 +01:00
|
|
|
this.dataset.uri = item.uriDataset;
|
|
|
|
this.dataset.dmp = item.dmp;
|
|
|
|
this.dataset.profile = item.profileId;
|
2017-10-30 17:37:17 +01:00
|
|
|
this.dataset.id = item.id;
|
2017-10-30 15:56:50 +01:00
|
|
|
$("#newDatasetModal").modal("show");
|
|
|
|
}
|
|
|
|
|
|
|
|
newDataset() {
|
|
|
|
this.dataset.label = "";
|
|
|
|
this.dataset.uri = "";
|
|
|
|
this.dataset.dmp =this.dmpIdforDatasets;
|
|
|
|
this.dataset.profile = "";
|
|
|
|
$("#newDatasetModal").modal("show");
|
|
|
|
}
|
2017-10-18 18:30:39 +02:00
|
|
|
|
|
|
|
}
|