2022-01-30 00:27:26 +03:00
|
|
|
import escapeHtml from 'escape-html';
|
2020-08-14 08:46:34 +02:00
|
|
|
import loading from '../../../components/loading/loading';
|
2020-08-16 20:24:45 +02:00
|
|
|
import { appRouter } from '../../../components/appRouter';
|
2020-08-14 08:46:34 +02:00
|
|
|
import layoutManager from '../../../components/layoutManager';
|
|
|
|
import libraryMenu from '../../../scripts/libraryMenu';
|
|
|
|
import appSettings from '../../../scripts/settings/appSettings';
|
|
|
|
import focusManager from '../../../components/focusManager';
|
|
|
|
import globalize from '../../../scripts/globalize';
|
|
|
|
import actionSheet from '../../../components/actionSheet/actionSheet';
|
|
|
|
import dom from '../../../scripts/dom';
|
|
|
|
import browser from '../../../scripts/browser';
|
|
|
|
import 'material-design-icons-iconfont';
|
2020-11-06 00:00:34 +00:00
|
|
|
import '../../../assets/css/flexstyles.scss';
|
2020-08-14 08:46:34 +02:00
|
|
|
import '../../../elements/emby-scroller/emby-scroller';
|
|
|
|
import '../../../elements/emby-itemscontainer/emby-itemscontainer';
|
2021-01-26 16:25:38 -05:00
|
|
|
import '../../../components/cardbuilder/card.scss';
|
2020-08-14 08:46:34 +02:00
|
|
|
import '../../../elements/emby-button/emby-button';
|
2022-04-10 02:22:13 -04:00
|
|
|
import Dashboard from '../../../utils/dashboard';
|
2020-10-17 19:08:56 +01:00
|
|
|
import ServerConnections from '../../../components/ServerConnections';
|
2020-10-18 15:18:15 +01:00
|
|
|
import alert from '../../../components/alert';
|
2021-02-16 22:52:28 +09:00
|
|
|
import cardBuilder from '../../../components/cardbuilder/cardBuilder';
|
2022-10-21 15:05:50 -04:00
|
|
|
import { ConnectionState } from '../../../utils/jellyfin-apiclient/ConnectionState.ts';
|
2020-07-09 16:20:32 +01:00
|
|
|
|
|
|
|
/* eslint-disable indent */
|
2018-10-23 01:05:09 +03:00
|
|
|
|
2020-07-15 09:29:15 +01:00
|
|
|
const enableFocusTransform = !browser.slow && !browser.edge;
|
2019-11-11 12:28:27 +03:00
|
|
|
|
2018-10-23 01:05:09 +03:00
|
|
|
function renderSelectServerItems(view, servers) {
|
2020-07-15 09:29:15 +01:00
|
|
|
const items = servers.map(function (server) {
|
2019-11-06 13:43:39 +03:00
|
|
|
return {
|
|
|
|
name: server.Name,
|
2022-10-20 17:38:33 -04:00
|
|
|
icon: 'storage',
|
2020-05-04 12:44:12 +02:00
|
|
|
cardType: '',
|
2019-11-06 13:43:39 +03:00
|
|
|
id: server.Id,
|
|
|
|
server: server
|
|
|
|
};
|
2019-04-10 00:47:58 -07:00
|
|
|
});
|
2020-07-15 09:29:15 +01:00
|
|
|
let html = items.map(function (item) {
|
2019-11-11 12:28:27 +03:00
|
|
|
// TODO move card creation code to Card component
|
2022-10-20 17:38:33 -04:00
|
|
|
const cardImageContainer = '<span class="cardImageIcon material-icons ' + item.icon + '" aria-hidden="true"></span>';
|
2020-07-15 09:29:15 +01:00
|
|
|
let cssClass = 'card overflowSquareCard loginSquareCard scalableCard overflowSquareCard-scalable';
|
2019-11-06 13:43:39 +03:00
|
|
|
|
|
|
|
if (layoutManager.tv) {
|
2020-05-04 12:44:12 +02:00
|
|
|
cssClass += ' show-focus';
|
2019-11-11 12:28:27 +03:00
|
|
|
|
|
|
|
if (enableFocusTransform) {
|
2020-05-04 12:44:12 +02:00
|
|
|
cssClass += ' show-animation';
|
2019-11-11 12:28:27 +03:00
|
|
|
}
|
2019-11-06 13:43:39 +03:00
|
|
|
}
|
|
|
|
|
2020-07-15 09:29:15 +01:00
|
|
|
const cardBoxCssClass = 'cardBox';
|
2019-11-11 12:28:27 +03:00
|
|
|
|
2020-07-15 09:29:15 +01:00
|
|
|
const innerOpening = '<div class="' + cardBoxCssClass + '">';
|
|
|
|
let cardContainer = '';
|
2020-05-04 12:44:12 +02:00
|
|
|
cardContainer += '<button raised class="' + cssClass + '" style="display:inline-block;" data-id="' + item.id + '" data-url="' + (item.url || '') + '" data-cardtype="' + item.cardType + '">';
|
2019-11-06 13:43:39 +03:00
|
|
|
cardContainer += innerOpening;
|
2019-11-11 12:28:27 +03:00
|
|
|
cardContainer += '<div class="cardScalable">';
|
2019-11-06 13:43:39 +03:00
|
|
|
cardContainer += '<div class="cardPadder cardPadder-square">';
|
|
|
|
cardContainer += '</div>';
|
|
|
|
cardContainer += '<div class="cardContent">';
|
2021-04-13 22:27:11 +03:00
|
|
|
cardContainer += `<div class="cardImageContainer coveredImage ${cardBuilder.getDefaultBackgroundClass()}">`;
|
2019-11-06 13:43:39 +03:00
|
|
|
cardContainer += cardImageContainer;
|
|
|
|
cardContainer += '</div>';
|
|
|
|
cardContainer += '</div>';
|
|
|
|
cardContainer += '</div>';
|
|
|
|
cardContainer += '<div class="cardFooter">';
|
2022-01-30 00:27:26 +03:00
|
|
|
cardContainer += '<div class="cardText cardTextCentered">' + escapeHtml(item.name) + '</div>';
|
2019-11-06 13:43:39 +03:00
|
|
|
cardContainer += '</div></div></button>';
|
|
|
|
return cardContainer;
|
2020-05-04 12:44:12 +02:00
|
|
|
}).join('');
|
2020-07-15 09:29:15 +01:00
|
|
|
const itemsContainer = view.querySelector('.servers');
|
2019-11-06 13:43:39 +03:00
|
|
|
|
2019-04-10 00:47:58 -07:00
|
|
|
if (!items.length) {
|
2020-05-04 12:44:12 +02:00
|
|
|
html = '<p>' + globalize.translate('MessageNoServersAvailable') + '</p>';
|
2019-04-10 00:47:58 -07:00
|
|
|
}
|
2019-11-06 13:43:39 +03:00
|
|
|
|
2019-04-10 00:47:58 -07:00
|
|
|
itemsContainer.innerHTML = html;
|
|
|
|
loading.hide();
|
2018-10-23 01:05:09 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
function updatePageStyle(view, params) {
|
2020-05-04 12:44:12 +02:00
|
|
|
if (params.showuser == '1') {
|
|
|
|
view.classList.add('libraryPage');
|
|
|
|
view.classList.remove('standalonePage');
|
|
|
|
view.classList.add('noSecondaryNavPage');
|
2019-04-10 00:47:58 -07:00
|
|
|
} else {
|
2020-05-04 12:44:12 +02:00
|
|
|
view.classList.add('standalonePage');
|
|
|
|
view.classList.remove('libraryPage');
|
|
|
|
view.classList.remove('noSecondaryNavPage');
|
2019-04-10 00:47:58 -07:00
|
|
|
}
|
2018-10-23 01:05:09 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
function alertText(text) {
|
|
|
|
alertTextWithOptions({
|
|
|
|
text: text
|
2019-04-10 00:47:58 -07:00
|
|
|
});
|
2018-10-23 01:05:09 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
function alertTextWithOptions(options) {
|
2020-10-18 15:18:15 +01:00
|
|
|
alert(options);
|
2018-10-23 01:05:09 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
function showServerConnectionFailure() {
|
2020-05-04 12:44:12 +02:00
|
|
|
alertText(globalize.translate('MessageUnableToConnectToServer'));
|
2018-10-23 01:05:09 +03:00
|
|
|
}
|
2019-01-16 15:01:17 +09:00
|
|
|
|
2020-07-09 16:20:32 +01:00
|
|
|
export default function (view, params) {
|
2018-10-23 01:05:09 +03:00
|
|
|
function connectToServer(server) {
|
2019-04-10 00:47:58 -07:00
|
|
|
loading.show();
|
2020-10-17 19:08:56 +01:00
|
|
|
ServerConnections.connectToServer(server, {
|
2018-10-23 01:05:09 +03:00
|
|
|
enableAutoLogin: appSettings.enableAutoLogin()
|
2019-11-06 13:43:39 +03:00
|
|
|
}).then(function (result) {
|
2018-10-23 01:05:09 +03:00
|
|
|
loading.hide();
|
2020-07-15 09:29:15 +01:00
|
|
|
const apiClient = result.ApiClient;
|
2019-11-06 13:43:39 +03:00
|
|
|
|
2018-10-23 01:05:09 +03:00
|
|
|
switch (result.State) {
|
2022-10-21 15:05:50 -04:00
|
|
|
case ConnectionState.SignedIn:
|
2019-04-10 00:47:58 -07:00
|
|
|
Dashboard.onServerChanged(apiClient.getCurrentUserId(), apiClient.accessToken(), apiClient);
|
2020-05-04 12:44:12 +02:00
|
|
|
Dashboard.navigate('home.html');
|
2018-10-23 01:05:09 +03:00
|
|
|
break;
|
2019-11-06 13:43:39 +03:00
|
|
|
|
2022-10-21 15:05:50 -04:00
|
|
|
case ConnectionState.ServerSignIn:
|
2019-04-10 00:47:58 -07:00
|
|
|
Dashboard.onServerChanged(null, null, apiClient);
|
2020-05-04 12:44:12 +02:00
|
|
|
Dashboard.navigate('login.html?serverid=' + result.Servers[0].Id);
|
2018-10-23 01:05:09 +03:00
|
|
|
break;
|
2019-11-06 13:43:39 +03:00
|
|
|
|
2022-10-21 15:05:50 -04:00
|
|
|
case ConnectionState.ServerUpdateNeeded:
|
2018-10-23 01:05:09 +03:00
|
|
|
alertTextWithOptions({
|
2020-05-04 12:44:12 +02:00
|
|
|
text: globalize.translate('core#ServerUpdateNeeded', 'https://github.com/jellyfin/jellyfin'),
|
|
|
|
html: globalize.translate('core#ServerUpdateNeeded', '<a href="https://github.com/jellyfin/jellyfin">https://github.com/jellyfin/jellyfin</a>')
|
2018-10-23 01:05:09 +03:00
|
|
|
});
|
|
|
|
break;
|
2019-11-06 13:43:39 +03:00
|
|
|
|
2018-10-23 01:05:09 +03:00
|
|
|
default:
|
2019-04-10 00:47:58 -07:00
|
|
|
showServerConnectionFailure();
|
2018-10-23 01:05:09 +03:00
|
|
|
}
|
2019-11-06 13:43:39 +03:00
|
|
|
});
|
2018-10-23 01:05:09 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
function deleteServer(server) {
|
2019-04-10 00:47:58 -07:00
|
|
|
loading.show();
|
2020-10-17 19:08:56 +01:00
|
|
|
ServerConnections.deleteServer(server.Id).then(function () {
|
2019-04-10 00:47:58 -07:00
|
|
|
loading.hide();
|
|
|
|
loadServers();
|
|
|
|
});
|
2018-10-23 01:05:09 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
function onServerClick(server) {
|
2020-07-15 09:29:15 +01:00
|
|
|
const menuItems = [];
|
2018-10-23 01:05:09 +03:00
|
|
|
menuItems.push({
|
2020-05-04 12:44:12 +02:00
|
|
|
name: globalize.translate('Connect'),
|
|
|
|
id: 'connect'
|
2019-04-10 00:47:58 -07:00
|
|
|
});
|
|
|
|
menuItems.push({
|
2020-05-04 12:44:12 +02:00
|
|
|
name: globalize.translate('Delete'),
|
|
|
|
id: 'delete'
|
2018-10-23 01:05:09 +03:00
|
|
|
});
|
2019-01-16 13:42:03 +09:00
|
|
|
actionSheet.show({
|
2018-10-23 01:05:09 +03:00
|
|
|
items: menuItems,
|
|
|
|
title: server.Name
|
2019-11-06 13:43:39 +03:00
|
|
|
}).then(function (id) {
|
2018-10-23 01:05:09 +03:00
|
|
|
switch (id) {
|
2020-05-04 12:44:12 +02:00
|
|
|
case 'connect':
|
2018-10-23 01:05:09 +03:00
|
|
|
connectToServer(server);
|
|
|
|
break;
|
2019-11-06 13:43:39 +03:00
|
|
|
|
2020-05-04 12:44:12 +02:00
|
|
|
case 'delete':
|
2018-10-23 01:05:09 +03:00
|
|
|
deleteServer(server);
|
|
|
|
}
|
2019-11-06 13:43:39 +03:00
|
|
|
});
|
2018-10-23 01:05:09 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
function onServersRetrieved(result) {
|
2019-04-10 00:47:58 -07:00
|
|
|
servers = result;
|
|
|
|
renderSelectServerItems(view, result);
|
2019-11-06 13:43:39 +03:00
|
|
|
|
2019-04-10 00:47:58 -07:00
|
|
|
if (layoutManager.tv) {
|
|
|
|
focusManager.autoFocus(view);
|
|
|
|
}
|
2018-10-23 01:05:09 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
function loadServers() {
|
2019-04-10 00:47:58 -07:00
|
|
|
loading.show();
|
2020-10-17 19:08:56 +01:00
|
|
|
ServerConnections.getAvailableServers().then(onServersRetrieved);
|
2018-10-23 01:05:09 +03:00
|
|
|
}
|
2019-04-10 00:47:58 -07:00
|
|
|
|
2020-07-15 09:29:15 +01:00
|
|
|
let servers;
|
2019-01-16 14:55:32 +09:00
|
|
|
updatePageStyle(view, params);
|
2020-05-04 12:44:12 +02:00
|
|
|
view.addEventListener('viewshow', function (e) {
|
2020-07-15 09:29:15 +01:00
|
|
|
const isRestored = e.detail.isRestored;
|
2022-03-31 14:36:09 -04:00
|
|
|
libraryMenu.setTitle(null);
|
2020-07-19 04:36:47 +02:00
|
|
|
libraryMenu.setTransparentMenu(true);
|
2019-11-06 13:43:39 +03:00
|
|
|
|
|
|
|
if (!isRestored) {
|
|
|
|
loadServers();
|
|
|
|
}
|
2019-04-10 00:47:58 -07:00
|
|
|
});
|
2020-05-04 12:44:12 +02:00
|
|
|
view.querySelector('.servers').addEventListener('click', function (e) {
|
2020-07-15 09:29:15 +01:00
|
|
|
const card = dom.parentWithClass(e.target, 'card');
|
2019-11-06 13:43:39 +03:00
|
|
|
|
2018-10-23 01:05:09 +03:00
|
|
|
if (card) {
|
2020-07-15 09:29:15 +01:00
|
|
|
const url = card.getAttribute('data-url');
|
2019-11-06 13:43:39 +03:00
|
|
|
|
2019-04-10 00:47:58 -07:00
|
|
|
if (url) {
|
|
|
|
appRouter.show(url);
|
|
|
|
} else {
|
2020-07-15 09:29:15 +01:00
|
|
|
const id = card.getAttribute('data-id');
|
2019-11-06 13:43:39 +03:00
|
|
|
onServerClick(servers.filter(function (s) {
|
2019-04-10 00:47:58 -07:00
|
|
|
return s.Id === id;
|
|
|
|
})[0]);
|
2018-10-23 01:05:09 +03:00
|
|
|
}
|
|
|
|
}
|
2019-11-06 13:43:39 +03:00
|
|
|
});
|
2020-07-15 09:29:15 +01:00
|
|
|
}
|
2020-07-09 16:20:32 +01:00
|
|
|
|
|
|
|
/* eslint-enable indent */
|