Skip to content

Commit

Permalink
polish the entry exit component UI
Browse files Browse the repository at this point in the history
  • Loading branch information
DedrickEnc committed Aug 4, 2017
1 parent 259acb1 commit 5be31bd
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 20 deletions.
41 changes: 30 additions & 11 deletions client/src/js/components/bhStockEntryExitType.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ angular.module('bhima.components')
controller: StockEntryExitTypeController,
bindings: {
onEntryExitTypeSelectCallback: '&?',
reference : '<?',
displayName : '<?',
isEntry : '<'
reference: '<?',
displayName: '<?',
isEntry: '<'
},
});

Expand All @@ -20,16 +20,35 @@ function StockEntryExitTypeController() {
$ctrl.selectedEntryExitType = null;

$ctrl.entryExitTypeList = [
{ label: 'patient', labelKey: 'PATIENT_REG.ENTITY', descriptionKey: 'STOCK.PATIENT_DISTRIBUTION', isEntry : false },
{ label: 'service', labelKey: 'SERVICE.ENTITY', descriptionKey: 'STOCK.SERVICE_DISTRIBUTION', isEntry : false },
{ label: 'depot', labelKey: 'DEPOT.ENTITY', descriptionKey: 'STOCK.DEPOT_DISTRIBUTION', isEntry : false },
{ label: 'loss', labelKey: 'STOCK.EXIT_LOSS', descriptionKey: 'STOCK.LOSS_DISTRIBUTION', isEntry : false },
{ label: 'purchase', labelKey: 'STOCK.ENTRY_PURCHASE', descriptionKey: 'STOCK_FLUX.FROM_PURCHASE', isEntry : true },
{ label: 'integration', labelKey: 'STOCK.INTEGRATION', descriptionKey: 'STOCK_FLUX.FROM_INTEGRATION', isEntry : true },
{ label: 'donation', labelKey: 'STOCK.DONATION', descriptionKey: 'STOCK_FLUX.FROM_DONATION', isEntry : true },
{ label: 'transfer_reception', labelKey: 'STOCK.RECEPTION_TRANSFER', descriptionKey: 'STOCK_FLUX.FROM_TRANSFER', isEntry : true }
{ label: 'patient', labelKey: 'PATIENT_REG.ENTITY', descriptionKey: 'STOCK.PATIENT_DISTRIBUTION', isEntry: false },
{ label: 'service', labelKey: 'SERVICE.ENTITY', descriptionKey: 'STOCK.SERVICE_DISTRIBUTION', isEntry: false },
{ label: 'depot', labelKey: 'DEPOT.ENTITY', descriptionKey: 'STOCK.DEPOT_DISTRIBUTION', isEntry: false },
{ label: 'loss', labelKey: 'STOCK.EXIT_LOSS', descriptionKey: 'STOCK.LOSS_DISTRIBUTION', isEntry: false },
{ label: 'purchase', labelKey: 'STOCK.ENTRY_PURCHASE', descriptionKey: 'STOCK_FLUX.FROM_PURCHASE', isEntry: true },
{ label: 'integration', labelKey: 'STOCK.INTEGRATION', descriptionKey: 'STOCK_FLUX.FROM_INTEGRATION', isEntry: true },
{ label: 'donation', labelKey: 'STOCK.DONATION', descriptionKey: 'STOCK_FLUX.FROM_DONATION', isEntry: true },
{ label: 'transfer_reception', labelKey: 'STOCK.RECEPTION_TRANSFER', descriptionKey: 'STOCK_FLUX.FROM_TRANSFER', isEntry: true }
];

$ctrl.display = function () {
if ($ctrl.isEntry) {
return $ctrl.reference || '';
} else {
var list = [];

if ($ctrl.reference) {
list.push($ctrl.reference);
}

if ($ctrl.displayName) {
list.push($ctrl.displayName);

}

return list.join(' - ');
}
}

$ctrl.selectEntryExitType = function (type) {
$ctrl.selectedEntryExitType = type;
$ctrl.onEntryExitTypeSelectCallback({ type: type });
Expand Down
23 changes: 21 additions & 2 deletions client/src/modules/stock/entry/entry.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ function StockEntryController(Depots, Inventory, Notify,
var mapEntry = {
purchase : { find: findPurchase, submit: submitPurchase },
donation : { find: angular.noop, submit: angular.noop }, // donation is not yet implemented
integration : { find: angular.noop, submit: submitIntegration},
integration : { find: handleIntegrationSelection, submit: submitIntegration},
transfer_reception : {find: findTransfer, submit : submitTransferReception},
};

Expand Down Expand Up @@ -145,6 +145,8 @@ function StockEntryController(Depots, Inventory, Notify,
// ============================ Modals ================================
// find purchase
function findPurchase() {
initSelectedEntity();

StockModal.openFindPurchase()
.then(function(purchase) {
if (!purchase) { return; }
Expand All @@ -153,13 +155,17 @@ function StockEntryController(Depots, Inventory, Notify,
type : 'purchase',
instance : purchase[0],
};

setSelectedEntity(purchase[0]);
populate(purchase);
})
.catch(Notify.handleError);
}

// find transfer
function findTransfer(params) {
initSelectedEntity();

StockModal.openFindTansfer({depot_uuid : vm.depot.uuid})
.then(function(transfers) {
if (!transfers) { return; }
Expand All @@ -174,6 +180,10 @@ function StockEntryController(Depots, Inventory, Notify,
.catch(Notify.handleError);
}

function handleIntegrationSelection (){
initSelectedEntity();
}

// populate the grid
function populate(items) {
if (!items.length) { return; }
Expand All @@ -192,9 +202,18 @@ function StockEntryController(Depots, Inventory, Notify,
});
}

function initSelectedEntity (){
vm.reference = vm.displayName = '';
}

function setSelectedEntity (entity){
var uniformEntity = Stock.uniformSelectedEntity(entity);
vm.reference = uniformEntity.reference;
vm.displayName = uniformEntity.displayName;
}

// ============================ lots management ===========================
function setLots(inventory) {
console.log('inventaire', inventory);
StockModal.openDefineLots({
inventory : inventory,
entry_type : vm.movement.entry_type,
Expand Down
1 change: 0 additions & 1 deletion client/src/modules/stock/entry/modals/lots.modal.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ StockDefineLotsModalController.$inject = [
];

function StockDefineLotsModalController(Instance, Notify, uiGridConstants, Data, Session) {
console.log('Data', Data);
var vm = this;

// globals
Expand Down
9 changes: 3 additions & 6 deletions client/src/modules/templates/bhStockEntryExitType.tmpl.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,9 @@
</div>
<div>
<div class="uilabel">
<span ng-show="type.label !== $ctrl.selectedEntryExitType.label" translate>{{type.descriptionKey}}</span>
<span ng-show="type.label === $ctrl.selectedEntryExitType.label && type.label !== 'loss'">
{{ $ctrl.reference }} - {{ $ctrl.displayName }}
</span>
<span ng-show="type.label === 'loss'" translate>
{{type.descriptionKey}}
<span ng-hide="($ctrl.reference || $ctrl.displayName) && type.label === $ctrl.selectedEntryExitType.label" translate>{{type.descriptionKey}}</span>
<span ng-show="($ctrl.reference || $ctrl.displayName) && type.label === $ctrl.selectedEntryExitType.label">
{{$ctrl.display()}}
</span>
</div>
</div>
Expand Down

0 comments on commit 5be31bd

Please sign in to comment.