Skip to content

Commit

Permalink
fix(stock): improve movements registry
Browse files Browse the repository at this point in the history
This commit fixes a number of bugs on the movements registry.
 1. The input/output search parameter now actually filters correctly.
 2. The "reason" ui-select actually filters the registry.
 3. The "actions" column does not present a dropdown on header rows.
 4. The date and unit cost columns sort properly.
 5. The grid footer no longer gives untranslated english text in the
 footer.

It also improves the performance of the registry by pre-computing costs
in the same way that it pre-computes the flux mappings.

Closes IMA-WorldHealth#2073.  Closes IMA-WorldHealth#2072.
  • Loading branch information
jniles committed Sep 2, 2017
1 parent b1f298c commit 108c4d1
Show file tree
Hide file tree
Showing 9 changed files with 262 additions and 296 deletions.
19 changes: 10 additions & 9 deletions client/src/modules/stock/lots/registry.js
Original file line number Diff line number Diff line change
Expand Up @@ -124,9 +124,10 @@ function StockLotsController(Stock, Notify,

if($state.params.filters) {
var changes = [{ key : $state.params.filters.key, value : $state.params.filters.value }]
stockLotFilters.replaceFilters(changes);
stockLotFilters.replaceFilters(changes);
Stock.cacheFilters(filterKey);
}

load(stockLotFilters.formatHTTP(true));
vm.latestViewFilters = stockLotFilters.formatView();
}
Expand Down Expand Up @@ -160,14 +161,14 @@ function StockLotsController(Stock, Notify,
toggleLoadingIndicator();

Stock.lots.read(null, filters)
.then(function(lots){
vm.gridOptions.data = lots;
vm.grouping.unfoldAllGroups();
})
.catch(errorHandler)
.finally(function (){
toggleLoadingIndicator();
});
.then(function (lots) {
vm.gridOptions.data = lots;
vm.grouping.unfoldAllGroups();
})
.catch(errorHandler)
.finally(function (){
toggleLoadingIndicator();
});
}

// remove a filter with from the filter object, save the filters and reload
Expand Down
27 changes: 8 additions & 19 deletions client/src/modules/stock/movements/modals/search.modal.html
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,13 @@
<bh-clear on-clear="$ctrl.clear('is_exit')"></bh-clear>
<div class="radio">
<label>
<input type="radio" name="is_exit" value="0" ng-model="$ctrl.searchQueries.is_exit">
<input type="radio" name="is_exit" value="0" ng-model="$ctrl.searchQueries.is_exit">
<span translate>STOCK.INPUT</span>
</label>
</div>
<div class="radio">
<label>
<input type="radio" name="is_exit" value="0" ng-model="$ctrl.searchQueries.is_exit">
<input type="radio" name="is_exit" value="1" ng-model="$ctrl.searchQueries.is_exit">
<span translate>STOCK.OUTPUT</span>
</label>
</div>
Expand Down Expand Up @@ -59,27 +59,16 @@
<div class="form-group">
<label class="control-label" translate>STOCK.FLUX</label>
<bh-clear on-clear="$ctrl.clear('flux_id')"></bh-clear>

<ui-select name="inventory" ng-model="$ctrl.searchQueries.flux_id">
<ui-select-match>
<span translate>{{$select.selected.label}}</span>
</ui-select-match>
<ui-select-choices ui-select-focus-patch repeat="flux as flux in $ctrl.fluxes | filter:{ 'label': $select.search }">
<ui-select-choices ui-select-focus-patch repeat="flux.id as flux in $ctrl.fluxes | filter:{ 'label': $select.search }">
<span ng-bind-html="flux.label | translate | highlight:$select.search"></span>
</ui-select-choices>
</ui-select>
</div>

<!-- date -->
<fieldset>
<legend translate>FORM.LABELS.DATE</legend>
<bh-date-interval
date-id="date"
date-from="$ctrl.searchQueries.dateFrom"
date-to="$ctrl.searchQueries.dateTo"
mode="clean">
</bh-date-interval>
</fieldset>
</div>
</uib-tab>
<uib-tab index="1" heading="{{ 'FORM.LABELS.DEFAULTS' | translate }}" data-default-filter-tab>
Expand All @@ -91,7 +80,7 @@

