2017-10-25 15:17:16 +02:00
|
|
|
|
import { Component, OnInit, Input, Output, EventEmitter, ViewChild } from '@angular/core';
|
2017-09-28 17:05:46 +02:00
|
|
|
|
import {GoogleSignInSuccess} from 'angular-google-signin';
|
|
|
|
|
import { Router, ActivatedRoute } from '@angular/router';
|
|
|
|
|
import { ServerService } from '../../app/services/server.service';
|
|
|
|
|
import { Project } from '../entities/model/project';
|
2017-10-27 10:34:05 +02:00
|
|
|
|
import { Dmp } from '../entities/model/dmp';
|
2017-10-18 18:30:39 +02:00
|
|
|
|
import { Dataset } from '../entities/model/dataset';
|
2017-11-01 10:56:35 +01:00
|
|
|
|
//import { DataTable, DataTableTranslations, DataTableResource } from 'angular-4-data-table-bootstrap-4';
|
|
|
|
|
import {DataTable} from 'angular2-datatable';
|
2017-10-23 15:09:50 +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-10-23 18:16:04 +02:00
|
|
|
|
import { FormGroup, FormControl } from '@angular/forms'; //na dw an xreiazontai
|
|
|
|
|
import { NgForm } from '@angular/forms';
|
2017-10-25 15:17:16 +02:00
|
|
|
|
import { TokenService, TokenProvider } from '../services/token.service';
|
2017-09-28 17:05:46 +02:00
|
|
|
|
|
2017-11-01 11:47:30 +01:00
|
|
|
|
declare var $ :any;
|
|
|
|
|
|
2017-09-28 17:05:46 +02:00
|
|
|
|
@Component({
|
|
|
|
|
selector: 'projects',
|
2017-10-18 14:50:12 +02:00
|
|
|
|
templateUrl: 'project.html',
|
2017-11-01 11:47:30 +01:00
|
|
|
|
styleUrls: ['./project.css'],
|
2017-09-28 17:05:46 +02:00
|
|
|
|
providers: [ServerService]
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
export class ProjectsComponent implements OnInit{
|
2017-11-01 10:56:35 +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-09-28 17:05:46 +02:00
|
|
|
|
returnUrl: string;
|
2017-10-18 14:50:12 +02:00
|
|
|
|
@Input() projects: Project[];
|
|
|
|
|
@Input() projectCount = 0;
|
2017-10-23 15:09:50 +02:00
|
|
|
|
@Input() datasetDropDown:DropdownField;
|
2017-10-25 15:17:16 +02:00
|
|
|
|
//@Input() dataSetVisibe:boolean;
|
2017-10-23 15:09:50 +02:00
|
|
|
|
@Input() datasets: Dataset[];
|
2017-10-23 18:16:04 +02:00
|
|
|
|
project: any;
|
2017-10-24 11:49:02 +02:00
|
|
|
|
modalEditedRow: ModalComponent;
|
2017-10-25 15:17:16 +02:00
|
|
|
|
public item:any;
|
|
|
|
|
public show:boolean = false;
|
|
|
|
|
public dataSetVisibe:boolean = false;
|
2017-10-18 14:50:12 +02:00
|
|
|
|
@ViewChild(DataTable) projectsTable;
|
2017-10-23 15:09:50 +02:00
|
|
|
|
@ViewChild(DataTable) datasetsTable;
|
|
|
|
|
@ViewChild('isignOutBtn') isignOutBtn;
|
2017-09-28 17:05:46 +02:00
|
|
|
|
|
|
|
|
|
constructor(
|
|
|
|
|
private serverService: ServerService,
|
|
|
|
|
private route: ActivatedRoute,
|
2017-10-25 15:17:16 +02:00
|
|
|
|
private router: Router, private tokenService: TokenService){
|
2017-10-23 15:09:50 +02:00
|
|
|
|
this.datasetDropDown = new DropdownField();
|
|
|
|
|
this.datasetDropDown.options = [];
|
|
|
|
|
this.datasets = [];
|
2017-10-23 18:16:04 +02:00
|
|
|
|
this.project = {
|
|
|
|
|
label: '',
|
|
|
|
|
abbreviation:'',
|
|
|
|
|
reference:'',
|
|
|
|
|
uri:'',
|
2017-11-01 11:47:30 +01:00
|
|
|
|
definition:'',
|
|
|
|
|
endDate:'',
|
|
|
|
|
startDate:''
|
2017-10-23 18:16:04 +02:00
|
|
|
|
}
|
2017-09-28 17:05:46 +02:00
|
|
|
|
}
|
|
|
|
|
|
2017-10-17 09:38:04 +02:00
|
|
|
|
ngOnInit() {
|
2017-10-25 15:17:16 +02:00
|
|
|
|
|
|
|
|
|
gapi.load('auth2', function() {
|
|
|
|
|
gapi.auth2.init({});
|
|
|
|
|
});
|
2017-10-17 15:20:40 +02:00
|
|
|
|
//this.projects = this.serverService.getDummyProjects();
|
|
|
|
|
this.projects = [];
|
2017-10-23 18:16:04 +02:00
|
|
|
|
this.serverService.getProjectOfUer().subscribe( //getProjects()
|
2017-10-17 15:20:40 +02:00
|
|
|
|
response => {
|
2017-11-01 10:56:35 +01:00
|
|
|
|
this.tableData = response;
|
2017-10-23 15:09:50 +02:00
|
|
|
|
|
2017-10-17 15:20:40 +02:00
|
|
|
|
response.forEach(resp => {
|
|
|
|
|
let pr = new Project();
|
|
|
|
|
pr.id = resp.id;
|
2017-10-24 11:49:02 +02:00
|
|
|
|
pr.label = resp.label;
|
2017-10-18 14:50:12 +02:00
|
|
|
|
pr.abbreviation = resp.abbreviation;
|
|
|
|
|
pr.definition = resp.definition;
|
|
|
|
|
pr.uri = resp.uri;
|
2017-11-01 10:56:35 +01:00
|
|
|
|
this.projects.push(pr);
|
2017-10-23 15:09:50 +02:00
|
|
|
|
}
|
|
|
|
|
);
|
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
|
|
|
|
);
|
2017-10-17 15:20:40 +02:00
|
|
|
|
}
|
2017-09-28 17:05:46 +02:00
|
|
|
|
|
2017-10-23 15:09:50 +02:00
|
|
|
|
getDMPs(){
|
|
|
|
|
this.serverService.listDmpsLabelID().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.datasetDropDown.options.push(params);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
|
2017-10-25 15:17:16 +02:00
|
|
|
|
showDatasets(){debugger; //dmpId, event
|
|
|
|
|
//this.dataSetVisibe = true;
|
2017-10-23 15:09:50 +02:00
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
2017-11-01 11:47:30 +01:00
|
|
|
|
// editRow(item){
|
|
|
|
|
// this.show = true;
|
|
|
|
|
// this.item = item;
|
|
|
|
|
// }
|
2017-10-24 11:49:02 +02:00
|
|
|
|
|
|
|
|
|
SaveNewProject(){
|
2017-10-23 18:16:04 +02:00
|
|
|
|
console.log(this.project);
|
|
|
|
|
//this.http.post('http://someurl', JSON.stringify(this.project))
|
|
|
|
|
this.serverService.createProject(this.project)
|
|
|
|
|
.subscribe(
|
|
|
|
|
response =>{
|
|
|
|
|
console.log("response");
|
|
|
|
|
console.log(response);
|
|
|
|
|
}
|
|
|
|
|
);
|
2017-11-01 11:47:30 +01:00
|
|
|
|
$("#newEditProjectModal").modal("hide");
|
2017-10-23 18:16:04 +02:00
|
|
|
|
}
|
|
|
|
|
|
2017-11-01 11:47:30 +01:00
|
|
|
|
newProject(item){
|
|
|
|
|
this.project.label = "";
|
|
|
|
|
this.project.id = null;
|
|
|
|
|
this.project.abbreviation = "";
|
|
|
|
|
this.project.reference = "";
|
|
|
|
|
this.project.uri = "";
|
|
|
|
|
this.project.definition = "";
|
|
|
|
|
$("#newEditProjectModal").modal("show");
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
editRow(item, event){
|
|
|
|
|
if (event.toElement.id == "editDMP"){
|
|
|
|
|
this.project.label = item.label;
|
|
|
|
|
this.project.abbreviation = item.abbreviation;
|
|
|
|
|
this.project.reference = item.reference;
|
|
|
|
|
this.project.uri = item.uri;
|
|
|
|
|
this.project.definition = item.definition;
|
|
|
|
|
this.project.id = item.id;
|
|
|
|
|
$("#newEditProjectModal").modal("show");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
2017-10-18 14:50:12 +02:00
|
|
|
|
|
2017-10-25 15:17:16 +02:00
|
|
|
|
signOut() {
|
|
|
|
|
this.serverService.logOut();
|
|
|
|
|
}
|
|
|
|
|
|
2017-09-28 17:05:46 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|