Allow platform multi-selection for VNF in modern UI
[vid.git] / vid-webpack-master / src / app / shared / components / formControls / component / multiselect / multiselect.formControl.component.ts
1 import {Component, Input, OnChanges, SimpleChanges} from "@angular/core";
2 import {FormGroup} from "@angular/forms";
3 import {MultiselectFormControl} from "../../../../models/formControlModels/multiselectFormControl.model";
4 import {MultiselectFormControlService} from "./multiselect.formControl.service";
5 import {MultiSelectItem} from "./multiselect.model";
6
7 @Component({
8   selector: 'multiselect-form-control',
9   templateUrl: './multiselect.formControl.component.html'
10 })
11 export class MultiselectFormControlComponent implements OnChanges{
12   @Input() data: MultiselectFormControl = null;
13   @Input() multiselectOptions: [] = null;
14   @Input() selectedItems  = [];
15   @Input() form: FormGroup = null;
16
17
18   multiselectFormControlService : MultiselectFormControlService;
19   constructor(private _multiselectFormControlService : MultiselectFormControlService){
20     this.multiselectFormControlService = _multiselectFormControlService;
21   }
22   dropdownSettings = {
23     singleSelection : false
24   };
25
26   options : MultiSelectItem[];
27
28
29
30   async ngOnChanges(changes: SimpleChanges) {
31     if(this.data.options$){
32       this._multiselectFormControlService.convertOriginalItems(this.data).then((options)=>{
33           this.options = options;
34           this._multiselectFormControlService.convertSelectedItems(this.data).then((res)=> {
35             this.selectedItems = res;
36             this.form.controls[this.data.controlName].setValue(this.selectedItems);
37           })
38       });
39
40     }
41     if (changes["data"] !== undefined && changes["data"].currentValue !== changes["data"].previousValue && changes["data"].firstChange) {
42       if (this.data.onInit) {
43         this.data.onInit(this.data, this.form);
44       }
45     }
46   }
47
48   onItemSelect(item:any){
49     this.data.onChange(this.selectedItems ,this.form);
50   }
51   OnItemDeSelect(item:any){
52     this.data.onChange(this.selectedItems ,this.form);
53   }
54   onSelectAll(items: any){
55     this.data.onChange(this.selectedItems ,this.form);
56   }
57   onDeSelectAll(items: any){
58     this.data.onChange(this.selectedItems ,this.form);
59   }
60 }
61