mirror of
https://github.com/Febbweiss/CloudBudget-AngularJS.git
synced 2026-03-04 22:35:38 +00:00
Feature: add account switch
This commit is contained in:
@@ -12,7 +12,7 @@
|
||||
if( !input ) {
|
||||
return '';
|
||||
}
|
||||
var category = categories.filter(function(elt, idx) {
|
||||
var category = categories.filter(function(elt) {
|
||||
return elt._id === input;
|
||||
});
|
||||
if( category.length > 0 ) {
|
||||
@@ -28,7 +28,7 @@
|
||||
return '';
|
||||
}
|
||||
|
||||
var category = categories.filter(function(elt, idx) {
|
||||
var category = categories.filter(function(elt) {
|
||||
return elt._id === category_id;
|
||||
})[0];
|
||||
|
||||
@@ -36,7 +36,7 @@
|
||||
return '';
|
||||
}
|
||||
|
||||
var res = category.sub_categories.filter( function(elt, idx) {
|
||||
var res = category.sub_categories.filter( function(elt) {
|
||||
return elt._id === input;
|
||||
});
|
||||
if( res.length === 1 ) {
|
||||
@@ -47,9 +47,9 @@
|
||||
};
|
||||
}
|
||||
|
||||
AccountController.$inject = ['$scope', '$location', '$routeParams', 'FlashService', 'AccountService'];
|
||||
AccountController.$inject = ['$scope', '$rootScope', '$routeParams', 'FlashService', 'AccountsService', 'AccountService'];
|
||||
|
||||
function AccountController($scope, $location, $routeParams, FlashService, AccountService) {
|
||||
function AccountController($scope, $rootScope, $routeParams, FlashService, AccountsService, AccountService) {
|
||||
var vm = this;
|
||||
|
||||
$scope.calendar = {
|
||||
@@ -62,13 +62,14 @@
|
||||
$scope.calendar.opened[which] = true;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
vm.dataLoading = false;
|
||||
vm.accounts = undefined;
|
||||
vm.account = undefined;
|
||||
vm.entries = [];
|
||||
vm.balance = undefined;
|
||||
vm.categories = [];
|
||||
vm.sub_categories = [];
|
||||
vm.account = undefined;
|
||||
vm.create = create;
|
||||
vm.drop = drop;
|
||||
vm.edit = edit;
|
||||
@@ -77,6 +78,8 @@
|
||||
vm.disabledSubCategories = false;
|
||||
vm.edit_sub_categories = [];
|
||||
|
||||
$rootScope.current_account = $routeParams.account_id;
|
||||
|
||||
(function init() {
|
||||
vm.dataLoading = true;
|
||||
AccountService.details($routeParams.account_id)
|
||||
@@ -99,6 +102,14 @@
|
||||
FlashService.error(response.message);
|
||||
}
|
||||
});
|
||||
AccountsService.list()
|
||||
.then(function(response) {
|
||||
if( response.success ) {
|
||||
$rootScope.accounts = response.accounts
|
||||
} else {
|
||||
FlashService.error(response.message);
|
||||
}
|
||||
});
|
||||
})();
|
||||
|
||||
function create() {
|
||||
|
||||
@@ -5,9 +5,9 @@
|
||||
.module('cloudbudget')
|
||||
.controller('AccountsController', AccountsController);
|
||||
|
||||
AccountsController.$inject = ['$scope', '$location', '$rootScope', 'FlashService', 'AccountsService'];
|
||||
AccountsController.$inject = ['$scope', '$location', 'FlashService', 'AccountsService'];
|
||||
|
||||
function AccountsController($scope, $location, $rootScope, FlashService, AccountsService) {
|
||||
function AccountsController($scope, $location, FlashService, AccountsService) {
|
||||
var vm = this;
|
||||
|
||||
vm.dataLoading = false;
|
||||
|
||||
@@ -14,20 +14,29 @@
|
||||
|
||||
<link rel="stylesheet" href="/css/cloudbudget.css" type="text/css" />
|
||||
</head>
|
||||
<body>
|
||||
<div class="container">
|
||||
<nav class="navbar navbar-inverse">
|
||||
<body ng-controller="GlobalController as globalController">
|
||||
<nav class="navbar navbar-inverse">
|
||||
<div class="container-fluid">
|
||||
<div class="navbar-header">
|
||||
<a class="navbar-brand" href="/">CloudBudget</a>
|
||||
</div>
|
||||
|
||||
<ul class="nav navbar-nav">
|
||||
<li><a href="/login" ng-hide="{{globals.user}}">Login</a></li>
|
||||
<li><a href="/logout" ng-show="{{globals.user}}">Logout</a></li>
|
||||
<form class="nav navbar-left navbar-form">
|
||||
<label for=""current_account>Account</label>
|
||||
<select name="current_account" id="current_account" class="form-control input-sm" ng-model="globalController.current_account" ng-change="globalController.change_account($data)">
|
||||
<option value="{{account._id}}" ng-repeat="account in accounts" >{{account.name}}</option>
|
||||
</select>
|
||||
</form>
|
||||
<ul class="nav navbar-nav navbar-right">
|
||||
<li>
|
||||
<a href="/login" ng-hide="{{globals.user}}">Login</a>
|
||||
<a href="/logout" ng-show="{{globals.user}}">Logout</a>
|
||||
</li>
|
||||
</ul>
|
||||
</nav>
|
||||
</div>
|
||||
<div growl></div>
|
||||
</div>
|
||||
</nav>
|
||||
|
||||
<div growl></div>
|
||||
<div ng-view></div>
|
||||
|
||||
<div class="credits text-center">
|
||||
@@ -55,6 +64,7 @@
|
||||
<script type="text/javascript" src="/js/services/accounts.service.js"></script>
|
||||
<script type="text/javascript" src="/js/services/account.service.js"></script>
|
||||
|
||||
<script type="text/javascript" src="/js/global.controller.js"></script>
|
||||
<script type="text/javascript" src="/home/home.controller.js"></script>
|
||||
<script type="text/javascript" src="/login/login.controller.js"></script>
|
||||
<script type="text/javascript" src="/register/register.controller.js"></script>
|
||||
|
||||
26
public/js/global.controller.js
Normal file
26
public/js/global.controller.js
Normal file
@@ -0,0 +1,26 @@
|
||||
(function() {
|
||||
'use strict';
|
||||
|
||||
angular
|
||||
.module('cloudbudget')
|
||||
.controller('GlobalController', GlobalController);
|
||||
|
||||
GlobalController.$inject = ['$scope', '$rootScope', '$location'];
|
||||
|
||||
function GlobalController($scope, $rootScope, $location) {
|
||||
var vm = this;
|
||||
|
||||
vm.change_account = change_account;
|
||||
vm.current_account = undefined;
|
||||
|
||||
$scope.$watch(function() {
|
||||
return $rootScope.current_account;
|
||||
}, function() {
|
||||
vm.current_account = $rootScope.current_account;
|
||||
}, true);
|
||||
|
||||
function change_account() {
|
||||
$location.path('/account/' + vm.current_account);
|
||||
};
|
||||
}
|
||||
})();
|
||||
Reference in New Issue
Block a user