Fix angular style issues.

This commit is contained in:
Alexis Lahouze 2016-10-14 08:19:23 +02:00
parent edac1ee6a9
commit e91bf14298
2 changed files with 293 additions and 294 deletions

View File

@ -91,14 +91,14 @@ angular.module('accountant', [
editableOptions.theme = 'bs3'; // bootstrap3 theme. Can be also 'bs2', 'default' editableOptions.theme = 'bs3'; // bootstrap3 theme. Can be also 'bs2', 'default'
}) })
.controller('MainController', function($scope, $rootScope, $http, authService, $storage, $ngBootbox) { .controller('MainController', function($rootScope, $http, authService, $storage, $ngBootbox) {
var vm = this; var vm = this;
vm.dialogShown = false; vm.dialogShown = false;
vm.showLoginForm = function() { vm.showLoginForm = function() {
// First, if there are registered credentials, use them // First, if there are registered credentials, use them
if ($scope.dialogShown) { if (vm.dialogShown) {
return; return;
} }
@ -127,13 +127,9 @@ angular.module('accountant', [
).success(function(result) { ).success(function(result) {
// TODO Alexis Lahouze 2015-08-28 Handle callback. // TODO Alexis Lahouze 2015-08-28 Handle callback.
// Call to /api/login to retrieve the token // Call to /api/login to retrieve the token
// jscs:disable requireCamelCaseOrUpperCaseIdentifiers
$storage.set('token_type', result.token_type); $storage.set('token_type', result.token_type);
// jscs:enable requireCamelCaseOrUpperCaseIdentifiers
$storage.set('token', result.token); $storage.set('token', result.token);
// jscs:disable requireCamelCaseOrUpperCaseIdentifiers
$storage.set('expiration_date', result.expiration_date); $storage.set('expiration_date', result.expiration_date);
// jscs:enable requireCamelCaseOrUpperCaseIdentifiers
authService.loginConfirmed(); authService.loginConfirmed();
}); });
@ -151,10 +147,10 @@ angular.module('accountant', [
}); });
}; };
var onAuthLoginRequired = $rootScope.$on('event:auth-loginRequired', $scope.showLoginForm); vm.onAuthLoginRequired = $rootScope.$on('event:auth-loginRequired', vm.showLoginForm);
$scope.$on('$destroy', function() { vm.$on('$destroy', function() {
onAuthLoginRequired = angular.noop(); vm.onAuthLoginRequired = angular.noop();
}); });
}) })

View File

