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-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
|
|
|
|
2017-11-01 12:30:39 +01:00
|
|
|
// Start ALTERNATIVE
|
2017-10-31 18:59:27 +01:00
|
|
|
//whole dmp data model
|
|
|
|
tableData : any[] = new Array();
|
|
|
|
|
|
|
|
//organisation editor data model
|
|
|
|
editingOrganisation: any = {};
|
|
|
|
organisationEditorForm : any;
|
|
|
|
|
|
|
|
//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";
|
|
|
|
|
|
|
|
//visibility rules for containers
|
|
|
|
tableVisible: boolean = true;
|
2017-11-01 16:07:51 +01:00
|
|
|
editorVisible: boolean = true;
|
2017-10-31 18:59:27 +01:00
|
|
|
|
|
|
|
|
|
|
|
// for tableIds
|
|
|
|
showIDs : boolean = false;
|
|
|
|
// END ALTERNATIVE
|
|
|
|
|
2017-10-25 15:17:16 +02:00
|
|
|
dmp:any;
|
2017-11-01 16:07:51 +01:00
|
|
|
@Input() dmpTableVisible: boolean;
|
2017-10-25 15:17:16 +02:00
|
|
|
@Input() dmpCount = 0;
|
|
|
|
@Input() projectsDropDown:DropdownField;
|
2017-10-27 16:08:10 +02:00
|
|
|
@Input() dataSetVisibe:boolean;
|
2017-11-01 16:42:01 +01:00
|
|
|
@Input() statusDropDown: DropdownField;
|
2017-11-07 15:03:12 +01:00
|
|
|
@Input() isSelected:boolean;
|
2017-11-01 12:30:39 +01:00
|
|
|
//@Input() projects: Project[];
|
2017-10-31 18:59:27 +01:00
|
|
|
dmpIdforDatasets: string;
|
|
|
|
dmpLabelforDatasets:string;
|
|
|
|
@ViewChild(DatasetsComponent) datasetsComponent:DatasetsComponent;
|
|
|
|
|
2017-10-25 15:17:16 +02:00
|
|
|
|
2017-10-31 18:59:27 +01:00
|
|
|
@ViewChild('isignOutBtn') isignOutBtn;
|
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-10 16:29:57 +01:00
|
|
|
this.statusDropDown.options= [{key:'', value:null},{key:'0', value:"Active"},{key:'1', value:"Inactive"}, {key:'2', value:"Submitted"}, {key:'3', value:"Cancel"}]
|
2017-10-31 18:59:27 +01:00
|
|
|
//this.projects = [];
|
2017-11-01 16:07:51 +01:00
|
|
|
this.dmpTableVisible = false;
|
2017-10-27 18:38:31 +02:00
|
|
|
this.dataSetVisibe = false;
|
2017-11-07 15:03:12 +01:00
|
|
|
this.isSelected=false;
|
2017-11-03 18:57:06 +01:00
|
|
|
|
2017-10-25 15:17:16 +02:00
|
|
|
this.dmp = {
|
2017-11-03 18:57:06 +01:00
|
|
|
id: null,
|
2017-10-25 15:17:16 +02:00
|
|
|
label: '',
|
2017-10-31 18:59:27 +01:00
|
|
|
previous:'',
|
2017-10-30 15:56:50 +01:00
|
|
|
version:'',
|
2017-11-01 12:59:57 +01:00
|
|
|
profileData:''
|
|
|
|
//profile:{}
|
2017-10-31 18:59:27 +01:00
|
|
|
}
|
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-01 12:30:39 +01:00
|
|
|
|
2017-11-07 12:35:31 +01:00
|
|
|
getDmps(muted? : boolean){
|
2017-10-31 18:59:27 +01:00
|
|
|
this.serverService.getDmpOfUser().subscribe(
|
2017-11-07 12:35:31 +01:00
|
|
|
response => {
|
2017-11-01 12:30:39 +01:00
|
|
|
this.tableData = response;
|
2017-11-07 12:35:31 +01:00
|
|
|
if(muted && muted!=true)
|
|
|
|
simple_notifier("success",null,"Refreshed DMPs");
|
2017-11-01 12:30:39 +01:00
|
|
|
},
|
|
|
|
(err: HttpErrorResponse) => {
|
2017-11-07 12:30:11 +01:00
|
|
|
simple_notifier("danger",null,"Could not refresh DMPs");
|
2017-11-01 12:30:39 +01:00
|
|
|
}
|
|
|
|
);
|
2017-10-25 15:17:16 +02:00
|
|
|
}
|
|
|
|
|
2017-11-01 12:30:39 +01:00
|
|
|
newDMP(){
|
2017-10-30 17:37:17 +01:00
|
|
|
console.log(this.dmp, this.dmp.projectsDropDownKey);
|
2017-10-27 11:24:04 +02:00
|
|
|
|
2017-11-01 12:30:39 +01:00
|
|
|
this.dmp.project = {"id" : this.dmp.project};
|
2017-10-27 11:24:04 +02:00
|
|
|
this.dmp["version"] = 1;
|
2017-11-01 12:59:57 +01:00
|
|
|
//this.dmp.profile = {};
|
2017-10-27 11:24:04 +02:00
|
|
|
|
2017-10-27 11:52:27 +02:00
|
|
|
this.serverService.createDmpForCurrentUser(this.dmp)
|
2017-10-25 15:17:16 +02:00
|
|
|
.subscribe(
|
|
|
|
response =>{
|
2017-11-07 12:30:11 +01:00
|
|
|
simple_notifier("success",null,"DMP created");
|
2017-11-01 12:30:39 +01:00
|
|
|
this.getDmps();
|
2017-11-07 12:30:11 +01:00
|
|
|
},
|
|
|
|
error => {
|
|
|
|
simple_notifier("danger",null,"Could not create the DMP");
|
2017-10-25 15:17:16 +02:00
|
|
|
}
|
|
|
|
);
|
2017-10-31 18:59:27 +01:00
|
|
|
$("#newDmpModal").modal("hide");
|
|
|
|
}
|
|
|
|
|
2017-11-01 12:30:39 +01:00
|
|
|
updateDMP(){
|
2017-10-27 18:38:31 +02:00
|
|
|
|
2017-10-31 18:59:27 +01:00
|
|
|
this.dmp.project = {"id":this.dmp.project};
|
2017-11-01 12:59:57 +01:00
|
|
|
|
2017-11-01 12:30:39 +01:00
|
|
|
this.serverService.updateDmp(this.dmp)
|
2017-10-31 18:59:27 +01:00
|
|
|
.subscribe(
|
|
|
|
response =>{
|
2017-11-07 12:30:11 +01:00
|
|
|
simple_notifier("success",null,"Edited the DMP");
|
2017-11-02 15:19:12 +01:00
|
|
|
this.getDmps();
|
2017-11-07 12:30:11 +01:00
|
|
|
},
|
|
|
|
error =>{
|
|
|
|
simple_notifier("danger",null,"Failed to edit the DMP");
|
2017-10-31 18:59:27 +01:00
|
|
|
}
|
|
|
|
);
|
2017-10-27 18:38:31 +02:00
|
|
|
$("#newDmpModal").modal("hide");
|
2017-11-01 10:18:51 +01:00
|
|
|
$("#newVersionDmpModal").modal("hide");
|
|
|
|
|
2017-10-25 15:17:16 +02:00
|
|
|
}
|
|
|
|
|
2017-11-07 10:45:19 +01:00
|
|
|
cloneDMP(dmp){
|
2017-11-07 17:05:54 +01:00
|
|
|
dmp = {"id": dmp.id, "label": dmp.label};
|
2017-11-07 10:45:19 +01:00
|
|
|
this.serverService.cloneDmp(dmp).subscribe(
|
|
|
|
response => {
|
2017-11-07 12:30:11 +01:00
|
|
|
simple_notifier("success",null,"Successfully cloned the DMP");
|
2017-11-07 10:45:19 +01:00
|
|
|
this.getDmps();
|
|
|
|
},
|
|
|
|
error => {
|
2017-11-07 12:30:11 +01:00
|
|
|
simple_notifier("danger",null,"Failed to clone the DMP");
|
2017-11-07 10:45:19 +01:00
|
|
|
}
|
|
|
|
);
|
|
|
|
$("#newVersionDmpModal").modal("hide");
|
|
|
|
}
|
|
|
|
|
2017-11-01 12:30:39 +01:00
|
|
|
SaveDmp(){
|
2017-10-31 18:59:27 +01:00
|
|
|
if (this.dmp.id == null)
|
2017-11-01 12:30:39 +01:00
|
|
|
this.newDMP();
|
2017-10-31 18:59:27 +01:00
|
|
|
else
|
2017-11-01 12:30:39 +01:00
|
|
|
this.updateDMP();
|
2017-10-31 18:59:27 +01:00
|
|
|
}
|
2017-10-25 15:17:16 +02:00
|
|
|
|
|
|
|
|
2017-10-31 18:59:27 +01:00
|
|
|
selectDmp(item){
|
|
|
|
this.dmpIdforDatasets = item.id;
|
|
|
|
this.dmpLabelforDatasets = item.label;
|
2017-10-27 18:38:31 +02:00
|
|
|
if(this.dataSetVisibe == false)
|
|
|
|
this.dataSetVisibe = true;
|
|
|
|
else
|
2017-10-31 18:59:27 +01:00
|
|
|
this.datasetsComponent.getDatasetForDmpMethod(item.id);
|
2017-10-27 16:08:10 +02:00
|
|
|
}
|
|
|
|
|
2017-11-08 09:59:07 +01:00
|
|
|
editRow(item, elementId){
|
2017-11-07 15:03:12 +01:00
|
|
|
this.isSelected = true;
|
2017-11-08 09:59:07 +01:00
|
|
|
if (elementId == "editDMP"){
|
2017-10-31 18:59:27 +01:00
|
|
|
this.dmp.label = item.label;
|
|
|
|
this.dmp.previous = item.previous;
|
|
|
|
this.dmp.version = item.version;
|
|
|
|
this.dmp.profile = item.profile;
|
|
|
|
this.dmp.profileData = item.profileData;
|
|
|
|
this.dmp.id = item.id;
|
|
|
|
this.dmp.project = item.project.id;
|
2017-11-07 10:19:31 +01:00
|
|
|
this.dmp.description = item.description;
|
|
|
|
this.dmp.status = item.status;
|
|
|
|
setTimeout(function() {
|
|
|
|
$("#newDmpModal").modal("show");
|
|
|
|
},0);
|
|
|
|
|
2017-10-31 18:59:27 +01:00
|
|
|
}
|
2017-11-08 09:59:07 +01:00
|
|
|
if(elementId == "changeVersionDMP"){
|
2017-10-31 18:59:27 +01:00
|
|
|
this.dmp.label = item.label;
|
|
|
|
this.dmp.previous = item.previous;
|
|
|
|
this.dmp.version = item.version;
|
|
|
|
this.dmp.profile = item.profile;
|
|
|
|
this.dmp.profileData = item.profileData;
|
|
|
|
this.dmp.id = item.id;
|
|
|
|
this.dmp.project = item.project.id;
|
2017-11-07 10:19:31 +01:00
|
|
|
this.dmp.description = item.description;
|
2017-10-31 18:59:27 +01:00
|
|
|
$("#newVersionDmpModal").modal("show");
|
|
|
|
}
|
|
|
|
|
2017-11-08 09:59:07 +01:00
|
|
|
if(elementId == "showDatasets"){
|
2017-10-31 18:59:27 +01:00
|
|
|
this.selectDmp(item);
|
|
|
|
|
|
|
|
}
|
2017-11-08 09:59:07 +01:00
|
|
|
|
|
|
|
return false; //return false will prevent browser from following the link
|
2017-10-31 18:59:27 +01:00
|
|
|
|
2017-10-30 15:56:50 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
newDmp(item){
|
|
|
|
this.dmp.label = "";
|
2017-11-01 10:18:51 +01:00
|
|
|
this.dmp.id = null;
|
2017-10-30 15:56:50 +01:00
|
|
|
this.dmp.version = "";
|
2017-10-31 11:19:16 +01:00
|
|
|
// this.dmp.profile = "";
|
2017-10-30 15:56:50 +01:00
|
|
|
this.dmp.profileData = "";
|
|
|
|
this.dmp.project = "";
|
2017-11-03 18:57:06 +01:00
|
|
|
|
2017-10-27 16:08:10 +02:00
|
|
|
$("#newDmpModal").modal("show");
|
|
|
|
}
|
|
|
|
|
2017-11-07 14:07:25 +01:00
|
|
|
markDMPForDelete(dmp){
|
|
|
|
this.dmp = dmp;
|
|
|
|
}
|
|
|
|
|
|
|
|
deleteDMP(confirmation){
|
|
|
|
if(confirmation==true)
|
|
|
|
this.deleteRow(this.dmp);
|
|
|
|
}
|
|
|
|
|
|
|
|
deleteRow(dmp){
|
2017-11-06 14:11:03 +01:00
|
|
|
|
|
|
|
this.serverService.deleteDmp(dmp).subscribe(
|
|
|
|
response => {
|
2017-11-07 12:30:11 +01:00
|
|
|
simple_notifier("success",null,"Successfully deleted the DMP");
|
|
|
|
this.getDmps();
|
2017-11-06 14:11:03 +01:00
|
|
|
},
|
|
|
|
(err: HttpErrorResponse) => {
|
2017-11-07 12:30:11 +01:00
|
|
|
simple_notifier("danger",null,"Failed to delete the DMP");
|
2017-11-06 14:11:03 +01:00
|
|
|
}
|
2017-11-07 12:30:11 +01:00
|
|
|
);
|
2017-11-06 14:11:03 +01:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2017-11-10 16:29:57 +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");
|
|
|
|
}
|
|
|
|
},
|
|
|
|
error => {
|
|
|
|
console.log("could not retrieve dataset for dpm: "+dmp.id);
|
|
|
|
}
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2017-11-07 15:03:12 +01:00
|
|
|
}
|
2017-10-25 15:17:16 +02:00
|
|
|
|
2017-11-01 12:30:39 +01:00
|
|
|
|
2017-10-25 15:17:16 +02:00
|
|
|
}
|