Skip to content
This repository has been archived by the owner on Feb 16, 2023. It is now read-only.

Commit

Permalink
fixes #17
Browse files Browse the repository at this point in the history
search for multiple tags
  • Loading branch information
Jonas Winkler committed Nov 3, 2020
1 parent 883d5aa commit 965e874
Show file tree
Hide file tree
Showing 7 changed files with 66 additions and 25 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -84,5 +84,6 @@ scripts/nuke
/data/index

/paperless.conf
/consumption/
/consume
/export
/src-ui/.vscode
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
<div *ngFor="let rule of filterRules" class="form-row form-group">
<div class="col">
<select class="form-control form-control-sm" [(ngModel)]="rule.type" (change)="rule.value = null">
<div class="col-md-3 col-form-label">
<!-- <select class="form-control form-control-sm" [(ngModel)]="rule.type" (change)="rule.value = null">
<option *ngFor="let ruleType of getRuleTypes()" [ngValue]="ruleType">{{ruleType.name}}</option>
</select>
</select> -->
<span>{{rule.type.name}}</span>
</div>
<div class="col">
<input *ngIf="rule.type.datatype == 'string'" type="text" class="form-control form-control-sm" [(ngModel)]="rule.value">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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))
}

}
36 changes: 19 additions & 17 deletions src-ui/src/app/data/filter-rule-type.ts
Original file line number Diff line number Diff line change
@@ -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
}
2 changes: 1 addition & 1 deletion src-ui/src/app/services/rest/abstract-paperless-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export abstract class AbstractPaperlessService<T extends ObjectWithId> {
httpParams = httpParams.set('ordering', ordering)
}
for (let extraParamKey in extraParams) {
if (extraParams[extraParamKey]) {
if (extraParams[extraParamKey] != null) {
httpParams = httpParams.set(extraParamKey, extraParams[extraParamKey])
}
}
Expand Down
6 changes: 5 additions & 1 deletion src-ui/src/app/services/rest/document.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,11 @@ export class DocumentService extends AbstractPaperlessService<PaperlessDocument>
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 {
Expand Down
34 changes: 33 additions & 1 deletion src/documents/filters.py
Original file line number Diff line number Diff line change
@@ -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

Expand Down Expand Up @@ -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(
Expand All @@ -44,6 +72,10 @@ class DocumentFilterSet(FilterSet):
exclude=True
)

tags__id__all = TagsFilter()

is_in_inbox = InboxFilter()

class Meta:
model = Document
fields = {
Expand Down

0 comments on commit 965e874

Please sign in to comment.