RSS feed from search results (Angular) (#3227)

* Port rss to 7.6 and upgrades to search functionality

* 116466: add missing imports

* 116466: fix tests and lint issues

* 116466: rss component use activated route data

* 116466: lint fixes

* 116466: More Lint fixes

---------

Co-authored-by: Nathan Buckingham <nathan.buckingham@atmire.com>
This commit is contained in:
Nathan Buckingham
2024-12-19 12:03:52 -05:00
committed by GitHub
parent 0ade76a99c
commit d13d8860f2
4 changed files with 107 additions and 28 deletions

View File

@@ -63,7 +63,7 @@ export const APP_ROUTES: Route[] = [
path: 'home', path: 'home',
loadChildren: () => import('./home-page/home-page-routes') loadChildren: () => import('./home-page/home-page-routes')
.then((m) => m.ROUTES), .then((m) => m.ROUTES),
data: { showBreadcrumbs: false }, data: { showBreadcrumbs: false, enableRSS: true },
providers: [provideSuggestionNotificationsState()], providers: [provideSuggestionNotificationsState()],
canActivate: [endUserAgreementCurrentUserGuard], canActivate: [endUserAgreementCurrentUserGuard],
}, },
@@ -101,12 +101,14 @@ export const APP_ROUTES: Route[] = [
path: COMMUNITY_MODULE_PATH, path: COMMUNITY_MODULE_PATH,
loadChildren: () => import('./community-page/community-page-routes') loadChildren: () => import('./community-page/community-page-routes')
.then((m) => m.ROUTES), .then((m) => m.ROUTES),
data: { enableRSS: true },
canActivate: [endUserAgreementCurrentUserGuard], canActivate: [endUserAgreementCurrentUserGuard],
}, },
{ {
path: COLLECTION_MODULE_PATH, path: COLLECTION_MODULE_PATH,
loadChildren: () => import('./collection-page/collection-page-routes') loadChildren: () => import('./collection-page/collection-page-routes')
.then((m) => m.ROUTES), .then((m) => m.ROUTES),
data: { showBreadcrumbs: false, enableRSS: true },
canActivate: [endUserAgreementCurrentUserGuard], canActivate: [endUserAgreementCurrentUserGuard],
}, },
{ {
@@ -137,6 +139,7 @@ export const APP_ROUTES: Route[] = [
path: 'mydspace', path: 'mydspace',
loadChildren: () => import('./my-dspace-page/my-dspace-page-routes') loadChildren: () => import('./my-dspace-page/my-dspace-page-routes')
.then((m) => m.ROUTES), .then((m) => m.ROUTES),
data: { enableRSS: true },
providers: [provideSuggestionNotificationsState()], providers: [provideSuggestionNotificationsState()],
canActivate: [authenticatedGuard, endUserAgreementCurrentUserGuard], canActivate: [authenticatedGuard, endUserAgreementCurrentUserGuard],
}, },
@@ -144,6 +147,7 @@ export const APP_ROUTES: Route[] = [
path: 'search', path: 'search',
loadChildren: () => import('./search-page/search-page-routes') loadChildren: () => import('./search-page/search-page-routes')
.then((m) => m.ROUTES), .then((m) => m.ROUTES),
data: { enableRSS: true },
canActivate: [endUserAgreementCurrentUserGuard], canActivate: [endUserAgreementCurrentUserGuard],
}, },
{ {
@@ -156,6 +160,7 @@ export const APP_ROUTES: Route[] = [
path: ADMIN_MODULE_PATH, path: ADMIN_MODULE_PATH,
loadChildren: () => import('./admin/admin-routes') loadChildren: () => import('./admin/admin-routes')
.then((m) => m.ROUTES), .then((m) => m.ROUTES),
data: { enableRSS: true },
canActivate: [siteAdministratorGuard, endUserAgreementCurrentUserGuard], canActivate: [siteAdministratorGuard, endUserAgreementCurrentUserGuard],
}, },
{ {
@@ -200,6 +205,7 @@ export const APP_ROUTES: Route[] = [
providers: [provideSubmissionState()], providers: [provideSubmissionState()],
loadChildren: () => import('./workflowitems-edit-page/workflowitems-edit-page-routes') loadChildren: () => import('./workflowitems-edit-page/workflowitems-edit-page-routes')
.then((m) => m.ROUTES), .then((m) => m.ROUTES),
data: { enableRSS: true },
canActivate: [endUserAgreementCurrentUserGuard], canActivate: [endUserAgreementCurrentUserGuard],
}, },
{ {

View File

@@ -1,5 +1,9 @@
<ng-container *ngIf="(isEnabled$ | async) && (hasRoute('home') || hasRoute('collections') || hasRoute('communities'))"> <ng-container
*ngIf="(isEnabled$ | async) && (isActivated$ | async)">
<div *ngIf="route$ | async as route" class="d-inline-block float-right margin-right"> <div *ngIf="route$ | async as route" class="d-inline-block float-right margin-right">
<a [href]="route" class="btn btn-secondary" [title]="'feed.description' | translate" [attr.aria-label]="'feed.description' | translate"><i class="fas fa-rss-square"></i></a> <a target="_blank" rel="noopener noreferrer" [href]="route" class="btn btn-secondary"
[title]="'feed.description' | translate" [attr.aria-label]="'feed.description' | translate">
<i class="fas fa-rss-square"></i>
</a>
</div> </div>
</ng-container> </ng-container>

View File

@@ -3,9 +3,17 @@ import {
TestBed, TestBed,
waitForAsync, waitForAsync,
} from '@angular/core/testing'; } from '@angular/core/testing';
import { Router } from '@angular/router'; import {
ActivatedRoute,
Router,
} from '@angular/router';
import { TranslateService } from '@ngx-translate/core';
import { of as observableOf } from 'rxjs'; import { of as observableOf } from 'rxjs';
import {
SortDirection,
SortOptions,
} from '../../core/cache/models/sort-options.model';
import { ConfigurationDataService } from '../../core/data/configuration-data.service'; import { ConfigurationDataService } from '../../core/data/configuration-data.service';
import { RemoteData } from '../../core/data/remote-data'; import { RemoteData } from '../../core/data/remote-data';
import { GroupDataService } from '../../core/eperson/group-data.service'; import { GroupDataService } from '../../core/eperson/group-data.service';
@@ -14,22 +22,24 @@ import { LinkHeadService } from '../../core/services/link-head.service';
import { Collection } from '../../core/shared/collection.model'; import { Collection } from '../../core/shared/collection.model';
import { ConfigurationProperty } from '../../core/shared/configuration-property.model'; import { ConfigurationProperty } from '../../core/shared/configuration-property.model';
import { SearchConfigurationService } from '../../core/shared/search/search-configuration.service'; import { SearchConfigurationService } from '../../core/shared/search/search-configuration.service';
import { MockActivatedRoute } from '../mocks/active-router.mock';
import { RouterMock } from '../mocks/router.mock'; import { RouterMock } from '../mocks/router.mock';
import { getMockTranslateService } from '../mocks/translate.service.mock';
import { PaginationComponentOptions } from '../pagination/pagination-component-options.model'; import { PaginationComponentOptions } from '../pagination/pagination-component-options.model';
import { import {
createSuccessfulRemoteDataObject, createSuccessfulRemoteDataObject,
createSuccessfulRemoteDataObject$, createSuccessfulRemoteDataObject$,
} from '../remote-data.utils'; } from '../remote-data.utils';
import { PaginatedSearchOptions } from '../search/models/paginated-search-options.model'; import { PaginatedSearchOptions } from '../search/models/paginated-search-options.model';
import { SearchFilter } from '../search/models/search-filter.model';
import { PaginationServiceStub } from '../testing/pagination-service.stub'; import { PaginationServiceStub } from '../testing/pagination-service.stub';
import { SearchConfigurationServiceStub } from '../testing/search-configuration-service.stub'; import { SearchConfigurationServiceStub } from '../testing/search-configuration-service.stub';
import { createPaginatedList } from '../testing/utils.test'; import { createPaginatedList } from '../testing/utils.test';
import { RSSComponent } from './rss.component'; import { RSSComponent } from './rss.component';
describe('RssComponent', () => { describe('RssComponent', () => {
let comp: RSSComponent; let comp: RSSComponent;
let options: SortOptions;
let fixture: ComponentFixture<RSSComponent>; let fixture: ComponentFixture<RSSComponent>;
let uuid: string; let uuid: string;
let query: string; let query: string;
@@ -69,6 +79,7 @@ describe('RssComponent', () => {
pageSize: 10, pageSize: 10,
currentPage: 1, currentPage: 1,
}), }),
sort: new SortOptions('dc.title', SortDirection.ASC),
})); }));
groupDataService = jasmine.createSpyObj('groupsDataService', { groupDataService = jasmine.createSpyObj('groupsDataService', {
findListByHref: createSuccessfulRemoteDataObject$(createPaginatedList([])), findListByHref: createSuccessfulRemoteDataObject$(createPaginatedList([])),
@@ -80,7 +91,6 @@ describe('RssComponent', () => {
paginatedSearchOptions: mockSearchOptions, paginatedSearchOptions: mockSearchOptions,
}; };
TestBed.configureTestingModule({ TestBed.configureTestingModule({
imports: [RSSComponent],
providers: [ providers: [
{ provide: GroupDataService, useValue: groupDataService }, { provide: GroupDataService, useValue: groupDataService },
{ provide: LinkHeadService, useValue: linkHeadService }, { provide: LinkHeadService, useValue: linkHeadService },
@@ -88,11 +98,15 @@ describe('RssComponent', () => {
{ provide: SearchConfigurationService, useValue: new SearchConfigurationServiceStub() }, { provide: SearchConfigurationService, useValue: new SearchConfigurationServiceStub() },
{ provide: PaginationService, useValue: paginationService }, { provide: PaginationService, useValue: paginationService },
{ provide: Router, useValue: new RouterMock() }, { provide: Router, useValue: new RouterMock() },
{ provide: ActivatedRoute, useValue: new MockActivatedRoute },
{ provide: TranslateService, useValue: getMockTranslateService() },
], ],
declarations: [],
}).compileComponents(); }).compileComponents();
})); }));
beforeEach(() => { beforeEach(() => {
options = new SortOptions('dc.title', SortDirection.DESC);
uuid = '2cfcf65e-0a51-4bcb-8592-b8db7b064790'; uuid = '2cfcf65e-0a51-4bcb-8592-b8db7b064790';
query = 'test'; query = 'test';
fixture = TestBed.createComponent(RSSComponent); fixture = TestBed.createComponent(RSSComponent);
@@ -100,18 +114,37 @@ describe('RssComponent', () => {
}); });
it('should formulate the correct url given params in url', () => { it('should formulate the correct url given params in url', () => {
const route = comp.formulateRoute(uuid, 'opensearch/search', query); const route = comp.formulateRoute(uuid, 'opensearch/search', options, query);
expect(route).toBe('/opensearch/search?format=atom&scope=2cfcf65e-0a51-4bcb-8592-b8db7b064790&query=test'); expect(route).toBe('/opensearch/search?format=atom&scope=2cfcf65e-0a51-4bcb-8592-b8db7b064790&sort=dc.title&sort_direction=DESC&query=test');
}); });
it('should skip uuid if its null', () => { it('should skip uuid if its null', () => {
const route = comp.formulateRoute(null, 'opensearch/search', query); const route = comp.formulateRoute(null, 'opensearch/search', options, query);
expect(route).toBe('/opensearch/search?format=atom&query=test'); expect(route).toBe('/opensearch/search?format=atom&sort=dc.title&sort_direction=DESC&query=test');
}); });
it('should default to query * if none provided', () => { it('should default to query * if none provided', () => {
const route = comp.formulateRoute(null, 'opensearch/search', null); const route = comp.formulateRoute(null, 'opensearch/search', options, null);
expect(route).toBe('/opensearch/search?format=atom&query=*'); expect(route).toBe('/opensearch/search?format=atom&sort=dc.title&sort_direction=DESC&query=*');
});
it('should include filters in opensearch url if provided', () => {
const filters = [
new SearchFilter('f.test', ['value','another value'], 'contains'), // should be split into two arguments, spaces should be URI-encoded
new SearchFilter('f.range', ['[1987 TO 1988]'], 'equals'), // value should be URI-encoded, ',equals' should not
];
const route = comp.formulateRoute(uuid, 'opensearch/search', options, query, filters);
expect(route).toBe('/opensearch/search?format=atom&scope=2cfcf65e-0a51-4bcb-8592-b8db7b064790&sort=dc.title&sort_direction=DESC&query=test&f.test=value,contains&f.test=another%20value,contains&f.range=%5B1987%20TO%201988%5D,equals');
});
it('should include configuration in opensearch url if provided', () => {
const route = comp.formulateRoute(uuid, 'opensearch/search', options, query, null, 'adminConfiguration');
expect(route).toBe('/opensearch/search?format=atom&scope=2cfcf65e-0a51-4bcb-8592-b8db7b064790&sort=dc.title&sort_direction=DESC&query=test&configuration=adminConfiguration');
});
it('should include rpp in opensearch url if provided', () => {
const route = comp.formulateRoute(uuid, 'opensearch/search', options, query, null, null, 50);
expect(route).toBe('/opensearch/search?format=atom&scope=2cfcf65e-0a51-4bcb-8592-b8db7b064790&sort=dc.title&sort_direction=DESC&query=test&rpp=50');
}); });
}); });

