Skip to content

Commit

Permalink
Merge pull request #2636 from DSpace/backport-2562-to-dspace-7_x
Browse files Browse the repository at this point in the history
[Port dspace-7_x] Fix match theme by handle with canonical prefix https://hdl.handle.net/ not working
  • Loading branch information
tdonohue authored Nov 13, 2023
2 parents 626cc30 + 0cd72e4 commit 0a3502e
Show file tree
Hide file tree
Showing 22 changed files with 495 additions and 302 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Component, Input, OnDestroy, OnInit } from '@angular/core';
import { ActivatedRoute } from '@angular/router';

import { BehaviorSubject, combineLatest as observableCombineLatest } from 'rxjs';
import { BehaviorSubject, combineLatest as observableCombineLatest, Subscription } from 'rxjs';

import { RemoteData } from '../../core/data/remote-data';
import { Collection } from '../../core/shared/collection.model';
Expand Down Expand Up @@ -50,6 +50,8 @@ export class CommunityPageSubCollectionListComponent implements OnInit, OnDestro
*/
subCollectionsRDObs: BehaviorSubject<RemoteData<PaginatedList<Collection>>> = new BehaviorSubject<RemoteData<PaginatedList<Collection>>>({} as any);

subscriptions: Subscription[] = [];

constructor(
protected cds: CollectionDataService,
protected paginationService: PaginationService,
Expand Down Expand Up @@ -77,7 +79,7 @@ export class CommunityPageSubCollectionListComponent implements OnInit, OnDestro
const pagination$ = this.paginationService.getCurrentPagination(this.config.id, this.config);
const sort$ = this.paginationService.getCurrentSort(this.config.id, this.sortConfig);

observableCombineLatest([pagination$, sort$]).pipe(
this.subscriptions.push(observableCombineLatest([pagination$, sort$]).pipe(
switchMap(([currentPagination, currentSort]) => {
return this.cds.findByParent(this.community.id, {
currentPage: currentPagination.currentPage,
Expand All @@ -87,11 +89,12 @@ export class CommunityPageSubCollectionListComponent implements OnInit, OnDestro
})
).subscribe((results) => {
this.subCollectionsRDObs.next(results);
});
}));
}

ngOnDestroy(): void {
this.paginationService.clearPagination(this.config.id);
this.paginationService.clearPagination(this.config?.id);
this.subscriptions.map((subscription: Subscription) => subscription.unsubscribe());
}

}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Component, Input, OnDestroy, OnInit } from '@angular/core';
import { ActivatedRoute } from '@angular/router';

import { BehaviorSubject, combineLatest as observableCombineLatest } from 'rxjs';
import { BehaviorSubject, combineLatest as observableCombineLatest, Subscription } from 'rxjs';

import { RemoteData } from '../../core/data/remote-data';
import { Community } from '../../core/shared/community.model';
Expand Down Expand Up @@ -52,6 +52,8 @@ export class CommunityPageSubCommunityListComponent implements OnInit, OnDestroy
*/
subCommunitiesRDObs: BehaviorSubject<RemoteData<PaginatedList<Community>>> = new BehaviorSubject<RemoteData<PaginatedList<Community>>>({} as any);

subscriptions: Subscription[] = [];

constructor(
protected cds: CommunityDataService,
protected paginationService: PaginationService,
Expand Down Expand Up @@ -79,7 +81,7 @@ export class CommunityPageSubCommunityListComponent implements OnInit, OnDestroy
const pagination$ = this.paginationService.getCurrentPagination(this.config.id, this.config);
const sort$ = this.paginationService.getCurrentSort(this.config.id, this.sortConfig);

observableCombineLatest([pagination$, sort$]).pipe(
this.subscriptions.push(observableCombineLatest([pagination$, sort$]).pipe(
switchMap(([currentPagination, currentSort]) => {
return this.cds.findByParent(this.community.id, {
currentPage: currentPagination.currentPage,
Expand All @@ -89,11 +91,12 @@ export class CommunityPageSubCommunityListComponent implements OnInit, OnDestroy
})
).subscribe((results) => {
this.subCommunitiesRDObs.next(results);
});
}));
}

ngOnDestroy(): void {
this.paginationService.clearPagination(this.config.id);
this.paginationService.clearPagination(this.config?.id);
this.subscriptions.map((subscription: Subscription) => subscription.unsubscribe());
}

}
1 change: 0 additions & 1 deletion src/app/core/data/configuration-data.service.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/* eslint-disable max-classes-per-file */
import { Injectable } from '@angular/core';
import { Observable } from 'rxjs';
import { RemoteDataBuildService } from '../cache/builders/remote-data-build.service';
Expand Down
12 changes: 7 additions & 5 deletions src/app/curation-form/curation-form.component.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ComponentFixture, TestBed, waitForAsync } from '@angular/core/testing';
import { ComponentFixture, TestBed, waitForAsync, fakeAsync, flush } from '@angular/core/testing';
import { TranslateModule } from '@ngx-translate/core';
import { CUSTOM_ELEMENTS_SCHEMA } from '@angular/core';
import { CurationFormComponent } from './curation-form.component';
Expand All @@ -16,6 +16,7 @@ import { ConfigurationDataService } from '../core/data/configuration-data.servic
import { ConfigurationProperty } from '../core/shared/configuration-property.model';
import { getProcessDetailRoute } from '../process-page/process-page-routing.paths';
import { HandleService } from '../shared/handle.service';
import { of as observableOf } from 'rxjs';

