123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365 |
- 'use strict';
- function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
- function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
- function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
- /**
- * Licensed Materials - Property of IBM
- * IBM Cognos Products: BI Cloud (C) Copyright IBM Corp. 2018, 2020
- * US Government Users Restricted Rights - Use, duplication or disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
- */
- define(['jquery', '../lib/@waca/dashboard-common/dist/core/APIFactory', './CanvasAPISpec', '../api/CanvasAPI', 'underscore', '../dashboard/util/PropertyLayoutHelper'], function ($, APIFactory, CanvasAPISpec, CanvasAPI, _, PropertyLayoutHelper) {
- var DEFAULT_LAYOUT_TYPES = ['widget', 'group'];
- var CanvasAPIImpl = function (_CanvasAPISpec) {
- _inherits(CanvasAPIImpl, _CanvasAPISpec);
- function CanvasAPIImpl(options) {
- _classCallCheck(this, CanvasAPIImpl);
- var _this = _possibleConstructorReturn(this, _CanvasAPISpec.call(this, options));
- _this.boardModel = options.boardModel;
- _this.extensions = options.extensions;
- _this.contentFeatureCollection = options.contentFeatureCollection;
- // TODO - add inline feature here
- _this.dashboardFeatures = options.dashboardFeatures;
- _this.logger = _this.dashboardFeatures.getFeature('Logger');
- _this.contentFactory = _this.dashboardFeatures.getFeature('ContentFactory');
- _this.canvasContent = _this.contentFactory.createContent({
- dashboardFeatures: _this.dashboardFeatures,
- contentFeatureCollection: _this.contentFeatureCollection,
- boardModel: _this.boardModel,
- layoutModel: _this.boardModel.layout,
- canvas: _this,
- profile: options.profile,
- type: _this.boardModel.layout.type
- });
- _this.copyCallback = options.copyCallback;
- _this.pasteCallback = options.pasteCallback;
- _this._dashboardContent = options.dashboardContent;
- APIFactory.setParentChildRelation(_this, _this.canvasContent);
- return _this;
- }
- CanvasAPIImpl.prototype.getRootContentInstance = function getRootContentInstance() {
- return this.canvasContent;
- };
- /**
- * @param {*} contentSpecType the type of content.spec
- * @return {booelan} if the spec is a layoutSpec(e.g. tab, group, ...)
- */
- CanvasAPIImpl.prototype.isLayoutType = function isLayoutType(contentSpecType) {
- var layoutViewExtentions = this.extensions.getLayoutViewExtensions();
- var authoringViewsLayoutTypeList = Object.keys(layoutViewExtentions.authoringViews);
- var consumeViewsLayoutTypeList = Object.keys(layoutViewExtentions.consumeViews);
- return authoringViewsLayoutTypeList.indexOf(contentSpecType) !== -1 || consumeViewsLayoutTypeList.indexOf(contentSpecType) !== -1;
- };
- CanvasAPIImpl.prototype.getAPI = function getAPI() {
- if (!this.api) {
- this.api = APIFactory.createAPI(this, [CanvasAPI]);
- }
- return this.api;
- };
- CanvasAPIImpl.prototype.initialize = function initialize() {
- var _this2 = this;
- return this.canvasContent.initialize().then(function () {
- _this2._contentTargets = [_this2._dashboardContent, _this2.canvasContent];
- });
- };
- CanvasAPIImpl.prototype.destroy = function destroy() {
- this.boardModel = null;
- this.canvasContent.destroy();
- this.canvasContent = null;
- this.dashboardFeatures = null;
- this.api = null;
- this._dashboardContent = null;
- };
- CanvasAPIImpl.prototype.getContentActionList = function getContentActionList(idList) {
- if (idList.length) {
- return this.dashboardFeatures.getFeature('ContentActions').getContentActionList(idList);
- }
- return [];
- };
- CanvasAPIImpl.prototype.copy = function copy() {
- // TODO - clean this up
- return this.copyCallback.apply(null, arguments);
- };
- CanvasAPIImpl.prototype.paste = function paste() {
- // TODO - clean this up
- return this.pasteCallback.apply(null, arguments);
- };
- CanvasAPIImpl.prototype.addContent = function addContent(options, transactionToken) {
- var container = this.getContentInstance(options.containerId);
- return container.getAPI().addContent(options, transactionToken);
- };
- CanvasAPIImpl.prototype.moveContent = function moveContent(containerId, contentIdList, transactionToken, insertBeforeMap) {
- var container = this.getContentInstance(containerId);
- return container.moveContent(containerId, contentIdList, transactionToken, insertBeforeMap);
- };
- CanvasAPIImpl.prototype.removeContent = function removeContent(id, transactionToken) {
- var content = this.getContent(id);
- if (content) {
- var container = content.getContainer();
- if (container) {
- container.removeContent(id, transactionToken);
- }
- }
- };
- CanvasAPIImpl.prototype.getContentInstance = function getContentInstance(contentId) {
- var content = void 0;
- if (!contentId || contentId === this.boardModel.layout.id) {
- content = this.canvasContent;
- } else {
- content = this.canvasContent.getContentInstance(contentId);
- }
- return content;
- };
- CanvasAPIImpl.prototype.registerContentFeatures = function registerContentFeatures(contentId, features) {
- var content = this.getContentInstance(contentId);
- if (content) {
- return content.registerFeatures(features);
- }
- return Promise.reject('The content with id "' + contentId + '" does not exist.');
- };
- CanvasAPIImpl.prototype.registerContentFeature = function registerContentFeature(contentId, featureId, featureInstance, featureSpec, skipInitialization) {
- var content = this.getContentInstance(contentId);
- if (content) {
- return content.registerFeature(featureId, featureInstance, featureSpec, skipInitialization);
- }
- return Promise.reject('The content with id "' + contentId + '" does not exist.');
- };
- CanvasAPIImpl.prototype.getContentFeature = function getContentFeature(contentId, featureId) {
- if (contentId === this.boardModel.layout.id) {
- return this.canvasContent.getFeature(featureId);
- }
- var content = this.canvasContent.getContentInstance(contentId);
- if (content) {
- return content.getFeature(featureId);
- }
- };
- CanvasAPIImpl.prototype.getContent = function getContent(id) {
- // Root layout
- if (!id || id === this.boardModel.layout.id) {
- return this.canvasContent.getAPI();
- }
- return this.canvasContent.getContent(id);
- };
- CanvasAPIImpl.prototype.findContent = function findContent(selector) {
- // if the type matches the top layout then return it..
- if (selector && selector.type === this.boardModel.layout.type) {
- return [this.canvasContent.getAPI()];
- }
- return this.canvasContent.findContent(selector);
- };
- CanvasAPIImpl.prototype.selectContent = function selectContent() {
- var _this3 = this;
- var idList = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
- idList.forEach(function (id) {
- var model = _this3.boardModel.layout.findModel(id);
- if (model) {
- var parent = model.getParent();
- if (parent) {
- parent.select(model.id);
- }
- }
- });
- };
- CanvasAPIImpl.prototype.deselectContent = function deselectContent() {
- var _this4 = this;
- var idList = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
- idList.forEach(function (id) {
- var model = _this4.boardModel.layout.findModel(id);
- if (model) {
- var parent = model.getParent();
- if (parent) {
- parent.deselect(model.id);
- }
- }
- });
- };
- CanvasAPIImpl.prototype.getSelectedContentList = function getSelectedContentList() {
- var _this5 = this;
- var selector = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
- var selectContentList = [];
- if (this.boardModel) {
- var contentRegistry = this.dashboardFeatures.getFeature('ContentTypeRegistry');
- var types = selector.type ? [selector.type] : DEFAULT_LAYOUT_TYPES;
- var selectedChildLayouts = this.boardModel.layout.getSelectedChildLayouts();
- var selectedFilteredChildLayouts = selectedChildLayouts.filter(function (layout) {
- var content = _this5.getContent(layout.id);
- var result = false;
- if (contentRegistry) {
- result = contentRegistry.isTypeRegistered(layout.type);
- }
- if (!result) {
- result = types.indexOf(layout.type) !== -1 || types.indexOf(content.getType()) !== -1;
- }
- return result;
- });
- var parents = _.filter(selectedFilteredChildLayouts, function (layout) {
- return _.isArray(layout.items);
- });
- var selectedLayouts = _.filter(selectedFilteredChildLayouts, function (layout) {
- // remove layouts that are part of selected parents
- return !_.find(parents, function (parent) {
- return parent.findChildItem(parent.items, layout.id);
- });
- });
- selectContentList = _.map(selectedLayouts, function (layout) {
- return _this5.getContent(layout.id);
- });
- }
- return selectContentList;
- };
- CanvasAPIImpl.prototype.getPropertyNameList = function getPropertyNameList() {
- return Object.keys(this._getPropertyMap());
- };
- CanvasAPIImpl.prototype.setPropertyValue = function setPropertyValue(propertyName, propertyValue, transactionToken) {
- var property = this._getProperty(propertyName);
- if (property.validatePropertyValue) {
- var validInfo = property.validatePropertyValue(propertyValue) || {};
- if (!validInfo.isValid) {
- this.logger.error(validInfo.message, propertyName, propertyValue);
- return;
- }
- }
- property.setPropertyValue(propertyValue, transactionToken);
- };
- CanvasAPIImpl.prototype.getPropertyValue = function getPropertyValue(propertyName) {
- var property = this._getProperty(propertyName);
- return property.getPropertyValue();
- };
- /**
- * Returns fully expanded layout specification. Called when rendering the property panel
- */
- CanvasAPIImpl.prototype.getPropertyLayoutList = function getPropertyLayoutList() {
- var allLayouts = {};
- //_.each(this._contentTargets, (target) => {
- for (var i = 0; i < this._contentTargets.length; i++) {
- var target = this._contentTargets[i];
- var targetProperties = target.getFeature('Properties');
- var layouts = targetProperties.getPropertyLayoutList();
- //_.each(layouts, (layout) => {
- for (var j = 0; j < layouts.length; j++) {
- var layout = layouts[j];
- if (allLayouts[layout.id]) {
- $.extend(true, allLayouts[layout.id], layout);
- } else {
- allLayouts[layout.id] = layout;
- }
- }
- }
- return PropertyLayoutHelper.getExpandedLayoutList(_.values(allLayouts), this._getPropertyList());
- };
- CanvasAPIImpl.prototype._getPropertyList = function _getPropertyList() {
- this._initProperties();
- return this._propertiesList;
- };
- CanvasAPIImpl.prototype._getPropertyMap = function _getPropertyMap() {
- this._initProperties();
- return this._propertiesMap;
- };
- /**
- * Get the list of properties and caches them
- */
- CanvasAPIImpl.prototype._initProperties = function _initProperties() {
- this._propertiesMap = {};
- this._contentTargets = this._contentTargets || [];
- for (var i = 0; i < this._contentTargets.length; i++) {
- var target = this._contentTargets[i];
- var properties = target.getPropertyList() || [];
- for (var j = 0; j < properties.length; j++) {
- var property = properties[j];
- if (this._propertiesMap[property.id]) {
- $.extend(true, this._propertiesMap[property.id], property);
- } else {
- this._propertiesMap[property.id] = property;
- }
- }
- }
- this._propertiesList = _.values(this._propertiesMap);
- };
- // TODO : we should define a way to get property using cache, currently,
- // every time we call _getProperty, it will init a new _propertiesMap again
- // it does not really using cache
- CanvasAPIImpl.prototype._getProperty = function _getProperty(propertyName) {
- var property = this._getPropertyMap()[propertyName];
- if (!property) {
- throw new Error('Property ' + propertyName + ' does not exist.');
- }
- return property;
- };
- CanvasAPIImpl.prototype.whenContentReady = function whenContentReady(contentId) {
- // find content and call intialize
- var contentImpl = this.getContentInstance(contentId);
- return contentImpl ? contentImpl.initialize() : Promise.reject('Could not find content with id ' + contentId);
- };
- return CanvasAPIImpl;
- }(CanvasAPISpec);
- return CanvasAPIImpl;
- });
- //# sourceMappingURL=Canvas.js.map
|