mirror of
https://github.com/paperless-ngx/paperless-ngx.git
synced 2026-10-11 18:47:13 +00:00
signals for open docuemtns service, saved views
This commit is contained in:
2 files changed
+25
-3
No files matched your search
@@ -1,5 +1,5 @@
|
||||
import { AsyncPipe } from '@angular/common'
|
||||
import { Component, OnDestroy, OnInit, inject } from '@angular/core'
|
||||
import { Component, OnDestroy, OnInit, inject, signal } from '@angular/core'
|
||||
import {
|
||||
FormControl,
|
||||
FormGroup,
|
||||
@@ -56,7 +56,7 @@ export class SavedViewsComponent
|
||||
|
||||
DisplayMode = DisplayMode
|
||||
|
||||
public savedViews: SavedView[]
|
||||
private savedViewsSignal = signal<SavedView[]>(undefined)
|
||||
private savedViewsGroup = new FormGroup({})
|
||||
public savedViewsForm: FormGroup = new FormGroup({
|
||||
savedViews: this.savedViewsGroup,
|
||||
@@ -69,6 +69,14 @@ export class SavedViewsComponent
|
||||
return this.settings.allDisplayFields
|
||||
}
|
||||
|
||||
public get savedViews(): SavedView[] {
|
||||
return this.savedViewsSignal()
|
||||
}
|
||||
|
||||
public set savedViews(savedViews: SavedView[]) {
|
||||
this.savedViewsSignal.set(savedViews)
|
||||
}
|
||||
|
||||
constructor() {
|
||||
super()
|
||||
this.settings.organizingSidebarSavedViews = true
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { Injectable, inject } from '@angular/core'
|
||||
import { Injectable, inject, signal } from '@angular/core'
|
||||
import { NgbModal } from '@ng-bootstrap/ng-bootstrap'
|
||||
import { Observable, Subject, of } from 'rxjs'
|
||||
import { first } from 'rxjs/operators'
|
||||
@@ -15,6 +15,7 @@ export class OpenDocumentsService {
|
||||
private modalService = inject(NgbModal)
|
||||
|
||||
private MAX_OPEN_DOCUMENTS = 5
|
||||
private stateVersion = signal(0)
|
||||
|
||||
constructor() {
|
||||
this.load()
|
||||
@@ -36,6 +37,14 @@ export class OpenDocumentsService {
|
||||
private openDocuments: Document[] = []
|
||||
private dirtyDocuments: Set<number> = new Set<number>()
|
||||
|
||||
private trackState(): void {
|
||||
this.stateVersion()
|
||||
}
|
||||
|
||||
private markChanged(): void {
|
||||
this.stateVersion.update((version) => version + 1)
|
||||
}
|
||||
|
||||
refreshDocument(id: number) {
|
||||
let index = this.openDocuments.findIndex((doc) => doc.id == id)
|
||||
if (index > -1) {
|
||||
@@ -53,10 +62,12 @@ export class OpenDocumentsService {
|
||||
}
|
||||
|
||||
getOpenDocuments(): Document[] {
|
||||
this.trackState()
|
||||
return this.openDocuments
|
||||
}
|
||||
|
||||
getOpenDocument(id: number): Document {
|
||||
this.trackState()
|
||||
return this.openDocuments.find((d) => d.id == id)
|
||||
}
|
||||
|
||||
@@ -101,10 +112,12 @@ export class OpenDocumentsService {
|
||||
}
|
||||
|
||||
hasDirty(): boolean {
|
||||
this.trackState()
|
||||
return this.dirtyDocuments.size > 0
|
||||
}
|
||||
|
||||
isDirty(doc: Document): boolean {
|
||||
this.trackState()
|
||||
return this.dirtyDocuments.has(doc.id)
|
||||
}
|
||||
|
||||
@@ -170,6 +183,7 @@ export class OpenDocumentsService {
|
||||
}
|
||||
|
||||
save() {
|
||||
this.markChanged()
|
||||
try {
|
||||
sessionStorage.setItem(
|
||||
OPEN_DOCUMENT_SERVICE.DOCUMENTS,
|
||||
|
||||
Reference in new issue
Block a user