62063: Browse config refactoring property metadata to id

This commit is contained in:
Kristof De Langhe
2019-07-11 13:59:23 +02:00
parent 480a1b482a
commit 1d98b8c29f
13 changed files with 48 additions and 48 deletions

View File

@@ -153,25 +153,25 @@ module.exports = {
// List of all the active Browse-By types // 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 // 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: // Allowed fields and their purpose:
// metadata: The browse id to use for fetching info from the rest api // id: The browse id to use for fetching info from the rest api
// type: The type of Browse-By page to display // 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') // metadataField: The metadata-field used to create starts-with options (only necessary when the type is set to 'date')
types: [ types: [
{ {
metadata: 'title', id: 'title',
type: 'title' type: 'title'
}, },
{ {
metadata: 'dateissued', id: 'dateissued',
type: 'date', type: 'date',
metadataField: 'dc.date.issued' metadataField: 'dc.date.issued'
}, },
{ {
metadata: 'author', id: 'author',
type: 'metadata' type: 'metadata'
}, },
{ {
metadata: 'subject', id: 'subject',
type: 'metadata' type: 'metadata'
} }
] ]

View File

@@ -22,7 +22,7 @@ import { BrowseByType, rendersBrowseBy } from '../+browse-by-switcher/browse-by-
}) })
/** /**
* Component for browsing items by metadata definition of type 'date' * Component for browsing items by metadata definition of type 'date'
* A metadata definition is a short term used to describe one or multiple metadata fields. * A metadata definition (a.k.a. browse id) is a short term used to describe one or multiple metadata fields.
* An example would be 'dateissued' for 'dc.date.issued' * An example would be 'dateissued' for 'dc.date.issued'
*/ */
@rendersBrowseBy(BrowseByType.Date) @rendersBrowseBy(BrowseByType.Date)
@@ -55,12 +55,12 @@ export class BrowseByDatePageComponent extends BrowseByMetadataPageComponent {
}) })
.subscribe((params) => { .subscribe((params) => {
const metadataField = params.metadataField || this.defaultMetadataField; const metadataField = params.metadataField || this.defaultMetadataField;
this.metadata = params.metadata || this.defaultMetadata; this.browseId = params.id || this.defaultBrowseId;
this.startsWith = +params.startsWith || params.startsWith; this.startsWith = +params.startsWith || params.startsWith;
const searchOptions = browseParamsToOptions(params, Object.assign({}), this.sortConfig, this.metadata); const searchOptions = browseParamsToOptions(params, Object.assign({}), this.sortConfig, this.browseId);
this.updatePageWithItems(searchOptions, this.value); this.updatePageWithItems(searchOptions, this.value);
this.updateParent(params.scope); this.updateParent(params.scope);
this.updateStartsWithOptions(this.metadata, metadataField, params.scope); this.updateStartsWithOptions(this.browseId, metadataField, params.scope);
})); }));
} }

View File

@@ -1,7 +1,7 @@
<div class="container"> <div class="container">
<div class="browse-by-metadata w-100"> <div class="browse-by-metadata w-100">
<ds-browse-by *ngIf="startsWithOptions" class="col-xs-12 w-100" <ds-browse-by *ngIf="startsWithOptions" class="col-xs-12 w-100"
title="{{'browse.title' | translate:{collection: (parent$ | async)?.payload?.name || '', field: 'browse.metadata.' + metadata | translate, value: (value)? '&quot;' + value + '&quot;': ''} }}" title="{{'browse.title' | translate:{collection: (parent$ | async)?.payload?.name || '', field: 'browse.metadata.' + browseId | translate, value: (value)? '&quot;' + value + '&quot;': ''} }}"
[objects$]="(items$ !== undefined)? items$ : browseEntries$" [objects$]="(items$ !== undefined)? items$ : browseEntries$"
[paginationConfig]="paginationConfig" [paginationConfig]="paginationConfig"
[sortConfig]="sortConfig" [sortConfig]="sortConfig"

