Skip to content

Commit

Permalink
Moved the context @input() to the loaders (since they are not always …
Browse files Browse the repository at this point in the history
…required for all the loaders) & added AbstractComponentLoaderComponent documentation
  • Loading branch information
alexandrevryghem committed Feb 3, 2024
1 parent 7942c90 commit 239f082
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,25 @@ 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',
templateUrl: '../../shared/abstract-component-loader/abstract-component-loader.component.html'
})
export class BrowseBySwitcherComponent extends AbstractComponentLoaderComponent<AbstractBrowseByTypeComponent> {

@Input() context: Context;

@Input() browseByType: BrowseByDataType;

protected inputNamesDependentForComponent: (keyof this & string)[] = [
...this.inputNamesDependentForComponent,
'context',
'browseByType',
];

protected inputNames: (keyof this & string)[] = [
...this.inputNames,
'context',
'browseByType',
];

Expand Down
Original file line number Diff line number Diff line change
@@ -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:
* <ul>
* <li>Create a new LoaderComponent component extending this component</li>
* <li>Point the templateUrl to this component's templateUrl</li>
* <li>Add all the @Input()/@Output() names that the dynamically generated components should inherit from the loader to the inputNames/outputNames lists</li>
* <li>Create a decorator file containing the new decorator function, a map containing all the collected {@link Component}s and a function to retrieve the {@link Component}</li>
* <li>Call the function to retrieve the correct {@link Component} in getComponent()</li>
* <li>Add all the @Input()s you had to used in getComponent() in the inputNamesDependentForComponent array</li>
* </ul>
*/
@Component({
selector: 'ds-abstract-component-loader',
templateUrl: './abstract-component-loader.component.html',
})
export abstract class AbstractComponentLoaderComponent<T> implements OnInit, OnChanges, OnDestroy {

/**
* The optional context
*/
@Input() context: Context;

/**
* Directive to determine where the dynamic child component is located
*/
Expand All @@ -33,20 +38,21 @@ export abstract class AbstractComponentLoaderComponent<T> 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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,20 @@ import { AbstractComponentLoaderComponent } from '../abstract-component-loader/a
*/
export class MetadataRepresentationLoaderComponent extends AbstractComponentLoaderComponent<MetadataRepresentationListElementComponent> {

@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',
];

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,15 +47,13 @@ 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',
'workflowitem',
];

protected outputNames: (keyof this & string)[] = [
...this.outputNames,
'processCompleted',
];

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -70,13 +70,19 @@ export class ListableObjectComponentLoaderComponent extends AbstractComponentLoa
*/
@Output() contentChange = new EventEmitter<ListableObject>();

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',
Expand All @@ -86,7 +92,6 @@ export class ListableObjectComponentLoaderComponent extends AbstractComponentLoa
];

protected outputNames: (keyof this & string)[] = [
...this.outputNames,
'contentChange',
];

Expand Down

0 comments on commit 239f082

Please sign in to comment.