Update compact-filter.component.ts
This commit is contained in:
parent
c6ad8b5c2f
commit
cdcf1e07c7
@ -1,4 +1,4 @@
|
|||||||
import { Component, OnInit, Input, Output, EventEmitter } from '@angular/core';
|
import { Component, OnInit, Input, Output, EventEmitter, OnChanges, SimpleChanges } from '@angular/core';
|
||||||
import { FilterService, Filter } from './filter.service';
|
import { FilterService, Filter } from './filter.service';
|
||||||
import { AlertsService } from 'src/app/services/fnd/alerts.service';
|
import { AlertsService } from 'src/app/services/fnd/alerts.service';
|
||||||
|
|
||||||
@ -7,7 +7,7 @@ import { AlertsService } from 'src/app/services/fnd/alerts.service';
|
|||||||
templateUrl: './compact-filter.component.html',
|
templateUrl: './compact-filter.component.html',
|
||||||
styleUrls: ['./compact-filter.component.scss']
|
styleUrls: ['./compact-filter.component.scss']
|
||||||
})
|
})
|
||||||
export class CompactFilterComponent implements OnInit {
|
export class CompactFilterComponent implements OnInit, OnChanges {
|
||||||
@Input() filterKey: string = '';
|
@Input() filterKey: string = '';
|
||||||
@Input() filterType: string = 'text';
|
@Input() filterType: string = 'text';
|
||||||
@Input() filterOptions: string[] = [];
|
@Input() filterOptions: string[] = [];
|
||||||
@ -67,6 +67,51 @@ export class CompactFilterComponent implements OnInit {
|
|||||||
this.loadAvailableValues(this.filterKey);
|
this.loadAvailableValues(this.filterKey);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Register this filter with the filter service
|
||||||
|
this.registerFilter();
|
||||||
|
}
|
||||||
|
|
||||||
|
ngOnChanges(changes: SimpleChanges): void {
|
||||||
|
// If filterKey or filterType changes, re-register the filter
|
||||||
|
if (changes.filterKey || changes.filterType) {
|
||||||
|
this.registerFilter();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Register this filter with the filter service
|
||||||
|
registerFilter(): void {
|
||||||
|
if (this.filterKey) {
|
||||||
|
// Create a filter definition for this compact filter
|
||||||
|
const filterDef: Filter = {
|
||||||
|
id: `compact-filter-${this.filterKey}`,
|
||||||
|
field: this.filterKey,
|
||||||
|
label: this.filterLabel || this.filterKey,
|
||||||
|
type: this.filterType as any,
|
||||||
|
options: this.filterOptions,
|
||||||
|
value: this.filterValue
|
||||||
|
};
|
||||||
|
|
||||||
|
// Get current filters
|
||||||
|
const currentFilters = this.filterService.getFilters();
|
||||||
|
|
||||||
|
// Check if this filter is already registered
|
||||||
|
const existingFilterIndex = currentFilters.findIndex(f => f.id === filterDef.id);
|
||||||
|
|
||||||
|
if (existingFilterIndex >= 0) {
|
||||||
|
// Update existing filter
|
||||||
|
currentFilters[existingFilterIndex] = filterDef;
|
||||||
|
} else {
|
||||||
|
// Add new filter
|
||||||
|
currentFilters.push(filterDef);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Update the filter service with the new filter list
|
||||||
|
this.filterService.setFilters(currentFilters);
|
||||||
|
|
||||||
|
// Update the selected filter reference
|
||||||
|
this.selectedFilter = filterDef;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
updateSelectedFilter(): void {
|
updateSelectedFilter(): void {
|
||||||
@ -175,6 +220,9 @@ export class CompactFilterComponent implements OnInit {
|
|||||||
this.loadAvailableValues(this.filterKey);
|
this.loadAvailableValues(this.filterKey);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Register the updated filter with the filter service
|
||||||
|
this.registerFilter();
|
||||||
|
|
||||||
// Update selected filter
|
// Update selected filter
|
||||||
this.updateSelectedFilter();
|
this.updateSelectedFilter();
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user