mirror of
https://github.com/paperless-ngx/paperless-ngx.git
synced 2025-04-17 10:13:56 -05:00
Implement warning for closeAll
This commit is contained in:
parent
d275a75517
commit
1950f805b3
@ -25,9 +25,7 @@ export class AppFrameComponent implements OnInit, OnDestroy {
|
|||||||
private searchService: SearchService,
|
private searchService: SearchService,
|
||||||
public savedViewService: SavedViewService,
|
public savedViewService: SavedViewService,
|
||||||
private meta: Meta
|
private meta: Meta
|
||||||
) {
|
) { }
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
versionString = `${environment.appTitle} ${environment.version}`
|
versionString = `${environment.appTitle} ${environment.version}`
|
||||||
|
|
||||||
@ -78,17 +76,21 @@ export class AppFrameComponent implements OnInit, OnDestroy {
|
|||||||
}
|
}
|
||||||
|
|
||||||
closeAll() {
|
closeAll() {
|
||||||
this.closeMenu()
|
// user may need to confirm losing unsaved changes
|
||||||
this.openDocumentsService.closeAll()
|
this.openDocumentsService.closeAll().subscribe(confirmed => {
|
||||||
|
if (confirmed) {
|
||||||
|
this.closeMenu()
|
||||||
|
|
||||||
// TODO: is there a better way to do this?
|
// TODO: is there a better way to do this?
|
||||||
let route = this.activatedRoute
|
let route = this.activatedRoute
|
||||||
while (route.firstChild) {
|
while (route.firstChild) {
|
||||||
route = route.firstChild
|
route = route.firstChild
|
||||||
}
|
}
|
||||||
if (route.component == DocumentDetailComponent) {
|
if (route.component == DocumentDetailComponent) {
|
||||||
this.router.navigate([""])
|
this.router.navigate([""])
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
ngOnInit() {
|
ngOnInit() {
|
||||||
|
@ -136,6 +136,9 @@ export class DocumentDetailComponent implements OnInit, DirtyComponent {
|
|||||||
|
|
||||||
// Initialize dirtyCheck
|
// Initialize dirtyCheck
|
||||||
this.isDirty$ = dirtyCheck(this.documentForm, this.store.asObservable())
|
this.isDirty$ = dirtyCheck(this.documentForm, this.store.asObservable())
|
||||||
|
this.isDirty$.subscribe(dirty => {
|
||||||
|
this.openDocumentService.setDirty(this.document.id, dirty)
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
createDocumentType() {
|
createDocumentType() {
|
||||||
|
@ -2,6 +2,9 @@ import { Injectable } from '@angular/core';
|
|||||||
import { PaperlessDocument } from '../data/paperless-document';
|
import { PaperlessDocument } from '../data/paperless-document';
|
||||||
import { OPEN_DOCUMENT_SERVICE } from '../data/storage-keys';
|
import { OPEN_DOCUMENT_SERVICE } from '../data/storage-keys';
|
||||||
import { DocumentService } from './rest/document.service';
|
import { DocumentService } from './rest/document.service';
|
||||||
|
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';
|
||||||
|
|
||||||
@Injectable({
|
@Injectable({
|
||||||
providedIn: 'root'
|
providedIn: 'root'
|
||||||
@ -10,7 +13,7 @@ export class OpenDocumentsService {
|
|||||||
|
|
||||||
private MAX_OPEN_DOCUMENTS = 5
|
private MAX_OPEN_DOCUMENTS = 5
|
||||||
|
|
||||||
constructor(private documentService: DocumentService) {
|
constructor(private documentService: DocumentService, private modalService: NgbModal) {
|
||||||
if (sessionStorage.getItem(OPEN_DOCUMENT_SERVICE.DOCUMENTS)) {
|
if (sessionStorage.getItem(OPEN_DOCUMENT_SERVICE.DOCUMENTS)) {
|
||||||
try {
|
try {
|
||||||
this.openDocuments = JSON.parse(sessionStorage.getItem(OPEN_DOCUMENT_SERVICE.DOCUMENTS))
|
this.openDocuments = JSON.parse(sessionStorage.getItem(OPEN_DOCUMENT_SERVICE.DOCUMENTS))
|
||||||
@ -22,6 +25,7 @@ export class OpenDocumentsService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private openDocuments: PaperlessDocument[] = []
|
private openDocuments: PaperlessDocument[] = []
|
||||||
|
private dirtyDocuments: Set<number> = new Set<number>()
|
||||||
|
|
||||||
refreshDocument(id: number) {
|
refreshDocument(id: number) {
|
||||||
let index = this.openDocuments.findIndex(doc => doc.id == id)
|
let index = this.openDocuments.findIndex(doc => doc.id == id)
|
||||||
@ -53,6 +57,11 @@ export class OpenDocumentsService {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
setDirty(documentId: number, dirty: boolean) {
|
||||||
|
if (dirty) this.dirtyDocuments.add(documentId)
|
||||||
|
else this.dirtyDocuments.delete(documentId)
|
||||||
|
}
|
||||||
|
|
||||||
closeDocument(doc: PaperlessDocument) {
|
closeDocument(doc: PaperlessDocument) {
|
||||||
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) {
|
||||||
@ -61,9 +70,28 @@ export class OpenDocumentsService {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
closeAll() {
|
closeAll(): Observable<boolean> {
|
||||||
this.openDocuments.splice(0, this.openDocuments.length)
|
if (this.dirtyDocuments.size) {
|
||||||
this.save()
|
let modal = this.modalService.open(ConfirmDialogComponent, {backdrop: 'static'})
|
||||||
|
modal.componentInstance.title = $localize`Unsaved Changes`
|
||||||
|
modal.componentInstance.messageBold = $localize`You have unsaved changes.`
|
||||||
|
modal.componentInstance.message = $localize`Are you sure you want to close all documents?`
|
||||||
|
modal.componentInstance.btnClass = "btn-warning"
|
||||||
|
modal.componentInstance.btnCaption = $localize`Close documents`
|
||||||
|
modal.componentInstance.confirmClicked.subscribe(() => {
|
||||||
|
modal.componentInstance.buttonsEnabled = false
|
||||||
|
modal.close()
|
||||||
|
this.openDocuments.splice(0, this.openDocuments.length)
|
||||||
|
this.save()
|
||||||
|
})
|
||||||
|
const subject = new Subject<boolean>()
|
||||||
|
modal.componentInstance.subject = subject
|
||||||
|
return subject.asObservable()
|
||||||
|
} else {
|
||||||
|
this.openDocuments.splice(0, this.openDocuments.length)
|
||||||
|
this.save()
|
||||||
|
return of(true)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
save() {
|
save() {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user