mirror of
https://github.com/DSpace/dspace-angular.git
synced 2025-10-07 18:14:17 +00:00
Desktop view: also using allOptions array, and tidying
This commit is contained in:
@@ -1,23 +1,24 @@
|
|||||||
<h2 class="comcol-browse-label h5">{{'browse.comcol.head' | translate}}</h2>
|
<h2 class="comcol-browse-label h5">{{'browse.comcol.head' | translate}}</h2>
|
||||||
<nav class="comcol-browse mb-4" aria-label="Browse Community or Collection" >
|
<nav class="comcol-browse mb-4" aria-label="Browse Community or Collection">
|
||||||
<div class="d-none d-sm-block">
|
<div class="d-none d-sm-block">
|
||||||
|
|
||||||
<div class="list-group list-group-horizontal">
|
<div class="list-group list-group-horizontal">
|
||||||
<a *ngIf="contentType=='collection'" [routerLink]="['/collections/' + id ]" class="list-group-item" routerLinkActive="active">{{'collection.page.browse.recent.head' | translate}}</a>
|
<a *ngFor="let option of allOptions"
|
||||||
<a *ngIf="contentType=='community'" [routerLink]="['/communities/' + id ]" class="list-group-item" routerLinkActive="active" >{{'community.all-lists.head' | translate}}</a>
|
class="list-group-item"
|
||||||
<a *ngFor="let config of types" class="list-group-item" [routerLink]="['/browse/' + config.id]" [queryParams]="{scope: id}" routerLinkActive="active">{{'browse.comcol.by.' + config.id | translate}}</a>
|
[routerLink]="option.routerLink"
|
||||||
|
[queryParams]="option.params"
|
||||||
|
routerLinkActive="active">{{ option.label | translate }}</a>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="d-block d-sm-none">
|
|
||||||
|
|
||||||
|
<div class="d-block d-sm-none">
|
||||||
<select name="browse-type"
|
<select name="browse-type"
|
||||||
class="form-control"
|
class="form-control"
|
||||||
aria-label="Browse Community or Collection"
|
aria-label="Browse Community or Collection"
|
||||||
(ngModelChange)="onSelectChange($event)"
|
(ngModelChange)="onSelectChange($event)" [ngModel]="currentOptionId$ | async">
|
||||||
[ngModel]="currentOptionId$ | async">
|
|
||||||
<option *ngFor="let option of allOptions"
|
<option *ngFor="let option of allOptions"
|
||||||
[ngValue]="option.id"
|
[ngValue]="option.id"
|
||||||
[attr.selected]="(currentOptionId$ | async) === option.id ? 'selected' : null">{{ option.label | translate }}</option>
|
[attr.selected]="(currentOptionId$ | async) === option.id ? 'selected' : null">{{ option.label | translate }}</option>
|
||||||
</select>
|
</select>
|
||||||
</div>
|
</div>
|
||||||
</nav>
|
</nav>
|
||||||
|
@@ -1,4 +1,11 @@
|
|||||||
import { Component, Inject, Input, NgZone, OnDestroy, OnInit } from '@angular/core';
|
import {
|
||||||
|
ChangeDetectionStrategy,
|
||||||
|
Component,
|
||||||
|
Inject,
|
||||||
|
Input, NgZone,
|
||||||
|
OnDestroy,
|
||||||
|
OnInit
|
||||||
|
} from '@angular/core';
|
||||||
import { Observable } from 'rxjs/internal/Observable';
|
import { Observable } from 'rxjs/internal/Observable';
|
||||||
import { Subscription } from 'rxjs/internal/Subscription';
|
import { Subscription } from 'rxjs/internal/Subscription';
|
||||||
import { filter, map, startWith, tap } from 'rxjs/operators';
|
import { filter, map, startWith, tap } from 'rxjs/operators';
|
||||||
@@ -15,6 +22,7 @@ export interface ComColPageNavOption {
|
|||||||
routerLink: string
|
routerLink: string
|
||||||
params?: any;
|
params?: any;
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A component to display the "Browse By" section of a Community or Collection page
|
* A component to display the "Browse By" section of a Community or Collection page
|
||||||
* It expects the ID of the Community or Collection as input to be passed on as a scope
|
* It expects the ID of the Community or Collection as input to be passed on as a scope
|
||||||
@@ -22,7 +30,7 @@ export interface ComColPageNavOption {
|
|||||||
@Component({
|
@Component({
|
||||||
selector: 'ds-comcol-page-browse-by',
|
selector: 'ds-comcol-page-browse-by',
|
||||||
styleUrls: ['./comcol-page-browse-by.component.scss'],
|
styleUrls: ['./comcol-page-browse-by.component.scss'],
|
||||||
templateUrl: './comcol-page-browse-by.component.html',
|
templateUrl: './comcol-page-browse-by.component.html'
|
||||||
})
|
})
|
||||||
export class ComcolPageBrowseByComponent implements OnInit {
|
export class ComcolPageBrowseByComponent implements OnInit {
|
||||||
/**
|
/**
|
||||||
@@ -39,17 +47,20 @@ export class ComcolPageBrowseByComponent implements OnInit {
|
|||||||
|
|
||||||
currentOptionId$: Observable<string>;
|
currentOptionId$: Observable<string>;
|
||||||
|
|
||||||
constructor(@Inject(GLOBAL_CONFIG) public config: GlobalConfig, private route: ActivatedRoute, private router: Router) {
|
constructor(
|
||||||
|
@Inject(GLOBAL_CONFIG) public config: GlobalConfig,
|
||||||
|
private route: ActivatedRoute,
|
||||||
|
private router: Router) {
|
||||||
}
|
}
|
||||||
|
|
||||||
ngOnInit(): void {
|
ngOnInit(): void {
|
||||||
this.allOptions = this.config.browseBy.types
|
this.allOptions = this.config.browseBy.types
|
||||||
.map((config: BrowseByTypeConfig) => ({
|
.map((config: BrowseByTypeConfig) => ({
|
||||||
id: config.id,
|
id: config.id,
|
||||||
label: `browse.comcol.by.${config.id}`,
|
label: `browse.comcol.by.${config.id}`,
|
||||||
routerLink: `/browse/${config.id}`,
|
routerLink: `/browse/${config.id}`,
|
||||||
params: { scope: this.id }
|
params: { scope: this.id }
|
||||||
}));
|
}));
|
||||||
|
|
||||||
if (this.contentType === 'collection') {
|
if (this.contentType === 'collection') {
|
||||||
this.allOptions = [ {
|
this.allOptions = [ {
|
||||||
@@ -64,14 +75,17 @@ export class ComcolPageBrowseByComponent implements OnInit {
|
|||||||
routerLink: getCommunityPageRoute(this.id)
|
routerLink: getCommunityPageRoute(this.id)
|
||||||
}, ...this.allOptions ];
|
}, ...this.allOptions ];
|
||||||
}
|
}
|
||||||
|
|
||||||
this.currentOptionId$ = this.route.url.pipe(
|
this.currentOptionId$ = this.route.url.pipe(
|
||||||
filter((urlSegments: UrlSegment[]) => hasValue(urlSegments)),
|
filter((urlSegments: UrlSegment[]) => hasValue(urlSegments)),
|
||||||
map((urlSegments: UrlSegment[]) => urlSegments[urlSegments.length - 1].path)
|
map((urlSegments: UrlSegment[]) => urlSegments[urlSegments.length - 1].path)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
onSelectChange(newId: string) {
|
onSelectChange(newId: string) {
|
||||||
const selectedOption = this.allOptions
|
const selectedOption = this.allOptions
|
||||||
.find((option: ComColPageNavOption) => option.id === newId);
|
.find((option: ComColPageNavOption) => option.id === newId);
|
||||||
this.router.navigate([selectedOption.routerLink], { queryParams: selectedOption.params });
|
|
||||||
|
this.router.navigate([selectedOption.routerLink], { queryParams: selectedOption.params });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user