Project

General

Profile

« Previous | Next » 

Revision 57884

[Monitor Dashboard | Trunk]: Reset user menu items before build

View differences:

modules/uoa-monitor-portal/trunk/monitor_dashboard/src/app/monitor/monitor.component.ts
25 25
import {UserManagementService} from "../openaireLibrary/services/user-management.service";
26 26

  
27 27
@Component({
28
    selector: 'monitor',
29
    templateUrl: 'monitor.component.html',
28
  selector: 'monitor',
29
  templateUrl: 'monitor.component.html',
30 30
})
31 31
export class MonitorComponent implements OnInit, OnDestroy, IDeactivateComponent {
32
    private static sidebarStatus: {
33
        id;
34
        status;
35
    };
36
    public user: User;
37
    public userMenuItems: MenuItem[] = [new MenuItem("", "My profile", "", "", false, [], [], {})];
38
    public subscriptions: any[] = [];
39
    public piwiksub: any;
40
    public pageContents = null;
41
    public divContents = null;
42
    public status: number;
43
    public loading: boolean = true;
44
    public indicatorUtils: IndicatorUtils = new IndicatorUtils();
45
    public stakeholderUtils: StakeholderUtils = new StakeholderUtils();
46
    public activeTopic: Topic = null;
47
    public activeCategory: Category = null;
48
    public activeSubCategory: SubCategory = null;
49
    public sideBar: Sidebar = null;
50
    public errorCodes: ErrorCodes;
51
    public stakeholder: Stakeholder;
52
    public numberResults: Map<number, number> = new Map<number, number>();
53
    public chartsActiveType: Map<number, IndicatorPath> = new Map<number, IndicatorPath>();
54
    private errorMessages: ErrorMessagesComponent;
55
    properties: EnvProperties;
56
    fundingL0;
57
    startYear;
58
    endYear;
59

  
60
    public keyword: FormControl;
61

  
62
    constructor(
63
      private route: ActivatedRoute,
64
      private _router: Router,
65
      private _meta: Meta,
66
      private _title: Title,
67
      private _piwikService: PiwikService,
68
      private helper: HelperService,
69
      private stakeholderService: StakeholderService,
70
      private userManagementService: UserManagementService,
71
      private statisticsService: StatisticsService,
72
      private layoutService: LayoutService,
73
      private seoService: SEOService,
74
      private cdr: ChangeDetectorRef,
75
      private sanitizer: DomSanitizer, private _fb: FormBuilder) {
76
        this.errorCodes = new ErrorCodes();
77
        this.errorMessages = new ErrorMessagesComponent();
78
        this.status = this.errorCodes.LOADING;
79
    }
80

  
81
    public ngOnInit() {
82
        this.keyword = this._fb.control('');
83
        this.keyword.valueChanges.subscribe(value => {
84
            console.log("Keyword Changed!");
85
            //TODO do a real action
32
  private static sidebarStatus: {
33
    id;
34
    status;
35
  };
36
  public user: User;
37
  public userMenuItems: MenuItem[] = [new MenuItem("", "My profile", "", "", false, [], [], {})];
38
  public subscriptions: any[] = [];
39
  public piwiksub: any;
40
  public pageContents = null;
41
  public divContents = null;
42
  public status: number;
43
  public loading: boolean = true;
44
  public indicatorUtils: IndicatorUtils = new IndicatorUtils();
45
  public stakeholderUtils: StakeholderUtils = new StakeholderUtils();
46
  public activeTopic: Topic = null;
47
  public activeCategory: Category = null;
48
  public activeSubCategory: SubCategory = null;
49
  public sideBar: Sidebar = null;
50
  public errorCodes: ErrorCodes;
51
  public stakeholder: Stakeholder;
52
  public numberResults: Map<number, number> = new Map<number, number>();
53
  public chartsActiveType: Map<number, IndicatorPath> = new Map<number, IndicatorPath>();
54
  private errorMessages: ErrorMessagesComponent;
55
  properties: EnvProperties;
56
  fundingL0;
57
  startYear;
58
  endYear;
59
  
60
  public keyword: FormControl;
61
  
62
  constructor(
63
    private route: ActivatedRoute,
64
    private _router: Router,
65
    private _meta: Meta,
66
    private _title: Title,
67
    private _piwikService: PiwikService,
68
    private helper: HelperService,
69
    private stakeholderService: StakeholderService,
70
    private userManagementService: UserManagementService,
71
    private statisticsService: StatisticsService,
72
    private layoutService: LayoutService,
73
    private seoService: SEOService,
74
    private cdr: ChangeDetectorRef,
75
    private sanitizer: DomSanitizer, private _fb: FormBuilder) {
76
    this.errorCodes = new ErrorCodes();
77
    this.errorMessages = new ErrorMessagesComponent();
78
    this.status = this.errorCodes.LOADING;
79
  }
80
  
81
  public ngOnInit() {
82
    this.keyword = this._fb.control('');
83
    this.keyword.valueChanges.subscribe(value => {
84
      console.log("Keyword Changed!");
85
      //TODO do a real action
86
    });
87
    this.route.data
88
      .subscribe((data: { envSpecific: EnvProperties }) => {
89
        let subscription: Subscription;
90
        this.route.params.subscribe(params => {
91
          if (subscription) {
92
            subscription.unsubscribe();
93
          }
94
          this.properties = data.envSpecific;
95
          var url = data.envSpecific.baseLink + this._router.url;
96
          if (!this.stakeholder || this.stakeholder.alias !== params['stakeholder']) {
97
            this.status = this.errorCodes.LOADING;
98
            this.numberResults = new Map<number, number>();
99
            this.chartsActiveType = new Map<number, IndicatorPath>();
100
            // subscription = this.stakeholderService.getStakeholderAsObservable().subscribe(stakeholder => {
101
            let stakeholder: Stakeholder = null;
102
            if (params['stakeholder'] == "fwf") {
103
              stakeholder = new Stakeholder(null, "funder", "fwf_________::FWF", "Austrian Science Fund (FWF)", "FWF",
104
                false, "fwf", true, true, null);
105
              stakeholder = this.stakeholderUtils.createFunderFromDefaultProfile(stakeholder, StakeholderCreator.createFunderDefaultProfile().topics);
106
              stakeholder.logoUrl = "./assets/fwf.png";
107
            } else if (params['stakeholder'] == "arc") {
108
              stakeholder = new Stakeholder(null, "funder", "arc_________::ARC",
109
                "Australian Research Council (ARC)", "ARC",
110
                false, null, true, true, null);
111
              stakeholder = this.stakeholderUtils.createFunderFromDefaultProfile(stakeholder, StakeholderCreator.createFunderDefaultProfile().topics);
112
              stakeholder.logoUrl = "./assets/arc1.gif";
113
            } else {
114
              stakeholder = new Stakeholder(null, "funder", "ec__________::EC",
115
                "European Commission", "EC",
116
                false, "ec", true, true, null);
117
              stakeholder = this.stakeholderUtils.createFunderFromDefaultProfile(stakeholder, StakeholderCreator.createFunderDefaultProfile().topics);
118
              stakeholder.logoUrl = "./assets/ec.png";
119
            }
120
            if (stakeholder) {
121
              this.stakeholder = stakeholder;
122
              this.seoService.createLinkForCanonicalURL(url, false);
123
              this._meta.updateTag({content: url}, "property='og:url'");
124
              var description = "Monitor Dashboard | " + this.stakeholder.index_name;
125
              var title = "Monitor Dashboard | " + this.stakeholder.index_shortName;
126
              this._meta.updateTag({content: description}, "name='description'");
127
              this._meta.updateTag({content: description}, "property='og:description'");
128
              this._meta.updateTag({content: title}, "property='og:title'");
129
              this._title.setTitle(title);
130
              if (this.properties.enablePiwikTrack && (typeof document !== 'undefined')) {
131
                this.piwiksub = this._piwikService.trackView(this.properties, title, this.properties.piwikSiteId).subscribe();
132
              }
133
              //this.getDivContents();
134
              this.getPageContents();
135
              this.status = this.errorCodes.DONE;
136
              this.setView(params);
137
            }
138
            // }, error => {
139
            //     this.navigateToError();
140
            // });
141
            this.subscriptions.push(subscription);
142
          } else {
143
            this.setView(params);
144
          }
145
          this.subscriptions.push(this.userManagementService.getUserInfo(this.properties.userInfoUrl).subscribe(user => {
146
            this.user = user;
147
            this.buildMenu();
148
          }, error => {
149
            console.log("App couldn't fetch properties");
150
            console.log(error);
151
          }));
86 152
        });
87
        this.route.data
88
            .subscribe((data: { envSpecific: EnvProperties }) => {
89
                let subscription: Subscription;
90
                this.route.params.subscribe(params => {
91
                    if(subscription) {
92
                        subscription.unsubscribe();
93
                    }
94
                    this.properties = data.envSpecific;
95
                    var url = data.envSpecific.baseLink + this._router.url;
96
                    if (!this.stakeholder || this.stakeholder.alias !== params['stakeholder']) {
97
                        this.status = this.errorCodes.LOADING;
98
                        this.numberResults = new Map<number, number>();
99
                        this.chartsActiveType = new Map<number, IndicatorPath>();
100
                        // subscription = this.stakeholderService.getStakeholderAsObservable().subscribe(stakeholder => {
101
                            let stakeholder: Stakeholder = null;
102
                            if (params['stakeholder'] == "fwf") {
103
                                stakeholder = new Stakeholder(null, "funder", "fwf_________::FWF", "Austrian Science Fund (FWF)", "FWF",
104
                                    false, "fwf", true, true, null);
105
                                stakeholder = this.stakeholderUtils.createFunderFromDefaultProfile(stakeholder, StakeholderCreator.createFunderDefaultProfile().topics);
106
                                stakeholder.logoUrl = "./assets/fwf.png";
107
                            } else if (params['stakeholder'] == "arc") {
108
                                stakeholder = new Stakeholder(null, "funder", "arc_________::ARC",
109
                                    "Australian Research Council (ARC)", "ARC",
110
                                    false, null, true, true, null);
111
                                stakeholder = this.stakeholderUtils.createFunderFromDefaultProfile(stakeholder, StakeholderCreator.createFunderDefaultProfile().topics);
112
                                stakeholder.logoUrl = "./assets/arc1.gif";
113
                            } else {
114
                                stakeholder = new Stakeholder(null, "funder", "ec__________::EC",
115
                                    "European Commission", "EC",
116
                                    false, "ec", true, true, null);
117
                                stakeholder = this.stakeholderUtils.createFunderFromDefaultProfile(stakeholder, StakeholderCreator.createFunderDefaultProfile().topics);
118
                                stakeholder.logoUrl = "./assets/ec.png";
119
                            }
120
                            if (stakeholder) {
121
                                this.stakeholder = stakeholder;
122
                                this.seoService.createLinkForCanonicalURL(url, false);
123
                                this._meta.updateTag({content: url}, "property='og:url'");
124
                                var description = "Monitor Dashboard | " + this.stakeholder.index_name;
125
                                var title = "Monitor Dashboard | " + this.stakeholder.index_shortName;
126
                                this._meta.updateTag({content: description}, "name='description'");
127
                                this._meta.updateTag({content: description}, "property='og:description'");
128
                                this._meta.updateTag({content: title}, "property='og:title'");
129
                                this._title.setTitle(title);
130
                                if (this.properties.enablePiwikTrack && (typeof document !== 'undefined')) {
131
                                    this.piwiksub = this._piwikService.trackView(this.properties, title, this.properties.piwikSiteId).subscribe();
132
                                }
133
                                //this.getDivContents();
134
                                this.getPageContents();
135
                                this.status = this.errorCodes.DONE;
136
                                this.setView(params);
137
                            }
138
                        // }, error => {
139
                        //     this.navigateToError();
140
                        // });
141
                        this.subscriptions.push(subscription);
142
                    } else {
143
                        this.setView(params);
144
                    }
145
                  this.subscriptions.push(this.userManagementService.getUserInfo(this.properties.userInfoUrl).subscribe(user => {
146
                    this.user = user;
147
                    this.buildMenu();
148
                  }, error => {
149
                    console.log("App couldn't fetch properties");
150
                    console.log(error);
151
                  }));
152
                });
153
            });
153
      });
154
  }
155
  
156
  canExit() {
157
    if (this.sideBar) {
158
      let status = [];
159
      this.sideBar.items.forEach(item => {
160
        status.push(item.open);
161
      });
162
      MonitorComponent.sidebarStatus = {
163
        id: this.activeTopic.alias,
164
        status: status
165
      };
154 166
    }
155

  
156
    canExit() {
157
        if (this.sideBar) {
158
            let status = [];
159
            this.sideBar.items.forEach(item => {
160
                status.push(item.open);
161
            });
162
            MonitorComponent.sidebarStatus = {
163
                id: this.activeTopic.alias,
164
                status: status
165
            };
166
        }
167
        return true;
167
    return true;
168
  }
169
  
170
  public get open() {
171
    return this.layoutService.open;
172
  }
173
  
174
  public toggleOpen(event = null) {
175
    if (!event) {
176
      this.layoutService.setOpen(!this.open);
177
    } else if (event && event['value'] === true) {
178
      this.layoutService.setOpen(false);
168 179
    }
169

  
170
    public get open() {
171
        return this.layoutService.open;
172
    }
173

  
174
    public toggleOpen(event = null) {
175
        if (!event) {
176
            this.layoutService.setOpen(!this.open);
177
        } else if (event && event['value'] === true) {
178
            this.layoutService.setOpen(false);
180
  }
181
  
182
  private getPageContents() {
183
    this.helper.getPageHelpContents(this._router.url, this.properties, 'monitor').subscribe(contents => {
184
      this.pageContents = contents;
185
    })
186
  }
187
  
188
  private getDivContents() {
189
    this.helper.getDivHelpContents(this._router.url, this.properties, 'monitor').subscribe(contents => {
190
      this.divContents = contents;
191
    })
192
  }
193
  
194
  private setView(params: Params) {
195
    if (params['topic']) {
196
      this.activeTopic = this.stakeholder.topics.find(topic => topic.alias === decodeURIComponent(params['topic']) && topic.isPublic && topic.isActive);
197
      if (this.activeTopic) {
198
        if (params['category']) {
199
          this.activeCategory = this.activeTopic.categories.find(category =>
200
            (category.alias === params['category']) && category.isPublic && category.isActive);
201
          if (!this.activeCategory) {
202
            this.navigateToError();
203
            return;
204
          }
205
        } else {
206
          this.activeCategory = this.activeTopic.categories.find(category => category.isPublic && category.isActive);
207
          if (this.activeCategory) {
208
            this.activeSubCategory = this.activeCategory.subCategories.find(subCategory =>
209
              subCategory.isPublic && subCategory.isActive);
210
            this.setSideBar();
211
            if (this.activeSubCategory) {
212
              this.setIndicators();
213
            }
214
          } else {
215
            this.setSideBar();
216
          }
217
          return;
179 218
        }
180
    }
181

  
182
    private getPageContents() {
183
        this.helper.getPageHelpContents(this._router.url, this.properties, 'monitor').subscribe(contents => {
184
            this.pageContents = contents;
185
        })
186
    }
187

  
188
    private getDivContents() {
189
        this.helper.getDivHelpContents(this._router.url, this.properties, 'monitor').subscribe(contents => {
190
            this.divContents = contents;
191
        })
192
    }
193

  
194
    private setView(params: Params) {
195
        if (params['topic']) {
196
            this.activeTopic = this.stakeholder.topics.find(topic => topic.alias === decodeURIComponent(params['topic']) && topic.isPublic && topic.isActive);
197
            if (this.activeTopic) {
198
                if (params['category']) {
199
                    this.activeCategory = this.activeTopic.categories.find(category =>
200
                        (category.alias === params['category']) && category.isPublic && category.isActive);
201
                    if(!this.activeCategory) {
202
                        this.navigateToError();
203
                        return;
204
                    }
205
                } else {
206
                    this.activeCategory = this.activeTopic.categories.find(category => category.isPublic && category.isActive);
207
                    if (this.activeCategory) {
208
                        this.activeSubCategory = this.activeCategory.subCategories.find(subCategory =>
209
                            subCategory.isPublic && subCategory.isActive);
210
                        this.setSideBar();
211
                        if (this.activeSubCategory) {
212
                            this.setIndicators();
213
                        }
214
                    } else {
215
                        this.setSideBar();
216
                    }
217
                    return;
218
                }
219
                if (this.activeCategory) {
220
                    if (params['subCategory']) {
221
                        this.activeSubCategory = this.activeCategory.subCategories.find(subCategory =>
222
                            (subCategory.alias === params['subCategory'] && subCategory.isPublic && subCategory.isActive));
223
                        if(!this.activeSubCategory) {
224
                            this.navigateToError();
225
                            return;
226
                        }
227
                    } else {
228
                        this.activeSubCategory = this.activeCategory.subCategories.find(subCategory =>
229
                          subCategory.isPublic && subCategory.isActive);
230
                    }
231
                    if (this.activeSubCategory) {
232
                        this.setSideBar();
233
                        this.setIndicators();
234
                    } else {
235
                        this.navigateToError();
236
                    }
237
                    return;
238
                } else {
239
                    this.activeSubCategory = null;
240
                }
241
            } else {
242
                this.navigateToError();
243
                return;
219
        if (this.activeCategory) {
220
          if (params['subCategory']) {
221
            this.activeSubCategory = this.activeCategory.subCategories.find(subCategory =>
222
              (subCategory.alias === params['subCategory'] && subCategory.isPublic && subCategory.isActive));
223
            if (!this.activeSubCategory) {
224
              this.navigateToError();
225
              return;
244 226
            }
227
          } else {
228
            this.activeSubCategory = this.activeCategory.subCategories.find(subCategory =>
229
              subCategory.isPublic && subCategory.isActive);
230
          }
231
          if (this.activeSubCategory) {
232
            this.setSideBar();
233
            this.setIndicators();
234
          } else {
235
            this.navigateToError();
236
          }
237
          return;
245 238
        } else {
246
            this.activeTopic = this.stakeholder.topics.find(topic => topic.isPublic && topic.isActive);
247
            if (this.activeTopic) {
248
                this.activeCategory = this.activeTopic.categories.find(category => category.isPublic && category.isActive);
249
                if (this.activeCategory) {
250
                    this.activeSubCategory = this.activeCategory.subCategories.find(subCategory => subCategory.isPublic && subCategory.isActive);
251
                    if (this.activeSubCategory) {
252
                        this.setSideBar();
253
                        this.setIndicators();
254
                    } else {
255
                        this.navigateToError();
256
                    }
257
                } else {
258
                    this.navigateToError();
259
                }
260
            } else {
261
                this.navigateToError();
262
            }
239
          this.activeSubCategory = null;
263 240
        }
241
      } else {
242
        this.navigateToError();
243
        return;
244
      }
245
    } else {
246
      this.activeTopic = this.stakeholder.topics.find(topic => topic.isPublic && topic.isActive);
247
      if (this.activeTopic) {
248
        this.activeCategory = this.activeTopic.categories.find(category => category.isPublic && category.isActive);
249
        if (this.activeCategory) {
250
          this.activeSubCategory = this.activeCategory.subCategories.find(subCategory => subCategory.isPublic && subCategory.isActive);
251
          if (this.activeSubCategory) {
252
            this.setSideBar();
253
            this.setIndicators();
254
          } else {
255
            this.navigateToError();
256
          }
257
        } else {
258
          this.navigateToError();
259
        }
260
      } else {
261
        this.navigateToError();
262
      }
264 263
    }
265

  
266
    private setSideBar() {
267
        let items: Item[] = [];
268
        this.activeTopic.categories.forEach((category, index) => {
269
            if (category.isPublic && category.isActive) {
270
                let subItems: Item[] = [];
271
                category.subCategories.forEach(subCategory => {
272
                    if (subCategory.isPublic && subCategory.isActive) {
273
                        subItems.push(new Item(subCategory.alias, subCategory.name, (
274
                          '/' + this.stakeholder.alias + '/' + this.activeTopic.alias + '/' + category.alias + '/' + subCategory.alias),
275
                          null, null, false));
276
                    }
277
                });
278
                let open = this.activeCategory.alias === category.alias;
279
                if (MonitorComponent.sidebarStatus && MonitorComponent.sidebarStatus.id === this.activeTopic.alias) {
280
                    open = MonitorComponent.sidebarStatus.status[index];
281
                }
282
                items.push(new Item(category.alias, category.name, (
283
                  '/' + this.stakeholder.alias + '/' + this.activeTopic.alias + '/' + category.alias),
284
                  subItems, null, open));
285
            }
264
  }
265
  
266
  private setSideBar() {
267
    let items: Item[] = [];
268
    this.activeTopic.categories.forEach((category, index) => {
269
      if (category.isPublic && category.isActive) {
270
        let subItems: Item[] = [];
271
        category.subCategories.forEach(subCategory => {
272
          if (subCategory.isPublic && subCategory.isActive) {
273
            subItems.push(new Item(subCategory.alias, subCategory.name, (
274
              '/' + this.stakeholder.alias + '/' + this.activeTopic.alias + '/' + category.alias + '/' + subCategory.alias),
275
              null, null, false));
276
          }
286 277
        });
287
        if(items.length === 0) {
288
            items.push(new Item('noCategories', 'No categories available yet', null, [], null, false));
278
        let open = this.activeCategory.alias === category.alias;
279
        if (MonitorComponent.sidebarStatus && MonitorComponent.sidebarStatus.id === this.activeTopic.alias) {
280
          open = MonitorComponent.sidebarStatus.status[index];
289 281
        }
290
        this.sideBar = new Sidebar(items, null);
282
        items.push(new Item(category.alias, category.name, (
283
          '/' + this.stakeholder.alias + '/' + this.activeTopic.alias + '/' + category.alias),
284
          subItems, null, open));
285
      }
286
    });
287
    if (items.length === 0) {
288
      items.push(new Item('noCategories', 'No categories available yet', null, [], null, false));
291 289
    }
292

  
293
    private setIndicators() {
294
        let urls: Map<string, number[]> = new Map<string, number[]>();
295
        this.activeSubCategory.numbers.forEach((number, index) => {
296
            if (number.isActive && number.isPublic) {
297
                let url = number.indicatorPaths[0].url;
298
                //add fundingLevel0 filter in the query
299
                if (this.fundingL0 && number.indicatorPaths[0].filters.get("fundingL0")) {
300
                    url = url + number.indicatorPaths[0].filters.get("fundingL0").replace(ChartHelper.prefix + 'fundingL0' + ChartHelper.suffix, encodeURIComponent(this.fundingL0));
301
                }
302
                const pair = JSON.stringify([number.indicatorPaths[0].source, url]);
303
                const indexes = urls.get(pair) ? urls.get(pair) : [];
304
                indexes.push(index);
305
                urls.set(pair, indexes);
290
    this.sideBar = new Sidebar(items, null);
291
  }
292
  
293
  private setIndicators() {
294
    let urls: Map<string, number[]> = new Map<string, number[]>();
295
    this.activeSubCategory.numbers.forEach((number, index) => {
296
      if (number.isActive && number.isPublic) {
297
        let url = number.indicatorPaths[0].url;
298
        //add fundingLevel0 filter in the query
299
        if (this.fundingL0 && number.indicatorPaths[0].filters.get("fundingL0")) {
300
          url = url + number.indicatorPaths[0].filters.get("fundingL0").replace(ChartHelper.prefix + 'fundingL0' + ChartHelper.suffix, encodeURIComponent(this.fundingL0));
301
        }
302
        const pair = JSON.stringify([number.indicatorPaths[0].source, url]);
303
        const indexes = urls.get(pair) ? urls.get(pair) : [];
304
        indexes.push(index);
305
        urls.set(pair, indexes);
306
      }
307
    });
308
    urls.forEach((indexes, pair) => {
309
      pair = JSON.parse(pair);
310
      this.statisticsService.getNumbers(pair[0], pair[1]).subscribe(response => {
311
        indexes.forEach(index => {
312
          let result = JSON.parse(JSON.stringify(response));
313
          this.activeSubCategory.numbers[index].indicatorPaths[0].jsonPath.forEach(jsonPath => {
314
            if (result) {
315
              result = result[jsonPath];
306 316
            }
317
          });
318
          this.numberResults.set(index, result);
307 319
        });
308
        urls.forEach((indexes, pair) => {
309
            pair = JSON.parse(pair);
310
            this.statisticsService.getNumbers(pair[0], pair[1]).subscribe(response => {
311
                indexes.forEach(index => {
312
                    let result = JSON.parse(JSON.stringify(response));
313
                    this.activeSubCategory.numbers[index].indicatorPaths[0].jsonPath.forEach(jsonPath => {
314
                        if (result) {
315
                            result = result[jsonPath];
316
                        }
317
                    });
318
                    this.numberResults.set(index, result);
319
                });
320
            })
321
        });
322
        this.activeSubCategory.charts.forEach((chart, index) => {
323
            if (chart.indicatorPaths.length > 0) {
324
                chart.indicatorPaths[0].safeResourceUrl = this.getUrlByStakeHolder(chart.indicatorPaths[0]);
325
                this.chartsActiveType.set(index, chart.indicatorPaths[0]);
326
            }
327
        });
328
        this.cdr.detectChanges();
320
      })
321
    });
322
    this.activeSubCategory.charts.forEach((chart, index) => {
323
      if (chart.indicatorPaths.length > 0) {
324
        chart.indicatorPaths[0].safeResourceUrl = this.getUrlByStakeHolder(chart.indicatorPaths[0]);
325
        this.chartsActiveType.set(index, chart.indicatorPaths[0]);
326
      }
327
    });
328
    this.cdr.detectChanges();
329
  }
330
  
331
  public getUrlByStakeHolder(indicatorPath: IndicatorPath) {
332
    return this.sanitizer.bypassSecurityTrustResourceUrl(
333
      this.statisticsService.getChartUrl(indicatorPath.source, this.indicatorUtils.getFullUrl(indicatorPath, this.fundingL0, this.startYear, this.endYear)));
334
  }
335
  
336
  public setActiveChart(index, type: string) {
337
    let activeChart = this.activeSubCategory.charts[index].indicatorPaths.filter(indicatorPath => indicatorPath.type === type)[0];
338
    activeChart.safeResourceUrl = this.getUrlByStakeHolder(activeChart);
339
    this.chartsActiveType.set(index, activeChart);
340
  }
341
  
342
  private navigateToError() {
343
    this._router.navigate(['/error'], {queryParams: {'page': this._router.url}});
344
  }
345
  
346
  public navigateTo(stakeholder: string, topic: string, category: string = null, subcategory: string = null) {
347
    let url = stakeholder + '/' + topic + ((category) ? ('/'
348
      + category) : '') + ((subcategory) ? ('/' + subcategory) : '');
349
    return this._router.navigate([url]);
350
  }
351
  
352
  public quote(param: string): string {
353
    return StringUtils.quote(param);
354
  }
355
  
356
  public ngOnDestroy() {
357
    if (this.piwiksub) {
358
      this.piwiksub.unsubscribe();
329 359
    }
330

  
331
    public getUrlByStakeHolder(indicatorPath: IndicatorPath) {
332
        return this.sanitizer.bypassSecurityTrustResourceUrl(
333
          this.statisticsService.getChartUrl(indicatorPath.source, this.indicatorUtils.getFullUrl(indicatorPath, this.fundingL0, this.startYear, this.endYear)));
334
    }
335

  
336
    public setActiveChart(index, type: string) {
337
        let activeChart = this.activeSubCategory.charts[index].indicatorPaths.filter(indicatorPath => indicatorPath.type === type)[0];
338
        activeChart.safeResourceUrl = this.getUrlByStakeHolder(activeChart);
339
        this.chartsActiveType.set(index, activeChart);
340
    }
341

  
342
    private navigateToError() {
343
        this._router.navigate(['/error'], {queryParams: {'page': this._router.url}});
344
    }
345

  
346
    public navigateTo(stakeholder: string, topic: string, category: string = null, subcategory: string = null) {
347
        let url = stakeholder + '/' + topic + ((category) ? ('/'
348
          + category) : '') + ((subcategory) ? ('/' + subcategory) : '');
349
        return this._router.navigate([url]);
350
    }
351

  
352
    public quote(param: string): string {
353
        return StringUtils.quote(param);
354
    }
355

  
356
    public ngOnDestroy() {
357
        if (this.piwiksub) {
358
            this.piwiksub.unsubscribe();
359
        }
360
    }
361

  
360
  }
361
  
362 362
  buildMenu() {
363
    this.userMenuItems = [];
363 364
    if (Session.isPortalAdministrator(this.user)) {
364 365
      this.userMenuItems.push(new MenuItem("", "Manage helptexts",
365 366
        ((this.properties.environment == "beta") ? "https://beta.admin.connect.openaire.eu" : "https://admin.explore.openaire.eu") + "/dashboard?communityId=openaire", "", true, [], [], {}))
366

  
367
      
367 368
    }
368
    if(this.user) {
369
    if (this.user) {
369 370
      this.userMenuItems.push(new MenuItem("", "User information", "", "/user-info", false, [], [], {}));
370 371
    }
371 372
  }
modules/uoa-monitor-portal/trunk/monitor_dashboard/src/app/app.component.ts
17 17
export class AppComponent implements OnInit, OnDestroy {
18 18
    properties: EnvProperties;
19 19
    user: User;
20
    loginCheck: boolean = false;
21 20
    hasSidebar: boolean = false;
22 21
    hasHeader: boolean = false;
23 22
    userMenuItems: MenuItem[] = [new MenuItem("", "My profile", "", "", false, [], [], {})];
......
65 64
                }));
66 65
                this.subscriptions.push(this.userManagementService.getUserInfo(this.properties.userInfoUrl).subscribe(user => {
67 66
                    this.user = user;
68
                    this.loginCheck = true;
69 67
                    this.buildMenu();
70 68
                }, error => {
71 69
                    console.log("App couldn't fetch properties");
......
96 94

  
97 95

  
98 96
    buildMenu() {
97
        this.userMenuItems = [];
99 98
        if (Session.isPortalAdministrator(this.user)) {
100 99
            this.userMenuItems.push(new MenuItem("", "Manage helptexts",
101 100
                ((this.properties.environment == "beta") ? "https://beta.admin.connect.openaire.eu" : "https://admin.explore.openaire.eu") + "/dashboard?communityId=openaire", "", true, [], [], {}))

Also available in: Unified diff