From d20af96ebb7c088f6c4905704bd1d87914016a8a Mon Sep 17 00:00:00 2001 From: Adam Pardyl Date: Wed, 12 Dec 2018 01:27:23 +0100 Subject: [PATCH 1/7] Implement user list #12 --- .../controllers/admin/UsersController.kt | 32 ++++++++++++++ .../templates/admin/layout_admin.html | 21 ++++++++++ .../resources/templates/admin/user_list.html | 42 +++++++++++++++++++ .../templates/fragments/pagination.html | 27 ++++++++++++ 4 files changed, 122 insertions(+) create mode 100644 src/main/kotlin/pl/edu/uj/ii/ksi/mordor/controllers/admin/UsersController.kt create mode 100644 src/main/resources/templates/admin/layout_admin.html create mode 100644 src/main/resources/templates/admin/user_list.html create mode 100644 src/main/resources/templates/fragments/pagination.html diff --git a/src/main/kotlin/pl/edu/uj/ii/ksi/mordor/controllers/admin/UsersController.kt b/src/main/kotlin/pl/edu/uj/ii/ksi/mordor/controllers/admin/UsersController.kt new file mode 100644 index 0000000..7154e35 --- /dev/null +++ b/src/main/kotlin/pl/edu/uj/ii/ksi/mordor/controllers/admin/UsersController.kt @@ -0,0 +1,32 @@ +package pl.edu.uj.ii.ksi.mordor.controllers.admin + +import org.springframework.data.domain.PageRequest +import org.springframework.security.access.annotation.Secured +import org.springframework.stereotype.Controller +import org.springframework.web.bind.annotation.GetMapping +import org.springframework.web.bind.annotation.PathVariable +import org.springframework.web.servlet.ModelAndView +import org.springframework.web.servlet.View +import org.springframework.web.servlet.view.RedirectView +import pl.edu.uj.ii.ksi.mordor.persistence.entities.Permission +import pl.edu.uj.ii.ksi.mordor.persistence.repositories.UserRepository + +@Controller +class UsersController(private val userRepository: UserRepository) { + companion object { + private const val usersPerPage = 100 + } + + @Secured(Permission.MANAGE_USERS_STR) + @GetMapping("/admin/users/") + fun userList(): View { + return RedirectView("/admin/users/0/") + } + + @Secured(Permission.MANAGE_USERS_STR) + @GetMapping("/admin/users/{num}/") + fun userList(@PathVariable("num") pageNumber: Int): ModelAndView { + val users = userRepository.findAll(PageRequest.of(pageNumber, usersPerPage)) + return ModelAndView("admin/user_list", "users", users) + } +} diff --git a/src/main/resources/templates/admin/layout_admin.html b/src/main/resources/templates/admin/layout_admin.html new file mode 100644 index 0000000..357f461 --- /dev/null +++ b/src/main/resources/templates/admin/layout_admin.html @@ -0,0 +1,21 @@ + + + + + Mordor - Admin + + +
+ +
+ +
+
+ + diff --git a/src/main/resources/templates/admin/user_list.html b/src/main/resources/templates/admin/user_list.html new file mode 100644 index 0000000..ab101ca --- /dev/null +++ b/src/main/resources/templates/admin/user_list.html @@ -0,0 +1,42 @@ + + + + + Users + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + +
IdUsernameEmailFirst nameLast nameLocal enabledRole
+
+ +
+
+ + + diff --git a/src/main/resources/templates/fragments/pagination.html b/src/main/resources/templates/fragments/pagination.html new file mode 100644 index 0000000..fe8725e --- /dev/null +++ b/src/main/resources/templates/fragments/pagination.html @@ -0,0 +1,27 @@ + + + + + Pagination + + + + + From d47952cc60f0f47f5418c11f1eefdf3b29da753f Mon Sep 17 00:00:00 2001 From: Adam Pardyl Date: Wed, 12 Dec 2018 10:59:01 +0100 Subject: [PATCH 2/7] Hide pagination menu if only one page exists --- src/main/resources/templates/fragments/pagination.html | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/resources/templates/fragments/pagination.html b/src/main/resources/templates/fragments/pagination.html index fe8725e..a454a9d 100644 --- a/src/main/resources/templates/fragments/pagination.html +++ b/src/main/resources/templates/fragments/pagination.html @@ -1,12 +1,12 @@ - + Pagination