mirror of
https://github.com/JasonHHouse/gaps.git
synced 2026-02-05 01:59:35 -06:00
Adding and testing plex connections correctly from add box
This commit is contained in:
@@ -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) {
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user