From d872aa1985e0c06a6ab3645c792215f72c3ae2e8 Mon Sep 17 00:00:00 2001 From: Chris Houseknecht Date: Fri, 25 Jul 2014 10:25:37 -0400 Subject: [PATCH] local_config.js Look for local_config.js. If not found, load config.js. Set debug_mode to true and make other config changes locally without affecting production builds. --- .gitignore | 1 + awx/ui/static/js/app.js | 9 ++-- awx/ui/static/js/config.js | 70 ++++++++++++++------------ awx/ui/static/js/helpers/LoadConfig.js | 46 +++++++++++++++++ awx/ui/templates/ui/index.html | 2 +- 5 files changed, 92 insertions(+), 36 deletions(-) create mode 100644 awx/ui/static/js/helpers/LoadConfig.js diff --git a/.gitignore b/.gitignore index e5dacd51ef..c61b0d9786 100644 --- a/.gitignore +++ b/.gitignore @@ -7,6 +7,7 @@ awx/job_output awx/public/media awx/public/static awx/ui/static/js/awx.min.js +awx/ui/static/js/local_config.js awx/ui/static/css/awx.min.css awx/main/fixtures awx/tower_warnings.log diff --git a/awx/ui/static/js/app.js b/awx/ui/static/js/app.js index 16bbb8f9ca..ae6255a3e0 100644 --- a/awx/ui/static/js/app.js +++ b/awx/ui/static/js/app.js @@ -5,6 +5,7 @@ * */ var urlPrefix = $basePath; +var $AnsibleConfig; angular.module('Tower', [ 'ngRoute', @@ -99,7 +100,8 @@ angular.module('Tower', [ 'HostEventsViewerHelper', 'JobDetailHelper', 'SocketIO', - 'lrInfiniteScroll' + 'lrInfiniteScroll', + 'LoadConfigHelper' ]) .constant('AngularScheduler.partials', $basePath + 'lib/angular-scheduler/lib/') @@ -407,12 +409,13 @@ angular.module('Tower', [ }]) .run(['$compile', '$cookieStore', '$rootScope', '$log', 'CheckLicense', '$location', 'Authorization', 'LoadBasePaths', 'ViewLicense', - 'Timer', 'ClearScope', 'HideStream', 'Socket', + 'Timer', 'ClearScope', 'HideStream', 'Socket', 'LoadConfig', function ($compile, $cookieStore, $rootScope, $log, CheckLicense, $location, Authorization, LoadBasePaths, ViewLicense, - Timer, ClearScope, HideStream, Socket) { + Timer, ClearScope, HideStream, Socket, LoadConfig) { var e, html, sock, checkCount; + LoadConfig(); LoadBasePaths(); $rootScope.breadcrumbs = []; diff --git a/awx/ui/static/js/config.js b/awx/ui/static/js/config.js index 66255cf4da..d5aaad5979 100644 --- a/awx/ui/static/js/config.js +++ b/awx/ui/static/js/config.js @@ -5,49 +5,55 @@ * config.js * * Gobal configuration variables for controlling application behavior. + * + * Do NOT change this file, unless the changes should be included in + * production builds. For development, copy this file to local_config.js, + * and make changes. git will ignore local_config.js * */ /*jshint unused:false */ -var $AnsibleConfig = { +(function() { + return { - tooltip_delay: {show: 500, hide: 100}, // Default number of milliseconds to delay displaying/hiding tooltips + tooltip_delay: {show: 500, hide: 100}, // Default number of milliseconds to delay displaying/hiding tooltips - debug_mode: false, // Enable console logging messages + debug_mode: false, // Enable console logging messages - password_strength: 45, // User password strength. Integer between 0 and 100, 100 being impossibly strong. - // This value controls progress bar colors: - // 0 to password_strength - 15 = red; - // password_strength - 15 to password_strength = yellow - // > password_strength = green - // It also controls password validation. Passwords are rejected if the score is not > password_strength. + password_strength: 45, // User password strength. Integer between 0 and 100, 100 being impossibly strong. + // This value controls progress bar colors: + // 0 to password_strength - 15 = red; + // password_strength - 15 to password_strength = yellow + // > password_strength = green + // It also controls password validation. Passwords are rejected if the score is not > password_strength. - session_timeout: 1800, // Number of seconds before an inactive session is automatically timed out and forced to log in again. - // Separate from time out value set in API. + session_timeout: 1800, // Number of seconds before an inactive session is automatically timed out and forced to log in again. + // Separate from time out value set in API. - variable_edit_modes: { // Options we pass to ControlMirror for editing YAML/JSON variables - yaml: { - mode:"text/x-yaml", - matchBrackets: true, - autoCloseBrackets: true, - styleActiveLine: true, - lineNumbers: true, - gutters: ["CodeMirror-lint-markers"], - lint: true + variable_edit_modes: { // Options we pass to ControlMirror for editing YAML/JSON variables + yaml: { + mode:"text/x-yaml", + matchBrackets: true, + autoCloseBrackets: true, + styleActiveLine: true, + lineNumbers: true, + gutters: ["CodeMirror-lint-markers"], + lint: true + }, + json: { + mode: "application/json", + styleActiveLine: true, + matchBrackets: true, + autoCloseBrackets: true, + lineNumbers: true, + gutters: ["CodeMirror-lint-markers"], + lint: true + } }, - json: { - mode: "application/json", - styleActiveLine: true, - matchBrackets: true, - autoCloseBrackets: true, - lineNumbers: true, - gutters: ["CodeMirror-lint-markers"], - lint: true - } - }, - websocket_port: 8080 + websocket_port: 8080 -}; + }; +})(); diff --git a/awx/ui/static/js/helpers/LoadConfig.js b/awx/ui/static/js/helpers/LoadConfig.js new file mode 100644 index 0000000000..13ad0a08e1 --- /dev/null +++ b/awx/ui/static/js/helpers/LoadConfig.js @@ -0,0 +1,46 @@ +/********************************************* + * Copyright (c) 2014 AnsibleWorks, Inc. + * + * LoadConfigHelper + * + * Attempts to load local_config.js. If not found, loads config.js. Then evaluates the loaded + * javascript, putting the result in $AnsibleConfig. + * + */ + +/*jshint evil:true */ + +'use strict'; + +angular.module('LoadConfigHelper', ['Utilities']) + +.factory('LoadConfig', ['$rootScope', '$http', 'ProcessErrors', function($rootScope, $http, ProcessErrors) { + return function() { + + if ($rootScope.removeLoadConfig) { + $rootScope.removeLoadConfig(); + } + $rootScope.removeLoadConfig = $rootScope.$on('LoadConfig', function() { + // local_config.js not found, so we'll load config.js + $http({ method:'GET', url: $basePath + 'js/config.js' }) + .success(function(data) { + $AnsibleConfig = eval(data); + }) + .error(function(data, status) { + ProcessErrors($rootScope, data, status, null, { hdr: 'Error!', + msg: 'Failed to load ' + $basePath + '/config.js. GET status: ' + status + }); + }); + }); + + // Load js/local_config.js + $http({ method:'GET', url: $basePath + 'js/local_config.js' }) + .success(function(data) { + $AnsibleConfig = eval(data); + }) + .error(function() { + //local_config.js not found + $rootScope.$emit('LoadConfig'); + }); + }; +}]); \ No newline at end of file diff --git a/awx/ui/templates/ui/index.html b/awx/ui/templates/ui/index.html index 50a02af713..cf79d47651 100644 --- a/awx/ui/templates/ui/index.html +++ b/awx/ui/templates/ui/index.html @@ -25,7 +25,6 @@ - @@ -126,6 +125,7 @@ +