Skip to content

Commit f45c6bc

Browse files
Nathan Buckinghammohideen
authored andcommitted
116466: rss component use activated route data
1 parent 1a5cd96 commit f45c6bc

4 files changed

Lines changed: 32 additions & 9 deletions

File tree

src/app/app-routes.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ export const APP_ROUTES: Route[] = [
7979
data: {
8080
showBreadcrumbs: false,
8181
dsoPath: 'site',
82+
enableRSS: true,
8283
},
8384
providers: [provideSuggestionNotificationsState()],
8485
canActivate: [endUserAgreementCurrentUserGuard],
@@ -121,12 +122,14 @@ export const APP_ROUTES: Route[] = [
121122
path: COMMUNITY_MODULE_PATH,
122123
loadChildren: () => import('./community-page/community-page-routes')
123124
.then((m) => m.ROUTES),
125+
data: { enableRSS: true },
124126
canActivate: [endUserAgreementCurrentUserGuard],
125127
},
126128
{
127129
path: COLLECTION_MODULE_PATH,
128130
loadChildren: () => import('./collection-page/collection-page-routes')
129131
.then((m) => m.ROUTES),
132+
data: { showBreadcrumbs: false, enableRSS: true },
130133
canActivate: [endUserAgreementCurrentUserGuard],
131134
},
132135
{
@@ -157,13 +160,15 @@ export const APP_ROUTES: Route[] = [
157160
path: 'mydspace',
158161
loadChildren: () => import('./my-dspace-page/my-dspace-page-routes')
159162
.then((m) => m.ROUTES),
163+
data: { enableRSS: true },
160164
providers: [provideSuggestionNotificationsState()],
161165
canActivate: [authenticatedGuard, endUserAgreementCurrentUserGuard],
162166
},
163167
{
164168
path: 'search',
165169
loadChildren: () => import('./search-page/search-page-routes')
166170
.then((m) => m.ROUTES),
171+
data: { enableRSS: true },
167172
canActivate: [endUserAgreementCurrentUserGuard],
168173
},
169174
{
@@ -176,6 +181,7 @@ export const APP_ROUTES: Route[] = [
176181
path: ADMIN_MODULE_PATH,
177182
loadChildren: () => import('./admin/admin-routes')
178183
.then((m) => m.ROUTES),
184+
data: { enableRSS: true },
179185
canActivate: [siteAdministratorGuard, endUserAgreementCurrentUserGuard],
180186
},
181187
{
@@ -220,6 +226,7 @@ export const APP_ROUTES: Route[] = [
220226
providers: [provideSubmissionState()],
221227
loadChildren: () => import('./workflowitems-edit-page/workflowitems-edit-page-routes')
222228
.then((m) => m.ROUTES),
229+
data: { enableRSS: true },
223230
canActivate: [endUserAgreementCurrentUserGuard],
224231
},
225232
{

src/app/shared/rss-feed/rss.component.html

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
<ng-container *ngIf="(isEnabled$ | async) && (hasRoute('home') || hasRoute('collections') || hasRoute('communities'))">
1+
<ng-container
2+
*ngIf="(isEnabled$ | async) && (isActivated$ | async)">
23
<div *ngIf="route$ | async as route" class="d-inline-block float-right margin-right">
34
<a [href]="route" class="btn btn-secondary" [title]="'feed.description' | translate" [attr.aria-label]="'feed.description' | translate" role="button" tabindex="0"><i class="fas fa-rss-square"></i></a>
45
</div>

src/app/shared/rss-feed/rss.component.spec.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@ import {
33
TestBed,
44
waitForAsync,
55
} from '@angular/core/testing';
6-
import { Router } from '@angular/router';
6+
import { ActivatedRoute, Router } from '@angular/router';
7+
import { TranslateService } from '@ngx-translate/core';
78
import { of as observableOf } from 'rxjs';
89

910
import { ConfigurationDataService } from '../../core/data/configuration-data.service';
@@ -25,6 +26,7 @@ import { PaginationServiceStub } from '../testing/pagination-service.stub';
2526
import { SearchConfigurationServiceStub } from '../testing/search-configuration-service.stub';
2627
import { createPaginatedList } from '../testing/utils.test';
2728
import { RSSComponent } from './rss.component';
29+
import { MockActivatedRoute } from '../mocks/active-router.mock';
2830

2931

3032

@@ -88,6 +90,8 @@ describe('RssComponent', () => {
8890
{ provide: SearchConfigurationService, useValue: new SearchConfigurationServiceStub() },
8991
{ provide: PaginationService, useValue: paginationService },
9092
{ provide: Router, useValue: new RouterMock() },
93+
{ provide: ActivatedRoute, useValue: new MockActivatedRoute },
94+
{ provide: TranslateService, useValue: getMockTranslateService() },
9195
],
9296
}).compileComponents();
9397
}));

src/app/shared/rss-feed/rss.component.ts

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,11 @@ import {
99
OnInit,
1010
ViewEncapsulation,
1111
} from '@angular/core';
12-
import { Router } from '@angular/router';
13-
import { TranslateModule } from '@ngx-translate/core';
12+
import { ActivatedRoute, Router } from '@angular/router';
13+
import {
14+
TranslateModule,
15+
TranslateService,
16+
} from '@ngx-translate/core';
1417
import {
1518
BehaviorSubject,
1619
Observable,
@@ -30,8 +33,9 @@ import { LinkHeadService } from '../../core/services/link-head.service';
3033
import { getFirstCompletedRemoteData } from '../../core/shared/operators';
3134
import { SearchConfigurationService } from '../../core/shared/search/search-configuration.service';
3235
import { PaginatedSearchOptions } from '../search/models/paginated-search-options.model';
33-
34-
36+
import { SearchFilter } from '../search/models/search-filter.model';
37+
import { hasValue } from '../empty.util';
38+
import { isUndefined } from 'lodash';
3539
/**
3640
* The Rss feed button componenet.
3741
*/
@@ -51,6 +55,8 @@ export class RSSComponent implements OnInit, OnDestroy {
5155

5256
isEnabled$: BehaviorSubject<boolean> = new BehaviorSubject<boolean>(null);
5357

58+
isActivated$: BehaviorSubject<boolean> = new BehaviorSubject<boolean>(false);
59+
5460
uuid: string;
5561
configuration$: Observable<string>;
5662

@@ -61,7 +67,9 @@ export class RSSComponent implements OnInit, OnDestroy {
6167
private configurationService: ConfigurationDataService,
6268
private searchConfigurationService: SearchConfigurationService,
6369
private router: Router,
64-
protected paginationService: PaginationService) {
70+
private route: ActivatedRoute,
71+
protected paginationService: PaginationService,
72+
protected translateService: TranslateService) {
6573
}
6674
/**
6775
* Removes the linktag created when the component gets removed from the page.
@@ -78,8 +86,11 @@ export class RSSComponent implements OnInit, OnDestroy {
7886
* Generates the link tags and the url to opensearch when the component is loaded.
7987
*/
8088
ngOnInit(): void {
81-
this.configuration$ = this.searchConfigurationService.getCurrentConfiguration('default');
82-
89+
if (hasValue(this.route.snapshot.data?.enableRSS)) {
90+
this.isActivated$.next(this.route.snapshot.data.enableRSS);
91+
} else if (isUndefined(this.route.snapshot.data?.enableRSS)) {
92+
this.isActivated$.next(false);
93+
}
8394
this.subs.push(this.configurationService.findByPropertyName('websvc.opensearch.enable').pipe(
8495
getFirstCompletedRemoteData(),
8596
).subscribe((result) => {

0 commit comments

Comments
 (0)