From 46aff6a5cc94ebebfb1f6df33e69e32fee361159 Mon Sep 17 00:00:00 2001 From: Sriram Viswanathan Date: Thu, 20 Jun 2013 16:13:21 +0530 Subject: [PATCH] |#756|+Manan| Reset override Isa buttons. Adding json ignore properties to AllocationProgramProduct --- .../domain/AllocationProgramProduct.java | 2 + .../src/main/resources/messages_en.properties | 3 +- .../controller/facility-controller.js | 23 +++--- .../js/facility/controller/isa-controller.js | 30 ++++++- .../js/facility/module/facility-module.js | 2 +- .../src/main/webapp/public/less/content.less | 36 ++++++++- .../pages/admin/facility/partials/create.html | 81 +++++++++++-------- .../controller/isa-controller-test.js | 61 ++++++++++++++ 8 files changed, 186 insertions(+), 52 deletions(-) diff --git a/modules/distribution/src/main/java/org/openlmis/distribution/domain/AllocationProgramProduct.java b/modules/distribution/src/main/java/org/openlmis/distribution/domain/AllocationProgramProduct.java index a7f801bd83..295995da50 100644 --- a/modules/distribution/src/main/java/org/openlmis/distribution/domain/AllocationProgramProduct.java +++ b/modules/distribution/src/main/java/org/openlmis/distribution/domain/AllocationProgramProduct.java @@ -10,12 +10,14 @@ import lombok.Data; import lombok.EqualsAndHashCode; import lombok.NoArgsConstructor; +import org.codehaus.jackson.annotate.JsonIgnoreProperties; import org.openlmis.core.domain.ProgramProduct; @AllArgsConstructor @NoArgsConstructor @EqualsAndHashCode(callSuper = false) @Data +@JsonIgnoreProperties(ignoreUnknown = true) public class AllocationProgramProduct extends ProgramProduct { Long programProductId; diff --git a/modules/openlmis-web/src/main/resources/messages_en.properties b/modules/openlmis-web/src/main/resources/messages_en.properties index a40aa78376..30cf674f4b 100644 --- a/modules/openlmis-web/src/main/resources/messages_en.properties +++ b/modules/openlmis-web/src/main/resources/messages_en.properties @@ -56,6 +56,7 @@ label.adjustment.quantity = Adjustment quantity (+/-) label.isa.minimum.value = ISA minimum value error.enter.numeric.value = Please enter numeric value button.use.calculated = Use calculated +button.use.all.calculated = Reset all to calculated ISAs label.isa.monthly.restock.amount = Monthly restock amount = label.isa.population.of = A population of label.isa.doses.of = doses of @@ -195,7 +196,7 @@ error.geo.level.invalid = Invalid Geographic Level Code error.geo.zone.parent.invalid = Invalid Geographic Zone Parent Code error.facility.program.mapping.exists = Facility has already been mapped to the program error.facility.requisition.group.mapping.exists = Facility to Requisition Group mapping already exists -error.facility.allocation.product.save = Error saving facility allocation products +error.facility.allocation.product.save = Error saving facility allocation products for program title.manage.users = Manage Users - OpenLMIS user.data.length.incorrect = Incorrect data type or length diff --git a/modules/openlmis-web/src/main/webapp/public/js/facility/controller/facility-controller.js b/modules/openlmis-web/src/main/webapp/public/js/facility/controller/facility-controller.js index 54db2c6809..a3bca08594 100644 --- a/modules/openlmis-web/src/main/webapp/public/js/facility/controller/facility-controller.js +++ b/modules/openlmis-web/src/main/webapp/public/js/facility/controller/facility-controller.js @@ -49,24 +49,25 @@ function FacilityController($scope, facilityReferenceData, $routeParams, facilit }; function saveAllocationProgramProducts() { - var defers = []; + var promises = []; var keys = _.keys($scope.allocationProgramProductsList); - $(keys).each(function(index, key) { - defers.push($q.defer()); + $(keys).each(function (index, key) { + var deferred = $q.defer(); + promises.push(deferred.promise); var program = $scope.allocationProgramProductsList[key][0].program; FacilityProgramProducts.post({facilityId: $routeParams.facilityId, programId: program.id}, $scope.allocationProgramProductsList[key], function (data) { - defers[index].resolve(); + deferred.resolve(); }, function () { - defers[index].reject("error.facility.allocation.product.save"); + deferred.reject({error: "error.facility.allocation.product.save", program: program.name}); }); }) - return defers; + return promises; } $scope.saveFacility = function () { @@ -84,15 +85,17 @@ function FacilityController($scope, facilityReferenceData, $routeParams, facilit $q.all(promises).then(function () { $scope.showError = "true"; $scope.error = ""; + $scope.errorProgram = ""; $scope.$parent.message = data.success; $scope.facility = getFacilityWithDateObjects(data.facility); $scope.$parent.facilityId = $scope.facility.id; populateFlags($scope); $location.path(''); - }, function(error) { + }, function (error) { $scope.showError = "true"; $scope.message = ""; - $scope.error = error; + $scope.error = error.error; + $scope.errorProgram = error.program; }) }; @@ -153,8 +156,8 @@ function FacilityController($scope, facilityReferenceData, $routeParams, facilit OpenLmisDialog.newDialog(options, $scope.removeSupportedProgramConfirm, $dialog, messageService); }; - $scope.removeSupportedProgramConfirm = function(result) { - if(result) { + $scope.removeSupportedProgramConfirm = function (result) { + if (result) { $scope.removeSupportedProgram() } $scope.selectedSupportedProgram = undefined; diff --git a/modules/openlmis-web/src/main/webapp/public/js/facility/controller/isa-controller.js b/modules/openlmis-web/src/main/webapp/public/js/facility/controller/isa-controller.js index d69773cec6..703de2d22c 100644 --- a/modules/openlmis-web/src/main/webapp/public/js/facility/controller/isa-controller.js +++ b/modules/openlmis-web/src/main/webapp/public/js/facility/controller/isa-controller.js @@ -13,13 +13,13 @@ function IsaModalController($scope, FacilityProgramProducts, $routeParams) { $scope.currentProgramProducts = []; if ($scope.$parent.allocationProgramProductsList[$scope.currentProgram.id]) { - $scope.currentProgramProducts = angular.copy($scope.$parent.allocationProgramProductsList[$scope.currentProgram.id]); + $scope.filteredProducts = $scope.currentProgramProducts = angular.copy($scope.$parent.allocationProgramProductsList[$scope.currentProgram.id]); return; } FacilityProgramProducts.get({programId: $scope.currentProgram.id, facilityId: $routeParams.facilityId}, function (data) { - $scope.$parent.allocationProgramProductsList[$scope.currentProgram.id] = angular.copy(data.programProductList); + $scope.$parent.allocationProgramProductsList[$scope.currentProgram.id] = data.programProductList; $($scope.$parent.allocationProgramProductsList[$scope.currentProgram.id]).each(function (index, product) { @@ -33,7 +33,7 @@ function IsaModalController($scope, FacilityProgramProducts, $routeParams) { }); - $scope.currentProgramProducts = angular.copy($scope.$parent.allocationProgramProductsList[$scope.currentProgram.id]); + $scope.filteredProducts = $scope.currentProgramProducts = angular.copy($scope.$parent.allocationProgramProductsList[$scope.currentProgram.id]); }, function (data) { }); @@ -48,4 +48,28 @@ function IsaModalController($scope, FacilityProgramProducts, $routeParams) { $scope.$parent.programProductsISAModal = false; } + $scope.resetAllToCalculatedIsa = function () { + $($scope.currentProgramProducts).each(function (index, product) { + product.overriddenIsa = null; + }); + } + + $scope.updateCurrentProgramProducts = function () { + $scope.filteredProducts = []; + $scope.query = $scope.query.trim(); + + if (!$scope.query.length) { + $scope.filteredProducts = $scope.currentProgramProducts; + return; + } + + $($scope.currentProgramProducts).each(function (index, product) { + var searchString = $scope.query.toLowerCase(); + if (product.product.primaryName.toLowerCase().indexOf(searchString) >= 0) { + $scope.filteredProducts.push(product); + } + }); + + } + } diff --git a/modules/openlmis-web/src/main/webapp/public/js/facility/module/facility-module.js b/modules/openlmis-web/src/main/webapp/public/js/facility/module/facility-module.js index 7dbac81ea5..0ce6c9c6d3 100644 --- a/modules/openlmis-web/src/main/webapp/public/js/facility/module/facility-module.js +++ b/modules/openlmis-web/src/main/webapp/public/js/facility/module/facility-module.js @@ -45,7 +45,7 @@ require(['../../shared/app', '../controller/facility-controller', '../controller angular.bootstrap(document, ['facility']); facilityModule.numericValue = function (value, errorHolder) { - var NUMBER_REGEXP = /^(\d{0,4}\.?\d{0,4}|\.\d{1,4})$/; + var NUMBER_REGEXP = /^\d*$/; var valid = (value == undefined) ? true : NUMBER_REGEXP.test(value); if (errorHolder != undefined) { diff --git a/modules/openlmis-web/src/main/webapp/public/less/content.less b/modules/openlmis-web/src/main/webapp/public/less/content.less index 988c25d1ee..d3435a94cd 100644 --- a/modules/openlmis-web/src/main/webapp/public/less/content.less +++ b/modules/openlmis-web/src/main/webapp/public/less/content.less @@ -183,7 +183,7 @@ span.field-error { width: 100%; } &.programs-table { - width: 60%; + width: 70%; } } } @@ -1677,4 +1677,36 @@ input[placeholder].placeholder{ font-style: italic; padding: 8px 0 0; font-size: 0.9em; -} \ No newline at end of file +} + +#override-isa-table { + margin: 5px; + div { + &.has-overridden-isa { + background-color: #FFFFE7; + } + .isa-list-row { + padding: 12px 0; + border: 1px solid #EEE; + border-top: 0; + input[type="text"] { + width: 76%; + } + div:first-child { + padding-left: 20px; + } + div:last-child input[type="button"] { + float: right; + margin-right: 12px; + } + } + } + + .use-calculated-isa-column { + min-width: 140px; + } +} + +#searchProduct.search-query { + margin-bottom: 8px; +} diff --git a/modules/openlmis-web/src/main/webapp/public/pages/admin/facility/partials/create.html b/modules/openlmis-web/src/main/webapp/public/pages/admin/facility/partials/create.html index 9cd7a2934f..d54bb1bc5f 100644 --- a/modules/openlmis-web/src/main/webapp/public/pages/admin/facility/partials/create.html +++ b/modules/openlmis-web/src/main/webapp/public/pages/admin/facility/partials/create.html @@ -294,46 +294,54 @@

