'use strict'; /** * Licensed Materials - Property of IBM * IBM Cognos Products: BI Cloud (C) Copyright IBM Corp. 2018 * US Government Users Restricted Rights - Use, duplication or disclosure restricted by GSA ADP Schedule Contract with IBM Corp. */ define(['../../../lib/@waca/core-client/js/core-client/ui/core/Events'], function (Events) { var ThumbnailStore = Events.extend({ /** * local cache * @type {Object} */ _items: null, /** * Constructor * * @param {Object} [items={}] - store data */ init: function init() { var items = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; ThumbnailStore.inherited('init', this, []); this._items = items; }, /** * Check whether a thumbnail id exists in the store * * @param {string} id - thumbnail id * * @return {boolean} TRUE if exists in store and FALSE if not */ exists: function exists(id) { return this._items[id] !== undefined; }, /** * Set data * * @param {string} id - thumbnail id * @param {any} data - thumbnail data * * @return {ThumbnailStore} self; current instance */ set: function set(id, _ref) { var data = _ref.data, cacheId = _ref.cacheId; var item = { data: data, cacheId: cacheId }; this._items[id] = item; this.trigger('thumbnailStore:set', { id: id, item: item }); return this; }, /** * Set error on the thumbnail * * @param {string} id - thumbnail id * @param {error} error - error to store on the object */ setError: function setError(id, _ref2) { var message = _ref2.message; var item = void 0; if (this.exists(id)) { item = this.getLocal(id); item.error = { message: message }; } else { item = { error: { message: message } }; this._items[id] = item; } this.trigger('thumbnailStore:set', { id: id, item: item }); return this; }, /** * Set warning on the thumbnail * * @param {string} id - thumbnail id * @param {warning} warning - warning to store on the object */ setWarning: function setWarning(id, _ref3) { var message = _ref3.message; var item = void 0; if (this.exists(id)) { item = this.getLocal(id); item.warning = { message: message }; } else { item = { warning: { message: message } }; this._items[id] = item; } this.trigger('thumbnailStore:set', { id: id, item: item }); return this; }, /** * Get data locally, from the cache * * @param {string} id - thumbnail id * * @return {any} thumbnail data */ getLocal: function getLocal(id) { return this._items[id]; }, /** * Get all data locally, from the cache * * @return {Object[]} array of thumbnail data */ getAllLocal: function getAllLocal() { var _this = this; return Object.keys(this._items).map(function (id) { var item = _this._items[id]; return { id: id, item: item }; }); }, /** * Get data * * @param {string} id - thumbnail id * @param {string} type - vis type * * @return {any} thumbnail data */ get: function get(id, type) { var result = void 0; if (this.exists(id)) { result = Promise.resolve(this.getLocal(id)); } else { result = this.getVisTypeDefault(type); } return result; }, /** * Delete data * * @param {string} id - thumbnail id * * @return {ThumbnailStore} self; current instance */ delete: function _delete(id) { delete this._items[id]; this.trigger('thumbnailStore:delete', { id: id }); return this; }, /** * Get default thumbnail for a specific vis type * * @param {string} type - vis type * * @return {string} default thumbnail */ getVisTypeDefault: function getVisTypeDefault() /* type */{ return Promise.resolve(); } }); return ThumbnailStore; }); //# sourceMappingURL=ThumbnailStore.js.map