1
0
Fork 0
mirror of https://github.com/jellyfin/jellyfin-web synced 2025-03-30 19:56:21 +00:00

Migrated livetvtuner.js file to es6 module

This commit is contained in:
matjaz321 2020-07-29 22:18:34 +02:00
parent ade438f53d
commit c5e6b5d95d
2 changed files with 217 additions and 220 deletions

View file

@ -193,6 +193,7 @@
"src/controllers/playback/queue/index.js",
"src/controllers/playback/video/index.js",
"src/controllers/searchpage.js",
"src/controllers/livetvtuner.js",
"src/controllers/shows/episodes.js",
"src/controllers/shows/tvgenres.js",
"src/controllers/shows/tvlatest.js",

View file

@ -1,14 +1,19 @@
define(['globalize', 'loading', 'libraryMenu', 'dom', 'emby-input', 'emby-button', 'emby-checkbox', 'emby-select'], function (globalize, loading, libraryMenu, dom) {
'use strict';
import globalize from 'globalize';
import loading from 'loading';
import dom from 'dom';
import 'emby-input';
import 'emby-button';
import 'emby-checkbox';
import 'emby-select';
function isM3uVariant(type) {
function isM3uVariant(type) {
return ['nextpvr'].indexOf(type || '') !== -1;
}
}
function fillTypes(view, currentId) {
function fillTypes(view, currentId) {
return ApiClient.getJSON(ApiClient.getUrl('LiveTv/TunerHosts/Types')).then(function (types) {
var selectType = view.querySelector('.selectType');
var html = '';
const selectType = view.querySelector('.selectType');
let html = '';
html += types.map(function (tuner) {
return '<option value="' + tuner.Id + '">' + tuner.Name + '</option>';
}).join('');
@ -20,26 +25,26 @@ define(['globalize', 'loading', 'libraryMenu', 'dom', 'emby-input', 'emby-button
selectType.value = '';
onTypeChange.call(selectType);
});
}
}
function reload(view, providerId) {
function reload(view, providerId) {
view.querySelector('.txtDevicePath').value = '';
view.querySelector('.chkFavorite').checked = false;
view.querySelector('.txtDevicePath').value = '';
if (providerId) {
ApiClient.getNamedConfiguration('livetv').then(function (config) {
var info = config.TunerHosts.filter(function (i) {
const info = config.TunerHosts.filter(function (i) {
return i.Id === providerId;
})[0];
fillTunerHostInfo(view, info);
});
}
}
}
function fillTunerHostInfo(view, info) {
var selectType = view.querySelector('.selectType');
var type = info.Type || '';
function fillTunerHostInfo(view, info) {
const selectType = view.querySelector('.selectType');
let type = info.Type || '';
if (info.Source && isM3uVariant(info.Source)) {
type = info.Source;
@ -55,11 +60,11 @@ define(['globalize', 'loading', 'libraryMenu', 'dom', 'emby-input', 'emby-button
view.querySelector('.chkTranscode').checked = info.AllowHWTranscoding;
view.querySelector('.chkStreamLoop').checked = info.EnableStreamLooping;
view.querySelector('.txtTunerCount').value = info.TunerCount || '0';
}
}
function submitForm(page) {
function submitForm(page) {
loading.show();
var info = {
const info = {
Type: page.querySelector('.selectType').value,
Url: page.querySelector('.txtDevicePath').value || null,
UserAgent: page.querySelector('.txtUserAgent').value || null,
@ -76,10 +81,8 @@ define(['globalize', 'loading', 'libraryMenu', 'dom', 'emby-input', 'emby-button
info.Type = 'm3u';
}
var id = getParameterByName('id');
if (id) {
info.Id = id;
if (getParameterByName('id')) {
info.Id = getParameterByName('id');
}
ApiClient.ajax({
@ -96,36 +99,30 @@ define(['globalize', 'loading', 'libraryMenu', 'dom', 'emby-input', 'emby-button
message: globalize.translate('ErrorSavingTvProvider')
});
});
}
}
function getRequirePromise(deps) {
return new Promise(function (resolve, reject) {
require(deps, resolve);
});
}
function getDetectedDevice() {
return getRequirePromise(['tunerPicker']).then(function (tunerPicker) {
function getDetectedDevice() {
return import('tunerPicker').then(({default: tunerPicker}) => {
return new tunerPicker().show({
serverId: ApiClient.serverId()
});
});
}
}
function onTypeChange() {
var value = this.value;
var view = dom.parentWithClass(this, 'page');
var mayIncludeUnsupportedDrmChannels = 'hdhomerun' === value;
var supportsTranscoding = 'hdhomerun' === value;
var supportsFavorites = 'hdhomerun' === value;
var supportsTunerIpAddress = 'hdhomerun' === value;
var supportsTunerFileOrUrl = 'm3u' === value;
var supportsStreamLooping = 'm3u' === value;
var supportsTunerCount = 'm3u' === value;
var supportsUserAgent = 'm3u' === value;
var suppportsSubmit = 'other' !== value;
var supportsSelectablePath = supportsTunerFileOrUrl;
var txtDevicePath = view.querySelector('.txtDevicePath');
function onTypeChange() {
const value = this.value;
const view = dom.parentWithClass(this, 'page');
const mayIncludeUnsupportedDrmChannels = 'hdhomerun' === value;
const supportsTranscoding = 'hdhomerun' === value;
const supportsFavorites = 'hdhomerun' === value;
const supportsTunerIpAddress = 'hdhomerun' === value;
const supportsTunerFileOrUrl = 'm3u' === value;
const supportsStreamLooping = 'm3u' === value;
const supportsTunerCount = 'm3u' === value;
const supportsUserAgent = 'm3u' === value;
const suppportsSubmit = 'other' !== value;
const supportsSelectablePath = supportsTunerFileOrUrl;
const txtDevicePath = view.querySelector('.txtDevicePath');
if (supportsTunerIpAddress) {
txtDevicePath.label(globalize.translate('LabelTunerIpAddress'));
@ -188,15 +185,15 @@ define(['globalize', 'loading', 'libraryMenu', 'dom', 'emby-input', 'emby-button
} else {
view.querySelector('.button-submit').classList.add('hide');
}
}
}
return function (view, params) {
export default function (view, params) {
if (!params.id) {
view.querySelector('.btnDetect').classList.remove('hide');
}
view.addEventListener('viewshow', function () {
var currentId = params.id;
const currentId = params.id;
fillTypes(view, currentId).then(function () {
reload(view, currentId);
});
@ -214,8 +211,8 @@ define(['globalize', 'loading', 'libraryMenu', 'dom', 'emby-input', 'emby-button
});
});
view.querySelector('.btnSelectPath').addEventListener('click', function () {
require(['directorybrowser'], function (directoryBrowser) {
var picker = new directoryBrowser.default();
import('directorybrowser').then(({default: directorybrowser}) => {
const picker = new directorybrowser();
picker.show({
includeFiles: true,
callback: function (path) {
@ -228,5 +225,4 @@ define(['globalize', 'loading', 'libraryMenu', 'dom', 'emby-input', 'emby-button
});
});
});
};
});
};