Skip to content

Commit

Permalink
feat(stock): implement depot selection modal
Browse files Browse the repository at this point in the history
This commit implements a depot selection modal for the stock modules.
The depot is cached between sessions, but if there is no depot, a user
is immediately directed to the open modal to choose a depot.  This modal
cannot be dismissed if the user has not chosen a depot.

Additionally, a dropdown menu has been implemented on the stock page to
put the "Change Depot" switch in.

Ideally, this should also clear and reset the stock form.  However,
since that isn't even implemented for the "submit" button, this feature
will be added later.

The prototype has been implemented on the Stock Entry page.
  • Loading branch information
jniles committed Sep 14, 2017
1 parent 08eaba1 commit 3533882
Show file tree
Hide file tree
Showing 13 changed files with 379 additions and 195 deletions.
41 changes: 21 additions & 20 deletions client/src/i18n/en/depot.json
Original file line number Diff line number Diff line change
@@ -1,22 +1,23 @@
{
"DEPOT": {
"ADD_DEPOT": "Add a Depot",
"ALL_DEPOTS": "All Depots",
"CREATED":"Depot created with success",
"DELETED":"Depot deleted with success",
"DELETE":"Delete",
"DEPOTS_LIST": "Depots list",
"DESCRIPTION": "This module allows you to List, Create, Edit and Delete a Depot",
"EDIT_DEPOT": "Edit the information in a Depot",
"ENTITY" : "Depot",
"LABEL":"Depot",
"MAIN": {
"TITLE": "Depot Management"
},
"NO_DEPOT": "No Depot",
"NOT_ALLOWED_ACTIONS":"Protected Depot, you cannot perform modification on this depot",
"TITLE": "Depot Management",
"UPDATED":"Depot updated with success",
"WAREHOUSE":"Warehouse"
}
"DEPOT" : {
"ADD_DEPOT" : "Add a Depot",
"ALL_DEPOTS" : "All Depots",
"CREATED" : "Depot created with success",
"CHANGE" : "Change Depot",
"DELETED" : "Depot deleted with success",
"DELETE" : "Delete",
"DEPOTS_LIST" : "Depots list",
"DESCRIPTION" : "This module allows you to List, Create, Edit and Delete a Depot",
"EDIT_DEPOT" : "Edit the information in a Depot",
"ENTITY" : "Depot",
"LABEL" : "Depot",
"MAIN" : {
"TITLE" : "Depot Management"
},
"NO_DEPOT" : "No Depot",
"NOT_ALLOWED_ACTIONS" : "This depot is protect. You cannot modify its properties.",
"TITLE" : "Depot Management",
"UPDATED" : "Depot updated with success",
"WAREHOUSE" : "Warehouse"
}
}
4 changes: 2 additions & 2 deletions client/src/i18n/en/form.json
Original file line number Diff line number Diff line change
Expand Up @@ -520,12 +520,12 @@
"CODE": "Enter code",
"COUNTRY": "Enter country",
"CREDITOR": "Enter creditor",
"DATE" : "Enter a Date",
"DEBTOR": "Enter debtor",
"DEBTOR_GROUP": "Enter a Debtor Group",
"DATE" : "Enter a Date",
"PATIENT_GROUP": "Enter patient group",
"DESCRIPTION": "Enter description",
"DOCUMENT_NAME": "Enter document name",
"PATIENT_GROUP": "Enter patient group",
"EMAIL": "Enter email",
"MAX_CREDIT": "Enter max credit",
"NAME": "Enter a name",
Expand Down
41 changes: 21 additions & 20 deletions client/src/i18n/fr/depot.json
Original file line number Diff line number Diff line change
@@ -1,22 +1,23 @@
{
"DEPOT": {
"ADD_DEPOT": "Ajouter un dépôt",
"ALL_DEPOTS": "Tous les dépôts",
"CREATED":"Dépôt crée avec succès",
"DELETED":"Dépôt supprimer avec succès",
"DELETE":"Supprimer",
"DEPOTS_LIST": "Liste des dépôts",
"DESCRIPTION": "Ce module vous permet de Lister, Creer, Modifier et Supprimer un dépôt",
"EDIT_DEPOT": "Editer les informations d'un dépôt",
"ENTITY" : "Depot",
"LABEL":"Dépôt",
"MAIN": {
"TITLE": "Gestion des dépôts"
},
"NO_DEPOT": "Aucun dépôt",
"NOT_ALLOWED_ACTIONS":"Ce dépôt est protégé, vous ne pouvez effectuer des modifications sur ce dépôt",
"TITLE": "Gestion des dépôts",
"UPDATED":"Dépôt mise à jour avec succès",
"WAREHOUSE":"Entrepôts"
}
"DEPOT" : {
"ADD_DEPOT" : "Ajouter un dépôt",
"ALL_DEPOTS" : "Tous les dépôts",
"CREATED" : "Dépôt crée avec succès",
"CHANGE" : "Changer Dépôt",
"DELETED" : "Dépôt supprimer avec succès",
"DELETE" : "Supprimer",
"DEPOTS_LIST" : "Liste des dépôts",
"DESCRIPTION" : "Ce module vous permet de Lister, Creer, Modifier et Supprimer un dépôt",
"EDIT_DEPOT" : "Editer les informations d'un dépôt",
"ENTITY" : "Dépôt",
"LABEL" : "Dépôt",
"MAIN" : {
"TITLE" : "Gestion des dépôts"
},
"NO_DEPOT" : "Aucun dépôt",
"NOT_ALLOWED_ACTIONS" : "Ce dépôt est protégé, vous ne pouvez effectuer des modifications sur ce dépôt",
"TITLE" : "Gestion des dépôts",
"UPDATED" : "Dépôt mise à jour avec succès",
"WAREHOUSE" : "Entrepôts"
}
}
13 changes: 6 additions & 7 deletions client/src/js/components/bhDepotSelect.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,7 @@ angular.module('bhima.components')
},
});

