mirror of
https://github.com/DSpace/dspace-angular.git
synced 2025-10-07 18:14:17 +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 { 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 { DYNAMIC_FORM_CONTROL_TYPE_TAG } from './ds-dynamic-form-ui/models/tag/dynamic-tag.model';
|
||||
import { RowParser } from './parsers/row-parser';
|
||||
@@ -56,9 +56,7 @@ export class FormBuilderService extends DynamicFormService {
|
||||
}
|
||||
|
||||
if (this.isConcatGroup(controlModel)) {
|
||||
const concatGroupId = controlModel.id.replace(CONCAT_GROUP_SUFFIX, '');
|
||||
// if (concatGroupId === findId) {
|
||||
if (concatGroupId.includes(findId)) {
|
||||
if (controlModel.id.match(new RegExp(findId + CONCAT_GROUP_SUFFIX + `_\\d+$`))) {
|
||||
result = (controlModel as DynamicConcatModel).group[0];
|
||||
break;
|
||||
}
|
||||
|
@@ -18,7 +18,7 @@
|
||||
<button type="button" class="btn btn-secondary"
|
||||
[disabled]="isItemReadOnly(context, index)"
|
||||
(click)="insertItem($event, group.context, group.index)">
|
||||
<span aria-label="Add">Add</span>
|
||||
<span aria-label="Add">{{'form.add' | translate}}</span>
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
|
@@ -9,7 +9,6 @@ export class SubmissionServiceStub {
|
||||
dispatchDeposit = jasmine.createSpy('dispatchDeposit');
|
||||
dispatchDiscard = jasmine.createSpy('dispatchDiscard');
|
||||
dispatchSave = jasmine.createSpy('dispatchSave');
|
||||
dispatchManualSave = jasmine.createSpy('dispatchManualSave');
|
||||
dispatchSaveForLater = jasmine.createSpy('dispatchSaveForLater');
|
||||
dispatchSaveSection = jasmine.createSpy('dispatchSaveSection');
|
||||
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);
|
||||
fixture.detectChanges();
|
||||
|
||||
expect(submissionServiceStub.dispatchManualSave).toHaveBeenCalledWith(submissionId);
|
||||
expect(submissionServiceStub.dispatchSave).toHaveBeenCalledWith(submissionId, true);
|
||||
});
|
||||
|
||||
it('should call dispatchSaveForLater on save for later', () => {
|
||||
|
@@ -80,7 +80,7 @@ export class SubmissionFormFooterComponent implements OnChanges {
|
||||
* Dispatch a submission save action
|
||||
*/
|
||||
save(event) {
|
||||
this.submissionService.dispatchManualSave(this.submissionId);
|
||||
this.submissionService.dispatchSave(this.submissionId, true);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@@ -3,7 +3,6 @@
|
||||
[formId]="formId"
|
||||
[formModel]="formModel"
|
||||
[displaySubmit]="false"
|
||||
(dfBlur)="onBlur($event)"
|
||||
(dfChange)="onChange($event)"
|
||||
(dfFocus)="onFocus($event)"
|
||||
(remove)="onRemove($event)"
|
||||
|
@@ -131,12 +131,6 @@ export class SubmissionSectionformComponent extends SectionModelComponent {
|
||||
*/
|
||||
@ViewChild('formRef', {static: false}) private formRef: FormComponent;
|
||||
|
||||
/**
|
||||
* Keep track whether the section is focused or not.
|
||||
* @protected
|
||||
*/
|
||||
protected isFocused = false;
|
||||
|
||||
/**
|
||||
* Initialize instance variables
|
||||
*
|
||||
@@ -265,6 +259,7 @@ export class SubmissionSectionformComponent extends SectionModelComponent {
|
||||
Object.keys(diffObj)
|
||||
.forEach((key) => {
|
||||
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) {
|
||||
diffResult.push(value);
|
||||
}
|
||||
@@ -407,7 +402,6 @@ export class SubmissionSectionformComponent extends SectionModelComponent {
|
||||
* the [[DynamicFormControlEvent]] emitted
|
||||
*/
|
||||
onFocus(event: DynamicFormControlEvent): void {
|
||||
this.isFocused = true;
|
||||
const value = this.formOperationsService.getFieldValueFromChangeEvent(event);
|
||||
const path = this.formBuilderService.getPath(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.
|
||||
* Dispatch form operations based on changes.
|
||||
|
@@ -487,16 +487,14 @@ describe('SubmissionService test suite', () => {
|
||||
|
||||
describe('dispatchSave', () => {
|
||||
it('should dispatch a new SaveSubmissionFormAction', () => {
|
||||
service.dispatchSave(submissionId,);
|
||||
service.dispatchSave(submissionId);
|
||||
const expected = new SaveSubmissionFormAction(submissionId);
|
||||
|
||||
expect((service as any).store.dispatch).toHaveBeenCalledWith(expected);
|
||||
});
|
||||
});
|
||||
|
||||
describe('dispatchManualSave', () => {
|
||||
it('should dispatch a new SaveSubmissionFormAction', () => {
|
||||
service.dispatchManualSave(submissionId,);
|
||||
it('should dispatch a new SaveSubmissionFormAction with manual flag', () => {
|
||||
service.dispatchSave(submissionId, true);
|
||||
const expected = new SaveSubmissionFormAction(submissionId, true);
|
||||
|
||||
expect((service as any).store.dispatch).toHaveBeenCalledWith(expected);
|
||||
|
@@ -209,26 +209,14 @@ export class SubmissionService {
|
||||
*
|
||||
* @param submissionId
|
||||
* The submission id
|
||||
* @param manual
|
||||
* whether is a manual save, default false
|
||||
*/
|
||||
dispatchManualSave(submissionId) {
|
||||
dispatchSave(submissionId, manual?: boolean) {
|
||||
this.getSubmissionSaveProcessingStatus(submissionId).pipe(
|
||||
find((isPending: boolean) => !isPending)
|
||||
).subscribe(() => {
|
||||
this.store.dispatch(new SaveSubmissionFormAction(submissionId, true));
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* 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));
|
||||
this.store.dispatch(new SaveSubmissionFormAction(submissionId, manual));
|
||||
})
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user