mirror of
https://github.com/DSpace/dspace-angular.git
synced 2025-10-07 18:14:17 +00:00
Merge pull request #1096 from atmire/fix-1094
Fix support for adding and removing relationships in relationship-only fields in the submission
This commit is contained in:
@@ -45,32 +45,32 @@ export const sendRequest = (requestService: RequestService) =>
|
||||
(source: Observable<RestRequest>): Observable<RestRequest> =>
|
||||
source.pipe(tap((request: RestRequest) => requestService.send(request)));
|
||||
|
||||
export const getRemoteDataPayload = () =>
|
||||
<T>(source: Observable<RemoteData<T>>): Observable<T> =>
|
||||
export const getRemoteDataPayload = <T>() =>
|
||||
(source: Observable<RemoteData<T>>): Observable<T> =>
|
||||
source.pipe(map((remoteData: RemoteData<T>) => remoteData.payload));
|
||||
|
||||
export const getPaginatedListPayload = () =>
|
||||
<T>(source: Observable<PaginatedList<T>>): Observable<T[]> =>
|
||||
export const getPaginatedListPayload = <T>() =>
|
||||
(source: Observable<PaginatedList<T>>): Observable<T[]> =>
|
||||
source.pipe(map((list: PaginatedList<T>) => list.page));
|
||||
|
||||
export const getAllCompletedRemoteData = () =>
|
||||
<T>(source: Observable<RemoteData<T>>): Observable<RemoteData<T>> =>
|
||||
export const getAllCompletedRemoteData = <T>() =>
|
||||
(source: Observable<RemoteData<T>>): Observable<RemoteData<T>> =>
|
||||
source.pipe(filter((rd: RemoteData<T>) => hasValue(rd) && rd.hasCompleted));
|
||||
|
||||
export const getFirstCompletedRemoteData = () =>
|
||||
<T>(source: Observable<RemoteData<T>>): Observable<RemoteData<T>> =>
|
||||
export const getFirstCompletedRemoteData = <T>() =>
|
||||
(source: Observable<RemoteData<T>>): Observable<RemoteData<T>> =>
|
||||
source.pipe(getAllCompletedRemoteData(), take(1));
|
||||
|
||||
export const takeUntilCompletedRemoteData = () =>
|
||||
<T>(source: Observable<RemoteData<T>>): Observable<RemoteData<T>> =>
|
||||
export const takeUntilCompletedRemoteData = <T>() =>
|
||||
(source: Observable<RemoteData<T>>): Observable<RemoteData<T>> =>
|
||||
source.pipe(takeWhile((rd: RemoteData<T>) => hasNoValue(rd) || rd.isLoading, true));
|
||||
|
||||
export const getFirstSucceededRemoteData = () =>
|
||||
<T>(source: Observable<RemoteData<T>>): Observable<RemoteData<T>> =>
|
||||
export const getFirstSucceededRemoteData = <T>() =>
|
||||
(source: Observable<RemoteData<T>>): Observable<RemoteData<T>> =>
|
||||
source.pipe(filter((rd: RemoteData<T>) => rd.hasSucceeded), take(1));
|
||||
|
||||
export const getFirstSucceededRemoteWithNotEmptyData = () =>
|
||||
<T>(source: Observable<RemoteData<T>>): Observable<RemoteData<T>> =>
|
||||
export const getFirstSucceededRemoteWithNotEmptyData = <T>() =>
|
||||
(source: Observable<RemoteData<T>>): Observable<RemoteData<T>> =>
|
||||
source.pipe(find((rd: RemoteData<T>) => rd.hasSucceeded && isNotEmpty(rd.payload)));
|
||||
|
||||
/**
|
||||
@@ -83,8 +83,8 @@ export const getFirstSucceededRemoteWithNotEmptyData = () =>
|
||||
* These operators were created as a first step in refactoring
|
||||
* out all the instances where this is used incorrectly.
|
||||
*/
|
||||
export const getFirstSucceededRemoteDataPayload = () =>
|
||||
<T>(source: Observable<RemoteData<T>>): Observable<T> =>
|
||||
export const getFirstSucceededRemoteDataPayload = <T>() =>
|
||||
(source: Observable<RemoteData<T>>): Observable<T> =>
|
||||
source.pipe(
|
||||
getFirstSucceededRemoteData(),
|
||||
getRemoteDataPayload()
|
||||
@@ -100,8 +100,8 @@ export const getFirstSucceededRemoteDataPayload = () =>
|
||||
* These operators were created as a first step in refactoring
|
||||
* out all the instances where this is used incorrectly.
|
||||
*/
|
||||
export const getFirstSucceededRemoteDataWithNotEmptyPayload = () =>
|
||||
<T>(source: Observable<RemoteData<T>>): Observable<T> =>
|
||||
export const getFirstSucceededRemoteDataWithNotEmptyPayload = <T>() =>
|
||||
(source: Observable<RemoteData<T>>): Observable<T> =>
|
||||
source.pipe(
|
||||
getFirstSucceededRemoteWithNotEmptyData(),
|
||||
getRemoteDataPayload()
|
||||
@@ -117,8 +117,8 @@ export const getFirstSucceededRemoteDataWithNotEmptyPayload = () =>
|
||||
* These operators were created as a first step in refactoring
|
||||
* out all the instances where this is used incorrectly.
|
||||
*/
|
||||
export const getAllSucceededRemoteDataPayload = () =>
|
||||
<T>(source: Observable<RemoteData<T>>): Observable<T> =>
|
||||
export const getAllSucceededRemoteDataPayload = <T>() =>
|
||||
(source: Observable<RemoteData<T>>): Observable<T> =>
|
||||
source.pipe(
|
||||
getAllSucceededRemoteData(),
|
||||
getRemoteDataPayload()
|
||||
@@ -138,8 +138,8 @@ export const getAllSucceededRemoteDataPayload = () =>
|
||||
* These operators were created as a first step in refactoring
|
||||
* out all the instances where this is used incorrectly.
|
||||
*/
|
||||
export const getFirstSucceededRemoteListPayload = () =>
|
||||
<T>(source: Observable<RemoteData<PaginatedList<T>>>): Observable<T[]> =>
|
||||
export const getFirstSucceededRemoteListPayload = <T>() =>
|
||||
(source: Observable<RemoteData<PaginatedList<T>>>): Observable<T[]> =>
|
||||
source.pipe(
|
||||
getFirstSucceededRemoteData(),
|
||||
getRemoteDataPayload(),
|
||||
@@ -160,8 +160,8 @@ export const getFirstSucceededRemoteListPayload = () =>
|
||||
* These operators were created as a first step in refactoring
|
||||
* out all the instances where this is used incorrectly.
|
||||
*/
|
||||
export const getAllSucceededRemoteListPayload = () =>
|
||||
<T>(source: Observable<RemoteData<PaginatedList<T>>>): Observable<T[]> =>
|
||||
export const getAllSucceededRemoteListPayload = <T>() =>
|
||||
(source: Observable<RemoteData<PaginatedList<T>>>): Observable<T[]> =>
|
||||
source.pipe(
|
||||
getAllSucceededRemoteData(),
|
||||
getRemoteDataPayload(),
|
||||
@@ -174,8 +174,8 @@ export const getAllSucceededRemoteListPayload = () =>
|
||||
* @param router The router used to navigate to a new page
|
||||
* @param authService Service to check if the user is authenticated
|
||||
*/
|
||||
export const redirectOn4xx = (router: Router, authService: AuthService) =>
|
||||
<T>(source: Observable<RemoteData<T>>): Observable<RemoteData<T>> =>
|
||||
export const redirectOn4xx = <T>(router: Router, authService: AuthService) =>
|
||||
(source: Observable<RemoteData<T>>): Observable<RemoteData<T>> =>
|
||||
observableCombineLatest(source, authService.isAuthenticated()).pipe(
|
||||
map(([rd, isAuthenticated]: [RemoteData<T>, boolean]) => {
|
||||
if (rd.hasFailed) {
|
||||
@@ -229,16 +229,16 @@ export const returnEndUserAgreementUrlTreeOnFalse = (router: Router, redirect: s
|
||||
return hasAgreed ? hasAgreed : router.createUrlTree([getEndUserAgreementPath()], { queryParams });
|
||||
}));
|
||||
|
||||
export const getFinishedRemoteData = () =>
|
||||
<T>(source: Observable<RemoteData<T>>): Observable<RemoteData<T>> =>
|
||||
export const getFinishedRemoteData = <T>() =>
|
||||
(source: Observable<RemoteData<T>>): Observable<RemoteData<T>> =>
|
||||
source.pipe(find((rd: RemoteData<T>) => !rd.isLoading));
|
||||
|
||||
export const getAllSucceededRemoteData = () =>
|
||||
<T>(source: Observable<RemoteData<T>>): Observable<RemoteData<T>> =>
|
||||
export const getAllSucceededRemoteData = <T>() =>
|
||||
(source: Observable<RemoteData<T>>): Observable<RemoteData<T>> =>
|
||||
source.pipe(filter((rd: RemoteData<T>) => rd.hasSucceeded));
|
||||
|
||||
export const toDSpaceObjectListRD = () =>
|
||||
<T extends DSpaceObject>(source: Observable<RemoteData<PaginatedList<SearchResult<T>>>>): Observable<RemoteData<PaginatedList<T>>> =>
|
||||
export const toDSpaceObjectListRD = <T extends DSpaceObject>() =>
|
||||
(source: Observable<RemoteData<PaginatedList<SearchResult<T>>>>): Observable<RemoteData<PaginatedList<T>>> =>
|
||||
source.pipe(
|
||||
filter((rd: RemoteData<PaginatedList<SearchResult<T>>>) => rd.hasSucceeded),
|
||||
map((rd: RemoteData<PaginatedList<SearchResult<T>>>) => {
|
||||
|
@@ -11,7 +11,7 @@
|
||||
'd-none': value?.isVirtual && (model.hasSelectableMetadata || context?.index > 0)}">
|
||||
<div [ngClass]="getClass('grid', 'control')">
|
||||
<ng-container #componentViewContainer></ng-container>
|
||||
<small *ngIf="hasHint && (model.repeatable === false || context?.index === context?.context?.groups?.length - 1) && (!showErrorMessages || errorMessages.length === 0)"
|
||||
<small *ngIf="hasHint && ((model.repeatable === false && (isRelationship === false || value?.value === null)) || (model.repeatable === true && context?.index === context?.context?.groups?.length - 1)) && (!showErrorMessages || errorMessages.length === 0)"
|
||||
class="text-muted ds-hint" [innerHTML]="model.hint | translate" [ngClass]="getClass('element', 'hint')"></small>
|
||||
<!-- In case of repeatable fields show empty space for all elements except the first -->
|
||||
<div *ngIf="context?.index !== null
|
||||
@@ -35,7 +35,7 @@
|
||||
<option *ngFor="let lang of model.languageCodes" [value]="lang.code">{{lang.display}}</option>
|
||||
</select>
|
||||
</div>
|
||||
<div *ngIf="isRelationship && !isVirtual()" class="col-auto text-center">
|
||||
<div *ngIf="isRelationship" class="col-auto text-center">
|
||||
<button class="btn btn-secondary"
|
||||
type="button"
|
||||
ngbTooltip="{{'form.lookup-help' | translate}}"
|
||||
|
@@ -17,12 +17,14 @@ import { RouterStub } from '../../shared/testing/router.stub';
|
||||
import { ActivatedRouteStub } from '../../shared/testing/active-router.stub';
|
||||
import { mockSubmissionObject } from '../../shared/mocks/submission.mock';
|
||||
import { createSuccessfulRemoteDataObject$ } from '../../shared/remote-data.utils';
|
||||
import { ItemDataService } from '../../core/data/item-data.service';
|
||||
|
||||
describe('SubmissionEditComponent Component', () => {
|
||||
|
||||
let comp: SubmissionEditComponent;
|
||||
let fixture: ComponentFixture<SubmissionEditComponent>;
|
||||
let submissionServiceStub: SubmissionServiceStub;
|
||||
let itemDataService: ItemDataService;
|
||||
let router: RouterStub;
|
||||
|
||||
const submissionId = '826';
|
||||
@@ -30,6 +32,9 @@ describe('SubmissionEditComponent Component', () => {
|
||||
const submissionObject: any = mockSubmissionObject;
|
||||
|
||||
beforeEach(waitForAsync(() => {
|
||||
itemDataService = jasmine.createSpyObj('itemDataService', {
|
||||
findByHref: createSuccessfulRemoteDataObject$(submissionObject.item),
|
||||
});
|
||||
TestBed.configureTestingModule({
|
||||
imports: [
|
||||
TranslateModule.forRoot(),
|
||||
@@ -41,6 +46,7 @@ describe('SubmissionEditComponent Component', () => {
|
||||
providers: [
|
||||
{ provide: NotificationsService, useClass: NotificationsServiceStub },
|
||||
{ provide: SubmissionService, useClass: SubmissionServiceStub },
|
||||
{ provide: ItemDataService, useValue: itemDataService },
|
||||
{ provide: TranslateService, useValue: getMockTranslateService() },
|
||||
{ provide: Router, useValue: new RouterStub() },
|
||||
{ provide: ActivatedRoute, useValue: route },
|
||||
@@ -63,7 +69,7 @@ describe('SubmissionEditComponent Component', () => {
|
||||
router = null;
|
||||
});
|
||||
|
||||
it('should init properly when a valid SubmissionObject has been retrieved', fakeAsync(() => {
|
||||
it('should init properly when a valid SubmissionObject has been retrieved',() => {
|
||||
|
||||
route.testParams = { id: submissionId };
|
||||
submissionServiceStub.retrieveSubmission.and.returnValue(
|
||||
@@ -78,9 +84,9 @@ describe('SubmissionEditComponent Component', () => {
|
||||
expect(comp.sections).toBe(submissionObject.sections);
|
||||
expect(comp.submissionDefinition).toBe(submissionObject.submissionDefinition);
|
||||
|
||||
}));
|
||||
});
|
||||
|
||||
it('should redirect to mydspace when an empty SubmissionObject has been retrieved', fakeAsync(() => {
|
||||
it('should redirect to mydspace when an empty SubmissionObject has been retrieved',() => {
|
||||
|
||||
route.testParams = { id: submissionId };
|
||||
submissionServiceStub.retrieveSubmission.and.returnValue(createSuccessfulRemoteDataObject$({})
|
||||
@@ -90,9 +96,9 @@ describe('SubmissionEditComponent Component', () => {
|
||||
|
||||
expect(router.navigate).toHaveBeenCalled();
|
||||
|
||||
}));
|
||||
});
|
||||
|
||||
it('should not has effects when an invalid SubmissionObject has been retrieved', fakeAsync(() => {
|
||||
it('should not has effects when an invalid SubmissionObject has been retrieved',() => {
|
||||
|
||||
route.testParams = { id: submissionId };
|
||||
submissionServiceStub.retrieveSubmission.and.returnValue(observableOf(null));
|
||||
@@ -104,6 +110,6 @@ describe('SubmissionEditComponent Component', () => {
|
||||
expect(comp.selfUrl).toBeUndefined();
|
||||
expect(comp.sections).toBeUndefined();
|
||||
expect(comp.submissionDefinition).toBeUndefined();
|
||||
}));
|
||||
});
|
||||
|
||||
});
|
||||
|
@@ -2,11 +2,11 @@ import { ChangeDetectorRef, Component, OnDestroy, OnInit } from '@angular/core';
|
||||
import { ActivatedRoute, ParamMap, Router } from '@angular/router';
|
||||
|
||||
import { Subscription } from 'rxjs';
|
||||
import { filter, switchMap } from 'rxjs/operators';
|
||||
import { filter, switchMap, debounceTime } from 'rxjs/operators';
|
||||
import { TranslateService } from '@ngx-translate/core';
|
||||
|
||||
import { WorkspaceitemSectionsObject } from '../../core/submission/models/workspaceitem-sections.model';
|
||||
import { hasValue, isEmpty, isNotNull } from '../../shared/empty.util';
|
||||
import { hasValue, isEmpty, isNotNull, isNotEmptyOperator } from '../../shared/empty.util';
|
||||
import { SubmissionDefinitionsModel } from '../../core/config/models/config-submission-definitions.model';
|
||||
import { SubmissionService } from '../submission.service';
|
||||
import { NotificationsService } from '../../shared/notifications/notifications.service';
|
||||
@@ -14,6 +14,9 @@ import { SubmissionObject } from '../../core/submission/models/submission-object
|
||||
import { Collection } from '../../core/shared/collection.model';
|
||||
import { RemoteData } from '../../core/data/remote-data';
|
||||
import { Item } from '../../core/shared/item.model';
|
||||
import { getAllSucceededRemoteData } from '../../core/shared/operators';
|
||||
import { ItemDataService } from '../../core/data/item-data.service';
|
||||
import { BehaviorSubject } from 'rxjs/internal/BehaviorSubject';
|
||||
|
||||
/**
|
||||
* This component allows to edit an existing workspaceitem/workflowitem.
|
||||
@@ -60,6 +63,16 @@ export class SubmissionEditComponent implements OnDestroy, OnInit {
|
||||
* @type {Array}
|
||||
*/
|
||||
private subs: Subscription[] = [];
|
||||
|
||||
/**
|
||||
* BehaviorSubject containing the self link to the item for this submission
|
||||
* @private
|
||||
*/
|
||||
private itemLink$: BehaviorSubject<string> = new BehaviorSubject(undefined);
|
||||
|
||||
/**
|
||||
* The item for this submission.
|
||||
*/
|
||||
public item: Item;
|
||||
|
||||
/**
|
||||
@@ -69,6 +82,7 @@ export class SubmissionEditComponent implements OnDestroy, OnInit {
|
||||
* @param {NotificationsService} notificationsService
|
||||
* @param {ActivatedRoute} route
|
||||
* @param {Router} router
|
||||
* @param {ItemDataService} itemDataService
|
||||
* @param {SubmissionService} submissionService
|
||||
* @param {TranslateService} translate
|
||||
*/
|
||||
@@ -76,6 +90,7 @@ export class SubmissionEditComponent implements OnDestroy, OnInit {
|
||||
private notificationsService: NotificationsService,
|
||||
private route: ActivatedRoute,
|
||||
private router: Router,
|
||||
private itemDataService: ItemDataService,
|
||||
private submissionService: SubmissionService,
|
||||
private translate: TranslateService) {
|
||||
}
|
||||
@@ -84,7 +99,8 @@ export class SubmissionEditComponent implements OnDestroy, OnInit {
|
||||
* Retrieve workspaceitem/workflowitem from server and initialize all instance variables
|
||||
*/
|
||||
ngOnInit() {
|
||||
this.subs.push(this.route.paramMap.pipe(
|
||||
this.subs.push(
|
||||
this.route.paramMap.pipe(
|
||||
switchMap((params: ParamMap) => this.submissionService.retrieveSubmission(params.get('id'))),
|
||||
// NOTE new submission is retrieved on the browser side only, so get null on server side rendering
|
||||
filter((submissionObjectRD: RemoteData<SubmissionObject>) => isNotNull(submissionObjectRD))
|
||||
@@ -98,9 +114,9 @@ export class SubmissionEditComponent implements OnDestroy, OnInit {
|
||||
this.collectionId = (submissionObjectRD.payload.collection as Collection).id;
|
||||
this.selfUrl = submissionObjectRD.payload._links.self.href;
|
||||
this.sections = submissionObjectRD.payload.sections;
|
||||
this.item = submissionObjectRD.payload.item as Item;
|
||||
this.itemLink$.next(submissionObjectRD.payload._links.item.href);
|
||||
this.item = submissionObjectRD.payload.item;
|
||||
this.submissionDefinition = (submissionObjectRD.payload.submissionDefinition as SubmissionDefinitionsModel);
|
||||
this.changeDetectorRef.detectChanges();
|
||||
}
|
||||
} else {
|
||||
if (submissionObjectRD.statusCode === 404) {
|
||||
@@ -109,7 +125,21 @@ export class SubmissionEditComponent implements OnDestroy, OnInit {
|
||||
}
|
||||
// TODO handle generic error
|
||||
}
|
||||
}));
|
||||
}),
|
||||
this.itemLink$.pipe(
|
||||
isNotEmptyOperator(),
|
||||
switchMap((itemLink: string) =>
|
||||
this.itemDataService.findByHref(itemLink)
|
||||
),
|
||||
getAllSucceededRemoteData(),
|
||||
// Multiple sources can update the item in quick succession.
|
||||
// We only want to rerender the form if the item is unchanged for some time
|
||||
debounceTime(300),
|
||||
).subscribe((itemRd: RemoteData<Item>) => {
|
||||
this.item = itemRd.payload;
|
||||
this.changeDetectorRef.detectChanges();
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@@ -15,18 +15,24 @@ import { RouterStub } from '../../shared/testing/router.stub';
|
||||
import { mockSubmissionObject } from '../../shared/mocks/submission.mock';
|
||||
import { SubmissionSubmitComponent } from './submission-submit.component';
|
||||
import { ActivatedRouteStub } from '../../shared/testing/active-router.stub';
|
||||
import { ItemDataService } from '../../core/data/item-data.service';
|
||||
import { createSuccessfulRemoteDataObject$ } from '../../shared/remote-data.utils';
|
||||
|
||||
describe('SubmissionSubmitComponent Component', () => {
|
||||
|
||||
let comp: SubmissionSubmitComponent;
|
||||
let fixture: ComponentFixture<SubmissionSubmitComponent>;
|
||||
let submissionServiceStub: SubmissionServiceStub;
|
||||
let itemDataService: ItemDataService;
|
||||
let router: RouterStub;
|
||||
|
||||
const submissionId = '826';
|
||||
const submissionObject: any = mockSubmissionObject;
|
||||
|
||||
beforeEach(waitForAsync(() => {
|
||||
itemDataService = jasmine.createSpyObj('itemDataService', {
|
||||
findByHref: createSuccessfulRemoteDataObject$(submissionObject.item),
|
||||
});
|
||||
TestBed.configureTestingModule({
|
||||
imports: [
|
||||
TranslateModule.forRoot(),
|
||||
@@ -38,6 +44,7 @@ describe('SubmissionSubmitComponent Component', () => {
|
||||
providers: [
|
||||
{ provide: NotificationsService, useClass: NotificationsServiceStub },
|
||||
{ provide: SubmissionService, useClass: SubmissionServiceStub },
|
||||
{ provide: ItemDataService, useValue: itemDataService },
|
||||
{ provide: TranslateService, useValue: getMockTranslateService() },
|
||||
{ provide: Router, useValue: new RouterStub() },
|
||||
{ provide: ActivatedRoute, useValue: new ActivatedRouteStub() },
|
||||
@@ -60,7 +67,7 @@ describe('SubmissionSubmitComponent Component', () => {
|
||||
router = null;
|
||||
});
|
||||
|
||||
it('should init properly when a valid SubmissionObject has been retrieved', fakeAsync(() => {
|
||||
it('should init properly when a valid SubmissionObject has been retrieved',() => {
|
||||
|
||||
submissionServiceStub.createSubmission.and.returnValue(observableOf(submissionObject));
|
||||
|
||||
@@ -72,9 +79,9 @@ describe('SubmissionSubmitComponent Component', () => {
|
||||
expect(comp.sections).toBe(submissionObject.sections);
|
||||
expect(comp.submissionDefinition).toBe(submissionObject.submissionDefinition);
|
||||
|
||||
}));
|
||||
});
|
||||
|
||||
it('should redirect to mydspace when an empty SubmissionObject has been retrieved', fakeAsync(() => {
|
||||
it('should redirect to mydspace when an empty SubmissionObject has been retrieved',() => {
|
||||
|
||||
submissionServiceStub.createSubmission.and.returnValue(observableOf({}));
|
||||
|
||||
@@ -82,9 +89,9 @@ describe('SubmissionSubmitComponent Component', () => {
|
||||
|
||||
expect(router.navigate).toHaveBeenCalled();
|
||||
|
||||
}));
|
||||
});
|
||||
|
||||
it('should not has effects when an invalid SubmissionObject has been retrieved', fakeAsync(() => {
|
||||
it('should not has effects when an invalid SubmissionObject has been retrieved',() => {
|
||||
|
||||
submissionServiceStub.createSubmission.and.returnValue(observableOf(null));
|
||||
|
||||
@@ -94,6 +101,6 @@ describe('SubmissionSubmitComponent Component', () => {
|
||||
expect(comp.collectionId).toBeUndefined();
|
||||
expect(comp.selfUrl).toBeUndefined();
|
||||
expect(comp.submissionDefinition).toBeUndefined();
|
||||
}));
|
||||
});
|
||||
|
||||
});
|
||||
|
@@ -3,7 +3,7 @@ import { ActivatedRoute, Router } from '@angular/router';
|
||||
|
||||
import { Subscription } from 'rxjs';
|
||||
|
||||
import { hasValue, isEmpty, isNotNull } from '../../shared/empty.util';
|
||||
import { hasValue, isEmpty, isNotNull, isNotEmptyOperator } from '../../shared/empty.util';
|
||||
import { SubmissionDefinitionsModel } from '../../core/config/models/config-submission-definitions.model';
|
||||
import { TranslateService } from '@ngx-translate/core';
|
||||
import { NotificationsService } from '../../shared/notifications/notifications.service';
|
||||
@@ -12,6 +12,11 @@ import { SubmissionObject } from '../../core/submission/models/submission-object
|
||||
import { Collection } from '../../core/shared/collection.model';
|
||||
import { Item } from '../../core/shared/item.model';
|
||||
import { WorkspaceitemSectionsObject } from '../../core/submission/models/workspaceitem-sections.model';
|
||||
import { BehaviorSubject } from 'rxjs/internal/BehaviorSubject';
|
||||
import { switchMap, debounceTime } from 'rxjs/operators';
|
||||
import { getAllSucceededRemoteData } from '../../core/shared/operators';
|
||||
import { RemoteData } from '../../core/data/remote-data';
|
||||
import { ItemDataService } from '../../core/data/item-data.service';
|
||||
|
||||
/**
|
||||
* This component allows to submit a new workspaceitem.
|
||||
@@ -28,6 +33,16 @@ export class SubmissionSubmitComponent implements OnDestroy, OnInit {
|
||||
* @type {string}
|
||||
*/
|
||||
public collectionId: string;
|
||||
|
||||
/**
|
||||
* BehaviorSubject containing the self link to the item for this submission
|
||||
* @private
|
||||
*/
|
||||
private itemLink$: BehaviorSubject<string> = new BehaviorSubject(undefined);
|
||||
|
||||
/**
|
||||
* The item for this submission.
|
||||
*/
|
||||
public item: Item;
|
||||
|
||||
/**
|
||||
@@ -71,6 +86,7 @@ export class SubmissionSubmitComponent implements OnDestroy, OnInit {
|
||||
*
|
||||
* @param {ChangeDetectorRef} changeDetectorRef
|
||||
* @param {NotificationsService} notificationsService
|
||||
* @param {ItemDataService} itemDataService
|
||||
* @param {SubmissionService} submissionService
|
||||
* @param {Router} router
|
||||
* @param {TranslateService} translate
|
||||
@@ -80,13 +96,16 @@ export class SubmissionSubmitComponent implements OnDestroy, OnInit {
|
||||
constructor(private changeDetectorRef: ChangeDetectorRef,
|
||||
private notificationsService: NotificationsService,
|
||||
private router: Router,
|
||||
private itemDataService: ItemDataService,
|
||||
private submissionService: SubmissionService,
|
||||
private translate: TranslateService,
|
||||
private viewContainerRef: ViewContainerRef,
|
||||
private route: ActivatedRoute) {
|
||||
this.route
|
||||
.queryParams
|
||||
.subscribe((params) => { this.collectionParam = (params.collection); });
|
||||
.subscribe((params) => {
|
||||
this.collectionParam = (params.collection);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -108,10 +127,23 @@ export class SubmissionSubmitComponent implements OnDestroy, OnInit {
|
||||
this.selfUrl = submissionObject._links.self.href;
|
||||
this.submissionDefinition = (submissionObject.submissionDefinition as SubmissionDefinitionsModel);
|
||||
this.submissionId = submissionObject.id;
|
||||
this.itemLink$.next(submissionObject._links.item.href);
|
||||
this.item = submissionObject.item as Item;
|
||||
}
|
||||
}
|
||||
}),
|
||||
this.itemLink$.pipe(
|
||||
isNotEmptyOperator(),
|
||||
switchMap((itemLink: string) =>
|
||||
this.itemDataService.findByHref(itemLink)
|
||||
),
|
||||
getAllSucceededRemoteData(),
|
||||
// Multiple sources can update the item in quick succession.
|
||||
// We only want to rerender the form if the item is unchanged for some time
|
||||
debounceTime(300),
|
||||
).subscribe((itemRd: RemoteData<Item>) => {
|
||||
this.item = itemRd.payload;
|
||||
this.changeDetectorRef.detectChanges();
|
||||
}
|
||||
}
|
||||
})
|
||||
);
|
||||
}
|
||||
|
Reference in New Issue
Block a user