Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: Rework query params logic #1000

Merged
merged 5 commits into from May 26, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 2 additions & 3 deletions src-ui/src/app/components/app-frame/app-frame.component.ts
Expand Up @@ -22,7 +22,6 @@ import {
RemoteVersionService,
AppRemoteVersion,
} from 'src/app/services/rest/remote-version.service'
import { QueryParamsService } from 'src/app/services/query-params.service'
import { SettingsService } from 'src/app/services/settings.service'

@Component({
Expand All @@ -38,7 +37,7 @@ export class AppFrameComponent {
private searchService: SearchService,
public savedViewService: SavedViewService,
private remoteVersionService: RemoteVersionService,
private queryParamsService: QueryParamsService,
private list: DocumentListViewService,
public settingsService: SettingsService
) {
this.remoteVersionService
Expand Down Expand Up @@ -94,7 +93,7 @@ export class AppFrameComponent {

search() {
this.closeMenu()
this.queryParamsService.navigateWithFilterRules([
this.list.quickFilter([
{
rule_type: FILTER_FULLTEXT_QUERY,
value: (this.searchField.value as string).trim(),
Expand Down
Expand Up @@ -7,8 +7,8 @@ import { ConsumerStatusService } from 'src/app/services/consumer-status.service'
import { DocumentService } from 'src/app/services/rest/document.service'
import { PaperlessTag } from 'src/app/data/paperless-tag'
import { FILTER_HAS_TAGS_ALL } from 'src/app/data/filter-rule-type'
import { QueryParamsService } from 'src/app/services/query-params.service'
import { OpenDocumentsService } from 'src/app/services/open-documents.service'
import { DocumentListViewService } from 'src/app/services/document-list-view.service'

@Component({
selector: 'app-saved-view-widget',
Expand All @@ -21,7 +21,7 @@ export class SavedViewWidgetComponent implements OnInit, OnDestroy {
constructor(
private documentService: DocumentService,
private router: Router,
private queryParamsService: QueryParamsService,
private list: DocumentListViewService,
private consumerStatusService: ConsumerStatusService,
public openDocumentsService: OpenDocumentsService
) {}
Expand Down Expand Up @@ -73,7 +73,7 @@ export class SavedViewWidgetComponent implements OnInit, OnDestroy {
}

clickTag(tag: PaperlessTag) {
this.queryParamsService.navigateWithFilterRules([
this.list.quickFilter([
{ rule_type: FILTER_HAS_TAGS_ALL, value: tag.id.toString() },
])
}
Expand Down
Expand Up @@ -32,7 +32,6 @@ import {
import { PaperlessDocumentSuggestions } from 'src/app/data/paperless-document-suggestions'
import { FILTER_FULLTEXT_MORELIKE } from 'src/app/data/filter-rule-type'
import { normalizeDateStr } from 'src/app/utils/date'
import { QueryParamsService } from 'src/app/services/query-params.service'
import { StoragePathService } from 'src/app/services/rest/storage-path.service'
import { PaperlessStoragePath } from 'src/app/data/paperless-storage-path'
import { StoragePathEditDialogComponent } from '../common/edit-dialog/storage-path-edit-dialog/storage-path-edit-dialog.component'
Expand Down Expand Up @@ -120,8 +119,7 @@ export class DocumentDetailComponent
private documentTitlePipe: DocumentTitlePipe,
private toastService: ToastService,
private settings: SettingsService,
private storagePathService: StoragePathService,
private queryParamsService: QueryParamsService
private storagePathService: StoragePathService
) {}

titleKeyUp(event) {
Expand Down Expand Up @@ -494,7 +492,7 @@ export class DocumentDetailComponent
}

moreLike() {
this.queryParamsService.navigateWithFilterRules([
this.documentListViewService.quickFilter([
{
rule_type: FILTER_FULLTEXT_MORELIKE,
value: this.documentId.toString(),
Expand Down
Expand Up @@ -93,7 +93,7 @@
<span i18n *ngIf="list.selected.size == 0">{list.collectionSize, plural, =1 {One document} other {{{list.collectionSize || 0}} documents}}</span>&nbsp;<span i18n *ngIf="isFiltered">(filtered)</span>
</ng-container>
</p>
<ngb-pagination [pageSize]="list.currentPageSize" [collectionSize]="list.collectionSize" [(page)]="list.currentPage" [maxSize]="5"
<ngb-pagination [pageSize]="list.currentPageSize" [collectionSize]="list.collectionSize" (pageChange)="setPage($event)" [page]="list.currentPage" [maxSize]="5"
[rotate]="true" aria-label="Default pagination"></ngb-pagination>
</div>
</ng-template>
Expand Down
@@ -1,5 +1,4 @@
import {
AfterViewInit,
Component,
OnDestroy,
OnInit,
Expand All @@ -21,7 +20,6 @@ import {
import { ConsumerStatusService } from 'src/app/services/consumer-status.service'
import { DocumentListViewService } from 'src/app/services/document-list-view.service'
import { OpenDocumentsService } from 'src/app/services/open-documents.service'
import { QueryParamsService } from 'src/app/services/query-params.service'
import {
DOCUMENT_SORT_FIELDS,
DOCUMENT_SORT_FIELDS_FULLTEXT,
Expand All @@ -36,7 +34,7 @@ import { SaveViewConfigDialogComponent } from './save-view-config-dialog/save-vi
templateUrl: './document-list.component.html',
styleUrls: ['./document-list.component.scss'],
})
export class DocumentListComponent implements OnInit, OnDestroy, AfterViewInit {
export class DocumentListComponent implements OnInit, OnDestroy {
constructor(
public list: DocumentListViewService,
public savedViewService: SavedViewService,
Expand All @@ -45,7 +43,6 @@ export class DocumentListComponent implements OnInit, OnDestroy, AfterViewInit {
private toastService: ToastService,
private modalService: NgbModal,
private consumerStatusService: ConsumerStatusService,
private queryParamsService: QueryParamsService,
public openDocumentsService: OpenDocumentsService
) {}

Expand Down Expand Up @@ -76,8 +73,6 @@ export class DocumentListComponent implements OnInit, OnDestroy, AfterViewInit {

set listSort(reverse: boolean) {
this.list.sortReverse = reverse
this.queryParamsService.sortField = this.list.sortField
this.queryParamsService.sortReverse = reverse
}

get listSort(): boolean {
Expand All @@ -86,14 +81,14 @@ export class DocumentListComponent implements OnInit, OnDestroy, AfterViewInit {

setSortField(field: string) {
this.list.sortField = field
this.queryParamsService.sortField = field
this.queryParamsService.sortReverse = this.listSort
}

onSort(event: SortEvent) {
this.list.setSort(event.column, event.reverse)
this.queryParamsService.sortField = event.column
this.queryParamsService.sortReverse = event.reverse
}

setPage(page: number) {
this.list.currentPage = page
}

get isBulkEditing(): boolean {
Expand Down Expand Up @@ -133,7 +128,6 @@ export class DocumentListComponent implements OnInit, OnDestroy, AfterViewInit {
}
this.list.activateSavedView(view)
this.list.reload()
this.queryParamsService.updateFromView(view)
this.unmodifiedFilterRules = view.filter_rules
})

Expand All @@ -148,22 +142,12 @@ export class DocumentListComponent implements OnInit, OnDestroy, AfterViewInit {
this.loadViewConfig(parseInt(queryParams.get('view')))
} else {
this.list.activateSavedView(null)
this.queryParamsService.parseQueryParams(queryParams)
this.list.loadFromQueryParams(queryParams)
this.unmodifiedFilterRules = []
}
})
}

ngAfterViewInit(): void {
this.filterEditor.filterRulesChange
.pipe(takeUntil(this.unsubscribeNotifier))
.subscribe({
next: (filterRules) => {
this.queryParamsService.updateFilterRules(filterRules)
},
})
}

ngOnDestroy() {
// unsubscribes all
this.unsubscribeNotifier.next(this)
Expand All @@ -175,9 +159,8 @@ export class DocumentListComponent implements OnInit, OnDestroy, AfterViewInit {
.getCached(viewId)
.pipe(first())
.subscribe((view) => {
this.list.loadSavedView(view)
this.list.activateSavedView(view)
this.list.reload()
this.queryParamsService.updateFromView(view)
})
}

Expand Down Expand Up @@ -246,34 +229,26 @@ export class DocumentListComponent implements OnInit, OnDestroy, AfterViewInit {

clickTag(tagID: number) {
this.list.selectNone()
setTimeout(() => {
this.filterEditor.addTag(tagID)
})
this.filterEditor.addTag(tagID)
}

clickCorrespondent(correspondentID: number) {
this.list.selectNone()
setTimeout(() => {
this.filterEditor.addCorrespondent(correspondentID)
})
this.filterEditor.addCorrespondent(correspondentID)
}

clickDocumentType(documentTypeID: number) {
this.list.selectNone()
setTimeout(() => {
this.filterEditor.addDocumentType(documentTypeID)
})
this.filterEditor.addDocumentType(documentTypeID)
}

clickStoragePath(storagePathID: number) {
this.list.selectNone()
setTimeout(() => {
this.filterEditor.addStoragePath(storagePathID)
})
this.filterEditor.addStoragePath(storagePathID)
}

clickMoreLike(documentID: number) {
this.queryParamsService.navigateWithFilterRules([
this.list.quickFilter([
{ rule_type: FILTER_FULLTEXT_MORELIKE, value: documentID.toString() },
])
}
Expand Down
Expand Up @@ -313,7 +313,10 @@ export class FilterEditorComponent implements OnInit, OnDestroy {
break
case FILTER_ASN_ISNULL:
this.textFilterTarget = TEXT_FILTER_TARGET_ASN
this.textFilterModifier = TEXT_FILTER_MODIFIER_NULL
this.textFilterModifier =
rule.value == 'true' || rule.value == '1'
? TEXT_FILTER_MODIFIER_NULL
: TEXT_FILTER_MODIFIER_NOTNULL
break
case FILTER_ASN_GT:
this.textFilterTarget = TEXT_FILTER_TARGET_ASN
Expand Down
Expand Up @@ -3,7 +3,7 @@ import { NgbModal } from '@ng-bootstrap/ng-bootstrap'
import { FILTER_CORRESPONDENT } from 'src/app/data/filter-rule-type'
import { PaperlessCorrespondent } from 'src/app/data/paperless-correspondent'
import { CustomDatePipe } from 'src/app/pipes/custom-date.pipe'
import { QueryParamsService } from 'src/app/services/query-params.service'
import { DocumentListViewService } from 'src/app/services/document-list-view.service'
import { CorrespondentService } from 'src/app/services/rest/correspondent.service'
import { ToastService } from 'src/app/services/toast.service'
import { CorrespondentEditDialogComponent } from '../../common/edit-dialog/correspondent-edit-dialog/correspondent-edit-dialog.component'
Expand All @@ -20,15 +20,15 @@ export class CorrespondentListComponent extends ManagementListComponent<Paperles
correspondentsService: CorrespondentService,
modalService: NgbModal,
toastService: ToastService,
queryParamsService: QueryParamsService,
documentListViewService: DocumentListViewService,
private datePipe: CustomDatePipe
) {
super(
correspondentsService,
modalService,
CorrespondentEditDialogComponent,
toastService,
queryParamsService,
documentListViewService,
FILTER_CORRESPONDENT,
$localize`correspondent`,
$localize`correspondents`,
Expand Down
Expand Up @@ -2,7 +2,7 @@ import { Component } from '@angular/core'
import { NgbModal } from '@ng-bootstrap/ng-bootstrap'
import { FILTER_DOCUMENT_TYPE } from 'src/app/data/filter-rule-type'
import { PaperlessDocumentType } from 'src/app/data/paperless-document-type'
import { QueryParamsService } from 'src/app/services/query-params.service'
import { DocumentListViewService } from 'src/app/services/document-list-view.service'
import { DocumentTypeService } from 'src/app/services/rest/document-type.service'
import { ToastService } from 'src/app/services/toast.service'
import { DocumentTypeEditDialogComponent } from '../../common/edit-dialog/document-type-edit-dialog/document-type-edit-dialog.component'
Expand All @@ -18,14 +18,14 @@ export class DocumentTypeListComponent extends ManagementListComponent<Paperless
documentTypeService: DocumentTypeService,
modalService: NgbModal,
toastService: ToastService,
queryParamsService: QueryParamsService
documentListViewService: DocumentListViewService
) {
super(
documentTypeService,
modalService,
DocumentTypeEditDialogComponent,
toastService,
queryParamsService,
documentListViewService,
FILTER_DOCUMENT_TYPE,
$localize`document type`,
$localize`document types`,
Expand Down
Expand Up @@ -18,7 +18,7 @@ import {
SortableDirective,
SortEvent,
} from 'src/app/directives/sortable.directive'
import { QueryParamsService } from 'src/app/services/query-params.service'
import { DocumentListViewService } from 'src/app/services/document-list-view.service'
import { AbstractNameFilterService } from 'src/app/services/rest/abstract-name-filter-service'
import { ToastService } from 'src/app/services/toast.service'
import { ConfirmDialogComponent } from '../../common/confirm-dialog/confirm-dialog.component'
Expand All @@ -42,7 +42,7 @@ export abstract class ManagementListComponent<T extends ObjectWithId>
private modalService: NgbModal,
private editDialogComponent: any,
private toastService: ToastService,
private queryParamsService: QueryParamsService,
private documentListViewService: DocumentListViewService,
protected filterRuleType: number,
public typeName: string,
public typeNamePlural: string,
Expand Down Expand Up @@ -141,7 +141,7 @@ export abstract class ManagementListComponent<T extends ObjectWithId>
}

filterDocuments(object: ObjectWithId) {
this.queryParamsService.navigateWithFilterRules([
this.documentListViewService.quickFilter([
{ rule_type: this.filterRuleType, value: object.id.toString() },
])
}
Expand Down
Expand Up @@ -3,7 +3,6 @@ import { NgbModal } from '@ng-bootstrap/ng-bootstrap'
import { FILTER_STORAGE_PATH } from 'src/app/data/filter-rule-type'
import { PaperlessStoragePath } from 'src/app/data/paperless-storage-path'
import { DocumentListViewService } from 'src/app/services/document-list-view.service'
import { QueryParamsService } from 'src/app/services/query-params.service'
import { StoragePathService } from 'src/app/services/rest/storage-path.service'
import { ToastService } from 'src/app/services/toast.service'
import { StoragePathEditDialogComponent } from '../../common/edit-dialog/storage-path-edit-dialog/storage-path-edit-dialog.component'
Expand All @@ -19,14 +18,14 @@ export class StoragePathListComponent extends ManagementListComponent<PaperlessS
directoryService: StoragePathService,
modalService: NgbModal,
toastService: ToastService,
queryParamsService: QueryParamsService
documentListViewService: DocumentListViewService
) {
super(
directoryService,
modalService,
StoragePathEditDialogComponent,
toastService,
queryParamsService,
documentListViewService,
FILTER_STORAGE_PATH,
$localize`storage path`,
$localize`storage paths`,
Expand Down
Expand Up @@ -2,7 +2,7 @@ import { Component } from '@angular/core'
import { NgbModal } from '@ng-bootstrap/ng-bootstrap'
import { FILTER_HAS_TAGS_ALL } from 'src/app/data/filter-rule-type'
import { PaperlessTag } from 'src/app/data/paperless-tag'
import { QueryParamsService } from 'src/app/services/query-params.service'
import { DocumentListViewService } from 'src/app/services/document-list-view.service'
import { TagService } from 'src/app/services/rest/tag.service'
import { ToastService } from 'src/app/services/toast.service'
import { TagEditDialogComponent } from '../../common/edit-dialog/tag-edit-dialog/tag-edit-dialog.component'
Expand All @@ -18,14 +18,14 @@ export class TagListComponent extends ManagementListComponent<PaperlessTag> {
tagService: TagService,
modalService: NgbModal,
toastService: ToastService,
queryParamsService: QueryParamsService
documentListViewService: DocumentListViewService
) {
super(
tagService,
modalService,
TagEditDialogComponent,
toastService,
queryParamsService,
documentListViewService,
FILTER_HAS_TAGS_ALL,
$localize`tag`,
$localize`tags`,
Expand Down