nav ui fixes

This commit is contained in:
Bill Burke 2013-08-04 19:33:25 -04:00
parent d11876f58e
commit fb45fcc5fd
9 changed files with 131 additions and 62 deletions

View file

@ -4,6 +4,7 @@ var module = angular.module('keycloak.controllers', [ 'keycloak.services' ]);
var realmslist = {}; var realmslist = {};
module.controller('GlobalCtrl', function($scope, $http, Auth, $location, Notifications) { module.controller('GlobalCtrl', function($scope, $http, Auth, $location, Notifications) {
$scope.addMessage = function() { $scope.addMessage = function() {
Notifications.success("test"); Notifications.success("test");
@ -152,20 +153,30 @@ module.controller('ApplicationDetailCtrl', function($scope, application, Applica
}); });
module.controller('RealmListCtrl', function($scope, Realm) { module.controller('RealmListCtrl', function($scope, Realm, Current) {
$scope.realms = Realm.get(); $scope.realms = Realm.get();
realmslist = $scope.realms; Current.realms = $scope.realms;
}); });
module.controller('RealmDropdownCtrl', function($scope, Realm) { module.controller('RealmDropdownCtrl', function($scope, Realm, Current, $location) {
console.log('test log writing'); console.log('test log writing');
realmslist = Realm.get(); Current.realms = Realm.get();
$scope.realmslist = function() { $scope.current = Current;
return realmslist; $scope.changeRealm = function() {
console.log('select box changed');
for (var id in Current.realms) {
var val = Current.realms[id];
console.log('checking: ' + val);
if (val == Current.realm) {
console.log("redirect to: /realms/" + id);
$location.url("/realms/" + id);
break;
}
}
}; };
}); });
module.controller('RealmDetailCtrl', function($scope, Realm, realm, $location, Dialog, Notifications) { module.controller('RealmDetailCtrl', function($scope, Current, Realm, realm, $location, Dialog, Notifications) {
$scope.realm = angular.copy(realm); $scope.realm = angular.copy(realm);
$scope.createRealm = !realm.id; $scope.createRealm = !realm.id;
@ -260,13 +271,21 @@ module.controller('RealmDetailCtrl', function($scope, Realm, realm, $location, D
Realm.save(realmCopy, function(data, headers) { Realm.save(realmCopy, function(data, headers) {
var l = headers().location; var l = headers().location;
var id = l.substring(l.lastIndexOf("/") + 1); var id = l.substring(l.lastIndexOf("/") + 1);
realmslist = Realm.get();
$location.url("/realms/" + id); var data = Realm.get(function() {
Current.realms = data;
Current.realm = Current.realms[id];
console.log('Current.realms[id]: ' + Current.realms[id]);
console.log('data[id]: ' + data[id]);
console.log('Current.realm.name: ' + Current.realm.name);
});
$location.url("/realms/" + id);
Notifications.success("Created realm"); Notifications.success("Created realm");
}); });
} else { } else {
Realm.update(realmCopy, function() { Realm.update(realmCopy, function() {
realmslist = Realm.get(); Current.realms = Realm.get();
$scope.changed = false; $scope.changed = false;
realm = angular.copy($scope.realm); realm = angular.copy($scope.realm);
Notifications.success("Saved changes to realm"); Notifications.success("Saved changes to realm");
@ -290,7 +309,7 @@ module.controller('RealmDetailCtrl', function($scope, Realm, realm, $location, D
$scope.remove = function() { $scope.remove = function() {
Dialog.confirmDelete($scope.realm.name, 'realm', function() { Dialog.confirmDelete($scope.realm.name, 'realm', function() {
Realm.remove($scope.realm, function() { Realm.remove($scope.realm, function() {
realmslist = Realm.get(); Current.realms = Realm.get();
$location.url("/realms"); $location.url("/realms");
Notifications.success("Deleted realm"); Notifications.success("Deleted realm");
}); });

View file

@ -158,3 +158,10 @@ module.factory('Role', function($resource) {
} }
}); });
}); });
module.factory('Current', function($resource) {
return {
realm : null,
realms : {}
};
});

View file

@ -3,32 +3,36 @@
<div class="container"> <div class="container">
<div class="nav-collapse"> <div class="nav-collapse">
<nav id="global-nav"> <nav id="global-nav">
<div data-ng-controller="RealmDropdownCtrl"> <div data-ng-controller="RealmDropdownCtrl" > <!--
<ul class="nav pull-left" data-ng-show="auth.loggedIn"> <ul class="nav pull-left" data-ng-show="auth.loggedIn">
<li class="dropdown"><a data-toggle="dropdown" class="dropdown-toggle" href="#"> Realms <i class="caret"></i></a> <li class="dropdown"><a data-toggle="dropdown" class="dropdown-toggle" href="#"> Realms <i class="caret"></i></a>
<ul class="dropdown-menu"> <ul class="dropdown-menu">
<li ng-repeat="(id, name) in realmslist()"><a href="#/realms/{{id}}">{{name}}</a> <li ng-repeat="(id, name) in current.realms"><a href="#/realms/{{id}}">{{name}}</a>
</li> </li>
</ul> </ul>
</li> </li>
</ul> </ul> -->
<h3 data-ng-show="auth.loggedIn"><span class="gray pull-left">Realm: </span></h3>
<select class="nav pull-left" data-ng-show="auth.loggedIn" ng-change="changeRealm()" ng-model="current.realm" ng-options="name for (id, name) in current.realms">
</select>
<!-- <select class="nav pull-left" ng-options="r.name for r in current.realms"></select> -->
</div> </div>
<ul class="nav">
<li class="divider-vertical-left" data-ng-class="path[0] == 'realms' && 'active'"
data-ng-show="auth.loggedIn"><a href="#/create/realm">New Realm</a></li>
</ul>
<ul class="nav pull-right" data-ng-hide="auth.loggedIn"> <ul class="nav pull-right" data-ng-hide="auth.loggedIn">
<li><a href="/auth-server/saas/saas-login.jsp">Login</a></li> <li><a href="/auth-server/saas/saas-login.jsp">Login</a></li>
<li><a href="/auth-server/saas/saas-register.jsp">Register</a></li> <li><a href="/auth-server/saas/saas-register.jsp">Register</a></li>
</ul> </ul>
<ul class="nav pull-right" data-ng-show="auth.loggedIn"> <ul class="nav pull-right" data-ng-show="auth.loggedIn">
<li class="dropdown"><a data-toggle="dropdown" class="dropdown-toggle" href="#"><i <li class="divider-vertical-left dropdown"><a data-toggle="dropdown" class="dropdown-toggle" href="#"><i
class="icon-user icon-gray"></i> Welcome: <b>{{auth.user.displayName}}</b> <i class="caret"></i></a> class="icon-user icon-gray"></i> Welcome: <b>{{auth.user.displayName}}</b> <i class="caret"></i></a>
<ul class="dropdown-menu"> <ul class="dropdown-menu">
<li><a href="/auth-server/rest/saas/logout">Sign Out</a></li> <li><a href="/auth-server/rest/saas/logout">Sign Out</a></li>
</ul> </ul>
</li> </li>
</ul> </ul>
<ul class="nav pull-right" data-ng-show="auth.loggedIn">
<li class="divider-vertical-left" data-ng-class="path[0] == 'realms' && 'active'"
data-ng-show="auth.loggedIn"><a href="#/create/realm">New Realm</a></li>
</ul>
</nav> </nav>
</div> </div>
</div> </div>

View file

@ -7,7 +7,7 @@
<h1 data-ng-show="createRealm"><span class="gray">New Realm</span></h1> <h1 data-ng-show="createRealm"><span class="gray">New Realm</span></h1>
<h1 data-ng-hide="createRealm"> <h1 data-ng-hide="createRealm">
<span class="gray">{{realm.realm}}</span> <span class="gray">Realm Settings</span>
</h1> </h1>
<div data-ng-show="realmForm.showErrors && realmForm.$error.required" class="alert alert-error">Please fill <div data-ng-show="realmForm.showErrors && realmForm.$error.required" class="alert alert-error">Please fill

View file

@ -1,21 +1,11 @@
<div data-ng-hide="createRealm"> <div data-ng-hide="createRealm">
<nav id="local-nav"> <nav id="local-nav">
<ul class="nav nav-list"> <ul class="nav nav-list">
<li> <li data-ng-class="!path[2] && 'active'"><a href="#/realms/{{realm.id}}">Realm Settings</a>
<div> </li>
<span class="toggle">Realm: </span> {{realm.realm}} <li data-ng-class="path[2] == 'users' && 'active'"><a href="#/realms/{{realm.id}}/users">Realm Users</a>
</div> </li>
<ul> <li data-ng-class="path[2] == 'roles' && 'active'"><a href="#/realms/{{realm.id}}/roles">Realm Roles</a></li>
<li>
<ul class="sub-items">
<li data-ng-class="!path[2] && 'active'"><a href="#/realms/{{realm.id}}">Settings</a>
</li>
<li data-ng-class="path[2] == 'users' && 'active'"><a href="#/realms/{{realm.id}}/users">Users</a>
</li>
<li data-ng-class="path[2] == 'roles' && 'active'"><a href="#/realms/{{realm.id}}/roles">Roles</a></li>
</ul>
</li>
</ul>
</ul> </ul>
</nav> </nav>
</div> </div>

View file

@ -7,7 +7,7 @@
<h1 data-ng-show="create"><span class="gray">New Role</span></h1> <h1 data-ng-show="create"><span class="gray">New Role</span></h1>
<h1 data-ng-hide="create"> <h1 data-ng-hide="create">
<span class="gray">Role {{role.name}}</span> <span class="gray">Realm Role {{role.name}}</span>
</h1> </h1>
<div data-ng-show="roleForm.showErrors && roleForm.$error.required" class="alert alert-error">Please fill in <div data-ng-show="roleForm.showErrors && roleForm.$error.required" class="alert alert-error">Please fill in

View file

@ -7,7 +7,7 @@
<a class="btn btn-small pull-right" href="#/create/role/{{realm.id}}">Add Role</a> <a class="btn btn-small pull-right" href="#/create/role/{{realm.id}}">Add Role</a>
<h1> <h1>
<span class="gray">{{realm.realm}}</span> roles <span class="gray">Realm Roles</span>
</h1> </h1>
<table class="table table-striped table-bordered"> <table class="table table-striped table-bordered">

View file

@ -0,0 +1,69 @@
package org.keycloak.services.resources.admin;
import org.jboss.resteasy.annotations.cache.NoCache;
import org.jboss.resteasy.logging.Logger;
import org.keycloak.representations.idm.ResourceRepresentation;
import org.keycloak.services.managers.RealmManager;
import org.keycloak.services.managers.ResourceManager;
import org.keycloak.services.models.RealmModel;
import org.keycloak.services.models.ResourceModel;
import org.keycloak.services.models.UserModel;
import org.keycloak.services.resources.Transaction;
import javax.ws.rs.Consumes;
import javax.ws.rs.GET;
import javax.ws.rs.NotFoundException;
import javax.ws.rs.POST;
import javax.ws.rs.PUT;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.UriInfo;
import java.util.ArrayList;
import java.util.List;
/**
* @author <a href="mailto:bill@burkecentral.com">Bill Burke</a>
* @version $Revision: 1 $
*/
public class RealmResourceResource {
protected static final Logger logger = Logger.getLogger(RealmAdminResource.class);
protected UserModel admin;
protected RealmModel realm;
protected ResourceModel resourceModel;
public RealmResourceResource(UserModel admin, RealmModel realm, ResourceModel resourceModel) {
this.admin = admin;
this.realm = realm;
this.resourceModel = resourceModel;
}
@PUT
@Consumes(MediaType.APPLICATION_JSON)
public void update(final ResourceRepresentation rep) {
new Transaction() {
@Override
protected void runImpl() {
ResourceManager resourceManager = new ResourceManager(new RealmManager(session));
resourceManager.updateResource(rep, resourceModel);
}
}.run();
}
@GET
@NoCache
@Produces(MediaType.APPLICATION_JSON)
public ResourceRepresentation getResource(final @PathParam("id") String id) {
return new Transaction() {
@Override
protected ResourceRepresentation callImpl() {
ResourceManager resourceManager = new ResourceManager(new RealmManager(session));
return resourceManager.toRepresentation(resourceModel);
}
}.call();
}
}

View file

@ -71,38 +71,18 @@ public class RealmResourcesResource {
} }
@Path("{id}") @Path("{id}")
@PUT public RealmResourceResource getResource(final @PathParam("id") String id) {
@Consumes(MediaType.APPLICATION_JSON)
public void update(final @PathParam("id") String id, final ResourceRepresentation rep) {
new Transaction() {
@Override
protected void runImpl() {
ResourceModel resourceModel = realm.getResourceById(id);
if (resourceModel == null) {
throw new NotFoundException();
}
ResourceManager resourceManager = new ResourceManager(new RealmManager(session));
resourceManager.updateResource(rep, resourceModel);
}
}.run();
}
@Path("{id}")
@GET
@NoCache
@Produces(MediaType.APPLICATION_JSON)
public ResourceRepresentation getResource(final @PathParam("id") String id) {
return new Transaction() { return new Transaction() {
@Override @Override
protected ResourceRepresentation callImpl() { protected RealmResourceResource callImpl() {
ResourceModel resourceModel = realm.getResourceById(id); ResourceModel resourceModel = realm.getResourceById(id);
if (resourceModel == null) { if (resourceModel == null) {
throw new NotFoundException(); throw new NotFoundException();
} }
ResourceManager resourceManager = new ResourceManager(new RealmManager(session)); return new RealmResourceResource(admin, realm, resourceModel);
return resourceManager.toRepresentation(resourceModel);
} }
}.call(); }.call();
} }
} }