From e4fb4030054477fb8eeca3a7a9ff1b65e1968b86 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=A0=D0=B0=D1=83=D1=84=20=D0=9B=D0=B0=D1=82=D1=8B=D0=BF?= =?UTF-8?q?=D0=BE=D0=B2?= Date: Thu, 24 Apr 2025 23:17:20 +0300 Subject: [PATCH] SUPPORT-9137: custom DateTimePicker filter component --- .../CurrentDateWithShiftFilterComponent.ts | 57 +++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 frontend/src/ts/ervu-dashboard/component/filter/CurrentDateWithShiftFilterComponent.ts diff --git a/frontend/src/ts/ervu-dashboard/component/filter/CurrentDateWithShiftFilterComponent.ts b/frontend/src/ts/ervu-dashboard/component/filter/CurrentDateWithShiftFilterComponent.ts new file mode 100644 index 00000000..8f2c4d83 --- /dev/null +++ b/frontend/src/ts/ervu-dashboard/component/filter/CurrentDateWithShiftFilterComponent.ts @@ -0,0 +1,57 @@ +import { + AnalyticalScope, + DateTimePicker, + DateTimeUtil, + DateValueType, + Filter, + FilterComponent, + FilterOperation, + FilterUtil +} from "@webbpm/base-package"; +import {Moment} from "moment-timezone"; + +@AnalyticalScope(DateTimePicker) +export class CurrentDateWithShiftFilterComponent extends FilterComponent { + public shift: number; + private dateTimePicker: DateTimePicker; + + public initialize(): void { + super.initialize(); + this.dateTimePicker = this.getScript(DateTimePicker); + } + + getFilter(): Filter { + if (!this.dateTimePicker) { + return null; + } + + const value: Moment = this.dateTimePicker.isValueEmpty() + ? DateTimeUtil.getCurrentDateInMidnight().add(this.shift, 'years') + : this.dateTimePicker.getValueAsMoment().clone(); + + let filterValue: string; + const dateValueType: DateValueType = this.dateTimePicker.getDateValueType(); + switch (dateValueType) { + case DateValueType.DATE: + switch (this.operation) { + case FilterOperation.GREATER_THAN: + case FilterOperation.LESS_OR_EQUAL: + value.hours(23); + value.minutes(59); + value.seconds(59); + value.milliseconds(999); + filterValue = DateTimeUtil.transformToString(value); + break; + default: + filterValue = DateTimeUtil.formatToDate(value); + break; + } + break; + case DateValueType.DATETIME: + filterValue = DateTimeUtil.formatToTimestamp(value); + break; + } + + return FilterUtil.singleValueFilter(this.getObjectId(), filterValue, this.operation); + } +}