300 lines
8.3 KiB
TypeScript
300 lines
8.3 KiB
TypeScript
import { Component, OnInit, Input, ViewChild, NgZone, Output, EventEmitter, ViewEncapsulation } 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 } from 'angular2-datatable';
|
|
import { DropdownField } from '../../app/form/fields/dropdown/field-dropdown';
|
|
import { Param } from '../entities/model/param';
|
|
import { StatusToString } from '../pipes/various/status-to-string';
|
|
import { ConfirmationComponent } from '../widgets/confirmation/confirmation.component';
|
|
import { Ng4LoadingSpinnerService } from 'ng4-loading-spinner';
|
|
|
|
declare var $: any;
|
|
|
|
|
|
import '../../assets/custom.js';
|
|
declare function simple_notifier(type: string, title: string, message: string): any;
|
|
|
|
@Component({
|
|
selector: 'datasets-table',
|
|
templateUrl: 'dataset.html',
|
|
styleUrls: ['./dataset.component.css'],
|
|
providers: [ServerService],
|
|
encapsulation: ViewEncapsulation.None
|
|
})
|
|
|
|
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 statusFilter = "";
|
|
public rowsOnPage = 10;
|
|
public sortBy = "label";
|
|
public sortOrder = "asc";
|
|
|
|
dmpIdforDatasets: string;
|
|
|
|
|
|
// for tableIds
|
|
showIDs: boolean = false;
|
|
// END ALTERNATIVE
|
|
|
|
returnUrl: string;
|
|
@Input() datasets: Dataset[];
|
|
@Input() datasetProfileDropDown: DropdownField;
|
|
@Input() datasetCount = 0;
|
|
|
|
@Input() dmpLabelforDatasets: string;
|
|
@Input() statusDropDown: DropdownField;
|
|
dataset: any;
|
|
saveAndDescribe: boolean;
|
|
|
|
dataSetValue: boolean = true;
|
|
|
|
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";
|
|
|
|
filteredServices: any[];
|
|
filteredRepositories: any[];
|
|
filteredRegistries: any[];
|
|
|
|
constructor(
|
|
|
|
private serverService: ServerService,
|
|
private route: ActivatedRoute,
|
|
private router: Router,
|
|
private ngZone: NgZone,
|
|
private spinnerService: Ng4LoadingSpinnerService) {
|
|
|
|
this.dataset = this.createEmptyDataset();
|
|
|
|
this.datasetProfileDropDown = new DropdownField();
|
|
this.datasetProfileDropDown.options = [];
|
|
this.saveAndDescribe = false;
|
|
this.statusDropDown = new DropdownField();
|
|
this.statusDropDown.options = [{ key: '', value: null }, { key: '0', value: "Active" }, { key: '1', value: "Inactive" }]
|
|
|
|
}
|
|
|
|
ngOnInit() {
|
|
|
|
|
|
this.route
|
|
.queryParams
|
|
.subscribe(params => {
|
|
this.dmpIdforDatasets = params['dmpid'];
|
|
this.getDatasets();
|
|
});
|
|
|
|
|
|
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);
|
|
},
|
|
error => {
|
|
simple_notifier("danger", null, "Could not load User's Dataset Profiles");
|
|
}
|
|
|
|
);
|
|
|
|
}
|
|
)
|
|
}
|
|
|
|
ngAfterViewInit() {
|
|
|
|
$(function () {
|
|
$('#status-filter').append("<option value='' style='text-color: #cccccc' selected disabled hidden>Filter by status</option>");
|
|
//$('#status-filter').value=;
|
|
})
|
|
|
|
}
|
|
|
|
createEmptyDataset() {
|
|
return {
|
|
id: null,
|
|
label: '',
|
|
reference: '',
|
|
uri: '',
|
|
status: 0,
|
|
properties: '',
|
|
profile: { "id": '' },
|
|
dmp: { "id": '' },
|
|
services: [],
|
|
registries: [],
|
|
dataRepositories: []
|
|
}
|
|
}
|
|
|
|
SaveDataset() {
|
|
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 => {
|
|
simple_notifier("success", null, "Created dataset");
|
|
this.getDatasets();
|
|
if (this.saveAndDescribe == true)
|
|
this.describeDataset(response);
|
|
},
|
|
error => {
|
|
simple_notifier("danger", null, "Could not create Dataset");
|
|
}
|
|
)
|
|
$("#newDatasetModal").modal("hide");
|
|
|
|
}
|
|
else {
|
|
|
|
this.dataset.dmp = { "id": this.dmpIdforDatasets };
|
|
this.dataset.profile = { "id": this.dataset.profile };
|
|
this.dataset.creator = { "id": this.dataset.creator };
|
|
|
|
this.serverService.updateDatsetsProfile(this.dataset).subscribe(
|
|
response => {
|
|
simple_notifier("success", null, "Dataset edited");
|
|
this.getDatasets();
|
|
if (this.saveAndDescribe == true)
|
|
this.describeDataset(response);
|
|
},
|
|
error => {
|
|
simple_notifier("danger", null, "Could not edit dataset");
|
|
}
|
|
)
|
|
$("#newDatasetModal").modal("hide");
|
|
}
|
|
|
|
}
|
|
|
|
getDatasets(muted?: boolean) {
|
|
this.spinnerService.show();
|
|
this.serverService.getDatasetForDmp({ "id": this.dmpIdforDatasets }).subscribe(
|
|
response => {
|
|
this.tableData = response;
|
|
if (muted && muted != true)
|
|
simple_notifier("success", null, "Updated datasets table");
|
|
},
|
|
error => {
|
|
simple_notifier("danger", null, "Could not update datasets table");
|
|
},
|
|
() => {
|
|
this.spinnerService.hide();
|
|
}
|
|
);
|
|
}
|
|
|
|
|
|
getDatasetForDmpMethod(dmpid) {
|
|
this.spinnerService.show();
|
|
this.serverService.getDatasetForDmp({ "id": dmpid }).subscribe(
|
|
response => {
|
|
this.tableData = response;
|
|
},
|
|
error => {
|
|
console.log("could not retrieve dataset for dpm: " + dmpid);
|
|
},
|
|
() => {
|
|
this.spinnerService.hide();
|
|
}
|
|
);
|
|
}
|
|
|
|
editRow(item, event) {
|
|
if (event.toElement.id == "editDataset") {
|
|
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()
|
|
)
|
|
}
|
|
else if (event.toElement.id == "describeDataset") {
|
|
this.describeDataset(item);
|
|
}
|
|
|
|
}
|
|
|
|
newDataset() {
|
|
this.dataset = this.createEmptyDataset();
|
|
this.dataset.dmp = this.dmpLabelforDatasets;
|
|
this.dataset.status = 0;
|
|
$("#newDatasetModal").modal("show");
|
|
}
|
|
|
|
SaveDescribeDataset() {
|
|
this.saveAndDescribe = true;
|
|
this.SaveDataset();
|
|
}
|
|
|
|
describeDataset(item) {
|
|
this.router.navigate(['/dynamic-form/' + item.id]);
|
|
//this.ngZone.run(() => this.router.navigate(['dynamic-form', {id: item.profile.id, datasetId:item.id, label: item.label}]));
|
|
}
|
|
|
|
markDatasetForDelete(dataset) {
|
|
this.dataset = dataset;
|
|
}
|
|
|
|
deleteDataset(confirmation) {
|
|
if (confirmation == true)
|
|
this.deleteRow(this.dataset);
|
|
}
|
|
|
|
|
|
deleteRow(dataset) {
|
|
this.serverService.deleteDataset(dataset).subscribe(
|
|
response => {
|
|
simple_notifier("success", null, "Deleted dataset");
|
|
this.getDatasets();
|
|
},
|
|
err => {
|
|
|
|
if (err.status >= 200 && err.status < 300)
|
|
simple_notifier("success", null, "Deleted dataset");
|
|
else
|
|
simple_notifier("danger", null, "Could not delete the dataset");
|
|
this.getDatasets();
|
|
|
|
}
|
|
);
|
|
}
|
|
|
|
searchServices(event) {
|
|
let query = event.query;
|
|
this.serverService.searchDatasetService(query).subscribe(services => {
|
|
this.filteredServices = services;
|
|
});
|
|
}
|
|
|
|
searchRegistries(event) {
|
|
let query = event.query;
|
|
this.serverService.searchDatasetRegistry(query).subscribe(registries => {
|
|
this.filteredRegistries = registries;
|
|
});
|
|
}
|
|
|
|
searchRepositories(event) {
|
|
let query = event.query;
|
|
this.serverService.searchDatasetRepository(query).subscribe(repos => {
|
|
this.filteredRepositories = repos;
|
|
});
|
|
}
|
|
}
|