2017-10-27 18:38:31 +02:00
|
|
|
import { Component, OnInit, Input, Output, EventEmitter, ViewChild } 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';
|
|
|
|
import { FormGroup, FormControl } from '@angular/forms'; //na dw an xreiazontai
|
|
|
|
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-11-14 15:06:00 +01:00
|
|
|
import {MenuItem} from 'primeng/primeng';
|
2017-10-25 15:17:16 +02:00
|
|
|
|
2017-10-27 16:08:10 +02:00
|
|
|
declare var $ :any;
|
|
|
|
|
2017-11-07 12:30:11 +01:00
|
|
|
import '../../assets/custom.js';
|
|
|
|
declare function simple_notifier(type: string, title: string, message:string): any;
|
|
|
|
|
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-10-25 15:17:16 +02:00
|
|
|
providers: [ServerService]
|
|
|
|
})
|
|
|
|
|
|
|
|
export class DmpComponent implements OnInit{
|
2017-10-31 18:59:27 +01:00
|
|
|
|
|
|
|
//whole dmp data model
|
|
|
|
tableData : any[] = new Array();
|
|
|
|
|
|
|
|
//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
|
|
|
|
showIDs : boolean = false;
|
2017-11-14 15:06:00 +01:00
|
|
|
|
|
|
|
|
2017-11-16 18:07:27 +01:00
|
|
|
dmp : any;
|
2017-11-14 15:06:00 +01:00
|
|
|
|
2017-10-25 15:17:16 +02:00
|
|
|
@Input() projectsDropDown:DropdownField;
|
2017-11-01 16:42:01 +01:00
|
|
|
@Input() statusDropDown: DropdownField;
|
2017-11-14 15:06:00 +01:00
|
|
|
|
2017-10-31 18:59:27 +01:00
|
|
|
@ViewChild(DatasetsComponent) datasetsComponent:DatasetsComponent;
|
|
|
|
|
2017-10-25 15:17:16 +02:00
|
|
|
|
|
|
|
constructor(
|
|
|
|
private serverService: ServerService,
|
|
|
|
private route: ActivatedRoute,
|
|
|
|
private router: Router){
|
2017-10-27 16:08:10 +02:00
|
|
|
this.projectsDropDown = new DropdownField();
|
2017-10-25 15:17:16 +02:00
|
|
|
this.projectsDropDown.options = [];
|
2017-11-01 16:42:01 +01:00
|
|
|
this.statusDropDown = new DropdownField();
|
2017-11-16 18:07:27 +01:00
|
|
|
this.statusDropDown.options= [{key:'', value:null},{key:'0', value:"Active"},{key:'1', value:"Inactive"}]
|
2017-10-31 18:59:27 +01:00
|
|
|
//this.projects = [];
|
2017-11-03 18:57:06 +01:00
|
|
|
|
2017-11-15 11:59:08 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
clearDmp() {
|
|
|
|
|
|
|
|
this.dmp = {
|
|
|
|
id: null,
|
|
|
|
label: '',
|
|
|
|
previous:'',
|
|
|
|
version:'',
|
|
|
|
profileData:'',
|
|
|
|
//project: '',
|
|
|
|
//profile:{}
|
|
|
|
}
|
|
|
|
|
2017-10-25 15:17:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
ngOnInit() {
|
2017-11-07 12:30:11 +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-11-07 12:30:11 +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-11-16 18:07:27 +01:00
|
|
|
|
2017-11-14 23:51:39 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
getDmps(muted? : boolean){
|
|
|
|
this.serverService.getDmpOfUser().subscribe(
|
|
|
|
response => {
|
|
|
|
this.tableData = response;
|
|
|
|
if(muted && muted!=true)
|
|
|
|
simple_notifier("success",null,"Refreshed DMPs");
|
|
|
|
},
|
|
|
|
(err: HttpErrorResponse) => {
|
|
|
|
simple_notifier("danger",null,"Could not refresh DMPs");
|
|
|
|
}
|
|
|
|
);
|
2017-10-25 15:17:16 +02:00
|
|
|
}
|
|
|
|
|
2017-11-14 23:51:39 +01:00
|
|
|
newDMP(){
|
2017-10-25 15:17:16 +02:00
|
|
|
|
2017-11-14 23:51:39 +01:00
|
|
|
this.dmp.project = {"id" : this.dmp.project};
|
|
|
|
this.dmp["version"] = 1;
|
|
|
|
|
|
|
|
this.serverService.createDmpForCurrentUser(this.dmp)
|
|
|
|
.subscribe(
|
|
|
|
response =>{
|
|
|
|
simple_notifier("success",null,"DMP created");
|
|
|
|
this.getDmps();
|
|
|
|
},
|
|
|
|
error => {
|
|
|
|
simple_notifier("danger",null,"Could not create the DMP");
|
|
|
|
}
|
|
|
|
);
|
|
|
|
$("#newDmpModal").modal("hide");
|
|
|
|
}
|
2017-11-01 12:30:39 +01:00
|
|
|
|
2017-11-14 23:51:39 +01:00
|
|
|
updateDMP(){
|
2017-10-25 15:17:16 +02:00
|
|
|
|
2017-11-14 23:51:39 +01:00
|
|
|
this.dmp.project = {"id":this.dmp.project};
|
2017-10-27 11:24:04 +02:00
|
|
|
|
2017-11-14 23:51:39 +01:00
|
|
|
this.serverService.updateDmp(this.dmp)
|
|
|
|
.subscribe(
|
|
|
|
response =>{
|
|
|
|
simple_notifier("success",null,"Edited the DMP");
|
|
|
|
this.getDmps();
|
|
|
|
},
|
|
|
|
error =>{
|
|
|
|
simple_notifier("danger",null,"Failed to edit the DMP");
|
|
|
|
}
|
|
|
|
);
|
|
|
|
$("#newDmpModal").modal("hide");
|
|
|
|
$("#newVersionDmpModal").modal("hide");
|
|
|
|
|
|
|
|
}
|
2017-10-31 18:59:27 +01:00
|
|
|
|
2017-11-14 23:51:39 +01:00
|
|
|
cloneDMP(dmp){
|
|
|
|
dmp = {"id": dmp.id, "label": dmp.label};
|
|
|
|
this.serverService.cloneDmp(dmp).subscribe(
|
|
|
|
response => {
|
|
|
|
simple_notifier("success",null,"Successfully cloned the DMP");
|
|
|
|
this.getDmps();
|
|
|
|
},
|
|
|
|
error => {
|
|
|
|
simple_notifier("danger",null,"Failed to clone the DMP");
|
|
|
|
}
|
|
|
|
);
|
|
|
|
$("#newVersionDmpModal").modal("hide");
|
|
|
|
}
|
2017-10-27 18:38:31 +02:00
|
|
|
|
2017-11-14 23:51:39 +01:00
|
|
|
SaveDmp(){
|
|
|
|
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-11-14 23:51:39 +01:00
|
|
|
editDmp(item){
|
2017-11-14 15:06:00 +01:00
|
|
|
this.dmp = item;
|
2017-10-31 18:59:27 +01:00
|
|
|
this.dmp.project = item.project.id;
|
2017-11-14 23:51:39 +01:00
|
|
|
$("#newDmpModal").modal("show");
|
2017-10-31 18:59:27 +01:00
|
|
|
}
|
2017-11-14 15:06:00 +01:00
|
|
|
|
2017-11-14 23:51:39 +01:00
|
|
|
editDmpVersion(item){
|
2017-11-14 15:06:00 +01:00
|
|
|
this.dmp = 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-11-15 11:59:08 +01:00
|
|
|
newDmpForm(item){
|
|
|
|
|
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-11-14 23:51:39 +01:00
|
|
|
markDMPForDelete(dmp){
|
|
|
|
this.dmp = dmp;
|
|
|
|
}
|
2017-11-07 14:07:25 +01:00
|
|
|
|
2017-11-14 23:51:39 +01:00
|
|
|
deleteDMP(confirmation){
|
|
|
|
if(confirmation==true)
|
|
|
|
this.deleteRow(this.dmp);
|
|
|
|
}
|
2017-11-06 14:11:03 +01:00
|
|
|
|
2017-11-14 23:51:39 +01:00
|
|
|
deleteRow(dmp){
|
2017-11-06 14:11:03 +01:00
|
|
|
|
2017-11-15 11:59:08 +01:00
|
|
|
this.dmp = {"id": this.dmp.id}; //only id is needed to delete
|
|
|
|
|
2017-11-14 23:51:39 +01:00
|
|
|
this.serverService.deleteDmp(dmp).subscribe(
|
|
|
|
response => {
|
|
|
|
simple_notifier("success",null,"Successfully deleted the DMP");
|
|
|
|
this.getDmps();
|
|
|
|
},
|
|
|
|
(err: HttpErrorResponse) => {
|
|
|
|
simple_notifier("danger",null,"Failed to delete the DMP");
|
|
|
|
}
|
|
|
|
);
|
2017-11-06 14:11:03 +01:00
|
|
|
|
2017-11-10 16:29:57 +01:00
|
|
|
}
|
|
|
|
|
2017-11-14 23:51:39 +01:00
|
|
|
clickFilters(element){
|
|
|
|
if(element.textContent == "More filters")
|
|
|
|
element.textContent = "Less Filters";
|
|
|
|
else
|
|
|
|
element.textContent = "More Filters";
|
|
|
|
}
|
|
|
|
|
|
|
|
SelectDMPStatus(dmp, event, oldValue){
|
|
|
|
console.log(dmp);
|
|
|
|
let cannotChangeStatus:boolean;
|
|
|
|
if(dmp.status == 2){
|
|
|
|
this.serverService.getDatasetForDmp({ "id": dmp.id }).subscribe(
|
|
|
|
response => {
|
|
|
|
response.forEach(dataset => {
|
|
|
|
if(dataset.status !==2 || dataset.status !==3){
|
|
|
|
cannotChangeStatus=true;
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
});
|
|
|
|
if(cannotChangeStatus == true){
|
|
|
|
dmp.status = 0;
|
|
|
|
$("#messageForChangingStatus").modal("show");
|
2017-11-10 16:29:57 +01:00
|
|
|
}
|
2017-11-14 23:51:39 +01:00
|
|
|
},
|
|
|
|
error => {
|
|
|
|
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-11-10 16:29:57 +01:00
|
|
|
}
|
2017-10-25 15:17:16 +02:00
|
|
|
|
2017-11-15 16:11:35 +01:00
|
|
|
showDatasetsOfDmp(item){
|
2017-11-15 23:55:49 +01:00
|
|
|
this.router.navigate(['/dataset'], { queryParams: { "dmpid":item.id , "label":item.label}});
|
2017-11-15 16:11:35 +01:00
|
|
|
}
|
|
|
|
|
2017-11-16 15:16:09 +01:00
|
|
|
viewDetailedDMP(dmp){
|
|
|
|
console.log(dmp)
|
|
|
|
this.router.navigate(['/dmp'], { queryParams: { "dmpid":dmp.id, "label":dmp.label }});
|
|
|
|
}
|
|
|
|
|
2017-11-15 16:11:35 +01:00
|
|
|
|
2017-11-01 12:30:39 +01:00
|
|
|
|
2017-10-25 15:17:16 +02:00
|
|
|
}
|