mirror of
https://github.com/hcengineering/platform.git
synced 2025-06-09 01:10:17 +00:00
Yesterday date filter (#3190)
Signed-off-by: Denis Bykhov <bykhov.denis@gmail.com>
This commit is contained in:
parent
a71127828a
commit
bb53cd615f
@ -819,6 +819,17 @@ export function createModel (builder: Builder): void {
|
|||||||
view.filter.FilterDateToday
|
view.filter.FilterDateToday
|
||||||
)
|
)
|
||||||
|
|
||||||
|
builder.createDoc(
|
||||||
|
view.class.FilterMode,
|
||||||
|
core.space.Model,
|
||||||
|
{
|
||||||
|
label: view.string.Today,
|
||||||
|
result: view.function.FilterDateYesterday,
|
||||||
|
disableValueSelector: true
|
||||||
|
},
|
||||||
|
view.filter.FilterDateYesterday
|
||||||
|
)
|
||||||
|
|
||||||
builder.createDoc(
|
builder.createDoc(
|
||||||
view.class.FilterMode,
|
view.class.FilterMode,
|
||||||
core.space.Model,
|
core.space.Model,
|
||||||
|
@ -108,6 +108,7 @@ export default mergeIds(viewId, view, {
|
|||||||
FilterNestedDontMatchResult: '' as FilterFunction,
|
FilterNestedDontMatchResult: '' as FilterFunction,
|
||||||
FilterDateOutdated: '' as FilterFunction,
|
FilterDateOutdated: '' as FilterFunction,
|
||||||
FilterDateToday: '' as FilterFunction,
|
FilterDateToday: '' as FilterFunction,
|
||||||
|
FilterDateYesterday: '' as FilterFunction,
|
||||||
FilterDateWeek: '' as FilterFunction,
|
FilterDateWeek: '' as FilterFunction,
|
||||||
FilterDateNextWeek: '' as FilterFunction,
|
FilterDateNextWeek: '' as FilterFunction,
|
||||||
FilterDateMonth: '' as FilterFunction,
|
FilterDateMonth: '' as FilterFunction,
|
||||||
|
@ -31,6 +31,7 @@
|
|||||||
? [
|
? [
|
||||||
view.filter.FilterDateOutdated,
|
view.filter.FilterDateOutdated,
|
||||||
view.filter.FilterDateToday,
|
view.filter.FilterDateToday,
|
||||||
|
view.filter.FilterDateYesterday,
|
||||||
view.filter.FilterDateWeek,
|
view.filter.FilterDateWeek,
|
||||||
view.filter.FilterDateNextW,
|
view.filter.FilterDateNextW,
|
||||||
view.filter.FilterDateM,
|
view.filter.FilterDateM,
|
||||||
@ -38,7 +39,13 @@
|
|||||||
view.filter.FilterDateCustom,
|
view.filter.FilterDateCustom,
|
||||||
view.filter.FilterDateNotSpecified
|
view.filter.FilterDateNotSpecified
|
||||||
]
|
]
|
||||||
: [view.filter.FilterDateToday, view.filter.FilterDateWeek, view.filter.FilterDateM, view.filter.FilterDateCustom]
|
: [
|
||||||
|
view.filter.FilterDateToday,
|
||||||
|
view.filter.FilterDateYesterday,
|
||||||
|
view.filter.FilterDateWeek,
|
||||||
|
view.filter.FilterDateM,
|
||||||
|
view.filter.FilterDateCustom
|
||||||
|
]
|
||||||
filter.mode = filter.mode === undefined ? filter.modes[0] : filter.mode
|
filter.mode = filter.mode === undefined ? filter.modes[0] : filter.mode
|
||||||
|
|
||||||
const client = getClient()
|
const client = getClient()
|
||||||
|
@ -98,17 +98,24 @@ export async function dateOutdated (filter: Filter): Promise<ObjQueryType<any>>
|
|||||||
}
|
}
|
||||||
|
|
||||||
export async function dateToday (filter: Filter): Promise<ObjQueryType<any>> {
|
export async function dateToday (filter: Filter): Promise<ObjQueryType<any>> {
|
||||||
const todayStart = new Date().setUTCHours(0, 0, 0, 0)
|
const todayStart = new Date().setHours(0, 0, 0, 0)
|
||||||
const todayEnd = new Date().setUTCHours(23, 59, 59, 999)
|
const todayEnd = new Date().setHours(23, 59, 59, 999)
|
||||||
return { $gte: todayStart, $lte: todayEnd }
|
return { $gte: todayStart, $lte: todayEnd }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export async function dateYesterday (filter: Filter): Promise<ObjQueryType<any>> {
|
||||||
|
const yesterday = new Date(new Date().setDate(new Date().getDate() - 1))
|
||||||
|
const yesterdayStart = new Date(yesterday).setHours(0, 0, 0, 0)
|
||||||
|
const yesterdayEnd = new Date(yesterday).setHours(23, 59, 59, 999)
|
||||||
|
return { $gte: yesterdayStart, $lte: yesterdayEnd }
|
||||||
|
}
|
||||||
|
|
||||||
export async function dateWeek (filter: Filter): Promise<ObjQueryType<any>> {
|
export async function dateWeek (filter: Filter): Promise<ObjQueryType<any>> {
|
||||||
const day = new Date().getDay()
|
const day = new Date().getDay()
|
||||||
const startDayDiff = day === 0 ? 6 : day - 1
|
const startDayDiff = day === 0 ? 6 : day - 1
|
||||||
const endDayDiff = 7 - startDayDiff
|
const endDayDiff = 7 - startDayDiff
|
||||||
const weekStart = new Date(new Date().setUTCDate(new Date().getUTCDate() - startDayDiff)).setUTCHours(0, 0, 0, 0)
|
const weekStart = new Date(new Date().setDate(new Date().getDate() - startDayDiff)).setHours(0, 0, 0, 0)
|
||||||
const weekEnd = new Date(new Date().setUTCDate(new Date().getUTCDate() + endDayDiff)).setUTCHours(23, 59, 59, 999)
|
const weekEnd = new Date(new Date().setDate(new Date().getDate() + endDayDiff)).setHours(23, 59, 59, 999)
|
||||||
return { $gte: weekStart, $lte: weekEnd }
|
return { $gte: weekStart, $lte: weekEnd }
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -116,24 +123,24 @@ export async function dateNextWeek (filter: Filter): Promise<ObjQueryType<any>>
|
|||||||
const day = new Date().getDay()
|
const day = new Date().getDay()
|
||||||
const startDayDiff = day === 0 ? 6 : day - 1
|
const startDayDiff = day === 0 ? 6 : day - 1
|
||||||
const endDayDiff = 7 - startDayDiff
|
const endDayDiff = 7 - startDayDiff
|
||||||
const weekStart = new Date(new Date().setUTCDate(new Date().getUTCDate() - startDayDiff + 7)).setUTCHours(0, 0, 0, 0)
|
const weekStart = new Date(new Date().setDate(new Date().getDate() - startDayDiff + 7)).setHours(0, 0, 0, 0)
|
||||||
const weekEnd = new Date(new Date().setUTCDate(new Date().getUTCDate() + endDayDiff + 7)).setUTCHours(23, 59, 59, 999)
|
const weekEnd = new Date(new Date().setDate(new Date().getDate() + endDayDiff + 7)).setHours(23, 59, 59, 999)
|
||||||
return { $gte: weekStart, $lte: weekEnd }
|
return { $gte: weekStart, $lte: weekEnd }
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function dateMonth (filter: Filter): Promise<ObjQueryType<any>> {
|
export async function dateMonth (filter: Filter): Promise<ObjQueryType<any>> {
|
||||||
const today = new Date()
|
const today = new Date()
|
||||||
const lastDayOfMonth = new Date(today.getFullYear(), today.getMonth() + 1, 0)
|
const lastDayOfMonth = new Date(today.getFullYear(), today.getMonth() + 1, 0)
|
||||||
const monthStart = new Date(new Date().setUTCDate(1)).setUTCHours(0, 0, 0, 0)
|
const monthStart = new Date(new Date().setDate(1)).setHours(0, 0, 0, 0)
|
||||||
const monthEnd = lastDayOfMonth.setUTCHours(23, 59, 59, 999)
|
const monthEnd = lastDayOfMonth.setHours(23, 59, 59, 999)
|
||||||
return { $gte: monthStart, $lte: monthEnd }
|
return { $gte: monthStart, $lte: monthEnd }
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function dateNextMonth (filter: Filter): Promise<ObjQueryType<any>> {
|
export async function dateNextMonth (filter: Filter): Promise<ObjQueryType<any>> {
|
||||||
const today = new Date()
|
const today = new Date()
|
||||||
const lastDayOfMonth = new Date(today.getFullYear(), today.getMonth() + 2, 0)
|
const lastDayOfMonth = new Date(today.getFullYear(), today.getMonth() + 2, 0)
|
||||||
const monthStart = new Date(new Date().setUTCMonth(new Date().getUTCMonth() + 1, 1)).setUTCHours(0, 0, 0, 0)
|
const monthStart = new Date(new Date().setMonth(new Date().getMonth() + 1, 1)).setHours(0, 0, 0, 0)
|
||||||
const monthEnd = lastDayOfMonth.setUTCHours(23, 59, 59, 999)
|
const monthEnd = lastDayOfMonth.setHours(23, 59, 59, 999)
|
||||||
return { $gte: monthStart, $lte: monthEnd }
|
return { $gte: monthStart, $lte: monthEnd }
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -143,13 +150,13 @@ export async function dateNotSpecified (filter: Filter): Promise<ObjQueryType<an
|
|||||||
|
|
||||||
export async function dateCustom (filter: Filter): Promise<ObjQueryType<any>> {
|
export async function dateCustom (filter: Filter): Promise<ObjQueryType<any>> {
|
||||||
if (filter.value.length === 1) {
|
if (filter.value.length === 1) {
|
||||||
const todayStart = new Date(filter.value[0]).setUTCHours(0, 0, 0, 0)
|
const todayStart = new Date(filter.value[0]).setHours(0, 0, 0, 0)
|
||||||
const todayEnd = new Date(filter.value[0]).setUTCHours(23, 59, 59, 999)
|
const todayEnd = new Date(filter.value[0]).setHours(23, 59, 59, 999)
|
||||||
return { $gte: todayStart, $lte: todayEnd }
|
return { $gte: todayStart, $lte: todayEnd }
|
||||||
}
|
}
|
||||||
if (filter.value.length === 2) {
|
if (filter.value.length === 2) {
|
||||||
const todayStart = new Date(filter.value[0]).setUTCHours(0, 0, 0, 0)
|
const todayStart = new Date(filter.value[0]).setHours(0, 0, 0, 0)
|
||||||
const todayEnd = new Date(filter.value[1]).setUTCHours(23, 59, 59, 999)
|
const todayEnd = new Date(filter.value[1]).setHours(23, 59, 59, 999)
|
||||||
return { $gte: todayStart, $lte: todayEnd }
|
return { $gte: todayStart, $lte: todayEnd }
|
||||||
}
|
}
|
||||||
return await dateNotSpecified(filter)
|
return await dateNotSpecified(filter)
|
||||||
|
@ -86,6 +86,7 @@ import {
|
|||||||
dateNotSpecified,
|
dateNotSpecified,
|
||||||
dateOutdated,
|
dateOutdated,
|
||||||
dateToday,
|
dateToday,
|
||||||
|
dateYesterday,
|
||||||
dateWeek,
|
dateWeek,
|
||||||
nestedDontMatchResult,
|
nestedDontMatchResult,
|
||||||
nestedMatchResult,
|
nestedMatchResult,
|
||||||
@ -240,6 +241,7 @@ export default async (): Promise<Resources> => ({
|
|||||||
StatusSort: statusSort,
|
StatusSort: statusSort,
|
||||||
FilterDateOutdated: dateOutdated,
|
FilterDateOutdated: dateOutdated,
|
||||||
FilterDateToday: dateToday,
|
FilterDateToday: dateToday,
|
||||||
|
FilterDateYesterday: dateYesterday,
|
||||||
FilterDateWeek: dateWeek,
|
FilterDateWeek: dateWeek,
|
||||||
FilterDateNextWeek: dateNextWeek,
|
FilterDateNextWeek: dateNextWeek,
|
||||||
FilterDateMonth: dateMonth,
|
FilterDateMonth: dateMonth,
|
||||||
|
@ -755,6 +755,7 @@ const view = plugin(viewId, {
|
|||||||
FilterNestedDontMatch: '' as Ref<FilterMode>,
|
FilterNestedDontMatch: '' as Ref<FilterMode>,
|
||||||
FilterDateOutdated: '' as Ref<FilterMode>,
|
FilterDateOutdated: '' as Ref<FilterMode>,
|
||||||
FilterDateToday: '' as Ref<FilterMode>,
|
FilterDateToday: '' as Ref<FilterMode>,
|
||||||
|
FilterDateYesterday: '' as Ref<FilterMode>,
|
||||||
FilterDateWeek: '' as Ref<FilterMode>,
|
FilterDateWeek: '' as Ref<FilterMode>,
|
||||||
FilterDateNextW: '' as Ref<FilterMode>,
|
FilterDateNextW: '' as Ref<FilterMode>,
|
||||||
FilterDateM: '' as Ref<FilterMode>,
|
FilterDateM: '' as Ref<FilterMode>,
|
||||||
|
Loading…
Reference in New Issue
Block a user