Project

General

Profile

« Previous | Next » 

Revision 59816

[Library|Trunk]

code clean up:
-remove app.* files from library
-remove unused imports, code, files (Old search pages for results, dataproviders, map search page, etc)
-remove Freeguard from modules
-unsubscribe all subscriptions
-Services: configuration, isvocabularies, user management: unsubscribe from app component or the component that uses them (clearSubscriptions())
-Fetchers: unsubscribe from the component that uses them (clearSubscriptions())

View differences:

user-management.service.ts
9 9
@Injectable({
10 10
  providedIn: 'root'
11 11
})
12
export class UserManagementService {
12
export class UserManagementService{
13 13
  
14 14
  private getUserInfoSubject: BehaviorSubject<User> = new BehaviorSubject<User>(null);
15 15
  private readonly promise: Promise<User>;
16
  
16
  sub;
17
  routeSub;
17 18
  constructor(private http: HttpClient,
18 19
              private router: Router) {
19 20
    this.promise = new Promise<any>((resolve => {
20 21
      this.updateUserInfo(resolve);
21 22
    }));
22
    this.router.events.subscribe(event => {
23
    this.routeSub = this.router.events.subscribe(event => {
23 24
      if (event instanceof NavigationEnd) {
24 25
        const token = COOKIE.getCookie('AccessToken');
25 26
        if (!token && this.getUserInfoSubject.getValue() !== null) {
26 27
          this.getUserInfoSubject.next(null);
27 28
        }
28 29
      }
29
    })
30
    });
30 31
  }
32

  
33
  clearSubscriptions() {
34
    if(this.routeSub){
35
      this.routeSub.unsubscribe();
36
    }
37
    if(this.sub){
38
      this.sub.unsubscribe();
39
    }
40
  }
31 41
  
32 42
  public getUserInfo(subject: boolean = true): Observable<User> {
33 43
    if (subject) {
......
45 55
        resolve();
46 56
      }
47 57
    } else {
48
      this.http.get<User>(properties.userInfoUrl + token).pipe(map(userInfo => {
58
     this.sub = this.http.get<User>(properties.userInfoUrl + token).pipe(map(userInfo => {
49 59
        return this.parseUserInfo(userInfo);
50 60
      })).pipe(timeout(3000), catchError(() => {
51 61
        return of(null);
......
60 70
  
61 71
  private async getUserInfoAsync(): Promise<User> {
62 72
    await this.promise;
73
    if(this.sub){
74
      this.sub.unsubscribe();
75
    }
63 76
    return this.getUserInfoSubject.getValue();
64 77
  }
65 78
  
66 79
  private parseUserInfo(info: any) {
67 80
    const user: User = new User();
68
    user.id = (info.sub && info.sub.indexOf('@')) ? info.sub.substring(0, info.sub.indexOf('@')) : info.sub;
81
    user.id = (info.subscriptions && info.subscriptions.indexOf('@')) ? info.subscriptions.substring(0, info.subscriptions.indexOf('@')) : info.subscriptions;
69 82
    user.firstname = (info.given_name) ? info.given_name : "";
70 83
    user.lastname = (info.family_name) ? info.family_name : "";
71 84
    user.email = info.email.toLowerCase(); // TODO remove, is a quick fix

Also available in: Unified diff