Saving plex server information and retreving it now

This commit is contained in:
jhouse
2020-01-27 16:32:29 +09:00
parent f1c8b98414
commit 8d7e43f412
3 changed files with 74 additions and 7 deletions

View File

@@ -13,6 +13,7 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.messaging.simp.SimpMessagingTemplate;
import org.springframework.stereotype.Controller;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.RequestMapping;
@@ -26,12 +27,14 @@ public class ConfigurationController {
private static final Logger LOGGER = LoggerFactory.getLogger(ConfigurationController.class);
private final BindingErrorsService bindingErrorsService;
private final SimpMessagingTemplate template;
private final PlexQueryImpl plexQuery;
private final GapsService gapsService;
private final IoService ioService;
public ConfigurationController(BindingErrorsService bindingErrorsService, PlexQueryImpl plexQuery, GapsService gapsService, IoService ioService) {
public ConfigurationController(BindingErrorsService bindingErrorsService, SimpMessagingTemplate template, PlexQueryImpl plexQuery, GapsService gapsService, IoService ioService) {
this.bindingErrorsService = bindingErrorsService;
this.template = template;
this.plexQuery = plexQuery;
this.gapsService = gapsService;
this.ioService = ioService;
@@ -73,5 +76,7 @@ public class ConfigurationController {
plexQuery.getLibraries(plexServer);
gapsService.getPlexSearch().addPlexServer(plexServer);
ioService.writePlexConfiguration(plexServer);
template.convertAndSend("/configuration/plex/complete", plexServer);
}
}

View File

@@ -0,0 +1,39 @@
/*
* Copyright 2019 Jason H House
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
document.addEventListener('DOMContentLoaded', function () {
const socket = new SockJS('/gs-guide-websocket');
stompClient = Stomp.over(socket);
stompClient.connect({}, function (frame) {
console.log('Connected: ' + frame);
stompClient.subscribe(`/configuration/plex/complete`, function (message) {
const plexServer = JSON.parse(message.body);
const plexServerCard = $("#plexServerCard").html();
const theTemplate = Handlebars.compile(plexServerCard);
const theCompiledHtml = theTemplate(plexServer);
$('#plexServers').append(theCompiledHtml);
});
});
});
function addPlexServer() {
$.ajax({
type: "POST",
url: '/configuration/plex',
data: {
'plexToken': $('#plexToken').val(),
'address': $('#address').val(),
'port': $('#port').val()
},
dataType: 'application/json'
});
}

View File

@@ -21,7 +21,7 @@
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
</head>
<body>
<body onload="connect()">
<nav class="navbar navbar-expand-lg navbar-dark bg-primary">
<a class="navbar-brand" href="/">Gaps</a>
<div class="collapse navbar-collapse" id="navbarColor01">
@@ -98,12 +98,12 @@
.</small>
</div>
<button type="button" id="addPlexServer" class="btn btn-primary">Add</button>
<button type="button" onclick="addPlexServer()" class="btn btn-primary">Add</button>
</form>
<h3 class="top-margin">Servers</h3>
<div class="row top-margin">
<div id="plexServers" class="row top-margin">
<div class="col-lg-4" th:each="plexServer,status : *{plexSearch.plexServers}">
<div class="top-margin">
<div class="card border-info mb-3" style="max-width: 20rem;">
@@ -130,8 +130,31 @@
</div>
</div>
<script type="text/javascript" src="js/jquery-3.4.1.min.js"></script>
<script type="text/javascript" src="js/bootstrap.bundle.min.js"></script>
<script type="text/javascript" src="js/plexConfiguration.js"></script>
<script id="plexServerCard" type="text/x-handlebars-template">
<div class="col-lg-4">
<div class="top-margin">
<div class="card border-info mb-3" style="max-width: 20rem;">
<div class="card-header">{{friendlyName}}</div>
<ul class="list-group list-group-flush">
{{#each plexLibraries}}
<li class="list-group-item">{{title}}</li>
{{/each}}
</ul>
<div class="card-body">
<a href="#test" class="card-link" data-ol-has-click-handler="">Test</a>
<a href="#remove" class="card-link" data-ol-has-click-handler="">Remove</a>
</div>
<div class="card-footer text-muted">http://{{address}}:{{port}}</div>
</div>
</div>
</div>
</script>
<script type="text/javascript" src="/js/jquery-3.4.1.min.js"></script>
<script type="text/javascript" src="/js/bootstrap.bundle.min.js"></script>
<script type="text/javascript" src="/js/sockjs-1.4.0.min.js"></script>
<script type="text/javascript" src="/js/stomp-2.3.3.min.js"></script>
<script type="text/javascript" src="https://cdn.jsdelivr.net/npm/handlebars@latest/dist/handlebars.js"></script>
<script type="text/javascript" src="js/configuration.js"></script>
</body>
</html>