'use strict'; function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } /** * Licensed Materials - Property of IBM * IBM Cognos Products: Dashboard (C) Copyright IBM Corp. 2020 * US Government Users Restricted Rights - Use, duplication or disclosure restricted by GSA ADP Schedule Contract with IBM Corp. */ define(['./content/ContentModel'], function (ContentModel) { // Utility class for models var ModelUtils = function () { function ModelUtils() { _classCallCheck(this, ModelUtils); } /** * Adds a contentModel to the provided model. * Transfers from model properties to content model specification if they exist or else uses content model specification. * @public * @static * @function ModelUtils#initializeContentModel * @param {Object} model A model object that can contain a ContentModel (ex. LayoutModel, BoardModel) * @param {String[]} [excludedProperties=[]] An array of properties to exclude in the property transfer */ ModelUtils.initializeContentModel = function initializeContentModel(model) { var excludedProperties = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : []; var contentModelSpec = model.content || {}; if (model.hasOwnProperty('properties')) { contentModelSpec.properties = {}; Object.keys(model.properties).forEach(function (property) { if (!(excludedProperties.indexOf(property) !== -1)) { contentModelSpec.properties[property] = model.properties[property]; delete model.properties[property]; } }); if (Object.keys(model.properties).length === 0) { delete model.properties; } } if (model.hasOwnProperty('features')) { contentModelSpec.features = model.features; delete model.features; } delete model.content; return new ContentModel(contentModelSpec); }; /** * Merges properties from the `content` in the spec to the root of spec * Removes content from spec if empty after merge. * Object properties to be transferred from content * - properties * - features * @public * @static * @function ModelUtils#pullPropertiesFromContentModelSpec * @param {Object} spec A json spec of a model (LayoutModel/BoardModel) */ ModelUtils.pullPropertiesFromContentModelSpec = function pullPropertiesFromContentModelSpec(spec) { var PropertiesToInclude = ['properties', 'features']; var contentModelSpec = spec.content; if (contentModelSpec) { PropertiesToInclude.forEach(function (prop) { if (contentModelSpec.hasOwnProperty(prop)) { if (contentModelSpec[prop] && Object.keys(contentModelSpec[prop]).length) { spec[prop] = Object.assign({}, spec[prop], contentModelSpec[prop]); } delete contentModelSpec[prop]; } }); if (Object.keys(contentModelSpec).length === 0) { delete spec.content; } } }; return ModelUtils; }(); return ModelUtils; }); //# sourceMappingURL=ModelUtils.js.map