mirror of
				https://github.com/paperless-ngx/paperless-ngx.git
				synced 2025-11-03 03:16:10 -06:00 
			
		
		
		
	Prevent dirty check lost on document close & reopen
This commit is contained in:
		@@ -103,23 +103,9 @@ export class DocumentDetailComponent implements OnInit, DirtyComponent {
 | 
				
			|||||||
      this.downloadOriginalUrl = this.documentsService.getDownloadUrl(this.documentId, true)
 | 
					      this.downloadOriginalUrl = this.documentsService.getDownloadUrl(this.documentId, true)
 | 
				
			||||||
      if (this.openDocumentService.getOpenDocument(this.documentId)) {
 | 
					      if (this.openDocumentService.getOpenDocument(this.documentId)) {
 | 
				
			||||||
        this.updateComponent(this.openDocumentService.getOpenDocument(this.documentId))
 | 
					        this.updateComponent(this.openDocumentService.getOpenDocument(this.documentId))
 | 
				
			||||||
      } else {
 | 
					      }
 | 
				
			||||||
      this.documentsService.get(this.documentId).subscribe(doc => {
 | 
					      this.documentsService.get(this.documentId).subscribe(doc => {
 | 
				
			||||||
          this.openDocumentService.openDocument(doc)
 | 
					        // Initialize dirtyCheck
 | 
				
			||||||
          this.updateComponent(doc)
 | 
					 | 
				
			||||||
        }, error => {this.router.navigate(['404'])})
 | 
					 | 
				
			||||||
      }
 | 
					 | 
				
			||||||
    })
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
  }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
  updateComponent(doc: PaperlessDocument) {
 | 
					 | 
				
			||||||
    this.document = doc
 | 
					 | 
				
			||||||
    this.documentsService.getMetadata(doc.id).subscribe(result => {
 | 
					 | 
				
			||||||
      this.metadata = result
 | 
					 | 
				
			||||||
    })
 | 
					 | 
				
			||||||
    this.title = this.documentTitlePipe.transform(doc.title)
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        this.store = new BehaviorSubject({
 | 
					        this.store = new BehaviorSubject({
 | 
				
			||||||
          title: doc.title,
 | 
					          title: doc.title,
 | 
				
			||||||
          content: doc.content,
 | 
					          content: doc.content,
 | 
				
			||||||
@@ -130,15 +116,27 @@ export class DocumentDetailComponent implements OnInit, DirtyComponent {
 | 
				
			|||||||
          tags: doc.tags
 | 
					          tags: doc.tags
 | 
				
			||||||
        })
 | 
					        })
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    this.storeSub = this.store.asObservable().subscribe(state => {
 | 
					 | 
				
			||||||
      this.documentForm.patchValue(state, { emitEvent: false })
 | 
					 | 
				
			||||||
    })
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    // Initialize dirtyCheck
 | 
					 | 
				
			||||||
        this.isDirty$ = dirtyCheck(this.documentForm, this.store.asObservable())
 | 
					        this.isDirty$ = dirtyCheck(this.documentForm, this.store.asObservable())
 | 
				
			||||||
        this.isDirty$.subscribe(dirty => {
 | 
					        this.isDirty$.subscribe(dirty => {
 | 
				
			||||||
          this.openDocumentService.setDirty(this.document.id, dirty)
 | 
					          this.openDocumentService.setDirty(this.document.id, dirty)
 | 
				
			||||||
        })
 | 
					        })
 | 
				
			||||||
 | 
					        
 | 
				
			||||||
 | 
					        if (!this.openDocumentService.getOpenDocument(this.documentId)) {
 | 
				
			||||||
 | 
					          this.openDocumentService.openDocument(doc)
 | 
				
			||||||
 | 
					          this.updateComponent(doc)
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					      }, error => {this.router.navigate(['404'])})
 | 
				
			||||||
 | 
					    })
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  updateComponent(doc: PaperlessDocument) {
 | 
				
			||||||
 | 
					    this.document = doc
 | 
				
			||||||
 | 
					    this.documentsService.getMetadata(doc.id).subscribe(result => {
 | 
				
			||||||
 | 
					      this.metadata = result
 | 
				
			||||||
 | 
					    })
 | 
				
			||||||
 | 
					    this.title = this.documentTitlePipe.transform(doc.title)
 | 
				
			||||||
 | 
					    this.documentForm.patchValue(doc)
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  createDocumentType() {
 | 
					  createDocumentType() {
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user