Get mapped fields (Github and Redis) working
This commit is contained in:
parent
219730c341
commit
32c0a14d96
4 changed files with 117 additions and 35 deletions
|
@ -11,6 +11,7 @@ angular.module("core-config-setup", ['angularFileUpload'])
|
|||
},
|
||||
controller: function($rootScope, $scope, $element, $timeout, ApiService) {
|
||||
$scope.config = null;
|
||||
$scope.mapped = {};
|
||||
|
||||
$scope.parseDbUri = function(value) {
|
||||
if (!value) { return null; }
|
||||
|
@ -41,11 +42,89 @@ angular.module("core-config-setup", ['angularFileUpload'])
|
|||
return uri;
|
||||
};
|
||||
|
||||
var githubSelector = function(key) {
|
||||
return function(value) {
|
||||
if (!value || !$scope.config) { return; }
|
||||
|
||||
if (!$scope.config[key]) {
|
||||
$scope.config[key] = {};
|
||||
}
|
||||
|
||||
if (value == 'enterprise') {
|
||||
$scope.config[key]['GITHUB_ENDPOINT'] = '';
|
||||
$scope.config[key]['API_ENDPOINT'] = '';
|
||||
} else if (value == 'hosted') {
|
||||
$scope.config[key]['GITHUB_ENDPOINT'] = 'https://github.com/';
|
||||
$scope.config[key]['API_ENDPOINT'] = 'https://api.github.com/';
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
var getKey = function(config, path) {
|
||||
var parts = path.split('.');
|
||||
var current = config;
|
||||
for (var i = 0; i < parts.length; ++i) {
|
||||
var part = parts[i];
|
||||
if (!config[part]) { return null; }
|
||||
current = config[part];
|
||||
}
|
||||
return current;
|
||||
};
|
||||
|
||||
var initializeMappedLogic = function(config) {
|
||||
var gle = getKey(config, 'GITHUB_LOGIN_CONFIG.GITHUB_ENDPOINT');
|
||||
var gte = getKey(config, 'GITHUB_TRIGGER_CONFIG.GITHUB_ENDPOINT');
|
||||
|
||||
$scope.mapped['GITHUB_LOGIN_KIND'] = gle == 'https://github.com/' ? 'hosted' : 'enterprise';
|
||||
$scope.mapped['GITHUB_TRIGGER_KIND'] = gte == 'https://github.com/' ? 'hosted' : 'enterprise';
|
||||
|
||||
$scope.mapped['redis'] = {};
|
||||
$scope.mapped['redis']['host'] = getKey(config, 'BUILDLOGS_REDIS.host') || getKey(config, 'USER_EVENTS_REDIS.host');
|
||||
$scope.mapped['redis']['port'] = getKey(config, 'BUILDLOGS_REDIS.port') || getKey(config, 'USER_EVENTS_REDIS.port');
|
||||
$scope.mapped['redis']['password'] = getKey(config, 'BUILDLOGS_REDIS.password') || getKey(config, 'USER_EVENTS_REDIS.password');
|
||||
};
|
||||
|
||||
var redisSetter = function(keyname) {
|
||||
return function(value) {
|
||||
if (value == null || !$scope.config) { return; }
|
||||
|
||||
if (!$scope.config['BUILDLOGS_REDIS']) {
|
||||
$scope.config['BUILDLOGS_REDIS'] = {};
|
||||
}
|
||||
|
||||
if (!$scope.config['USER_EVENTS_REDIS']) {
|
||||
$scope.config['USER_EVENTS_REDIS'] = {};
|
||||
}
|
||||
|
||||
if (!value) {
|
||||
delete $scope.config['BUILDLOGS_REDIS'][keyname];
|
||||
delete $scope.config['USER_EVENTS_REDIS'][keyname];
|
||||
return;
|
||||
}
|
||||
|
||||
$scope.config['BUILDLOGS_REDIS'][keyname] = value;
|
||||
$scope.config['USER_EVENTS_REDIS'][keyname] = value;
|
||||
};
|
||||
};
|
||||
|
||||
// Add mapped logic.
|
||||
$scope.$watch('mapped.GITHUB_LOGIN_KIND', githubSelector('GITHUB_LOGIN_CONFIG'));
|
||||
$scope.$watch('mapped.GITHUB_TRIGGER_KIND', githubSelector('GITHUB_TRIGGER_CONFIG'));
|
||||
|
||||
$scope.$watch('mapped.redis.host', redisSetter('host'));
|
||||
$scope.$watch('mapped.redis.port', redisSetter('port'));
|
||||
$scope.$watch('mapped.redis.password', redisSetter('password'));
|
||||
|
||||
$scope.$watch('config', function(value) {
|
||||
window.console.log(value);
|
||||
}, true);
|
||||
|
||||
$scope.$watch('isActive', function(value) {
|
||||
if (!value) { return; }
|
||||
|
||||
ApiService.scGetConfig().then(function(resp) {
|
||||
$scope.config = resp['config'];
|
||||
initializeMappedLogic($scope.config);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
|
Reference in a new issue