123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246 |
- "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(['underscore', 'bi/admin/nls/StringResource', 'bacontentnav/common/ContentListPageView', 'bi/admin/system/services/TopicUploader', 'bi/commons/ui/properties/PropertyUIControl', 'bi/commons/ui/dialogs/ConfirmationDialog', 'bi/admin/system/services/TopicsListController', 'bi/commons/utils/Downloader'], function (_, StringResource, View, Uploader, PropertyUIControl, ConfirmationDialog, TopicsListController, Downloader) {
- 'use strict'; //NOSONAR: meant to be strict
- var CustomTopicTab = View.extend({
- loggingConfigUrl: 'v1/glug/config/logging',
- builtinTopicUrl: 'v1/glug/topics/builtin',
- customTopicUrl: 'v1/glug/topics/custom',
- getAddOnContextMenuId: function getAddOnContextMenuId() {
- return "com.ibm.bi.admin.loggingAddOnTopicListViewMenu";
- },
- currentCustomSelection: {
- topicName: '',
- topicType: 'CUSTOM'
- },
- currentTopic: {
- topicName: '',
- topicType: ''
- },
- init: function init(options) {
- CustomTopicTab.inherited('init', this, arguments);
- this.showTitle = true;
- _.extend(this, options);
- this.topicsController = new TopicsListController({
- glassContext: this.glassContext
- });
- if (this.currentHomeValue.topicType === 'CUSTOM') {
- this.currentCustomSelection = this.currentHomeValue;
- }
- },
- renderContent: function renderContent() {
- var aControls = [];
- this.$el.addClass("adminContentListView");
- aControls.push({
- 'type': 'SingleLineLinks',
- 'items': [{
- 'align': 'right',
- 'items': [{
- 'type': 'icon',
- 'svgIcon': 'common-upload',
- 'clickCallback': this.uploadTopic.bind(this),
- 'iconTooltip': StringResource.get('uploadTopic')
- }, {
- 'type': 'text',
- 'value': StringResource.get('uploadTopic')
- }]
- }]
- }, {
- 'module': 'bi/content_apps/ui/RenderCallback',
- 'renderCallback': this.renderListControl.bind(this),
- 'el': this.$el
- });
- this._oPropertyUIControl = this._newPropertyUIControl(aControls);
- return this._oPropertyUIControl.render();
- },
- _newPropertyUIControl: function _newPropertyUIControl(items) {
- return new PropertyUIControl({
- 'glassContext': this.glassContext,
- 'el': this.$el,
- 'items': items
- });
- },
- _getSelectedTopic: function _getSelectedTopic() {
- var selectedDefaultItem = this._listControl.getSelectedObjects()[0];
- if (!_.isUndefined(selectedDefaultItem)) {
- this.currentCustomSelection.topicName = selectedDefaultItem.id;
- this.currentValue = this.currentCustomSelection;
- }
- },
- 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();
- },
- _renderContentList: function _renderContentList() {
- return this.renderContentList({
- 'minHeight': 350,
- '$container': this.$el,
- 'columns': this._getColumnSpecs(),
- 'ajaxProp': '',
- 'getJSONDataCallback': this.topicsController._getAddOnTopicList.bind(this),
- 'defaultSort': [1, 'asc'],
- 'multiSelect': false,
- 'selectedRow': ['name', StringResource.get(this.currentCustomSelection.topicName)],
- 'disableColumnHeaders': true,
- 'singleSelectCallback': this.onSelected.bind(this),
- 'getSelectedObjectWPermissions': function getSelectedObjectWPermissions(selectedObjects) {
- return Promise.resolve(selectedObjects);
- },
- 'getContextMenuId': this.getAddOnContextMenuId,
- 'dataTableOptions': {
- 'iDisplayLength': 100
- },
- '_showLoadBuffer': 100,
- 'emptyFolderString': StringResource.get('noCustomTopic')
- });
- },
- 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'
- }];
- },
- _deleteTopic: function _deleteTopic() {
- var oDialog = new ConfirmationDialog('confirmDelete', StringResource.get('confirmDelete'), StringResource.get('confirmDeleteMessage'));
- oDialog.confirm(function () {
- this._getSelectedTopic();
- var selectedTopicName = this.currentValue.topicName;
- this.topicsController.deleteAddOnTopic(selectedTopicName).then(function () {
- var sText = StringResource.get('topicDeleteMsg', {
- 'topicName': selectedTopicName
- });
- this.glassContext.appController.showToast(sText, {
- 'type': 'success'
- });
- this._listControl.removeSelectedRows(); // when the topic is deleted, need to update the selected item to null
- this.currentValue = null;
- this.onSelectCallback(this.currentValue);
- }.bind(this), function (ajaxObj, err) {
- this.glassContext.appController.showErrorMessage(AJAXUtils.buildErrorMessage(err.responseJSON.errors), StringResource.get('error'));
- }.bind(this));
- }.bind(this));
- oDialog.renderContent($('<div>'));
- },
- uploadTopic: function uploadTopic() {
- var ajaxOptions = {
- 'isUpload': true,
- 'type': 'topic'
- };
- var uploader = new Uploader({
- '$el': this.$el,
- 'glassContext': this.glassContext,
- 'ajax': this.updateOrUpload.bind(this),
- 'ajaxOptions': ajaxOptions,
- 'fileType': 'json'
- });
- return uploader.doUpload().then();
- },
- updateOrUpload: function updateOrUpload(options) {
- return this.topicsController._updateOrUpload(options).then(this.refreshList.bind(this));
- },
- _downloadTopic: function _downloadTopic() {
- var selectedItem = this._listControl.getSelectedObjects()[0];
- if (_.isUndefined(selectedItem)) {
- //in this case nothing selected so nothing to download
- return;
- } else {
- var name = this._listControl.getSelectedObjects()[0].name;
- var promise = this.topicsController._getAddOnTopicDescription(name);
- return promise.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();
- });
- }
- },
- 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 CustomTopicTab;
- });
|