Skip to content

Commit

Permalink
116466: rss component use activated route data
Browse files Browse the repository at this point in the history
  • Loading branch information
Nathan Buckingham committed Nov 21, 2024
1 parent 970f989 commit 974bac7
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 4 deletions.
8 changes: 7 additions & 1 deletion src/app/app-routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ export const APP_ROUTES: Route[] = [
path: 'home',
loadChildren: () => import('./home-page/home-page-routes')
.then((m) => m.ROUTES),
data: { showBreadcrumbs: false },
data: { showBreadcrumbs: false, enableRSS: true },
providers: [provideSuggestionNotificationsState()],
canActivate: [endUserAgreementCurrentUserGuard],
},
Expand Down Expand Up @@ -101,12 +101,14 @@ export const APP_ROUTES: Route[] = [
path: COMMUNITY_MODULE_PATH,
loadChildren: () => import('./community-page/community-page-routes')
.then((m) => m.ROUTES),
data: { enableRSS: true },
canActivate: [endUserAgreementCurrentUserGuard],
},
{
path: COLLECTION_MODULE_PATH,
loadChildren: () => import('./collection-page/collection-page-routes')
.then((m) => m.ROUTES),
data: { showBreadcrumbs: false, enableRSS: true },
canActivate: [endUserAgreementCurrentUserGuard],
},
{
Expand Down Expand Up @@ -137,13 +139,15 @@ export const APP_ROUTES: Route[] = [
path: 'mydspace',
loadChildren: () => import('./my-dspace-page/my-dspace-page-routes')
.then((m) => m.ROUTES),
data: { enableRSS: true },
providers: [provideSuggestionNotificationsState()],
canActivate: [authenticatedGuard, endUserAgreementCurrentUserGuard],
},
{
path: 'search',
loadChildren: () => import('./search-page/search-page-routes')
.then((m) => m.ROUTES),
data: { enableRSS: true },
canActivate: [endUserAgreementCurrentUserGuard],
},
{
Expand All @@ -156,6 +160,7 @@ export const APP_ROUTES: Route[] = [
path: ADMIN_MODULE_PATH,
loadChildren: () => import('./admin/admin-routes')
.then((m) => m.ROUTES),
data: { enableRSS: true },
canActivate: [siteAdministratorGuard, endUserAgreementCurrentUserGuard],
},
{
Expand Down Expand Up @@ -200,6 +205,7 @@ export const APP_ROUTES: Route[] = [
providers: [provideSubmissionState()],
loadChildren: () => import('./workflowitems-edit-page/workflowitems-edit-page-routes')
.then((m) => m.ROUTES),
data: { enableRSS: true },
canActivate: [endUserAgreementCurrentUserGuard],
},
{
Expand Down
2 changes: 1 addition & 1 deletion src/app/shared/rss-feed/rss.component.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<ng-container
*ngIf="(isEnabled$ | async) && (hasRoute('home') || hasRoute('exhibits') || hasRoute('workflow') || hasRoute('admin') || hasRoute('mydspace') || hasRoute('search') || hasRoute('collections') || hasRoute('communities'))">
*ngIf="(isEnabled$ | async) && (isActivated$ | async)">
<div *ngIf="route$ | async as route" class="d-inline-block float-right margin-right">
<a target="_blank" rel="noopener noreferrer" [href]="route" class="btn btn-secondary"
[title]="'feed.description' | translate" [attr.aria-label]="'feed.description' | translate">
Expand Down
4 changes: 3 additions & 1 deletion src/app/shared/rss-feed/rss.component.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import {
TestBed,
waitForAsync,
} from '@angular/core/testing';
import { Router } from '@angular/router';
import { ActivatedRoute, Router } from '@angular/router';

Check failure on line 6 in src/app/shared/rss-feed/rss.component.spec.ts

View workflow job for this annotation

GitHub Actions / tests (18.x)

Imports must be broken into multiple lines if there are more than 1 elements

Check failure on line 6 in src/app/shared/rss-feed/rss.component.spec.ts

View workflow job for this annotation

GitHub Actions / tests (20.x)

Imports must be broken into multiple lines if there are more than 1 elements
import { TranslateService } from '@ngx-translate/core';
import { of as observableOf } from 'rxjs';

Expand Down Expand Up @@ -32,6 +32,7 @@ import { PaginationServiceStub } from '../testing/pagination-service.stub';
import { SearchConfigurationServiceStub } from '../testing/search-configuration-service.stub';
import { createPaginatedList } from '../testing/utils.test';
import { RSSComponent } from './rss.component';
import { MockActivatedRoute } from '../mocks/active-router.mock';

describe('RssComponent', () => {
let comp: RSSComponent;
Expand Down Expand Up @@ -94,6 +95,7 @@ describe('RssComponent', () => {
{ provide: SearchConfigurationService, useValue: new SearchConfigurationServiceStub() },
{ provide: PaginationService, useValue: paginationService },
{ provide: Router, useValue: new RouterMock() },
{ provide: ActivatedRoute, useValue: new MockActivatedRoute },
{ provide: TranslateService, useValue: getMockTranslateService() },
],
declarations: [],
Expand Down
12 changes: 11 additions & 1 deletion src/app/shared/rss-feed/rss.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
OnInit,
ViewEncapsulation,
} from '@angular/core';
import { Router } from '@angular/router';
import { ActivatedRoute, Router } from '@angular/router';

Check failure on line 12 in src/app/shared/rss-feed/rss.component.ts

View workflow job for this annotation

GitHub Actions / tests (18.x)

Imports must be broken into multiple lines if there are more than 1 elements

Check failure on line 12 in src/app/shared/rss-feed/rss.component.ts

View workflow job for this annotation

GitHub Actions / tests (20.x)

Imports must be broken into multiple lines if there are more than 1 elements
import {
TranslateModule,
TranslateService,
Expand All @@ -34,6 +34,8 @@ import { getFirstCompletedRemoteData } from '../../core/shared/operators';
import { SearchConfigurationService } from '../../core/shared/search/search-configuration.service';
import { PaginatedSearchOptions } from '../search/models/paginated-search-options.model';
import { SearchFilter } from '../search/models/search-filter.model';
import { hasValue } from '../empty.util';
import { isUndefined } from 'lodash';

Check failure on line 38 in src/app/shared/rss-feed/rss.component.ts

View workflow job for this annotation

GitHub Actions / tests (18.x)

Import individual methods from the Lodash module

Check failure on line 38 in src/app/shared/rss-feed/rss.component.ts

View workflow job for this annotation

GitHub Actions / tests (20.x)

Import individual methods from the Lodash module
/**
* The Rss feed button component.
*/
Expand All @@ -53,6 +55,8 @@ export class RSSComponent implements OnInit, OnDestroy {

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

isActivated$: BehaviorSubject<boolean> = new BehaviorSubject<boolean>(false);

uuid: string;

subs: Subscription[] = [];
Expand All @@ -62,6 +66,7 @@ export class RSSComponent implements OnInit, OnDestroy {
private configurationService: ConfigurationDataService,
private searchConfigurationService: SearchConfigurationService,
private router: Router,
private route: ActivatedRoute,
protected paginationService: PaginationService,
protected translateService: TranslateService) {
}
Expand All @@ -80,6 +85,11 @@ export class RSSComponent implements OnInit, OnDestroy {
* Generates the link tags and the url to opensearch when the component is loaded.
*/
ngOnInit(): void {
if (hasValue(this.route.snapshot.data?.enableRSS)) {
this.isActivated$.next(this.route.snapshot.data.enableRSS);
} else if (isUndefined(this.route.snapshot.data?.enableRSS)) {
this.isActivated$.next(false);
}
this.subs.push(this.configurationService.findByPropertyName('websvc.opensearch.enable').pipe(
getFirstCompletedRemoteData(),
).subscribe((result) => {
Expand Down

0 comments on commit 974bac7

Please sign in to comment.