diff --git a/src/admin-valid-destination-add/admin-valid-destination-add.routes.js b/src/admin-valid-destination-add/admin-valid-destination-add.routes.js new file mode 100644 index 0000000..5aa3ffa --- /dev/null +++ b/src/admin-valid-destination-add/admin-valid-destination-add.routes.js @@ -0,0 +1,64 @@ +/* + * 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-valid-destination-add') + .config(routes); + + routes.$inject = ['modalStateProvider', 'ADMINISTRATION_RIGHTS']; + + function routes(modalStateProvider, ADMINISTRATION_RIGHTS) { + + modalStateProvider.state('openlmis.administration.validDestination.add', { + controller: 'ValidDestinationAddController', + controllerAs: 'vm', + accessRights: [ADMINISTRATION_RIGHTS.STOCK_DESTINATIONS_MANAGE], + templateUrl: 'admin-valid-destination-add/valid-destination-add.html', + url: '/add', + resolve: { + organizations: organizationsResolve, + geoLevels: geoLevelsResolve + }, + parentResolves: [ + 'facilities', + 'facilityTypes', + 'geographicLevelMap', + 'programs' + ] + }); + + geoLevelsResolve.$inject = ['GeoLevelResource']; + + function geoLevelsResolve(GeoLevelResource) { + return new GeoLevelResource().query() + .then(function(resource) { + return resource.content; + }); + } + + organizationsResolve.$inject = ['OrganizationResource']; + + function organizationsResolve(OrganizationResource) { + return new OrganizationResource().query() + .then(function(resource) { + return resource.content; + }); + } + } +})(); diff --git a/src/admin-valid-destination-add/valid-destination-add.html b/src/admin-valid-destination-add/valid-destination-add.html new file mode 100644 index 0000000..a15ef4e --- /dev/null +++ b/src/admin-valid-destination-add/valid-destination-add.html @@ -0,0 +1,89 @@ + + diff --git a/src/admin-valid-destination-list/admin-valid-destination-list.routes.js b/src/admin-valid-destination-list/admin-valid-destination-list.routes.js index d54aa91..23cbcd0 100644 --- a/src/admin-valid-destination-list/admin-valid-destination-list.routes.js +++ b/src/admin-valid-destination-list/admin-valid-destination-list.routes.js @@ -38,7 +38,8 @@ size: params.size, page: params.page, programId: params.programId, - facilityId: params.facilityId + facilityId: params.facilityId, + includeDisabled: true }); }); }, diff --git a/src/admin-valid-source-add/admin-valid-source-add.routes.js b/src/admin-valid-source-add/admin-valid-source-add.routes.js new file mode 100644 index 0000000..194e771 --- /dev/null +++ b/src/admin-valid-source-add/admin-valid-source-add.routes.js @@ -0,0 +1,64 @@ +/* + * 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-valid-source-add') + .config(routes); + + routes.$inject = ['modalStateProvider', 'ADMINISTRATION_RIGHTS']; + + function routes(modalStateProvider, ADMINISTRATION_RIGHTS) { + + modalStateProvider.state('openlmis.administration.validSource.add', { + controller: 'ValidSourceAddController', + controllerAs: 'vm', + accessRights: [ADMINISTRATION_RIGHTS.STOCK_SOURCES_MANAGE], + templateUrl: 'admin-valid-source-add/valid-source-add.html', + url: '/add', + resolve: { + organizations: organizationsResolve, + geoLevels: geoLevelsResolve + }, + parentResolves: [ + 'facilities', + 'facilityTypes', + 'geographicLevelMap', + 'programs' + ] + }); + + geoLevelsResolve.$inject = ['GeoLevelResource']; + + function geoLevelsResolve(GeoLevelResource) { + return new GeoLevelResource().query() + .then(function(resource) { + return resource.content; + }); + } + + organizationsResolve.$inject = ['OrganizationResource']; + + function organizationsResolve(OrganizationResource) { + return new OrganizationResource().query() + .then(function(resource) { + return resource.content; + }); + } + } +})(); diff --git a/src/admin-valid-source-add/valid-source-add.html b/src/admin-valid-source-add/valid-source-add.html new file mode 100644 index 0000000..912c3d4 --- /dev/null +++ b/src/admin-valid-source-add/valid-source-add.html @@ -0,0 +1,89 @@ + + diff --git a/src/admin-valid-source-list/admin-valid-source-list.routes.js b/src/admin-valid-source-list/admin-valid-source-list.routes.js index 6cb7feb..0b86ed0 100644 --- a/src/admin-valid-source-list/admin-valid-source-list.routes.js +++ b/src/admin-valid-source-list/admin-valid-source-list.routes.js @@ -38,7 +38,8 @@ size: params.size, page: params.page, programId: params.programId, - facilityId: params.facilityId + facilityId: params.facilityId, + includeDisabled: true }); }); }, diff --git a/src/openlmis-rights/administration-rights.constant.js b/src/openlmis-rights/administration-rights.constant.js index ea60a70..124182a 100644 --- a/src/openlmis-rights/administration-rights.constant.js +++ b/src/openlmis-rights/administration-rights.constant.js @@ -49,6 +49,7 @@ ORDER_CREATE: 'ORDER_CREATE', DATA_EXPORT: 'DATA_EXPORT', DATA_IMPORT: 'DATA_IMPORT', + STOCK_ORGANIZATIONS_MANAGE: 'STOCK_ORGANIZATIONS_MANAGE', // AO-805: Allow users with proper rights to edit product prices EDIT_PRODUCT_PRICE_STOCK_MANAGEMENT: 'EDIT_PRODUCT_PRICE_STOCK_MANAGEMENT' // AO-805: Ends here diff --git a/src/organization-add/messages_en.json b/src/organization-add/messages_en.json new file mode 100644 index 0000000..8434fba --- /dev/null +++ b/src/organization-add/messages_en.json @@ -0,0 +1,11 @@ +{ + "organizationAdd.addOrganization": "Add Organization", + "organizationAdd.cancel": "Cancel", + "organizationAdd.save": "Save", + "organizationAdd.create": "Create", + "organizationAdd.organizationName": "Organization Name", + "organizationAdd.disabled": "Disabled", + "organizationAdd.confirmationPrompt": "Are you sure you want to create organization?", + "organizationAdd.organizationCreated": "Organization created successfully.", + "organizationAdd.organizationCreateError": "Error while creating organization." +} diff --git a/src/organization-add/organization-add.controller.js b/src/organization-add/organization-add.controller.js new file mode 100644 index 0000000..7ada319 --- /dev/null +++ b/src/organization-add/organization-add.controller.js @@ -0,0 +1,89 @@ +/* + * 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('organization-add') + .controller('OrganizationAddController', OrganizationAddController); + + OrganizationAddController.$inject = [ + 'stateTrackerService', + 'confirmService', + 'organizationService', + 'notificationService', + 'loadingModalService' + ]; + + /** + * @ngdoc controller + * @name organization-add.controller:OrganizationAddController + * + * @description + * Controller for adding organizations. + */ + function OrganizationAddController( + stateTrackerService, + confirmService, + organizationService, + notificationService, + loadingModalService + ) { + + var vm = this; + + vm.createOrganization = createOrganization; + vm.goToPreviousState = stateTrackerService.goToPreviousState; + + /** + * @ngdoc property + * @propertyOf organization-add.controller:OrganizationAddController + * @name createdOrganization + * + * @description + * Organization to be created. + */ + vm.organization = null; + + /** + * @ngdoc method + * @methodOf organization-add.controller:OrganizationAddController + * @name createOrganization + * + * @description + * Creates the organization. + */ + function createOrganization() { + confirmService.confirm('organizationAdd.confirmationPrompt', 'organizationAdd.create') + .then(function() { + loadingModalService.open(); + + organizationService.createNewOrganization(vm.createdOrganization) + .then(function() { + notificationService.success('organizationAdd.organizationCreated'); + loadingModalService.close(); + stateTrackerService.goToPreviousState(); + }) + .catch(function() { + loadingModalService.close(); + notificationService.error('organizationAdd.organizationCreateError'); + }); + }); + } + + } +})(); diff --git a/src/organization-add/organization-add.html b/src/organization-add/organization-add.html new file mode 100644 index 0000000..a9a2c6f --- /dev/null +++ b/src/organization-add/organization-add.html @@ -0,0 +1,30 @@ + + \ No newline at end of file diff --git a/src/organization-add/organization-add.module.js b/src/organization-add/organization-add.module.js new file mode 100644 index 0000000..69fc946 --- /dev/null +++ b/src/organization-add/organization-add.module.js @@ -0,0 +1,35 @@ +/* + * 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 organization-add + * + * @description + * Provides a view (modal) for adding a new organization. + */ + angular.module('organization-add', [ + 'referencedata-facility', + 'openlmis-modal', + 'openlmis-templates', + 'openlmis-state-tracker', + 'openlmis-modal-state', + 'openlmis-table' + ]); + +})(); diff --git a/src/organization-add/organization-add.routes.js b/src/organization-add/organization-add.routes.js new file mode 100644 index 0000000..10f671a --- /dev/null +++ b/src/organization-add/organization-add.routes.js @@ -0,0 +1,38 @@ +/* + * 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('organization-add') + .config(routes); + + routes.$inject = ['modalStateProvider', 'ADMINISTRATION_RIGHTS']; + + function routes(modalStateProvider, ADMINISTRATION_RIGHTS) { + + modalStateProvider.state('openlmis.administration.organizations.add', { + controller: 'OrganizationAddController', + controllerAs: 'vm', + templateUrl: 'organization-add/organization-add.html', + url: '/add', + accessRights: [ADMINISTRATION_RIGHTS.STOCK_ORGANIZATIONS_MANAGE] + }); + + } + +})(); diff --git a/src/organization-edit/messages_en.json b/src/organization-edit/messages_en.json new file mode 100644 index 0000000..8f9beb8 --- /dev/null +++ b/src/organization-edit/messages_en.json @@ -0,0 +1,10 @@ +{ + "organizationEdit.editOrganization": "Edit Organization", + "organizationEdit.cancel": "Cancel", + "organizationEdit.update": "Update", + "organizationEdit.organizationName": "Organization Name", + "organizationEdit.disabled": "Disabled", + "organizationEdit.confirmationPrompt": "Are you sure you want to update this organization?", + "organizationEdit.organizationSaved": "Organization saved successfully.", + "organizationEdit.organizationSaveError": "Error while saving organization." +} diff --git a/src/organization-edit/organization-edit.controller.js b/src/organization-edit/organization-edit.controller.js new file mode 100644 index 0000000..61cc4b8 --- /dev/null +++ b/src/organization-edit/organization-edit.controller.js @@ -0,0 +1,106 @@ +/* + * 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('organization-edit') + .controller('OrganizationEditController', OrganizationEditController); + + OrganizationEditController.$inject = [ + 'stateTrackerService', + 'confirmService', + 'organization', + 'organizationService', + 'notificationService', + 'loadingModalService' + ]; + + /** + * @ngdoc controller + * @name organization-edit.controller:OrganizationEditController + * + * @description + * Controller for editing organizations. + */ + function OrganizationEditController( + stateTrackerService, + confirmService, + organization, + organizationService, + notificationService, + loadingModalService + ) { + + var vm = this; + + vm.$onInit = onInit; + vm.saveOrganization = saveOrganization; + vm.goToPreviousState = stateTrackerService.goToPreviousState; + + /** + * @ngdoc property + * @propertyOf organization-edit.controller:OrganizationEditController + * @name editedOrganization + * @type {Object} + * + * @description + * Organization that is being edited. + */ + vm.editedOrganization = undefined; + + /** + * @ngdoc method + * @methodOf organization-edit.controller:OrganizationEditController + * @name $onInit + * + * @description + * Initialization method of the OrganizationEditController. + */ + function onInit() { + vm.editedOrganization = organization; + } + + /** + * @ngdoc method + * @methodOf organization-edit.controller:OrganizationEditController + * @name saveOrganization + * + * @description + * Saves the organization and takes user back to the previous state. + */ + function saveOrganization() { + confirmService.confirm('organizationEdit.confirmationPrompt', 'organizationEdit.update') + .then(function() { + loadingModalService.open(); + + organizationService.updateOrganization(vm.editedOrganization) + .then(function() { + notificationService.success('organizationEdit.organizationSaved'); + loadingModalService.close(); + stateTrackerService.goToPreviousState(); + }) + .catch(function() { + loadingModalService.close(); + notificationService.error('organizationEdit.organizationSaveError'); + }); + }); + } + + } + +})(); diff --git a/src/organization-edit/organization-edit.html b/src/organization-edit/organization-edit.html new file mode 100644 index 0000000..26e69bd --- /dev/null +++ b/src/organization-edit/organization-edit.html @@ -0,0 +1,29 @@ + diff --git a/src/organization-edit/organization-edit.module.js b/src/organization-edit/organization-edit.module.js new file mode 100644 index 0000000..2fede1c --- /dev/null +++ b/src/organization-edit/organization-edit.module.js @@ -0,0 +1,35 @@ +/* + * 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 organization-edit + * + * @description + * Provides a view (modal) for editing a organization. + */ + angular.module('organization-edit', [ + 'referencedata-facility', + 'openlmis-modal', + 'openlmis-templates', + 'openlmis-state-tracker', + 'openlmis-modal-state', + 'openlmis-table' + ]); + +})(); diff --git a/src/organization-edit/organization-edit.routes.js b/src/organization-edit/organization-edit.routes.js new file mode 100644 index 0000000..3e86181 --- /dev/null +++ b/src/organization-edit/organization-edit.routes.js @@ -0,0 +1,55 @@ +/* + * 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('organization-edit') + .config(routes); + + routes.$inject = ['modalStateProvider', 'ADMINISTRATION_RIGHTS']; + + function routes(modalStateProvider, ADMINISTRATION_RIGHTS) { + + modalStateProvider.state('openlmis.administration.organizations.edit', { + controller: 'OrganizationEditController', + controllerAs: 'vm', + resolve: { + organization: function($stateParams, organizationService) { + return organizationService.getOrganizations($stateParams) + .then(function(response) { + var requestedOrganizationId = $stateParams.id; + + var organization = response.find(function(organization) { + return organization.id === requestedOrganizationId; + }); + + return organization; + }) + .catch(function(error) { + throw new Error('Error while getting organization', error); + }); + } + }, + templateUrl: 'organization-edit/organization-edit.html', + url: '/edit/:id', + accessRights: [ADMINISTRATION_RIGHTS.STOCK_ORGANIZATIONS_MANAGE] + }); + + } + +})(); diff --git a/src/organization-list/messages_en.json b/src/organization-list/messages_en.json new file mode 100644 index 0000000..70b390d --- /dev/null +++ b/src/organization-list/messages_en.json @@ -0,0 +1,13 @@ +{ + "organizationList.navRoute": "Organizations", + "organizationList.pageHeader": "Organization List", + "organizationList.noOrganizations": "No Organizations found.", + "organizationList.filter.name": "Organization Name", + "organizationList.column.name": "Name", + "organizationList.column.code": "Code", + "organizationList.column.disabled": "Disabled", + "organizationList.column.actions": "Actions", + "organizationList.action.edit": "Edit", + "organizationList.addOrganization": "Add Organization", + "organizationList.deleteSelected": "Delete selected" +} diff --git a/src/organization-list/organization-list.controller.js b/src/organization-list/organization-list.controller.js new file mode 100644 index 0000000..61a1d53 --- /dev/null +++ b/src/organization-list/organization-list.controller.js @@ -0,0 +1,142 @@ +/* + * 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 organization-list.controller:OrganizationListController + * + * @description + * Controller for managing organizations list view. + */ + + angular + .module('organization-list') + .controller('OrganizationListController', controller); + + controller.$inject = ['$state', 'organizationsData', 'TABLE_CONSTANTS']; + + function controller($state, organizationsData, TABLE_CONSTANTS) { + var vm = this; + + vm.$onInit = onInit; + vm.redirectToAddOrganization = redirectToAddOrganization; + + /** + * @ngdoc property + * @propertyOf organization-list.controller:OrganizationListController + * @name tableConfig + * @type {Object} + * + * @description + * Holds table config for organization list. + */ + vm.tableConfig = undefined; + + /** + * @ngdoc property + * @propertyOf organization-list.controller:OrganizationListController + * @name organizationName + * @type {String} + * + * @description + * Contains name param for searching organization. + */ + vm.organizationName = undefined; + + /** + * @ngdoc property + * @propertyOf organization-list.controller:OrganizationListController + * @name organizations + * @type {Array} + * + * @description + * Contains list of organizations. + */ + vm.organizations = undefined; + + /** + * @ngdoc method + * @methodOf organization-list.controller:OrganizationListController + * @name $onInit + * + * @description + * Method that is executed on initiating OrganizationListController. + */ + function onInit() { + vm.organizations = organizationsData; + vm.tableConfig = getTableConfig(); + } + + /** + * @ngdoc method + * @methodOf organization-list.controller:OrganizationListController + * @name redirectToAddOrganization + * + * @description + * Redirects the user to the add organization page. + */ + function redirectToAddOrganization() { + $state.go('openlmis.administration.organizations.add'); + } + + /** + * @ngdoc method + * @methodOf organization-list.controller:OrganizationListController + * @name getTableConfig + * + * @description + * Returns the configuration for the organization list table. + */ + function getTableConfig() { + return { + caption: 'organizationList.noOrganizations', + displayCaption: !vm.organizations || vm.organizations.length === 0, + isSelectable: false, + columns: [ + { + header: 'organizationList.column.name', + propertyPath: 'name', + sortable: false, + template: function(item) { + return item.name; + } + }, + { + header: 'organizationList.column.disabled', + propertyPath: 'disabled', + sortable: false, + template: '' + } + ], + actions: { + header: 'organizationList.column.actions', + data: [ + { + type: TABLE_CONSTANTS.actionTypes.REDIRECT, + redirectLink: function(item) { + return 'openlmis.administration.organizations.edit({id:\'' + item.id + '\'})'; + }, + text: 'organizationList.action.edit' + } + ] + }, + data: vm.organizations + }; + } + } +})(); diff --git a/src/organization-list/organization-list.html b/src/organization-list/organization-list.html new file mode 100644 index 0000000..e5f615a --- /dev/null +++ b/src/organization-list/organization-list.html @@ -0,0 +1,7 @@ +

