Skip to content

Commit

Permalink
fix(enterprise): account select sane defaults
Browse files Browse the repository at this point in the history
This commit disables the account ui-select on the enterprise page for
title accounts.  It also includes some minor code cleanup, including
ensuring accounts are properly ordered.

This also includes some performance improvements by debouncing the
ui-select search routine.
  • Loading branch information
Jonathan Niles authored and sfount committed Nov 27, 2016
1 parent aaada58 commit 2907850
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 55 deletions.
18 changes: 12 additions & 6 deletions client/src/partials/enterprises/enterprises.html
Original file line number Diff line number Diff line change
Expand Up @@ -62,13 +62,16 @@

<ui-select
name="gain_account"
ng-model="EnterpriseCtrl.enterprise.gain_account"
theme="bootstrap"
ng-model="EnterpriseCtrl.enterprise.gain_account_id"
ng-model-options="{ 'debounce' : 250 }"
required>
<ui-select-match placeholder="{{ 'FORM.PLACEHOLDERS.ACCOUNT' | translate }}">
<strong>{{$select.selected.number}}</strong> <span>{{$select.selected.label}}</span>
</ui-select-match>
<ui-select-choices ui-select-focus-patch repeat="account.id as account in EnterpriseCtrl.accounts.data | filter:$select.search">
<ui-select-choices
ui-select-focus-patch
ui-disable-choice="account.type_id === EnterpriseCtrl.bhConstants.accounts.TITLE"
repeat="account.id as account in EnterpriseCtrl.accounts | filter: { 'hrlabel': $select.search }">
<strong ng-bind-html="account.number | highlight:$select.search"></strong>
<span ng-bind-html="account.label | highlight:$select.search"></span>
</ui-select-choices>
Expand All @@ -87,13 +90,16 @@

<ui-select
name="loss_account"
ng-model="EnterpriseCtrl.enterprise.loss_account"
theme="bootstrap"
ng-model="EnterpriseCtrl.enterprise.loss_account_id"
ng-model-options="{ 'debounce' : 250 }"
required>
<ui-select-match placeholder="{{ 'FORM.PLACEHOLDERS.ACCOUNT' | translate }}">
<strong>{{$select.selected.number}}</strong> <span>{{$select.selected.label}}</span>
</ui-select-match>
<ui-select-choices ui-select-focus-patch repeat="account.id as account in EnterpriseCtrl.accounts.data | filter:$select.search">
<ui-select-choices
ui-select-focus-patch
ui-disable-choice="account.type_id === EnterpriseCtrl.bhConstants.accounts.TITLE"
repeat="account.id as account in EnterpriseCtrl.accounts | filter:{'hrlabel' : $select.search}">
<strong ng-bind-html="account.number | highlight:$select.search"></strong>
<span ng-bind-html="account.label | highlight:$select.search"></span>
</ui-select-choices>
Expand Down
67 changes: 27 additions & 40 deletions client/src/partials/enterprises/enterprises.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
angular.module('bhima.controllers')
.controller('EnterpriseController', EnterpriseController);
.controller('EnterpriseController', EnterpriseController);

EnterpriseController.$inject = [
'$translate', 'EnterpriseService', 'CurrencyService', 'AccountStoreService',
'util', 'NotifyService', 'ProjectService', 'ModalService'
'EnterpriseService', 'CurrencyService', 'util', 'NotifyService',
'ProjectService', 'ModalService', 'AccountService', 'bhConstants'
];

