'use strict';
/*
*+------------------------------------------------------------------------+
*| Licensed Materials - Property of IBM
*| IBM Cognos Products: Content Explorer
*| (C) Copyright IBM Corp. 2017, 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/Class', 'underscore'], function (BaseClass, _) {
'use strict';
/**
* @class DashboardFactory
* @hideconstructor
* @classdesc Factory class that is used to instantiate a {@link DashboardApi} instance.
* DashboardFactory can not be instantiated directly.
* DashboardFactory can be obtained through an instance of {@link CognosApi}.
* @example
* // Create an instance of the CognosApi
* const api = new CognosApi({
* cognosRootURL: 'http://localhost/bi/',
* node: document.getElementById('containerDivId'),
* sessionCode: 'CD1a2b34567b8c901234d5'
* });
*
* // initialize the CognosApi in order to obtain the service APIs
* api.initialize().then(() => {
* // create a new dashboard through the dashboard factory
* api.dashboard.createNew();
* ...
* // open an existing dashboard through the dashboard factory
* api.dashboard.openDashboard();
* ...
* });
*/
var DashboardFactory = BaseClass.extend({
API_METHODS: ['createNew', 'openDashboard'],
API_ENUMS: [],
init: function init(options) {
this.glassContext = options.glassContext;
},
/**
* Create a {@link DashboardApi} instance of a new dashboard
* @function DashboardFactory#createNew
* @example
* const dashboardApi = null;
* api.dashboard.createNew().then((dashboardApi) => {
* console.log('Dashboard created successfully.');
* dashboardApi = dashboardApi;
* }).catch((err) => {
* console.log('Cancelled by user.');
* });
*/
createNew: function createNew() {
return new Promise(function (resolve, reject) {
this.glassContext.appController.openAppView('createBoard', {
content: {
id: 'createBoardPage_dashboard',
editMode: true,
restrictTemplate: 'dashboard',
containerAppOptions: {
callbacks: {
resolve: resolve,
reject: reject
},
configuration: {
ui: {},
pinning: 'disabled'
}
},
ui_appbar: false
}
});
}.bind(this));
},
/**
* Create a {@link DashboardApi} instance of an existing dashboard
* @function DashboardFactory#openDashboard
* @param {Object} option.dashboardSpec dashboard specification to open
* @see {@link DashboardApi#getSpec DashboardApi.getSpec}
* @example
* const dashboardApi = null;
* api.dashboard.openDashboard({
* dashboardSpec: {...}
* }).then((dashboardApi) => {
* console.log('Dashboard opened successfully.');
* dashboardApi = dashboardApi;
* });
*/
openDashboard: function openDashboard(options) {
return new Promise(function (resolve, reject) {
this.glassContext.appController.openAppView('dashboard', {
content: {
id: _.uniqueId(),
editMode: false,
containerAppOptions: {
callbacks: {
resolve: resolve,
reject: reject
},
configuration: {
ui: {},
pinning: 'disabled'
}
},
ui_appbar: false,
boardId: options.dashboardId || null,
boardSpec: options.dashboardSpec
}
});
}.bind(this));
}
});
return DashboardFactory;
});
//# sourceMappingURL=DashboardFactory.js.map