Skip to content

A community-supported supercharged document management system: scan, index and archive all your documents

Merge branch 'dev' into feature-bulk-editor

Michael Shamoonfbb2da42dc92
diff --git a/README.md b/README.md
index 41f85af19..e8ae8feb2 100644
--- a/README.md
+++ b/README.md
@@ -7,7 +7,7 @@
[Paperless](https://github.com/the-paperless-project/paperless) is an application by Daniel Quinn and others that indexes your scanned documents and allows you to easily search for documents and store metadata alongside your documents.
-Paperless-ng is a fork of the original project, adding a new interface and many other changes under the hood. For a detailed list of changes, see below.
+Paperless-ng is a fork of the original project, adding a new interface and many other changes under the hood. For a detailed list of changes, have a look at the changelog in the documentation.
This project is still in development and some things may not work as expected.
@@ -15,11 +15,13 @@ This project is still in development and some things may not work as expected.
Paperless does not control your scanner, it only helps you deal with what your scanner produces.
-1. Buy a document scanner that can write to a place on your network. If you need some inspiration, have a look at the [scanner recommendations](https://paperless-ng.readthedocs.io/en/latest/scanners.html) page.
-2. Set it up to "scan to FTP" or something similar. It should be able to push scanned images to a server without you having to do anything. Of course if your scanner doesn't know how to automatically upload the file somewhere, you can always do that manually. Paperless doesn't care how the documents get into its local consumption directory.
-3. Have the target server run the Paperless consumption script to OCR the file and index it into a local database.
-4. Use the web frontend to sift through the database and find what you want.
-5. Download the PDF you need/want via the web interface and do whatever you like with it. You can even print it and send it as if it's the original. In most cases, no one will care or notice.
+1. Buy a document scanner that can write to a place on your network. If you need some inspiration, have a look at the [scanner recommendations](https://paperless-ng.readthedocs.io/en/latest/scanners.html) page. Set it up to "scan to FTP" or something similar. It should be able to push scanned images to a server without you having to do anything. Of course if your scanner doesn't know how to automatically upload the file somewhere, you can always do that manually. Paperless doesn't care how the documents get into its local consumption directory.
+
+ - Alternatively, you can use any of the mobile scanning apps out there. We have an app that allows you to share documents with paperless, if you're on Android. See the section on affiliated projects.
+
+2. Wait for paperless to process your files. OCR is expensive, and depending on the power of your machine, this might take a bit of time.
+3. Use the web frontend to sift through the database and find what you want.
+4. Download the PDF you need/want via the web interface and do whatever you like with it. You can even print it and send it as if it's the original. In most cases, no one will care or notice.
Here's what you get:
@@ -39,7 +41,6 @@ Here's what you get:
* When adding documents from mails, paperless can move these mails to a new folder, mark them as read, flag them or delete them.
* Machine learning powered document matching.
* Paperless learns from your documents and will be able to automatically assign tags, correspondents and types to documents once you've stored a few documents in paperless.
-* We have a mobile app that offers a 'Share with paperless' option over at https://github.com/qcasey/paperless_share. You can use that in combination with any of the mobile scanning apps out there. It's still a little rough around the edges, but it works!
* A task processor that processes documents in parallel and also tells you when something goes wrong. On modern multi core systems, consumption is blazing fast.
* Code cleanup in many, MANY areas. Some of the code from OG paperless was just overly complicated.
* More tests, more stability.
@@ -78,7 +79,7 @@ The recommended way to deploy paperless is docker-compose. Don't clone the repos
Read the [documentation](https://paperless-ng.readthedocs.io/en/latest/setup.html#installation) on how to get started.
-Alternatively, you can install the dependencies and setup apache and a database server yourself. The documenation has information about the individual components of paperless that you need to take care of.
+Alternatively, you can install the dependencies and setup apache and a database server yourself. The documenation has a step by step guide on how to do it.
# Migrating to paperless-ng
@@ -102,13 +103,15 @@ If you want to implement something big: Please start a discussion about that in
Paperless has been around a while now, and people are starting to build stuff on top of it. If you're one of those people, we can add your project to this list:
-* [Paperless App](https://github.com/bauerj/paperless_app): An Android/iOS app for Paperless. We're working on making this compatible.
+* [Paperless App](https://github.com/bauerj/paperless_app): An Android/iOS app for Paperless. Updated to work with paperless-ng.
+* [Paperless Share](https://github.com/qcasey/paperless_share). Share any files from your Android application with paperless. Very simple, but works with all of the mobile scanning apps out there that allow you to share scanned documents.
+
+These projects also exist, but their status and compatibility with paperless-ng is unknown.
+
* [Paperless Desktop](https://github.com/thomasbrueggemann/paperless-desktop): A desktop UI for your Paperless installation. Runs on Mac, Linux, and Windows.
* [ansible-role-paperless](https://github.com/ovv/ansible-role-paperless): An easy way to get Paperless running via Ansible.
* [paperless-cli](https://github.com/stgarf/paperless-cli): A golang command line binary to interact with a Paperless instance.
-Compatibility with Paperless-ng is unknown.
-
# Important Note
Document scanners are typically used to scan sensitive documents. Things like your social insurance number, tax records, invoices, etc. Everything is stored in the clear without encryption by default (it needs to be searchable, so if someone has ideas on how to do that on encrypted data, I'm all ears). This means that Paperless should never be run on an untrusted host. Instead, I recommend that if you do want to use it, run it locally on a server in your own home.
diff --git a/docker/hub/docker-compose.postgres.yml b/docker/hub/docker-compose.postgres.yml
index 24f0e118f..d33e4c38d 100644
--- a/docker/hub/docker-compose.postgres.yml
+++ b/docker/hub/docker-compose.postgres.yml
@@ -15,7 +15,7 @@ services:
POSTGRES_PASSWORD: paperless
webserver:
- image: jonaswinkler/paperless-ng:0.9.6
+ image: jonaswinkler/paperless-ng:0.9.8
restart: always
depends_on:
- db
diff --git a/docker/hub/docker-compose.sqlite.yml b/docker/hub/docker-compose.sqlite.yml
index 6ae619fd6..c130dfef6 100644
--- a/docker/hub/docker-compose.sqlite.yml
+++ b/docker/hub/docker-compose.sqlite.yml
@@ -5,7 +5,7 @@ services:
restart: always
webserver:
- image: jonaswinkler/paperless-ng:0.9.6
+ image: jonaswinkler/paperless-ng:0.9.8
restart: always
depends_on:
- broker
diff --git a/docs/advanced_usage.rst b/docs/advanced_usage.rst
index b5ae254b3..48a86384c 100644
--- a/docs/advanced_usage.rst
+++ b/docs/advanced_usage.rst
@@ -263,10 +263,10 @@ using the identifier which it has assigned to each document. You will end up get
files like ``0000123.pdf`` in your media directory. This isn't necessarily a bad
thing, because you normally don't have to access these files manually. However, if
you wish to name your files differently, you can do that by adjusting the
-``PAPERLESS_FILENAME_FORMAT`` settings variable.
+``PAPERLESS_FILENAME_FORMAT`` configuration option.
-This variable allows you to configure the filename (folders are allowed!) using
-placeholders. For example, setting
+This variable allows you to configure the filename (folders are allowed) using
+placeholders. For example, configuring this to
.. code:: bash
@@ -277,17 +277,16 @@ will create a directory structure as follows:
.. code::
2019/
- my_bank/
- statement-january-0000001.pdf
- statement-february-0000002.pdf
+ My bank/
+ Statement January.pdf
+ Statement February.pdf
2020/
- my_bank/
- statement-january-0000003.pdf
- shoe_store/
- my_new_shoes-0000004.pdf
-
-Paperless appends the unique identifier of each document to the filename. This
-avoids filename clashes.
+ My bank/
+ Statement January.pdf
+ Letter.pdf
+ Letter_01.pdf
+ Shoe store/
+ My new shoes.pdf
.. danger::
@@ -299,6 +298,7 @@ Paperless provides the following placeholders withing filenames:
* ``{correspondent}``: The name of the correspondent, or "none".
* ``{document_type}``: The name of the document type, or "none".
+* ``{tag_list}``: A comma separated list of all tags assigned to the document.
* ``{title}``: The title of the document.
* ``{created}``: The full date and time the document was created.
* ``{created_year}``: Year created only.
@@ -309,8 +309,14 @@ Paperless provides the following placeholders withing filenames:
* ``{added_month}``: Month added only (number 1-12).
* ``{added_day}``: Day added only (number 1-31).
-Paperless will convert all values for the placeholders into values which are safe
-for use in filenames.
+
+Paperless will try to conserve the information from your database as much as possible.
+However, some characters that you can use in document titles and correspondent names (such
+as ``: \ /`` and a couple more) are not allowed in filenames and will be replaced with dashes.
+
+If paperless detects that two documents share the same filename, paperless will automatically
+append ``_01``, ``_02``, etc to the filename. This happens if all the placeholders in a filename
+evaluate to the same value.
.. hint::
diff --git a/docs/changelog.rst b/docs/changelog.rst
index a50fc31d5..a993eb530 100644
--- a/docs/changelog.rst
+++ b/docs/changelog.rst
@@ -5,6 +5,58 @@
Changelog
*********
+
+paperless-ng 0.9.8
+##################
+
+This release addresses two severe issues with the previous release.
+
+* The delete buttons for document types, correspondents and tags were not working.
+* The document section in the admin was causing internal server errors (500).
+
+
+paperless-ng 0.9.7
+##################
+
+
+* Front end
+
+ * Thanks to the hard work of `Michael Shamoon`_, paperless now comes with a much more streamlined UI for
+ filtering documents.
+
+ * `Michael Shamoon`_ replaced the document preview with another component. This should fix compatibility with Safari browsers.
+
+ * Added buttons to the management pages to quickly show all documents with one specific tag, correspondent, or title.
+
+ * Paperless now stores your saved views on the server and associates them with your user account.
+ This means that you can access your views on multiple devices and have separate views for different users.
+ You will have to recreate your views.
+
+ * The GitHub and documentation links now open in new tabs/windows. Thanks to `rYR79435`_.
+
+ * Paperless now generates default saved view names when saving views with certain filter rules.
+
+ * Added a small version indicator to the front end.
+
+* Other additions and changes
+
+ * The new filename format field ``{tag_list}`` inserts a list of tags into the filename, separated by comma.
+ * The ``document_retagger`` no longer removes inbox tags or tags without matching rules.
+ * The new configuration option ``PAPERLESS_COOKIE_PREFIX`` allows you to run multiple instances of paperless on different ports.
+ This option enables you to be logged in into multiple instances by specifying different cookie names for each instance.
+
+* Fixes
+
+ * Sometimes paperless would assign dates in the future to newly consumed documents.
+ * The filename format fields ``{created_month}`` and ``{created_day}`` now use a leading zero for single digit values.
+ * The filename format field ``{tags}`` can no longer be used without arguments.
+ * Paperless was not able to consume many images (especially images from mobile scanners) due to missing DPI information.
+ Paperless now assumes A4 paper size for PDF generation if no DPI information is present.
+ * Documents with empty titles could not be opened from the table view due to the link being empty.
+ * Fixed an issue with filenames containing special characters such as ``:`` not being accepted for upload.
+ * Fixed issues with thumbnail generation for plain text files.
+
+
paperless-ng 0.9.6
##################
@@ -841,6 +893,8 @@ bulk of the work on this big change.
* Initial release
+.. _rYR79435: https://github.com/rYR79435
+.. _Michael Shamoon: https://github.com/shamoon
.. _jayme-github: http://github.com/jayme-github
.. _Brian Conn: https://github.com/TheConnMan
.. _Christopher Luu: https://github.com/nuudles
diff --git a/docs/usage_overview.rst b/docs/usage_overview.rst
index bb9ecd452..7a4fd7740 100644
--- a/docs/usage_overview.rst
+++ b/docs/usage_overview.rst
@@ -57,9 +57,6 @@ Adding documents to paperless
#############################
Once you've got Paperless setup, you need to start feeding documents into it.
-Currently, there are four options: the consumption directory, the dashboard, IMAP (email), and
-HTTP POST.
-
When adding documents to paperless, it will perform the following operations on
your documents:
@@ -112,6 +109,17 @@ Dashboard upload
The dashboard has a file drop field to upload documents to paperless. Simply drag a file
onto this field or select a file with the file dialog. Multiple files are supported.
+
+Mobile upload
+=============
+
+The mobile app over at `<https://github.com/qcasey/paperless_share>`_ allows Android users
+to share any documents with paperless. This can be combined with any of the mobile
+scanning apps out there, such as Office Lens.
+
+Furthermore, there is the `Paperless App <https://github.com/bauerj/paperless_app>`_ as well,
+which no only has document upload, but also document editing and browsing.
+
.. _usage-email:
IMAP (Email)
diff --git a/scripts/make-release.sh b/scripts/make-release.sh
index 0a7bc7a9b..f5c9028fa 100755
--- a/scripts/make-release.sh
+++ b/scripts/make-release.sh
@@ -5,6 +5,7 @@
# adjust src/paperless/version.py
# changelog in the documentation
# adjust versions in docker/hub/*
+# adjust version in src-ui/src/environments/prod
# If docker-compose was modified: all compose files are the same.
# Steps:
diff --git a/src-ui/package-lock.json b/src-ui/package-lock.json
index 5eca0b3c0..10215a32d 100644
--- a/src-ui/package-lock.json
+++ b/src-ui/package-lock.json
@@ -2056,6 +2056,14 @@
"tslib": "^2.0.0"
}
},
+ "@ng-select/ng-select": {
+ "version": "5.0.9",
+ "resolved": "https://registry.npmjs.org/@ng-select/ng-select/-/ng-select-5.0.9.tgz",
+ "integrity": "sha512-YZeSAiS8/Nx/eHZJPmOOYL8YmcvSq+dr1P8WIrsKmRA7mueorBpPc5xlUj+nLQbpLtsiQvdWDQspf/ykOvD/lA==",
+ "requires": {
+ "tslib": "^2.0.0"
+ }
+ },
"@ngtools/webpack": {
"version": "10.2.0",
"resolved": "https://registry.npmjs.org/@ngtools/webpack/-/webpack-10.2.0.tgz",
diff --git a/src-ui/package.json b/src-ui/package.json
index 6293f2672..14d828483 100644
--- a/src-ui/package.json
+++ b/src-ui/package.json
@@ -21,6 +21,7 @@
"@angular/platform-browser-dynamic": "~10.1.5",
"@angular/router": "~10.1.5",
"@ng-bootstrap/ng-bootstrap": "^8.0.0",
+ "@ng-select/ng-select": "^5.0.9",
"bootstrap": "^4.5.0",
"ng-bootstrap": "^1.6.3",
"ng2-pdf-viewer": "^6.3.2",
diff --git a/src-ui/src/app/app.module.ts b/src-ui/src/app/app.module.ts
index 627d4f6cf..6c4cabe92 100644
--- a/src-ui/src/app/app.module.ts
+++ b/src-ui/src/app/app.module.ts
@@ -56,6 +56,7 @@ import { FilterPipe } from './pipes/filter.pipe';
import { DocumentTitlePipe } from './pipes/document-title.pipe';
import { MetadataCollapseComponent } from './components/document-detail/metadata-collapse/metadata-collapse.component';
import { SelectDialogComponent } from './components/common/select-dialog/select-dialog.component';
+import { NgSelectModule } from '@ng-select/ng-select';
@NgModule({
declarations: [
@@ -114,7 +115,8 @@ import { SelectDialogComponent } from './components/common/select-dialog/select-
ReactiveFormsModule,
NgxFileDropModule,
InfiniteScrollModule,
- PdfViewerModule
+ PdfViewerModule,
+ NgSelectModule
],
providers: [
DatePipe,
@@ -123,7 +125,8 @@ import { SelectDialogComponent } from './components/common/select-dialog/select-
useClass: CsrfInterceptor,
multi: true
},
- FilterPipe
+ FilterPipe,
+ DocumentTitlePipe
],
bootstrap: [AppComponent]
})
diff --git a/src-ui/src/app/components/app-frame/app-frame.component.html b/src-ui/src/app/components/app-frame/app-frame.component.html
index 7876150af..2458005f4 100644
--- a/src-ui/src/app/components/app-frame/app-frame.component.html
+++ b/src-ui/src/app/components/app-frame/app-frame.component.html
@@ -17,6 +17,11 @@
<div class="container-fluid">
<div class="row">
<nav id="sidebarMenu" class="col-md-3 col-lg-2 d-md-block bg-light sidebar collapse" [ngbCollapse]="isMenuCollapsed">
+
+ <div style="position: absolute; bottom: 0; left: 0;" class="text-muted p-1">
+ {{versionString}}
+ </div>
+
<div class="sidebar-sticky pt-3">
<ul class="nav flex-column">
<li class="nav-item">
@@ -60,7 +65,7 @@
<svg class="sidebaricon" fill="currentColor">
<use xlink:href="assets/bootstrap-icons.svg#file-text"/>
</svg>
- {{d.title}}
+ {{d.title | documentTitle}}
</a>
</li>
<li class="nav-item w-100" *ngIf="openDocuments.length > 1">
diff --git a/src-ui/src/app/components/app-frame/app-frame.component.ts b/src-ui/src/app/components/app-frame/app-frame.component.ts
index ef859bf35..c4c00843d 100644
--- a/src-ui/src/app/components/app-frame/app-frame.component.ts
+++ b/src-ui/src/app/components/app-frame/app-frame.component.ts
@@ -7,6 +7,7 @@ import { PaperlessDocument } from 'src/app/data/paperless-document';
import { OpenDocumentsService } from 'src/app/services/open-documents.service';
import { SavedViewService } from 'src/app/services/rest/saved-view.service';
import { SearchService } from 'src/app/services/rest/search.service';
+import { environment } from 'src/environments/environment';
import { DocumentDetailComponent } from '../document-detail/document-detail.component';
@Component({
@@ -25,6 +26,8 @@ export class AppFrameComponent implements OnInit, OnDestroy {
) {
}
+ versionString = `${environment.appTitle} ${environment.version}`
+
isMenuCollapsed: boolean = true
closeMenu() {
diff --git a/src-ui/src/app/components/common/input/select/select.component.html b/src-ui/src/app/components/common/input/select/select.component.html
index 717aa7964..655adbe74 100644
--- a/src-ui/src/app/components/common/input/select/select.component.html
+++ b/src-ui/src/app/components/common/input/select/select.component.html
@@ -1,11 +1,15 @@
-<div class="form-group">
+<div class="form-group paperless-input-select">
<label [for]="inputId">{{title}}</label>
<div [class.input-group]="showPlusButton()">
- <select class="form-control" [id]="inputId" [(ngModel)]="value" (change)="onChange(value)" (blur)="onTouched()"
- [disabled]="disabled" [style.color]="textColor" [style.background]="backgroundColor">
- <option *ngIf="allowNull" [ngValue]="null" class="form-control">---</option>
- <option *ngFor="let i of items" [ngValue]="i.id" class="form-control">{{i.name}}</option>
- </select>
+ <ng-select name="correspondent" [(ngModel)]="value"
+ [disabled]="disabled"
+ [style.color]="textColor"
+ [style.background]="backgroundColor"
+ (change)="onChange(value)"
+ (blur)="onTouched()">
+ <ng-option *ngFor="let i of items" [value]="i.id">{{i.name}}</ng-option>
+ </ng-select>
+
<div *ngIf="showPlusButton()" class="input-group-append">
<button class="btn btn-outline-secondary" type="button" (click)="createNew.emit()">
<svg class="buttonicon" fill="currentColor">
@@ -15,4 +19,4 @@
</div>
</div>
<small *ngIf="hint" class="form-text text-muted">{{hint}}</small>
-</div>
\ No newline at end of file
+</div>
diff --git a/src-ui/src/app/components/common/input/select/select.component.scss b/src-ui/src/app/components/common/input/select/select.component.scss
index e69de29bb..8faec3bc0 100644
--- a/src-ui/src/app/components/common/input/select/select.component.scss
+++ b/src-ui/src/app/components/common/input/select/select.component.scss
@@ -0,0 +1 @@
+// styles for ng-select child are in styles.scss
diff --git a/src-ui/src/app/components/common/input/tags/tags.component.html b/src-ui/src/app/components/common/input/tags/tags.component.html
index 8029dd860..8a5dbc4f2 100644
--- a/src-ui/src/app/components/common/input/tags/tags.component.html
+++ b/src-ui/src/app/components/common/input/tags/tags.component.html
@@ -1,30 +1,41 @@
-<div class="form-group">
- <label for="exampleFormControlTextarea1">Tags</label>
+<div class="form-group paperless-input-select paperless-input-tags">
+ <label for="tags">Tags</label>
- <div class="input-group">
- <div class="form-control tags-form-control" id="tags">
- <app-tag class="mr-2" *ngFor="let id of displayValue" [tag]="getTag(id)" (click)="removeTag(id)"></app-tag>
- </div>
+ <div class="input-group flex-nowrap">
+ <ng-select name="tags" [items]="tags" bindLabel="name" bindValue="id" [(ngModel)]="displayValue"
+ [multiple]="true"
+ [closeOnSelect]="false"
+ [disabled]="disabled"
+ (change)="ngSelectChange()">
- <div class="input-group-append" ngbDropdown placement="top-right">
- <button class="btn btn-outline-secondary" type="button" ngbDropdownToggle></button>
- <div ngbDropdownMenu class="scrollable-menu shadow">
- <button type="button" *ngFor="let tag of tags" ngbDropdownItem (click)="addTag(tag.id)">
- <app-tag [tag]="tag"></app-tag>
- </button>
- </div>
- </div>
+ <ng-template ng-label-tmp let-item="item">
+ <span class="tag-wrap tag-wrap-delete" (click)="removeTag(item.id)">
+ <svg width="1.2em" height="1em" viewBox="0 0 16 16" fill="currentColor" xmlns="http://www.w3.org/2000/svg">
+ <use xlink:href="assets/bootstrap-icons.svg#x"/>
+ </svg>
+ <app-tag style="background-color: none;" [tag]="getTag(item.id)"></app-tag>
+ </span>
+ </ng-template>
+ <ng-template ng-option-tmp let-item="item" let-index="index" let-search="searchTerm">
+ <div class="tag-wrap">
+ <div class="selected-icon d-inline-block mr-1">
+ <svg *ngIf="displayValue.includes(item.id)" width="1em" height="1em" viewBox="0 0 16 16" fill="currentColor" xmlns="http://www.w3.org/2000/svg">
+ <use xlink:href="assets/bootstrap-icons.svg#check"/>
+ </svg>
+ </div>
+ <app-tag class="mr-2" [tag]="getTag(item.id)"></app-tag>
+ </div>
+ </ng-template>
+ </ng-select>
<div class="input-group-append">
-
<button class="btn btn-outline-secondary" type="button" (click)="createTag()">
<svg class="buttonicon" fill="currentColor">
<use xlink:href="assets/bootstrap-icons.svg#plus" />
</svg>
</button>
</div>
-
</div>
<small class="form-text text-muted" *ngIf="hint">{{hint}}</small>
-</div>
\ No newline at end of file
+</div>
diff --git a/src-ui/src/app/components/common/input/tags/tags.component.scss b/src-ui/src/app/components/common/input/tags/tags.component.scss
index f2635b7f2..2eaaa4f6d 100644
--- a/src-ui/src/app/components/common/input/tags/tags.component.scss
+++ b/src-ui/src/app/components/common/input/tags/tags.component.scss
@@ -1,10 +1,12 @@
-.tags-form-control {
- height: auto;
+.selected-icon {
+ min-width: 1em;
+ min-height: 1em;
}
+.tag-wrap {
+ font-size: 1rem;
+}
-.scrollable-menu {
- height: auto;
- max-height: 300px;
- overflow-x: hidden;
-}
\ No newline at end of file
+.tag-wrap-delete {
+ cursor: pointer;
+}
diff --git a/src-ui/src/app/components/common/input/tags/tags.component.ts b/src-ui/src/app/components/common/input/tags/tags.component.ts
index cca99cc55..5501ac5a6 100644
--- a/src-ui/src/app/components/common/input/tags/tags.component.ts
+++ b/src-ui/src/app/components/common/input/tags/tags.component.ts
@@ -21,7 +21,7 @@ export class TagsComponent implements OnInit, ControlValueAccessor {
onChange = (newValue: number[]) => {};
-
+
onTouched = () => {};
writeValue(newValue: number[]): void {
@@ -66,29 +66,28 @@ export class TagsComponent implements OnInit, ControlValueAccessor {
removeTag(id) {
let index = this.displayValue.indexOf(id)
if (index > -1) {
- this.displayValue.splice(index, 1)
+ let oldValue = this.displayValue
+ oldValue.splice(index, 1)
+ this.displayValue = [...oldValue]
this.onChange(this.displayValue)
}
}
- addTag(id) {
- let index = this.displayValue.indexOf(id)
- if (index == -1) {
- this.displayValue.push(id)
- this.onChange(this.displayValue)
- }
- }
-
-
createTag() {
var modal = this.modalService.open(TagEditDialogComponent, {backdrop: 'static'})
modal.componentInstance.dialogMode = 'create'
modal.componentInstance.success.subscribe(newTag => {
this.tagService.listAll().subscribe(tags => {
this.tags = tags.results
- this.addTag(newTag.id)
+ this.displayValue = [...this.displayValue, newTag.id]
+ this.onChange(this.displayValue)
})
})
}
+ ngSelectChange() {
+ this.value = this.displayValue
+ this.onChange(this.displayValue)
+ }
+
}
diff --git a/src-ui/src/app/components/dashboard/widgets/saved-view-widget/saved-view-widget.component.html b/src-ui/src/app/components/dashboard/widgets/saved-view-widget/saved-view-widget.component.html
index 194497d39..f50708af3 100644
--- a/src-ui/src/app/components/dashboard/widgets/saved-view-widget/saved-view-widget.component.html
+++ b/src-ui/src/app/components/dashboard/widgets/saved-view-widget/saved-view-widget.component.html
@@ -13,7 +13,7 @@
<tbody>
<tr *ngFor="let doc of documents" routerLink="/documents/{{doc.id}}">
<td>{{doc.created | date}}</td>
- <td>{{doc.title}}<app-tag [tag]="t" *ngFor="let t of doc.tags$ | async" class="ml-1"></app-tag>
+ <td>{{doc.title | documentTitle}}<app-tag [tag]="t" *ngFor="let t of doc.tags$ | async" class="ml-1"></app-tag>
</tr>
</tbody>
</table>
diff --git a/src-ui/src/app/components/document-detail/document-detail.component.html b/src-ui/src/app/components/document-detail/document-detail.component.html
index c0114f709..a3bc7e1e6 100644
--- a/src-ui/src/app/components/document-detail/document-detail.component.html
+++ b/src-ui/src/app/components/document-detail/document-detail.component.html
@@ -52,9 +52,9 @@
</div>
<app-input-date-time titleDate="Date created" formControlName="created"></app-input-date-time>
<app-input-select [items]="correspondents" title="Correspondent" formControlName="correspondent"
- allowNull="true" (createNew)="createCorrespondent()"></app-input-select>
+ (createNew)="createCorrespondent()"></app-input-select>
<app-input-select [items]="documentTypes" title="Document type" formControlName="document_type"
- allowNull="true" (createNew)="createDocumentType()"></app-input-select>
+ (createNew)="createDocumentType()"></app-input-select>
<app-input-tags formControlName="tags" title="Tags"></app-input-tags>
</ng-template>
@@ -110,8 +110,8 @@
</tbody>
</table>
- <app-metadata-collapse title="Original document metadata" [metadata]="metadata.original_metadata" *ngIf="metadata?.original_metadata.length > 0"></app-metadata-collapse>
- <app-metadata-collapse title="Archived document metadata" [metadata]="metadata.archive_metadata" *ngIf="metadata?.archive_metadata.length > 0"></app-metadata-collapse>
+ <app-metadata-collapse title="Original document metadata" [metadata]="metadata.original_metadata" *ngIf="metadata?.original_metadata?.length > 0"></app-metadata-collapse>
+ <app-metadata-collapse title="Archived document metadata" [metadata]="metadata.archive_metadata" *ngIf="metadata?.archive_metadata?.length > 0"></app-metadata-collapse>
</ng-template>
</li>
diff --git a/src-ui/src/app/components/document-detail/document-detail.component.ts b/src-ui/src/app/components/document-detail/document-detail.component.ts
index 5fe9f9250..b4005b920 100644
--- a/src-ui/src/app/components/document-detail/document-detail.component.ts
+++ b/src-ui/src/app/components/document-detail/document-detail.component.ts
@@ -6,6 +6,7 @@ import { PaperlessCorrespondent } from 'src/app/data/paperless-correspondent';
import { PaperlessDocument } from 'src/app/data/paperless-document';
import { PaperlessDocumentMetadata } from 'src/app/data/paperless-document-metadata';
import { PaperlessDocumentType } from 'src/app/data/paperless-document-type';
+import { DocumentTitlePipe } from 'src/app/pipes/document-title.pipe';
import { DocumentListViewService } from 'src/app/services/document-list-view.service';
import { OpenDocumentsService } from 'src/app/services/open-documents.service';
import { CorrespondentService } from 'src/app/services/rest/correspondent.service';
@@ -54,7 +55,8 @@ export class DocumentDetailComponent implements OnInit {
private router: Router,
private modalService: NgbModal,
private openDocumentService: OpenDocumentsService,
- private documentListViewService: DocumentListViewService) { }
+ private documentListViewService: DocumentListViewService,
+ private documentTitlePipe: DocumentTitlePipe) { }
getContentType() {
return this.metadata?.has_archive_version ? 'application/pdf' : this.metadata?.original_mime_type
@@ -90,7 +92,7 @@ export class DocumentDetailComponent implements OnInit {
this.documentsService.getMetadata(doc.id).subscribe(result => {
this.metadata = result
})
- this.title = doc.title
+ this.title = this.documentTitlePipe.transform(doc.title)
this.documentForm.patchValue(doc)
}
diff --git a/src-ui/src/app/components/document-list/document-card-large/document-card-large.component.scss b/src-ui/src/app/components/document-list/document-card-large/document-card-large.component.scss
index d6be8837e..11fb10562 100644
--- a/src-ui/src/app/components/document-list/document-card-large/document-card-large.component.scss
+++ b/src-ui/src/app/components/document-list/document-card-large/document-card-large.component.scss
@@ -1,5 +1,6 @@
.result-content {
color: darkgray;
+ overflow-wrap: anywhere;
}
.doc-img {
diff --git a/src-ui/src/app/components/document-list/document-card-small/document-card-small.component.html b/src-ui/src/app/components/document-list/document-card-small/document-card-small.component.html
index 378047602..948d585f4 100644
--- a/src-ui/src/app/components/document-list/document-card-small/document-card-small.component.html
+++ b/src-ui/src/app/components/document-list/document-card-small/document-card-small.component.html
@@ -31,7 +31,7 @@
</div>
<div class="card-footer">
- <div class="d-flex justify-content-between align-items-center ml-n2">
+ <div class="d-flex justify-content-between align-items-center mx-n2">
<div class="btn-group">
<a routerLink="/documents/{{document.id}}" class="btn btn-sm btn-outline-secondary" title="Edit">
<svg width="1em" height="1em" viewBox="0 0 16 16" class="bi bi-pencil" fill="currentColor" xmlns="http://www.w3.org/2000/svg">
@@ -51,7 +51,7 @@
</svg>
</a>
</div>
- <small class="text-muted">{{document.created | date}}</small>
+ <small class="text-muted pl-1">{{document.created | date}}</small>
</div>
</div>
diff --git a/src-ui/src/app/components/document-list/document-list.component.html b/src-ui/src/app/components/document-list/document-list.component.html
index a88ad65b7..5b4511866 100644
--- a/src-ui/src/app/components/document-list/document-list.component.html
+++ b/src-ui/src/app/components/document-list/document-list.component.html
@@ -77,7 +77,7 @@
</app-page-header>
-<div class="w-100 mb-4">
+<div class="w-100 mb-2 mb-sm-4">
<app-filter-editor [(filterRules)]="list.filterRules" #filterEditor></app-filter-editor>
</div>
@@ -135,7 +135,7 @@
</td>
<td>
<a routerLink="/documents/{{d.id}}" title="Edit document" style="overflow-wrap: anywhere;">{{d.title | documentTitle}}</a>
- <app-tag [tag]="t" *ngFor="let t of d.tags$ | async" class="ml-1" clickable="true" linkTitle="Filter by tag" (click)="clickTag(t)"></app-tag>
+ <app-tag [tag]="t" *ngFor="let t of d.tags$ | async" class="ml-1" clickable="true" linkTitle="Filter by tag" (click)="clickTag(t.id)"></app-tag>
</td>
<td class="d-none d-xl-table-cell">
<ng-container *ngIf="d.document_type">
@@ -154,5 +154,5 @@
<div class=" m-n2 row" *ngIf="displayMode == 'smallCards'">
- <app-document-card-small [selected]="list.isSelected(d)" (selectedChange)="list.setSelected(d, $event)" [document]="d" *ngFor="let d of list.documents" (clickTag)="clickTag($event)" (clickCorrespondent)="clickCorrespondent($event)"></app-document-card-small>
+ <app-document-card-small [selected]="list.isSelected(d)" (selectedChange)="list.setSelected(d, $event)" [document]="d" *ngFor="let d of list.documents" (clickTag)="clickTag($event)" (clickCorrespondent)="clickCorrespondent($event)"></app-document-card-small>
</div>
diff --git a/src-ui/src/app/components/document-list/document-list.component.scss b/src-ui/src/app/components/document-list/document-list.component.scss
index b9553930b..d7c08abec 100644
--- a/src-ui/src/app/components/document-list/document-list.component.scss
+++ b/src-ui/src/app/components/document-list/document-list.component.scss
@@ -2,4 +2,26 @@
.table-row-selected {
background-color: $primaryFaded;
-}
\ No newline at end of file
+}
+
+$paperless-card-breakpoints: (
+ 0: 2, // xs
+ 768px: 3, //md
+ 992px: 4, //lg
+ 1200px: 5, //xl
+ 1400px: 6, // xxl
+ 1600px: 7,
+ 1800px: 8,
+ 2000px: 9
+);
+
+.row-cols-paperless-cards {
+ @each $width, $n_cols in $paperless-card-breakpoints {
+ @media(min-width: $width) {
+ > * {
+ flex: 0 0 auto;
+ width: 100% / $n_cols;
+ }
+ }
+ }
+}
diff --git a/src-ui/src/app/components/document-list/document-list.component.ts b/src-ui/src/app/components/document-list/document-list.component.ts
index 0a6fa4352..a8bdf89d3 100644
--- a/src-ui/src/app/components/document-list/document-list.component.ts
+++ b/src-ui/src/app/components/document-list/document-list.component.ts
@@ -98,6 +98,7 @@ export class DocumentListComponent implements OnInit {
saveViewConfigAs() {
let modal = this.modalService.open(SaveViewConfigDialogComponent, {backdrop: 'static'})
+ modal.componentInstance.defaultName = this.filterEditor.generateFilterName()
modal.componentInstance.saveClicked.subscribe(formValue => {
let savedView = {
name: formValue.name,
diff --git a/src-ui/src/app/components/document-list/save-view-config-dialog/save-view-config-dialog.component.ts b/src-ui/src/app/components/document-list/save-view-config-dialog/save-view-config-dialog.component.ts
index 284be49f6..8f0eb26f2 100644
--- a/src-ui/src/app/components/document-list/save-view-config-dialog/save-view-config-dialog.component.ts
+++ b/src-ui/src/app/components/document-list/save-view-config-dialog/save-view-config-dialog.component.ts
@@ -1,4 +1,4 @@
-import { Component, EventEmitter, OnInit, Output } from '@angular/core';
+import { Component, EventEmitter, Input, OnInit, Output } from '@angular/core';
import { FormControl, FormGroup } from '@angular/forms';
import { NgbActiveModal } from '@ng-bootstrap/ng-bootstrap';
@@ -14,6 +14,19 @@ export class SaveViewConfigDialogComponent implements OnInit {
@Output()
public saveClicked = new EventEmitter()
+ _defaultName = ""
+
+ get defaultName() {
+ return this._defaultName
+ }
+
+ @Input()
+ set defaultName(value: string) {
+ this._defaultName = value
+ this.saveViewConfigForm.patchValue({name: value})
+ }
+
+
saveViewConfigForm = new FormGroup({
name: new FormControl(''),
showInSideBar: new FormControl(false),
diff --git a/src-ui/src/app/components/filter-editor/filter-dropdown-date/filter-dropdown-date.component.html b/src-ui/src/app/components/filter-editor/filter-dropdown-date/filter-dropdown-date.component.html
index 6f6a42fe2..aca6e836c 100644
--- a/src-ui/src/app/components/filter-editor/filter-dropdown-date/filter-dropdown-date.component.html
+++ b/src-ui/src/app/components/filter-editor/filter-dropdown-date/filter-dropdown-date.component.html
@@ -4,38 +4,39 @@
</button>
<div class="dropdown-menu date-filter shadow pt-0" ngbDropdownMenu attr.aria-labelledby="dropdown{{title}}">
<div class="list-group list-group-flush">
- <button class="list-group-item small list-goup list-group-item-action d-flex p-2 pl-3" (click)="clear()">Clear</button>
- <button *ngFor="let range of [7, 30, 'month', 'year']" class="list-group-item small list-goup list-group-item-action d-flex p-2 pl-3" role="menuitem" (click)="setDateQuickFilter(range)">
- <ng-container *ngIf="isStringRange(range)">This </ng-container>
- {{ range }}
- <ng-container *ngIf="!isStringRange(range)"> days</ng-container>
+ <button *ngFor="let qf of quickFilters" class="list-group-item small list-goup list-group-item-action d-flex p-2 pl-3" role="menuitem" (click)="setDateQuickFilter(qf.id)">
+ {{qf.name}}
</button>
<div class="list-group-item d-flex flex-column align-items-start" role="menuitem">
- <div>Before</div>
+
+ <div class="mb-2 d-flex flex-row w-100 justify-content-between small">
+ <div>After</div>
+ <a *ngIf="dateAfter" class="btn btn-link p-0 m-0" (click)="clearAfter()">
+ <svg width="0.8em" height="0.8em" viewBox="0 0 16 16" class="bi bi-x" fill="currentColor" xmlns="http://www.w3.org/2000/svg">
+ <path fill-rule="evenodd" d="M4.646 4.646a.5.5 0 0 1 .708 0L8 7.293l2.646-2.647a.5.5 0 0 1 .708.708L8.707 8l2.647 2.646a.5.5 0 0 1-.708.708L8 8.707l-2.646 2.647a.5.5 0 0 1-.708-.708L7.293 8 4.646 5.354a.5.5 0 0 1 0-.708z" />
+ </svg>
+ <small>Clear</small>
+ </a>
+ </div>
+
<div class="input-group input-group-sm">
- <input class="form-control" type="text" placeholder="yyyy-mm-dd" name="before" [(ngModel)]="_dateBefore" [maxDate]="this._maxDate" ngbDatepicker (dateSelect)="onBeforeSelected($event)" #dpBefore="ngbDatepicker">
- <div class="input-group-append">
- <button class="btn btn-outline-secondary btn-sm" (click)="dpBefore.toggle()" type="button">
- <svg width="1em" height="1em" viewBox="0 0 16 16" class="bi bi-calendar-date" fill="currentColor" xmlns="http://www.w3.org/2000/svg">
- <path fill-rule="evenodd" d="M3.5 0a.5.5 0 0 1 .5.5V1h8V.5a.5.5 0 0 1 1 0V1h1a2 2 0 0 1 2 2v11a2 2 0 0 1-2 2H2a2 2 0 0 1-2-2V3a2 2 0 0 1 2-2h1V.5a.5.5 0 0 1 .5-.5zM1 4v10a1 1 0 0 0 1 1h12a1 1 0 0 0 1-1V4H1z"/>
- <path d="M6.445 11.688V6.354h-.633A12.6 12.6 0 0 0 4.5 7.16v.695c.375-.257.969-.62 1.258-.777h.012v4.61h.675zm1.188-1.305c.047.64.594 1.406 1.703 1.406 1.258 0 2-1.066 2-2.871 0-1.934-.781-2.668-1.953-2.668-.926 0-1.797.672-1.797 1.809 0 1.16.824 1.77 1.676 1.77.746 0 1.23-.376 1.383-.79h.027c-.004 1.316-.461 2.164-1.305 2.164-.664 0-1.008-.45-1.05-.82h-.684zm2.953-2.317c0 .696-.559 1.18-1.184 1.18-.601 0-1.144-.383-1.144-1.2 0-.823.582-1.21 1.168-1.21.633 0 1.16.398 1.16 1.23z"/>
- </svg>
- </button>
- </div>
+ <input type="date" class="form-control" id="date_after" [(ngModel)]="dateAfter" (change)="onChangeDebounce()">
</div>
</div>
<div class="list-group-item d-flex flex-column align-items-start" role="menuitem">
- <div>After</div>
+
+ <div class="mb-2 d-flex flex-row w-100 justify-content-between small">
+ <div>Before</div>
+ <a *ngIf="dateBefore" class="btn btn-link p-0 m-0" (click)="clearBefore()">
+ <svg width="0.8em" height="0.8em" viewBox="0 0 16 16" class="bi bi-x" fill="currentColor" xmlns="http://www.w3.org/2000/svg">
+ <path fill-rule="evenodd" d="M4.646 4.646a.5.5 0 0 1 .708 0L8 7.293l2.646-2.647a.5.5 0 0 1 .708.708L8.707 8l2.647 2.646a.5.5 0 0 1-.708.708L8 8.707l-2.646 2.647a.5.5 0 0 1-.708-.708L7.293 8 4.646 5.354a.5.5 0 0 1 0-.708z" />
+ </svg>
+ <small>Clear</small>
+ </a>
+ </div>
+
<div class="input-group input-group-sm">
- <input class="form-control form-control-sm" type="text" placeholder="yyyy-mm-dd" name="after" [(ngModel)]="_dateAfter" [maxDate]="this._maxDate" ngbDatepicker (dateSelect)="onAfterSelected($event)" #dpAfter="ngbDatepicker">
- <div class="input-group-append">
- <button class="btn btn-outline-secondary btn-sm" (click)="dpAfter.toggle()" type="button">
- <svg width="1em" height="1em" viewBox="0 0 16 16" class="bi bi-calendar-date" fill="currentColor" xmlns="http://www.w3.org/2000/svg">
- <path fill-rule="evenodd" d="M3.5 0a.5.5 0 0 1 .5.5V1h8V.5a.5.5 0 0 1 1 0V1h1a2 2 0 0 1 2 2v11a2 2 0 0 1-2 2H2a2 2 0 0 1-2-2V3a2 2 0 0 1 2-2h1V.5a.5.5 0 0 1 .5-.5zM1 4v10a1 1 0 0 0 1 1h12a1 1 0 0 0 1-1V4H1z"/>
- <path d="M6.445 11.688V6.354h-.633A12.6 12.6 0 0 0 4.5 7.16v.695c.375-.257.969-.62 1.258-.777h.012v4.61h.675zm1.188-1.305c.047.64.594 1.406 1.703 1.406 1.258 0 2-1.066 2-2.871 0-1.934-.781-2.668-1.953-2.668-.926 0-1.797.672-1.797 1.809 0 1.16.824 1.77 1.676 1.77.746 0 1.23-.376 1.383-.79h.027c-.004 1.316-.461 2.164-1.305 2.164-.664 0-1.008-.45-1.05-.82h-.684zm2.953-2.317c0 .696-.559 1.18-1.184 1.18-.601 0-1.144-.383-1.144-1.2 0-.823.582-1.21 1.168-1.21.633 0 1.16.398 1.16 1.23z"/>
- </svg>
- </button>
- </div>
+ <input type="date" class="form-control" id="date_before" [(ngModel)]="dateBefore" (change)="onChangeDebounce()">
</div>
</div>
</div>
diff --git a/src-ui/src/app/components/filter-editor/filter-dropdown-date/filter-dropdown-date.component.ts b/src-ui/src/app/components/filter-editor/filter-dropdown-date/filter-dropdown-date.component.ts
index 806027f9c..e570862cd 100644
--- a/src-ui/src/app/components/filter-editor/filter-dropdown-date/filter-dropdown-date.component.ts
+++ b/src-ui/src/app/components/filter-editor/filter-dropdown-date/filter-dropdown-date.component.ts
@@ -1,25 +1,37 @@
-import { Component, EventEmitter, Input, Output, ElementRef, ViewChild, SimpleChange } from '@angular/core';
-import { NgbDate, NgbDateStruct, NgbDatepicker } from '@ng-bootstrap/ng-bootstrap';
-
+import { formatDate } from '@angular/common';
+import { Component, EventEmitter, Input, Output, OnInit, OnDestroy } from '@angular/core';
+import { Subject, Subscription } from 'rxjs';
+import { debounceTime, distinctUntilChanged } from 'rxjs/operators';
export interface DateSelection {
- before?: NgbDateStruct
- after?: NgbDateStruct
+ before?: string
+ after?: string
}
+const FILTER_LAST_7_DAYS = 0
+const FILTER_LAST_MONTH = 1
+const FILTER_LAST_3_MONTHS = 2
+const FILTER_LAST_YEAR = 3
@Component({
selector: 'app-filter-dropdown-date',
templateUrl: './filter-dropdown-date.component.html',
styleUrls: ['./filter-dropdown-date.component.scss']
})
-export class FilterDropdownDateComponent {
+export class FilterDropdownDateComponent implements OnInit, OnDestroy {
+
+ quickFilters = [
+ {id: FILTER_LAST_7_DAYS, name: "Last 7 days"},
+ {id: FILTER_LAST_MONTH, name: "Last month"},
+ {id: FILTER_LAST_3_MONTHS, name: "Last 3 months"},
+ {id: FILTER_LAST_YEAR, name: "Last year"}
+ ]
@Input()
- dateBefore: NgbDateStruct
+ dateBefore: string
@Input()
- dateAfter: NgbDateStruct
+ dateAfter: string
@Input()
title: string
@@ -27,83 +39,65 @@ export class FilterDropdownDateComponent {
@Output()
datesSet = new EventEmitter<DateSelection>()
- @ViewChild('dpAfter') dpAfter: NgbDatepicker
- @ViewChild('dpBefore') dpBefore: NgbDatepicker
-
- _dateBefore: NgbDateStruct
- _dateAfter: NgbDateStruct
-
- get _maxDate(): NgbDate {
- let date = new Date()
- return NgbDate.from({year: date.getFullYear(), month: date.getMonth() + 1, day: date.getDate()})
- }
+ private datesSetDebounce$ = new Subject()
- isStringRange(range: any) {
- return typeof range == 'string'
+ private sub: Subscription
+
+ ngOnInit() {
+ this.sub = this.datesSetDebounce$.pipe(
+ debounceTime(400)
+ ).subscribe(() => {
+ this.onChange()
+ })
}
- ngOnChanges(changes: SimpleChange) {
- // this is a hacky workaround perhaps because of https://github.com/angular/angular/issues/11097
- let dateString: string = ''
- let dateAfterChange: SimpleChange
- let dateBeforeChange: SimpleChange
- if (changes) {
- dateAfterChange = changes['dateAfter']
- dateBeforeChange = changes['dateBefore']
- }
-
- if (this.dpBefore && this.dpAfter) {
- let dpAfterElRef: ElementRef = this.dpAfter['_elRef']
- let dpBeforeElRef: ElementRef = this.dpBefore['_elRef']
-
- if (dateAfterChange && dateAfterChange.currentValue) {
- let dateAfterDate = dateAfterChange.currentValue as NgbDateStruct
- dateString = `${dateAfterDate.year}-${dateAfterDate.month.toString().padStart(2,'0')}-${dateAfterDate.day.toString().padStart(2,'0')}`
- dpAfterElRef.nativeElement.value = dateString
- } else if (dateBeforeChange && dateBeforeChange.currentValue) {
- let dateBeforeDate = dateBeforeChange.currentValue as NgbDateStruct
- dateString = `${dateBeforeDate.year}-${dateBeforeDate.month.toString().padStart(2,'0')}-${dateBeforeDate.day.toString().padStart(2,'0')}`
- dpBeforeElRef.nativeElement.value = dateString
- } else {
- dpAfterElRef.nativeElement.value = dateString
- dpBeforeElRef.nativeElement.value = dateString
- }
+ ngOnDestroy() {
+ if (this.sub) {
+ this.sub.unsubscribe()
}
}
- setDateQuickFilter(range: any) {
- this._dateAfter = this._dateBefore = undefined
+ setDateQuickFilter(qf: number) {
+ this.dateBefore = null
let date = new Date()
- let newDate: NgbDateStruct = { year: date.getFullYear(), month: date.getMonth() + 1, day: date.getDate() }
- switch (typeof range) {
- case 'number':
- date.setDate(date.getDate() - range)
- newDate.year = date.getFullYear()
- newDate.month = date.getMonth() + 1
- newDate.day = date.getDate()
- break
+ switch (qf) {
+ case FILTER_LAST_7_DAYS:
+ date.setDate(date.getDate() - 7)
+ break;
- case 'string':
- newDate.day = 1
- if (range == 'year') newDate.month = 1
+ case FILTER_LAST_MONTH:
+ date.setMonth(date.getMonth() - 1)
+ break;
+
+ case FILTER_LAST_3_MONTHS:
+ date.setMonth(date.getMonth() - 3)
break
- default:
+ case FILTER_LAST_YEAR:
+ date.setFullYear(date.getFullYear() - 1)
break
- }
- this._dateAfter = newDate
- this.datesSet.emit({after: newDate, before: null})
+
+ }
+ this.dateAfter = formatDate(date, 'yyyy-MM-dd', "en-us", "UTC")
+ this.onChange()
+ }
+
+ onChange() {
+ this.datesSet.emit({after: this.dateAfter, before: this.dateBefore})
}
- onBeforeSelected(date: NgbDateStruct) {
- this.datesSet.emit({after: this._dateAfter, before: date})
+ onChangeDebounce() {
+ this.datesSetDebounce$.next({after: this.dateAfter, before: this.dateBefore})
}
- onAfterSelected(date: NgbDateStruct) {
- this.datesSet.emit({after: date, before: this._dateBefore})
+ clearBefore() {
+ this.dateBefore = null;
+ this.onChange()
}
- clear() {
- this.datesSet.emit({after: null, before: null})
+ clearAfter() {
+ this.dateAfter = null;
+ this.onChange()
}
+
}
diff --git a/src-ui/src/app/components/filter-editor/filter-dropdown/filter-dropdown.component.html b/src-ui/src/app/components/filter-editor/filter-dropdown/filter-dropdown.component.html
index 5de9228bd..d0cbfc3c9 100644
--- a/src-ui/src/app/components/filter-editor/filter-dropdown/filter-dropdown.component.html
+++ b/src-ui/src/app/components/filter-editor/filter-dropdown/filter-dropdown.component.html
@@ -1,6 +1,16 @@
<div class="btn-group" ngbDropdown role="group" (openChange)="dropdownOpenChange($event)" #filterDropdown="ngbDropdown">
<button class="btn btn-sm" id="dropdown{{title}}" ngbDropdownToggle [ngClass]="itemsSelected?.length > 0 ? 'btn-primary' : 'btn-outline-primary'">
- {{title}}
+ <div class="d-none d-md-inline">{{title}}</div>
+ <div class="d-inline-block d-md-none">
+ <svg class="toolbaricon" fill="currentColor">
+ <use attr.xlink:href="assets/bootstrap-icons.svg#{{icon}}" />
+ </svg>
+ </div>
+ <ng-container *ngIf="itemsSelected?.length > 0">
+ <div class="badge bg-secondary text-light rounded-pill badge-corner">
+ {{itemsSelected?.length}}
+ </div>
+ </ng-container>
</button>
<div class="dropdown-menu py-0 shadow" ngbDropdownMenu attr.aria-labelledby="dropdown{{title}}">
<div class="list-group list-group-flush">
diff --git a/src-ui/src/app/components/filter-editor/filter-dropdown/filter-dropdown.component.scss b/src-ui/src/app/components/filter-editor/filter-dropdown/filter-dropdown.component.scss
index d34729eee..40c93838f 100644
--- a/src-ui/src/app/components/filter-editor/filter-dropdown/filter-dropdown.component.scss
+++ b/src-ui/src/app/components/filter-editor/filter-dropdown/filter-dropdown.component.scss
@@ -1,3 +1,9 @@
+.badge-corner {
+ position: absolute;
+ top: -8px;
+ right: -8px;
+}
+
.dropdown-menu {
min-width: 250px;
diff --git a/src-ui/src/app/components/filter-editor/filter-dropdown/filter-dropdown.component.ts b/src-ui/src/app/components/filter-editor/filter-dropdown/filter-dropdown.component.ts
index d675e14f1..b9d3fca6f 100644
--- a/src-ui/src/app/components/filter-editor/filter-dropdown/filter-dropdown.component.ts
+++ b/src-ui/src/app/components/filter-editor/filter-dropdown/filter-dropdown.component.ts
@@ -22,7 +22,7 @@ export class FilterDropdownComponent {
title: string
@Input()
- display: string
+ icon: string
@Output()
toggle = new EventEmitter()
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 e07edba14..6847a2902 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,22 +1,27 @@
-<div class="form-row form-group mb-0">
- <div class="col-auto">
- <div class="text-muted mt-1">Filter by:</div>
+<div class="row">
+ <div class="col mb-2 mb-xl-0">
+ <div class="form-inline d-flex">
+ <label class="text-muted mr-2">Filter by:</label>
+ <input class="form-control form-control-sm flex-grow-1" type="text" [(ngModel)]="titleFilter" placeholder="Title">
+ </div>
</div>
- <div class="col">
- <input class="form-control form-control-sm" type="text" [(ngModel)]="titleFilter" placeholder="Title">
- </div>
-
- <app-filter-dropdown class="col-auto" [items]="tags" [itemsSelected]="selectedTags" title="Tags" (toggle)="toggleTag($event.id)"></app-filter-dropdown>
- <app-filter-dropdown class="col-auto" [items]="correspondents" [itemsSelected]="selectedCorrespondents" title="Correspondents" (toggle)="toggleCorrespondent($event.id)"></app-filter-dropdown>
- <app-filter-dropdown class="col-auto" [items]="documentTypes" [itemsSelected]="selectedDocumentTypes" title="Document types" (toggle)="toggleDocumentType($event.id)"></app-filter-dropdown>
-
- <app-filter-dropdown-date class="col-auto" [dateBefore]="dateCreatedBefore" [dateAfter]="dateCreatedAfter" title="Created" (datesSet)="onDatesCreatedSet($event)"></app-filter-dropdown-date>
- <app-filter-dropdown-date class="col-auto" [dateBefore]="dateAddedBefore" [dateAfter]="dateAddedAfter" title="Added" (datesSet)="onDatesAddedSet($event)"></app-filter-dropdown-date>
-
- <button class="btn btn-link btn-sm" [disabled]="!hasFilters()" (click)="clearSelected()">
- <svg width="1em" height="1em" viewBox="0 0 16 16" fill="currentColor">
- <use xlink:href="assets/bootstrap-icons.svg#x" />
- </svg>
- Clear all filters
- </button>
+ <div class="w-100 d-xl-none"></div>
+ <div class="col col-xl-auto mb-2 mb-xl-0">
+ <div class="d-flex">
+ <app-filter-dropdown class="mr-2 mr-md-3" [items]="tags" [itemsSelected]="selectedTags" title="Tags" icon="tag-fill" (toggle)="toggleTag($event.id)"></app-filter-dropdown>
+ <app-filter-dropdown class="mr-2 mr-md-3" [items]="correspondents" [itemsSelected]="selectedCorrespondents" title="Correspondents" icon="person-fill" (toggle)="toggleCorrespondent($event.id)"></app-filter-dropdown>
+ <app-filter-dropdown class="mr-2 mr-md-3" [items]="documentTypes" [itemsSelected]="selectedDocumentTypes" title="Document types" icon="file-earmark-fill" (toggle)="toggleDocumentType($event.id)"></app-filter-dropdown>
+ <app-filter-dropdown-date class="mr-2 mr-md-3" [dateBefore]="dateCreatedBefore" [dateAfter]="dateCreatedAfter" title="Created" (datesSet)="onDatesCreatedSet($event)"></app-filter-dropdown-date>
+ <app-filter-dropdown-date [dateBefore]="dateAddedBefore" [dateAfter]="dateAddedAfter" title="Added" (datesSet)="onDatesAddedSet($event)"></app-filter-dropdown-date>
+ </div>
+ </div>
+ <div class="w-100 d-xl-none"></div>
+ <div class="col col-xl-auto mb-2 mb-xl-0">
+ <button class="btn btn-link btn-sm px-0 mx-0 ml-xl-n4" [disabled]="!hasFilters()" (click)="clearSelected()">
+ <svg width="1em" height="1em" viewBox="0 0 16 16" class="bi bi-x" fill="currentColor" xmlns="http://www.w3.org/2000/svg">
+ <path fill-rule="evenodd" d="M4.646 4.646a.5.5 0 0 1 .708 0L8 7.293l2.646-2.647a.5.5 0 0 1 .708.708L8.707 8l2.647 2.646a.5.5 0 0 1-.708.708L8 8.707l-2.646 2.647a.5.5 0 0 1-.708-.708L7.293 8 4.646 5.354a.5.5 0 0 1 0-.708z"/>
+ </svg>
+ Clear all filters
+ </button>
+ </div>
</div>
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 f98b9517f..913c738a5 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
@@ -19,6 +19,26 @@ import { DateSelection } from './filter-dropdown-date/filter-dropdown-date.compo
})
export class FilterEditorComponent implements OnInit, OnDestroy {
+ generateFilterName() {
+ if (this.filterRules.length == 1) {
+ let rule = this.filterRules[0]
+ switch(this.filterRules[0].rule_type) {
+
+ case FILTER_CORRESPONDENT:
+ return `Correspondent: ${this.correspondents.find(c => c.id == +rule.value)?.name}`
+
+ case FILTER_DOCUMENT_TYPE:
+ return `Type: ${this.documentTypes.find(dt => dt.id == +rule.value)?.name}`
+
+ case FILTER_HAS_TAG:
+ return `Tag: ${this.tags.find(t => t.id == +rule.value)?.name}`
+
+ }
+ }
+
+ return ""
+ }
+
constructor(
private documentTypeService: DocumentTypeService,
private tagService: TagService,
@@ -159,65 +179,61 @@ export class FilterEditorComponent implements OnInit, OnDestroy {
this.applyFilters()
}
- get dateCreatedBefore(): NgbDateStruct {
+ get dateCreatedBefore(): string {
let createdBeforeRule: FilterRule = this.filterRules.find(fr => fr.rule_type == FILTER_CREATED_BEFORE)
- return createdBeforeRule ? this.dateParser.parse(createdBeforeRule.value) : null
+ return createdBeforeRule ? createdBeforeRule.value : null
}
- get dateCreatedAfter(): NgbDateStruct {
+ get dateCreatedAfter(): string {
let createdAfterRule: FilterRule = this.filterRules.find(fr => fr.rule_type == FILTER_CREATED_AFTER)
- return createdAfterRule ? this.dateParser.parse(createdAfterRule.value) : null
+ return createdAfterRule ? createdAfterRule.value : null
}
- get dateAddedBefore(): NgbDateStruct {
+ get dateAddedBefore(): string {
let addedBeforeRule: FilterRule = this.filterRules.find(fr => fr.rule_type == FILTER_ADDED_BEFORE)
- return addedBeforeRule ? this.dateParser.parse(addedBeforeRule.value) : null
+ return addedBeforeRule ? addedBeforeRule.value : null
}
- get dateAddedAfter(): NgbDateStruct {
+ get dateAddedAfter(): string {
let addedAfterRule: FilterRule = this.filterRules.find(fr => fr.rule_type == FILTER_ADDED_AFTER)
- return addedAfterRule ? this.dateParser.parse(addedAfterRule.value) : null
+ return addedAfterRule ? addedAfterRule.value : null
}
- setDateCreatedBefore(date?: NgbDateStruct) {
+ setDateCreatedBefore(date?: string) {
if (date) this.setDateFilter(date, FILTER_CREATED_BEFORE)
else this.clearDateFilter(FILTER_CREATED_BEFORE)
}
- setDateCreatedAfter(date?: NgbDateStruct) {
+ setDateCreatedAfter(date?: string) {
if (date) this.setDateFilter(date, FILTER_CREATED_AFTER)
else this.clearDateFilter(FILTER_CREATED_AFTER)
}
- setDateAddedBefore(date?: NgbDateStruct) {
+ setDateAddedBefore(date?: string) {
if (date) this.setDateFilter(date, FILTER_ADDED_BEFORE)
else this.clearDateFilter(FILTER_ADDED_BEFORE)
}
- setDateAddedAfter(date?: NgbDateStruct) {
+ setDateAddedAfter(date?: string) {
if (date) this.setDateFilter(date, FILTER_ADDED_AFTER)
else this.clearDateFilter(FILTER_ADDED_AFTER)
}
- setDateFilter(date: NgbDateStruct, dateRuleTypeID: number) {
- let filterRules = this.filterRules
- let existingRule = filterRules.find(rule => rule.rule_type == dateRuleTypeID)
- let newValue = this.dateParser.format(date)
+ setDateFilter(date: string, dateRuleTypeID: number) {
+ let existingRule = this.filterRules.find(rule => rule.rule_type == dateRuleTypeID)
if (existingRule) {
- existingRule.value = newValue
+ existingRule.value = date
} else {
- filterRules.push({rule_type: dateRuleTypeID, value: newValue})
+ this.filterRules.push({rule_type: dateRuleTypeID, value: date})
}
-
- this.filterRules = filterRules
}
clearDateFilter(dateRuleTypeID: number) {
- let filterRules = this.filterRules
- let existingRule = filterRules.find(rule => rule.rule_type == dateRuleTypeID)
- filterRules.splice(filterRules.indexOf(existingRule), 1)
- this.filterRules = filterRules
+ let ruleIndex = this.filterRules.findIndex(rule => rule.rule_type == dateRuleTypeID)
+ if (ruleIndex != -1) {
+ this.filterRules.splice(ruleIndex, 1)
+ }
}
}
diff --git a/src-ui/src/app/components/manage/correspondent-list/correspondent-list.component.html b/src-ui/src/app/components/manage/correspondent-list/correspondent-list.component.html
index 27aa4d366..2efd1c58d 100644
--- a/src-ui/src/app/components/manage/correspondent-list/correspondent-list.component.html
+++ b/src-ui/src/app/components/manage/correspondent-list/correspondent-list.component.html
@@ -26,9 +26,26 @@
<td scope="row">{{ correspondent.last_correspondence | date }}</td>
<td scope="row">
<div class="btn-group">
- <button class="btn btn-sm btn-outline-secondary" (click)="openEditDialog(correspondent)">Edit</button>
- <button class="btn btn-sm btn-outline-danger" (click)="openDeleteDialog(correspondent)">Delete</button>
- </div>
+ <button class="btn btn-sm btn-outline-secondary" (click)="filterDocuments(correspondent)">
+ <svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-funnel" viewBox="0 0 16 16">
+ <path fill-rule="evenodd" d="M1.5 1.5A.5.5 0 0 1 2 1h12a.5.5 0 0 1 .5.5v2a.5.5 0 0 1-.128.334L10 8.692V13.5a.5.5 0 0 1-.342.474l-3 1A.5.5 0 0 1 6 14.5V8.692L1.628 3.834A.5.5 0 0 1 1.5 3.5v-2zm1 .5v1.308l4.372 4.858A.5.5 0 0 1 7 8.5v5.306l2-.666V8.5a.5.5 0 0 1 .128-.334L13.5 3.308V2h-11z"/>
+ </svg>
+ Documents
+ </button>
+ <button class="btn btn-sm btn-outline-secondary" (click)="openEditDialog(correspondent)">
+ <svg width="1em" height="1em" viewBox="0 0 16 16" class="bi bi-pencil" fill="currentColor" xmlns="http://www.w3.org/2000/svg">
+ <path fill-rule="evenodd" d="M12.146.146a.5.5 0 0 1 .708 0l3 3a.5.5 0 0 1 0 .708l-10 10a.5.5 0 0 1-.168.11l-5 2a.5.5 0 0 1-.65-.65l2-5a.5.5 0 0 1 .11-.168l10-10zM11.207 2.5L13.5 4.793 14.793 3.5 12.5 1.207 11.207 2.5zm1.586 3L10.5 3.207 4 9.707V10h.5a.5.5 0 0 1 .5.5v.5h.5a.5.5 0 0 1 .5.5v.5h.293l6.5-6.5zm-9.761 5.175l-.106.106-1.528 3.821 3.821-1.528.106-.106A.5.5 0 0 1 5 12.5V12h-.5a.5.5 0 0 1-.5-.5V11h-.5a.5.5 0 0 1-.468-.325z"/>
+ </svg>
+ Edit
+ </button>
+ <button class="btn btn-sm btn-outline-danger" (click)="openDeleteDialog(correspondent)">
+ <svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-trash" viewBox="0 0 16 16">
+ <path d="M5.5 5.5A.5.5 0 0 1 6 6v6a.5.5 0 0 1-1 0V6a.5.5 0 0 1 .5-.5zm2.5 0a.5.5 0 0 1 .5.5v6a.5.5 0 0 1-1 0V6a.5.5 0 0 1 .5-.5zm3 .5a.5.5 0 0 0-1 0v6a.5.5 0 0 0 1 0V6z"/>
+ <path fill-rule="evenodd" d="M14.5 3a1 1 0 0 1-1 1H13v9a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V4h-.5a1 1 0 0 1-1-1V2a1 1 0 0 1 1-1H6a1 1 0 0 1 1-1h2a1 1 0 0 1 1 1h3.5a1 1 0 0 1 1 1v1zM4.118 4L4 4.059V13a1 1 0 0 0 1 1h6a1 1 0 0 0 1-1V4.059L11.882 4H4.118zM2.5 3V2h11v1h-11z"/>
+ </svg>
+ Delete
+ </button>
+ </div>
</td>
</tr>
</tbody>
diff --git a/src-ui/src/app/components/manage/correspondent-list/correspondent-list.component.ts b/src-ui/src/app/components/manage/correspondent-list/correspondent-list.component.ts
index effae2826..a128340b9 100644
--- a/src-ui/src/app/components/manage/correspondent-list/correspondent-list.component.ts
+++ b/src-ui/src/app/components/manage/correspondent-list/correspondent-list.component.ts
@@ -1,6 +1,9 @@
import { Component, OnInit } from '@angular/core';
+import { Router } from '@angular/router';
import { NgbModal } from '@ng-bootstrap/ng-bootstrap';
+import { FILTER_CORRESPONDENT } from 'src/app/data/filter-rule-type';
import { PaperlessCorrespondent } from 'src/app/data/paperless-correspondent';
+import { DocumentListViewService } from 'src/app/services/document-list-view.service';
import { CorrespondentService } from 'src/app/services/rest/correspondent.service';
import { GenericListComponent } from '../generic-list/generic-list.component';
import { CorrespondentEditDialogComponent } from './correspondent-edit-dialog/correspondent-edit-dialog.component';
@@ -12,7 +15,10 @@ import { CorrespondentEditDialogComponent } from './correspondent-edit-dialog/co
})
export class CorrespondentListComponent extends GenericListComponent<PaperlessCorrespondent> {
- constructor(correspondentsService: CorrespondentService, modalService: NgbModal,) {
+ constructor(correspondentsService: CorrespondentService, modalService: NgbModal,
+ private router: Router,
+ private list: DocumentListViewService
+ ) {
super(correspondentsService,modalService,CorrespondentEditDialogComponent)
}
@@ -20,4 +26,10 @@ export class CorrespondentListComponent extends GenericListComponent<PaperlessCo
return `correspondent '${object.name}'`
}
+ filterDocuments(object: PaperlessCorrespondent) {
+ this.list.documentListView.filter_rules = [
+ {rule_type: FILTER_CORRESPONDENT, value: object.id.toString()}
+ ]
+ this.router.navigate(["documents"])
+ }
}
diff --git a/src-ui/src/app/components/manage/document-type-list/document-type-list.component.html b/src-ui/src/app/components/manage/document-type-list/document-type-list.component.html
index 78c86daf3..d2ffab400 100644
--- a/src-ui/src/app/components/manage/document-type-list/document-type-list.component.html
+++ b/src-ui/src/app/components/manage/document-type-list/document-type-list.component.html
@@ -25,8 +25,25 @@
<td scope="row">{{ document_type.document_count }}</td>
<td scope="row">
<div class="btn-group">
- <button class="btn btn-sm btn-outline-secondary" (click)="openEditDialog(document_type)">Edit</button>
- <button class="btn btn-sm btn-outline-danger" (click)="openDeleteDialog(document_type)">Delete</button>
+ <button class="btn btn-sm btn-outline-secondary" (click)="filterDocuments(document_type)">
+ <svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-funnel" viewBox="0 0 16 16">
+ <path fill-rule="evenodd" d="M1.5 1.5A.5.5 0 0 1 2 1h12a.5.5 0 0 1 .5.5v2a.5.5 0 0 1-.128.334L10 8.692V13.5a.5.5 0 0 1-.342.474l-3 1A.5.5 0 0 1 6 14.5V8.692L1.628 3.834A.5.5 0 0 1 1.5 3.5v-2zm1 .5v1.308l4.372 4.858A.5.5 0 0 1 7 8.5v5.306l2-.666V8.5a.5.5 0 0 1 .128-.334L13.5 3.308V2h-11z"/>
+ </svg>
+ Documents
+ </button>
+ <button class="btn btn-sm btn-outline-secondary" (click)="openEditDialog(document_type)">
+ <svg width="1em" height="1em" viewBox="0 0 16 16" class="bi bi-pencil" fill="currentColor" xmlns="http://www.w3.org/2000/svg">
+ <path fill-rule="evenodd" d="M12.146.146a.5.5 0 0 1 .708 0l3 3a.5.5 0 0 1 0 .708l-10 10a.5.5 0 0 1-.168.11l-5 2a.5.5 0 0 1-.65-.65l2-5a.5.5 0 0 1 .11-.168l10-10zM11.207 2.5L13.5 4.793 14.793 3.5 12.5 1.207 11.207 2.5zm1.586 3L10.5 3.207 4 9.707V10h.5a.5.5 0 0 1 .5.5v.5h.5a.5.5 0 0 1 .5.5v.5h.293l6.5-6.5zm-9.761 5.175l-.106.106-1.528 3.821 3.821-1.528.106-.106A.5.5 0 0 1 5 12.5V12h-.5a.5.5 0 0 1-.5-.5V11h-.5a.5.5 0 0 1-.468-.325z"/>
+ </svg>
+ Edit
+ </button>
+ <button class="btn btn-sm btn-outline-danger" (click)="openDeleteDialog(document_type)">
+ <svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-trash" viewBox="0 0 16 16">
+ <path d="M5.5 5.5A.5.5 0 0 1 6 6v6a.5.5 0 0 1-1 0V6a.5.5 0 0 1 .5-.5zm2.5 0a.5.5 0 0 1 .5.5v6a.5.5 0 0 1-1 0V6a.5.5 0 0 1 .5-.5zm3 .5a.5.5 0 0 0-1 0v6a.5.5 0 0 0 1 0V6z"/>
+ <path fill-rule="evenodd" d="M14.5 3a1 1 0 0 1-1 1H13v9a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V4h-.5a1 1 0 0 1-1-1V2a1 1 0 0 1 1-1H6a1 1 0 0 1 1-1h2a1 1 0 0 1 1 1h3.5a1 1 0 0 1 1 1v1zM4.118 4L4 4.059V13a1 1 0 0 0 1 1h6a1 1 0 0 0 1-1V4.059L11.882 4H4.118zM2.5 3V2h11v1h-11z"/>
+ </svg>
+ Delete
+ </button>
</div>
</td>
</tr>
diff --git a/src-ui/src/app/components/manage/document-type-list/document-type-list.component.ts b/src-ui/src/app/components/manage/document-type-list/document-type-list.component.ts
index 16cdd88a9..d18a19226 100644
--- a/src-ui/src/app/components/manage/document-type-list/document-type-list.component.ts
+++ b/src-ui/src/app/components/manage/document-type-list/document-type-list.component.ts
@@ -1,6 +1,9 @@
import { Component } from '@angular/core';
+import { Router } from '@angular/router';
import { NgbModal } from '@ng-bootstrap/ng-bootstrap';
+import { FILTER_DOCUMENT_TYPE } from 'src/app/data/filter-rule-type';
import { PaperlessDocumentType } from 'src/app/data/paperless-document-type';
+import { DocumentListViewService } from 'src/app/services/document-list-view.service';
import { DocumentTypeService } from 'src/app/services/rest/document-type.service';
import { GenericListComponent } from '../generic-list/generic-list.component';
import { DocumentTypeEditDialogComponent } from './document-type-edit-dialog/document-type-edit-dialog.component';
@@ -12,7 +15,10 @@ import { DocumentTypeEditDialogComponent } from './document-type-edit-dialog/doc
})
export class DocumentTypeListComponent extends GenericListComponent<PaperlessDocumentType> {
- constructor(service: DocumentTypeService, modalService: NgbModal) {
+ constructor(service: DocumentTypeService, modalService: NgbModal,
+ private router: Router,
+ private list: DocumentListViewService
+ ) {
super(service, modalService, DocumentTypeEditDialogComponent)
}
@@ -20,4 +26,10 @@ export class DocumentTypeListComponent extends GenericListComponent<PaperlessDoc
return `document type '${object.name}'`
}
+ filterDocuments(object: PaperlessDocumentType) {
+ this.list.documentListView.filter_rules = [
+ {rule_type: FILTER_DOCUMENT_TYPE, value: object.id.toString()}
+ ]
+ this.router.navigate(["documents"])
+ }
}
diff --git a/src-ui/src/app/components/manage/generic-list/generic-list.component.ts b/src-ui/src/app/components/manage/generic-list/generic-list.component.ts
index 76a92e4e9..783c22b36 100644
--- a/src-ui/src/app/components/manage/generic-list/generic-list.component.ts
+++ b/src-ui/src/app/components/manage/generic-list/generic-list.component.ts
@@ -95,7 +95,7 @@ export abstract class GenericListComponent<T extends ObjectWithId> implements On
activeModal.componentInstance.message = "Associated documents will not be deleted."
activeModal.componentInstance.btnClass = "btn-danger"
activeModal.componentInstance.btnCaption = "Delete"
- activeModal.componentInstance.confirmPressed.subscribe(() => {
+ activeModal.componentInstance.confirmClicked.subscribe(() => {
this.service.delete(object).subscribe(_ => {
activeModal.close()
this.reloadData()
diff --git a/src-ui/src/app/components/manage/settings/settings.component.ts b/src-ui/src/app/components/manage/settings/settings.component.ts
index 41bb21156..f839010b1 100644
--- a/src-ui/src/app/components/manage/settings/settings.component.ts
+++ b/src-ui/src/app/components/manage/settings/settings.component.ts
@@ -50,16 +50,26 @@ export class SettingsComponent implements OnInit {
})
}
+ private saveLocalSettings() {
+ localStorage.setItem(GENERAL_SETTINGS.DOCUMENT_LIST_SIZE, this.settingsForm.value.documentListItemPerPage)
+ this.documentListViewService.updatePageSize()
+ this.toastService.showToast(Toast.make("Information", "Settings saved successfully."))
+ }
+
saveSettings() {
let x = []
for (let id in this.savedViewGroup.value) {
x.push(this.savedViewGroup.value[id])
}
- this.savedViewService.patchMany(x).subscribe(s => {
- this.toastService.showToast(Toast.make("Information", "Settings saved successfully."))
- localStorage.setItem(GENERAL_SETTINGS.DOCUMENT_LIST_SIZE, this.settingsForm.value.documentListItemPerPage)
- this.documentListViewService.updatePageSize()
- })
+ if (x.length > 0) {
+ this.savedViewService.patchMany(x).subscribe(s => {
+ this.saveLocalSettings()
+ }, error => {
+ this.toastService.showToast(Toast.makeError(`Error while storing settings on server: ${JSON.stringify(error.error)}`))
+ })
+ } else {
+ this.saveLocalSettings()
+ }
}
}
diff --git a/src-ui/src/app/components/manage/tag-list/tag-list.component.html b/src-ui/src/app/components/manage/tag-list/tag-list.component.html
index e68b997d1..bbe2c6dd2 100644
--- a/src-ui/src/app/components/manage/tag-list/tag-list.component.html
+++ b/src-ui/src/app/components/manage/tag-list/tag-list.component.html
@@ -9,7 +9,7 @@
aria-label="Default pagination"></ngb-pagination>
</div>
-<table class="table table-striped border shadow">
+<table class="table table-striped border shadow-sm">
<thead>
<tr>
<th scope="col" sortable="name" (sort)="onSort($event)">Name</th>
@@ -28,8 +28,25 @@
<td scope="row">{{ tag.document_count }}</td>
<td scope="row">
<div class="btn-group">
- <button class="btn btn-sm btn-outline-secondary" (click)="openEditDialog(tag)">Edit</button>
- <button class="btn btn-sm btn-outline-danger" (click)="openDeleteDialog(tag)">Delete</button>
+ <button class="btn btn-sm btn-outline-secondary" (click)="filterDocuments(tag)">
+ <svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-funnel" viewBox="0 0 16 16">
+ <path fill-rule="evenodd" d="M1.5 1.5A.5.5 0 0 1 2 1h12a.5.5 0 0 1 .5.5v2a.5.5 0 0 1-.128.334L10 8.692V13.5a.5.5 0 0 1-.342.474l-3 1A.5.5 0 0 1 6 14.5V8.692L1.628 3.834A.5.5 0 0 1 1.5 3.5v-2zm1 .5v1.308l4.372 4.858A.5.5 0 0 1 7 8.5v5.306l2-.666V8.5a.5.5 0 0 1 .128-.334L13.5 3.308V2h-11z"/>
+ </svg>
+ Documents
+ </button>
+ <button class="btn btn-sm btn-outline-secondary" (click)="openEditDialog(tag)">
+ <svg width="1em" height="1em" viewBox="0 0 16 16" class="bi bi-pencil" fill="currentColor" xmlns="http://www.w3.org/2000/svg">
+ <path fill-rule="evenodd" d="M12.146.146a.5.5 0 0 1 .708 0l3 3a.5.5 0 0 1 0 .708l-10 10a.5.5 0 0 1-.168.11l-5 2a.5.5 0 0 1-.65-.65l2-5a.5.5 0 0 1 .11-.168l10-10zM11.207 2.5L13.5 4.793 14.793 3.5 12.5 1.207 11.207 2.5zm1.586 3L10.5 3.207 4 9.707V10h.5a.5.5 0 0 1 .5.5v.5h.5a.5.5 0 0 1 .5.5v.5h.293l6.5-6.5zm-9.761 5.175l-.106.106-1.528 3.821 3.821-1.528.106-.106A.5.5 0 0 1 5 12.5V12h-.5a.5.5 0 0 1-.5-.5V11h-.5a.5.5 0 0 1-.468-.325z"/>
+ </svg>
+ Edit
+ </button>
+ <button class="btn btn-sm btn-outline-danger" (click)="openDeleteDialog(tag)">
+ <svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-trash" viewBox="0 0 16 16">
+ <path d="M5.5 5.5A.5.5 0 0 1 6 6v6a.5.5 0 0 1-1 0V6a.5.5 0 0 1 .5-.5zm2.5 0a.5.5 0 0 1 .5.5v6a.5.5 0 0 1-1 0V6a.5.5 0 0 1 .5-.5zm3 .5a.5.5 0 0 0-1 0v6a.5.5 0 0 0 1 0V6z"/>
+ <path fill-rule="evenodd" d="M14.5 3a1 1 0 0 1-1 1H13v9a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V4h-.5a1 1 0 0 1-1-1V2a1 1 0 0 1 1-1H6a1 1 0 0 1 1-1h2a1 1 0 0 1 1 1h3.5a1 1 0 0 1 1 1v1zM4.118 4L4 4.059V13a1 1 0 0 0 1 1h6a1 1 0 0 0 1-1V4.059L11.882 4H4.118zM2.5 3V2h11v1h-11z"/>
+ </svg>
+ Delete
+ </button>
</div>
</td>
</tr>
diff --git a/src-ui/src/app/components/manage/tag-list/tag-list.component.ts b/src-ui/src/app/components/manage/tag-list/tag-list.component.ts
index 32093e0a8..e3f151550 100644
--- a/src-ui/src/app/components/manage/tag-list/tag-list.component.ts
+++ b/src-ui/src/app/components/manage/tag-list/tag-list.component.ts
@@ -1,6 +1,9 @@
import { Component } from '@angular/core';
+import { Router } from '@angular/router';
import { NgbModal } from '@ng-bootstrap/ng-bootstrap';
+import { FILTER_HAS_TAG } from 'src/app/data/filter-rule-type';
import { TAG_COLOURS, PaperlessTag } from 'src/app/data/paperless-tag';
+import { DocumentListViewService } from 'src/app/services/document-list-view.service';
import { TagService } from 'src/app/services/rest/tag.service';
import { GenericListComponent } from '../generic-list/generic-list.component';
import { TagEditDialogComponent } from './tag-edit-dialog/tag-edit-dialog.component';
@@ -12,7 +15,10 @@ import { TagEditDialogComponent } from './tag-edit-dialog/tag-edit-dialog.compon
})
export class TagListComponent extends GenericListComponent<PaperlessTag> {
- constructor(tagService: TagService, modalService: NgbModal) {
+ constructor(tagService: TagService, modalService: NgbModal,
+ private router: Router,
+ private list: DocumentListViewService
+ ) {
super(tagService, modalService, TagEditDialogComponent)
}
@@ -23,4 +29,11 @@ export class TagListComponent extends GenericListComponent<PaperlessTag> {
getObjectName(object: PaperlessTag) {
return `tag '${object.name}'`
}
+
+ filterDocuments(object: PaperlessTag) {
+ this.list.documentListView.filter_rules = [
+ {rule_type: FILTER_HAS_TAG, value: object.id.toString()}
+ ]
+ this.router.navigate(["documents"])
+ }
}
diff --git a/src-ui/src/app/interceptors/csrf.interceptor.ts b/src-ui/src/app/interceptors/csrf.interceptor.ts
index 32f3e99dc..2c654aa36 100644
--- a/src-ui/src/app/interceptors/csrf.interceptor.ts
+++ b/src-ui/src/app/interceptors/csrf.interceptor.ts
@@ -7,16 +7,21 @@ import {
} from '@angular/common/http';
import { Observable } from 'rxjs';
import { CookieService } from 'ngx-cookie-service';
+import { Meta } from '@angular/platform-browser';
@Injectable()
export class CsrfInterceptor implements HttpInterceptor {
- constructor(private cookieService: CookieService) {
+ constructor(private cookieService: CookieService, private meta: Meta) {
}
intercept(request: HttpRequest<unknown>, next: HttpHandler): Observable<HttpEvent<unknown>> {
- let csrfToken = this.cookieService.get('csrftoken')
+ let prefix = ""
+ if (this.meta.getTag('name=cookie_prefix')) {
+ prefix = this.meta.getTag('name=cookie_prefix').content
+ }
+ let csrfToken = this.cookieService.get(`${prefix?prefix:''}csrftoken`)
if (csrfToken) {
request = request.clone({
setHeaders: {
diff --git a/src-ui/src/app/pipes/document-title.pipe.ts b/src-ui/src/app/pipes/document-title.pipe.ts
index 09445f595..621562d39 100644
--- a/src-ui/src/app/pipes/document-title.pipe.ts
+++ b/src-ui/src/app/pipes/document-title.pipe.ts
@@ -5,7 +5,7 @@ import { Pipe, PipeTransform } from '@angular/core';
})
export class DocumentTitlePipe implements PipeTransform {
- transform(value: string): unknown {
+ transform(value: string): string {
if (value) {
return value
} else {
diff --git a/src-ui/src/app/services/document-list-view.service.ts b/src-ui/src/app/services/document-list-view.service.ts
index 05c46750d..00f84048b 100644
--- a/src-ui/src/app/services/document-list-view.service.ts
+++ b/src-ui/src/app/services/document-list-view.service.ts
@@ -116,14 +116,14 @@ export class DocumentListViewService {
set filterRules(filterRules: FilterRule[]) {
//we're going to clone the filterRules object, since we don't
//want changes in the filter editor to propagate into here right away.
- this.view.filter_rules = cloneFilterRules(filterRules)
+ this.view.filter_rules = filterRules
this.reload()
this.reduceSelectionToFilter()
this.saveDocumentListView()
}
get filterRules(): FilterRule[] {
- return cloneFilterRules(this.view.filter_rules)
+ return this.view.filter_rules
}
set sortField(field: string) {
@@ -245,7 +245,7 @@ export class DocumentListViewService {
this.documentListView = null
}
}
- if (!this.documentListView) {
+ if (!this.documentListView || !this.documentListView.filter_rules || !this.documentListView.sort_reverse || !this.documentListView.sort_field) {
this.documentListView = {
filter_rules: [],
sort_reverse: true,
diff --git a/src-ui/src/assets/save-filter.png b/src-ui/src/assets/save-filter.png
index dcaa41714..0f011f812 100644
Binary files a/src-ui/src/assets/save-filter.png and b/src-ui/src/assets/save-filter.png differ
diff --git a/src-ui/src/environments/environment.prod.ts b/src-ui/src/environments/environment.prod.ts
index 09154dfca..f12c6a7cb 100644
--- a/src-ui/src/environments/environment.prod.ts
+++ b/src-ui/src/environments/environment.prod.ts
@@ -1,5 +1,6 @@
export const environment = {
production: true,
apiBaseUrl: "/api/",
- appTitle: "Paperless-ng"
+ appTitle: "Paperless-ng",
+ version: "0.9.8"
};
diff --git a/src-ui/src/styles.scss b/src-ui/src/styles.scss
index b0b66b7f9..6e09db630 100644
--- a/src-ui/src/styles.scss
+++ b/src-ui/src/styles.scss
@@ -1,7 +1,6 @@
@import "theme";
-
@import "node_modules/bootstrap/scss/bootstrap";
-
+@import "~@ng-select/ng-select/themes/default.theme.css";
.toolbaricon {
width: 1.2em;
@@ -20,7 +19,7 @@
}
body {
- font-size: .875rem;
+ font-size: 0.875rem;
}
.form-control-dark {
@@ -65,4 +64,39 @@ body {
display: block;
background-size: 1rem;
float: right;
-}
\ No newline at end of file
+}
+
+.paperless-input-select {
+ .ng-select {
+ position: relative;
+ flex: 1 1 auto;
+ margin-bottom: 0;
+ min-height: calc(1.5em + 0.75rem + 5px);
+ line-height: 1.5;
+
+ .ng-select-container {
+ height: 100%;
+ border-top-right-radius: 0;
+ border-bottom-right-radius: 0;
+
+ .ng-value-container .ng-input {
+ top: 10px;
+ }
+ }
+
+ .ng-dropdown-panel .ng-dropdown-panel-items .ng-option.ng-option-selected,
+ .ng-dropdown-panel .ng-dropdown-panel-items .ng-option.ng-option-selected.ng-option-marked {
+ background: none;
+ }
+ }
+}
+
+.paperless-input-tags {
+ .ng-select.ng-select-multiple .ng-select-container .ng-value-container .ng-value {
+ background-color: transparent;
+ }
+
+ .ng-select.ng-select-multiple .ng-select-container .ng-value-container {
+ padding-top: 1px;
+ }
+}
diff --git a/src/documents/admin.py b/src/documents/admin.py
index 6ec3b736e..78437f91c 100755
--- a/src/documents/admin.py
+++ b/src/documents/admin.py
@@ -69,7 +69,7 @@ class DocumentAdmin(admin.ModelAdmin):
filter_horizontal = ("tags",)
- ordering = ["-created", "correspondent"]
+ ordering = ["-created"]
date_hierarchy = "created"
diff --git a/src/documents/checks.py b/src/documents/checks.py
index 3e3ddb1fb..b6da5bfc9 100644
--- a/src/documents/checks.py
+++ b/src/documents/checks.py
@@ -2,6 +2,7 @@ import textwrap
from django.conf import settings
from django.core.checks import Error, register
+from django.core.exceptions import FieldError
from django.db.utils import OperationalError, ProgrammingError
from documents.signals import document_consumer_declaration
@@ -16,7 +17,7 @@ def changed_password_check(app_configs, **kwargs):
try:
encrypted_doc = Document.objects.filter(
storage_type=Document.STORAGE_TYPE_GPG).first()
- except (OperationalError, ProgrammingError):
+ except (OperationalError, ProgrammingError, FieldError):
return [] # No documents table yet
if encrypted_doc:
diff --git a/src/documents/file_handling.py b/src/documents/file_handling.py
index c49493991..5643756ac 100644
--- a/src/documents/file_handling.py
+++ b/src/documents/file_handling.py
@@ -99,6 +99,11 @@ def generate_filename(doc, counter=0):
tags = defaultdictNoStr(lambda: slugify(None),
many_to_dictionary(doc.tags))
+ tag_list = pathvalidate.sanitize_filename(
+ ",".join([tag.name for tag in doc.tags.all()]),
+ replacement_text="-"
+ )
+
if doc.correspondent:
correspondent = pathvalidate.sanitize_filename(
doc.correspondent.name, replacement_text="-"
@@ -127,7 +132,7 @@ def generate_filename(doc, counter=0):
added_month=f"{doc.added.month:02}" if doc.added else "none",
added_day=f"{doc.added.day:02}" if doc.added else "none",
tags=tags,
- tag_list=",".join([tag.name for tag in doc.tags.all()])
+ tag_list=tag_list
).strip()
path = path.strip(os.sep)
diff --git a/src/documents/management/commands/decrypt_documents.py b/src/documents/management/commands/decrypt_documents.py
index 918f1a175..8f5c2e123 100644
--- a/src/documents/management/commands/decrypt_documents.py
+++ b/src/documents/management/commands/decrypt_documents.py
@@ -2,7 +2,6 @@ import os
from django.conf import settings
from django.core.management.base import BaseCommand, CommandError
-from termcolor import colored as coloured
from documents.models import Document
from paperless.db import GnuPG
@@ -26,16 +25,14 @@ class Command(BaseCommand):
def handle(self, *args, **options):
try:
- print(coloured(
+ print(
"\n\nWARNING: This script is going to work directly on your "
"document originals, so\nWARNING: you probably shouldn't run "
"this unless you've got a recent backup\nWARNING: handy. It "
"*should* work without a hitch, but be safe and backup your\n"
"WARNING: stuff first.\n\nHit Ctrl+C to exit now, or Enter to "
- "continue.\n\n",
- "yellow",
- attrs=("bold",)
- ))
+ "continue.\n\n"
+ )
__ = input()
except KeyboardInterrupt:
return
@@ -57,8 +54,8 @@ class Command(BaseCommand):
for document in encrypted_files:
- print(coloured("Decrypting {}".format(
- document).encode('utf-8'), "green"))
+ print("Decrypting {}".format(
+ document).encode('utf-8'))
old_paths = [document.source_path, document.thumbnail_path]
diff --git a/src/documents/migrations/1003_mime_types.py b/src/documents/migrations/1003_mime_types.py
index 1038d57b3..78ecced2b 100644
--- a/src/documents/migrations/1003_mime_types.py
+++ b/src/documents/migrations/1003_mime_types.py
@@ -6,13 +6,17 @@ import magic
from django.conf import settings
from django.db import migrations, models
+from paperless.db import GnuPG
+
+STORAGE_TYPE_UNENCRYPTED = "unencrypted"
+STORAGE_TYPE_GPG = "gpg"
def source_path(self):
if self.filename:
fname = str(self.filename)
else:
fname = "{:07}.{}".format(self.pk, self.file_type)
- if self.storage_type == self.STORAGE_TYPE_GPG:
+ if self.storage_type == STORAGE_TYPE_GPG:
fname += ".gpg"
return os.path.join(
@@ -26,9 +30,18 @@ def add_mime_types(apps, schema_editor):
documents = Document.objects.all()
for d in documents:
- d.mime_type = magic.from_file(source_path(d), mime=True)
+ f = open(source_path(d), "rb")
+ if d.storage_type == STORAGE_TYPE_GPG:
+
+ data = GnuPG.decrypted(f)
+ else:
+ data = f.read(1024)
+
+ d.mime_type = magic.from_buffer(data, mime=True)
d.save()
+ f.close()
+
def add_file_extensions(apps, schema_editor):
Document = apps.get_model("documents", "Document")
diff --git a/src/documents/migrations/1008_auto_20201216_1736.py b/src/documents/migrations/1008_auto_20201216_1736.py
new file mode 100644
index 000000000..d94f4767f
--- /dev/null
+++ b/src/documents/migrations/1008_auto_20201216_1736.py
@@ -0,0 +1,34 @@
+# Generated by Django 3.1.4 on 2020-12-16 17:36
+
+from django.db import migrations
+import django.db.models.functions.text
+
+
+class Migration(migrations.Migration):
+
+ dependencies = [
+ ('documents', '1007_savedview_savedviewfilterrule'),
+ ]
+
+ operations = [
+ migrations.AlterModelOptions(
+ name='correspondent',
+ options={'ordering': (django.db.models.functions.text.Lower('name'),)},
+ ),
+ migrations.AlterModelOptions(
+ name='document',
+ options={'ordering': ('-created',)},
+ ),
+ migrations.AlterModelOptions(
+ name='documenttype',
+ options={'ordering': (django.db.models.functions.text.Lower('name'),)},
+ ),
+ migrations.AlterModelOptions(
+ name='savedview',
+ options={'ordering': (django.db.models.functions.text.Lower('name'),)},
+ ),
+ migrations.AlterModelOptions(
+ name='tag',
+ options={'ordering': (django.db.models.functions.text.Lower('name'),)},
+ ),
+ ]
diff --git a/src/documents/migrations/1009_auto_20201216_2005.py b/src/documents/migrations/1009_auto_20201216_2005.py
new file mode 100644
index 000000000..5e8302bb0
--- /dev/null
+++ b/src/documents/migrations/1009_auto_20201216_2005.py
@@ -0,0 +1,29 @@
+# Generated by Django 3.1.4 on 2020-12-16 20:05
+
+from django.db import migrations
+
+
+class Migration(migrations.Migration):
+
+ dependencies = [
+ ('documents', '1008_auto_20201216_1736'),
+ ]
+
+ operations = [
+ migrations.AlterModelOptions(
+ name='correspondent',
+ options={'ordering': ('name',)},
+ ),
+ migrations.AlterModelOptions(
+ name='documenttype',
+ options={'ordering': ('name',)},
+ ),
+ migrations.AlterModelOptions(
+ name='savedview',
+ options={'ordering': ('name',)},
+ ),
+ migrations.AlterModelOptions(
+ name='tag',
+ options={'ordering': ('name',)},
+ ),
+ ]
diff --git a/src/documents/models.py b/src/documents/models.py
index 1b1f697bc..3a6d155ed 100755
--- a/src/documents/models.py
+++ b/src/documents/models.py
@@ -12,7 +12,6 @@ from django.conf import settings
from django.contrib.auth.models import User
from django.db import models
from django.utils import timezone
-from django.utils.text import slugify
from documents.file_handling import archive_name_from_filename
from documents.parsers import get_default_file_extension
@@ -205,7 +204,7 @@ class Document(models.Model):
)
class Meta:
- ordering = ("correspondent", "title")
+ ordering = ("-created",)
def __str__(self):
created = datetime.date.isoformat(self.created)
@@ -221,7 +220,7 @@ class Document(models.Model):
else:
fname = "{:07}{}".format(self.pk, self.file_type)
if self.storage_type == self.STORAGE_TYPE_GPG:
- fname += ".gpg"
+ fname += ".gpg" # pragma: no cover
return os.path.join(
settings.ORIGINALS_DIR,
@@ -308,6 +307,10 @@ class Log(models.Model):
class SavedView(models.Model):
+ class Meta:
+
+ ordering = ("name",)
+
user = models.ForeignKey(User, on_delete=models.CASCADE)
name = models.CharField(max_length=128)
@@ -340,7 +343,11 @@ class SavedViewFilterRule(models.Model):
(17, "Does not have tag"),
]
- saved_view = models.ForeignKey(SavedView, on_delete=models.CASCADE, related_name="filter_rules")
+ saved_view = models.ForeignKey(
+ SavedView,
+ on_delete=models.CASCADE,
+ related_name="filter_rules"
+ )
rule_type = models.PositiveIntegerField(choices=RULE_TYPES)
diff --git a/src/documents/parsers.py b/src/documents/parsers.py
index 228e2c86e..cbbb912de 100644
--- a/src/documents/parsers.py
+++ b/src/documents/parsers.py
@@ -163,8 +163,6 @@ def parse_date(filename, text):
date = None
- next_year = timezone.now().year + 5 # Arbitrary 5 year future limit
-
# if filename date parsing is enabled, search there first:
if settings.FILENAME_DATE_ORDER:
for m in re.finditer(DATE_REGEX, filename):
@@ -176,7 +174,7 @@ def parse_date(filename, text):
# Skip all matches that do not parse to a proper date
continue
- if date is not None and next_year > date.year > 1900:
+ if date and date.year > 1900 and date <= timezone.now():
return date
# Iterate through all regex matches in text and try to parse the date
@@ -189,7 +187,7 @@ def parse_date(filename, text):
# Skip all matches that do not parse to a proper date
continue
- if date is not None and next_year > date.year > 1900:
+ if date and date.year > 1900 and date <= timezone.now():
break
else:
date = None
diff --git a/src/documents/serialisers.py b/src/documents/serialisers.py
index e34279b1a..f9fde9ac8 100644
--- a/src/documents/serialisers.py
+++ b/src/documents/serialisers.py
@@ -187,17 +187,19 @@ class SavedViewSerializer(serializers.ModelSerializer):
else:
rules_data = None
super(SavedViewSerializer, self).update(instance, validated_data)
- if rules_data:
+ if rules_data is not None:
SavedViewFilterRule.objects.filter(saved_view=instance).delete()
for rule_data in rules_data:
- SavedViewFilterRule.objects.create(saved_view=instance, **rule_data)
+ SavedViewFilterRule.objects.create(
+ saved_view=instance, **rule_data)
return instance
def create(self, validated_data):
rules_data = validated_data.pop('filter_rules')
saved_view = SavedView.objects.create(**validated_data)
for rule_data in rules_data:
- SavedViewFilterRule.objects.create(saved_view=saved_view, **rule_data)
+ SavedViewFilterRule.objects.create(
+ saved_view=saved_view, **rule_data)
return saved_view
diff --git a/src/documents/templates/index.html b/src/documents/templates/index.html
index 728f3a0e7..06dbb678e 100644
--- a/src/documents/templates/index.html
+++ b/src/documents/templates/index.html
@@ -8,6 +8,7 @@
<title>PaperlessUi</title>
<base href="/">
<meta name="viewport" content="width=device-width, initial-scale=1">
+ <meta name="cookie_prefix" content="{{cookie_prefix}}">
<link rel="icon" type="image/x-icon" href="favicon.ico">
<link rel="stylesheet" href="{% static 'frontend/styles.css' %}"></head>
<body>
diff --git a/src/documents/tests/test_api.py b/src/documents/tests/test_api.py
index bd0d9a421..43da9c058 100644
--- a/src/documents/tests/test_api.py
+++ b/src/documents/tests/test_api.py
@@ -5,13 +5,11 @@ import tempfile
from unittest import mock
from django.contrib.auth.models import User
-from django.test import client
-from pathvalidate import ValidationError
from rest_framework.test import APITestCase
from whoosh.writing import AsyncWriter
-from documents import index, bulk_edit
-from documents.models import Document, Correspondent, DocumentType, Tag
+from documents import index
+from documents.models import Document, Correspondent, DocumentType, Tag, SavedView
from documents.tests.utils import DirectoriesMixin
@@ -20,8 +18,8 @@ class TestDocumentApi(DirectoriesMixin, APITestCase):
def setUp(self):
super(TestDocumentApi, self).setUp()
- user = User.objects.create_superuser(username="temp_admin")
- self.client.force_login(user=user)
+ self.user = User.objects.create_superuser(username="temp_admin")
+ self.client.force_login(user=self.user)
def testDocuments(self):
@@ -172,15 +170,13 @@ class TestDocumentApi(DirectoriesMixin, APITestCase):
self.assertEqual(response.status_code, 200)
results = response.data['results']
self.assertEqual(len(results), 2)
- self.assertEqual(results[0]['id'], doc2.id)
- self.assertEqual(results[1]['id'], doc3.id)
+ self.assertCountEqual([results[0]['id'], results[1]['id']], [doc2.id, doc3.id])
response = self.client.get("/api/documents/?tags__id__in={},{}".format(tag_inbox.id, tag_3.id))
self.assertEqual(response.status_code, 200)
results = response.data['results']
self.assertEqual(len(results), 2)
- self.assertEqual(results[0]['id'], doc1.id)
- self.assertEqual(results[1]['id'], doc3.id)
+ self.assertCountEqual([results[0]['id'], results[1]['id']], [doc1.id, doc3.id])
response = self.client.get("/api/documents/?tags__id__all={},{}".format(tag_2.id, tag_3.id))
self.assertEqual(response.status_code, 200)
@@ -202,8 +198,7 @@ class TestDocumentApi(DirectoriesMixin, APITestCase):
self.assertEqual(response.status_code, 200)
results = response.data['results']
self.assertEqual(len(results), 2)
- self.assertEqual(results[0]['id'], doc1.id)
- self.assertEqual(results[1]['id'], doc2.id)
+ self.assertCountEqual([results[0]['id'], results[1]['id']], [doc1.id, doc2.id])
response = self.client.get("/api/documents/?tags__id__none={},{}".format(tag_3.id, tag_2.id))
self.assertEqual(response.status_code, 200)
@@ -518,114 +513,86 @@ class TestDocumentApi(DirectoriesMixin, APITestCase):
self.assertGreater(len(meta['original_metadata']), 0)
self.assertIsNone(meta['archive_metadata'])
+ def test_saved_views(self):
+ u1 = User.objects.create_user("user1")
+ u2 = User.objects.create_user("user2")
-class TestBulkEdit(DirectoriesMixin, APITestCase):
+ v1 = SavedView.objects.create(user=u1, name="test1", sort_field="", show_on_dashboard=False, show_in_sidebar=False)
+ v2 = SavedView.objects.create(user=u2, name="test2", sort_field="", show_on_dashboard=False, show_in_sidebar=False)
+ v3 = SavedView.objects.create(user=u2, name="test3", sort_field="", show_on_dashboard=False, show_in_sidebar=False)
- def setUp(self):
- super(TestBulkEdit, self).setUp()
-
- user = User.objects.create_superuser(username="temp_admin")
- self.client.force_login(user=user)
-
- patcher = mock.patch('documents.bulk_edit.async_task')
- self.async_task = patcher.start()
- self.addCleanup(patcher.stop)
- self.c1 = Correspondent.objects.create(name="c1")
- self.c2 = Correspondent.objects.create(name="c2")
- self.dt1 = DocumentType.objects.create(name="dt1")
- self.dt2 = DocumentType.objects.create(name="dt2")
- self.t1 = Tag.objects.create(name="t1")
- self.t2 = Tag.objects.create(name="t2")
- self.doc1 = Document.objects.create(checksum="A", title="A")
- self.doc2 = Document.objects.create(checksum="B", title="B", correspondent=self.c1, document_type=self.dt1)
- self.doc3 = Document.objects.create(checksum="C", title="C", correspondent=self.c2, document_type=self.dt2)
- self.doc4 = Document.objects.create(checksum="D", title="D")
- self.doc5 = Document.objects.create(checksum="E", title="E")
- self.doc2.tags.add(self.t1)
- self.doc3.tags.add(self.t2)
- self.doc4.tags.add(self.t1, self.t2)
-
- def test_set_correspondent(self):
- self.assertEqual(Document.objects.filter(correspondent=self.c2).count(), 1)
- bulk_edit.set_correspondent([self.doc1.id, self.doc2.id, self.doc3.id], self.c2.id)
- self.assertEqual(Document.objects.filter(correspondent=self.c2).count(), 3)
- self.async_task.assert_called_once()
- args, kwargs = self.async_task.call_args
- self.assertCountEqual(kwargs['document_ids'], [self.doc1.id, self.doc2.id])
-
- def test_unset_correspondent(self):
- self.assertEqual(Document.objects.filter(correspondent=self.c2).count(), 1)
- bulk_edit.set_correspondent([self.doc1.id, self.doc2.id, self.doc3.id], None)
- self.assertEqual(Document.objects.filter(correspondent=self.c2).count(), 0)
- self.async_task.assert_called_once()
- args, kwargs = self.async_task.call_args
- self.assertCountEqual(kwargs['document_ids'], [self.doc2.id, self.doc3.id])
-
- def test_set_document_type(self):
- self.assertEqual(Document.objects.filter(document_type=self.dt2).count(), 1)
- bulk_edit.set_document_type([self.doc1.id, self.doc2.id, self.doc3.id], self.dt2.id)
- self.assertEqual(Document.objects.filter(document_type=self.dt2).count(), 3)
- self.async_task.assert_called_once()
- args, kwargs = self.async_task.call_args
- self.assertCountEqual(kwargs['document_ids'], [self.doc1.id, self.doc2.id])
-
- def test_unset_document_type(self):
- self.assertEqual(Document.objects.filter(document_type=self.dt2).count(), 1)
- bulk_edit.set_document_type([self.doc1.id, self.doc2.id, self.doc3.id], None)
- self.assertEqual(Document.objects.filter(document_type=self.dt2).count(), 0)
- self.async_task.assert_called_once()
- args, kwargs = self.async_task.call_args
- self.assertCountEqual(kwargs['document_ids'], [self.doc2.id, self.doc3.id])
-
- def test_add_tag(self):
- self.assertEqual(Document.objects.filter(tags__id=self.t1.id).count(), 2)
- bulk_edit.add_tag([self.doc1.id, self.doc2.id, self.doc3.id, self.doc4.id], self.t1.id)
- self.assertEqual(Document.objects.filter(tags__id=self.t1.id).count(), 4)
- self.async_task.assert_called_once()
- args, kwargs = self.async_task.call_args
- self.assertCountEqual(kwargs['document_ids'], [self.doc1.id, self.doc3.id])
-
-
- def test_remove_tag(self):
- self.assertEqual(Document.objects.filter(tags__id=self.t1.id).count(), 2)
- bulk_edit.remove_tag([self.doc1.id, self.doc3.id, self.doc4.id], self.t1.id)
- self.assertEqual(Document.objects.filter(tags__id=self.t1.id).count(), 1)
- self.async_task.assert_called_once()
- args, kwargs = self.async_task.call_args
- self.assertCountEqual(kwargs['document_ids'], [self.doc4.id])
-
- def test_delete(self):
- self.assertEqual(Document.objects.count(), 5)
- bulk_edit.delete([self.doc1.id, self.doc2.id])
- self.assertEqual(Document.objects.count(), 3)
- self.assertCountEqual([doc.id for doc in Document.objects.all()], [self.doc3.id, self.doc4.id, self.doc5.id])
-
- def test_api(self):
- self.assertEqual(Document.objects.count(), 5)
- response = self.client.post("/api/documents/bulk_edit/", json.dumps({
- "documents": [self.doc1.id],
- "method": "delete",
- "parameters": {}
- }), content_type='application/json')
- self.assertEqual(response.status_code, 200)
- self.assertEqual(Document.objects.count(), 4)
-
- def test_api_invalid_doc(self):
- self.assertEqual(Document.objects.count(), 5)
- response = self.client.post("/api/documents/bulk_edit/", json.dumps({
- "documents": [-235],
- "method": "delete",
- "parameters": {}
- }), content_type='application/json')
- self.assertEqual(response.status_code, 400)
- self.assertEqual(Document.objects.count(), 5)
-
- def test_api_invalid_method(self):
- self.assertEqual(Document.objects.count(), 5)
- response = self.client.post("/api/documents/bulk_edit/", json.dumps({
- "documents": [self.doc2.id],
- "method": "exterminate",
- "parameters": {}
- }), content_type='application/json')
- self.assertEqual(response.status_code, 400)
- self.assertEqual(Document.objects.count(), 5)
+ response = self.client.get("/api/saved_views/")
+ self.assertEqual(response.status_code, 200)
+ self.assertEqual(response.data['count'], 0)
+
+ self.assertEqual(self.client.get(f"/api/saved_views/{v1.id}/").status_code, 404)
+
+ self.client.force_login(user=u1)
+
+ response = self.client.get("/api/saved_views/")
+ self.assertEqual(response.status_code, 200)
+ self.assertEqual(response.data['count'], 1)
+
+ self.assertEqual(self.client.get(f"/api/saved_views/{v1.id}/").status_code, 200)
+
+ self.client.force_login(user=u2)
+
+ response = self.client.get("/api/saved_views/")
+ self.assertEqual(response.status_code, 200)
+ self.assertEqual(response.data['count'], 2)
+
+ self.assertEqual(self.client.get(f"/api/saved_views/{v1.id}/").status_code, 404)
+
+ def test_create_update_patch(self):
+
+ u1 = User.objects.create_user("user1")
+
+ view = {
+ "name": "test",
+ "show_on_dashboard": True,
+ "show_in_sidebar": True,
+ "sort_field": "created2",
+ "filter_rules": [
+ {
+ "rule_type": 4,
+ "value": "test"
+ }
+ ]
+ }
+
+ response = self.client.post("/api/saved_views/", view, format='json')
+ self.assertEqual(response.status_code, 201)
+
+ v1 = SavedView.objects.get(name="test")
+ self.assertEqual(v1.sort_field, "created2")
+ self.assertEqual(v1.filter_rules.count(), 1)
+ self.assertEqual(v1.user, self.user)
+
+ response = self.client.patch(f"/api/saved_views/{v1.id}/", {
+ "show_in_sidebar": False
+ }, format='json')
+
+ v1 = SavedView.objects.get(id=v1.id)
+ self.assertEqual(response.status_code, 200)
+ self.assertFalse(v1.show_in_sidebar)
+ self.assertEqual(v1.filter_rules.count(), 1)
+
+ view['filter_rules'] = [{
+ "rule_type": 12,
+ "value": "secret"
+ }]
+
+ response = self.client.put(f"/api/saved_views/{v1.id}/", view, format='json')
+ self.assertEqual(response.status_code, 200)
+
+ v1 = SavedView.objects.get(id=v1.id)
+ self.assertEqual(v1.filter_rules.count(), 1)
+ self.assertEqual(v1.filter_rules.first().value, "secret")
+
+ view['filter_rules'] = []
+
+ response = self.client.put(f"/api/saved_views/{v1.id}/", view, format='json')
+ self.assertEqual(response.status_code, 200)
+
+ v1 = SavedView.objects.get(id=v1.id)
+ self.assertEqual(v1.filter_rules.count(), 0)
diff --git a/src/documents/tests/test_file_handling.py b/src/documents/tests/test_file_handling.py
index dec89c45b..2e60065f1 100644
--- a/src/documents/tests/test_file_handling.py
+++ b/src/documents/tests/test_file_handling.py
@@ -9,6 +9,7 @@ from unittest import mock
from django.conf import settings
from django.db import DatabaseError
from django.test import TestCase, override_settings
+from django.utils import timezone
from .utils import DirectoriesMixin
from ..file_handling import generate_filename, create_source_path_directory, delete_empty_directories, \
@@ -298,23 +299,23 @@ class TestFileHandling(DirectoriesMixin, TestCase):
@override_settings(PAPERLESS_FILENAME_FORMAT="{created_year}-{created_month}-{created_day}")
def test_created_year_month_day(self):
- d1 = datetime.datetime(2020, 3, 6, 1, 1, 1)
+ d1 = timezone.make_aware(datetime.datetime(2020, 3, 6, 1, 1, 1))
doc1 = Document.objects.create(title="doc1", mime_type="application/pdf", created=d1)
self.assertEqual(generate_filename(doc1), "2020-03-06.pdf")
- doc1.created = datetime.datetime(2020, 11, 16, 1, 1, 1)
+ doc1.created = timezone.make_aware(datetime.datetime(2020, 11, 16, 1, 1, 1))
self.assertEqual(generate_filename(doc1), "2020-11-16.pdf")
@override_settings(PAPERLESS_FILENAME_FORMAT="{added_year}-{added_month}-{added_day}")
def test_added_year_month_day(self):
- d1 = datetime.datetime(232, 1, 9, 1, 1, 1)
+ d1 = timezone.make_aware(datetime.datetime(232, 1, 9, 1, 1, 1))
doc1 = Document.objects.create(title="doc1", mime_type="application/pdf", added=d1)
self.assertEqual(generate_filename(doc1), "232-01-09.pdf")
- doc1.added = datetime.datetime(2020, 11, 16, 1, 1, 1)
+ doc1.added = timezone.make_aware(datetime.datetime(2020, 11, 16, 1, 1, 1))
self.assertEqual(generate_filename(doc1), "2020-11-16.pdf")
@@ -599,7 +600,7 @@ class TestFilenameGeneration(TestCase):
PAPERLESS_FILENAME_FORMAT="{created}"
)
def test_date(self):
- doc = Document.objects.create(title="does not matter", created=datetime.datetime(2020,5,21, 7,36,51, 153), mime_type="application/pdf", pk=2, checksum="2")
+ doc = Document.objects.create(title="does not matter", created=timezone.make_aware(datetime.datetime(2020,5,21, 7,36,51, 153)), mime_type="application/pdf", pk=2, checksum="2")
self.assertEqual(generate_filename(doc), "2020-05-21.pdf")
diff --git a/src/documents/tests/test_index.py b/src/documents/tests/test_index.py
index 830fca0e0..2baa9621d 100644
--- a/src/documents/tests/test_index.py
+++ b/src/documents/tests/test_index.py
@@ -1,6 +1,9 @@
from django.test import TestCase
+from documents import index
from documents.index import JsonFormatter
+from documents.models import Document
+from documents.tests.utils import DirectoriesMixin
class JsonFormatterTest(TestCase):
@@ -12,3 +15,21 @@ class JsonFormatterTest(TestCase):
self.assertListEqual(self.formatter.format([]), [])
+class TestAutoComplete(DirectoriesMixin, TestCase):
+
+ def test_auto_complete(self):
+
+ doc1 = Document.objects.create(title="doc1", checksum="A", content="test test2 test3")
+ doc2 = Document.objects.create(title="doc2", checksum="B", content="test test2")
+ doc3 = Document.objects.create(title="doc3", checksum="C", content="test2")
+
+ index.add_or_update_document(doc1)
+ index.add_or_update_document(doc2)
+ index.add_or_update_document(doc3)
+
+ ix = index.open_index()
+
+ self.assertListEqual(index.autocomplete(ix, "tes"), [b"test3", b"test", b"test2"])
+ self.assertListEqual(index.autocomplete(ix, "tes", limit=3), [b"test3", b"test", b"test2"])
+ self.assertListEqual(index.autocomplete(ix, "tes", limit=1), [b"test3"])
+ self.assertListEqual(index.autocomplete(ix, "tes", limit=0), [])
diff --git a/src/documents/tests/test_sanity_check.py b/src/documents/tests/test_sanity_check.py
index 725e87617..0554cd7cd 100644
--- a/src/documents/tests/test_sanity_check.py
+++ b/src/documents/tests/test_sanity_check.py
@@ -2,6 +2,8 @@ import os
import shutil
from pathlib import Path
+import filelock
+from django.conf import settings
from django.test import TestCase
from documents.models import Document
@@ -13,9 +15,11 @@ class TestSanityCheck(DirectoriesMixin, TestCase):
def make_test_data(self):
- shutil.copy(os.path.join(os.path.dirname(__file__), "samples", "documents", "originals", "0000001.pdf"), os.path.join(self.dirs.originals_dir, "0000001.pdf"))
- shutil.copy(os.path.join(os.path.dirname(__file__), "samples", "documents", "archive", "0000001.pdf"), os.path.join(self.dirs.archive_dir, "0000001.pdf"))
- shutil.copy(os.path.join(os.path.dirname(__file__), "samples", "documents", "thumbnails", "0000001.png"), os.path.join(self.dirs.thumbnail_dir, "0000001.png"))
+ with filelock.FileLock(settings.MEDIA_LOCK):
+ # just make sure that the lockfile is present.
+ shutil.copy(os.path.join(os.path.dirname(__file__), "samples", "documents", "originals", "0000001.pdf"), os.path.join(self.dirs.originals_dir, "0000001.pdf"))
+ shutil.copy(os.path.join(os.path.dirname(__file__), "samples", "documents", "archive", "0000001.pdf"), os.path.join(self.dirs.archive_dir, "0000001.pdf"))
+ shutil.copy(os.path.join(os.path.dirname(__file__), "samples", "documents", "thumbnails", "0000001.png"), os.path.join(self.dirs.thumbnail_dir, "0000001.png"))
return Document.objects.create(title="test", checksum="42995833e01aea9b3edee44bbfdd7ce1", archive_checksum="62acb0bcbfbcaa62ca6ad3668e4e404b", content="test", pk=1, filename="0000001.pdf", mime_type="application/pdf")
diff --git a/src/documents/tests/utils.py b/src/documents/tests/utils.py
index 7f9d50ed5..dfefc4061 100644
--- a/src/documents/tests/utils.py
+++ b/src/documents/tests/utils.py
@@ -34,7 +34,8 @@ def setup_directories():
ARCHIVE_DIR=dirs.archive_dir,
CONSUMPTION_DIR=dirs.consumption_dir,
INDEX_DIR=dirs.index_dir,
- MODEL_FILE=os.path.join(dirs.data_dir, "classification_model.pickle")
+ MODEL_FILE=os.path.join(dirs.data_dir, "classification_model.pickle"),
+ MEDIA_LOCK=os.path.join(dirs.media_dir, "media.lock")
)
dirs.settings_override.enable()
diff --git a/src/documents/views.py b/src/documents/views.py
index 3924f3d1a..ebe41c9d1 100755
--- a/src/documents/views.py
+++ b/src/documents/views.py
@@ -55,6 +55,11 @@ from .serialisers import (
class IndexView(TemplateView):
template_name = "index.html"
+ def get_context_data(self, **kwargs):
+ context = super().get_context_data(**kwargs)
+ context['cookie_prefix'] = settings.COOKIE_PREFIX
+ return context
+
class CorrespondentViewSet(ModelViewSet):
model = Correspondent
@@ -185,7 +190,12 @@ class DocumentViewSet(RetrieveModelMixin,
parser_class = get_parser_class_for_mime_type(mime_type)
if parser_class:
parser = parser_class(logging_group=None)
- return parser.extract_metadata(file, mime_type)
+
+ try:
+ return parser.extract_metadata(file, mime_type)
+ except Exception as e:
+ # TODO: cover GPG errors, remove later.
+ return []
else:
return []
@@ -231,7 +241,12 @@ class DocumentViewSet(RetrieveModelMixin,
@cache_control(public=False, max_age=315360000)
def thumb(self, request, pk=None):
try:
- return HttpResponse(Document.objects.get(id=pk).thumbnail_file,
+ doc = Document.objects.get(id=pk)
+ if doc.storage_type == Document.STORAGE_TYPE_GPG:
+ handle = GnuPG.decrypted(doc.thumbnail_file)
+ else:
+ handle = doc.thumbnail_file
+ return HttpResponse(handle,
content_type='image/png')
except (FileNotFoundError, Document.DoesNotExist):
raise Http404()
diff --git a/src/paperless/version.py b/src/paperless/version.py
index 527e0668d..10283c145 100644
--- a/src/paperless/version.py
+++ b/src/paperless/version.py
@@ -1 +1 @@
-__version__ = (0, 9, 6)
+__version__ = (0, 9, 8)
diff --git a/src/paperless_mail/mail.py b/src/paperless_mail/mail.py
index a82c34f15..3c200362d 100644
--- a/src/paperless_mail/mail.py
+++ b/src/paperless_mail/mail.py
@@ -26,7 +26,7 @@ class BaseMailAction:
return {}
def post_consume(self, M, message_uids, parameter):
- pass
+ pass # pragma: nocover
class DeleteMailAction(BaseMailAction):
@@ -69,7 +69,7 @@ def get_rule_action(rule):
elif rule.action == MailRule.ACTION_MARK_READ:
return MarkReadMailAction()
else:
- raise ValueError("Unknown action.")
+ raise NotImplementedError("Unknown action.") # pragma: nocover
def make_criterias(rule):
@@ -95,7 +95,7 @@ def get_mailbox(server, port, security):
elif security == MailAccount.IMAP_SECURITY_SSL:
mailbox = MailBox(server, port)
else:
- raise ValueError("Unknown IMAP security")
+ raise NotImplementedError("Unknown IMAP security") # pragma: nocover
return mailbox
@@ -119,7 +119,7 @@ class MailAccountHandler(LoggingMixin):
return os.path.splitext(os.path.basename(att.filename))[0]
else:
- raise ValueError("Unknown title selector.")
+ raise NotImplementedError("Unknown title selector.") # pragma: nocover # NOQA: E501
def get_correspondent(self, message, rule):
c_from = rule.assign_correspondent_from
@@ -141,7 +141,7 @@ class MailAccountHandler(LoggingMixin):
return rule.assign_correspondent
else:
- raise ValueError("Unknwown correspondent selector")
+ raise NotImplementedError("Unknwown correspondent selector") # pragma: nocover # NOQA: E501
def handle_mail_account(self, account):
diff --git a/src/paperless_mail/tests/test_mail.py b/src/paperless_mail/tests/test_mail.py
index 2a391a268..9c0f52c53 100644
--- a/src/paperless_mail/tests/test_mail.py
+++ b/src/paperless_mail/tests/test_mail.py
@@ -399,7 +399,7 @@ class TestMail(TestCase):
c = Correspondent.objects.get(name="[email protected]")
# should work
- self.assertEquals(kwargs['override_correspondent_id'], c.id)
+ self.assertEqual(kwargs['override_correspondent_id'], c.id)
self.async_task.reset_mock()
self.reset_bogus_mailbox()
@@ -411,7 +411,7 @@ class TestMail(TestCase):
args, kwargs = self.async_task.call_args
self.async_task.assert_called_once()
- self.assertEquals(kwargs['override_correspondent_id'], None)
+ self.assertEqual(kwargs['override_correspondent_id'], None)
def test_filters(self):
diff --git a/src/paperless_text/parsers.py b/src/paperless_text/parsers.py
index f8f369ab0..7e488ca37 100644
--- a/src/paperless_text/parsers.py
+++ b/src/paperless_text/parsers.py
@@ -1,6 +1,7 @@
import os
import subprocess
+from PIL import ImageDraw, ImageFont, Image
from django.conf import settings
from documents.parsers import DocumentParser, ParseError
@@ -12,63 +13,22 @@ class TextDocumentParser(DocumentParser):
"""
def get_thumbnail(self, document_path, mime_type):
- """
- The thumbnail of a text file is just a 500px wide image of the text
- rendered onto a letter-sized page.
- """
- # The below is heavily cribbed from https://askubuntu.com/a/590951
-
- bg_color = "white" # bg color
- text_color = "black" # text color
- psize = [500, 647] # icon size
- n_lines = 50 # number of lines to show
- out_path = os.path.join(self.tempdir, "convert.png")
-
- temp_bg = os.path.join(self.tempdir, "bg.png")
- temp_txlayer = os.path.join(self.tempdir, "tx.png")
- picsize = "x".join([str(n) for n in psize])
- txsize = "x".join([str(n - 8) for n in psize])
-
- def create_bg():
- work_size = ",".join([str(n - 1) for n in psize])
- r = str(round(psize[0] / 10))
- rounded = ",".join([r, r])
- run_command(
- settings.CONVERT_BINARY,
- "-size ", picsize,
- ' xc:none -draw ',
- '"fill ', bg_color, ' roundrectangle 0,0,', work_size, ",", rounded, '" ', # NOQA: E501
- temp_bg
- )
def read_text():
with open(document_path, 'r') as src:
lines = [line.strip() for line in src.readlines()]
- text = "\n".join([line for line in lines[:n_lines]])
- return text.replace('"', "'")
-
- def create_txlayer():
- run_command(
- settings.CONVERT_BINARY,
- "-background none",
- "-fill",
- text_color,
- "-pointsize", "12",
- "-border 4 -bordercolor none",
- "-size ", txsize,
- ' caption:"', read_text(), '" ',
- temp_txlayer
- )
-
- create_txlayer()
- create_bg()
- run_command(
- settings.CONVERT_BINARY,
- temp_bg,
- temp_txlayer,
- "-background None -layers merge ",
- out_path
- )
+ text = "\n".join(lines[:50])
+ return text
+
+ img = Image.new("RGB", (500, 700), color="white")
+ draw = ImageDraw.Draw(img)
+ font = ImageFont.truetype(
+ "/usr/share/fonts/liberation/LiberationSerif-Regular.ttf", 20,
+ layout_engine=ImageFont.LAYOUT_BASIC)
+ draw.text((5, 5), read_text(), font=font, fill="black")
+
+ out_path = os.path.join(self.tempdir, "thumb.png")
+ img.save(out_path)
return out_path
diff --git a/src/paperless_text/tests/samples/test.txt b/src/paperless_text/tests/samples/test.txt
new file mode 100644
index 000000000..6de7b8c69
--- /dev/null
+++ b/src/paperless_text/tests/samples/test.txt
@@ -0,0 +1 @@
+This is a test file.
diff --git a/src/paperless_text/tests/test_parser.py b/src/paperless_text/tests/test_parser.py
new file mode 100644
index 000000000..413aa91cf
--- /dev/null
+++ b/src/paperless_text/tests/test_parser.py
@@ -0,0 +1,26 @@
+import os
+
+from django.test import TestCase
+
+from documents.tests.utils import DirectoriesMixin
+from paperless_text.parsers import TextDocumentParser
+
+
+class TestTextParser(DirectoriesMixin, TestCase):
+
+ def test_thumbnail(self):
+
+ parser = TextDocumentParser(None)
+
+ # just make sure that it does not crash
+ f = parser.get_thumbnail(os.path.join(os.path.dirname(__file__), "samples", "test.txt"), "text/plain")
+ self.assertTrue(os.path.isfile(f))
+
+ def test_parse(self):
+
+ parser = TextDocumentParser(None)
+
+ parser.parse(os.path.join(os.path.dirname(__file__), "samples", "test.txt"), "text/plain")
+
+ self.assertEqual(parser.get_text(), "This is a test file.\n")
+ self.assertIsNone(parser.get_archive_path())