describe('CurationFormComponent', () => {
let comp: CurationFormComponent;
Expand Down Expand Up @@ -54,7 +55,7 @@ describe('CurationFormComponent', () => {
});

handleService = {
normalizeHandle: (a) => a
normalizeHandle: (a: string) => observableOf(a),
} as any;

notificationsService = new NotificationsServiceStub();
Expand Down Expand Up @@ -151,12 +152,13 @@ describe('CurationFormComponent', () => {
], []);
});

it(`should show an error notification and return when an invalid dsoHandle is provided`, () => {
it(`should show an error notification and return when an invalid dsoHandle is provided`, fakeAsync(() => {
comp.dsoHandle = 'test-handle';
spyOn(handleService, 'normalizeHandle').and.returnValue(null);
spyOn(handleService, 'normalizeHandle').and.returnValue(observableOf(null));
comp.submit();
flush();

expect(notificationsService.error).toHaveBeenCalled();
expect(scriptDataService.invoke).not.toHaveBeenCalled();
});
}));
});
82 changes: 47 additions & 35 deletions src/app/curation-form/curation-form.component.ts
Original file line number Diff line number Diff line change
@@ -1,30 +1,30 @@
import { ChangeDetectorRef, Component, Input, OnInit } from '@angular/core';
import { ChangeDetectorRef, Component, Input, OnDestroy, OnInit } from '@angular/core';
import { ScriptDataService } from '../core/data/processes/script-data.service';
import { UntypedFormControl, UntypedFormGroup } from '@angular/forms';
import { getFirstCompletedRemoteData } from '../core/shared/operators';
import { find, map } from 'rxjs/operators';
import { getFirstCompletedRemoteData, getFirstSucceededRemoteDataPayload } from '../core/shared/operators';
import { map } from 'rxjs/operators';
import { NotificationsService } from '../shared/notifications/notifications.service';
import { TranslateService } from '@ngx-translate/core';
import { hasValue, isEmpty, isNotEmpty } from '../shared/empty.util';
import { RemoteData } from '../core/data/remote-data';
import { Router } from '@angular/router';
import { ProcessDataService } from '../core/data/processes/process-data.service';
import { Process } from '../process-page/processes/process.model';
import { ConfigurationDataService } from '../core/data/configuration-data.service';
import { ConfigurationProperty } from '../core/shared/configuration-property.model';
import { Observable } from 'rxjs';
import { Observable, Subscription } from 'rxjs';
import { getProcessDetailRoute } from '../process-page/process-page-routing.paths';
import { HandleService } from '../shared/handle.service';

export const CURATION_CFG = 'plugin.named.org.dspace.curate.CurationTask';

