diff --git a/resources/i18n/en.json5 b/resources/i18n/en.json5 index bc4feda0c2..b66bd24212 100644 --- a/resources/i18n/en.json5 +++ b/resources/i18n/en.json5 @@ -792,6 +792,8 @@ "item.bitstreams.upload.bundles.empty": "This item doesn\'t contain any bundles to upload a bitstream to.", + "item.bitstreams.upload.cancel": "Cancel", + "item.bitstreams.upload.drop-message": "Drop a file to upload", "item.bitstreams.upload.item": "Item: ", diff --git a/src/app/+bitstream-page/edit-bitstream-page/edit-bitstream-page.component.spec.ts b/src/app/+bitstream-page/edit-bitstream-page/edit-bitstream-page.component.spec.ts index 3edff7c225..c802622dc4 100644 --- a/src/app/+bitstream-page/edit-bitstream-page/edit-bitstream-page.component.spec.ts +++ b/src/app/+bitstream-page/edit-bitstream-page/edit-bitstream-page.component.spec.ts @@ -124,7 +124,7 @@ describe('EditBitstreamPageComponent', () => { providers: [ { provide: NotificationsService, useValue: notificationsService }, { provide: DynamicFormService, useValue: formService }, - { provide: ActivatedRoute, useValue: { data: observableOf({ bitstream: new RemoteData(false, false, true, null, bitstream) }) } }, + { provide: ActivatedRoute, useValue: { data: observableOf({ bitstream: new RemoteData(false, false, true, null, bitstream) }), snapshot: { queryParams: {} } } }, { provide: BitstreamDataService, useValue: bitstreamService }, { provide: BitstreamFormatDataService, useValue: bitstreamFormatService }, ChangeDetectorRef diff --git a/src/app/+bitstream-page/edit-bitstream-page/edit-bitstream-page.component.ts b/src/app/+bitstream-page/edit-bitstream-page/edit-bitstream-page.component.ts index 46567eb93b..cce6932cd1 100644 --- a/src/app/+bitstream-page/edit-bitstream-page/edit-bitstream-page.component.ts +++ b/src/app/+bitstream-page/edit-bitstream-page/edit-bitstream-page.component.ts @@ -1,6 +1,6 @@ import { ChangeDetectionStrategy, Component, OnDestroy, OnInit } from '@angular/core'; import { Bitstream } from '../../core/shared/bitstream.model'; -import { ActivatedRoute } from '@angular/router'; +import { ActivatedRoute, Router } from '@angular/router'; import { filter, map, switchMap } from 'rxjs/operators'; import { combineLatest as observableCombineLatest, of as observableOf } from 'rxjs'; import { Subscription } from 'rxjs/internal/Subscription'; @@ -36,8 +36,7 @@ import { Observable } from 'rxjs/internal/Observable'; import { RemoteData } from '../../core/data/remote-data'; import { PaginatedList } from '../../core/data/paginated-list'; import { followLink } from '../../shared/utils/follow-link-config.model'; -import { ObjectCacheService } from '../../core/cache/object-cache.service'; -import { RequestService } from '../../core/data/request.service'; +import { getItemEditPath } from '../../+item-page/item-page-routing.module'; @Component({ selector: 'ds-edit-bitstream-page', @@ -263,6 +262,12 @@ export class EditBitstreamPageComponent implements OnInit, OnDestroy { */ formGroup: FormGroup; + /** + * The ID of the item the bitstream originates from + * Taken from the current query parameters when present + */ + itemId: string; + /** * Array to track all subscriptions and unsubscribe them onDestroy * @type {Array} @@ -270,6 +275,7 @@ export class EditBitstreamPageComponent implements OnInit, OnDestroy { protected subs: Subscription[] = []; constructor(private route: ActivatedRoute, + private router: Router, private location: Location, private formService: DynamicFormService, private translate: TranslateService, @@ -287,6 +293,7 @@ export class EditBitstreamPageComponent implements OnInit, OnDestroy { ngOnInit(): void { this.formGroup = this.formService.createFormGroup(this.formModel); + this.itemId = this.route.snapshot.queryParams.itemId; this.bitstreamRD$ = this.route.data.pipe(map((data) => data.bitstream)); this.bitstreamFormatsRD$ = this.bitstreamFormatService.findAll(this.findAllOptions); @@ -464,6 +471,7 @@ export class EditBitstreamPageComponent implements OnInit, OnDestroy { this.translate.instant(this.NOTIFICATIONS_PREFIX + 'saved.title'), this.translate.instant(this.NOTIFICATIONS_PREFIX + 'saved.content') ); + this.navigateToItemEditBitstreams(); }); } @@ -489,7 +497,19 @@ export class EditBitstreamPageComponent implements OnInit, OnDestroy { * Cancel the form and return to the previous page */ onCancel() { - this.location.back(); + this.navigateToItemEditBitstreams(); + } + + /** + * When the item ID is present, navigate back to the item's edit bitstreams page, otherwise go back to the previous + * page the user came from + */ + navigateToItemEditBitstreams() { + if (hasValue(this.itemId)) { + this.router.navigate([getItemEditPath(this.itemId), 'bitstreams']); + } else { + this.location.back(); + } } /** diff --git a/src/app/+item-page/bitstreams/upload/upload-bitstream.component.html b/src/app/+item-page/bitstreams/upload/upload-bitstream.component.html index 58561123e7..289ede209a 100644 --- a/src/app/+item-page/bitstreams/upload/upload-bitstream.component.html +++ b/src/app/+item-page/bitstreams/upload/upload-bitstream.component.html @@ -34,6 +34,7 @@ [uploadFilesOptions]="uploadFilesOptions" (onCompleteItem)="onCompleteItem($event)" (onUploadError)="onUploadError()"> + diff --git a/src/app/+item-page/bitstreams/upload/upload-bitstream.component.spec.ts b/src/app/+item-page/bitstreams/upload/upload-bitstream.component.spec.ts index 76954158a8..061d7014a8 100644 --- a/src/app/+item-page/bitstreams/upload/upload-bitstream.component.spec.ts +++ b/src/app/+item-page/bitstreams/upload/upload-bitstream.component.spec.ts @@ -23,6 +23,7 @@ import { VarDirective } from '../../../shared/utils/var.directive'; import { Bitstream } from '../../../core/shared/bitstream.model'; import { BundleDataService } from '../../../core/data/bundle-data.service'; import { Bundle } from '../../../core/shared/bundle.model'; +import { RequestService } from '../../../core/data/request.service'; describe('UploadBistreamComponent', () => { let comp: UploadBitstreamComponent; @@ -90,6 +91,9 @@ describe('UploadBistreamComponent', () => { }); const notificationsServiceStub = new NotificationsServiceStub(); const uploaderComponent = jasmine.createSpyObj('uploaderComponent', ['ngOnInit']); + const requestService = jasmine.createSpyObj('requestService', { + removeByHrefSubstring: {} + }); describe('when a file is uploaded', () => { beforeEach(async(() => { @@ -211,7 +215,8 @@ describe('UploadBistreamComponent', () => { { provide: ItemDataService, useValue: mockItemDataService }, { provide: NotificationsService, useValue: notificationsServiceStub }, { provide: AuthService, useValue: authServiceStub }, - { provide: BundleDataService, useValue: bundleService } + { provide: BundleDataService, useValue: bundleService }, + { provide: RequestService, useValue: requestService } ], schemas: [ NO_ERRORS_SCHEMA ] diff --git a/src/app/+item-page/bitstreams/upload/upload-bitstream.component.ts b/src/app/+item-page/bitstreams/upload/upload-bitstream.component.ts index 35982a5233..75e70f5610 100644 --- a/src/app/+item-page/bitstreams/upload/upload-bitstream.component.ts +++ b/src/app/+item-page/bitstreams/upload/upload-bitstream.component.ts @@ -19,6 +19,8 @@ import { getFirstSucceededRemoteDataPayload } from '../../../core/shared/operators'; import { UploaderComponent } from '../../../shared/uploader/uploader.component'; +import { getItemEditPath } from '../../item-page-routing.module'; +import { RequestService } from '../../../core/data/request.service'; @Component({ selector: 'ds-upload-bitstream', @@ -87,7 +89,8 @@ export class UploadBitstreamComponent implements OnInit, OnDestroy { protected bundleService: BundleDataService, protected authService: AuthService, protected notificationsService: NotificationsService, - protected translate: TranslateService) { + protected translate: TranslateService, + protected requestService: RequestService) { } /** @@ -157,7 +160,14 @@ export class UploadBitstreamComponent implements OnInit, OnDestroy { * @param bitstream */ public onCompleteItem(bitstream) { - this.router.navigate([getBitstreamModulePath(), bitstream.id, 'edit']); + // Clear cached requests for this bundle's bitstreams to ensure lists on all pages are up-to-date + this.bundleService.getBitstreamsEndpoint(this.selectedBundleId).pipe(take(1)).subscribe((href: string) => { + this.requestService.removeByHrefSubstring(href); + }); + + // Bring over the item ID as a query parameter + const queryParams = { itemId: this.itemId }; + this.router.navigate([getBitstreamModulePath(), bitstream.id, 'edit'], { queryParams: queryParams }); } /** @@ -178,6 +188,13 @@ export class UploadBitstreamComponent implements OnInit, OnDestroy { this.setUploadUrl(); } + /** + * When cancel is clicked, navigate back to the item's edit bitstreams page + */ + onCancel() { + this.router.navigate([getItemEditPath(this.itemId), 'bitstreams']); + } + /** * @returns {string} the current URL */