admin home stats

This commit is contained in:
Etienne Roudeix
2013-10-30 17:00:38 +01:00
committed by Manuel Raynaud
parent bc454124f3
commit 689de106c7
2 changed files with 115 additions and 115 deletions

View File

@@ -43,7 +43,7 @@ class HomeController extends BaseAdminController
{ {
$data = new \stdClass(); $data = new \stdClass();
$data->title = "Stats on [...]"; $data->title = "Stats on " . $this->getRequest()->request->get('month', date('m')) . "/" . $this->getRequest()->request->get('month', date('Y'));
/* sales */ /* sales */
$saleSeries = new \stdClass(); $saleSeries = new \stdClass();

View File

@@ -266,133 +266,133 @@
<script type="text/javascript" src="{$asset_url}"></script> <script type="text/javascript" src="{$asset_url}"></script>
{/javascripts} {/javascripts}
<script> <script>
(function($, window, document){ jQuery(function($){
$(function(){ var $elem = $('#jqplot');
var $elem = $('#jqplot'); var url = "{url path='/admin/home/stats'}",
series = [],
seriesColors = [],
ticks = [],
days = 0,
jqplot;
var url = "{url path='/admin/home/stats'}", var options = {
series = [], animate: true,
seriesColors = [], axesDefaults: {
ticks = [], tickOptions: { showMark: true, showGridline: true }
days = 0, },
jqplot; axes: {
xaxis: {
borderColor: '#ccc',
ticks : ticks,
tickOptions: { showGridline: false }
},
yaxis: {
tickOptions: { showGridline: true, showMark: false, showLabel: false, shadow: false }
}
},
seriesDefaults: {
lineWidth: 3,
shadow : false,
markerOptions: { shadow : false, style: 'filledCircle', size: 12 }
},
grid: {
background: '#FFF',
shadow : false,
borderColor : '#FFF'
},
highlighter: {
show: true,
sizeAdjust: 7,
tooltipLocation: 'n',
tooltipContentEditor: function(str, seriesIndex, pointIndex, plot){
var options = { // Return axis value : data value
animate: true, return ticks[pointIndex][1] + ': ' + plot.data[seriesIndex][pointIndex][1];
axesDefaults: { }
tickOptions: { showMark: true, showGridline: true } }
}, };
axes: {
xaxis: {
borderColor: '#ccc',
ticks : ticks,
tickOptions: { showGridline: false }
},
yaxis: {
tickOptions: { showGridline: true, showMark: false, showLabel: false, shadow: false }
}
},
seriesDefaults: {
lineWidth: 3,
shadow : false,
markerOptions: { shadow : false, style: 'filledCircle', size: 12 }
},
grid: {
background: '#FFF',
shadow : false,
borderColor : '#FFF'
},
highlighter: {
show: true,
sizeAdjust: 7,
tooltipLocation: 'n',
tooltipContentEditor: function(str, seriesIndex, pointIndex, plot){
// Return axis value : data value // Get initial data Json
return ticks[pointIndex][1] + ': ' + plot.data[seriesIndex][pointIndex][1]; $.getJSON(url)
} .done(jsonSuccessLoad)
} .fail(jsonFailLoad);
};
// Get data Json
$.getJSON(url)
.done(function(data) {
// Init series data and colors
initJqplotData(series, seriesColors, options, data);
// Add days to xaxis
for(var i = 1; i < (days+1); i++){
ticks.push([i-1, i]);
}
// Start jqplot
var elementId = $elem.attr('id');
jqplot = $.jqplot(elementId, series, options);
$('[data-toggle="jqplot"]').each(function(){
$(this).click(function(){
if($('[data-toggle="jqplot-serie"].active').length > 1 || !$(this).hasClass('active')){
// Active button and jqplot-serie management
$(this).toggleClass('active');
var id = $(this).data('target');
$('[data-toggle="jqplot-serie"]#' + id).toggleClass('active');
// Reinit variables
series = [];
seriesColors = [];
// Init series data and colors
initJqplotData(series, seriesColors, options, data);
// Restart jqplot
jqplot.destroy();
jqplot = $.jqplot(elementId, series, options);
}
});
});
$(window).bind('resize', function(event, ui) {
jqplot.replot( { resetAxes: true } );
});
})
.fail(function() {
$elem.append('<div class="alert alert-danger">An error occurred while reading from JSON file</div>');
});
function initJqplotData(series, seriesColors, options, json){ function initJqplotData(series, seriesColors, options, json){
$('[data-toggle="jqplot-serie"].active').each(function(i){ $('[data-toggle="jqplot-serie"].active').each(function(i){
var position = $(this).index() - 1; var position = $(this).index() - 1;
series.push(json.series[position].data); series.push(json.series[position].data);
seriesColors.push(json.series[position].color); seriesColors.push(json.series[position].color);
}); });
// Number of days to display ( = data.length in one serie) // Number of days to display ( = data.length in one serie)
days = json.series[0].data.length; days = json.series[0].data.length;
// Graph title // Graph title
options.title = json.title; options.title = json.title;
// Graph series colors // Graph series colors
options.seriesColors = seriesColors; options.seriesColors = seriesColors;
} }
}); function jsonFailLoad(data) {
$elem.append('<div class="alert alert-danger">An error occurred while reading from JSON file</div>');
}
}(window.jQuery, window, document)); function jsonSuccessLoad(data) {
</script> // Init series data and colors
initJqplotData(series, seriesColors, options, data);
// Add days to xaxis
for(var i = 1; i < (days+1); i++){
ticks.push([i-1, i]);
}
// Start jqplot
var elementId = $elem.attr('id');
jqplot = $.jqplot(elementId, series, options);
$('[data-toggle="jqplot"]').each(function(){
$(this).click(function(){
if($('[data-toggle="jqplot-serie"].active').length > 1 || !$(this).hasClass('active')){
// Active button and jqplot-serie management
$(this).toggleClass('active');
var id = $(this).data('target');
$('[data-toggle="jqplot-serie"]#' + id).toggleClass('active');
// Reinit variables
series = [];
seriesColors = [];
// Init series data and colors
initJqplotData(series, seriesColors, options, data);
// Restart jqplot
jqplot.destroy();
jqplot = $.jqplot(elementId, series, options);
}
});
});
$(window).bind('resize', function(event, ui) {
jqplot.replot( { resetAxes: true } );
});
}
});
</script>
{/javascripts} {/javascripts}
{/block} {/block}