2017-12-08 11:26:52 +01:00
|
|
|
import { Component, OnInit, Input, Output, EventEmitter, ViewChild, ViewEncapsulation } from '@angular/core';
|
2017-11-10 16:47:03 +01:00
|
|
|
import { GoogleSignInSuccess } from 'angular-google-signin';
|
2017-10-25 15:17:16 +02:00
|
|
|
import { Router, ActivatedRoute } from '@angular/router';
|
|
|
|
import { ServerService } from '../../app/services/server.service';
|
2017-10-27 10:34:05 +02:00
|
|
|
import { Dmp } from '../entities/model/dmp';
|
2017-10-25 15:17:16 +02:00
|
|
|
import { Dataset } from '../entities/model/dataset';
|
|
|
|
import { Project } from '../entities/model/project';
|
2017-11-07 14:07:25 +01:00
|
|
|
import { ConfirmationComponent } from '../widgets/confirmation/confirmation.component';
|
2017-11-03 18:57:06 +01:00
|
|
|
|
2017-11-10 16:47:03 +01:00
|
|
|
import { DataTable } from 'angular2-datatable';
|
2017-10-25 15:17:16 +02:00
|
|
|
import { DropdownField } from '../../app/form/fields/dropdown/field-dropdown';
|
|
|
|
import { Param } from '../entities/model/param';
|
|
|
|
import { ModalComponent } from '../modal/modal.component';
|
|
|
|
import { HttpErrorResponse } from '@angular/common/http';
|
2017-12-08 11:26:52 +01:00
|
|
|
import { FormGroup, FormControl } from '@angular/forms'; //na dw an xreiazontai
|
2017-10-25 15:17:16 +02:00
|
|
|
import { NgForm } from '@angular/forms';
|
2017-10-27 18:38:31 +02:00
|
|
|
import { DatasetsComponent } from '../datasets/dataset.component';
|
2017-11-03 18:57:06 +01:00
|
|
|
import { StatusToString } from '../pipes/various/status-to-string';
|
2017-12-08 11:26:52 +01:00
|
|
|
import { MenuItem } from 'primeng/primeng';
|
2017-10-25 15:17:16 +02:00
|
|
|
|
2017-12-08 11:26:52 +01:00
|
|
|
declare var $: any;
|
2017-10-27 16:08:10 +02:00
|
|
|
|
2017-11-07 12:30:11 +01:00
|
|
|
import '../../assets/custom.js';
|
2017-12-08 11:26:52 +01:00
|
|
|
declare function simple_notifier(type: string, title: string, message: string): any;
|
2017-11-07 12:30:11 +01:00
|
|
|
|
2017-10-25 15:17:16 +02:00
|
|
|
@Component({
|
|
|
|
selector: 'dmps',
|
|
|
|
templateUrl: 'dmps.html',
|
2017-10-31 18:59:27 +01:00
|
|
|
styleUrls: ['./dmp.component.css'],
|
2017-12-08 11:26:52 +01:00
|
|
|
providers: [ServerService],
|
|
|
|
encapsulation: ViewEncapsulation.None
|
2017-10-25 15:17:16 +02:00
|
|
|
})
|
|
|
|
|
2017-12-08 11:26:52 +01:00
|
|
|
export class DmpComponent implements OnInit {
|
2017-10-31 18:59:27 +01:00
|
|
|
|
|
|
|
//whole dmp data model
|
2017-12-08 11:26:52 +01:00
|
|
|
tableData: any[] = new Array();
|
|
|
|
|
2017-10-31 18:59:27 +01:00
|
|
|
//required by the table
|
|
|
|
public filterQuery = "";
|
|
|
|
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";
|
|
|
|
|
|
|
|
// for tableIds
|
2017-12-08 11:26:52 +01:00
|
|
|
showIDs: boolean = false;
|
2017-11-14 15:06:00 +01:00
|
|
|
|
|
|
|
|
2017-12-08 11:26:52 +01:00
|
|
|
dmp: any;
|
2017-11-14 15:06:00 +01:00
|
|
|
|
2017-12-08 11:26:52 +01:00
|
|
|
@Input() projectsDropDown: DropdownField;
|
2017-11-01 16:42:01 +01:00
|
|
|
@Input() statusDropDown: DropdownField;
|
2017-10-25 15:17:16 +02:00
|
|
|
|
2017-12-08 11:26:52 +01:00
|
|
|
@ViewChild(DatasetsComponent) datasetsComponent: DatasetsComponent;
|
|
|
|
|
|
|
|
filteredResearchers: any[];
|
|
|
|
filteredOrganizations: any[];
|
|
|
|
|
|
|
|
constructor(
|
2017-10-25 15:17:16 +02:00
|
|
|
private serverService: ServerService,
|
|
|
|
private route: ActivatedRoute,
|
2017-12-08 11:26:52 +01:00
|
|
|
private router: Router) {
|
|
|
|
this.projectsDropDown = new DropdownField();
|
|
|
|
this.projectsDropDown.options = [];
|
|
|
|
this.statusDropDown = new DropdownField();
|
|
|
|
this.statusDropDown.options = [{ key: '', value: null }, { key: '0', value: "Active" }, { key: '1', value: "Inactive" }]
|
|
|
|
//this.projects = [];
|
|
|
|
|
2017-11-15 11:59:08 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
clearDmp() {
|
|
|
|
|
|
|
|
this.dmp = {
|
|
|
|
id: null,
|
|
|
|
label: '',
|
2017-12-08 11:26:52 +01:00
|
|
|
previous: '',
|
|
|
|
version: '',
|
|
|
|
organizations: [],
|
|
|
|
researchers: []
|
2017-11-15 11:59:08 +01:00
|
|
|
}
|
|
|
|
|
2017-10-25 15:17:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
ngOnInit() {
|
2017-11-07 12:30:11 +01:00
|
|
|
|
2017-12-08 11:26:52 +01:00
|
|
|
this.getDmps();
|
2017-10-25 15:17:16 +02:00
|
|
|
|
|
|
|
this.serverService.getAllProjects().subscribe(
|
|
|
|
response => {
|
|
|
|
//let params = new Param();
|
|
|
|
response.forEach((dmp) => {
|
|
|
|
let params = new Param();
|
|
|
|
params.key = dmp.id;
|
|
|
|
params.value = dmp.label;
|
|
|
|
this.projectsDropDown.options.push(params);
|
|
|
|
});
|
|
|
|
|
2017-11-01 12:30:39 +01:00
|
|
|
},
|
|
|
|
(err: HttpErrorResponse) => {
|
2017-12-08 11:26:52 +01:00
|
|
|
simple_notifier("danger", null, "Could not load User's Projects");
|
2017-10-25 15:17:16 +02:00
|
|
|
}
|
|
|
|
)
|
2017-11-14 15:06:00 +01:00
|
|
|
|
2017-11-16 18:07:27 +01:00
|
|
|
this.clearDmp();
|
2017-11-14 23:51:39 +01:00
|
|
|
|
2017-12-08 11:26:52 +01:00
|
|
|
|
2017-11-14 23:51:39 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-12-08 11:26:52 +01:00
|
|
|
getDmps(muted?: boolean) {
|
|
|
|
this.serverService.getDmpOfUser().subscribe(
|
2017-11-14 23:51:39 +01:00
|
|
|
response => {
|
|
|
|
this.tableData = response;
|
2017-12-08 11:26:52 +01:00
|
|
|
if (muted && muted != true)
|
|
|
|
simple_notifier("success", null, "Refreshed DMPs");
|
2017-11-27 13:03:43 +01:00
|
|
|
|
2017-12-08 11:26:52 +01:00
|
|
|
this.tableData.forEach(dmp => {
|
|
|
|
if (dmp.previous != null)
|
|
|
|
this.serverService.getDmp(dmp.previous).subscribe(previous => { dmp.previous = previous; });
|
2017-11-27 13:03:43 +01:00
|
|
|
});
|
|
|
|
|
2017-11-14 23:51:39 +01:00
|
|
|
},
|
|
|
|
(err: HttpErrorResponse) => {
|
2017-12-08 11:26:52 +01:00
|
|
|
simple_notifier("danger", null, "Could not refresh DMPs");
|
|
|
|
}
|
|
|
|
);
|
2017-10-25 15:17:16 +02:00
|
|
|
}
|
|
|
|
|
2017-12-08 11:26:52 +01:00
|
|
|
newDMP() {
|
2017-10-25 15:17:16 +02:00
|
|
|
|
2017-12-08 11:26:52 +01:00
|
|
|
this.dmp.project = { "id": this.dmp.project };
|
2017-11-14 23:51:39 +01:00
|
|
|
this.dmp["version"] = 1;
|
2017-12-08 11:26:52 +01:00
|
|
|
|
2017-11-14 23:51:39 +01:00
|
|
|
this.serverService.createDmpForCurrentUser(this.dmp)
|
2017-12-08 11:26:52 +01:00
|
|
|
.subscribe(
|
|
|
|
response => {
|
|
|
|
simple_notifier("success", null, "DMP created");
|
2017-11-14 23:51:39 +01:00
|
|
|
this.getDmps();
|
|
|
|
},
|
|
|
|
error => {
|
2017-12-08 11:26:52 +01:00
|
|
|
simple_notifier("danger", null, "Could not create the DMP");
|
2017-11-14 23:51:39 +01:00
|
|
|
}
|
2017-12-08 11:26:52 +01:00
|
|
|
);
|
2017-11-14 23:51:39 +01:00
|
|
|
$("#newDmpModal").modal("hide");
|
|
|
|
}
|
2017-11-01 12:30:39 +01:00
|
|
|
|
2017-12-08 11:26:52 +01:00
|
|
|
updateDMP() {
|
2017-10-25 15:17:16 +02:00
|
|
|
|
2017-12-08 11:26:52 +01:00
|
|
|
this.dmp.project = { "id": this.dmp.project };
|
|
|
|
this.dmp.creator = { "id": this.dmp.creator };
|
|
|
|
if (this.dmp.previous != null)
|
2017-11-27 13:03:43 +01:00
|
|
|
this.dmp.previous = this.dmp.previous.id;
|
2017-10-27 11:24:04 +02:00
|
|
|
|
2017-11-14 23:51:39 +01:00
|
|
|
this.serverService.updateDmp(this.dmp)
|
2017-12-08 11:26:52 +01:00
|
|
|
.subscribe(
|
|
|
|
response => {
|
|
|
|
simple_notifier("success", null, "Edited the DMP");
|
2017-11-14 23:51:39 +01:00
|
|
|
this.getDmps();
|
|
|
|
},
|
2017-12-08 11:26:52 +01:00
|
|
|
error => {
|
|
|
|
simple_notifier("danger", null, "Failed to edit the DMP");
|
2017-11-14 23:51:39 +01:00
|
|
|
}
|
2017-12-08 11:26:52 +01:00
|
|
|
);
|
2017-11-14 23:51:39 +01:00
|
|
|
$("#newDmpModal").modal("hide");
|
|
|
|
$("#newVersionDmpModal").modal("hide");
|
2017-12-08 11:26:52 +01:00
|
|
|
|
2017-11-14 23:51:39 +01:00
|
|
|
}
|
2017-10-31 18:59:27 +01:00
|
|
|
|
2017-12-08 11:26:52 +01:00
|
|
|
cloneDMP(dmp) {
|
|
|
|
dmp = { "id": dmp.id, "label": dmp.label };
|
2017-11-14 23:51:39 +01:00
|
|
|
this.serverService.cloneDmp(dmp).subscribe(
|
|
|
|
response => {
|
2017-12-08 11:26:52 +01:00
|
|
|
simple_notifier("success", null, "Successfully cloned the DMP");
|
2017-11-14 23:51:39 +01:00
|
|
|
this.getDmps();
|
|
|
|
},
|
|
|
|
error => {
|
2017-12-08 11:26:52 +01:00
|
|
|
simple_notifier("danger", null, "Failed to clone the DMP");
|
2017-11-14 23:51:39 +01:00
|
|
|
}
|
|
|
|
);
|
|
|
|
$("#newVersionDmpModal").modal("hide");
|
|
|
|
}
|
2017-10-27 18:38:31 +02:00
|
|
|
|
2017-12-08 11:26:52 +01:00
|
|
|
SaveDmp() {
|
2017-11-14 23:51:39 +01:00
|
|
|
if (this.dmp.id == null)
|
|
|
|
this.newDMP();
|
|
|
|
else
|
|
|
|
this.updateDMP();
|
|
|
|
}
|
2017-11-01 12:59:57 +01:00
|
|
|
|
2017-10-25 15:17:16 +02:00
|
|
|
|
2017-12-08 11:26:52 +01:00
|
|
|
editDmp(item) {
|
|
|
|
this.dmp = Object.assign({}, item);
|
2017-10-31 18:59:27 +01:00
|
|
|
this.dmp.project = item.project.id;
|
2017-12-08 11:26:52 +01:00
|
|
|
$("#newDmpModal").modal("show");
|
2017-10-31 18:59:27 +01:00
|
|
|
}
|
2017-11-14 15:06:00 +01:00
|
|
|
|
2017-12-08 11:26:52 +01:00
|
|
|
cloneDmp(item) {
|
|
|
|
this.dmp = Object.assign({}, item);
|
2017-10-31 18:59:27 +01:00
|
|
|
this.dmp.project = item.project.id;
|
|
|
|
$("#newVersionDmpModal").modal("show");
|
|
|
|
}
|
2017-11-08 09:59:07 +01:00
|
|
|
|
2017-12-08 11:26:52 +01:00
|
|
|
newDmpForm(item) {
|
2017-11-15 11:59:08 +01:00
|
|
|
|
2017-11-16 18:07:27 +01:00
|
|
|
this.clearDmp();
|
2017-11-03 18:57:06 +01:00
|
|
|
|
2017-11-14 23:51:39 +01:00
|
|
|
$("#newDmpModal").modal("show");
|
|
|
|
}
|
2017-11-07 14:07:25 +01:00
|
|
|
|
2017-12-08 11:26:52 +01:00
|
|
|
markDMPForDelete(dmp) {
|
2017-11-14 23:51:39 +01:00
|
|
|
this.dmp = dmp;
|
|
|
|
}
|
2017-11-07 14:07:25 +01:00
|
|
|
|
2017-12-08 11:26:52 +01:00
|
|
|
deleteDMP(confirmation) {
|
|
|
|
if (confirmation == true)
|
2017-11-14 23:51:39 +01:00
|
|
|
this.deleteRow(this.dmp);
|
|
|
|
}
|
2017-11-06 14:11:03 +01:00
|
|
|
|
2017-12-08 11:26:52 +01:00
|
|
|
deleteRow(dmp) {
|
2017-11-06 14:11:03 +01:00
|
|
|
|
2017-12-08 11:26:52 +01:00
|
|
|
this.dmp = { "id": this.dmp.id }; //only id is needed to delete
|
2017-11-15 11:59:08 +01:00
|
|
|
|
2017-12-08 11:26:52 +01:00
|
|
|
|
|
|
|
this.serverService.deleteDmp(this.dmp).subscribe(
|
|
|
|
response => {
|
|
|
|
simple_notifier("success", null, "Successfully deleted the DMP");
|
2017-11-14 23:51:39 +01:00
|
|
|
this.getDmps();
|
|
|
|
},
|
|
|
|
(err: HttpErrorResponse) => {
|
2017-12-08 11:26:52 +01:00
|
|
|
if (err.status >= 200 && err.status < 300)
|
|
|
|
simple_notifier("success", null, "Successfully deleted the DMP");
|
2017-11-17 02:15:09 +01:00
|
|
|
else
|
2017-12-08 11:26:52 +01:00
|
|
|
simple_notifier("danger", null, "Failed to delete the DMP");
|
2017-11-17 02:15:09 +01:00
|
|
|
this.getDmps();
|
2017-12-08 11:26:52 +01:00
|
|
|
}
|
2017-11-14 23:51:39 +01:00
|
|
|
);
|
2017-11-06 14:11:03 +01:00
|
|
|
|
2017-11-10 16:29:57 +01:00
|
|
|
}
|
|
|
|
|
2017-12-08 11:26:52 +01:00
|
|
|
clickFilters(element) {
|
|
|
|
if (element.textContent == "More filters")
|
2017-11-14 23:51:39 +01:00
|
|
|
element.textContent = "Less Filters";
|
|
|
|
else
|
|
|
|
element.textContent = "More Filters";
|
2017-12-08 11:26:52 +01:00
|
|
|
}
|
2017-11-14 23:51:39 +01:00
|
|
|
|
2017-12-08 11:26:52 +01:00
|
|
|
SelectDMPStatus(dmp, event, oldValue) {
|
2017-11-14 23:51:39 +01:00
|
|
|
console.log(dmp);
|
2017-12-08 11:26:52 +01:00
|
|
|
let cannotChangeStatus: boolean;
|
|
|
|
if (dmp.status == 2) {
|
2017-11-14 23:51:39 +01:00
|
|
|
this.serverService.getDatasetForDmp({ "id": dmp.id }).subscribe(
|
|
|
|
response => {
|
|
|
|
response.forEach(dataset => {
|
2017-12-08 11:26:52 +01:00
|
|
|
if (dataset.status !== 2 || dataset.status !== 3) {
|
|
|
|
cannotChangeStatus = true;
|
2017-11-14 23:51:39 +01:00
|
|
|
}
|
|
|
|
return;
|
|
|
|
});
|
2017-12-08 11:26:52 +01:00
|
|
|
if (cannotChangeStatus == true) {
|
2017-11-14 23:51:39 +01:00
|
|
|
dmp.status = 0;
|
|
|
|
$("#messageForChangingStatus").modal("show");
|
2017-11-10 16:29:57 +01:00
|
|
|
}
|
2017-11-14 23:51:39 +01:00
|
|
|
},
|
|
|
|
error => {
|
2017-12-08 11:26:52 +01:00
|
|
|
console.log("could not retrieve dataset for dpm: " + dmp.id);
|
2017-11-10 16:29:57 +01:00
|
|
|
}
|
2017-11-14 23:51:39 +01:00
|
|
|
);
|
|
|
|
}
|
2017-12-08 11:26:52 +01:00
|
|
|
|
2017-11-10 16:29:57 +01:00
|
|
|
}
|
2017-10-25 15:17:16 +02:00
|
|
|
|
2017-12-08 11:26:52 +01:00
|
|
|
showDatasetsOfDmp(item) {
|
|
|
|
this.router.navigate(['/dataset'], { queryParams: { "dmpid": item.id, "label": item.label } });
|
2017-11-15 16:11:35 +01:00
|
|
|
}
|
|
|
|
|
2017-12-08 11:26:52 +01:00
|
|
|
viewDetailedDMP(dmp) {
|
2017-11-24 09:39:24 +01:00
|
|
|
let random = Math.random().toString(36).replace(/[^a-z]+/g, '').substr(0, 5);
|
2017-12-08 11:26:52 +01:00
|
|
|
this.router.navigate(['/dmps/dmp'], { queryParams: { "dmpid": dmp.id, "label": dmp.label, random: random } });
|
2017-11-16 15:16:09 +01:00
|
|
|
}
|
|
|
|
|
2017-12-08 11:26:52 +01:00
|
|
|
viewDetailedProject(dmp) {
|
2017-11-24 09:39:24 +01:00
|
|
|
let random = Math.random().toString(36).replace(/[^a-z]+/g, '').substr(0, 5);
|
2017-12-08 11:26:52 +01:00
|
|
|
this.router.navigate(['/dmps/project'], { queryParams: { "projectid": dmp.project.id, "label": dmp.project.label, random: random } });
|
2017-11-22 13:25:01 +01:00
|
|
|
}
|
2017-11-15 16:11:35 +01:00
|
|
|
|
2017-12-08 11:26:52 +01:00
|
|
|
searchResearchers(event) {
|
|
|
|
let query = event.query;
|
|
|
|
this.serverService.searchDMPResearchers(query).subscribe(researchers => {
|
|
|
|
this.filteredResearchers = researchers;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
searchOrganizations(event) {
|
|
|
|
let query = event.query;
|
|
|
|
this.serverService.searchDMPOrganizations(query).subscribe(organizations => {
|
|
|
|
this.filteredOrganizations = organizations;
|
|
|
|
});
|
|
|
|
}
|
2017-11-01 12:30:39 +01:00
|
|
|
|
2017-10-25 15:17:16 +02:00
|
|
|
}
|