Project

General

Profile

« Previous | Next » 

Revision 57357

[Monitor]: Stakeholder page: Build menu and navigation

View differences:

monitor.component.ts
1 1
import {Component} from '@angular/core';
2
import {ActivatedRoute, Router} from '@angular/router';
2
import {ActivatedRoute, Params, Router} from '@angular/router';
3 3
import {Meta, Title} from '@angular/platform-browser';
4 4
import {EnvProperties} from '../openaireLibrary/utils/properties/env-properties';
5
import {CommunitiesService} from '../openaireLibrary/connect/communities/communities.service';
6
import {SubscribeService} from '../openaireLibrary/utils/subscribe/subscribe.service';
7
import {CommunityInfo} from '../openaireLibrary/connect/community/communityInfo';
8 5

  
9 6
import {PiwikService} from '../openaireLibrary/utils/piwik/piwik.service';
10 7
import {StringUtils} from '../openaireLibrary/utils/string-utils.class';
......
14 11
import {HelperService} from "../openaireLibrary/utils/helper/helper.service";
15 12
import {SEOService} from "../openaireLibrary/sharedComponents/SEO/SEO.service";
16 13
import {StakeholderService} from "../services/stakeholder.service";
17
import {Stakeholder} from "../stakeholder";
14
import {Category, Stakeholder, SubCategory, Topic} from "../utils/entities/stakeholder";
15
import {MenuItem, RootMenuItem, SideMenuItem} from "../openaireLibrary/sharedComponents/menu";
18 16

  
19 17
@Component({
20 18
  selector: 'monitor',
21 19
  templateUrl: 'monitor.component.html',
22 20
})
23

  
24 21
export class MonitorComponent {
25 22
  public piwiksub: any;
26 23
  public pageContents = null;
27 24
  public divContents = null;
28 25
  public status: number;
29 26
  public loading: boolean = true;
27
  public activeTopic: Topic = null;
28
  public activeCategory: Category = null;
29
  public activeSubCategory: SubCategory = null;
30
  public sideMenuItems: SideMenuItem[] = null;
30 31
  public errorCodes: ErrorCodes;
31 32
  public stakeholder: Stakeholder;
32 33
  private errorMessages: ErrorMessagesComponent;
......
52 53
        this.route.params.subscribe( params => {
53 54
          this.properties = data.envSpecific;
54 55
          var url = data.envSpecific.baseLink + this._router.url;
55
          this.stakeholderService.getStakeholder(params['id']).subscribe(stakeholder => {
56
            this.stakeholder = stakeholder;
57
            this.seoService.createLinkForCanonicalURL(url, false);
58
            this._meta.updateTag({content: url}, "property='og:url'");
59
            var description = "Monitor | " + this.stakeholder.index_name;
60
            var title = "Monitor | " + this.stakeholder.index_shortName;
61
            this._meta.updateTag({content: description}, "name='description'");
62
            this._meta.updateTag({content: description}, "property='og:description'");
63
            this._meta.updateTag({content: title}, "property='og:title'");
64
            this._title.setTitle(title);
65
            if (this.properties.enablePiwikTrack && (typeof document !== 'undefined')) {
66
              this.piwiksub = this._piwikService.trackView(this.properties, title, this.properties.piwikSiteId).subscribe();
67
            }
68
            //this.getDivContents();
69
            this.getPageContents();
70
          }, error => {
71
            console.log(error);
72
            this._router.navigate(['']);
73
          })
56
          if(!this.stakeholder || this.stakeholder.index_id !== params['stakeholder']) {
57
            this.status = this.errorCodes.LOADING;
58
            this.stakeholderService.getStakeholder(params['stakeholder']).subscribe(stakeholder => {
59
              this.stakeholder = stakeholder;
60
              this.seoService.createLinkForCanonicalURL(url, false);
61
              this._meta.updateTag({content: url}, "property='og:url'");
62
              var description = "Monitor Dashboard | " + this.stakeholder.index_name;
63
              var title = "Monitor Dashboard | " + this.stakeholder.index_shortName;
64
              this._meta.updateTag({content: description}, "name='description'");
65
              this._meta.updateTag({content: description}, "property='og:description'");
66
              this._meta.updateTag({content: title}, "property='og:title'");
67
              this._title.setTitle(title);
68
              if (this.properties.enablePiwikTrack && (typeof document !== 'undefined')) {
69
                this.piwiksub = this._piwikService.trackView(this.properties, title, this.properties.piwikSiteId).subscribe();
70
              }
71
              //this.getDivContents();
72
              this.getPageContents();
73
              this.status = this.errorCodes.DONE;
74
              this.setView(params);
75
            }, error => {
76
              this.navigateToError();
77
            })
78
          } else {
79
            this.setView(params);
80
          }
74 81
        });
75 82
      });
