mirror of
https://github.com/paperless-ngx/paperless-ngx.git
synced 2025-04-02 13:45:10 -05:00
parent
883d5aa5b6
commit
965e874740
3
.gitignore
vendored
3
.gitignore
vendored
@ -84,5 +84,6 @@ scripts/nuke
|
|||||||
/data/index
|
/data/index
|
||||||
|
|
||||||
/paperless.conf
|
/paperless.conf
|
||||||
/consumption/
|
/consume
|
||||||
|
/export
|
||||||
/src-ui/.vscode
|
/src-ui/.vscode
|
||||||
|
@ -1,8 +1,9 @@
|
|||||||
<div *ngFor="let rule of filterRules" class="form-row form-group">
|
<div *ngFor="let rule of filterRules" class="form-row form-group">
|
||||||
<div class="col">
|
<div class="col-md-3 col-form-label">
|
||||||
<select class="form-control form-control-sm" [(ngModel)]="rule.type" (change)="rule.value = null">
|
<!-- <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>
|
<option *ngFor="let ruleType of getRuleTypes()" [ngValue]="ruleType">{{ruleType.name}}</option>
|
||||||
</select>
|
</select> -->
|
||||||
|
<span>{{rule.type.name}}</span>
|
||||||
</div>
|
</div>
|
||||||
<div class="col">
|
<div class="col">
|
||||||
<input *ngIf="rule.type.datatype == 'string'" type="text" class="form-control form-control-sm" [(ngModel)]="rule.value">
|
<input *ngIf="rule.type.datatype == 'string'" type="text" class="form-control form-control-sm" [(ngModel)]="rule.value">
|
||||||
|
@ -32,6 +32,7 @@ export class FilterEditorComponent implements OnInit {
|
|||||||
|
|
||||||
newRuleClicked() {
|
newRuleClicked() {
|
||||||
this.filterRules.push({type: this.selectedRuleType, value: null})
|
this.filterRules.push({type: this.selectedRuleType, value: null})
|
||||||
|
this.selectedRuleType = this.getRuleTypes().length > 0 ? this.getRuleTypes()[0] : null
|
||||||
}
|
}
|
||||||
|
|
||||||
removeRuleClicked(rule) {
|
removeRuleClicked(rule) {
|
||||||
@ -57,7 +58,7 @@ export class FilterEditorComponent implements OnInit {
|
|||||||
}
|
}
|
||||||
|
|
||||||
getRuleTypes() {
|
getRuleTypes() {
|
||||||
return FILTER_RULE_TYPES
|
return FILTER_RULE_TYPES.filter(rt => rt.multi || !this.filterRules.find(r => r.type == rt))
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1,31 +1,33 @@
|
|||||||
export const FILTER_RULE_TYPES: FilterRuleType[] = [
|
export const FILTER_RULE_TYPES: FilterRuleType[] = [
|
||||||
{name: "Title contains", filtervar: "title__icontains", datatype: "string"},
|
{name: "Title contains", filtervar: "title__icontains", datatype: "string", multi: false},
|
||||||
{name: "Content contains", filtervar: "content__icontains", datatype: "string"},
|
{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: "Correspondent is", filtervar: "correspondent__id", datatype: "correspondent", multi: false},
|
||||||
{name: "Document type is", filtervar: "document_type__id", datatype: "document_type"},
|
{name: "Document type is", filtervar: "document_type__id", datatype: "document_type", multi: false},
|
||||||
{name: "Has tag", filtervar: "tags__id", datatype: "tag"},
|
|
||||||
|
|
||||||
{name: "Has any tag", filtervar: "is_tagged", datatype: "boolean"},
|
|
||||||
|
|
||||||
{name: "Date created before", filtervar: "created__date__lt", datatype: "date"},
|
{name: "Is in Inbox", filtervar: "is_in_inbox", datatype: "boolean", multi: false},
|
||||||
{name: "Date created after", filtervar: "created__date__gt", datatype: "date"},
|
{name: "Has tag", filtervar: "tags__id__all", datatype: "tag", multi: true},
|
||||||
|
{name: "Has any tag", filtervar: "is_tagged", datatype: "boolean", multi: false},
|
||||||
|
|
||||||
{name: "Year created is", filtervar: "created__year", datatype: "number"},
|
{name: "Created before", filtervar: "created__date__lt", datatype: "date", multi: false},
|
||||||
{name: "Month created is", filtervar: "created__month", datatype: "number"},
|
{name: "Created after", filtervar: "created__date__gt", datatype: "date", multi: false},
|
||||||
{name: "Day created is", filtervar: "created__day", datatype: "number"},
|
|
||||||
|
|
||||||
{name: "Date added before", filtervar: "added__date__lt", datatype: "date"},
|
{name: "Year created is", filtervar: "created__year", datatype: "number", multi: false},
|
||||||
{name: "Date added after", filtervar: "added__date__gt", datatype: "date"},
|
{name: "Month created is", filtervar: "created__month", datatype: "number", multi: false},
|
||||||
|
{name: "Day created is", filtervar: "created__day", datatype: "number", multi: false},
|
||||||
|
|
||||||
|
{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: "Modified before", filtervar: "modified__date__lt", datatype: "date", multi: false},
|
||||||
{name: "Date modified after", filtervar: "modified__date__gt", datatype: "date"},
|
{name: "Modified after", filtervar: "modified__date__gt", datatype: "date", multi: false},
|
||||||
]
|
]
|
||||||
|
|
||||||
export interface FilterRuleType {
|
export interface FilterRuleType {
|
||||||
name: string
|
name: string
|
||||||
filtervar: string
|
filtervar: string
|
||||||
datatype: string //number, string, boolean, date
|
datatype: string //number, string, boolean, date
|
||||||
|
multi: boolean
|
||||||
}
|
}
|
@ -33,7 +33,7 @@ export abstract class AbstractPaperlessService<T extends ObjectWithId> {
|
|||||||
httpParams = httpParams.set('ordering', ordering)
|
httpParams = httpParams.set('ordering', ordering)
|
||||||
}
|
}
|
||||||
for (let extraParamKey in extraParams) {
|
for (let extraParamKey in extraParams) {
|
||||||
if (extraParams[extraParamKey]) {
|
if (extraParams[extraParamKey] != null) {
|
||||||
httpParams = httpParams.set(extraParamKey, extraParams[extraParamKey])
|
httpParams = httpParams.set(extraParamKey, extraParams[extraParamKey])
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -34,7 +34,11 @@ export class DocumentService extends AbstractPaperlessService<PaperlessDocument>
|
|||||||
if (filterRules) {
|
if (filterRules) {
|
||||||
let params = {}
|
let params = {}
|
||||||
for (let rule of filterRules) {
|
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
|
return params
|
||||||
} else {
|
} else {
|
||||||
|
@ -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
|
from .models import Correspondent, Document, Tag, DocumentType, Log
|
||||||
|
|
||||||
@ -35,6 +35,34 @@ class DocumentTypeFilterSet(FilterSet):
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
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):
|
class DocumentFilterSet(FilterSet):
|
||||||
|
|
||||||
is_tagged = BooleanFilter(
|
is_tagged = BooleanFilter(
|
||||||
@ -44,6 +72,10 @@ class DocumentFilterSet(FilterSet):
|
|||||||
exclude=True
|
exclude=True
|
||||||
)
|
)
|
||||||
|
|
||||||
|
tags__id__all = TagsFilter()
|
||||||
|
|
||||||
|
is_in_inbox = InboxFilter()
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
model = Document
|
model = Document
|
||||||
fields = {
|
fields = {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user