Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OAM-45: Add ability to create and edit wards #110

Merged
merged 2 commits into from
Jun 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/admin-facility-add/admin-facility-add.module.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
'referencedata-facility',
'referencedata-facility-type',
'referencedata-facility-operator',
'referencedata-geographic-zone',
'admin-facility',
'openlmis-modal',
'openlmis-templates',
Expand Down
51 changes: 39 additions & 12 deletions src/admin-facility-add/facility-add.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,15 @@
FacilityAddController.$inject = [
'facility', 'facilityTypes', 'geographicZones', 'facilityOperators', 'confirmService',
'FacilityRepository', 'stateTrackerService', '$state', 'loadingModalService',
'notificationService', 'messageService', 'requisitionGroupService', 'TABLE_CONSTANTS'
'notificationService', 'messageService', 'requisitionGroupService', 'TABLE_CONSTANTS',
'geographicZoneService', 'WARDS_CONSTANTS'
];

function FacilityAddController(facility, facilityTypes, geographicZones, facilityOperators,
confirmService, FacilityRepository, stateTrackerService,
$state, loadingModalService, notificationService,
messageService, requisitionGroupService, TABLE_CONSTANTS) {
messageService, requisitionGroupService, TABLE_CONSTANTS,
geographicZoneService, WARDS_CONSTANTS) {
var vm = this;

vm.$onInit = onInit;
Expand All @@ -62,7 +64,11 @@
*/
function onInit() {
vm.facility = angular.copy(facility);
vm.facilityTypes = facilityTypes;
if (facilityTypes) {
vm.facilityTypes = facilityTypes.filter(function(facilityType) {
return facilityType.code !== WARDS_CONSTANTS.WARD_TYPE_CODE;
});
}
vm.geographicZones = geographicZones;
vm.facilityOperators = facilityOperators;
vm.facility.active = facility.active !== false;
Expand Down Expand Up @@ -96,17 +102,38 @@

function doSave() {
loadingModalService.open();
return new FacilityRepository().create(vm.facility)
.then(function(facility) {
notificationService.success('adminFacilityAdd.facilityHasBeenSaved');
stateTrackerService.goToPreviousState();

angular.forEach(vm.selectedRequisitionGroups, function(requisitionGroup) {
requisitionGroup.memberFacilities.push(facility);
var newGeoZone = {
name: vm.facility.name,
parent: vm.facility.geographicZone,
code: vm.facility.geographicZone.code + '_' + vm.facility.name,
level: {
id: '533a0771-bf2b-414a-91b2-6824d7df281d',
name: 'local',
code: 'local',
levelNumber: vm.facility.geographicZone.level.levelNumber + 1
}
};

requisitionGroupService.update(requisitionGroup);
});
return facility;
return geographicZoneService.create(newGeoZone)
.then(function(facilityGeoZone) {
vm.facility.geographicZone = facilityGeoZone;
return new FacilityRepository().create(vm.facility)
.then(function(facility) {
notificationService.success('adminFacilityAdd.facilityHasBeenSaved');
stateTrackerService.goToPreviousState();

angular.forEach(vm.selectedRequisitionGroups, function(requisitionGroup) {
requisitionGroup.memberFacilities.push(facility);

requisitionGroupService.update(requisitionGroup);
});
return facility;
})
.catch(function() {
notificationService.error('adminFacilityAdd.failedToSaveFacility');
loadingModalService.close();
});
})
.catch(function() {
notificationService.error('adminFacilityAdd.failedToSaveFacility');
Expand Down
23 changes: 23 additions & 0 deletions src/admin-facility-add/facility-add.controller.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,14 @@ describe('FacilityAddController', function() {

beforeEach(function() {
module('admin-facility-add');
module('referencedata-geographic-zone');

inject(function($injector) {
this.$controller = $injector.get('$controller');
this.$rootScope = $injector.get('$rootScope');
this.confirmService = $injector.get('confirmService');
this.$q = $injector.get('$q');
this.geographicZoneService = $injector.get('geographicZoneService');
this.FacilityRepository = $injector.get('FacilityRepository');
this.stateTrackerService = $injector.get('stateTrackerService');
this.$state = $injector.get('$state');
Expand Down Expand Up @@ -59,8 +61,19 @@ describe('FacilityAddController', function() {
this.saveDeferred = this.$q.defer();
var loadingDeferred = this.$q.defer();

this.newGeoZone = {
code: 'xxx',
level: {
id: '533a0771-bf2b-414a-91b2-6824d7df281d',
name: 'local',
code: 'local',
levelNumber: 2
}
};

spyOn(this.confirmService, 'confirm').andReturn(this.confirmDeferred.promise);
spyOn(this.stateTrackerService, 'goToPreviousState').andCallFake(loadingDeferred.resolve);
spyOn(this.geographicZoneService, 'create').andReturn(this.saveDeferred.promise);
spyOn(this.FacilityRepository.prototype, 'create').andReturn(this.saveDeferred.promise);
spyOn(this.$state, 'go');
spyOn(this.loadingModalService, 'open').andReturn(loadingDeferred.promise);
Expand All @@ -73,12 +86,20 @@ describe('FacilityAddController', function() {
}
});

this.facility.geographicZone = {
code: 'test_code',
level: {
levelNumber: 3
}
};

this.vm = this.$controller('FacilityAddController', {
facility: this.facility,
facilityTypes: this.facilityTypes,
geographicZones: this.geographicZones,
facilityOperators: this.facilityOperators
});

this.vm.$onInit();

this.$rootScope.$apply();
Expand Down Expand Up @@ -128,6 +149,7 @@ describe('FacilityAddController', function() {
describe('save', function() {

it('should prompt user to add programs', function() {
this.geographicZoneService.create.andReturn(this.$q.when(this.newGeoZone));
this.FacilityRepository.prototype.create.andReturn(this.$q.when(this.facility));
this.vm.save();
this.$rootScope.$apply();
Expand Down Expand Up @@ -173,6 +195,7 @@ describe('FacilityAddController', function() {
});

it('should take to the user to add programs page if user agrees to it', function() {
this.geographicZoneService.create.andReturn(this.$q.when(this.newGeoZone));
this.FacilityRepository.prototype.create.andReturn(this.$q.when(this.facility));
this.vm.save();

Expand Down
54 changes: 29 additions & 25 deletions src/admin-facility-add/facility-information.html
Original file line number Diff line number Diff line change
@@ -1,26 +1,30 @@
<label for="facilityName">{{'adminFacilityAdd.facilityName' | message}}</label>
<input id="facilityName" type="text" ng-model="vm.facility.name" ng-disabled="vm.managedExternally" required />
<label for="facilityCode">{{'adminFacilityAdd.facilityCode' | message}}</label>
<input id="facilityCode" type="text" ng-model="vm.facility.code" ng-disabled="vm.managedExternally"required />
<label for="facilityType">{{'adminFacilityAdd.facilityType' | message}}</label>
<select id="facilityType" ng-model="vm.facility.type" ng-options="type as type.name for type in vm.facilityTypes track by type.id" required></select>
<label for="operationalDate">{{'adminFacilityAdd.operationalDate' | message}}</label>
<input id="operationalDate" type="date" ng-model="vm.facility.goLiveDate" ng-required="vm.facility.id" />
<p class="note">{{'adminFacilityAdd.operationalDate.description' | message}}</p>
<label for="facilityActive" class="checkbox">
<input id="facilityActive" type="checkbox" ng-model="vm.facility.active" ng-disabled="vm.managedExternally" />
{{'adminFacilityAdd.activeFacility' | message}}
</label>
<p class="note">{{'adminFacilityAdd.activeFacility.description' | message}}</p>
<label for="facilityEnabled" class="checkbox">
<input id="facilityEnabled" type="checkbox" ng-model="vm.facility.enabled" />
{{'adminFacilityAdd.enabled' | message}}
</label>
<p class="note">{{'adminFacilityAdd.enabled.description.checked' | message}}</p>
<p class="note">{{'adminFacilityAdd.enabled.description.unchecked' | message}}</p>
<label for="geographicZone">{{'adminFacilityAdd.geographicZone' | message}}</label>
<select id="geographicZone" ng-disabled="vm.managedExternally" ng-model="vm.facility.geographicZone" ng-options="geographicZone as geographicZone.name for geographicZone in vm.geographicZones track by geographicZone.id" required></select>
<label for="description">{{'adminFacilityAdd.description' | message}}</label>
<textarea id="description" ng-model="vm.facility.description" ng-disabled="vm.managedExternally"></textarea>
<label for="facilityOperator">{{'adminFacilityAdd.facilityOperator' | message}}</label>
<select id="facilityOperator" ng-model="vm.facility.operator" ng-options="facilityOperator as facilityOperator.name for facilityOperator in vm.facilityOperators track by facilityOperator.id"></select>
<input id="facilityName" type="text" ng-model="vm.facility.name" ng-disabled="vm.managedExternally" required />
<label for="facilityCode">{{'adminFacilityAdd.facilityCode' | message}}</label>
<input id="facilityCode" type="text" ng-model="vm.facility.code" ng-disabled="vm.managedExternally" required />
<label for="facilityType">{{'adminFacilityAdd.facilityType' | message}}</label>
<select id="facilityType" ng-model="vm.facility.type"
ng-options="type as type.name for type in vm.facilityTypes track by type.id" required></select>
<label for="operationalDate">{{'adminFacilityAdd.operationalDate' | message}}</label>
<input id="operationalDate" type="date" ng-model="vm.facility.goLiveDate" ng-required="vm.facility.id" />
<p class="note">{{'adminFacilityAdd.operationalDate.description' | message}}</p>
<label for="facilityActive" class="checkbox">
<input id="facilityActive" type="checkbox" ng-model="vm.facility.active" ng-disabled="vm.managedExternally" />
{{'adminFacilityAdd.activeFacility' | message}}
</label>
<p class="note">{{'adminFacilityAdd.activeFacility.description' | message}}</p>
<label for="facilityEnabled" class="checkbox">
<input id="facilityEnabled" type="checkbox" ng-model="vm.facility.enabled" />
{{'adminFacilityAdd.enabled' | message}}
</label>
<p class="note">{{'adminFacilityAdd.enabled.description.checked' | message}}</p>
<p class="note">{{'adminFacilityAdd.enabled.description.unchecked' | message}}</p>
<label for="geographicZone">{{'adminFacilityAdd.geographicZone' | message}}</label>
<select id="geographicZone" ng-disabled="vm.managedExternally" ng-model="vm.facility.geographicZone"
ng-options="geographicZone as geographicZone.name for geographicZone in vm.geographicZones track by geographicZone.id"
required></select>
<label for="description">{{'adminFacilityAdd.description' | message}}</label>
<textarea id="description" ng-model="vm.facility.description" ng-disabled="vm.managedExternally"></textarea>
<label for="facilityOperator">{{'adminFacilityAdd.facilityOperator' | message}}</label>
<select id="facilityOperator" ng-model="vm.facility.operator"
ng-options="facilityOperator as facilityOperator.name for facilityOperator in vm.facilityOperators track by facilityOperator.id"></select>
3 changes: 2 additions & 1 deletion src/admin-facility-list/admin-facility-list.module.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
'referencedata-geographic-zone',
'openlmis-admin',
'ui.router',
'openlmis-table'
'openlmis-table',
'admin-facility-view'
]);
})();
9 changes: 6 additions & 3 deletions src/admin-facility-list/facility-list.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,10 @@
.controller('FacilityListController', controller);

controller.$inject = [
'$state', '$stateParams', 'facilities', 'geographicZones', 'TABLE_CONSTANTS'
'$state', '$stateParams', 'facilities', 'geographicZones', 'TABLE_CONSTANTS', 'WARDS_CONSTANTS'
];

function controller($state, $stateParams, facilities, geographicZones, TABLE_CONSTANTS) {
function controller($state, $stateParams, facilities, geographicZones, TABLE_CONSTANTS, WARDS_CONSTANTS) {
var vm = this;

vm.$onInit = onInit;
Expand Down Expand Up @@ -195,7 +195,10 @@
redirectLink: function(item) {
return 'openlmis.administration.facilities.edit({id:\'' + item.id + '\'})';
},
text: 'adminFacilityList.edit'
text: 'adminFacilityList.edit',
displayAction: function(item) {
return item.type.code !== WARDS_CONSTANTS.WARD_TYPE_CODE;
}
}
]
},
Expand Down
2 changes: 1 addition & 1 deletion src/admin-facility-view/facility-view.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,7 @@
* Generates ward code based on the facility code.
*/
function generateWardCode(facilityCode) {
var serialNumber = padNumber(vm.wards.length + 1, 4);
var serialNumber = padNumber((vm.wards.length + vm.addedWards.length) + 1, 4);

return facilityCode + '.' + serialNumber;
}
Expand Down
117 changes: 117 additions & 0 deletions src/referencedata-geographic-zone/geographic-zone.service.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
/*
* 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 service
* @name referencedata-geographic-zone.geographicZoneService
*
* @description
* Responsible for retrieving all geographic zone information from server.
*/
angular
.module('referencedata-geographic-zone')
.service('geographicZoneService', service);

service.$inject = ['$resource', 'referencedataUrlFactory'];

function service($resource, referencedataUrlFactory) {

var resource = $resource(referencedataUrlFactory('/api/geographicZones/:id'), {}, {
getAll: {
url: referencedataUrlFactory('/api/geographicZones'),
method: 'GET'
},
search: {
url: referencedataUrlFactory('/api/geographicZones/search'),
method: 'POST'
},
create: {
url: referencedataUrlFactory('/api/geographicZones'),
method: 'POST'
}
});

this.get = get;
this.getAll = getAll;
this.search = search;
this.create = createGeoZone;

/**
* @ngdoc method
* @methodOf referencedata-geographic-zone.geographicZoneService
* @name get
*
* @description
* Gets geographic zone by id.
*
* @param {String} id the geographic zone UUID
* @return {Promise} the geographic zone object
*/
function get(id) {
return resource.get({
id: id
}).$promise;
}

/**
* @ngdoc method
* @methodOf referencedata-geographic-zone.geographicZoneService
* @name getAll
*
* @description
* Gets all geographic zones.
*
* @param {Object} paginationParams the pagination params: page and size
* @return {Promise} the paginated object of all geographic zones
*/
function getAll(paginationParams) {
return resource.getAll(paginationParams).$promise;
}

/**
* @ngdoc method
* @methodOf referencedata-geographic-zone.geographicZoneService
* @name search
*
* @description
* Searches Geographic Zones using given parameters.
*
* @param {Object} params the pagination and query parameters
* @return {Promise} the requested page of filtered geographic zones
*/
function search(params) {
var paginationParams = {
page: params.page,
size: params.size,
sort: params.sort
},
queryParams = angular.copy(params);

delete queryParams.page;
delete queryParams.size;
delete queryParams.sort;

return resource.search(paginationParams, queryParams).$promise;
}

function createGeoZone(geoZone) {
return resource.create(geoZone).$promise;
}
}
})();
4 changes: 0 additions & 4 deletions src/stock-event/stock-event.factory.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,6 @@
throw 'stockPhysicalInventoryDraft.submitInvalidActive';
}

if (item.unitOfOrderableId) {
console.log('this one has unit: ' + item);
}

return new StockEventLineItem(
item.orderable.id, item.lot ? item.lot.id : null,
item.quantity, physicalInventory.occurredDate,
Expand Down
3 changes: 0 additions & 3 deletions src/stock-physical-inventory/physical-inventory.factory.js
Original file line number Diff line number Diff line change
Expand Up @@ -202,9 +202,6 @@
angular.forEach(draft.lineItems, function(item) {
// ANGOLASUP-825: Fixed inventory saving functionality
if (!(item.lot && (item.lot.lotCode && !item.lot.id))) {
if (item.unitOfOrderableId) {
console.log(item);
}
physicalInventory.lineItems.push({
orderableId: item.orderable.id,
lotId: (item.lot && item) ? item.lot.id : null,
Expand Down
Loading