Skip to content
This repository has been archived by the owner on Nov 19, 2020. It is now read-only.

Commit

Permalink
|#756|+Manan| Reset override Isa buttons. Adding json ignore properti…
Browse files Browse the repository at this point in the history
…es to AllocationProgramProduct
  • Loading branch information
Sriram Viswanathan committed Jun 20, 2013
1 parent 2cb504f commit 46aff6a
Show file tree
Hide file tree
Showing 8 changed files with 186 additions and 52 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 () {
Expand All @@ -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;
})
};

Expand Down Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {

Expand All @@ -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) {
});
Expand All @@ -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);
}
});

}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
36 changes: 34 additions & 2 deletions modules/openlmis-web/src/main/webapp/public/less/content.less
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ span.field-error {
width: 100%;
}
&.programs-table {
width: 60%;
width: 70%;
}
}
}
Expand Down Expand Up @@ -1677,4 +1677,36 @@ input[placeholder].placeholder{
font-style: italic;
padding: 8px 0 0;
font-size: 0.9em;
}
}

#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;
}
Original file line number Diff line number Diff line change
Expand Up @@ -294,46 +294,54 @@ <h3>
</h3>
</div>
<div class="modal-body">
<hr ng-show="currentProgramProducts.length > 0"/>
<div class="isa-product-list" ng-show="currentProgramProducts.length > 0">
<table class="table table-striped table-bordered">
<thead>
<tr>
<th openlmis-message="label.product"></th>
<th openlmis-message="label.calculated.isa"></th>
<th openlmis-message="label.overridden.isa"></th>
<th></th>
</tr>
</thead>
<tbody>
<tr ng-repeat="programProduct in currentProgramProducts">
<td>
<span id="product-name{{$index}}" ng-bind="programProduct.product.primaryName"></span>
</td>
<td>
<span id="calculated-isa{{$index}}" ng-bind="programProduct.calculatedIsa"></span>
</td>
<td ng-form="overrideForm">
<input id="override-isa{{$index}}" name="overrideISA{{$index}}" type="text" ng-model="programProduct.overriddenIsa"
numeric-validator="numericValue" />

<span id="overrideISA{{$index}}" class="form-error" ng-show="overrideForm.overriddenISA.$error.numeric"
openlmis-message="error.enter.numeric.value" style="display:none;"></span>
</td>
<td>
<input id="use-calculated-button{{$index}}" type="button"
openlmis-message="button.use.calculated"/>
</td>
</tr>
</tbody>
</table>
<div ng-hide="currentProgramProducts.length > 0" openlmis-message="message.no.products.mapped" class="alert alert-info"></div>
<div ng-show="currentProgramProducts.length > 0" >
<div class="row-fluid">
<div class="pull-right">
<input id="searchProduct" class="search-query" type="text" ng-model="query" ng-change="updateCurrentProgramProducts()"
placeholder="Filter products"/>
</div>
</div>
<div id="override-isa-table">
<div class="row-fluid list-header">
<div class="span3" openlmis-message="label.product"></div>
<div class="span2" openlmis-message="label.calculated.isa"></div>
<div class="span3" openlmis-message="label.overridden.isa"></div>
<div class="span3"></div>
</div>

<div ng-class="{'has-overridden-isa': programProduct.overriddenIsa != null || programProduct.overriddenIsa != undefined}"
ng-repeat="programProduct in filteredProducts">
<div class="row-fluid isa-list-row">
<div class="span3">
<span id="product-name{{$index}}" ng-bind="programProduct.product.primaryName"></span>
</div>
<div class="span2">
<span id="calculated-isa{{$index}}" ng-bind="programProduct.calculatedIsa"></span>
</div>
<div class="span3" ng-form="overrideForm">
<input id="override-isa{{$index}}" name="overrideISA{{$index}}" type="text" ng-model="programProduct.overriddenIsa"
numeric-validator="numericValue" maxlength="6"/>

<span id="overrideISA{{$index}}" class="form-error" ng-show="overrideForm.overriddenISA.$error.numeric"
openlmis-message="error.enter.numeric.value" style="display:none;"></span>
</div>
<div class="span3 use-calculated-isa-column">
<input ng-show="programProduct.overriddenIsa != null || programProduct.overriddenIsa != undefined"
class="btn" id="use-calculated-button{{$index}}" ng-click="programProduct.overriddenIsa = null" type="button"
openlmis-message="button.use.calculated"/>
</div>
</div>
</div>
</div>
</div>

</div>

<div class="modal-footer">
<input type="button" class="btn btn-primary" openlmis-message="button.done" ng-click="updateISA()"/>
<input type="button" class="btn btn-cancel" openlmis-message="button.cancel" ng-click="resetISAModal()"/>
<input type="button" ng-show="currentProgramProducts.length > 0" class="btn btn-warning pull-right"
openlmis-message="button.use.all.calculated" ng-click="resetAllToCalculatedIsa()"/>
</div>
</form>
</div>
Expand Down Expand Up @@ -556,7 +564,10 @@ <h3 openlmis-message="create.facility.otherInformation"></h3>
openlmis-message="button.restore"></a>
</div>

<div class="toolbar-error" id="saveErrorMsgDiv" openlmis-message="error" ng-show="error"></div>
<div class="toolbar-error" id="saveErrorMsgDiv">
<span openlmis-message="error" ng-show="error"></span>&nbsp;
<span ng-show="errorProgram" ng-bind="errorProgram"></span>
</div>
<div class="toolbar-success" id="saveSuccessMsgDiv" openlmis-message="message" ng-show="message"></div>
</div>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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]]);
});

});
});

0 comments on commit 46aff6a

Please sign in to comment.