Saved views, some refactoring

This commit is contained in:
Jonas Winkler
2020-10-30 22:46:43 +01:00
parent 6afdf666fd
commit d1e10754a5
43 changed files with 461 additions and 232 deletions

View File

@@ -0,0 +1,31 @@
export const FILTER_RULE_TYPES: FilterRuleType[] = [
{name: "Title contains", filtervar: "title__icontains", datatype: "string"},
{name: "Content contains", filtervar: "content__icontains", datatype: "string"},
{name: "ASN is", filtervar: "archive_serial_number", datatype: "number"},
{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: "Date created before", filtervar: "created__date__lt", datatype: "date"},
{name: "Date created after", filtervar: "created__date__gt", datatype: "date"},
{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: "Date added before", filtervar: "added__date__lt", datatype: "date"},
{name: "Date added after", filtervar: "added__date__gt", datatype: "date"},
{name: "Date modified before", filtervar: "modified__date__lt", datatype: "date"},
{name: "Date modified after", filtervar: "modified__date__gt", datatype: "date"},
]
export interface FilterRuleType {
name: string
filtervar: string
datatype: string //number, string, boolean, date
}

View File

@@ -0,0 +1,23 @@
import { FilterRuleType } from './filter-rule-type';
export function filterRulesToQueryParams(filterRules: FilterRule[]) {
let params = {}
for (let rule of filterRules) {
params[rule.type.filtervar] = rule.value
}
return params
}
export function cloneFilterRules(filterRules: FilterRule[]): FilterRule[] {
let newRules: FilterRule[] = []
for (let rule of filterRules) {
newRules.push({type: rule.type, value: rule.value})
}
return newRules
}
export interface FilterRule {
type: FilterRuleType
value: any
}

View File

@@ -1,7 +0,0 @@
import { MatchingModel } from './matching-model';
describe('MatchingModel', () => {
it('should create an instance', () => {
expect(new MatchingModel()).toBeTruthy();
});
});

View File