DepotSelectController.$inject = [
'DepotService', 'NotifyService'
];
DepotSelectController.$inject = ['DepotService', 'NotifyService'];

/**
* Depot selection component
Expand All @@ -22,15 +20,16 @@ function DepotSelectController(Depots, Notify) {
var $ctrl = this;

$ctrl.$onInit = function onInit() {
// fired when a depot has been selected
$ctrl.onSelectCallback = $ctrl.onSelectCallback || angular.noop;
$ctrl.loading = true;

// load all Depots
Depots.read()
.then(function (depots) {
$ctrl.depots = depots;
})
.catch(Notify.handleError);
.catch(Notify.handleError)
.finally(function () {
$ctrl.loading = false;
});
};

// fires the onSelectCallback bound to the component boundary
Expand Down
36 changes: 17 additions & 19 deletions client/src/js/services/StockService.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ angular.module('bhima.services')

StockService.$inject = [
'PrototypeApiService', 'FilterService', 'appcache', 'PeriodService',
'$httpParamSerializer', 'LanguageService', 'bhConstants'];
'$httpParamSerializer', 'LanguageService', 'bhConstants',
];

function StockService(Api, Filters, AppCache, Periods, $httpParamSerializer, Languages, bhConstants) {

// API for stock lots
var stocks = new Api('/stock/lots');

Expand All @@ -29,7 +29,7 @@ function StockService(Api, Filters, AppCache, Periods, $httpParamSerializer, Lan
var StockLotFilters = new Filters();
var StockMovementFilters = new Filters();
var filterMovementCache = new AppCache('stock-movement-filters');
var filterLotCache = new AppCache('stock-lot-filters');
var filterLotCache = new AppCache('stock-lot-filters');

StockLotFilters.registerDefaultFilters(bhConstants.defaultFilters);
StockMovementFilters.registerDefaultFilters(bhConstants.defaultFilters);
Expand All @@ -45,40 +45,39 @@ function StockService(Api, Filters, AppCache, Periods, $httpParamSerializer, Lan
]);

StockMovementFilters.registerCustomFilters([
{ key : 'is_exit', label : 'STOCK.OUTPUT'},
{ key: 'depot_uuid', label: 'STOCK.DEPOT' },
{ key: 'inventory_uuid', label: 'STOCK.INVENTORY' },
{ key: 'label', label: 'STOCK.LOT' },
{ key: 'flux_id', label: 'STOCK.FLUX'},
{ key : 'is_exit', label : 'STOCK.OUTPUT'},
{ key : 'depot_uuid', label : 'STOCK.DEPOT' },
{ key : 'inventory_uuid', label : 'STOCK.INVENTORY' },
{ key : 'label', label : 'STOCK.LOT' },
{ key : 'flux_id', label : 'STOCK.FLUX'},
{ key : 'dateFrom', label : 'FORM.LABELS.DATE', comparitor: '>', valueFilter : 'date' },
{ key : 'dateTo', label : 'FORM.LABELS.DATE', comparitor: '<', valueFilter : 'date' }
]);


if(filterLotCache.filters){
if (filterLotCache.filters) {
StockLotFilters.loadCache(filterLotCache.filters);
}

if(filterMovementCache.filters){
if (filterMovementCache.filters) {
StockMovementFilters.loadCache(filterMovementCache.filters);
}

// once the cache has been loaded - ensure that default filters are provided appropriate values
assignLotDefaultFilters();
assignMovementDefaultFilters();

// creating an an object of filter to avoid method duplication
// creating an object of filter to avoid method duplication
var stockFilter = {
lot : StockLotFilters,
movement : StockMovementFilters
}
movement : StockMovementFilters,
};

// creating an object of filter object to avoid method duplication
var filterCache = {
lot : filterLotCache,
movement : filterMovementCache
}

movement : filterMovementCache,
};

function assignLotDefaultFilters() {
// get the keys of filters already assigned - on initial load this will be empty
Expand Down Expand Up @@ -149,6 +148,7 @@ function StockService(Api, Filters, AppCache, Periods, $httpParamSerializer, Lan
}

var keys = ['name', 'text', 'display_name'];

keys.forEach(function (key) {
if (entity[key]) {
entity.displayName = entity[key];
Expand All @@ -158,7 +158,7 @@ function StockService(Api, Filters, AppCache, Periods, $httpParamSerializer, Lan
return { reference : entity.reference || '', displayName : entity.displayName || '' };
}

var service = {
return {
stocks : stocks,
lots : lots,
movements : movements,
Expand All @@ -172,6 +172,4 @@ function StockService(Api, Filters, AppCache, Periods, $httpParamSerializer, Lan
download : download,
uniformSelectedEntity : uniformSelectedEntity,
};

return service;
}
2 changes: 1 addition & 1 deletion client/src/modules/cash/cash.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<div class="toolbar-item">
<div uib-dropdown dropdown-append-to-body data-action="open-tools">
<a class="btn btn-default" uib-dropdown-toggle>
<span translate>FORM.LABELS.MENU</span> <span class="caret"></span>
<span class="fa fa-bars"></span> <span class="hidden-xs" translate>FORM.LABELS.MENU</span> <span class="caret"></span>
</a>
<ul uib-dropdown-menu role="menu" class="dropdown-menu-right">
<li role="menuitem">
Expand Down
27 changes: 24 additions & 3 deletions client/src/modules/depots/depots.service.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
angular.module('bhima.services')
.service('DepotService', DepotService);
.service('DepotService', DepotService);

DepotService.$inject = ['PrototypeApiService'];
DepotService.$inject = ['PrototypeApiService', '$uibModal'];

/**
* @class DepotService
Expand All @@ -10,7 +10,28 @@ DepotService.$inject = ['PrototypeApiService'];
* @description
* Encapsulates common requests to the /depots/ URL.
*/
function DepotService(Api) {
function DepotService(Api, Modal) {
var service = new Api('/depots/');

/**
* @method openSelectionModal
*
* @description
* Opens the selection modal to allow a user to select a depot.
*
* @returns Promise - a promise containing the depot.
*/
service.openSelectionModal = function openSelectionModal(depot) {
return Modal.open({
controller : 'SelectDepotModalController as $ctrl',
templateUrl : 'modules/stock/depot-selection.modal.html',
resolve : {
depot: function injectDepot() { return depot; },
},
backdrop : 'static',
keyboard : false,
}).result;
};

return service;
}
59 changes: 59 additions & 0 deletions client/src/modules/stock/depot-selection.ctrl.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
angular.module('bhima.controllers')
.controller('SelectDepotModalController', SelectDepotModalController);

SelectDepotModalController.$inject = [
'$uibModalInstance', 'DepotService', 'NotifyService', 'depot',
];

/**
* This modal selects a depot from the list of all depots.
*/
function SelectDepotModalController(Instance, Depots, Notify, depot) {
var vm = this;

// bind the depot passed into the controller
vm.depot = depot;
vm.selectDepot = selectDepot;
vm.hasSelectedDepot = hasSelectedDepot;
vm.loading = false;

// this is a one-time message shown to the user if they do not have a cached depot.
vm.hasNoDefaultDepot = !angular.isDefined(depot);

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

// loads a new set of depots from the server.
function startup() {
toggleLoadingIndicator();

Depots.read()
.then(function (depots) {
vm.depots = depots;
})
.catch(Notify.handleError)
.finally(toggleLoadingIndicator);
}

// fired when a user selects a depot from a list
function selectDepot(uuid) {
var selected;

vm.depots.forEach(function (d) {
if (d.uuid === uuid) { selected = d; }
});

vm.depot = selected;
}

function toggleLoadingIndicator() {
vm.loading = !vm.loading;
}

function hasSelectedDepot() {
return vm.depot && vm.depot.uuid;
}

// start up the module
startup();
}
Loading

0 comments on commit 3533882

Please sign in to comment.