Skip to content

Commit 2c543ad

Browse files
108588: Updated CommunityPageRoutingModule to use custom sections
1 parent bb0b66f commit 2c543ad

8 files changed

Lines changed: 112 additions & 119 deletions

File tree

Lines changed: 20 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -1,67 +1,24 @@
11
<div class="container">
2-
<ng-container *ngVar="(parent$ | async) as parent">
3-
<ng-container *ngIf="parent?.payload as parentContext">
4-
<div class="d-flex flex-row border-bottom mb-4 pb-4">
5-
6-
<header class="comcol-header mr-auto">
7-
<!-- Parent Name -->
8-
<ds-comcol-page-header [name]="dsoNameService.getName(parentContext)">
9-
</ds-comcol-page-header>
10-
<!-- Collection logo -->
11-
<ds-comcol-page-logo *ngIf="logo$"
12-
[logo]="(logo$ | async)?.payload"
13-
[alternateText]="'Community or Collection Logo'">
14-
</ds-comcol-page-logo>
15-
<!-- Handle -->
16-
<ds-themed-comcol-page-handle
17-
[content]="parentContext.handle"
18-
[title]="parentContext.type+'.page.handle'" >
19-
</ds-themed-comcol-page-handle>
20-
<!-- Introductory text -->
21-
<ds-comcol-page-content [content]="parentContext.introductoryText" [hasInnerHtml]="true">
22-
</ds-comcol-page-content>
23-
<!-- News -->
24-
<ds-comcol-page-content [content]="parentContext.sidebarText" [hasInnerHtml]="true" [title]="'community.page.news'">
25-
</ds-comcol-page-content>
26-
</header>
27-
<ds-dso-edit-menu></ds-dso-edit-menu>
28-
</div>
29-
<!-- Browse-By Links -->
30-
<ds-themed-comcol-page-browse-by [id]="parentContext.id" [contentType]="parentContext.type"></ds-themed-comcol-page-browse-by>
31-
</ng-container></ng-container>
32-
33-
<section class="comcol-page-browse-section">
2+
<section class="comcol-page-browse-section">
343
<div class="browse-by-metadata w-100">
35-
<ds-browse-by *ngIf="startsWithOptions" class="col-xs-12 w-100"
36-
title="{{'browse.title' | translate:
37-
{
38-
collection: dsoNameService.getName((parent$ | async)?.payload),
39-
field: 'browse.metadata.' + browseId | translate,
40-
startsWith: (startsWith)? ('browse.startsWith' | translate: { startsWith: '&quot;' + startsWith + '&quot;' }) : '',
41-
value: (value)? '&quot;' + value + '&quot;': ''
42-
} }}"
43-
parentname="{{dsoNameService.getName((parent$ | async)?.payload)}}"
44-
[objects$]="(items$ !== undefined)? items$ : browseEntries$"
45-
[paginationConfig]="(currentPagination$ |async)"
46-
[sortConfig]="(currentSort$ |async)"
47-
[type]="startsWithType"
48-
[startsWithOptions]="startsWithOptions"
49-
(prev)="goPrev()"
50-
(next)="goNext()">
51-
</ds-browse-by>
52-
<ds-themed-loading *ngIf="!startsWithOptions" message="{{'loading.browse-by-page' | translate}}"></ds-themed-loading>
53-
</div>
54-
</section>
55-
<ng-container *ngVar="(parent$ | async) as parent">
56-
<ng-container *ngIf="parent?.payload as parentContext">
57-
<footer *ngIf="parentContext.copyrightText" class="border-top my-5 pt-4">
58-
<div >
59-
60-
<!-- Copyright -->
61-
<ds-comcol-page-content [content]="parentContext.copyrightText" [hasInnerHtml]="true">
62-
</ds-comcol-page-content>
4+
<ds-browse-by *ngIf="startsWithOptions" class="col-xs-12 w-100"
5+
title="{{'browse.title' | translate:
6+
{
7+
collection: dsoNameService.getName((parent$ | async)?.payload),
8+
field: 'browse.metadata.' + browseId | translate,
9+
startsWith: (startsWith)? ('browse.startsWith' | translate: { startsWith: '&quot;' + startsWith + '&quot;' }) : '',
10+
value: (value)? '&quot;' + value + '&quot;': ''
11+
} }}"
12+
parentname="{{dsoNameService.getName((parent$ | async)?.payload)}}"
13+
[objects$]="(items$ !== undefined)? items$ : browseEntries$"
14+
[paginationConfig]="(currentPagination$ |async)"
15+
[sortConfig]="(currentSort$ |async)"
16+
[type]="startsWithType"
17+
[startsWithOptions]="startsWithOptions"
18+
(prev)="goPrev()"
19+
(next)="goNext()">
20+
</ds-browse-by>
21+
<ds-themed-loading *ngIf="!startsWithOptions" message="{{'loading.browse-by-page' | translate}}"></ds-themed-loading>
6322
</div>
64-
</footer>
65-
</ng-container>
66-
</ng-container>
23+
</section>
6724
</div>

