Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SELV3-782: Added Reports Management Page in Administration #52

Merged
merged 1 commit into from
Jan 8, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
5.6.15-SNAPSHOT / wip
==================
New functionality:
* [SELV3-782](https://openlmis.atlassian.net/browse/SELV3-782): Added Reports Management Page in Administration

5.6.14 / 2024-12-17
==================
Expand Down
136 changes: 136 additions & 0 deletions src/admin-report-category-add/admin-report-category-add.controller.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
/*
* 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-report-category-add.controller:adminReportCategoryAddController
*
* @description
* Allows user to add new report category
*/
angular
.module('admin-report-category-add')
.controller('adminReportCategoryAddController', adminReportCategoryAddController);

adminReportCategoryAddController.$inject = ['reportCategoryService', 'loadingModalService', '$state',
'notificationService', 'reportCategory', 'stateTrackerService'];

function adminReportCategoryAddController(reportCategoryService, loadingModalService, $state,
notificationService, reportCategory, stateTrackerService) {

var vm = this;
vm.$onInit = onInit;

vm.add = add;
vm.validateField = validateField;
vm.invalidFields = new Set();

/**
* @ngdoc method
* @methodOf admin-report-category-add.controller:adminReportCategoryAddController
* @name goToPreviousState
*
* @description
* Helper for using previous state from view layer
*/
vm.goToPreviousState = stateTrackerService.goToPreviousState;

/**
* @ngdoc property
* @methodOf admin-report-category-add.controller:adminReportCategoryAddController
* @name editMode
* @type {boolean}
*
* @description
* Indicates if report category type is already created.
*/
vm.editMode = undefined;

/**
* @ngdoc property
* @methodOf admin-report-category-add.controller:adminReportCategoryAddController
* @name reportCategory
* @type {Object}
*
* @description
* Current report category
*/
vm.reportCategory = undefined;

/**
* @ngdoc method
* @methodOf admin-report-category-add.controller:adminReportCategoryAddController
* @name $onInit
*
* @description
* Method that is executed on initiating adminReportCategoryAddController.
*/
function onInit() {
vm.reportCategory = reportCategory;
vm.editMode = !!vm.reportCategory;
}

function add() {
loadingModalService.open();

if (validateAddReport()) {
getSavePromise()
.then(function() {
notificationService.success('adminReportCategoryAdd.success');
$state.go('openlmis.administration.adminReportsCategoriesList', {}, {
reload: true
});
})
.catch(function() {
notificationService.error('adminReportCategoryAdd.error');
loadingModalService.close();
});
} else {
loadingModalService.close();
}
}

function getSavePromise() {
return vm.editMode ?
reportCategoryService.update(vm.reportCategory) :
reportCategoryService.create(vm.reportCategory);
}

function validateAddReport() {
var fieldsToValidate = ['name'];
fieldsToValidate.forEach(function(fieldName) {
validateField(vm.reportCategory[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);
}
}
}
})();
32 changes: 32 additions & 0 deletions src/admin-report-category-add/admin-report-category-add.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<div class="modal" role="dialog" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<h2 ng-if="!vm.editMode">{{:: 'adminReportCategoryAdd.titleAdd' | message}}</h2>
<h2 ng-if="vm.editMode">{{:: 'adminReportCategoryAdd.titleEdit' | message}}</h2>
</div>
<div class="modal-body">
<form id="addReport">
<fieldset class="form-group">
<label for="name" class="is-required">{{:: 'adminReportCategoryAdd.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.reportCategory.name"
ng-change="vm.validateField(vm.reportCategory.name, 'name')" required />
</div>
<ul class="openlmis-invalid" ng-if="vm.invalidFields.has('name')">
<li>{{'adminReportCategoryAdd.fieldRequired' | message}}</li>
</ul>
</fieldset>
</form>
</div>
<div class="modal-footer">
<button id="cancel" ng-click="vm.goToPreviousState()">
{{:: 'adminReportCategoryAdd.cancel' | message}}
</button>
<button class="primary" ng-click="vm.add()">{{vm.editMode ? 'adminReportCategoryAdd.save' :
'adminReportCategoryAdd.add' | message}}</button>

</div>
</div>
</div>
</div>
34 changes: 34 additions & 0 deletions src/admin-report-category-add/admin-report-category-add.module.js
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 info@OpenLMIS.org. 
*/

(function() {
'use strict';

/**
* @module admin-report-category-add
*
* @description
* Responsible for add reports screen.
*/
angular.module('admin-report-category-add', [
'ngResource',
'openlmis-i18n',
'openlmis-rights',
'openlmis-urls',
'openlmis-permissions',
'openlmis-pagination',
'ui.router'
]);
})();
43 changes: 43 additions & 0 deletions src/admin-report-category-add/admin-report-category-add.routes.js
Original file line number Diff line number Diff line change
@@ -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-report-category-add')
.config(routes);

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

function routes(modalStateProvider, ADMINISTRATION_RIGHTS) {
modalStateProvider.state('openlmis.administration.adminReportsCategoriesList.add', {
url: '/add/:id',
label: 'adminReportCategoryAdd.title',
controller: 'adminReportCategoryAddController',
controllerAs: 'vm',
templateUrl: 'admin-report-category-add/admin-report-category-add.html',
accessRights: [ADMINISTRATION_RIGHTS.REPORT_CATEGORIES_MANAGE],
resolve: {
reportCategory: function($stateParams, reportCategoryService) {
if ($stateParams.id) {
return reportCategoryService.get($stateParams.id);
}
return undefined;
}
}
});
}
})();
11 changes: 11 additions & 0 deletions src/admin-report-category-add/messages_en.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"adminReportCategoryAdd.titleAdd": "Add Report Category",
"adminReportCategoryAdd.titleEdit": "Edit Report Category",
"adminReportCategoryAdd.name": "Name",
"adminReportCategoryAdd.add": "Add",
"adminReportCategoryAdd.save": "Save",
"adminReportCategoryAdd.cancel": "Cancel",
"adminReportCategoryAdd.fieldRequired": "This field is required",
"adminReportCategoryAdd.success": "Rreport category created successfully",
"adminReportCategoryAdd.error": "Failed to create report category"
}
Loading
Loading