Skip to content

Commit

Permalink
chore(payroll): Unify the interfaces for rubric configuration
Browse files Browse the repository at this point in the history
Uses a unified interface for the rubric configuration service.
  • Loading branch information
jniles committed Dec 31, 2024
1 parent 0178404 commit 221dc67
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 127 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,6 @@ angular.module('bhima.routes')
},
onEnter : ['$uibModal', '$transition$', configurationRubric],
onExit : ['$uibModalStack', closeModal],
})

.state('configurationRubric.config', {
url : '/:id/config',
params : {
id : { value : null },
},
onEnter : ['$uibModal', '$transition$', configurationRubric],
onExit : ['$uibModalStack', closeModal],
});
}]);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,38 +1,15 @@
angular.module('bhima.services')
.service('ConfigurationService', ConfigurationService);

ConfigurationService.$inject = ['PrototypeApiService', '$http', 'util'];
ConfigurationService.$inject = ['PrototypeApiService'];

/**
* @class ConfigurationService
* @extends PrototypeApiService
*
* @description
* Encapsulates common requests to the /rubric_config/ URL.
* Encapsulates common requests to the payroll /rubric_config/ URL.
*/
function ConfigurationService(Api, $http, util) {
const service = new Api('/rubric_config/');

service.getRubrics = getRubrics;
service.setRubrics = setRubrics;

// loads the configuration's rubrics
function getRubrics(id) {
if (angular.isUndefined(id)) {
throw new Error(
'Trying to get configuration of rubrics without the identity property',
);
}

return $http.get(`/rubric_config/${id}/setting`)
.then(util.unwrapHttpResponse);
}

// Sets Payroll Rubric's Configuration using the public API
function setRubrics(id, data) {
return $http.post(`/rubric_config/${id}/setting`, { configuration : data })
.then(util.unwrapHttpResponse);
}

return service;
function ConfigurationService(Api) {
return new Api('/payroll/rubric_config/');
}
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,9 @@ function RubricConfigModalController($state, Configs, Notify, AppCache, Rubrics,
$q.all([
Configs.read(vm.stateParams.id),
Rubrics.read(),
Configs.getRubrics(vm.stateParams.id),
])
.then(([config, rubrics, rubConfig]) => {
console.log('config:', config);
.then(([config, rubrics]) => {
vm.config = config;

vm.rubrics = rubrics;

// TODO(@jniles): why do we have a different classifcation of rubrics here?
Expand All @@ -65,7 +62,7 @@ function RubricConfigModalController($state, Configs, Notify, AppCache, Rubrics,
vm.membershipFee = rubrics.filter(Rubrics.isMembershipFeeRubric);
vm.others = rubrics.filter(Rubrics.isOtherRubric);

const rubConfigMap = rubConfig.reduce((map, c) => {
const rubConfigMap = vm.config.items.reduce((map, c) => {
map[c.rubric_payroll_id] = true;
return map;
}, {});
Expand Down Expand Up @@ -149,9 +146,19 @@ function RubricConfigModalController($state, Configs, Notify, AppCache, Rubrics,
});
});

return Configs.setRubrics(vm.stateParams.id, rubricChecked)
const data = {
items : rubricChecked,
label : vm.config.label,
};

const promise = vm.isCreateState ? Configs.create(data) : Configs.update(vm.stateParams.id, data);
return promise
.then(() => {
Notify.success('FORM.INFO.UPDATE_SUCCESS');
if (vm.isCreateState) {
Notify.success('FORM.INFO.CREATE_SUCCESS');
} else {
Notify.success('FORM.INFO.UPDATE_SUCCESS');
}
$state.go('configurationRubric', null, { reload : true });
})
.catch(Notify.handleError);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,6 @@
<i class="fa fa-edit"></i> <span translate>FORM.BUTTONS.EDIT</span>
</a>
</li>
<li>
<a data-method="configure" ui-sref="configurationRubric.config({id : row.entity.id})" href>
<i class="fa fa-cog"></i> <span translate>FORM.BUTTONS.CONFIGURE</span>
</a>
</li>
<li class="divider"></li>
<li>
<a data-method="delete-record" ng-click="grid.appScope.deleteConfig(row.entity)" href>
Expand Down
79 changes: 0 additions & 79 deletions test/client-unit/services/rubricsConfigurationService.spec.js

This file was deleted.

0 comments on commit 221dc67

Please sign in to comment.