diff --git a/src/main/java/net/Broken/webView/GeneralWebView.java b/src/main/java/net/Broken/webView/GeneralWebView.java index a81d0cd..a344f16 100644 --- a/src/main/java/net/Broken/webView/GeneralWebView.java +++ b/src/main/java/net/Broken/webView/GeneralWebView.java @@ -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 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{ diff --git a/src/main/resources/static/css/style.css b/src/main/resources/static/css/style.css index 4e2aa6e..526f1d9 100644 --- a/src/main/resources/static/css/style.css +++ b/src/main/resources/static/css/style.css @@ -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; } \ No newline at end of file diff --git a/src/main/resources/static/js/navabar.js b/src/main/resources/static/js/navabar.js index 988b817..efcdb1d 100644 --- a/src/main/resources/static/js/navabar.js +++ b/src/main/resources/static/js/navabar.js @@ -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 + } + ); } } diff --git a/src/main/resources/templates/header.html b/src/main/resources/templates/header.html index 39d59bf..1567bd8 100644 --- a/src/main/resources/templates/header.html +++ b/src/main/resources/templates/header.html @@ -20,7 +20,7 @@ + +