Skip to content

Commit

Permalink
Allowing selection of path
Browse files Browse the repository at this point in the history
  • Loading branch information
fresnik committed Sep 12, 2017
1 parent 99bb242 commit f6191a3
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 53 deletions.
10 changes: 0 additions & 10 deletions opt/options.html
Original file line number Diff line number Diff line change
Expand Up @@ -83,16 +83,6 @@ <h3>API Key:<i class="fa fa-question-circle icon-small" data-toggle="tooltip" ar
<input type="text" id="radarrapikey" class="form-control x-path tt-input form-custom" autocomplete="off" spellcheck="false" dir="auto">
</div>
</div>
<div class="row">
<div class="col-xs-12">
<h3>Root Path:<i class="fa fa-question-circle icon-small" data-toggle="tooltip" aria-hidden="true"></i></h3>
</div>
</div>
<div class="row">
<div class="col-xs-12">
<input type="text" id="txtMoviePath" class="form-control x-path tt-input form-custom" autocomplete="off" spellcheck="false" dir="auto">
</div>
</div>
</div>
<div class="row internal-container">
<div class="col-md-12 col-xs-12">
Expand Down
38 changes: 16 additions & 22 deletions opt/options.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,11 @@ var apikey = "";
var auth = false;
var user = "";
var password = "";
var moviePath = "";
var tooltips = [
{title: "IP address or domain name of your Radarr server.", placement: "right", animation: true, delay: {show: 500, hide: 100}},
{title: "Enable if your server requires basic http authentication.", placement: "right", animation: true, delay: {show: 500, hide: 100}},
{title: "Port number that Radarr is accessible on. Radarr > Settings > General", placement: "right", animation: true, delay: {show: 500, hide: 100}},
{title: "Radarr API Key. Radarr > Settings > General", placement: "right", animation: true, delay: {show: 500, hide: 100}},
{title: "Path to root folder where movies will be saved. Leave blank to use Radarr default path.", placement: "right", animation: true, delay: {show: 500, hide: 100}},
{title: "Radarr API Key. Radarr > Settings > General", placement: "right", animation: true, delay: {show: 500, hide: 100}}
];

