From fa4fcd3ccd2cf334039d0c57ebca351c27eab579 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aleksandra=20So=C5=82tys?= Date: Tue, 16 Jul 2024 10:38:04 +0200 Subject: [PATCH] AO-870: Create a UI module to manage mailing list for facility syncho report (#151) * AO-870: Added component to manage integration emails * AO-870: added correct url, little corrections * wip * AO-870: Changed url * AO-870: Added one-time bindings --------- Co-authored-by: Jan --- .../admin-integration-email-add.controller.js | 148 ++++++++++++++++++ .../admin-integration-email-add.html | 19 +++ .../admin-integration-email-add.module.js | 35 +++++ .../admin-integration-email-add.routes.js | 43 +++++ .../messages_en.json | 13 ++ ...admin-integration-email-list.controller.js | 88 +++++++++++ .../admin-integration-email-list.html | 31 ++++ .../admin-integration-email-list.module.js | 37 +++++ .../admin-integration-email-list.routes.js | 49 ++++++ .../integration-email.service.js | 85 ++++++++++ .../messages_en.json | 13 ++ 11 files changed, 561 insertions(+) create mode 100644 src/admin-integration-email-add/admin-integration-email-add.controller.js create mode 100644 src/admin-integration-email-add/admin-integration-email-add.html create mode 100644 src/admin-integration-email-add/admin-integration-email-add.module.js create mode 100644 src/admin-integration-email-add/admin-integration-email-add.routes.js create mode 100644 src/admin-integration-email-add/messages_en.json create mode 100644 src/admin-integration-email-list/admin-integration-email-list.controller.js create mode 100644 src/admin-integration-email-list/admin-integration-email-list.html create mode 100644 src/admin-integration-email-list/admin-integration-email-list.module.js create mode 100644 src/admin-integration-email-list/admin-integration-email-list.routes.js create mode 100644 src/admin-integration-email-list/integration-email.service.js create mode 100644 src/admin-integration-email-list/messages_en.json diff --git a/src/admin-integration-email-add/admin-integration-email-add.controller.js b/src/admin-integration-email-add/admin-integration-email-add.controller.js new file mode 100644 index 0000000..55f42dd --- /dev/null +++ b/src/admin-integration-email-add/admin-integration-email-add.controller.js @@ -0,0 +1,148 @@ +/* + * 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-integration-email-add.controller:AdminIntegrationEmailAddController + * + * @description + * Controller for integration email add screen. + */ + angular + .module('admin-integration-email-add') + .controller('AdminIntegrationEmailAddController', AdminIntegrationEmailAddController); + + AdminIntegrationEmailAddController.$inject = [ + '$state', '$stateParams', 'email', 'FunctionDecorator', 'integrationEmailService' + ]; + + function AdminIntegrationEmailAddController($state, $stateParams, email, FunctionDecorator, + integrationEmailService) { + + var vm = this; + + vm.$onInit = onInit; + vm.saveEmail = saveEmail; + vm.goToEmailList = goToEmailList; + + /** + * @ngdoc property + * @propertyOf admin-integration-email-add.controller:AdminIntegrationEmailAddController + * @name email + * @type {Object} + * + * @description + * Holds email that will be created. + */ + vm.email = undefined; + + /** + * @ngdoc property + * @propertyOf admin-integration-email-add.controller:AdminIntegrationEmailAddController + * @name successNotificationKey + * @type {String} + * + * @description + * Holds successNotificationKey message. + */ + vm.successNotificationKey = email ? 'adminIntegrationEmailAdd.save.success' : + 'adminIntegrationEmailAdd.create.success'; + + /** + * @ngdoc property + * @propertyOf admin-integration-email-add.controller:AdminIntegrationEmailAddController + * @name errorNotificationKey + * @type {String} + * + * @description + * Holds errorNotificationKey message. + */ + vm.errorNotificationKey = email ? 'adminIntegrationEmailAdd.save.failure' : + 'adminIntegrationEmailAdd.create.failure'; + + /** + * @ngdoc property + * @propertyOf admin-integration-email-add.controller:AdminIntegrationEmailAddController + * @name modalHeaderKey + * @type {String} + * + * @description + * Holds modalHeaderKey message. + */ + vm.modalHeaderKey = email ? 'adminIntegrationEmailAdd.editEmail' : + 'adminIntegrationEmailAdd.addEmail'; + + /** + * @ngdoc property + * @methodOf admin-integration-email-add.controller:AdminIntegrationEmailAddController + * @name onInit + * + * @description + * Initialization method for AdminIntegrationEmailAddController. + */ + function onInit() { + vm.email = email; + vm.saveEmail = new FunctionDecorator() + .decorateFunction(saveEmail) + .withSuccessNotification(vm.successNotificationKey) + .withErrorNotification(vm.errorNotificationKey) + .withConfirm('adminIntegrationEmailAdd.confirm') + .withLoading(true) + .getDecoratedFunction(); + } + + /** + * @ngdoc method + * @methodOf admin-integration-email-add.controller:AdminIntegrationEmailAddController + * @name save + * + * @description + * Saves the email address. + */ + function saveEmail() { + if (email) { + return integrationEmailService + .update(vm.email) + .then(function() { + vm.goToEmailList(); + }); + } + return integrationEmailService + .add(vm.email) + .then(function() { + vm.goToEmailList(); + }); + } + + /** + * @ngdoc property + * @methodOf admin-integration-email-add.controller:AdminIntegrationEmailAddController + * @name goToEmailList + * + * @description + * Redirects user to integration email list screen. + */ + function goToEmailList() { + var stateParams = angular.copy($stateParams); + $state.go('openlmis.administration.adminIntegrationEmailList', stateParams, { + reload: true + }); + } + } +})(); diff --git a/src/admin-integration-email-add/admin-integration-email-add.html b/src/admin-integration-email-add/admin-integration-email-add.html new file mode 100644 index 0000000..33f7eac --- /dev/null +++ b/src/admin-integration-email-add/admin-integration-email-add.html @@ -0,0 +1,19 @@ + diff --git a/src/admin-integration-email-add/admin-integration-email-add.module.js b/src/admin-integration-email-add/admin-integration-email-add.module.js new file mode 100644 index 0000000..7977ffc --- /dev/null +++ b/src/admin-integration-email-add/admin-integration-email-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 admin-integration-email-add + * + * @description + * Provides a modal for adding new integration emails + */ + angular.module('admin-integration-email-add', [ + 'openlmis-function-decorator', + 'openlmis-i18n', + 'ui.router', + 'openlmis-modal', + 'openlmis-state-tracker', + 'openlmis-pagination' + ]); + +})(); diff --git a/src/admin-integration-email-add/admin-integration-email-add.routes.js b/src/admin-integration-email-add/admin-integration-email-add.routes.js new file mode 100644 index 0000000..2d379ef --- /dev/null +++ b/src/admin-integration-email-add/admin-integration-email-add.routes.js @@ -0,0 +1,43 @@ +/* + * 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-integration-email-add') + .config(routes); + + routes.$inject = ['$stateProvider', 'modalStateProvider']; + + function routes($stateProvider, modalStateProvider) { + + modalStateProvider.state('openlmis.administration.adminIntegrationEmailList.add', { + controller: 'AdminIntegrationEmailAddController', + controllerAs: 'vm', + url: '/add/:emailId', + templateUrl: 'admin-integration-email-add/admin-integration-email-add.html', + resolve: { + email: function($stateParams, emails) { + var email = _.findWhere(emails, { + id: $stateParams.emailId + }); + return email; + } + } + }); + } +})(); diff --git a/src/admin-integration-email-add/messages_en.json b/src/admin-integration-email-add/messages_en.json new file mode 100644 index 0000000..bbb5a95 --- /dev/null +++ b/src/admin-integration-email-add/messages_en.json @@ -0,0 +1,13 @@ +{ + "adminIntegrationEmailAdd.addEmail": "Add e-mail", + "adminIntegrationEmailAdd.editEmail": "Edit e-mail", + "adminIntegrationEmailAdd.active": "Active", + "adminIntegrationEmailAdd.emailName": "E-mail Name", + "adminIntegrationEmailAdd.save": "Save", + "adminIntegrationEmailAdd.cancel": "Cancel", + "adminIntegrationEmailAdd.confirm": "Are you sure you want to save e-mail?", + "adminIntegrationEmailAdd.save.success": "E-mail saved successfully", + "adminIntegrationEmailAdd.create.success": "E-mail created successfully", + "adminIntegrationEmailAdd.save.failure": "Failed to save e-mail", + "adminIntegrationEmailAdd.create.failure": "Failed to create e-mial" +} diff --git a/src/admin-integration-email-list/admin-integration-email-list.controller.js b/src/admin-integration-email-list/admin-integration-email-list.controller.js new file mode 100644 index 0000000..990eb79 --- /dev/null +++ b/src/admin-integration-email-list/admin-integration-email-list.controller.js @@ -0,0 +1,88 @@ +/* + * 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-integration-email-list.controller:AdminIntegrationEmailListController + * + * @description + * Controller for managing integration email list. + */ + angular + .module('admin-integration-email-list') + .controller('AdminIntegrationEmailListController', controller); + + controller.$inject = ['$state', '$stateParams', 'emails', 'FunctionDecorator', 'integrationEmailService']; + + function controller($state, $stateParams, emails, FunctionDecorator, integrationEmailService) { + + var vm = this; + vm.$onInit = onInit; + + vm.removeEmail = new FunctionDecorator() + .decorateFunction(removeEmail) + .withSuccessNotification('adminIntegrationEmailList.emailRemovedSuccessfully') + .withErrorNotification('adminIntegrationEmailList.failedToRemoveEmail') + .withConfirm('adminIntegrationEmailList.confirmToRemoveEmail') + .withLoading(true) + .getDecoratedFunction(); + + /** + * @ngdoc property + * @name emails + * @propertyOf admin-integration-email-list.controller:AdminIntegrationEmailListController + * @type {Array} + * + * @description + * Holds list of all integration emials. + */ + vm.emails = undefined; + + /** + * @ngdoc method + * @methodOf admin-integration-email-list.controller:AdminIntegrationEmailListController + * @name $onInit + * + * @description + * Initializes controller + */ + function onInit() { + vm.emails = emails; + } + + /** + * @ngdoc method + * @methodOf admin-integration-email-list.controller:AdminIntegrationEmailListController + * @name removeEmail + * + * @description + * Remove the integration email. + */ + function removeEmail(email) { + return integrationEmailService.remove(email.email.id) + .then(function() { + var stateParams = angular.copy($stateParams); + $state.go('openlmis.administration.adminIntegrationEmailList', stateParams, { + reload: true + }); + }); + } + } + +})(); diff --git a/src/admin-integration-email-list/admin-integration-email-list.html b/src/admin-integration-email-list/admin-integration-email-list.html new file mode 100644 index 0000000..ccbe08d --- /dev/null +++ b/src/admin-integration-email-list/admin-integration-email-list.html @@ -0,0 +1,31 @@ +

{{'adminIntegrationEmailList.header' | message}}

+
+ + + + + + + + + + + + + + + +
+ {{:: 'adminIntegrationEmailList.noEmails' | message}} +
{{:: 'adminIntegrationEmailList.name' | message}}{{:: 'adminIntegrationEmailList.actions' | message}}
{{:: email.email}} + + +
+ +
diff --git a/src/admin-integration-email-list/admin-integration-email-list.module.js b/src/admin-integration-email-list/admin-integration-email-list.module.js new file mode 100644 index 0000000..af87fca --- /dev/null +++ b/src/admin-integration-email-list/admin-integration-email-list.module.js @@ -0,0 +1,37 @@ +/* + * 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-integration-email-list + * + * @description + * Provides integration emails list screen for administrator. + */ + angular.module('admin-integration-email-list', [ + 'openlmis-admin', + 'openlmis-pagination', + 'openlmis-table', + 'openlmis-i18n', + 'openlmis-rights', + 'openlmis-urls', + 'openlmis-permissions', + 'ui.router', + 'openlmis-templates' + ]); +})(); diff --git a/src/admin-integration-email-list/admin-integration-email-list.routes.js b/src/admin-integration-email-list/admin-integration-email-list.routes.js new file mode 100644 index 0000000..d9f9fca --- /dev/null +++ b/src/admin-integration-email-list/admin-integration-email-list.routes.js @@ -0,0 +1,49 @@ +/* + * 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-integration-email-list').config(routes); + + routes.$inject = ['$stateProvider']; + + function routes($stateProvider) { + + $stateProvider.state('openlmis.administration.adminIntegrationEmailList', { + showInNavigation: true, + label: 'adminIntegrationEmailList.integrationEmails', + url: '/integrationEmails?page&size', + controller: 'AdminIntegrationEmailListController', + templateUrl: 'admin-integration-email-list/admin-integration-email-list.html', + controllerAs: 'vm', + resolve: { + emails: function($q, paginationService, integrationEmailService, $stateParams) { + return paginationService.registerUrl($stateParams, function(stateParams) { + var deferred = $q.defer(); + integrationEmailService.getAll({ + page: stateParams.page, + size: stateParams.size + }).then(function(response) { + deferred.resolve(response); + }, deferred.reject); + return deferred.promise; + }); + } + } + }); + } +})(); diff --git a/src/admin-integration-email-list/integration-email.service.js b/src/admin-integration-email-list/integration-email.service.js new file mode 100644 index 0000000..52a72d9 --- /dev/null +++ b/src/admin-integration-email-list/integration-email.service.js @@ -0,0 +1,85 @@ +/* + * 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-integration-email-list') + .factory('integrationEmailService', service); + + service.$inject = ['openlmisUrlFactory', '$resource']; + + function service(openlmisUrlFactory, $resource) { + + var resource = $resource(openlmisUrlFactory('/api/integrationEmails'), {}, { + get: { + method: 'GET', + url: openlmisUrlFactory('/api/integrationEmails/:id') + }, + getAll: { + method: 'GET', + url: openlmisUrlFactory('/api/integrationEmails') + }, + add: { + method: 'POST', + url: openlmisUrlFactory('/api/integrationEmails') + }, + update: { + method: 'PUT', + url: openlmisUrlFactory('/api/integrationEmails/:id') + }, + remove: { + method: 'DELETE', + url: openlmisUrlFactory('/api/integrationEmails/:id') + } + }); + + return { + get: get, + getAll: getAll, + add: add, + update: update, + remove: remove + }; + + function getAll(paginationParams) { + return resource.getAll(paginationParams).$promise; + } + + function get(id) { + return resource.get({ + id: id + }).$promise; + } + + function add(email) { + return resource.add(email).$promise; + } + + function update(email) { + return resource.update({ + id: email.id + }, email).$promise; + } + + function remove(id) { + return resource.remove({ + id: id + }).$promise; + } + } +})(); \ No newline at end of file diff --git a/src/admin-integration-email-list/messages_en.json b/src/admin-integration-email-list/messages_en.json new file mode 100644 index 0000000..6a91352 --- /dev/null +++ b/src/admin-integration-email-list/messages_en.json @@ -0,0 +1,13 @@ +{ + "adminIntegrationEmailList.integrationEmails": "Administrator e-mails", + "adminIntegrationEmailList.header": "Administrator e-mails", + "adminIntegrationEmailList.noEmails": "No e-mails found", + "adminIntegrationEmailList.name": "Name", + "adminIntegrationEmailList.actions": "Actions", + "adminIntegrationEmailList.edit": "Edit", + "adminIntegrationEmailList.addEmail": "Add e-mail", + "adminIntegrationEmailList.delete": "Delete", + "adminIntegrationEmailList.emailRemovedSuccessfully": "Email removed successfully", + "adminIntegrationEmailList.failedToRemoveEmail": "Failed to remove e-mail", + "adminIntegrationEmailList.confirmToRemoveEmail": "Are you sure you want to remove the e-mial?" +}