diff --git a/.gitignore b/.gitignore index 3d79e7145..871a7bd08 100644 --- a/.gitignore +++ b/.gitignore @@ -84,5 +84,6 @@ scripts/nuke /data/index /paperless.conf -/consumption/ +/consume +/export /src-ui/.vscode diff --git a/src-ui/src/app/components/filter-editor/filter-editor.component.html b/src-ui/src/app/components/filter-editor/filter-editor.component.html index 27b941e49..1cca0fd7f 100644 --- a/src-ui/src/app/components/filter-editor/filter-editor.component.html +++ b/src-ui/src/app/components/filter-editor/filter-editor.component.html @@ -1,8 +1,9 @@
-
- diff --git a/src-ui/src/app/components/filter-editor/filter-editor.component.ts b/src-ui/src/app/components/filter-editor/filter-editor.component.ts index 61102fcd0..8c47ceafb 100644 --- a/src-ui/src/app/components/filter-editor/filter-editor.component.ts +++ b/src-ui/src/app/components/filter-editor/filter-editor.component.ts @@ -32,6 +32,7 @@ export class FilterEditorComponent implements OnInit { newRuleClicked() { this.filterRules.push({type: this.selectedRuleType, value: null}) + this.selectedRuleType = this.getRuleTypes().length > 0 ? this.getRuleTypes()[0] : null } removeRuleClicked(rule) { @@ -57,7 +58,7 @@ export class FilterEditorComponent implements OnInit { } getRuleTypes() { - return FILTER_RULE_TYPES + return FILTER_RULE_TYPES.filter(rt => rt.multi || !this.filterRules.find(r => r.type == rt)) } } diff --git a/src-ui/src/app/data/filter-rule-type.ts b/src-ui/src/app/data/filter-rule-type.ts index eb9465aaa..e5de30271 100644 --- a/src-ui/src/app/data/filter-rule-type.ts +++ b/src-ui/src/app/data/filter-rule-type.ts @@ -1,31 +1,33 @@ export const FILTER_RULE_TYPES: FilterRuleType[] = [ - {name: "Title contains", filtervar: "title__icontains", datatype: "string"}, - {name: "Content contains", filtervar: "content__icontains", datatype: "string"}, + {name: "Title contains", filtervar: "title__icontains", datatype: "string", multi: false}, + {name: "Content contains", filtervar: "content__icontains", datatype: "string", multi: false}, - {name: "ASN is", filtervar: "archive_serial_number", datatype: "number"}, + {name: "ASN is", filtervar: "archive_serial_number", datatype: "number", multi: false}, - {name: "Correspondent is", filtervar: "correspondent__id", datatype: "correspondent"}, - {name: "Document type is", filtervar: "document_type__id", datatype: "document_type"}, - {name: "Has tag", filtervar: "tags__id", datatype: "tag"}, - - {name: "Has any tag", filtervar: "is_tagged", datatype: "boolean"}, + {name: "Correspondent is", filtervar: "correspondent__id", datatype: "correspondent", multi: false}, + {name: "Document type is", filtervar: "document_type__id", datatype: "document_type", multi: false}, + + {name: "Is in Inbox", filtervar: "is_in_inbox", datatype: "boolean", multi: false}, + {name: "Has tag", filtervar: "tags__id__all", datatype: "tag", multi: true}, + {name: "Has any tag", filtervar: "is_tagged", datatype: "boolean", multi: false}, - {name: "Date created before", filtervar: "created__date__lt", datatype: "date"}, - {name: "Date created after", filtervar: "created__date__gt", datatype: "date"}, + {name: "Created before", filtervar: "created__date__lt", datatype: "date", multi: false}, + {name: "Created after", filtervar: "created__date__gt", datatype: "date", multi: false}, - {name: "Year created is", filtervar: "created__year", datatype: "number"}, - {name: "Month created is", filtervar: "created__month", datatype: "number"}, - {name: "Day created is", filtervar: "created__day", datatype: "number"}, + {name: "Year created is", filtervar: "created__year", datatype: "number", multi: false}, + {name: "Month created is", filtervar: "created__month", datatype: "number", multi: false}, + {name: "Day created is", filtervar: "created__day", datatype: "number", multi: false}, - {name: "Date added before", filtervar: "added__date__lt", datatype: "date"}, - {name: "Date added after", filtervar: "added__date__gt", datatype: "date"}, + {name: "Added before", filtervar: "added__date__lt", datatype: "date", multi: false}, + {name: "Added after", filtervar: "added__date__gt", datatype: "date", multi: false}, - {name: "Date modified before", filtervar: "modified__date__lt", datatype: "date"}, - {name: "Date modified after", filtervar: "modified__date__gt", datatype: "date"}, + {name: "Modified before", filtervar: "modified__date__lt", datatype: "date", multi: false}, + {name: "Modified after", filtervar: "modified__date__gt", datatype: "date", multi: false}, ] export interface FilterRuleType { name: string filtervar: string datatype: string //number, string, boolean, date + multi: boolean } \ No newline at end of file diff --git a/src-ui/src/app/services/rest/abstract-paperless-service.ts b/src-ui/src/app/services/rest/abstract-paperless-service.ts index 9ee07d31a..c8459f080 100644 --- a/src-ui/src/app/services/rest/abstract-paperless-service.ts +++ b/src-ui/src/app/services/rest/abstract-paperless-service.ts @@ -33,7 +33,7 @@ export abstract class AbstractPaperlessService { httpParams = httpParams.set('ordering', ordering) } for (let extraParamKey in extraParams) { - if (extraParams[extraParamKey]) { + if (extraParams[extraParamKey] != null) { httpParams = httpParams.set(extraParamKey, extraParams[extraParamKey]) } } diff --git a/src-ui/src/app/services/rest/document.service.ts b/src-ui/src/app/services/rest/document.service.ts index ff030e21d..7328b380e 100644 --- a/src-ui/src/app/services/rest/document.service.ts +++ b/src-ui/src/app/services/rest/document.service.ts @@ -34,7 +34,11 @@ export class DocumentService extends AbstractPaperlessService if (filterRules) { let params = {} for (let rule of filterRules) { - params[rule.type.filtervar] = rule.value + if (rule.type.multi) { + params[rule.type.filtervar] = params[rule.type.filtervar] ? params[rule.type.filtervar] + "," + rule.value : rule.value + } else { + params[rule.type.filtervar] = rule.value + } } return params } else { diff --git a/src/documents/filters.py b/src/documents/filters.py index d8fe09301..770e0e5af 100755 --- a/src/documents/filters.py +++ b/src/documents/filters.py @@ -1,4 +1,4 @@ -from django_filters.rest_framework import BooleanFilter, FilterSet +from django_filters.rest_framework import BooleanFilter, FilterSet, Filter from .models import Correspondent, Document, Tag, DocumentType, Log @@ -35,6 +35,34 @@ class Meta: } +class TagsFilter(Filter): + + def filter(self, qs, value): + if not value: + return qs + + try: + tag_ids = [int(x) for x in value.split(',')] + except ValueError: + return qs + + for tag_id in tag_ids: + qs = qs.filter(tags__id=tag_id) + + return qs + + +class InboxFilter(Filter): + + def filter(self, qs, value): + if value == 'true': + return qs.filter(tags__is_inbox_tag=True) + elif value == 'false': + return qs.exclude(tags__is_inbox_tag=True) + else: + return qs + + class DocumentFilterSet(FilterSet): is_tagged = BooleanFilter( @@ -44,6 +72,10 @@ class DocumentFilterSet(FilterSet): exclude=True ) + tags__id__all = TagsFilter() + + is_in_inbox = InboxFilter() + class Meta: model = Document fields = {