Dynamic counts include all pages, hide for "Any"

This commit is contained in:
shamoon 2023-05-05 01:01:57 -07:00
parent 02875f5a34
commit c59420581c
6 changed files with 31 additions and 10 deletions

View File

@ -34,7 +34,7 @@
<div *ngIf="selectionModel.items" class="items" #buttonItems>
<ng-container *ngFor="let item of selectionModel.itemsSorted | filter: filterText; let i = index">
<app-toggleable-dropdown-button
*ngIf="allowSelectNone || item.id" [item]="item" [state]="selectionModel.get(item.id)" [count]="getUpdatedDocumentCount(item.id)" (toggle)="selectionModel.toggle(item.id)" (exclude)="excludeClicked(item.id)" (click)="setButtonItemIndex(i)" [disabled]="disabled">
*ngIf="allowSelectNone || item.id" [item]="item" [hideCount]="hideCount(item)" [state]="selectionModel.get(item.id)" [count]="getUpdatedDocumentCount(item.id)" (toggle)="selectionModel.toggle(item.id)" (exclude)="excludeClicked(item.id)" (click)="setButtonItemIndex(i)" [disabled]="disabled">
</app-toggleable-dropdown-button>
</ng-container>
</div>

View File

@ -12,6 +12,7 @@ import { ToggleableItemState } from './toggleable-dropdown-button/toggleable-dro
import { MatchingModel } from 'src/app/data/matching-model'
import { Subject } from 'rxjs'
import { SelectionDataItem } from 'src/app/services/rest/document.service'
import { ObjectWithPermissions } from 'src/app/data/object-with-permissions'
export interface ChangedItems {
itemsToAdd: MatchingModel[]
@ -552,4 +553,13 @@ export class FilterableDropdownComponent {
// just track the index in case user uses arrows
this.keyboardIndex = index
}
hideCount(item: ObjectWithPermissions) {
// counts are pointless when clicking item would add to the set of docs
return (
this.selectionModel.logicalOperator === LogicalOperator.Or &&
this.manyToOne &&
this.selectionModel.get(item.id) !== ToggleableItemState.Selected
)
}
}

View File

@ -20,5 +20,5 @@
<app-tag *ngIf="isTag; else displayName" [tag]="item" [clickable]="false"></app-tag>
<ng-template #displayName><small>{{item.name}}</small></ng-template>
</div>
<div class="badge bg-light text-dark rounded-pill ms-auto me-1">{{count ?? item.document_count}}</div>
<div *ngIf="!hideCount" class="badge bg-light text-dark rounded-pill ms-auto me-1">{{count ?? item.document_count}}</div>
</button>

View File

@ -26,6 +26,9 @@ export class ToggleableDropdownButtonComponent {
@Input()
disabled: boolean = false
@Input()
hideCount: boolean = false
@Output()
toggle = new EventEmitter()

View File

@ -1,6 +1,6 @@
import { Injectable } from '@angular/core'
import { ParamMap, Router } from '@angular/router'
import { Observable } from 'rxjs'
import { Observable, first } from 'rxjs'
import {
filterRulesDiffer,
cloneFilterRules,
@ -230,13 +230,21 @@ export class DocumentListViewService {
activeListViewState.documents = result.results
this.documentService
.getSelectionData(result.results.map((d) => d.id))
.listAllFilteredIds(activeListViewState.filterRules)
.pipe(first())
.subscribe({
next: (selectionData) => {
this.selectionData = selectionData
},
error: () => {
this.selectionData = null
next: (ids: number[]) => {
this.documentService
.getSelectionData(ids)
.pipe(first())
.subscribe({
next: (selectionData) => {
this.selectionData = selectionData
},
error: () => {
this.selectionData = null
},
})
},
})

View File

@ -422,7 +422,7 @@ class DocumentSerializer(OwnedObjectSerializer, DynamicFieldsModelSerializer):
def to_representation(self, instance):
doc = super().to_representation(instance)
if self.truncate_content:
if self.truncate_content and "content" in self.fields:
doc["content"] = doc.get("content")[0:550]
return doc