Migrated to bootstrap 3.0.x

This commit is contained in:
Alexis Lahouze
2013-12-06 20:36:26 +01:00
parent a300db9845
commit 5dd9543b38
12 changed files with 257 additions and 12105 deletions

View File

@ -112,6 +112,19 @@ var AccountController = function($scope, $http, $rootScope, $window) {
// Reload accounts to update solds.
$scope.loadAccounts();
}).error(function(data) {
if(data.error_type == 'validation') {
angular.forEach(data.errors, function(errors, field) {
// $scope.form[field].$setValidity('server', false);
//$scope.errors[field] = errors.join(', ');
});
} else {
$.pnotify({
type: "error",
title: "Save",
text: data.errors
});
}
});
};

View File

@ -17,6 +17,9 @@
var EntryController = function($scope, $http, $rootScope, $filter) {
// Entry store and selection
$scope.entries = [];
$scope.categories = [];
$scope.chartValues = [];
$scope.pieChartValues = [];
$scope.selectedItem = null;
$scope.account = null;
@ -61,15 +64,24 @@ var EntryController = function($scope, $http, $rootScope, $filter) {
}
});
$scope.chartValues = chartValues;
// Second pass: transform to an array readable by jqplot.
var pieChartValues = [];
angular.forEach(pieChartValuesTmp, function(value, key) {
pieChartValues.push([key, value]);
});
$scope.pieChartValues = pieChartValues;
//$scope.categories.length = 0;
//$scope.categories.concat(categories);
$scope.categories = categories;
$scope.drawChart({account: $scope.account, entries: chartValues}, "#entries-chart-placeholder");
$scope.drawPieChart(pieChartValues, "#expense-categories-chart-placeholder");
nv.addGraph($scope.drawChart);
nv.addGraph($scope.drawPieChart);
//$scope.drawPieChart(pieChartValues, "#expense-categories-chart-placeholder");
//$scope.drawPieChart();
};
$scope.getAccountStatus = function(account, month) {
@ -200,17 +212,17 @@ var EntryController = function($scope, $http, $rootScope, $filter) {
$scope.iconSaveClass = function(entry) {
if(!$scope.isSaved(entry)) {
return "icon-plus";
return "fa fa-plus";
} else if ($scope.isEditing(entry)) {
return "icon-ok";
return "fa fa-floppy-o";
}
};
$scope.iconCancelClass = function(entry) {
if($scope.isNew(entry)) {
return "icon-remove";
return "fa fa-times";
} else if ($scope.isEditing(entry)) {
return "icon-ban-circle";
return "fa fa-ban";
}
};
@ -330,13 +342,13 @@ var EntryController = function($scope, $http, $rootScope, $filter) {
};
// Function to draw the sold evolution chart.
$scope.drawChart = function(data, elementId) {
$scope.drawChart = function() {
// Clear previous chart
//var element = angular.element(elementId);
//element.html("");
//element.css("height", "0px");
var entries = data.entries;
var entries = $scope.chartValues;
console.debug("drawChart", entries);
var width = 700;
var height = 300;
//if(entries && entries.length > 1) {
// Prepare for today vertical line.
@ -346,27 +358,35 @@ var EntryController = function($scope, $http, $rootScope, $filter) {
// Find first and last days to set limits of the x axis.
var day = 24 * 60 * 60 * 1000;
var firstDate = $filter('date')(new Date(Date.parse(entries[0][0]).valueOf() - day), 'yyyy-MM-dd');
var lastDate = $filter('date')(new Date(Date.parse(entries[entries.length -1][0]).valueOf() + day), 'yyyy-MM-dd');
//var firstDate = new Date(Date.parse(entries[0][0]).valueOf() - day);
//var lastDate = new Date(Date.parse(entries[entries.length -1][0]).valueOf() + day);
// Plot chart, and store it in a window parameter for resize callback (need to be done better than it...)
var chart = nv.models.lineChart()
.x(function(d) { return d3.time.format("%Y-%m-%d").parse(d[0]); })
.y(function(d) { return new Number(d[1]); });
var chart = nv.models.lineChart().options({
x: function(d) { return d3.time.format("%Y-%m-%d").parse(d[0]); },
y: function(d) { return new Number(d[1]); },
transitionDuration: 250,
showXAxis: true,
showYAxis: true,
width: width,
height: height,
});
chart.lines.interpolate("monotone");
chart.xAxis.axisLabel("Date").tickFormat(function(d) {
return d3.time.format("%Y-%m-%d")(new Date(d));
});
chart.xAxis.scale().range([firstDate, lastDate]);
chart.xAxis
.axisLabel("Date")
.tickFormat(function(d) {
return d3.time.format("%Y-%m-%d")(new Date(d));
});
//chart.xAxis.scale().range([firstDate, lastDate]);
chart.yAxis.axisLabel("Solde").tickFormat(d3.format('.02f'));
chart.yAxis
.axisLabel("Solde")
.tickFormat(d3.format('.02f'));
// FIXME add vertical line for today
graph = d3.select(elementId + " svg").datum([
graph = d3.select("#entries-chart-placeholder").datum([
{ color: "orange", key: "Zero", values:[
[firstDate, "0"],
[lastDate, "0"]
@ -376,23 +396,40 @@ var EntryController = function($scope, $http, $rootScope, $filter) {
[lastDate, new Number($scope.account.authorized_overdraft)]
]},
{ color: "darkblue", key: "Sold evolution", values: entries},
]).transition().duration(1200).call(chart);
])
.transition().duration(1200)
.attr("width", width)
.attr("height", height)
.call(chart);
nv.utils.windowResize(chart.update);
return chart;
};
// Function to draw the expense category pie chart.
$scope.drawPieChart = function(entries, elementId) {
//if(entries && entries.length > 1) {
$scope.drawPieChart = function() {
// FIXME retrieve width and height from DOM
var width = 300;
var height = 300;
var chart = nv.models.pieChart()
.x(function(d) { return d[0]; })
.x(function(d) { console.debug(d); return d[0]; })
.y(function(d) { return d[1]; })
.width(width)
.height(height)
.showLabels(true);
d3.select(elementId + " svg").datum([{key: "Expenses", values: entries}]).transition().duration(1200).call(chart);
d3.select("#expense-categories-chart-placeholder")
.datum($scope.pieChartValues)
.transition().duration(1200)
.attr('width', width)
.attr('height', height)
.call(chart);
nv.utils.windowResize(chart.update);
//}
return chart
};
$rootScope.$on("monthsLoadedEvent", function(event, args){

View File

@ -62,17 +62,17 @@ var SchedulerController = function($scope, $http, $rootScope, $filter) {
$scope.iconSaveClass = function(operation) {
if($scope.isNew(operation)) {
return "icon-plus";
return "fa fa-plus";
} else if ($scope.isEditing(operation)) {
return "icon-ok";
return "fa fa-floppy-o";
}
};
$scope.iconCancelClass = function(operation) {
if($scope.isNew(operation)) {
return "icon-remove";
return "fa fa-times";
} else if ($scope.isEditing(operation)) {
return "icon-ban-circle";
return "fa fa-ban";
}
};