<div class="form-group" ng-class="{ 'has-error' : ModalForm.limit.$invalid }">
<label class="control-label" translate>FORM.LABELS.LIMIT</label>
<input
<input
name="limit"
type="number"
bh-integer
Expand All @@ -105,14 +94,14 @@
</div>
</div>
</uib-tab>
</uib-tabset>
</uib-tabset>
</div>

<div class="modal-footer">
<button type="button" class="btn btn-default" ng-click="$ctrl.cancel()" data-method="cancel" translate>
<button type="button" class="btn btn-default" ng-click="$ctrl.cancel()" data-method="cancel" translate>
FORM.BUTTONS.CLOSE
</button>
<button type="submit" class="btn btn-primary" data-method="submit" translate>
<button type="submit" class="btn btn-primary" data-method="submit" translate>
FORM.BUTTONS.SUBMIT
</button>
</div>
Expand Down
36 changes: 18 additions & 18 deletions client/src/modules/stock/movements/modals/search.modal.js
Original file line number Diff line number Diff line change
@@ -1,32 +1,32 @@
angular.module('bhima.controllers')
.controller('SearchMovementsModalController', SearchMovementsModalController);
.controller('SearchMovementsModalController', SearchMovementsModalController);

SearchMovementsModalController.$inject = [
'data', 'NotifyService', '$uibModalInstance', 'FluxService',
'$translate', 'PeriodService', 'Store', 'util'
'data', 'NotifyService', '$uibModalInstance', 'FluxService',
'$translate', 'PeriodService', 'Store', 'util',
];

function SearchMovementsModalController(data, Notify, Instance, Flux, $translate, Periods, Store, util) {
var vm = this;
var changes = new Store({ identifier : 'key'});
var changes = new Store({ identifier : 'key' });

var searchQueryOptions = [
'is_exit', 'depot_uuid', 'inventory_uuid', 'label', 'flux_id', 'dateFrom', 'dateTo',
];

vm.filters = data;
vm.searchQueries = {};
vm.defaultQueries = {};

var searchQueryOptions = [
'is_exit', 'depot_uuid', 'inventory_uuid', 'label', 'flux_id', 'dateFrom', 'dateTo'
];

// load flux
// load flux
Flux.read()
.then(function (rows) {
.then(function (rows) {
vm.fluxes = rows.map(function (row) {
row.label = $translate.instant(row.label);
return row;
});
})
.catch(Notify.handleError);
})
.catch(Notify.handleError);

// default filter period - directly write to changes list
vm.onSelectPeriod = function onSelectPeriod(period) {
Expand All @@ -50,36 +50,36 @@ function SearchMovementsModalController(data, Notify, Instance, Flux, $translate
// assign already defined custom filters to searchQueries object
vm.searchQueries = util.maskObjectFromKeys(data, searchQueryOptions);

if(data.limit) {
if (data.limit) {
vm.defaultQueries.limit = data.limit;
}

// default filter limit - directly write to changes list
vm.onSelectLimit = function onSelectLimit(value) {
// input is type value, this will only be defined for a valid number
if (angular.isDefined(value)) {
changes.post({ key: 'limit', value: value });
changes.post({ key : 'limit', value : value });
}
};

// deletes a filter from the custom filter object,
// deletes a filter from the custom filter object,
// this key will no longer be written to changes on exit
vm.clear = function clear(key) {
delete vm.searchQueries[key];
};

vm.cancel = function cancel() { Instance.close(); };

vm.submit = function submit(form) {
vm.submit = function submit() {
// push all searchQuery values into the changes array to be applied
angular.forEach(vm.searchQueries, function (value, key) {
if (angular.isDefined(value)) {
changes.post({ key: key, value: value });
changes.post({ key : key, value : value });
}
});

var loggedChanges = changes.getAll();

return Instance.close(loggedChanges);
};
}
Loading

0 comments on commit 108c4d1

Please sign in to comment.