From 57528e145666412ce2c0a888b1b5df970cb123ef Mon Sep 17 00:00:00 2001 From: Jonathan Niles Date: Thu, 20 Apr 2017 13:39:17 +0100 Subject: [PATCH] feat(journal): default limit to today's records (#1523) This commit extends the hacks done for other registries to the Posting Journal, so that it defaults to today's records as a search. This should speed up the initial startup of the module considerably while we develop a better representation of our filters on the client. Addresses #1436 in a hacky way. --- .env.development | 2 +- client/src/modules/inventory/list/list.js | 10 ++-- .../invoices/patientInvoice.service.js | 2 +- .../src/modules/invoices/registry/registry.js | 1 - client/src/modules/journal/journal.html | 1 + client/src/modules/journal/journal.js | 29 ++++++++-- client/src/modules/journal/journal.service.js | 14 ++++- .../modules/journal/modals/search.modal.js | 3 + server/config/interceptors.js | 2 +- server/controllers/finance/journal/index.js | 2 + .../edit_journal/edit_journal.spec.js | 58 ++++++++----------- 11 files changed, 75 insertions(+), 49 deletions(-) diff --git a/.env.development b/.env.development index bcad38125d..899164f988 100644 --- a/.env.development +++ b/.env.development @@ -17,7 +17,7 @@ LOG_LEVEL='warn' UPLOAD_DIR='client/upload' # this will toggle all MYSQL errors to be reflected to the client. -LOG_ALL_MYSQL_ERRORS=false +LOG_ALL_MYSQL_ERRORS=0 # control Redis Pub/Sub ENABLE_EVENTS=false diff --git a/client/src/modules/inventory/list/list.js b/client/src/modules/inventory/list/list.js index 1ea6ee3ca2..75db387462 100644 --- a/client/src/modules/inventory/list/list.js +++ b/client/src/modules/inventory/list/list.js @@ -83,14 +83,14 @@ function InventoryListController ($translate, Inventory, Notify, uiGridConstants vm.gridApi.core.notifyDataChange(uiGridConstants.dataChange.COLUMN); } - function runResearch(params){ + function runResearch(params){ vm.filtersFmt = Inventory.formatFilterParameters(params); Inventory.search(params) .then(function (rows) { vm.gridOptions.data = rows; }) - .catch(Notify.handleError); + .catch(Notify.handleError); } // research and filter data in Inventory List @@ -110,7 +110,7 @@ function InventoryListController ($translate, Inventory, Notify, uiGridConstants runResearch(vm.filters); } - // clears the filters + // clears the filters function clearFilters() { startup(); $state.params.filters = null; @@ -121,7 +121,7 @@ function InventoryListController ($translate, Inventory, Notify, uiGridConstants function startup() { vm.filters = {}; - // if filters are directly passed in + // if filters are directly passed in if ($state.params.filters) { runResearch($state.params.filters); @@ -130,7 +130,7 @@ function InventoryListController ($translate, Inventory, Notify, uiGridConstants .then(function (inventory) { vm.gridOptions.data = inventory; }) - .catch(Notify.handleError); + .catch(Notify.handleError); } diff --git a/client/src/modules/invoices/patientInvoice.service.js b/client/src/modules/invoices/patientInvoice.service.js index a7906babd0..64722f6342 100644 --- a/client/src/modules/invoices/patientInvoice.service.js +++ b/client/src/modules/invoices/patientInvoice.service.js @@ -2,7 +2,7 @@ angular.module('bhima.services') .service('PatientInvoiceService', PatientInvoiceService); PatientInvoiceService.$inject = [ - '$uibModal', 'util', 'SessionService', 'PrototypeApiService', 'FilterService' + '$uibModal', 'util', 'SessionService', 'PrototypeApiService', 'FilterService', ]; /** diff --git a/client/src/modules/invoices/registry/registry.js b/client/src/modules/invoices/registry/registry.js index f3d90026df..c4cebdce54 100644 --- a/client/src/modules/invoices/registry/registry.js +++ b/client/src/modules/invoices/registry/registry.js @@ -118,7 +118,6 @@ function InvoiceRegistryController(Invoices, bhConstants, Notify, Session, Recei // search and filter data in Invoice Registry function search() { - Invoices.openSearchModal(vm.filters) .then(function (parameters) { // no parameters means the modal was dismissed. diff --git a/client/src/modules/journal/journal.html b/client/src/modules/journal/journal.html index 938f6ca3ef..8395677407 100644 --- a/client/src/modules/journal/journal.html +++ b/client/src/modules/journal/journal.html @@ -76,6 +76,7 @@ diff --git a/client/src/modules/journal/journal.js b/client/src/modules/journal/journal.js index a6e32fc1da..49302d866f 100644 --- a/client/src/modules/journal/journal.js +++ b/client/src/modules/journal/journal.js @@ -7,6 +7,7 @@ JournalController.$inject = [ 'SessionService', 'NotifyService', 'TransactionService', 'GridEditorService', 'bhConstants', '$state', 'uiGridConstants', 'ModalService', 'LanguageService', 'AppCache', 'Store', 'uiGridGroupingConstants', 'ExportService', 'FindEntityService', + 'FilterService', '$rootScope', ]; /** @@ -32,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) { + AppCache, Store, uiGridGroupingConstants, Export, FindEntity, Filters, $rootScope) { // Journal utilities var sorting; var grouping; @@ -40,6 +41,8 @@ function JournalController(Journal, Sorting, Grouping, var columnConfig; var transactions; + var filter = new Filters(); + /** @const the cache alias for this controller */ var cacheKey = 'Journal'; @@ -47,6 +50,7 @@ function JournalController(Journal, Sorting, Grouping, var cache = AppCache(cacheKey + '-filters'); var vm = this; + vm.filter = filter; /** @constants */ vm.ROW_EDIT_FLAG = bhConstants.transactions.ROW_EDIT_FLAG; @@ -356,6 +360,7 @@ function JournalController(Journal, Sorting, Grouping, // save the parameters to use later. Formats the parameters in filtersFmt for the filter toolbar. function cacheFilters(filters) { + filters = filter.applyDefaults(filters); vm.filters = cache.filters = filters; vm.filtersFmt = Journal.formatFilterParameters(filters); vm.filterBarHeight = (vm.filtersFmt.length > 0) ? @@ -372,7 +377,7 @@ function JournalController(Journal, Sorting, Grouping, // clears the filters by forcing a cache of an empty array function clearFilters() { cacheFilters({}); - load({}); + load(vm.filters); } vm.editTransaction = editTransaction; @@ -436,9 +441,25 @@ function JournalController(Journal, Sorting, Grouping, // runs on startup function startup() { - vm.filters = cache.filters; + var filters; + + // @TODO standardise loading/ caching/ assigning filters with a client service + // if filters are directly passed in through params, override cached filters + if ($state.params.filters) { + cacheFilters($state.params.filters); + } + + if (!cache.filters) { cache.filters = {}; } + filters = filter.applyDefaults(cache.filters); + + vm.filters = filters; vm.filtersFmt = Journal.formatFilterParameters(cache.filters || {}); load(vm.filters); + + // show filter bar as needed + vm.filterBarHeight = (vm.filtersFmt.length > 0) ? + bhConstants.utilBar.expandedHeightStyle : + bhConstants.utilBar.collapsedHeightStyle; } // ===================== edit entity =============================== @@ -466,7 +487,7 @@ function JournalController(Journal, Sorting, Grouping, delete row.entity_uuid; delete row.hrEntity; } - + // ===================== end edit entity =========================== startup(); diff --git a/client/src/modules/journal/journal.service.js b/client/src/modules/journal/journal.service.js index fc69638299..0c54e99975 100644 --- a/client/src/modules/journal/journal.service.js +++ b/client/src/modules/journal/journal.service.js @@ -2,16 +2,18 @@ angular.module('bhima.services') .service('JournalService', JournalService); // Dependencies injection -JournalService.$inject = ['PrototypeApiService']; +JournalService.$inject = ['PrototypeApiService', 'FilterService']; /** * Journal Service * This service is responsible of all process with the posting journal */ -function JournalService(Api) { +function JournalService(Api, Filters) { var URL = '/journal/'; var service = new Api(URL); + var filter = new Filters(); + service.formatFilterParameters = formatFilterParameters; service.grid = grid; service.saveChanges = saveChanges; @@ -34,7 +36,7 @@ function JournalService(Api) { added : sanitiseNewRows(added), removed : entity.removedRows, }; - + return service.$http.post('/journal/'.concat(entity.uuid, '/edit'), saveRequest) .then(service.util.unwrapHttpRequest); } @@ -72,6 +74,7 @@ function JournalService(Api) { { field: 'amount', displayName: 'FORM.LABELS.AMOUNT' }, { field: 'project_id', displayName: 'FORM.LABELS.PROJECT' }, { field: 'origin_id', displayName: 'FORM.LABELS.TRANSACTION_TYPE' }, + { field: 'defaultPeriod', displayName: 'TABLE.COLUMNS.PERIOD', ngFilter: 'translate' }, ]; // returns columns from filters @@ -88,6 +91,11 @@ function JournalService(Api) { column.value = value; } + // @FIXME temporary hack for default period + if (column.field === 'defaultPeriod') { + column.value = filter.lookupPeriod(value).label; + } + return true; } else { return false; diff --git a/client/src/modules/journal/modals/search.modal.js b/client/src/modules/journal/modals/search.modal.js index d8542e6734..6e534c340f 100644 --- a/client/src/modules/journal/modals/search.modal.js +++ b/client/src/modules/journal/modals/search.modal.js @@ -10,6 +10,9 @@ function JournalSearchModalController(Instance, Users, Projects, Notify, options vm.options = options || {}; + // @FIXME patch hack - this should be handled by FilterService + delete vm.options.defaultPeriod; + Users.read() .then(function (users) { vm.users = users; diff --git a/server/config/interceptors.js b/server/config/interceptors.js index 95ff7f5c5c..1ac5c06999 100644 --- a/server/config/interceptors.js +++ b/server/config/interceptors.js @@ -15,7 +15,7 @@ const winston = require('winston'); const BadRequest = require('../lib/errors/BadRequest'); -const LOG_ALL_MYSQL_ERRORS = process.env.LOG_ALL_MYSQL_ERRORS; +const LOG_ALL_MYSQL_ERRORS = Number(process.env.LOG_ALL_MYSQL_ERRORS); // map MySQL error codes to HTTP status codes const map = { diff --git a/server/controllers/finance/journal/index.js b/server/controllers/finance/journal/index.js index dbf67b0df3..e4894f5df0 100644 --- a/server/controllers/finance/journal/index.js +++ b/server/controllers/finance/journal/index.js @@ -111,6 +111,8 @@ function find(options, source) { LEFT JOIN document_map dm2 ON dm2.uuid = p.reference_uuid `; + filters.period('defaultPeriod', 'trans_date'); + filters.dateFrom('dateFrom', 'trans_date'); filters.dateTo('dateTo', 'trans_date'); diff --git a/test/end-to-end/edit_journal/edit_journal.spec.js b/test/end-to-end/edit_journal/edit_journal.spec.js index 2b2adb6fda..dd9e41a965 100644 --- a/test/end-to-end/edit_journal/edit_journal.spec.js +++ b/test/end-to-end/edit_journal/edit_journal.spec.js @@ -6,32 +6,25 @@ const GU = require('../shared/GridUtils'); const components = require('../shared/components'); helpers.configure(chai); -const expect = chai.expect; describe('Edit Posting Journal', () => { const path = '#!/journal'; const gridId = 'journal-grid'; - + // simulates a double click - const doubleClick = (element) => browser.actions().mouseMove(element).doubleClick().perform(); + const doubleClick = element => browser.actions().mouseMove(element).doubleClick().perform(); before(() => helpers.navigate(path)); - var accountKey = 11; - - it('edits a transaction change an account', function () { + it('edits a transaction change an account', () => { // click the "grouping" button FU.buttons.grouping(); element.all(by.css('[class="ui-grid-icon-plus-squared"]')).get(0).click(); element.all(by.css('[class="fa fa-edit"]')).get(0).click(); - const accountNumberCell = GU.getCellName(gridId, 1, 4); + const accountNumberCell = GU.getCellName(gridId, 1, 4); doubleClick(accountNumberCell); - - accountNumberCell.element(by.css("input")).clear(); - - accountNumberCell.element(by.css("input")).sendKeys(accountKey); - element.all(by.css('[title="1100 - Test Capital One"]')).click(); + FU.typeahead('accountInputValue', '1100', accountNumberCell); element.all(by.css('[data-method="save"]')).click(); components.notification.hasSuccess(); @@ -40,19 +33,19 @@ describe('Edit Posting Journal', () => { }); - it('edits a transaction change value of Debit and Credit', function () { + it('edits a transaction change value of Debit and Credit', () => { FU.buttons.grouping(); element.all(by.css('[class="ui-grid-icon-plus-squared"]')).get(1).click(); element.all(by.css('[class="fa fa-edit"]')).get(1).click(); - + const debitCell = GU.getCellName(gridId, 2, 5); const creditCell = GU.getCellName(gridId, 3, 6); - + doubleClick(debitCell); - debitCell.element(by.css("input")).sendKeys(50); + debitCell.element(by.css('input')).sendKeys(50); doubleClick(creditCell); - creditCell.element(by.css("input")).sendKeys(50); + creditCell.element(by.css('input')).sendKeys(50); element.all(by.css('[data-method="save"]')).click(); @@ -61,8 +54,8 @@ describe('Edit Posting Journal', () => { FU.buttons.grouping(); }); - // Test for validation - it('Preventing a single-line transaction', function () { + // Test for validation + it('Preventing a single-line transaction', () => { FU.buttons.grouping(); element.all(by.css('[class="ui-grid-icon-plus-squared"]')).get(1).click(); element.all(by.css('[class="fa fa-edit"]')).get(1).click(); @@ -78,19 +71,19 @@ describe('Edit Posting Journal', () => { FU.buttons.grouping(); }); - it('Preventing unbalanced transaction', function () { + it('Preventing unbalanced transaction', () => { FU.buttons.grouping(); element.all(by.css('[class="ui-grid-icon-plus-squared"]')).get(1).click(); element.all(by.css('[class="fa fa-edit"]')).get(1).click(); - + const debitCell = GU.getCellName(gridId, 2, 5); const creditCell = GU.getCellName(gridId, 3, 6); - + doubleClick(debitCell); - debitCell.element(by.css("input")).sendKeys(100); + debitCell.element(by.css('input')).sendKeys(100); browser.actions().mouseMove(creditCell).doubleClick().perform(); - creditCell.element(by.css("input")).sendKeys(50); + creditCell.element(by.css('input')).sendKeys(50); element.all(by.css('[data-method="save"]')).click(); @@ -100,19 +93,19 @@ describe('Edit Posting Journal', () => { FU.buttons.grouping(); }); - it('Preventing transaction who have debit and Credit null', function () { + it('Preventing transaction who have debit and Credit null', () => { FU.buttons.grouping(); element.all(by.css('[class="ui-grid-icon-plus-squared"]')).get(1).click(); element.all(by.css('[class="fa fa-edit"]')).get(1).click(); - + const debitCell = GU.getCellName(gridId, 2, 5); const creditCell = GU.getCellName(gridId, 2, 6); doubleClick(debitCell); - debitCell.element(by.css("input")).sendKeys(0); + debitCell.element(by.css('input')).sendKeys(0); doubleClick(creditCell); - creditCell.element(by.css("input")).sendKeys(0); + creditCell.element(by.css('input')).sendKeys(0); element.all(by.css('[data-method="save"]')).click(); @@ -122,19 +115,19 @@ describe('Edit Posting Journal', () => { FU.buttons.grouping(); }); - it('Preventing transaction who was debited and Credited in a same line', function () { + it('Preventing transaction who was debited and Credited in a same line', () => { FU.buttons.grouping(); element.all(by.css('[class="ui-grid-icon-plus-squared"]')).get(1).click(); element.all(by.css('[class="fa fa-edit"]')).get(1).click(); - + const debitCell = GU.getCellName(gridId, 2, 5); const creditCell = GU.getCellName(gridId, 2, 6); doubleClick(debitCell); - debitCell.element(by.css("input")).sendKeys(50); + debitCell.element(by.css('input')).sendKeys(50); doubleClick(creditCell); - creditCell.element(by.css("input")).sendKeys(50); + creditCell.element(by.css('input')).sendKeys(50); element.all(by.css('[data-method="save"]')).click(); @@ -143,5 +136,4 @@ describe('Edit Posting Journal', () => { element.all(by.css('[class="ui-grid-icon-minus-squared"]')).get(0).click(); FU.buttons.grouping(); }); - });