import {Component, ViewChild, Input} from '@angular/core'; import {Location} from '@angular/common'; import {Observable} from 'rxjs/Observable'; import {ActivatedRoute, Params} from '@angular/router'; import {ClaimsByTokenService} from './claimsByToken.service'; import {ModalSelect} from '../../utils/modal/selectModal.component'; import {ModalLoading} from '../../utils/modal/loading.component'; import {Session} from '../../login/utils/helper.class'; import {RouterHelper} from '../../utils/routerHelper.class'; import { Meta} from '../../sharedComponents/metaService'; import {ClaimsDatatablePipe} from '../../utils/pipes/claimsDatatable.pipe'; import { DataTableDirective } from 'angular-datatables'; import{EnvProperties} from '../../utils/properties/env-properties'; @Component({ selector: 'claims-project-manager', templateUrl: 'claimsByToken.component.html' }) export class ClaimsByTokenComponent { public token: string = ""; public sub: any; public project: any; private claims:any = []; public pending_claims: any = []; public curated_claims: any = []; public selectedRight: Set; public selectedWrong: Set; public editable: Set; public contact_person: string[] = ["Konstantina", "Argiro", "Katerina"]; // when 'valid' show proper claims, when 'invalid' show no matched entry-wanna retry public accessStatus: string;// = "empty"; public rowsOnPage = 5; public sortOrder = "asc"; public filterQuery:string = ""; public filterQuery2:string = ""; public activePendingPage:any = {page: 1}; public totalPendingResults:any = {count: 0}; public activeCuratedPage:any = {page: 1}; public totalCuratedResults:any = {count: 0}; @ViewChild('mf1') table1: any;//DataTable; @ViewChild('mf2') table2: any;//DataTable; @ViewChild('filtered1') filteredItems1; @ViewChild (ModalSelect) selectModal : ModalSelect; @ViewChild (ModalLoading) loading : ModalLoading ; properties:EnvProperties; public routerHelper:RouterHelper = new RouterHelper(); constructor ( private route: ActivatedRoute, private claimsByTokenService: ClaimsByTokenService, private _meta: Meta) { } ngOnInit() { this.route.data .subscribe((data: { envSpecific: EnvProperties }) => { this.properties = data.envSpecific; }); this.sub = this.route.queryParams.subscribe(params => { this.token = params['token']; this.selectedRight = new Set(); this.selectedWrong = new Set(); this.editable = new Set(); //this.openSelect(); //this.setMessageSelect("Please select your identity:"); //this.setOptionsSelect(this.contact_person); this.validateJWTandToken(); this.updateTitle("Claims For Project Managers"); } ); } refreshTable(table:any, $event:any, whichTable: string) { if(whichTable == "pending") { this.activePendingPage.page = $event.value; } else if(whichTable == 'curated') { this.activeCuratedPage.page = $event.value; } table.mfActivePage=$event.value; table.setPage(table.mfActivePage, this.rowsOnPage); } public sortByClaimDate1 = (claim: any) => { return new Date(claim.date); } public sortByCurationDate1 = (claim: any) => { return new Date(claim.curationDate); } public sortByTitle1 = (claim: any) => { if(claim.targetType != 'project') { return claim.target.title; } else { return claim.source.title; } } public sortByClaimDate2 = (claim: any) => { return new Date(claim.date); } public sortByCurationDate2 = (claim: any) => { console.info(new Date(claim.curationDate)); return new Date(claim.curationDate); } public sortByTitle2= (claim: any) => { if(claim.targetType != 'project') { return claim.target.title; } else { return claim.source.title; } } validateJWTandToken() { var jwtToken=Session.getUserJwt(); if(this.token) { this.claimsByTokenService.getClaims(this.token, jwtToken, this.properties.claimsAPIURL).subscribe( data => { this.closeLoading(); this.accessStatus = "valid"; //console.info(data); this.claims = data.data; for(let claim of this.claims) { if(claim.targetType == "project") { this.project = claim.target; } else { this.project = claim.source; } if(claim.curatedBy) { this.curated_claims.push(claim); } else { this.pending_claims.push(claim); } } this.totalPendingResults.count = this.pending_claims.length; this.totalCuratedResults.count = this.curated_claims.length; this.updateTitle("Claims For Project Managers - "+this.project.name); }, err => { this.accessStatus = "invalid"; console.log(err); } ); } else { this.accessStatus = "invalid"; } } selectApprove(id:string, event) { var value = event.currentTarget.checked; if(value){ this.selectedRight.add(id); this.selectedWrong.delete(id); console.info(this.selectedRight); }else{ this.selectedRight.delete(id); console.info(this.selectedRight); } } selectDisapprove(id:string,event) { var value = event.currentTarget.checked; if(value){ this.selectedWrong.add(id); this.selectedRight.delete(id); }else{ this.selectedWrong.delete(id); } } isSelectedRight(id:string) { return this.selectedRight.has(id); } isSelectedWrong(id:string) { return this.selectedWrong.has(id); } isRight(claim: any) { //claim.approved = true; if(this.isSelectedRight(claim.id)) { return true; } else if(claim.approved == true && !this.isSelectedWrong(claim.id)) { return true; } return false; } isWrong(claim: any) { if(this.isSelectedWrong(claim.id)) { return true; } else if(claim.approved == false && !this.isSelectedRight(claim.id)) { return true; } return false; } saveChanges() { console.info("Changes Saved!"); var jwtToken=Session.getUserJwt(); this.claimsByTokenService.updateClaimsCuration(this.selectedRight, this.selectedWrong, this.properties.claimsAPIURL).subscribe( data => { console.info(data); }, err => { console.log(err); } ); } public closeLoading(){ if(this.loading){ this.loading.close(); } } curatorSelected(selected: string) { console.info("selected curator: "+selected); } public openSelect(){ if(this.selectModal){ this.selectModal.open(); } } public setMessageSelect(message: string){ if(this.selectModal){ this.selectModal.message = message; } } public setOptionsSelect(options: string[]){ if(this.selectModal){ this.selectModal.options = options; } } totalPages(totalResults: number): number { let totalPages:any = totalResults/(this.rowsOnPage); if(!(Number.isInteger(totalPages))) { totalPages = (parseInt(totalPages, 10) + 1); } return totalPages; } updateTitle(title:string){ var _prefix ="OpenAIRE | "; var _title = _prefix + ((title.length> 50 ) ?title.substring(0,50):title); this._meta.setTitle(_title ); } }