Project

General

Profile

1
import {Component, OnInit} from '@angular/core';
2
import {HelpContentService} from '../../services/help-content.service';
3
import {ActivatedRoute} from '@angular/router';
4
import {EnvProperties} from '../../openaireLibrary/utils/properties/env-properties';
5
import { Community } from '../../domain/community';
6
import { DomSanitizer } from '@angular/platform-browser';
7
import {TitleCasePipe} from '@angular/common';
8
import {availableEntitiesMap, StatisticsDisplay, StatisticsSummary} from '../../openaireLibrary/connect/statistics/statisticsEntities';
9
import {Observable} from 'rxjs/Observable';
10
import {ConfigurationService} from '../../openaireLibrary/utils/configuration/configuration.service';
11

    
12
@Component({
13
    selector: 'stats',
14
    templateUrl: 'stats.component.html'
15
})
16

    
17
export class StatsComponent implements OnInit {
18
    // errorMessage: string;
19
    // loadingMessage: string;
20
    public showLoading: boolean = true;
21
    public errorMessage: string = '';
22
    public updateErrorMessage: string = '';
23

    
24
    communities: Community[] = [];
25
    communityId: string;
26
    communityInfo = null;
27
    deactivatedEntity: boolean;
28

    
29
    displayedTimeline: string;
30
    displayedGraph: string;
31
    displayedProjectChart: string;
32
    displayedEntity: string;
33

    
34
    entitiesList: string[] = [];
35
    entitiesMap: Map<string, string> = availableEntitiesMap;
36

    
37
    statisticsSum: StatisticsSummary;
38
    statisticsDisplay: StatisticsDisplay;
39
    chartsUrlMap: {};
40

    
41
    showAllInMonitor: boolean = false;
42
    showAllInDashboard: boolean = false;
43

    
44
    public properties: EnvProperties = null;
45

    
46
    constructor(private contentService: HelpContentService,
47
                private configService: ConfigurationService,
48
                private route: ActivatedRoute,
49
                private sanitizer: DomSanitizer,
50
                private titleCase: TitleCasePipe) {}
51

    
52
    ngOnInit() {
53
        this.route.data
54
            .subscribe((data: { envSpecific: EnvProperties }) => {
55
                this.properties = data.envSpecific;
56
                    this.route.queryParams.subscribe(
57
                        params => {
58
                            this.communityId = params['communityId'];
59
                            this.getStatistics();
60
                        });
61
                },
62
                error => console.log(`E R R O R!!`)
63
            );
64
    }
65

    
66
    getStatistics() {
67
        // this.loadingMessage = 'Retrieving statistics';
68
        // this.errorMessage = '';
69
        this.showLoading = true;
70
        this.updateErrorMessage = "";
71
        this.errorMessage = "";
72

    
73
        this.statisticsSum = null;
74
        this.statisticsDisplay = null;
75
        this.contentService.getCommunityStatistics(this.properties.statisticsAPIURL, this.communityId).subscribe(
76
            stats => {
77

    
78
              this.statisticsSum = stats;
79
              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
80
                this.statisticsSum["orp"]=stats["other"];
81
              }
82
            },
83
            error => {
84
                //this.loadingMessage = '';
85
                //this.errorMessage = 'Failed to retrieve statistics for the chosen community!';
86
                //console.log(error);
87
                this.handleError('Failed to retrieve statistics for the chosen community!', error);
88
            },
89
            () => {
90
                console.log(`I have statistics!`);
91
                //this.loadingMessage = '';
92
                this.getDisplayOptions();
93
            }
94
        );
95
    }
96

    
97
    getDisplayOptions() {
98
        this.contentService.getCommunityAdminStatisticsChoices(this.properties.adminToolsAPIURL, this.communityId)
99
            .subscribe(
100
                res => {
101
                    this.statisticsDisplay = res;
102
                },
103
                error => {
104
                    //console.log(error);
105
                    this.handleError('Failed to retrieve statistics\' choices for the chosen community!', error);
106
                },
107
                () => {
108
                    this.getCommunityInfo();
109
                }
110
            );
111
    }
