81 lines
4.2 KiB
JavaScript
81 lines
4.2 KiB
JavaScript
"use strict";
|
|
(function () {
|
|
'use strict';
|
|
angular.module('myitsmApp')
|
|
.factory('gainsightModel', ['gainsightService', '$q', '$modal',
|
|
function (gainsightService, $q, $modal) {
|
|
var gainsightModel = {
|
|
cache: {}
|
|
};
|
|
gainsightModel.getTelemetryConfiguration = function () {
|
|
if (gainsightModel.cache.telemetryConfig) {
|
|
var isPromise = _.has(gainsightModel.cache.telemetryConfig, '$$state.status');
|
|
return $q.when(isPromise ? gainsightModel.cache.telemetryConfig : angular.copy(gainsightModel.cache.telemetryConfig));
|
|
}
|
|
gainsightModel.cache.telemetryConfig = gainsightService.getTelemetryConfiguration().then(function (config) {
|
|
gainsightModel.cache.telemetryConfig = config;
|
|
return config;
|
|
});
|
|
return gainsightModel.cache.telemetryConfig;
|
|
};
|
|
gainsightModel.getUserPreference = function () {
|
|
return gainsightService.getUserPreference();
|
|
};
|
|
gainsightModel.setUserPreference = function (userPreferences) {
|
|
return gainsightService.setUserPreference(userPreferences);
|
|
};
|
|
gainsightModel.showOptinConfig = function () {
|
|
var loadingModal = $modal.open({
|
|
templateUrl: 'views/gainsight/gainsight-user-preference.html',
|
|
windowClass: 'bmc-system-analytics-modal',
|
|
size: 'md',
|
|
controller: ['$scope', '$filter', 'getData', 'gainsightModel', 'systemAlertService', function ($scope, $filter, getData, gainsightModel, systemAlertService) {
|
|
$scope.data = getData;
|
|
$scope.data.label = $filter('i18n')('user.preference.dataCollection.enable.label');
|
|
$scope.dataLoading = true;
|
|
$scope.dataSaving = false;
|
|
var userPreferences;
|
|
gainsightModel.getUserPreference().then(function (userPreferenceResp) {
|
|
$scope.data.value = userPreferenceResp.trackUsage === null ? true : userPreferenceResp.trackUsage;
|
|
userPreferences = userPreferenceResp;
|
|
$scope.dataLoading = false;
|
|
});
|
|
$scope.saveOptin = function () {
|
|
userPreferences.trackUsage = $scope.data.value;
|
|
$scope.dataSaving = true;
|
|
gainsightModel.setUserPreference(userPreferences).then(function (resp) {
|
|
userPreferences = resp.responseObject;
|
|
$scope.dataSaving = false;
|
|
if (resp.statusInfo.number === 2000) {
|
|
systemAlertService.success({
|
|
text: $filter('i18n')('user.preference.dataCollection.successMessage'),
|
|
clear: true,
|
|
hide: 5000
|
|
});
|
|
loadingModal.close();
|
|
}
|
|
else {
|
|
systemAlertService.error({
|
|
text: resp.statusInfo && resp.statusInfo.message,
|
|
clear: false
|
|
});
|
|
}
|
|
});
|
|
};
|
|
}],
|
|
resolve: {
|
|
getData: function () {
|
|
return {
|
|
name: "optin",
|
|
isRequired: true,
|
|
value: false
|
|
};
|
|
}
|
|
}
|
|
});
|
|
return loadingModal;
|
|
};
|
|
return gainsightModel;
|
|
}]);
|
|
})();
|