]> git.ipfire.org Git - thirdparty/paperless-ngx.git/commitdiff
ASN 'is null' from frontend
authorMichael Shamoon <4887959+shamoon@users.noreply.github.com>
Wed, 11 May 2022 04:21:57 +0000 (21:21 -0700)
committerMichael Shamoon <4887959+shamoon@users.noreply.github.com>
Wed, 11 May 2022 04:51:29 +0000 (21:51 -0700)
src-ui/src/app/components/document-list/filter-editor/filter-editor.component.html
src-ui/src/app/components/document-list/filter-editor/filter-editor.component.ts

index 6280cff10eb28e74109f57a3eba35edb46086278..7a0f91899bbd71d61b3a691543747343fd822932 100644 (file)
@@ -8,7 +8,13 @@
               <button *ngFor="let t of textFilterTargets" ngbDropdownItem [class.active]="textFilterTarget == t.id" (click)="changeTextFilterTarget(t.id)">{{t.name}}</button>
             </div>
           </div>
-          <input #textFilterInput class="form-control form-control-sm" type="text" [(ngModel)]="textFilter" (keyup.enter)="textFilterEnter()" [readonly]="textFilterTarget == 'fulltext-morelike'">
+          <div *ngIf="textFilterTarget == 'asn'" class="input-group-text py-0">
+            <div class="form-check form-switch m-0">
+              <input class="form-check-input" type="checkbox" role="switch" [(ngModel)]="textFilterTargetIsNull" (change)="updateRules()">
+              <label class="form-check-label" [class.text-muted]="!textFilterTargetIsNull" i18n>Is empty</label>
+            </div>
+          </div>
+          <input #textFilterInput class="form-control form-control-sm" type="text" [disabled]="textFilterTargetIsNull" [(ngModel)]="textFilter" (keyup.enter)="textFilterEnter()" [readonly]="textFilterTarget == 'fulltext-morelike'">
          </div>
      </div>
   </div>
index b222597fbc9cbd249305eecff1d3cd99eeea8316..acfe2236a6d379ea97ebb8830a49cd3bb67cf58b 100644 (file)
@@ -33,6 +33,7 @@ import {
   FILTER_DOES_NOT_HAVE_TAG,
   FILTER_TITLE,
   FILTER_TITLE_CONTENT,
+  FILTER_ASN_ISNULL,
 } from 'src/app/data/filter-rule-type'
 import { FilterableDropdownSelectionModel } from '../../common/filterable-dropdown/filterable-dropdown.component'
 import { ToggleableItemState } from '../../common/filterable-dropdown/toggleable-dropdown-button/toggleable-dropdown-button.component'
@@ -135,6 +136,7 @@ export class FilterEditorComponent implements OnInit, OnDestroy {
   }
 
   textFilterTarget = TEXT_FILTER_TARGET_TITLE_CONTENT
+  textFilterTargetIsNull: boolean = false
 
   get textFilterTargetName() {
     return this.textFilterTargets.find((t) => t.id == this.textFilterTarget)
@@ -176,6 +178,7 @@ export class FilterEditorComponent implements OnInit, OnDestroy {
     this.dateAddedAfter = null
     this.dateCreatedBefore = null
     this.dateCreatedAfter = null
+    this.textFilterTargetIsNull = false
 
     value.forEach((rule) => {
       switch (rule.rule_type) {
@@ -254,6 +257,10 @@ export class FilterEditorComponent implements OnInit, OnDestroy {
             false
           )
           break
+        case FILTER_ASN_ISNULL:
+          this.textFilterTarget = TEXT_FILTER_TARGET_ASN
+          this.textFilterTargetIsNull = rule.value == 'true'
+          break
       }
     })
     this.checkIfRulesHaveChanged()
@@ -273,8 +280,15 @@ export class FilterEditorComponent implements OnInit, OnDestroy {
     if (this._textFilter && this.textFilterTarget == TEXT_FILTER_TARGET_TITLE) {
       filterRules.push({ rule_type: FILTER_TITLE, value: this._textFilter })
     }
-    if (this._textFilter && this.textFilterTarget == TEXT_FILTER_TARGET_ASN) {
-      filterRules.push({ rule_type: FILTER_ASN, value: this._textFilter })
+    if (this.textFilterTarget == TEXT_FILTER_TARGET_ASN) {
+      if (this.textFilter?.length && !this.textFilterTargetIsNull) {
+        filterRules.push({ rule_type: FILTER_ASN, value: this._textFilter })
+      } else if (!this.textFilter?.length) {
+        filterRules.push({
+          rule_type: FILTER_ASN_ISNULL,
+          value: this.textFilterTargetIsNull.toString(),
+        })
+      }
     }
     if (
       this._textFilter &&
@@ -398,7 +412,7 @@ export class FilterEditorComponent implements OnInit, OnDestroy {
   }
 
   get textFilter() {
-    return this._textFilter
+    return this.textFilterTargetIsNull ? '' : this._textFilter
   }
 
   set textFilter(value) {