mirror of
https://github.com/jellyfin/jellyfin-web
synced 2025-03-30 19:56:21 +00:00
Implement auto refresh and activate button
This commit is contained in:
parent
fdfdcd60fe
commit
c37e8f2f1b
9 changed files with 170 additions and 123 deletions
|
@ -152,51 +152,54 @@ define(["apphost", "appSettings", "dom", "connectionManager", "loading", "layout
|
|||
|
||||
function loginQuickConnect() {
|
||||
var apiClient = getApiClient();
|
||||
var friendlyName = "test";
|
||||
|
||||
var friendlyName = navigator.userAgent; // TODO: what should this be changed to?
|
||||
|
||||
var url = apiClient.getUrl("/QuickConnect/Initiate?FriendlyName=" + friendlyName);
|
||||
apiClient.getJSON(url)
|
||||
.then(json => {
|
||||
if (!json.Secret || !json.Code) {
|
||||
.then(json => {
|
||||
if (!json.Secret || !json.Code) {
|
||||
Dashboard.alert({
|
||||
message: json.Error,
|
||||
title: "Error"
|
||||
});
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
Dashboard.alert({
|
||||
message: json.Error,
|
||||
title: "Error"
|
||||
message: "Authorize request " + json.Code + " to continue",
|
||||
title: "Quick Connect Code"
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
Dashboard.alert({
|
||||
message: "Authorize request " + json.Code + " to continue",
|
||||
title: "Quick Connect Code"
|
||||
});
|
||||
loading.show();
|
||||
|
||||
loading.show();
|
||||
var interval = setInterval(async function() {
|
||||
let connectUrl = apiClient.getUrl('/QuickConnect/Connect?Secret=' + json.Secret);
|
||||
let data = await apiClient.getJSON(connectUrl);
|
||||
if (data.Authenticated) {
|
||||
let result = await apiClient.quickConnect(data.Authentication);
|
||||
var user = result.User;
|
||||
var serverId = getParameterByName("serverid");
|
||||
var newUrl = "home.html";
|
||||
|
||||
var interval = setInterval(() => {
|
||||
var url = apiClient.getUrl('/QuickConnect/Connect?Secret=' + json.Secret);
|
||||
apiClient.getJSON(url)
|
||||
.then(data => {
|
||||
if(data.Authenticated) {
|
||||
apiClient.quickConnect(data.Authentication).then((result) => {
|
||||
var user = result.User;
|
||||
var serverId = getParameterByName("serverid");
|
||||
var newUrl;
|
||||
if (user.Policy.IsAdministrator && !serverId) {
|
||||
newUrl = "dashboard.html";
|
||||
}
|
||||
|
||||
if (user.Policy.IsAdministrator && !serverId) {
|
||||
newUrl = "dashboard.html";
|
||||
} else {
|
||||
newUrl = "home.html";
|
||||
}
|
||||
loading.hide();
|
||||
Dashboard.onServerChanged(user.Id, result.AccessToken, apiClient);
|
||||
Dashboard.navigate(newUrl);
|
||||
clearInterval(interval);
|
||||
|
||||
loading.hide();
|
||||
Dashboard.onServerChanged(user.Id, result.AccessToken, apiClient);
|
||||
Dashboard.navigate(newUrl);
|
||||
clearInterval(interval);
|
||||
});
|
||||
return true;
|
||||
}
|
||||
});
|
||||
}, 5000);
|
||||
});
|
||||
return false;
|
||||
}, 5000);
|
||||
|
||||
return true;
|
||||
}).catch((e) => {
|
||||
console.error("Unable to initiate quick connect login request. Error:", e);
|
||||
});
|
||||
}
|
||||
|
||||
view.querySelector("#divUsers").addEventListener("click", function (e) {
|
||||
|
@ -240,7 +243,7 @@ define(["apphost", "appSettings", "dom", "connectionManager", "loading", "layout
|
|||
view.querySelector(".btnSelectServer").addEventListener("click", function () {
|
||||
Dashboard.selectServer();
|
||||
});
|
||||
view.addEventListener("viewshow", function (e) {
|
||||
view.addEventListener("viewshow", function () {
|
||||
loading.show();
|
||||
|
||||
if (!appHost.supports('multiserver')) {
|
||||
|
|
|
@ -1,9 +1,8 @@
|
|||
define(["jQuery", "loading", "libraryMenu", "fnchecked"], function ($, loading, libraryMenu) {
|
||||
define(["jQuery", "loading", "fnchecked"], function ($, loading) {
|
||||
"use strict";
|
||||
|
||||
var page;
|
||||
function loadPage(page, status) {
|
||||
console.debug("status is \"" + status + "\"");
|
||||
|
||||
var active = (status == "Active");
|
||||
var available = (status == "Available") || active;
|
||||
|
||||
|
@ -16,44 +15,53 @@ define(["jQuery", "loading", "libraryMenu", "fnchecked"], function ($, loading,
|
|||
|
||||
function onSubmit() {
|
||||
loading.show();
|
||||
|
||||
var available = $("#chkQuickConnectAvailable").is(":checked") ? "Available" : "Unavailable";
|
||||
|
||||
var newStatus = page.querySelector("#chkQuickConnectAvailable").checked ? "Available" : "Unavailable";
|
||||
if (newStatus && page.querySelector("#chkQuickConnectActive").checked) {
|
||||
newStatus = "Active";
|
||||
}
|
||||
|
||||
var url = ApiClient.getUrl("/QuickConnect/Available");
|
||||
|
||||
|
||||
ApiClient.ajax({
|
||||
type: "POST",
|
||||
data: {
|
||||
"Status": available
|
||||
"Status": newStatus
|
||||
},
|
||||
url: url
|
||||
}, true).then(() => {
|
||||
if($("#chkQuickConnectActive").is(":checked")) {
|
||||
url = ApiClient.getUrl("/QuickConnect/Activate");
|
||||
ApiClient.ajax({
|
||||
type: "POST",
|
||||
url: url
|
||||
}, true);
|
||||
}
|
||||
|
||||
Dashboard.alert({
|
||||
message: "Settings saved",
|
||||
title: "Saved"
|
||||
});
|
||||
|
||||
setTimeout(updatePage, 500);
|
||||
|
||||
return true;
|
||||
}).catch((e) => {
|
||||
console.error("Unable to set quick connect status. error:", e);
|
||||
});
|
||||
|
||||
|
||||
loading.hide();
|
||||
return false;
|
||||
}
|
||||
|
||||
$(document).on("pageinit", "#quickConnectPage", function () {
|
||||
document.querySelector("#quickConnectPage").onsubmit = onSubmit;
|
||||
document.querySelector("#btnQuickConnectSubmit").onclick = onSubmit;
|
||||
}).on("pageshow", "#quickConnectPage", function () {
|
||||
loading.show();
|
||||
var page = this;
|
||||
function updatePage() {
|
||||
var promise1 = ApiClient.getQuickConnect("Status");
|
||||
Promise.all([promise1]).then(function (responses) {
|
||||
Promise.all([promise1]).then((responses) => {
|
||||
loadPage(page, responses[0]);
|
||||
return true;
|
||||
}).catch((e) => {
|
||||
console.error("Unable to get quick connect status. error:", e);
|
||||
});
|
||||
}
|
||||
|
||||
$(document).on("pageshow", "#quickConnectPage", function () {
|
||||
loading.show();
|
||||
page = this;
|
||||
|
||||
page.querySelector("#btnQuickConnectSubmit").onclick = onSubmit;
|
||||
|
||||
updatePage();
|
||||
});
|
||||
});
|
||||
|
|
|
@ -1,50 +1,55 @@
|
|||
define(["quickConnectSettings", "dom", "globalize", "loading", "userSettings", "autoFocuser", "listViewStyle"], function (QuickConnectSettings, dom, globalize, loading, userSettings, autoFocuser) {
|
||||
"use strict";
|
||||
|
||||
return function (view, params) {
|
||||
function notImplemented() {
|
||||
Dashboard.alert({
|
||||
message: "This button is not implemented yet, you must check the checkbox labeled \"Always accept quick connect login requests\" in the dashboard",
|
||||
title: "Not implemented"
|
||||
});
|
||||
}
|
||||
|
||||
return function (view) {
|
||||
var quickConnectSettingsInstance = null;
|
||||
var hasChanges;
|
||||
var userId = params.userId || ApiClient.getCurrentUserId();
|
||||
var currentSettings = userId === ApiClient.getCurrentUserId() ? userSettings : new userSettings();
|
||||
|
||||
view.addEventListener("viewshow", function () {
|
||||
console.debug("defining instance");
|
||||
|
||||
$("#btnQuickConnectActivate").click(notImplemented);
|
||||
|
||||
quickConnectSettingsInstance = new QuickConnectSettings({
|
||||
serverId: ApiClient.serverId(),
|
||||
userId: userId,
|
||||
element: view.querySelector(".quickConnectSettingsContainer"),
|
||||
userSettings: currentSettings,
|
||||
enableSaveButton: false,
|
||||
enableSaveConfirmation: false,
|
||||
autoFocus: autoFocuser.isEnabled()
|
||||
page: view,
|
||||
interval: 0
|
||||
});
|
||||
|
||||
|
||||
view.querySelector("#btnQuickConnectActivate").addEventListener("click", () => {
|
||||
quickConnectSettingsInstance.activate(quickConnectSettingsInstance);
|
||||
});
|
||||
|
||||
quickConnectSettingsInstance.loadData();
|
||||
});
|
||||
view.addEventListener("change", function () {
|
||||
hasChanges = true;
|
||||
|
||||
ApiClient.getQuickConnect("Status").then((status) => {
|
||||
let btn = view.querySelector("#btnQuickConnectActivate");
|
||||
|
||||
if (status === "Unavailable") {
|
||||
btn.textContent = "Quick connect is not available on this server";
|
||||
btn.disabled = true;
|
||||
return false;
|
||||
}
|
||||
|
||||
else if (status === "Available") {
|
||||
return false;
|
||||
}
|
||||
|
||||
btn.style.display = "none";
|
||||
return true;
|
||||
}).catch((e) => {
|
||||
throw e;
|
||||
});
|
||||
});
|
||||
view.addEventListener("viewbeforehide", function () {
|
||||
hasChanges = false;
|
||||
|
||||
if (quickConnectSettingsInstance) {
|
||||
quickConnectSettingsInstance.submit();
|
||||
}
|
||||
onDestroy();
|
||||
});
|
||||
view.addEventListener("viewdestroy", function () {
|
||||
onDestroy();
|
||||
});
|
||||
|
||||
function onDestroy() {
|
||||
if (quickConnectSettingsInstance) {
|
||||
quickConnectSettingsInstance.destroy();
|
||||
quickConnectSettingsInstance = null;
|
||||
}
|
||||
});
|
||||
}
|
||||
};
|
||||
});
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue