diff --git a/src/admin-lot-edit/admin-lot-edit.controller.js b/src/admin-lot-edit/admin-lot-edit.controller.js deleted file mode 100644 index a76b28e..0000000 --- a/src/admin-lot-edit/admin-lot-edit.controller.js +++ /dev/null @@ -1,115 +0,0 @@ -/* - * 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 info@OpenLMIS.org. - */ - -(function() { - - 'use strict'; - - /** - * @ngdoc controller - * @name admin-lot-edit.controller:LotEditController - * - * @description - * Provides methods for Edit Lot modal. - */ - angular - .module('admin-lot-edit') - .controller('LotEditController', LotEditController); - - LotEditController.$inject = [ - '$state', - 'loadingModalService', - 'notificationService', - 'confirmService', - 'stateTrackerService', - 'LotResource', - 'lot' - ]; - - function LotEditController( - $state, - loadingModalService, - notificationService, - confirmService, - stateTrackerService, - LotResource, - lot - ) { - var vm = this; - - vm.$onInit = onInit; - vm.editLot = editLot; - vm.goToPreviousState = stateTrackerService.goToPreviousState; - - /** - * @ngdoc property - * @methodOf admin-lot-edit.controller:LotEditController - * @name lot - * @type {Object} - * - * @description - * Current lot - */ - vm.lot = undefined; - - /** - * @ngdoc property - * @methodOf admin-lot-edit.controller:LotEditController - * @name lotResource - * @type {LotResource} - * - * @description - */ - vm.lotResource = undefined; - - /** - * @ngdoc method - * @methodOf admin-lot-edit.controller:LotEditController - * @name $onInit - * - * @description - * Method that is executed on initiating LotEditController. - */ - function onInit() { - vm.lot = lot; - vm.lotResource = new LotResource(); - } - - /** - * @ngdoc property - * @methodOf admin-lot-edit.controller:LotEditController - * @name editLot - * - * @description - */ - function editLot() { - console.log(vm.lot); - confirmService.confirm('adminLotEdit.save.confirmationQuestion', 'adminLotEdit.save') - .then(function() { - loadingModalService.open(); - - vm.lotResource.update(vm.lot).then(function() { - notificationService.success('adminLotEdit.save.success'); - loadingModalService.close(); - stateTrackerService.goToPreviousState(); - }) - .catch(function() { - loadingModalService.close(); - notificationService.error('adminLotEdit.save.failure'); - }); - }); - } - } -})(); \ No newline at end of file diff --git a/src/admin-lot-edit/admin-lot-edit.controller.spec.js b/src/admin-lot-edit/admin-lot-edit.controller.spec.js deleted file mode 100644 index 2dccaab..0000000 --- a/src/admin-lot-edit/admin-lot-edit.controller.spec.js +++ /dev/null @@ -1,126 +0,0 @@ -/* - * 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 info@OpenLMIS.org. - */ - -describe('LotEditController', function() { - - beforeEach(function() { - module('admin-lot-edit'); - - inject(function($injector) { - this.$controller = $injector.get('$controller'); - this.$state = $injector.get('$state'); - this.$rootScope = $injector.get('$rootScope'); - this.$q = $injector.get('$q'); - this.confirmService = $injector.get('confirmService'); - this.loadingModalService = $injector.get('loadingModalService'); - this.notificationService = $injector.get('notificationService'); - - this.LotDataBuilder = $injector.get('LotDataBuilder'); - this.LotResource = $injector.get('LotResource'); - }); - - this.defaultLot = new this.LotDataBuilder().build(); - - spyOn(this.loadingModalService, 'open'); - spyOn(this.loadingModalService, 'close'); - - spyOn(this.notificationService, 'success'); - spyOn(this.notificationService, 'error'); - - this.vm = this.$controller('LotEditController', { - loadingModalService: this.loadingModalService, - notificationService: this.notificationService, - confirmService: this.confirmService, - LotResource: this.LotResource, - lot: this.defaultLot - }); - - this.vm.$onInit(); - }); - - describe('onInit', function() { - - it('should expose editLot method', function() { - expect(typeof this.vm.editLot).toBe('function'); - - }); - - it('should expose lot', function() { - expect(this.vm.lot).toEqual(this.defaultLot); - }); - }); - - describe('editLot', function() { - - it('should not perform update if user does not confirm', function() { - this.confirmDeferred = this.$q.defer(); - spyOn(this.confirmService, 'confirm').andReturn(this.confirmDeferred.promise); - - this.vm.editLot(); - - this.confirmDeferred.reject(); - this.$rootScope.$apply(); - - expect(this.confirmService.confirm).toHaveBeenCalledWith( - 'adminLotEdit.save.confirmationQuestion', - 'adminLotEdit.save' - ); - }); - - it('should update when user confirms', function() { - this.confirmDeferred = this.$q.defer(); - this.updateResultDeferred = this.$q.defer(); - - spyOn(this.confirmService, 'confirm').andReturn(this.confirmDeferred.promise); - spyOn(this.vm.lotResource, 'update').andReturn(this.updateResultDeferred.promise); - - this.vm.editLot(); - - this.confirmDeferred.resolve(); - this.updateResultDeferred.resolve(); - this.$rootScope.$apply(); - - expect(this.confirmService.confirm).toHaveBeenCalledWith( - 'adminLotEdit.save.confirmationQuestion', - 'adminLotEdit.save' - ); - - expect(this.vm.lotResource.update).toHaveBeenCalled(); - expect(this.notificationService.success).toHaveBeenCalledWith('adminLotEdit.save.success'); - }); - - it('should show error message on failure', function() { - this.confirmDeferred = this.$q.defer(); - this.updateResultDeferred = this.$q.defer(); - - spyOn(this.confirmService, 'confirm').andReturn(this.confirmDeferred.promise); - spyOn(this.vm.lotResource, 'update').andReturn(this.updateResultDeferred.promise); - - this.vm.editLot(); - - this.confirmDeferred.resolve(); - this.updateResultDeferred.reject(); - this.$rootScope.$apply(); - - expect(this.confirmService.confirm).toHaveBeenCalledWith( - 'adminLotEdit.save.confirmationQuestion', - 'adminLotEdit.save' - ); - - expect(this.vm.lotResource.update).toHaveBeenCalled(); - expect(this.notificationService.error).toHaveBeenCalledWith('adminLotEdit.save.failure'); - }); - }); -}); diff --git a/src/admin-lot-edit/admin-lot-edit.module.js b/src/admin-lot-edit/admin-lot-edit.module.js deleted file mode 100644 index d11d5bd..0000000 --- a/src/admin-lot-edit/admin-lot-edit.module.js +++ /dev/null @@ -1,35 +0,0 @@ -/* - * 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 info@OpenLMIS.org. - */ - -(function() { - - 'use strict'; - - /** - * @module admin-lot-edit - * - * @description - * Provides lot edit modal. - */ - angular.module('admin-lot-edit', [ - 'openlmis-modal', - 'openlmis-templates', - 'openlmis-modal-state', - 'openlmis-state-tracker', - 'openlmis-rights', - 'referencedata-lot' - ]); - -})(); \ No newline at end of file diff --git a/src/admin-lot-edit/admin-lot-edit.routes.js b/src/admin-lot-edit/admin-lot-edit.routes.js deleted file mode 100644 index a96a645..0000000 --- a/src/admin-lot-edit/admin-lot-edit.routes.js +++ /dev/null @@ -1,46 +0,0 @@ -/* - * 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 info@OpenLMIS.org. - */ - -(function() { - - 'use strict'; - - angular.module('admin-lot-edit').config(routes); - - routes.$inject = ['modalStateProvider', 'ADMINISTRATION_RIGHTS']; - - function routes(modalStateProvider, ADMINISTRATION_RIGHTS) { - modalStateProvider.state('openlmis.administration.lots.edit', { - controller: 'LotEditController', - controllerAs: 'vm', - templateUrl: 'admin-lot-edit/lot-edit.html', - url: '/edit/:lotId', - accessRights: [ADMINISTRATION_RIGHTS.LOTS_MANAGE], - resolve: { - lot: function($stateParams, alertService, stateTrackerService, LotResource) { - return new LotResource().get($stateParams.lotId) - .then(function(response) { - return response; - }) - .catch(function() { - alertService.error('adminLotsEdit.lotNotFound'); - stateTrackerService.goToPreviousState(); - }); - } - }, - parentResolves: [] - }); - } -})(); \ No newline at end of file diff --git a/src/admin-lot-edit/lot-edit.html b/src/admin-lot-edit/lot-edit.html index 27254f3..648b3f4 100644 --- a/src/admin-lot-edit/lot-edit.html +++ b/src/admin-lot-edit/lot-edit.html @@ -38,4 +38,4 @@