Add typedocs and websvc.opensearch.svccontext

This commit is contained in:
Nathan Buckingham
2022-04-27 16:13:01 -04:00
parent 0bf0e1f274
commit be8a8f5f6b
6 changed files with 41 additions and 55 deletions

View File

@@ -29,8 +29,6 @@ export class LinkHeadService {
}); });
const link = renderer.createElement('link'); const link = renderer.createElement('link');
console.log(tag);
console.log(link);
const head = this.document.head; const head = this.document.head;
if (head === null) { if (head === null) {

View File

@@ -96,17 +96,17 @@ 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, options, query); const route = comp.formulateRoute(uuid, 'opensearch', options, query);
expect(route).toBe('/opensearch/search?format=atom&scope=2cfcf65e-0a51-4bcb-8592-b8db7b064790&sort=dc.title&sort_direction=DESC&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, options, query); const route = comp.formulateRoute(null, 'opensearch', options, query);
expect(route).toBe('/opensearch/search?format=atom&sort=dc.title&sort_direction=DESC&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, options, null); const route = comp.formulateRoute(null, 'opensearch', options, null);
expect(route).toBe('/opensearch/search?format=atom&sort=dc.title&sort_direction=DESC&query=*'); expect(route).toBe('/opensearch/search?format=atom&sort=dc.title&sort_direction=DESC&query=*');
}); });
}); });

View File

@@ -45,10 +45,17 @@ export class RSSComponent implements OnInit, OnDestroy {
private router: Router, private router: Router,
protected paginationService: PaginationService) { protected paginationService: PaginationService) {
} }
/**
* 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'");
} }
/**
* Generates the link tags and the url to opensearch when the component is loaded.
*/
ngOnInit(): void { ngOnInit(): void {
this.configuration$ = this.searchConfigurationService.getCurrentConfiguration('default'); this.configuration$ = this.searchConfigurationService.getCurrentConfiguration('default');
@@ -58,26 +65,36 @@ export class RSSComponent implements OnInit, OnDestroy {
const enabled = (result.payload.values[0] === 'true'); const enabled = (result.payload.values[0] === 'true');
this.isEnabled$.next(enabled); this.isEnabled$.next(enabled);
}); });
this.configurationService.findByPropertyName('websvc.opensearch.svccontext').pipe(
this.searchConfigurationService.getCurrentQuery('').subscribe((query) => { getFirstCompletedRemoteData(),
this.sortOption$ = this.paginationService.getCurrentSort(this.searchConfigurationService.paginationID, null, true); ).subscribe((url) => {
this.sortOption$.subscribe((sort) => { this.searchConfigurationService.getCurrentQuery('').subscribe((query) => {
this.uuid = this.groupDataService.getUUIDFromString(this.router.url); this.sortOption$ = this.paginationService.getCurrentSort(this.searchConfigurationService.paginationID, null, true);
this.sortOption$.subscribe((sort) => {
const route = environment.rest.baseUrl + this.formulateRoute(this.uuid, sort, query); this.uuid = this.groupDataService.getUUIDFromString(this.router.url);
this.addLinks(route); const route = environment.rest.baseUrl + this.formulateRoute(this.uuid, url.payload.values[0], sort, query);
this.linkHeadService.addTag({ this.addLinks(route);
href: environment.rest.baseUrl + '/opensearch/service', this.linkHeadService.addTag({
type: 'application/atom+xml', href: environment.rest.baseUrl + '/' + url.payload.values[0] + '/service',
rel: 'search', type: 'application/atom+xml',
title: 'Dspace' rel: 'search',
title: 'Dspace'
});
this.route$ = new BehaviorSubject<string>(route);
}); });
this.route$ = new BehaviorSubject<string>(route);
}); });
}); });
} }
formulateRoute(uuid: string, sort: SortOptions, query: string): string { /**
* Function created a route given the different params available to opensearch
* @param uuid The uuid if a scope is present
* @param opensearch openSearch uri
* @param sort The sort options for the opensearch request
* @param query The query string that was provided in the search
* @returns The combine URL to opensearch
*/
formulateRoute(uuid: string, opensearch: string, sort: SortOptions, query: string): string {
let route = 'search?format=atom'; let route = 'search?format=atom';
if (uuid) { if (uuid) {
route += `&scope=${uuid}`; route += `&scope=${uuid}`;
@@ -90,10 +107,14 @@ export class RSSComponent implements OnInit, OnDestroy {
} else { } else {
route += `&query=*`; route += `&query=*`;
} }
route = '/opensearch/' + route; route = '/' + opensearch +'/' + route;
return route; return route;
} }
/**
* 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({
href: route, href: route,

View File

@@ -174,6 +174,7 @@ import { DsSelectComponent } from './ds-select/ds-select.component';
import { LogInOidcComponent } from './log-in/methods/oidc/log-in-oidc.component'; import { LogInOidcComponent } from './log-in/methods/oidc/log-in-oidc.component';
import { ThemedItemListPreviewComponent } from './object-list/my-dspace-result-list-element/item-list-preview/themed-item-list-preview.component'; import { ThemedItemListPreviewComponent } from './object-list/my-dspace-result-list-element/item-list-preview/themed-item-list-preview.component';
import { RSSComponent } from './rss-feed/rss.component'; import { RSSComponent } from './rss-feed/rss.component';
import { ExternalLinkMenuItemComponent } from './menu/menu-item/external-link-menu-item.component';
const MODULES = [ const MODULES = [
CommonModule, CommonModule,

View File

@@ -1,17 +0,0 @@
export const environment = {
ui: {
ssl: false,
host: 'localhost',
port: 18080,
nameSpace: '/'
},
rest: {
ssl: false,
host: 'localhost',
port: 8080,
nameSpace: '/server'
},
universal: {
preboot: false
}
};

View File

@@ -1,17 +0,0 @@
export const environment = {
ui: {
ssl: false,
host: 'localhost',
port: 18080,
nameSpace: '/'
},
rest: {
ssl: false,
host: 'localhost',
port: 8080,
nameSpace: '/server'
},
universal: {
preboot: true
}
};