export interface DateSelection {
before?: string
after?: string
- dateQuery?: string
+ relativeDateID?: number
}
-interface QuickFilter {
- id: number
- name: string
- dateQuery: string
+export enum RelativeDate {
+ LAST_7_DAYS = 0,
+ LAST_MONTH = 1,
+ LAST_3_MONTHS = 2,
+ LAST_YEAR = 3,
}
-const LAST_7_DAYS = 0
-const LAST_MONTH = 1
-const LAST_3_MONTHS = 2
-const LAST_YEAR = 3
-
@Component({
selector: 'app-date-dropdown',
templateUrl: './date-dropdown.component.html',
this.datePlaceHolder = settings.getLocalizedDateInputFormat()
}
- quickFilters: Array<QuickFilter> = [
+ relativeDates = [
{
- id: LAST_7_DAYS,
+ date: RelativeDate.LAST_7_DAYS,
name: $localize`Last 7 days`,
- dateQuery: '-1 week to now',
},
{
- id: LAST_MONTH,
+ date: RelativeDate.LAST_MONTH,
name: $localize`Last month`,
- dateQuery: '-1 month to now',
},
{
- id: LAST_3_MONTHS,
+ date: RelativeDate.LAST_3_MONTHS,
name: $localize`Last 3 months`,
- dateQuery: '-3 month to now',
},
- { id: LAST_YEAR, name: $localize`Last year`, dateQuery: '-1 year to now' },
+ {
+ date: RelativeDate.LAST_YEAR,
+ name: $localize`Last year`,
+ },
]
datePlaceHolder: string
@Output()
dateAfterChange = new EventEmitter<string>()
- quickFilter: number
-
@Input()
- set dateQuery(query: string) {
- this.quickFilter = this.quickFilters.find((qf) => qf.dateQuery == query)?.id
- }
-
- get dateQuery(): string {
- return (
- this.quickFilters.find((qf) => qf.id == this.quickFilter)?.dateQuery ?? ''
- )
- }
+ relativeDate: RelativeDate
@Output()
- dateQueryChange = new EventEmitter<string>()
+ relativeDateChange = new EventEmitter<number>()
@Input()
title: string
get isActive(): boolean {
return (
- this.quickFilter > -1 ||
+ this.relativeDate !== null ||
this.dateAfter?.length > 0 ||
this.dateBefore?.length > 0
)
}
}
- setDateQuickFilter(qf: number) {
+ setRelativeDate(rd: RelativeDate) {
this.dateBefore = null
this.dateAfter = null
- this.quickFilter = this.quickFilter == qf ? null : qf
+ this.relativeDate = this.relativeDate == rd ? null : rd
this.onChange()
}
- qfIsSelected(qf: number) {
- return this.quickFilter == qf
- }
-
onChange() {
this.dateBeforeChange.emit(this.dateBefore)
this.dateAfterChange.emit(this.dateAfter)
- this.dateQueryChange.emit(this.dateQuery)
+ this.relativeDateChange.emit(this.relativeDate)
this.datesSet.emit({
after: this.dateAfter,
before: this.dateBefore,
- dateQuery: this.dateQuery,
+ relativeDateID: this.relativeDate,
})
}
onChangeDebounce() {
- this.dateQuery = null
+ this.relativeDate = null
this.datesSetDebounce$.next({
after: this.dateAfter,
before: this.dateBefore,
import { PaperlessDocument } from 'src/app/data/paperless-document'
import { PaperlessStoragePath } from 'src/app/data/paperless-storage-path'
import { StoragePathService } from 'src/app/services/rest/storage-path.service'
+import { RelativeDate } from '../../common/date-dropdown/date-dropdown.component'
const TEXT_FILTER_TARGET_TITLE = 'title'
const TEXT_FILTER_TARGET_TITLE_CONTENT = 'title-content'
const RELATIVE_DATE_QUERY_REGEXP_CREATED = /created:\[([^\]]+)\]/g
const RELATIVE_DATE_QUERY_REGEXP_ADDED = /added:\[([^\]]+)\]/g
+const RELATIVE_DATE_QUERYSTRINGS = [
+ {
+ relativeDate: RelativeDate.LAST_7_DAYS,
+ dateQuery: '-1 week to now',
+ },
+ {
+ relativeDate: RelativeDate.LAST_MONTH,
+ dateQuery: '-1 month to now',
+ },
+ {
+ relativeDate: RelativeDate.LAST_3_MONTHS,
+ dateQuery: '-3 month to now',
+ },
+ {
+ relativeDate: RelativeDate.LAST_YEAR,
+ dateQuery: '-1 year to now',
+ },
+]
@Component({
selector: 'app-filter-editor',
dateCreatedAfter: string
dateAddedBefore: string
dateAddedAfter: string
- dateCreatedQuery: string
- dateAddedQuery: string
+ dateCreatedRelativeDate: RelativeDate
+ dateAddedRelativeDate: RelativeDate
_unmodifiedFilterRules: FilterRule[] = []
_filterRules: FilterRule[] = []
this.dateAddedAfter = null
this.dateCreatedBefore = null
this.dateCreatedAfter = null
- this.dateCreatedQuery = null
- this.dateAddedQuery = null
+ this.dateCreatedRelativeDate = null
+ this.dateAddedRelativeDate = null
this.textFilterModifier = TEXT_FILTER_MODIFIER_EQUALS
value.forEach((rule) => {
;[...arg.matchAll(RELATIVE_DATE_QUERY_REGEXP_CREATED)].forEach(
(match) => {
if (match[1]?.length) {
- this.dateCreatedQuery = match[1]
+ this.dateCreatedRelativeDate =
+ RELATIVE_DATE_QUERYSTRINGS.find(
+ (qS) => qS.dateQuery == match[1]
+ )?.relativeDate
}
}
)
;[...arg.matchAll(RELATIVE_DATE_QUERY_REGEXP_ADDED)].forEach(
(match) => {
if (match[1]?.length) {
- this.dateAddedQuery = match[1]
+ this.dateAddedRelativeDate =
+ RELATIVE_DATE_QUERYSTRINGS.find(
+ (qS) => qS.dateQuery == match[1]
+ )?.relativeDate
}
}
)
value: this.dateAddedAfter,
})
}
- if (this.dateAddedQuery || this.dateCreatedQuery) {
+ if (
+ this.dateAddedRelativeDate !== null ||
+ this.dateCreatedRelativeDate !== null
+ ) {
let queryArgs: Array<string> = []
- if (this.dateCreatedQuery)
- queryArgs.push(`created:[${this.dateCreatedQuery}]`)
- if (this.dateAddedQuery) queryArgs.push(`added:[${this.dateAddedQuery}]`)
const existingRule = filterRules.find(
(fr) => fr.rule_type == FILTER_FULLTEXT_QUERY
)
- if (existingRule) {
- let existingRuleArgs = existingRule.value.split(',')
- if (this.dateCreatedQuery) {
+ let existingRuleArgs = existingRule?.value.split(',')
+ if (this.dateCreatedRelativeDate !== null) {
+ queryArgs.push(
+ `created:[${
+ RELATIVE_DATE_QUERYSTRINGS.find(
+ (qS) => qS.relativeDate == this.dateCreatedRelativeDate
+ ).dateQuery
+ }]`
+ )
+ if (existingRule) {
queryArgs = existingRuleArgs
- .filter((arg) => !arg.includes('created:'))
+ .filter((arg) => !arg.match(RELATIVE_DATE_QUERY_REGEXP_CREATED))
.concat(queryArgs)
}
- if (this.dateAddedQuery) {
+ }
+ if (this.dateAddedRelativeDate !== null) {
+ queryArgs.push(
+ `added:[${
+ RELATIVE_DATE_QUERYSTRINGS.find(
+ (qS) => qS.relativeDate == this.dateAddedRelativeDate
+ ).dateQuery
+ }]`
+ )
+ if (existingRule) {
queryArgs = existingRuleArgs
- .filter((arg) => !arg.includes('added:'))
+ .filter((arg) => !arg.match(RELATIVE_DATE_QUERY_REGEXP_ADDED))
.concat(queryArgs)
}
+ }
+
+ if (existingRule) {
existingRule.value = queryArgs.join(',')
} else {
filterRules.push({
})
}
}
- if (!this.dateAddedQuery && !this.dateCreatedQuery) {
+ if (
+ this.dateCreatedRelativeDate == null &&
+ this.dateAddedRelativeDate == null
+ ) {
const existingRule = filterRules.find(
(fr) => fr.rule_type == FILTER_FULLTEXT_QUERY
)
if (
- existingRule?.value.includes('created:') ||
- existingRule?.value.includes('added:')
+ existingRule?.value.match(RELATIVE_DATE_QUERY_REGEXP_CREATED) ||
+ existingRule?.value.match(RELATIVE_DATE_QUERY_REGEXP_ADDED)
) {
// remove any existing date query
existingRule.value = existingRule.value
target != TEXT_FILTER_TARGET_FULLTEXT_MORELIKE
) {
this._textFilter = ''
- this.dateAddedQuery = ''
- this.dateCreatedQuery = ''
}
this.textFilterTarget = target
this.textFilterInput.nativeElement.focus()