VisDefinitions.js 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. 'use strict';
  2. /**
  3. * Licensed Materials - Property of IBM
  4. * IBM Cognos Products: BI Cloud (C) Copyright IBM Corp. 2013, 2019
  5. * US Government Users Restricted Rights - Use, duplication or disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
  6. *
  7. * VisDefinitions
  8. */
  9. define(['underscore', '../../lib/@waca/core-client/js/core-client/ui/core/Class'], function (_, Class) {
  10. var VisDefinitions = null;
  11. VisDefinitions = Class.extend({
  12. init: function init(params) {
  13. VisDefinitions.inherited('init', this, arguments);
  14. this.mapDefinitionsById = {};
  15. this.jsonDefinitions = {};
  16. if (params) {
  17. this.jsonDefinitions = params.jsonDefinitions;
  18. for (var i = 0; i < params.jsonDefinitions.length; i++) {
  19. var def = params.jsonDefinitions[i];
  20. this.mapDefinitionsById[def.id] = def;
  21. }
  22. }
  23. },
  24. getDefinitionById: function getDefinitionById(id) {
  25. return this.mapDefinitionsById[id];
  26. },
  27. // return an array of all available definitions
  28. getDefinitions: function getDefinitions() {
  29. return this.jsonDefinitions;
  30. },
  31. removeObsoleteCachedVisDefinitions: function removeObsoleteCachedVisDefinitions() {
  32. var _this = this;
  33. var cachedDefIds = Object.keys(this.mapDefinitionsById);
  34. var allIds = this.jsonDefinitions.map(function (def) {
  35. return def.id;
  36. });
  37. var idsNoLongerExist = _.difference(cachedDefIds, allIds);
  38. idsNoLongerExist.forEach(function (id) {
  39. delete _this.mapDefinitionsById[id];
  40. });
  41. }
  42. });
  43. return VisDefinitions;
  44. });
  45. //# sourceMappingURL=VisDefinitions.js.map