Adding and testing plex connections correctly from add box

This commit is contained in:
jhouse
2020-01-29 16:07:00 +09:00
parent 9d311b9fbb
commit adb73bc1ca
3 changed files with 77 additions and 27 deletions

View File

@@ -1,6 +1,5 @@
package com.jasonhhouse.gaps;
import java.util.List;
import java.util.Objects;
import java.util.Set;
import java.util.TreeSet;
@@ -15,6 +14,7 @@ public class PlexServer {
private Set<PlexLibrary> plexLibraries;
public PlexServer() {
plexLibraries = new TreeSet<>();
}
public PlexServer(String friendlyName, String machineIdentifier, String plexToken, String address, Integer port) {

View File

@@ -81,12 +81,20 @@ public class ConfigurationController {
LOGGER.error("Error binding PlexServer object: " + plexServer);
}
*/
plexQuery.queryPlexServer(plexServer);
plexQuery.getLibraries(plexServer);
gapsService.getPlexSearch().addPlexServer(plexServer);
ioService.writePlexConfiguration(gapsService.getPlexSearch().getPlexServers());
ObjectNode objectNode = objectMapper.createObjectNode();
template.convertAndSend("/configuration/plex/complete", plexServer);
try {
plexQuery.queryPlexServer(plexServer);
plexQuery.getLibraries(plexServer);
gapsService.getPlexSearch().addPlexServer(plexServer);
ioService.writePlexConfiguration(gapsService.getPlexSearch().getPlexServers());
template.convertAndSend("/configuration/plex/complete", plexServer);
} catch (Exception e) {
LOGGER.error("Could not add plex server", e);
objectNode.put("failed", true);
template.convertAndSend("/configuration/plex/complete", objectNode.toString());
}
}
@RequestMapping(value = "/test/plex",
@@ -125,7 +133,6 @@ public class ConfigurationController {
@RequestMapping(value = "/save/tmdbKey/{tmdbKey}",
method = RequestMethod.POST,
consumes = MediaType.APPLICATION_JSON_VALUE,
produces = MediaType.APPLICATION_JSON_VALUE)
@ResponseBody
public ResponseEntity<String> postSaveTmdbKey(@PathVariable("tmdbKey") final String tmdbKey) {

View File

@@ -15,36 +15,43 @@ document.addEventListener('DOMContentLoaded', function () {
stompClient.connect({}, function (frame) {
console.log('Connected: ' + frame);
stompClient.subscribe(`/configuration/plex/complete`, function (message) {
const plexServer = JSON.parse(message.body);
const plexSpinner = $('#plexSpinner');
const plexSaveSuccess = $('#plexSaveSuccess');
const plexSaveError = $('#plexSaveError');
const plexServerCard = $("#plexServerCard").html();
const theTemplate = Handlebars.compile(plexServerCard);
const theCompiledHtml = theTemplate(plexServer);
$('#plexServers').append(theCompiledHtml);
const body = message.body;
plexSpinner.hide();
if (body) {
const response = JSON.parse(body);
if (response.failed) {
plexSaveError.show();
} else {
plexSaveSuccess.show();
const plexServerCard = $("#plexServerCard").html();
const theTemplate = Handlebars.compile(plexServerCard);
const theCompiledHtml = theTemplate(response);
$('#plexServers').append(theCompiledHtml);
}
} else {
plexSaveError.show();
}
});
});
});
function addPlexServer() {
$.ajax({
type: "POST",
url: '/configuration/add/plex',
data: {
'plexToken': $('#plexToken').val(),
'address': $('#address').val(),
'port': $('#port').val()
},
dataType: 'application/json'
});
}
function testTmdbKey() {
const tmdbSpinner = $('#tmdbSpinner');
const tmdbSaveSuccess = $('#tmdbSaveSuccess');
const tmdbSaveError = $('#tmdbSaveError');
const tmdbTestSuccess = $('#tmdbTestSuccess');
const tmdbTestError = $('#tmdbTestError');
tmdbTestSuccess.hide();
tmdbTestError.hide();
tmdbSaveSuccess.hide();
tmdbSaveError.hide();
tmdbSpinner.show();
$.ajax({
@@ -70,7 +77,11 @@ function saveTmdbKey() {
const tmdbSpinner = $('#tmdbSpinner');
const tmdbSaveSuccess = $('#tmdbSaveSuccess');
const tmdbSaveError = $('#tmdbSaveError');
const tmdbTestSuccess = $('#tmdbTestSuccess');
const tmdbTestError = $('#tmdbTestError');
tmdbTestSuccess.hide();
tmdbTestError.hide();
tmdbSaveSuccess.hide();
tmdbSaveError.hide();
tmdbSpinner.show();
@@ -96,11 +107,15 @@ function saveTmdbKey() {
function testPlexServer() {
const plexSpinner = $('#plexSpinner');
const plexSaveSuccess = $('#plexSaveSuccess');
const plexSaveError = $('#plexSaveError');
const plexTestSuccess = $('#plexTestSuccess');
const plexTestError = $('#plexTestError');
plexTestSuccess.hide();
plexTestError.hide();
plexSaveSuccess.hide();
plexSaveError.hide();
plexSpinner.show();
$.ajax({
@@ -126,8 +141,36 @@ function testPlexServer() {
});
}
$(function(){
$("[data-hide]").on("click", function(){
function addPlexServer() {
const plexSpinner = $('#plexSpinner');
const plexSaveSuccess = $('#plexSaveSuccess');
const plexSaveError = $('#plexSaveError');
const plexTestSuccess = $('#plexTestSuccess');
const plexTestError = $('#plexTestError');
plexTestSuccess.hide();
plexTestError.hide();
plexSaveSuccess.hide();
plexSaveError.hide();
plexSpinner.show();
$.ajax({
type: "POST",
url: '/configuration/add/plex',
data: {
'plexToken': $('#plexToken').val(),
'address': $('#address').val(),
'port': $('#port').val()
},
error: function () {
plexSpinner.hide();
plexSaveError.show();
}
});
}
$(function () {
$("[data-hide]").on("click", function () {
//$("." + $(this).attr("data-hide")).hide();
// -or-, see below
$(this).closest("." + $(this).attr("data-hide")).hide();