272 lines
7.4 KiB
TypeScript
272 lines
7.4 KiB
TypeScript
import { Component, OnInit, Input, Output, EventEmitter, ViewChild } from '@angular/core';
|
||
import {GoogleSignInSuccess} from 'angular-google-signin';
|
||
import { Router, ActivatedRoute } from '@angular/router';
|
||
import { ServerService } from '../../app/services/server.service';
|
||
import { Dmp } from '../entities/model/dmp';
|
||
import { Dataset } from '../entities/model/dataset';
|
||
import { Project } from '../entities/model/project';
|
||
//import { DataTable, DataTableTranslations, DataTableResource } from 'angular-4-data-table-bootstrap-4';
|
||
import {DataTable} from 'angular2-datatable';
|
||
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';
|
||
import { DatasetsComponent } from '../datasets/dataset.component';
|
||
|
||
declare var $ :any;
|
||
|
||
@Component({
|
||
selector: 'dmps',
|
||
templateUrl: 'dmps.html',
|
||
styleUrls: ['./dmp.component.css'],
|
||
providers: [ServerService]
|
||
})
|
||
|
||
export class DmpComponent implements OnInit{
|
||
|
||
// 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 = "label";
|
||
public sortOrder = "asc";
|
||
|
||
//visibility rules for containers
|
||
tableVisible: boolean = true;
|
||
editorVisible: boolean = false;
|
||
|
||
|
||
// for tableIds
|
||
showIDs : boolean = false;
|
||
// END ALTERNATIVE
|
||
|
||
|
||
|
||
|
||
@Input() dmps: Dmp[];
|
||
dmp:any;
|
||
@Input() dmpCount = 0;
|
||
@Input() projectsDropDown:DropdownField;
|
||
@Input() dataSetVisibe:boolean;
|
||
@Input() projects: Project[];
|
||
dmpIdforDatasets: string;
|
||
dmpLabelforDatasets:string;
|
||
@ViewChild(DatasetsComponent) datasetsComponent:DatasetsComponent;
|
||
/*dmpResource :DataTableResource<Dmp>;
|
||
|
||
@ViewChild(DataTable) dmpsTable;
|
||
@ViewChild(DataTable) datasetsTable;
|
||
|
||
*/
|
||
|
||
@ViewChild('isignOutBtn') isignOutBtn;
|
||
constructor(
|
||
private serverService: ServerService,
|
||
private route: ActivatedRoute,
|
||
private router: Router){
|
||
this.projectsDropDown = new DropdownField();
|
||
this.projectsDropDown.options = [];
|
||
//this.projects = [];
|
||
this.dataSetVisibe = false;
|
||
this.dmp = {
|
||
id:null,
|
||
label: '',
|
||
previous:'',
|
||
version:'',
|
||
profileData:'',
|
||
profile:''
|
||
}
|
||
}
|
||
|
||
ngOnInit() {
|
||
//this.projects = this.serverService.getDummyProjects();
|
||
gapi.load('auth2', function() {
|
||
gapi.auth2.init({});
|
||
});
|
||
this.dmps = [];
|
||
this.serverService.getDmpOfUser().subscribe(
|
||
response => {
|
||
this.tableData = response;
|
||
console.log(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;
|
||
// 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);
|
||
}
|
||
);
|
||
(err: HttpErrorResponse) => {debugger;
|
||
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}`);
|
||
}
|
||
}
|
||
});
|
||
|
||
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);
|
||
});
|
||
|
||
}
|
||
)
|
||
}
|
||
|
||
|
||
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);
|
||
}
|
||
);
|
||
});
|
||
}
|
||
|
||
SaveNewDmp(){
|
||
console.log(this.dmp, this.dmp.projectsDropDownKey);
|
||
//this.http.post('http://someurl', JSON.stringify(this.project))
|
||
|
||
this.dmp.project = {"id":this.dmp.project};
|
||
this.dmp["version"] = 1;
|
||
|
||
this.serverService.createDmpForCurrentUser(this.dmp)
|
||
.subscribe(
|
||
response =>{
|
||
console.log("response");
|
||
console.log(response);
|
||
this.dmps = [];
|
||
this.CallDmps();
|
||
}
|
||
);
|
||
$("#newDmpModal").modal("hide");
|
||
}
|
||
|
||
SaveUpdatesDmp(){
|
||
console.log(this.dmp, this.dmp.projectsDropDownKey);
|
||
//this.http.post('http://someurl', JSON.stringify(this.project))
|
||
|
||
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();
|
||
}
|
||
);
|
||
$("#newDmpModal").modal("hide");
|
||
$("#newVersionDmpModal").modal("hide");
|
||
|
||
}
|
||
|
||
SaveDmp(){ debugger;
|
||
if (this.dmp.id == null)
|
||
this.SaveNewDmp();
|
||
else
|
||
this.SaveUpdatesDmp();
|
||
}
|
||
|
||
signOut() {
|
||
this.serverService.logOut();
|
||
}
|
||
|
||
selectDmp(item){
|
||
this.dmpIdforDatasets = item.id;
|
||
this.dmpLabelforDatasets = item.label;
|
||
if(this.dataSetVisibe == false)
|
||
this.dataSetVisibe = true;
|
||
else
|
||
this.datasetsComponent.getDatasetForDmpMethod(item.id);
|
||
}
|
||
|
||
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);
|
||
|
||
}
|
||
|
||
}
|
||
|
||
newDmp(item){
|
||
this.dmp.label = "";
|
||
this.dmp.id = null;
|
||
this.dmp.version = "";
|
||
// this.dmp.profile = "";
|
||
this.dmp.profileData = "";
|
||
this.dmp.project = "";
|
||
$("#newDmpModal").modal("show");
|
||
}
|
||
|
||
refreshTable(){
|
||
this.CallDmps();
|
||
}
|
||
|
||
}
|