From 5dd9543b38b6bc972acc95001cc482d3c9c328c3 Mon Sep 17 00:00:00 2001 From: Alexis Lahouze Date: Fri, 6 Dec 2013 20:36:26 +0100 Subject: [PATCH] Migrated to bootstrap 3.0.x --- frontend/static/js/accounts.js | 13 + frontend/static/js/entries.js | 99 +- frontend/static/js/scheduler.js | 8 +- frontend/static/templates/account_edit.html | 16 +- frontend/static/templates/entry_remove.html | 32 - frontend/static/third-party/nv.d3/nv.d3.css | 656 - frontend/static/third-party/nv.d3/nv.d3.js | 11307 ---------------- .../static/third-party/nv.d3/nv.d3.min.js | 5 - frontend/templates/index.html | 98 +- frontend/templates/layout.html | 39 +- frontend/templates/remove_entry.html | 39 + frontend/templates/scheduler.html | 50 +- 12 files changed, 257 insertions(+), 12105 deletions(-) delete mode 100644 frontend/static/templates/entry_remove.html delete mode 100644 frontend/static/third-party/nv.d3/nv.d3.css delete mode 100644 frontend/static/third-party/nv.d3/nv.d3.js delete mode 100644 frontend/static/third-party/nv.d3/nv.d3.min.js create mode 100644 frontend/templates/remove_entry.html diff --git a/frontend/static/js/accounts.js b/frontend/static/js/accounts.js index db1befa..755f338 100644 --- a/frontend/static/js/accounts.js +++ b/frontend/static/js/accounts.js @@ -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 + }); + } }); }; diff --git a/frontend/static/js/entries.js b/frontend/static/js/entries.js index 0752a0f..e80cf27 100644 --- a/frontend/static/js/entries.js +++ b/frontend/static/js/entries.js @@ -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){ diff --git a/frontend/static/js/scheduler.js b/frontend/static/js/scheduler.js index 8ca4f74..1e40675 100644 --- a/frontend/static/js/scheduler.js +++ b/frontend/static/js/scheduler.js @@ -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"; } }; diff --git a/frontend/static/templates/account_edit.html b/frontend/static/templates/account_edit.html index fe1c099..1e0e3ee 100644 --- a/frontend/static/templates/account_edit.html +++ b/frontend/static/templates/account_edit.html @@ -21,18 +21,22 @@