-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #166 from OpenLMIS-Angola/OAM-273-frontend
OAM-273: OpenLMIS kit unpack hangs during submission
- Loading branch information
Showing
5 changed files
with
251 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
180 changes: 180 additions & 0 deletions
180
src/admin-orderable-edit/orderable-edit-kit-unpack-list.controller.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,180 @@ | ||
/* | ||
* This program is part of the OpenLMIS logistics management information system platform software. | ||
* Copyright © 2017 VillageReach | ||
* | ||
* This program is free software: you can redistribute it and/or modify it under the terms | ||
* of the GNU Affero General Public License as published by the Free Software Foundation, either | ||
* version 3 of the License, or (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; | ||
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. | ||
* See the GNU Affero General Public License for more details. You should have received a copy of | ||
* the GNU Affero General Public License along with this program. If not, see | ||
* http://www.gnu.org/licenses. For additional information contact [email protected]. | ||
*/ | ||
|
||
(function() { | ||
|
||
'use strict'; | ||
|
||
/** | ||
* @ngdoc controller | ||
* @name admin-orderable-edit.controller:OrderableEditKitUnpackListController | ||
* | ||
* @description | ||
* Controller for managing orderable view screen. | ||
*/ | ||
angular | ||
.module('admin-orderable-edit') | ||
.controller('OrderableEditKitUnpackListController', controller); | ||
|
||
controller.$inject = [ | ||
'selectProductsModalService', 'orderable', 'children', 'OrderableResource', 'orderablesMap', | ||
'FunctionDecorator', 'stateTrackerService' | ||
]; | ||
|
||
function controller(selectProductsModalService, orderable, children, OrderableResource, orderablesMap, | ||
FunctionDecorator, stateTrackerService) { | ||
|
||
var vm = this; | ||
|
||
vm.$onInit = onInit; | ||
vm.goToOrderableList = goToOrderableList; | ||
vm.addChild = addChild; | ||
vm.removeChild = removeChild; | ||
vm.saveOrderable = new FunctionDecorator() | ||
.decorateFunction(saveOrderable) | ||
.withSuccessNotification('adminOrderableEdit.kitUnpackListSavedSuccessfully') | ||
.withErrorNotification('adminOrderableEdit.failedToSaveKitUnpackList') | ||
.withLoading(true) | ||
.getDecoratedFunction(); | ||
|
||
/** | ||
* @ngdoc method | ||
* @propertyOf admin-orderable-edit.controller:OrderableEditKitUnpackListController | ||
* @name $onInit | ||
* | ||
* @description | ||
* Method that is executed on initiating OrderableEditKitUnpackListController. | ||
*/ | ||
function onInit() { | ||
vm.orderable = orderable; | ||
vm.children = children; | ||
vm.orderablesMap = orderablesMap; | ||
vm.unitOfOrderables = orderable.units; | ||
} | ||
|
||
/** | ||
* @ngdoc method | ||
* @propertyOf admin-orderable-edit.controller:OrderableEditKitUnpackListController | ||
* @name addChild | ||
* | ||
* @description | ||
* Method that displays a modal for selecting and adding a orderable to the UI | ||
*/ | ||
function addChild() { | ||
selectProducts({ | ||
selections: vm.orderablesMap | ||
}) | ||
.then(addToOrderablesMap) | ||
.then(updateChildrenList); | ||
} | ||
|
||
/** | ||
* @ngdoc method | ||
* @propertyOf admin-orderable-edit.controller:OrderableEditKitUnpackListController | ||
* @name removeChild | ||
* | ||
* @description | ||
* Method that removes kit constituent from the kit orderable | ||
* | ||
* @param {Object} a single child or kit constituent to be removed | ||
*/ | ||
function removeChild(child) { | ||
if (vm.children.indexOf(child) > -1) { | ||
vm.children.splice(vm.children.indexOf(child), 1); | ||
} | ||
|
||
vm.orderable.children = vm.children; | ||
|
||
Object.keys(vm.orderablesMap).forEach(function(key) { | ||
if (key === child.orderable.id) { | ||
delete vm.orderablesMap[child.orderable.id]; | ||
} | ||
}); | ||
} | ||
|
||
/** | ||
* @ngdoc method | ||
* @methodOf admin-orderable-edit.controller:OrderableEditKitUnpackListController | ||
* @name goToOrderableList | ||
* | ||
* @description | ||
* Redirects to orderable list screen. | ||
*/ | ||
function goToOrderableList() { | ||
stateTrackerService.goToPreviousState('openlmis.administration.orderables', {}, { | ||
reload: true | ||
}); | ||
} | ||
|
||
/** | ||
* @ngdoc method | ||
* @methodOf admin-orderable-edit.controller:OrderableEditKitUnpackListController | ||
* @name saveOrderable | ||
* | ||
* @description | ||
* Updates the orderable and return to the orderable list on success. | ||
*/ | ||
function saveOrderable() { | ||
return new OrderableResource() | ||
.update(vm.orderable) | ||
.then(goToOrderableList); | ||
} | ||
|
||
function selectProducts(availableProducts) { | ||
return selectProductsModalService.show(availableProducts); | ||
} | ||
|
||
function mapToChild(orderable) { | ||
return { | ||
orderable: { | ||
id: orderable.id | ||
}, | ||
quantity: undefined, | ||
unit: undefined | ||
}; | ||
} | ||
|
||
function updateChildrenList(selectedOrderables) { | ||
var childrenMap = vm.children.reduce(function(childrenMap, child) { | ||
childrenMap[child.orderable.id] = child; | ||
return childrenMap; | ||
}, {}); | ||
|
||
clearChildrenList(); | ||
|
||
selectedOrderables.forEach(function(orderable) { | ||
vm.children.push(childrenMap[orderable.id] ? childrenMap[orderable.id] : mapToChild(orderable)); | ||
}); | ||
|
||
vm.orderable.children = vm.children; | ||
} | ||
|
||
function addToOrderablesMap(orderables) { | ||
vm.orderablesMap = orderables.reduce(function(orderablesMap, orderable) { | ||
orderablesMap[orderable.id] = orderable; | ||
return orderablesMap; | ||
}, {}); | ||
|
||
return orderables; | ||
} | ||
|
||
function clearChildrenList() { | ||
while (children.length) { | ||
children.pop(); | ||
} | ||
} | ||
|
||
} | ||
})(); |
52 changes: 52 additions & 0 deletions
52
src/admin-orderable-edit/orderable-edit-kit-unpack-list.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
<h3>{{'adminOrderableEdit.kitUnpackList' | message}}</h3> | ||
<form name="saveKitUnpackListForm" id="saveKitUnpackList" class="form-inline" ng-submit="vm.saveOrderable()"> | ||
<section class="openlmis-table-container"> | ||
<div class="is-primary"> | ||
<button type="button" class="add" ng-click="vm.addChild()"> | ||
{{'adminOrderableEdit.addProduct' | message}} | ||
</button> | ||
</div> | ||
<table> | ||
<caption ng-if="!vm.children || vm.children.length === 0"> | ||
{{'adminOrderableEdit.noKitProductsFound' | message}} | ||
</caption> | ||
<thead> | ||
<tr> | ||
<th>{{'adminOrderableEdit.productCode' | message}}</th> | ||
<th>{{'adminOrderableEdit.name' | message}}</th> | ||
<th>{{'adminOrderableEdit.quantity' | message}}</th> | ||
<!-- OAM-273: Start --> | ||
<th>{{'adminOrderableEdit.unit' | message}}</th> | ||
<!-- OAM-273: End --> | ||
<th>{{'adminOrderableEdit.actions' | message}}</th> | ||
</tr> | ||
</thead> | ||
<tbody> | ||
<tr ng-repeat="child in vm.childrenPage"> | ||
<td>{{vm.orderablesMap[child.orderable.id].productCode}}</td> | ||
<td>{{vm.orderablesMap[child.orderable.id].fullProductName}}</td> | ||
<td><input positive-integer id="quantity_{{$index}}" max="100" ng-model="child.quantity" | ||
required> | ||
</td> | ||
<!-- OAM-273: Start --> | ||
<td> | ||
<select id="unitOfOrderable" ng-model="child.unit" | ||
ng-options="unit.name for unit in vm.unitOfOrderables track by unit.id" required></select> | ||
</td> | ||
<!-- OAM-273: End --> | ||
<td><button ng-click="vm.removeChild(child)" id="remove_{{$index}}" type="button" | ||
class="danger"> | ||
{{'adminOrderableEdit.remove' | message}}</button></td> | ||
</tr> | ||
</tbody> | ||
</table> | ||
<openlmis-pagination list="vm.children" paged-list="vm.childrenPage" pagination-id="'kitUnpackList'" /> | ||
</section> | ||
</form> | ||
|
||
<div class="openlmis-toolbar"> | ||
<button ng-click="vm.goToOrderableList()">{{'adminOrderableEdit.cancel' | message}}</button> | ||
<div class="button-group primary"> | ||
<button class="primary" type="submit" form="saveKitUnpackList">{{'adminOrderableEdit.saveKitUnpackList' | message}}</button> | ||
</div> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters