From 4b70c278a960a8d43407f0039aa03d0b08b44f9c Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Fri, 26 May 2023 10:27:02 +0200 Subject: Automatic colspan for tables --- .../abuse-list-table.component.html | 6 +++--- .../shared-main/angular/auto-colspan.directive.ts | 22 ++++++++++++++++++++++ client/src/app/shared/shared-main/angular/index.ts | 1 + .../app/shared/shared-main/shared-main.module.ts | 3 +++ .../account-blocklist.component.html | 2 +- .../server-blocklist.component.html | 2 +- 6 files changed, 31 insertions(+), 5 deletions(-) create mode 100644 client/src/app/shared/shared-main/angular/auto-colspan.directive.ts (limited to 'client/src/app/shared') diff --git a/client/src/app/shared/shared-abuse-list/abuse-list-table.component.html b/client/src/app/shared/shared-abuse-list/abuse-list-table.component.html index 2571cc952..5833e3465 100644 --- a/client/src/app/shared/shared-abuse-list/abuse-list-table.component.html +++ b/client/src/app/shared/shared-abuse-list/abuse-list-table.component.html @@ -136,10 +136,10 @@ - + - + @@ -147,7 +147,7 @@ - +
No abuses found matching current filters. No abuses found. diff --git a/client/src/app/shared/shared-main/angular/auto-colspan.directive.ts b/client/src/app/shared/shared-main/angular/auto-colspan.directive.ts new file mode 100644 index 000000000..8da89b668 --- /dev/null +++ b/client/src/app/shared/shared-main/angular/auto-colspan.directive.ts @@ -0,0 +1,22 @@ +import { AfterViewInit, Directive, ElementRef, Renderer2 } from '@angular/core' + +@Directive({ + selector: '[myAutoColspan]' +}) +export class AutoColspanDirective implements AfterViewInit { + + constructor ( + private host: ElementRef, + private renderer: Renderer2 + ) { } + + ngAfterViewInit () { + const el = this.host.nativeElement as HTMLElement + const table = el.closest('table') + if (!table) throw new Error('table element not found') + + const th = table.querySelectorAll('th') + + this.renderer.setAttribute(el, 'colspan', th.length + '') + } +} diff --git a/client/src/app/shared/shared-main/angular/index.ts b/client/src/app/shared/shared-main/angular/index.ts index f72d60313..6ea494129 100644 --- a/client/src/app/shared/shared-main/angular/index.ts +++ b/client/src/app/shared/shared-main/angular/index.ts @@ -1,3 +1,4 @@ +export * from './auto-colspan.directive' export * from './autofocus.directive' export * from './bytes.pipe' export * from './defer-loading.directive' diff --git a/client/src/app/shared/shared-main/shared-main.module.ts b/client/src/app/shared/shared-main/shared-main.module.ts index 0bdf27263..d3ec31d6e 100644 --- a/client/src/app/shared/shared-main/shared-main.module.ts +++ b/client/src/app/shared/shared-main/shared-main.module.ts @@ -18,6 +18,7 @@ import { LoadingBarHttpClientModule } from '@ngx-loading-bar/http-client' import { SharedGlobalIconModule } from '../shared-icons' import { AccountService, SignupLabelComponent } from './account' import { + AutoColspanDirective, AutofocusDirective, BytesPipe, DeferLoadingDirective, @@ -89,6 +90,7 @@ import { VideoChannelService } from './video-channel' DurationFormatterPipe, AutofocusDirective, DeferLoadingDirective, + AutoColspanDirective, InfiniteScrollerDirective, PeerTubeTemplateDirective, @@ -150,6 +152,7 @@ import { VideoChannelService } from './video-channel' DurationFormatterPipe, AutofocusDirective, DeferLoadingDirective, + AutoColspanDirective, InfiniteScrollerDirective, PeerTubeTemplateDirective, diff --git a/client/src/app/shared/shared-moderation/account-blocklist.component.html b/client/src/app/shared/shared-moderation/account-blocklist.component.html index 8cf9aa4c9..609a8cecd 100644 --- a/client/src/app/shared/shared-moderation/account-blocklist.component.html +++ b/client/src/app/shared/shared-moderation/account-blocklist.component.html @@ -49,7 +49,7 @@ - +
No account found matching current filters. No account found. diff --git a/client/src/app/shared/shared-moderation/server-blocklist.component.html b/client/src/app/shared/shared-moderation/server-blocklist.component.html index 1a13e0207..a98333339 100644 --- a/client/src/app/shared/shared-moderation/server-blocklist.component.html +++ b/client/src/app/shared/shared-moderation/server-blocklist.component.html @@ -51,7 +51,7 @@ - +
No server found matching current filters. No server found. -- cgit v1.2.3