diff --git a/src-ui/messages.xlf b/src-ui/messages.xlf index 5931ea867..1c9cb7f59 100644 --- a/src-ui/messages.xlf +++ b/src-ui/messages.xlf @@ -1120,7 +1120,7 @@ src/app/components/document-list/filter-editor/filter-editor.component.ts - 173 + 193 @@ -3358,6 +3358,10 @@ src/app/components/common/dates-dropdown/dates-dropdown.component.html 163 + + src/app/components/common/dates-dropdown/dates-dropdown.component.ts + 103 + src/app/components/common/input/date/date.component.html 21 @@ -3517,7 +3521,7 @@ now src/app/components/common/dates-dropdown/dates-dropdown.component.html - 32 + 31 src/app/components/common/dates-dropdown/dates-dropdown.component.html @@ -3573,28 +3577,53 @@ Within 1 week src/app/components/common/dates-dropdown/dates-dropdown.component.ts - 70 + 73 Within 1 month src/app/components/common/dates-dropdown/dates-dropdown.component.ts - 75 + 78 Within 3 months src/app/components/common/dates-dropdown/dates-dropdown.component.ts - 80 + 83 Within 1 year src/app/components/common/dates-dropdown/dates-dropdown.component.ts - 85 + 88 + + + + This year + + src/app/components/common/dates-dropdown/dates-dropdown.component.ts + 93 + + + + This month + + src/app/components/common/dates-dropdown/dates-dropdown.component.ts + 98 + + + + Yesterday + + src/app/components/common/dates-dropdown/dates-dropdown.component.ts + 108 + + + src/app/pipes/custom-date.pipe.ts + 29 @@ -6519,7 +6548,7 @@ src/app/components/document-list/filter-editor/filter-editor.component.ts - 160 + 180 src/app/data/document.ts @@ -7147,7 +7176,7 @@ src/app/components/document-list/filter-editor/filter-editor.component.ts - 168 + 188 @@ -7749,7 +7778,7 @@ src/app/components/document-list/filter-editor/filter-editor.component.ts - 165 + 185 src/app/data/document.ts @@ -7945,154 +7974,154 @@ Title & content src/app/components/document-list/filter-editor/filter-editor.component.ts - 163 + 183 File type src/app/components/document-list/filter-editor/filter-editor.component.ts - 170 + 190 More like src/app/components/document-list/filter-editor/filter-editor.component.ts - 179 + 199 equals src/app/components/document-list/filter-editor/filter-editor.component.ts - 185 + 205 is empty src/app/components/document-list/filter-editor/filter-editor.component.ts - 189 + 209 is not empty src/app/components/document-list/filter-editor/filter-editor.component.ts - 193 + 213 greater than src/app/components/document-list/filter-editor/filter-editor.component.ts - 197 + 217 less than src/app/components/document-list/filter-editor/filter-editor.component.ts - 201 + 221 Correspondent: src/app/components/document-list/filter-editor/filter-editor.component.ts - 233,235 + 253,255 Without correspondent src/app/components/document-list/filter-editor/filter-editor.component.ts - 237 + 257 Document type: src/app/components/document-list/filter-editor/filter-editor.component.ts - 243,245 + 263,265 Without document type src/app/components/document-list/filter-editor/filter-editor.component.ts - 247 + 267 Storage path: src/app/components/document-list/filter-editor/filter-editor.component.ts - 253,255 + 273,275 Without storage path src/app/components/document-list/filter-editor/filter-editor.component.ts - 257 + 277 Tag: src/app/components/document-list/filter-editor/filter-editor.component.ts - 261,263 + 281,283 Without any tag src/app/components/document-list/filter-editor/filter-editor.component.ts - 267 + 287 Custom fields query src/app/components/document-list/filter-editor/filter-editor.component.ts - 271 + 291 Title: src/app/components/document-list/filter-editor/filter-editor.component.ts - 274 + 294 ASN: src/app/components/document-list/filter-editor/filter-editor.component.ts - 277 + 297 Owner: src/app/components/document-list/filter-editor/filter-editor.component.ts - 280 + 300 Owner not in: src/app/components/document-list/filter-editor/filter-editor.component.ts - 283 + 303 Without an owner src/app/components/document-list/filter-editor/filter-editor.component.ts - 286 + 306 @@ -9426,13 +9455,6 @@ 25 - - Yesterday - - src/app/pipes/custom-date.pipe.ts - 29 - - %s days ago diff --git a/src-ui/src/app/components/common/dates-dropdown/dates-dropdown.component.ts b/src-ui/src/app/components/common/dates-dropdown/dates-dropdown.component.ts index d56b00358..3645f7ddc 100644 --- a/src-ui/src/app/components/common/dates-dropdown/dates-dropdown.component.ts +++ b/src-ui/src/app/components/common/dates-dropdown/dates-dropdown.component.ts @@ -1,4 +1,4 @@ -import { NgClass, NgTemplateOutlet } from '@angular/common' +import { NgClass } from '@angular/common' import { Component, EventEmitter, @@ -37,6 +37,10 @@ export enum RelativeDate { WITHIN_1_MONTH = 2, WITHIN_3_MONTHS = 3, WITHIN_1_YEAR = 4, + THIS_YEAR = 5, + THIS_MONTH = 6, + TODAY = 7, + YESTERDAY = 8, } @Component({ @@ -54,7 +58,6 @@ export enum RelativeDate { FormsModule, ReactiveFormsModule, NgClass, - NgTemplateOutlet, ], }) export class DatesDropdownComponent implements OnInit, OnDestroy { @@ -85,6 +88,26 @@ export class DatesDropdownComponent implements OnInit, OnDestroy { name: $localize`Within 1 year`, date: new Date().setFullYear(new Date().getFullYear() - 1), }, + { + id: RelativeDate.THIS_YEAR, + name: $localize`This year`, + date: new Date('1/1/' + new Date().getFullYear()), + }, + { + id: RelativeDate.THIS_MONTH, + name: $localize`This month`, + date: new Date().setDate(1), + }, + { + id: RelativeDate.TODAY, + name: $localize`Today`, + date: new Date().setHours(0, 0, 0, 0), + }, + { + id: RelativeDate.YESTERDAY, + name: $localize`Yesterday`, + date: new Date().setDate(new Date().getDate() - 1), + }, ] datePlaceHolder: string @@ -176,6 +199,8 @@ export class DatesDropdownComponent implements OnInit, OnDestroy { } onSetCreatedRelativeDate(rd: { id: number; name: string; date: number }) { + console.log(rd) + // createdRelativeDate is set by ngModel this.createdDateTo = null this.createdDateFrom = null @@ -183,6 +208,8 @@ export class DatesDropdownComponent implements OnInit, OnDestroy { } onSetAddedRelativeDate(rd: { id: number; name: string; date: number }) { + console.log(rd) + // addedRelativeDate is set by ngModel this.addedDateTo = null this.addedDateFrom = null diff --git a/src-ui/src/app/components/document-list/filter-editor/filter-editor.component.spec.ts b/src-ui/src/app/components/document-list/filter-editor/filter-editor.component.spec.ts index c4528637b..58524fa99 100644 --- a/src-ui/src/app/components/document-list/filter-editor/filter-editor.component.spec.ts +++ b/src-ui/src/app/components/document-list/filter-editor/filter-editor.component.spec.ts @@ -96,7 +96,10 @@ import { import { environment } from 'src/environments/environment' import { ClearableBadgeComponent } from '../../common/clearable-badge/clearable-badge.component' import { CustomFieldsQueryDropdownComponent } from '../../common/custom-fields-query-dropdown/custom-fields-query-dropdown.component' -import { DatesDropdownComponent } from '../../common/dates-dropdown/dates-dropdown.component' +import { + DatesDropdownComponent, + RelativeDate, +} from '../../common/dates-dropdown/dates-dropdown.component' import { FilterableDropdownComponent, Intersection, @@ -422,7 +425,7 @@ describe('FilterEditorComponent', () => { value: 'created:[-1 week to now]', }, ] - expect(component.dateCreatedRelativeDate).toEqual(0) // RELATIVE_DATE_QUERYSTRINGS['-1 week to now'] + expect(component.dateCreatedRelativeDate).toEqual(1) // RELATIVE_DATE_QUERYSTRINGS['-1 week to now'] expect(component.textFilter).toBeNull() })) @@ -434,7 +437,7 @@ describe('FilterEditorComponent', () => { value: 'added:[-1 week to now]', }, ] - expect(component.dateAddedRelativeDate).toEqual(0) // RELATIVE_DATE_QUERYSTRINGS['-1 week to now'] + expect(component.dateAddedRelativeDate).toEqual(1) // RELATIVE_DATE_QUERYSTRINGS['-1 week to now'] expect(component.textFilter).toBeNull() })) @@ -1587,10 +1590,8 @@ describe('FilterEditorComponent', () => { const dateCreatedDropdown = fixture.debugElement.queryAll( By.directive(DatesDropdownComponent) )[0] - const dateCreatedBeforeRelativeButton = dateCreatedDropdown.queryAll( - By.css('button') - )[1] - dateCreatedBeforeRelativeButton.triggerEventHandler('click') + component.dateCreatedRelativeDate = RelativeDate.WITHIN_1_WEEK + dateCreatedDropdown.triggerEventHandler('datesSet') fixture.detectChanges() tick(400) expect(component.filterRules).toEqual([ @@ -1606,10 +1607,8 @@ describe('FilterEditorComponent', () => { const dateCreatedDropdown = fixture.debugElement.queryAll( By.directive(DatesDropdownComponent) )[0] - const dateCreatedBeforeRelativeButton = dateCreatedDropdown.queryAll( - By.css('button') - )[1] - dateCreatedBeforeRelativeButton.triggerEventHandler('click') + component.dateCreatedRelativeDate = RelativeDate.WITHIN_1_WEEK + dateCreatedDropdown.triggerEventHandler('datesSet') fixture.detectChanges() tick(400) expect(component.filterRules).toEqual([ @@ -1692,16 +1691,14 @@ describe('FilterEditorComponent', () => { const datesDropdown = fixture.debugElement.query( By.directive(DatesDropdownComponent) ) - const dateCreatedBeforeRelativeButton = datesDropdown.queryAll( - By.css('button') - )[1] - dateCreatedBeforeRelativeButton.triggerEventHandler('click') + component.dateAddedRelativeDate = RelativeDate.WITHIN_1_WEEK + datesDropdown.triggerEventHandler('datesSet') fixture.detectChanges() tick(400) expect(component.filterRules).toEqual([ { rule_type: FILTER_FULLTEXT_QUERY, - value: 'created:[-1 week to now]', + value: 'added:[-1 week to now]', }, ]) })) @@ -1711,16 +1708,14 @@ describe('FilterEditorComponent', () => { const datesDropdown = fixture.debugElement.query( By.directive(DatesDropdownComponent) ) - const dateCreatedBeforeRelativeButton = datesDropdown.queryAll( - By.css('button') - )[1] - dateCreatedBeforeRelativeButton.triggerEventHandler('click') + component.dateAddedRelativeDate = RelativeDate.WITHIN_1_WEEK + datesDropdown.triggerEventHandler('datesSet') fixture.detectChanges() tick(400) expect(component.filterRules).toEqual([ { rule_type: FILTER_FULLTEXT_QUERY, - value: 'foo,created:[-1 week to now]', + value: 'foo,added:[-1 week to now]', }, ]) })) diff --git a/src-ui/src/app/components/document-list/filter-editor/filter-editor.component.ts b/src-ui/src/app/components/document-list/filter-editor/filter-editor.component.ts index 0916d9c0d..900e72785 100644 --- a/src-ui/src/app/components/document-list/filter-editor/filter-editor.component.ts +++ b/src-ui/src/app/components/document-list/filter-editor/filter-editor.component.ts @@ -135,24 +135,44 @@ const TEXT_FILTER_MODIFIER_NOTNULL = 'not null' const TEXT_FILTER_MODIFIER_GT = 'greater' const TEXT_FILTER_MODIFIER_LT = 'less' -const RELATIVE_DATE_QUERY_REGEXP_CREATED = /created:\[([^\]]+)\]/g -const RELATIVE_DATE_QUERY_REGEXP_ADDED = /added:\[([^\]]+)\]/g +const RELATIVE_DATE_QUERY_REGEXP_CREATED = /created:[\["]([^\]]+)[\]"]/g +const RELATIVE_DATE_QUERY_REGEXP_ADDED = /added:[\["]([^\]]+)[\]"]/g const RELATIVE_DATE_QUERYSTRINGS = [ { relativeDate: RelativeDate.WITHIN_1_WEEK, dateQuery: '-1 week to now', + isRange: true, }, { relativeDate: RelativeDate.WITHIN_1_MONTH, dateQuery: '-1 month to now', + isRange: true, }, { relativeDate: RelativeDate.WITHIN_3_MONTHS, dateQuery: '-3 month to now', + isRange: true, }, { relativeDate: RelativeDate.WITHIN_1_YEAR, dateQuery: '-1 year to now', + isRange: true, + }, + { + relativeDate: RelativeDate.THIS_YEAR, + dateQuery: 'this year', + }, + { + relativeDate: RelativeDate.THIS_MONTH, + dateQuery: 'this month', + }, + { + relativeDate: RelativeDate.TODAY, + dateQuery: 'today', + }, + { + relativeDate: RelativeDate.YESTERDAY, + dateQuery: 'yesterday', }, ] @@ -907,12 +927,11 @@ export class FilterEditorComponent let existingRuleArgs = existingRule?.value.split(',') if (this.dateCreatedRelativeDate !== null) { + const rd = RELATIVE_DATE_QUERYSTRINGS.find( + (qS) => qS.relativeDate == this.dateCreatedRelativeDate + ) queryArgs.push( - `created:[${ - RELATIVE_DATE_QUERYSTRINGS.find( - (qS) => qS.relativeDate == this.dateCreatedRelativeDate - ).dateQuery - }]` + `created:${rd.isRange ? `[${rd.dateQuery}]` : `"${rd.dateQuery}"`}` ) if (existingRule) { queryArgs = existingRuleArgs @@ -921,12 +940,11 @@ export class FilterEditorComponent } } if (this.dateAddedRelativeDate !== null) { + const rd = RELATIVE_DATE_QUERYSTRINGS.find( + (qS) => qS.relativeDate == this.dateAddedRelativeDate + ) queryArgs.push( - `added:[${ - RELATIVE_DATE_QUERYSTRINGS.find( - (qS) => qS.relativeDate == this.dateAddedRelativeDate - ).dateQuery - }]` + `added:${rd.isRange ? `[${rd.dateQuery}]` : `"${rd.dateQuery}"`}` ) if (existingRule) { queryArgs = existingRuleArgs