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:

displayClaims.component.ts
1 1
import {Component, Input, ViewChild} from '@angular/core';
2 2
import {Location} from '@angular/common';
3 3
import {ActivatedRoute, Router} from '@angular/router';
4
import {Subject} from 'rxjs';
4
import {Subject, Subscriber} from 'rxjs';
5 5
import {debounceTime, distinctUntilChanged} from 'rxjs/operators';
6 6
import {ClaimsService} from '../service/claims.service';
7 7
import {ModalLoading} from '../../../utils/modal/loading.component';
......
28 28
export class DisplayClaimsComponent {
29 29
  @Input() piwikSiteId = null;
30 30
  @Input() title: string = "";
31
  piwiksub: any;
32

  
33 31
  properties: EnvProperties;
34 32
  public searchTermStream = new Subject<string>();
35
  sub: any;
33
  subscriptions: any = [];
36 34
  //string because comes as input from component directive
37 35
  @Input() enableDelete: boolean = false;
38 36
  @Input() showUserEmail: boolean = true;
......
99 97
        this.updateDescription(description);
100 98
        this.updateUrl(this.url);
101 99
        if (this.properties.enablePiwikTrack && (typeof document !== 'undefined')) {
102
          this.piwiksub = this._piwikService.trackView(this.properties, this.title, this.piwikSiteId).subscribe();
100
          this.subscriptions.push(this._piwikService.trackView(this.properties, this.title, this.piwikSiteId).subscribe());
103 101
        }
104 102

  
105
        this.helper.getPageHelpContents(this.properties, this.communityId, this._router.url).subscribe(contents => {
103
        this.subscriptions.push(this.helper.getPageHelpContents(this.properties, this.communityId, this._router.url).subscribe(contents => {
106 104
          this.pageContents = contents;
107
        });
108
        this.indexInfoService.getLastIndexDate(this.properties).subscribe(res => {
105
        }));
106
        this.subscriptions.push(this.indexInfoService.getLastIndexDate(this.properties).subscribe(res => {
109 107
          this.lastIndexDate = res;
110
        });
111
        this.sub = this.route.queryParams.subscribe(params => {
108
        }));
109
        this.subscriptions.push(this.route.queryParams.subscribe(params => {
112 110
          this.seoService.createLinkForCanonicalURL(this.url, false);
113 111

  
114 112
          if (this.myClaims) {
......
133 131
          this.setTypes(params['types']); // check the appropriate checkboxes
134 132
          this.setSortby(params['sort']);
135 133
          this.getClaims();
136
          this.searchTermStream
134
          this.subscriptions.push(this.searchTermStream
137 135
            .pipe(debounceTime(300), distinctUntilChanged())
138 136
            .subscribe((term: string) => {
139 137
              this.keyword = term;
140 138
              this.page = 1;
141 139
              this.goTo();
142
            });
140
            }));
143 141

  
144
        });
142
        }));
145 143

  
146 144

  
147 145

  
148 146
  }
149 147

  
150 148
  ngOnDestroy() {
151
    this.sub.unsubscribe();
152
    if (this.piwiksub) {
153
      this.piwiksub.unsubscribe();
154
    }
155
    //this.searchTermStreamSub.unsubscribe();
149
    this.subscriptions.forEach(subscription => {
150
      if (subscription instanceof Subscriber) {
151
        subscription.unsubscribe();
152
      }
153
    });
156 154
  }
157 155

  
158 156
  getClaims() {
......
174 172
      }
175 173
      this.pageLoading = true;
