mirror of
https://github.com/paperless-ngx/paperless-ngx.git
synced 2026-11-21 21:12:40 +00:00
Wire in the collapseTags, split and parentClick. Update get more tags too
This commit is contained in:
10 files changed
+64
-27
No files matched your search
+2
-2
@@ -76,8 +76,8 @@
|
||||
}
|
||||
}
|
||||
@case (DisplayField.TAGS) {
|
||||
@for (tagID of doc.tags; track tagID) {
|
||||
<pngx-tag [tagID]="tagID" class="ms-1 fs-6" (click)="clickTag(tagID, $event)" [clickable]="true" linkTitle="Filter by tag" i18n-title></pngx-tag>
|
||||
@for (tagID of doc.tags | collapseTags | async; track tagID) {
|
||||
<pngx-tag [tagID]="tagID" [split]="true" class="ms-1 fs-6" (click)="clickTag(tagID, $event)" (parentClick)="clickTag($event)" [clickable]="true" linkTitle="Filter by tag" i18n-title></pngx-tag>
|
||||
}
|
||||
}
|
||||
@case (DisplayField.DOCUMENT_TYPE) {
|
||||
|
||||
+2
@@ -38,6 +38,7 @@ import {
|
||||
} from 'src/app/data/filter-rule-type'
|
||||
import { SavedView } from 'src/app/data/saved-view'
|
||||
import { IfPermissionsDirective } from 'src/app/directives/if-permissions.directive'
|
||||
import { CollapseTagsPipe } from 'src/app/pipes/collapse-tags.pipe'
|
||||
import { CorrespondentNamePipe } from 'src/app/pipes/correspondent-name.pipe'
|
||||
import { CustomDatePipe } from 'src/app/pipes/custom-date.pipe'
|
||||
import { DocumentTitlePipe } from 'src/app/pipes/document-title.pipe'
|
||||
@@ -75,6 +76,7 @@ import { WidgetFrameComponent } from '../widget-frame/widget-frame.component'
|
||||
DocumentTypeNamePipe,
|
||||
StoragePathNamePipe,
|
||||
AsyncPipe,
|
||||
CollapseTagsPipe,
|
||||
DocumentTitlePipe,
|
||||
CustomDatePipe,
|
||||
NgClass,
|
||||
|
||||
+2
-2
@@ -36,8 +36,8 @@
|
||||
{{document().title | documentTitle}}
|
||||
}
|
||||
@if (displayFields().includes(DisplayField.TAGS)) {
|
||||
@for (tagID of document().tags; track tagID) {
|
||||
<pngx-tag [tagID]="tagID" linkTitle="Filter by tag" i18n-linkTitle class="ms-1" (click)="clickTag.emit(tagID);$event.stopPropagation()" [clickable]="clickTag.observers.length"></pngx-tag>
|
||||
@for (tagID of document().tags | collapseTags | async; track tagID) {
|
||||
<pngx-tag [tagID]="tagID" [split]="true" linkTitle="Filter by tag" i18n-linkTitle class="ms-1" (click)="clickTag.emit(tagID);$event.stopPropagation()" (parentClick)="clickTag.emit($event)" [clickable]="clickTag.observers.length"></pngx-tag>
|
||||
}
|
||||
}
|
||||
} @else {
|
||||
|
||||
+2
@@ -20,6 +20,7 @@ import {
|
||||
Document,
|
||||
} from 'src/app/data/document'
|
||||
import { SETTINGS_KEYS } from 'src/app/data/ui-settings'
|
||||
import { CollapseTagsPipe } from 'src/app/pipes/collapse-tags.pipe'
|
||||
import { CorrespondentNamePipe } from 'src/app/pipes/correspondent-name.pipe'
|
||||
import { CustomDatePipe } from 'src/app/pipes/custom-date.pipe'
|
||||
import { DocumentTitlePipe } from 'src/app/pipes/document-title.pipe'
|
||||
@@ -45,6 +46,7 @@ import { LoadingComponentWithPermissions } from '../../loading-component/loading
|
||||
TagComponent,
|
||||
CustomFieldDisplayComponent,
|
||||
AsyncPipe,
|
||||
CollapseTagsPipe,
|
||||
NgOptimizedImage,
|
||||
UsernamePipe,
|
||||
CorrespondentNamePipe,
|
||||
|
||||
+5
-4
@@ -19,11 +19,12 @@
|
||||
}
|
||||
|
||||
@if (document() && displayFields().includes(DisplayField.TAGS)) {
|
||||
<div class="tags d-flex flex-column text-end position-absolute me-1 fs-6" [class.tags-no-wrap]="document().tags.length > 3">
|
||||
@for (tagID of tagIDs; track tagID) {
|
||||
<pngx-tag [tagID]="tagID" (click)="clickTag.emit(tagID);$event.stopPropagation()" [clickable]="true" linkTitle="Toggle tag filter" i18n-linkTitle></pngx-tag>
|
||||
@let visibleTagIDs = document().tags | collapseTags | async;
|
||||
<div class="tags d-flex flex-column text-end position-absolute me-1 fs-6" [class.tags-no-wrap]="visibleTagIDs?.length > 3">
|
||||
@for (tagID of getTagIDs(visibleTagIDs); track tagID) {
|
||||
<pngx-tag [tagID]="tagID" [split]="true" (click)="clickTag.emit(tagID);$event.stopPropagation()" (parentClick)="clickTag.emit($event)" [clickable]="true" linkTitle="Toggle tag filter" i18n-linkTitle></pngx-tag>
|
||||
}
|
||||
@if (moreTags) {
|
||||
@if (getMoreTags(visibleTagIDs); as moreTags) {
|
||||
<div>
|
||||
<span class="badge text-dark">+ {{moreTags}}</span>
|
||||
</div>
|
||||
|
||||
+2
-1
@@ -103,7 +103,8 @@ a {
|
||||
line-height: 1;
|
||||
|
||||
&.tags-no-wrap {
|
||||
::ng-deep .badge {
|
||||
// split-pill parents clip to a stub instead (see TagComponent)
|
||||
::ng-deep .badge:not(.split-parent) {
|
||||
display: inline-block;
|
||||
max-width: 100%;
|
||||
white-space: nowrap;
|
||||
|
||||
+33
-2
@@ -4,6 +4,9 @@ import { provideHttpClientTesting } from '@angular/common/http/testing'
|
||||
import { ComponentFixture, TestBed } from '@angular/core/testing'
|
||||
import { By } from '@angular/platform-browser'
|
||||
import { RouterTestingModule } from '@angular/router/testing'
|
||||
import { of } from 'rxjs'
|
||||
import { PermissionsService } from 'src/app/services/permissions.service'
|
||||
import { TagService } from 'src/app/services/rest/tag.service'
|
||||
import { TagComponent } from '../../common/tag/tag.component'
|
||||
import { DocumentCardSmallComponent } from './document-card-small.component'
|
||||
|
||||
@@ -97,8 +100,36 @@ describe('DocumentCardSmallComponent', () => {
|
||||
).toHaveLength(6)
|
||||
})
|
||||
|
||||
it('should hide parent tags implied by a child and count pills for the hidden tag counter', () => {
|
||||
jest
|
||||
.spyOn(TestBed.inject(PermissionsService), 'currentUserCan')
|
||||
.mockReturnValue(true)
|
||||
jest.spyOn(TestBed.inject(TagService), 'listAll').mockReturnValue(
|
||||
of({
|
||||
count: 8,
|
||||
all: [1, 2, 3, 4, 5, 6, 7, 8],
|
||||
results: [
|
||||
{ id: 1, name: 'Parent' },
|
||||
{ id: 2, name: 'Child', parent: 1 },
|
||||
...[3, 4, 5, 6, 7, 8].map((id) => ({ id, name: `Tag ${id}` })),
|
||||
],
|
||||
})
|
||||
)
|
||||
fixture.componentRef.setInput('document', {
|
||||
...component.document(),
|
||||
tags: [1, 2, 3, 4, 5, 6, 7, 8],
|
||||
})
|
||||
fixture.detectChanges()
|
||||
|
||||
const tags = fixture.debugElement.queryAll(By.directive(TagComponent))
|
||||
expect(tags.map((t) => t.componentInstance.tagID())).toEqual([
|
||||
2, 3, 4, 5, 6,
|
||||
])
|
||||
expect(fixture.nativeElement.textContent).toContain('+ 2')
|
||||
})
|
||||
|
||||
it('should clear hidden tag counter when tag count falls below the limit', () => {
|
||||
expect(component.moreTags).toEqual(3)
|
||||
expect(component.getMoreTags(component.document().tags)).toEqual(3)
|
||||
|
||||
fixture.componentRef.setInput('document', {
|
||||
...component.document(),
|
||||
@@ -106,7 +137,7 @@ describe('DocumentCardSmallComponent', () => {
|
||||
})
|
||||
fixture.detectChanges()
|
||||
|
||||
expect(component.moreTags).toBeNull()
|
||||
expect(component.getMoreTags(component.document().tags)).toBeNull()
|
||||
expect(fixture.nativeElement.textContent).not.toContain('+ 3')
|
||||
})
|
||||
|
||||
|
||||
+12
-14
@@ -20,6 +20,7 @@ import {
|
||||
Document,
|
||||
} from 'src/app/data/document'
|
||||
import { SETTINGS_KEYS } from 'src/app/data/ui-settings'
|
||||
import { CollapseTagsPipe } from 'src/app/pipes/collapse-tags.pipe'
|
||||
import { CorrespondentNamePipe } from 'src/app/pipes/correspondent-name.pipe'
|
||||
import { CustomDatePipe } from 'src/app/pipes/custom-date.pipe'
|
||||
import { DocumentTitlePipe } from 'src/app/pipes/document-title.pipe'
|
||||
@@ -45,6 +46,7 @@ import { LoadingComponentWithPermissions } from '../../loading-component/loading
|
||||
TagComponent,
|
||||
CustomFieldDisplayComponent,
|
||||
AsyncPipe,
|
||||
CollapseTagsPipe,
|
||||
NgOptimizedImage,
|
||||
UsernamePipe,
|
||||
CorrespondentNamePipe,
|
||||
@@ -90,12 +92,13 @@ export class DocumentCardSmallComponent
|
||||
@Output()
|
||||
clickStoragePath = new EventEmitter<number>()
|
||||
|
||||
get moreTags(): number {
|
||||
const document = this.document()
|
||||
const limit = document?.notes.length > 0 ? 6 : 7
|
||||
return document?.tags.length > limit
|
||||
? document.tags.length - (limit - 1)
|
||||
: null
|
||||
private get tagLimit(): number {
|
||||
return this.document()?.notes.length > 0 ? 6 : 7
|
||||
}
|
||||
|
||||
getMoreTags(tagIDs: number[]): number {
|
||||
const limit = this.tagLimit
|
||||
return tagIDs?.length > limit ? tagIDs.length - (limit - 1) : null
|
||||
}
|
||||
|
||||
@ViewChild('popupPreview') popupPreview: PreviewPopupComponent
|
||||
@@ -116,14 +119,9 @@ export class DocumentCardSmallComponent
|
||||
return this.documentService.getDownloadUrl(this.document().id)
|
||||
}
|
||||
|
||||
get tagIDs() {
|
||||
const document = this.document()
|
||||
const limit = document.notes.length > 0 ? 6 : 7
|
||||
if (document.tags.length > limit) {
|
||||
return document.tags.slice(0, limit - 1)
|
||||
} else {
|
||||
return document.tags
|
||||
}
|
||||
getTagIDs(tagIDs: number[]): number[] {
|
||||
const limit = this.tagLimit
|
||||
return tagIDs?.length > limit ? tagIDs.slice(0, limit - 1) : tagIDs
|
||||
}
|
||||
|
||||
mouseLeaveCard() {
|
||||
|
||||
@@ -335,8 +335,8 @@
|
||||
<a routerLink="/documents/{{d.id}}" title="Edit document" i18n-title style="overflow-wrap: anywhere;">{{d.title | documentTitle}}</a>
|
||||
}
|
||||
@if (activeDisplayFields.includes(DisplayField.TAGS)) {
|
||||
@for (tagID of d.tags; track tagID) {
|
||||
<pngx-tag [tagID]="tagID" class="ms-1 fs-6" clickable="true" linkTitle="Filter by tag" i18n-linkTitle (click)="clickTag(tagID);$event.stopPropagation()"></pngx-tag>
|
||||
@for (tagID of d.tags | collapseTags | async; track tagID) {
|
||||
<pngx-tag [tagID]="tagID" [split]="true" class="ms-1 fs-6" clickable="true" linkTitle="Filter by tag" i18n-linkTitle (click)="clickTag(tagID);$event.stopPropagation()" (parentClick)="clickTag($event)"></pngx-tag>
|
||||
}
|
||||
}
|
||||
</td>
|
||||
|
||||
@@ -39,6 +39,7 @@ import {
|
||||
SortableDirective,
|
||||
SortEvent,
|
||||
} from 'src/app/directives/sortable.directive'
|
||||
import { CollapseTagsPipe } from 'src/app/pipes/collapse-tags.pipe'
|
||||
import { CorrespondentNamePipe } from 'src/app/pipes/correspondent-name.pipe'
|
||||
import { CustomDatePipe } from 'src/app/pipes/custom-date.pipe'
|
||||
import { DocumentTitlePipe } from 'src/app/pipes/document-title.pipe'
|
||||
@@ -96,6 +97,7 @@ import { SaveViewConfigDialogComponent } from './save-view-config-dialog/save-vi
|
||||
StoragePathNamePipe,
|
||||
BootstrapIconComponent,
|
||||
AsyncPipe,
|
||||
CollapseTagsPipe,
|
||||
FormsModule,
|
||||
ReactiveFormsModule,
|
||||
NgTemplateOutlet,
|
||||
|
||||
Reference in new issue
Block a user