mirror of
https://github.com/DSpace/dspace-angular.git
synced 2025-10-07 10:04:11 +00:00
62063: Browse config refactoring property metadata to id
This commit is contained in:
@@ -153,25 +153,25 @@ module.exports = {
|
||||
// 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
|
||||
// id: 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',
|
||||
id: 'title',
|
||||
type: 'title'
|
||||
},
|
||||
{
|
||||
metadata: 'dateissued',
|
||||
id: 'dateissued',
|
||||
type: 'date',
|
||||
metadataField: 'dc.date.issued'
|
||||
},
|
||||
{
|
||||
metadata: 'author',
|
||||
id: 'author',
|
||||
type: 'metadata'
|
||||
},
|
||||
{
|
||||
metadata: 'subject',
|
||||
id: 'subject',
|
||||
type: 'metadata'
|
||||
}
|
||||
]
|
||||
|
@@ -22,7 +22,7 @@ import { BrowseByType, rendersBrowseBy } from '../+browse-by-switcher/browse-by-
|
||||
})
|
||||
/**
|
||||
* 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'
|
||||
*/
|
||||
@rendersBrowseBy(BrowseByType.Date)
|
||||
@@ -55,12 +55,12 @@ export class BrowseByDatePageComponent extends BrowseByMetadataPageComponent {
|
||||
})
|
||||
.subscribe((params) => {
|
||||
const metadataField = params.metadataField || this.defaultMetadataField;
|
||||
this.metadata = params.metadata || this.defaultMetadata;
|
||||
this.browseId = params.id || this.defaultBrowseId;
|
||||
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.updateParent(params.scope);
|
||||
this.updateStartsWithOptions(this.metadata, metadataField, params.scope);
|
||||
this.updateStartsWithOptions(this.browseId, metadataField, params.scope);
|
||||
}));
|
||||
}
|
||||
|
||||
|
@@ -1,7 +1,7 @@
|
||||
<div class="container">
|
||||
<div class="browse-by-metadata 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)? '"' + value + '"': ''} }}"
|
||||
title="{{'browse.title' | translate:{collection: (parent$ | async)?.payload?.name || '', field: 'browse.metadata.' + browseId | translate, value: (value)? '"' + value + '"': ''} }}"
|
||||
[objects$]="(items$ !== undefined)? items$ : browseEntries$"
|
||||
[paginationConfig]="paginationConfig"
|
||||
[sortConfig]="sortConfig"
|
||||
|
@@ -24,7 +24,7 @@ import { BrowseByType, rendersBrowseBy } from '../+browse-by-switcher/browse-by-
|
||||
})
|
||||
/**
|
||||
* 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.*'
|
||||
*/
|
||||
@rendersBrowseBy(BrowseByType.Metadata)
|
||||
@@ -65,14 +65,14 @@ export class BrowseByMetadataPageComponent implements OnInit {
|
||||
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
|
||||
@@ -114,10 +114,10 @@ export class BrowseByMetadataPageComponent implements OnInit {
|
||||
return Object.assign({}, params, queryParams);
|
||||
})
|
||||
.subscribe((params) => {
|
||||
this.metadata = params.metadata || this.defaultMetadata;
|
||||
this.browseId = params.id || this.defaultBrowseId;
|
||||
this.value = +params.value || params.value || '';
|
||||
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)) {
|
||||
this.updatePageWithItems(searchOptions, this.value);
|
||||
} else {
|
||||
|
@@ -13,7 +13,7 @@ describe('BrowseBySwitcherComponent', () => {
|
||||
|
||||
const types = ENV_CONFIG.browseBy.types;
|
||||
|
||||
const params = new BehaviorSubject(createParamsWithMetadata('initialValue'));
|
||||
const params = new BehaviorSubject(createParamsWithId('initialValue'));
|
||||
|
||||
const activatedRouteStub = {
|
||||
params: params
|
||||
@@ -37,9 +37,9 @@ describe('BrowseBySwitcherComponent', () => {
|
||||
}));
|
||||
|
||||
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(() => {
|
||||
params.next(createParamsWithMetadata(type.metadata));
|
||||
params.next(createParamsWithId(type.id));
|
||||
fixture.detectChanges();
|
||||
});
|
||||
|
||||
@@ -50,6 +50,6 @@ describe('BrowseBySwitcherComponent', () => {
|
||||
});
|
||||
});
|
||||
|
||||
export function createParamsWithMetadata(metadata) {
|
||||
return { metadata: metadata };
|
||||
export function createParamsWithId(id) {
|
||||
return { id: id };
|
||||
}
|
||||
|
@@ -30,8 +30,8 @@ export class BrowseBySwitcherComponent implements OnInit {
|
||||
ngOnInit(): void {
|
||||
this.browseByComponent = this.route.params.pipe(
|
||||
map((params) => {
|
||||
const metadata = params.metadata;
|
||||
return this.config.browseBy.types.find((config: BrowseByTypeConfig) => config.metadata === metadata);
|
||||
const id = params.id;
|
||||
return this.config.browseBy.types.find((config: BrowseByTypeConfig) => config.id === id);
|
||||
}),
|
||||
map((config: BrowseByTypeConfig) => getComponentByBrowseByType(config.type))
|
||||
);
|
||||
|
@@ -42,8 +42,8 @@ export class BrowseByTitlePageComponent extends BrowseByMetadataPageComponent {
|
||||
return Object.assign({}, params, queryParams, data);
|
||||
})
|
||||
.subscribe((params) => {
|
||||
this.metadata = params.metadata || this.defaultMetadata;
|
||||
this.updatePageWithItems(browseParamsToOptions(params, this.paginationConfig, this.sortConfig, this.metadata), undefined);
|
||||
this.browseId = params.id || this.defaultBrowseId;
|
||||
this.updatePageWithItems(browseParamsToOptions(params, this.paginationConfig, this.sortConfig, this.browseId), undefined);
|
||||
this.updateParent(params.scope)
|
||||
}));
|
||||
this.updateStartsWithTextOptions();
|
||||
|
@@ -12,14 +12,14 @@ describe('BrowseByGuard', () => {
|
||||
const name = 'An interesting DSO';
|
||||
const title = 'Author';
|
||||
const field = 'Author';
|
||||
const metadata = 'author';
|
||||
const id = 'author';
|
||||
const metadataField = 'dc.contributor';
|
||||
const scope = '1234-65487-12354-1235';
|
||||
const value = 'Filter';
|
||||
|
||||
beforeEach(() => {
|
||||
dsoService = {
|
||||
findById: (id: string) => observableOf({ payload: { name: name }, hasSucceeded: true })
|
||||
findById: (dsoId: string) => observableOf({ payload: { name: name }, hasSucceeded: true })
|
||||
};
|
||||
|
||||
translateService = {
|
||||
@@ -35,7 +35,7 @@ describe('BrowseByGuard', () => {
|
||||
metadataField,
|
||||
},
|
||||
params: {
|
||||
metadata,
|
||||
id,
|
||||
},
|
||||
queryParams: {
|
||||
scope,
|
||||
@@ -48,7 +48,7 @@ describe('BrowseByGuard', () => {
|
||||
(canActivate) => {
|
||||
const result = {
|
||||
title,
|
||||
metadata,
|
||||
id,
|
||||
metadataField,
|
||||
collection: name,
|
||||
field,
|
||||
@@ -67,7 +67,7 @@ describe('BrowseByGuard', () => {
|
||||
metadataField,
|
||||
},
|
||||
params: {
|
||||
metadata,
|
||||
id,
|
||||
},
|
||||
queryParams: {
|
||||
scope
|
||||
@@ -80,7 +80,7 @@ describe('BrowseByGuard', () => {
|
||||
(canActivate) => {
|
||||
const result = {
|
||||
title,
|
||||
metadata,
|
||||
id,
|
||||
metadataField,
|
||||
collection: name,
|
||||
field,
|
||||
@@ -99,7 +99,7 @@ describe('BrowseByGuard', () => {
|
||||
metadataField,
|
||||
},
|
||||
params: {
|
||||
metadata,
|
||||
id,
|
||||
},
|
||||
queryParams: {
|
||||
value
|
||||
@@ -111,7 +111,7 @@ describe('BrowseByGuard', () => {
|
||||
(canActivate) => {
|
||||
const result = {
|
||||
title,
|
||||
metadata,
|
||||
id,
|
||||
metadataField,
|
||||
collection: '',
|
||||
field,
|
||||
|
@@ -21,36 +21,36 @@ export class BrowseByGuard implements CanActivate {
|
||||
|
||||
canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot) {
|
||||
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;
|
||||
if (hasNoValue(metadataField) && hasValue(metadata)) {
|
||||
const config = this.config.browseBy.types.find((conf) => conf.metadata === metadata);
|
||||
if (hasNoValue(metadataField) && hasValue(id)) {
|
||||
const config = this.config.browseBy.types.find((conf) => conf.id === id);
|
||||
if (hasValue(config) && hasValue(config.metadataField)) {
|
||||
metadataField = config.metadataField;
|
||||
}
|
||||
}
|
||||
const scope = route.queryParams.scope;
|
||||
const value = route.queryParams.value;
|
||||
const metadataTranslated = this.translate.instant('browse.metadata.' + metadata);
|
||||
const metadataTranslated = this.translate.instant('browse.metadata.' + id);
|
||||
if (hasValue(scope)) {
|
||||
const dsoAndMetadata$ = this.dsoService.findById(scope).pipe(getSucceededRemoteData());
|
||||
return dsoAndMetadata$.pipe(
|
||||
map((dsoRD) => {
|
||||
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;
|
||||
})
|
||||
);
|
||||
} else {
|
||||
route.data = this.createData(title, metadata, metadataField, '', metadataTranslated, value);
|
||||
route.data = this.createData(title, id, metadataField, '', metadataTranslated, value);
|
||||
return observableOf(true);
|
||||
}
|
||||
}
|
||||
|
||||
private createData(title, metadata, metadataField, collection, field, value) {
|
||||
private createData(title, id, metadataField, collection, field, value) {
|
||||
return {
|
||||
title: title,
|
||||
metadata: metadata,
|
||||
id: id,
|
||||
metadataField: metadataField,
|
||||
collection: collection,
|
||||
field: field,
|
||||
|
@@ -6,7 +6,7 @@ import { BrowseBySwitcherComponent } from './+browse-by-switcher/browse-by-switc
|
||||
@NgModule({
|
||||
imports: [
|
||||
RouterModule.forChild([
|
||||
{ path: ':metadata', component: BrowseBySwitcherComponent, canActivate: [BrowseByGuard], data: { title: 'browse.title' } }
|
||||
{ path: ':id', component: BrowseBySwitcherComponent, canActivate: [BrowseByGuard], data: { title: 'browse.title' } }
|
||||
])
|
||||
]
|
||||
})
|
||||
|
@@ -82,14 +82,14 @@ export class NavbarComponent extends MenuComponent implements OnInit {
|
||||
const types = this.config.browseBy.types;
|
||||
types.forEach((typeConfig) => {
|
||||
menuList.push({
|
||||
id: `browse_global_by_${typeConfig.metadata}`,
|
||||
id: `browse_global_by_${typeConfig.id}`,
|
||||
parentID: 'browse_global',
|
||||
active: false,
|
||||
visible: true,
|
||||
model: {
|
||||
type: MenuItemType.LINK,
|
||||
text: `menu.section.browse_global_by_${typeConfig.metadata}`,
|
||||
link: `/browse/${typeConfig.metadata}`
|
||||
text: `menu.section.browse_global_by_${typeConfig.id}`,
|
||||
link: `/browse/${typeConfig.id}`
|
||||
} as LinkMenuItemModel
|
||||
});
|
||||
});
|
||||
|
@@ -1,6 +1,6 @@
|
||||
<h3>{{'browse.comcol.head' | translate}}</h3>
|
||||
<ul>
|
||||
<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>
|
||||
</ul>
|
||||
|
@@ -9,7 +9,7 @@ export interface BrowseByTypeConfig extends Config {
|
||||
* The browse id used for fetching browse data from the rest api
|
||||
* e.g. author
|
||||
*/
|
||||
metadata: string;
|
||||
id: string;
|
||||
|
||||
/**
|
||||
* The type of Browse-By page to render
|
||||
|
Reference in New Issue
Block a user