Merge branch 'generify-component-loaders_contribute-7.6' into generify-component-loaders_contribute-main

This commit is contained in:
Alexandre Vryghem
2024-02-06 22:37:16 +01:00
11 changed files with 95 additions and 80 deletions

View File

@@ -1,32 +0,0 @@
import { Component, Input, OnDestroy } from '@angular/core';
import { BrowseByDataType } from './browse-by-switcher/browse-by-data-type';
import { Context } from '../core/shared/context.model';
import { Subscription } from 'rxjs';
import { hasValue } from '../shared/empty.util';
@Component({
selector: 'ds-abstract-browse-by-type',
template: '',
})
export abstract class AbstractBrowseByTypeComponent implements OnDestroy {
/**
* The optional context
*/
@Input() context: Context;
/**
* The {@link BrowseByDataType} of this Component
*/
@Input() browseByType: BrowseByDataType;
/**
* List of subscriptions
*/
subs: Subscription[] = [];
ngOnDestroy(): void {
this.subs.filter((sub: Subscription) => hasValue(sub)).forEach((sub: Subscription) => sub.unsubscribe());
}
}

View File

@@ -1,5 +1,5 @@
import { combineLatest as observableCombineLatest, Observable } from 'rxjs'; import { combineLatest as observableCombineLatest, Observable, Subscription } from 'rxjs';
import { Component, Inject, OnInit, OnDestroy } from '@angular/core'; import { Component, Inject, OnInit, OnDestroy, Input } from '@angular/core';
import { RemoteData } from '../../core/data/remote-data'; import { RemoteData } from '../../core/data/remote-data';
import { PaginatedList } from '../../core/data/paginated-list.model'; import { PaginatedList } from '../../core/data/paginated-list.model';
import { PaginationComponentOptions } from '../../shared/pagination/pagination-component-options.model'; import { PaginationComponentOptions } from '../../shared/pagination/pagination-component-options.model';
@@ -23,8 +23,8 @@ import { Community } from '../../core/shared/community.model';
import { APP_CONFIG, AppConfig } from '../../../config/app-config.interface'; import { APP_CONFIG, AppConfig } from '../../../config/app-config.interface';
import { DSONameService } from '../../core/breadcrumbs/dso-name.service'; import { DSONameService } from '../../core/breadcrumbs/dso-name.service';
import { rendersBrowseBy } from '../browse-by-switcher/browse-by-decorator'; import { rendersBrowseBy } from '../browse-by-switcher/browse-by-decorator';
import { AbstractBrowseByTypeComponent } from '../abstract-browse-by-type.component';
import { BrowseByDataType } from '../browse-by-switcher/browse-by-data-type'; import { BrowseByDataType } from '../browse-by-switcher/browse-by-data-type';
import { Context } from '../../core/shared/context.model';
export const BBM_PAGINATION_ID = 'bbm'; export const BBM_PAGINATION_ID = 'bbm';
@@ -40,7 +40,17 @@ export const BBM_PAGINATION_ID = 'bbm';
* 'dc.contributor.*' * 'dc.contributor.*'
*/ */
@rendersBrowseBy(BrowseByDataType.Metadata) @rendersBrowseBy(BrowseByDataType.Metadata)
export class BrowseByMetadataPageComponent extends AbstractBrowseByTypeComponent implements OnInit, OnDestroy { export class BrowseByMetadataPageComponent implements OnInit, OnDestroy {
/**
* The optional context
*/
@Input() context: Context;
/**
* The {@link BrowseByDataType} of this Component
*/
@Input() browseByType: BrowseByDataType;
/** /**
* The list of browse-entries to display * The list of browse-entries to display
@@ -77,6 +87,11 @@ export class BrowseByMetadataPageComponent extends AbstractBrowseByTypeComponent
*/ */
currentSort$: Observable<SortOptions>; currentSort$: Observable<SortOptions>;
/**
* List of subscriptions
*/
subs: Subscription[] = [];
/** /**
* The default browse id to resort to when none is provided * The default browse id to resort to when none is provided
*/ */
@@ -129,7 +144,6 @@ export class BrowseByMetadataPageComponent extends AbstractBrowseByTypeComponent
@Inject(APP_CONFIG) public appConfig: AppConfig, @Inject(APP_CONFIG) public appConfig: AppConfig,
public dsoNameService: DSONameService, public dsoNameService: DSONameService,
) { ) {
super();
this.fetchThumbnails = this.appConfig.browseBy.showThumbnails; this.fetchThumbnails = this.appConfig.browseBy.showThumbnails;
this.paginationConfig = Object.assign(new PaginationComponentOptions(), { this.paginationConfig = Object.assign(new PaginationComponentOptions(), {
id: BBM_PAGINATION_ID, id: BBM_PAGINATION_ID,
@@ -277,7 +291,7 @@ export class BrowseByMetadataPageComponent extends AbstractBrowseByTypeComponent
} }
ngOnDestroy(): void { ngOnDestroy(): void {
super.ngOnDestroy(); this.subs.filter((sub: Subscription) => hasValue(sub)).forEach((sub: Subscription) => sub.unsubscribe());
this.paginationService.clearPagination(this.paginationConfig.id); this.paginationService.clearPagination(this.paginationConfig.id);
} }

View File

@@ -9,7 +9,6 @@ import { getMockThemeService } from '../../shared/mocks/theme-service.mock';
import { ThemeService } from '../../shared/theme-support/theme.service'; import { ThemeService } from '../../shared/theme-support/theme.service';
import { rendersBrowseBy } from '../browse-by-switcher/browse-by-decorator'; import { rendersBrowseBy } from '../browse-by-switcher/browse-by-decorator';
import { Component } from '@angular/core'; import { Component } from '@angular/core';
import { AbstractBrowseByTypeComponent } from '../abstract-browse-by-type.component';
import { BrowseDefinition } from '../../core/shared/browse-definition.model'; import { BrowseDefinition } from '../../core/shared/browse-definition.model';
import { By } from '@angular/platform-browser'; import { By } from '@angular/platform-browser';
import { BrowseByDataType } from '../browse-by-switcher/browse-by-data-type'; import { BrowseByDataType } from '../browse-by-switcher/browse-by-data-type';
@@ -20,7 +19,7 @@ import { BrowseByDataType } from '../browse-by-switcher/browse-by-data-type';
selector: '', selector: '',
template: '<span id="BrowseByTestComponent"></span>', template: '<span id="BrowseByTestComponent"></span>',
}) })
class BrowseByTestComponent extends AbstractBrowseByTypeComponent { class BrowseByTestComponent {
} }
class TestBrowseByPageBrowseDefinition extends BrowseDefinition { class TestBrowseByPageBrowseDefinition extends BrowseDefinition {

View File

@@ -1,6 +1,6 @@
import { Component } from '@angular/core';
import { hasNoValue } from '../../shared/empty.util'; import { hasNoValue } from '../../shared/empty.util';
import { DEFAULT_THEME, resolveTheme } from '../../shared/object-collection/shared/listable-object/listable-object.decorator'; import { DEFAULT_THEME, resolveTheme } from '../../shared/object-collection/shared/listable-object/listable-object.decorator';
import { AbstractBrowseByTypeComponent } from '../abstract-browse-by-type.component';
import { Context } from '../../core/shared/context.model'; import { Context } from '../../core/shared/context.model';
import { GenericConstructor } from '../../core/shared/generic-constructor'; import { GenericConstructor } from '../../core/shared/generic-constructor';
import { BrowseByDataType } from './browse-by-data-type'; import { BrowseByDataType } from './browse-by-data-type';
@@ -8,7 +8,7 @@ import { BrowseByDataType } from './browse-by-data-type';
export const DEFAULT_BROWSE_BY_TYPE = BrowseByDataType.Metadata; export const DEFAULT_BROWSE_BY_TYPE = BrowseByDataType.Metadata;
export const DEFAULT_BROWSE_BY_CONTEXT = Context.Any; export const DEFAULT_BROWSE_BY_CONTEXT = Context.Any;
const map: Map<BrowseByDataType, Map<Context, Map<string, GenericConstructor<AbstractBrowseByTypeComponent>>>> = new Map(); const map: Map<BrowseByDataType, Map<Context, Map<string, GenericConstructor<Component>>>> = new Map();
/** /**
* Decorator used for rendering Browse-By pages by type * Decorator used for rendering Browse-By pages by type
@@ -41,12 +41,12 @@ export function rendersBrowseBy(browseByType: BrowseByDataType, context = DEFAUL
* @param context The context to match * @param context The context to match
* @param theme the theme to match * @param theme the theme to match
*/ */
export function getComponentByBrowseByType(browseByType: BrowseByDataType, context: Context, theme: string): GenericConstructor<AbstractBrowseByTypeComponent> { export function getComponentByBrowseByType(browseByType: BrowseByDataType, context: Context, theme: string): GenericConstructor<Component> {
let contextMap: Map<Context, Map<string, GenericConstructor<AbstractBrowseByTypeComponent>>> = map.get(browseByType); let contextMap: Map<Context, Map<string, GenericConstructor<Component>>> = map.get(browseByType);
if (hasNoValue(contextMap)) { if (hasNoValue(contextMap)) {
contextMap = map.get(DEFAULT_BROWSE_BY_TYPE); contextMap = map.get(DEFAULT_BROWSE_BY_TYPE);
} }
let themeMap: Map<string, GenericConstructor<AbstractBrowseByTypeComponent>> = contextMap.get(context); let themeMap: Map<string, GenericConstructor<Component>> = contextMap.get(context);
if (hasNoValue(themeMap)) { if (hasNoValue(themeMap)) {
themeMap = contextMap.get(DEFAULT_BROWSE_BY_CONTEXT); themeMap = contextMap.get(DEFAULT_BROWSE_BY_CONTEXT);
} }

View File

@@ -8,7 +8,6 @@ import { ValueListBrowseDefinition } from '../../core/shared/value-list-browse-d
import { NonHierarchicalBrowseDefinition } from '../../core/shared/non-hierarchical-browse-definition'; import { NonHierarchicalBrowseDefinition } from '../../core/shared/non-hierarchical-browse-definition';
import { getMockThemeService } from '../../shared/mocks/theme-service.mock'; import { getMockThemeService } from '../../shared/mocks/theme-service.mock';
import { DynamicComponentLoaderDirective } from '../../shared/abstract-component-loader/dynamic-component-loader.directive'; import { DynamicComponentLoaderDirective } from '../../shared/abstract-component-loader/dynamic-component-loader.directive';
import { AbstractBrowseByTypeComponent } from '../abstract-browse-by-type.component';
import { BrowseByDataType } from './browse-by-data-type'; import { BrowseByDataType } from './browse-by-data-type';
@rendersBrowseBy('BrowseBySwitcherComponent' as BrowseByDataType) @rendersBrowseBy('BrowseBySwitcherComponent' as BrowseByDataType)
@@ -17,7 +16,7 @@ import { BrowseByDataType } from './browse-by-data-type';
selector: '', selector: '',
template: '<span id="BrowseByTestComponent"></span>', template: '<span id="BrowseByTestComponent"></span>',
}) })
class BrowseByTestComponent extends AbstractBrowseByTypeComponent { class BrowseByTestComponent {
} }
describe('BrowseBySwitcherComponent', () => { describe('BrowseBySwitcherComponent', () => {

View File

@@ -2,28 +2,30 @@ import { Component, Input } from '@angular/core';
import { getComponentByBrowseByType } from './browse-by-decorator'; import { getComponentByBrowseByType } from './browse-by-decorator';
import { GenericConstructor } from '../../core/shared/generic-constructor'; import { GenericConstructor } from '../../core/shared/generic-constructor';
import { AbstractComponentLoaderComponent } from '../../shared/abstract-component-loader/abstract-component-loader.component'; 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 { BrowseByDataType } from './browse-by-data-type';
import { Context } from '../../core/shared/context.model';
@Component({ @Component({
selector: 'ds-browse-by-switcher', selector: 'ds-browse-by-switcher',
templateUrl: '../../shared/abstract-component-loader/abstract-component-loader.component.html' templateUrl: '../../shared/abstract-component-loader/abstract-component-loader.component.html'
}) })
export class BrowseBySwitcherComponent extends AbstractComponentLoaderComponent<AbstractBrowseByTypeComponent> { export class BrowseBySwitcherComponent extends AbstractComponentLoaderComponent<Component> {
@Input() context: Context;
@Input() browseByType: BrowseByDataType; @Input() browseByType: BrowseByDataType;
protected inputNamesDependentForComponent: (keyof this & string)[] = [ protected inputNamesDependentForComponent: (keyof this & string)[] = [
...this.inputNamesDependentForComponent, 'context',
'browseByType', 'browseByType',
]; ];
protected inputNames: (keyof this & string)[] = [ protected inputNames: (keyof this & string)[] = [
...this.inputNames, 'context',
'browseByType', 'browseByType',
]; ];
public getComponent(): GenericConstructor<AbstractBrowseByTypeComponent> { public getComponent(): GenericConstructor<Component> {
return getComponentByBrowseByType(this.browseByType, this.context, this.themeService.getThemeName()); return getComponentByBrowseByType(this.browseByType, this.context, this.themeService.getThemeName());
} }

View File

@@ -1,14 +1,14 @@
import { Component, OnInit, OnDestroy } from '@angular/core'; import { Component, OnInit, OnDestroy, Input } from '@angular/core';
import { VocabularyOptions } from '../../core/submission/vocabularies/models/vocabulary-options.model'; import { VocabularyOptions } from '../../core/submission/vocabularies/models/vocabulary-options.model';
import { VocabularyEntryDetail } from '../../core/submission/vocabularies/models/vocabulary-entry-detail.model'; import { VocabularyEntryDetail } from '../../core/submission/vocabularies/models/vocabulary-entry-detail.model';
import { ActivatedRoute } from '@angular/router'; import { ActivatedRoute } from '@angular/router';
import { Observable } from 'rxjs'; import { Observable, Subscription } from 'rxjs';
import { BrowseDefinition } from '../../core/shared/browse-definition.model'; import { BrowseDefinition } from '../../core/shared/browse-definition.model';
import { rendersBrowseBy } from '../browse-by-switcher/browse-by-decorator'; import { rendersBrowseBy } from '../browse-by-switcher/browse-by-decorator';
import { map } from 'rxjs/operators'; import { map } from 'rxjs/operators';
import { HierarchicalBrowseDefinition } from '../../core/shared/hierarchical-browse-definition.model'; import { HierarchicalBrowseDefinition } from '../../core/shared/hierarchical-browse-definition.model';
import { AbstractBrowseByTypeComponent } from '../abstract-browse-by-type.component';
import { BrowseByDataType } from '../browse-by-switcher/browse-by-data-type'; import { BrowseByDataType } from '../browse-by-switcher/browse-by-data-type';
import { Context } from '../../core/shared/context.model';
@Component({ @Component({
selector: 'ds-browse-by-taxonomy-page', selector: 'ds-browse-by-taxonomy-page',
@@ -19,7 +19,17 @@ import { BrowseByDataType } from '../browse-by-switcher/browse-by-data-type';
* Component for browsing items by metadata in a hierarchical controlled vocabulary * Component for browsing items by metadata in a hierarchical controlled vocabulary
*/ */
@rendersBrowseBy(BrowseByDataType.Hierarchy) @rendersBrowseBy(BrowseByDataType.Hierarchy)
export class BrowseByTaxonomyPageComponent extends AbstractBrowseByTypeComponent implements OnInit, OnDestroy { export class BrowseByTaxonomyPageComponent implements OnInit, OnDestroy {
/**
* The optional context
*/
@Input() context: Context;
/**
* The {@link BrowseByDataType} of this Component
*/
@Input() browseByType: BrowseByDataType;
/** /**
* The {@link VocabularyOptions} object * The {@link VocabularyOptions} object
@@ -56,10 +66,14 @@ export class BrowseByTaxonomyPageComponent extends AbstractBrowseByTypeComponent
*/ */
browseDefinition$: Observable<BrowseDefinition>; browseDefinition$: Observable<BrowseDefinition>;
/**
* Subscriptions to track
*/
subs: Subscription[] = [];
public constructor( public constructor(
protected route: ActivatedRoute, protected route: ActivatedRoute,
) { ) {
super();
} }
ngOnInit(): void { ngOnInit(): void {
@@ -108,4 +122,7 @@ export class BrowseByTaxonomyPageComponent extends AbstractBrowseByTypeComponent
}; };
} }
ngOnDestroy(): void {
this.subs.forEach((sub: Subscription) => sub.unsubscribe());
}
} }

View File

@@ -1,22 +1,27 @@
import { Component, ComponentRef, Input, OnChanges, OnDestroy, OnInit, SimpleChanges, ViewChild, ViewContainerRef } from '@angular/core'; import { Component, ComponentRef, OnChanges, OnDestroy, OnInit, SimpleChanges, ViewChild, ViewContainerRef } from '@angular/core';
import { Context } from '../../core/shared/context.model';
import { ThemeService } from '../theme-support/theme.service'; import { ThemeService } from '../theme-support/theme.service';
import { GenericConstructor } from '../../core/shared/generic-constructor'; import { GenericConstructor } from '../../core/shared/generic-constructor';
import { hasValue, isNotEmpty } from '../empty.util'; import { hasValue, isNotEmpty } from '../empty.util';
import { Subscription } from 'rxjs'; import { Subscription } from 'rxjs';
import { DynamicComponentLoaderDirective } from './dynamic-component-loader.directive'; 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({ @Component({
selector: 'ds-abstract-component-loader', selector: 'ds-abstract-component-loader',
templateUrl: './abstract-component-loader.component.html', templateUrl: './abstract-component-loader.component.html',
}) })
export abstract class AbstractComponentLoaderComponent<T> implements OnInit, OnChanges, OnDestroy { 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 * Directive to determine where the dynamic child component is located
*/ */
@@ -33,20 +38,21 @@ export abstract class AbstractComponentLoaderComponent<T> implements OnInit, OnC
protected subs: Subscription[] = []; protected subs: Subscription[] = [];
/** /**
* The @{@link Input}() that are used to find the matching component using {@link getComponent}. When the value of * The @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 * one of these @Input() change this loader needs to retrieve the best matching component again using the
* {@link getComponent} method. * {@link getComponent} method.
*/ */
protected inputNamesDependentForComponent: (keyof this & string)[] = [ protected inputNamesDependentForComponent: (keyof this & string)[] = [];
'context',
];
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( constructor(
protected themeService: ThemeService, protected themeService: ThemeService,

View File

@@ -19,13 +19,20 @@ import { AbstractComponentLoaderComponent } from '../abstract-component-loader/a
*/ */
export class MetadataRepresentationLoaderComponent extends AbstractComponentLoaderComponent<MetadataRepresentationListElementComponent> { export class MetadataRepresentationLoaderComponent extends AbstractComponentLoaderComponent<MetadataRepresentationListElementComponent> {
@Input() context: Context;
/** /**
* The item or metadata to determine the component for * The item or metadata to determine the component for
*/ */
@Input() mdRepresentation: MetadataRepresentation; @Input() mdRepresentation: MetadataRepresentation;
protected inputNamesDependentForComponent: (keyof this & string)[] = [
'context',
'mdRepresentation',
];
protected inputNames: (keyof this & string)[] = [ protected inputNames: (keyof this & string)[] = [
...this.inputNames, 'context',
'mdRepresentation', 'mdRepresentation',
]; ];

View File

@@ -47,7 +47,6 @@ export class ClaimedTaskActionsLoaderComponent extends AbstractComponentLoaderCo
* The list of input and output names for the dynamic component * The list of input and output names for the dynamic component
*/ */
protected inputNames: (keyof this & string)[] = [ protected inputNames: (keyof this & string)[] = [
...this.inputNames,
'item', 'item',
'object', 'object',
'option', 'option',
@@ -55,7 +54,6 @@ export class ClaimedTaskActionsLoaderComponent extends AbstractComponentLoaderCo
]; ];
protected outputNames: (keyof this & string)[] = [ protected outputNames: (keyof this & string)[] = [
...this.outputNames,
'processCompleted', 'processCompleted',
]; ];

View File

@@ -58,7 +58,7 @@ export class ListableObjectComponentLoaderComponent extends AbstractComponentLoa
/** /**
* Whether to show the thumbnail preview * Whether to show the thumbnail preview
*/ */
@Input() showThumbnails; @Input() showThumbnails: boolean;
/** /**
* The value to display for this element * The value to display for this element
@@ -70,13 +70,19 @@ export class ListableObjectComponentLoaderComponent extends AbstractComponentLoa
*/ */
@Output() contentChange = new EventEmitter<ListableObject>(); @Output() contentChange = new EventEmitter<ListableObject>();
protected inputNamesDependentForComponent: (keyof this & string)[] = [
'object',
'viewMode',
'context',
];
/** /**
* The list of input and output names for the dynamic component * The list of input and output names for the dynamic component
*/ */
protected inputNames: (keyof this & string)[] = [ protected inputNames: (keyof this & string)[] = [
...this.inputNames,
'object', 'object',
'index', 'index',
'context',
'linkType', 'linkType',
'listID', 'listID',
'showLabel', 'showLabel',
@@ -86,7 +92,6 @@ export class ListableObjectComponentLoaderComponent extends AbstractComponentLoa
]; ];
protected outputNames: (keyof this & string)[] = [ protected outputNames: (keyof this & string)[] = [
...this.outputNames,
'contentChange', 'contentChange',
]; ];