sort by date

This commit is contained in:
Gwenhael Le Moine 2016-08-09 15:30:06 +02:00
parent 1190718023
commit 728b4d0710
2 changed files with 24 additions and 1 deletions

View file

@ -199,6 +199,29 @@ app.controller( 'DashboardCtrl',
var retrieve_graph_values = function( params ) {
API.graph_values( params ).then( function( response ) {
$scope.periods = [];
var largest_cat = _(response.data).reduce( function( memo, cat ) {
return cat.length > memo.length ? cat : memo;
}, [] );
_.chain(largest_cat)
.pluck( 'date' )
.each( function( date ) {
_(response.data).each( function( cat ) {
var value = _(cat).find( { date: date } );
if ( _(value).isUndefined() ) {
cat.push( { date: date,
amount: 0,
currency: _(cat).first().currency } );
}
} );
} );
_(response.data).each( function( cat ) {
cat = _(cat).sortBy( function( month ) {
return month.date;
} );
} );
console.log( response.data )
$scope.monthly_values = _.chain( response.data )
.keys()
.reverse()

View file

@ -25,7 +25,7 @@
<md-toolbar flex="100" layout="column" layout-gt-md="row" layout-align="center center">
<h2>
<md-input-container>
<md-select data-ng-model="period">
<md-select data-ng-model="period" aria-label="what">
<md-option data-ng-repeat="period in periods">{{period}}</md-option>
</md-select>
</md-input-container>