Remove unused code.

This commit is contained in:
Alexis Lahouze 2017-06-14 22:14:40 +02:00
parent 13766be8cb
commit e364b1e3ef

View File

@ -34,10 +34,7 @@ var ngResource = require('angular-resource'),
// Note: ngBootbox seems to have no module.exports. // Note: ngBootbox seems to have no module.exports.
ngBootbox = 'ngBootbox'; ngBootbox = 'ngBootbox';
var accountModule = require('../accounts');
var operationModule = angular.module('accountant.operations', [ var operationModule = angular.module('accountant.operations', [
accountModule.name,
ngResource, ngResource,
ngMessages, ngMessages,
ngUiNotification, ngUiNotification,
@ -58,331 +55,12 @@ var operationModule = angular.module('accountant.operations', [
); );
}) })
.factory('OHLC', function($resource, $routeParams) {
return $resource(
'/api/account/:account_id/ohlc', {
// eslint-disable-next-line camelcase
account_id: $routeParams.accountId
}
);
})
.factory('Category', function($resource, $routeParams) {
return $resource(
'/api/account/:account_id/category', {
// eslint-disable-next-line camelcase
account_id: $routeParams.accountId
}
);
})
.factory('Balance', function($resource, $routeParams) {
return $resource(
'/api/account/:account_id/balance', {
// eslint-disable-next-line camelcase
account_id: $routeParams.accountId
}
);
})
/*
* Controller for category chart.
*/
.controller('CategoryChartController',
function($rootScope, Category, Balance) {
var vm = this;
var colors = Highcharts.getOptions().colors;
vm.revenueColor = colors[2];
vm.expenseColor = colors[3];
// Configure pie chart for categories.
vm.config = {
options: {
chart: {
type: 'pie',
animation: {
duration: 500
}
},
plotOptions: {
pie: {
startAngle: -90
},
series: {
allowPointSelect: 0
}
},
tooltip: {
valueDecimals: 2,
valueSuffix: '€'
}
},
yAxis: {
title: {
text: 'Categories'
}
},
title: {
text: 'Répartition dépenses/recettes'
},
series: [{
name: 'Value',
data: [],
innerSize: '33%',
size: '60%',
dataLabels: {
formatter: function() {
// eslint-disable-next-line angular/controller-as-vm
return this.point.name;
},
distance: -40
}
}, {
name: 'Value',
data: [],
innerSize: '66%',
size: '60%',
dataLabels: {
formatter: function() {
// eslint-disable-next-line angular/controller-as-vm
if (this.point.name !== null && this.percentage >= 2.5) {
// eslint-disable-next-line angular/controller-as-vm
return this.point.name;
}
return null;
}
}
}]
};
vm.brightenColor = function(color) {
var brightness = 0.2;
// eslint-disable-next-line new-cap
return Highcharts.Color(color).brighten(brightness).get();
};
// Load categories, mainly to populate the pie chart.
vm.load = function(begin, end) {
vm.config.loading = true;
Category.query({
begin: begin.format('YYYY-MM-DD'),
end: end.format('YYYY-MM-DD')
}, function(data) {
var expenses = [];
var revenues = [];
var expenseColor = vm.brightenColor(vm.expenseColor);
var revenueColor = vm.brightenColor(vm.revenueColor);
angular.forEach(angular.fromJson(data), function(category) {
expenses.push({
name: category.category,
y: -category.expenses,
color: expenseColor
});
revenues.push({
name: category.category,
y: category.revenues,
color: revenueColor
});
});
// Note: expenses and revenues must be in the same order than in series[0].
vm.config.series[1].data = revenues.concat(expenses);
vm.config.loading = false;
});
};
/*
* Get account balance.
*/
vm.getBalance = function(begin, end) {
Balance.get({
begin: begin.format('YYYY-MM-DD'),
end: end.format('YYYY-MM-DD')
}, function(balance) {
// Update pie chart subtitle with Balance.
vm.config.subtitle = {
text: 'Balance: ' + balance.balance
};
vm.config.series[0].data = [{
name: 'Revenues',
y: balance.revenues,
color: vm.revenueColor
}, {
name: 'Expenses',
y: -balance.expenses,
color: vm.expenseColor
}];
});
};
// Reload categories and account status on range selection.
vm.onRangeSelected = $rootScope.$on('rangeSelectedEvent', function(e, args) {
vm.load(args.begin, args.end);
vm.getBalance(args.begin, args.end);
});
$rootScope.$on('$destroy', function(){
vm.onRangeSelected = angular.noop();
});
}
)
/*
* Controller for the sold chart.
*/
.controller('SoldChartController', function($rootScope, $scope, OHLC) {
var vm = this;
// Configure chart for operations.
vm.config = {
options: {
chart: {
zoomType: 'x'
},
rangeSelector: {
buttons: [{
type: 'month',
count: 1,
text: '1m'
}, {
type: 'month',
count: 3,
text: '3m'
}, {
type: 'month',
count: 6,
text: '6m'
}, {
type: 'year',
count: 1,
text: '1y'
}, {
type: 'all',
text: 'All'
}],
selected: 0
},
navigator: {
enabled: true
},
tooltip: {
crosshairs: true,
shared: true,
valueDecimals: 2,
valueSuffix: '€'
},
scrollbar: {
liveRedraw: false
}
},
series: [{
type: 'ohlc',
name: 'Sold',
data: [],
dataGrouping: {
units: [[
'week', // unit name
[1] // allowed multiples
], [
'month',
[1, 2, 3, 4, 6]
]]
}
}],
title: {
text: 'Sold evolution'
},
xAxis: {
type: 'datetime',
dateTimeLabelFormats: {
month: '%e. %b',
year: '%Y'
},
minRange: 3600 * 1000 * 24 * 14, // 2 weeks
events: {
afterSetExtremes: function(e) {
$scope.$emit('rangeSelectedEvent', {
begin: moment.utc(e.min), end: moment.utc(e.max)
});
}
},
currentMin: moment.utc().startOf('month'),
currentMax: moment.utc().endOf('month')
},
yAxis: {
plotLines: [{
color: 'orange',
width: 2,
value: 0.0
}, {
color: 'red',
width: 2,
value: 0.0
}]
},
useHighStocks: true
};
vm.loadSolds = function() {
vm.config.loading = true;
OHLC.query({}, function(data) {
vm.config.series[0].data = [];
angular.forEach(data, function(operation) {
vm.config.series[0].data.push([
moment.utc(operation.operation_date).valueOf(),
operation.open, operation.high, operation.low, operation.close
]);
});
$scope.$emit('rangeSelectedEvent', {
begin: vm.config.xAxis.currentMin,
end: vm.config.xAxis.currentMax
});
vm.config.loading = false;
});
};
// Reload solds when an operation is saved.
vm.onOperationSaved = $rootScope.$on('operationSavedEvent', function() {
vm.loadSolds();
});
// Reload solds when an operation is deleted.
vm.onOperationDeleted = $rootScope.$on('operationDeletedEvent', function() {
vm.loadSolds();
});
// Update authorized overdraft on account loading.
vm.onAccountLoaded = $rootScope.$on('accountLoadedEvent', function(e, account) {
vm.config.yAxis.plotLines[1].value = account.authorized_overdraft;
});
$rootScope.$on('$destroy', function() {
vm.onOperationSaved = angular.noop();
vm.onOperationDeleted = angular.noop();
vm.onAccountLoaded = angular.noop();
});
// Select beginning and end of month.
vm.loadSolds();
})
/* /*
* Controller for the operations. * Controller for the operations.
*/ */
.controller('OperationController', function($rootScope, $scope, $routeParams, $ngBootbox, Notification, Account, Operation) { .controller('OperationController', function($rootScope, $scope, $routeParams,
$ngBootbox, Notification, Operation) {
var vm = this; var vm = this;
// List of operations. // List of operations.
@ -490,10 +168,6 @@ var operationModule = angular.module('accountant.operations', [
); );
}; };
vm.account = Account.get({
id: $routeParams.accountId
});
/* /*
* Reload operations on rangeSelectedEvent. * Reload operations on rangeSelectedEvent.
*/ */