Ittay Stern | f792671 | 2019-07-07 19:23:03 +0300 | [diff] [blame] | 1 | import {Component, Input, OnDestroy, OnInit, ViewChild} from '@angular/core'; |
| 2 | import {DialogComponent, DialogService} from "ng2-bootstrap-modal"; |
| 3 | import {IframeService} from "../../utils/iframe.service"; |
| 4 | import {AaiService} from "../../services/aaiService/aai.service"; |
| 5 | import {VnfGroupModel} from "../../models/vnfGroupModel"; |
| 6 | import {ElementsTableService} from "./members-table/elements-table.service"; |
| 7 | import {Level1Instance} from "../../models/level1Instance"; |
| 8 | import {ModalInformation} from "./members-table/element-table-row.model"; |
| 9 | import {NgRedux} from "@angular-redux/store"; |
| 10 | import {AppState} from "../../store/reducers"; |
| 11 | import {FormGroup} from "@angular/forms"; |
| 12 | import * as _ from "lodash"; |
| 13 | import {clearAllGenericModalhelper} from "../../storeUtil/utils/global/global.actions"; |
| 14 | @Component({ |
| 15 | selector: 'search-members-modal', |
| 16 | templateUrl: 'search-elements-modal.component.html', |
| 17 | styleUrls: ['search-elements-modal.component.scss'] |
| 18 | }) |
| 19 | |
| 20 | export class SearchElementsModalComponent extends DialogComponent<{ modalInformation: ModalInformation }, boolean> implements OnInit, OnDestroy { |
| 21 | modalInformation: ModalInformation; |
| 22 | parentElementClassName = 'content'; |
| 23 | elementsData: Level1Instance[]; |
| 24 | vnfGroupModel: VnfGroupModel; |
| 25 | disableSetElements: boolean = true; |
| 26 | disableSearchByNetworkRole: boolean = false; |
| 27 | dynamicFormGroup: FormGroup = null; |
| 28 | |
| 29 | constructor(dialogService: DialogService, |
| 30 | private _iframeService: IframeService, |
| 31 | private _aaiService: AaiService, |
| 32 | private _membersTableService: ElementsTableService, |
| 33 | private _store: NgRedux<AppState>) { |
| 34 | super(dialogService); |
| 35 | ElementsTableService.changeFnTableDataTrigger.subscribe((triggerRes) => { |
| 36 | this._membersTableService.resetAll(this.modalInformation.uniqObjectField, this.modalInformation.maxSelectRow); |
| 37 | this.elementsData = triggerRes; |
| 38 | }); |
| 39 | |
| 40 | ElementsTableService.changeModalInformationDataTrigger.subscribe(({modalInformation, selectedRowsIds}) => { |
| 41 | this.disableSetElements = true; |
| 42 | this.modalInformation = modalInformation; |
| 43 | this.ngOnInit(selectedRowsIds); |
| 44 | }) |
| 45 | } |
| 46 | |
| 47 | @ViewChild('ElementsTableComponent') membersTable; |
| 48 | |
| 49 | ngOnInit(selectedRowsIds?: string[]): void { |
| 50 | const genericModalHelper = this._store.getState().global.genericModalHelper; |
| 51 | if(!_.isNil(genericModalHelper) && !_.isNil(genericModalHelper[`${this.modalInformation.type}_TABLE_DATA`]) && !_.isNil(genericModalHelper[`selected${this.modalInformation.type}`])){ |
| 52 | this.elementsData = this._store.getState().global.genericModalHelper[`${this.modalInformation.type}_TABLE_DATA`]; |
| 53 | } else { |
| 54 | this.modalInformation.getElements() |
| 55 | .subscribe((result) => { |
| 56 | this.elementsData = result; |
| 57 | }); |
| 58 | } |
| 59 | }; |
| 60 | |
| 61 | closeDialog(): void { |
| 62 | this._iframeService.removeFullScreen(); |
| 63 | this._iframeService.removeClassCloseModal(this.parentElementClassName); |
| 64 | this.dialogService.removeDialog(this); |
| 65 | setTimeout(() => { |
| 66 | window.parent.postMessage("closeIframe", "*"); |
| 67 | }, 15); |
| 68 | } |
| 69 | |
| 70 | selectedMembersAmountChange(selectedMembersAmount: number): void { |
| 71 | this.disableSetElements = selectedMembersAmount == 0; |
| 72 | } |
| 73 | |
| 74 | doneAction(): void { |
| 75 | this.modalInformation.topButton.action.call(this, this); |
| 76 | } |
| 77 | |
| 78 | searchByCriteriaAction(): void { |
| 79 | this.modalInformation.searchButton.action.call(this, this); |
| 80 | } |
| 81 | |
| 82 | backAction(): void { |
| 83 | if (this.modalInformation.backAction) { |
| 84 | this.modalInformation.backAction.call(this, this); |
| 85 | } else { |
| 86 | this.closeDialog(); |
| 87 | } |
| 88 | } |
| 89 | } |
| 90 | |
| 91 | |