mirror of
				https://github.com/paperless-ngx/paperless-ngx.git
				synced 2025-11-03 03:16:10 -06:00 
			
		
		
		
	documents now remain open fixes #16
This commit is contained in:
		@@ -69,7 +69,7 @@ export class AppFrameComponent implements OnInit, OnDestroy {
 | 
				
			|||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  ngOnInit() {
 | 
					  ngOnInit() {
 | 
				
			||||||
    this.openDocumentsSubscription = this.openDocumentsService.getOpenDocuments().subscribe(docs => this.openDocuments = docs)
 | 
					    this.openDocuments = this.openDocumentsService.getOpenDocuments()
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  ngOnDestroy() {
 | 
					  ngOnDestroy() {
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										3
									
								
								src-ui/src/app/data/storage-keys.ts
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										3
									
								
								src-ui/src/app/data/storage-keys.ts
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,3 @@
 | 
				
			|||||||
 | 
					export const OPEN_DOCUMENT_SERVICE = {
 | 
				
			||||||
 | 
					  DOCUMENTS: 'open-documents-service:openDocuments'
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
@@ -1,26 +1,38 @@
 | 
				
			|||||||
import { Injectable } from '@angular/core';
 | 
					import { Injectable } from '@angular/core';
 | 
				
			||||||
import { Observable, Subject } from 'rxjs';
 | 
					import { Observable, Subject } from 'rxjs';
 | 
				
			||||||
import { PaperlessDocument } from '../data/paperless-document';
 | 
					import { PaperlessDocument } from '../data/paperless-document';
 | 
				
			||||||
 | 
					import { OPEN_DOCUMENT_SERVICE } from '../data/storage-keys';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@Injectable({
 | 
					@Injectable({
 | 
				
			||||||
  providedIn: 'root'
 | 
					  providedIn: 'root'
 | 
				
			||||||
})
 | 
					})
 | 
				
			||||||
export class OpenDocumentsService {
 | 
					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 openDocuments: PaperlessDocument[] = []
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  private openDocumentsSubject: Subject<PaperlessDocument[]> = new Subject()
 | 
					  getOpenDocuments(): PaperlessDocument[] {
 | 
				
			||||||
 | 
					    return this.openDocuments
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  getOpenDocuments(): Observable<PaperlessDocument[]> {
 | 
					  getOpenDocument(id: number): PaperlessDocument {
 | 
				
			||||||
    return this.openDocumentsSubject
 | 
					    return this.openDocuments.find(d => d.id == id)
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  openDocument(doc: PaperlessDocument) {
 | 
					  openDocument(doc: PaperlessDocument) {
 | 
				
			||||||
    if (this.openDocuments.find(d => d.id == doc.id) == null) {
 | 
					    if (this.openDocuments.find(d => d.id == doc.id) == null) {
 | 
				
			||||||
      this.openDocuments.push(doc)
 | 
					      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)
 | 
					    let index = this.openDocuments.findIndex(d => d.id == doc.id)
 | 
				
			||||||
    if (index > -1) {
 | 
					    if (index > -1) {
 | 
				
			||||||
      this.openDocuments.splice(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))
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user