jellyfin-web/src/components/tunerPicker.js

178 lines
6.5 KiB
JavaScript
Raw Normal View History

2020-05-04 03:44:12 -07:00
define(['dialogHelper', 'dom', 'layoutManager', 'connectionManager', 'globalize', 'loading', 'browser', 'focusManager', 'scrollHelper', 'material-icons', 'formDialogStyle', 'emby-button', 'emby-itemscontainer', 'cardStyle'], function (dialogHelper, dom, layoutManager, connectionManager, globalize, loading, browser, focusManager, scrollHelper) {
'use strict';
2018-10-22 15:05:09 -07:00
var enableFocusTransform = !browser.slow && !browser.edge;
2018-10-22 15:05:09 -07:00
function getEditorHtml() {
2020-05-04 03:44:12 -07:00
var html = '';
2019-10-09 09:35:12 -07:00
html += '<div class="formDialogContent scrollY">';
html += '<div class="dialogContentInner dialog-content-centered">';
html += '<div class="loadingContent hide">';
2020-05-04 03:44:12 -07:00
html += '<h1>' + globalize.translate('DetectingDevices') + '...</h1>';
html += '<p>' + globalize.translate('MessagePleaseWait') + '</p>';
html += '</div>';
html += '<h1 style="margin-bottom:.25em;" class="devicesHeader hide">' + globalize.translate('HeaderNewDevices') + '</h1>';
2019-10-09 09:35:12 -07:00
html += '<div is="emby-itemscontainer" class="results vertical-wrap">';
2020-05-04 03:44:12 -07:00
html += '</div>';
html += '</div>';
return html += '</div>';
2018-10-22 15:05:09 -07:00
}
function getDeviceHtml(device) {
2019-10-09 09:35:12 -07:00
var padderClass;
2020-05-04 03:44:12 -07:00
var html = '';
var cssClass = 'card scalableCard';
var cardBoxCssClass = 'cardBox visualCardBox';
cssClass += ' backdropCard backdropCard-scalable';
padderClass = 'cardPadder-backdrop';
2019-10-09 09:35:12 -07:00
// TODO move card creation code to Card component
2019-10-09 09:35:12 -07:00
if (layoutManager.tv) {
2020-05-04 03:44:12 -07:00
cssClass += ' show-focus';
if (enableFocusTransform) {
2020-05-04 03:44:12 -07:00
cssClass += ' show-animation';
}
2019-10-09 09:35:12 -07:00
}
html += '<button type="button" class="' + cssClass + '" data-id="' + device.DeviceId + '" style="min-width:33.3333%;">';
html += '<div class="' + cardBoxCssClass + '">';
html += '<div class="cardScalable visualCardBox-cardScalable">';
html += '<div class="' + padderClass + '"></div>';
html += '<div class="cardContent searchImage">';
2020-04-25 16:37:28 -07:00
html += '<div class="cardImageContainer coveredImage"><span class="cardImageIcon material-icons dvr"></span></div>';
2020-05-04 03:44:12 -07:00
html += '</div>';
html += '</div>';
2019-10-09 09:35:12 -07:00
html += '<div class="cardFooter visualCardBox-cardFooter">';
2020-05-04 03:44:12 -07:00
html += '<div class="cardText cardTextCentered">' + getTunerName(device.Type) + '</div>';
html += '<div class="cardText cardTextCentered cardText-secondary">' + device.FriendlyName + '</div>';
2019-10-09 09:35:12 -07:00
html += '<div class="cardText cardText-secondary cardTextCentered">';
2020-05-04 03:44:12 -07:00
html += device.Url || '&nbsp;';
html += '</div>';
html += '</div>';
html += '</div>';
return html += '</button>';
2018-10-22 15:05:09 -07:00
}
function getTunerName(providerId) {
switch (providerId = providerId.toLowerCase()) {
2020-05-04 03:44:12 -07:00
case 'm3u':
return 'M3U';
2019-10-09 09:35:12 -07:00
2020-05-04 03:44:12 -07:00
case 'hdhomerun':
return 'HDHomerun';
2019-10-09 09:35:12 -07:00
2020-05-04 03:44:12 -07:00
case 'hauppauge':
return 'Hauppauge';
2019-10-09 09:35:12 -07:00
2020-05-04 03:44:12 -07:00
case 'satip':
return 'DVB';
2019-10-09 09:35:12 -07:00
2018-10-22 15:05:09 -07:00
default:
2020-05-04 03:44:12 -07:00
return 'Unknown';
2018-10-22 15:05:09 -07:00
}
}
function renderDevices(view, devices) {
2019-10-09 09:35:12 -07:00
var i;
var length;
2020-05-04 03:44:12 -07:00
var html = '';
2019-10-09 09:35:12 -07:00
for (i = 0, length = devices.length; i < length; i++) {
html += getDeviceHtml(devices[i]);
}
if (devices.length) {
2020-05-04 03:44:12 -07:00
view.querySelector('.devicesHeader').classList.remove('hide');
2019-10-09 09:35:12 -07:00
} else {
2020-05-04 03:44:12 -07:00
html = '<p><br/>' + globalize.translate('NoNewDevicesFound') + '</p>';
view.querySelector('.devicesHeader').classList.add('hide');
2019-10-09 09:35:12 -07:00
}
2020-05-04 03:44:12 -07:00
var elem = view.querySelector('.results');
2019-10-09 09:35:12 -07:00
elem.innerHTML = html;
if (layoutManager.tv) {
focusManager.autoFocus(elem);
}
2018-10-22 15:05:09 -07:00
}
function discoverDevices(view, apiClient) {
2019-10-09 09:35:12 -07:00
loading.show();
2020-05-04 03:44:12 -07:00
view.querySelector('.loadingContent').classList.remove('hide');
return ApiClient.getJSON(ApiClient.getUrl('LiveTv/Tuners/Discvover', {
2019-10-09 09:35:12 -07:00
NewDevicesOnly: true
})).then(function (devices) {
currentDevices = devices;
renderDevices(view, devices);
2020-05-04 03:44:12 -07:00
view.querySelector('.loadingContent').classList.add('hide');
2019-10-09 09:35:12 -07:00
loading.hide();
});
2018-10-22 15:05:09 -07:00
}
function tunerPicker() {
2019-10-09 09:35:12 -07:00
this.show = function (options) {
2018-10-22 15:05:09 -07:00
var dialogOptions = {
2019-10-09 09:35:12 -07:00
removeOnClose: true,
scrollY: false
2018-10-22 15:05:09 -07:00
};
2019-10-09 09:35:12 -07:00
if (layoutManager.tv) {
2020-05-04 03:44:12 -07:00
dialogOptions.size = 'fullscreen';
2019-10-09 09:35:12 -07:00
} else {
2020-05-04 03:44:12 -07:00
dialogOptions.size = 'small';
2019-10-09 09:35:12 -07:00
}
2018-10-22 15:05:09 -07:00
var dlg = dialogHelper.createDialog(dialogOptions);
2020-05-04 03:44:12 -07:00
dlg.classList.add('formDialog');
var html = '';
2019-10-09 09:35:12 -07:00
html += '<div class="formDialogHeader">';
2020-04-25 16:37:28 -07:00
html += '<button is="paper-icon-button-light" class="btnCancel autoSize" tabindex="-1"><span class="material-icons arrow_back"></span></button>';
2019-10-09 09:35:12 -07:00
html += '<h3 class="formDialogHeaderTitle">';
2020-05-04 03:44:12 -07:00
html += globalize.translate('HeaderLiveTvTunerSetup');
html += '</h3>';
html += '</div>';
2019-10-09 09:35:12 -07:00
html += getEditorHtml();
dlg.innerHTML = html;
2020-05-04 03:44:12 -07:00
dlg.querySelector('.btnCancel').addEventListener('click', function () {
2019-10-09 09:35:12 -07:00
dialogHelper.close(dlg);
2018-10-22 15:05:09 -07:00
});
var deviceResult;
2020-05-04 03:44:12 -07:00
dlg.querySelector('.results').addEventListener('click', function (e) {
var tunerCard = dom.parentWithClass(e.target, 'card');
2019-10-09 09:35:12 -07:00
2018-10-22 15:05:09 -07:00
if (tunerCard) {
2020-05-04 03:44:12 -07:00
var deviceId = tunerCard.getAttribute('data-id');
2019-10-09 09:35:12 -07:00
deviceResult = currentDevices.filter(function (d) {
return d.DeviceId === deviceId;
})[0];
dialogHelper.close(dlg);
2018-10-22 15:05:09 -07:00
}
2019-10-09 09:35:12 -07:00
});
if (layoutManager.tv) {
2020-05-04 03:44:12 -07:00
scrollHelper.centerFocus.on(dlg.querySelector('.formDialogContent'), false);
2019-10-09 09:35:12 -07:00
}
2018-10-22 15:05:09 -07:00
var apiClient = connectionManager.getApiClient(options.serverId);
2019-10-09 09:35:12 -07:00
discoverDevices(dlg, apiClient);
if (layoutManager.tv) {
2020-05-04 03:44:12 -07:00
scrollHelper.centerFocus.off(dlg.querySelector('.formDialogContent'), false);
2019-10-09 09:35:12 -07:00
}
return dialogHelper.open(dlg).then(function () {
if (deviceResult) {
return Promise.resolve(deviceResult);
}
return Promise.reject();
});
};
2018-10-22 15:05:09 -07:00
}
2019-10-09 09:35:12 -07:00
2018-10-22 15:05:09 -07:00
var currentDevices = [];
2019-10-09 09:35:12 -07:00
return tunerPicker;
});