76 83
  }
......
87 94
    })
88 95
  }
89 96

  
97
  private setView(params: Params) {
98
    if(params && params['topic']) {
99
      this.activeTopic = this.stakeholder.topics.filter(topic => topic.alias === decodeURIComponent(params['topic']))[0];
100
      if(this.activeTopic) {
101
        if(params['category']) {
102
          this.activeCategory = this.activeTopic.categories.filter(category =>
103
            category.alias === decodeURIComponent(params['category']))[0];
104
        } else {
105
          let category: Category = this.activeTopic.categories[0];
106
          this.navigateTo(this.stakeholder.alias, this.activeTopic.alias, category.alias);
107
          return;
108
        }
109
        if(this.activeCategory) {
110
          if(params['subCategory']) {
111
            this.activeSubCategory = this.activeCategory.subCategories.filter(subCategory =>
112
              subCategory.alias = decodeURIComponent(params['subCategory']))[0];
113
          } else {
114
            this.activeSubCategory = this.activeCategory.subCategories.filter(subCategory => !subCategory.alias)[0];
115
          }
116
          if(this.activeSubCategory) {
117
            this.setSideBar();
118
            return;
119
          }
120
        }
121
      }
122
      this.navigateToError();
123
    } else {
124
      let topic: Topic = this.stakeholder.topics[0];
125
      let category: Category = topic.categories[0];
126
      this.navigateTo(this.stakeholder.alias, topic.alias, category.alias);
127
    }
128
  }
129

  
130
  private setSideBar() {
131
    this.sideMenuItems = [];
132
    this.activeTopic.categories.forEach(category => {
133
      let rootItem: MenuItem = new MenuItem(category.alias, category.name, null, (
134
        '/monitor/' + this.stakeholder.alias + '/' + this.activeTopic.alias + '/' + category.alias),
135
        false, null, null, null);
136
      let items: RootMenuItem[] = [];
137
      category.subCategories.forEach(subCategory => {
138
        if(subCategory.alias != null) {
139
          items.push({
140
            items: [],
141
            rootItem: new MenuItem(subCategory.alias, subCategory.name, null, (
142
              '/monitor/' + this.stakeholder.alias + '/' + this.activeTopic.alias + '/' + category.alias + '/' + subCategory.alias),
143
              false, null, null, null)
144
          });
145
        }
146
      });
147
      this.sideMenuItems.push({
148
        rootItem: rootItem,
149
        items: items,
150
        ukIcon: null
151
      });
152
    });
153
  }
154

  
155
  public navigateToError() {
156
    this._router.navigate(['/error'],{queryParams: {'page': this._router.url}});
157
  }
158

  
159
  public navigateTo(stakeholder: string, topic: string, category: string = null, subcategory: string = null) {
160
    let url = 'monitor/' + stakeholder+ '/' + topic + ((category)?('/'
161
      + category):'') + ((subcategory)?('/' + subcategory):'');
162
    return this._router.navigate([url]);
163
  }
164

  
90 165
  public quote(param: string): string {
91 166
    return StringUtils.quote(param);
92 167
  }

Also available in: Unified diff