Project

General

Profile

« Previous | Next » 

Revision 57847

[MonitorDashboard]: Fix a bug on app component

View differences:

modules/uoa-monitor-portal/trunk/monitor_dashboard/src/app/app.component.ts
1 1
import {ChangeDetectorRef, Component, OnDestroy, OnInit} from '@angular/core';
2
import {ActivatedRoute, NavigationEnd, Router} from '@angular/router';
2
import {ActivatedRoute, NavigationEnd, RouteConfigLoadEnd, Router} from '@angular/router';
3 3

  
4 4
import {EnvProperties} from './openaireLibrary/utils/properties/env-properties';
5 5
import {EnvironmentSpecificService} from './openaireLibrary/utils/properties/environment-specific.service';
......
11 11

  
12 12

  
13 13
@Component({
14
  selector: 'app-root',
15
  templateUrl: './app.component.html'
14
    selector: 'app-root',
15
    templateUrl: './app.component.html'
16 16
})
17 17
export class AppComponent implements OnInit, OnDestroy {
18
  properties: EnvProperties;
19
  user: User;
20
  loginCheck: boolean = false;
21
  hasSidebar: boolean = false;
22
  hasHeader: boolean = false;
23
  private subscriptions: any[] = [];
18
    properties: EnvProperties;
19
    user: User;
20
    loginCheck: boolean = false;
21
    hasSidebar: boolean = false;
22
    hasHeader: boolean = false;
23
    private subscriptions: any[] = [];
24 24

  
25
  constructor(private  route: ActivatedRoute,
26
              private propertiesService: EnvironmentSpecificService,
27
              private router: Router,
28
              private userManagementService: UserManagementService,
29
              private layoutService: LayoutService,
30
              private stakeholderService: StakeholderService,
31
              private cdr: ChangeDetectorRef) {
32
  }
25
    constructor(private  route: ActivatedRoute,
26
                private propertiesService: EnvironmentSpecificService,
27
                private router: Router,
28
                private userManagementService: UserManagementService,
29
                private layoutService: LayoutService,
30
                private stakeholderService: StakeholderService,
31
                private cdr: ChangeDetectorRef) {
32
    }
33 33

  
34
  ngOnInit() {
35
    this.subscriptions.push(this.layoutService.hasSidebar.subscribe(hasSidebar => {
36
      this.hasSidebar = hasSidebar;
37
      this.cdr.detectChanges();
38
    }));
39
    this.subscriptions.push(this.layoutService.hasHeader.subscribe(hasHeader => {
40
      this.hasHeader = hasHeader;
41
      this.cdr.detectChanges();
42
    }));
43
    this.propertiesService.loadEnvironment()
44
      .then(properties => {
45
        this.properties = properties;
46
        this.router.events.subscribe(event => {
47
          if (event instanceof NavigationEnd) {
48
            let r = this.route;
49
            while (r.firstChild) {
50
              r = r.firstChild;
34
    ngOnInit() {
35
        this.subscriptions.push(this.layoutService.hasSidebar.subscribe(hasSidebar => {
36
            this.hasSidebar = hasSidebar;
37
            this.cdr.detectChanges();
38
        }));
39
        this.subscriptions.push(this.layoutService.hasHeader.subscribe(hasHeader => {
40
            this.hasHeader = hasHeader;
41
            this.cdr.detectChanges();
42
        }));
43
        this.propertiesService.loadEnvironment()
44
            .then(properties => {
45
                this.properties = properties;
46
                this.router.events.subscribe(event => {
47
                    if (event instanceof RouteConfigLoadEnd && event.route.path.indexOf('stakeholder') !== -1 ||
48
                        event instanceof NavigationEnd) {
49
                        let r = this.route;
50
                        while (r.firstChild) {
51
                            r = r.firstChild;
52
                        }
53
                        r.params.subscribe(params => {
54
                            if (params['stakeholder']) {
55
                                if (!this.stakeholderService.stakeholder ||
56
                                    this.stakeholderService.stakeholder.alias !== params['stakeholder']) {
57
                                    this.stakeholderService.getStakeholder(this.properties.monitorServiceAPIURL, params['stakeholder']).subscribe(stakeholder => {
58
                                        this.stakeholderService.setStakeholder(stakeholder);
59
                                        this.layoutService.setOpen(true);
60
                                    });
61
                                }
62
                            } else {
63
                                this.stakeholderService.setStakeholder(null);
64
                            }
65
                        });
66
                    }
67
                });
68
                this.userManagementService.getUserInfo(this.properties.userInfoUrl).subscribe(user => {
69
                    this.user = user;
70
                    this.loginCheck = true;
71
                }, error => {
72
                    console.log("App couldn't fetch properties");
73
                    console.log(error);
74
                });
75
            });
76
    }
77

  
78
    public ngOnDestroy() {
79
        this.subscriptions.forEach(value => {
80
            if (value instanceof Subscriber) {
81
                value.unsubscribe();
51 82
            }
52
            r.params.subscribe(params => {
53
              if (params['stakeholder']) {
54
                if (!this.stakeholderService.stakeholder ||
55
                  this.stakeholderService.stakeholder.alias !== params['stakeholder']) {
56
                  this.stakeholderService.getStakeholder(this.properties.monitorServiceAPIURL, params['stakeholder']).subscribe(stakeholder => {
57
                    this.stakeholderService.setStakeholder(stakeholder);
58
                    this.layoutService.setOpen(true);
59
                  });
60
                }
61
              } else {
62
                this.stakeholderService.setStakeholder(null);
63
              }
64
            });
65
          }
66 83
        });
67
        this.userManagementService.getUserInfo(this.properties.userInfoUrl).subscribe(user => {
68
          this.user = user;
69
          this.loginCheck = true;
70
        }, error => {
71
          console.log("App couldn't fetch properties");
72
          console.log(error);
73
        });
74
      });
75
  }
84
    }
76 85

  
77
  public ngOnDestroy() {
78
    this.subscriptions.forEach(value => {
79
      if (value instanceof Subscriber) {
80
        value.unsubscribe();
81
      }
82
    });
83
  }
86
    public get open() {
87
        return this.layoutService.open;
88
    }
84 89

  
85
  public get open() {
86
    return this.layoutService.open;
87
  }
88

  
89
  public toggleOpen(event = null) {
90
    if (!event) {
91
      this.layoutService.setOpen(!this.open);
92
    } else if (event && event['value'] === true) {
93
      this.layoutService.setOpen(false);
90
    public toggleOpen(event = null) {
91
        if (!event) {
92
            this.layoutService.setOpen(!this.open);
93
        } else if (event && event['value'] === true) {
94
            this.layoutService.setOpen(false);
95
        }
94 96
    }
95
  }
96 97
}

Also available in: Unified diff