Skip to content

Commit

Permalink
AO-899: fixed offline indicator
Browse files Browse the repository at this point in the history
  • Loading branch information
DominikNoga committed Nov 6, 2024
1 parent 2d04eac commit 71ee062
Show file tree
Hide file tree
Showing 3 changed files with 202 additions and 6 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
/*
* 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 offline-events-indicator.controller:OfflineEventsIndicatorController
*
* @description
* Exposes count of the pending offline events or count of stock event sync errors.
*/
angular
.module('openlmis-offline-events-indicator')
.controller('OfflineEventsIndicatorController', controller);

controller.$inject = ['offlineEventsService', '$rootScope', '$state'];

function controller(offlineEventsService, $rootScope, $state) {

var vm = this;

vm.$onInit = onInit;
vm.goToPendingOfflineEventsPage = goToPendingOfflineEventsPage;
vm.goToSynchronizationErrorsPage = goToSynchronizationErrorsPage;

/**
* @ngdoc property
* @propertyOf offline-events-indicator.controller:OfflineEventsIndicatorController
* @name pendingEventsCount
* @type {Number}
*
* @description
* Holds pending offline events count.
*/
vm.pendingEventsCount;

/**
* @ngdoc property
* @propertyOf offline-events-indicator.controller:OfflineEventsIndicatorController
* @name offlineSyncErrorsCount
* @type {Number}
*
* @description
* Holds event synchronization errors count.
*/
vm.offlineSyncErrorsCount;

function onInit() {
offlineEventsService.getCountOfPendingOfflineEvents()
.then(function(result) {
vm.pendingEventsCount = result;
});

offlineEventsService.getCountOfSyncErrorEvents()
.then(function(result) {
vm.offlineSyncErrorsCount = result;
});
}

/**
* @ngdoc method
* @methodOf offline-events-indicator.controller:OfflineEventsIndicatorController
* @name goToPendingOfflineEventsPage
*
* @description
* Takes the user to the pending offline events page.
*/
function goToPendingOfflineEventsPage() {
$state.go('openlmis.pendingOfflineEvents');
}

/**
* @ngdoc method
* @methodOf offline-events-indicator.controller:OfflineEventsIndicatorController
* @name goToSynchronizationErrorsPage
*
* @description
* Takes the user to the synchronization errors page.
*/
function goToSynchronizationErrorsPage() {
$state.go('openlmis.eventsSynchronizationErrors');
}

$rootScope.$on('openlmis-referencedata.offline-events-indicator', function() {
offlineEventsService.getCountOfPendingOfflineEvents()
.then(function(result) {
vm.pendingEventsCount = result;
});

offlineEventsService.getCountOfSyncErrorEvents()
.then(function(result) {
vm.offlineSyncErrorsCount = result;
});
});
}

})();
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
/*
* 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]
*/

describe('OfflineEventsIndicatorController', function() {

beforeEach(function() {
module('openlmis-offline-events-indicator');

inject(function($injector) {
this.$q = $injector.get('$q');
this.$rootScope = $injector.get('$rootScope');
this.$state = $injector.get('$state');
this.$controller = $injector.get('$controller');
this.offlineEventsService = $injector.get('offlineEventsService');
});

this.pendingEventsCount = 2;
this.offlineSyncErrorsCount = 1;

spyOn(this.offlineEventsService, 'getCountOfPendingOfflineEvents')
.andReturn(this.$q.resolve(this.pendingEventsCount));
spyOn(this.offlineEventsService, 'getCountOfSyncErrorEvents')
.andReturn(this.$q.resolve(this.offlineSyncErrorsCount));

spyOn(this.$state, 'go').andReturn();

this.vm = this.$controller('OfflineEventsIndicatorController');
});

describe('$onInit', function() {

it('should expose pending offline events and offline sync errors', function() {
this.vm.$onInit();
this.$rootScope.$apply();

expect(this.offlineEventsService.getCountOfPendingOfflineEvents).toHaveBeenCalled();
expect(this.vm.pendingEventsCount).toEqual(this.pendingEventsCount);
expect(this.offlineEventsService.getCountOfSyncErrorEvents).toHaveBeenCalled();
expect(this.vm.offlineSyncErrorsCount).toEqual(this.offlineSyncErrorsCount);
});

it('should update offline events count and errors', function() {
this.$rootScope.$emit('openlmis-referencedata.offline-events-indicator');
this.$rootScope.$apply();

expect(this.offlineEventsService.getCountOfPendingOfflineEvents).toHaveBeenCalled();
expect(this.offlineEventsService.getCountOfSyncErrorEvents).toHaveBeenCalled();
});

});

describe('goToPendingOfflineEventsPage', function() {

it('should call state go method', function() {
this.vm.goToPendingOfflineEventsPage();
this.$rootScope.$apply();

expect(this.$state.go).toHaveBeenCalledWith('openlmis.pendingOfflineEvents');
});
});

describe('goToSynchronizationErrorsPage', function() {

it('should call state go method', function() {
this.vm.goToSynchronizationErrorsPage();
this.$rootScope.$apply();

expect(this.$state.go).toHaveBeenCalledWith('openlmis.eventsSynchronizationErrors');
});
});
});
13 changes: 7 additions & 6 deletions src/stock-adjustment-creation/adjustment-creation.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@
// AO-805: Allow users with proper rights to edit product prices
'OrderableResource', 'permissionService', 'ADMINISTRATION_RIGHTS', 'authorizationService',
// AO-805: Ends here
'unitOfOrderableService', 'wardService', 'orderableGroupsByWard', 'WARDS_CONSTANTS', 'sourceDestinationService'
'unitOfOrderableService', 'wardService', 'orderableGroupsByWard', 'WARDS_CONSTANTS', 'sourceDestinationService',
'$timeout'
];

function controller($scope, $state, $stateParams, $filter, confirmDiscardService, program,
Expand All @@ -54,7 +55,7 @@
// AO-805: Allow users with proper rights to edit product prices
accessTokenFactory, $window, stockmanagementUrlFactory, OrderableResource, permissionService,
ADMINISTRATION_RIGHTS, authorizationService, unitOfOrderableService, wardService,
orderableGroupsByWard, WARDS_CONSTANTS, sourceDestinationService) {
orderableGroupsByWard, WARDS_CONSTANTS, sourceDestinationService, $timeout) {
// ANGOLASUP-717: ends here
// AO-805: Ends here
var vm = this;
Expand Down Expand Up @@ -849,9 +850,9 @@
}

return $q.all(submitAdjustmentPromises).then(function() {
return $q.resolve(function() {
$timeout(function() {
goToStockCardSummaries();
}());
});
});
}

Expand All @@ -877,9 +878,9 @@
goToStockCardSummaries();
});
} else {
return $q.resolve(function() {
$timeout(function() {
goToStockCardSummaries();
}());
});
}
// ANGOLASUP-717: ends here
}, function(errorResponse) {
Expand Down

0 comments on commit 71ee062

Please sign in to comment.