2022-03-11 10:53:32 -08:00
|
|
|
import { Injectable } from '@angular/core'
|
|
|
|
|
import { ActivatedRoute, Router } from '@angular/router'
|
|
|
|
|
import { Observable } from 'rxjs'
|
|
|
|
|
import {
|
|
|
|
|
cloneFilterRules,
|
|
|
|
|
FilterRule,
|
|
|
|
|
isFullTextFilterRule,
|
|
|
|
|
} from '../data/filter-rule'
|
|
|
|
|
import { PaperlessDocument } from '../data/paperless-document'
|
|
|
|
|
import { PaperlessSavedView } from '../data/paperless-saved-view'
|
|
|
|
|
import { DOCUMENT_LIST_SERVICE } from '../data/storage-keys'
|
|
|
|
|
import { DocumentService } from './rest/document.service'
|
|
|
|
|
import { SettingsService, SETTINGS_KEYS } from './settings.service'
|
2020-10-27 01:10:18 +01:00
|
|
|
|
2021-05-15 18:48:39 +02:00
|
|
|
/**
|
|
|
|
|
* Captures the current state of the list view.
|
|
|
|
|
*/
|
2021-02-18 17:29:21 +01:00
|
|
|
interface ListViewState {
|
2021-05-15 18:48:39 +02:00
|
|
|
/**
|
|
|
|
|
* Title of the document list view. Either "Documents" (localized) or the name of a saved view.
|
|
|
|
|
*/
|
2021-02-18 17:29:21 +01:00
|
|
|
title?: string
|
|
|
|
|
|
2021-05-15 18:48:39 +02:00
|
|
|
/**
|
|
|
|
|
* Current paginated list of documents displayed.
|
|
|
|
|
*/
|
2021-02-18 17:29:21 +01:00
|
|
|
documents?: PaperlessDocument[]
|
|
|
|
|
|
|
|
|
|
currentPage: number
|
2021-05-15 18:48:39 +02:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Total amount of documents with the current filter rules. Used to calculate the number of pages.
|
|
|
|
|
*/
|
2021-02-18 17:29:21 +01:00
|
|
|
collectionSize: number
|
|
|
|
|
|
2021-05-15 18:48:39 +02:00
|
|
|
/**
|
|
|
|
|
* Currently selected sort field.
|
|
|
|
|
*/
|
2021-02-18 17:29:21 +01:00
|
|
|
sortField: string
|
2021-05-15 18:48:39 +02:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* True if the list is sorted in reverse.
|
|
|
|
|
*/
|
2021-02-18 17:29:21 +01:00
|
|
|
sortReverse: boolean
|
|
|
|
|
|
2021-05-15 18:48:39 +02:00
|
|
|
/**
|
|
|
|
|
* Filter rules for the current list view.
|
|
|
|
|
*/
|
2021-02-18 17:29:21 +01:00
|
|
|
filterRules: FilterRule[]
|
|
|
|
|
|
2021-05-15 18:48:39 +02:00
|
|
|
/**
|
|
|
|
|
* Contains the IDs of all selected documents.
|
|
|
|
|
*/
|
2021-02-18 17:29:21 +01:00
|
|
|
selected?: Set<number>
|
|
|
|
|
}
|
2020-10-30 22:51:16 +01:00
|
|
|
|
2020-11-28 21:27:04 +01:00
|
|
|
/**
|
|
|
|
|
* This service manages the document list which is displayed using the document list view.
|
2020-12-12 22:53:34 -08:00
|
|
|
*
|
2020-11-28 21:27:04 +01:00
|
|
|
* This service also serves saved views by transparently switching between the document list
|
|
|
|
|
* and saved views on request. See below.
|
|
|
|
|
*/
|
2020-10-27 01:10:18 +01:00
|
|
|
@Injectable({
|
2022-03-11 10:53:32 -08:00
|
|
|
providedIn: 'root',
|
2020-10-27 01:10:18 +01:00
|
|
|
})
|
|
|
|
|
export class DocumentListViewService {
|
2020-11-28 21:27:04 +01:00
|
|
|
isReloading: boolean = false
|
2021-04-03 21:02:33 +02:00
|
|
|
error: string = null
|
2021-02-18 17:29:21 +01:00
|
|
|
|
2021-01-15 02:15:26 -08:00
|
|
|
rangeSelectionAnchorIndex: number
|
|
|
|
|
lastRangeSelectionToIndex: number
|
2020-12-12 22:53:34 -08:00
|
|
|
|
2021-02-18 17:29:21 +01:00
|
|
|
currentPageSize: number = this.settings.get(SETTINGS_KEYS.DOCUMENT_LIST_SIZE)
|
2020-10-27 01:10:18 +01:00
|
|
|
|
2021-02-18 17:29:21 +01:00
|
|
|
private listViewStates: Map<number, ListViewState> = new Map()
|
|
|
|
|
|
|
|
|
|
private _activeSavedViewId: number = null
|
2020-11-28 21:27:04 +01:00
|
|
|
|
2021-02-18 17:29:21 +01:00
|
|
|
get activeSavedViewId() {
|
|
|
|
|
return this._activeSavedViewId
|
2020-11-28 21:27:04 +01:00
|
|
|
}
|
|
|
|
|
|
2021-02-18 17:29:21 +01:00
|
|
|
get activeSavedViewTitle() {
|
|
|
|
|
return this.activeListViewState.title
|
2020-11-28 21:27:04 +01:00
|
|
|
}
|
|
|
|
|
|
2021-02-18 17:29:21 +01:00
|
|
|
private defaultListViewState(): ListViewState {
|
|
|
|
|
return {
|
|
|
|
|
title: null,
|
|
|
|
|
documents: [],
|
|
|
|
|
currentPage: 1,
|
|
|
|
|
collectionSize: null,
|
2022-03-11 10:53:32 -08:00
|
|
|
sortField: 'created',
|
2021-02-18 17:29:21 +01:00
|
|
|
sortReverse: true,
|
|
|
|
|
filterRules: [],
|
2022-03-11 10:53:32 -08:00
|
|
|
selected: new Set<number>(),
|
2020-11-28 21:27:04 +01:00
|
|
|
}
|
|
|
|
|
}
|
2020-10-30 22:46:43 +01:00
|
|
|
|
2021-02-18 17:29:21 +01:00
|
|
|
private get activeListViewState() {
|
|
|
|
|
if (!this.listViewStates.has(this._activeSavedViewId)) {
|
2022-03-11 10:53:32 -08:00
|
|
|
this.listViewStates.set(
|
|
|
|
|
this._activeSavedViewId,
|
|
|
|
|
this.defaultListViewState()
|
|
|
|
|
)
|
2021-02-18 17:29:21 +01:00
|
|
|
}
|
|
|
|
|
return this.listViewStates.get(this._activeSavedViewId)
|
2020-11-28 21:27:04 +01:00
|
|
|
}
|
|
|
|
|
|
2021-02-18 17:29:21 +01:00
|
|
|
activateSavedView(view: PaperlessSavedView) {
|
|
|
|
|
this.rangeSelectionAnchorIndex = this.lastRangeSelectionToIndex = null
|
|
|
|
|
if (view) {
|
|
|
|
|
this._activeSavedViewId = view.id
|
|
|
|
|
this.loadSavedView(view)
|
|
|
|
|
} else {
|
|
|
|
|
this._activeSavedViewId = null
|
|
|
|
|
}
|
2020-11-28 21:27:04 +01:00
|
|
|
}
|
|
|
|
|
|
2021-02-18 17:29:21 +01:00
|
|
|
loadSavedView(view: PaperlessSavedView, closeCurrentView: boolean = false) {
|
|
|
|
|
if (closeCurrentView) {
|
|
|
|
|
this._activeSavedViewId = null
|
|
|
|
|
}
|
|
|
|
|
this.activeListViewState.filterRules = cloneFilterRules(view.filter_rules)
|
|
|
|
|
this.activeListViewState.sortField = view.sort_field
|
|
|
|
|
this.activeListViewState.sortReverse = view.sort_reverse
|
|
|
|
|
if (this._activeSavedViewId) {
|
|
|
|
|
this.activeListViewState.title = view.name
|
|
|
|
|
}
|
|
|
|
|
this.reduceSelectionToFilter()
|
2020-12-03 19:55:42 +01:00
|
|
|
}
|
|
|
|
|
|
2020-11-28 21:27:04 +01:00
|
|
|
reload(onFinish?) {
|
|
|
|
|
this.isReloading = true
|
2021-04-03 21:02:33 +02:00
|
|
|
this.error = null
|
2021-02-18 17:29:21 +01:00
|
|
|
let activeListViewState = this.activeListViewState
|
|
|
|
|
|
2022-03-11 10:53:32 -08:00
|
|
|
this.documentService
|
|
|
|
|
.listFiltered(
|
|
|
|
|
activeListViewState.currentPage,
|
|
|
|
|
this.currentPageSize,
|
|
|
|
|
activeListViewState.sortField,
|
|
|
|
|
activeListViewState.sortReverse,
|
|
|
|
|
activeListViewState.filterRules
|
|
|
|
|
)
|
|
|
|
|
.subscribe(
|
|
|
|
|
(result) => {
|
2021-02-18 17:29:21 +01:00
|
|
|
this.isReloading = false
|
|
|
|
|
activeListViewState.collectionSize = result.count
|
|
|
|
|
activeListViewState.documents = result.results
|
2020-10-27 01:10:18 +01:00
|
|
|
if (onFinish) {
|
|
|
|
|
onFinish()
|
|
|
|
|
}
|
2021-01-15 02:15:26 -08:00
|
|
|
this.rangeSelectionAnchorIndex = this.lastRangeSelectionToIndex = null
|
2020-10-27 01:10:18 +01:00
|
|
|
},
|
2022-03-11 10:53:32 -08:00
|
|
|
(error) => {
|
2021-02-18 17:29:21 +01:00
|
|
|
this.isReloading = false
|
|
|
|
|
if (activeListViewState.currentPage != 1 && error.status == 404) {
|
2021-01-04 17:31:35 +01:00
|
|
|
// this happens when applying a filter: the current page might not be available anymore due to the reduced result set.
|
2021-02-18 17:29:21 +01:00
|
|
|
activeListViewState.currentPage = 1
|
2020-10-27 01:10:18 +01:00
|
|
|
this.reload()
|
2021-04-03 21:02:33 +02:00
|
|
|
} else {
|
|
|
|
|
this.error = error.error
|
2020-10-27 01:10:18 +01:00
|
|
|
}
|
2022-03-11 10:53:32 -08:00
|
|
|
}
|
|
|
|
|
)
|
2020-10-27 01:10:18 +01:00
|
|
|
}
|
|
|
|
|
|
2020-11-08 00:07:31 +01:00
|
|
|
set filterRules(filterRules: FilterRule[]) {
|
2022-03-11 10:53:32 -08:00
|
|
|
if (
|
|
|
|
|
!isFullTextFilterRule(filterRules) &&
|
|
|
|
|
this.activeListViewState.sortField == 'score'
|
|
|
|
|
) {
|
|
|
|
|
this.activeListViewState.sortField = 'created'
|
2021-04-03 22:19:12 +02:00
|
|
|
}
|
2021-05-15 18:48:39 +02:00
|
|
|
this.activeListViewState.filterRules = filterRules
|
2020-11-08 00:07:31 +01:00
|
|
|
this.reload()
|
2020-12-11 14:48:33 +01:00
|
|
|
this.reduceSelectionToFilter()
|
2020-11-28 21:27:04 +01:00
|
|
|
this.saveDocumentListView()
|
2020-11-08 00:07:31 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
get filterRules(): FilterRule[] {
|
2021-02-18 17:29:21 +01:00
|
|
|
return this.activeListViewState.filterRules
|
2020-11-08 00:07:31 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
set sortField(field: string) {
|
2021-02-18 17:29:21 +01:00
|
|
|
this.activeListViewState.sortField = field
|
2020-11-08 00:07:31 +01:00
|
|
|
this.reload()
|
2021-02-18 17:29:21 +01:00
|
|
|
this.saveDocumentListView()
|
2020-11-08 00:07:31 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
get sortField(): string {
|
2021-02-18 17:29:21 +01:00
|
|
|
return this.activeListViewState.sortField
|
2020-11-08 00:07:31 +01:00
|
|
|
}
|
|
|
|
|
|
2020-12-14 19:26:36 +01:00
|
|
|
set sortReverse(reverse: boolean) {
|
2021-02-18 17:29:21 +01:00
|
|
|
this.activeListViewState.sortReverse = reverse
|
2020-11-08 00:07:31 +01:00
|
|
|
this.reload()
|
2021-02-18 17:29:21 +01:00
|
|
|
this.saveDocumentListView()
|
2020-11-08 00:07:31 +01:00
|
|
|
}
|
|
|
|
|
|
2020-12-14 19:26:36 +01:00
|
|
|
get sortReverse(): boolean {
|
2021-02-18 17:29:21 +01:00
|
|
|
return this.activeListViewState.sortReverse
|
2020-11-08 00:07:31 +01:00
|
|
|
}
|
|
|
|
|
|
2021-02-18 17:29:21 +01:00
|
|
|
get collectionSize(): number {
|
|
|
|
|
return this.activeListViewState.collectionSize
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
get currentPage(): number {
|
|
|
|
|
return this.activeListViewState.currentPage
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
set currentPage(page: number) {
|
|
|
|
|
this.activeListViewState.currentPage = page
|
|
|
|
|
this.reload()
|
2021-01-04 15:58:04 +01:00
|
|
|
this.saveDocumentListView()
|
2021-02-18 17:29:21 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
get documents(): PaperlessDocument[] {
|
|
|
|
|
return this.activeListViewState.documents
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
get selected(): Set<number> {
|
|
|
|
|
return this.activeListViewState.selected
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
setSort(field: string, reverse: boolean) {
|
|
|
|
|
this.activeListViewState.sortField = field
|
|
|
|
|
this.activeListViewState.sortReverse = reverse
|
2021-01-04 15:58:04 +01:00
|
|
|
this.reload()
|
2021-02-18 17:29:21 +01:00
|
|
|
this.saveDocumentListView()
|
2021-01-04 15:58:04 +01:00
|
|
|
}
|
|
|
|
|
|
2020-11-28 21:27:04 +01:00
|
|
|
private saveDocumentListView() {
|
2021-02-18 17:29:21 +01:00
|
|
|
if (this._activeSavedViewId == null) {
|
|
|
|
|
let savedState: ListViewState = {
|
|
|
|
|
collectionSize: this.activeListViewState.collectionSize,
|
|
|
|
|
currentPage: this.activeListViewState.currentPage,
|
|
|
|
|
filterRules: this.activeListViewState.filterRules,
|
|
|
|
|
sortField: this.activeListViewState.sortField,
|
2022-03-11 10:53:32 -08:00
|
|
|
sortReverse: this.activeListViewState.sortReverse,
|
2021-02-18 17:29:21 +01:00
|
|
|
}
|
2022-03-11 10:53:32 -08:00
|
|
|
localStorage.setItem(
|
|
|
|
|
DOCUMENT_LIST_SERVICE.CURRENT_VIEW_CONFIG,
|
|
|
|
|
JSON.stringify(savedState)
|
|
|
|
|
)
|
2021-02-18 17:29:21 +01:00
|
|
|
}
|
2020-10-27 01:10:18 +01:00
|
|
|
}
|
|
|
|
|
|
2020-12-30 23:34:50 +01:00
|
|
|
quickFilter(filterRules: FilterRule[]) {
|
2021-02-18 17:29:21 +01:00
|
|
|
this._activeSavedViewId = null
|
|
|
|
|
this.activeListViewState.filterRules = filterRules
|
|
|
|
|
this.activeListViewState.currentPage = 1
|
2021-05-15 18:48:39 +02:00
|
|
|
if (isFullTextFilterRule(filterRules)) {
|
2022-03-11 10:53:32 -08:00
|
|
|
this.activeListViewState.sortField = 'score'
|
2021-05-15 18:48:39 +02:00
|
|
|
this.activeListViewState.sortReverse = false
|
|
|
|
|
}
|
2020-12-30 23:34:50 +01:00
|
|
|
this.reduceSelectionToFilter()
|
|
|
|
|
this.saveDocumentListView()
|
2022-03-11 10:53:32 -08:00
|
|
|
if (this.router.url == '/documents') {
|
2021-03-17 22:25:22 +01:00
|
|
|
this.reload()
|
|
|
|
|
} else {
|
2022-03-11 10:53:32 -08:00
|
|
|
this.router.navigate(['documents'])
|
2021-03-17 22:25:22 +01:00
|
|
|
}
|
2020-12-30 23:34:50 +01:00
|
|
|
}
|
|
|
|
|
|
2020-10-27 01:10:18 +01:00
|
|
|
getLastPage(): number {
|
2020-11-04 19:28:08 +01:00
|
|
|
return Math.ceil(this.collectionSize / this.currentPageSize)
|
2020-10-27 01:10:18 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
hasNext(doc: number) {
|
|
|
|
|
if (this.documents) {
|
2022-03-11 10:53:32 -08:00
|
|
|
let index = this.documents.findIndex((d) => d.id == doc)
|
|
|
|
|
return (
|
|
|
|
|
index != -1 &&
|
|
|
|
|
(this.currentPage < this.getLastPage() ||
|
|
|
|
|
index + 1 < this.documents.length)
|
|
|
|
|
)
|
2020-10-27 01:10:18 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-03-11 17:35:38 +01:00
|
|
|
hasPrevious(doc: number) {
|
|
|
|
|
if (this.documents) {
|
|
|
|
|
let index = this.documents.findIndex(d => d.id == doc)
|
2022-03-11 20:16:53 +01:00
|
|
|
return index != -1 && !(index == 0 && this.currentPage == 1)
|
2022-03-11 17:35:38 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-10-27 01:10:18 +01:00
|
|
|
getNext(currentDocId: number): Observable<number> {
|
2022-03-11 10:53:32 -08:00
|
|
|
return new Observable((nextDocId) => {
|
2020-10-27 01:10:18 +01:00
|
|
|
if (this.documents != null) {
|
2022-03-11 10:53:32 -08:00
|
|
|
let index = this.documents.findIndex((d) => d.id == currentDocId)
|
2020-10-27 01:10:18 +01:00
|
|
|
|
2022-03-11 10:53:32 -08:00
|
|
|
if (index != -1 && index + 1 < this.documents.length) {
|
|
|
|
|
nextDocId.next(this.documents[index + 1].id)
|
2020-10-27 01:10:18 +01:00
|
|
|
nextDocId.complete()
|
|
|
|
|
} else if (index != -1 && this.currentPage < this.getLastPage()) {
|
|
|
|
|
this.currentPage += 1
|
|
|
|
|
this.reload(() => {
|
|
|
|
|
nextDocId.next(this.documents[0].id)
|
|
|
|
|
nextDocId.complete()
|
|
|
|
|
})
|
|
|
|
|
} else {
|
|
|
|
|
nextDocId.complete()
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
nextDocId.complete()
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
2022-03-11 17:35:38 +01:00
|
|
|
getPrevious(currentDocId: number): Observable<number> {
|
|
|
|
|
return new Observable(prevDocId => {
|
|
|
|
|
if (this.documents != null) {
|
|
|
|
|
|
|
|
|
|
let index = this.documents.findIndex(d => d.id == currentDocId)
|
|
|
|
|
|
|
|
|
|
if (index != 0) {
|
|
|
|
|
prevDocId.next(this.documents[index-1].id)
|
|
|
|
|
prevDocId.complete()
|
|
|
|
|
} else if (this.currentPage > 1) {
|
|
|
|
|
this.currentPage -= 1
|
|
|
|
|
this.reload(() => {
|
|
|
|
|
prevDocId.next(this.documents[this.documents.length - 1].id)
|
|
|
|
|
prevDocId.complete()
|
|
|
|
|
})
|
|
|
|
|
} else {
|
|
|
|
|
prevDocId.complete()
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
prevDocId.complete()
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
2020-11-04 19:28:08 +01:00
|
|
|
updatePageSize() {
|
2020-12-29 17:09:07 +01:00
|
|
|
let newPageSize = this.settings.get(SETTINGS_KEYS.DOCUMENT_LIST_SIZE)
|
2020-11-04 19:28:08 +01:00
|
|
|
if (newPageSize != this.currentPageSize) {
|
|
|
|
|
this.currentPageSize = newPageSize
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-12-11 14:48:33 +01:00
|
|
|
selectNone() {
|
|
|
|
|
this.selected.clear()
|
2021-01-15 02:15:26 -08:00
|
|
|
this.rangeSelectionAnchorIndex = this.lastRangeSelectionToIndex = null
|
2020-12-11 14:48:33 +01:00
|
|
|
}
|
|
|
|
|
|
2020-12-29 17:20:45 +01:00
|
|
|
reduceSelectionToFilter() {
|
2020-12-11 14:48:33 +01:00
|
|
|
if (this.selected.size > 0) {
|
2022-03-11 10:53:32 -08:00
|
|
|
this.documentService
|
|
|
|
|
.listAllFilteredIds(this.filterRules)
|
|
|
|
|
.subscribe((ids) => {
|
|
|
|
|
for (let id of this.selected) {
|
|
|
|
|
if (!ids.includes(id)) {
|
|
|
|
|
this.selected.delete(id)
|
|
|
|
|
}
|
2020-12-11 14:48:33 +01:00
|
|
|
}
|
2022-03-11 10:53:32 -08:00
|
|
|
})
|
2020-12-11 14:48:33 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
selectAll() {
|
2022-03-11 10:53:32 -08:00
|
|
|
this.documentService
|
|
|
|
|
.listAllFilteredIds(this.filterRules)
|
|
|
|
|
.subscribe((ids) => ids.forEach((id) => this.selected.add(id)))
|
2020-12-11 14:48:33 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
selectPage() {
|
|
|
|
|
this.selected.clear()
|
2022-03-11 10:53:32 -08:00
|
|
|
this.documents.forEach((doc) => {
|
2020-12-11 14:48:33 +01:00
|
|
|
this.selected.add(doc.id)
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
isSelected(d: PaperlessDocument) {
|
|
|
|
|
return this.selected.has(d.id)
|
|
|
|
|
}
|
|
|
|
|
|
2021-01-15 01:59:29 -08:00
|
|
|
toggleSelected(d: PaperlessDocument): void {
|
|
|
|
|
if (this.selected.has(d.id)) this.selected.delete(d.id)
|
|
|
|
|
else this.selected.add(d.id)
|
2021-01-15 02:15:26 -08:00
|
|
|
this.rangeSelectionAnchorIndex = this.documentIndexInCurrentView(d.id)
|
|
|
|
|
this.lastRangeSelectionToIndex = null
|
2021-01-15 01:59:29 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
selectRangeTo(d: PaperlessDocument) {
|
2021-01-15 02:15:26 -08:00
|
|
|
if (this.rangeSelectionAnchorIndex !== null) {
|
2021-01-15 01:54:33 -08:00
|
|
|
const documentToIndex = this.documentIndexInCurrentView(d.id)
|
2022-03-11 10:53:32 -08:00
|
|
|
const fromIndex = Math.min(
|
|
|
|
|
this.rangeSelectionAnchorIndex,
|
|
|
|
|
documentToIndex
|
|
|
|
|
)
|
2021-01-15 02:15:26 -08:00
|
|
|
const toIndex = Math.max(this.rangeSelectionAnchorIndex, documentToIndex)
|
2021-01-15 01:54:33 -08:00
|
|
|
|
2021-01-15 07:57:01 -08:00
|
|
|
if (this.lastRangeSelectionToIndex !== null) {
|
|
|
|
|
// revert the old selection
|
2022-03-11 10:53:32 -08:00
|
|
|
this.documents
|
|
|
|
|
.slice(
|
|
|
|
|
Math.min(
|
|
|
|
|
this.rangeSelectionAnchorIndex,
|
|
|
|
|
this.lastRangeSelectionToIndex
|
|
|
|
|
),
|
|
|
|
|
Math.max(
|
|
|
|
|
this.rangeSelectionAnchorIndex,
|
|
|
|
|
this.lastRangeSelectionToIndex
|
|
|
|
|
) + 1
|
|
|
|
|
)
|
|
|
|
|
.forEach((d) => {
|
|
|
|
|
this.selected.delete(d.id)
|
|
|
|
|
})
|
2021-01-15 01:54:33 -08:00
|
|
|
}
|
2021-01-14 14:10:23 -08:00
|
|
|
|
2022-03-11 10:53:32 -08:00
|
|
|
this.documents.slice(fromIndex, toIndex + 1).forEach((d) => {
|
2021-01-14 14:10:23 -08:00
|
|
|
this.selected.add(d.id)
|
|
|
|
|
})
|
2021-01-15 02:15:26 -08:00
|
|
|
this.lastRangeSelectionToIndex = documentToIndex
|
2022-03-11 10:53:32 -08:00
|
|
|
} else {
|
|
|
|
|
// e.g. shift key but was first click
|
2021-01-15 02:13:21 -08:00
|
|
|
this.toggleSelected(d)
|
2021-01-14 14:10:23 -08:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
documentIndexInCurrentView(documentID: number): number {
|
2022-03-11 10:53:32 -08:00
|
|
|
return this.documents.map((d) => d.id).indexOf(documentID)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
constructor(
|
|
|
|
|
private documentService: DocumentService,
|
|
|
|
|
private settings: SettingsService,
|
|
|
|
|
private router: Router,
|
|
|
|
|
private route: ActivatedRoute
|
|
|
|
|
) {
|
|
|
|
|
let documentListViewConfigJson = localStorage.getItem(
|
|
|
|
|
DOCUMENT_LIST_SERVICE.CURRENT_VIEW_CONFIG
|
|
|
|
|
)
|
2020-11-28 21:27:04 +01:00
|
|
|
if (documentListViewConfigJson) {
|
2020-11-08 00:07:31 +01:00
|
|
|
try {
|
2021-02-18 17:29:21 +01:00
|
|
|
let savedState: ListViewState = JSON.parse(documentListViewConfigJson)
|
|
|
|
|
// Remove null elements from the restored state
|
2022-03-11 10:53:32 -08:00
|
|
|
Object.keys(savedState).forEach((k) => {
|
2021-02-18 17:29:21 +01:00
|
|
|
if (savedState[k] == null) {
|
|
|
|
|
delete savedState[k]
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
//only use restored state attributes instead of defaults if they are not null
|
|
|
|
|
let newState = Object.assign(this.defaultListViewState(), savedState)
|
|
|
|
|
this.listViewStates.set(null, newState)
|
2020-11-08 00:07:31 +01:00
|
|
|
} catch (e) {
|
2021-04-02 14:46:45 +02:00
|
|
|
localStorage.removeItem(DOCUMENT_LIST_SERVICE.CURRENT_VIEW_CONFIG)
|
2020-11-08 00:07:31 +01:00
|
|
|
}
|
2020-11-28 21:27:04 +01:00
|
|
|
}
|
2020-11-08 00:07:31 +01:00
|
|
|
}
|
2020-10-27 01:10:18 +01:00
|
|
|
}
|