mirror of
https://github.com/paperless-ngx/paperless-ngx.git
synced 2025-04-21 10:29:29 -05:00
Document detail dirty checking
This commit is contained in:
parent
b0fa0f2319
commit
8080b7a119
@ -20,7 +20,7 @@ const routes: Routes = [
|
|||||||
{path: 'documents', component: DocumentListComponent },
|
{path: 'documents', component: DocumentListComponent },
|
||||||
{path: 'view/:id', component: DocumentListComponent },
|
{path: 'view/:id', component: DocumentListComponent },
|
||||||
{path: 'search', component: SearchComponent },
|
{path: 'search', component: SearchComponent },
|
||||||
{path: 'documents/:id', component: DocumentDetailComponent },
|
{path: 'documents/:id', component: DocumentDetailComponent, canDeactivate: [FormDirtyGuard] },
|
||||||
|
|
||||||
{path: 'tags', component: TagListComponent },
|
{path: 'tags', component: TagListComponent },
|
||||||
{path: 'documenttypes', component: DocumentTypeListComponent },
|
{path: 'documenttypes', component: DocumentTypeListComponent },
|
||||||
|
@ -128,8 +128,8 @@
|
|||||||
<div [ngbNavOutlet]="nav" class="mt-2"></div>
|
<div [ngbNavOutlet]="nav" class="mt-2"></div>
|
||||||
|
|
||||||
<button type="button" class="btn btn-outline-secondary" (click)="discard()" i18n [disabled]="networkActive">Discard</button>
|
<button type="button" class="btn btn-outline-secondary" (click)="discard()" i18n [disabled]="networkActive">Discard</button>
|
||||||
<button type="button" class="btn btn-outline-primary" (click)="saveEditNext()" *ngIf="hasNext()" i18n [disabled]="networkActive">Save & next</button>
|
<button type="button" class="btn btn-outline-primary" (click)="saveEditNext()" *ngIf="hasNext()" i18n [disabled]="networkActive || !(isDirty$ | async)">Save & next</button>
|
||||||
<button type="submit" class="btn btn-primary" i18n [disabled]="networkActive">Save</button>
|
<button type="submit" class="btn btn-primary" i18n [disabled]="networkActive || !(isDirty$ | async)">Save</button>
|
||||||
</form>
|
</form>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
@ -19,13 +19,15 @@ import { PDFDocumentProxy } from 'ng2-pdf-viewer';
|
|||||||
import { ToastService } from 'src/app/services/toast.service';
|
import { ToastService } from 'src/app/services/toast.service';
|
||||||
import { TextComponent } from '../common/input/text/text.component';
|
import { TextComponent } from '../common/input/text/text.component';
|
||||||
import { SettingsService, SETTINGS_KEYS } from 'src/app/services/settings.service';
|
import { SettingsService, SETTINGS_KEYS } from 'src/app/services/settings.service';
|
||||||
|
import { dirtyCheck, DirtyComponent } from '@ngneat/dirty-check-forms';
|
||||||
|
import { Observable, Subscription, BehaviorSubject } from 'rxjs';
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'app-document-detail',
|
selector: 'app-document-detail',
|
||||||
templateUrl: './document-detail.component.html',
|
templateUrl: './document-detail.component.html',
|
||||||
styleUrls: ['./document-detail.component.scss']
|
styleUrls: ['./document-detail.component.scss']
|
||||||
})
|
})
|
||||||
export class DocumentDetailComponent implements OnInit {
|
export class DocumentDetailComponent implements OnInit, DirtyComponent {
|
||||||
|
|
||||||
@ViewChild("inputTitle")
|
@ViewChild("inputTitle")
|
||||||
titleInput: TextComponent
|
titleInput: TextComponent
|
||||||
@ -61,6 +63,10 @@ export class DocumentDetailComponent implements OnInit {
|
|||||||
previewCurrentPage: number = 1
|
previewCurrentPage: number = 1
|
||||||
previewNumPages: number = 1
|
previewNumPages: number = 1
|
||||||
|
|
||||||
|
store: BehaviorSubject<any>
|
||||||
|
storeSub: Subscription
|
||||||
|
isDirty$: Observable<boolean>
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
private documentsService: DocumentService,
|
private documentsService: DocumentService,
|
||||||
private route: ActivatedRoute,
|
private route: ActivatedRoute,
|
||||||
@ -113,7 +119,23 @@ export class DocumentDetailComponent implements OnInit {
|
|||||||
this.metadata = result
|
this.metadata = result
|
||||||
})
|
})
|
||||||
this.title = this.documentTitlePipe.transform(doc.title)
|
this.title = this.documentTitlePipe.transform(doc.title)
|
||||||
this.documentForm.patchValue(doc)
|
|
||||||
|
this.store = new BehaviorSubject({
|
||||||
|
title: doc.title,
|
||||||
|
content: doc.content,
|
||||||
|
created: doc.created,
|
||||||
|
correspondent: doc.correspondent,
|
||||||
|
document_type: doc.document_type,
|
||||||
|
archive_serial_number: doc.archive_serial_number,
|
||||||
|
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())
|
||||||
}
|
}
|
||||||
|
|
||||||
createDocumentType() {
|
createDocumentType() {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user