mirror of
https://github.com/DSpace/dspace-angular.git
synced 2025-10-09 11:03:05 +00:00
[835] Auto-save in new Item Submission form breaks the form
Minor changes and cleanup.
This commit is contained in:
@@ -16,7 +16,7 @@ import {
|
|||||||
import { isObject, isString, mergeWith } from 'lodash';
|
import { isObject, isString, mergeWith } from 'lodash';
|
||||||
|
|
||||||
import { hasValue, isEmpty, isNotEmpty, isNotNull, isNotUndefined, isNull } from '../../empty.util';
|
import { hasValue, isEmpty, isNotEmpty, isNotNull, isNotUndefined, isNull } from '../../empty.util';
|
||||||
import { DynamicQualdropModel } from './ds-dynamic-form-ui/models/ds-dynamic-qualdrop.model';
|
import {DynamicQualdropModel} from './ds-dynamic-form-ui/models/ds-dynamic-qualdrop.model';
|
||||||
import { SubmissionFormsModel } from '../../../core/config/models/config-submission-forms.model';
|
import { SubmissionFormsModel } from '../../../core/config/models/config-submission-forms.model';
|
||||||
import { DYNAMIC_FORM_CONTROL_TYPE_TAG } from './ds-dynamic-form-ui/models/tag/dynamic-tag.model';
|
import { DYNAMIC_FORM_CONTROL_TYPE_TAG } from './ds-dynamic-form-ui/models/tag/dynamic-tag.model';
|
||||||
import { RowParser } from './parsers/row-parser';
|
import { RowParser } from './parsers/row-parser';
|
||||||
@@ -56,9 +56,7 @@ export class FormBuilderService extends DynamicFormService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (this.isConcatGroup(controlModel)) {
|
if (this.isConcatGroup(controlModel)) {
|
||||||
const concatGroupId = controlModel.id.replace(CONCAT_GROUP_SUFFIX, '');
|
if (controlModel.id.match(new RegExp(findId + CONCAT_GROUP_SUFFIX + `_\\d+$`))) {
|
||||||
// if (concatGroupId === findId) {
|
|
||||||
if (concatGroupId.includes(findId)) {
|
|
||||||
result = (controlModel as DynamicConcatModel).group[0];
|
result = (controlModel as DynamicConcatModel).group[0];
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@@ -18,7 +18,7 @@
|
|||||||
<button type="button" class="btn btn-secondary"
|
<button type="button" class="btn btn-secondary"
|
||||||
[disabled]="isItemReadOnly(context, index)"
|
[disabled]="isItemReadOnly(context, index)"
|
||||||
(click)="insertItem($event, group.context, group.index)">
|
(click)="insertItem($event, group.context, group.index)">
|
||||||
<span aria-label="Add">Add</span>
|
<span aria-label="Add">{{'form.add' | translate}}</span>
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
@@ -9,7 +9,6 @@ export class SubmissionServiceStub {
|
|||||||
dispatchDeposit = jasmine.createSpy('dispatchDeposit');
|
dispatchDeposit = jasmine.createSpy('dispatchDeposit');
|
||||||
dispatchDiscard = jasmine.createSpy('dispatchDiscard');
|
dispatchDiscard = jasmine.createSpy('dispatchDiscard');
|
||||||
dispatchSave = jasmine.createSpy('dispatchSave');
|
dispatchSave = jasmine.createSpy('dispatchSave');
|
||||||
dispatchManualSave = jasmine.createSpy('dispatchManualSave');
|
|
||||||
dispatchSaveForLater = jasmine.createSpy('dispatchSaveForLater');
|
dispatchSaveForLater = jasmine.createSpy('dispatchSaveForLater');
|
||||||
dispatchSaveSection = jasmine.createSpy('dispatchSaveSection');
|
dispatchSaveSection = jasmine.createSpy('dispatchSaveSection');
|
||||||
getActiveSectionId = jasmine.createSpy('getActiveSectionId');
|
getActiveSectionId = jasmine.createSpy('getActiveSectionId');
|
||||||
|
@@ -164,12 +164,12 @@ describe('SubmissionFormFooterComponent Component', () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should call dispatchManualSave on save', () => {
|
it('should call dispatchSave on save', () => {
|
||||||
|
|
||||||
comp.save(null);
|
comp.save(null);
|
||||||
fixture.detectChanges();
|
fixture.detectChanges();
|
||||||
|
|
||||||
expect(submissionServiceStub.dispatchManualSave).toHaveBeenCalledWith(submissionId);
|
expect(submissionServiceStub.dispatchSave).toHaveBeenCalledWith(submissionId, true);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should call dispatchSaveForLater on save for later', () => {
|
it('should call dispatchSaveForLater on save for later', () => {
|
||||||
|
@@ -80,7 +80,7 @@ export class SubmissionFormFooterComponent implements OnChanges {
|
|||||||
* Dispatch a submission save action
|
* Dispatch a submission save action
|
||||||
*/
|
*/
|
||||||
save(event) {
|
save(event) {
|
||||||
this.submissionService.dispatchManualSave(this.submissionId);
|
this.submissionService.dispatchSave(this.submissionId, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@@ -3,7 +3,6 @@
|
|||||||
[formId]="formId"
|
[formId]="formId"
|
||||||
[formModel]="formModel"
|
[formModel]="formModel"
|
||||||
[displaySubmit]="false"
|
[displaySubmit]="false"
|
||||||
(dfBlur)="onBlur($event)"
|
|
||||||
(dfChange)="onChange($event)"
|
(dfChange)="onChange($event)"
|
||||||
(dfFocus)="onFocus($event)"
|
(dfFocus)="onFocus($event)"
|
||||||
(remove)="onRemove($event)"
|
(remove)="onRemove($event)"
|
||||||
|
@@ -131,12 +131,6 @@ export class SubmissionSectionformComponent extends SectionModelComponent {
|
|||||||
*/
|
*/
|
||||||
@ViewChild('formRef', {static: false}) private formRef: FormComponent;
|
@ViewChild('formRef', {static: false}) private formRef: FormComponent;
|
||||||
|
|
||||||
/**
|
|
||||||
* Keep track whether the section is focused or not.
|
|
||||||
* @protected
|
|
||||||
*/
|
|
||||||
protected isFocused = false;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Initialize instance variables
|
* Initialize instance variables
|
||||||
*
|
*
|
||||||
@@ -265,6 +259,7 @@ export class SubmissionSectionformComponent extends SectionModelComponent {
|
|||||||
Object.keys(diffObj)
|
Object.keys(diffObj)
|
||||||
.forEach((key) => {
|
.forEach((key) => {
|
||||||
diffObj[key].forEach((value) => {
|
diffObj[key].forEach((value) => {
|
||||||
|
// the findIndex extra check excludes values already present in the form but in different positions
|
||||||
if (value.hasOwnProperty('value') && findIndex(this.formData[key], { value: value.value }) < 0) {
|
if (value.hasOwnProperty('value') && findIndex(this.formData[key], { value: value.value }) < 0) {
|
||||||
diffResult.push(value);
|
diffResult.push(value);
|
||||||
}
|
}
|
||||||
@@ -407,7 +402,6 @@ export class SubmissionSectionformComponent extends SectionModelComponent {
|
|||||||
* the [[DynamicFormControlEvent]] emitted
|
* the [[DynamicFormControlEvent]] emitted
|
||||||
*/
|
*/
|
||||||
onFocus(event: DynamicFormControlEvent): void {
|
onFocus(event: DynamicFormControlEvent): void {
|
||||||
this.isFocused = true;
|
|
||||||
const value = this.formOperationsService.getFieldValueFromChangeEvent(event);
|
const value = this.formOperationsService.getFieldValueFromChangeEvent(event);
|
||||||
const path = this.formBuilderService.getPath(event.model);
|
const path = this.formBuilderService.getPath(event.model);
|
||||||
if (this.formBuilderService.hasMappedGroupValue(event.model)) {
|
if (this.formBuilderService.hasMappedGroupValue(event.model)) {
|
||||||
@@ -419,17 +413,6 @@ export class SubmissionSectionformComponent extends SectionModelComponent {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Method called when a form dfBlur event is fired.
|
|
||||||
*
|
|
||||||
* @param event
|
|
||||||
* the [[DynamicFormControlEvent]] emitted
|
|
||||||
*/
|
|
||||||
|
|
||||||
onBlur(event: DynamicFormControlEvent): void {
|
|
||||||
this.isFocused = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Method called when a form remove event is fired.
|
* Method called when a form remove event is fired.
|
||||||
* Dispatch form operations based on changes.
|
* Dispatch form operations based on changes.
|
||||||
|
@@ -487,16 +487,14 @@ describe('SubmissionService test suite', () => {
|
|||||||
|
|
||||||
describe('dispatchSave', () => {
|
describe('dispatchSave', () => {
|
||||||
it('should dispatch a new SaveSubmissionFormAction', () => {
|
it('should dispatch a new SaveSubmissionFormAction', () => {
|
||||||
service.dispatchSave(submissionId,);
|
service.dispatchSave(submissionId);
|
||||||
const expected = new SaveSubmissionFormAction(submissionId);
|
const expected = new SaveSubmissionFormAction(submissionId);
|
||||||
|
|
||||||
expect((service as any).store.dispatch).toHaveBeenCalledWith(expected);
|
expect((service as any).store.dispatch).toHaveBeenCalledWith(expected);
|
||||||
});
|
});
|
||||||
});
|
|
||||||
|
|
||||||
describe('dispatchManualSave', () => {
|
it('should dispatch a new SaveSubmissionFormAction with manual flag', () => {
|
||||||
it('should dispatch a new SaveSubmissionFormAction', () => {
|
service.dispatchSave(submissionId, true);
|
||||||
service.dispatchManualSave(submissionId,);
|
|
||||||
const expected = new SaveSubmissionFormAction(submissionId, true);
|
const expected = new SaveSubmissionFormAction(submissionId, true);
|
||||||
|
|
||||||
expect((service as any).store.dispatch).toHaveBeenCalledWith(expected);
|
expect((service as any).store.dispatch).toHaveBeenCalledWith(expected);
|
||||||
|
@@ -209,26 +209,14 @@ export class SubmissionService {
|
|||||||
*
|
*
|
||||||
* @param submissionId
|
* @param submissionId
|
||||||
* The submission id
|
* The submission id
|
||||||
|
* @param manual
|
||||||
|
* whether is a manual save, default false
|
||||||
*/
|
*/
|
||||||
dispatchManualSave(submissionId) {
|
dispatchSave(submissionId, manual?: boolean) {
|
||||||
this.getSubmissionSaveProcessingStatus(submissionId).pipe(
|
this.getSubmissionSaveProcessingStatus(submissionId).pipe(
|
||||||
find((isPending: boolean) => !isPending)
|
find((isPending: boolean) => !isPending)
|
||||||
).subscribe(() => {
|
).subscribe(() => {
|
||||||
this.store.dispatch(new SaveSubmissionFormAction(submissionId, true));
|
this.store.dispatch(new SaveSubmissionFormAction(submissionId, manual));
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Dispatch a new [SaveSubmissionFormAction]
|
|
||||||
*
|
|
||||||
* @param submissionId
|
|
||||||
* The submission id
|
|
||||||
*/
|
|
||||||
dispatchSave(submissionId) {
|
|
||||||
this.getSubmissionSaveProcessingStatus(submissionId).pipe(
|
|
||||||
find((isPending: boolean) => !isPending)
|
|
||||||
).subscribe(() => {
|
|
||||||
this.store.dispatch(new SaveSubmissionFormAction(submissionId));
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user