112

    
113
    getCommunityInfo() {
114
        console.log(`calling ${this.properties.adminToolsAPIURL}/communityFull/${this.communityId}`);
115
        this.configService.getCommunityInformation(this.properties.adminToolsAPIURL, this.communityId).subscribe(
116
            res => {
117
                this.communityInfo = res;
118
            },
119
            error => this.handleError('Failed to retrieve information for the chosen community!', error),//console.log(error),
120
            () => {
121
                this.createChartUrlMap();
122
                this.entitiesList = Array.from( this.entitiesMap.keys() );
123
                this.onChangeEntity(this.entitiesList[0]);
124
            }
125
        );
126
    }
127

    
128
    onChangeEntity (entity: string) {
129
        this.showLoading = true;
130

    
131
        this.deactivatedEntity = false;
132
        this.displayedEntity = entity;
133
        console.log(`displayed entity is ${entity}`);
134
        console.log(`statisticsSum[${entity}].total is ${this.statisticsSum[entity].total}`);
135

    
136
        console.log(`found ${entity} in allowedEntities`);
137
        this.displayedTimeline = `${entity}Timeline`;
138
        console.log(`displayed Timeline is: ${this.displayedTimeline}`);
139
        this.displayedGraph = `${entity}Graph`;
140
        console.log(`displayed Graph is: ${this.displayedGraph}`);
141
        this.changeDisplayedProjectChart(`${entity}Projectcolumn`);
142
        if (this.statisticsDisplay.entities[entity].charts.map['projectColumn'].showInMonitor &&
143
            this.statisticsDisplay.entities[entity].charts.map['projectPie'].showInMonitor &&
144
            this.statisticsDisplay.entities[entity].charts.map['projectTable'].showInMonitor) {
145
            this.showAllInMonitor = true;
146
        }
147
        if (this.statisticsDisplay.entities[entity].charts.map['projectColumn'].showInDashboard &&
148
            this.statisticsDisplay.entities[entity].charts.map['projectPie'].showInDashboard &&
149
            this.statisticsDisplay.entities[entity].charts.map['projectTable'].showInDashboard) {
150
            this.showAllInDashboard = true;
151
        }
152

    
153
        const activatedEntities = this.communityInfo['entities'];
154
        if ( !activatedEntities.some(item => item.pid === entity) ) {
155
            this.deactivatedEntity = true;
156
        }
157

    
158
        this.showLoading = false;
159
    }
160

    
161
    changeDisplayedProjectChart(chartName: string) {
162
        this.displayedProjectChart = chartName;
163
        console.log(`displayed ProjectChart is: ${this.displayedProjectChart}`);
164
    }
165

    
166
    createChartUrlMap() {
167
        this.chartsUrlMap = {
168
            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%`),
169
            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%`),
170
            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%`),
171
            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%`),
172
            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%`),
173
            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%`),
174
            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%`),
175
            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%`),
176
            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%`),
177
            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%`),
178
            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%`),
179
            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%`),
180
            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%`),
181
            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%`),
182
            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%`),
183

    
184
            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%`),
185
            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%`),
186
            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%`),
187
            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%`),
188
            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%`)
189
        };
190
    }
