Skip to content

Commit

Permalink
Merge pull request #648 from apruden/roles-sort
Browse files Browse the repository at this point in the history
preserve order in micaConfig roles
  • Loading branch information
ymarcon committed Nov 27, 2015
2 parents 4d60631 + a531381 commit 405a8b4
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public class MicaConfig extends AbstractAuditableDocument {

private AggregationsConfig aggregations;

private Set<String> roles = Sets.newHashSet(Membership.CONTACT, Membership.INVESTIGATOR);
private List<String> roles = Lists.newArrayList(Membership.CONTACT, Membership.INVESTIGATOR);

private String publicUrl;

Expand Down Expand Up @@ -147,11 +147,11 @@ public void setPrivacyThreshold(int privacyThreshold) {
this.privacyThreshold = privacyThreshold;
}

public Set<String> getRoles() {
public List<String> getRoles() {
return roles;
}

public void setRoles(Set<String> roles) {
this.roles = roles == null ? Sets.newHashSet() : roles;
public void setRoles(List<String> roles) {
this.roles = roles == null ? Lists.newArrayList() : Lists.newArrayList(Sets.newLinkedHashSet(roles));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ MicaConfig fromDto(@NotNull Mica.MicaConfigDtoOrBuilder dto) {
if (dto.hasPrivacyThreshold()) config.setPrivacyThreshold(dto.getPrivacyThreshold());

if(dto.getRolesCount() > 0) {
config.setRoles(Sets.newHashSet(dto.getRolesList()));
config.setRoles(dto.getRolesList());
}

return config;
Expand Down
13 changes: 9 additions & 4 deletions mica-webapp/src/main/webapp/app/config/config-controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,9 @@ mica.config
templateUrl: 'app/config/views/config-roles-modal-form.html',
controller: 'RoleModalController',
resolve: {
micaConfig: function() {
return $scope.micaConfig;
},
role: function () {
return null;
}
Expand Down Expand Up @@ -269,16 +272,18 @@ mica.config
};
}])

.controller('RoleModalController', ['$scope', '$modalInstance', '$log', 'role',
function ($scope, $modalInstance, $log, role) {
.controller('RoleModalController', ['$scope', '$modalInstance', '$log', 'micaConfig', 'role',
function ($scope, $modalInstance, $log, micaConfig, role) {
var oldRole = role;
$scope.role = {id: role};
$log.debug('Modal Ctrl scope:', $scope.role);

$scope.save = function (form) {
form.id.$setValidity('text', micaConfig.roles.indexOf($scope.role.id) < 0 || $scope.role.id === oldRole);

if (form.$valid) {
$modalInstance.close($scope.role.id);
}
else {
} else {
$scope.form = form;
$scope.form.saveAttempted = true;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
<div class="modal-content">

<form name="form" role="form" novalidate
class="ng-scope ng-invalid ng-invalid-required ng-dirty ng-valid-minlength" ng-submit="save(form)">

<form name="form" role="form" novalidate ng-submit="save(form)">
<div class="modal-header">
<button type="button" class="close" aria-hidden="true" ng-click="cancel()">&times;</button>
<h4 class="modal-title" id="configRoleModal">
Expand All @@ -11,7 +9,8 @@ <h4 class="modal-title" id="configRoleModal">
</div>

<div class="modal-body">
<p class="alert alert-danger" ng-show="form.saveAttempted && form.$invalid" translate="">fix-error</p>
<p class="alert alert-danger" ng-show="form.saveAttempted && form.id.$error.text" translate>
config.role-error</p>
<div form-input name="id" model="role.id" label="id" required="true"></div>
</div>

Expand Down
3 changes: 2 additions & 1 deletion mica-webapp/src/main/webapp/i18n/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,8 @@
"roles": "Roles",
"roles-help": "List of available roles for studies and networks.",
"add-role": "Add Role",
"edit-role": "Edit Role"
"edit-role": "Edit Role",
"role-error": "Role id already exists."
},
"publish": {
"label": "Publish",
Expand Down

0 comments on commit 405a8b4

Please sign in to comment.