View File

@@ -9,11 +9,16 @@ import {
OnInit, OnInit,
ViewEncapsulation, ViewEncapsulation,
} from '@angular/core'; } from '@angular/core';
import { Router } from '@angular/router'; import {
import { TranslateModule } from '@ngx-translate/core'; ActivatedRoute,
Router,
} from '@angular/router';
import {
TranslateModule,
TranslateService,
} from '@ngx-translate/core';
import { import {
BehaviorSubject, BehaviorSubject,
Observable,
Subscription, Subscription,
} from 'rxjs'; } from 'rxjs';
import { import {
@@ -21,7 +26,8 @@ import {
switchMap, switchMap,
} from 'rxjs/operators'; } from 'rxjs/operators';
import { environment } from '../../../../src/environments/environment'; import { environment } from '../../../environments/environment';
import { SortOptions } from '../../core/cache/models/sort-options.model';
import { ConfigurationDataService } from '../../core/data/configuration-data.service'; import { ConfigurationDataService } from '../../core/data/configuration-data.service';
import { RemoteData } from '../../core/data/remote-data'; import { RemoteData } from '../../core/data/remote-data';
import { GroupDataService } from '../../core/eperson/group-data.service'; import { GroupDataService } from '../../core/eperson/group-data.service';
@@ -29,9 +35,12 @@ import { PaginationService } from '../../core/pagination/pagination.service';
import { LinkHeadService } from '../../core/services/link-head.service'; import { LinkHeadService } from '../../core/services/link-head.service';
import { getFirstCompletedRemoteData } from '../../core/shared/operators'; import { getFirstCompletedRemoteData } from '../../core/shared/operators';
import { SearchConfigurationService } from '../../core/shared/search/search-configuration.service'; import { SearchConfigurationService } from '../../core/shared/search/search-configuration.service';
import {
hasValue,
isUndefined,
} from '../empty.util';
import { PaginatedSearchOptions } from '../search/models/paginated-search-options.model'; import { PaginatedSearchOptions } from '../search/models/paginated-search-options.model';
import { SearchFilter } from '../search/models/search-filter.model';
/** /**
* The Rss feed button component. * The Rss feed button component.
*/ */
@@ -51,8 +60,9 @@ export class RSSComponent implements OnInit, OnDestroy {
isEnabled$: BehaviorSubject<boolean> = new BehaviorSubject<boolean>(null); isEnabled$: BehaviorSubject<boolean> = new BehaviorSubject<boolean>(null);
isActivated$: BehaviorSubject<boolean> = new BehaviorSubject<boolean>(false);
uuid: string; uuid: string;
configuration$: Observable<string>;
subs: Subscription[] = []; subs: Subscription[] = [];
@@ -61,7 +71,9 @@ export class RSSComponent implements OnInit, OnDestroy {
private configurationService: ConfigurationDataService, private configurationService: ConfigurationDataService,
private searchConfigurationService: SearchConfigurationService, private searchConfigurationService: SearchConfigurationService,
private router: Router, private router: Router,
protected paginationService: PaginationService) { private route: ActivatedRoute,
protected paginationService: PaginationService,
protected translateService: TranslateService) {
} }
/** /**
* Removes the linktag created when the component gets removed from the page. * Removes the linktag created when the component gets removed from the page.
@@ -78,8 +90,11 @@ export class RSSComponent implements OnInit, OnDestroy {
* Generates the link tags and the url to opensearch when the component is loaded. * Generates the link tags and the url to opensearch when the component is loaded.
*/ */
ngOnInit(): void { ngOnInit(): void {
this.configuration$ = this.searchConfigurationService.getCurrentConfiguration('default'); 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( this.subs.push(this.configurationService.findByPropertyName('websvc.opensearch.enable').pipe(
getFirstCompletedRemoteData(), getFirstCompletedRemoteData(),
).subscribe((result) => { ).subscribe((result) => {
@@ -106,7 +121,7 @@ export class RSSComponent implements OnInit, OnDestroy {
return null; return null;
} }
this.uuid = this.groupDataService.getUUIDFromString(this.router.url); this.uuid = this.groupDataService.getUUIDFromString(this.router.url);
const route = environment.rest.baseUrl + this.formulateRoute(this.uuid, openSearchUri, searchOptions.query); const route = environment.rest.baseUrl + this.formulateRoute(this.uuid, openSearchUri, searchOptions.sort, searchOptions.query, searchOptions.filters, searchOptions.configuration, searchOptions.pagination?.pageSize, searchOptions.fixedFilter);
this.addLinks(route); this.addLinks(route);
this.linkHeadService.addTag({ this.linkHeadService.addTag({
href: environment.rest.baseUrl + '/' + openSearchUri + '/service', href: environment.rest.baseUrl + '/' + openSearchUri + '/service',
@@ -122,20 +137,40 @@ export class RSSComponent implements OnInit, OnDestroy {
* Function created a route given the different params available to opensearch * Function created a route given the different params available to opensearch
* @param uuid The uuid if a scope is present * @param uuid The uuid if a scope is present
* @param opensearch openSearch uri * @param opensearch openSearch uri
* @param sort The sort options for the opensearch request
* @param query The query string that was provided in the search * @param query The query string that was provided in the search
* @returns The combine URL to opensearch * @returns The combine URL to opensearch
*/ */
formulateRoute(uuid: string, opensearch: string, query: string): string { formulateRoute(uuid: string, opensearch: string, sort?: SortOptions, query?: string, searchFilters?: SearchFilter[], configuration?: string, pageSize?: number, fixedFilter?: string): string {
let route = '?format=atom'; let route = 'format=atom';
if (uuid) { if (uuid) {
route += `&scope=${uuid}`; route += `&scope=${uuid}`;
} }
if (sort && sort.direction && sort.field && sort.field !== 'id') {
route += `&sort=${sort.field}&sort_direction=${sort.direction}`;
}
if (query) { if (query) {
route += `&query=${query}`; route += `&query=${query}`;
} else { } else {
route += `&query=*`; route += `&query=*`;
} }
route = '/' + opensearch + route; if (configuration) {
route += `&configuration=${configuration}`;
}
if (pageSize) {
route += `&rpp=${pageSize}`;
}
if (searchFilters) {
for (const filter of searchFilters) {
for (const val of filter.values) {
route += '&' + filter.key + '=' + encodeURIComponent(val) + (filter.operator ? ',' + filter.operator : '');
}
}
}
if (fixedFilter) {
route += '&' + fixedFilter;
}
route = '/' + opensearch + '?' + route;
return route; return route;
} }
@@ -169,4 +204,5 @@ export class RSSComponent implements OnInit, OnDestroy {
title: 'Sitewide RSS feed', title: 'Sitewide RSS feed',
}); });
} }
} }