Project

General

Profile

« Previous | Next » 

Revision 57805

[MonitorDashboard]: Sidebar: add activeItem and subItem to check which element is active

View differences:

modules/uoa-monitor-portal/trunk/monitor_dashboard/src/app/monitor/monitor.component.html
72 72
        </div>
73 73
      </nav>
74 74
    </div>
75
    <dashboard-sidebar *ngIf="sideBar && stakeholder" [items]="sideBar.items" [name]="stakeholder.index_name"
76
                       [showHeader]=false
75
    <dashboard-sidebar *ngIf="sideBar && stakeholder" [items]="sideBar.items"
76
                       [activeItem]="activeCategory?activeCategory.alias:null"
77
                       [activeSubItem]="activeSubCategory?activeSubCategory.alias:null" [showHeader]=false
77 78
    ></dashboard-sidebar>
78 79
    <div *ngIf="activeSubCategory"
79 80
         id="page_content" click-outside-or-esc targetId="page_content" [escClose]="false"
modules/uoa-monitor-portal/trunk/monitor_dashboard/src/app/monitor/monitor.component.ts
20 20
import {FormBuilder, FormControl} from "@angular/forms";
21 21

  
22 22
@Component({
23
  selector: 'monitor',
24
  templateUrl: 'monitor.component.html',
23
    selector: 'monitor',
24
    templateUrl: 'monitor.component.html',
25 25
})
26 26
export class MonitorComponent implements OnInit, OnDestroy {
27
  public piwiksub: any;
28
  public pageContents = null;
29
  public divContents = null;
30
  public status: number;
31
  public loading: boolean = true;
32
  public indicatorUtils: IndicatorUtils = new IndicatorUtils();
33
  public stakeholderUtils: StakeholderUtils = new StakeholderUtils();
34
  public activeTopic: Topic = null;
35
  public activeCategory: Category = null;
36
  public activeSubCategory: SubCategory = null;
37
  public sideBar: Sidebar = null;
38
  public errorCodes: ErrorCodes;
39
  public stakeholder: Stakeholder;
40
  public numberResults: Map<number, number> = new Map<number, number>();
41
  public chartsActiveType: Map<number, IndicatorPath> = new Map<number, IndicatorPath>();
42
  private errorMessages: ErrorMessagesComponent;
43
  properties: EnvProperties;
44
  fundingL0;
45
  startYear;
46
  endYear;
27
    public piwiksub: any;
28
    public pageContents = null;
29
    public divContents = null;
30
    public status: number;
31
    public loading: boolean = true;
32
    public indicatorUtils: IndicatorUtils = new IndicatorUtils();
33
    public stakeholderUtils: StakeholderUtils = new StakeholderUtils();
34
    public activeTopic: Topic = null;
35
    public activeCategory: Category = null;
36
    public activeSubCategory: SubCategory = null;
37
    public sideBar: Sidebar = null;
38
    public errorCodes: ErrorCodes;
39
    public stakeholder: Stakeholder;
40
    public numberResults: Map<number, number> = new Map<number, number>();
41
    public chartsActiveType: Map<number, IndicatorPath> = new Map<number, IndicatorPath>();
42
    private errorMessages: ErrorMessagesComponent;
43
    properties: EnvProperties;
44
    fundingL0;
45
    startYear;
46
    endYear;
47 47

  
48
  public keyword:FormControl;
48
    public keyword: FormControl;
49 49

  
50
  constructor(
51
    private route: ActivatedRoute,
52
    private _router: Router,
53
    private _meta: Meta,
54
    private _title: Title,
55
    private _piwikService: PiwikService,
56
    private helper: HelperService,
57
    private stakeholderService: StakeholderService,
58
    private statisticsService: StatisticsService,
59
    private layoutService: LayoutService,
60
    private seoService: SEOService,
61
    private cdr: ChangeDetectorRef,
62
    private sanitizer: DomSanitizer, private _fb: FormBuilder) {
63
      this.errorCodes = new ErrorCodes();
64
      this.errorMessages = new ErrorMessagesComponent();
65
      this.status = this.errorCodes.LOADING;
66
  }
50
    constructor(
51
        private route: ActivatedRoute,
52
        private _router: Router,
53
        private _meta: Meta,
54
        private _title: Title,
55
        private _piwikService: PiwikService,
56
        private helper: HelperService,
57
        private stakeholderService: StakeholderService,
58
        private statisticsService: StatisticsService,
59
        private layoutService: LayoutService,
60
        private seoService: SEOService,
61
        private cdr: ChangeDetectorRef,
62
        private sanitizer: DomSanitizer, private _fb: FormBuilder) {
63
        this.errorCodes = new ErrorCodes();
64
        this.errorMessages = new ErrorMessagesComponent();
65
        this.status = this.errorCodes.LOADING;
66
    }
67 67

  
68
  public ngOnInit() {
69
    this.keyword = this._fb.control('');
70
    this.keyword.valueChanges.subscribe(value=>{
71
      console.log("KEyword Changed!");
72
      //TODO do a real action
73
    });
74
    this.layoutService.setHasSidebar(false);
75
    this.layoutService.setHasHeader(false);
76
    this.route.data
77
      .subscribe((data: { envSpecific: EnvProperties }) => {
78
        this.route.params.subscribe(params => {
79
          this.properties = data.envSpecific;
80
          var url = data.envSpecific.baseLink + this._router.url;
81
          if (!this.stakeholder || this.stakeholder.index_id !== params['stakeholder']) {
82
            this.status = this.errorCodes.LOADING;
83
            this.numberResults = new Map<number, number>();
84
            this.chartsActiveType = new Map<number, IndicatorPath>();
85
            // this.stakeholderService.getStakeholderAsObservable().subscribe(stakeholder => {
86
            let stakeholder:Stakeholder = null;
87
            if(params['stakeholder']=="fwf"){
88
              stakeholder = new Stakeholder("fwf", "funder", "fwf_________::FWF","Austrian Science Fund (FWF)","FWF",
89
              false,"fwf",true,true, null);
90
              stakeholder = this.stakeholderUtils.
91
              createFunderFromDefaultProfile(stakeholder, StakeholderCreator.createFunderDefaultProfile().topics);
92
              stakeholder.logoUrl = "./assets/fwf.png";
93
            }else if(params['stakeholder']=="arc"){
94
              stakeholder = new Stakeholder("arc","funder","arc_________::ARC",
95
                "Australian Research Council (ARC)","ARC",
96
                false,"arc",true,true, null);
97
              stakeholder = this.stakeholderUtils.
98
              createFunderFromDefaultProfile(stakeholder, StakeholderCreator.createFunderDefaultProfile().topics);
99
              stakeholder.logoUrl = "./assets/arc1.gif";
100
            }else{
101
              stakeholder = new Stakeholder("ec","funder","ec__________::EC",
102
                "European Commission","EC",
103
                false,"ec",true,true, null);
104
              stakeholder = this.stakeholderUtils.
105
              createFunderFromDefaultProfile(stakeholder, StakeholderCreator.createFunderDefaultProfile().topics);
106
              stakeholder.logoUrl = "./assets/ec.png";
107
            }
108

  
109
              if(stakeholder) {
110
                this.stakeholder = stakeholder;
111
                this.seoService.createLinkForCanonicalURL(url, false);
112
                this._meta.updateTag({content: url}, "property='og:url'");
113
                var description = "Monitor Dashboard | " + this.stakeholder.index_name;
114
                var title = "Monitor Dashboard | " + this.stakeholder.index_shortName;
115
                this._meta.updateTag({content: description}, "name='description'");
116
                this._meta.updateTag({content: description}, "property='og:description'");
117
                this._meta.updateTag({content: title}, "property='og:title'");
118
                this._title.setTitle(title);
119
                if (this.properties.enablePiwikTrack && (typeof document !== 'undefined')) {
120
                  this.piwiksub = this._piwikService.trackView(this.properties, title, this.properties.piwikSiteId).subscribe();
121
                }
122
                //this.getDivContents();
123
                this.getPageContents();
124
                this.status = this.errorCodes.DONE;
125
                this.setView(params);
126
              }
127
            // }, error => {
128
            //   this.navigateToError();
129
            // })
130
          } else {
131
            this.setView(params);
132
          }
68
    public ngOnInit() {
69
        this.keyword = this._fb.control('');
70
        this.keyword.valueChanges.subscribe(value => {
71
            console.log("KEyword Changed!");
72
            //TODO do a real action
133 73
        });
134
      });
135
  }
74
        this.layoutService.setHasSidebar(false);
75
        this.layoutService.setHasHeader(false);
76
        this.route.data
77
            .subscribe((data: { envSpecific: EnvProperties }) => {
78
                this.route.params.subscribe(params => {
79
                    this.properties = data.envSpecific;
80
                    var url = data.envSpecific.baseLink + this._router.url;
81
                    if (!this.stakeholder || this.stakeholder.index_id !== params['stakeholder']) {
82
                        this.status = this.errorCodes.LOADING;
83
                        this.numberResults = new Map<number, number>();
84
                        this.chartsActiveType = new Map<number, IndicatorPath>();
85
                        // this.stakeholderService.getStakeholderAsObservable().subscribe(stakeholder => {
86
                        let stakeholder: Stakeholder = null;
87
                        if (params['stakeholder'] == "fwf") {
88
                            stakeholder = new Stakeholder("fwf", "funder", "fwf_________::FWF", "Austrian Science Fund (FWF)", "FWF",
89
                                false, "fwf", true, true, null);
90
                            stakeholder = this.stakeholderUtils.createFunderFromDefaultProfile(stakeholder, StakeholderCreator.createFunderDefaultProfile().topics);
91
                            stakeholder.logoUrl = "./assets/fwf.png";
92
                        } else if (params['stakeholder'] == "arc") {
93
                            stakeholder = new Stakeholder("arc", "funder", "arc_________::ARC",
94
                                "Australian Research Council (ARC)", "ARC",
95
                                false, "arc", true, true, null);
96
                            stakeholder = this.stakeholderUtils.createFunderFromDefaultProfile(stakeholder, StakeholderCreator.createFunderDefaultProfile().topics);
97
                            stakeholder.logoUrl = "./assets/arc1.gif";
98
                        } else {
99
                            stakeholder = new Stakeholder("ec", "funder", "ec__________::EC",
100
                                "European Commission", "EC",
101
                                false, "ec", true, true, null);
102
                            stakeholder = this.stakeholderUtils.createFunderFromDefaultProfile(stakeholder, StakeholderCreator.createFunderDefaultProfile().topics);
103
                            stakeholder.logoUrl = "./assets/ec.png";
104
                        }
105
                        if (stakeholder) {
106
                            this.stakeholder = stakeholder;
107
                            this.seoService.createLinkForCanonicalURL(url, false);
108
                            this._meta.updateTag({content: url}, "property='og:url'");
109
                            var description = "Monitor Dashboard | " + this.stakeholder.index_name;
110
                            var title = "Monitor Dashboard | " + this.stakeholder.index_shortName;
111
                            this._meta.updateTag({content: description}, "name='description'");
112
                            this._meta.updateTag({content: description}, "property='og:description'");
113
                            this._meta.updateTag({content: title}, "property='og:title'");
114
                            this._title.setTitle(title);
115
                            if (this.properties.enablePiwikTrack && (typeof document !== 'undefined')) {
116
                                this.piwiksub = this._piwikService.trackView(this.properties, title, this.properties.piwikSiteId).subscribe();
117
                            }
118
                            //this.getDivContents();
119
                            this.getPageContents();
120
                            this.status = this.errorCodes.DONE;
121
                            this.setView(params);
122
                        }
123
                        // }, error => {
124
                        //   this.navigateToError();
125
                        // })
126
                    } else {
127
                        this.setView(params);
128
                    }
129
                });
130
            });
131
    }
136 132

  
137
  public get open() {
138
    return this.layoutService.open;
139
  }
133
    public get open() {
134
        return this.layoutService.open;
135
    }
140 136

  
141
  public toggleOpen(event = null) {
142
    if(!event) {
143
      this.layoutService.setOpen(!this.open);
144
    } else if(event && event['value'] === true) {
145
      this.layoutService.setOpen(false);
137
    public toggleOpen(event = null) {
138
        if (!event) {
139
            this.layoutService.setOpen(!this.open);
140
        } else if (event && event['value'] === true) {
141
            this.layoutService.setOpen(false);
142
        }
146 143
    }
147
  }
148 144

  
149
  private getPageContents() {
150
    this.helper.getPageHelpContents(this._router.url, this.properties, 'monitor').subscribe(contents => {
151
      this.pageContents = contents;
152
    })
153
  }
145
    private getPageContents() {
146
        this.helper.getPageHelpContents(this._router.url, this.properties, 'monitor').subscribe(contents => {
147
            this.pageContents = contents;
148
        })
149
    }
154 150

  
155
  private getDivContents() {
156
    this.helper.getDivHelpContents(this._router.url, this.properties, 'monitor').subscribe(contents => {
157
      this.divContents = contents;
158
    })
159
  }
151
    private getDivContents() {
152
        this.helper.getDivHelpContents(this._router.url, this.properties, 'monitor').subscribe(contents => {
153
            this.divContents = contents;
154
        })
155
    }
160 156

  
161
  private setView(params: Params) {
162
    if (params && params['topic']) {
163
      this.activeTopic = this.stakeholder.topics.filter(topic => topic.alias === decodeURIComponent(params['topic']))[0];
164
      if (this.activeTopic) {
165
        if (params['category']) {
166
          this.activeCategory = this.activeTopic.categories.filter(category =>
167
            (category.alias === params['category']) && category.isPublic && category.isActive)[0];
157
    private setView(params: Params) {
158
        if (params && params['topic']) {
159
            this.activeTopic = this.stakeholder.topics.
160
            find(topic => topic.alias === decodeURIComponent(params['topic']) && topic.isPublic && topic.isActive);
161
            if (this.activeTopic) {
162
                if (params['category']) {
163
                    this.activeCategory = this.activeTopic.categories.find(category =>
164
                        (category.alias === params['category']) && category.isPublic && category.isActive);
165
                } else {
166
                    this.activeCategory = this.activeTopic.categories.
167
                    find(category => category.isPublic && category.isActive);
168
                    if (this.activeCategory) {
169
                      this.activeSubCategory = this.activeCategory.subCategories.find(subCategory =>
170
                          subCategory.isPublic && subCategory.isActive);
171
                      if (this.activeSubCategory) {
172
                        this.setSideBar();
173
                        this.setIndicators();
174
                      } else {
175
                        this.navigateToError();
176
                      }
177
                    } else {
178
                        this.navigateToError();
179
                    }
180
                    return;
181
                }
182
                if (this.activeCategory) {
183
                    if (params['subCategory']) {
184
                        this.activeSubCategory = this.activeCategory.subCategories.find(subCategory =>
185
                            (subCategory.alias === params['subCategory'] && subCategory.isPublic && subCategory.isActive));
186
                    } else {
187
                        this.activeSubCategory = this.activeCategory.subCategories.find(subCategory =>
188
                            subCategory.isPublic && subCategory.isActive);
189
                    }
190
                    if (this.activeSubCategory) {
191
                        this.setSideBar();
192
                        this.setIndicators();
193
                    } else {
194
                       this.navigateToError();
195
                    }
196
                  return;
197
                }
198
            }
199
            this.navigateToError();
168 200
        } else {
169
          let category: Category = this.activeTopic.categories[0];
170
          if(category) {
171
            this.navigateTo(this.stakeholder.alias, this.activeTopic.alias, category.alias);
172
          } else {
173
            this.navigateToError();
174
          }
175
          return;
201
            this.activeTopic = this.stakeholder.topics.find(topic => topic.isPublic && topic.isActive);
202
            if(this.activeTopic) {
203
              this.activeCategory = this.activeTopic.categories.find(category => category.isPublic && category.isActive);
204
              if (this.activeCategory) {
205
                this.activeSubCategory = this.activeCategory.subCategories.find(subCategory => subCategory.isPublic && subCategory.isActive);
206
                if (this.activeSubCategory) {
207
                  this.setSideBar();
208
                  this.setIndicators();
209
                } else {
210
                  this.navigateToError();
211
                }
212
              } else {
213
                this.navigateToError();
214
              }
215
            } else {
216
              this.navigateToError();
217
            }
176 218
        }
177
        if (this.activeCategory) {
178
          if (params['subCategory']) {
179
            this.activeSubCategory = this.activeCategory.subCategories.filter(subCategory =>
180
              (subCategory.alias === params['subCategory'] && subCategory.isPublic && subCategory.isActive))[0];
181
          } else {
182
            this.activeSubCategory = this.activeCategory.subCategories.filter(subCategory =>
183
              !subCategory.alias && subCategory.isPublic && subCategory.isActive)[0];
184
          }
185
          if (this.activeSubCategory) {
186
            this.setSideBar();
187
            this.setIndicators();
188
            return;
189
          } else {
190
            let subCategory: SubCategory = this.activeCategory.subCategories.filter(subCategory =>
191
              subCategory.isPublic && subCategory.isActive)[0];
192
            this.navigateTo(this.stakeholder.alias, this.activeTopic.alias, this.activeCategory.alias, subCategory.alias);
193
            return;
194
          }
195
        }
196
      }
197
      this.navigateToError();
198
    } else {
199
      let topic: Topic = this.stakeholder.topics[0];
200
      let category: Category = topic.categories.filter(category => category.isPublic && category.isActive)[0];
201
      if(topic && category) {
202
        this.navigateTo(this.stakeholder.alias, topic.alias, category.alias);
203
      } else {
204
        this.navigateToError();
205
      }
206 219
    }
207
  }
208 220

  
209
  private setSideBar() {
210
    let items: Item[] = [];
211
    this.activeTopic.categories.forEach(category => {
212
      if (category.isPublic && category.isActive) {
213
        let subItems: Item[] = [];
214
        category.subCategories.forEach(subCategory => {
215
          if (subCategory.alias != null && subCategory.isPublic && subCategory.isActive) {
216
            subItems.push(new Item(subCategory.name, (
217
              '/' + this.stakeholder.alias + '/' + this.activeTopic.alias + '/' + category.alias + '/' + subCategory.alias),
218
              null, null, false));
219
          }
221
    private setSideBar() {
222
        let items: Item[] = [];
223
        this.activeTopic.categories.forEach(category => {
224
            if (category.isPublic && category.isActive) {
225
                let subItems: Item[] = [];
226
                category.subCategories.forEach(subCategory => {
227
                    if (subCategory.isPublic && subCategory.isActive) {
228
                        subItems.push(new Item(subCategory.alias, subCategory.name, (
229
                            '/' + this.stakeholder.alias + '/' + this.activeTopic.alias + '/' + category.alias + '/' + subCategory.alias),
230
                            null, null, false));
231
                    }
232
                });
233
                const open = this.activeCategory.alias === category.alias;
234
                items.push(new Item(category.alias, category.name, (
235
                    '/' + this.stakeholder.alias + '/' + this.activeTopic.alias + '/' + category.alias),
236
                    subItems, null, open));
237
            }
220 238
        });
221
        const open = this.activeCategory.alias === category.alias;
222
        items.push(new Item(category.name, (
223
          '/' +  this.stakeholder.alias + '/' + this.activeTopic.alias + '/' + category.alias),
224
          subItems, null, open));
225
      }
226
    });
227
    this.sideBar = new Sidebar(items, null);
228
  }
239
        this.sideBar = new Sidebar(items, null);
240
    }
229 241

  
230
  private setIndicators() {
231
    let urls: Map<string, number[]> = new Map<string, number[]>();
232
    this.activeSubCategory.numbers.forEach((number, index) => {
233
      if (number.isActive && number.isPublic) {
234
        let url = number.indicatorPaths[0].url;
235
        //add fundingLevel0 filter in the query
236
        if(this.fundingL0 && number.indicatorPaths[0].filters.get("fundingL0")){
237
          url = url + number.indicatorPaths[0].filters.get("fundingL0").replace(ChartHelper.prefix+'fundingL0'+ChartHelper.suffix,encodeURIComponent(this.fundingL0));
238
        }
239
        const pair = JSON.stringify([number.indicatorPaths[0].source, url]);
240
        const indexes = urls.get(pair) ? urls.get(pair) : [];
241
        indexes.push(index);
242
        urls.set(pair, indexes);
243
      }
244
    });
245
    urls.forEach((indexes, pair) => {
246
      pair = JSON.parse(pair);
247
      this.statisticsService.getNumbers(pair[0], pair[1]).subscribe(response => {
248
        indexes.forEach(index => {
249
          let result = JSON.parse(JSON.stringify(response));
250
          this.activeSubCategory.numbers[index].indicatorPaths[0].jsonPath.forEach(jsonPath => {
251
            if (result) {
252
              result = result[jsonPath];
242
    private setIndicators() {
243
        let urls: Map<string, number[]> = new Map<string, number[]>();
244
        this.activeSubCategory.numbers.forEach((number, index) => {
245
            if (number.isActive && number.isPublic) {
246
                let url = number.indicatorPaths[0].url;
247
                //add fundingLevel0 filter in the query
248
                if (this.fundingL0 && number.indicatorPaths[0].filters.get("fundingL0")) {
249
                    url = url + number.indicatorPaths[0].filters.get("fundingL0").replace(ChartHelper.prefix + 'fundingL0' + ChartHelper.suffix, encodeURIComponent(this.fundingL0));
250
                }
251
                const pair = JSON.stringify([number.indicatorPaths[0].source, url]);
252
                const indexes = urls.get(pair) ? urls.get(pair) : [];
253
                indexes.push(index);
254
                urls.set(pair, indexes);
253 255
            }
254
          });
255
          this.numberResults.set(index, result);
256 256
        });
257
      })
258
    });
259
    this.activeSubCategory.charts.forEach((chart, index) => {
260
      if (chart.indicatorPaths.length > 0) {
261
        chart.indicatorPaths[0].safeResourceUrl = this.getUrlByStakeHolder(chart.indicatorPaths[0]);
262
        this.chartsActiveType.set(index, chart.indicatorPaths[0]);
263
      }
264
    });
265
    this.cdr.detectChanges();
266
  }
257
        urls.forEach((indexes, pair) => {
258
            pair = JSON.parse(pair);
259
            this.statisticsService.getNumbers(pair[0], pair[1]).subscribe(response => {
260
                indexes.forEach(index => {
261
                    let result = JSON.parse(JSON.stringify(response));
262
                    this.activeSubCategory.numbers[index].indicatorPaths[0].jsonPath.forEach(jsonPath => {
263
                        if (result) {
264
                            result = result[jsonPath];
265
                        }
266
                    });
267
                    this.numberResults.set(index, result);
268
                });
269
            })
270
        });
271
        this.activeSubCategory.charts.forEach((chart, index) => {
272
            if (chart.indicatorPaths.length > 0) {
273
                chart.indicatorPaths[0].safeResourceUrl = this.getUrlByStakeHolder(chart.indicatorPaths[0]);
274
                this.chartsActiveType.set(index, chart.indicatorPaths[0]);
275
            }
276
        });
277
        this.cdr.detectChanges();
278
    }
267 279

  
268
  public getUrlByStakeHolder(indicatorPath: IndicatorPath) {
269
    return this.sanitizer.bypassSecurityTrustResourceUrl(
270
      this.statisticsService.getChartUrl(indicatorPath.source, this.indicatorUtils.getFullUrl(indicatorPath, this.fundingL0, this.startYear, this.endYear)));
271
  }
280
    public getUrlByStakeHolder(indicatorPath: IndicatorPath) {
281
        return this.sanitizer.bypassSecurityTrustResourceUrl(
282
            this.statisticsService.getChartUrl(indicatorPath.source, this.indicatorUtils.getFullUrl(indicatorPath, this.fundingL0, this.startYear, this.endYear)));
283
    }
272 284

  
273
  public setActiveChart(index, type: string) {
274
    let activeChart = this.activeSubCategory.charts[index].indicatorPaths.filter(indicatorPath => indicatorPath.type === type)[0];
275
    activeChart.safeResourceUrl = this.getUrlByStakeHolder(activeChart);
276
    this.chartsActiveType.set(index, activeChart);
277
  }
285
    public setActiveChart(index, type: string) {
286
        let activeChart = this.activeSubCategory.charts[index].indicatorPaths.filter(indicatorPath => indicatorPath.type === type)[0];
287
        activeChart.safeResourceUrl = this.getUrlByStakeHolder(activeChart);
288
        this.chartsActiveType.set(index, activeChart);
289
    }
278 290

  
279
  private navigateToError() {
280
    this._router.navigate(['/error'], {queryParams: {'page': this._router.url}});
281
  }
291
    private navigateToError() {
292
        this._router.navigate(['/error'], {queryParams: {'page': this._router.url}});
293
    }
282 294

  
283
  public navigateTo(stakeholder: string, topic: string, category: string = null, subcategory: string = null) {
284
    let url = stakeholder + '/' + topic + ((category) ? ('/'
285
      + category) : '') + ((subcategory) ? ('/' + subcategory) : '');
286
    return this._router.navigate([url]);
287
  }
295
    public navigateTo(stakeholder: string, topic: string, category: string = null, subcategory: string = null) {
296
        let url = stakeholder + '/' + topic + ((category) ? ('/'
297
            + category) : '') + ((subcategory) ? ('/' + subcategory) : '');
298
        return this._router.navigate([url]);
299
    }
288 300

  
289
  public quote(param: string): string {
290
    return StringUtils.quote(param);
291
  }
301
    public quote(param: string): string {
302
        return StringUtils.quote(param);
303
    }
292 304

  
293
  public ngOnDestroy() {
294
    if (this.piwiksub) {
295
      this.piwiksub.unsubscribe();
305
    public ngOnDestroy() {
306
        if (this.piwiksub) {
307
            this.piwiksub.unsubscribe();
308
        }
296 309
    }
297
  }
298 310
}
modules/uoa-monitor-portal/trunk/monitor_dashboard/src/app/utils/entities/sidebar.ts
1
import {ElementRef, TemplateRef} from "@angular/core";
2

  
3 1
export class Header {
4 2
  name: string;
5 3
  dashboard: string;
......
13 11
}
14 12

  
15 13
export class Item {
14
  id: string;
16 15
  name: string;
17 16
  route: string;
18 17
  items: Item[];
19 18
  icon: string;
20 19
  open: boolean;
21
  action: TemplateRef<ElementRef>;
22 20

  
23
  constructor(name: string, route: string, items: Item[], icon, open: boolean, action: TemplateRef<ElementRef> = null) {
21
  constructor(id: string, name: string, route: string, items: Item[], icon, open: boolean) {
22
    this.id = id;
24 23
    this.name = name;
25 24
    this.route = route;
26 25
    this.items = items;
27 26
    this.icon = icon;
28 27
    this.open = open;
29
    this.action = action;
30 28
  }
31 29
}
32 30

  
modules/uoa-monitor-portal/trunk/monitor_dashboard/src/app/library/sharedComponents/sidebar/sideBar.component.ts
8 8
})
9 9
export class SideBarComponent implements OnInit {
10 10
  @Input() items: Item[] = [];
11
  // TODO remove it
12
  @Input() name = null;
13 11
  @Input() header: Header = null;
14 12
  @Input() showHeader: boolean = true;
13
  @Input() activeItem: string = '';
14
  @Input() activeSubItem: string = '';
15 15

  
16 16
  constructor(private router: Router) {
17 17
  }
......
19 19
  ngOnInit(): void {
20 20
  }
21 21

  
22
  private getCurrentRoute(): string {
23
    return this.router.url.split('?')[0];
24
  }
25 22

  
26
  isTheActiveMenu(route: string): boolean {
27
    return this.getCurrentRoute().indexOf(route) !== -1;
23
  isTheActiveMenuItem(item: Item, subItem = false): boolean {
24
    return  (!subItem && this.activeItem === item.id) ||
25
        (subItem && this.activeSubItem === item.id);
28 26
  }
29 27
}
modules/uoa-monitor-portal/trunk/monitor_dashboard/src/app/library/sharedComponents/sidebar/sideBar.component.html
1 1
<aside id="sidebar_main">
2 2
  <div *ngIf= "showHeader" class="sidebar_main_header">
3
    <div *ngIf="name" class="uk-padding-small">
4
      <div class="uk-text-bold">{{name}}</div>
5
      <div>Monitor Dashboard</div>
6
    </div>
7 3
    <div *ngIf="header" class="uk-padding-small">
8 4
      <img *ngIf="header.logoUrl" [src]="header.logoUrl">
9 5
      <div class="uk-text-bold uk-margin-top">{{header.name}}</div>
......
13 9
  <div class="menu_section uk-margin-top">
14 10
    <ul>
15 11
      <ng-template ngFor [ngForOf]="items" let-item let-i="index">
16
        <li [class.current_section]="isTheActiveMenu(item.route)"
12
        <li [class.current_section]="isTheActiveMenuItem(item)"
17 13
            [class.act_section]="item.open"
18 14
            [title]="item.name"
19 15
            [class.submenu_trigger]="item.items.length > 1">
20
          <a *ngIf="item.items.length <= 1 && item.route" [routerLink]="item.route">
16
          <a *ngIf="item.items.length <= 1 && item.route" [routerLink]="!isTheActiveMenuItem(item)?item.route:null">
21 17
            <span *ngIf="item.icon" class="menu_icon"><i class="material-icons">{{item.icon}}</i></span>
22 18
            <span class="menu_title">{{item.name}}</span>
23 19
          </a>
......
28 24
            </a>
29 25
            <ul [style.display]="(item.open?'block':'none')">
30 26
              <ng-template ngFor [ngForOf]="item.items" let-subItem let-j="index">
31
                <li *ngIf="subItem.route" [class.act_item]="isTheActiveMenu(subItem.route)">
32
                  <a [routerLink]="subItem.route">
27
                <li *ngIf="subItem.route" [class.act_item]="isTheActiveMenuItem(subItem, true)">
28
                  <a [routerLink]="!isTheActiveMenuItem(subItem, true)?subItem.route:null">
33 29
                    <span *ngIf="subItem.icon" class="menu_icon"><i class="material-icons">{{subItem.icon}}</i></span>
34 30
                    <span class="menu_title">{{subItem.name}}</span>
35 31
                  </a>

Also available in: Unified diff