diff --git a/accountant/frontend/__init__.py b/accountant/frontend/__init__.py index bb30311..ae78e2c 100644 --- a/accountant/frontend/__init__.py +++ b/accountant/frontend/__init__.py @@ -1,4 +1,4 @@ -from flask import Blueprint, redirect, render_template, jsonify +from flask import Blueprint, render_template frontend = Blueprint( 'frontend', @@ -8,26 +8,7 @@ frontend = Blueprint( ) -@frontend.route('/') -def root(): - return redirect('entries') - - -@frontend.route('/entries') -def entries(): - return render_template('entries.html') - - -@frontend.route('/scheduler') -def scheduler(): - return render_template('scheduler.html') - - -@frontend.route('/accounts') -def accounts(): - return render_template('accounts.html') - - -@frontend.errorhandler(BaseException) -def default_errorhandler(error): - return jsonify(title="Error", text="Error %s" % str(error)), 500 +@frontend.route('/', defaults={'path': 'accounts'}) +@frontend.route('/') +def index(path): + return render_template('layout.html') diff --git a/accountant/frontend/static/js/app.js b/accountant/frontend/static/js/app.js index ad66a35..60b56e0 100644 --- a/accountant/frontend/static/js/app.js +++ b/accountant/frontend/static/js/app.js @@ -20,7 +20,7 @@ var accountantApp = angular.module("accountantApp", [ "highcharts-ng" ]) -.config(function($interpolateProvider, $httpProvider) { +.config(function($interpolateProvider, $httpProvider, $routeProvider, $locationProvider) { $interpolateProvider.startSymbol('[['); $interpolateProvider.endSymbol(']]'); @@ -47,4 +47,20 @@ var accountantApp = angular.module("accountantApp", [ } }; }); -}); + + $routeProvider.when('/account/:accountId/entries', { + templateUrl: 'static/templates/entries.html', + controller: 'EntryController' + }).when('/account/:accountId/scheduler', { + templateUrl: 'static/templates/scheduler.html', + controller: 'SchedulerController' + }).when('/accounts', { + templateUrl: 'static/templates/accounts.html', + controller: 'AccountController' + }).when('/', { + redirectTo: 'accounts' + }); + + $locationProvider.html5Mode(true); +}) +; diff --git a/accountant/frontend/static/js/entries.js b/accountant/frontend/static/js/entries.js index 40cc316..6e0139d 100644 --- a/accountant/frontend/static/js/entries.js +++ b/accountant/frontend/static/js/entries.js @@ -26,8 +26,8 @@ accountantApp .controller( "EntryController", [ - "$scope", "$http", "$rootScope", "$filter", "Entries", - function($scope, $http, $rootScope, $filter, Entries) { + "$scope", "$http", "$rootScope", "$filter", "$routeParams", "Entries", + function($scope, $http, $rootScope, $filter, $routeParams, Entries) { // Range for entries. $scope.begin = moment.utc().startOf('month'); $scope.end = moment.utc().endOf('month'); @@ -272,24 +272,23 @@ accountantApp * Hook on account selected event to display account status. */ $rootScope.$on("accountSelectedEvent", function(event, args) { - $scope.account = args.account; - - $scope.getAccountStatus(); + $scope.getAccountStatus($routeParams.accountId); }); $rootScope.$on("rangeSelectedEvent", function(event, args) { - $scope.getAccountStatus(); + $scope.getAccountStatus($routeParams.accountId); }); - $scope.getAccountStatus = function() { + $scope.getAccountStatus = function(accountId) { $scope.categoriesChartConfig.loading = true; - $http.get("/api/accounts/" + $scope.account.id, { + $http.get("/api/accounts/" + accountId, { params: { begin: $scope.begin.format('YYYY-MM-DD'), end: $scope.end.format('YYYY-MM-DD') } }).success(function(account) { + $scope.account = account; $scope.categoriesChartConfig.loading = false; $scope.$emit("accountLoadedEvent", account); @@ -513,4 +512,6 @@ accountantApp modalScope.dismiss(); } }; + + $scope.getAccountStatus($routeParams.accountId); }]); diff --git a/accountant/frontend/static/js/scheduler.js b/accountant/frontend/static/js/scheduler.js index be28d3f..f7908b7 100644 --- a/accountant/frontend/static/js/scheduler.js +++ b/accountant/frontend/static/js/scheduler.js @@ -15,28 +15,20 @@ along with Accountant. If not, see . */ accountantApp.controller( - "SchedulerController", function($scope, $http, $rootScope, $filter) { + "SchedulerController", function($scope, $http, $rootScope, $filter, $routeParams) { // Operations store and selection $scope.operations = []; $scope.selectedOperation = null; - $scope.account = null; - // Placeholder for saved value to cancel entry edition $scope.savedOperation = null; - $scope.loadOperations = function(account) { + $scope.loadOperations = function(accountId) { // Clean up selected entry. $scope.selectedOperation = null; $scope.savedOperation = null; - if(account) { - $scope.account = account; - - $http.get("/api/scheduled_operations/" + account.id).success($scope.loadOperations_success); - } else { - $scope.loadOperations_success(null); - } + $http.get("/api/scheduled_operations/" + accountId).success($scope.loadOperations_success); }; $scope.loadOperations_success = function(data) { @@ -92,7 +84,7 @@ accountantApp.controller( $scope.saveOperation = function(operation) { if(!operation.account_id) { - operation.account_id = $scope.account.id; + operation.account_id = $routeParams.accountId; } // prepare the Ajax xall to save the sceduled operation. @@ -138,7 +130,7 @@ accountantApp.controller( operation.label = null; operation.value = null; operation.category = null; - operation.account_id = $scope.account.id; + operation.account_id = $routeParams.accountId; } else if ($scope.isEditing(operation)) { if($scope.savedOperation) { operation.id = $scope.savedOperation.id; @@ -193,6 +185,8 @@ accountantApp.controller( }; $rootScope.$on("accountSelectedEvent", function(event, args){ - $scope.loadOperations(args.account); + $scope.loadOperations(args.account.id); }); + + $scope.loadOperations($routeParams.accountId); }); diff --git a/accountant/frontend/templates/accounts.html b/accountant/frontend/static/templates/accounts.html similarity index 94% rename from accountant/frontend/templates/accounts.html rename to accountant/frontend/static/templates/accounts.html index 3cfffb4..0b615d3 100644 --- a/accountant/frontend/templates/accounts.html +++ b/accountant/frontend/static/templates/accounts.html @@ -1,4 +1,4 @@ -{# + + -
+
@@ -77,5 +74,3 @@
- -{% endblock %} diff --git a/accountant/frontend/templates/entries.html b/accountant/frontend/static/templates/entries.html similarity index 94% rename from accountant/frontend/templates/entries.html rename to accountant/frontend/static/templates/entries.html index 672ed88..30d8254 100644 --- a/accountant/frontend/templates/entries.html +++ b/accountant/frontend/static/templates/entries.html @@ -1,5 +1,4 @@ -{# vim: set tw=80 ts=2 sw=2 sts=2: #} -{# + +
@@ -45,7 +41,7 @@ - {# The new entry row. #} + @@ -88,7 +84,7 @@ - {# Row for an editing entry. #} + @@ -131,7 +127,7 @@ - {# Row for a displayed entry. #} + @@ -156,7 +152,7 @@ - {# Button group for a saved entry. #} +
- {# Button group for an unsaved (scheduled) entry. #} +
- -{% include "remove_entry.html" %} - -
-{% endblock %} diff --git a/accountant/frontend/templates/scheduler.html b/accountant/frontend/static/templates/scheduler.html similarity index 92% rename from accountant/frontend/templates/scheduler.html rename to accountant/frontend/static/templates/scheduler.html index de39d08..111bf10 100644 --- a/accountant/frontend/templates/scheduler.html +++ b/accountant/frontend/static/templates/scheduler.html @@ -1,4 +1,4 @@ -{# + + -
+
@@ -88,7 +86,7 @@ - @@ -97,4 +95,3 @@
-{% endblock %} diff --git a/accountant/frontend/templates/layout.html b/accountant/frontend/templates/layout.html index 0ed7c53..3d40b66 100644 --- a/accountant/frontend/templates/layout.html +++ b/accountant/frontend/templates/layout.html @@ -21,18 +21,20 @@ Entries + + - + + - + - - + @@ -48,12 +50,12 @@