123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170 |
- '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 Business Analytics (C) Copyright IBM Corp. 2019
- * US Government Users Restricted Rights - Use, duplication or disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
- */
- /**
- * @class UnionAPI
- * @hideconstructor
- * @classdesc Provides access to the the union object associated to this dataitem.
- */
- define(['underscore', '../../lib/@waca/dashboard-common/dist/core/APIFactory', '../../lib/@waca/dashboard-common/dist/core/UniqueHashIdBuilder', './UnionAPISpec', '../../api/UnionAPI'], function (_, APIFactory, UniqueHashIdBuilder, UnionAPISpec, UnionAPI) {
- return function (_UnionAPISpec) {
- _inherits(Union, _UnionAPISpec);
- function Union(unionModel, UnionDataItem, dataItem, dataSourceAPI, transaction, locale) {
- _classCallCheck(this, Union);
- var _this = _possibleConstructorReturn(this, _UnionAPISpec.call(this));
- _this.unionModel = unionModel;
- _this.dataItem = dataItem;
- _this._UnionDataItem = UnionDataItem;
- _this.dataSourceAPI = dataSourceAPI;
- _this.transaction = transaction;
- _this.locale = locale;
- _this._currentDataItemIdList = [];
- _this.dataItemImplList = [];
- _this._initalizeDataItems();
- return _this;
- }
- Union.prototype.destroy = function destroy() {
- this.unionModel = null;
- this.dataItem = null;
- this._UnionDataItem = null;
- this.dataSourceAPI = null;
- this.transaction = null;
- this.locale = null;
- this.dataItemImplList.forEach(function (dataItem) {
- return dataItem.destroy();
- });
- this.dataItemImplList = [];
- this.dataItemAPIListCache = null;
- this._currentDataItemIdList = null;
- };
- Union.prototype._initalizeDataItems = function _initalizeDataItems() {
- var _this2 = this;
- if (this.unionModel.dataItems) {
- this.unionModel.dataItems.forEach(function (model) {
- _this2._createDataItemImpl(model);
- });
- }
- };
- Union.prototype._createDataItemImpl = function _createDataItemImpl(model) {
- if (!model.id) {
- model.id = UniqueHashIdBuilder.createUniqueHashId(model.itemId, this._currentDataItemIdList);
- }
- this._currentDataItemIdList.push(model.id);
- this.dataItemAPIListCache = null;
- var dataItem = new this._UnionDataItem(model, this.dataSourceAPI, this.transaction, this.locale);
- APIFactory.setParentChildRelation(this, dataItem);
- this.dataItemImplList.push(dataItem);
- return dataItem;
- };
- Union.prototype.getAPI = function getAPI() {
- return APIFactory.createAPI(this, [UnionAPI]);
- };
- Union.prototype.getDataItemList = function getDataItemList() {
- if (!this.dataItemAPIListCache) {
- this.dataItemAPIListCache = this.dataItemImplList.map(function (impl) {
- return impl.getAPI();
- });
- }
- return this.dataItemAPIListCache;
- };
- Union.prototype.getDataItemImpl = function getDataItemImpl(id) {
- return this.dataItemImplList.find(function (dataItem) {
- return dataItem.getId() === id;
- });
- };
- Union.prototype.getDataItem = function getDataItem(id) {
- return this.getDataItemList().find(function (dataItem) {
- return dataItem.getId() === id;
- });
- };
- Union.prototype._getItemId = function _getItemId() {
- return this.dataItem.getColumnId();
- };
- Union.prototype.addDataItem = function addDataItem(dataItem) {
- if (!this.unionModel.dataItems) {
- this.unionModel.dataItems = [];
- }
- var dataItemCollection = this.unionModel.dataItems;
- var model = function (_ref) {
- var id = _ref.id,
- itemId = _ref.itemId,
- columnId = _ref.columnId,
- itemLabel = _ref.itemLabel,
- navigationPathId = _ref.navigationPathId;
- return { id: id, itemId: itemId, columnId: columnId, itemLabel: itemLabel, navigationPathId: navigationPathId };
- }(dataItem);
- if (model.columnId) {
- model.itemId = model.columnId;
- delete model.columnId;
- }
- dataItemCollection.push(model);
- return this._createDataItemImpl(model).getAPI();
- };
- Union.prototype.removeDataItem = function removeDataItem(dataItemId) {
- if (this.unionModel.dataItems) {
- var index = -1;
- this.unionModel.dataItems.find(function (model, currentIndex) {
- if (model.id === dataItemId) {
- index = currentIndex;
- return true;
- }
- return false;
- });
- if (index != -1) {
- this.unionModel.dataItems.splice(index, 1);
- this.dataItemImplList[index].destroy();
- this.dataItemImplList.splice(index, 1);
- this.dataItemAPIListCache.splice(index, 1);
- this._currentDataItemIdList.splice(index, 1);
- }
- }
- };
- Union.prototype.setDataItems = function setDataItems(dataItemPropsList, transactionToken) {
- var _this3 = this;
- var subTransaction = this.transaction.startTransaction(transactionToken);
- var currentIds = this.dataItemImplList.map(function (dataItem) {
- return dataItem.getId();
- });
- // destroy the dataitem APIs
- currentIds.forEach(function (id) {
- return _this3.getAPI().removeDataItem(id, subTransaction);
- });
- dataItemPropsList.forEach(function (dataItem) {
- return _this3.getAPI().addDataItem(dataItem, subTransaction);
- });
- this.transaction.endTransaction(subTransaction);
- return this.getDataItemList();
- };
- return Union;
- }(UnionAPISpec);
- });
- //# sourceMappingURL=Union.js.map
|