import {Component, OnInit, ElementRef} from '@angular/core'; import {HelpContentService} from '../../services/help-content.service'; import {ActivatedRoute, Router} from '@angular/router'; import {EnvProperties} from '../../openaireLibrary/utils/properties/env-properties'; import { Community } from '../../domain/community'; import { DomSanitizer } from '@angular/platform-browser'; import {TitleCasePipe} from '@angular/common'; import {availableEntitiesMap, StatisticsDisplay, StatisticsSummary} from '../../openaireLibrary/connect/statistics/statisticsEntities'; import {Observable} from 'rxjs/Observable'; import {ConfigurationService} from '../../openaireLibrary/utils/configuration/configuration.service'; import {Session} from '../../openaireLibrary/login/utils/helper.class'; import {LoginErrorCodes} from '../../openaireLibrary/login/utils/guardHelper.class'; @Component({ selector: 'stats', templateUrl: 'stats.component.html' }) export class StatsComponent implements OnInit { // errorMessage: string; // loadingMessage: string; public showLoading: boolean = true; public errorMessage: string = ''; public updateErrorMessage: string = ''; communities: Community[] = []; communityId: string; communityInfo = null; deactivatedEntity: boolean; displayedTimeline: string; displayedGraph: string; displayedProjectChart: string; displayedEntity: string; entitiesList: string[] = []; entitiesMap: Map = availableEntitiesMap; statisticsSum: StatisticsSummary; statisticsDisplay: StatisticsDisplay; chartsUrlMap: {}; showAllInMonitor: boolean = false; showAllInDashboard: boolean = false; public properties: EnvProperties = null; constructor(private element: ElementRef, private contentService: HelpContentService, private configService: ConfigurationService, private route: ActivatedRoute, private _router: Router, private sanitizer: DomSanitizer, private titleCase: TitleCasePipe) {} ngOnInit() { this.route.data .subscribe((data: { envSpecific: EnvProperties }) => { this.properties = data.envSpecific; this.route.queryParams.subscribe( params => { this.scroll(); this.communityId = params['communityId']; this.getStatistics(); }); }, error => console.log(`E R R O R!!`) ); } getStatistics() { if(!Session.isLoggedIn()){ console.info(this._router.url); this._router.navigate(['/user-info'], { queryParams: { "errorCode": LoginErrorCodes.NOT_VALID, "redirectUrl": this._router.url} }); } else { // this.loadingMessage = 'Retrieving statistics'; // this.errorMessage = ''; this.showLoading = true; this.updateErrorMessage = ""; this.errorMessage = ""; this.statisticsSum = null; this.statisticsDisplay = null; this.contentService.getCommunityStatistics(this.properties.statisticsAPIURL, this.communityId).subscribe( stats => { this.statisticsSum = stats; if(stats["other"]){ //hack because in stats API the entity name is "other" while in admin API is "orp". This component uses also "orp" name this.statisticsSum["orp"]=stats["other"]; } }, error => { //this.loadingMessage = ''; //this.errorMessage = 'Failed to retrieve statistics for the chosen community!'; //console.log(error); this.handleError('Failed to retrieve statistics for the chosen community!', error); }, () => { console.log(`I have statistics!`); //this.loadingMessage = ''; this.getDisplayOptions(); } ); } } getDisplayOptions() { if(!Session.isLoggedIn()){ console.info(this._router.url); this._router.navigate(['/user-info'], { queryParams: { "errorCode": LoginErrorCodes.NOT_VALID, "redirectUrl": this._router.url} }); } else { this.contentService.getCommunityAdminStatisticsChoices(this.properties.adminToolsAPIURL, this.communityId) .subscribe( res => { this.statisticsDisplay = res; }, error => { //console.log(error); this.handleError('Failed to retrieve statistics\' choices for the chosen community!', error); }, () => { this.getCommunityInfo(); } ); } } getCommunityInfo() { if(!Session.isLoggedIn()){ console.info(this._router.url); this._router.navigate(['/user-info'], { queryParams: { "errorCode": LoginErrorCodes.NOT_VALID, "redirectUrl": this._router.url} }); } else { console.log(`calling ${this.properties.adminToolsAPIURL}/communityFull/${this.communityId}`); this.configService.getCommunityInformation(this.properties.adminToolsAPIURL, this.communityId).subscribe( res => { this.communityInfo = res; }, error => this.handleError('Failed to retrieve information for the chosen community!', error),//console.log(error), () => { this.createChartUrlMap(); this.entitiesList = Array.from( this.entitiesMap.keys() ); this.onChangeEntity(this.entitiesList[0]); } ); } } onChangeEntity (entity: string) { if(!Session.isLoggedIn()){ console.info(this._router.url); this._router.navigate(['/user-info'], { queryParams: { "errorCode": LoginErrorCodes.NOT_VALID, "redirectUrl": this._router.url} }); } else { this.showLoading = true; this.deactivatedEntity = false; this.displayedEntity = entity; console.log(`displayed entity is ${entity}`); console.log(`statisticsSum[${entity}].total is ${this.statisticsSum[entity].total}`); console.log(`found ${entity} in allowedEntities`); this.displayedTimeline = `${entity}Timeline`; console.log(`displayed Timeline is: ${this.displayedTimeline}`); this.displayedGraph = `${entity}Graph`; console.log(`displayed Graph is: ${this.displayedGraph}`); this.changeDisplayedProjectChart(`${entity}Projectcolumn`); if (this.statisticsDisplay.entities[entity].charts.map['projectColumn'].showInMonitor && this.statisticsDisplay.entities[entity].charts.map['projectPie'].showInMonitor && this.statisticsDisplay.entities[entity].charts.map['projectTable'].showInMonitor) { this.showAllInMonitor = true; } if (this.statisticsDisplay.entities[entity].charts.map['projectColumn'].showInDashboard && this.statisticsDisplay.entities[entity].charts.map['projectPie'].showInDashboard && this.statisticsDisplay.entities[entity].charts.map['projectTable'].showInDashboard) { this.showAllInDashboard = true; } const activatedEntities = this.communityInfo['entities']; if ( !activatedEntities.some(item => item.pid === entity) ) { this.deactivatedEntity = true; } this.showLoading = false; } } changeDisplayedProjectChart(chartName: string) { this.displayedProjectChart = chartName; console.log(`displayed ProjectChart is: ${this.displayedProjectChart}`); } createChartUrlMap() { this.chartsUrlMap = { publicationTimeline : this.sanitizer.bypassSecurityTrustResourceUrl(`${this.properties.statisticsFrameAPIURL}chart.php?com=query&persistent=false&data=com=query&data={"query":"comTimelinePubs","comId":"${this.communityId}","table":"result","fields":[{"fld":"number","agg":"count","type":"column","yaxis":1,"c":false}],"xaxis":{"name":"year","agg":"avg"},"group":"","color":"","type":"chart","size":30,"sort":"xaxis","xStyle":{"r":"-","s":"-","l":"-","ft":"-","wt":"-"},"yaxisheaders":["Publications"],"fieldsheaders":["publications"],"in":[{"f":0,"text":"Yearly"}],"filters":[{"name":"year","max":"2013","min":"2007","to":-1},{"name":"result_projects-project-funding_lvl0","values":["FP7"],"to":"-1"},{"name":"type","values":["publication"],"to":"-1"},{"name":"result_projects-project-funding_lvl2","values":["ERC"],"to":"-1"}],"having":[],"incfilters":[],"inchaving":[],"title":"Publications through the years","subtitle":"","xaxistitle":"Year"}&w=70%&h=83%`), publicationGraph: this.sanitizer.bypassSecurityTrustResourceUrl(`${this.properties.statisticsFrameAPIURL}chart.php?com=query&data={"query":"comOAPubs","comId":"${this.communityId}","table":"result","fields":[{"fld":"number","agg":"count","type":"pie","yaxis":1,"c":false}],"xaxis":{"name":"bestlicense","agg":"avg"},"group":"","color":"","type":"chart","size":30,"sort":"xaxis","xStyle":{"r":"-","s":"-","l":"-","ft":"-","wt":"-"},"order":"d","yaxisheaders":[""],"fieldsheaders":[""],"in":[],"filters":[],"having":[],"incfilters":[],"inchaving":[],"title":"Publications by access mode","subtitle":"","xaxistitle":"","nulls":true}&w=70%&h=70%`), publicationProjectcolumn: this.sanitizer.bypassSecurityTrustResourceUrl(`${this.properties.statisticsFrameAPIURL}chart.php?com=query&data={"query":"comProjectPubs","comId":"${this.communityId}","table":"result","fields":[{"fld":"number","agg":"count","type":"bar","yaxis":1,"c":false}],"xaxis":{"name":"year","agg":"avg"},"group":"","color":"","type":"chart","size":30,"sort":"xaxis","xStyle":{"r":"-","s":"-","l":"-","ft":"-","wt":"-"},"yaxisheaders":["publications"],"fieldsheaders":["publications"],"in":[],"filters":[{"name":"year","max":"2013","min":"2007","to":-1},{"name":"result_projects-project-funding_lvl0","values":["FP7"],"to":"-1"},{"name":"type","values":["publication"],"to":"-1"},{"name":"result_projects-project-funding_lvl2","values":["ERC"],"to":"-1"}],"having":[],"incfilters":[],"inchaving":[],"title":"Publications per project","subtitle":"","xaxistitle":"Project"}&w=70%&h=90%`), publicationProjectpie: this.sanitizer.bypassSecurityTrustResourceUrl(`${this.properties.statisticsFrameAPIURL}chart.php?com=query&data={"query":"comProjectPubs","comId":"${this.communityId}","table":"result","fields":[{"fld":"number","agg":"count","type":"pie","yaxis":1,"c":false}],"xaxis":{"name":"year","agg":"avg"},"group":"","color":"","type":"chart","size":30,"sort":"xaxis","xStyle":{"r":"-","s":"-","l":"-","ft":"-","wt":"-"},"yaxisheaders":[""],"fieldsheaders":["publications"],"in":[],"filters":[{"name":"year","max":"2013","min":"2007","to":-1},{"name":"result_projects-project-funding_lvl0","values":["FP7"],"to":"-1"},{"name":"type","values":["publication"],"to":"-1"},{"name":"result_projects-project-funding_lvl2","values":["ERC"],"to":"-1"}],"having":[],"incfilters":[],"inchaving":[],"title":"Publications per project","subtitle":"","xaxistitle":"Project"}&w=91%&h=90%`), publicationProjecttable: this.sanitizer.bypassSecurityTrustResourceUrl(`${this.properties.statisticsFrameAPIURL}gtable.php?com=query&data={"query":"comProjectPubs","comId":"${this.communityId}","table":"result","fields":[{"fld":"number","agg":"count","type":"bar","yaxis":1,"c":false}],"xaxis":{"name":"year","agg":"avg"},"group":"","color":"","type":"chart","size":30,"sort":"xaxis","xStyle":{"r":"-","s":"-","l":"-","ft":"-","wt":"-"},"yaxisheaders":["Publications"],"fieldsheaders":["Publications"],"in":[],"filters":[{"name":"year","max":"2013","min":"2007","to":-1},{"name":"result_projects-project-funding_lvl0","values":["FP7"],"to":"-1"},{"name":"type","values":["publication"],"to":"-1"},{"name":"result_projects-project-funding_lvl2","values":["ERC"],"to":"-1"}],"having":[],"incfilters":[],"inchaving":[],"title":"","subtitle":"","xaxistitle":"Project"}&w=90%&h=83%`), datasetTimeline: this.sanitizer.bypassSecurityTrustResourceUrl(`${this.properties.statisticsFrameAPIURL}chart.php?com=query&data={"query":"comTimelineData","comId":"${this.communityId}","table":"result","fields":[{"fld":"number","agg":"count","type":"column","yaxis":1,"c":false}],"xaxis":{"name":"year","agg":"avg"},"group":"","color":"","type":"chart","size":30,"sort":"xaxis","xStyle":{"r":"-","s":"-","l":"-","ft":"-","wt":"-"},"yaxisheaders":["Datasets"],"fieldsheaders":["datasets"],"in":[{"f":0,"text":"Yearly"}],"filters":[{"name":"year","max":"2013","min":"2007","to":-1},{"name":"result_projects-project-funding_lvl0","values":["FP7"],"to":"-1"},{"name":"type","values":["publication"],"to":"-1"},{"name":"result_projects-project-funding_lvl2","values":["ERC"],"to":"-1"}],"having":[],"incfilters":[],"inchaving":[],"title":"Research data through the years","subtitle":"","xaxistitle":"Year"}&w=70%&h=83%`), datasetGraph: this.sanitizer.bypassSecurityTrustResourceUrl(`${this.properties.statisticsFrameAPIURL}chart.php?com=query&data={"query":"comOAData","comId":"${this.communityId}","table":"result","fields":[{"fld":"number","agg":"count","type":"pie","yaxis":1,"c":false}],"xaxis":{"name":"bestlicense","agg":"avg"},"group":"","color":"","type":"chart","size":30,"sort":"xaxis","xStyle":{"r":"-","s":"-","l":"-","ft":"-","wt":"-"},"order":"d","yaxisheaders":[""],"fieldsheaders":[""],"in":[],"filters":[],"having":[],"incfilters":[],"inchaving":[],"title":"Research data by access mode","subtitle":"","xaxistitle":"","nulls":true}&w=70%&h=70%`), datasetProjectcolumn: this.sanitizer.bypassSecurityTrustResourceUrl(`${this.properties.statisticsFrameAPIURL}chart.php?com=query&data={"query":"comProjectData","comId":"${this.communityId}","table":"result","fields":[{"fld":"number","agg":"count","type":"bar","yaxis":1,"c":false}],"xaxis":{"name":"year","agg":"avg"},"group":"","color":"","type":"chart","size":30,"sort":"xaxis","xStyle":{"r":"-","s":"-","l":"-","ft":"-","wt":"-"},"yaxisheaders":["Datasets"],"fieldsheaders":["datasets"],"in":[],"filters":[{"name":"year","max":"2013","min":"2007","to":-1},{"name":"result_projects-project-funding_lvl0","values":["FP7"],"to":"-1"},{"name":"type","values":["publication"],"to":"-1"},{"name":"result_projects-project-funding_lvl2","values":["ERC"],"to":"-1"}],"having":[],"incfilters":[],"inchaving":[],"title":"Research data per project","subtitle":"","xaxistitle":"Project"}&w=70%&h=90%`), datasetProjectpie: this.sanitizer.bypassSecurityTrustResourceUrl(`${this.properties.statisticsFrameAPIURL}chart.php?com=query&data={"query":"comProjectData","comId":"${this.communityId}","table":"result","fields":[{"fld":"number","agg":"count","type":"pie","yaxis":1,"c":false}],"xaxis":{"name":"year","agg":"avg"},"group":"","color":"","type":"chart","size":30,"sort":"xaxis","xStyle":{"r":"-","s":"-","l":"-","ft":"-","wt":"-"},"yaxisheaders":[""],"fieldsheaders":["datasets"],"in":[],"filters":[{"name":"year","max":"2013","min":"2007","to":-1},{"name":"result_projects-project-funding_lvl0","values":["FP7"],"to":"-1"},{"name":"type","values":["publication"],"to":"-1"},{"name":"result_projects-project-funding_lvl2","values":["ERC"],"to":"-1"}],"having":[],"incfilters":[],"inchaving":[],"title":"Research data per project","subtitle":"","xaxistitle":"Project"}&w=91%&h=90%`), datasetProjecttable: this.sanitizer.bypassSecurityTrustResourceUrl(`${this.properties.statisticsFrameAPIURL}gtable.php?com=query&data={"query":"comProjectData","comId":"${this.communityId}","table":"result","fields":[{"fld":"number","agg":"count","type":"bar","yaxis":1,"c":false}],"xaxis":{"name":"year","agg":"avg"},"group":"","color":"","type":"chart","size":30,"sort":"xaxis","xStyle":{"r":"-","s":"-","l":"-","ft":"-","wt":"-"},"yaxisheaders":["Datasets"],"fieldsheaders":["Datasets"],"in":[],"filters":[{"name":"year","max":"2013","min":"2007","to":-1},{"name":"result_projects-project-funding_lvl0","values":["FP7"],"to":"-1"},{"name":"type","values":["publication"],"to":"-1"},{"name":"result_projects-project-funding_lvl2","values":["ERC"],"to":"-1"}],"having":[],"incfilters":[],"inchaving":[],"title":"","subtitle":"","xaxistitle":"Project"}&w=90%&h=83%`), softwareTimeline: this.sanitizer.bypassSecurityTrustResourceUrl(`${this.properties.statisticsFrameAPIURL}chart.php?com=query&data={"query":"comTimelineSoft","comId":"${this.communityId}","table":"result","fields":[{"fld":"number","agg":"count","type":"column","yaxis":1,"c":false}],"xaxis":{"name":"year","agg":"avg"},"group":"","color":"","type":"chart","size":30,"sort":"xaxis","xStyle":{"r":"-","s":"-","l":"-","ft":"-","wt":"-"},"yaxisheaders":["Software"],"fieldsheaders":["software"],"in":[{"f":0,"text":"Yearly"}],"filters":[{"name":"year","max":"2013","min":"2007","to":-1},{"name":"result_projects-project-funding_lvl0","values":["FP7"],"to":"-1"},{"name":"type","values":["publication"],"to":"-1"},{"name":"result_projects-project-funding_lvl2","values":["ERC"],"to":"-1"}],"having":[],"incfilters":[],"inchaving":[],"title":"Software through the years","subtitle":"","xaxistitle":"Year"}&w=70%&h=83%`), softwareGraph: this.sanitizer.bypassSecurityTrustResourceUrl(`${this.properties.statisticsFrameAPIURL}chart.php?com=query&data={"query":"comOASoft","comId":"${this.communityId}","table":"result","fields":[{"fld":"number","agg":"count","type":"pie","yaxis":1,"c":false}],"xaxis":{"name":"bestlicense","agg":"avg"},"group":"","color":"","type":"chart","size":30,"sort":"xaxis","xStyle":{"r":"-","s":"-","l":"-","ft":"-","wt":"-"},"order":"d","yaxisheaders":[""],"fieldsheaders":[""],"in":[],"filters":[],"having":[],"incfilters":[],"inchaving":[],"title":"Software by access mode","subtitle":"","xaxistitle":"","nulls":true}&w=70%&h=70%`), softwareProjectcolumn: this.sanitizer.bypassSecurityTrustResourceUrl(`${this.properties.statisticsFrameAPIURL}chart.php?com=query&data={"query":"comProjectSoft","comId":"${this.communityId}","table":"result","fields":[{"fld":"number","agg":"count","type":"bar","yaxis":1,"c":false}],"xaxis":{"name":"year","agg":"avg"},"group":"","color":"","type":"chart","size":30,"sort":"xaxis","xStyle":{"r":"-","s":"-","l":"-","ft":"-","wt":"-"},"yaxisheaders":["Software"],"fieldsheaders":["software"],"in":[],"filters":[{"name":"year","max":"2013","min":"2007","to":-1},{"name":"result_projects-project-funding_lvl0","values":["FP7"],"to":"-1"},{"name":"type","values":["publication"],"to":"-1"},{"name":"result_projects-project-funding_lvl2","values":["ERC"],"to":"-1"}],"having":[],"incfilters":[],"inchaving":[],"title":"Software per project","subtitle":"","xaxistitle":"Project"}&w=70%&h=90%`), softwareProjectpie: this.sanitizer.bypassSecurityTrustResourceUrl(`${this.properties.statisticsFrameAPIURL}chart.php?com=query&data={"query":"comProjectSoft","comId":"${this.communityId}","table":"result","fields":[{"fld":"number","agg":"count","type":"pie","yaxis":1,"c":false}],"xaxis":{"name":"year","agg":"avg"},"group":"","color":"","type":"chart","size":30,"sort":"xaxis","xStyle":{"r":"-","s":"-","l":"-","ft":"-","wt":"-"},"yaxisheaders":[""],"fieldsheaders":["software"],"in":[],"filters":[{"name":"year","max":"2013","min":"2007","to":-1},{"name":"result_projects-project-funding_lvl0","values":["FP7"],"to":"-1"},{"name":"type","values":["publication"],"to":"-1"},{"name":"result_projects-project-funding_lvl2","values":["ERC"],"to":"-1"}],"having":[],"incfilters":[],"inchaving":[],"title":"Software per project","subtitle":"","xaxistitle":"Project"}&w=91%&h=90%`), softwareProjecttable: this.sanitizer.bypassSecurityTrustResourceUrl(`${this.properties.statisticsFrameAPIURL}gtable.php?com=query&data={"query":"comProjectSoft","comId":"${this.communityId}","table":"result","fields":[{"fld":"number","agg":"count","type":"bar","yaxis":1,"c":false}],"xaxis":{"name":"year","agg":"avg"},"group":"","color":"","type":"chart","size":30,"sort":"xaxis","xStyle":{"r":"-","s":"-","l":"-","ft":"-","wt":"-"},"yaxisheaders":["Software"],"fieldsheaders":["Software"],"in":[],"filters":[{"name":"year","max":"2013","min":"2007","to":-1},{"name":"result_projects-project-funding_lvl0","values":["FP7"],"to":"-1"},{"name":"type","values":["publication"],"to":"-1"},{"name":"result_projects-project-funding_lvl2","values":["ERC"],"to":"-1"}],"having":[],"incfilters":[],"inchaving":[],"title":"","subtitle":"","xaxistitle":"Project"}&w=90%&h=83%`), orpTimeline: this.sanitizer.bypassSecurityTrustResourceUrl(`${this.properties.statisticsFrameAPIURL}chart.php?com=query&data={"query":"comTimelineOther","comId":"${this.communityId}","table":"result","fields":[{"fld":"number","agg":"count","type":"column","yaxis":1,"c":false}],"xaxis":{"name":"year","agg":"avg"},"group":"","color":"","type":"chart","size":30,"sort":"xaxis","xStyle":{"r":"-","s":"-","l":"-","ft":"-","wt":"-"},"yaxisheaders":["Other Research products"],"fieldsheaders":["Other Research products"],"in":[{"f":0,"text":"Yearly"}],"filters":[{"name":"year","max":"2013","min":"2007","to":-1},{"name":"result_projects-project-funding_lvl0","values":["FP7"],"to":"-1"},{"name":"type","values":["publication"],"to":"-1"},{"name":"result_projects-project-funding_lvl2","values":["ERC"],"to":"-1"}],"having":[],"incfilters":[],"inchaving":[],"title":"Other Research products through the years","subtitle":"","xaxistitle":"Year"}&w=70%&h=83%`), orpGraph: this.sanitizer.bypassSecurityTrustResourceUrl(`${this.properties.statisticsFrameAPIURL}chart.php?com=query&data={"query":"comOAOther","comId":"${this.communityId}","table":"result","fields":[{"fld":"number","agg":"count","type":"pie","yaxis":1,"c":false}],"xaxis":{"name":"bestlicense","agg":"avg"},"group":"","color":"","type":"chart","size":30,"sort":"xaxis","xStyle":{"r":"-","s":"-","l":"-","ft":"-","wt":"-"},"order":"d","yaxisheaders":[""],"fieldsheaders":[""],"in":[],"filters":[],"having":[],"incfilters":[],"inchaving":[],"title":"Other Research products by access mode","subtitle":"","xaxistitle":"","nulls":true}&w=70%&h=70%`), orpProjectcolumn: this.sanitizer.bypassSecurityTrustResourceUrl(`${this.properties.statisticsFrameAPIURL}chart.php?com=query&data={"query":"comProjectOther","comId":"${this.communityId}","table":"result","fields":[{"fld":"number","agg":"count","type":"bar","yaxis":1,"c":false}],"xaxis":{"name":"year","agg":"avg"},"group":"","color":"","type":"chart","size":30,"sort":"xaxis","xStyle":{"r":"-","s":"-","l":"-","ft":"-","wt":"-"},"yaxisheaders":["Other Research products"],"fieldsheaders":["Other Research products"],"in":[],"filters":[{"name":"year","max":"2013","min":"2007","to":-1},{"name":"result_projects-project-funding_lvl0","values":["FP7"],"to":"-1"},{"name":"type","values":["publication"],"to":"-1"},{"name":"result_projects-project-funding_lvl2","values":["ERC"],"to":"-1"}],"having":[],"incfilters":[],"inchaving":[],"title":"Other Research products per project","subtitle":"","xaxistitle":"Project"}&w=70%&h=90%`), orpProjectpie: this.sanitizer.bypassSecurityTrustResourceUrl(`${this.properties.statisticsFrameAPIURL}chart.php?com=query&data={"query":"comProjectOther","comId":"${this.communityId}","table":"result","fields":[{"fld":"number","agg":"count","type":"pie","yaxis":1,"c":false}],"xaxis":{"name":"year","agg":"avg"},"group":"","color":"","type":"chart","size":30,"sort":"xaxis","xStyle":{"r":"-","s":"-","l":"-","ft":"-","wt":"-"},"yaxisheaders":[""],"fieldsheaders":["Other Research products"],"in":[],"filters":[{"name":"year","max":"2013","min":"2007","to":-1},{"name":"result_projects-project-funding_lvl0","values":["FP7"],"to":"-1"},{"name":"type","values":["publication"],"to":"-1"},{"name":"result_projects-project-funding_lvl2","values":["ERC"],"to":"-1"}],"having":[],"incfilters":[],"inchaving":[],"title":"Other Research products per project","subtitle":"","xaxistitle":"Project"}&w=91%&h=90%`), orpProjecttable: this.sanitizer.bypassSecurityTrustResourceUrl(`${this.properties.statisticsFrameAPIURL}gtable.php?com=query&data={"query":"comProjectOther","comId":"${this.communityId}","table":"result","fields":[{"fld":"number","agg":"count","type":"bar","yaxis":1,"c":false}],"xaxis":{"name":"year","agg":"avg"},"group":"","color":"","type":"chart","size":30,"sort":"xaxis","xStyle":{"r":"-","s":"-","l":"-","ft":"-","wt":"-"},"yaxisheaders":["Other Research products"],"fieldsheaders":["Other Research products"],"in":[],"filters":[{"name":"year","max":"2013","min":"2007","to":-1},{"name":"result_projects-project-funding_lvl0","values":["FP7"],"to":"-1"},{"name":"type","values":["publication"],"to":"-1"},{"name":"result_projects-project-funding_lvl2","values":["ERC"],"to":"-1"}],"having":[],"incfilters":[],"inchaving":[],"title":"","subtitle":"","xaxistitle":"Project"}&w=90%&h=83%`) }; } toggleShowAllInMonitor(entity: string) { if(!Session.isLoggedIn()){ console.info(this._router.url); this._router.navigate(['/user-info'], { queryParams: { "errorCode": LoginErrorCodes.NOT_VALID, "redirectUrl": this._router.url} }); } else { this.showLoading = true; this.updateErrorMessage = ""; //this.loadingMessage = 'Saving changes'; this.showAllInMonitor = !this.showAllInMonitor; this.contentService.postCommunityAdminStatisticsChoices( this.properties.adminToolsAPIURL, this.communityId, entity, 'charts', 'projectColumn', this.showAllInMonitor, true).subscribe( response => console.log(JSON.stringify(response)), error => { console.log(error); //this.loadingMessage = ''; //this.errorMessage = 'The changes could not be saved'; this.handleUpdateError('The changes could not be saved', error); }, () => { this.contentService.postCommunityAdminStatisticsChoices( this.properties.adminToolsAPIURL, this.communityId, entity, 'charts', 'projectPie', this.showAllInMonitor, true).subscribe( response => console.log(JSON.stringify(response)), error => { console.log(error); //this.loadingMessage = ''; //this.errorMessage = 'The changes could not be saved'; this.handleUpdateError('The changes could not be saved', error); }, () => { this.contentService.postCommunityAdminStatisticsChoices( this.properties.adminToolsAPIURL, this.communityId, entity, 'charts', 'projectTable', this.showAllInMonitor, true).subscribe( response => console.log(JSON.stringify(response)), error => { console.log(error); //this.loadingMessage = ''; //this.errorMessage = 'The changes could not be saved'; this.handleUpdateError('The changes could not be saved' ,error); }, () => { this.statisticsDisplay.entities[entity]['charts'].map['projectColumn'].showInMonitor = this.showAllInMonitor; this.statisticsDisplay.entities[entity]['charts'].map['projectPie'].showInMonitor = this.showAllInMonitor; this.statisticsDisplay.entities[entity]['charts'].map['projectTable'].showInMonitor = this.showAllInMonitor; //this.loadingMessage = ''; this.showLoading = false; } ); } ); } ); /*forkJoin didn't work properly - maybe try another way*/ /*Observable.forkJoin( this.contentService.postCommunityAdminStatisticsChoices( this.properties.adminToolsAPIURL, this.communityId, entity, 'charts', 'projectColumn', this.showAllInMonitor, true), this.contentService.postCommunityAdminStatisticsChoices( this.properties.adminToolsAPIURL, this.communityId, entity, 'charts', 'projectPie', this.showAllInMonitor, true), this.contentService.postCommunityAdminStatisticsChoices( this.properties.adminToolsAPIURL, this.communityId, entity, 'charts', 'projectTable', this.showAllInMonitor, true) ).subscribe( response => console.log('All went well in forkJoin!'), error => { console.log(error); this.loadingMessage = ''; this.errorMessage = 'The changes could not be saved'; }, () => { this.statisticsDisplay.entities[entity]['charts'].map['projectColumn'].showInMonitor = this.showAllInMonitor; this.statisticsDisplay.entities[entity]['charts'].map['projectPie'].showInMonitor = this.showAllInMonitor; this.statisticsDisplay.entities[entity]['charts'].map['projectTable'].showInMonitor = this.showAllInMonitor; this.loadingMessage = ''; } );*/ } } toggleShowAllInDashboard(entity: string) { if(!Session.isLoggedIn()){ console.info(this._router.url); this._router.navigate(['/user-info'], { queryParams: { "errorCode": LoginErrorCodes.NOT_VALID, "redirectUrl": this._router.url} }); } else { this.showLoading = true; this.updateErrorMessage = ""; //this.loadingMessage = 'Saving changes'; this.contentService.postCommunityAdminStatisticsChoices( this.properties.adminToolsAPIURL, this.communityId, entity, 'charts', 'projectColumn', !this.showAllInDashboard, false).subscribe( response => console.log(JSON.stringify(response)), error => { console.log(error); //this.loadingMessage = ''; //this.errorMessage = 'The changes could not be saved'; this.handleUpdateError('The changed could not be saved', error); }, () => { this.contentService.postCommunityAdminStatisticsChoices( this.properties.adminToolsAPIURL, this.communityId, entity, 'charts', 'projectPie', !this.showAllInDashboard, false).subscribe( response => console.log(JSON.stringify(response)), error => { console.log(error); //this.loadingMessage = ''; //this.errorMessage = 'The changes could not be saved'; this.handleUpdateError('The changes could not be saved', error); }, () => { this.contentService.postCommunityAdminStatisticsChoices( this.properties.adminToolsAPIURL, this.communityId, entity, 'charts', 'projectTable', !this.showAllInDashboard, false).subscribe( response => console.log(JSON.stringify(response)), error => { console.log(error); //this.loadingMessage = ''; //this.errorMessage = 'The changes could not be saved'; this.handleUpdateError('The changes could not be saved', error); }, () => { this.showAllInDashboard = !this.showAllInDashboard; this.statisticsDisplay.entities[entity]['charts'].map['projectColumn'].showInDashboard = this.showAllInDashboard; this.statisticsDisplay.entities[entity]['charts'].map['projectPie'].showInDashboard = this.showAllInDashboard; this.statisticsDisplay.entities[entity]['charts'].map['projectTable'].showInDashboard = this.showAllInDashboard; //this.loadingMessage = ''; this.showLoading = false; } ); } ); } ); } } toggleShowInMonitor(entity: string, chartsOrNumbers: string, title: string) { if(!Session.isLoggedIn()){ console.info(this._router.url); this._router.navigate(['/user-info'], { queryParams: { "errorCode": LoginErrorCodes.NOT_VALID, "redirectUrl": this._router.url} }); } else { this.showLoading = true; this.updateErrorMessage = ""; this.contentService.postCommunityAdminStatisticsChoices( this.properties.adminToolsAPIURL, this.communityId, entity, chartsOrNumbers, title, !this.statisticsDisplay.entities[entity][chartsOrNumbers].map[title].showInMonitor, true).subscribe( response => console.log(JSON.stringify(response)), error => this.handleUpdateError('The changes could not be saved', error),//console.log(error), () => { this.statisticsDisplay.entities[entity][chartsOrNumbers].map[title].showInMonitor = !this.statisticsDisplay.entities[entity][chartsOrNumbers].map[title].showInMonitor; this.showLoading = false; } ); } } toggleShowInDashboard(entity: string, chartsOrNumbers: string, title: string) { if(!Session.isLoggedIn()){ console.info(this._router.url); this._router.navigate(['/user-info'], { queryParams: { "errorCode": LoginErrorCodes.NOT_VALID, "redirectUrl": this._router.url} }); } else { this.showLoading = true; this.updateErrorMessage = ""; this.contentService.postCommunityAdminStatisticsChoices( this.properties.adminToolsAPIURL, this.communityId, entity, chartsOrNumbers, title, !this.statisticsDisplay.entities[entity][chartsOrNumbers].map[title].showInDashboard, false).subscribe( response => console.log(JSON.stringify(response)), error => this.handleUpdateError('The changes could not be saved', error),//console.log(error), () => { this.statisticsDisplay.entities[entity][chartsOrNumbers].map[title].showInDashboard = !this.statisticsDisplay.entities[entity][chartsOrNumbers].map[title].showInDashboard; this.showLoading = false; } ); } } getCamelCaseString (inputString: string) { return this.titleCase.transform(inputString); } handleUpdateError(message: string, error) { this.updateErrorMessage = message; console.log('Server responded: ' +error); this.showLoading = false; } handleError(message: string, error) { this.errorMessage = message; console.log('Server responded: ' + error); this.showLoading = false; } public scroll() { console.info("scroll into view"); if (typeof document !== 'undefined') { this.element.nativeElement.scrollIntoView(); } } }