123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141 |
- "use strict";
- /**
- * Licensed Materials - Property of IBM
- * IBM Cognos Products: Manage
- * Copyright IBM Corp. 2015, 2021
- * US Government Users Restricted Rights
- * Use, duplication or disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
- */
- define(['rave2', 'bi/admin/common/visualizations/VizBar', 'bi/admin/common/visualizations/VizStackedBar', 'bi/admin/common/utils/CapabilityHelper', 'bi/admin/nls/StringResource', 'react', 'react-dom', 'ba-react-admin/ba-react-admin.min', 'bi/commons/utils/DateTimeUtils', 'bi/commons/ui/AccessibleView', 'bacontentnav/ui/dialogs/OpenDialog', 'doT', 'moment-timezone', 'bacontentnav/utils/ContentStoreObject'], function (rave, VizBar, VizStackedBar, CapabilityHelper, StringResource, React, ReactDOM, AdminReact, DateTimeUtils, AccessibleView, OpenDialog, doT, moment, ContentStoreObject) {
- //NOSONAR: needed for amd
- var ActivitiesPane = AccessibleView.extend({
- init: function init(options) {
- ActivitiesPane.inherited('init', this, arguments);
- $.extend(this, options);
- this.modifiedStamp = '';
- if (!ContentStoreObject.glassContext) {
- ContentStoreObject.setGlassContext(this.glassContext);
- }
- },
- getTitle: function getTitle() {
- return StringResource.get('activities');
- },
- getIcon: function getIcon() {
- return 'common-subscribe_icon';
- },
- render: function render() {
- this.$el.css('height', '100%');
- this.$el.css('width', '100%');
- this.$el.css('display', 'flex');
- this.$el.css('flex-direction', 'column');
- this.$el.append('<div class="bi-admin-runAsDialog"></div>');
- this.$el.append('<div id="mng-activities-container" style="display: flex; flex-direction: column; height: 100%; position: relative;"></div>');
- var activitiesView = React.createElement(AdminReact.ActivitiesView, {
- StringResource: StringResource,
- glassContext: this.glassContext,
- CapabilityHelper: CapabilityHelper,
- pane: this,
- DateTimeUtils: DateTimeUtils,
- doT: doT,
- isMyActivities: !!this.isMyActivities,
- APICallbacks: {
- renderVis: this.renderVis.bind(this),
- showScopeDialog: this.showScopeDialog.bind(this),
- showRunAsDialog: this.showRunAsDialog.bind(this)
- }
- });
- ReactDOM.render(activitiesView, this.$el.find('#mng-activities-container')[0]);
- return Promise.resolve(true);
- },
- renderVis: function renderVis(container, chartType, chartData) {
- var width = container.offsetWidth;
- if (chartType === 'vizBar') {
- this.vizChart = new VizBar({
- el: container,
- data: chartData,
- parentWidth: width,
- legend: true
- });
- } else if (chartType === 'vizStackedBar') {
- this.vizChart = new VizStackedBar({
- el: container,
- data: this._prepareStackedBarChartData(chartData),
- parentWidth: width,
- legend: true,
- chartMode: 'stacked'
- });
- }
- },
- showScopeDialog: function showScopeDialog(rootObjects, onOpenCallback) {
- var dialog = new OpenDialog({
- glassContext: this.glassContext,
- typesToOpen: ['folder', 'package', 'subscriptionFolder', 'adminFolder'],
- multiSelect: false,
- primaryBtnText: StringResource.get('select'),
- filesToOpenTitle: StringResource.get('selectScope'),
- rootObjects: rootObjects,
- ancestors: [],
- onOpenCallback: onOpenCallback
- });
- dialog.title = StringResource.get('selectScope');
- dialog.primaryBtnText = StringResource.get('select');
- dialog.open();
- },
- showRunAsDialog: function showRunAsDialog(report) {
- var runAsActionView = React.createElement(AdminReact.RunAsAction, {
- StringResource: StringResource,
- glassContext: this.glassContext,
- objectInfo: report,
- slideout: this,
- runOnce: true
- });
- var runAs = this.$el.find('.bi-admin-runAsDialog');
- ReactDOM.unmountComponentAtNode(runAs[0]);
- ReactDOM.render(runAsActionView, runAs[0]);
- },
- _prepareStackedBarChartData: function _prepareStackedBarChartData(originalChartData) {
- var chartData = [];
- chartData = _.map(originalChartData, function (row) {
- return {
- name: row.label,
- total: row.total,
- layer: this._createLayer(row.details),
- legendName: row.label
- };
- }.bind(this));
- return chartData;
- },
- _createLayer: function _createLayer(items) {
- var range = rave.range(24);
- var layer = _.map(range, function (x) {
- return {
- x: x,
- y: this._findGroupValue(items, x)
- };
- }.bind(this));
- return layer;
- },
- _findGroupValue: function _findGroupValue(items, x) {
- var result = _.find(items, function (item) {
- var fixedDt = item.use;
- if (fixedDt.indexOf('Z') < 0) {
- fixedDt += 'Z';
- }
- var timezone = this.glassContext.services.userProfile.preferences.timeZoneID;
- var locale = this.glassContext.services.userProfile.preferences.contentLocale;
- var hour = moment(fixedDt).locale(locale).tz(timezone).hour();
- return hour === x;
- }.bind(this));
- return result ? result.total : 0;
- }
- });
- return ActivitiesPane;
- });
|