Added filtering capability on user page.

This commit is contained in:
Mattias Hellborg Arthursson
2013-11-08 11:11:57 +01:00
parent aa81fcb9f2
commit 889d4a73ff
6 changed files with 38 additions and 6 deletions

View File

@@ -25,5 +25,5 @@ import java.util.List;
*/
public interface UserRepo extends LdapRepository<User> {
User findByEmployeeNumber(int employeeNumber);
List<User> findByLastName(String lastName);
List<User> findByFullNameContains(String name);
}

View File

@@ -31,6 +31,7 @@ import org.springframework.ldap.support.LdapUtils;
import javax.naming.Name;
import javax.naming.ldap.LdapName;
import java.util.Collection;
import java.util.List;
import java.util.Set;
/**
@@ -186,4 +187,8 @@ public class UserService implements BaseLdapNameAware {
groupRepo.save(group);
}
}
public List<User> searchByNameName(String lastName) {
return userRepo.findByFullNameContains(lastName);
}
}

View File

@@ -24,8 +24,10 @@ import org.springframework.ldap.samples.useradmin.domain.User;
import org.springframework.ldap.samples.useradmin.service.UserService;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import java.util.List;
import java.util.Map;
@@ -49,8 +51,12 @@ public class UserController {
private DepartmentRepo departmentRepo;
@RequestMapping(value = {"/", "/users"}, method = GET)
public String index(ModelMap map) {
map.put("users", userService.findAll());
public String index(ModelMap map, @RequestParam(required = false) String name) {
if(StringUtils.hasText(name)) {
map.put("users", userService.searchByNameName(name));
} else {
map.put("users", userService.findAll());
}
return "listUsers";
}
@@ -74,7 +80,7 @@ public class UserController {
}
private void populateDepartments(ModelMap map) throws JsonProcessingException {
Map<String,List<String>> departmentMap = departmentRepo.getDepartmentMap();
Map<String, List<String>> departmentMap = departmentRepo.getDepartmentMap();
ObjectMapper objectMapper = new ObjectMapper();
String departmentsAsJson = objectMapper.writeValueAsString(departmentMap);
map.put("departments", departmentsAsJson);

View File

@@ -1,6 +1,7 @@
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<html>
<head>
<title>Spring LDAP User Admin</title>
<link rel="icon" type="image/x-icon" href="<c:url value='/resources/img/favicon.png'/>" />
<link href="<c:url value='/resources/bootstrap/css/bootstrap.min.css'/>" rel="stylesheet" />
<link href="<c:url value='/resources/css/default.css'/>" rel="stylesheet" />
@@ -29,7 +30,7 @@
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="#">Spring LDAP User Admin</a>
<a class="navbar-brand" href="http://projects.spring.io/spring-ldap/">Spring LDAP</a>
</div>
<div class="collapse navbar-collapse">
<ul class="nav navbar-nav">

View File

@@ -3,7 +3,23 @@
<div class="container">
<div class="main-body item-list">
<h2>User List</h2>
<div class="row">
<div class="col-md-2">
<h2>Users</h2>
</div>
<div class="col-md-10">
<form method="GET" role="form">
<div class="row search-form">
<div class="col-md-offset-6 col-md-4">
<input type="text" class="form-control" id="name" name="name"/>
</div>
<div class="col-md-1">
<button type="submit" class="btn btn-default">Filter</button>
</div>
</div>
</form>
</div>
</div>
<c:forEach var="user" items="${users}" varStatus="stat">
<div class="row row-${stat.index % 2}">
<div class="col-md-11">${user.fullName} - ${user.department}&nbsp;</div>

View File

@@ -10,6 +10,10 @@ body {
padding-top: 10px;
}
.search-form {
padding-top: 20px;
}
.item-list {
width: 600px;
}