From 369a6dfaea920be93c3e69cd9dbabd22ef6d643f Mon Sep 17 00:00:00 2001 From: Kristof De Langhe Date: Tue, 30 Apr 2019 17:24:58 +0200 Subject: [PATCH] 62063: JSDocs and comments --- config/environment.default.js | 6 ++++++ .../+browse-by-switcher/browse-by-decorator.ts | 8 ++++++++ .../browse-by-switcher.component.ts | 12 ++++++++++++ src/app/navbar/navbar.component.ts | 1 + .../comcol-page-browse-by.component.ts | 3 +++ src/config/browse-by-config.interface.ts | 3 +++ src/config/browse-by-type-config.interface.ts | 15 +++++++++++++++ 7 files changed, 48 insertions(+) diff --git a/config/environment.default.js b/config/environment.default.js index 3013705a2e..4fccc92889 100644 --- a/config/environment.default.js +++ b/config/environment.default.js @@ -150,6 +150,12 @@ module.exports = { fiveYearLimit: 30, // The absolute lowest year to display in the dropdown (only used when no lowest date can be found for all items) defaultLowerLimit: 1900, + // List of all the active Browse-By types + // Adding a type will activate their Browse-By page and add them to the global navigation menu, as well as community and collection pages + // Allowed fields and their purpose: + // metadata: The browse id to use for fetching info from the rest api + // type: The type of Browse-By page to display + // metadataField: The metadata-field used to create starts-with options (only necessary when the type is set to 'date') types: [ { metadata: 'title', diff --git a/src/app/+browse-by/+browse-by-switcher/browse-by-decorator.ts b/src/app/+browse-by/+browse-by-switcher/browse-by-decorator.ts index fe61a2edd2..0143377922 100644 --- a/src/app/+browse-by/+browse-by-switcher/browse-by-decorator.ts +++ b/src/app/+browse-by/+browse-by-switcher/browse-by-decorator.ts @@ -10,6 +10,10 @@ export const DEFAULT_BROWSE_BY_TYPE = BrowseByType.Metadata; const map = new Map(); +/** + * Decorator used for rendering Browse-By pages by type + * @param browseByType The type of page + */ export function rendersBrowseBy(browseByType: BrowseByType) { return function decorator(component: any) { if (hasNoValue(map.get(browseByType))) { @@ -20,6 +24,10 @@ export function rendersBrowseBy(browseByType: BrowseByType) { }; } +/** + * Get the component used for rendering a Browse-By page by type + * @param browseByType The type of page + */ export function getComponentByBrowseByType(browseByType) { const comp = map.get(browseByType); if (hasNoValue(comp)) { diff --git a/src/app/+browse-by/+browse-by-switcher/browse-by-switcher.component.ts b/src/app/+browse-by/+browse-by-switcher/browse-by-switcher.component.ts index c3af4ddf52..b8652509b3 100644 --- a/src/app/+browse-by/+browse-by-switcher/browse-by-switcher.component.ts +++ b/src/app/+browse-by/+browse-by-switcher/browse-by-switcher.component.ts @@ -10,14 +10,23 @@ import { getComponentByBrowseByType } from './browse-by-decorator'; selector: 'ds-browse-by-switcher', templateUrl: './browse-by-switcher.component.html' }) +/** + * Component for determining what Browse-By component to use depending on the metadata (browse ID) provided + */ export class BrowseBySwitcherComponent implements OnInit { + /** + * Resolved browse config + */ browseByTypeConfig: Observable; public constructor(@Inject(GLOBAL_CONFIG) public config: GlobalConfig, protected route: ActivatedRoute) { } + /** + * Fetch the correct browse config from environment.js + */ ngOnInit(): void { this.browseByTypeConfig = this.route.params.pipe( map((params) => { @@ -27,6 +36,9 @@ export class BrowseBySwitcherComponent implements OnInit { ); } + /** + * Fetch the component depending on the browse type + */ getComponent() { return this.browseByTypeConfig.pipe( map((config: BrowseByTypeConfig) => getComponentByBrowseByType(config.type)) diff --git a/src/app/navbar/navbar.component.ts b/src/app/navbar/navbar.component.ts index a8736fabda..bd0a82e1e9 100644 --- a/src/app/navbar/navbar.component.ts +++ b/src/app/navbar/navbar.component.ts @@ -78,6 +78,7 @@ export class NavbarComponent extends MenuComponent implements OnInit { index: 2 }, ]; + // Read the different Browse-By types from config and add them to the browse menu const types = this.config.browseBy.types; types.forEach((typeConfig) => { menuList.push({ diff --git a/src/app/shared/comcol-page-browse-by/comcol-page-browse-by.component.ts b/src/app/shared/comcol-page-browse-by/comcol-page-browse-by.component.ts index 6b26d9f438..dcc7840bb4 100644 --- a/src/app/shared/comcol-page-browse-by/comcol-page-browse-by.component.ts +++ b/src/app/shared/comcol-page-browse-by/comcol-page-browse-by.component.ts @@ -16,6 +16,9 @@ export class ComcolPageBrowseByComponent implements OnInit { */ @Input() id: string; + /** + * List of currently active browse configurations + */ types: BrowseByTypeConfig[]; constructor(@Inject(GLOBAL_CONFIG) public config: GlobalConfig) { diff --git a/src/config/browse-by-config.interface.ts b/src/config/browse-by-config.interface.ts index dec2f1bcf5..719e127b4b 100644 --- a/src/config/browse-by-config.interface.ts +++ b/src/config/browse-by-config.interface.ts @@ -20,5 +20,8 @@ export interface BrowseByConfig extends Config { */ defaultLowerLimit: number; + /** + * A list of all the active Browse-By pages + */ types: BrowseByTypeConfig[]; } diff --git a/src/config/browse-by-type-config.interface.ts b/src/config/browse-by-type-config.interface.ts index d9ecc14704..92e3af20c0 100644 --- a/src/config/browse-by-type-config.interface.ts +++ b/src/config/browse-by-type-config.interface.ts @@ -1,8 +1,23 @@ import { Config } from './config.interface'; import { BrowseByType } from '../app/+browse-by/+browse-by-switcher/browse-by-decorator'; +/** + * Config used for rendering Browse-By pages and links + */ export interface BrowseByTypeConfig extends Config { + /** + * The browse id used for fetching browse data from the rest api + * e.g. author + */ metadata: string; + + /** + * The type of Browse-By page to render + */ type: BrowseByType; + + /** + * The metadata field to use for rendering starts-with options (only necessary when type is set to BrowseByType.Date) + */ metadataField: string; }