From 239f082cce32edce7719ba3eab8f71e06e3955d0 Mon Sep 17 00:00:00 2001 From: Alexandre Vryghem Date: Fri, 2 Feb 2024 09:35:27 +0100 Subject: [PATCH] Moved the context @Input() to the loaders (since they are not always required for all the loaders) & added AbstractComponentLoaderComponent documentation --- .../browse-by-switcher.component.ts | 7 +++- .../abstract-component-loader.component.ts | 40 +++++++++++-------- ...etadata-representation-loader.component.ts | 9 ++++- .../claimed-task-actions-loader.component.ts | 2 - ...table-object-component-loader.component.ts | 11 +++-- 5 files changed, 44 insertions(+), 25 deletions(-) diff --git a/src/app/browse-by/browse-by-switcher/browse-by-switcher.component.ts b/src/app/browse-by/browse-by-switcher/browse-by-switcher.component.ts index 2ebea9a262..99ad720dd3 100644 --- a/src/app/browse-by/browse-by-switcher/browse-by-switcher.component.ts +++ b/src/app/browse-by/browse-by-switcher/browse-by-switcher.component.ts @@ -4,6 +4,7 @@ import { GenericConstructor } from '../../core/shared/generic-constructor'; import { AbstractComponentLoaderComponent } from '../../shared/abstract-component-loader/abstract-component-loader.component'; import { AbstractBrowseByTypeComponent } from '../abstract-browse-by-type.component'; import { BrowseByDataType } from './browse-by-data-type'; +import { Context } from '../../core/shared/context.model'; @Component({ selector: 'ds-browse-by-switcher', @@ -11,15 +12,17 @@ import { BrowseByDataType } from './browse-by-data-type'; }) export class BrowseBySwitcherComponent extends AbstractComponentLoaderComponent { + @Input() context: Context; + @Input() browseByType: BrowseByDataType; protected inputNamesDependentForComponent: (keyof this & string)[] = [ - ...this.inputNamesDependentForComponent, + 'context', 'browseByType', ]; protected inputNames: (keyof this & string)[] = [ - ...this.inputNames, + 'context', 'browseByType', ]; diff --git a/src/app/shared/abstract-component-loader/abstract-component-loader.component.ts b/src/app/shared/abstract-component-loader/abstract-component-loader.component.ts index 888edffe67..2ea7c50d75 100644 --- a/src/app/shared/abstract-component-loader/abstract-component-loader.component.ts +++ b/src/app/shared/abstract-component-loader/abstract-component-loader.component.ts @@ -1,22 +1,27 @@ -import { Component, ComponentRef, Input, OnChanges, OnDestroy, OnInit, SimpleChanges, ViewChild, ViewContainerRef } from '@angular/core'; -import { Context } from '../../core/shared/context.model'; +import { Component, ComponentRef, OnChanges, OnDestroy, OnInit, SimpleChanges, ViewChild, ViewContainerRef } from '@angular/core'; import { ThemeService } from '../theme-support/theme.service'; import { GenericConstructor } from '../../core/shared/generic-constructor'; import { hasValue, isNotEmpty } from '../empty.util'; import { Subscription } from 'rxjs'; import { DynamicComponentLoaderDirective } from './dynamic-component-loader.directive'; +/** + * To create a new loader component you will need to: + * + */ @Component({ selector: 'ds-abstract-component-loader', templateUrl: './abstract-component-loader.component.html', }) export abstract class AbstractComponentLoaderComponent implements OnInit, OnChanges, OnDestroy { - /** - * The optional context - */ - @Input() context: Context; - /** * Directive to determine where the dynamic child component is located */ @@ -33,20 +38,21 @@ export abstract class AbstractComponentLoaderComponent implements OnInit, OnC protected subs: Subscription[] = []; /** - * The @{@link Input}() that are used to find the matching component using {@link getComponent}. When the value of - * one of these @{@link Input}() change this loader needs to retrieve the best matching component again using the + * The @Input() that are used to find the matching component using {@link getComponent}. When the value of + * one of these @Input() change this loader needs to retrieve the best matching component again using the * {@link getComponent} method. */ - protected inputNamesDependentForComponent: (keyof this & string)[] = [ - 'context', - ]; + protected inputNamesDependentForComponent: (keyof this & string)[] = []; - protected inputNames: (keyof this & string)[] = [ - 'context', - ]; + /** + * The list of the @Input() names that should be passed down to the dynamically created components. + */ + protected inputNames: (keyof this & string)[] = []; - protected outputNames: (keyof this & string)[] = [ - ]; + /** + * The list of the @Output() names that should be passed down to the dynamically created components. + */ + protected outputNames: (keyof this & string)[] = []; constructor( protected themeService: ThemeService, diff --git a/src/app/shared/metadata-representation/metadata-representation-loader.component.ts b/src/app/shared/metadata-representation/metadata-representation-loader.component.ts index 4b63a31a2b..d722d24ff6 100644 --- a/src/app/shared/metadata-representation/metadata-representation-loader.component.ts +++ b/src/app/shared/metadata-representation/metadata-representation-loader.component.ts @@ -19,13 +19,20 @@ import { AbstractComponentLoaderComponent } from '../abstract-component-loader/a */ export class MetadataRepresentationLoaderComponent extends AbstractComponentLoaderComponent { + @Input() context: Context; + /** * The item or metadata to determine the component for */ @Input() mdRepresentation: MetadataRepresentation; + protected inputNamesDependentForComponent: (keyof this & string)[] = [ + 'context', + 'mdRepresentation', + ]; + protected inputNames: (keyof this & string)[] = [ - ...this.inputNames, + 'context', 'mdRepresentation', ]; diff --git a/src/app/shared/mydspace-actions/claimed-task/switcher/claimed-task-actions-loader.component.ts b/src/app/shared/mydspace-actions/claimed-task/switcher/claimed-task-actions-loader.component.ts index fb39347d63..7b01e98249 100644 --- a/src/app/shared/mydspace-actions/claimed-task/switcher/claimed-task-actions-loader.component.ts +++ b/src/app/shared/mydspace-actions/claimed-task/switcher/claimed-task-actions-loader.component.ts @@ -47,7 +47,6 @@ export class ClaimedTaskActionsLoaderComponent extends AbstractComponentLoaderCo * The list of input and output names for the dynamic component */ protected inputNames: (keyof this & string)[] = [ - ...this.inputNames, 'item', 'object', 'option', @@ -55,7 +54,6 @@ export class ClaimedTaskActionsLoaderComponent extends AbstractComponentLoaderCo ]; protected outputNames: (keyof this & string)[] = [ - ...this.outputNames, 'processCompleted', ]; diff --git a/src/app/shared/object-collection/shared/listable-object/listable-object-component-loader.component.ts b/src/app/shared/object-collection/shared/listable-object/listable-object-component-loader.component.ts index a83cdfb6b2..d280768631 100644 --- a/src/app/shared/object-collection/shared/listable-object/listable-object-component-loader.component.ts +++ b/src/app/shared/object-collection/shared/listable-object/listable-object-component-loader.component.ts @@ -58,7 +58,7 @@ export class ListableObjectComponentLoaderComponent extends AbstractComponentLoa /** * Whether to show the thumbnail preview */ - @Input() showThumbnails; + @Input() showThumbnails: boolean; /** * The value to display for this element @@ -70,13 +70,19 @@ export class ListableObjectComponentLoaderComponent extends AbstractComponentLoa */ @Output() contentChange = new EventEmitter(); + protected inputNamesDependentForComponent: (keyof this & string)[] = [ + 'object', + 'viewMode', + 'context', + ]; + /** * The list of input and output names for the dynamic component */ protected inputNames: (keyof this & string)[] = [ - ...this.inputNames, 'object', 'index', + 'context', 'linkType', 'listID', 'showLabel', @@ -86,7 +92,6 @@ export class ListableObjectComponentLoaderComponent extends AbstractComponentLoa ]; protected outputNames: (keyof this & string)[] = [ - ...this.outputNames, 'contentChange', ];