@@ -556,7 +564,10 @@

openlmis-message="button.restore"> -
+
+   + +
diff --git a/modules/openlmis-web/src/test/javascript/specs/facility/controller/isa-controller-test.js b/modules/openlmis-web/src/test/javascript/specs/facility/controller/isa-controller-test.js index d2f2f78bc7..6714058f69 100644 --- a/modules/openlmis-web/src/test/javascript/specs/facility/controller/isa-controller-test.js +++ b/modules/openlmis-web/src/test/javascript/specs/facility/controller/isa-controller-test.js @@ -120,5 +120,66 @@ describe("ISA Controller", function () { expect(scope.currentProgramProducts).toEqual(scope.$parent.allocationProgramProductsList[scope.currentProgram.id]); }); + it('should reset all isa values', function() { + var currentProducts = [ + {programProductId: 1, facilityId: 1, overriddenIsa: 34, programProductIsa: {}}, + {programProductId: 2, facilityId: 1, overriddenIsa: 45, programProductIsa: {}} + ]; + scope.currentProgramProducts = currentProducts; + + scope.resetAllToCalculatedIsa(); + + expect(scope.currentProgramProducts[0].overriddenIsa).toEqual(null); + expect(scope.currentProgramProducts[1].overriddenIsa).toEqual(null); + }); + + it('should filter program products based on query', function() { + var currentProducts = [ + {programProductId: 1, facilityId: 1, overriddenIsa: 34, programProductIsa: {}, product: {primaryName: 'abcd'}}, + {programProductId: 2, facilityId: 1, overriddenIsa: 45, programProductIsa: {}, product: {primaryName: 'efgh'}} + ]; + scope.currentProgramProducts = currentProducts; + scope.query = 'ef'; + scope.updateCurrentProgramProducts(); + + expect(scope.filteredProducts).toEqual([currentProducts[1]]); + }); + + it('should filter program products based on query even for case mismatch', function() { + var currentProducts = [ + {programProductId: 1, facilityId: 1, overriddenIsa: 34, programProductIsa: {}, product: {primaryName: 'abcd'}}, + {programProductId: 2, facilityId: 1, overriddenIsa: 45, programProductIsa: {}, product: {primaryName: 'efgh'}} + ]; + scope.currentProgramProducts = currentProducts; + scope.query = 'EF'; + scope.updateCurrentProgramProducts(); + + expect(scope.filteredProducts).toEqual([currentProducts[1]]); + }); + + it('should have all program products if query is empty', function() { + var currentProducts = [ + {programProductId: 1, facilityId: 1, overriddenIsa: 34, programProductIsa: {}, product: {primaryName: 'abcd'}}, + {programProductId: 2, facilityId: 1, overriddenIsa: 45, programProductIsa: {}, product: {primaryName: 'efgh'}} + ]; + scope.currentProgramProducts = currentProducts; + scope.query = ''; + scope.updateCurrentProgramProducts(); + + expect(scope.filteredProducts).toEqual(currentProducts); + }); + + it('should filter program products based on query even if query contains leading and trailing whitespace', function() { + var currentProducts = [ + {programProductId: 1, facilityId: 1, overriddenIsa: 34, programProductIsa: {}, product: {primaryName: 'abcd'}}, + {programProductId: 2, facilityId: 1, overriddenIsa: 45, programProductIsa: {}, product: {primaryName: 'efgh'}} + ]; + scope.currentProgramProducts = currentProducts; + scope.query = ' efgh '; + scope.updateCurrentProgramProducts(); + + expect(scope.filteredProducts).toEqual([currentProducts[1]]); + }); + }); }); \ No newline at end of file