191

    
192
    toggleShowAllInMonitor(entity: string) {
193
        this.showLoading = true;
194
        this.updateErrorMessage = "";
195

    
196
        //this.loadingMessage = 'Saving changes';
197
        this.showAllInMonitor = !this.showAllInMonitor;
198

    
199
        this.contentService.postCommunityAdminStatisticsChoices(
200
            this.properties.adminToolsAPIURL,
201
            this.communityId,
202
            entity,
203
            'charts',
204
            'projectColumn',
205
            !this.showAllInMonitor,
206
            true).subscribe(
207
            response => console.log(JSON.stringify(response)),
208
            error => {
209
                console.log(error);
210
                //this.loadingMessage = '';
211
                //this.errorMessage = 'The changes could not be saved';
212

    
213
                this.handleUpdateError('The changes could not be saved', error);
214
            },
215
            () => {
216

    
217
                this.contentService.postCommunityAdminStatisticsChoices(
218
                    this.properties.adminToolsAPIURL,
219
                    this.communityId,
220
                    entity,
221
                    'charts',
222
                    'projectPie',
223
                    !this.showAllInMonitor,
224
                    true).subscribe(
225
                    response => console.log(JSON.stringify(response)),
226
                    error => {
227
                        console.log(error);
228
                        //this.loadingMessage = '';
229
                        //this.errorMessage = 'The changes could not be saved';
230

    
231
                        this.handleUpdateError('The changes could not be saved', error);
232
                    },
233
                    () => {
234

    
235
                        this.contentService.postCommunityAdminStatisticsChoices(
236
                            this.properties.adminToolsAPIURL,
237
                            this.communityId,
238
                            entity,
239
                            'charts',
240
                            'projectTable',
241
                            !this.showAllInMonitor,
242
                            true).subscribe(
243
                            response => console.log(JSON.stringify(response)),
244
                            error => {
245
                                console.log(error);
246
                                //this.loadingMessage = '';
247
                                //this.errorMessage = 'The changes could not be saved';
248

    
249
                                this.handleUpdateError('The changes could not be saved' ,error);
250
                            },
251
                            () => {
252

    
253
                                this.statisticsDisplay.entities[entity]['charts'].map['projectColumn'].showInMonitor = this.showAllInMonitor;
254
                                this.statisticsDisplay.entities[entity]['charts'].map['projectPie'].showInMonitor = this.showAllInMonitor;
255
                                this.statisticsDisplay.entities[entity]['charts'].map['projectTable'].showInMonitor = this.showAllInMonitor;
256
                                //this.loadingMessage = '';
257

    
258
                                this.showLoading = false;
259
                            }
260
                        );
261
                    }
262
                );
263
            }
264
        );
265

    
266
        /*forkJoin didn't work properly - maybe try another way*/
267
        /*Observable.forkJoin(
268
            this.contentService.postCommunityAdminStatisticsChoices(
269
                this.properties.adminToolsAPIURL,
270
                this.communityId,
271
                entity,
272
                'charts',
273
                'projectColumn',
274
                this.showAllInMonitor,
275
            true),
276
            this.contentService.postCommunityAdminStatisticsChoices(
277
                this.properties.adminToolsAPIURL,
278
                this.communityId,
279
                entity,
280
                'charts',
281
                'projectPie',
282
                this.showAllInMonitor,
283
                true),
284
            this.contentService.postCommunityAdminStatisticsChoices(
285
                this.properties.adminToolsAPIURL,
286
                this.communityId,
287
                entity,
288
                'charts',
289
                'projectTable',
290
                this.showAllInMonitor,
291
                true)
292

    
293
        ).subscribe(
294
            response => console.log('All went well in forkJoin!'),
295
            error => {
296
                console.log(error);
297
                this.loadingMessage = '';
298
                this.errorMessage = 'The changes could not be saved';
299
            },
300
            () => {
301
                this.statisticsDisplay.entities[entity]['charts'].map['projectColumn'].showInMonitor = this.showAllInMonitor;
302
                this.statisticsDisplay.entities[entity]['charts'].map['projectPie'].showInMonitor = this.showAllInMonitor;
303
                this.statisticsDisplay.entities[entity]['charts'].map['projectTable'].showInMonitor = this.showAllInMonitor;
304
                this.loadingMessage = '';
305
            }
306
        );*/
307

    
308
    }