176 174
      if (this.fetchBy == "Project") {
177
        this._claimService.getClaimsByProject(this.size, this.page, this.fetchId, this.keyword, this.sortby, this.descending, types, this.properties.claimsAPIURL).subscribe(
175
        this.subscriptions.push(this._claimService.getClaimsByProject(this.size, this.page, this.fetchId, this.keyword, this.sortby, this.descending, types, this.properties.claimsAPIURL).subscribe(
178 176
          data => {
179 177
            this.manageAPIData(data);
180 178
            this.pageLoading = false;
......
182 180
          err => {
183 181
            this.handleErrors(err, "Error getting claims for project with id: " + this.fetchId);
184 182
          }
185
        );
183
        ));
186 184
      } else if (this.fetchBy == "User") {
187
        this._claimService.getClaimsByUser(this.size, this.page, this.fetchId, this.keyword, this.sortby, this.descending, types, this.properties.claimsAPIURL).subscribe(
185
        this.subscriptions.push(this._claimService.getClaimsByUser(this.size, this.page, this.fetchId, this.keyword, this.sortby, this.descending, types, this.properties.claimsAPIURL).subscribe(
188 186
          data => {
189 187
            this.manageAPIData(data);
190 188
            this.pageLoading = false;
......
193 191
            this.handleErrors(err, "Error getting claims for user with id: " + this.fetchId);
194 192
            this.pageLoading = false;
195 193
          }
196
        );
194
        ));
197 195
      } else if (this.fetchBy == "Result") {
198
        this._claimService.getClaimsByResult(this.size, this.page, this.fetchId, this.keyword, this.sortby, this.descending, types, this.properties.claimsAPIURL).subscribe(
196
        this.subscriptions.push(this._claimService.getClaimsByResult(this.size, this.page, this.fetchId, this.keyword, this.sortby, this.descending, types, this.properties.claimsAPIURL).subscribe(
199 197
          data => {
200 198
            this.manageAPIData(data);
201 199
            this.pageLoading = false;
......
204 202
            this.handleErrors(err, "Error getting claims for entity with id: " + this.fetchId);
205 203
            this.pageLoading = false;
206 204
          }
207
        );
205
        ));
208 206
      } else if (this.fetchBy == "Context") {
209
        this._claimService.getClaimsBycontext(this.size, this.page, this.fetchId, this.keyword, this.sortby, this.descending, types, this.properties.claimsAPIURL).subscribe(
207
        this.subscriptions.push(this._claimService.getClaimsBycontext(this.size, this.page, this.fetchId, this.keyword, this.sortby, this.descending, types, this.properties.claimsAPIURL).subscribe(
210 208
          data => {
211 209
            this.manageAPIData(data);
212 210
            this.pageLoading = false;
......
215 213
            this.handleErrors(err, "Error getting claims for context with id: " + this.fetchId);
216 214
            this.pageLoading = false;
217 215
          }
218
        );
216
        ));
219 217
      } else {
220
        this._claimService.getClaims(this.size, this.page, this.keyword, this.sortby, this.descending, types, this.properties.claimsAPIURL).subscribe(
218
        this.subscriptions.push(this._claimService.getClaims(this.size, this.page, this.keyword, this.sortby, this.descending, types, this.properties.claimsAPIURL).subscribe(
221 219
          data => {
222 220
              this.manageAPIData(data);
223 221
              this.pageLoading = false;
......
226 224
            this.handleErrors(err, "Error getting claims");
227 225
            this.pageLoading = false;
228 226
          }
229
        );
227
        ));
230 228
      }
231 229
    }
232 230
  }
......
547 545
      });
548 546
    } else {
549 547
      //console.warn("Deleting claim with ids:"+ids);
550
      this._claimService.deleteBulk(ids, this.properties.claimsAPIURL).subscribe(
548
      this.subscriptions.push(this._claimService.deleteBulk(ids, this.properties.claimsAPIURL).subscribe(
551 549
        res => {
552 550
          //console.info('Delete response'+res.code );
553 551
          //console.warn("Deleted ids:"+ res.deletedIds);
......
588 586
          this.showErrorMessage = true;
589 587
          this.loading.close();
590 588

  
591
        });
589
        }));
592 590
    }
593 591
  }
594 592

  

Also available in: Unified diff