diff --git a/src/app/shared/form/builder/ds-dynamic-form-ui/models/dynamic-group/dynamic-group.components.ts b/src/app/shared/form/builder/ds-dynamic-form-ui/models/dynamic-group/dynamic-group.components.ts index 6662f7e24b..7ad62ce479 100644 --- a/src/app/shared/form/builder/ds-dynamic-form-ui/models/dynamic-group/dynamic-group.components.ts +++ b/src/app/shared/form/builder/ds-dynamic-form-ui/models/dynamic-group/dynamic-group.components.ts @@ -81,7 +81,7 @@ export class DsDynamicGroupComponent implements OnDestroy, OnInit { this.formId = this.formService.getUniqueId(this.model.id); this.formModel = this.formBuilderService.modelFromConfiguration(config, this.model.scopeUUID, {}); - this.chips = new Chips(this.model.value, 'value', this.model.mandatoryField, this.EnvConfig.submission.metadata.icons); + this.chips = new Chips(this.model.value, 'value', this.model.mandatoryField); this.subs.push( this.chips.chipsItems .subscribe((subItems: any[]) => { diff --git a/src/app/shared/form/builder/models/form-field-metadata-value.model.ts b/src/app/shared/form/builder/models/form-field-metadata-value.model.ts index ebcdc9264c..542e5d029e 100644 --- a/src/app/shared/form/builder/models/form-field-metadata-value.model.ts +++ b/src/app/shared/form/builder/models/form-field-metadata-value.model.ts @@ -1,4 +1,4 @@ -import { isNotEmpty } from '../../../empty.util'; +import { isNotEmpty, isNotNull } from '../../../empty.util'; export class FormFieldMetadataValueObject { metadata?: string; diff --git a/src/app/shared/notifications/models/notification-type.ts b/src/app/shared/notifications/models/notification-type.ts index 8ef5d790b5..935129943e 100644 --- a/src/app/shared/notifications/models/notification-type.ts +++ b/src/app/shared/notifications/models/notification-type.ts @@ -2,6 +2,5 @@ export enum NotificationType { Success = 'alert-success', Error = 'alert-danger', Info = 'alert-info', - Warning = 'alert-warning', - // Bare = 'bare' + Warning = 'alert-warning' } diff --git a/src/app/shared/object.util.ts b/src/app/shared/object.util.ts new file mode 100644 index 0000000000..50680d6d32 --- /dev/null +++ b/src/app/shared/object.util.ts @@ -0,0 +1,52 @@ +import { isNotEmpty } from './empty.util'; +import { isEqual, isObject, transform } from 'lodash'; + +/** + * Returns passed object without specified property + */ +export function deleteProperty(object, key): object { + const {[key]: deletedKey, ...otherKeys} = object; + return otherKeys; +} + +/** + * Returns true if the passed value is null or undefined. + * hasNoValue(); // true + * hasNoValue(null); // true + * hasNoValue(undefined); // true + * hasNoValue(''); // false + * hasNoValue({}); // false + * hasNoValue([]); // false + * hasNoValue(function() {}); // false + */ +export function isObjectEmpty(obj: any): boolean { + const objectType = typeof obj; + if (objectType === 'object') { + if (Object.keys(obj).length === 0) { + return true; + } else { + let result = true; + for (const key in obj) { + if (isNotEmpty(obj[key])) { + result = false; + break; + } + } + return result; + } + } +} + +export function difference(object, base) { + const changes = (o, b) => { + return transform(o, (result, value, key) => { + if (!isEqual(value, b[key]) && isNotEmpty(value)) { + const resultValue = (isObject(value) && isObject(b[key])) ? changes(value, b[key]) : value; + if (!isObjectEmpty(resultValue)) { + result[key] = resultValue; + } + } + }); + }; + return changes(object, base); +}