aboutsummaryrefslogtreecommitdiffstats
path: root/vid-webpack-master/src/app/shared/components/searchMembersModal/members-table/members-table.component.ts
blob: 9736563af9639e05d975a008675f273541955fb6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
import {Component, Input, OnChanges, Output, SimpleChanges, EventEmitter} from '@angular/core';
import {VnfMember} from "../../../models/VnfMember";
import {MembersTableService} from "./members-table.service";
import * as _ from 'lodash';

export class CustomTableColumnDefinition {
  public displayName = '';
  public key : any = '';
  public type? = 'text';
  public filter? = '';
}

@Component({
  selector: 'app-members-table',
  templateUrl: './members-table.component.html',
  styleUrls: ['./members-table.component.scss']
})

export class MembersTableComponent implements OnChanges{
  filterValue: string = null;
  allMemberStatusMap = null;
  membersTableService : MembersTableService;
  headers: CustomTableColumnDefinition[] = MembersTableService.getHeaders();
  @Input() data: VnfMember[];
  @Input() description: string;
  @Output() selectedMembersAmountChange : EventEmitter<number> = new EventEmitter();
  constructor(private _membersTableService : MembersTableService){
    this.membersTableService = this._membersTableService;
  }

  ngOnChanges(changes: SimpleChanges): void {
    if(_.isNil(this.data)){
      this._membersTableService.resetAll();
    }else {
      this._membersTableService.allMemberStatusMap = MembersTableService.generateAllMembersStatus(this.data);
      this._membersTableService.filteredMembers = MembersTableService.sortVnfMembersByName(this.data, "instanceName");
      this._membersTableService.updateAmountsAndCheckAll();
    }
  }
  
  search(searchStr: string): void {
    this.filterValue = searchStr;
    this._membersTableService.filterMembers(this.filterValue);
  }

  changeAllCheckboxStatus(status: boolean) : void {
    this._membersTableService.changeAllCheckboxStatus(status);
    this.selectedMembersAmountChange.emit(this._membersTableService.numberOfSelectedVnfMembers);
  }


  changeCheckboxStatus(vnfInstanceId: string) : void {
    this._membersTableService.changeCheckboxStatus(vnfInstanceId);
    this.selectedMembersAmountChange.emit(this._membersTableService.numberOfSelectedVnfMembers);
  }

}