Skip to content

Commit

Permalink
Merge branch 'generify-component-loaders_contribute-7.6' into generif…
Browse files Browse the repository at this point in the history
…y-component-loaders_contribute-main
  • Loading branch information
alexandrevryghem committed Feb 6, 2024
2 parents e071b7f + 2fb393d commit 82d4ccf
Show file tree
Hide file tree
Showing 11 changed files with 95 additions and 80 deletions.
32 changes: 0 additions & 32 deletions src/app/browse-by/abstract-browse-by-type.component.ts

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { combineLatest as observableCombineLatest, Observable } from 'rxjs';
import { Component, Inject, OnInit, OnDestroy } from '@angular/core';
import { combineLatest as observableCombineLatest, Observable, Subscription } from 'rxjs';
import { Component, Inject, OnInit, OnDestroy, Input } from '@angular/core';
import { RemoteData } from '../../core/data/remote-data';
import { PaginatedList } from '../../core/data/paginated-list.model';
import { PaginationComponentOptions } from '../../shared/pagination/pagination-component-options.model';
Expand All @@ -23,8 +23,8 @@ import { Community } from '../../core/shared/community.model';
import { APP_CONFIG, AppConfig } from '../../../config/app-config.interface';
import { DSONameService } from '../../core/breadcrumbs/dso-name.service';
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 { Context } from '../../core/shared/context.model';

export const BBM_PAGINATION_ID = 'bbm';

Expand All @@ -40,7 +40,17 @@ export const BBM_PAGINATION_ID = 'bbm';
* 'dc.contributor.*'
*/
@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
Expand Down Expand Up @@ -77,6 +87,11 @@ export class BrowseByMetadataPageComponent extends AbstractBrowseByTypeComponent
*/
currentSort$: Observable<SortOptions>;

/**
* List of subscriptions
*/
subs: Subscription[] = [];

/**
* The default browse id to resort to when none is provided
*/
Expand Down Expand Up @@ -129,7 +144,6 @@ export class BrowseByMetadataPageComponent extends AbstractBrowseByTypeComponent
@Inject(APP_CONFIG) public appConfig: AppConfig,
public dsoNameService: DSONameService,
) {
super();
this.fetchThumbnails = this.appConfig.browseBy.showThumbnails;
this.paginationConfig = Object.assign(new PaginationComponentOptions(), {
id: BBM_PAGINATION_ID,
Expand Down Expand Up @@ -277,7 +291,7 @@ export class BrowseByMetadataPageComponent extends AbstractBrowseByTypeComponent
}

ngOnDestroy(): void {
super.ngOnDestroy();
this.subs.filter((sub: Subscription) => hasValue(sub)).forEach((sub: Subscription) => sub.unsubscribe());
this.paginationService.clearPagination(this.paginationConfig.id);
}

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

class TestBrowseByPageBrowseDefinition extends BrowseDefinition {
Expand Down
10 changes: 5 additions & 5 deletions src/app/browse-by/browse-by-switcher/browse-by-decorator.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import { Component } from '@angular/core';
import { hasNoValue } from '../../shared/empty.util';
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 { GenericConstructor } from '../../core/shared/generic-constructor';
import { BrowseByDataType } from './browse-by-data-type';

export const DEFAULT_BROWSE_BY_TYPE = BrowseByDataType.Metadata;
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
Expand Down Expand Up @@ -41,12 +41,12 @@ export function rendersBrowseBy(browseByType: BrowseByDataType, context = DEFAUL
* @param context The context to match
* @param theme the theme to match
*/
export function getComponentByBrowseByType(browseByType: BrowseByDataType, context: Context, theme: string): GenericConstructor<AbstractBrowseByTypeComponent> {
let contextMap: Map<Context, Map<string, GenericConstructor<AbstractBrowseByTypeComponent>>> = map.get(browseByType);
export function getComponentByBrowseByType(browseByType: BrowseByDataType, context: Context, theme: string): GenericConstructor<Component> {
let contextMap: Map<Context, Map<string, GenericConstructor<Component>>> = map.get(browseByType);
if (hasNoValue(contextMap)) {
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)) {
themeMap = contextMap.get(DEFAULT_BROWSE_BY_CONTEXT);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import { ValueListBrowseDefinition } from '../../core/shared/value-list-browse-d
import { NonHierarchicalBrowseDefinition } from '../../core/shared/non-hierarchical-browse-definition';
import { getMockThemeService } from '../../shared/mocks/theme-service.mock';
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';

@rendersBrowseBy('BrowseBySwitcherComponent' as BrowseByDataType)
Expand All @@ -17,7 +16,7 @@ import { BrowseByDataType } from './browse-by-data-type';
selector: '',
template: '<span id="BrowseByTestComponent"></span>',
})
class BrowseByTestComponent extends AbstractBrowseByTypeComponent {
class BrowseByTestComponent {
}

describe('BrowseBySwitcherComponent', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,28 +2,30 @@ import { Component, Input } from '@angular/core';
import { getComponentByBrowseByType } from './browse-by-decorator';
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> {
export class BrowseBySwitcherComponent extends AbstractComponentLoaderComponent<Component> {

@Input() context: Context;

@Input() browseByType: BrowseByDataType;

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

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

public getComponent(): GenericConstructor<AbstractBrowseByTypeComponent> {
public getComponent(): GenericConstructor<Component> {
return getComponentByBrowseByType(this.browseByType, this.context, this.themeService.getThemeName());
}

Expand Down
Original file line number Diff line number Diff line change
@@ -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 { VocabularyEntryDetail } from '../../core/submission/vocabularies/models/vocabulary-entry-detail.model';
import { ActivatedRoute } from '@angular/router';
import { Observable } from 'rxjs';
import { Observable, Subscription } from 'rxjs';
import { BrowseDefinition } from '../../core/shared/browse-definition.model';
import { rendersBrowseBy } from '../browse-by-switcher/browse-by-decorator';
import { map } from 'rxjs/operators';
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 { Context } from '../../core/shared/context.model';

@Component({
selector: 'ds-browse-by-taxonomy-page',
Expand All @@ -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
*/
@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
Expand Down Expand Up @@ -56,10 +66,14 @@ export class BrowseByTaxonomyPageComponent extends AbstractBrowseByTypeComponent
*/
browseDefinition$: Observable<BrowseDefinition>;

/**
* Subscriptions to track
*/
subs: Subscription[] = [];

public constructor(
protected route: ActivatedRoute,
) {
super();
}

ngOnInit(): void {
Expand Down Expand Up @@ -108,4 +122,7 @@ export class BrowseByTaxonomyPageComponent extends AbstractBrowseByTypeComponent
};
}

ngOnDestroy(): void {
this.subs.forEach((sub: Subscription) => sub.unsubscribe());
}
}
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
Loading

0 comments on commit 82d4ccf

Please sign in to comment.