');
$(container).append($wrapper);
$wrapper.append(this.$contentBars);
return this.renderContentList({
'el': $wrapper,
'columns': this._getColumnSpecification(),
'$container': this.$el,
'getJSONDataCallback': this._getCredentialData.bind(this)
})
.then(function() {
this.getListControl().setIsAccountPickerSlideout();
}.bind(this));
},
// credential data
_getCredentialData: function() {
return this._getUserCredentials()
.then(function() {
return this._getPolicies(this.credentialId)
.then(function() {
return {
data: this.policyArray.data[0].policies
};
}.bind(this));
}.bind(this))
.catch(function(err) {
this.slideout.hide();
return Promise.reject(err);
}.bind(this));
},
// query to retrieve credential id
_getUserCredentials: function() {
return this._sendRequest({
dataType: 'json',
type: 'GET',
url: 'v1/users/~/credentials'
}, function(response) {
if (response.data && response.data.id) {
this.credentialId = response.data.id;
} else {
return Promise.reject(new Error());
}
}.bind(this));
},
// query to retrieve policies of current credential
_getPolicies: function(id) {
return this._sendRequest({
dataType: 'json',
type: 'GET',
url: 'v1/objects/' + id + '?fields=policies{defaultName,id,searchPath}'
}, function(response) {
if (response.data && response.data.data[0].policies) {
this.policyArray = response.data;
return this.policyArray;
} else {
return Promise.reject(new Error());
}
}.bind(this));
},
_onApplyClick: function() {
var data = {};
data.policies = this.policyArray.data[0].policies;
data.type = 'credential';
var jsonData = JSON.stringify(data);
var url = 'v1/objects/' + this.credentialId;
var options = {
'headers': {
'Accept': 'application/json',
'Content-Type': 'application/json'
},
'type': 'PUT',
'url': url,
'data': jsonData
};
return this._sendRequest(options, function() {});
},
_onCancelClick: function() {
this.slideout.hide();
},
_sendRequest: function(options, successHandler) {
return this.glassContext.getCoreSvc('.Ajax').ajax(options)
.then(successHandler.bind(this))
.catch(function(err) {
if (err.message) {
this.glassContext.appController.showErrorMessage(err.message, 'Error');
}
return Promise.reject(err);
}.bind(this));
},
_getDefaultRequestURL: function() {
return this.itemURL;
},
_getModuleName: function() {
return 'bi/content_apps/CredentialsView';
},
getDefaultSort: function() {
return [1, 'asc'];
},
setFocus: function() {
var $tabs = this.$el.find(':tabbable');
if ($tabs.length > 0) {
$tabs.get(0).focus();
}
},
_isDuplicate: function(oData, matchId) {
var isDuplicate = false;
oData.forEach(function(arrayElem) {
var id = arrayElem.securityObject.id;
if (id === matchId) {
isDuplicate = true;
return false;
}
});
return isDuplicate;
},
removeSelection: function() {
setTimeout(function() {
var selectedPolicies = this.getListControl().getSelectedObjects();
var currentPolicies = this.policyArray.data[0].policies;
var updatedPolicies = _.reject(currentPolicies, function(policy) {
return _.find(selectedPolicies, function(selPol) {
return policy.securityObject.defaultName === selPol.securityObject.defaultName;
});
});
this.policyArray.data[0].policies = updatedPolicies;
var numberDeleted = this.getListControl().getSelectedRows().length;
if (numberDeleted > 0) {
var sToastMessage = (numberDeleted === 1)? StringResource.get('toastItemsWereDeletedSingular', {
'noOfItems': numberDeleted
}) : StringResource.get('toastItemsWereDeleted', {
'noOfItems': numberDeleted
});
this.getListControl().removeSelectedRows();
this.glassContext.appController.showToast(sToastMessage);
}
this.setFocus();
}.bind(this), 100);
},
addSelection: function(selectedItems) {
var itemCount = 0;
var numberAdded = 0;
var dataTable = this.getListControl().getDatatable();
var tableApi = dataTable.api();
var oData = dataTable.fnGetData();
selectedItems.forEach(function(item) {
var itemId = item.id;
var itemType = item.type;
var itemName = item.defaultName;
var itemPath = item.searchPath;
var foundDuplicate = this._isDuplicate(oData, itemId);
itemCount = itemCount + 1;
if (!foundDuplicate) {
numberAdded = numberAdded + 1;
var policy = new Policy(itemName, itemId, itemType, itemPath);
this.policyArray.data[0].policies.push(policy);
tableApi.row.add(policy).draw(true);
}
}.bind(this));
var sToastMessage;
if (numberAdded === 1) {
sToastMessage = StringResource.get('toastItemsWereAddedSingular', {
'noOfItems': numberAdded
});
} else if (numberAdded === 0 && itemCount === 1) {
sToastMessage = StringResource.get('toastItemsAlreadyAddedSingular');
} else if (numberAdded === 0 && itemCount > 1) {
sToastMessage = StringResource.get('toastItemsAlreadyAdded');
} else {
sToastMessage = StringResource.get('toastItemsWereAdded', {
'noOfItems': numberAdded
});
}
this.glassContext.appController.showToast(sToastMessage);
},
_onClose: function() {
this.slideout.hide();
},
_openAddMembersSlideout: function(oData) {
var overlaySlideoutEl = $('
');
this.slideout.$el.append(overlaySlideoutEl);
var overlaySlideout = this._getSlideout({
'glassContext': this.glassContext,
'position': this.position || 'right',
'el': overlaySlideoutEl,
'overlay': true,
'width': this.slideout.$el.width(),
'enableTabLooping': true,
'content': {
'module': AccountPickerSlideoutView,
'showBreadcrumbs': true,
'navigateOnRowSelect': true,
'addCallback': function(selectedItems) {
this.addSelection(selectedItems);
}.bind(this),
'objectInformation': oData,
'glassContext': this.glassContext
}
});
overlaySlideout.render()
.then(function() {
overlaySlideout.show();
});
},
_getSlideout: function(options) {
return new Slideout(options);
},
contentbarItems: function() {
var filterString = window.localStorage.getItem('filterString_' + this.stateId);
return [{
'name': 'nameLabel',
'position': 'leading',
'label': StringResource.get('preferencesCredentialsLabel'),
'style': 'nameLabel',
'module': 'bacontentnav/common/ui/contentbar_components/HiddenLabel'
}, {
'name': 'typeMenu',
'label': StringResource.get('type'),
'labelOnly': true,
'hcLabel': false,
'position': 'trailing',
'supportCustomCollapse': true,
'showTitle': false,
'updateLabel': true,
'icon': 'common-filter',
'bSVG': true,
'module': 'bacontentnav/common/ui/contentbar_components/ToggleMenuBar',
'items': [{
'name': 'allContent',
'icon': 'wft_checkmark',
'label': StringResource.get('allGenericItems'),
'checked': (filterString === 'allContent'),
'action': function() {
this._filter('allContent');
}.bind(this)
}, {
'name': 'accounts',
'icon': 'wft_checkmark',
'label': StringResource.get('policyFilterAccounts'),
'checked': (filterString === 'accounts'),
'action': function() {
this._filter('accounts');
}.bind(this)
}, {
'name': 'groups',
'icon': 'wft_checkmark',
'label': StringResource.get('policyFilterGroups'),
'checked': (filterString === 'groups'),
'action': function() {
this._filter('groups');
}.bind(this)
}, {
'name': 'roles',
'icon': 'wft_checkmark',
'label': StringResource.get('policyFilterRoles'),
'checked': (filterString === 'roles'),
'action': function() {
this._filter('roles');
}.bind(this)
}]
}, {
'name': 'separator',
'type': 'Separator',
'position': 'trailing'
}, {
'name': 'add',
'position': 'trailing',
'displayLabel': false,
'label': StringResource.get('policesAddMemberButtonLabel'),
'module': 'bacontentnav/common/ui/contentbar_components/Button',
'className': 'addNewFolder',
'icon': 'common-add',
'_handleClick': function() {
this._openAddMembersSlideout();
}.bind(this)
}];
},
getListControlOptions: function() {
return {
'ajaxProp': 'data',
'emptyFolderString': StringResource.get('emptyPolicyList'),
'showEmptyNewFolderButton': true,
'multiSelect': true,
'rightClickContextMenu': false
};
},
_getColumnSpecification: function() {
return [{
'type': 'Icon',
'getDataFn': function(oRowData) {
if (oRowData.securityObject[ContentStoreObject.TYPE] === 'nil') {
return StringResource.get('unknown');
} else {
return oRowData.securityObject[ContentStoreObject.TYPE];
}
}
}, {
'type': 'Name',
'scope': 'row',
'getDataFn': function(oRowData) {
if (oRowData.securityObject[ContentStoreObject.DEFAULT_NAME] === undefined) {
return StringResource.get('unavailable');
} else {
return _.escape(oRowData.securityObject[ContentStoreObject.DEFAULT_NAME]);
}
}
}, {
'type': 'ClickableIcon',
'name': StringResource.get('policesRemove'),
'icon': 'common-remove-delete',
'clickCallback': this.removeSelection.bind(this)
}];
},
_adjustWidth: function() {
this.$el.addClass('pageview-small');
},
_multiselectbarItems: function() {
return Promise.resolve([{
'name': 'removeButton',
'position': 'leading',
'icon': 'common-remove-delete',
'module': 'bacontentnav/common/ui/contentbar_components/Button',
'className': 'policyMulSel',
'action': this.removeSelection.bind(this)
}, {
'name': 'selectedLabel',
'position': 'leading',
'module': '../../lib/gemini/app/ui/toolbar_components/Label',
'style': 'selectedLabel'
}, {
'position': 'leading',
'type': 'Separator'
}, {
'name': 'cancelButton',
'position': 'trailing',
'label': StringResource.get('cancel'),
'text': StringResource.get('cancel'),
'labelOnly': true,
'module': 'bacontentnav/common/ui/contentbar_components/Button',
'className': 'cancelButton',
'_handleClick': function() {
this.getListControl()._clearRows();
this.multiselectBar.hide();
this.contentBar.show();
}.bind(this)
}]);
},
getFilterSpec: function() {
return [{
'name': 'allContent',
'label': StringResource.get('allContent'),
'value': 'allContent'
}, {
'name': 'accounts',
'label': StringResource.get('policyFilterAccounts'),
'value': 'accounts'
}, {
'name': 'groups',
'label': StringResource.get('policyFilterGroups'),
'value': 'groups'
}, {
'name': 'roles',
'label': StringResource.get('policyFilterRoles'),
'value': 'roles'
}];
}
});
return CredentialsView;
});
/*
*+------------------------------------------------------------------------+
*| Licensed Materials - Property of IBM
*| IBM Cognos Products: Content Explorer
*| (C) Copyright IBM Corp. 2016, 2018
*|
*| US Government Users Restricted Rights - Use, duplication or disclosure
*| restricted by GSA ADP Schedule Contract with IBM Corp.
*+------------------------------------------------------------------------+
*/
define('bi/content_apps/DataSourceCredentialsView',[
'q',
'jquery',
'underscore',
'bacontentnav/common/ContentListPageView',
'bi/content_apps/nls/StringResource',
'bacontentnav/utils/GlassContextHelper',
'bacontentnav/lib/@waca/core-client/js/core-client/ui/properties/PropertyUIControl'
],
function(Q, $, _, ContentListPageView, StringResource, GlassContextHelper, PropertyUIControl) {
'use strict';
var DataSourceCredentialsView = ContentListPageView.extend({
init: function(options) {
this.itemURL = options.itemURL;
DataSourceCredentialsView.inherited('init', this, arguments);
_.extend(this, options);
},
renderContent: function() {
// The content bars get rendered first, detach them here so we can re-attach them to the DOM when just above the list control
this.$contentBars = this.$el.children().detach();
var aControls = [];
aControls.push({
'module': 'bi/content_apps/ui/RenderCallback',
'renderCallback': this._renderListControl.bind(this)
}, {
'type': 'Banner',
'name': 'credentialsBanner',
'value': StringResource.get('preferencesDatasourceTitle'),
'centerLabel': true,
'hintText': StringResource.get('preferencesDataSourceCredentialsHintText'),
'backButton': true,
'editable': false,
'readOnly': true,
'onClose': this._onClose.bind(this)
});
this._oPropertyUIControl = new PropertyUIControl({
'el': this.$el,
'glassContext': this.glassContext,
'items': aControls
});
this._oPropertyUIControl.render().then(function() {
return this;
});
},
_renderListControl: function(container) {
var $wrapper = $('
');
$(container).append($wrapper);
$wrapper.append(this.$contentBars);
return this.renderContentList({
'el': $wrapper,
'columns': this._getColumnSpecification(),
'$container': this.$el,
'url': this._getRequestURL()
}).then(function() {
this.setFocus();
}.bind(this));
},
_getRequestURL: function() {
return 'v1/objects/' + this.glassContext.profile.account.id + '/items?types=dataSourceCredential&fields=dataSourceName,dataSourceConnectionName,defaultName';
},
_getDefaultRequestURL: function() {
return this.itemURL;
},
_getModuleName: function() {
return 'bi/content_apps/DataSourceCredentialsView';
},
_sendRequest: function(options, successHandler) {
var deferred = Q.defer();
if (!successHandler) {
successHandler = this._handleSuccess;
}
this.glassContext.services.ajax.ajax(options)
.then(successHandler.bind(this, deferred), this._handleError.bind(this, deferred));
return deferred.promise;
},
_handleSuccess: function(deferred) {
deferred.resolve();
},
_handleError: function(deferred, dfd, jqXHR) {
GlassContextHelper.showAjaxServiceErrorMessage(this.glassContext, jqXHR);
deferred.reject();
},
contentbarItems: function() {
return [{
'name': 'nameLabel',
'position': 'leading',
'style': 'nameLabel',
'label': StringResource.get('preferencesDataSourceCredentialsLabel'),
'module': 'bacontentnav/common/ui/contentbar_components/HiddenLabel'
}];
},
getListControlOptions: function() {
return {
'ajaxProp': 'data',
'emptyFolderString': StringResource.get('emptyPolicyList'),
'showEmptyNewFolderButton': false,
'multiSelect': true,
'rightClickContextMenu': false
};
},
setFocus: function() {
var $tabs = this.$el.find(':tabbable');
if ($tabs.length > 0) {
$tabs.get(0).focus();
}
},
_onClose: function() {
this.slideout.hide();
},
getDefaultSort: function() {
return [1, 'asc'];
},
removeSelection: function() {
var deferred = Q.defer();
setTimeout(function() {
var selectedRows = this.getListControl().getSelectedObjects();
for (var i = 0; i < selectedRows.length; i += 1) {
var url = 'v1/objects/' + selectedRows[i].id;
var options = {
'headers': {
'Accept': 'application/json',
'Content-Type': 'application/json'
},
'type': 'DELETE',
'url': url
};
this._sendRequest(options);
}
this.getListControl().removeSelectedRows();
this.setFocus();
deferred.resolve();
}.bind(this), 100);
return deferred.promise;
},
getListControl: function() {
return this._listControl;
},
_getColumnSpecification: function() {
return [{
'type': 'Icon'
}, {
'type': 'Text',
'propertyName': 'dataSourceName',
'label': StringResource.get('preferencesDatasourceHeader')
}, {
'type': 'ClickableIcon',
'name': StringResource.get('policesRemove'),
'icon': 'common-remove-delete',
'clickCallback': this.removeSelection.bind(this)
}];
},
_adjustWidth: function() {
this.$el.addClass('pageview-small');
},
_multiselectbarItems: function() {
var items = [{
'name': 'removeButton',
'position': 'leading',
'icon': 'common-remove-delete',
'module': 'bacontentnav/common/ui/contentbar_components/Button',
'className': 'policyMulSel',
'action': this.removeSelection.bind(this)
}, {
'name': 'selectedLabel',
'position': 'leading',
'label': StringResource.get('selected'),
'module': '../../lib/gemini/app/ui/toolbar_components/Label',
'style': 'selectedLabel'
}, {
'name': 'cancelButton',
'position': 'trailing',
'label': StringResource.get('cancel'),
'text': StringResource.get('cancel'),
'labelOnly': true,
'module': 'bacontentnav/common/ui/contentbar_components/Button',
'className': 'cancelButton',
'_handleClick': function() {
this._listControl._clearRows();
this.multiselectBar.hide();
this.contentBar.show();
}.bind(this)
}];
return Q.when(items);
}
});
return DataSourceCredentialsView;
});
/*
*+------------------------------------------------------------------------+
*| Licensed Materials - Property of IBM
*| IBM Cognos Products: Content Explorer
*| (C) Copyright IBM Corp. 2016, 2018
*|
*| US Government Users Restricted Rights - Use, duplication or disclosure
*| restricted by GSA ADP Schedule Contract with IBM Corp.
*+------------------------------------------------------------------------+
*/
define('bi/content_apps/GroupsAndRolesView',[
'q',
'jquery',
'underscore',
'bi/glass/app/ContentView',
'bi/content_apps/nls/StringResource',
'bacontentnav/lib/@waca/core-client/js/core-client/ui/properties/PropertyUIControl',
'bacontentnav/utils/GlassContextHelper'
],
function(Q, $, _, ContentView, StringResource, PropertyUIControl, GlassContextHelper) {
'use strict';
var GroupsAndRolesView = ContentView.extend({
init: function(options) {
GroupsAndRolesView.inherited('init', this, arguments);
_.extend(this, options);
},
render: function() {
var deferred = Q.defer();
this._containerElement = $('
', {
'class': 'propertyUIControl'
});
this.$el.append(this._containerElement);
this._getGroupsAndRoles().then(function() {
var hierarchicalList = this._createHierarchicalList();
this._oPropertyUIControl = new PropertyUIControl({
'el': this.$el,
'glassContext': this.glassContext,
'items': [{
'type': 'Banner',
'name': 'GroupsAndRolesBanner',
'value': StringResource.get('preferencesGroupsAndRoles'),
'centerLabel': true,
'hintText': StringResource.get('preferencesGroupsAndRolesHintText'),
'backButton': true,
'editable': false,
'readOnly': true,
'onClose': function() {
this.slideout.hide();
}.bind(this)
}, {
'type': 'HierarchicalList',
'name': 'groups_and_roles',
'data': hierarchicalList
}]
});
this._oPropertyUIControl.render().done(deferred.resolve);
}.bind(this), function() {
this.slideout.hide();
}.bind(this));
return deferred.promise;
},
_getGroupsAndRoles: function() {
var deferred = Q.defer();
var url = 'v1/users/~/identity';
this.glassContext.services.ajax.ajax({
dataType: 'json',
type: 'GET',
url: url
}).then(function(response) {
var roles = [];
var groups = [];
response.data.forEach(function(anEl) {
if (anEl.type === 'role') {
roles.push(anEl);
} else if (anEl.type === 'group') {
groups.push(anEl);
}
}.bind(this));
if (groups.length > 0 || roles.length > 0) {
if (groups.length > 0) {
this.groups = groups;
}
if (roles.length > 0) {
this.roles = roles;
}
deferred.resolve();
} else {
deferred.reject();
}
}.bind(this), this._handleError.bind(this, deferred));
return deferred.promise;
},
/**
* Creates a hierarchical list - an array of parentobjects with array of chldren objects
* @private
*
*/
_createHierarchicalList: function() {
var listData = [];
// create the groups parent and children
var groupInfo = {
'defaultName': StringResource.get('policyFilterGroups')
};
var childInfo = [];
if (this.groups) {
for (var i = 0; i < this.groups.length; i += 1) {
childInfo.push({
'defaultName': this.groups[i].defaultName
});
}
groupInfo.children = _.sortBy(childInfo, 'defaultName');
listData.push(groupInfo);
}
// create the roles parent and children
var roleInfo = {
'defaultName': StringResource.get('policyFilterRoles')
};
if (this.roles) {
childInfo = [];
for (var j = 0; j < this.roles.length; j += 1) {
childInfo.push({
'defaultName': this.roles[j].defaultName
});
}
roleInfo.children = _.sortBy(childInfo, 'defaultName');
listData.push(roleInfo);
}
return listData;
},
/**
* Handles an Ajax error
* @private
*
*/
_handleError: function(deferred, dfd, jqXHR) {
GlassContextHelper.showAjaxServiceErrorMessage(this.glassContext, jqXHR);
deferred.reject();
}
});
return GroupsAndRolesView;
});
define("js/content_apps/preferencesBundle", function(){});