Skip to content

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

documents now remain open fixes #16

Jonas Winkler7b561af7a14e
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 595da5b1d..fcd05f2fc 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
@@ -69,7 +69,7 @@ export class AppFrameComponent implements OnInit, OnDestroy {
}
ngOnInit() {
- this.openDocumentsSubscription = this.openDocumentsService.getOpenDocuments().subscribe(docs => this.openDocuments = docs)
+ this.openDocuments = this.openDocumentsService.getOpenDocuments()
}
ngOnDestroy() {
diff --git a/src-ui/src/app/data/storage-keys.ts b/src-ui/src/app/data/storage-keys.ts
new file mode 100644
index 000000000..aa39b31d1
--- /dev/null
+++ b/src-ui/src/app/data/storage-keys.ts
@@ -0,0 +1,3 @@
+export const OPEN_DOCUMENT_SERVICE = {
+ DOCUMENTS: 'open-documents-service:openDocuments'
+}
\ No newline at end of file
diff --git a/src-ui/src/app/services/open-documents.service.ts b/src-ui/src/app/services/open-documents.service.ts
index bcf4166f9..009652103 100644
--- a/src-ui/src/app/services/open-documents.service.ts
+++ b/src-ui/src/app/services/open-documents.service.ts
@@ -1,26 +1,38 @@
import { Injectable } from '@angular/core';
import { Observable, Subject } from 'rxjs';
import { PaperlessDocument } from '../data/paperless-document';
+import { OPEN_DOCUMENT_SERVICE } from '../data/storage-keys';
@Injectable({
providedIn: 'root'
})
export class OpenDocumentsService {
- constructor() { }
+ constructor() {
+ if (sessionStorage.getItem(OPEN_DOCUMENT_SERVICE.DOCUMENTS)) {
+ try {
+ this.openDocuments = JSON.parse(sessionStorage.getItem(OPEN_DOCUMENT_SERVICE.DOCUMENTS))
+ } catch (e) {
+ sessionStorage.removeItem(OPEN_DOCUMENT_SERVICE.DOCUMENTS)
+ this.openDocuments = []
+ }
+ }
+ }
private openDocuments: PaperlessDocument[] = []
- private openDocumentsSubject: Subject<PaperlessDocument[]> = new Subject()
+ getOpenDocuments(): PaperlessDocument[] {
+ return this.openDocuments
+ }
- getOpenDocuments(): Observable<PaperlessDocument[]> {
- return this.openDocumentsSubject
+ getOpenDocument(id: number): PaperlessDocument {
+ return this.openDocuments.find(d => d.id == id)
}
openDocument(doc: PaperlessDocument) {
if (this.openDocuments.find(d => d.id == doc.id) == null) {
this.openDocuments.push(doc)
- this.openDocumentsSubject.next(this.openDocuments)
+ this.save()
}
}
@@ -28,8 +40,12 @@ export class OpenDocumentsService {
let index = this.openDocuments.findIndex(d => d.id == doc.id)
if (index > -1) {
this.openDocuments.splice(index, 1)
- this.openDocumentsSubject.next(this.openDocuments)
+ this.save()
}
}
+ save() {
+ sessionStorage.setItem(OPEN_DOCUMENT_SERVICE.DOCUMENTS, JSON.stringify(this.openDocuments))
+ }
+
}