@ -27,64 +27,59 @@ angular.module('accountant.operations', [
'highcharts-ng' 'highcharts-ng'
]) ])
.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('Operation', ['$resource', function($resource) { .factory('Operation', function($resource) {
return $resource( return $resource(
'/api/operation/:id', { '/api/operation/:id', {
id: '@id' id: '@id'
} }
); );
}]) })
.factory('OHLC', [ .factory('OHLC', function($resource, $routeParams) {
'$resource', '$routeParams', function($resource, $routeParams) {
return $resource( return $resource(
'/api/account/:account_id/ohlc', { '/api/account/:account_id/ohlc', {
// eslint-disable-next-line camelcase // eslint-disable-next-line camelcase
account_id: $routeParams.accountId account_id: $routeParams.accountId
} }
); );
} })
])
.factory('Category', [ .factory('Category', function($resource, $routeParams) {
'$resource', '$routeParams', function($resource, $routeParams) {
return $resource( return $resource(
'/api/account/:account_id/category', { '/api/account/:account_id/category', {
// eslint-disable-next-line camelcase // eslint-disable-next-line camelcase
account_id: $routeParams.accountId account_id: $routeParams.accountId
} }
); );
} })
])
.factory('Balance', [ .factory('Balance', function($resource, $routeParams) {
'$resource', '$routeParams', function($resource, $routeParams) {
return $resource( return $resource(
'/api/account/:account_id/balance', { '/api/account/:account_id/balance', {
// eslint-disable-next-line camelcase // eslint-disable-next-line camelcase
account_id: $routeParams.accountId account_id: $routeParams.accountId
} }
); );
} })
])
/* /*
* Controller for category chart. * Controller for category chart.
*/ */
.controller('CategoryChartController', [ .controller('CategoryChartController',
'$rootScope', '$scope', '$http', 'Category', 'Balance', function($rootScope, $http, Category, Balance) {
function($rootScope, $scope, $http, Category, Balance) { var vm = this;
var colors = Highcharts.getOptions().colors; var colors = Highcharts.getOptions().colors;
$scope.revenueColor = colors[2]; vm.revenueColor = colors[2];
$scope.expenseColor = colors[3]; vm.expenseColor = colors[3];
// Configure pie chart for categories. // Configure pie chart for categories.
$scope.config = { vm.config = {
options: { options: {
chart: { chart: {
type: 'pie', type: 'pie',
@ -137,7 +132,7 @@ angular.module('accountant.operations', [
}] }]
}; };
$scope.brightenColor = function(color) { vm.brightenColor = function(color) {
var brightness = 0.2; var brightness = 0.2;
// eslint-disable-next-line new-cap // eslint-disable-next-line new-cap
@ -145,8 +140,8 @@ angular.module('accountant.operations', [
}; };
// Load categories, mainly to populate the pie chart. // Load categories, mainly to populate the pie chart.
$scope.load = function(begin, end) { vm.load = function(begin, end) {
$scope.config.loading = true; vm.config.loading = true;
Category.query({ Category.query({
begin: begin.format('YYYY-MM-DD'), begin: begin.format('YYYY-MM-DD'),
@ -155,8 +150,8 @@ angular.module('accountant.operations', [
var expenses = []; var expenses = [];
var revenues = []; var revenues = [];
var expenseColor = $scope.brightenColor($scope.expenseColor); var expenseColor = vm.brightenColor(vm.expenseColor);
var revenueColor = $scope.brightenColor($scope.revenueColor); var revenueColor = vm.brightenColor(vm.revenueColor);
angular.forEach(angular.fromJson(data), function(category) { angular.forEach(angular.fromJson(data), function(category) {
expenses.push({ expenses.push({
@ -173,53 +168,57 @@ angular.module('accountant.operations', [
}); });
// Note: expenses and revenues must be in the same order than in series[0]. // Note: expenses and revenues must be in the same order than in series[0].
$scope.config.series[1].data = revenues.concat(expenses); vm.config.series[1].data = revenues.concat(expenses);
$scope.config.loading = false; vm.config.loading = false;
}); });
}; };
/* /*
* Get account balance. * Get account balance.
*/ */
$scope.getBalance = function(begin, end) { vm.getBalance = function(begin, end) {
Balance.get({ Balance.get({
begin: begin.format('YYYY-MM-DD'), begin: begin.format('YYYY-MM-DD'),
end: end.format('YYYY-MM-DD') end: end.format('YYYY-MM-DD')
}, function(balance) { }, function(balance) {
// Update pie chart subtitle with Balance. // Update pie chart subtitle with Balance.
$scope.config.subtitle = { vm.config.subtitle = {
text: 'Balance: ' + balance.balance text: 'Balance: ' + balance.balance
}; };
$scope.config.series[0].data = [{ vm.config.series[0].data = [{
name: 'Revenues', name: 'Revenues',
y: balance.revenues, y: balance.revenues,
color: $scope.revenueColor color: vm.revenueColor
}, { }, {
name: 'Expenses', name: 'Expenses',
y: -balance.expenses, y: -balance.expenses,
color: $scope.expenseColor color: vm.expenseColor
}]; }];
}); });
}; };
// Reload categories and account status on range selection. // Reload categories and account status on range selection.
$rootScope.$on('rangeSelectedEvent', function(e, args) { vm.onRangeSelected = $rootScope.$on('rangeSelectedEvent', function(e, args) {
$scope.load(args.begin, args.end); vm.load(args.begin, args.end);
$scope.getBalance(args.begin, args.end); vm.getBalance(args.begin, args.end);
});
vm.$on('$destroy', function(){
vm.onRangeSelected = angular.noop();
}); });
} }
]) )
/* /*
* Controller for the sold chart. * Controller for the sold chart.
*/ */
.controller('SoldChartController', [ .controller('SoldChartController', function($rootScope, $http, OHLC) {
'$rootScope', '$scope', '$http', 'OHLC', var vm = this;
function($rootScope, $scope, $http, OHLC) {
// Configure chart for operations. // Configure chart for operations.
$scope.config = { vm.config = {
options: { options: {
chart: { chart: {
zoomType: 'x' zoomType: 'x'
@ -286,7 +285,7 @@ angular.module('accountant.operations', [
minRange: 3600 * 1000 * 24 * 14, // 2 weeks minRange: 3600 * 1000 * 24 * 14, // 2 weeks
events: { events: {
afterSetExtremes: function(e) { afterSetExtremes: function(e) {
$scope.$emit('rangeSelectedEvent', { vm.$emit('rangeSelectedEvent', {
begin: moment.utc(e.min), end: moment.utc(e.max) begin: moment.utc(e.min), end: moment.utc(e.max)
}); });
} }
@ -308,78 +307,79 @@ angular.module('accountant.operations', [
useHighStocks: true useHighStocks: true
}; };
$scope.loadSolds = function() { vm.loadSolds = function() {
$scope.config.loading = true; vm.config.loading = true;
OHLC.query({}, function(data) { OHLC.query({}, function(data) {
$scope.config.series[0].data = []; vm.config.series[0].data = [];
angular.forEach(data, function(operation) { angular.forEach(data, function(operation) {
$scope.config.series[0].data.push([ vm.config.series[0].data.push([
// jscs:disable requireCamelCaseOrUpperCaseIdentifiers
moment.utc(operation.operation_date).valueOf(), moment.utc(operation.operation_date).valueOf(),
// jscs:enable requireCamelCaseOrUpperCaseIdentifiers
operation.open, operation.high, operation.low, operation.close operation.open, operation.high, operation.low, operation.close
]); ]);
}); });
$scope.$emit('rangeSelectedEvent', { vm.$emit('rangeSelectedEvent', {
begin: $scope.config.xAxis.currentMin, begin: vm.config.xAxis.currentMin,
end: $scope.config.xAxis.currentMax end: vm.config.xAxis.currentMax
}); });
$scope.config.loading = false; vm.config.loading = false;
}); });
}; };
// Reload solds when an operation is saved. // Reload solds when an operation is saved.
$rootScope.$on('operationSavedEvent', function() { vm.onOperationSaved = $rootScope.$on('operationSavedEvent', function() {
$scope.loadSolds(); vm.loadSolds();
}); });
// Reload solds when an operation is deleted. // Reload solds when an operation is deleted.
$rootScope.$on('operationDeletedEvent', function() { vm.onOperationDeleted = $rootScope.$on('operationDeletedEvent', function() {
$scope.loadSolds(); vm.loadSolds();
}); });
// Update authorized overdraft on account loading. // Update authorized overdraft on account loading.
$rootScope.$on('accountLoadedEvent', function(e, account) { vm.onAccountLoaded = $rootScope.$on('accountLoadedEvent', function(e, account) {
// jscs:disable requireCamelCaseOrUpperCaseIdentifiers vm.config.yAxis.plotLines[1].value = account.authorized_overdraft;
$scope.config.yAxis.plotLines[1].value = account.authorized_overdraft; });
// jscs:enable requireCamelCaseOrUpperCaseIdentifiers
vm.$on('$destroy', function() {
vm.onOperationSaved = angular.noop();
vm.onOperationDeleted = angular.noop();
vm.onAccountLoaded = angular.noop();
}); });
// Select beginning and end of month. // Select beginning and end of month.
$scope.loadSolds(); vm.loadSolds();
} })
])
/* /*
* Controller for the operations. * Controller for the operations.
*/ */
.controller('OperationController', [ .controller('OperationController', function($rootScope, $routeParams, $ngBootbox, Notification, Account, Operation) {
'$scope', '$rootScope', '$routeParams', '$ngBootbox', 'Notification', 'Account', 'Operation', var vm = this;
function($scope, $rootScope, $routeParams, $ngBootbox, Notification, Account, Operation) {
// List of operations. // List of operations.
$scope.operations = []; vm.operations = [];
/* /*
* Add an empty operation. * Add an empty operation.
*/ */
$scope.add = function() { vm.add = function() {
var operation = new Operation({ var operation = new Operation({
// eslint-disable-next-line camelcase // eslint-disable-next-line camelcase
account_id: $routeParams.accountId account_id: $routeParams.accountId
}); });
$scope.operations.splice(0, 0, operation); vm.operations.splice(0, 0, operation);
}; };
/* /*
* Load operations. * Load operations.
*/ */
$scope.load = function(begin, end) { vm.load = function(begin, end) {
$scope.operations = Operation.query({ vm.operations = Operation.query({
// eslint-disable-next-line camelcase // eslint-disable-next-line camelcase
account_id: $routeParams.accountId, account_id: $routeParams.accountId,
begin: begin.format('YYYY-MM-DD'), begin: begin.format('YYYY-MM-DD'),
@ -390,46 +390,46 @@ angular.module('accountant.operations', [
/* /*
* Cancel edition. * Cancel edition.
*/ */
$scope.cancelEdit = function(operation, rowform, $index) { vm.cancelEdit = function(operation, rowform, $index) {
if (operation.id) { if (operation.id) {
rowform.$cancel(); rowform.$cancel();
} else { } else {
$scope.operations.splice($index, 1); vm.operations.splice($index, 1);
} }
}; };
/* /*
* Toggle pointed indicator for an operation. * Toggle pointed indicator for an operation.
*/ */
$scope.togglePointed = function(operation, rowform) { vm.togglePointed = function(operation, rowform) {
operation.pointed = !operation.pointed; operation.pointed = !operation.pointed;
// Save operation if not editing it. // Save operation if not editing it.
if (!rowform.$visible) { if (!rowform.$visible) {
$scope.save(operation); vm.save(operation);
} }
}; };
/* /*
* Toggle cancel indicator for an operation. * Toggle cancel indicator for an operation.
*/ */
$scope.toggleCanceled = function(operation) { vm.toggleCanceled = function(operation) {
operation.canceled = !operation.canceled; operation.canceled = !operation.canceled;
$scope.save(operation); vm.save(operation);
}; };
/* /*
* Save an operation and emit operationSavedEvent. * Save an operation and emit operationSavedEvent.
*/ */
$scope.save = function($data, $index) { vm.save = function($data, $index) {
// Check if $data is already a resource. // Check if $data is already a resource.
var operation; var operation;
if ($data.$save) { if ($data.$save) {
operation = $data; operation = $data;
} else { } else {
operation = $scope.operations[$index]; operation = vm.operations[$index];
operation = angular.merge(operation, $data); operation = angular.merge(operation, $data);
} }
@ -438,14 +438,14 @@ angular.module('accountant.operations', [
return operation.$save().then(function(data) { return operation.$save().then(function(data) {
Notification.success('Operation #' + data.id + ' saved.'); Notification.success('Operation #' + data.id + ' saved.');
$scope.$emit('operationSavedEvent', data); vm.$emit('operationSavedEvent', data);
}); });
}; };
/* /*
* Delete an operation and emit operationDeletedEvent. * Delete an operation and emit operationDeletedEvent.
*/ */
$scope.delete = function(operation, $index) { vm.delete = function(operation, $index) {
var id = operation.id; var id = operation.id;
$ngBootbox.confirm( $ngBootbox.confirm(
@ -456,29 +456,32 @@ angular.module('accountant.operations', [
Notification.success('Operation #' + id + ' deleted.'); Notification.success('Operation #' + id + ' deleted.');
// Remove operation from array. // Remove operation from array.
$scope.operation.splice($index, 1); vm.operation.splice($index, 1);
$scope.$emit('operationDeletedEvent', operation); vm.$emit('operationDeletedEvent', operation);
}); });
} }
} }
); );
}; };
$scope.account = Account.get({ vm.account = Account.get({
id: $routeParams.accountId id: $routeParams.accountId
}); });
/* /*
* Reload operations on rangeSelectedEvent. * Reload operations on rangeSelectedEvent.
*/ */
$rootScope.$on('rangeSelectedEvent', function(e, args) { vm.onRangeSelected = $rootScope.$on('rangeSelectedEvent', function(e, args) {
$scope.load(args.begin, args.end); vm.load(args.begin, args.end);
}); });
}
])
.directive('operationFormDialog', function($ngBootbox) { vm.$on('$destroy', function() {
vm.onRangeSelected = angular.noop;
});
})
.directive('operationFormDialog', function($log, $ngBootbox) {
return { return {
restrict: 'A', restrict: 'A',
scope: { scope: {
@ -509,10 +512,10 @@ angular.module('accountant.operations', [
className: 'btn-success', className: 'btn-success',
callback: function() { callback: function() {
// Validate form // Validate form
console.log(scope.form); $log.log(scope.form);
// Save operation // Save operation
console.log(scope.operation); $log.log(scope.operation);
// TODO Alexis Lahouze 2016-05-24 Save operation, handle return. // TODO Alexis Lahouze 2016-05-24 Save operation, handle return.
return false; return false;