diff --git a/src-ui/messages.xlf b/src-ui/messages.xlf index dd388c374..0c9ca23e0 100644 --- a/src-ui/messages.xlf +++ b/src-ui/messages.xlf @@ -368,7 +368,7 @@ src/app/components/document-list/document-list.component.ts - 69 + 68 src/app/components/manage/management-list/management-list.component.html @@ -1913,14 +1913,14 @@ View "" saved successfully. src/app/components/document-list/document-list.component.ts - 198 + 197 View "" created successfully. src/app/components/document-list/document-list.component.ts - 228 + 227 @@ -2651,11 +2651,11 @@ src/app/services/open-documents.service.ts - 84 + 111 src/app/services/open-documents.service.ts - 107 + 138 @@ -2666,11 +2666,7 @@ src/app/services/open-documents.service.ts - 85 - - - src/app/services/open-documents.service.ts - 108 + 139 @@ -2803,32 +2799,39 @@ 27 + + You have unsaved changes to the document + + src/app/services/open-documents.service.ts + 113 + + Are you sure you want to close this document? src/app/services/open-documents.service.ts - 86 + 117 Close document src/app/services/open-documents.service.ts - 88 + 119 Are you sure you want to close all documents? src/app/services/open-documents.service.ts - 109 + 140 Close documents src/app/services/open-documents.service.ts - 111 + 142 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 8d5b9c43f..50d064c37 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 @@ -11,7 +11,7 @@ - + {{doc.created | customDate}} {{doc.title | documentTitle}} diff --git a/src-ui/src/app/components/dashboard/widgets/saved-view-widget/saved-view-widget.component.ts b/src-ui/src/app/components/dashboard/widgets/saved-view-widget/saved-view-widget.component.ts index 6e8b67900..94e0c4052 100644 --- a/src-ui/src/app/components/dashboard/widgets/saved-view-widget/saved-view-widget.component.ts +++ b/src-ui/src/app/components/dashboard/widgets/saved-view-widget/saved-view-widget.component.ts @@ -8,6 +8,7 @@ import { DocumentService } from 'src/app/services/rest/document.service' import { PaperlessTag } from 'src/app/data/paperless-tag' import { FILTER_HAS_TAGS_ALL } from 'src/app/data/filter-rule-type' import { QueryParamsService } from 'src/app/services/query-params.service' +import { OpenDocumentsService } from 'src/app/services/open-documents.service' @Component({ selector: 'app-saved-view-widget', @@ -21,7 +22,8 @@ export class SavedViewWidgetComponent implements OnInit, OnDestroy { private documentService: DocumentService, private router: Router, private queryParamsService: QueryParamsService, - private consumerStatusService: ConsumerStatusService + private consumerStatusService: ConsumerStatusService, + public openDocumentsService: OpenDocumentsService ) {} @Input() 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 4d66ea384..6f1614e5f 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 @@ -204,7 +204,7 @@ export class DocumentDetailComponent this.openDocumentService.getOpenDocument(this.documentId) ) } else { - this.openDocumentService.openDocument(doc) + this.openDocumentService.openDocument(doc, false) this.updateComponent(doc) } diff --git a/src-ui/src/app/components/document-list/document-card-large/document-card-large.component.html b/src-ui/src/app/components/document-list/document-card-large/document-card-large.component.html index a5b238504..5eb4a97dd 100644 --- a/src-ui/src/app/components/document-list/document-card-large/document-card-large.component.html +++ b/src-ui/src/app/components/document-list/document-card-large/document-card-large.component.html @@ -37,7 +37,7 @@  More like this - +  Edit diff --git a/src-ui/src/app/components/document-list/document-card-large/document-card-large.component.ts b/src-ui/src/app/components/document-list/document-card-large/document-card-large.component.ts index 1c4e9a7aa..061a0e681 100644 --- a/src-ui/src/app/components/document-list/document-card-large/document-card-large.component.ts +++ b/src-ui/src/app/components/document-list/document-card-large/document-card-large.component.ts @@ -6,7 +6,6 @@ import { Output, ViewChild, } from '@angular/core' -import { DomSanitizer } from '@angular/platform-browser' import { PaperlessDocument } from 'src/app/data/paperless-document' import { DocumentService } from 'src/app/services/rest/document.service' import { @@ -14,8 +13,7 @@ import { SETTINGS_KEYS, } from 'src/app/services/settings.service' import { NgbPopover } from '@ng-bootstrap/ng-bootstrap' -import { DocumentListViewService } from 'src/app/services/document-list-view.service' -import { FILTER_FULLTEXT_MORELIKE } from 'src/app/data/filter-rule-type' +import { OpenDocumentsService } from 'src/app/services/open-documents.service' @Component({ selector: 'app-document-card-large', @@ -28,8 +26,8 @@ import { FILTER_FULLTEXT_MORELIKE } from 'src/app/data/filter-rule-type' export class DocumentCardLargeComponent implements OnInit { constructor( private documentService: DocumentService, - private sanitizer: DomSanitizer, - private settingsService: SettingsService + private settingsService: SettingsService, + public openDocumentsService: OpenDocumentsService ) {} @Input() 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 2e8d29b7f..6c68cc26f 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 @@ -63,7 +63,7 @@
- + diff --git a/src-ui/src/app/components/document-list/document-card-small/document-card-small.component.ts b/src-ui/src/app/components/document-list/document-card-small/document-card-small.component.ts index cbff950a2..c166b42cb 100644 --- a/src-ui/src/app/components/document-list/document-card-small/document-card-small.component.ts +++ b/src-ui/src/app/components/document-list/document-card-small/document-card-small.component.ts @@ -14,6 +14,7 @@ import { SETTINGS_KEYS, } from 'src/app/services/settings.service' import { NgbPopover } from '@ng-bootstrap/ng-bootstrap' +import { OpenDocumentsService } from 'src/app/services/open-documents.service' @Component({ selector: 'app-document-card-small', @@ -26,7 +27,8 @@ import { NgbPopover } from '@ng-bootstrap/ng-bootstrap' export class DocumentCardSmallComponent implements OnInit { constructor( private documentService: DocumentService, - private settingsService: SettingsService + private settingsService: SettingsService, + public openDocumentsService: OpenDocumentsService ) {} @Input() 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 4a15fe976..aa43243fc 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 @@ -168,7 +168,7 @@ - {{d.title | documentTitle}} + {{d.title | documentTitle}} 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 01c2bee34..8cf6c3848 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 @@ -20,10 +20,8 @@ import { } from 'src/app/directives/sortable.directive' import { ConsumerStatusService } from 'src/app/services/consumer-status.service' import { DocumentListViewService } from 'src/app/services/document-list-view.service' -import { - filterRulesFromQueryParams, - QueryParamsService, -} from 'src/app/services/query-params.service' +import { OpenDocumentsService } from 'src/app/services/open-documents.service' +import { QueryParamsService } from 'src/app/services/query-params.service' import { DOCUMENT_SORT_FIELDS, DOCUMENT_SORT_FIELDS_FULLTEXT, @@ -47,7 +45,8 @@ export class DocumentListComponent implements OnInit, OnDestroy, AfterViewInit { private toastService: ToastService, private modalService: NgbModal, private consumerStatusService: ConsumerStatusService, - private queryParamsService: QueryParamsService + private queryParamsService: QueryParamsService, + public openDocumentsService: OpenDocumentsService ) {} @ViewChild('filterEditor') diff --git a/src-ui/src/app/services/open-documents.service.ts b/src-ui/src/app/services/open-documents.service.ts index 5297a38bf..d7746d261 100644 --- a/src-ui/src/app/services/open-documents.service.ts +++ b/src-ui/src/app/services/open-documents.service.ts @@ -6,6 +6,7 @@ import { NgbModal } from '@ng-bootstrap/ng-bootstrap' import { ConfirmDialogComponent } from 'src/app/components/common/confirm-dialog/confirm-dialog.component' import { Observable, Subject, of } from 'rxjs' import { first } from 'rxjs/operators' +import { Router } from '@angular/router' @Injectable({ providedIn: 'root', @@ -15,7 +16,8 @@ export class OpenDocumentsService { constructor( private documentService: DocumentService, - private modalService: NgbModal + private modalService: NgbModal, + private router: Router ) { if (sessionStorage.getItem(OPEN_DOCUMENT_SERVICE.DOCUMENTS)) { try { @@ -55,13 +57,38 @@ export class OpenDocumentsService { return this.openDocuments.find((d) => d.id == id) } - openDocument(doc: PaperlessDocument) { + openDocument( + doc: PaperlessDocument, + navigate: boolean = true + ): Observable { if (this.openDocuments.find((d) => d.id == doc.id) == null) { - this.openDocuments.unshift(doc) - if (this.openDocuments.length > this.MAX_OPEN_DOCUMENTS) { - this.openDocuments.pop() + if (this.openDocuments.length == this.MAX_OPEN_DOCUMENTS) { + // at max, ensure changes arent lost + const docToRemove = this.openDocuments[this.MAX_OPEN_DOCUMENTS - 1] + const closeObservable = this.closeDocument(docToRemove) + closeObservable.pipe(first()).subscribe((closed) => { + if (closed) this.finishOpenDocument(doc, navigate) + }) + return closeObservable + } else { + // not at max + this.finishOpenDocument(doc, navigate) } - this.save() + } else { + // doc is open, just maybe navigate + if (navigate) { + this.router.navigate(['documents', doc.id]) + } + } + return of(true) + } + + private finishOpenDocument(doc: PaperlessDocument, navigate: boolean) { + this.openDocuments.unshift(doc) + this.dirtyDocuments.delete(doc.id) + this.save() + if (navigate) { + this.router.navigate(['documents', doc.id]) } } @@ -82,7 +109,11 @@ export class OpenDocumentsService { backdrop: 'static', }) modal.componentInstance.title = $localize`Unsaved Changes` - modal.componentInstance.messageBold = $localize`You have unsaved changes.` + modal.componentInstance.messageBold = + $localize`You have unsaved changes to the document` + + ' "' + + doc.title + + '".' modal.componentInstance.message = $localize`Are you sure you want to close this document?` modal.componentInstance.btnClass = 'btn-warning' modal.componentInstance.btnCaption = $localize`Close document` diff --git a/src-ui/src/theme.scss b/src-ui/src/theme.scss index a18ce1358..732ac47d9 100644 --- a/src-ui/src/theme.scss +++ b/src-ui/src/theme.scss @@ -39,7 +39,7 @@ $form-check-radio-checked-bg-image-dark: url("data:image/svg+xml,