Skip to content

Commit

Permalink
Merge pull request #275 from compucorp/CIWEMB-435-multi-scoring
Browse files Browse the repository at this point in the history
CIWEMB-435: Allow using multiple review custom groups
  • Loading branch information
omarabuhussein authored Nov 13, 2023
2 parents 6d1fff9 + e21ceb4 commit 32c411d
Show file tree
Hide file tree
Showing 9 changed files with 103 additions and 70 deletions.
1 change: 1 addition & 0 deletions ang/civiawards-base.ang.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,5 +46,6 @@ function get_awards_base_js_files() {
'settings' => $options,
'requires' => [
'civicase-base',
'api4',
],
];
1 change: 1 addition & 0 deletions ang/civiawards.ang.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ function get_awards_js_files() {
0 => 'css/civiawards.min.css',
],
'requires' => [
'api4',
'crmUi',
'crmUtil',
'ngRoute',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
<thead>
<tr>
<th>Review Field Name</th>
<th>Field Set</th>
<th>Enabled</th>
<th>Data Type</th>
<th>Field Type</th>
Expand All @@ -28,6 +29,7 @@
ng-repeat="reviewField in model.reviewFields | filter: model.searchText"
ng-click="model.toggleReviewField(reviewField)">
<td>{{reviewField.label}}</td>
<td>{{reviewField['api.CustomGroup.getvalue']}}</td>
<td align="center">
<input
ng-checked="!!model.findReviewFieldByID(reviewField.id)"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
<thead>
<tr>
<th>Review Field Name</th>
<th>Field Set</th>
<th>Order</th>
<th width="20">Required</th>
<th>Data Type</th>
Expand All @@ -27,6 +28,7 @@
ng-repeat="reviewField in additionalDetails.selectedReviewFields | orderBy: 'weight'"
ng-if="additionalDetails.selectedReviewFields.length > 0">
<td>{{getReviewFieldData(reviewField.id, 'label')}}</td>
<td>{{getReviewFieldData(reviewField.id, 'api.CustomGroup.getvalue')}}</td>
<td>
<a
class="crm-weight-arrow" ng-if="$index > 0"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@
});

