120 lines
6.0 KiB
JavaScript
120 lines
6.0 KiB
JavaScript
"use strict";
|
|
/**
|
|
* Created by mkumar1 on 31-01-2018.
|
|
*/
|
|
(function () {
|
|
'use strict';
|
|
angular.module('adminModule')
|
|
.controller('ProviderConfigurationController', ['$filter', '$modal', '$rootScope', '$scope', '$log', '$q', '$state', 'events', 'adminConsoleConfigurationModel', 'systemAlertService', '$timeout', 'configurationModel',
|
|
function ($filter, $modal, $rootScope, $scope, $log, $q, $state, events, adminConsoleConfigurationModel, systemAlertService, $timeout, configurationModel) {
|
|
$scope.settingsLabelData = $scope.sideMenuItems = configurationModel.get('adminConsoleConfig.settingsLabelMapping');
|
|
$scope.providerData = _.cloneDeep($scope.displayData);
|
|
$scope.formHolder = {};
|
|
$scope.providerStatusChange = function (provider) {
|
|
if (provider.instanceName !== 'mcsm') {
|
|
return false;
|
|
}
|
|
$scope.dataLoading = true;
|
|
adminConsoleConfigurationModel.providerEnableStatusChange(provider).then(function (res) {
|
|
provider.enabled = !provider.enabled;
|
|
systemAlertService.success({ text: $filter('i18n')('console.config.providers.update.success'), clear: true, hide: 5000 });
|
|
$scope.dataLoading = false;
|
|
});
|
|
};
|
|
$scope.pagination = {
|
|
totalItems: $scope.providerData.length,
|
|
currentPage: 1,
|
|
numPerPage: 10
|
|
};
|
|
$scope.paginate = function (value) {
|
|
var begin, end, index;
|
|
begin = ($scope.pagination.currentPage - 1) * $scope.pagination.numPerPage;
|
|
end = begin + $scope.pagination.numPerPage;
|
|
index = $scope.providerData.indexOf(value);
|
|
return (begin <= index && index < end);
|
|
};
|
|
$scope.isSelectedRow = null;
|
|
$scope.settingsDisplay = function (data) {
|
|
if (data.settings.length == 0) {
|
|
$scope.showSettings = false;
|
|
return false;
|
|
}
|
|
else {
|
|
$scope.showSettings = true;
|
|
$scope.isSelectedRow = data.id;
|
|
$scope.nativeSettings = data.settings;
|
|
$scope.settingsData = _.cloneDeep(data.settings);
|
|
$scope.oldSettings = _.cloneDeep(data.settings);
|
|
}
|
|
};
|
|
$scope.flipCheckbox = function (setting) {
|
|
setting.value = (setting.value === 'true') ? 'false' : 'true';
|
|
$scope.formHolder.providerSettingsForm.$dirty = true;
|
|
};
|
|
$scope.submitSettings = function () {
|
|
if ($scope.formHolder.providerSettingsForm.$dirty) {
|
|
var diffArray = [], sendBlankPassword = true, passwordObj = null;
|
|
_.each($scope.settingsData, function (setting) {
|
|
_.each($scope.oldSettings, function (old) {
|
|
if (old.id === setting.id && old.value !== setting.value) {
|
|
diffArray.push(setting);
|
|
}
|
|
});
|
|
if (setting.key === "mcsm.password" && setting.value === null) {
|
|
passwordObj = setting;
|
|
}
|
|
});
|
|
if (diffArray.length) {
|
|
_.each(diffArray, function (dif) {
|
|
dif.changed = true;
|
|
dif.displayName = dif.key;
|
|
dif.order = 500;
|
|
if (dif.key === "mcsm.password") {
|
|
sendBlankPassword = false;
|
|
}
|
|
});
|
|
}
|
|
if (passwordObj && sendBlankPassword) {
|
|
passwordObj.changed = true;
|
|
passwordObj.displayName = passwordObj.key;
|
|
passwordObj.order = 500;
|
|
passwordObj.value = "";
|
|
diffArray.push(passwordObj);
|
|
}
|
|
$scope.dataLoading = true;
|
|
adminConsoleConfigurationModel.updateProviderSettings(diffArray).then(function (res) {
|
|
if (res) {
|
|
_.forEach(res, function (r) {
|
|
var s1 = _.find($scope.settingsData, { 'id': r.id });
|
|
var s2 = _.find($scope.nativeSettings, { 'id': r.id });
|
|
s1.value = r.value;
|
|
s2.value = r.value;
|
|
});
|
|
}
|
|
$scope.oldSettings = angular.copy($scope.settingsData);
|
|
systemAlertService.success({ text: $filter('i18n')('console.config.settings.update.success'), clear: true, hide: 5000 });
|
|
$scope.dataLoading = false;
|
|
});
|
|
}
|
|
};
|
|
$scope.reloadProviders = function () {
|
|
$scope.dataLoading = true;
|
|
adminConsoleConfigurationModel.reloadProviders().then(function (res) {
|
|
systemAlertService.success({ text: $filter('i18n')('console.config.providers.reload.success'), clear: true, hide: 5000 });
|
|
$timeout(function () {
|
|
$state.reload();
|
|
$scope.dataLoading = false;
|
|
}, 2000);
|
|
});
|
|
};
|
|
$scope.getValidLabel = function (setting) {
|
|
var validLabel = !_.isUndefined($scope.settingsLabelData[setting.key]) ? $scope.settingsLabelData[setting.key] : setting.key;
|
|
return validLabel;
|
|
};
|
|
$scope.getValidInputType = function (setting) {
|
|
return (setting.key.indexOf('password') !== -1) ? 'password' : 'text';
|
|
};
|
|
}
|
|
]);
|
|
})();
|