123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189 |
- '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
|