2017-10-27 18:38:31 +02:00
|
|
|
|
import { Component, OnInit, Input, Output, EventEmitter, ViewChild } from '@angular/core';
|
2017-10-25 15:17:16 +02:00
|
|
|
|
import {GoogleSignInSuccess} from 'angular-google-signin';
|
|
|
|
|
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-10-31 18:59:27 +01:00
|
|
|
|
//import { DataTable, DataTableTranslations, DataTableResource } from 'angular-4-data-table-bootstrap-4';
|
|
|
|
|
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-10-25 15:17:16 +02:00
|
|
|
|
|
2017-10-27 16:08:10 +02:00
|
|
|
|
declare var $ :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
|
|
|
|
|
|
|
|
|
// 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 rowsOnPage = 10;
|
|
|
|
|
//public sortBy = "email";
|
|
|
|
|
public sortOrder = "asc";
|
|
|
|
|
|
|
|
|
|
//visibility rules for containers
|
|
|
|
|
tableVisible: boolean = true;
|
|
|
|
|
editorVisible: boolean = false;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// for tableIds
|
|
|
|
|
showIDs : boolean = false;
|
|
|
|
|
// END ALTERNATIVE
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2017-10-25 15:17:16 +02:00
|
|
|
|
@Input() dmps: Dmp[];
|
|
|
|
|
dmp:any;
|
|
|
|
|
@Input() dmpCount = 0;
|
|
|
|
|
@Input() projectsDropDown:DropdownField;
|
2017-10-27 16:08:10 +02:00
|
|
|
|
@Input() dataSetVisibe:boolean;
|
2017-10-31 18:59:27 +01:00
|
|
|
|
@Input() projects: Project[];
|
|
|
|
|
dmpIdforDatasets: string;
|
|
|
|
|
dmpLabelforDatasets:string;
|
|
|
|
|
@ViewChild(DatasetsComponent) datasetsComponent:DatasetsComponent;
|
|
|
|
|
/*dmpResource :DataTableResource<Dmp>;
|
|
|
|
|
|
2017-10-25 15:17:16 +02:00
|
|
|
|
@ViewChild(DataTable) dmpsTable;
|
|
|
|
|
@ViewChild(DataTable) datasetsTable;
|
2017-10-31 18:59:27 +01:00
|
|
|
|
|
|
|
|
|
*/
|
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-10-31 18:59:27 +01:00
|
|
|
|
//this.projects = [];
|
2017-10-27 18:38:31 +02:00
|
|
|
|
this.dataSetVisibe = false;
|
2017-10-25 15:17:16 +02:00
|
|
|
|
this.dmp = {
|
2017-10-31 18:59:27 +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:'',
|
|
|
|
|
profileData:'',
|
2017-10-31 18:59:27 +01:00
|
|
|
|
profile:''
|
|
|
|
|
}
|
2017-10-25 15:17:16 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ngOnInit() {
|
|
|
|
|
//this.projects = this.serverService.getDummyProjects();
|
|
|
|
|
gapi.load('auth2', function() {
|
|
|
|
|
gapi.auth2.init({});
|
|
|
|
|
});
|
|
|
|
|
this.dmps = [];
|
|
|
|
|
this.serverService.getDmpOfUser().subscribe(
|
2017-10-31 18:59:27 +01:00
|
|
|
|
response => {
|
|
|
|
|
this.tableData = response;
|
2017-10-31 11:19:16 +01:00
|
|
|
|
console.log(response);
|
2017-10-25 15:17:16 +02:00
|
|
|
|
response.forEach(resp => {
|
2017-10-31 18:59:27 +01:00
|
|
|
|
// let dmp = new Dmp();
|
|
|
|
|
// dmp.id = resp.id;
|
|
|
|
|
// dmp.label = resp.label;
|
|
|
|
|
// dmp.version = resp.version;
|
|
|
|
|
// dmp.dataset = resp.dataset;
|
|
|
|
|
// dmp.projectLabel = resp.project.label;
|
|
|
|
|
// dmp.projectid = resp.project.id;
|
|
|
|
|
// dmp.previous = resp.previous;
|
|
|
|
|
// dmp.profile = resp.profile;
|
|
|
|
|
// dmp.profileData = resp.profileData;
|
|
|
|
|
// this.dmps.push(dmp);
|
|
|
|
|
// var params = {limit:8,offset:0, sortAsc:false}
|
|
|
|
|
//this.afterLoad();
|
|
|
|
|
//this.dmpResource.query(params).then(dmps => this.dmps = dmps);
|
2017-10-25 15:17:16 +02:00
|
|
|
|
}
|
|
|
|
|
);
|
2017-10-30 17:37:17 +01:00
|
|
|
|
(err: HttpErrorResponse) => {debugger;
|
2017-10-30 15:56:50 +01:00
|
|
|
|
if (err.error instanceof Error) {
|
|
|
|
|
// A client-side or network error occurred. Handle it accordingly.
|
|
|
|
|
console.log('An error occurred:', err.error.message);
|
|
|
|
|
} else {
|
|
|
|
|
// The backend returned an unsuccessful response code.
|
|
|
|
|
// The response body may contain clues as to what went wrong,
|
|
|
|
|
if(err.status == 401){
|
|
|
|
|
this.isignOutBtn.nativeElement.click();
|
|
|
|
|
}
|
|
|
|
|
console.log(`Backend returned code ${err.status}, body was: ${err.error}`);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
});
|
2017-10-25 15:17:16 +02:00
|
|
|
|
|
|
|
|
|
this.serverService.getAllProjects().subscribe(
|
|
|
|
|
response => {
|
|
|
|
|
console.log("response");
|
|
|
|
|
console.log(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-10-31 18:59:27 +01:00
|
|
|
|
CallDmps(){
|
|
|
|
|
this.serverService.getDmpOfUser().subscribe(
|
|
|
|
|
response => {
|
|
|
|
|
response.forEach(resp => {
|
|
|
|
|
let dmp = new Dmp();
|
|
|
|
|
dmp.id = resp.id;
|
|
|
|
|
dmp.label = resp.label;
|
|
|
|
|
dmp.version = resp.version;
|
|
|
|
|
dmp.dataset = resp.dataset;
|
|
|
|
|
dmp.projectLabel = resp.project.label;
|
|
|
|
|
this.dmps.push(dmp);
|
|
|
|
|
var params = {limit:8,offset:0, sortAsc:false}
|
|
|
|
|
//this.afterLoad();
|
|
|
|
|
//this.dmpResource.query(params).then(dmps => this.dmps = dmps);
|
|
|
|
|
}
|
|
|
|
|
);
|
|
|
|
|
});
|
2017-10-25 15:17:16 +02:00
|
|
|
|
}
|
|
|
|
|
|
2017-10-25 17:25:27 +02:00
|
|
|
|
SaveNewDmp(){
|
2017-10-30 17:37:17 +01:00
|
|
|
|
console.log(this.dmp, this.dmp.projectsDropDownKey);
|
2017-10-25 15:17:16 +02:00
|
|
|
|
//this.http.post('http://someurl', JSON.stringify(this.project))
|
2017-10-27 11:24:04 +02:00
|
|
|
|
|
|
|
|
|
this.dmp.project = {"id":this.dmp.project};
|
|
|
|
|
this.dmp["version"] = 1;
|
|
|
|
|
|
2017-10-27 11:52:27 +02:00
|
|
|
|
this.serverService.createDmpForCurrentUser(this.dmp)
|
2017-10-25 15:17:16 +02:00
|
|
|
|
.subscribe(
|
|
|
|
|
response =>{
|
|
|
|
|
console.log("response");
|
2017-10-27 18:38:31 +02:00
|
|
|
|
console.log(response);
|
|
|
|
|
this.dmps = [];
|
2017-10-31 18:59:27 +01:00
|
|
|
|
this.CallDmps();
|
2017-10-25 15:17:16 +02:00
|
|
|
|
}
|
|
|
|
|
);
|
2017-10-31 18:59:27 +01:00
|
|
|
|
$("#newDmpModal").modal("hide");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
SaveUpdatesDmp(){
|
|
|
|
|
console.log(this.dmp, this.dmp.projectsDropDownKey);
|
|
|
|
|
//this.http.post('http://someurl', JSON.stringify(this.project))
|
2017-10-27 18:38:31 +02:00
|
|
|
|
|
2017-10-31 18:59:27 +01:00
|
|
|
|
this.dmp.project = {"id":this.dmp.project};
|
|
|
|
|
this.dmp["version"] = 1;
|
|
|
|
|
|
|
|
|
|
this.serverService.updateDmpForCurrentUser(this.dmp)
|
|
|
|
|
.subscribe(
|
|
|
|
|
response =>{
|
|
|
|
|
console.log("response");
|
|
|
|
|
console.log(response);
|
|
|
|
|
this.dmps = [];
|
|
|
|
|
this.CallDmps();
|
|
|
|
|
}
|
|
|
|
|
);
|
2017-10-27 18:38:31 +02:00
|
|
|
|
$("#newDmpModal").modal("hide");
|
2017-10-25 15:17:16 +02:00
|
|
|
|
}
|
|
|
|
|
|
2017-10-31 18:59:27 +01:00
|
|
|
|
SaveDmp(){ debugger;
|
|
|
|
|
if (this.dmp.id == null)
|
|
|
|
|
this.SaveNewDmp();
|
|
|
|
|
else
|
|
|
|
|
this.SaveUpdatesDmp();
|
|
|
|
|
}
|
2017-10-25 15:17:16 +02:00
|
|
|
|
|
|
|
|
|
signOut() {
|
|
|
|
|
this.serverService.logOut();
|
|
|
|
|
}
|
|
|
|
|
|
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-10-31 18:59:27 +01:00
|
|
|
|
editRow(item, event){
|
|
|
|
|
if (event.toElement.id == "editDMP"){
|
|
|
|
|
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;
|
|
|
|
|
$("#newDmpModal").modal("show");
|
|
|
|
|
}
|
|
|
|
|
if(event.toElement.id == "changeVersionDMP"){
|
|
|
|
|
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;
|
|
|
|
|
$("#newVersionDmpModal").modal("show");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if(event.toElement.id == "showDatasets"){
|
|
|
|
|
this.selectDmp(item);
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
2017-10-30 15:56:50 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
newDmp(item){
|
|
|
|
|
this.dmp.label = "";
|
2017-10-31 11:19:16 +01:00
|
|
|
|
//this.dmp.previous = "";
|
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-10-27 16:08:10 +02:00
|
|
|
|
$("#newDmpModal").modal("show");
|
|
|
|
|
}
|
|
|
|
|
|
2017-10-31 18:59:27 +01:00
|
|
|
|
refreshTable(){
|
|
|
|
|
this.CallDmps();
|
|
|
|
|
}
|
2017-10-25 15:17:16 +02:00
|
|
|
|
|
|
|
|
|
}
|