Skip to content

Commit

Permalink
Fixed User Group Dashboard
Browse files Browse the repository at this point in the history
  • Loading branch information
ericfeldmann committed May 2, 2014
1 parent c288bbc commit 04fe7da
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 106 deletions.
51 changes: 2 additions & 49 deletions app/scripts/controllers/user_group_detail.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,13 @@ angular.module('vinzApp')
$scope.userGroup = userGroups.getUserGroup(userGroupId);

$scope.access = {has:true, message: "Revoke"};
$scope.maintain = {title: "Servers", inGroupYesLabel: "In Group", inGroupNoLabel: "Not In Group"};
$scope.maintain = {title: "Users", inGroupYesLabel: "In Group", inGroupNoLabel: "Not In Group"};
$scope.action = {buttonClass: "danger", message: "Remove"};
$scope.inGroupYes = true;

// caseId = 0 => users in group
// caseId = 1 => users not in group
// caseId = 2 => servers with access to group
// caseId = 3 => servers without access to group
// caseId = 4 => servergroups with access to group
// caseId = 5 => servergroups without access to group
$scope.shownInTable = function(caseId) {
if (!$scope.inGroupYes && caseId % 2 == 0) {
caseId++;
}

$scope.caseId = caseId;

Expand All @@ -31,17 +24,9 @@ angular.module('vinzApp')
}

if (caseId == 0 || caseId == 1) {
$scope.maintain.title = "Servers";
$scope.maintain.title = "Users";
$scope.maintain.inGroupNoLabel = "Not In Group";
$scope.maintain.inGroupYesLabel = "In Group";
} else if (caseId == 2 || caseId == 3) {
$scope.maintain.title = "Users";
$scope.maintain.inGroupNoLabel = "No Access";
$scope.maintain.inGroupYesLabel = "Has Access";
} else {
$scope.maintain.title = "User Groups";
$scope.maintain.inGroupNoLabel = "No Access";
$scope.maintain.inGroupYesLabel = "Has Access";
}

switch(caseId)
Expand All @@ -54,22 +39,6 @@ angular.module('vinzApp')
$scope.myUsers = userGroups.getNonGroupUsers(userGroupId);
$scope.action.message = "Add";
break;
case 2:
$scope.myServers = userGroups.getUserGroupServers(userGroupId);
$scope.action.message = "Revoke";
break;
case 3:
$scope.myServers = userGroups.getNonUserGroupServers(userGroupId);
$scope.action.message = "Grant";
break;
case 4:
$scope.myServerGroups = userGroups.getUserGroupServerGroups(userGroupId);
$scope.action.message = "Revoke";
break;
case 5:
$scope.myServerGroups = userGroups.getNonUserGroupServerGroups(userGroupId);
$scope.action.message = "Grant";
break;
}
}

Expand Down Expand Up @@ -99,22 +68,6 @@ angular.module('vinzApp')
removeFromArray($scope.myUsers, id, 'id');
userGroups.addUserToGroup(userGroupId, id);
break;
case 2:
removeFromArray($scope.myServers, id, 'id');
userGroups.revokeServerAccessToGroup(userGroupId, id);
break;
case 3:
removeFromArray($scope.myServers, id, 'id');
userGroups.grantServerAccessToGroup(userGroupId, id);
break;
case 4:
removeFromArray($scope.myServerGroups, id, 'id');
userGroups.revokeServerGroupAccessToGroup(userGroupId, id);
break;
case 5:
removeFromArray($scope.myServerGroups, id, 'id');
userGroups.grantServerGroupAccessToGroup(userGroupId, id);
break;
}
}

