From 7ae7ae9bf6b7776f4d632f7fee62a8bc72cbdc05 Mon Sep 17 00:00:00 2001 From: Sebastien Date: Mon, 14 May 2018 11:57:05 +0200 Subject: [PATCH] Add Guild name on navbar --- .../net/Broken/RestApi/MusicWebAPIController.java | 7 ++++++- src/main/java/net/Broken/webView/GeneralWebView.java | 11 ++++++++++- src/main/java/net/Broken/webView/MusicWebView.java | 11 ++++++++++- src/main/resources/static/js/navabar.js | 4 +++- src/main/resources/templates/header.html | 12 +++++++++--- src/main/resources/templates/index.html | 2 +- src/main/resources/templates/music.html | 2 +- src/main/resources/templates/register.html | 2 +- 8 files changed, 41 insertions(+), 10 deletions(-) diff --git a/src/main/java/net/Broken/RestApi/MusicWebAPIController.java b/src/main/java/net/Broken/RestApi/MusicWebAPIController.java index a24475d..687fa97 100644 --- a/src/main/java/net/Broken/RestApi/MusicWebAPIController.java +++ b/src/main/java/net/Broken/RestApi/MusicWebAPIController.java @@ -32,11 +32,16 @@ import java.util.List; @RequestMapping("/api/music/") public class MusicWebAPIController { Logger logger = LogManager.getLogger(); - @Autowired + private final UserRepository userRepository; UserUtils userUtils = UserUtils.getInstance(); + @Autowired + public MusicWebAPIController(UserRepository userRepository) { + this.userRepository = userRepository; + } + @RequestMapping("/currentMusicInfo") public ResponseEntity getCurrentM(@RequestParam(value = "guild") String guildId){ diff --git a/src/main/java/net/Broken/webView/GeneralWebView.java b/src/main/java/net/Broken/webView/GeneralWebView.java index 71616ad..b867b6e 100644 --- a/src/main/java/net/Broken/webView/GeneralWebView.java +++ b/src/main/java/net/Broken/webView/GeneralWebView.java @@ -4,11 +4,15 @@ import net.Broken.DB.Entity.PlaylistEntity; import net.Broken.DB.Entity.TrackEntity; import net.Broken.DB.Entity.UserEntity; import net.Broken.DB.Repository.UserRepository; +import net.Broken.MainBot; import net.Broken.RestApi.Commands.Play; +import net.dv8tion.jda.core.entities.Guild; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; import org.springframework.ui.Model; +import org.springframework.web.bind.annotation.CookieValue; import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; import java.util.ArrayList; import java.util.List; @@ -21,7 +25,12 @@ public class GeneralWebView { @RequestMapping("/") - public String music(Model model){ + public String music(Model model, @CookieValue(value = "guild", defaultValue = "1") String guildId){ + Guild guild = MainBot.jda.getGuildById(guildId); + if(guild != null) + model.addAttribute("guild_name", guild.getName()); + else + model.addAttribute("guild_name", ""); return CheckPage.getPageIfReady("index"); } diff --git a/src/main/java/net/Broken/webView/MusicWebView.java b/src/main/java/net/Broken/webView/MusicWebView.java index 753aa35..6dddf53 100644 --- a/src/main/java/net/Broken/webView/MusicWebView.java +++ b/src/main/java/net/Broken/webView/MusicWebView.java @@ -1,7 +1,10 @@ package net.Broken.webView; +import net.Broken.MainBot; +import net.dv8tion.jda.core.entities.Guild; import org.springframework.stereotype.Controller; import org.springframework.ui.Model; +import org.springframework.web.bind.annotation.CookieValue; import org.springframework.web.bind.annotation.RequestMapping; /** @@ -10,7 +13,13 @@ import org.springframework.web.bind.annotation.RequestMapping; @Controller public class MusicWebView { @RequestMapping("/music") - public String music(Model model){ + public String music(Model model, @CookieValue(value = "guild", defaultValue = "1") String guildId){ + Guild guild = MainBot.jda.getGuildById(guildId); + if(guild != null) + model.addAttribute("guild_name", guild.getName()); + else + model.addAttribute("guild_name", ""); + return CheckPage.getPageIfReady("music"); } } diff --git a/src/main/resources/static/js/navabar.js b/src/main/resources/static/js/navabar.js index 15e7d7d..98d4b10 100644 --- a/src/main/resources/static/js/navabar.js +++ b/src/main/resources/static/js/navabar.js @@ -79,7 +79,9 @@ function disconnected() { console.log("Disconnected"); nav_bar_account_link.html(disconnected_link); var modalConnection = $('#modal_connection'); - modalConnection.modal(); + modalConnection.modal({ + dismissible: false // Modal can be dismissed by clicking outside of the modal + }); if (typeof needLogin !== 'undefined'){ modalConnection.modal('open'); } diff --git a/src/main/resources/templates/header.html b/src/main/resources/templates/header.html index edcc37a..eb5181c 100644 --- a/src/main/resources/templates/header.html +++ b/src/main/resources/templates/header.html @@ -4,24 +4,30 @@ + -
+ +