@@ -1,22 +1,23 @@
import { ObjectWithId } from './object-with-id';
export class MatchingModel extends ObjectWithId {
static MATCH_ANY = 1
static MATCH_ALL = 2
static MATCH_LITERAL = 3
static MATCH_REGEX = 4
static MATCH_FUZZY = 5
static MATCH_AUTO = 6
export const MATCH_ANY = 1
export const MATCH_ALL = 2
export const MATCH_LITERAL = 3
export const MATCH_REGEX = 4
export const MATCH_FUZZY = 5
export const MATCH_AUTO = 6
static MATCHING_ALGORITHMS = [
{id: MatchingModel.MATCH_ANY, name: "Any"},
{id: MatchingModel.MATCH_ALL, name: "All"},
{id: MatchingModel.MATCH_LITERAL, name: "Literal"},
{id: MatchingModel.MATCH_REGEX, name: "Regular Expression"},
{id: MatchingModel.MATCH_FUZZY, name: "Fuzzy Match"},
{id: MatchingModel.MATCH_AUTO, name: "Auto"},
]
export const MATCHING_ALGORITHMS = [
{id: MATCH_ANY, name: "Any"},
{id: MATCH_ALL, name: "All"},
{id: MATCH_LITERAL, name: "Literal"},
{id: MATCH_REGEX, name: "Regular Expression"},
{id: MATCH_FUZZY, name: "Fuzzy Match"},
{id: MATCH_AUTO, name: "Auto"},
]
export interface MatchingModel extends ObjectWithId {
name?: string

View File

@@ -1,7 +0,0 @@
import { ObjectWithId } from './object-with-id';
describe('ObjectWithId', () => {
it('should create an instance', () => {
expect(new ObjectWithId()).toBeTruthy();
});
});

View File

@@ -1,4 +1,4 @@
export class ObjectWithId {
export interface ObjectWithId {
id?: number

View File

@@ -1,7 +0,0 @@
import { PaperlessCorrespondent } from './paperless-correspondent';
describe('PaperlessCorrespondent', () => {
it('should create an instance', () => {
expect(new PaperlessCorrespondent()).toBeTruthy();
});
});

View File

@@ -1,6 +1,6 @@
import { MatchingModel } from './matching-model';
export class PaperlessCorrespondent extends MatchingModel {
export interface PaperlessCorrespondent extends MatchingModel {
document_count?: number

View File

@@ -1,7 +0,0 @@
import { PaperlessDocumentType } from './paperless-document-type';
describe('PaperlessDocumentType', () => {
it('should create an instance', () => {
expect(new PaperlessDocumentType()).toBeTruthy();
});
});

View File

@@ -1,6 +1,6 @@
import { MatchingModel } from './matching-model';
export class PaperlessDocumentType extends MatchingModel {
export interface PaperlessDocumentType extends MatchingModel {
document_count?: number

View File

@@ -1,7 +0,0 @@
import { PaperlessDocument } from './paperless-document';
describe('PaperlessDocument', () => {
it('should create an instance', () => {
expect(new PaperlessDocument()).toBeTruthy();
});
});

View File

@@ -3,7 +3,7 @@ import { ObjectWithId } from './object-with-id'
import { PaperlessTag } from './paperless-tag'
import { PaperlessDocumentType } from './paperless-document-type'
export class PaperlessDocument extends ObjectWithId {
export interface PaperlessDocument extends ObjectWithId {
correspondent?: PaperlessCorrespondent

View File

@@ -1,7 +0,0 @@
import { PaperlessLog } from './paperless-log';
describe('PaperlessLog', () => {
it('should create an instance', () => {
expect(new PaperlessLog()).toBeTruthy();
});
});

View File

@@ -1,2 +1,2 @@
export class PaperlessLog {
export interface PaperlessLog {
}

View File

@@ -1,7 +0,0 @@
import { PaperlessTag } from './paperless-tag';
describe('PaperlessTag', () => {
it('should create an instance', () => {
expect(new PaperlessTag()).toBeTruthy();
});
});

View File

@@ -1,23 +1,24 @@
import { MatchingModel } from './matching-model';
import { ObjectWithId } from './object-with-id';
export class PaperlessTag extends MatchingModel {
static COLOURS = [
{id: 1, value: "#a6cee3", name: "Light Blue", textColor: "#000000"},
{id: 2, value: "#1f78b4", name: "Blue", textColor: "#ffffff"},
{id: 3, value: "#b2df8a", name: "Light Green", textColor: "#000000"},
{id: 4, value: "#33a02c", name: "Green", textColor: "#000000"},
{id: 5, value: "#fb9a99", name: "Light Red", textColor: "#000000"},
{id: 6, value: "#e31a1c", name: "Red ", textColor: "#ffffff"},
{id: 7, value: "#fdbf6f", name: "Light Orange", textColor: "#000000"},
{id: 8, value: "#ff7f00", name: "Orange", textColor: "#000000"},
{id: 9, value: "#cab2d6", name: "Light Violet", textColor: "#000000"},
{id: 10, value: "#6a3d9a", name: "Violet", textColor: "#ffffff"},
{id: 11, value: "#b15928", name: "Brown", textColor: "#000000"},
{id: 12, value: "#000000", name: "Black", textColor: "#ffffff"},
{id: 13, value: "#cccccc", name: "Light Grey", textColor: "#000000"}
]
export const TAG_COLOURS = [
{id: 1, value: "#a6cee3", name: "Light Blue", textColor: "#000000"},
{id: 2, value: "#1f78b4", name: "Blue", textColor: "#ffffff"},
{id: 3, value: "#b2df8a", name: "Light Green", textColor: "#000000"},
{id: 4, value: "#33a02c", name: "Green", textColor: "#000000"},
{id: 5, value: "#fb9a99", name: "Light Red", textColor: "#000000"},
{id: 6, value: "#e31a1c", name: "Red ", textColor: "#ffffff"},
{id: 7, value: "#fdbf6f", name: "Light Orange", textColor: "#000000"},
{id: 8, value: "#ff7f00", name: "Orange", textColor: "#000000"},
{id: 9, value: "#cab2d6", name: "Light Violet", textColor: "#000000"},
{id: 10, value: "#6a3d9a", name: "Violet", textColor: "#ffffff"},
{id: 11, value: "#b15928", name: "Brown", textColor: "#000000"},
{id: 12, value: "#000000", name: "Black", textColor: "#ffffff"},
{id: 13, value: "#cccccc", name: "Light Grey", textColor: "#000000"}
]
export interface PaperlessTag extends MatchingModel {
colour?: number

View File

@@ -1,7 +0,0 @@
import { Results } from './results';
describe('Results', () => {
it('should create an instance', () => {
expect(new Results()).toBeTruthy();
});
});

View File

@@ -1,4 +1,4 @@
export class Results<T> {
export interface Results<T> {
count: number

View File

@@ -0,0 +1,19 @@
import { FilterRule } from './filter-rule';
export interface SavedViewConfig {
id?: string
filterRules: FilterRule[]
sortField: string
sortDirection: string
title: string
showInSideBar: boolean
showInDashboard: boolean
}