309

    
310
    toggleShowAllInDashboard(entity: string) {
311
        this.showLoading = true;
312
        this.updateErrorMessage = "";
313

    
314
        //this.loadingMessage = 'Saving changes';
315
        this.contentService.postCommunityAdminStatisticsChoices(
316
            this.properties.adminToolsAPIURL,
317
            this.communityId,
318
            entity,
319
            'charts',
320
            'projectColumn',
321
            !this.showAllInDashboard,
322
            false).subscribe(
323
            response => console.log(JSON.stringify(response)),
324
            error => {
325
                console.log(error);
326
                //this.loadingMessage = '';
327
                //this.errorMessage = 'The changes could not be saved';
328
                this.handleUpdateError('The changed could not be saved', error);
329
            },
330
            () => {
331

    
332
                this.contentService.postCommunityAdminStatisticsChoices(
333
                    this.properties.adminToolsAPIURL,
334
                    this.communityId,
335
                    entity,
336
                    'charts',
337
                    'projectPie',
338
                    !this.showAllInDashboard,
339
                    false).subscribe(
340
                    response => console.log(JSON.stringify(response)),
341
                    error => {
342
                        console.log(error);
343
                        //this.loadingMessage = '';
344
                        //this.errorMessage = 'The changes could not be saved';
345
                        this.handleUpdateError('The changes could not be saved', error);
346
                    },
347
                    () => {
348

    
349
                        this.contentService.postCommunityAdminStatisticsChoices(
350
                            this.properties.adminToolsAPIURL,
351
                            this.communityId,
352
                            entity,
353
                            'charts',
354
                            'projectTable',
355
                            !this.showAllInDashboard,
356
                            false).subscribe(
357
                            response => console.log(JSON.stringify(response)),
358
                            error => {
359
                                console.log(error);
360
                                //this.loadingMessage = '';
361
                                //this.errorMessage = 'The changes could not be saved';
362
                                this.handleUpdateError('The changes could not be saved', error);
363
                            },
364
                            () => {
365

    
366
                                this.showAllInDashboard = !this.showAllInDashboard;
367
                                this.statisticsDisplay.entities[entity]['charts'].map['projectColumn'].showInDashboard = this.showAllInDashboard;
368
                                this.statisticsDisplay.entities[entity]['charts'].map['projectPie'].showInDashboard = this.showAllInDashboard;
369
                                this.statisticsDisplay.entities[entity]['charts'].map['projectTable'].showInDashboard = this.showAllInDashboard;
370
                                //this.loadingMessage = '';
371

    
372
                                this.showLoading = false;
373
                            }
374
                        );
375
                    }
376
                );
377
            }
378
        );
379
    }
380

    
381
    toggleShowInMonitor(entity: string, chartsOrNumbers: string, title: string) {
382
        this.showLoading = true;
383
        this.updateErrorMessage = "";
384

    
385
        this.contentService.postCommunityAdminStatisticsChoices(
386
            this.properties.adminToolsAPIURL,
387
            this.communityId,
388
            entity,
389
            chartsOrNumbers,
390
            title,
391
            !this.statisticsDisplay.entities[entity][chartsOrNumbers].map[title].showInMonitor,
392
            true).subscribe(
393
                    response => console.log(JSON.stringify(response)),
394
                    error => this.handleUpdateError('The changes could not be saved', error),//console.log(error),
395
                    () => {
396
                      this.statisticsDisplay.entities[entity][chartsOrNumbers].map[title].showInMonitor = !this.statisticsDisplay.entities[entity][chartsOrNumbers].map[title].showInMonitor;
397
                      this.showLoading = false;
398
                    }
399
                );
400
    }
401

    
402
    toggleShowInDashboard(entity: string, chartsOrNumbers: string, title: string) {
403
        this.showLoading = true;
404
        this.updateErrorMessage = "";
405

    
406
        this.contentService.postCommunityAdminStatisticsChoices(
407
            this.properties.adminToolsAPIURL,
408
            this.communityId,
409
            entity,
410
            chartsOrNumbers,
411
            title,
412
            !this.statisticsDisplay.entities[entity][chartsOrNumbers].map[title].showInDashboard,
413
            false).subscribe(
414
                response => console.log(JSON.stringify(response)),
415
                error => this.handleUpdateError('The changes could not be saved', error),//console.log(error),
416
                () => {
417
                  this.statisticsDisplay.entities[entity][chartsOrNumbers].map[title].showInDashboard = !this.statisticsDisplay.entities[entity][chartsOrNumbers].map[title].showInDashboard;
418
                  this.showLoading = false;
419
                }
420
            );
421
    }
422

    
423
    getCamelCaseString (inputString: string) {
424
        return this.titleCase.transform(inputString);
425
    }
426

    
427

    
428
    handleUpdateError(message: string, error) {
429
        this.updateErrorMessage = message;
430
        console.log('Server responded: ' +error);
431

    
432
        this.showLoading = false;
433
    }
434

    
435
    handleError(message: string, error) {
436
        this.errorMessage = message;
437
        console.log('Server responded: ' + error);
438

    
439
        this.showLoading = false;
440
    }
441
}
(2-2/2)