{{'organizationList.pageHeader' | message}}

+
+ + +
diff --git a/src/organization-list/organization-list.module.js b/src/organization-list/organization-list.module.js new file mode 100644 index 0000000..030d0db --- /dev/null +++ b/src/organization-list/organization-list.module.js @@ -0,0 +1,38 @@ +/* + * 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 organization-list + * + * @description + * Provides a view for the list of organizations. + */ + angular.module('organization-list', [ + 'openlmis-table', + 'openlmis-admin', + 'openlmis-cached-repository', + 'openlmis-pagination', + 'openlmis-rights', + 'ui.router', + 'openlmis-state-tracker', + 'openlmis-uuid', + 'openlmis-table' + ]); + +})(); diff --git a/src/organization-list/organization-list.routes.js b/src/organization-list/organization-list.routes.js new file mode 100644 index 0000000..e16140f --- /dev/null +++ b/src/organization-list/organization-list.routes.js @@ -0,0 +1,48 @@ +/* + * 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('organization-list').config(routes); + + routes.$inject = ['$stateProvider', 'ADMINISTRATION_RIGHTS']; + + function routes($stateProvider, ADMINISTRATION_RIGHTS) { + + $stateProvider.state('openlmis.administration.organizations', { + showInNavigation: true, + label: 'organizationList.navRoute', + url: '/organizations?page&size&name&sort', + controller: 'OrganizationListController', + templateUrl: 'organization-list/organization-list.html', + controllerAs: 'vm', + accessRights: [ADMINISTRATION_RIGHTS.STOCK_ORGANIZATIONS_MANAGE], + resolve: { + organizationsData: function(organizationService, $stateParams) { + return organizationService.getOrganizations($stateParams) + .then(function(response) { + return response; + }) + .catch(function(error) { + throw new Error('Error while fetching organizations: ' + error); + }); + } + } + }); + } + +})(); diff --git a/src/organization-list/organization-service.js b/src/organization-list/organization-service.js new file mode 100644 index 0000000..340e989 --- /dev/null +++ b/src/organization-list/organization-service.js @@ -0,0 +1,102 @@ +/* + * 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 service + * @name organization-list.organizationService + * + * @description + * Responsible for retrieving organizations from the server. + */ + angular + .module('organization-list') + .service('organizationService', service); + + service.$inject = ['$resource', 'referencedataUrlFactory']; + + function service($resource, referencedataUrlFactory) { + var resource = $resource(referencedataUrlFactory('/api/organizations/:id'), {}, { + getOrganizations: { + url: referencedataUrlFactory('/api/organizations'), + method: 'GET', + isArray: true + }, + createNewOrganization: { + url: referencedataUrlFactory('/api/organizations'), + method: 'POST' + }, + updateOrganization: { + method: 'PUT' + } + }); + + return { + getOrganizations: getOrganizations, + createNewOrganization: createNewOrganization, + updateOrganization: updateOrganization + }; + + /** + * @ngdoc method + * @name organization-list.organizationService + * @methodOf organization-list.organizationService + * + * @description + * Retrieves organizations from the server. + */ + function getOrganizations(searchParams) { + return resource.getOrganizations(searchParams).$promise; + } + + /** + * @ngdoc method + * @name organization-list.organizationService + * @methodOf organization-list.organizationService + * + * @description + * Creates a new organization. + * + * @param {Object} organization The organization to create. + * + * @returns {Promise} A promise that will be resolved with the created organization. + */ + function createNewOrganization(organization) { + return resource.createNewOrganization(null, organization).$promise; + } + + /** + * @ngdoc method + * @name organization-list.organizationService + * @methodOf organization-list.organizationService + * + * @description + * Updates an organization. + * + * @param {Object} organization The organization to update. + * + * @returns {Promise} A promise that will be resolved with the updated organization. + */ + function updateOrganization(organization) { + return resource.updateOrganization({ + id: organization.id + }, organization).$promise; + } + + } +})();