From 8afade2607e072221a8ff8c108bd1787a3501a2d Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Fri, 26 Nov 2021 17:36:44 +0100 Subject: Introduce plugin id selectors --- client/src/app/shared/shared-main/plugins/index.ts | 1 + .../plugins/plugin-selector.directive.ts | 21 +++++++++++++++++++++ 2 files changed, 22 insertions(+) create mode 100644 client/src/app/shared/shared-main/plugins/plugin-selector.directive.ts (limited to 'client/src/app/shared/shared-main/plugins') diff --git a/client/src/app/shared/shared-main/plugins/index.ts b/client/src/app/shared/shared-main/plugins/index.ts index f36dab624..f45ed9b73 100644 --- a/client/src/app/shared/shared-main/plugins/index.ts +++ b/client/src/app/shared/shared-main/plugins/index.ts @@ -1 +1,2 @@ export * from './plugin-placeholder.component' +export * from './plugin-selector.directive' diff --git a/client/src/app/shared/shared-main/plugins/plugin-selector.directive.ts b/client/src/app/shared/shared-main/plugins/plugin-selector.directive.ts new file mode 100644 index 000000000..576569f19 --- /dev/null +++ b/client/src/app/shared/shared-main/plugins/plugin-selector.directive.ts @@ -0,0 +1,21 @@ +import { Directive, ElementRef, Input, OnInit, Renderer2 } from '@angular/core' +import { PluginSelectorId } from '@shared/models' + +@Directive({ selector: '[myPluginSelector]' }) +export class PluginSelectorDirective implements OnInit { + @Input() pluginSelectorId: PluginSelectorId + + constructor ( + private renderer: Renderer2, + private hostElement: ElementRef + ) { + + } + + ngOnInit () { + const id = this.hostElement.nativeElement.getAttribute('id') + if (id) throw new Error('Cannot set id on element that already has an id') + + this.renderer.setAttribute(this.hostElement.nativeElement, 'id', `plugin-selector-${this.pluginSelectorId}`) + } +} -- cgit v1.2.3