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';
|
|
|
|
|
import { DataTable, DataTableTranslations, DataTableResource } from 'angular-4-data-table-bootstrap-4';
|
|
|
|
|
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',
|
|
|
|
|
providers: [ServerService]
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
export class DmpComponent implements OnInit{
|
|
|
|
|
@Input() dmps: Dmp[];
|
|
|
|
|
dmp:any;
|
|
|
|
|
dmpResource :DataTableResource<Dmp>;
|
2017-10-27 16:08:10 +02:00
|
|
|
|
dmpIdforDatasets: string;
|
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-10-25 15:17:16 +02:00
|
|
|
|
@Input() projects: Project[];
|
|
|
|
|
|
2017-10-27 18:38:31 +02:00
|
|
|
|
|
2017-10-25 15:17:16 +02:00
|
|
|
|
@ViewChild(DataTable) dmpsTable;
|
|
|
|
|
@ViewChild(DataTable) datasetsTable;
|
2017-10-27 18:38:31 +02:00
|
|
|
|
@ViewChild(DatasetsComponent) datasetsComponent:DatasetsComponent;
|
2017-10-25 15:17:16 +02:00
|
|
|
|
@ViewChild('isignOutBtn') isignOutBtn;
|
|
|
|
|
|
|
|
|
|
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 = [];
|
|
|
|
|
this.projects = [];
|
2017-10-27 18:38:31 +02:00
|
|
|
|
this.dataSetVisibe = false;
|
2017-10-25 15:17:16 +02:00
|
|
|
|
this.dmp = {
|
|
|
|
|
label: '',
|
|
|
|
|
abbreviation:'',
|
|
|
|
|
reference:'',
|
|
|
|
|
uri:'',
|
|
|
|
|
definition:''
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ngOnInit() {
|
|
|
|
|
//this.projects = this.serverService.getDummyProjects();
|
|
|
|
|
gapi.load('auth2', function() {
|
|
|
|
|
gapi.auth2.init({});
|
|
|
|
|
});
|
|
|
|
|
this.dmps = [];
|
|
|
|
|
this.serverService.getDmpOfUser().subscribe(
|
2017-10-25 17:25:27 +02:00
|
|
|
|
response => {
|
2017-10-27 16:08:10 +02:00
|
|
|
|
console.log(response);
|
2017-10-25 15:17:16 +02:00
|
|
|
|
response.forEach(resp => {
|
2017-10-27 16:08:10 +02: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;
|
|
|
|
|
this.dmps.push(dmp);
|
2017-10-25 15:17:16 +02:00
|
|
|
|
var params = {limit:8,offset:0, sortAsc:false}
|
|
|
|
|
this.afterLoad();
|
|
|
|
|
this.dmpResource.query(params).then(dmps => this.dmps = dmps);
|
|
|
|
|
}
|
|
|
|
|
);
|
2017-10-27 10:40:44 +02:00
|
|
|
|
}
|
|
|
|
|
// (err: HttpErrorResponse) => {
|
|
|
|
|
// 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);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
reloadDmps(params) {
|
|
|
|
|
this.dmpResource = new DataTableResource(this.dmps);
|
|
|
|
|
this.dmpResource.query(params).then(projects => this.dmps = projects);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
afterLoad(){
|
|
|
|
|
this.dmpResource = new DataTableResource(this.dmps);
|
|
|
|
|
this.dmpResource.count().then(count => this.dmpCount = count);
|
|
|
|
|
}
|
|
|
|
|
|
2017-10-27 12:00:46 +02:00
|
|
|
|
filterGrid() {
|
2017-10-25 15:17:16 +02:00
|
|
|
|
var input, filter, table, tr, td, i;
|
|
|
|
|
input = document.getElementById("myInput");
|
|
|
|
|
filter = input.value.toUpperCase();
|
2017-10-27 18:38:31 +02:00
|
|
|
|
table = document.getElementById("dmps-grid");
|
2017-10-25 15:17:16 +02:00
|
|
|
|
tr = table.getElementsByTagName("tr");
|
|
|
|
|
for (i = 0; i < tr.length; i++) {
|
2017-10-27 18:38:31 +02:00
|
|
|
|
td = tr[i].getElementsByTagName("td")[4];
|
2017-10-25 15:17:16 +02:00
|
|
|
|
if (td) {
|
|
|
|
|
if (td.innerText.toUpperCase().indexOf(filter) > -1) {
|
|
|
|
|
tr[i].style.display = "";
|
|
|
|
|
} else {
|
|
|
|
|
tr[i].style.display = "none";
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2017-10-25 17:25:27 +02:00
|
|
|
|
SaveNewDmp(){
|
2017-10-27 10:56:37 +02:00
|
|
|
|
console.log(this.dmp, this.dmp.projectsDropDownKey); debugger;
|
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 = [];
|
|
|
|
|
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-27 18:38:31 +02:00
|
|
|
|
|
|
|
|
|
$("#newDmpModal").modal("hide");
|
2017-10-25 15:17:16 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// special params:
|
|
|
|
|
translations = <DataTableTranslations>{
|
|
|
|
|
indexColumn: 'Index column',
|
|
|
|
|
expandColumn: 'Expand column',
|
|
|
|
|
selectColumn: 'Select column',
|
|
|
|
|
paginationLimit: 'Max results',
|
|
|
|
|
paginationRange: 'Result range'
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
signOut() {
|
|
|
|
|
this.serverService.logOut();
|
|
|
|
|
}
|
|
|
|
|
|
2017-10-27 18:38:31 +02:00
|
|
|
|
selectDmp(rowEvent){debugger;
|
2017-10-27 16:08:10 +02:00
|
|
|
|
this.dmpIdforDatasets = rowEvent.row.item.id;
|
2017-10-27 18:38:31 +02:00
|
|
|
|
if(this.dataSetVisibe == false)
|
|
|
|
|
this.dataSetVisibe = true;
|
|
|
|
|
else
|
|
|
|
|
this.datasetsComponent.getDatasetForDmpMethod(rowEvent.row.item.id);
|
2017-10-27 16:08:10 +02:00
|
|
|
|
}
|
|
|
|
|
|
2017-10-27 18:38:31 +02:00
|
|
|
|
editRow(item){debugger;
|
|
|
|
|
this.dmp.label = item.label;
|
|
|
|
|
this.dmp.abbreviation = item.abbreviation;
|
|
|
|
|
this.dmp.uri = item.uri;
|
|
|
|
|
this.dmp.id = item.id;
|
|
|
|
|
this.dmp.project = item.project;
|
2017-10-27 16:08:10 +02:00
|
|
|
|
$("#newDmpModal").modal("show");
|
|
|
|
|
}
|
|
|
|
|
|
2017-10-25 15:17:16 +02:00
|
|
|
|
|
|
|
|
|
}
|