Skip to content

Commit

Permalink
fix(journal): update footer when data changes
Browse files Browse the repository at this point in the history
This commit fixes the journal footer, updating the totals when the data changes.  It also refactors the journal footer to remove the template into an external file for better maintainability.
  • Loading branch information
lomamech authored and jniles committed May 8, 2017
1 parent 4504703 commit 4df53c2
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 17 deletions.
6 changes: 3 additions & 3 deletions client/src/js/services/grid/GridGrouping.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,22 +47,22 @@ function GridGroupingService(GridAggregators, uiGridGroupingConstants, Session,
// show debit or credit total for transaction on transaction header
if (column.grouping && column.grouping.groupPriority > -1) {

column.treeAggregationFn = function (aggregation, fieldValue, numValue, row) {
column.treeAggregationFn = function (aggregation, fieldValue, numValue, row) {
// @todo this will be called for every row in a group but only needs to be called once
if (row.entity.transaction) {
aggregation.value = row.entity.transaction.debit_equiv;
}
};

column.customTreeAggregationFinalizerFn = function (aggregation) {
column.customTreeAggregationFinalizerFn = function (aggregation) {
if (typeof(aggregation.groupVal) !== 'undefined') {
aggregation.rendered = aggregation.groupVal + ' (' + aggregation.value + ')';
} else {
aggregation.rendered = null;
}
};
// return true;
}
}

});
return columns;
Expand Down
38 changes: 24 additions & 14 deletions client/src/modules/journal/journal.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ JournalController.$inject = [
'SessionService', 'NotifyService', 'TransactionService', 'GridEditorService',
'bhConstants', '$state', 'uiGridConstants', 'ModalService', 'LanguageService',
'AppCache', 'Store', 'uiGridGroupingConstants', 'ExportService', 'FindEntityService',
'FilterService', '$rootScope', '$filter', '$translate'
'FilterService', '$rootScope', '$filter'
];

/**
Expand All @@ -33,7 +33,7 @@ JournalController.$inject = [
function JournalController(Journal, Sorting, Grouping,
Filtering, Columns, Config, Session, Notify, Transactions, Editors,
bhConstants, $state, uiGridConstants, Modal, Languages, AppCache, Store,
uiGridGroupingConstants, Export, FindEntity, Filters, $rootScope, $filter, $translate) {
uiGridGroupingConstants, Export, FindEntity, Filters, $rootScope, $filter) {

// Journal utilities
var sorting;
Expand Down Expand Up @@ -70,6 +70,7 @@ function JournalController(Journal, Sorting, Grouping,
vm.DATEPICKER_OPTIONS = { format: bhConstants.dates.format };

vm.enterprise = Session.enterprise;
vm.gridApi = {};

// gridOptions is bound to the UI Grid and used to configure many of the
// options, it is also used by the grid to expose the API
Expand All @@ -80,9 +81,10 @@ function JournalController(Journal, Sorting, Grouping,
flatEntityAccess : true,
enableGroupHeaderSelection : true,
enableRowHeaderSelection : true,
rowTemplate : '/modules/templates/grid/transaction.row.html'
rowTemplate : '/modules/templates/grid/transaction.row.html',
onRegisterApi : onRegisterApi,
};

vm.grouped = angular.isDefined(cache.grouped) ? cache.grouped : false;

// Initialise each of the journal utilities, providing them access to the journal
Expand Down Expand Up @@ -200,7 +202,9 @@ function JournalController(Journal, Sorting, Grouping,
customTreeAggregationFinalizerFn : function (aggregation) {
aggregation.rendered = aggregation.value;
},
enableFiltering : false },
enableFiltering : true,
footerCellFilter : 'currency:grid.appScope.enterprise.currency_id'
},

{ field : 'credit_equiv',
displayName : 'TABLE.COLUMNS.CREDIT',
Expand All @@ -209,7 +213,9 @@ function JournalController(Journal, Sorting, Grouping,
customTreeAggregationFinalizerFn : function (aggregation) {
aggregation.rendered = aggregation.value;
},
enableFiltering : false },
enableFiltering : true,
footerCellFilter : 'currency:grid.appScope.enterprise.currency_id'
},

{ field : 'currencyName',
displayName : 'TABLE.COLUMNS.CURRENCY',
Expand Down Expand Up @@ -258,8 +264,12 @@ function JournalController(Journal, Sorting, Grouping,
enableFiltering : false,
},
];

vm.gridOptions.columnDefs = columns;

// API register function
function onRegisterApi(gridApi) {
vm.gridApi = gridApi;
}

// This function opens a modal through column service to let the user show or Hide columns
vm.openColumnConfigModal = function openColumnConfigModal() {
Expand Down Expand Up @@ -326,21 +336,21 @@ function JournalController(Journal, Sorting, Grouping,
vm.gridOptions.gridFooterTemplate = null;
vm.gridOptions.showGridFooter = false;

// number of transactions downloaded and shown in the current journal
var numberCurrentGridTransactions = 0;

// @fixme
Journal.grid(null, options)
.then(function (records) {
// To Get the number of transaction
numberCurrentGridTransactions = records.aggregate.length;
// number of transactions downloaded and shown in the current journal
vm.numberCurrentGridTransactions = records.aggregate.length;

// pre process data - this should be done in a more generic way in a service
vm.gridOptions.data = transactions.preprocessJournalData(records);
vm.gridOptions.showGridFooter = true;
vm.gridOptions.gridFooterTemplate = '<div><strong>' + $translate.instant('FORM.INFO.NUM_TRANSACTION') +
' : ' + numberCurrentGridTransactions + ' / ' + vm.numberTotalSystemTransactions + '</strong></div>';
vm.gridOptions.gridFooterTemplate = '/modules/journal/templates/grid.footer.html';

transactions.applyEdits();

//@TODO investigate why footer totals aren't updated automatically on data change
vm.gridApi.core.notifyDataChange(uiGridConstants.dataChange.ALL);

// try to unfold groups
// try { grouping.unfoldAllGroups(); } catch (e) {}
Expand Down
6 changes: 6 additions & 0 deletions client/src/modules/journal/templates/grid.footer.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<div>
<strong>
<span translate>FORM.INFO.NUM_TRANSACTION</span>:
{{ grid.appScope.numberCurrentGridTransactions }} / {{ grid.appScope.numberTotalSystemTransactions }}
</strong>
</div>

0 comments on commit 4df53c2

Please sign in to comment.