View File

@@ -24,7 +24,7 @@ import { BrowseByType, rendersBrowseBy } from '../+browse-by-switcher/browse-by-
}) })
/** /**
* Component for browsing (items) by metadata definition * Component for browsing (items) by metadata definition
* A metadata definition is a short term used to describe one or multiple metadata fields. * A metadata definition (a.k.a. browse id) is a short term used to describe one or multiple metadata fields.
* An example would be 'author' for 'dc.contributor.*' * An example would be 'author' for 'dc.contributor.*'
*/ */
@rendersBrowseBy(BrowseByType.Metadata) @rendersBrowseBy(BrowseByType.Metadata)
@@ -65,14 +65,14 @@ export class BrowseByMetadataPageComponent implements OnInit {
subs: Subscription[] = []; subs: Subscription[] = [];
/** /**
* The default metadata definition to resort to when none is provided * The default browse id to resort to when none is provided
*/ */
defaultMetadata = 'author'; defaultBrowseId = 'author';
/** /**
* The current metadata definition * The current browse id
*/ */
metadata = this.defaultMetadata; browseId = this.defaultBrowseId;
/** /**
* The type of StartsWith options to render * The type of StartsWith options to render
@@ -114,10 +114,10 @@ export class BrowseByMetadataPageComponent implements OnInit {
return Object.assign({}, params, queryParams); return Object.assign({}, params, queryParams);
}) })
.subscribe((params) => { .subscribe((params) => {
this.metadata = params.metadata || this.defaultMetadata; this.browseId = params.id || this.defaultBrowseId;
this.value = +params.value || params.value || ''; this.value = +params.value || params.value || '';
this.startsWith = +params.startsWith || params.startsWith; this.startsWith = +params.startsWith || params.startsWith;
const searchOptions = browseParamsToOptions(params, this.paginationConfig, this.sortConfig, this.metadata); const searchOptions = browseParamsToOptions(params, this.paginationConfig, this.sortConfig, this.browseId);
if (isNotEmpty(this.value)) { if (isNotEmpty(this.value)) {
this.updatePageWithItems(searchOptions, this.value); this.updatePageWithItems(searchOptions, this.value);
} else { } else {

View File

@@ -13,7 +13,7 @@ describe('BrowseBySwitcherComponent', () => {
const types = ENV_CONFIG.browseBy.types; const types = ENV_CONFIG.browseBy.types;
const params = new BehaviorSubject(createParamsWithMetadata('initialValue')); const params = new BehaviorSubject(createParamsWithId('initialValue'));
const activatedRouteStub = { const activatedRouteStub = {
params: params params: params
@@ -37,9 +37,9 @@ describe('BrowseBySwitcherComponent', () => {
})); }));
types.forEach((type) => { types.forEach((type) => {
describe(`when switching to a browse-by page for "${type.metadata}"`, () => { describe(`when switching to a browse-by page for "${type.id}"`, () => {
beforeEach(() => { beforeEach(() => {
params.next(createParamsWithMetadata(type.metadata)); params.next(createParamsWithId(type.id));
fixture.detectChanges(); fixture.detectChanges();
}); });
@@ -50,6 +50,6 @@ describe('BrowseBySwitcherComponent', () => {
}); });
}); });
export function createParamsWithMetadata(metadata) { export function createParamsWithId(id) {
return { metadata: metadata }; return { id: id };
} }

View File

@@ -30,8 +30,8 @@ export class BrowseBySwitcherComponent implements OnInit {
ngOnInit(): void { ngOnInit(): void {
this.browseByComponent = this.route.params.pipe( this.browseByComponent = this.route.params.pipe(
map((params) => { map((params) => {
const metadata = params.metadata; const id = params.id;
return this.config.browseBy.types.find((config: BrowseByTypeConfig) => config.metadata === metadata); return this.config.browseBy.types.find((config: BrowseByTypeConfig) => config.id === id);
}), }),
map((config: BrowseByTypeConfig) => getComponentByBrowseByType(config.type)) map((config: BrowseByTypeConfig) => getComponentByBrowseByType(config.type))
); );

View File

@@ -42,8 +42,8 @@ export class BrowseByTitlePageComponent extends BrowseByMetadataPageComponent {
return Object.assign({}, params, queryParams, data); return Object.assign({}, params, queryParams, data);
}) })
.subscribe((params) => { .subscribe((params) => {
this.metadata = params.metadata || this.defaultMetadata; this.browseId = params.id || this.defaultBrowseId;
this.updatePageWithItems(browseParamsToOptions(params, this.paginationConfig, this.sortConfig, this.metadata), undefined); this.updatePageWithItems(browseParamsToOptions(params, this.paginationConfig, this.sortConfig, this.browseId), undefined);
this.updateParent(params.scope) this.updateParent(params.scope)
})); }));
this.updateStartsWithTextOptions(); this.updateStartsWithTextOptions();

View File

@@ -12,14 +12,14 @@ describe('BrowseByGuard', () => {
const name = 'An interesting DSO'; const name = 'An interesting DSO';
const title = 'Author'; const title = 'Author';
const field = 'Author'; const field = 'Author';
const metadata = 'author'; const id = 'author';
const metadataField = 'dc.contributor'; const metadataField = 'dc.contributor';
const scope = '1234-65487-12354-1235'; const scope = '1234-65487-12354-1235';
const value = 'Filter'; const value = 'Filter';
beforeEach(() => { beforeEach(() => {
dsoService = { dsoService = {
findById: (id: string) => observableOf({ payload: { name: name }, hasSucceeded: true }) findById: (dsoId: string) => observableOf({ payload: { name: name }, hasSucceeded: true })
}; };
translateService = { translateService = {
@@ -35,7 +35,7 @@ describe('BrowseByGuard', () => {
metadataField, metadataField,
}, },
params: { params: {
metadata, id,
}, },
queryParams: { queryParams: {
scope, scope,
@@ -48,7 +48,7 @@ describe('BrowseByGuard', () => {
(canActivate) => { (canActivate) => {
const result = { const result = {
title, title,
metadata, id,
metadataField, metadataField,
collection: name, collection: name,
field, field,
@@ -67,7 +67,7 @@ describe('BrowseByGuard', () => {
metadataField, metadataField,
}, },
params: { params: {
metadata, id,
}, },
queryParams: { queryParams: {
scope scope
@@ -80,7 +80,7 @@ describe('BrowseByGuard', () => {
(canActivate) => { (canActivate) => {
const result = { const result = {
title, title,
metadata, id,
metadataField, metadataField,
collection: name, collection: name,
field, field,
@@ -99,7 +99,7 @@ describe('BrowseByGuard', () => {
metadataField, metadataField,
}, },
params: { params: {
metadata, id,
}, },
queryParams: { queryParams: {
value value
@@ -111,7 +111,7 @@ describe('BrowseByGuard', () => {
(canActivate) => { (canActivate) => {
const result = { const result = {
title, title,
metadata, id,
metadataField, metadataField,
collection: '', collection: '',
field, field,

View File

@@ -21,36 +21,36 @@ export class BrowseByGuard implements CanActivate {
canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot) { canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot) {
const title = route.data.title; const title = route.data.title;
const metadata = route.params.metadata || route.queryParams.metadata || route.data.metadata; const id = route.params.id || route.queryParams.id || route.data.id;
let metadataField = route.data.metadataField; let metadataField = route.data.metadataField;
if (hasNoValue(metadataField) && hasValue(metadata)) { if (hasNoValue(metadataField) && hasValue(id)) {
const config = this.config.browseBy.types.find((conf) => conf.metadata === metadata); const config = this.config.browseBy.types.find((conf) => conf.id === id);
if (hasValue(config) && hasValue(config.metadataField)) { if (hasValue(config) && hasValue(config.metadataField)) {
metadataField = config.metadataField; metadataField = config.metadataField;
} }
} }
const scope = route.queryParams.scope; const scope = route.queryParams.scope;
const value = route.queryParams.value; const value = route.queryParams.value;
const metadataTranslated = this.translate.instant('browse.metadata.' + metadata); const metadataTranslated = this.translate.instant('browse.metadata.' + id);
if (hasValue(scope)) { if (hasValue(scope)) {
const dsoAndMetadata$ = this.dsoService.findById(scope).pipe(getSucceededRemoteData()); const dsoAndMetadata$ = this.dsoService.findById(scope).pipe(getSucceededRemoteData());
return dsoAndMetadata$.pipe( return dsoAndMetadata$.pipe(
map((dsoRD) => { map((dsoRD) => {
const name = dsoRD.payload.name; const name = dsoRD.payload.name;
route.data = this.createData(title, metadata, metadataField, name, metadataTranslated, value); route.data = this.createData(title, id, metadataField, name, metadataTranslated, value);
return true; return true;
}) })
); );
} else { } else {
route.data = this.createData(title, metadata, metadataField, '', metadataTranslated, value); route.data = this.createData(title, id, metadataField, '', metadataTranslated, value);
return observableOf(true); return observableOf(true);
} }
} }
private createData(title, metadata, metadataField, collection, field, value) { private createData(title, id, metadataField, collection, field, value) {
return { return {
title: title, title: title,
metadata: metadata, id: id,
metadataField: metadataField, metadataField: metadataField,
collection: collection, collection: collection,
field: field, field: field,

View File

@@ -6,7 +6,7 @@ import { BrowseBySwitcherComponent } from './+browse-by-switcher/browse-by-switc
@NgModule({ @NgModule({
imports: [ imports: [
RouterModule.forChild([ RouterModule.forChild([
{ path: ':metadata', component: BrowseBySwitcherComponent, canActivate: [BrowseByGuard], data: { title: 'browse.title' } } { path: ':id', component: BrowseBySwitcherComponent, canActivate: [BrowseByGuard], data: { title: 'browse.title' } }
]) ])
] ]
}) })

View File

@@ -82,14 +82,14 @@ export class NavbarComponent extends MenuComponent implements OnInit {
const types = this.config.browseBy.types; const types = this.config.browseBy.types;
types.forEach((typeConfig) => { types.forEach((typeConfig) => {
menuList.push({ menuList.push({
id: `browse_global_by_${typeConfig.metadata}`, id: `browse_global_by_${typeConfig.id}`,
parentID: 'browse_global', parentID: 'browse_global',
active: false, active: false,
visible: true, visible: true,
model: { model: {
type: MenuItemType.LINK, type: MenuItemType.LINK,
text: `menu.section.browse_global_by_${typeConfig.metadata}`, text: `menu.section.browse_global_by_${typeConfig.id}`,
link: `/browse/${typeConfig.metadata}` link: `/browse/${typeConfig.id}`
} as LinkMenuItemModel } as LinkMenuItemModel
}); });
}); });

View File

@@ -1,6 +1,6 @@
<h3>{{'browse.comcol.head' | translate}}</h3> <h3>{{'browse.comcol.head' | translate}}</h3>
<ul> <ul>
<li *ngFor="let config of types"> <li *ngFor="let config of types">
<a [routerLink]="['/browse/' + config.metadata]" [queryParams]="{scope: id}">{{'browse.comcol.by.' + config.metadata | translate}}</a> <a [routerLink]="['/browse/' + config.id]" [queryParams]="{scope: id}">{{'browse.comcol.by.' + config.id | translate}}</a>
</li> </li>
</ul> </ul>

View File

@@ -9,7 +9,7 @@ export interface BrowseByTypeConfig extends Config {
* The browse id used for fetching browse data from the rest api * The browse id used for fetching browse data from the rest api
* e.g. author * e.g. author
*/ */
metadata: string; id: string;
/** /**
* The type of Browse-By page to render * The type of Browse-By page to render