Project

General

Profile

« Previous | Next » 

Revision 60315

[Libraryr | Trunk]: Fix filters on admin tools pages

View differences:

entities.component.ts
62 62
      status: ['all', Validators.required]
63 63
    });
64 64
    this.subscriptions.push(this.filterForm.get('keyword').valueChanges.subscribe(value => {
65
      this.filterBySearch(value);
65
      this.searchText = new RegExp(value, 'i');
66
      this.applyFilters();
66 67
    }));
67 68
    this.subscriptions.push(this.filterForm.get('status').valueChanges.subscribe(value => {
68
      this.applyStatusFilter();
69
      this.applyFilters();
69 70
    }));
70 71
    this.userManagementService.getUserInfo().subscribe(user => {
71 72
      this.portal = (this.route.snapshot.data.portal) ? this.route.snapshot.data.portal : this.route.snapshot.params[this.route.snapshot.data.param];
......
145 146
      let i = this.entities.findIndex(_ => _._id == id);
146 147
      this.entities.splice(i, 1);
147 148
    }
148
    this.applyFilter();
149
    this.applyFilters();
149 150
  }
150 151
  
151 152
  public confirmDeleteEntity(id: string) {
......
258 259
  
259 260
  public entitySavedSuccessfully(entity: Entity) {
260 261
    this.entities.push(entity);
261
    this.applyFilter();
262
    this.applyFilters();
262 263
    this.applyCheck(false);
263 264
  }
264 265
  
265 266
  public entityUpdatedSuccessfully(entity: Entity) {
266 267
    this.entities[this.index] = entity;
267
    this.applyFilter();
268
    this.applyFilters();
268 269
    this.applyCheck(false);
269 270
  }
270 271
  
271
  public filterBySearch(text: string) {
272
    this.searchText = new RegExp(text, 'i');
273
    this.applyFilter();
274
  }
275
  
276
  public applyFilter() {
272
  public applyFilters() {
277 273
    this.checkboxes = [];
278
    this.entities.filter(item => this.filterEntities(item)).forEach(
274
    this.entities.filter(item => this.filterEntitiesByStatus(item)).forEach(
279 275
      _ => this.checkboxes.push(<CheckEntity>{entity: _, checked: false})
280 276
    );
277
    this.checkboxes = this.checkboxes.filter(item => this.filterEntities(item.entity));
281 278
  }
282 279
  
283 280
  public filterEntities(entity: Entity): boolean {
......
285 282
    return textFlag;
286 283
  }
287 284
  
288
  public applyStatusFilter() {
289
    this.checkboxes = [];
290
    this.entities.filter(item => this.filterEntitiesByStatus(item)).forEach(
291
      _ => this.checkboxes.push(<CheckEntity>{entity: _, checked: false})
292
    );
293
  }
294
  
295 285
  public filterEntitiesByStatus(entity: Entity): boolean {
296 286
    let status = this.filterForm.get("status").value;
297 287
    return status == "all" || (status == "disabled" && !entity.isEnabled) || (status == "enabled" && entity.isEnabled);

Also available in: Unified diff