123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224 |
- "use strict";
- /**
- * Licensed Materials - Property of IBM
- * IBM Cognos Products: Cognos Analytics
- * Copyright IBM Corp. 2017, 2018
- * US Government Users Restricted Rights - Use, duplication or disclosure
- * restricted by GSA ADP Schedule Contract with IBM Corp.
- */
- define(['bi/admin/nls/StringResource', 'bacontentnav/common/ContentListPageView', 'bi/commons/ui/properties/PropertyUIControl', 'bi/admin/system/services/TopicsListController', 'bi/commons/utils/Downloader', 'underscore'], function (StringResource, View, PropertyUIControl, TopicsListController, Downloader, _) {
- 'use strict'; //NOSONAR: meant to be strict
- var BuiltinTopicTab = View.extend({
- loggingConfigUrl: 'v1/glug/config/logging',
- builtinTopicUrl: 'v1/glug/topics/builtin',
- customTopicUrl: 'v1/glug/topics/custom',
- favouriteTopicList: ['AAA', 'CM', 'MOSER', 'DISP', 'POGO_MSGS', 'DEFAULT', 'RSVP'],
- getContextMenuId: function getContextMenuId() {
- return "com.ibm.bi.admin.loggingTopicListViewMenu";
- },
- currentBuiltinSelection: {
- topicName: '',
- topicType: 'BUILTIN'
- },
- currentTopic: {
- topicName: '',
- topicType: ''
- },
- init: function init(options) {
- BuiltinTopicTab.inherited('init', this, arguments);
- this.showTitle = true;
- _.extend(this, options);
- this.topicsController = new TopicsListController({
- glassContext: this.glassContext
- });
- if (this.currentHomeValue.topicType === 'BUILTIN') {
- this.currentBuiltinSelection = this.currentHomeValue;
- }
- },
- renderContent: function renderContent() {
- var aControls = [];
- this.$el.addClass("adminContentListView");
- this.$el.addClass("builtInTopicList");
- aControls.push({
- 'type': 'CheckBox',
- 'name': 'showAllBuiltinTopic',
- 'label': StringResource.get('showAll'),
- 'checked': this.checkFavorite(),
- 'onChange': this.refreshList.bind(this),
- 'controlOnLeft': true
- }, {
- 'module': 'bi/content_apps/ui/RenderCallback',
- 'renderCallback': this.renderListControl.bind(this),
- 'el': this.$el,
- 'name': 'topicList'
- });
- this._oPropertyUIControl = this._newPropertyUIControl(aControls);
- return this._oPropertyUIControl.render().then(function () {
- this.rightAlignLabel();
- }.bind(this));
- },
- _newPropertyUIControl: function _newPropertyUIControl(items) {
- return new PropertyUIControl({
- 'glassContext': this.glassContext,
- 'el': this.$el,
- 'items': items
- });
- },
- rightAlignLabel: function rightAlignLabel() {
- var $showAllParentDiv = this._oPropertyUIControl.getProperty('showAllBuiltinTopic').getPropertyNode().parent();
- $showAllParentDiv.addClass('showAllBuiltinTopicFlexRightAlignControl');
- },
- checkFavorite: function checkFavorite() {
- var isChecked = true;
- if (_.contains(this.favouriteTopicList, this.currentBuiltinSelection.topicName)) {
- isChecked = false;
- }
- return isChecked;
- },
- _getSelectedTopic: function _getSelectedTopic() {
- var selectedDefaultItem = this._listControl.getSelectedObjects()[0];
- if (!_.isUndefined(selectedDefaultItem)) {
- this.currentBuiltinSelection.topicName = selectedDefaultItem.id;
- this.currentValue = this.currentBuiltinSelection;
- }
- },
- getSelectedObjects: function getSelectedObjects() {
- var i;
- var rowObjects = [];
- var ancestors = this._listControl.contentView.getAncestors();
- for (i = 0; i < this.aSelectedRows.length; i += 1) {
- var obj = this._dTable.fnGetData(this.aSelectedRows[i]);
- if (!obj[ContentStoreObject.ANCESTORS] && ancestors && ancestors.length > 0) {
- obj[ContentStoreObject.ANCESTORS] = ancestors;
- }
- rowObjects.push(obj);
- }
- return rowObjects;
- },
- renderListControl: function renderListControl(container) {
- if (!_.isUndefined(container)) {
- this.$container = $(container);
- }
- if (_.isUndefined(this.$container)) {
- this.$container = this.$el;
- }
- this.$wrapper = $('<div>');
- this.$container.append(this.$wrapper);
- this.$wrapper.append(this.$contentBars);
- return this._renderContentList();
- },
- _getDataTableSource: function _getDataTableSource() {
- var getJsonUrl;
- if (this._oPropertyUIControl.getProperty('showAllBuiltinTopic').isChecked()) {
- getJsonUrl = this.topicsController._getDefaultTopicList.bind(this.topicsController);
- } else {
- getJsonUrl = this.topicsController._getFavouriteTopicList.bind(this.topicsController);
- }
- return getJsonUrl;
- },
- _renderContentList: function _renderContentList() {
- var getJsonUrl = this._getDataTableSource();
- return this.renderContentList({
- 'minHeight': 350,
- '$container': this.$el,
- 'columns': this._getColumnSpecs(),
- 'ajaxProp': '',
- 'getJSONDataCallback': getJsonUrl,
- 'defaultSort': [1, 'asc'],
- 'multiSelect': false,
- 'selectedRow': ['name', StringResource.get(this.currentBuiltinSelection.topicName)],
- 'disableColumnHeaders': true,
- 'singleSelectCallback': this.onSelected.bind(this),
- 'getSelectedObjectWPermissions': function getSelectedObjectWPermissions(selectedObjects) {
- return Promise.resolve(selectedObjects);
- },
- 'getContextMenuId': this.getContextMenuId,
- 'dataTableOptions': {
- 'iDisplayLength': 100
- },
- '_showLoadBuffer': 100
- });
- },
- onSelected: function onSelected() {
- this._getSelectedTopic();
- return this.onSelectCallback(this.currentValue);
- },
- _getContentBarAccesibleLabel: function _getContentBarAccesibleLabel() {
- return StringResource.get('topics');
- },
- _getColumnSpecs: function _getColumnSpecs() {
- return [{
- 'type': 'RadioButtons'
- }, {
- 'type': 'Text',
- 'propertyName': 'name',
- '_bNavigable': true,
- 'label': StringResource.get('name'),
- 'scope': 'row'
- }, {
- 'type': 'ContextMenu',
- 'width': '10%',
- 'module': 'bacontentnav/common/ui/list_columns/ContextMenu'
- }];
- },
- _downloadTopic: function _downloadTopic() {
- var selectedObj = this._listControl.getSelectedObjects()[0];
- if (!_.isUndefined(selectedObj)) {
- var name = selectedObj.id;
- return this.topicsController._getDefaultTopicDescription(name).then(function (data) {
- var downloader = new Downloader({
- 'url': 'data:text/json;charset=utf-8,' + encodeURIComponent(JSON.stringify(data, 0, 4)),
- 'name': name + '.json'
- });
- downloader.doDownload();
- });
- } else {
- return Promise.resolve();
- }
- },
- cancel: function cancel() {},
- onContextMenu: function onContextMenu(id) {
- switch (id) {
- case 'deleteTopic':
- this._deleteTopic();
- break;
- case 'downloadTopic':
- this._downloadTopic();
- break;
- default:
- this.logger.error("Unexpected context menu id for logging list pane: " + id);
- }
- },
- refreshList: function refreshList() {
- this._listControl.remove();
- this.renderListControl();
- }
- });
- return BuiltinTopicTab;
- });
|