Fix angular style issues.

This commit is contained in:
Alexis Lahouze 2016-10-12 23:32:54 +02:00
parent 032dd9bdc6
commit a872788def

View File

@ -24,12 +24,12 @@ angular.module('accountant.accounts', [
'ngBootbox' 'ngBootbox'
]) ])
.config(['$resourceProvider', function($resourceProvider) { .config(function($resourceProvider) {
// Keep trailing slashes to avoid redirect by flask.. // Keep trailing slashes to avoid redirect by flask..
$resourceProvider.defaults.stripTrailingSlashes = false; $resourceProvider.defaults.stripTrailingSlashes = false;
}]) })
.factory('Account', ['$resource', function($resource) { .factory('Account', function($resource) {
var Account = $resource( var Account = $resource(
'/api/account/:id', { '/api/account/:id', {
id: '@id' id: '@id'
@ -54,114 +54,113 @@ angular.module('accountant.accounts', [
}; };
return Account; return Account;
}]) })
.controller('AccountController', [ .controller('AccountController', function($scope, $ngBootbox, Account, Notification) {
'$scope', '$ngBootbox', 'Account', 'Notification', var vm=this;
function($scope, $ngBootbox, Account, Notification) {
/* /*
* Return the class for an account current value compared to authorized * Return the class for an account current value compared to authorized
* overdraft. * overdraft.
*/ */
$scope.rowClass = function(account) { vm.rowClass = function(account) {
// eslint-disable-next-line camelcase
if (!account || !account.authorized_overdraft || !account.current) {
return;
}
// eslint-disable-next-line camelcase
if (account.current < account.authorized_overdraft) {
return 'danger';
} else if (account.current < 0) {
return 'warning';
}
};
/*
* Return the class for a value compared to account authorized overdraft.
*/
vm.valueClass = function(account, value) {
if (!account || !value) {
return;
}
// eslint-disable-next-line camelcase
if (value < account.authorized_overdraft) {
return 'text-danger';
} else if (value < 0) {
return 'text-warning';
}
};
/*
* Add an empty account.
*/
vm.add = function() {
var account = new Account({
// eslint-disable-next-line camelcase // eslint-disable-next-line camelcase
if (!account || !account.authorized_overdraft || !account.current) { authorized_overdraft: 0
return; });
}
// eslint-disable-next-line camelcase // Insert account at the begining of the array.
if (account.current < account.authorized_overdraft) { $scope.accounts.splice(0, 0, account);
return 'danger'; };
} else if (account.current < 0) {
return 'warning';
}
};
/* /*
* Return the class for a value compared to account authorized overdraft. * Cancel account edition. Remove it from array if a new one.
*/ */
$scope.valueClass = function(account, value) { vm.cancelEdit = function(rowform, account, $index) {
if (!account || !value) { if (account.id) {
return; rowform.$cancel();
} } else {
// Account not saved, just remove it from array.
$scope.accounts.splice($index, 1);
}
};
// eslint-disable-next-line camelcase /*
if (value < account.authorized_overdraft) { * Save account.
return 'text-danger'; */
} else if (value < 0) { vm.save = function(account) {
return 'text-warning'; // var account = $scope.accounts[$index];
}
};
/* // account = angular.merge(account, $data);
* Add an empty account.
*/
$scope.add = function() {
var account = new Account({
// eslint-disable-next-line camelcase
authorized_overdraft: 0
});
// Insert account at the begining of the array. return account.$save().then(function(data) {
$scope.accounts.splice(0, 0, account); Notification.success('Account #' + data.id + ' saved.');
};
/* // TODO Alexis Lahouze 2016-03-08 Update solds
* Cancel account edition. Remove it from array if a new one.
*/
$scope.cancelEdit = function(rowform, account, $index) {
if (account.id) {
rowform.$cancel();
} else {
// Account not saved, just remove it from array.
$scope.accounts.splice($index, 1);
}
};
/* return data;
* Save account. });
*/ };
$scope.save = function(account) {
// var account = $scope.accounts[$index];
// account = angular.merge(account, $data); /*
* Delete an account.
*/
vm.delete = function(account, $index) {
var id = account.id;
return account.$save().then(function(data) { $ngBootbox.confirm(
Notification.success('Account #' + data.id + ' saved.'); 'Voulez-vous supprimer le compte \'' + account.name + '\' ?',
function(result) {
if (result) {
account.$delete().then(function() {
Notification.success('Account #' + id + ' deleted.');
// TODO Alexis Lahouze 2016-03-08 Update solds // Remove account from array.
$scope.accounts.splice($index, 1);
return data; });
});
};
/*
* Delete an account.
*/
$scope.delete = function(account, $index) {
var id = account.id;
$ngBootbox.confirm(
'Voulez-vous supprimer le compte \'' + account.name + '\' ?',
function(result) {
if (result) {
account.$delete().then(function() {
Notification.success('Account #' + id + ' deleted.');
// Remove account from array.
$scope.accounts.splice($index, 1);
});
}
} }
); }
}; );
};
// Load accounts. // Load accounts.
$scope.accounts = Account.query(); vm.accounts = Account.query();
}] })
)
.directive('accountFormDialog', function(Account, $ngBootbox, Notification) { .directive('accountFormDialog', function(Account, $ngBootbox, Notification, $log) {
return { return {
restrict: 'A', restrict: 'A',
scope: { scope: {
@ -189,7 +188,7 @@ angular.module('accountant.accounts', [
angular.copy(scope.data, scope.account); angular.copy(scope.data, scope.account);
// Save account // Save account
console.log(scope.account); $log.log(scope.account);
return scope.account.$save().then( return scope.account.$save().then(
function(data) { function(data) {
Notification.success('Account #' + data.id + ' saved.'); Notification.success('Account #' + data.id + ' saved.');
@ -201,7 +200,7 @@ angular.module('accountant.accounts', [
function(data) { function(data) {
Notification.error('Error while saving account #' + data.id); Notification.error('Error while saving account #' + data.id);
scope.account.getSolds(); scope.account.getSolds();
console.log(data); $log.log(data);
return false; return false;
} }
); );