Change guild selection to dropdown

This commit is contained in:
Sebastien 2019-06-05 21:48:18 +02:00
parent 9fcac88f95
commit 4986e662f2
4 changed files with 61 additions and 11 deletions

View File

@ -29,6 +29,8 @@ import org.springframework.web.bind.annotation.ResponseStatus;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.ArrayList;
import java.util.List;
/**
* Web page controller for index
@ -70,11 +72,14 @@ public class GeneralWebView {
UserEntity userE = userUtils.getUserWithApiToken(userRepository, token);
User user = MainBot.jda.getUserById(userE.getJdaId());
if(user == null)
if(user == null) {
model.addAttribute("noMutualGuilds", true);
else
addGuildAndRedirect(model, token, guildId, new ArrayList<>());
} else {
model.addAttribute("noMutualGuilds", false);
addGuildAndRedirect(model, guildId);
addGuildAndRedirect(model, token, guildId, user.getMutualGuilds());
}
model.addAttribute("isAdmin", SettingsUtils.getInstance().checkPermission(token, guildId));
model.addAttribute("isLogged", true);
model.addAttribute("inviteLink", "https://discordapp.com/oauth2/authorize?client_id=" + MainBot.jda.getSelfUser().getId() + "&scope=bot&permissions=8");
@ -126,10 +131,17 @@ public class GeneralWebView {
public String settings(Model model, @CookieValue(value = "guild", defaultValue = "") String guildId, @CookieValue(value = "token", defaultValue = "") String token){
SettingsUtils settingsUtils = SettingsUtils.getInstance();
if(settingsUtils.checkPermission(token, guildId)){
addGuildAndRedirect(model, guildId);
Guild guild = MainBot.jda.getGuildById(guildId);
model.addAttribute("settings", SettingsUtils.getInstance().extractSettings(guild));
model.addAttribute("isAdmin", SettingsUtils.getInstance().checkPermission(token, guildId));
try {
UserEntity userE = userUtils.getUserWithApiToken(userRepository, token);
User user = MainBot.jda.getUserById(userE.getJdaId());
addGuildAndRedirect(model, token, guildId, user.getMutualGuilds());
Guild guild = MainBot.jda.getGuildById(guildId);
model.addAttribute("settings", SettingsUtils.getInstance().extractSettings(guild));
model.addAttribute("isAdmin", SettingsUtils.getInstance().checkPermission(token, guildId));
} catch (UnknownTokenException e) {
throw new ForbiddenException();
}
@ -160,12 +172,19 @@ public class GeneralWebView {
GuildStatsPack stack;
if(!cookieGuildId.equals("")){
stack = UserStatsUtils.getINSTANCE().getStatPack(userEntity, cookieGuildId);
addGuildAndRedirect(model, cookieGuildId);
}
else
stack = null;
model.addAttribute("stack", stack);
try {
UserEntity userE = userUtils.getUserWithApiToken(userRepository, token);
User user = MainBot.jda.getUserById(userE.getJdaId());
addGuildAndRedirect(model, token, cookieGuildId, user.getMutualGuilds());
} catch (UnknownTokenException e) {
throw new ForbiddenException();
}
return CheckPage.getPageIfReady("rank");
} catch (UnknownTokenException e) {
@ -178,11 +197,14 @@ public class GeneralWebView {
private Model addGuildAndRedirect(Model model, String guildId){
private Model addGuildAndRedirect(Model model, String token, String guildId, List<Guild> mutualGuilds){
Guild guild = MainBot.jda.getGuildById(guildId);
if(guild != null){
model.addAttribute("guild_name", guild.getName());
model.addAttribute("guild_id", guild.getId());
model.addAttribute("guild_icon", guild.getIconUrl() == null ? "https://discordapp.com/assets/dd4dbc0016779df1378e7812eabaa04d.png": guild.getIconUrl());
model.addAttribute("mutual_guilds", mutualGuilds);
model.addAttribute("isAdmin", SettingsUtils.getInstance().checkPermission(token, guildId));
}
else{

View File

@ -32,6 +32,12 @@ main {
-webkit-text-fill-color: #fbcf40;
-webkit-text-stroke-color: black;
-webkit-text-stroke-width: 3px;
}
#dropdown_guilds a:hover{
background-color: rgba(0, 0, 0, 0) !important;
}
#dropdown_guilds li:hover{
background-color: rgba(0, 0, 0, 0.2) !important;
}

View File

@ -80,11 +80,16 @@ function navListeners() {
$('#btn_ok_guild').click(function () {
guild = $('input[name=guildRadio]:checked').val();
let url = $('input[name=guildRadio]:checked').attr("data-icon");
Cookies.set('guild', guild, { expires: 31 });
window.location.reload(true);
});
$('.guild_change').click(function () {
let id = this.getAttribute("data-id");
Cookies.set('guild', id, { expires: 31 });
window.location.reload(true);
});
$('.nav-change-guild').click(function () {
Cookies.remove('guild');
window.location.reload(true);
@ -179,6 +184,14 @@ function checkToken() {
});
if (Cookies.get('guild') === undefined ) {
getGuild()
}else{
$('#drop-trigger-guilds').dropdown({
constrainWidth: false, // Does not change width of dropdown to that of the activator
coverTrigger: false, // Displays dropdown below the button
alignment: 'left', // Displays dropdown with edge aligned to the left of button
stopPropagation: false // Stops event propagation
}
);
}
}

View File

@ -20,7 +20,7 @@
<a href="/" class="brand-logo hide-on-med-and-up show-on-small" style="white-space: nowrap">Claptrap</a>
<ul class="right hide-on-med-and-down">
<li>
<a class="nav-change-guild truncate waves-effect waves-light btn-flat grey-text text-darken-1" th:inline="text" style="margin-top: 2px;margin-right: 0px;">[[${guild_name}]]<img th:src="${guild_icon}" id="guildLogo" class="brand-logo left circle" style="max-height: 100%; margin-right: 10px"/></a>
<a class="truncate waves-effect brown darken-3 waves-light btn-flat grey-text text-darken-1 dropdown-trigger" id="drop-trigger-guilds" data-target="dropdown_guilds" th:inline="text" style="margin-top: 2px;margin-right: 10px;">[[${guild_name}]]<img th:src="${guild_icon}" id="guildLogo" class="brand-logo left circle" style="max-height: 100%; margin-right: 10px; padding: 2px; padding-left: 0"/></a>
</li>
<li class="" th:classappend="(${page} == 'home')? 'active' : ''">
<a class="waves-effect waves-light" href="/">Home</a>
@ -83,8 +83,17 @@
</ul>
<ul class="dropdown-content" id="dropdown_guilds">
<!--/*@thymesVar id="mutual_guilds" type="java.util.List<net.dv8tion.jda.core.entities.Guild>"*/-->
<th:block th:each="guild : ${mutual_guilds}">
<li style="height: 50px; white-space: nowrap;" th:attr="data-id = ${guild.getId()}" th:if="${guild.getId() != guild_id}" class="guild_change">
<img th:src="${guild.getIconUrl() == null ? 'https://discordapp.com/assets/dd4dbc0016779df1378e7812eabaa04d.png' : guild.getIconUrl()}" class="left circle" style="max-height: 100%; padding: 5px; "/><a class="center blue-grey-text text-darken-4" th:inline="text" style="margin-left: 50px">[[${guild.getName()}]]</a>
</li>
</th:block>
</ul>
<!-- Dropdown connected -->