Skip to content

Commit

Permalink
ANGOLASUP-859: Add whole functionality to embedded report categories.
Browse files Browse the repository at this point in the history
  • Loading branch information
mdulko committed Jun 5, 2024
1 parent 4517ce8 commit 4d3400b
Show file tree
Hide file tree
Showing 16 changed files with 507 additions and 13 deletions.
5 changes: 3 additions & 2 deletions src/report-embedded-add/report-embedded-add.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,9 @@
if (validateAddReport()) {
reportEmbeddedService.add(vm.report)
.then(function() {
loadingModalService.close();
$state.reload('openlmis.administration.embeddedReportsList');
$state.go('openlmis.administration.embeddedReportsList', {}, {
reload: true
});
});
} else {
loadingModalService.close();
Expand Down
2 changes: 1 addition & 1 deletion src/report-embedded-add/report-embedded-add.html
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ <h2>{{:: 'adminReportAdd.title' | message}}</h2>
</ul>
</fieldset>
<fieldset class="form-group">
<label for="enabled" class="is-required">
<label for="enabled">
<input id="enabled" type="checkbox" ng-model="vm.report.enabled"/>
{{:: 'adminReportAdd.enabled' | message}}
</label>
Expand Down
7 changes: 7 additions & 0 deletions src/report-embedded-category-add/messages_en.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"adminEmbeddedReportCategoryAdd.title": "Add Embedded Report Category",
"adminEmbeddedReportCategoryAdd.name": "Name",
"adminEmbeddedReportCategoryAdd.add": "Add",
"adminEmbeddedReportCategoryAdd.cancel": "Cancel",
"adminEmbeddedReportCategoryAdd.fieldRequired": "This field is required"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
/*
* 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 report-embedded-category-add.controller:ReportEmbeddedCategoryAddController
*
* @description
* Allows user to add new embedded report category
*/
angular
.module('report-embedded-category-add')
.controller('ReportEmbeddedCategoryAddController', ReportEmbeddedCategoryAddController);

ReportEmbeddedCategoryAddController.$inject = ['reportEmbeddedService', 'loadingModalService', '$state'];

function ReportEmbeddedCategoryAddController(reportEmbeddedService, loadingModalService, $state) {
var vm = this;

vm.goBack = goBack;
vm.add = add;
vm.validateField = validateField;
vm.invalidFields = new Set();
vm.category = {};

function add() {
loadingModalService.open();

if (validateAddReport()) {
reportEmbeddedService.addReportCategory(vm.category)
.then(function() {
$state.go('openlmis.administration.embeddedReportsCategoriesList', {}, {
reload: true
});
});
} else {
loadingModalService.close();
}
}

function goBack() {
window.history.back();
}

function validateAddReport() {
var fieldsToValidate = ['name'];
fieldsToValidate.forEach(function(fieldName) {
validateField(vm.category[fieldName], fieldName);
});

return vm.invalidFields.size === 0;
}

function isNotEmpty(value) {
return !!value;
}

function validateField(value, fieldName) {
var isValid = isNotEmpty(value);

if (vm.invalidFields.has(fieldName) && isValid) {
vm.invalidFields.delete(fieldName);
} else if (!isValid) {
vm.invalidFields.add(fieldName);
}
}
}
})();
42 changes: 42 additions & 0 deletions src/report-embedded-category-add/report-embedded-category-add.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<div class="modal" role="dialog" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<h2>{{:: 'adminEmbeddedReportCategoryAdd.title' | message}}</h2>
</div>
<div class="modal-body">
<form id="addReport">
<fieldset class="form-group">
<label for="name" class="is-required"
>{{:: 'adminEmbeddedReportCategoryAdd.name' | message}}</label
>
<div
class="input-control"
ng-class="{'is-invalid': vm.invalidFields.has('name')}"
>
<input
type="text"
id="name"
style="width: 100%"
ng-model="vm.category.name"
ng-change="vm.validateField(vm.category.name, 'name')"
required
/>
</div>
<ul class="openlmis-invalid" ng-if="vm.invalidFields.has('name')">
<li>{{'adminEmbeddedReportCategoryAdd.fieldRequired' | message}}</li>
</ul>
</fieldset>
</form>
</div>
<div class="modal-footer">
<button id="cancel" ng-click="vm.goBack()">
{{:: 'adminEmbeddedReportCategoryAdd.cancel' | message}}
</button>
<button class="primary" ng-click="vm.add()">
{{:: 'adminEmbeddedReportCategoryAdd.add' | message}}
</button>
</div>
</div>
</div>
</div>
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/*
* 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';

/**
* @module report-embedded-category-add
*
* @description
* Responsible for add reports screen.
*/
angular.module('report-embedded-category-add', [
'ngResource',
'openlmis-i18n',
'openlmis-rights',
'openlmis-urls',
'openlmis-permissions',
'openlmis-pagination',
'ui.router'
]);
})();
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/*
* 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';

angular
.module('report-embedded-category-add')
.config(routes);

routes.$inject = ['$stateProvider', 'modalStateProvider'];

function routes($stateProvider, modalStateProvider) {
modalStateProvider.state('openlmis.administration.embeddedReportsCategoriesList.add', {
url: '/add',
label: 'adminEmbeddedReportCategoryAdd.title',
controller: 'ReportEmbeddedCategoryAddController',
controllerAs: 'vm',
templateUrl: 'report-embedded-category-add/report-embedded-category-add.html'
});
}
})();
17 changes: 17 additions & 0 deletions src/report-embedded-category-list/messages_en.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"reportEmbeddedCategoriesList.navRoute": "Embedded Report Categories",
"reportEmbeddedCategoriesList.pageHeader": "Embedded Report Categories",
"reportEmbeddedCategoriesList.noEmbeddedReport": "No Embedded Report Categories found.",
"reportEmbeddedCategoriesList.filter.name": "Name",
"reportEmbeddedCategoriesList.column.name": "Name",
"reportEmbeddedCategoriesList.column.category": "Category",
"reportEmbeddedCategoriesList.column.enabled": "Enabled",
"reportEmbeddedCategoriesList.column.actions": "Actions",
"reportEmbeddedCategoriesList.action.edit": "Edit",
"reportEmbeddedCategoriesList.action.delete": "Delete",
"reportEmbeddedCategoriesList.addEmbeddedReport": "Add Category",
"reportEmbeddedCategoriesList.deleteReport.question": "Are you sure you want to remove ${categoryName} category?",
"reportEmbeddedCategoriesList.delete": "Delete",
"reportEmbeddedCategoriesList.deleteReport.success": "Embedded report category deleted successfully",
"reportEmbeddedCategoriesList.deleteReport.fail": "Failed to delete embedded report category"
}
Loading

0 comments on commit 4d3400b

Please sign in to comment.