mirror of
https://github.com/DSpace/dspace-angular.git
synced 2025-10-07 10:04:11 +00:00
90873: Add default bundle suggestions on upload bundle
This commit is contained in:
@@ -1,4 +1,4 @@
|
|||||||
<div class="container" *ngVar="(bundlesRD$ | async)?.payload?.page as bundles">
|
<div class="container">
|
||||||
<ng-container *ngIf="bundles">
|
<ng-container *ngIf="bundles">
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col-12 mb-4">
|
<div class="col-12 mb-4">
|
||||||
|
@@ -21,9 +21,8 @@ import { createPaginatedList } from '../../../shared/testing/utils.test';
|
|||||||
import { RouterStub } from '../../../shared/testing/router.stub';
|
import { RouterStub } from '../../../shared/testing/router.stub';
|
||||||
import { NotificationsServiceStub } from '../../../shared/testing/notifications-service.stub';
|
import { NotificationsServiceStub } from '../../../shared/testing/notifications-service.stub';
|
||||||
import { AuthServiceStub } from '../../../shared/testing/auth-service.stub';
|
import { AuthServiceStub } from '../../../shared/testing/auth-service.stub';
|
||||||
import { getTestScheduler } from 'jasmine-marbles';
|
|
||||||
|
|
||||||
describe('UploadBistreamComponent', () => {
|
describe('UploadBitstreamComponent', () => {
|
||||||
let comp: UploadBitstreamComponent;
|
let comp: UploadBitstreamComponent;
|
||||||
let fixture: ComponentFixture<UploadBitstreamComponent>;
|
let fixture: ComponentFixture<UploadBitstreamComponent>;
|
||||||
|
|
||||||
@@ -94,22 +93,6 @@ describe('UploadBistreamComponent', () => {
|
|||||||
removeByHrefSubstring: {}
|
removeByHrefSubstring: {}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
describe('on init', () => {
|
|
||||||
beforeEach(waitForAsync(() => {
|
|
||||||
createUploadBitstreamTestingModule({
|
|
||||||
bundle: bundle.id
|
|
||||||
});
|
|
||||||
}));
|
|
||||||
beforeEach(() => {
|
|
||||||
loadFixtureAndComp();
|
|
||||||
});
|
|
||||||
it('should initialize the bundles', () => {
|
|
||||||
expect(comp.bundlesRD$).toBeDefined();
|
|
||||||
getTestScheduler().expectObservable(comp.bundlesRD$).toBe('(a|)', {a: createSuccessfulRemoteDataObject([bundle])});
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('when a file is uploaded', () => {
|
describe('when a file is uploaded', () => {
|
||||||
beforeEach(waitForAsync(() => {
|
beforeEach(waitForAsync(() => {
|
||||||
createUploadBitstreamTestingModule({});
|
createUploadBitstreamTestingModule({});
|
||||||
|
@@ -1,8 +1,8 @@
|
|||||||
import { Component, OnDestroy, OnInit, ViewChild } from '@angular/core';
|
import { Component, OnDestroy, OnInit, ViewChild } from '@angular/core';
|
||||||
import { Observable, Subscription } from 'rxjs';
|
import { Observable, Subscription, of as observableOf } from 'rxjs';
|
||||||
import { RemoteData } from '../../../core/data/remote-data';
|
import { RemoteData } from '../../../core/data/remote-data';
|
||||||
import { Item } from '../../../core/shared/item.model';
|
import { Item } from '../../../core/shared/item.model';
|
||||||
import { map, take } from 'rxjs/operators';
|
import { map, take, switchMap } from 'rxjs/operators';
|
||||||
import { ActivatedRoute, Router } from '@angular/router';
|
import { ActivatedRoute, Router } from '@angular/router';
|
||||||
import { UploaderOptions } from '../../../shared/uploader/uploader-options.model';
|
import { UploaderOptions } from '../../../shared/uploader/uploader-options.model';
|
||||||
import { hasValue, isEmpty, isNotEmpty } from '../../../shared/empty.util';
|
import { hasValue, isEmpty, isNotEmpty } from '../../../shared/empty.util';
|
||||||
@@ -13,11 +13,13 @@ import { TranslateService } from '@ngx-translate/core';
|
|||||||
import { PaginatedList } from '../../../core/data/paginated-list.model';
|
import { PaginatedList } from '../../../core/data/paginated-list.model';
|
||||||
import { Bundle } from '../../../core/shared/bundle.model';
|
import { Bundle } from '../../../core/shared/bundle.model';
|
||||||
import { BundleDataService } from '../../../core/data/bundle-data.service';
|
import { BundleDataService } from '../../../core/data/bundle-data.service';
|
||||||
import { getFirstSucceededRemoteDataPayload } from '../../../core/shared/operators';
|
import { getFirstSucceededRemoteDataPayload, getFirstCompletedRemoteData } from '../../../core/shared/operators';
|
||||||
import { UploaderComponent } from '../../../shared/uploader/uploader.component';
|
import { UploaderComponent } from '../../../shared/uploader/uploader.component';
|
||||||
import { RequestService } from '../../../core/data/request.service';
|
import { RequestService } from '../../../core/data/request.service';
|
||||||
import { getBitstreamModuleRoute } from '../../../app-routing-paths';
|
import { getBitstreamModuleRoute } from '../../../app-routing-paths';
|
||||||
import { getEntityEditRoute } from '../../item-page-routing-paths';
|
import { getEntityEditRoute } from '../../item-page-routing-paths';
|
||||||
|
import { environment } from '../../../../environments/environment';
|
||||||
|
import { StandardBundleConfig } from '../../../../config/standard-bundle-config.interface';
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'ds-upload-bitstream',
|
selector: 'ds-upload-bitstream',
|
||||||
@@ -49,9 +51,9 @@ export class UploadBitstreamComponent implements OnInit, OnDestroy {
|
|||||||
itemRD$: Observable<RemoteData<Item>>;
|
itemRD$: Observable<RemoteData<Item>>;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The item's bundles
|
* The item's bundles and default the default bundles that should be suggested (defined in environment)
|
||||||
*/
|
*/
|
||||||
bundlesRD$: Observable<RemoteData<PaginatedList<Bundle>>>;
|
bundles: Bundle[] = [];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The ID of the currently selected bundle to upload a bitstream to
|
* The ID of the currently selected bundle to upload a bitstream to
|
||||||
@@ -99,7 +101,6 @@ export class UploadBitstreamComponent implements OnInit, OnDestroy {
|
|||||||
/**
|
/**
|
||||||
* Initialize component properties:
|
* Initialize component properties:
|
||||||
* itemRD$ Fetched from the current route data (populated by BitstreamPageResolver)
|
* itemRD$ Fetched from the current route data (populated by BitstreamPageResolver)
|
||||||
* bundlesRD$ List of bundles on the item
|
|
||||||
* selectedBundleId Starts off by checking if the route's queryParams contain a "bundle" parameter. If none is found,
|
* selectedBundleId Starts off by checking if the route's queryParams contain a "bundle" parameter. If none is found,
|
||||||
* the ID of the first bundle in the list is selected.
|
* the ID of the first bundle in the list is selected.
|
||||||
* Calls setUploadUrl after setting the selected bundle
|
* Calls setUploadUrl after setting the selected bundle
|
||||||
@@ -108,7 +109,39 @@ export class UploadBitstreamComponent implements OnInit, OnDestroy {
|
|||||||
this.itemId = this.route.snapshot.params.id;
|
this.itemId = this.route.snapshot.params.id;
|
||||||
this.entityType = this.route.snapshot.params['entity-type'];
|
this.entityType = this.route.snapshot.params['entity-type'];
|
||||||
this.itemRD$ = this.route.data.pipe(map((data) => data.dso));
|
this.itemRD$ = this.route.data.pipe(map((data) => data.dso));
|
||||||
this.bundlesRD$ = this.itemService.getBundles(this.itemId);
|
const bundlesRD$ = this.itemService.getBundles(this.itemId).pipe(
|
||||||
|
getFirstCompletedRemoteData(),
|
||||||
|
switchMap((remoteData: RemoteData<PaginatedList<Bundle>>) => {
|
||||||
|
if (remoteData.hasSucceeded) {
|
||||||
|
if (remoteData.payload.page) {
|
||||||
|
this.bundles = remoteData.payload.page;
|
||||||
|
} else if (environment.standardBundles) {
|
||||||
|
this.bundles = environment.standardBundles.map((defaultBundle: StandardBundleConfig) => Object.assign(new Bundle(), {
|
||||||
|
_name: defaultBundle.bundle,
|
||||||
|
type: 'bundle'
|
||||||
|
})
|
||||||
|
);
|
||||||
|
}
|
||||||
|
if (remoteData.payload.page && environment.standardBundles) {
|
||||||
|
for (const defaultBundle of environment.standardBundles) {
|
||||||
|
let check = true;
|
||||||
|
remoteData.payload.page.forEach((bundle: Bundle) => {
|
||||||
|
// noinspection JSDeprecatedSymbols
|
||||||
|
if (defaultBundle.bundle === bundle.name) {
|
||||||
|
check = false;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
if (check) {
|
||||||
|
this.bundles.push(Object.assign(new Bundle(), {
|
||||||
|
_name: defaultBundle.bundle,
|
||||||
|
type: 'bundle'
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return observableOf(remoteData.payload.page);
|
||||||
|
}
|
||||||
|
}));
|
||||||
this.selectedBundleId = this.route.snapshot.queryParams.bundle;
|
this.selectedBundleId = this.route.snapshot.queryParams.bundle;
|
||||||
if (isNotEmpty(this.selectedBundleId)) {
|
if (isNotEmpty(this.selectedBundleId)) {
|
||||||
this.bundleService.findById(this.selectedBundleId).pipe(
|
this.bundleService.findById(this.selectedBundleId).pipe(
|
||||||
@@ -118,6 +151,7 @@ export class UploadBitstreamComponent implements OnInit, OnDestroy {
|
|||||||
});
|
});
|
||||||
this.setUploadUrl();
|
this.setUploadUrl();
|
||||||
}
|
}
|
||||||
|
this.subs.push(bundlesRD$.subscribe());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -142,6 +176,13 @@ export class UploadBitstreamComponent implements OnInit, OnDestroy {
|
|||||||
*/
|
*/
|
||||||
bundleNameChange() {
|
bundleNameChange() {
|
||||||
this.selectedBundleId = undefined;
|
this.selectedBundleId = undefined;
|
||||||
|
for (const bundle of this.bundles) {
|
||||||
|
// noinspection JSDeprecatedSymbols
|
||||||
|
if (this.selectedBundleName === bundle.name) {
|
||||||
|
this.selectedBundleId = bundle.id;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@@ -1643,7 +1643,7 @@
|
|||||||
|
|
||||||
"item.bitstreams.upload.bundle": "Bundle",
|
"item.bitstreams.upload.bundle": "Bundle",
|
||||||
|
|
||||||
"item.bitstreams.upload.bundle.placeholder": "Select a bundle",
|
"item.bitstreams.upload.bundle.placeholder": "Select a bundle or input new bundle name",
|
||||||
|
|
||||||
"item.bitstreams.upload.bundle.new": "Create bundle",
|
"item.bitstreams.upload.bundle.new": "Create bundle",
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user