2017-12-08 11:26:52 +01:00
|
|
|
import { Component, OnInit, Input, ViewChild, NgZone, Output, EventEmitter, ViewEncapsulation } from '@angular/core';
|
2017-10-30 15:56:50 +01:00
|
|
|
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-12-08 10:51:39 +01:00
|
|
|
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-11-07 14:07:25 +01:00
|
|
|
import { ConfirmationComponent } from '../widgets/confirmation/confirmation.component';
|
2017-11-08 09:59:07 +01:00
|
|
|
import { Ng4LoadingSpinnerService } from 'ng4-loading-spinner';
|
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-11-07 13:04:58 +01:00
|
|
|
|
|
|
|
import '../../assets/custom.js';
|
2017-12-08 10:51:39 +01:00
|
|
|
declare function simple_notifier(type: string, title: string, message: string): any;
|
2017-11-07 13:04:58 +01: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-31 18:59:27 +01:00
|
|
|
styleUrls: ['./dataset.component.css'],
|
2017-12-08 11:26:52 +01:00
|
|
|
providers: [ServerService],
|
|
|
|
encapsulation: ViewEncapsulation.None
|
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-31 18:59:27 +01:00
|
|
|
// Start ALTERNATIVE
|
|
|
|
//whole dmp data model
|
2017-12-08 10:51:39 +01:00
|
|
|
tableData: any[] = new Array();
|
2017-11-23 11:40:02 +01:00
|
|
|
|
2017-10-31 18:59:27 +01:00
|
|
|
//organisation editor data model
|
|
|
|
editingOrganisation: any = {};
|
2017-12-08 10:51:39 +01:00
|
|
|
organisationEditorForm: any;
|
2017-10-31 18:59:27 +01:00
|
|
|
|
|
|
|
//required by the table
|
|
|
|
public filterQuery = "";
|
2017-11-29 17:15:47 +01:00
|
|
|
public statusFilter = "";
|
2017-10-31 18:59:27 +01:00
|
|
|
public rowsOnPage = 10;
|
2017-11-01 13:01:14 +01:00
|
|
|
public sortBy = "label";
|
2017-10-31 18:59:27 +01:00
|
|
|
public sortOrder = "asc";
|
|
|
|
|
2017-11-15 16:11:35 +01:00
|
|
|
dmpIdforDatasets: string;
|
|
|
|
|
2017-10-31 18:59:27 +01:00
|
|
|
|
|
|
|
// for tableIds
|
2017-12-08 10:51:39 +01:00
|
|
|
showIDs: boolean = false;
|
|
|
|
// END ALTERNATIVE
|
2017-10-31 18:59:27 +01: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-18 20:30:55 +02:00
|
|
|
@Input() datasetCount = 0;
|
2017-11-23 11:40:02 +01:00
|
|
|
|
2017-10-31 11:19:16 +01:00
|
|
|
@Input() dmpLabelforDatasets: string;
|
2017-11-01 13:01:14 +01:00
|
|
|
@Input() statusDropDown: DropdownField;
|
2017-10-30 15:56:50 +01:00
|
|
|
dataset: any;
|
2017-12-08 10:51:39 +01:00
|
|
|
saveAndDescribe: boolean;
|
2017-11-23 11:40:02 +01:00
|
|
|
|
2017-11-15 16:11:35 +01:00
|
|
|
dataSetValue: boolean = true;
|
2017-11-23 11:40:02 +01:00
|
|
|
|
2017-11-17 10:47:32 +01:00
|
|
|
uriRegex = "/^([a-z0-9+.-]+):(?://(?:((?:[a-z0-9-._~!$&'()*+,;=:]|%[0-9A-F]{2})*)@)?((?:[a-z0-9-._~!$&'()*+,;=]|%[0-9A-F]{2})*)(?::(\d*))?(/(?:[a-z0-9-._~!$&'()*+,;=:@/]|%[0-9A-F]{2})*)?|(/?(?:[a-z0-9-._~!$&'()*+,;=:@]|%[0-9A-F]{2})+(?:[a-z0-9-._~!$&'()*+,;=:@/]|%[0-9A-F]{2})*)?)(?:\?((?:[a-z0-9-._~!$&'()*+,;=:/?@]|%[0-9A-F]{2})*))?(?:#((?:[a-z0-9-._~!$&'()*+,;=:/?@]|%[0-9A-F]{2})*))?$/i";
|
|
|
|
|
2017-12-08 10:51:39 +01:00
|
|
|
filteredServices: any[];
|
|
|
|
filteredRepositories: any[];
|
|
|
|
filteredRegistries: any[];
|
2017-10-25 15:17:16 +02:00
|
|
|
|
2017-10-30 15:56:50 +01:00
|
|
|
constructor(
|
2017-11-23 11:40:02 +01:00
|
|
|
|
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-11-08 09:59:07 +01:00
|
|
|
private ngZone: NgZone,
|
|
|
|
private spinnerService: Ng4LoadingSpinnerService) {
|
2017-11-15 16:11:35 +01:00
|
|
|
|
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 = [];
|
2017-11-01 10:18:51 +01:00
|
|
|
this.saveAndDescribe = false;
|
2017-11-01 13:01:14 +01:00
|
|
|
this.statusDropDown = new DropdownField();
|
2017-12-08 10:51:39 +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-23 11:40:02 +01:00
|
|
|
ngOnInit() {
|
|
|
|
|
|
|
|
|
2017-11-15 16:11:35 +01:00
|
|
|
this.route
|
|
|
|
.queryParams
|
|
|
|
.subscribe(params => {
|
|
|
|
this.dmpIdforDatasets = params['dmpid'];
|
|
|
|
this.getDatasets();
|
|
|
|
});
|
|
|
|
|
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-11-07 13:04:58 +01:00
|
|
|
},
|
2017-12-08 10:51:39 +01:00
|
|
|
error => {
|
|
|
|
simple_notifier("danger", null, "Could not load User's Dataset Profiles");
|
|
|
|
}
|
2017-11-23 11:40:02 +01:00
|
|
|
|
2017-12-08 10:51:39 +01:00
|
|
|
);
|
2017-10-27 16:08:10 +02:00
|
|
|
|
|
|
|
}
|
|
|
|
)
|
2017-10-18 18:30:39 +02:00
|
|
|
}
|
|
|
|
|
2017-12-08 10:51:39 +01:00
|
|
|
ngAfterViewInit() {
|
2017-11-29 17:15:47 +01:00
|
|
|
|
2017-12-08 10:51:39 +01:00
|
|
|
$(function () {
|
2017-11-29 17:15:47 +01:00
|
|
|
$('#status-filter').append("<option value='' style='text-color: #cccccc' selected disabled hidden>Filter by status</option>");
|
|
|
|
//$('#status-filter').value=;
|
2017-12-08 10:51:39 +01:00
|
|
|
})
|
|
|
|
|
2017-11-29 17:15:47 +01:00
|
|
|
}
|
|
|
|
|
2017-12-08 10:51:39 +01:00
|
|
|
createEmptyDataset() {
|
2017-11-07 11:13:54 +01:00
|
|
|
return {
|
|
|
|
id: null,
|
|
|
|
label: '',
|
|
|
|
reference: '',
|
|
|
|
uri: '',
|
2017-11-15 18:32:34 +01:00
|
|
|
status: 0,
|
2017-11-07 11:13:54 +01:00
|
|
|
properties: '',
|
|
|
|
profile: { "id": '' },
|
2017-12-08 10:51:39 +01:00
|
|
|
dmp: { "id": '' },
|
2017-12-11 12:20:48 +01:00
|
|
|
services: [],
|
|
|
|
registries: [],
|
|
|
|
dataRepositories: []
|
2017-11-07 11:13:54 +01:00
|
|
|
}
|
|
|
|
}
|
2017-11-06 14:11:03 +01:00
|
|
|
|
2017-12-08 10:51:39 +01:00
|
|
|
SaveDataset() {
|
|
|
|
if (this.dataset.id == null) {
|
2017-11-01 16:07:51 +01:00
|
|
|
this.dataset.dmp = { "id": this.dmpIdforDatasets }
|
|
|
|
this.dataset.profile = { "id": this.dataset.profile }
|
|
|
|
this.serverService.createDatasetForDmp(this.dataset).subscribe(
|
|
|
|
response => {
|
2017-12-08 10:51:39 +01:00
|
|
|
simple_notifier("success", null, "Created dataset");
|
2017-11-01 16:07:51 +01:00
|
|
|
this.getDatasets();
|
|
|
|
if (this.saveAndDescribe == true)
|
|
|
|
this.describeDataset(response);
|
2017-11-07 13:04:58 +01:00
|
|
|
},
|
2017-12-08 10:51:39 +01:00
|
|
|
error => {
|
|
|
|
simple_notifier("danger", null, "Could not create Dataset");
|
2017-11-01 16:07:51 +01:00
|
|
|
}
|
|
|
|
)
|
2017-11-23 11:40:02 +01:00
|
|
|
$("#newDatasetModal").modal("hide");
|
|
|
|
|
2017-11-01 16:07:51 +01:00
|
|
|
}
|
2017-12-08 10:51:39 +01:00
|
|
|
else {
|
2017-11-17 02:15:09 +01:00
|
|
|
|
|
|
|
this.dataset.dmp = { "id": this.dmpIdforDatasets };
|
|
|
|
this.dataset.profile = { "id": this.dataset.profile };
|
2017-12-08 10:51:39 +01:00
|
|
|
this.dataset.creator = { "id": this.dataset.creator };
|
2017-11-17 02:15:09 +01:00
|
|
|
|
2017-11-01 16:07:51 +01:00
|
|
|
this.serverService.updateDatsetsProfile(this.dataset).subscribe(
|
|
|
|
response => {
|
2017-12-08 10:51:39 +01:00
|
|
|
simple_notifier("success", null, "Dataset edited");
|
2017-11-01 16:07:51 +01:00
|
|
|
this.getDatasets();
|
|
|
|
if (this.saveAndDescribe == true)
|
2017-12-08 10:51:39 +01:00
|
|
|
this.describeDataset(response);
|
2017-11-07 13:04:58 +01:00
|
|
|
},
|
|
|
|
error => {
|
2017-12-08 10:51:39 +01:00
|
|
|
simple_notifier("danger", null, "Could not edit dataset");
|
2017-11-01 16:07:51 +01:00
|
|
|
}
|
|
|
|
)
|
|
|
|
$("#newDatasetModal").modal("hide");
|
|
|
|
}
|
2017-11-23 11:40:02 +01:00
|
|
|
|
2017-10-30 17:37:17 +01:00
|
|
|
}
|
|
|
|
|
2017-12-08 10:51:39 +01:00
|
|
|
getDatasets(muted?: boolean) {
|
2017-11-16 10:46:31 +01:00
|
|
|
this.spinnerService.show();
|
2017-10-30 17:37:17 +01:00
|
|
|
this.serverService.getDatasetForDmp({ "id": this.dmpIdforDatasets }).subscribe(
|
2017-11-07 13:04:58 +01:00
|
|
|
response => {
|
2017-11-01 16:07:51 +01:00
|
|
|
this.tableData = response;
|
2017-12-08 10:51:39 +01:00
|
|
|
if (muted && muted != true)
|
|
|
|
simple_notifier("success", null, "Updated datasets table");
|
2017-11-07 13:04:58 +01:00
|
|
|
},
|
|
|
|
error => {
|
2017-12-08 10:51:39 +01:00
|
|
|
simple_notifier("danger", null, "Could not update datasets table");
|
2017-11-16 10:46:31 +01:00
|
|
|
},
|
2017-12-08 10:51:39 +01:00
|
|
|
() => {
|
2017-11-16 10:46:31 +01:00
|
|
|
this.spinnerService.hide();
|
2017-10-30 15:56:50 +01:00
|
|
|
}
|
|
|
|
);
|
|
|
|
}
|
2017-11-23 11:40:02 +01:00
|
|
|
|
2017-10-18 18:30:39 +02:00
|
|
|
|
2017-10-30 15:56:50 +01:00
|
|
|
getDatasetForDmpMethod(dmpid) {
|
2017-11-08 09:59:07 +01:00
|
|
|
this.spinnerService.show();
|
2017-10-30 15:56:50 +01:00
|
|
|
this.serverService.getDatasetForDmp({ "id": dmpid }).subscribe(
|
|
|
|
response => {
|
2017-11-01 16:54:14 +01:00
|
|
|
this.tableData = response;
|
2017-11-07 13:04:58 +01:00
|
|
|
},
|
|
|
|
error => {
|
2017-12-08 10:51:39 +01:00
|
|
|
console.log("could not retrieve dataset for dpm: " + dmpid);
|
2017-11-08 09:59:07 +01:00
|
|
|
},
|
2017-12-08 10:51:39 +01:00
|
|
|
() => {
|
2017-11-08 09:59:07 +01:00
|
|
|
this.spinnerService.hide();
|
2017-10-30 15:56:50 +01:00
|
|
|
}
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2017-11-23 11:40:02 +01:00
|
|
|
editRow(item, event) {
|
2017-12-08 10:51:39 +01:00
|
|
|
if (event.toElement.id == "editDataset") {
|
2017-12-11 12:20:48 +01:00
|
|
|
this.spinnerService.show();
|
|
|
|
this.serverService.getDatasetByID(item.id).subscribe(item => {
|
|
|
|
this.dataset = item;
|
|
|
|
this.dataset.profile = item.profile.id;
|
|
|
|
$("#newDatasetModal").modal("show");
|
|
|
|
},
|
|
|
|
error => simple_notifier("danger", null, "Could not Open Dataset"),
|
|
|
|
() => this.spinnerService.hide()
|
|
|
|
)
|
2017-11-01 16:07:51 +01:00
|
|
|
}
|
2017-12-08 10:51:39 +01:00
|
|
|
else if (event.toElement.id == "describeDataset") {
|
2017-11-01 16:07:51 +01:00
|
|
|
this.describeDataset(item);
|
|
|
|
}
|
2017-11-23 11:40:02 +01:00
|
|
|
|
2017-10-30 15:56:50 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
newDataset() {
|
2017-11-07 11:13:54 +01:00
|
|
|
this.dataset = this.createEmptyDataset();
|
2017-12-08 10:51:39 +01:00
|
|
|
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
|
|
|
|
2017-12-08 10:51:39 +01:00
|
|
|
SaveDescribeDataset() {
|
2017-11-01 10:18:51 +01:00
|
|
|
this.saveAndDescribe = true;
|
|
|
|
this.SaveDataset();
|
|
|
|
}
|
|
|
|
|
2017-11-06 17:25:23 +01:00
|
|
|
describeDataset(item) {
|
2017-12-08 10:51:39 +01:00
|
|
|
this.router.navigate(['/dynamic-form/' + item.id]);
|
2017-11-15 23:55:49 +01:00
|
|
|
//this.ngZone.run(() => this.router.navigate(['dynamic-form', {id: item.profile.id, datasetId:item.id, label: item.label}]));
|
2017-11-01 10:18:51 +01:00
|
|
|
}
|
|
|
|
|
2017-12-08 10:51:39 +01:00
|
|
|
markDatasetForDelete(dataset) {
|
2017-11-07 14:07:25 +01:00
|
|
|
this.dataset = dataset;
|
|
|
|
}
|
2017-11-23 11:40:02 +01:00
|
|
|
|
2017-12-08 10:51:39 +01:00
|
|
|
deleteDataset(confirmation) {
|
|
|
|
if (confirmation == true)
|
2017-11-07 14:07:25 +01:00
|
|
|
this.deleteRow(this.dataset);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-12-08 10:51:39 +01:00
|
|
|
deleteRow(dataset) {
|
2017-11-23 11:40:02 +01:00
|
|
|
this.serverService.deleteDataset(dataset).subscribe(
|
|
|
|
response => {
|
2017-12-08 10:51:39 +01:00
|
|
|
simple_notifier("success", null, "Deleted dataset");
|
2017-11-07 13:04:58 +01:00
|
|
|
this.getDatasets();
|
2017-11-06 14:11:03 +01:00
|
|
|
},
|
|
|
|
err => {
|
2017-11-17 02:15:09 +01:00
|
|
|
|
2017-12-08 10:51:39 +01:00
|
|
|
if (err.status >= 200 && err.status < 300)
|
|
|
|
simple_notifier("success", null, "Deleted dataset");
|
2017-11-17 02:15:09 +01:00
|
|
|
else
|
2017-12-08 10:51:39 +01:00
|
|
|
simple_notifier("danger", null, "Could not delete the dataset");
|
2017-11-17 02:15:09 +01:00
|
|
|
this.getDatasets();
|
|
|
|
|
2017-11-23 11:40:02 +01:00
|
|
|
}
|
|
|
|
);
|
2017-11-06 14:11:03 +01:00
|
|
|
}
|
|
|
|
|
2017-12-08 10:51:39 +01:00
|
|
|
searchServices(event) {
|
|
|
|
let query = event.query;
|
|
|
|
this.serverService.searchDatasetService(query).subscribe(services => {
|
|
|
|
this.filteredServices = services;
|
|
|
|
});
|
|
|
|
}
|
2017-11-06 14:11:03 +01:00
|
|
|
|
2017-12-08 10:51:39 +01:00
|
|
|
searchRegistries(event) {
|
|
|
|
let query = event.query;
|
|
|
|
this.serverService.searchDatasetRegistry(query).subscribe(registries => {
|
|
|
|
this.filteredRegistries = registries;
|
|
|
|
});
|
|
|
|
}
|
2017-11-06 14:11:03 +01:00
|
|
|
|
2017-12-08 10:51:39 +01:00
|
|
|
searchRepositories(event) {
|
|
|
|
let query = event.query;
|
|
|
|
this.serverService.searchDatasetRepository(query).subscribe(repos => {
|
|
|
|
this.filteredRepositories = repos;
|
|
|
|
});
|
|
|
|
}
|
2017-10-18 18:30:39 +02:00
|
|
|
}
|