/**
* Enterprise Controller
*/
function EnterpriseController($translate, Enterprises, Currencies, Accounts, util, Notify, Projects, Modal) {
function EnterpriseController(Enterprises, Currencies, util, Notify, Projects, Modal, Accounts, bhConstants) {
var vm = this;

vm.bhConstants = bhConstants;

vm.enterprises = [];
vm.enterprise = {};
vm.maxLength = util.maxTextLength;
Expand All @@ -29,45 +31,30 @@ function EnterpriseController($translate, Enterprises, Currencies, Accounts, uti

// load enterprises
Enterprises.read(null, { detailed : 1 })
.then(function (enterprises) {
vm.hasEnterprise = enterprises.length ? true : false;
vm.enterprises = vm.hasEnterprise ? enterprises : [];

/**
* @note: set the enterprise to the first one
* this choice need the team point of view for to setting the default enterprise
*/
vm.enterprise = vm.hasEnterprise ? vm.enterprises[0] : {};
})
.then(Accounts.accounts)
.then(function (list) {
vm.accounts = list;

// gain account
vm.enterprise.gain_account = vm.accounts.get(vm.enterprise.gain_account_id);
// loss account
vm.enterprise.loss_account = vm.accounts.get(vm.enterprise.loss_account_id);
})
.then(refreshProjects)
.catch(Notify.handleError);
.then(function (enterprises) {
vm.hasEnterprise = (enterprises.length > 0);
vm.enterprises = vm.hasEnterprise ? enterprises : [];

// load accounts
Accounts.accounts()
.then(function (list) {
vm.accounts = list;
/**
* @note: set the enterprise to the first one
* this choice need the team point of view for to setting the default enterprise
*/
vm.enterprise = vm.hasEnterprise ? vm.enterprises[0] : {};

// gain account
vm.enterprise.gain_account = vm.accounts.get(vm.enterprise.gain_account_id);
// loss account
vm.enterprise.loss_account = vm.accounts.get(vm.enterprise.loss_account_id);
})
.catch(Notify.handleError);
return Accounts.read();
})
.then(function (accounts) {
vm.accounts = Accounts.order(accounts);
return refreshProjects();
})
.catch(Notify.handleError);

// load currencies
Currencies.read()
.then(function (currencies) {
vm.currencies = currencies;
}).catch(Notify.handleError);
.then(function (currencies) {
vm.currencies = currencies;
})
.catch(Notify.handleError);

}

Expand Down Expand Up @@ -104,8 +91,8 @@ function EnterpriseController($translate, Enterprises, Currencies, Accounts, uti
location_id : enterprise.location_id,
currency_id : enterprise.currency_id,
po_box : enterprise.po_box,
gain_account_id : enterprise.gain_account.id,
loss_account_id : enterprise.loss_account.id
gain_account_id : enterprise.gain_account_id,
loss_account_id : enterprise.loss_account_id
};
}

Expand Down
18 changes: 9 additions & 9 deletions test/end-to-end/enterprises/enterprises.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ helpers.configure(chai);
const FU = require('../shared/FormUtils');
const components = require('../shared/components');

describe('Enterprises ::', function () {
describe('Enterprises', function () {

const path = '#/enterprises';
const enterpriseId = 1;
Expand All @@ -20,8 +20,8 @@ describe('Enterprises ::', function () {
email : 'ima@imaworldhealth.com',
po_box : 'POBOX USA 1',
phone : '01500',
gain_account : 'Test Gain Account',
loss_account : 'Test Expense Accounts'
gain_account_id : 'Test Gain Account',
loss_account_id : 'Test Expense Accounts'
};

// default enterprise
Expand All @@ -31,8 +31,8 @@ describe('Enterprises ::', function () {
email : 'enterprise@test.org',
po_box : 'POBOX USA 1',
phone : '243 81 504 0540',
gain_account : 'Test Gain Account',
loss_account : 'Test Expense Accounts'
gain_account_id : 'Test Gain Account',
loss_account_id : 'Test Expense Accounts'
};

// project
Expand Down Expand Up @@ -61,8 +61,8 @@ describe('Enterprises ::', function () {
FU.input('EnterpriseCtrl.enterprise.name', enterprise.name);
FU.input('EnterpriseCtrl.enterprise.abbr', enterprise.abbr);

FU.uiSelect('EnterpriseCtrl.enterprise.gain_account', enterprise.gain_account);
FU.uiSelect('EnterpriseCtrl.enterprise.loss_account', enterprise.loss_account);
FU.uiSelect('EnterpriseCtrl.enterprise.gain_account_id', enterprise.gain_account_id);
FU.uiSelect('EnterpriseCtrl.enterprise.loss_account_id', enterprise.loss_account_id);

FU.input('EnterpriseCtrl.enterprise.po_box', enterprise.po_box);
FU.input('EnterpriseCtrl.enterprise.email', enterprise.email);
Expand Down Expand Up @@ -105,8 +105,8 @@ describe('Enterprises ::', function () {
FU.input('EnterpriseCtrl.enterprise.name', default_enterprise.name);
FU.input('EnterpriseCtrl.enterprise.abbr', default_enterprise.abbr);

FU.uiSelect('EnterpriseCtrl.enterprise.gain_account', default_enterprise.gain_account);
FU.uiSelect('EnterpriseCtrl.enterprise.loss_account', default_enterprise.loss_account);
FU.uiSelect('EnterpriseCtrl.enterprise.gain_account_id', default_enterprise.gain_account_id);
FU.uiSelect('EnterpriseCtrl.enterprise.loss_account_id', default_enterprise.loss_account_id);

FU.input('EnterpriseCtrl.enterprise.po_box', default_enterprise.po_box);
FU.input('EnterpriseCtrl.enterprise.email', default_enterprise.email);
Expand Down

0 comments on commit 2907850

Please sign in to comment.