94 lines
2.6 KiB
TypeScript
94 lines
2.6 KiB
TypeScript
import { Component, EventEmitter, Input, OnInit, Output, SimpleChanges, OnChanges } from '@angular/core';
|
|
import { BaseComponent } from '@common/base/base.component';
|
|
import { IsActive } from '@app/core/common/enum/is-active.enum';
|
|
import { NotificationInAppTracking } from '@app/core/common/enum/notification-inapp-tracking.enum';
|
|
import { EnumUtils } from '@app/core/services/utilities/enum-utils.service';
|
|
import { InAppNotificationFilter } from '@app/core/query/inapp-notification.lookup';
|
|
import { nameof } from 'ts-simple-nameof';
|
|
@Component({
|
|
selector: 'app-mine-inapp-notification-listing-filters',
|
|
templateUrl: './mine-inapp-notification-listing-filters.component.html',
|
|
styleUrls: ['./mine-inapp-notification-listing-filters.component.scss']
|
|
})
|
|
export class MineInAppNotificationListingFiltersComponent extends BaseComponent implements OnInit, OnChanges {
|
|
|
|
@Input() readonly filter: InAppNotificationFilter;
|
|
@Output() filterChange = new EventEmitter<InAppNotificationFilter>();
|
|
|
|
notificationInAppTrackingEnumValues = this.enumUtils.getEnumValues<NotificationInAppTracking>(NotificationInAppTracking);
|
|
|
|
// * State
|
|
internalFilters: InAppNotificationListingFilters = this._getEmptyFilters();
|
|
|
|
protected appliedFilterCount: number = 0;
|
|
constructor(
|
|
public enumUtils: EnumUtils,
|
|
) { super(); }
|
|
|
|
ngOnInit() {
|
|
}
|
|
|
|
ngOnChanges(changes: SimpleChanges): void {
|
|
const filterChange = changes[nameof<MineInAppNotificationListingFiltersComponent>(x => x.filter)]?.currentValue as InAppNotificationFilter;
|
|
if (filterChange) {
|
|
this.updateFilters()
|
|
}
|
|
}
|
|
|
|
|
|
onSearchTermChange(searchTerm: string): void {
|
|
this.applyFilters()
|
|
}
|
|
|
|
|
|
protected updateFilters(): void {
|
|
this.internalFilters = this._parseToInternalFilters(this.filter);
|
|
this.appliedFilterCount = this._computeAppliedFilters(this.internalFilters);
|
|
}
|
|
|
|
protected applyFilters(): void {
|
|
const { like, trackingState } = this.internalFilters ?? {}
|
|
this.filterChange.emit({
|
|
...this.filter,
|
|
like,
|
|
trackingState
|
|
})
|
|
}
|
|
|
|
|
|
private _parseToInternalFilters(inputFilter: InAppNotificationFilter): InAppNotificationListingFilters {
|
|
if (!inputFilter) {
|
|
return this._getEmptyFilters();
|
|
}
|
|
|
|
let { like, trackingState } = inputFilter;
|
|
|
|
return {
|
|
like: like,
|
|
trackingState: trackingState
|
|
}
|
|
|
|
}
|
|
|
|
private _getEmptyFilters(): InAppNotificationListingFilters {
|
|
return {
|
|
like: null,
|
|
trackingState: null
|
|
}
|
|
}
|
|
|
|
private _computeAppliedFilters(filters: InAppNotificationListingFilters): number {
|
|
let count = 0;
|
|
return count;
|
|
}
|
|
|
|
clearFilters() {
|
|
this.internalFilters = this._getEmptyFilters();
|
|
}
|
|
}
|
|
|
|
interface InAppNotificationListingFilters {
|
|
like: string;
|
|
trackingState: NotificationInAppTracking[];
|
|
}
|