Skip to content

Commit

Permalink
Merge pull request #7346 from Ebed-meleck/registry-user
Browse files Browse the repository at this point in the history
fix search by period.

Tested okay by @jmcameron.
  • Loading branch information
jmcameron committed Nov 30, 2023
2 parents 5b83721 + d519b46 commit 6a77482
Show file tree
Hide file tree
Showing 8 changed files with 81 additions and 16 deletions.
1 change: 1 addition & 0 deletions client/src/i18n/en/form.json
Original file line number Diff line number Diff line change
Expand Up @@ -1075,6 +1075,7 @@
"RENDERER" : "Select a Renderer",
"REPORT_TYPE": "Select a Report Type",
"RESULT_ACCOUNT_SCT": "Select a Result Account section",
"ROLE": "Select a role",
"ROOM":"Select a Room",
"ROOM_TYPE":"Select a Room Type",
"ROOT_ACCOUNT": "Select a Root Account",
Expand Down
1 change: 1 addition & 0 deletions client/src/i18n/fr/form.json
Original file line number Diff line number Diff line change
Expand Up @@ -1075,6 +1075,7 @@
"RENDERER" : "Sélectionner un rendu",
"REPORT_TYPE": "Sélectionner le type de rapport",
"RESULT_ACCOUNT_SCT": "Sélectionnez une section de compte de résultats",
"ROLE": "Sélectionner un role",
"ROOM":"Sélectionner une chambre",
"ROOM_TYPE":"Sélectionner un type de lit",
"ROOT_ACCOUNT": "Sélectionner le compte titre",
Expand Down
2 changes: 2 additions & 0 deletions client/src/js/components/bhPeriodSelect.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ angular.module('bhima.components')
bindings : {
defaultPeriod : '@',
onSelectCallback : '&',
label : '@?',
},
templateUrl : 'modules/templates/bhPeriodSelect.tmpl.html',
controller : PeriodSelect,
Expand Down Expand Up @@ -30,6 +31,7 @@ function PeriodSelect(Periods, bhConstants) {
ctrl.dateFormat = bhConstants.dates.format;

ctrl.$onInit = function onInit() {
ctrl.label = ctrl.label || 'FORM.LABELS.PERIOD';
ctrl.periodKey = ctrl.defaultPeriod || DEFAULT_PERIOD;
ctrl.period = Periods.definition(ctrl.periodKey);

Expand Down
5 changes: 3 additions & 2 deletions client/src/modules/templates/bhPeriodSelect.tmpl.html
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
<div class="form-group" data-bh-period-select>
<label class="form-label">
<span ng-if="$ctrl.required" translate>PERIODS.PERIOD_LIMIT</span>
<span ng-if="!$ctrl.required" translate>PERIODS.PERIOD_LIMIT_OPTIONAL</span>
<span ng-if="$ctrl.label==='FORM.LABELS.PERIOD' && $ctrl.required" translate>FORM.LABELS.PERIOD</span>
<span ng-if="$ctrl.label==='FORM.LABELS.PERIOD' && !$ctrl.required" translate>FORM.LABELS.PERIOD_OPTIONAL</span>
<span ng-if="$ctrl.label!=='FORM.LABELS.PERIOD'" translate>{{ $ctrl.label }}</span>
</label>
<p class="form-static">
<span translate>{{$ctrl.period.translateKey}}</span>
Expand Down
49 changes: 38 additions & 11 deletions client/src/modules/users/search.modal.html
Original file line number Diff line number Diff line change
Expand Up @@ -31,21 +31,47 @@
on-select-callback="$ctrl.onSelectDepot(depot)">
<bh-clear on-clear="$ctrl.clear('depot_uuid')"></bh-clear>
</bh-depot-select>


<!-- roles -->
<div class="form-group has-feedback">
<label class="control-label" translate>FORM.LABELS.ROLES</label>
<bh-clear on-clear="$ctrl.clear('role_uuid')"></bh-clear>
<ui-select name="role_uuid"
ng-model="$ctrl.searchQueries.role_uuid"
on-select="$ctrl.onSelectRole($item, $model)"
required="false"
>
<ui-select-match placeholder="{{ 'FORM.SELECT.ROLE' | translate }}"><span translate>{{$select.selected.label}}</span></ui-select-match>
<ui-select-choices ui-select-focus-patch repeat="role.uuid as role in ($ctrl.roles | filter:$select.search) track by role.uuid">
<span ng-bind-html="role.label | highlight:$select.search"></span>
</ui-select-choices>
</ui-select>
</div>

<!-- cashbox -->
<div class="form-group has-feedback">
<label class="control-label" translate>FORM.SELECT.CASHBOX_OPTIONAL</label>
<bh-clear on-clear="$ctrl.clear('cashbox_id')"></bh-clear>
<ui-select name="cashbox_id"
ng-model="$ctrl.searchQueries.cashbox_id"
on-select="$ctrl.onSelectCashbox($item, $model)"
required>
<ui-select-match placeholder="{{ 'FORM.SELECT.CASHBOX' | translate }}"><span translate>{{$select.selected.label}}</span></ui-select-match>
<ui-select-choices ui-select-focus-patch repeat="cashbox.id as cashbox in ($ctrl.cashboxes | filter:$select.search) track by cashbox.id">
<span ng-bind-html="cashbox.label | highlight:$select.search"></span>
</ui-select-choices>
</ui-select>
</div>
<ui-select name="cashbox_id"
ng-model="$ctrl.searchQueries.cashbox_id"
on-select="$ctrl.onSelectCashbox($item, $model)"
required="false"
>
<ui-select-match placeholder="{{ 'FORM.SELECT.CASHBOX' | translate }}"><span translate>{{$select.selected.label}}</span></ui-select-match>
<ui-select-choices ui-select-focus-patch repeat="cashbox.id as cashbox in ($ctrl.cashboxes | filter:$select.search) track by cashbox.id">
<span ng-bind-html="cashbox.label | highlight:$select.search"></span>
</ui-select-choices>
</ui-select>
</div>

<!-- login date -->
<bh-date-interval
label="USERS.LAST_LOGIN"
date-id="login-date"
date-from="$ctrl.searchQueries.login_date_from"
date-to="$ctrl.searchQueries.login_date_to"
on-change="$ctrl.onLoginDate(dateFrom, dateTo)">
</bh-date-interval>

</div>
</uib-tab>
Expand All @@ -54,6 +80,7 @@
<div class="tab-body">
<!-- period selection -->
<bh-period-select
label="FORM.LABELS.DATE_CREATED"
default-period="{{$ctrl.filters.period}}"
on-select-callback="$ctrl.onSelectPeriod(period)">
</bh-period-select>
Expand Down
28 changes: 25 additions & 3 deletions client/src/modules/users/search.modal.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ angular.module('bhima.controllers')

UserRegistryModalController.$inject = [
'$uibModalInstance', 'filters', 'Store', 'util', 'PeriodService', 'UserService',
'SearchModalUtilService', 'CashboxService', 'NotifyService',
'SearchModalUtilService', 'CashboxService', 'NotifyService', 'RolesService',
];

/**
Expand All @@ -16,7 +16,7 @@ UserRegistryModalController.$inject = [
*/
function UserRegistryModalController(
ModalInstance, filters, Store, util, Periods,
Users, SearchModal, CashBox, Notify) {
Users, SearchModal, CashBox, Notify, RolesService) {
const vm = this;
const changes = new Store({ identifier : 'key' });

Expand All @@ -25,6 +25,7 @@ function UserRegistryModalController(

const searchQueryOptions = [
'display_name', 'depot_uuid', 'id', 'cashbox_id',
'role_uuid', 'login_date_from', 'login_date_to',
];

vm.filters = filters;
Expand Down Expand Up @@ -77,12 +78,25 @@ function UserRegistryModalController(
displayValues.cashbox_id = cash.label;
};

// custom filter cashbox
vm.onSelectRole = function onSelectRole(role) {
vm.searchQueries.role_uuid = role.uuid;
displayValues.role_uuid = role.label;
};

// custom filter depot_uuid - assign the value to the params object
vm.onSelectDepot = function onSelectDepot(depot) {
vm.searchQueries.depot_uuid = depot.uuid;
displayValues.depot_uuid = depot.text;
};

// Save the login dates
vm.onLoginDate = (dateFrom, dateTo) => {
vm.searchQueries.login_date_from = dateFrom;
displayValues.login_date_from = dateFrom;
vm.searchQueries.login_date_to = dateTo;
displayValues.login_date_to = dateTo;
};
// returns the parameters to the parent controller
function submit() {
const loggedChanges = SearchModal.getChanges(vm.searchQueries, changes, displayValues, lastDisplayValues);
Expand All @@ -96,7 +110,14 @@ function UserRegistryModalController(
vm.cashboxes = data;
}).catch(Notify.handleError);
}

// load all roles
function loadRoles() {
return RolesService.read()
.then(role => {
vm.roles = role;
})
.catch(Notify.handleError);
}
function clear(value) {
delete vm.searchQueries[value];
}
Expand All @@ -107,4 +128,5 @@ function UserRegistryModalController(
}

loadCashBoxes();
loadRoles();
}
6 changes: 6 additions & 0 deletions client/src/modules/users/users.service.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,12 @@ function UserService(Api, $uibModal, Filters, bhConstants, AppCache, Periods) {
{ key : 'depot_uuid', label : 'FORM.LABELS.DEPOT' },
{ key : 'display_name', label : 'FORM.LABELS.USERNAME' },
{ key : 'id', label : 'FORM.LABELS.USERNAME' },
{
key : 'login_date_from', label : 'USERS.LAST_LOGIN', comparitor : '>', valueFilter : 'date',
},
{
key : 'login_date_to', label : 'USERS.LAST_LOGIN', comparitor : '<', valueFilter : 'date',
},
]);

if (filterCache.filters) {
Expand Down
5 changes: 5 additions & 0 deletions server/controllers/admin/users/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,11 @@ async function list(req, res, next) {
filters.equals('depot_uuid', 'depot_uuid', 'dp');
filters.equals('cashbox_id', 'id', 'cb');
filters.fullText('display_name');
filters.period('period', 'created_at');
filters.dateFrom('custom_period_start', 'created_at');
filters.dateTo('custom_period_end', 'created_at');
filters.dateFrom('login_date_from', 'last_login');
filters.dateTo('login_date_to', 'last_login');

filters.setGroup('GROUP BY user.id');
filters.setOrder('ORDER BY user.display_name DESC');
Expand Down

0 comments on commit 6a77482

Please sign in to comment.