Skip to content

Commit

Permalink
perf: Refactoring the code
Browse files Browse the repository at this point in the history
  • Loading branch information
DedrickEnc committed Jun 3, 2017
1 parent 11566f3 commit 090d999
Show file tree
Hide file tree
Showing 16 changed files with 252 additions and 362 deletions.
2 changes: 1 addition & 1 deletion client/src/modules/employees/employee.service.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ function EmployeeService(Filters, $uibModal, Api) {
function formatFilterParameters(params) {
var columns = [
{ field: 'display_name', displayName: 'FORM.LABELS.NAME' },
{ field: 'sexe', displayName: 'FORM.LABELS.GENDER' },
{ field: 'sex', displayName: 'FORM.LABELS.GENDER' },
{ field: 'code', displayName: 'FORM.LABELS.CODE' },
{ field: 'dateBirthFrom', displayName: 'FORM.LABELS.DOB', comparitor: '>', ngFilter:'date' },
{ field: 'dateBirthTo', displayName: 'FORM.LABELS.DOB', comparitor: '<', ngFilter:'date' },
Expand Down
72 changes: 36 additions & 36 deletions client/src/modules/employees/registration/employees.html

Large diffs are not rendered by default.

15 changes: 7 additions & 8 deletions client/src/modules/employees/registration/employees.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,29 +28,29 @@ function EmployeeController(Employees, Services, Grades, Functions, CreditorGrou

// Loading Grades
Grades.read(null, { detailed : 1 }).then((data) => {
data.forEach((g) => {
g.format = `${g.code} - ${g.text}`;
data.forEach(function (g){
g.format = g.code + ' - ' + g.text;
});
vm.grades = data;
}).catch(Notify.handleError);

// Loading Creditor Groups
CreditorGroups.read().then((data) => {
CreditorGroups.read().then(function (data) {
vm.creditorGroups = data;
}).catch(Notify.handleError);

// Loading Debtor Groups
DebtorGroups.read().then((data) => {
DebtorGroups.read().then(function (data) {
vm.debtorGroups = data;
}).catch(Notify.handleError);

// Loading Services
Services.read().then((services) => {
Services.read().then(function (services) {
vm.services = services;
}).catch(Notify.handleError);

// Loading Functions
Functions.read().then((data) => {
Functions.read().then(function (data) {
vm.functions = data;
}).catch(Notify.handleError);

Expand All @@ -60,10 +60,9 @@ function EmployeeController(Employees, Services, Grades, Functions, CreditorGrou
var promise;

if (employeeForm.$invalid) { return Notify.danger('FORM.ERRORS.INVALID');}
if (!employeeForm.$dirty) { return Notify.danger('FORM.ERRORS.NO_DATA_PROVIDED'); }

return Employees.create(vm.employee)
.then((feedBack) => {
.then(function (feedBack) {
Receipts.patient(feedBack.patient_uuid, true);

// reset form state
Expand Down
54 changes: 25 additions & 29 deletions client/src/modules/employees/registry/registry.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ angular.module('bhima.controllers')
EmployeeRegistryController.$inject = [
'$state', 'EmployeeService', 'NotifyService', 'AppCache',
'util', 'ReceiptModal', 'uiGridConstants', '$translate',
'GridColumnService', 'GridSortingService', 'bhConstants',
'GridColumnService', 'bhConstants',
'DepricatedFilterService',
];

Expand All @@ -15,7 +15,7 @@ EmployeeRegistryController.$inject = [
*/
function EmployeeRegistryController($state, Employees, Notify, AppCache,
util, Receipts, uiGridConstants, $translate,
Columns, Sorting, bhConstants, Filters) {
Columns, bhConstants, Filters) {
var vm = this;
var filter = new Filters();

Expand All @@ -28,7 +28,7 @@ function EmployeeRegistryController($state, Employees, Notify, AppCache,
vm.search = search;
vm.onRemoveFilter = onRemoveFilter;
vm.clearFilters = clearFilters;
vm.employeeCard = employeeCard;
vm.openPatientCard = openPatientCard;
vm.filterBarHeight = {};
vm.openColumnConfiguration = openColumnConfiguration;

Expand All @@ -46,7 +46,7 @@ function EmployeeRegistryController($state, Employees, Notify, AppCache,
displayName : 'TABLE.COLUMNS.NAME',
headerCellFilter : 'translate',
},
{ field : 'sexe',
{ field : 'sex',
displayName : 'TABLE.COLUMNS.GENDER',
headerCellFilter : 'translate',
},
Expand All @@ -58,7 +58,8 @@ function EmployeeRegistryController($state, Employees, Notify, AppCache,
{ field : 'date_embauche',
displayName : 'FORM.LABELS.DATE_EMBAUCHE',
headerCellFilter : 'translate',
type : 'date',
type : 'date',
visible : false
},
{ field : 'text',
displayName : 'TABLE.COLUMNS.GRADE',
Expand All @@ -68,15 +69,18 @@ function EmployeeRegistryController($state, Employees, Notify, AppCache,
displayName : 'FORM.LABELS.NB_SPOUSE',
headerCellFilter : 'translate',
type : 'number',
visible : false
},
{ field : 'nb_enfant',
displayName : 'FORM.LABELS.NB_CHILD',
headerCellFilter : 'translate',
type : 'number',
visible : false
},
{ field : 'daily_salary',
displayName : 'FORM.LABELS.DAILY_SALARY',
headerCellFilter : 'translate',
visible : false
},
{ field : 'bank',
displayName : 'FORM.LABELS.BANK',
Expand Down Expand Up @@ -115,20 +119,17 @@ function EmployeeRegistryController($state, Employees, Notify, AppCache,
},
{ name : 'actions',
displayName : '',
cellTemplate : '/modules/employees/templates/action.cell.html',
enableSorting : false
},
cellTemplate : '/modules/employees/templates/action.cell.html'
}
];

/** TODO manage column : last_transaction */
vm.uiGridOptions = {
appScopeProvider : vm,
showColumnFooter : true,
enableSorting : true,
enableColumnMenus : false,
flatEntityAccess : true,
fastWatch : true,
columnDefs : columnDefs,
columnDefs : columnDefs
};

var columnConfig = new Columns(vm.uiGridOptions, cacheKey);
Expand All @@ -150,25 +151,20 @@ function EmployeeRegistryController($state, Employees, Notify, AppCache,
vm.hasError = false;
toggleLoadingIndicator();

// if we have search parameters, use search. Otherwise, just read all
// employees.
var request = angular.isDefined(parameters) && !isEmpty(parameters) ?
Employees.search(parameters) :
Employees.read();

// hook the returned patients up to the grid.
request.then(function (employees) {
employees.forEach(function (employee) {
employee.employeeAge = util.getMomentAge(employee.dob, 'years');
Employees.read(null, parameters)
.then(function (employees) {
employees.forEach(function (employee) {
employee.employeeAge = util.getMomentAge(employee.dob, 'years');
});

// put data in the grid
vm.uiGridOptions.data = employees;
})
.catch(handler)
.finally(function () {
toggleLoadingIndicator();
});

// put data in the grid
vm.uiGridOptions.data = employees;
})
.catch(handler)
.finally(function () {
toggleLoadingIndicator();
});
}

// search and filter data in employee Registry
Expand Down Expand Up @@ -219,7 +215,7 @@ function EmployeeRegistryController($state, Employees, Notify, AppCache,
}

// employee patient card
function employeeCard(uuid) {
function openPatientCard(uuid) {
Receipts.patient(uuid);
}

Expand Down
63 changes: 13 additions & 50 deletions client/src/modules/employees/registry/search.modal.html
Original file line number Diff line number Diff line change
Expand Up @@ -27,34 +27,20 @@
<br />

<fieldset>
<legend>
{{ "FORM.LABELS.EMPLOYEE_DETAILS" | translate }}
</legend>
<legend translate>FORM.LABELS.EMPLOYEE_DETAILS</legend>

<div class="form-group" ng-class="{ 'has-error' : ModalForm.$submitted && ModalForm.name.$invalid }">
<label class="control-label">
{{ 'FORM.LABELS.NAME' | translate }}
</label>
<span style="display:inline-block;" class="pull-right">
<a href ng-click="ModalCtrl.clear('display_name')" tabindex="-1">
<i class="fa fa-eraser"></i> <span translate>FORM.BUTTONS.CLEAR</span>
</a>
</span>
<label class="control-label" translate>FORM.LABELS.NAME</label>
<bh-clear on-clear="ModalCtrl.clear('display_name')"></bh-clear>
<input type="text" class="form-control" name="display_name" ng-model="ModalCtrl.params.display_name">
<div class="help-block" ng-messages="ModalForm.display_name.$error" ng-show="ModalForm.$submitted">
<div ng-messages-include="modules/templates/messages.tmpl.html"></div>
</div>
</div>

<div class="form-group" ng-class="{ 'has-error' : ModalForm.$submitted && ModalForm.code.$invalid }">
<label class="control-label">
{{ 'FORM.LABELS.CODE' | translate }}
</label>
<span style="display:inline-block;" class="pull-right">
<a href ng-click="ModalCtrl.clear('code')" tabindex="-1">
<i class="fa fa-eraser"></i> <span translate>FORM.BUTTONS.CLEAR</span>
</a>
</span>
<label class="control-label" translate>FORM.LABELS.CODE</label>
<bh-clear on-clear="ModalCtrl.clear('code')"></bh-clear>
<input type="text" class="form-control" name="code" ng-model="ModalCtrl.params.code">
<div class="help-block" ng-messages="ModalForm.code.$error" ng-show="ModalForm.$submitted">
<div ng-messages-include="modules/templates/messages.tmpl.html"></div>
Expand All @@ -65,22 +51,18 @@
<p class="control-label">
<strong translate>FORM.LABELS.GENDER</strong>

<span style="display:inline-block;" class="pull-right">
<a href ng-click="ModalCtrl.clear('sexe')" tabindex="-1">
<i class="fa fa-eraser"></i> <span translate>FORM.BUTTONS.CLEAR</span>
</a>
</span>
<bh-clear on-clear="ModalCtrl.clear('sex')"></bh-clear>
</p>

<label>
<input type="radio" name="sexe" id="male" value="M" ng-model="ModalCtrl.params.sexe">
<input type="radio" name="sex" id="male" value="M" ng-model="ModalCtrl.params.sex">
<span translate>FORM.LABELS.MALE</span>
</label>
</div>

<div class="radio">
<label>
<input type="radio" name="sexe" id="female" value="F" ng-model="ModalCtrl.params.sexe">
<input type="radio" name="sex" id="female" value="F" ng-model="ModalCtrl.params.sex">
<span translate>FORM.LABELS.FEMALE</span>
</label>
</div>
Expand All @@ -90,14 +72,7 @@
FORM.LABELS.GRADE
</label>

<!-- @todo make this a component - it is used everywhere. Calls back method
`clear` and resets the id passed to the component -->
<span style="display:inline-block;" class="pull-right">
<a href ng-click="ModalCtrl.clear('grade')" tabindex="-1">
<i class="fa fa-eraser"></i> <span translate>FORM.BUTTONS.CLEAR</span>
</a>
</span>

<bh-clear on-clear="ModalCtrl.clear('grade_id')"></bh-clear>
<!-- @todo make data driven selects components to handle loading and error states -->
<select
class="form-control"
Expand All @@ -115,20 +90,14 @@
FORM.LABELS.FUNCTION
</label>

<!-- @todo make this a component - it is used everywhere. Calls back method
`clear` and resets the id passed to the component -->
<span style="display:inline-block;" class="pull-right">
<a href ng-click="ModalCtrl.clear('function')" tabindex="-1">
<i class="fa fa-eraser"></i> <span translate>FORM.BUTTONS.CLEAR</span>
</a>
</span>
<bh-clear on-clear="ModalCtrl.clear('fonction_id')"></bh-clear>

<!-- @todo make data driven selects components to handle loading and error states -->
<select
class="form-control"
name="function"
ng-options="function.id as function.function_txt for function in ModalCtrl.functions"
ng-model="ModalCtrl.params.function_id">
ng-options="f.id as f.fonction_txt for f in ModalCtrl.functions"
ng-model="ModalCtrl.params.fonction_id">
<option disabled value="" translate>
FORM.PLACEHOLDERS.FUNCTION
</option>
Expand All @@ -140,13 +109,7 @@
FORM.LABELS.SERVICE
</label>

<!-- @todo make this a component - it is used everywhere. Calls back method
`clear` and resets the id passed to the component -->
<span style="display:inline-block;" class="pull-right">
<a href ng-click="ModalCtrl.clear('service')" tabindex="-1">
<i class="fa fa-eraser"></i> <span translate>FORM.BUTTONS.CLEAR</span>
</a>
</span>
<bh-clear on-clear="ModalCtrl.clear('service_id')"></bh-clear>

<!-- @todo make data driven selects components to handle loading and error states -->
<select
Expand Down
7 changes: 3 additions & 4 deletions client/src/modules/employees/registry/search.modal.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,11 @@ EmployeeRegistryModalController.$inject = [
];

/**
* @class PatientRegistryModalController
* @class EmployeeRegistryModalController
*
* @description
* This controller is responsible for setting up the filters for the patient
* search functionality on the patient registry page. Filters that are already
* applied to the grid can be passed in via the params inject.
* This controller is responsible for setting up the filters for the employee
* search functionality on the employee registry page.
*/
function EmployeeRegistryModalController(ModalInstance, params, Functions, Grades, bhConstants, moment, Services) {
var vm = this;
Expand Down
4 changes: 2 additions & 2 deletions client/src/modules/employees/templates/action.cell.html
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@
</li>
<li class="divider"></li>
<li>
<a data-method="card" href>
<a data-method="invoice" href>
<span class="fa fa-file-text-o"></span> <span translate>PATIENT_REGISTRY.INVOICES</span>
</a>
</li>
<li>
<a data-method="card" href>
<a data-method="payment" href>
<span class="fa fa-money"></span> <span translate>PATIENT_REGISTRY.PAYMENTS</span>
</a>
</li>
Expand Down
Loading

0 comments on commit 090d999

Please sign in to comment.