module.controller('CiviawardReviewFieldsTableController', function (
$rootScope, $scope, civicaseCrmApi, dialogService, ts,
reviewScoringFieldsGroupName, isTruthy) {
$rootScope, $scope, civicaseCrmApi, dialogService, ts, isTruthy, crmApi4) {
$scope.reviewFields = [];
$scope.resourcesBaseUrl = CRM.config.resourceBase;
$scope.toggleReviewField = toggleReviewField;
Expand All @@ -26,10 +25,7 @@
$scope.getReviewFieldData = getReviewFieldData;

(function init () {
fetchAllReviewFields()
.then(function (reviewFields) {
$scope.reviewFields = reviewFields;
});
assignAllReviewFields();

$rootScope.$on('civiawards::edit-award::details-fetched', setDetails);
}());
Expand Down Expand Up @@ -197,17 +193,31 @@
}

/**
* Fetch All Review Fields
* Fetch And assign all Review Fields
*
* @returns {Promise} promise containing all review fields
*/
function fetchAllReviewFields () {
return civicaseCrmApi([['CustomField', 'get', {
sequential: true,
custom_group_id: reviewScoringFieldsGroupName,
options: { limit: 0 }
}]]).then(function (customFieldData) {
return customFieldData[0].values;
function assignAllReviewFields () {
crmApi4('CustomGroup', 'get', {
select: ['name'],
join: [['OptionValue AS option_value', 'INNER', ['extends_entity_column_value', '=', 'option_value.value']]],
where: [['extends', '=', 'Activity'], ['option_value.option_group_id:name', '=', 'activity_type'], ['option_value.name', '=', 'Applicant Review']]
}).then(function (customGroups) {
if (customGroups.length === 0) {
return [];
}

var applicantReviewCustomGroups = customGroups.map(function (customGroup) {
return customGroup.name;
});

return civicaseCrmApi([['CustomField', 'get', {
sequential: true,
custom_group_id: { IN: applicantReviewCustomGroups },
options: { limit: 0 },
'api.CustomGroup.getvalue': { id: '$value.custom_group_id', return: 'title' }
}]]);
}).then(function (customFields) {
$scope.reviewFields = customFields[0].values;
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,15 @@
* @param {object} $sce angular Strict Contextual Escaping service.
* @param {Function} civicaseCrmApi the CiviCRM API service.
* @param {string} reviewsActivityTypeName the reviews activity type name.
* @param {string} reviewScoringFieldsGroupName the review scoring fields group name.
* @param {Function} ts the translation function.
* @param {Function} crmStatus crm status service
* @param {Function} civicaseCrmUrl civicrm url service
* @param {Function} civicaseCrmLoadForm service to load civicrm forms
* @param {Function} crmApi4 access to CiviCRM API v4
*/
function civiawardsReviewsCaseTabContentController ($q, $scope, $sce,
civicaseCrmApi, reviewsActivityTypeName, reviewScoringFieldsGroupName, ts,
crmStatus, civicaseCrmUrl, civicaseCrmLoadForm) {
civicaseCrmApi, reviewsActivityTypeName, ts,
crmStatus, civicaseCrmUrl, civicaseCrmLoadForm, crmApi4) {
var CRM_FORM_LOAD_EVENT = 'crmFormLoad';
var CRM_FORM_SUCCESS_EVENT = 'crmFormSuccess.crmPopup crmPopupFormSuccess.crmPopup';
var REVIEW_FORM_URL = 'civicrm/awardreview';
Expand Down Expand Up @@ -68,24 +68,33 @@
* @returns {Promise} resolves after fetching the reviews.
*/
function getReviewActivities () {
return civicaseCrmApi('Activity', 'get', {
activity_type_id: reviewsActivityTypeName,
case_id: $scope.caseItem.id,
options: { limit: 0 },
sequential: 1,
'api.OptionValue.getsingle': {
option_group_id: 'activity_status',
value: '$value.status_id'
},
'api.CustomValue.gettreevalues': {
entity_id: '$value.id',
entity_type: 'Activity',
'custom_group.name': reviewScoringFieldsGroupName
}
})
.then(function (response) {
return response.values;
return crmApi4('CustomGroup', 'get', {
select: ['name'],
join: [['OptionValue AS option_value', 'INNER', ['extends_entity_column_value', '=', 'option_value.value']]],
where: [['extends', '=', 'Activity'], ['option_value.option_group_id:name', '=', 'activity_type'], ['option_value.name', '=', 'Applicant Review']]
}).then(function (customGroups) {
var applicantReviewCustomGroups = customGroups.map(function (customGroup) {
return customGroup.name;
});

return civicaseCrmApi('Activity', 'get', {
activity_type_id: reviewsActivityTypeName,
case_id: $scope.caseItem.id,
options: { limit: 0 },
sequential: 1,
'api.OptionValue.getsingle': {
option_group_id: 'activity_status',
value: '$value.status_id'
},
'api.CustomValue.gettreevalues': {
entity_id: '$value.id',
entity_type: 'Activity',
'custom_group.name': { IN: applicantReviewCustomGroups }
}
});
}).then(function (response) {
return response.values;
});
}

/**
Expand All @@ -110,9 +119,21 @@
var sortOrder = _.sortBy(scoringFieldsSortOrder, 'weight');

return _.map(angular.copy(activitiesData), function (activity) {
var applicantReviewFields = {};
activity['api.CustomValue.gettreevalues'].values.map(function (fieldSet) {
Object.keys(fieldSet.fields).forEach(function (key) {
var field = fieldSet.fields[key];
var newKey = key + field.id;
fieldSet.fields[newKey] = Object.assign({ id: field.id }, field);
delete fieldSet.fields[key];
});

applicantReviewFields = Object.assign(applicantReviewFields, fieldSet.fields);
});

activity.status_label = activity['api.OptionValue.getsingle'].label;
activity.reviewFields = sortOrder.map(function (scoringFieldSortOrder) {
return _.find(activity['api.CustomValue.gettreevalues'].values[0].fields, function (field) {
return _.find(applicantReviewFields, function (field) {
return field.id === scoringFieldSortOrder.id;
});
});
Expand Down
3 changes: 1 addition & 2 deletions ang/civiawards/shared/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,5 @@
var module = angular.module('civiawards');

module
.constant('reviewsActivityTypeName', 'Applicant Review')
.constant('reviewScoringFieldsGroupName', 'Applicant_Review');
.constant('reviewsActivityTypeName', 'Applicant Review');
})(angular);
Original file line number Diff line number Diff line change
@@ -1,19 +1,21 @@
(function (_) {
describe('civiawardReviewFieldsTable', () => {
var $rootScope, $controller, $scope, $q, civicaseCrmApi, ReviewFieldsMockData,
AwardAdditionalDetailsMockData, dialogService;
AwardAdditionalDetailsMockData, dialogService, crmApi4;

beforeEach(module('civiawards.templates', 'civiawards', 'civicase.data', 'civiawards.data', function ($provide) {
$provide.value('civicaseCrmApi', jasmine.createSpy('civicaseCrmApi'));
$provide.value('crmApi4', jasmine.createSpy('crmApi4'));
$provide.value('dialogService', jasmine.createSpyObj('dialogService', ['open', 'close']));
}));

beforeEach(inject((_$q_, _$controller_, _$rootScope_, _civicaseCrmApi_,
_ReviewFieldsMockData_, _AwardAdditionalDetailsMockData_, _dialogService_) => {
_ReviewFieldsMockData_, _AwardAdditionalDetailsMockData_, _dialogService_, _crmApi4_) => {
$q = _$q_;
$controller = _$controller_;
$rootScope = _$rootScope_;
dialogService = _dialogService_;
crmApi4 = _crmApi4_;
civicaseCrmApi = _civicaseCrmApi_;
ReviewFieldsMockData = _ReviewFieldsMockData_;
AwardAdditionalDetailsMockData = _AwardAdditionalDetailsMockData_.get();
Expand All @@ -23,6 +25,9 @@
civicaseCrmApi.and.returnValue($q.resolve([
{ values: ReviewFieldsMockData }
]));
crmApi4.and.returnValue($q.resolve([
{ values: ReviewFieldsMockData }
]));

$scope.$digest();
}));
Expand All @@ -34,11 +39,11 @@
});

it('fetches all review fields', () => {
expect(civicaseCrmApi).toHaveBeenCalledWith([['CustomField', 'get', {
sequential: true,
custom_group_id: 'Applicant_Review',
options: { limit: 0 }
}]]);
expect(crmApi4).toHaveBeenCalledWith('CustomGroup', 'get', {
select: ['name'],
join: [['OptionValue AS option_value', 'INNER', ['extends_entity_column_value', '=', 'option_value.value']]],
where: [['extends', '=', 'Activity'], ['option_value.option_group_id:name', '=', 'activity_type'], ['option_value.name', '=', 'Applicant Review']]
});
});

it('displays all review fields', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@
describe('Review Case Tab Content', () => {
let $controller, $q, $rootScope, $scope, AwardAdditionalDetailsMockData,
caseItem, civicaseCrmApi, ReviewActivitiesMockData, ReviewFieldsMockData,
reviewsActivityTypeName, reviewScoringFieldsGroupName, crmStatus,
civicaseCrmUrl, civicaseCrmLoadForm;
crmStatus, civicaseCrmUrl, civicaseCrmLoadForm, crmApi4;
const entityActionHandlers = {
'Activity.get': activityGetHandler,
'AwardDetail.getsingle': awardDetailGetSingleHandler,
Expand All @@ -12,29 +11,32 @@

beforeEach(module('civiawards', 'civiawards.data', ($provide) => {
civicaseCrmApi = getCrmApiMock();

$provide.value('civicaseCrmApi', civicaseCrmApi);

$provide.value('crmApi4', jasmine.createSpy('crmApi4'));
}));

beforeEach(inject((_$controller_, _$q_, _$rootScope_, _ApplicationsMockData_,
_AwardAdditionalDetailsMockData_, _ReviewActivitiesMockData_, _ReviewFieldsMockData_,
_reviewsActivityTypeName_, _reviewScoringFieldsGroupName_, _crmStatus_,
_civicaseCrmUrl_, _civicaseCrmLoadForm_) => {
_crmStatus_,
_civicaseCrmUrl_, _civicaseCrmLoadForm_, _crmApi4_) => {
$controller = _$controller_;
$q = _$q_;
$rootScope = _$rootScope_;
crmStatus = _crmStatus_;
AwardAdditionalDetailsMockData = _AwardAdditionalDetailsMockData_;
ReviewActivitiesMockData = _ReviewActivitiesMockData_;
ReviewFieldsMockData = _ReviewFieldsMockData_;
reviewsActivityTypeName = _reviewsActivityTypeName_;
reviewScoringFieldsGroupName = _reviewScoringFieldsGroupName_;
civicaseCrmUrl = _civicaseCrmUrl_;
crmApi4 = _crmApi4_;
civicaseCrmLoadForm = _civicaseCrmLoadForm_;

caseItem = _.first(_ApplicationsMockData_);
$scope = $rootScope.$new();
$scope.caseItem = caseItem;
crmApi4.and.returnValue($q.resolve([
{ values: [{ name: 'Applicant_Review' }] }
]));

initController({ $scope });
}));
Expand All @@ -50,21 +52,11 @@
});
});

it('requests all review activities for the application', () => {
expect(civicaseCrmApi).toHaveBeenCalledWith('Activity', 'get', {
activity_type_id: reviewsActivityTypeName,
case_id: $scope.caseItem.id,
options: { limit: 0 },
sequential: 1,
'api.OptionValue.getsingle': {
option_group_id: 'activity_status',
value: '$value.status_id'
},
'api.CustomValue.gettreevalues': {
entity_id: '$value.id',
entity_type: 'Activity',
'custom_group.name': reviewScoringFieldsGroupName
}
it('fetches all review fields', () => {
expect(crmApi4).toHaveBeenCalledWith('CustomGroup', 'get', {
select: ['name'],
join: [['OptionValue AS option_value', 'INNER', ['extends_entity_column_value', '=', 'option_value.value']]],
where: [['extends', '=', 'Activity'], ['option_value.option_group_id:name', '=', 'activity_type'], ['option_value.name', '=', 'Applicant Review']]
});
});

Expand Down Expand Up @@ -119,7 +111,7 @@
});

it('reloads the list of reviews', () => {
expect(civicaseCrmApi).toHaveBeenCalledWith('Activity', 'get', jasmine.any(Object));
expect(crmApi4).toHaveBeenCalledWith('CustomGroup', 'get', jasmine.any(Object));
});
});

Expand Down Expand Up @@ -162,7 +154,7 @@
});

it('reloads the reviews', () => {
expect(civicaseCrmApi).toHaveBeenCalledWith('Activity', 'get', jasmine.any(Object));
expect(crmApi4).toHaveBeenCalledWith('CustomGroup', 'get', jasmine.any(Object));
});
});
});
Expand Down Expand Up @@ -206,7 +198,7 @@
});

it('reloads the reviews', () => {
expect(civicaseCrmApi).toHaveBeenCalledWith('Activity', 'get', jasmine.any(Object));
expect(crmApi4).toHaveBeenCalledWith('CustomGroup', 'get', jasmine.any(Object));
});
});
});
Expand Down

0 comments on commit 32c411d

Please sign in to comment.