Expand Down
30 changes: 2 additions & 28 deletions app/scripts/services/user_groups.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ angular.module('vinzApp')
createUserGroup: function(newUserGroup) {
$http.post(userGroupsURL, newUserGroup);
},
getUserServers: function(userGroupId) {
return UserServer.query({id: userGroupId});
getGroupUsers: function(userGroupId) {
return GroupUser.query({id: userGroupId});
},
getNonGroupUsers: function(userGroupId) {
return GroupUser.query({id: userGroupId, not_in_group: true});
Expand All @@ -40,32 +40,6 @@ angular.module('vinzApp')
addUserToGroup: function(userGroupId, userId) {
var groupUsersAPI = userGroupsURL + userGroupId + '/users/';
$http.post(groupUsersAPI, {user_id: userId});
},
getUserGroupServer: function(userGroupId) {
return GroupServer.query({id: userGroupId});
},
getNonUserGroupServers: function(userGroupId) {
return GroupServer.query({id: userGroupId, no_access: true});
},
revokeServerAccessToGroup: function(userGroupId, serverId) {
GroupServer.remove({id: userGroupId, server_id: serverId});
},
grantServerAccessToGroup: function(userGroupId, serverId) {
var groupServersAPI = userGroupsURL + userGroupId + '/servers/';
$http.post(groupServersAPI, {server_id: serverId});
},
getUserGroupServerGroups: function(userGroupId) {
return GroupServerGroup.query({id: userGroupId});
},
getNonUserGroupServerGroups: function(userGroupId) {
return GroupServerGroup.query({id: userGroupId, no_access: true});
},
revokeServerGroupAccessToGroup: function(userGroupId, serverGroupId) {
GroupServerGroup.remove({id: userGroupId, server_group_id: serverGroupId});
},
grantServerGroupAccessToGroup: function(userGroupId, serverGroupId) {
var groupServerGroupsAPI = userGroupsURL + userGroupId + '/servergroups/';
$http.post(groupServerGroupsAPI, {server_group_id: serverGroupId});
}
};
});
45 changes: 16 additions & 29 deletions app/views/user_group_detail.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<div class="col-sm-12 sectionTitle sectionBannerTitle">
User Group Dashboard
</div>
<a class="btn btn-default backButton" href="#/user_groups/">
<a class="btn btn-default backButton" href="/user_groups/">
<i class="fa fa-chevron-left"></i> All Groups
</a>
</div>
Expand All @@ -19,49 +19,41 @@
</tbody>
</table>

<!-- Section Header -->
<!-- Table Header -->
<div class="row sectionBanner">
<div class="col-xs-2 sectionBody">
<div class="btn-group btn-input clearfix">
<button type="button" class="btn btn-default dropdown-toggle form-control" data-toggle="dropdown">
<span data-bind="label">Users</span> <span class="caret"></span>
</button>
<ul class="dropdown-menu" role="menu">
<li><a href="#">Server</a></li>
<li><a href="#">Server Groups</a></li>
</ul>
</div>
<div class="col-xs-2 sectionTitle">
Users
</div>
<div class="row sectionBody col-xs-offset-2 col-xs-8">
<div class="btn-group col-xs-6" data-toggle="buttons">
<label class="btn btn-default active">
<input id="showAccess" type="radio" name="access" checked="checked"> Access
<input id="inGroupYes" type="radio" name="access" checked="checked"> In Group
</label>
<label class="btn btn-default">
<input type="radio" name="access"> No Access
<input id="inGroupNo" type="radio" name="access"> Not In Group
</label>
</div>
<div class="col-xs-6 right-inner-addon">
<input ng-model="serverSearch" type="text" class="form-control" placeholder="Search">
<input ng-model="search" type="text" class="form-control" placeholder="Search">
<i class="fa fa-search"></i>
</div>
</div>
</div>

<!-- User Servers -->
<table class="userTable table table-hover table-striped table-bordered">
<!-- UserGroup Users Table -->
<table id="users" class="userTable table table-hover table-striped table-bordered">
<thead>
<tr>
<th>Name</th>
<th>Hostname</th>
<th>Access</th>
<th>Email</th>
<th>Group</th>
</tr>
</thead>
<tbody>
<tr ng-repeat="server in serversToDisplayUnderUser | filter:serverSearch">
<td>{{server.name}}</td>
<td>{{server.hostname}}</td>
<td class="col-sm-2"><div ng-click="toggleAccess(server);" class="btn userInfoBtn" ng-class="{ 'btn-danger': access.has, 'btn-success': !access.has }">{{access.message}}</div></td>
<tr ng-repeat="user in myUsers | filter:search">
<td>{{user.first_name}} {{user.last_name}}</td>
<td>{{user.email}}</td>
<td class="col-sm-2"><button ng-click="switchSides(user.id);" class="serverInfoBtn btn btn-{{action.buttonClass}}">{{action.message}}</button></td>
</tr>
</tbody>
</table>
Expand All @@ -70,19 +62,14 @@
<script type="text/javascript">
$(function() {
var scope = angular.element($("#vinzApp")).scope();
var $showAccess = $("#showAccess");

$(".navbar-nav li").removeClass("active");
$("#users-nav").addClass("active");

//This should be doable with angular, but I couldn't get it to.
$('input:radio[name="access"]').change(function() {
scope.$apply(function() {
if ($showAccess.is(':checked')) {
scope.showHasAccess(true);
} else {
scope.showHasAccess(false);
}
scope.toggleInGroup();
});
});
});
Expand Down

0 comments on commit 04fe7da

Please sign in to comment.