mirror of
https://github.com/paperless-ngx/paperless-ngx.git
synced 2026-11-21 21:12:40 +00:00
actual css animation stuff for the tag and hover, ancestor parsing and parent click output
This commit is contained in:
3 files changed
+162
-24
No files matched your search
@@ -1,13 +1,18 @@
|
||||
@if (tag()) {
|
||||
@if (showParents() && tag().parent) {
|
||||
<pngx-tag [tagID]="tag().parent" [clickable]="clickable()" [linkTitle]="linkTitle()"></pngx-tag>
|
||||
>
|
||||
}
|
||||
@if (!clickable()) {
|
||||
<span class="badge" [style.background]="tag().color" [style.color]="tag().text_color">{{tag().name}}</span>
|
||||
}
|
||||
@if (clickable()) {
|
||||
<a [title]="linkTitle()" class="badge" [style.background]="tag().color" [style.color]="tag().text_color">{{tag().name}}</a>
|
||||
@if (ancestorSegments.length) {
|
||||
<span #pill class="split-pill d-inline-flex mw-100" [title]="path()" (mouseleave)="setFocus(pill, null)">
|
||||
@for (ancestor of ancestorSegments; track ancestor.id; let first = $first) {
|
||||
<span #segment class="badge split-parent" [class.rounded-end-0]="first" [class.rounded-0]="!first" [style.background]="ancestor.color" [style.color]="ancestor.text_color" (mouseenter)="setFocus(pill, segment)" (click)="onParentClick($event, ancestor.id)">{{ancestor.name}}</span>
|
||||
}
|
||||
<span #leaf class="badge rounded-start-0 split-child" [style.background]="tag().color" [style.color]="tag().text_color" (mouseenter)="setFocus(pill, leaf)">{{tag().name}}</span>
|
||||
</span>
|
||||
} @else {
|
||||
@if (!clickable()) {
|
||||
<span class="badge" [style.background]="tag().color" [style.color]="tag().text_color">{{tag().name}}</span>
|
||||
}
|
||||
@if (clickable()) {
|
||||
<a [title]="linkTitle()" class="badge" [style.background]="tag().color" [style.color]="tag().text_color">{{tag().name}}</a>
|
||||
}
|
||||
}
|
||||
} @else if (loading) {
|
||||
<span class="placeholder-glow">
|
||||
|
||||
@@ -11,3 +11,45 @@ a, span {
|
||||
opacity: .5;
|
||||
font-style: italic;
|
||||
}
|
||||
|
||||
.split-parent,
|
||||
.split-child {
|
||||
overflow: hidden;
|
||||
white-space: nowrap;
|
||||
transition: color .2s ease;
|
||||
}
|
||||
|
||||
.split-parent {
|
||||
min-width: 1.5em;
|
||||
max-width: 10em;
|
||||
padding-inline: .4em;
|
||||
text-overflow: clip;
|
||||
|
||||
&:nth-last-child(2) { flex-shrink: 1e12; }
|
||||
&:nth-last-child(3) { flex-shrink: 1e18; }
|
||||
&:nth-last-child(4) { flex-shrink: 1e24; }
|
||||
&:nth-last-child(5) { flex-shrink: 1e30; }
|
||||
|
||||
&.collapsed {
|
||||
color: transparent !important;
|
||||
}
|
||||
}
|
||||
|
||||
.split-child {
|
||||
flex-shrink: 1e6;
|
||||
min-width: 2em;
|
||||
text-overflow: ellipsis;
|
||||
}
|
||||
|
||||
// Hovered segment gets priority, other parents can shrink to a sliver
|
||||
.split-pill {
|
||||
> .split-parent.focused,
|
||||
> .split-child.focused {
|
||||
flex-shrink: 1;
|
||||
text-overflow: ellipsis;
|
||||
}
|
||||
|
||||
&:has(> .focused) > .split-parent:not(.focused) {
|
||||
min-width: 0;
|
||||
}
|
||||
}
|
||||
@@ -1,11 +1,27 @@
|
||||
import { Component, effect, inject, input, model } from '@angular/core'
|
||||
import {
|
||||
Component,
|
||||
computed,
|
||||
effect,
|
||||
inject,
|
||||
input,
|
||||
model,
|
||||
output,
|
||||
signal,
|
||||
} from '@angular/core'
|
||||
import { Tag } from 'src/app/data/tag'
|
||||
import { SETTINGS_KEYS } from 'src/app/data/ui-settings'
|
||||
import {
|
||||
PermissionAction,
|
||||
PermissionsService,
|
||||
PermissionType,
|
||||
} from 'src/app/services/permissions.service'
|
||||
import { TagService } from 'src/app/services/rest/tag.service'
|
||||
import { SettingsService } from 'src/app/services/settings.service'
|
||||
import { getTagAncestors } from 'src/app/utils/collapse-tags'
|
||||
|
||||
const FOCUS_ANIMATION_MS = 200
|
||||
// matches the .split-parent min-width in tag.component.scss
|
||||
const COLLAPSE_BELOW_EM = 1.5
|
||||
|
||||
@Component({
|
||||
selector: 'pngx-tag',
|
||||
@@ -13,8 +29,9 @@ import { TagService } from 'src/app/services/rest/tag.service'
|
||||
styleUrls: ['./tag.component.scss'],
|
||||
})
|
||||
export class TagComponent {
|
||||
private permissionsService = inject(PermissionsService)
|
||||
private tagService = inject(TagService)
|
||||
private readonly permissionsService = inject(PermissionsService)
|
||||
private readonly tagService = inject(TagService)
|
||||
private readonly settingsService = inject(SettingsService)
|
||||
|
||||
readonly tag = model<Tag>(null)
|
||||
readonly tagID = input<number>(undefined)
|
||||
@@ -23,27 +40,101 @@ export class TagComponent {
|
||||
transform: (value: boolean | string) =>
|
||||
value === '' || value === true || value === 'true',
|
||||
})
|
||||
readonly showParents = input(false)
|
||||
|
||||
readonly split = input(false)
|
||||
|
||||
readonly parentClick = output<number>()
|
||||
|
||||
private readonly ancestors = signal<Tag[]>([])
|
||||
|
||||
public get ancestorSegments(): Tag[] {
|
||||
return this.split() &&
|
||||
this.settingsService.get(SETTINGS_KEYS.TAGS_SHOW_HIERARCHY)
|
||||
? this.ancestors()
|
||||
: []
|
||||
}
|
||||
|
||||
public readonly path = computed(() =>
|
||||
[...this.ancestors(), this.tag()]
|
||||
.filter(Boolean)
|
||||
.map((t) => t.name)
|
||||
.join(' › ')
|
||||
)
|
||||
|
||||
constructor() {
|
||||
effect(() => {
|
||||
const tagID = this.tagID()
|
||||
if (tagID) {
|
||||
if (
|
||||
this.permissionsService.currentUserCan(
|
||||
PermissionAction.View,
|
||||
PermissionType.Tag
|
||||
)
|
||||
) {
|
||||
this.tagService.getCached(tagID).subscribe((tag) => {
|
||||
this.tag.set(tag)
|
||||
})
|
||||
}
|
||||
if (tagID && this.canViewTags) {
|
||||
this.tagService.getCached(tagID).subscribe((tag) => {
|
||||
this.tag.set(tag)
|
||||
})
|
||||
}
|
||||
})
|
||||
|
||||
// ancestors for split badges, from either tagID or a passed-in tag
|
||||
effect(() => {
|
||||
const id = this.tagID() || this.tag()?.id
|
||||
if (!this.split() || !id || !this.canViewTags) {
|
||||
this.ancestors.set([])
|
||||
return
|
||||
}
|
||||
this.tagService.listAll().subscribe((tags) => {
|
||||
this.ancestors.set(
|
||||
getTagAncestors(
|
||||
id,
|
||||
new Map<number, Tag>(tags.results.map((t) => [t.id, t]))
|
||||
)
|
||||
)
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
private get canViewTags(): boolean {
|
||||
return this.permissionsService.currentUserCan(
|
||||
PermissionAction.View,
|
||||
PermissionType.Tag
|
||||
)
|
||||
}
|
||||
|
||||
public get loading(): boolean {
|
||||
return this.tagService.loading
|
||||
}
|
||||
|
||||
/**
|
||||
* Gives the hovered segment priority (.focused class, see scss)
|
||||
* and animates each from old width to new
|
||||
*/
|
||||
setFocus(segment: HTMLElement, focused: HTMLElement | null) {
|
||||
const segments = Array.from(segment.children) as HTMLElement[]
|
||||
const before = segments.map((s) => s.getBoundingClientRect().width)
|
||||
for (const segment of segments) {
|
||||
segment.getAnimations().forEach((a) => a.cancel())
|
||||
segment.classList.toggle('focused', segment === focused)
|
||||
}
|
||||
const after = segments.map((s) => s.getBoundingClientRect().width)
|
||||
|
||||
segments.forEach((segment, i) => {
|
||||
const em = Number.parseFloat(getComputedStyle(segment).fontSize)
|
||||
segment.classList.toggle(
|
||||
'collapsed',
|
||||
!!focused &&
|
||||
segment.classList.contains('split-parent') &&
|
||||
after[i] < COLLAPSE_BELOW_EM * em
|
||||
)
|
||||
if (Math.abs(after[i] - before[i]) < 0.5) return
|
||||
segment.animate(
|
||||
[
|
||||
{ flex: `0 0 ${before[i]}px`, minWidth: 0 },
|
||||
{ flex: `0 0 ${after[i]}px`, minWidth: 0 },
|
||||
],
|
||||
{ duration: FOCUS_ANIMATION_MS, easing: 'ease' }
|
||||
)
|
||||
})
|
||||
}
|
||||
|
||||
onParentClick(event: MouseEvent, id: number) {
|
||||
event.preventDefault()
|
||||
event.stopImmediatePropagation()
|
||||
this.parentClick.emit(id)
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user