Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
import { JsonPatchOperationPathObject } from './json-patch-operation-path-combiner';
import { Injectable } from '@angular/core';
import { hasNoValue, hasValue, isEmpty, isNotEmpty } from '../../../shared/empty.util';
import { dateToISOFormat } from '../../../shared/date.util';
import { dateToISOFormat, dateToString, isNgbDateStruct } from '../../../shared/date.util';
import { VocabularyEntry } from '../../submission/vocabularies/models/vocabulary-entry.model';
import { FormFieldMetadataValueObject } from '../../../shared/form/builder/models/form-field-metadata-value.model';
import { FormFieldLanguageValueObject } from '../../../shared/form/builder/models/form-field-language-value.model';
Expand Down Expand Up @@ -136,6 +136,8 @@ export class JsonPatchOperationsBuilder {
operationValue = new FormFieldMetadataValueObject(value.value, value.language);
} else if (value.hasOwnProperty('authority')) {
operationValue = new FormFieldMetadataValueObject(value.value, value.language, value.authority);
} else if (isNgbDateStruct(value)) {
operationValue = new FormFieldMetadataValueObject(dateToString(value));
} else if (value.hasOwnProperty('value')) {
operationValue = new FormFieldMetadataValueObject(value.value);
} else {
Expand Down
9 changes: 5 additions & 4 deletions src/app/shared/date.util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { NgbDateStruct } from '@ng-bootstrap/ng-bootstrap';
import { isObject } from 'lodash';
import * as moment from 'moment';

import { isNull } from './empty.util';
import { isNull, isUndefined } from './empty.util';

/**
* Returns true if the passed value is a NgbDateStruct.
Expand All @@ -27,8 +27,9 @@ export function isNgbDateStruct(value: object): boolean {
* @return string
* the formatted date
*/
export function dateToISOFormat(date: Date | NgbDateStruct): string {
const dateObj: Date = (date instanceof Date) ? date : ngbDateStructToDate(date);
export function dateToISOFormat(date: Date | NgbDateStruct | string): string {
const dateObj: Date = (date instanceof Date) ? date :
((typeof date === 'string') ? ngbDateStructToDate(stringToNgbDateStruct(date)) : ngbDateStructToDate(date));

let year = dateObj.getFullYear().toString();
let month = (dateObj.getMonth() + 1).toString();
Expand Down Expand Up @@ -80,7 +81,7 @@ export function stringToNgbDateStruct(date: string): NgbDateStruct {
* the NgbDateStruct object
*/
export function dateToNgbDateStruct(date?: Date): NgbDateStruct {
if (isNull(date)) {
if (isNull(date) || isUndefined(date)) {
date = new Date();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
[startDate]="model.focusedDate"
(blur)="onBlur($event)"
(dateSelect)="onChange($event)"
(change)="onChange($event)"
(focus)="onFocus($event)">

<div class="input-group-append">
Expand Down
9 changes: 8 additions & 1 deletion src/app/shared/form/form.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -309,9 +309,16 @@ export class FormComponent implements OnDestroy, OnInit {
removeItem($event, arrayContext: DynamicFormArrayModel, index: number): void {
const formArrayControl = this.formGroup.get(this.formBuilderService.getPath(arrayContext)) as FormArray;
const event = this.getEvent($event, arrayContext, index, 'remove');
if (this.formBuilderService.isQualdropGroup(event.model as DynamicFormControlModel)) {
// In case of qualdrop value remove event must be dispatched before removing the control from array
this.removeArrayItem.emit(event);
}
this.formBuilderService.removeFormArrayGroup(index, formArrayControl, arrayContext);
this.formService.changeForm(this.formId, this.formModel);
this.removeArrayItem.emit(event);
if (!this.formBuilderService.isQualdropGroup(event.model as DynamicFormControlModel)) {
// dispatch remove event for any field type except for qualdrop value
this.removeArrayItem.emit(event);
}
}

insertItem($event, arrayContext: DynamicFormArrayModel, index: number): void {
Expand Down
154 changes: 79 additions & 75 deletions src/app/shared/mocks/submission.mock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1519,83 +1519,87 @@ export const mockFileFormData = {
},
accessConditions: [
{
name: [
{
value: 'openaccess',
language: null,
authority: null,
display: 'openaccess',
confidence: -1,
place: 0,
otherInformation: null
}
],
}
,
accessConditionGroup: {
name: [
{
value: 'openaccess',
language: null,
authority: null,
display: 'openaccess',
confidence: -1,
place: 0,
otherInformation: null
}
],
},
},
{
name: [
{
value: 'lease',
language: null,
authority: null,
display: 'lease',
confidence: -1,
place: 0,
otherInformation: null
}
],
endDate: [
{
value: {
year: 2019,
month: 1,
day: 16
},
language: null,
authority: null,
display: {
year: 2019,
month: 1,
day: 16
},
confidence: -1,
place: 0,
otherInformation: null
}
],
}
,
accessConditionGroup:{
name: [
{
value: 'lease',
language: null,
authority: null,
display: 'lease',
confidence: -1,
place: 0,
otherInformation: null
}
],
endDate: [
{
value: {
year: 2019,
month: 1,
day: 16
},
language: null,
authority: null,
display: {
year: 2019,
month: 1,
day: 16
},
confidence: -1,
place: 0,
otherInformation: null
}
],
}
},
{
name: [
{
value: 'embargo',
language: null,
authority: null,
display: 'lease',
confidence: -1,
place: 0,
otherInformation: null
}
],
startDate: [
{
value: {
year: 2019,
month: 1,
day: 16
},
language: null,
authority: null,
display: {
year: 2019,
month: 1,
day: 16
},
confidence: -1,
place: 0,
otherInformation: null
}
],
accessConditionGroup: {
name: [
{
value: 'embargo',
language: null,
authority: null,
display: 'lease',
confidence: -1,
place: 0,
otherInformation: null
}
],
startDate: [
{
value: {
year: 2019,
month: 1,
day: 16
},
language: null,
authority: null,
display: {
year: 2019,
month: 1,
day: 16
},
confidence: -1,
place: 0,
otherInformation: null
}
],
}
}
]
};
2 changes: 1 addition & 1 deletion src/app/submission/form/submission-form.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ export class SubmissionFormComponent implements OnChanges, OnDestroy {
* Initialize all instance variables and retrieve form configuration
*/
ngOnChanges(changes: SimpleChanges) {
if (this.collectionId && this.submissionId) {
if ((changes.collectionId && this.collectionId) && (changes.submissionId && this.submissionId)) {
this.isActive = true;

// retrieve submission's section list
Expand Down
Loading