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

160 lines
4.8 KiB
TypeScript
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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 { 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';
@Component({
selector: 'dmps',
templateUrl: 'dmps.html',
providers: [ServerService]
})
export class DmpComponent implements OnInit{
@Input() dmps: Dmp[];
dmp:any;
dmpResource :DataTableResource<Dmp>;
@Input() dmpCount = 0;
@Input() projectsDropDown:DropdownField;
//@Input() dataSetVisibe:boolean;
@Input() projects: Project[];
@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.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(
response => {
response.forEach(resp => {
let pr = new Dmp();
pr.id = resp.id;
pr.id = resp.label;
pr.name = resp.abbreviation;
pr.dataset = resp.definition;
this.dmps.push(pr);
var params = {limit:8,offset:0, sortAsc:false}
this.afterLoad();
this.dmpResource.query(params).then(dmps => this.dmps = dmps);
}
);
}
// (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}`);
// }
// }
);
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);
}
myFunction() {
var input, filter, table, tr, td, i;
input = document.getElementById("myInput");
filter = input.value.toUpperCase();
table = document.getElementById("projects-grid");
tr = table.getElementsByTagName("tr");
for (i = 0; i < tr.length; i++) {
td = tr[i].getElementsByTagName("td")[3];
if (td) {
if (td.innerText.toUpperCase().indexOf(filter) > -1) {
tr[i].style.display = "";
} else {
tr[i].style.display = "none";
}
}
}
}
SaveNewDmp(){
console.log(this.dmp, this.dmp.projectsDropDownKey);
//this.http.post('http://someurl', JSON.stringify(this.project))
this.serverService.createDmpForProject(this.dmp)
.subscribe(
response =>{
console.log("response");
console.log(response);
}
);
}
// special params:
translations = <DataTableTranslations>{
indexColumn: 'Index column',
expandColumn: 'Expand column',
selectColumn: 'Select column',
paginationLimit: 'Max results',
paginationRange: 'Result range'
};
signOut() {
    this.serverService.logOut();
}
}