Skip to content

Commit 239f082

Browse files
Moved the context @input() to the loaders (since they are not always required for all the loaders) & added AbstractComponentLoaderComponent documentation
1 parent 7942c90 commit 239f082

5 files changed

Lines changed: 44 additions & 25 deletions

File tree

src/app/browse-by/browse-by-switcher/browse-by-switcher.component.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,22 +4,25 @@ import { GenericConstructor } from '../../core/shared/generic-constructor';
44
import { AbstractComponentLoaderComponent } from '../../shared/abstract-component-loader/abstract-component-loader.component';
55
import { AbstractBrowseByTypeComponent } from '../abstract-browse-by-type.component';
66
import { BrowseByDataType } from './browse-by-data-type';
7+
import { Context } from '../../core/shared/context.model';
78

89
@Component({
910
selector: 'ds-browse-by-switcher',
1011
templateUrl: '../../shared/abstract-component-loader/abstract-component-loader.component.html'
1112
})
1213
export class BrowseBySwitcherComponent extends AbstractComponentLoaderComponent<AbstractBrowseByTypeComponent> {
1314

15+
@Input() context: Context;
16+
1417
@Input() browseByType: BrowseByDataType;
1518

1619
protected inputNamesDependentForComponent: (keyof this & string)[] = [
17-
...this.inputNamesDependentForComponent,
20+
'context',
1821
'browseByType',
1922
];
2023

2124
protected inputNames: (keyof this & string)[] = [
22-
...this.inputNames,
25+
'context',
2326
'browseByType',
2427
];
2528

src/app/shared/abstract-component-loader/abstract-component-loader.component.ts

Lines changed: 23 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,27 @@
1-
import { Component, ComponentRef, Input, OnChanges, OnDestroy, OnInit, SimpleChanges, ViewChild, ViewContainerRef } from '@angular/core';
2-
import { Context } from '../../core/shared/context.model';
1+
import { Component, ComponentRef, OnChanges, OnDestroy, OnInit, SimpleChanges, ViewChild, ViewContainerRef } from '@angular/core';
32
import { ThemeService } from '../theme-support/theme.service';
43
import { GenericConstructor } from '../../core/shared/generic-constructor';
54
import { hasValue, isNotEmpty } from '../empty.util';
65
import { Subscription } from 'rxjs';
76
import { DynamicComponentLoaderDirective } from './dynamic-component-loader.directive';
87

8+
/**
9+
* To create a new loader component you will need to:
10+
* <ul>
11+
* <li>Create a new LoaderComponent component extending this component</li>
12+
* <li>Point the templateUrl to this component's templateUrl</li>
13+
* <li>Add all the @Input()/@Output() names that the dynamically generated components should inherit from the loader to the inputNames/outputNames lists</li>
14+
* <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>
15+
* <li>Call the function to retrieve the correct {@link Component} in getComponent()</li>
16+
* <li>Add all the @Input()s you had to used in getComponent() in the inputNamesDependentForComponent array</li>
17+
* </ul>
18+
*/
919
@Component({
1020
selector: 'ds-abstract-component-loader',
1121
templateUrl: './abstract-component-loader.component.html',
1222
})
1323
export abstract class AbstractComponentLoaderComponent<T> implements OnInit, OnChanges, OnDestroy {
1424

15-
/**
16-
* The optional context
17-
*/
18-
@Input() context: Context;
19-
2025
/**
2126
* Directive to determine where the dynamic child component is located
2227
*/
@@ -33,20 +38,21 @@ export abstract class AbstractComponentLoaderComponent<T> implements OnInit, OnC
3338
protected subs: Subscription[] = [];
3439

3540
/**
36-
* The @{@link Input}() that are used to find the matching component using {@link getComponent}. When the value of
37-
* one of these @{@link Input}() change this loader needs to retrieve the best matching component again using the
41+
* The @Input() that are used to find the matching component using {@link getComponent}. When the value of
42+
* one of these @Input() change this loader needs to retrieve the best matching component again using the
3843
* {@link getComponent} method.
3944
*/
40-
protected inputNamesDependentForComponent: (keyof this & string)[] = [
41-
'context',
42-
];
45+
protected inputNamesDependentForComponent: (keyof this & string)[] = [];
4346

44-
protected inputNames: (keyof this & string)[] = [
45-
'context',
46-
];
47+
/**
48+
* The list of the @Input() names that should be passed down to the dynamically created components.
49+
*/
50+
protected inputNames: (keyof this & string)[] = [];
4751

48-
protected outputNames: (keyof this & string)[] = [
49-
];
52+
/**
53+
* The list of the @Output() names that should be passed down to the dynamically created components.
54+
*/
55+
protected outputNames: (keyof this & string)[] = [];
5056

5157
constructor(
5258
protected themeService: ThemeService,

src/app/shared/metadata-representation/metadata-representation-loader.component.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,20 @@ import { AbstractComponentLoaderComponent } from '../abstract-component-loader/a
1919
*/
2020
export class MetadataRepresentationLoaderComponent extends AbstractComponentLoaderComponent<MetadataRepresentationListElementComponent> {
2121

22+
@Input() context: Context;
23+
2224
/**
2325
* The item or metadata to determine the component for
2426
*/
2527
@Input() mdRepresentation: MetadataRepresentation;
2628

29+
protected inputNamesDependentForComponent: (keyof this & string)[] = [
30+
'context',
31+
'mdRepresentation',
32+
];
33+
2734
protected inputNames: (keyof this & string)[] = [
28-
...this.inputNames,
35+
'context',
2936
'mdRepresentation',
3037
];
3138

src/app/shared/mydspace-actions/claimed-task/switcher/claimed-task-actions-loader.component.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,15 +47,13 @@ export class ClaimedTaskActionsLoaderComponent extends AbstractComponentLoaderCo
4747
* The list of input and output names for the dynamic component
4848
*/
4949
protected inputNames: (keyof this & string)[] = [
50-
...this.inputNames,
5150
'item',
5251
'object',
5352
'option',
5453
'workflowitem',
5554
];
5655

5756
protected outputNames: (keyof this & string)[] = [
58-
...this.outputNames,
5957
'processCompleted',
6058
];
6159

src/app/shared/object-collection/shared/listable-object/listable-object-component-loader.component.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ export class ListableObjectComponentLoaderComponent extends AbstractComponentLoa
5858
/**
5959
* Whether to show the thumbnail preview
6060
*/
61-
@Input() showThumbnails;
61+
@Input() showThumbnails: boolean;
6262

6363
/**
6464
* The value to display for this element
@@ -70,13 +70,19 @@ export class ListableObjectComponentLoaderComponent extends AbstractComponentLoa
7070
*/
7171
@Output() contentChange = new EventEmitter<ListableObject>();
7272

73+
protected inputNamesDependentForComponent: (keyof this & string)[] = [
74+
'object',
75+
'viewMode',
76+
'context',
77+
];
78+
7379
/**
7480
* The list of input and output names for the dynamic component
7581
*/
7682
protected inputNames: (keyof this & string)[] = [
77-
...this.inputNames,
7883
'object',
7984
'index',
85+
'context',
8086
'linkType',
8187
'listID',
8288
'showLabel',
@@ -86,7 +92,6 @@ export class ListableObjectComponentLoaderComponent extends AbstractComponentLoa
8692
];
8793

8894
protected outputNames: (keyof this & string)[] = [
89-
...this.outputNames,
9095
'contentChange',
9196
];
9297

0 commit comments

Comments
 (0)