diff --git a/resources/i18n/en.json5 b/resources/i18n/en.json5
index b9c01f3ab4..bc6f4991fd 100644
--- a/resources/i18n/en.json5
+++ b/resources/i18n/en.json5
@@ -270,12 +270,14 @@
"home.top-level-communities.head": "Communities in DSpace",
"home.top-level-communities.help": "Select a community to browse its collections.",
- "item.bitstreams.upload.bundle-name": "Bundle Name",
+ "item.bitstreams.upload.bundle": "Bundle",
+ "item.bitstreams.upload.bundles.empty": "This item doesn\'t contain any bundles to upload a bitstream to.",
"item.bitstreams.upload.drop-message": "Drop a file to upload",
"item.bitstreams.upload.failed": "Upload failed. Please verify the content before retrying.",
"item.bitstreams.upload.item": "Item: ",
"item.bitstreams.upload.title": "Upload bitstream",
+ "item.edit.bitstreams.bundle.edit.buttons.upload": "Upload",
"item.edit.bitstreams.bundle.name": "BUNDLE: {{ name }}",
"item.edit.bitstreams.discard-button": "Discard",
"item.edit.bitstreams.edit.buttons.download": "Download",
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 75d31ee34e..9556dbe705 100644
--- a/src/app/+item-page/bitstreams/upload/upload-bitstream.component.html
+++ b/src/app/+item-page/bitstreams/upload/upload-bitstream.component.html
@@ -1,28 +1,36 @@
-
-
-
-
{{'item.bitstreams.upload.title' | translate}}
-
-
-
{{'item.bitstreams.upload.item' | translate}}
-
{{item.name}}
+
+
+ 0">
+
+
{{'item.bitstreams.upload.title' | translate}}
+
+
+ {{'item.bitstreams.upload.item' | translate}}
+ {{item.name}}
+
+
+
+
+
+
+
+
+
+
+
+
+ {{'item.bitstreams.upload.bundles.empty' | translate}}
-
+
-
-
-
-
-
-
+
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 3caf8b586d..13ac76591a 100644
--- a/src/app/+item-page/bitstreams/upload/upload-bitstream.component.ts
+++ b/src/app/+item-page/bitstreams/upload/upload-bitstream.component.ts
@@ -2,17 +2,20 @@ import { ChangeDetectionStrategy, Component, OnDestroy, OnInit } from '@angular/
import { Observable } from 'rxjs/internal/Observable';
import { RemoteData } from '../../../core/data/remote-data';
import { Item } from '../../../core/shared/item.model';
-import { distinctUntilChanged, map, switchMap } from 'rxjs/operators';
+import { map, switchMap, take } from 'rxjs/operators';
import { ActivatedRoute, Router } from '@angular/router';
import { UploaderOptions } from '../../../shared/uploader/uploader-options.model';
import { Subscription } from 'rxjs/internal/Subscription';
-import { hasValue, hasValueOperator } from '../../../shared/empty.util';
+import { hasValue, isEmpty } from '../../../shared/empty.util';
import { ItemDataService } from '../../../core/data/item-data.service';
import { AuthService } from '../../../core/auth/auth.service';
import { NotificationsService } from '../../../shared/notifications/notifications.service';
import { TranslateService } from '@ngx-translate/core';
-import { UploaderProperties } from '../../../shared/uploader/uploader-properties.model';
import { getBitstreamModulePath } from '../../../app-routing.module';
+import { PaginatedList } from '../../../core/data/paginated-list';
+import { Bundle } from '../../../core/shared/bundle.model';
+import { BundleDataService } from '../../../core/data/bundle-data.service';
+import { getRemoteDataPayload, getSucceededRemoteData } from '../../../core/shared/operators';
@Component({
selector: 'ds-upload-bitstream',
@@ -29,12 +32,23 @@ export class UploadBitstreamComponent implements OnInit, OnDestroy {
*/
itemRD$: Observable>;
+ /**
+ * The item's bundles
+ */
+ bundlesRD$: Observable>>;
+
+ /**
+ * The ID of the currently selected bundle to upload a bitstream to
+ */
+ selectedBundleId: string;
+
/**
* The uploader configuration options
* @type {UploaderOptions}
*/
uploadFilesOptions: UploaderOptions = {
- url: '',
+ // URL needs to contain something to not produce any errors. This will be replaced once a bundle has been selected.
+ url: 'placeholder',
authToken: null,
disableMultipart: false,
itemAlias: null
@@ -46,16 +60,10 @@ export class UploadBitstreamComponent implements OnInit, OnDestroy {
*/
subs: Subscription[] = [];
- /**
- * Properties to send with the upload request
- */
- uploadProperties = Object.assign(new UploaderProperties(), {
- bundleName: 'ORIGINAL'
- });
-
constructor(protected route: ActivatedRoute,
protected router: Router,
protected itemService: ItemDataService,
+ protected bundleService: BundleDataService,
protected authService: AuthService,
protected notificationsService: NotificationsService,
protected translate: TranslateService) {
@@ -63,25 +71,36 @@ export class UploadBitstreamComponent implements OnInit, OnDestroy {
ngOnInit(): void {
this.itemRD$ = this.route.data.pipe(map((data) => data.item));
- this.subs.push(
- this.route.queryParams.pipe(
- map((params) => params.bundleName),
- hasValueOperator(),
- distinctUntilChanged()
- ).subscribe((bundleName: string) => {
- this.uploadProperties.bundleName = bundleName;
- })
+ this.bundlesRD$ = this.itemRD$.pipe(
+ switchMap((itemRD: RemoteData- ) => itemRD.payload.bundles)
);
- this.subs.push(
- this.itemRD$.pipe(
- map((itemRD: RemoteData
- ) => itemRD.payload),
- switchMap((item: Item) => this.itemService.getBitstreamsEndpoint(item.id)),
- distinctUntilChanged()
- ).subscribe((url: string) => {
- this.uploadFilesOptions.url = url;
+ this.selectedBundleId = this.route.snapshot.queryParams.bundle;
+ if (isEmpty(this.selectedBundleId)) {
+ this.bundlesRD$.pipe(
+ getSucceededRemoteData(),
+ getRemoteDataPayload(),
+ take(1)
+ ).subscribe((bundles: PaginatedList) => {
+ if (bundles.page.length > 0) {
+ this.selectedBundleId = bundles.page[0].id;
+ this.setUploadUrl();
+ }
+ });
+ } else {
+ this.setUploadUrl();
+ }
+ }
+
+ /**
+ * Set the upload url to match the selected bundle ID
+ */
+ setUploadUrl() {
+ this.bundleService.getBitstreamsEndpoint(this.selectedBundleId).pipe(take(1)).subscribe((href: string) => {
+ this.uploadFilesOptions.url = href;
+ if (isEmpty(this.uploadFilesOptions.authToken)) {
this.uploadFilesOptions.authToken = this.authService.buildAuthHeader();
- })
- );
+ }
+ });
}
/**
diff --git a/src/app/+item-page/edit-item-page/edit-item-page.module.ts b/src/app/+item-page/edit-item-page/edit-item-page.module.ts
index 4f73cbeaf1..2b48141011 100644
--- a/src/app/+item-page/edit-item-page/edit-item-page.module.ts
+++ b/src/app/+item-page/edit-item-page/edit-item-page.module.ts
@@ -24,6 +24,7 @@ import { EditRelationshipListComponent } from './item-relationships/edit-relatio
import { AbstractItemUpdateComponent } from './abstract-item-update/abstract-item-update.component';
import { ItemMoveComponent } from './item-move/item-move.component';
import { ItemEditBitstreamBundleComponent } from './item-bitstreams/item-edit-bitstream-bundle/item-edit-bitstream-bundle.component';
+import { BundleDataService } from '../../core/data/bundle-data.service';
/**
* Module that contains all components related to the Edit Item page administrator functionality
@@ -58,6 +59,9 @@ import { ItemEditBitstreamBundleComponent } from './item-bitstreams/item-edit-bi
EditRelationshipListComponent,
ItemCollectionMapperComponent,
ItemMoveComponent,
+ ],
+ providers: [
+ BundleDataService
]
})
export class EditItemPageModule {
diff --git a/src/app/+item-page/edit-item-page/item-bitstreams/item-bitstreams.component.html b/src/app/+item-page/edit-item-page/item-bitstreams/item-bitstreams.component.html
index ddcff0c207..dc0acda61a 100644
--- a/src/app/+item-page/edit-item-page/item-bitstreams/item-bitstreams.component.html
+++ b/src/app/+item-page/edit-item-page/item-bitstreams/item-bitstreams.component.html
@@ -23,7 +23,7 @@
-
0" class="table table-responsive table-striped table-bordered mt-4">
+ 0" class="table table-responsive table-striped table-bordered mt-4">
{{'item.edit.bitstreams.headers.name' | translate}} |
@@ -33,7 +33,8 @@
+ [bundle]="bundle"
+ [item]="item">
diff --git a/src/app/+item-page/edit-item-page/item-bitstreams/item-edit-bitstream-bundle/item-edit-bitstream-bundle.component.html b/src/app/+item-page/edit-item-page/item-bitstreams/item-edit-bitstream-bundle/item-edit-bitstream-bundle.component.html
index 4be9ee2610..5baa4e04b4 100644
--- a/src/app/+item-page/edit-item-page/item-bitstreams/item-edit-bitstream-bundle/item-edit-bitstream-bundle.component.html
+++ b/src/app/+item-page/edit-item-page/item-bitstreams/item-edit-bitstream-bundle/item-edit-bitstream-bundle.component.html
@@ -1,6 +1,16 @@
- {{'item.edit.bitstreams.bundle.name' | translate:{ name: bundle.name } }} |
+ {{'item.edit.bitstreams.bundle.name' | translate:{ name: bundle.name } }} |
+
+
+
+
+ |
{
protected linkPath = 'bundles';
+ protected bitstreamsEndpoint = 'bitstreams';
protected forceBypassCache = false;
constructor(
@@ -43,4 +45,14 @@ export class BundleDataService extends DataService {
getBrowseEndpoint(options: FindAllOptions = {}, linkPath?: string): Observable {
return this.halService.getEndpoint(this.linkPath);
}
+
+ /**
+ * Get the bitstreams endpoint for a bundle
+ * @param bundleId
+ */
+ getBitstreamsEndpoint(bundleId: string): Observable {
+ return this.getBrowseEndpoint().pipe(
+ switchMap((href: string) => this.halService.getEndpoint(this.bitstreamsEndpoint, `${href}/${bundleId}`))
+ );
+ }
}