|
| 1 | +import { Component, Inject, OnInit } from '@angular/core'; |
| 2 | +import { MAT_DIALOG_DATA, MatDialogRef } from '@angular/material/dialog'; |
| 3 | +import { FormControl, FormGroup } from '@angular/forms'; |
| 4 | +import { Filter, TableColumn } from '../../_models/common'; |
| 5 | +import { FilterService } from '../../_services/filter.service'; |
| 6 | +import { EventGroupService } from '../../_services/api/event-group.service'; |
| 7 | +import { EventGroupsIndexDto } from '../../_models/eventGroupsIndexDto'; |
| 8 | +import { TableAppearanceOptions } from '../../_constants/enums'; |
| 9 | +import { defaultColumnDefs } from './event-group-add-events-modal-table-data'; |
| 10 | + |
| 11 | +@Component({ |
| 12 | + selector: 'app-event-group-add-events-modal', |
| 13 | + templateUrl: './event-group-add-events-modal.component.html', |
| 14 | + styleUrls: ['./event-group-add-events-modal.component.scss'], |
| 15 | +}) |
| 16 | +export class EventGroupAddEventsModalComponent implements OnInit { |
| 17 | + defaultColumns: TableColumn[] = []; |
| 18 | + filtersForm = new FormGroup({}); |
| 19 | + selectedEventGroup: EventGroupsIndexDto | null; |
| 20 | + tableAppearanceOptions = TableAppearanceOptions; |
| 21 | + |
| 22 | + constructor( |
| 23 | + public dialogRef: MatDialogRef<EventGroupAddEventsModalComponent>, |
| 24 | + @Inject(MAT_DIALOG_DATA) public data: any, |
| 25 | + public eventGroupService: EventGroupService, |
| 26 | + private filterService: FilterService |
| 27 | + ) {} |
| 28 | + |
| 29 | + ngOnInit(): void { |
| 30 | + this.defaultColumns = defaultColumnDefs; |
| 31 | + this.initFiltersForm(); |
| 32 | + } |
| 33 | + |
| 34 | + initFiltersForm(): void { |
| 35 | + this.filtersForm = new FormGroup({ |
| 36 | + searchEventGroup: new FormControl(), |
| 37 | + }); |
| 38 | + } |
| 39 | + |
| 40 | + filtersToArray(): void { |
| 41 | + const filter: Filter = { |
| 42 | + field: 'searchEventGroup', |
| 43 | + value: this.filtersForm.value.searchEventGroup, |
| 44 | + }; |
| 45 | + this.filterService.setFilters([filter]); |
| 46 | + } |
| 47 | + |
| 48 | + onSelectEventGroup(event: any): void { |
| 49 | + this.selectedEventGroup = null; |
| 50 | + if (event.selected.length) { |
| 51 | + // eslint-disable-next-line prefer-destructuring |
| 52 | + this.selectedEventGroup = event.selected[0]; |
| 53 | + } |
| 54 | + } |
| 55 | + |
| 56 | + onFormChange(): void { |
| 57 | + this.filtersToArray(); |
| 58 | + } |
| 59 | + |
| 60 | + confirm(): void { |
| 61 | + this.dialogRef.close({ |
| 62 | + selectedEventGroup: this.selectedEventGroup, |
| 63 | + }); |
| 64 | + } |
| 65 | + |
| 66 | + newEventGroup(): void { |
| 67 | + this.dialogRef.close({ |
| 68 | + selectedEventGroup: null, |
| 69 | + }); |
| 70 | + } |
| 71 | +} |
0 commit comments