Project

General

Profile

« Previous | Next » 

Revision 59048

[Monitor Dashboard | Trunk]: Move sidebar and header to app component

View differences:

monitor.component.ts
28 28
  templateUrl: 'monitor.component.html',
29 29
  styleUrls:['monitor.component.css']
30 30
})
31
export class MonitorComponent implements OnInit, OnDestroy, IDeactivateComponent {
32
  private static sidebarStatus: {
33
    id;
34
    status;
35
  };
31
export class MonitorComponent implements OnInit, OnDestroy {
36 32
  public user: User;
37
  public userMenuItems: MenuItem[] = [new MenuItem("", "My profile", "", "", false, [], [], {})];
38 33
  public subscriptions: any[] = [];
39 34
  public piwiksub: any;
40 35
  public pageContents = null;
41 36
  public divContents = null;
42 37
  public status: number;
43
  public loading: boolean = true;
44 38
  public isViewPublic: boolean = false;
45 39
  public indicatorUtils: IndicatorUtils = new IndicatorUtils();
46 40
  public stakeholderUtils: StakeholderUtils = new StakeholderUtils();
47 41
  public activeTopic: Topic = null;
48 42
  public activeCategory: Category = null;
49 43
  public activeSubCategory: SubCategory = null;
50
  public sideBarItems: MenuItem[] = [];
51
  public topBarItems: MenuItem[] = [];
52 44
  public errorCodes: ErrorCodes;
53 45
  public stakeholder: Stakeholder;
54 46
  public numberResults: Map<string, number> = new Map<string, number>();
......
93 85
          this.user = user;
94 86

  
95 87
          this.route.params.subscribe(params => {
96
            this.loading = true;
97 88
            this.activeTopic = null;
98 89
            this.activeCategory = null;
99 90
            this.activeSubCategory = null;
......
106 97
            this.route.queryParams.subscribe(params => {
107 98
              this.isViewPublic = (params['view'] == 'public');
108 99
            });
109
            this.buildMenu();
110

  
111 100
            if (!this.stakeholder || this.stakeholder.alias !== params['stakeholder']) {
112 101
              this.status = this.errorCodes.LOADING;
113 102
              this.numberResults = new Map<string, number>();
......
150 139
      });
151 140
  }
152 141
  
153
  canExit() {
154
    if (this.sideBarItems.length > 0) {
155
      let status = [];
156
      this.sideBarItems.forEach(item => {
157
        status.push(item.open);
158
      });
159
      MonitorComponent.sidebarStatus = {
160
        id: this.activeTopic.alias,
161
        status: status
162
      };
163
    }
164
    return true;
165
  }
166
  
167 142
  public get open() {
168 143
    return this.layoutService.open;
169 144
  }
......
196 171
          if (this.activeCategory) {
197 172
            this.activeSubCategory = this.activeCategory.subCategories.find(subCategory =>
198 173
              this.isPublicOrIsMember(subCategory.isPublic) && subCategory.isActive);
199
            this.setSideBar();
200 174
            if (this.activeSubCategory) {
201 175
              this.setIndicators();
202 176
            }
203
          } else {
204
            this.setSideBar();
205 177
          }
206 178
          return;
207 179
        }
......
218 190
              this.isPublicOrIsMember(subCategory.isPublic) && subCategory.isActive);
219 191
          }
220 192
          if (this.activeSubCategory) {
221
            this.setSideBar();
222 193
            this.setIndicators();
223 194
          } else {
224 195
            this.navigateToError();
......
241 212
            this.setIndicators();
242 213
          }
243 214
        }
244
        this.setSideBar();
245 215
      }
246 216
    }
247 217
  }
248 218
  
249
  private setSideBar() {
250
    let items: MenuItem[] = [];
251
    this.stakeholder.topics.forEach((topic) => {
252
      if (this.isPublicOrIsMember(topic.isPublic) && topic.isActive) {
253
        let topicItem: MenuItem = new MenuItem(topic.alias, topic.name, "", (
254
          '/' + this.stakeholder.alias + '/' + topic.alias ),
255
          null, [], [], {});
256
         topicItem.icon = topic.icon;
257
        items.push(topicItem);
258
        }
259
    });
260
    let categoryItems: MenuItem[] = [];
261
    this.activeTopic.categories.forEach((category, index) => {
262
      if (this.isPublicOrIsMember(category.isPublic) && category.isActive) {
263
        let subItems: MenuItem[] = [];
264
        /*category.subCategories.forEach(subCategory => {
265
          if (this.isPublicOrIsMember(subCategory.isPublic) && subCategory.isActive) {
266
            subItems.push(new MenuItem(subCategory.alias, subCategory.name, "", (
267
              '/' + this.stakeholder.alias + '/' + this.activeTopic.alias + '/' + category.alias + '/' + subCategory.alias),
268
              null, null, [], {}));
269
          }
270
        });*/
271
        let open = this.activeCategory.alias === category.alias;
272
        if (MonitorComponent.sidebarStatus && MonitorComponent.sidebarStatus.id === this.activeTopic.alias) {
273
          open = MonitorComponent.sidebarStatus.status[index];
274
        }
275
        //  constructor(id: string, title: string, url: string, route: string, needsAuthorization: boolean, entitiesRequired: string[], routeRequired: string[], params) {
276
        let categoryItem: MenuItem = new MenuItem(category.alias, category.name, "", (
277
          '/' + this.stakeholder.alias + '/' + this.activeTopic.alias + '/' + category.alias),
278
          null, [], [], {});
279
        categoryItem.items = subItems;
280
        categoryItem.open = open;
281
        categoryItems.push(categoryItem);
282
      }
283
    });
284
    this.topBarItems = categoryItems;
285
    if (items.length === 0) {
286
      items.push(new MenuItem('noCategories', 'No categories available yet', "", "", false, [], [], {}));
287
    }
288
    this.sideBarItems = items;
289
    this.loading = false;
290
  }
291
  
292 219
  private setIndicators() {
293 220
    let urls: Map<string, [number, number][]> = new Map<string, [number, number][]>();
294 221
    this.activeSubCategory.numbers.forEach((section, i) => {
......
363 290
      this.piwiksub.unsubscribe();
364 291
    }
365 292
  }
366
  
367
  buildMenu() {
368
    this.userMenuItems = [];
369
    // if (Session.isPortalAdministrator(this.user)) {
370
    //   this.userMenuItems.push(new MenuItem("", "Manage helptexts",
371
    //     ((this.properties.environment == "beta") ? "https://beta.admin.connect.openaire.eu" : "https://admin.explore.openaire.eu") + "/dashboard?communityId=openaire", "", true, [], [], {}))
372
    //
373
    // }
374
    if (this.user) {
375
      this.userMenuItems.push(new MenuItem("", "Manage profiles", "", "/admin", false, [], [], {}));
376
    }
377
    if (this.user) {
378
      this.userMenuItems.push(new MenuItem("", "User information", "", "/user-info", false, [], [], {}));
379
    }
380
  }
381 293

  
382 294
  isAdmin(){
383 295
    return this.user && (Session.isPortalAdministrator(this.user) || Session.isCommunityCurator(this.user) || Session.isMonitorCurator(this.user));
384 296
  }
385

  
386
  isLoggedIn() {
387
    return this.user;
388
  }
389

  
297
  
390 298
  public isPublicOrIsMember(isPublic: boolean): boolean {
391 299
    if (isPublic) {
392 300
      return true;

Also available in: Unified diff