argos/dmp-frontend/src/app/projects/projects.component.ts

221 lines
5.7 KiB
TypeScript
Raw Normal View History

2017-11-06 17:25:23 +01:00
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';
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';
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-11-06 17:25:23 +01:00
import { DatepickerOptions } from 'ng2-datepicker';
import { StatusToString} from '../pipes/various/status-to-string';
2017-11-07 14:07:25 +01:00
import { ConfirmationComponent } from '../widgets/confirmation/confirmation.component';
2017-11-14 23:51:39 +01:00
import {MenuItem} from 'primeng/primeng';
import { BreadcrumbService } from '../services/breadcrumb.service';
2017-11-03 18:57:06 +01:00
import { ProjectTableFilterPipe } from '../pipes/project-table-filter.pipe';
2017-11-01 11:47:30 +01:00
declare var $ :any;
2017-11-07 13:15:50 +01:00
import '../../assets/custom.js';
declare function simple_notifier(type: string, title: string, message:string): any;
2017-11-06 17:25:23 +01: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'],
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;
2017-11-01 13:01:14 +01:00
public sortBy = "label";
2017-11-01 10:56:35 +01:00
public sortOrder = "asc";
//visibility rules for containers
tableVisible: boolean = true;
editorVisible: boolean = false;
// for tableIds
showIDs : boolean = false;
// END ALTERNATIVE
returnUrl: string;
2017-10-18 14:50:12 +02:00
@Input() projectCount = 0;
@Input() datasetDropDown:DropdownField;
@Input() statusDropDown: DropdownField;
//@Input() dataSetVisibe:boolean;
@Input() datasets: Dataset[];
2017-10-23 18:16:04 +02:00
project: any;
2017-10-24 11:49:02 +02:00
modalEditedRow: ModalComponent;
public item:any;
public show:boolean = false;
public dataSetVisibe:boolean = false;
2017-10-18 14:50:12 +02:00
@ViewChild(DataTable) projectsTable;
@ViewChild(DataTable) datasetsTable;
@ViewChild('isignOutBtn') isignOutBtn;
2017-11-06 17:25:23 +01:00
options: DatepickerOptions = {
minYear: 1900,
maxYear: 2050,
displayFormat: 'MMM D[,] YYYY',
barTitleFormat: 'MMMM YYYY',
firstCalendarDay: 0 // 0 - Sunday, 1 - Monday
};
2017-11-14 23:51:39 +01:00
//breadcrumbHome: MenuItem = {icon: 'fa fa-home'};
breadcrumbData: MenuItem[] = new Array<MenuItem>();
2017-11-06 17:25:23 +01:00
constructor(
private serverService: ServerService,
private route: ActivatedRoute,
2017-11-14 23:51:39 +01:00
private breadcrumbService : BreadcrumbService,
2017-11-06 17:25:23 +01:00
private router: Router) {
this.datasetDropDown = new DropdownField();
this.datasetDropDown.options = [];
this.datasets = [];
this.statusDropDown = new DropdownField();
this.statusDropDown.options= [{key:'0', value:"Active"},{key:'1', value:"Inactive"}]
//this.projects = [];
2017-11-06 17:25:23 +01:00
this.project = this.getEmptyProject();
}
2017-11-06 17:25:23 +01:00
ngAfterViewInit() {
}
getEmptyProject(){
return {
label: '',
abbreviation:'',
reference:'',
uri:'',
description:'',
2017-11-06 17:25:23 +01:00
enddate:'',
startdate:''
}
}
2017-10-17 09:38:04 +02:00
ngOnInit() {
2017-11-02 15:19:12 +01:00
this.getProjects();
2017-11-14 23:51:39 +01:00
this.breadcrumbService.clearAll();
this.breadcrumbData.push({label:'My Projects', routerLink:"/projects"});
this.breadcrumbService.setData(this.breadcrumbData);
2017-11-01 16:07:51 +01:00
}
2017-11-06 17:25:23 +01:00
2017-11-07 13:15:50 +01:00
getProjects(muted? : boolean){
2017-11-06 17:25:23 +01:00
this.serverService.getProjectsOfUser().subscribe(
2017-11-01 16:07:51 +01:00
response => {
this.tableData = response;
2017-11-07 13:15:50 +01:00
if(muted && muted!=true)
simple_notifier("success",null,"Updated projects table");
2017-11-06 17:25:23 +01:00
},
err => {
2017-11-07 13:15:50 +01:00
simple_notifier("danger",null,"Could not retrieve projects");
}
2017-11-01 16:07:51 +01: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-11-07 13:15:50 +01:00
},
error => {
}
);
}
)
}
2017-11-07 13:15:50 +01:00
showDatasets(){ //dmpId, event
//this.dataSetVisibe = true;
}
2017-10-24 11:49:02 +02:00
2017-11-06 17:25:23 +01:00
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(
2017-10-23 18:16:04 +02:00
response =>{
this.getProjects();
2017-11-07 13:15:50 +01:00
simple_notifier("success",null, (this.project.id == null) ? "Created" : "Updated" +" projects table");
},
error => {
simple_notifier("danger",null, "Could not "+ (this.project.id == null) ? "create" : "update" + " projects table");
2017-10-23 18:16:04 +02:00
}
);
2017-11-06 17:25:23 +01:00
2017-11-01 11:47:30 +01:00
$("#newEditProjectModal").modal("hide");
2017-10-23 18:16:04 +02:00
}
2017-11-07 14:10:56 +01:00
newProject(item){
this.project = this.getEmptyProject();
$("#newEditProjectModal").modal("show");
2017-11-01 11:47:30 +01:00
2017-11-07 14:10:56 +01:00
}
2017-11-06 17:25:23 +01:00
2017-11-07 14:10:56 +01:00
editRow(item, event){
2017-11-06 17:25:23 +01:00
this.project = item; //this will have id - that defines whether it's an update or not
2017-11-01 11:47:30 +01:00
$("#newEditProjectModal").modal("show");
2017-11-08 11:07:56 +01:00
return false;
2017-11-01 11:47:30 +01:00
}
2017-10-18 14:50:12 +02:00
2017-11-07 14:10:56 +01:00
/*
markProjectForDelete(project){
this.project = project;
}
deleteProject(confirmation){
if(confirmation==true)
this.deleteRow(this.project);
}
*/
}