Skip to content

Commit

Permalink
feat: admin-panel layout finished with topics/users revealed with col…
Browse files Browse the repository at this point in the history
…lapse. Added methods for enabling/disabling (banning) users.
  • Loading branch information
franchescoURJC committed Mar 2, 2023
1 parent e5dc5dd commit 3c26cd8
Show file tree
Hide file tree
Showing 6 changed files with 101 additions and 14 deletions.
Original file line number Diff line number Diff line change
@@ -1,13 +1,32 @@
package net.daw.alist.controllers;

import net.daw.alist.models.User;
import net.daw.alist.repositories.TopicRepository;
import net.daw.alist.repositories.UserRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Sort;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;

import java.util.List;

@Controller
public class AdminPanelController {

@Autowired
private UserRepository userRepository;
@Autowired
private TopicRepository topicRepository;

@GetMapping("/admin-panel")
public String adminPanel() {
public String adminPanel(Model model) {
List<String> usernameList = userRepository.findAllUsernames();
model.addAttribute("users", usernameList);

List<String> topicNameList = topicRepository.findAllTopicNames();
model.addAttribute("topics", topicNameList);
return "admin-panel";
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@

import net.daw.alist.models.Topic;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;

import java.util.List;

public interface TopicRepository extends JpaRepository<Topic, Long> {

@Query(value = "SELECT name FROM Topic t")
List<String> findAllTopicNames();
}
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
package net.daw.alist.repositories;

import net.daw.alist.models.User;
import org.springframework.data.domain.Sort;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;

import javax.transaction.Transactional;
import java.util.List;
import java.util.Optional;

@Repository
Expand All @@ -19,5 +21,25 @@ public interface UserRepository extends JpaRepository<User, Long> {
@Modifying
@Query("UPDATE User a " +
"SET a.enabled = TRUE WHERE a.email = ?1")
public int enableUser(String email);
public void enableUser(String email);

@Transactional
@Modifying
@Query("UPDATE User u " +
"SET u.locked = TRUE WHERE u.username = ?1")
public void banUser (String username);

@Transactional
@Modifying
@Query("UPDATE User u " +
"SET u.locked = FALSE WHERE u.username = ?1")
public void unbanUser (String username);

@Query(value = "SELECT username FROM User u")
List<String> findAllUsernames();





}
4 changes: 2 additions & 2 deletions back/src/main/java/net/daw/alist/services/UserService.java
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ public String register(User user) {
return "token=" + token;
}

public int enableUser(String email) {
return userRepository.enableUser(email);
public void enableUser(String email) {
userRepository.enableUser(email);
}
}
16 changes: 16 additions & 0 deletions back/src/main/resources/static/styles/admin-panel.css
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,22 @@ a:hover {
color: #63b1b1;
}

ul {
list-style-type: none;
margin: 0;
padding: 0;
}

.listItem, form{
width: 100%;
}

@media only screen and (min-width: 768px) {
/* For desktop: */
.listItem, form{
width: 75%;
}



}
44 changes: 34 additions & 10 deletions back/src/main/resources/templates/admin-panel.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,40 +13,64 @@
<link rel="stylesheet" type="text/css" href="styles/bootstrap/bootstrap.min.css">
<link rel="stylesheet" type="text/css" href="styles/styles.css">
<link rel="stylesheet" type="text/css" href="styles/admin-panel.css">
<script src="scripts/bootstrap/bootstrap.bundle.min.js"></script>
<!-- <script src="scripts/bootstrap/bootstrap.bundle.min.js"></script>-->
<title>Alist | Admin Panel</title>
</head>

<body>
{{>navbar}}
<div class="container px-4 py-5 text-center" id="featured-3">
<h1 class="pb-2 border-bottom">Admin Panel</h1>
<div class="row d-flex row-cols-1 row-cols-lg-3">
<div class="row d-flex row-cols-1 row-cols-lg-3 m-auto">
<div class="feature col flex-grow-1">
<a href="#">
<a href="#collapseUsers" data-bs-toggle="collapse" data-target="#collapseUsers" role="button" aria-expanded="false" aria-controls="collapseUsers">
<div class="feature-icon d-inline-flex align-items-center justify-content-center fs-2 mb-3">
<i class="fa-regular fa-solid fa-user fa-xl"></i>
</div>
<h3 class="fs-2">Manage Users</h3>
</a>
<p>Paragraph of text beneath the heading to explain the heading. We'll add onto it with another sentence and
probably just keep going until we run out of words.</p>
<p>
Click on a user to ban their account. If a user is highlighted in grey, that means their account is suspended.
Clicking on it again will unban the user.
</p>
<div class="collapse mt-4 d-flex flex-column justify-content-center align-items-center" id="collapseUsers">
<ul class="w-100 mt-auto">
{{#users}}
<button type="button" class="listItem btn btn-primary mt-2"><li>{{.}}</li></button>
{{/users}}
</ul>
</div>
</div>
<div class="feature col flex-grow-1">
<a href="#">
<a href="#collapseTopics" data-bs-toggle="collapse" data-target="#collapseTopics" role="button" aria-expanded="false" aria-controls="collapseTopics">
<div class="feature-icon d-inline-flex align-items-center justify-content-center fs-2 mb-3">
<i class="fa-regular fa-solid fa-at fa-xl"></i>
</div>
<h3 class="fs-2">Manage Topics</h3>
</a>
<p>Paragraph of text beneath the heading to explain the heading. We'll add onto it with another sentence and
probably just keep going until we run out of words.</p>
<p>
Type in a new topic to create it, or click on an already existing one to delete it.
</p>
<div class="collapse mt-4 w-100 d-flex flex-column justify-content-center align-items-center" id="collapseTopics">

<form>
<div class="form-floating mb-2">
<input type="text" class="form-control h-100" id="newTopic" placeholder="Type new topic..." name="newTopic">
<label for="newTopic" class="text-muted">Type new topic...</label>
</div>
<button class="w-100 btn btn-lg btn-light" type="submit">Add topic</button>
</form>

<ul class="w-100 mt-4">
{{#topics}}
<button type="button" class="listItem btn btn-primary mt-2"><li>{{.}}</li></button>
{{/topics}}
</ul>
</div>
</div>
</div>
</div>

<div></div>

</body>

</html>

0 comments on commit 3c26cd8

Please sign in to comment.