Skip to content

Commit

Permalink
Removed the AbstractBrowseByTypeComponent
Browse files Browse the repository at this point in the history
  • Loading branch information
alexandrevryghem committed Feb 3, 2024
1 parent 239f082 commit e3d8726
Show file tree
Hide file tree
Showing 13 changed files with 63 additions and 68 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 @@ -273,7 +287,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 { 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';
import { Component } from '@angular/core';

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,15 +2,14 @@ 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 {

@Input() context: Context;

Expand All @@ -26,7 +25,7 @@ export class BrowseBySwitcherComponent extends AbstractComponentLoaderComponent<
'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
Expand Up @@ -20,7 +20,7 @@ import { DynamicComponentLoaderDirective } from './dynamic-component-loader.dire
selector: 'ds-abstract-component-loader',
templateUrl: './abstract-component-loader.component.html',
})
export abstract class AbstractComponentLoaderComponent<T> implements OnInit, OnChanges, OnDestroy {
export abstract class AbstractComponentLoaderComponent implements OnInit, OnChanges, OnDestroy {

/**
* Directive to determine where the dynamic child component is located
Expand All @@ -30,7 +30,7 @@ export abstract class AbstractComponentLoaderComponent<T> implements OnInit, OnC
/**
* The reference to the dynamic component
*/
protected compRef: ComponentRef<T>;
protected compRef: ComponentRef<Component>;

/**
* Array to track all subscriptions and unsubscribe them onDestroy
Expand Down Expand Up @@ -91,7 +91,7 @@ export abstract class AbstractComponentLoaderComponent<T> implements OnInit, OnC
* Creates the component and connects the @Input() & @Output() from the ThemedComponent to its child Component.
*/
public instantiateComponent(): void {
const component: GenericConstructor<T> = this.getComponent();
const component: GenericConstructor<Component> = this.getComponent();

const viewContainerRef: ViewContainerRef = this.componentDirective.viewContainerRef;
viewContainerRef.clear();
Expand Down Expand Up @@ -119,7 +119,7 @@ export abstract class AbstractComponentLoaderComponent<T> implements OnInit, OnC
/**
* Fetch the component depending on the item's entity type, metadata representation type and context
*/
public abstract getComponent(): GenericConstructor<T>;
public abstract getComponent(): GenericConstructor<Component>;

/**
* Connect the inputs and outputs of this component to the dynamic component,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import {
import { METADATA_REPRESENTATION_COMPONENT_FACTORY } from './metadata-representation.decorator';
import { Context } from '../../core/shared/context.model';
import { GenericConstructor } from '../../core/shared/generic-constructor';
import { MetadataRepresentationListElementComponent } from '../object-list/metadata-representation-list-element/metadata-representation-list-element.component';
import { ThemeService } from '../theme-support/theme.service';
import { AbstractComponentLoaderComponent } from '../abstract-component-loader/abstract-component-loader.component';

Expand All @@ -17,7 +16,7 @@ import { AbstractComponentLoaderComponent } from '../abstract-component-loader/a
/**
* Component for determining what component to use depending on the item's entity type (dspace.entity.type), its metadata representation and, optionally, its context
*/
export class MetadataRepresentationLoaderComponent extends AbstractComponentLoaderComponent<MetadataRepresentationListElementComponent> {
export class MetadataRepresentationLoaderComponent extends AbstractComponentLoaderComponent {

@Input() context: Context;

Expand All @@ -43,7 +42,7 @@ export class MetadataRepresentationLoaderComponent extends AbstractComponentLoad
super(themeService);
}

public getComponent(): GenericConstructor<MetadataRepresentationListElementComponent> {
public getComponent(): GenericConstructor<Component> {
return this.getMetadataRepresentationComponent(this.mdRepresentation.itemType, this.mdRepresentation.representationType, this.context, this.themeService.getThemeName());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ describe('ClaimedTaskActionsLoaderComponent', () => {
comp.object = object;
comp.option = option;
comp.workflowitem = workflowitem;
spyOn(comp, 'getComponent').and.returnValue(ClaimedTaskActionsEditMetadataComponent);
spyOn(comp, 'getComponent').and.returnValue(ClaimedTaskActionsEditMetadataComponent as any);

fixture.detectChanges();
}));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import { ClaimedTask } from '../../../../core/tasks/models/claimed-task-object.m
import { MyDSpaceActionsResult } from '../../mydspace-actions';
import { Item } from '../../../../core/shared/item.model';
import { WorkflowItem } from '../../../../core/submission/models/workflowitem.model';
import { ClaimedTaskActionsAbstractComponent } from '../abstract/claimed-task-actions-abstract.component';
import { AbstractComponentLoaderComponent } from '../../../abstract-component-loader/abstract-component-loader.component';
import { GenericConstructor } from '../../../../core/shared/generic-constructor';

Expand All @@ -16,7 +15,8 @@ import { GenericConstructor } from '../../../../core/shared/generic-constructor'
* Component for loading a ClaimedTaskAction component depending on the "option" input
* Passes on the ClaimedTask to the component and subscribes to the processCompleted output
*/
export class ClaimedTaskActionsLoaderComponent extends AbstractComponentLoaderComponent<ClaimedTaskActionsAbstractComponent> {
export class ClaimedTaskActionsLoaderComponent extends AbstractComponentLoaderComponent {

/**
* The item object that belonging to the ClaimedTask object
*/
Expand Down Expand Up @@ -57,7 +57,7 @@ export class ClaimedTaskActionsLoaderComponent extends AbstractComponentLoaderCo
'processCompleted',
];

public getComponent(): GenericConstructor<ClaimedTaskActionsAbstractComponent> {
public getComponent(): GenericConstructor<Component> {
return getComponentByWorkflowTaskOption(this.option);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import { ThemeService } from 'src/app/shared/theme-support/theme.service';
/**
* Component for determining what component to use depending on the item's entity type (dspace.entity.type)
*/
export class ListableObjectComponentLoaderComponent extends AbstractComponentLoaderComponent<Component> {
export class ListableObjectComponentLoaderComponent extends AbstractComponentLoaderComponent {

/**
* The item or metadata to determine the component for
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import { ThemeService } from '../../../shared/theme-support/theme.service';
selector: 'ds-advanced-workflow-actions-loader',
templateUrl: '../../../shared/abstract-component-loader/abstract-component-loader.component.html',
})
export class AdvancedWorkflowActionsLoaderComponent extends AbstractComponentLoaderComponent<Component> implements OnInit {
export class AdvancedWorkflowActionsLoaderComponent extends AbstractComponentLoaderComponent implements OnInit {

/**
* The name of the type to render
Expand Down

0 comments on commit e3d8726

Please sign in to comment.