mirror of
https://github.com/DSpace/dspace-angular.git
synced 2025-10-18 07:23:03 +00:00
68346: Routing back to edit-bitstreams page
This commit is contained in:
@@ -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: ",
|
||||
|
@@ -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
|
||||
|
@@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@@ -34,6 +34,7 @@
|
||||
[uploadFilesOptions]="uploadFilesOptions"
|
||||
(onCompleteItem)="onCompleteItem($event)"
|
||||
(onUploadError)="onUploadError()"></ds-uploader>
|
||||
<button class="btn btn-outline-secondary" (click)="onCancel()">{{'item.bitstreams.upload.cancel' | translate}}</button>
|
||||
</div>
|
||||
</div>
|
||||
</ng-container>
|
||||
|
@@ -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
|
||||
]
|
||||
|
@@ -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
|
||||
*/
|
||||
|
Reference in New Issue
Block a user