Merge pull request #4217 from kshepherd/rss-sort-link-fix

Several fixes to RSS component and object lists
This commit is contained in:
Tim Donohue
2025-04-29 08:58:47 -05:00
committed by GitHub
16 changed files with 153 additions and 65 deletions

View File

@@ -109,14 +109,12 @@ 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: { enableRSS: true },
canActivate: [endUserAgreementCurrentUserGuard], canActivate: [endUserAgreementCurrentUserGuard],
}, },
{ {

View File

@@ -100,6 +100,7 @@ export const ROUTES: Route[] = [
data: { data: {
breadcrumbKey: 'collection.search', breadcrumbKey: 'collection.search',
menuRoute: MenuRoute.COLLECTION_PAGE, menuRoute: MenuRoute.COLLECTION_PAGE,
enableRSS: true,
}, },
}, },
{ {

View File

@@ -90,6 +90,7 @@ export const ROUTES: Route[] = [
data: { data: {
breadcrumbKey: 'community.search', breadcrumbKey: 'community.search',
menuRoute: MenuRoute.COMMUNITY_PAGE, menuRoute: MenuRoute.COMMUNITY_PAGE,
enableRSS: true,
}, },
}, },
{ {

View File

@@ -8,6 +8,7 @@
<ds-viewable-collection <ds-viewable-collection
[config]="config" [config]="config"
[sortConfig]="sortConfig" [sortConfig]="sortConfig"
[showRSS]="rssSortConfig"
[objects]="communitiesRD$ | async" [objects]="communitiesRD$ | async"
[hideGear]="true"> [hideGear]="true">
</ds-viewable-collection> </ds-viewable-collection>

View File

@@ -65,9 +65,10 @@ export class TopLevelCommunityListComponent implements OnInit, OnDestroy {
pageId = 'tl'; pageId = 'tl';
/** /**
* The sorting configuration * The sorting configuration for the community list itself, and the optional RSS feed button
*/ */
sortConfig: SortOptions; sortConfig: SortOptions;
rssSortConfig: SortOptions;
/** /**
* The subscription to the observable for the current page. * The subscription to the observable for the current page.
@@ -84,6 +85,7 @@ export class TopLevelCommunityListComponent implements OnInit, OnDestroy {
this.config.pageSize = appConfig.homePage.topLevelCommunityList.pageSize; this.config.pageSize = appConfig.homePage.topLevelCommunityList.pageSize;
this.config.currentPage = 1; this.config.currentPage = 1;
this.sortConfig = new SortOptions('dc.title', SortDirection.ASC); this.sortConfig = new SortOptions('dc.title', SortDirection.ASC);
this.rssSortConfig = new SortOptions('dc.date.accessioned', SortDirection.DESC);
} }
ngOnInit() { ngOnInit() {

View File

@@ -13,6 +13,7 @@
[linkType]="linkType" [linkType]="linkType"
[context]="context" [context]="context"
[hidePaginationDetail]="hidePaginationDetail" [hidePaginationDetail]="hidePaginationDetail"
[showRSS]="showRSS"
[showPaginator]="showPaginator" [showPaginator]="showPaginator"
[showThumbnails]="showThumbnails" [showThumbnails]="showThumbnails"
(paginationChange)="onPaginationChange($event)" (paginationChange)="onPaginationChange($event)"
@@ -58,6 +59,7 @@
[sortConfig]="sortConfig" [sortConfig]="sortConfig"
[objects]="objects" [objects]="objects"
[hideGear]="hideGear" [hideGear]="hideGear"
[showRSS]="showRSS"
[linkType]="linkType" [linkType]="linkType"
[context]="context" [context]="context"
[hidePaginationDetail]="hidePaginationDetail" [hidePaginationDetail]="hidePaginationDetail"

View File

@@ -71,17 +71,22 @@ export class ObjectCollectionComponent implements OnInit {
@Input() sortConfig: SortOptions; @Input() sortConfig: SortOptions;
/** /**
* Whether or not the list elements have a border or not * Whether the list elements have a border or not
*/ */
@Input() hasBorder = false; @Input() hasBorder = false;
/** /**
* Whether or not to hide the gear to change the sort and pagination configuration * Whether to hide the gear to change the sort and pagination configuration
*/ */
@Input() hideGear = false; @Input() hideGear = false;
@Input() selectable = false; @Input() selectable = false;
@Input() selectionConfig: {repeatable: boolean, listId: string}; @Input() selectionConfig: {repeatable: boolean, listId: string};
/**
* Whether to show an RSS syndication button for the current search options
*/
@Input() showRSS: SortOptions | boolean = false;
/** /**
* Emit custom event for listable object custom actions. * Emit custom event for listable object custom actions.
*/ */

View File

@@ -4,6 +4,7 @@
[sortOptions]="sortConfig" [sortOptions]="sortConfig"
[objects]="objects" [objects]="objects"
[hideGear]="hideGear" [hideGear]="hideGear"
[showRSS]="showRSS"
[hidePaginationDetail]="hidePaginationDetail" [hidePaginationDetail]="hidePaginationDetail"
[hidePagerWhenSinglePage]="hidePagerWhenSinglePage" [hidePagerWhenSinglePage]="hidePagerWhenSinglePage"
[showPaginator]="showPaginator" [showPaginator]="showPaginator"

View File

@@ -85,6 +85,11 @@ export class ObjectDetailComponent {
*/ */
@Input() showThumbnails; @Input() showThumbnails;
/**
* Whether to show the RSS syndication link. Either false, or valid SortOptions object
*/
@Input() showRSS: SortOptions | boolean = false;
/** /**
* Emit when one of the listed object has changed. * Emit when one of the listed object has changed.
*/ */

View File

@@ -4,6 +4,7 @@
[objects]="objects" [objects]="objects"
[sortOptions]="sortConfig" [sortOptions]="sortConfig"
[hideGear]="hideGear" [hideGear]="hideGear"
[showRSS]="showRSS"
[hidePagerWhenSinglePage]="hidePagerWhenSinglePage" [hidePagerWhenSinglePage]="hidePagerWhenSinglePage"
[hidePaginationDetail]="hidePaginationDetail" [hidePaginationDetail]="hidePaginationDetail"
[showPaginator]="showPaginator" [showPaginator]="showPaginator"

View File

@@ -39,7 +39,7 @@ import { SelectableListService } from './selectable-list/selectable-list.service
}) })
export class ObjectListComponent { export class ObjectListComponent {
/** /**
* The view mode of the this component * The view mode of this component
*/ */
viewMode = ViewMode.ListElement; viewMode = ViewMode.ListElement;
@@ -70,6 +70,11 @@ export class ObjectListComponent {
@Input() selectable = false; @Input() selectable = false;
@Input() selectionConfig: { repeatable: boolean, listId: string }; @Input() selectionConfig: { repeatable: boolean, listId: string };
/**
* Whether to show an RSS syndication button for the current search options
*/
@Input() showRSS: SortOptions | boolean = false;
/** /**
* The link type of the listable elements * The link type of the listable elements
*/ */

View File

@@ -59,6 +59,8 @@ export class ThemedObjectListComponent extends ThemedComponent<ObjectListCompone
@Input() selectionConfig: { repeatable: boolean, listId: string }; @Input() selectionConfig: { repeatable: boolean, listId: string };
@Input() showRSS: SortOptions | boolean = false;
/** /**
* The link type of the listable elements * The link type of the listable elements
*/ */
@@ -163,6 +165,7 @@ export class ThemedObjectListComponent extends ThemedComponent<ObjectListCompone
'sortConfig', 'sortConfig',
'hasBorder', 'hasBorder',
'hideGear', 'hideGear',
'showRSS',
'hidePagerWhenSinglePage', 'hidePagerWhenSinglePage',
'selectable', 'selectable',
'selectionConfig', 'selectionConfig',

View File

@@ -43,7 +43,9 @@
</ul> </ul>
</div> </div>
} }
<ds-rss></ds-rss> @if (showRSS !== false) {
<ds-rss [sortConfig]="rssSortOptions"></ds-rss>
}
</div> </div>
</div> </div>
</div> </div>

View File

@@ -168,6 +168,13 @@ export class PaginationComponent implements OnChanges, OnDestroy, OnInit {
*/ */
@Input() public retainScrollPosition = false; @Input() public retainScrollPosition = false;
/**
* Options for showing or hiding the RSS syndication feed. This is useful for e.g. top-level community lists
* or other lists where an RSS feed doesn't make sense, but uses the same components as recent items or search result
* lists.
*/
@Input() public showRSS: SortOptions | boolean = false;
/** /**
* Current page. * Current page.
*/ */
@@ -266,7 +273,6 @@ export class PaginationComponent implements OnChanges, OnDestroy, OnInit {
* Initializes all default variables * Initializes all default variables
*/ */
private initializeConfig() { private initializeConfig() {
// Set initial values
this.id = this.paginationOptions.id || null; this.id = this.paginationOptions.id || null;
this.pageSizeOptions = this.paginationOptions.pageSizeOptions; this.pageSizeOptions = this.paginationOptions.pageSizeOptions;
this.currentPage$ = this.paginationService.getCurrentPagination(this.id, this.paginationOptions).pipe( this.currentPage$ = this.paginationService.getCurrentPagination(this.id, this.paginationOptions).pipe(
@@ -436,4 +442,19 @@ export class PaginationComponent implements OnChanges, OnDestroy, OnInit {
}); });
} }
/**
* Get the sort options to use for the RSS feed. Defaults to the sort options used for this pagination component
* so it matches the search/browse context, but also allows more flexibility if, for example a top-level community
* list is displayed in "title asc" order, but the RSS feed should default to an item list of "date desc" order.
* If the SortOptions are null, incomplete or invalid, the pagination sortOptions will be used instead.
*/
get rssSortOptions() {
if (this.showRSS !== false && this.showRSS instanceof SortOptions
&& this.showRSS.direction !== null
&& this.showRSS.field !== null) {
return this.showRSS;
}
return this.sortOptions;
}
} }

View File

@@ -2,12 +2,16 @@ import { AsyncPipe } from '@angular/common';
import { import {
ChangeDetectionStrategy, ChangeDetectionStrategy,
Component, Component,
Input,
OnChanges,
OnDestroy, OnDestroy,
OnInit, OnInit,
SimpleChanges,
ViewEncapsulation, ViewEncapsulation,
} from '@angular/core'; } from '@angular/core';
import { import {
ActivatedRoute, ActivatedRoute,
NavigationEnd,
Router, Router,
} from '@angular/router'; } from '@angular/router';
import { import {
@@ -16,12 +20,10 @@ import {
} from '@ngx-translate/core'; } from '@ngx-translate/core';
import { import {
BehaviorSubject, BehaviorSubject,
filter,
Subscription, Subscription,
} from 'rxjs'; } from 'rxjs';
import { import { map } from 'rxjs/operators';
map,
switchMap,
} from 'rxjs/operators';
import { environment } from '../../../environments/environment'; import { environment } from '../../../environments/environment';
import { SortOptions } from '../../core/cache/models/sort-options.model'; import { SortOptions } from '../../core/cache/models/sort-options.model';
@@ -36,8 +38,8 @@ import {
hasValue, hasValue,
isUndefined, isUndefined,
} from '../empty.util'; } from '../empty.util';
import { PaginatedSearchOptions } from '../search/models/paginated-search-options.model';
import { SearchFilter } from '../search/models/search-filter.model'; import { SearchFilter } from '../search/models/search-filter.model';
/** /**
* The Rss feed button component. * The Rss feed button component.
*/ */
@@ -51,17 +53,16 @@ import { SearchFilter } from '../search/models/search-filter.model';
standalone: true, standalone: true,
imports: [AsyncPipe, TranslateModule], imports: [AsyncPipe, TranslateModule],
}) })
export class RSSComponent implements OnInit, OnDestroy { export class RSSComponent implements OnInit, OnDestroy, OnChanges {
route$: BehaviorSubject<string> = new BehaviorSubject<string>(''); route$: BehaviorSubject<string> = new BehaviorSubject<string>('');
isEnabled$: BehaviorSubject<boolean> = new BehaviorSubject<boolean>(null); isEnabled$: BehaviorSubject<boolean> = new BehaviorSubject<boolean>(null);
isActivated$: BehaviorSubject<boolean> = new BehaviorSubject<boolean>(false); isActivated$: BehaviorSubject<boolean> = new BehaviorSubject<boolean>(false);
@Input() sortConfig?: SortOptions;
uuid: string; uuid: string;
subs: Subscription[] = []; subs: Subscription[] = [];
openSearchUri: string;
constructor(private groupDataService: GroupDataService, constructor(private groupDataService: GroupDataService,
private linkHeadService: LinkHeadService, private linkHeadService: LinkHeadService,
@@ -72,9 +73,7 @@ export class RSSComponent implements OnInit, OnDestroy {
protected paginationService: PaginationService, protected paginationService: PaginationService,
protected translateService: TranslateService) { protected translateService: TranslateService) {
} }
/**
* Removes the linktag created when the component gets removed from the page.
*/
ngOnDestroy(): void { ngOnDestroy(): void {
this.linkHeadService.removeTag("rel='alternate'"); this.linkHeadService.removeTag("rel='alternate'");
this.subs.forEach(sub => { this.subs.forEach(sub => {
@@ -82,24 +81,52 @@ export class RSSComponent implements OnInit, OnDestroy {
}); });
} }
/**
* Generates the link tags and the url to opensearch when the component is loaded.
*/
ngOnInit(): void { ngOnInit(): void {
// Set initial activation state
if (hasValue(this.route.snapshot.data?.enableRSS)) { if (hasValue(this.route.snapshot.data?.enableRSS)) {
this.isActivated$.next(this.route.snapshot.data.enableRSS); this.isActivated$.next(this.route.snapshot.data.enableRSS);
} else if (isUndefined(this.route.snapshot.data?.enableRSS)) { } else if (isUndefined(this.route.snapshot.data?.enableRSS)) {
this.isActivated$.next(false); this.isActivated$.next(false);
} }
// Get initial UUID from URL
this.uuid = this.groupDataService.getUUIDFromString(this.router.url);
// Check if RSS is enabled
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) => {
if (result.hasSucceeded) { if (result.hasSucceeded) {
const enabled = (result.payload.values[0] === 'true'); const enabled = (result.payload.values[0] === 'true');
this.isEnabled$.next(enabled); this.isEnabled$.next(enabled);
// If enabled, get the OpenSearch URI
if (enabled) {
this.getOpenSearchUri();
}
} }
})); }));
// Listen for navigation events to update the UUID
this.subs.push(this.router.events.pipe(
filter(event => event instanceof NavigationEnd),
).subscribe(() => {
this.uuid = this.groupDataService.getUUIDFromString(this.router.url);
this.updateRssLinks();
}));
}
ngOnChanges(changes: SimpleChanges): void {
// If sortConfig changes, update the RSS links
if (changes.sortConfig && this.openSearchUri && this.isEnabled$.getValue()) {
this.updateRssLinks();
}
}
/**
* Get the OpenSearch URI and update RSS links
*/
private getOpenSearchUri(): void {
this.subs.push(this.configurationService.findByPropertyName('websvc.opensearch.svccontext').pipe( this.subs.push(this.configurationService.findByPropertyName('websvc.opensearch.svccontext').pipe(
getFirstCompletedRemoteData(), getFirstCompletedRemoteData(),
map((result: RemoteData<any>) => { map((result: RemoteData<any>) => {
@@ -108,35 +135,60 @@ export class RSSComponent implements OnInit, OnDestroy {
} }
return null; return null;
}), }),
switchMap((openSearchUri: string) => filter(uri => !!uri),
this.searchConfigurationService.paginatedSearchOptions.pipe( ).subscribe(uri => {
map((searchOptions: PaginatedSearchOptions) => ({ openSearchUri, searchOptions })), this.openSearchUri = uri;
), this.updateRssLinks();
),
).subscribe(({ openSearchUri, searchOptions }) => {
if (!openSearchUri) {
return null;
}
this.uuid = this.groupDataService.getUUIDFromString(this.router.url);
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.linkHeadService.addTag({
href: environment.rest.baseUrl + '/' + openSearchUri + '/service',
type: 'application/atom+xml',
rel: 'search',
title: 'Dspace',
});
this.route$.next(route);
})); }));
} }
/** /**
* Function created a route given the different params available to opensearch * Update RSS links based on current search configuration and sortConfig input
* @param uuid The uuid if a scope is present */
* @param opensearch openSearch uri private updateRssLinks(): void {
* @param sort The sort options for the opensearch request if (!this.openSearchUri || !this.isEnabled$.getValue()) {
* @param query The query string that was provided in the search return;
* @returns The combine URL to opensearch }
// Remove existing link tags before adding new ones
this.linkHeadService.removeTag("rel='alternate'");
// Get the current search options and apply our sortConfig if provided
const searchOptions = this.searchConfigurationService.paginatedSearchOptions.value;
const modifiedOptions = { ...searchOptions };
if (hasValue(this.sortConfig)) {
modifiedOptions.sort = this.sortConfig;
}
// Create the RSS feed URL
const route = environment.rest.baseUrl + this.formulateRoute(
this.uuid,
this.openSearchUri,
modifiedOptions.sort,
modifiedOptions.query,
modifiedOptions.filters,
modifiedOptions.configuration,
modifiedOptions.pagination?.pageSize,
modifiedOptions.fixedFilter,
);
// Add the link tags
this.addLinks(route);
// Add the OpenSearch service link
this.linkHeadService.addTag({
href: environment.rest.baseUrl + '/' + this.openSearchUri + '/service',
type: 'application/atom+xml',
rel: 'search',
title: 'Dspace',
});
// Update the route subject
this.route$.next(route);
}
/**
* Create a route given the different params available to opensearch
*/ */
formulateRoute(uuid: string, opensearch: string, sort?: SortOptions, query?: string, searchFilters?: SearchFilter[], configuration?: string, pageSize?: number, fixedFilter?: 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';
@@ -158,9 +210,9 @@ export class RSSComponent implements OnInit, OnDestroy {
route += `&rpp=${pageSize}`; route += `&rpp=${pageSize}`;
} }
if (searchFilters) { if (searchFilters) {
for (const filter of searchFilters) { for (const searchFilter of searchFilters) {
for (const val of filter.values) { for (const val of searchFilter.values) {
route += '&' + filter.key + '=' + encodeURIComponent(val) + (filter.operator ? ',' + filter.operator : ''); route += '&' + searchFilter.key + '=' + encodeURIComponent(val) + (searchFilter.operator ? ',' + searchFilter.operator : '');
} }
} }
} }
@@ -171,20 +223,8 @@ export class RSSComponent implements OnInit, OnDestroy {
return route; return route;
} }
/**
* Check if the router url contains the specified route
*
* @param {string} route
* @returns
* @memberof MyComponent
*/
hasRoute(route: string) {
return this.router.url.includes(route);
}
/** /**
* Creates <link> tags in the header of the page * Creates <link> tags in the header of the page
* @param route The composed url to opensearch
*/ */
addLinks(route: string): void { addLinks(route: string): void {
this.linkHeadService.addTag({ this.linkHeadService.addTag({
@@ -201,5 +241,4 @@ export class RSSComponent implements OnInit, OnDestroy {
title: 'Sitewide RSS feed', title: 'Sitewide RSS feed',
}); });
} }
} }

View File

@@ -25,6 +25,7 @@
[sortConfig]="searchConfig.sort" [sortConfig]="searchConfig.sort"
[objects]="searchResults" [objects]="searchResults"
[hideGear]="true" [hideGear]="true"
[showRSS]="true"
[selectable]="selectable" [selectable]="selectable"
[selectionConfig]="selectionConfig" [selectionConfig]="selectionConfig"
[linkType]="linkType" [linkType]="linkType"