$('#chkAuth').on('change', function () {
Expand Down Expand Up @@ -60,7 +58,6 @@ function readInputs() {
user = document.getElementById('user').value.trim();
password = document.getElementById('password').value.trim();
}
moviePath = document.getElementById('txtMoviePath').value.trim();
}

function constructBaseUrl(host, port) {
Expand All @@ -83,16 +80,16 @@ function testApi(url) {
if (this.status === 200) {
resolve(http.statusText);
} else {
switch (http.status) {
case 400:
reject(Error("Failed to add movie! Please check it is not already in your collection."));
break;
case 401:
reject("Unauthorised! Please check your API key or server authentication.");
break;
default:
reject(Error("(" + http.status + ")" + http.statusText));
}
switch (http.status) {
case 400:
reject(Error("Failed to add movie! Please check it is not already in your collection."));
break;
case 401:
reject("Unauthorised! Please check your API key or server authentication.");
break;
default:
reject(Error("(" + http.status + ")" + http.statusText));
}
}
};

Expand Down Expand Up @@ -121,7 +118,6 @@ function saveConfig() {
localStorage.setItem("auth", auth);
localStorage.setItem("user", user);
localStorage.setItem("password", password);
localStorage.setItem("moviePath", moviePath);

$("#status").text("Sucess! Configuration saved.");
$("#page *").prop('disabled', false);
Expand All @@ -139,15 +135,13 @@ function restoreConfig() {
auth = localStorage.getItem("auth") == "true";
user = localStorage.getItem("user");
password = localStorage.getItem("password");
moviePath = localStorage.getItem("moviePath");

$('#host').val(host);
$('#port').val(port);
$('#radarrapikey').val(apikey);
$('#host').val(host);
$('#port').val(port);
$('#radarrapikey').val(apikey);

$('#chkAuth').prop('checked', auth);
if (auth) $('#optAuth').removeClass('hidden');
$('#user').val(user);
$('#password').val(password);
$('#txtMoviePath').val(moviePath);
$('#user').val(user);
$('#password').val(password);
}
8 changes: 8 additions & 0 deletions popup.html
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,14 @@ <h2 id="title"><span id="year"></span></h2>
<select id="profile" class="form-control x-profile"></select>
</div>
</div>
<div class="row internal-container">
<div class="col-xs-4 vcenter">
<label class="textpadding">Folder</label>
</div>
<div class="col-xs-8 vcenter">
<select id="folderPath" class="form-control x-profile"></select>
</div>
</div>
</div>
<div class="row internal-container ctlRow">
<div class="col-md-6 col-xs-4 text-left">
Expand Down
47 changes: 26 additions & 21 deletions popup.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,8 @@ function extractIMDBID(url) {
var radarrExt = {

config: {
getRootPath: function() {
return radarrExt.server.get("rootfolder", "").text[0].path;
getRootPaths: function() {
return radarrExt.server.get("rootfolder", "").text.map(f => f.path);
},

getHost: function() {
Expand Down Expand Up @@ -116,18 +116,6 @@ var radarrExt = {
getAuth: function() {
return btoa(localStorage.getItem("user") + ":" + localStorage.getItem("password"));
},

getMoviePath: function() {
return new Promise(function(resolve, reject) {
if (localStorage.getItem('moviePath') !== "") {
resolve(localStorage.getItem('moviePath'));
} else {
radarrExt.server.get("rootfolder", "").then(function(response) {
resolve(response.text[0].path);
});
}
});
}
},

server: {
Expand Down Expand Up @@ -212,11 +200,10 @@ var radarrExt = {

popup: {
init: function(movie, slug) {
var addPath;
radarrExt.config.getMoviePath().then(function(response) {addPath = response;});
$('#description').html(movie.text[0].overview);
if (movie.status == 200) {
radarrExt.popup.profilesById();
radarrExt.popup.folderPathsById();
radarrExt.popup.restoreSettings();
}
$('body').changepanel(movie.text[0]);
Expand All @@ -242,12 +229,12 @@ var radarrExt = {

$('#btnAdd').on('click', function() {
radarrExt.addMovie(
movie.text[0],
movie.text[0],
$('#profile').val(),
$("#monitored").prop('checked'),
$('#minAvail').val(),
false,
addPath
$('#folderPath').val()
);
});

Expand All @@ -258,7 +245,7 @@ var radarrExt = {
$("#monitored").prop('checked'),
$('#minAvail').val(),
true,
addPath
$('#folderPath').val()
);
});
},
Expand All @@ -268,10 +255,11 @@ var radarrExt = {
$("#serverResponse").removeClass("hidden");
},

saveSettings: function(monitored, qualityId, minAvail) {
saveSettings: function(monitored, qualityId, minAvail, folderPath) {
localStorage.setItem("monitored", monitored);
localStorage.setItem("profile", qualityId);
localStorage.setItem("minAvail", minAvail);
localStorage.setItem("folderPath", folderPath);
},

restoreSettings: function() {
Expand All @@ -298,6 +286,22 @@ var radarrExt = {
}).catch(function(error) {
radarrExt.popup.info("profilesById Failed! " + error);
});
},

folderPathsById: function() {
radarrExt.server.get("rootfolder", "").then(function(response) {
var folderPaths = response.text;
for (var i = 0; i < folderPaths.length; i++) {
$('#folderPath')
.append($('<option>', { value: folderPaths[i].path })
.text(folderPaths[i].path));
if (localStorage.getItem("folderPath") !== null && (localStorage.getItem("folderPath") === folderPaths[i].path)) {
$('#folderPath').prop('selectedIndex', i);
}
}
}).catch(function(error) {
radarrExt.popup.info("folderPathsById Failed! " + error);
});
}
},

Expand Down Expand Up @@ -360,9 +364,10 @@ var radarrExt = {
"searchForMovie": addSearch
}
};
chrome.extension.getBackgroundPage().console.log(newMovie);

radarrExt.server.post("movie", newMovie).then(function(response) {
radarrExt.popup.saveSettings(monitored, qualityId, minAvail);
radarrExt.popup.saveSettings(monitored, qualityId, minAvail, folderPath);
$("#popup").stop(true).fadeTo('fast', 1);
$('#serverResponse').text("Movie added to Radarr!");
$("#serverResponse").removeClass("hidden");
Expand Down

0 comments on commit f6191a3

Please sign in to comment.