mirror of
https://github.com/DSpace/dspace-angular.git
synced 2025-10-07 18:14:17 +00:00
71712: Item export no longer redirects & test async fixes
This commit is contained in:
@@ -15,6 +15,7 @@
|
|||||||
class="list-group-item list-group-item-action border-0 list-entry"
|
class="list-group-item list-group-item-action border-0 list-entry"
|
||||||
title="{{ listEntry.indexableObject.name }}"
|
title="{{ listEntry.indexableObject.name }}"
|
||||||
(click)="onSelect.emit(listEntry.indexableObject)" #listEntryElement>
|
(click)="onSelect.emit(listEntry.indexableObject)" #listEntryElement>
|
||||||
<ds-listable-object-component-loader [object]="listEntry" [viewMode]="viewMode"></ds-listable-object-component-loader>
|
<ds-listable-object-component-loader [object]="listEntry" [viewMode]="viewMode"
|
||||||
|
[linkType]=linkTypes.None></ds-listable-object-component-loader>
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
|
@@ -13,6 +13,7 @@ import { FormControl } from '@angular/forms';
|
|||||||
import { Observable } from 'rxjs';
|
import { Observable } from 'rxjs';
|
||||||
import { debounceTime, startWith, switchMap } from 'rxjs/operators';
|
import { debounceTime, startWith, switchMap } from 'rxjs/operators';
|
||||||
import { SearchService } from '../../../core/shared/search/search.service';
|
import { SearchService } from '../../../core/shared/search/search.service';
|
||||||
|
import { CollectionElementLinkType } from '../../object-collection/collection-element-link.type';
|
||||||
import { PaginatedSearchOptions } from '../../search/paginated-search-options.model';
|
import { PaginatedSearchOptions } from '../../search/paginated-search-options.model';
|
||||||
import { DSpaceObjectType } from '../../../core/shared/dspace-object-type.model';
|
import { DSpaceObjectType } from '../../../core/shared/dspace-object-type.model';
|
||||||
import { RemoteData } from '../../../core/data/remote-data';
|
import { RemoteData } from '../../../core/data/remote-data';
|
||||||
@@ -76,6 +77,11 @@ export class DSOSelectorComponent implements OnInit {
|
|||||||
*/
|
*/
|
||||||
debounceTime = 500;
|
debounceTime = 500;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The available link types
|
||||||
|
*/
|
||||||
|
linkTypes = CollectionElementLinkType;
|
||||||
|
|
||||||
constructor(private searchService: SearchService) {
|
constructor(private searchService: SearchService) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -30,7 +30,7 @@ describe('ExportMetadataSelectorComponent', () => {
|
|||||||
lastModified: '2018'
|
lastModified: '2018'
|
||||||
});
|
});
|
||||||
|
|
||||||
const mockCollection1: Collection = Object.assign(new Collection(), {
|
const mockCollection: Collection = Object.assign(new Collection(), {
|
||||||
id: 'test-collection-1-1',
|
id: 'test-collection-1-1',
|
||||||
name: 'test-collection-1',
|
name: 'test-collection-1',
|
||||||
handle: 'fake/test-collection-1',
|
handle: 'fake/test-collection-1',
|
||||||
@@ -100,26 +100,36 @@ describe('ExportMetadataSelectorComponent', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
describe('if item is selected', () => {
|
describe('if item is selected', () => {
|
||||||
beforeEach(() => {
|
let scriptRequestSucceeded;
|
||||||
component.navigate(mockItem);
|
beforeEach((done) => {
|
||||||
|
component.navigate(mockItem).subscribe((succeeded: boolean) => {
|
||||||
|
scriptRequestSucceeded = succeeded;
|
||||||
|
done()
|
||||||
|
});
|
||||||
});
|
});
|
||||||
it('should show error notification', () => {
|
it('should show error notification', () => {
|
||||||
expect(notificationService.error).toHaveBeenCalled();
|
expect(notificationService.error).toHaveBeenCalled();
|
||||||
|
expect(scriptRequestSucceeded).toBeFalse();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('if collection is selected', () => {
|
describe('if collection is selected', () => {
|
||||||
beforeEach(() => {
|
let scriptRequestSucceeded;
|
||||||
component.navigate(mockCollection1);
|
beforeEach((done) => {
|
||||||
|
component.navigate(mockCollection).subscribe((succeeded: boolean) => {
|
||||||
|
scriptRequestSucceeded = succeeded;
|
||||||
|
done()
|
||||||
|
});
|
||||||
});
|
});
|
||||||
it('metadata-export script is invoked with its -i handle and -f uuid.csv', () => {
|
it('metadata-export script is invoked with its -i handle and -f uuid.csv', () => {
|
||||||
const parameterValues: ProcessParameter[] = [
|
const parameterValues: ProcessParameter[] = [
|
||||||
Object.assign(new ProcessParameter(), { name: '-i', value: mockCollection1.handle }),
|
Object.assign(new ProcessParameter(), { name: '-i', value: mockCollection.handle }),
|
||||||
Object.assign(new ProcessParameter(), { name: '-f', value: mockCollection1.uuid + '.csv' }),
|
Object.assign(new ProcessParameter(), { name: '-f', value: mockCollection.uuid + '.csv' }),
|
||||||
];
|
];
|
||||||
expect(scriptService.invoke).toHaveBeenCalledWith(METADATA_EXPORT_SCRIPT_NAME, parameterValues, []);
|
expect(scriptService.invoke).toHaveBeenCalledWith(METADATA_EXPORT_SCRIPT_NAME, parameterValues, []);
|
||||||
});
|
});
|
||||||
it('success notification is shown', () => {
|
it('success notification is shown', () => {
|
||||||
|
expect(scriptRequestSucceeded).toBeTrue();
|
||||||
expect(notificationService.success).toHaveBeenCalled();
|
expect(notificationService.success).toHaveBeenCalled();
|
||||||
});
|
});
|
||||||
it('redirected to process page', () => {
|
it('redirected to process page', () => {
|
||||||
@@ -128,8 +138,12 @@ describe('ExportMetadataSelectorComponent', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
describe('if community is selected', () => {
|
describe('if community is selected', () => {
|
||||||
beforeEach(() => {
|
let scriptRequestSucceeded;
|
||||||
component.navigate(mockCommunity);
|
beforeEach((done) => {
|
||||||
|
component.navigate(mockCommunity).subscribe((succeeded: boolean) => {
|
||||||
|
scriptRequestSucceeded = succeeded;
|
||||||
|
done()
|
||||||
|
});
|
||||||
});
|
});
|
||||||
it('metadata-export script is invoked with its -i handle and -f uuid.csv', () => {
|
it('metadata-export script is invoked with its -i handle and -f uuid.csv', () => {
|
||||||
const parameterValues: ProcessParameter[] = [
|
const parameterValues: ProcessParameter[] = [
|
||||||
@@ -139,6 +153,7 @@ describe('ExportMetadataSelectorComponent', () => {
|
|||||||
expect(scriptService.invoke).toHaveBeenCalledWith(METADATA_EXPORT_SCRIPT_NAME, parameterValues, []);
|
expect(scriptService.invoke).toHaveBeenCalledWith(METADATA_EXPORT_SCRIPT_NAME, parameterValues, []);
|
||||||
});
|
});
|
||||||
it('success notification is shown', () => {
|
it('success notification is shown', () => {
|
||||||
|
expect(scriptRequestSucceeded).toBeTrue();
|
||||||
expect(notificationService.success).toHaveBeenCalled();
|
expect(notificationService.success).toHaveBeenCalled();
|
||||||
});
|
});
|
||||||
it('redirected to process page', () => {
|
it('redirected to process page', () => {
|
||||||
@@ -147,7 +162,8 @@ describe('ExportMetadataSelectorComponent', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
describe('if community/collection is selected; but script invoke fails', () => {
|
describe('if community/collection is selected; but script invoke fails', () => {
|
||||||
beforeEach(() => {
|
let scriptRequestSucceeded;
|
||||||
|
beforeEach((done) => {
|
||||||
jasmine.getEnv().allowRespy(true);
|
jasmine.getEnv().allowRespy(true);
|
||||||
spyOn(scriptService, 'invoke').and.returnValue(observableOf({
|
spyOn(scriptService, 'invoke').and.returnValue(observableOf({
|
||||||
response:
|
response:
|
||||||
@@ -155,9 +171,13 @@ describe('ExportMetadataSelectorComponent', () => {
|
|||||||
isSuccessful: false,
|
isSuccessful: false,
|
||||||
}
|
}
|
||||||
}));
|
}));
|
||||||
component.navigate(mockCommunity);
|
component.navigate(mockCommunity).subscribe((succeeded: boolean) => {
|
||||||
|
scriptRequestSucceeded = succeeded;
|
||||||
|
done()
|
||||||
|
});
|
||||||
});
|
});
|
||||||
it('error notification is shown', () => {
|
it('error notification is shown', () => {
|
||||||
|
expect(scriptRequestSucceeded).toBeFalse();
|
||||||
expect(notificationService.error).toHaveBeenCalled();
|
expect(notificationService.error).toHaveBeenCalled();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@@ -1,7 +1,9 @@
|
|||||||
import { Component, OnInit } from '@angular/core';
|
import { Component, OnInit } from '@angular/core';
|
||||||
import { ActivatedRoute, Router } from '@angular/router';
|
import { ActivatedRoute, Router } from '@angular/router';
|
||||||
import { TranslateService } from '@ngx-translate/core';
|
import { TranslateService } from '@ngx-translate/core';
|
||||||
import { take } from 'rxjs/operators';
|
import { Observable } from 'rxjs/internal/Observable';
|
||||||
|
import { take, map } from 'rxjs/operators';
|
||||||
|
import { of as observableOf } from 'rxjs';
|
||||||
import { ScriptDataService } from '../../../../core/data/processes/script-data.service';
|
import { ScriptDataService } from '../../../../core/data/processes/script-data.service';
|
||||||
import { RequestEntry } from '../../../../core/data/request.reducer';
|
import { RequestEntry } from '../../../../core/data/request.reducer';
|
||||||
import { Collection } from '../../../../core/shared/collection.model';
|
import { Collection } from '../../../../core/shared/collection.model';
|
||||||
@@ -39,11 +41,14 @@ export class ExportMetadataSelectorComponent extends DSOSelectorModalWrapperComp
|
|||||||
* If the dso is a collection or community: start export-metadata script & navigate to process if successful
|
* If the dso is a collection or community: start export-metadata script & navigate to process if successful
|
||||||
* Otherwise show error message
|
* Otherwise show error message
|
||||||
*/
|
*/
|
||||||
navigate(dso: DSpaceObject) {
|
navigate(dso: DSpaceObject): Observable<boolean> {
|
||||||
if (dso instanceof Collection || dso instanceof Community) {
|
if (dso instanceof Collection || dso instanceof Community) {
|
||||||
this.startScriptNotifyAndRedirect(dso, dso.handle);
|
const startScriptSucceeded = this.startScriptNotifyAndRedirect(dso, dso.handle);
|
||||||
|
startScriptSucceeded.pipe(take(1)).subscribe();
|
||||||
|
return startScriptSucceeded;
|
||||||
} else {
|
} else {
|
||||||
this.notificationsService.error(this.translationService.get('dso-selector.export-metadata.notValidDSO'));
|
this.notificationsService.error(this.translationService.get('dso-selector.export-metadata.notValidDSO'));
|
||||||
|
return observableOf(false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -52,28 +57,31 @@ export class ExportMetadataSelectorComponent extends DSOSelectorModalWrapperComp
|
|||||||
* Otherwise show error message
|
* Otherwise show error message
|
||||||
* @param dso Dso to export
|
* @param dso Dso to export
|
||||||
*/
|
*/
|
||||||
private startScriptNotifyAndRedirect(dso: DSpaceObject, handle: string) {
|
private startScriptNotifyAndRedirect(dso: DSpaceObject, handle: string): Observable<boolean> {
|
||||||
const parameterValues: ProcessParameter[] = [
|
const parameterValues: ProcessParameter[] = [
|
||||||
Object.assign(new ProcessParameter(), { name: '-i', value: handle }),
|
Object.assign(new ProcessParameter(), { name: '-i', value: handle }),
|
||||||
Object.assign(new ProcessParameter(), { name: '-f', value: dso.uuid + '.csv' }),
|
Object.assign(new ProcessParameter(), { name: '-f', value: dso.uuid + '.csv' }),
|
||||||
];
|
];
|
||||||
this.scriptDataService.invoke(METADATA_EXPORT_SCRIPT_NAME, parameterValues, [])
|
return this.scriptDataService.invoke(METADATA_EXPORT_SCRIPT_NAME, parameterValues, [])
|
||||||
.pipe(take(1))
|
.pipe(
|
||||||
.subscribe((requestEntry: RequestEntry) => {
|
take(1),
|
||||||
if (requestEntry.response.isSuccessful) {
|
map((requestEntry: RequestEntry) => {
|
||||||
const title = this.translationService.get('process.new.notification.success.title');
|
if (requestEntry.response.isSuccessful) {
|
||||||
const content = this.translationService.get('process.new.notification.success.content');
|
const title = this.translationService.get('process.new.notification.success.title');
|
||||||
this.notificationsService.success(title, content);
|
const content = this.translationService.get('process.new.notification.success.content');
|
||||||
const response: any = requestEntry.response;
|
this.notificationsService.success(title, content);
|
||||||
if (isNotEmpty(response.resourceSelfLinks)) {
|
const response: any = requestEntry.response;
|
||||||
const processNumber = response.resourceSelfLinks[0].split('/').pop();
|
if (isNotEmpty(response.resourceSelfLinks)) {
|
||||||
this.router.navigateByUrl('/processes/' + processNumber);
|
const processNumber = response.resourceSelfLinks[0].split('/').pop();
|
||||||
|
this.router.navigateByUrl('/processes/' + processNumber);
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
} else {
|
||||||
|
const title = this.translationService.get('process.new.notification.error.title');
|
||||||
|
const content = this.translationService.get('process.new.notification.error.content');
|
||||||
|
this.notificationsService.error(title, content);
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
} else {
|
}));
|
||||||
const title = this.translationService.get('process.new.notification.error.title');
|
|
||||||
const content = this.translationService.get('process.new.notification.error.content');
|
|
||||||
this.notificationsService.error(title, content);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user