Commit 6593650a authored by julienmege's avatar julienmege

Report fix(actormapping): have member list show REST API results

Added a search property in member object for select box to refer
to it when checking member search validity.

Relates to [BS-15793](https://bonitasoft.atlassian.net/browse/BS-15793)
parent c6a44e39
......@@ -74,19 +74,23 @@
.value('roleIdAttribute', 'role_id').service('MappingService', function(i18nService, userIdAttribute, groupIdAttribute, roleIdAttribute, userAPI, groupAPI, roleAPI, MAPPING_PROFILES, store) {
var mappingService = {};
/* jshint camelcase: false */
mappingService.labelFormatter = {
var groupAndRoleFormatter = function groupAndRoleFormatter(currentMember) {
var member = currentMember[groupIdAttribute] || currentMember;
member = angular.copy(member, {});
member.listLabel = member.buttonLabel = member.displayName;
member.contentToSearch = member.name + ' ' + member.displayName + ' ' + member.description;
return member;
};
mappingService.formatToSelectBox = {
USER: function(currentMember) {
var member = currentMember[userIdAttribute] || currentMember;
return member.firstname + ' ' + member.lastname;
},
GROUP: function(currentMember) {
var member = currentMember[groupIdAttribute] || currentMember;
return member.displayName;
},
ROLE: function(currentMember) {
var member = currentMember[roleIdAttribute] || currentMember;
return member.displayName;
member = angular.copy(member, {});
member.listLabel = member.buttonLabel = member.firstname + ' ' + member.lastname;
member.contentToSearch = member.firstname + ' ' + member.lastname + ' ' + member.userName + ' ' + member.job_title;
return member;
},
GROUP: groupAndRoleFormatter,
ROLE: groupAndRoleFormatter,
MEMBERSHIP: function(currentMember) {
return i18nService.getKey('processDetails.actors.memberships.item.label', {
group: currentMember[groupIdAttribute].displayName,
......@@ -131,7 +135,7 @@
d: searchMemberParams.deploy
}).then(function success(members) {
members.forEach(function(currentMember) {
currentMember.label = mappingService.labelFormatter[type](currentMember);
currentMember.label = mappingService.formatToSelectBox[type](currentMember).listLabel;
});
if (type !== MAPPING_PROFILES.MEMBERSHIP) {
members.forEach(function(member) {
......
......@@ -9,6 +9,7 @@
max-height="200px"
translation="localLang"
on-search-change="actorsCtrl.search(data)"
search-property="contentToSearch"
on-clear="actorsCtrl.search({})"
on-reset="actorsCtrl.search({})"
selection-mode="{{actorsCtrl.selectionMode}}"></isteven-multi-select>
......@@ -76,10 +76,8 @@
.then(function (results) {
vm.members = _.chain(results).filter(function (currentMember) {
return $scope.alreadyMappedActorsIds.indexOf(currentMember.id) === -1;
}).forEach(function (currentMember) {
currentMember.listLabel = MappingService.labelFormatter[type](currentMember);
currentMember.buttonLabel = currentMember.listLabel;
}).value();
}).map(MappingService.formatToSelectBox[type]).value();
// isteven-multi-select filter input-model on search term but bonita search API search with a logical OR
// when there are space in search term. We need to re-apply search term in order to make input model consistent
// with mutli-select internal model
......@@ -95,7 +93,7 @@
vm.search({});
vm.ensureKeywordMatchesEntries = function (keyword, members) {
return members.filter(function (member) {
return member.listLabel.match(new RegExp(keyword, 'i'));
return member.contentToSearch.match(new RegExp(keyword, 'i'));
});
};
......
......@@ -73,20 +73,24 @@
.value('groupIdAttribute', 'group_id')
.value('roleIdAttribute', 'role_id').service('MappingService', function(i18nService, userIdAttribute, groupIdAttribute, roleIdAttribute, userAPI, groupAPI, roleAPI, MAPPING_PROFILES, store) {
var mappingService = {};
var groupAndRolFormatter = function groupAndRolFormatter(currentMember) {
var member = currentMember[groupIdAttribute] || currentMember;
member = angular.copy(member, {});
member.listLabel = member.buttonLabel = member.displayName;
member.contentToSearch = member.name + ' ' + member.displayName + ' ' + member.description;
return member;
};
/* jshint camelcase: false */
mappingService.labelFormatter = {
USER: function(currentMember) {
mappingService.formatToSelectBox = {
USER: function (currentMember) {
var member = currentMember[userIdAttribute] || currentMember;
return member.firstname + ' ' + member.lastname;
},
GROUP: function(currentMember) {
var member = currentMember[groupIdAttribute] || currentMember;
return member.displayName;
},
ROLE: function(currentMember) {
var member = currentMember[roleIdAttribute] || currentMember;
return member.displayName;
member = angular.copy(member, {});
member.listLabel = member.buttonLabel = member.firstname + ' ' + member.lastname;
member.contentToSearch = member.firstname + ' ' + member.lastname + ' ' + member.userName + ' ' + member.job_title;
return member;
},
GROUP: groupAndRolFormatter,
ROLE: groupAndRolFormatter,
MEMBERSHIP: function(currentMember) {
return i18nService.getKey('processDetails.actors.memberships.item.label', {
group: currentMember[groupIdAttribute].displayName,
......@@ -131,7 +135,7 @@
d: searchMemberParams.deploy
}).then(function success(members) {
members.forEach(function(currentMember) {
currentMember.label = mappingService.labelFormatter[type](currentMember);
currentMember.label = mappingService.formatToSelectBox[type](currentMember).listLabel;
});
if (type !== MAPPING_PROFILES.MEMBERSHIP) {
members.forEach(function(member) {
......
......@@ -30,32 +30,49 @@ describe('mapping-commons', function () {
spyOn(i18nService, 'getKey').and.callThrough();
spyOn(store, 'load');
}));
describe('labelFormatter', function () {
describe('formatToSelectBox', function () {
it('for a user, should return "firstname lastname"', function () {
var content = {
displayName: 'Acme',
firstname: 'walter',
lastname: 'bates'
lastname: 'bates',
'job_title': 'CEO',
userName: 'walter.bates'
};
expect(mappingService.labelFormatter.USER({
'user_id': content
})).toEqual('walter bates');
expect(mappingService.labelFormatter.USER(content)).toEqual('walter bates');
let member = mappingService.formatToSelectBox.USER({'user_id': content});
expect(member.buttonLabel).toEqual('walter bates');
expect(member.contentToSearch).toEqual('walter bates walter.bates CEO');
expect(member.listLabel).toEqual('walter bates');
member = mappingService.formatToSelectBox.USER(content);
expect(member.buttonLabel).toEqual('walter bates');
expect(member.contentToSearch).toEqual('walter bates walter.bates CEO');
expect(member.listLabel).toEqual('walter bates');
});
it('for a group and role, should return the displayName', function () {
var content = {
displayName: 'Acme',
name: 'local',
description: 'Bonita role',
firstname: 'walter',
lastname: 'bates'
};
expect(mappingService.labelFormatter.GROUP({
'group_id': content
})).toEqual('Acme');
expect(mappingService.labelFormatter.GROUP(content)).toEqual('Acme');
expect(mappingService.labelFormatter.ROLE({
'role_id': content
})).toEqual('Acme');
expect(mappingService.labelFormatter.ROLE(content)).toEqual('Acme');
let member = mappingService.formatToSelectBox.GROUP({'group_id': content});
expect(member.buttonLabel).toEqual('Acme');
expect(member.listLabel).toEqual('Acme');
expect(member.contentToSearch).toEqual('local Acme Bonita role');
member = mappingService.formatToSelectBox.GROUP(content);
expect(member.buttonLabel).toEqual('Acme');
expect(member.listLabel).toEqual('Acme');
expect(member.contentToSearch).toEqual('local Acme Bonita role');
member = mappingService.formatToSelectBox.ROLE({'group_id': content});
expect(member.buttonLabel).toEqual('Acme');
expect(member.listLabel).toEqual('Acme');
expect(member.contentToSearch).toEqual('local Acme Bonita role');
member = mappingService.formatToSelectBox.ROLE(content);
expect(member.buttonLabel).toEqual('Acme');
expect(member.listLabel).toEqual('Acme');
expect(member.contentToSearch).toEqual('local Acme Bonita role');
});
it('for a membership, should return "member of role"', function () {
var groupContent = {
......@@ -64,7 +81,7 @@ describe('mapping-commons', function () {
roleContent = {
displayName: 'Member'
};
expect(mappingService.labelFormatter.MEMBERSHIP({
expect(mappingService.formatToSelectBox.MEMBERSHIP({
'role_id': roleContent,
'group_id': groupContent
})).toEqual('Member of Acme');
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment