190 lines
4.3 KiB
TypeScript
190 lines
4.3 KiB
TypeScript
import { Component, OnInit, Input, Output, EventEmitter, ViewChild } from '@angular/core';
|
|
import {Observable} from 'rxjs/Observable';
|
|
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';
|
|
import { Dmp } from '../entities/model/dmp';
|
|
import { Dataset } from '../entities/model/dataset';
|
|
//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 { DatepickerOptions } from 'ng2-datepicker';
|
|
import { StatusToString} from '../pipes/various/status-to-string';
|
|
|
|
import { ProjectTableFilterPipe } from '../pipes/project-table-filter.pipe';
|
|
|
|
|
|
declare var $ :any;
|
|
|
|
|
|
|
|
@Component({
|
|
selector: 'projects',
|
|
templateUrl: 'project.html',
|
|
styleUrls: ['./project.css'],
|
|
providers: [ServerService]
|
|
})
|
|
|
|
export class ProjectsComponent 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
|
|
|
|
returnUrl: string;
|
|
@Input() projectCount = 0;
|
|
@Input() datasetDropDown:DropdownField;
|
|
//@Input() dataSetVisibe:boolean;
|
|
@Input() datasets: Dataset[];
|
|
project: any;
|
|
modalEditedRow: ModalComponent;
|
|
public item:any;
|
|
public show:boolean = false;
|
|
public dataSetVisibe:boolean = false;
|
|
@ViewChild(DataTable) projectsTable;
|
|
@ViewChild(DataTable) datasetsTable;
|
|
@ViewChild('isignOutBtn') isignOutBtn;
|
|
|
|
|
|
options: DatepickerOptions = {
|
|
minYear: 1900,
|
|
maxYear: 2050,
|
|
displayFormat: 'MMM D[,] YYYY',
|
|
barTitleFormat: 'MMMM YYYY',
|
|
firstCalendarDay: 0 // 0 - Sunday, 1 - Monday
|
|
};
|
|
|
|
|
|
|
|
constructor(
|
|
private serverService: ServerService,
|
|
private route: ActivatedRoute,
|
|
private router: Router) {
|
|
this.datasetDropDown = new DropdownField();
|
|
this.datasetDropDown.options = [];
|
|
this.datasets = [];
|
|
this.project = this.getEmptyProject();
|
|
}
|
|
|
|
ngAfterViewInit() {
|
|
|
|
}
|
|
|
|
getEmptyProject(){
|
|
return {
|
|
label: '',
|
|
abbreviation:'',
|
|
reference:'',
|
|
uri:'',
|
|
definition:'',
|
|
enddate:'',
|
|
startdate:''
|
|
}
|
|
}
|
|
|
|
|
|
ngOnInit() {
|
|
|
|
this.getProjects();
|
|
}
|
|
|
|
|
|
getProjects(){
|
|
this.serverService.getProjectsOfUser().subscribe(
|
|
response => {
|
|
this.tableData = response;
|
|
console.log(this.tableData)
|
|
},
|
|
err => {
|
|
|
|
}
|
|
);
|
|
}
|
|
|
|
|
|
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);
|
|
});
|
|
|
|
}
|
|
)
|
|
}
|
|
|
|
showDatasets(){debugger; //dmpId, event
|
|
//this.dataSetVisibe = true;
|
|
|
|
}
|
|
|
|
|
|
SaveProject(){
|
|
|
|
let action : Observable<any>;
|
|
|
|
if(this.project.id == null) //means it's a new one
|
|
action = this.serverService.createProject(this.project);
|
|
else
|
|
action = this.serverService.updateProject(this.project);
|
|
action.subscribe(
|
|
response =>{
|
|
console.log("response");
|
|
console.log(response);
|
|
}
|
|
);
|
|
|
|
$("#newEditProjectModal").modal("hide");
|
|
}
|
|
|
|
newProject(item){
|
|
this.project = this.getEmptyProject();
|
|
$("#newEditProjectModal").modal("show");
|
|
|
|
}
|
|
|
|
editRow(item, event){
|
|
|
|
this.project = item; //this will have id - that defines whether it's an update or not
|
|
$("#newEditProjectModal").modal("show");
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|