A community-supported supercharged document management system: scan, index and archive all your documents
Python aiangulararchivingdjangodmsdocument-managementdocument-management-systemllmmachine-learningocroptical-character-recognitionpdf
Fix: allow relative date queries not in quick list (#5801)
shamoon47dfe85a7c5d
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.tsindex 1f7874669..e091dbf15 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@@ -381,6 +381,28 @@ describe('FilterEditorComponent', () => {expect(component.textFilter).toBeNull()}))+ it('should ingest text filter content with relative dates that are not in quick list', fakeAsync(() => {+ expect(component.dateAddedRelativeDate).toBeNull()+ component.filterRules = [+ {+ rule_type: FILTER_FULLTEXT_QUERY,+ value: 'added:[-2 week to now]',+ },+ ]+ expect(component.dateAddedRelativeDate).toBeNull()+ expect(component.textFilter).toEqual('added:[-2 week to now]')++ expect(component.dateCreatedRelativeDate).toBeNull()+ component.filterRules = [+ {+ rule_type: FILTER_FULLTEXT_QUERY,+ value: 'created:[-2 week to now]',+ },+ ]+ expect(component.dateCreatedRelativeDate).toBeNull()+ expect(component.textFilter).toEqual('created:[-2 week to now]')+ }))+it('should ingest text filter rules for more like', fakeAsync(() => {const moreLikeSpy = jest.spyOn(documentService, 'get')moreLikeSpy.mockReturnValue(of({ id: 1, title: 'Foo Bar' }))@@ -1372,6 +1394,34 @@ describe('FilterEditorComponent', () => {])}))+ it('should leave relative dates not in quick list intact', fakeAsync(() => {+ component.textFilterInput.nativeElement.value = 'created:[-2 week to now]'+ component.textFilterInput.nativeElement.dispatchEvent(new Event('input'))+ const textFieldTargetDropdown = fixture.debugElement.queryAll(+ By.directive(NgbDropdownItem)+ )[4]+ textFieldTargetDropdown.triggerEventHandler('click')+ fixture.detectChanges()+ tick(400)+ expect(component.filterRules).toEqual([+ {+ rule_type: FILTER_FULLTEXT_QUERY,+ value: 'created:[-2 week to now]',+ },+ ])++ component.textFilterInput.nativeElement.value = 'added:[-2 month to now]'+ component.textFilterInput.nativeElement.dispatchEvent(new Event('input'))+ fixture.detectChanges()+ tick(400)+ expect(component.filterRules).toEqual([+ {+ rule_type: FILTER_FULLTEXT_QUERY,+ value: 'added:[-2 month to now]',+ },+ ])+ }))+it('should convert user input to correct filter rules on date added after', fakeAsync(() => {const dateAddedDropdown = fixture.debugElement.queryAll(By.directive(DateDropdownComponent)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.tsindex b11874d7c..a6aafe049 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@@ -362,10 +362,11 @@ export class FilterEditorComponentthis.dateCreatedRelativeDate =RELATIVE_DATE_QUERYSTRINGS.find((qS) => qS.dateQuery == match[1]- )?.relativeDate+ )?.relativeDate ?? null}})+ if (this.dateCreatedRelativeDate === null) textQueryArgs.push(arg) // relative query not in the quick list} else if (arg.match(RELATIVE_DATE_QUERY_REGEXP_ADDED)) {;[...arg.matchAll(RELATIVE_DATE_QUERY_REGEXP_ADDED)].forEach((match) => {@@ -373,10 +374,11 @@ export class FilterEditorComponentthis.dateAddedRelativeDate =RELATIVE_DATE_QUERYSTRINGS.find((qS) => qS.dateQuery == match[1]- )?.relativeDate+ )?.relativeDate ?? null}})+ if (this.dateAddedRelativeDate === null) textQueryArgs.push(arg) // relative query not in the quick list} else {textQueryArgs.push(arg)}@@ -787,27 +789,6 @@ export class FilterEditorComponent})}}- if (- this.dateCreatedRelativeDate == null &&- this.dateAddedRelativeDate == null- ) {- const existingRule = filterRules.find(- (fr) => fr.rule_type == FILTER_FULLTEXT_QUERY- )- if (- 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- .replace(RELATIVE_DATE_QUERY_REGEXP_CREATED, '')- .replace(RELATIVE_DATE_QUERY_REGEXP_ADDED, '')- if (existingRule.value.replace(',', '').trim() === '') {- // if its empty now, remove it entirely- filterRules.splice(filterRules.indexOf(existingRule), 1)- }- }- }if (this.permissionsSelectionModel.ownerFilter == OwnerFilterType.SELF) {filterRules.push({rule_type: FILTER_OWNER,