Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes "Insufficient collection information when submitting an article" #2070

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<ds-truncatable-part [maxLines]="1" [background]="isCurrent() ? 'primary' : 'default'" [showToggle]="false">
<ds-truncatable-part [maxLines]="1" [background]="isCurrent() ? 'primary' : 'default'" [showToggle]="false" [ngbTooltip]="fullHierarchy$ | async">
<div [ngClass]="isCurrent() ? 'text-light' : 'text-body'"
[innerHTML]="(parentTitle$ && parentTitle$ | async) ? (parentTitle$ | async) : ('home.breadcrumbs' | translate)"></div>
[innerHTML]="(fullHierarchy$ && fullHierarchy$ | async) ? (fullHierarchy$ | async) : ('home.breadcrumbs' | translate)"></div>
</ds-truncatable-part>
<ds-truncatable-part [maxLines]="1" [background]="isCurrent() ? 'primary' : 'default'" [showToggle]="false">
<div class="font-weight-bold"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ export function createSidebarSearchListElementTests(
let linkService;

beforeEach(waitForAsync(() => {
jasmine.DEFAULT_TIMEOUT_INTERVAL = 20000;
linkService = jasmine.createSpyObj('linkService', {
resolveLink: Object.assign(new HALResource(), {
[object.indexableObject.getParentLinkKey()]: createSuccessfulRemoteDataObject$(parent)
Expand All @@ -54,10 +55,9 @@ export function createSidebarSearchListElementTests(
fixture.detectChanges();
});

it('should contain the correct parent title', (done) => {
component.parentTitle$.subscribe((title) => {
it('should contain the correct parent title', () => {
component.fullHierarchy$.subscribe((title) => {
expect(title).toEqual(expectedParentTitle);
done();
});
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { followLink } from '../../utils/follow-link-config.model';
import { RemoteData } from '../../../core/data/remote-data';
import { Context } from '../../../core/shared/context.model';
import { DSONameService } from '../../../core/breadcrumbs/dso-name.service';
import { from } from 'rxjs';

@Component({
selector: 'ds-sidebar-search-list-element',
Expand All @@ -23,19 +24,20 @@ import { DSONameService } from '../../../core/breadcrumbs/dso-name.service';
* component by overriding the relevant methods of this component
*/
export class SidebarSearchListElementComponent<T extends SearchResult<K>, K extends DSpaceObject> extends SearchResultListElementComponent<T, K> {

/**
* Observable for the title of the parent object (displayed above the object's title)
* Observable for the hierarchy of the parent object
*/
parentTitle$: Observable<string>;
fullHierarchy$: Observable<string>;

/**
* A description to display below the title
*/
description: string;

public constructor(protected truncatableService: TruncatableService,
protected linkService: LinkService,
protected dsoNameService: DSONameService
protected linkService: LinkService,
protected dsoNameService: DSONameService
) {
super(truncatableService, dsoNameService, null);
}
Expand All @@ -46,8 +48,12 @@ export class SidebarSearchListElementComponent<T extends SearchResult<K>, K exte
ngOnInit(): void {
super.ngOnInit();
if (hasValue(this.dso)) {
this.parentTitle$ = this.getParentTitle();

const parent = this.getParent(this.dso);

this.description = this.getDescription();

this.fullHierarchy$ = from(this.getFullHierarchyTitles(parent));
}
}

Expand All @@ -59,28 +65,74 @@ export class SidebarSearchListElementComponent<T extends SearchResult<K>, K exte
}

/**
* Get the title of the object's parent
* gets the full hiearchy titles for the given `dso`.
* for example: "faculty of english > faculty of maths > journals"
*/
async getFullHierarchyTitles(dsoObservable: any): Promise<string> {

let title = await this.getTitle(dsoObservable).toPromise();

if (!title) {
return '';
}

const dso = await dsoObservable.toPromise();

if (!dso || !dso.payload) {
return title;
}

const parentObserver = this.getParent(dso.payload);
const parent = await parentObserver.toPromise();

if (parent && parent.payload != null && parentObserver) {
await new Promise((resolve) => setTimeout(resolve, 1));
return (await this.getFullHierarchyTitles(parentObserver)) + ' • ' + title;
}

return title;
}

/**
* Get the title of the given observable object
* Retrieve the parent by using the object's parent link and retrieving its 'dc.title' metadata
*/
getParentTitle(): Observable<string> {
return this.getParent().pipe(
map((parentRD: RemoteData<DSpaceObject>) => {
return hasValue(parentRD) && hasValue(parentRD.payload) ? this.dsoNameService.getName(parentRD.payload) : undefined;
getTitle(dso: any): Observable<string> {
return dso.pipe(
map((dspaceObject: RemoteData<DSpaceObject>) => {

if (!hasValue(dspaceObject) || !hasValue(dspaceObject.payload)) {
return undefined;
}

return this.dsoNameService.getName(dspaceObject.payload);
})
);
}

/**
* Get the parent of the object
*/
getParent(): Observable<RemoteData<DSpaceObject>> {
if (typeof (this.dso as any).getParentLinkKey === 'function') {
const propertyName = (this.dso as any).getParentLinkKey();
return this.linkService.resolveLink(this.dso, followLink(propertyName))[propertyName].pipe(
find((parentRD: RemoteData<ChildHALResource & DSpaceObject>) => parentRD.hasSucceeded || parentRD.statusCode === 204)
);
getParent(dso: any): Observable<RemoteData<DSpaceObject>> {
if (typeof (dso).getParentLinkKey !== 'function') {
return observableOf(undefined);
}

const propertyName = (dso).getParentLinkKey();

if (!propertyName) {
return observableOf(undefined);
}
return observableOf(undefined);

const pipe = this.linkService.resolveLink(dso, followLink(propertyName))[propertyName];

if (!pipe) {
return observableOf(undefined);
}

return pipe.pipe(
find((parentRD: RemoteData<ChildHALResource & DSpaceObject>) => parentRD.hasSucceeded || parentRD.statusCode === 204)
);
}

/**
Expand Down