/**
* Component responsible for rendering the Curation Task form
*/
@Component({
selector: 'ds-curation-form',
templateUrl: './curation-form.component.html'
})
export class CurationFormComponent implements OnInit {
export class CurationFormComponent implements OnDestroy, OnInit {

config: Observable<RemoteData<ConfigurationProperty>>;
tasks: string[];
Expand All @@ -33,10 +33,11 @@ export class CurationFormComponent implements OnInit {
@Input()
dsoHandle: string;

subs: Subscription[] = [];

constructor(
private scriptDataService: ScriptDataService,
private configurationDataService: ConfigurationDataService,
private processDataService: ProcessDataService,
private notificationsService: NotificationsService,
private translateService: TranslateService,
private handleService: HandleService,
Expand All @@ -45,23 +46,26 @@ export class CurationFormComponent implements OnInit {
) {
}

ngOnDestroy(): void {
this.subs.forEach((sub: Subscription) => sub.unsubscribe());
}

ngOnInit(): void {
this.form = new UntypedFormGroup({
task: new UntypedFormControl(''),
handle: new UntypedFormControl('')
});

this.config = this.configurationDataService.findByPropertyName(CURATION_CFG);
this.config.pipe(
find((rd: RemoteData<ConfigurationProperty>) => rd.hasSucceeded),
map((rd: RemoteData<ConfigurationProperty>) => rd.payload)
).subscribe((configProperties) => {
this.subs.push(this.config.pipe(
getFirstSucceededRemoteDataPayload(),
).subscribe((configProperties: ConfigurationProperty) => {
this.tasks = configProperties.values
.filter((value) => isNotEmpty(value) && value.includes('='))
.map((value) => value.split('=')[1].trim());
this.form.get('task').patchValue(this.tasks[0]);
this.cdr.detectChanges();
});
}));
}

/**
Expand All @@ -77,33 +81,41 @@ export class CurationFormComponent implements OnInit {
*/
submit() {
const taskName = this.form.get('task').value;
let handle;
let handle$: Observable<string | null>;
if (this.hasHandleValue()) {
handle = this.handleService.normalizeHandle(this.dsoHandle);
if (isEmpty(handle)) {
this.notificationsService.error(this.translateService.get('curation.form.submit.error.head'),
this.translateService.get('curation.form.submit.error.invalid-handle'));
return;
}
handle$ = this.handleService.normalizeHandle(this.dsoHandle).pipe(
map((handle: string | null) => {
if (isEmpty(handle)) {
this.notificationsService.error(this.translateService.get('curation.form.submit.error.head'),
this.translateService.get('curation.form.submit.error.invalid-handle'));
}
return handle;
}),
);
} else {
handle = this.handleService.normalizeHandle(this.form.get('handle').value);
if (isEmpty(handle)) {
handle = 'all';
}
handle$ = this.handleService.normalizeHandle(this.form.get('handle').value).pipe(
map((handle: string | null) => isEmpty(handle) ? 'all' : handle),
);
}

this.scriptDataService.invoke('curate', [
{ name: '-t', value: taskName },
{ name: '-i', value: handle },
], []).pipe(getFirstCompletedRemoteData()).subscribe((rd: RemoteData<Process>) => {
if (rd.hasSucceeded) {
this.notificationsService.success(this.translateService.get('curation.form.submit.success.head'),
this.translateService.get('curation.form.submit.success.content'));
this.router.navigateByUrl(getProcessDetailRoute(rd.payload.processId));
} else {
this.notificationsService.error(this.translateService.get('curation.form.submit.error.head'),
this.translateService.get('curation.form.submit.error.content'));
this.subs.push(handle$.subscribe((handle: string) => {
if (hasValue(handle)) {
this.subs.push(this.scriptDataService.invoke('curate', [
{ name: '-t', value: taskName },
{ name: '-i', value: handle },
], []).pipe(
getFirstCompletedRemoteData(),
).subscribe((rd: RemoteData<Process>) => {
if (rd.hasSucceeded) {
this.notificationsService.success(this.translateService.get('curation.form.submit.success.head'),
this.translateService.get('curation.form.submit.success.content'));
void this.router.navigateByUrl(getProcessDetailRoute(rd.payload.processId));
} else {
this.notificationsService.error(this.translateService.get('curation.form.submit.error.head'),
this.translateService.get('curation.form.submit.error.content'));
}
}));
}
});
}));
}
}
2 changes: 1 addition & 1 deletion src/app/root/root.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { AuthService } from '../core/auth/auth.service';
import { CSSVariableService } from '../shared/sass-helper/css-variable.service';
import { MenuService } from '../shared/menu/menu.service';
import { HostWindowService } from '../shared/host-window.service';
import { ThemeConfig } from '../../config/theme.model';
import { ThemeConfig } from '../../config/theme.config';
import { Angulartics2DSpace } from '../statistics/angulartics/dspace-provider';
import { environment } from '../../environments/environment';
import { slideSidebarPadding } from '../shared/animations/slide';
Expand Down
Loading

0 comments on commit 0a3502e

Please sign in to comment.