import { Component } from '@angular/core'; import { CopyLinkModalComponent } from '@core/components/copy-link-modal/copy-link-modal.component'; import { FormsService } from '@features/configure-forms/services/forms/forms.service'; import { ALL_SKIP_FILTER, DebounceFactory, PaginationOptions, TopLevelFilter } from '@yourcause/common'; import { I18nService } from '@yourcause/common/i18n'; import { ModalFactory } from '@yourcause/common/modals'; import { ProgramAutomationBuilderModalComponent } from '../program-automation-builder/program-automation-builder-modal/program-automation-builder-modal.component'; import { ProgramAutomationService } from '../program-automation.service'; import { ProgramAutomationRowForUi, ProgramAutomationTableAction, Program_Automation_Table_Key } from '../program-automation.typing'; @Component({ selector: 'gc-program-automation-table', templateUrl: './program-automation-table.component.html', styleUrls: ['./program-automation-table.component.scss'] }) export class ProgramAutomationTableComponent { tableDataFactory = DebounceFactory.createSimple( (options: PaginationOptions) => { return this.programAutomationService.getAutomationRules(options); } ); routingFormOptions = this.formService.getRoutingFormOptions(); topLevelFilters: TopLevelFilter[] = [ new TopLevelFilter( 'text', 'name', '', this.i18n.translate( 'common:textSearchByName', {}, 'Search by name' ) ), new TopLevelFilter( 'typeaheadSingleEquals', 'draft', ALL_SKIP_FILTER, this.i18n.translate( 'GLOBAL:textSearchByStatus', {}, 'Search by status' ), { selectOptions: [{ value: ALL_SKIP_FILTER, label: this.i18n.translate('common:lblAllCap', {}, 'All') }, { value: true, label: this.i18n.translate('common:textDraft', {}, 'Draft') }, { value: false, label: this.i18n.translate('common:textPublished', {}, 'Published') }, { value: 'archived', customValue: true, customColumn: 'isArchived', label: this.i18n.translate('common:textArchived', {}, 'Archived') }] }, this.i18n.translate( 'GLOBAL:textSearchByStatus', {}, 'Search by status' ) ) ]; tableKey = Program_Automation_Table_Key; constructor ( private programAutomationService: ProgramAutomationService, private modalFactory: ModalFactory, private i18n: I18nService, private formService: FormsService ) { } async editRuleset (id: number) { const needsUpdate = await this.modalFactory.open( ProgramAutomationBuilderModalComponent, { id }, { class: 'modal-full-size' } ); if (needsUpdate) { this.programAutomationService.resetProgramAutomationTableRepo(); this.programAutomationService.resetProgramAutomationRules(); } } async publish (row: ProgramAutomationRowForUi) { await this.programAutomationService.handleTableAction(row, ProgramAutomationTableAction.PUBLISH); } async delete (row: ProgramAutomationRowForUi) { await this.programAutomationService.handleTableAction(row, ProgramAutomationTableAction.DELETE); } async archive (row: ProgramAutomationRowForUi) { await this.programAutomationService.handleTableAction(row, ProgramAutomationTableAction.ARCHIVE); } async share (row: ProgramAutomationRowForUi) { await this.modalFactory.open( CopyLinkModalComponent, { modalHeader: this.i18n.translate( 'common:textShare', {}, 'Share' ), modalSubHeader: row.name, route: `/apply/programs/${row.landingLinkGuid}/routing` } ); } }