123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105 |
- 'use strict';
- function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
- /*
- *+------------------------------------------------------------------------+
- *| Licensed Materials - Property of IBM
- *| IBM Cognos Products: Content Explorer
- *| (C) Copyright IBM Corp. 2018
- *|
- *| US Government Users Restricted Rights - Use, duplication or disclosure
- *| restricted by GSA ADP Schedule Contract with IBM Corp.
- *+------------------------------------------------------------------------+
- */
- define([], function () {
- /**
- * Create a glass context instance that will simulate a dashboard perspective glass context from anywhere.
- * This class will wrap a given glass context, but adapt certain functions to behave as if we are in a dashboard perspective
- */
- var DashboardGlassContext = function () {
- function DashboardGlassContext(options) {
- _classCallCheck(this, DashboardGlassContext);
- this.model = options.model;
- this.impersonateGlassContext(options.glassContext);
- }
- DashboardGlassContext.prototype.setServices = function setServices(services) {
- this._services = services;
- };
- /**
- * Copy all function and members of the glass context to be part of this instance.
- * If we find the appController, we need to overrider with out own version
- */
- DashboardGlassContext.prototype.impersonateGlassContext = function impersonateGlassContext(glassContext) {
- for (var m in glassContext) {
- if (typeof glassContext[m] === 'function') {
- this[m] = glassContext[m].bind(glassContext);
- } else if (m === 'appController') {
- this[m] = this.impersonateAppController(glassContext[m]);
- } else {
- this[m] = glassContext[m];
- }
- }
- };
- /**
- * Create our own version of the app controller.
- * Copy all functions and memebers of the original appcontroller, but override:
- * - findCollection : return dashboard collections available in the dashboard model
- * - getCurrentContentView : return a call that simulates the dashbord perspective content view
- */
- DashboardGlassContext.prototype.impersonateAppController = function impersonateAppController(appController) {
- var newAppController = {};
- for (var m in appController) {
- if (typeof appController[m] === 'function') {
- if (m === 'findCollection') {
- newAppController[m] = function (id) {
- var _this = this;
- var whenReady = new Promise(function (resolve) {
- var collection = _this.model.collectionContainers.find(function (collection) {
- return collection.id === id;
- });
- resolve(collection ? collection.items : []);
- });
- return whenReady;
- }.bind(this);
- } else if (m === 'getCurrentContentView') {
- newAppController[m] = function () {
- return {
- services: this._services,
- getDashboardApi: function getDashboardApi() {
- return {
- getDashboardInfo: function getDashboardInfo() {
- return { type: 'exploration' };
- }
- };
- }
- };
- }.bind(this);
- } else {
- newAppController[m] = appController[m].bind(appController);
- }
- } else {
- newAppController[m] = appController[m];
- }
- }
- return newAppController;
- };
- return DashboardGlassContext;
- }();
- return DashboardGlassContext;
- });
- //# sourceMappingURL=DashboardGlassContext.js.map
|