src/app/community-page/community-page-routing.module.ts

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@ import { ThemedCommunityPageComponent } from './themed-community-page.component'
1616
import { MenuItemType } from '../shared/menu/menu-item-type.model';
1717
import { DSOEditMenuResolver } from '../shared/dso-page/dso-edit-menu.resolver';
1818
import { SubComColSectionComponent } from './sections/sub-com-col-section/sub-com-col-section.component';
19+
import { BrowseByI18nBreadcrumbResolver } from '../browse-by/browse-by-i18n-breadcrumb.resolver';
20+
import { BrowseByGuard } from '../browse-by/browse-by-guard';
21+
import { BrowseBySwitcherComponent } from '../browse-by/browse-by-switcher/browse-by-switcher.component';
1922

2023
@NgModule({
2124
imports: [
@@ -47,14 +50,24 @@ import { SubComColSectionComponent } from './sections/sub-com-col-section/sub-co
4750
canActivate: [AuthenticatedGuard],
4851
},
4952
{
50-
path: '**',
53+
path: '',
5154
component: ThemedCommunityPageComponent,
52-
pathMatch: 'full',
5355
children: [
5456
{
5557
path: '',
58+
pathMatch: 'full',
5659
component: SubComColSectionComponent,
5760
},
61+
{
62+
path: 'browse/:id',
63+
pathMatch: 'full',
64+
component: BrowseBySwitcherComponent,
65+
canActivate: [BrowseByGuard],
66+
resolve: {
67+
breadcrumb: BrowseByI18nBreadcrumbResolver,
68+
},
69+
data: { breadcrumbKey: 'browse.metadata' },
70+
},
5871
],
5972
}
6073
],

src/app/community-page/community-page.component.html

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
</ds-comcol-page-content>
1818
<!-- News -->
1919
<ds-comcol-page-content [content]="communityPayload.sidebarText" [hasInnerHtml]="true"
20-
[title]="'community.page.news'">
20+
[title]="'community.page.news'">
2121
</ds-comcol-page-content>
2222
</header>
2323
<ds-dso-edit-menu></ds-dso-edit-menu>
@@ -31,10 +31,9 @@
3131
<ds-themed-comcol-page-browse-by [id]="communityPayload.id" [contentType]="communityPayload.type">
3232
</ds-themed-comcol-page-browse-by>
3333

34-
<ds-themed-community-page-sub-community-list [community]="communityPayload"></ds-themed-community-page-sub-community-list>
35-
<ds-themed-community-page-sub-collection-list [community]="communityPayload"></ds-themed-community-page-sub-collection-list>
34+
<router-outlet></router-outlet>
3635
</section>
37-
<footer *ngIf="communityPayload.copyrightText" class="border-top my-5 pt-4">
36+
<footer *ngIf="communityPayload.copyrightText" class="border-top my-5 pt-4">
3837
<!-- Copyright -->
3938
<ds-comcol-page-content [content]="communityPayload.copyrightText" [hasInnerHtml]="true">
4039
</ds-comcol-page-content>

src/app/community-page/community-page.component.ts

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,10 @@
11
import { mergeMap, filter, map } from 'rxjs/operators';
22
import { ChangeDetectionStrategy, Component, OnInit } from '@angular/core';
33
import { ActivatedRoute, Router } from '@angular/router';
4-
54
import { Observable } from 'rxjs';
6-
import { CommunityDataService } from '../core/data/community-data.service';
75
import { RemoteData } from '../core/data/remote-data';
86
import { Bitstream } from '../core/shared/bitstream.model';
9-
107
import { Community } from '../core/shared/community.model';
11-
12-
import { MetadataService } from '../core/metadata/metadata.service';
13-
148
import { fadeInOut } from '../shared/animations/fade';
159
import { hasValue } from '../shared/empty.util';
1610
import { getAllSucceededRemoteDataPayload} from '../core/shared/operators';
@@ -53,8 +47,6 @@ export class CommunityPageComponent implements OnInit {
5347
communityPageRoute$: Observable<string>;
5448

5549
constructor(
56-
private communityDataService: CommunityDataService,
57-
private metadata: MetadataService,
5850
private route: ActivatedRoute,
5951
private router: Router,
6052
private authService: AuthService,

src/app/community-page/community-page.module.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,10 @@ import {
2121
} from './sections/sub-com-col-section/sub-collection-list/themed-community-page-sub-collection-list.component';
2222
import { DsoPageModule } from '../shared/dso-page/dso-page.module';
2323
import { SubComColSectionComponent } from './sections/sub-com-col-section/sub-com-col-section.component';
24+
import { BrowseByPageModule } from '../browse-by/browse-by-page.module';
2425

25-
const DECLARATIONS = [CommunityPageComponent,
26+
const DECLARATIONS = [
27+
CommunityPageComponent,
2628
ThemedCommunityPageComponent,
2729
ThemedCommunityPageSubCommunityListComponent,
2830
CommunityPageSubCollectionListComponent,
@@ -42,6 +44,7 @@ const DECLARATIONS = [CommunityPageComponent,
4244
CommunityFormModule,
4345
ComcolModule,
4446
DsoPageModule,
47+
BrowseByPageModule,
4548
],
4649
declarations: [
4750
...DECLARATIONS

src/app/community-page/sections/community-browse-section/community-browse-section.component.html

Whitespace-only changes.
Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,28 @@
11
<h2 class="comcol-browse-label h5">{{'browse.comcol.head' | translate}}</h2>
2-
<nav class="comcol-browse mb-4" aria-label="Browse Community or Collection">
2+
<nav *ngIf="(allOptions$ | async) as allOptions" class="comcol-browse mb-4" aria-label="Browse Community or Collection">
33
<div class="d-none d-sm-block">
44

55
<div class="list-group list-group-horizontal">
66
<a *ngFor="let option of allOptions"
77
class="list-group-item"
88
[routerLink]="option.routerLink"
99
[queryParams]="option.params"
10-
routerLinkActive="active">{{ option.label | translate }}</a>
10+
[class.active]="(currentOption$ | async)?.id === option.id">
11+
{{ option.label | translate }}
12+
</a>
1113
</div>
1214
</div>
1315

1416
<div class="d-block d-sm-none">
1517
<select name="browse-type"
1618
class="form-control"
1719
aria-label="Browse Community or Collection"
18-
(ngModelChange)="onSelectChange($event)" [ngModel]="currentOptionId$ | async">
20+
(change)="onSelectChange($event)">
1921
<option *ngFor="let option of allOptions"
20-
[ngValue]="option.id"
21-
[attr.selected]="(currentOptionId$ | async) === option.id ? 'selected' : null">{{ option.label | translate }}</option>
22+
[value]="option.id"
23+
[attr.selected]="(currentOption$ | async)?.id === option.id ? 'selected' : null">
24+
{{ option.label | translate }}
25+
</option>
2226
</select>
2327
</div>
2428
</nav>
Lines changed: 61 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
import { Component, Input, OnInit } from '@angular/core';
2-
import { Observable } from 'rxjs';
3-
import { map } from 'rxjs/operators';
4-
import { ActivatedRoute, Params, Router } from '@angular/router';
1+
import { Component, Input, OnInit, OnDestroy } from '@angular/core';
2+
import { BehaviorSubject, combineLatest, Observable, Subscription } from 'rxjs';
3+
import { map, take } from 'rxjs/operators';
4+
import { Router, EventType, Scroll } from '@angular/router';
55
import { getCommunityPageRoute } from '../../../community-page/community-page-routing-paths';
66
import { getCollectionPageRoute } from '../../../collection-page/collection-page-routing-paths';
77
import { getFirstCompletedRemoteData } from '../../../core/shared/operators';
@@ -26,62 +26,87 @@ export interface ComColPageNavOption {
2626
styleUrls: ['./comcol-page-browse-by.component.scss'],
2727
templateUrl: './comcol-page-browse-by.component.html'
2828
})
29-
export class ComcolPageBrowseByComponent implements OnInit {
29+
export class ComcolPageBrowseByComponent implements OnDestroy, OnInit {
3030
/**
3131
* The ID of the Community or Collection
3232
*/
3333
@Input() id: string;
3434
@Input() contentType: string;
3535

36-
allOptions: ComColPageNavOption[];
36+
allOptions$: Observable<ComColPageNavOption[]>;
3737

38-
currentOptionId$: Observable<string>;
38+
currentOption$: BehaviorSubject<ComColPageNavOption> = new BehaviorSubject(undefined);
39+
40+
subs: Subscription[] = [];
3941

4042
constructor(
41-
private route: ActivatedRoute,
42-
private router: Router,
43+
public router: Router,
4344
private browseService: BrowseService
4445
) {
4546
}
4647

4748
ngOnInit(): void {
48-
this.browseService.getBrowseDefinitions()
49-
.pipe(getFirstCompletedRemoteData<PaginatedList<BrowseDefinition>>())
50-
.subscribe((browseDefListRD: RemoteData<PaginatedList<BrowseDefinition>>) => {
49+
this.allOptions$ = this.browseService.getBrowseDefinitions().pipe(
50+
getFirstCompletedRemoteData(),
51+
map((browseDefListRD: RemoteData<PaginatedList<BrowseDefinition>>) => {
52+
const allOptions: ComColPageNavOption[] = [];
5153
if (browseDefListRD.hasSucceeded) {
52-
this.allOptions = browseDefListRD.payload.page
53-
.map((config: BrowseDefinition) => ({
54-
id: config.id,
55-
label: `browse.comcol.by.${config.id}`,
56-
routerLink: `/browse/${config.id}`,
57-
params: { scope: this.id }
58-
}));
59-
54+
let comColRoute: string;
6055
if (this.contentType === 'collection') {
61-
this.allOptions = [{
62-
id: this.id,
56+
comColRoute = getCollectionPageRoute(this.id);
57+
allOptions.push({
58+
id: 'recent_submissions',
6359
label: 'collection.page.browse.recent.head',
64-
routerLink: getCollectionPageRoute(this.id)
65-
}, ...this.allOptions];
60+
routerLink: comColRoute,
61+
});
6662
} else if (this.contentType === 'community') {
67-
this.allOptions = [{
68-
id: this.id,
63+
comColRoute = getCommunityPageRoute(this.id);
64+
allOptions.push({
65+
id: 'comcols',
6966
label: 'community.all-lists.head',
70-
routerLink: getCommunityPageRoute(this.id)
71-
}, ...this.allOptions];
67+
routerLink: comColRoute,
68+
});
7269
}
73-
}
74-
});
7570

76-
this.currentOptionId$ = this.route.params.pipe(
77-
map((params: Params) => params.id)
71+
allOptions.push(...browseDefListRD.payload.page.map((config: BrowseDefinition) => ({
72+
id: `browse_${config.id}`,
73+
label: `browse.comcol.by.${config.id}`,
74+
routerLink: `${comColRoute}/browse/${config.id}`,
75+
})));
76+
}
77+
return allOptions;
78+
}),
7879
);
80+
81+
this.subs.push(combineLatest([
82+
this.allOptions$,
83+
this.router.events,
84+
]).subscribe(([navOptions, scrollEvent]: [ComColPageNavOption[], Scroll]) => {
85+
if (scrollEvent.type === EventType.Scroll) {
86+
for (let option of navOptions) {
87+
if (option.routerLink === scrollEvent.routerEvent.urlAfterRedirects.split('?')[0]) {
88+
this.currentOption$.next(option);
89+
}
90+
}
91+
}
92+
}));
7993
}
8094

81-
onSelectChange(newId: string) {
82-
const selectedOption = this.allOptions
83-
.find((option: ComColPageNavOption) => option.id === newId);
95+
ngOnDestroy(): void {
96+
this.subs.forEach((sub: Subscription) => sub.unsubscribe());
97+
}
8498

85-
this.router.navigate([selectedOption.routerLink], { queryParams: selectedOption.params });
99+
onSelectChange(event: any): void {
100+
this.allOptions$.pipe(
101+
take(1),
102+
).subscribe((allOptions: ComColPageNavOption[]) => {
103+
for (let option of allOptions) {
104+
if (option.id === event.target.value) {
105+
this.currentOption$.next(option[0]);
106+
void this.router.navigate([option.routerLink], { queryParams: option.params });
107+
break;
108+
}
109+
}
110+
});
86111
}
87112
}

0 commit comments

Comments
 (0)