Replace horizon.conf with an angular one

Horizon configuration is now fully integrated into the angular
application. The object horizon.conf is still available in the
application in order to keep the compatibility, it is a link to the
angular constant object.

Change-Id: I55e1672a89a78032b24c096258471d0ea9d2489e
Implements: blueprint horizon-angular
This commit is contained in:
Maxime Vidori 2014-02-06 18:58:33 +01:00
parent 8d8e57b3f0
commit 2d591beff5
7 changed files with 76 additions and 61 deletions

View File

@ -0,0 +1,45 @@
/*global angular*/
(function () {
'use strict';
angular.module('hz.conf', [])
.constant('hzConfig', {
// Placeholders; updated by Django.
debug: null, //
static_url: null,
ajax: {
queue_limit: null
},
// Config options which may be overridden.
spinner_options: {
inline: {
lines: 10,
length: 5,
width: 2,
radius: 3,
color: '#000',
speed: 0.8,
trail: 50,
zIndex: 100
},
modal: {
lines: 10,
length: 15,
width: 4,
radius: 10,
color: '#000',
speed: 0.8,
trail: 50
},
line_chart: {
lines: 10,
length: 15,
width: 4,
radius: 11,
color: '#000',
speed: 0.8,
trail: 50
}
}
});
}());

View File

@ -1,6 +1,5 @@
var horizonApp = angular.module('horizonApp', [])
.config(function($interpolateProvider) {
var horizonApp = angular.module('hz', ['hz.conf'])
.config(['$interpolateProvider', function ($interpolateProvider) {
$interpolateProvider.startSymbol('{$');
$interpolateProvider.endSymbol('$}');
})
.constant('horizon', horizon);
}]);

View File

@ -1,40 +0,0 @@
horizon.conf = {
// Placeholders; updated by Django.
debug: null, //
static_url: null,
ajax: {
queue_limit: null
},
// Config options which may be overridden.
spinner_options: {
inline: {
lines: 10,
length: 5,
width: 2,
radius: 3,
color: '#000',
speed: 0.8,
trail: 50,
zIndex: 100
},
modal: {
lines: 10,
length: 15,
width: 4,
radius: 10,
color: '#000',
speed: 0.8,
trail: 50
},
line_chart: {
lines: 10,
length: 15,
width: 4,
radius: 11,
color: '#000',
speed: 0.8,
trail: 50
}
}
};

View File

@ -43,7 +43,7 @@ horizon.utils = {
},
loadAngular: function (element) {
angular.injector(['ng', 'horizonApp']).
angular.injector(['ng', 'hz']).
invoke(['$rootScope', '$compile', function ($rootScope, $compile) {
try {
$compile(element)($rootScope);

View File

@ -13,7 +13,7 @@
{% include "horizon/client_side/_script_loader.html" %}
{% include "horizon/_custom_head_js.html" %}
</head>
<body id="{% block body_id %}{% endblock %}" ng-app='horizonApp'>
<body id="{% block body_id %}{% endblock %}" ng-app='hz'>
{% block content %}
<div id="container">
{% block sidebar %}

View File

@ -1,21 +1,35 @@
{% load compress %}
{% compress js %}
<script src='{{ STATIC_URL }}horizon/lib/jquery/jquery.min.js' type='text/javascript' charset="utf-8"></script>
<script src="{{ STATIC_URL }}horizon/lib/angular.js" type="text/javascript" charset="utf-8"></script>
<script src='{{ STATIC_URL }}horizon/js/horizon.js' type='text/javascript' charset='utf-8'></script>
<script src='{{ STATIC_URL }}horizon/js/horizon.conf.js' type='text/javascript' charset='utf-8'></script>
<script src='{{ STATIC_URL }}horizon/js/angular/horizon.js' type='text/javascript' charset='utf-8'></script>
<script type='text/javascript' charset='utf-8'>
/* Storage for backend configuration variables which the frontend
* should be aware of.
*/
horizon.conf.debug = {{ debug|yesno:"true,false" }};
horizon.conf.static_url = "{{ STATIC_URL }}";
horizon.conf.ajax = {
queue_limit: {{ HORIZON_CONFIG.ajax_queue_limit|default:"null" }}
};
horizon.conf.auto_fade_alerts = {
delay: {{ HORIZON_CONFIG.auto_fade_alerts.delay|default:"3000" }},
fade_duration: {{ HORIZON_CONFIG.auto_fade_alerts.fade_duration|default:"1500" }},
types: {{ HORIZON_CONFIG.auto_fade_alerts.types|default:"[]"|safe }}
};
horizonApp
.config(['hzConfig', function (hzConfig) {
hzConfig.debug = {{ debug|yesno:"true,false" }};
hzConfig.static_url = "{{ STATIC_URL }}";
hzConfig.ajax = {
queue_limit: {{ HORIZON_CONFIG.ajax_queue_limit|default:"null" }}
};
hzConfig.auto_fade_alerts = {
delay: {{ HORIZON_CONFIG.auto_fade_alerts.delay|default:"3000" }},
fade_duration: {{ HORIZON_CONFIG.auto_fade_alerts.fade_duration|default:"1500" }},
types: {{ HORIZON_CONFIG.auto_fade_alerts.types|default:"[]"|safe }}
};
}])
.run(['hzConfig', function (hzConfig) {
//expose the configuration for horizon legacy variable
horizon.conf = hzConfig;
}]);
</script>
{% endcompress %}

View File

@ -6,12 +6,9 @@
{% comment %} Compress jQuery, Angular, Plugins, Bootstrap, Hogan.js and Horizon-specific JS. {% endcomment %}
{% compress js %}
<script src='{{ STATIC_URL }}horizon/lib/jquery/jquery.min.js' type='text/javascript' charset="utf-8"></script>
<script src="{{ STATIC_URL }}horizon/lib/angular.js" type="text/javascript" charset="utf-8"></script>
<script src='{{ STATIC_URL }}horizon/js/angular/horizon.js' type='text/javascript' charset='utf-8'></script>
<script src='{{ STATIC_URL }}horizon/js/angular/controllers/dummy.js' type='text/javascript' charset='utf-8'></script>
<script src='{{ STATIC_URL }}horizon/js/angular/directives/forms.js' type='text/javascript' charset='utf-8'></script>
<script src='{{ STATIC_URL }}horizon/js/angular/horizon.conf.js' type='text/javascript' charset='utf-8'></script>
<script src='{{ STATIC_URL }}horizon/lib/jquery/jquery.cookie.js' type='text/javascript' charset="utf-8"></script>
<script src='{{ STATIC_URL }}horizon/lib/jquery/jquery.quicksearch.js' type='text/javascript' charset="utf-8"></script>