X-Git-Url: https://osm.etsi.org/gitweb/?a=blobdiff_plain;f=skyquake%2Fplugins%2Fcomposer%2Fsrc%2Fsrc%2Flibraries%2Fmodel%2FDescriptorModel.js;h=3db2a0dc3a77668380743b955b695d6a2d5f2683;hb=refs%2Ftags%2Fv3.0.2;hp=02bbfcd3297f5399766b9fb9009b1400b878f5b4;hpb=e29efc315df33d546237e270470916e26df391d6;p=osm%2FUI.git diff --git a/skyquake/plugins/composer/src/src/libraries/model/DescriptorModel.js b/skyquake/plugins/composer/src/src/libraries/model/DescriptorModel.js index 02bbfcd32..3db2a0dc3 100644 --- a/skyquake/plugins/composer/src/src/libraries/model/DescriptorModel.js +++ b/skyquake/plugins/composer/src/src/libraries/model/DescriptorModel.js @@ -1,6 +1,6 @@ /* - * + * * Copyright 2016 RIFT.IO Inc * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -20,7 +20,9 @@ * Created by onvelocity on 8/23/15. */ -import _ from 'lodash' +import _isArray from 'lodash/isArray' +import _set from 'lodash/set' +import _get from 'lodash/get' import guid from '../guid' import Position from '../graph/Position' import IconFactory from './IconFactory' @@ -34,7 +36,7 @@ import DescriptorModelMetaFactory from './DescriptorModelMetaFactory' */ export default class DescriptorModel { - constructor(model = {uiState: {}}, parent = null) { + constructor(model = {uiState: {}}, parent = null, readonly = false) { // when our instance has no more strong references // then our properties will get garbage collected. this._props_ = new WeakMap(); @@ -49,6 +51,7 @@ export default class DescriptorModel { if (parent instanceof DescriptorModel) { parent.addChild(this); } + this.isReadOnly = readonly; } get fieldNames() { @@ -182,7 +185,10 @@ export default class DescriptorModel { throw new ReferenceError('child must be an instance of DescriptorModel class'); } if (this.findChildByUid(child.uid)) { - throw new ReferenceError('child already exists'); + console.warn('Child already exists'); + // NOTE: Commented out this line because it was causing issues with Internal VLD. + // TODO: Check why it caused issues with Internal VLD + // throw new ReferenceError('child already exists'); } if (child.parent instanceof DescriptorModel) { throw new ReferenceError('child already has a parent'); @@ -276,7 +282,7 @@ export default class DescriptorModel { updateModelList(modelFieldName, modelFieldValue, descriptorClass = DescriptorModel, newItemAddedSuccessCallback = () => {}) { // value can be Array of (DescriptorModel | json model), DescriptorModel, or json model - if (_.isArray(modelFieldValue)) { + if (_isArray(modelFieldValue)) { this.model[modelFieldName] = modelFieldValue.map(d => d instanceof descriptorClass ? d.model : d); return true; } @@ -306,4 +312,12 @@ export default class DescriptorModel { return length !== this[propertyName].length; } + setUiState(setting, path, value){ + _set(this.uiState, [setting].concat(path), value); + } + + getUiState(setting, path, defaultValue){ + return _get(this.uiState, [setting].concat(path), defaultValue); + } + }