123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170 |
- /*
- *+------------------------------------------------------------------------+
- *| Licensed Materials - Property of IBM
- *| IBM Cognos Products: Content Explorer
- *| (C) Copyright IBM Corp. 2017, 2020
- *|
- *| US Government Users Restricted Rights - Use, duplication or disclosure
- *| restricted by GSA ADP Schedule Contract with IBM Corp.
- *+------------------------------------------------------------------------+
- */
- define([
- 'jquery',
- 'underscore',
- 'baglass/core-client/js/core-client/ui/properties/PropertyPageView',
- 'baglass/core-client/js/core-client/ui/dialogs/ConfirmationDialog',
- '../../nls/StringResources'
- ], function($, _, PropertyPageView, ConfirmationDialog, StringResources) {
- 'use strict';
- var AILearningConfigSlideout;
- AILearningConfigSlideout = PropertyPageView.extend({
- init: function (options) {
- AILearningConfigSlideout.inherited('init', this, arguments);
- _.extend(this, options);
- this.logger = this.glassContext.getCoreSvc('.Logger');
- this.ajaxSvc = this.glassContext.getCoreSvc('.Ajax');
- this.userProfile = this.glassContext.getCoreSvc('.UserProfile');
- },
- render: function () {
- this.$el.addClass('AILearningConfigPane');
- return this._hasLearningUsageData()
- .then( function(hasLearningUsageData) {
- return this.renderPropertyUIControl({
- 'ariaLabel': StringResources.get('AILearningConfigurationSlideoutAllyLabel'),
- 'glassContext': this.glassContext,
- 'el': this.$el,
- 'items': [{
- 'value': StringResources.get('AILearning_config_title'),
- 'type': 'Banner',
- 'backButton': true,
- 'centerLabel': true,
- 'onClose': this._onClose.bind(this),
- 'doClose': this._closeSlideout.bind(this)
- }, {
- 'type': 'HintText',
- 'name': 'TypeInHintText',
- 'visibility': 'visible',
- 'label': StringResources.get('AILearning_config_description')
- }, {
- 'name': 'implicit_learning',
- 'checked': this._isLearningEnabled(),
- 'label': StringResources.get('AILearning_active'),
- 'type': 'ToggleButton'
- }, {
- 'type': 'Separator'
- },{
- 'name': 'deleteProductUsage',
- 'type': 'SingleLineLinks',
- 'disabled': !hasLearningUsageData,
- 'items': [{
- 'align': 'left',
- 'items': [{
- 'type': 'text',
- 'name': 'deleteUsageDataText',
- 'value': StringResources.get('deleteUsageData')
- }]
- }, {
- 'align': 'right',
- 'items': [{
- 'type': 'icon',
- 'name': 'deleteUsageDataTextIcon',
- 'svgIcon': 'common-remove-trash',
- 'iconTooltip': StringResources.get('deleteUsageData'),
- 'role': 'button',
- 'clickCallback': this._showConfirmationDialog.bind(this)
- }]
- }]
- }]
- });
- }.bind(this));
- },
- _isLearningEnabled: function () {
- return this.userProfile.userProfileSettings.implicit_learning;
- },
- _showConfirmationDialog: function () {
- var dialog = new ConfirmationDialog(
- 'implicit_learning',
- StringResources.get('confirmDeletion'),
- StringResources.get( 'usageDataDeletionConfirmation'));
- dialog.confirm( this._deleteUsageData.bind(this) );
- },
- _deleteUsageData: function(){
- var options = {
- type: 'DELETE',
- 'headers': {
- 'Accept': 'application/json',
- 'Content-Type': 'application/json'
- },
- url: AILearningConfigSlideout.LEARNING
- };
- return this.ajaxSvc.ajax(options).then(function() {
- //Only disable the option if request is successful
- this.getPropertyUIControl().getProperty('deleteProductUsage').disable();
- }.bind(this));
- },
- _hasLearningUsageData: function(){
- var options = {
- type: 'GET',
- 'headers': {
- 'Accept': 'application/json',
- 'Content-Type': 'application/json'
- },
- url: AILearningConfigSlideout.LEARNING + '/status'
- };
- return this.ajaxSvc.ajax(options)
- .then(function(response){
- if( response && response.data ){
- return (response.data.recModelAvailable );
- }
- return false;
- }).catch( function(){
- //If request failed, just set it to false
- return Promise.resolve(false);
- });
- },
- _doSave: function () {
- if(!this.getPropertyUIControl().hasModifiedProperties()) {
- return Promise.resolve();
- }
- var modifiedProps = this.getPropertyUIControl().getModifiedProperties();
- var options = {
- type: 'PUT',
- 'headers': {
- 'Accept': 'application/json',
- 'Content-Type': 'application/json'
- },
- url: AILearningConfigSlideout.USER_PROFILE_SETTINGS,
- data: JSON.stringify( { implicit_learning : modifiedProps.implicit_learning })
- };
- return this.ajaxSvc.ajax(options)
- .then(function(){
- //Update glassContext if save is successful
- return this.userProfile.updateContext({ userProfileSettings: { implicit_learning: modifiedProps.implicit_learning } });
- }.bind(this));
- },
- _onClose: function () {
- this._doSave();
- },
- _closeSlideout: function () {
- this.slideout.hide();
- }
- });
- AILearningConfigSlideout.LEARNING = 'v1/smarts/user-actions/visualization/online';
- AILearningConfigSlideout.USER_PROFILE_SETTINGS = 'v1/users/~/user_profile_settings';
- return AILearningConfigSlideout;
- });
|