mirror of
https://github.com/paperless-ngx/paperless-ngx.git
synced 2025-04-09 09:58:20 -05:00
Refactor: fix unnecessary use of filterable dropdown sorting (#8328)
This commit is contained in:
parent
f6cc2f9fc3
commit
447b4cdb98
@ -35,7 +35,7 @@
|
|||||||
</div>
|
</div>
|
||||||
@if (selectionModel.items) {
|
@if (selectionModel.items) {
|
||||||
<div class="items" #buttonItems>
|
<div class="items" #buttonItems>
|
||||||
@for (item of selectionModel.itemsSorted | filter: filterText:'name'; track item; let i = $index) {
|
@for (item of selectionModel.items | filter: filterText:'name'; track item; let i = $index) {
|
||||||
@if (allowSelectNone || item.id) {
|
@if (allowSelectNone || item.id) {
|
||||||
<pngx-toggleable-dropdown-button
|
<pngx-toggleable-dropdown-button
|
||||||
[item]="item" [hideCount]="hideCount(item)" [state]="selectionModel.get(item.id)" [count]="getUpdatedDocumentCount(item.id)" (toggled)="selectionModel.toggle(item.id)" (exclude)="excludeClicked(item.id)" (click)="setButtonItemIndex(i - 1)" [disabled]="disabled">
|
[item]="item" [hideCount]="hideCount(item)" [state]="selectionModel.get(item.id)" [count]="getUpdatedDocumentCount(item.id)" (toggled)="selectionModel.toggle(item.id)" (exclude)="excludeClicked(item.id)" (click)="setButtonItemIndex(i - 1)" [disabled]="disabled">
|
||||||
@ -45,13 +45,13 @@
|
|||||||
</div>
|
</div>
|
||||||
}
|
}
|
||||||
@if (editing) {
|
@if (editing) {
|
||||||
@if ((selectionModel.itemsSorted | filter: filterText:'name').length === 0 && createRef !== undefined) {
|
@if ((selectionModel.items | filter: filterText:'name').length === 0 && createRef !== undefined) {
|
||||||
<button class="list-group-item list-group-item-action bg-light" (click)="createClicked()" [disabled]="disabled">
|
<button class="list-group-item list-group-item-action bg-light" (click)="createClicked()" [disabled]="disabled">
|
||||||
<small class="ms-2"><ng-container i18n>Create</ng-container> "{{filterText}}"</small>
|
<small class="ms-2"><ng-container i18n>Create</ng-container> "{{filterText}}"</small>
|
||||||
<i-bs width="1.5em" height="1em" name="plus"></i-bs>
|
<i-bs width="1.5em" height="1em" name="plus"></i-bs>
|
||||||
</button>
|
</button>
|
||||||
}
|
}
|
||||||
@if ((selectionModel.itemsSorted | filter: filterText:'name').length > 0) {
|
@if ((selectionModel.items | filter: filterText:'name').length > 0) {
|
||||||
<button class="list-group-item list-group-item-action bg-light" (click)="applyClicked()" [disabled]="!modelIsDirty || disabled">
|
<button class="list-group-item list-group-item-action bg-light" (click)="applyClicked()" [disabled]="!modelIsDirty || disabled">
|
||||||
<small class="ms-2" [ngClass]="{'fw-bold': modelIsDirty}" i18n>Apply</small>
|
<small class="ms-2" [ngClass]="{'fw-bold': modelIsDirty}" i18n>Apply</small>
|
||||||
<i-bs width="1.5em" height="1em" name="arrow-right"></i-bs>
|
<i-bs width="1.5em" height="1em" name="arrow-right"></i-bs>
|
||||||
|
@ -501,7 +501,7 @@ describe('FilterableDropdownComponent & FilterableDropdownSelectionModel', () =>
|
|||||||
component.selectionModel = selectionModel
|
component.selectionModel = selectionModel
|
||||||
selectionModel.toggle(items[1].id)
|
selectionModel.toggle(items[1].id)
|
||||||
selectionModel.apply()
|
selectionModel.apply()
|
||||||
expect(selectionModel.itemsSorted).toEqual([
|
expect(selectionModel.items).toEqual([
|
||||||
nullItem,
|
nullItem,
|
||||||
{ id: null, name: 'Null B' },
|
{ id: null, name: 'Null B' },
|
||||||
items[1],
|
items[1],
|
||||||
|
@ -43,11 +43,18 @@ export class FilterableDropdownSelectionModel {
|
|||||||
private _intersection: Intersection = Intersection.Include
|
private _intersection: Intersection = Intersection.Include
|
||||||
temporaryIntersection: Intersection = this._intersection
|
temporaryIntersection: Intersection = this._intersection
|
||||||
|
|
||||||
items: MatchingModel[] = []
|
private _items: MatchingModel[] = []
|
||||||
|
get items(): MatchingModel[] {
|
||||||
|
return this._items
|
||||||
|
}
|
||||||
|
|
||||||
get itemsSorted(): MatchingModel[] {
|
set items(items: MatchingModel[]) {
|
||||||
// TODO: this is getting called very often
|
this._items = items
|
||||||
return this.items.sort((a, b) => {
|
this.sortItems()
|
||||||
|
}
|
||||||
|
|
||||||
|
private sortItems() {
|
||||||
|
this._items.sort((a, b) => {
|
||||||
if (a.id == null && b.id != null) {
|
if (a.id == null && b.id != null) {
|
||||||
return -1
|
return -1
|
||||||
} else if (a.id != null && b.id == null) {
|
} else if (a.id != null && b.id == null) {
|
||||||
@ -291,6 +298,7 @@ export class FilterableDropdownSelectionModel {
|
|||||||
})
|
})
|
||||||
this._logicalOperator = this.temporaryLogicalOperator
|
this._logicalOperator = this.temporaryLogicalOperator
|
||||||
this._intersection = this.temporaryIntersection
|
this._intersection = this.temporaryIntersection
|
||||||
|
this.sortItems()
|
||||||
}
|
}
|
||||||
|
|
||||||
reset(complete: boolean = false) {
|
reset(complete: boolean = false) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user