|
| 1 | +import { Component, Inject, OnInit } from '@angular/core'; |
| 2 | +import { FormGroup } from '@angular/forms'; |
| 3 | +import { MatDialogRef, MAT_DIALOG_DATA } from '@angular/material/dialog'; |
| 4 | +import { FormBase } from '../../shared/dynamic-form/types/form-element-base'; |
| 5 | +import { TableAppearanceOptions } from '../../_constants/enums'; |
| 6 | +import { EVENT_GROUP_LINK_EVENT_FILTERS_FORM_ID } from '../../_constants/form-identifiers'; |
| 7 | +import { Filter, TableColumn } from '../../_models/common'; |
| 8 | +import { EventDto } from '../../_models/eventDto'; |
| 9 | +import { EventService } from '../../_services/api/event.service'; |
| 10 | +import { FilterService } from '../../_services/filter.service'; |
| 11 | +import { FORM_DATA_EVENT_GROUP_LINK_EVENT_FILTERS } from '../event-group-link-events-modal-filters/event-group-link-events-modal-filters-form-data'; |
| 12 | +import { defaultColumnDefs } from './event-group-link-events-modal-table-data'; |
| 13 | + |
| 14 | +@Component({ |
| 15 | + selector: 'app-event-group-link-events-modal', |
| 16 | + templateUrl: './event-group-link-events-modal.component.html', |
| 17 | + styleUrls: ['./event-group-link-events-modal.component.scss'], |
| 18 | +}) |
| 19 | +export class EventGroupLinkEventsModalComponent implements OnInit { |
| 20 | + defaultColumns: TableColumn[] = []; |
| 21 | + filtersForm = new FormGroup({}); |
| 22 | + selectedEvent: EventDto | null; |
| 23 | + presetFilters: Filter[]; |
| 24 | + tableAppearanceOptions = TableAppearanceOptions; |
| 25 | + filtersData: FormBase<any>[] = JSON.parse( |
| 26 | + JSON.stringify(FORM_DATA_EVENT_GROUP_LINK_EVENT_FILTERS) |
| 27 | + ); |
| 28 | + formId = EVENT_GROUP_LINK_EVENT_FILTERS_FORM_ID; |
| 29 | + |
| 30 | + constructor( |
| 31 | + public dialogRef: MatDialogRef<EventGroupLinkEventsModalComponent>, |
| 32 | + @Inject(MAT_DIALOG_DATA) public data: any, |
| 33 | + public eventService: EventService, |
| 34 | + public filterService: FilterService |
| 35 | + ) {} |
| 36 | + |
| 37 | + ngOnInit(): void { |
| 38 | + this.defaultColumns = defaultColumnDefs; |
| 39 | + this.presetFilters = [ |
| 40 | + { |
| 41 | + field: 'excludedUuids', |
| 42 | + value: this.data.excludeIds, |
| 43 | + }, |
| 44 | + ]; |
| 45 | + } |
| 46 | + |
| 47 | + onSelectEvent(event: any): void { |
| 48 | + this.selectedEvent = null; |
| 49 | + if (event.selected.length) { |
| 50 | + // eslint-disable-next-line prefer-destructuring |
| 51 | + this.selectedEvent = event.selected[0]; |
| 52 | + } |
| 53 | + } |
| 54 | + |
| 55 | + resetFilters(): void { |
| 56 | + this.filterService.setFilters([]); |
| 57 | + } |
| 58 | + |
| 59 | + confirm(): void { |
| 60 | + this.dialogRef.close({ |
| 61 | + selectedEvent: this.selectedEvent, |
| 62 | + }); |
| 63 | + } |
| 64 | +} |
0 commit comments