jellyfin-web/dashboard-ui/scripts/livetvstatus.js

620 lines
17 KiB
JavaScript
Raw Normal View History

2016-08-17 13:32:39 -07:00
define(['jQuery', 'scripts/taskbutton', 'listViewStyle'], function ($, taskButton) {
2014-01-22 13:46:01 -07:00
2014-01-23 15:15:15 -07:00
function resetTuner(page, id) {
2014-05-30 12:23:56 -07:00
var message = Globalize.translate('MessageConfirmResetTuner');
2014-01-23 15:15:15 -07:00
2016-02-22 12:31:28 -07:00
require(['confirm'], function (confirm) {
2014-01-23 15:15:15 -07:00
2016-02-22 12:31:28 -07:00
confirm(message, Globalize.translate('HeaderResetTuner')).then(function () {
2014-01-23 15:15:15 -07:00
Dashboard.showLoadingMsg();
2015-12-14 08:43:03 -07:00
ApiClient.resetLiveTvTuner(id).then(function () {
2014-01-23 15:15:15 -07:00
Dashboard.hideLoadingMsg();
reload(page);
});
2016-02-22 12:31:28 -07:00
});
2014-01-23 15:15:15 -07:00
});
}
function renderTuners(page, tuners) {
var html = '';
2015-09-12 09:39:24 -07:00
if (tuners.length) {
html += '<div class="paperList">';
2014-01-23 15:15:15 -07:00
2015-09-12 09:39:24 -07:00
for (var i = 0, length = tuners.length; i < length; i++) {
2014-01-23 15:15:15 -07:00
2015-09-12 09:39:24 -07:00
var tuner = tuners[i];
2016-08-05 13:25:09 -07:00
html += '<div class="listItem">';
2014-01-23 15:15:15 -07:00
2016-08-05 13:25:09 -07:00
html += '<i class="listItemIcon md-icon">live_tv</i>';
2014-01-23 15:15:15 -07:00
2016-08-05 13:25:09 -07:00
html += '<div class="listItemBody two-line">';
2015-09-12 09:39:24 -07:00
2016-08-05 13:25:09 -07:00
html += '<h3 class="listItemBodyText">';
2015-09-12 09:39:24 -07:00
html += tuner.Name;
2016-08-05 13:25:09 -07:00
html += '</h3>';
2014-01-23 15:15:15 -07:00
2016-08-05 13:25:09 -07:00
html += '<div class="listItemBodyText secondary">';
2015-09-12 09:39:24 -07:00
html += tuner.SourceType;
html += '</div>';
2014-01-24 11:09:50 -07:00
2016-08-05 13:25:09 -07:00
html += '<div class="listItemBodyText secondary">';
2015-09-12 09:39:24 -07:00
if (tuner.Status == 'RecordingTv') {
if (tuner.ChannelName) {
2014-01-24 11:09:50 -07:00
2015-09-12 09:39:24 -07:00
html += '<a href="itemdetails.html?id=' + tuner.ChannelId + '">';
html += Globalize.translate('StatusRecordingProgram').replace('{0}', tuner.ChannelName);
html += '</a>';
} else {
2014-01-24 11:09:50 -07:00
2015-09-12 09:39:24 -07:00
html += Globalize.translate('StatusRecording');
}
2014-01-24 11:09:50 -07:00
}
2015-09-12 09:39:24 -07:00
else if (tuner.Status == 'LiveTv') {
2014-01-24 11:09:50 -07:00
2015-09-12 09:39:24 -07:00
if (tuner.ChannelName) {
2014-01-24 11:09:50 -07:00
2015-09-12 09:39:24 -07:00
html += '<a href="itemdetails.html?id=' + tuner.ChannelId + '">';
html += Globalize.translate('StatusWatchingProgram').replace('{0}', tuner.ChannelName);
html += '</a>';
} else {
2014-01-24 11:09:50 -07:00
2015-09-12 09:39:24 -07:00
html += Globalize.translate('StatusWatching');
}
2014-01-24 11:09:50 -07:00
}
2015-09-12 09:39:24 -07:00
else {
html += tuner.Status;
}
html += '</div>';
2014-01-23 15:15:15 -07:00
2016-08-05 13:25:09 -07:00
html += '</div>';
2016-03-13 00:34:17 -07:00
if (tuner.CanReset) {
2016-08-05 13:25:09 -07:00
html += '<button type="button" is="paper-icon-button-light" data-tunerid="' + tuner.Id + '" title="' + Globalize.translate('ButtonResetTuner') + '" class="btnResetTuner"><i class="md-icon">refresh</i></button>';
2016-03-13 00:34:17 -07:00
}
2016-08-05 13:25:09 -07:00
html += '</div>';
2014-01-23 15:15:15 -07:00
}
2015-09-12 09:39:24 -07:00
html += '</div>';
2014-01-23 15:15:15 -07:00
}
2015-10-16 15:21:03 -07:00
if (tuners.length) {
page.querySelector('.tunerSection').classList.remove('hide');
} else {
page.querySelector('.tunerSection').classList.add('hide');
}
2015-09-12 09:39:24 -07:00
var elem = $('.tunerList', page).html(html);
2014-01-23 15:15:15 -07:00
$('.btnResetTuner', elem).on('click', function () {
var id = this.getAttribute('data-tunerid');
resetTuner(page, id);
});
}
2015-03-12 08:51:48 -07:00
function getServiceHtml(service) {
2014-01-22 13:46:01 -07:00
2015-03-12 08:51:48 -07:00
var html = '';
html += '<div>';
2014-01-22 13:46:01 -07:00
var serviceUrl = service.HomePageUrl || '#';
2015-03-12 08:51:48 -07:00
html += '<p><a href="' + serviceUrl + '" target="_blank">' + service.Name + '</a></p>';
2014-01-22 13:46:01 -07:00
var versionHtml = service.Version || 'Unknown';
if (service.HasUpdateAvailable) {
2014-05-30 12:23:56 -07:00
versionHtml += ' <a style="margin-left: .25em;" href="' + serviceUrl + '" target="_blank">' + Globalize.translate('LiveTvUpdateAvailable') + '</a>';
2014-01-22 13:46:01 -07:00
}
else {
2014-05-30 12:23:56 -07:00
versionHtml += '<img src="css/images/checkmarkgreen.png" style="height: 17px; margin-left: 10px; margin-right: 0; position: relative; top: 5px; border-radius:3px;" /> ' + Globalize.translate('LabelVersionUpToDate');
2014-01-22 13:46:01 -07:00
}
2014-01-23 15:15:15 -07:00
2015-03-12 08:51:48 -07:00
html += '<p>' + versionHtml + '</p>';
2014-01-22 13:46:01 -07:00
2015-03-12 08:51:48 -07:00
var status = service.Status;
2014-01-22 13:46:01 -07:00
2015-03-12 08:51:48 -07:00
if (service.Status == 'Ok') {
2014-01-22 13:46:01 -07:00
status = '<span style="color:green;">' + status + '</span>';
} else {
2015-03-12 08:51:48 -07:00
if (service.StatusMessage) {
status += ' (' + service.StatusMessage + ')';
2014-01-22 13:46:01 -07:00
}
status = '<span style="color:red;">' + status + '</span>';
}
2015-03-12 08:51:48 -07:00
html += '<p>' + Globalize.translate('ValueStatus', status) + '</p>';
html += '</div>';
return html;
}
function loadPage(page, liveTvInfo) {
if (liveTvInfo.IsEnabled) {
$('.liveTvStatusContent', page).show();
} else {
$('.liveTvStatusContent', page).hide();
}
2015-07-20 21:22:46 -07:00
var servicesToDisplay = liveTvInfo.Services.filter(function (s) {
return s.IsVisible;
});
if (servicesToDisplay.length) {
$('.servicesSection', page).show();
} else {
$('.servicesSection', page).hide();
}
2016-03-06 11:09:20 -07:00
$('.servicesList', page).html(servicesToDisplay.map(getServiceHtml).join(''));
2015-03-12 08:51:48 -07:00
var tuners = [];
for (var i = 0, length = liveTvInfo.Services.length; i < length; i++) {
for (var j = 0, numTuners = liveTvInfo.Services[i].Tuners.length; j < numTuners; j++) {
tuners.push(liveTvInfo.Services[i].Tuners[j]);
}
}
2014-01-22 13:46:01 -07:00
2015-03-12 08:51:48 -07:00
renderTuners(page, tuners);
2014-01-23 15:15:15 -07:00
2015-12-14 08:43:03 -07:00
ApiClient.getNamedConfiguration("livetv").then(function (config) {
2015-07-20 21:22:46 -07:00
renderDevices(page, config.TunerHosts);
2015-07-23 06:23:22 -07:00
renderProviders(page, config.ListingProviders);
2015-07-20 21:22:46 -07:00
});
2014-01-22 13:46:01 -07:00
Dashboard.hideLoadingMsg();
}
2015-07-20 21:22:46 -07:00
function renderDevices(page, devices) {
var html = '';
2015-08-20 14:58:07 -07:00
if (devices.length) {
html += '<div class="paperList">';
2015-07-20 21:22:46 -07:00
2015-08-20 14:58:07 -07:00
for (var i = 0, length = devices.length; i < length; i++) {
2015-07-20 21:22:46 -07:00
2015-08-20 14:58:07 -07:00
var device = devices[i];
2015-07-25 11:11:46 -07:00
2015-08-20 14:58:07 -07:00
var href = 'livetvtunerprovider-' + device.Type + '.html?id=' + device.Id;
2015-07-25 11:11:46 -07:00
2016-08-05 13:25:09 -07:00
html += '<div class="listItem">';
2015-07-20 21:22:46 -07:00
2016-08-05 13:25:09 -07:00
html += '<i class="listItemIcon md-icon">live_tv</i>';
2015-07-20 21:22:46 -07:00
2016-08-05 13:25:09 -07:00
html += '<div class="listItemBody two-line">';
2015-08-20 14:58:07 -07:00
html += '<a class="clearLink" href="' + href + '">';
2016-08-05 13:25:09 -07:00
html += '<h3 class="listItemBodyText">';
2016-03-13 00:34:17 -07:00
html += device.FriendlyName || getTunerName(device.Type);
2016-08-05 13:25:09 -07:00
html += '</h3>';
2015-07-20 21:22:46 -07:00
2016-08-05 13:25:09 -07:00
html += '<div class="listItemBodyText secondary">';
2015-08-20 14:58:07 -07:00
html += device.Url;
html += '</div>';
html += '</a>';
2016-08-05 13:25:09 -07:00
html += '</div>';
2015-07-20 21:22:46 -07:00
2016-08-05 13:25:09 -07:00
html += '<button type="button" is="paper-icon-button-light" class="btnDeleteDevice" data-id="' + device.Id + '" title="' + Globalize.translate('ButtonDelete') + '"><i class="md-icon">delete</i></button>';
html += '</div>';
2015-08-20 14:58:07 -07:00
}
2015-07-20 21:22:46 -07:00
2015-08-20 14:58:07 -07:00
html += '</div>';
}
var elem = $('.devicesList', page).html(html);
2015-07-20 21:22:46 -07:00
$('.btnDeleteDevice', elem).on('click', function () {
var id = this.getAttribute('data-id');
deleteDevice(page, id);
});
}
function deleteDevice(page, id) {
var message = Globalize.translate('MessageConfirmDeleteTunerDevice');
2016-02-22 12:31:28 -07:00
require(['confirm'], function (confirm) {
2015-07-20 21:22:46 -07:00
2016-02-22 12:31:28 -07:00
confirm(message, Globalize.translate('HeaderDeleteDevice')).then(function () {
2015-07-20 21:22:46 -07:00
Dashboard.showLoadingMsg();
ApiClient.ajax({
type: "DELETE",
url: ApiClient.getUrl('LiveTv/TunerHosts', {
Id: id
})
2015-12-14 08:43:03 -07:00
}).then(function () {
2015-07-20 21:22:46 -07:00
reload(page);
});
2016-02-22 12:31:28 -07:00
});
2015-07-20 21:22:46 -07:00
});
}
2014-01-23 15:15:15 -07:00
function reload(page) {
2014-01-22 13:46:01 -07:00
Dashboard.showLoadingMsg();
2015-12-14 08:43:03 -07:00
ApiClient.getLiveTvInfo().then(function (liveTvInfo) {
2014-01-22 13:46:01 -07:00
loadPage(page, liveTvInfo);
2016-07-27 22:19:24 -07:00
}, function () {
loadPage(page, {
Services: [],
IsEnabled: true
});
2014-01-22 13:46:01 -07:00
});
2014-01-23 15:15:15 -07:00
}
2015-07-20 21:22:46 -07:00
function submitAddDeviceForm(page) {
2015-07-20 21:22:46 -07:00
page.querySelector('.dlgAddDevice').close();
Dashboard.showLoadingMsg();
2015-07-20 21:22:46 -07:00
ApiClient.ajax({
type: "POST",
url: ApiClient.getUrl('LiveTv/TunerHosts'),
data: JSON.stringify({
Type: $('#selectTunerDeviceType', page).val(),
Url: $('#txtDevicePath', page).val()
}),
contentType: "application/json"
2015-12-14 08:43:03 -07:00
}).then(function () {
2014-01-22 13:46:01 -07:00
2015-07-20 21:22:46 -07:00
reload(page);
2015-07-23 06:23:22 -07:00
2015-12-14 08:43:03 -07:00
}, function () {
2015-07-23 06:23:22 -07:00
Dashboard.alert({
message: Globalize.translate('ErrorAddingTunerDevice')
});
});
}
function renderProviders(page, providers) {
var html = '';
2015-08-20 14:58:07 -07:00
if (providers.length) {
html += '<div class="paperList">';
2015-07-23 06:23:22 -07:00
2015-08-20 14:58:07 -07:00
for (var i = 0, length = providers.length; i < length; i++) {
2015-07-23 06:23:22 -07:00
2015-08-20 14:58:07 -07:00
var provider = providers[i];
2016-08-05 13:25:09 -07:00
html += '<div class="listItem">';
2015-07-23 06:23:22 -07:00
2016-08-05 13:25:09 -07:00
html += '<i class="listItemIcon md-icon">dvr</i>';
2015-07-23 06:23:22 -07:00
2016-08-05 13:25:09 -07:00
html += '<div class="listItemBody two-line">';
2015-07-23 06:23:22 -07:00
2015-08-21 19:59:10 -07:00
html += '<a class="clearLink" href="' + getProviderConfigurationUrl(provider.Type) + '&id=' + provider.Id + '">';
2015-08-20 14:58:07 -07:00
2016-08-05 13:25:09 -07:00
html += '<h3 class="listItemBodyText">';
2015-08-20 14:58:07 -07:00
html += getProviderName(provider.Type);
2016-08-05 13:25:09 -07:00
html += '</h3>';
2015-08-20 14:58:07 -07:00
html += '</a>';
2016-08-05 13:25:09 -07:00
html += '</div>';
html += '<button type="button" is="paper-icon-button-light" class="btnOptions" data-id="' + provider.Id + '"><i class="md-icon">more_vert</i></button>';
html += '</div>';
2015-08-20 14:58:07 -07:00
}
html += '</div>';
}
2015-07-23 06:23:22 -07:00
2015-08-20 14:58:07 -07:00
var elem = $('.providerList', page).html(html);
2015-07-23 06:23:22 -07:00
2016-06-07 22:24:25 -07:00
$('.btnOptions', elem).on('click', function () {
2015-07-23 06:23:22 -07:00
var id = this.getAttribute('data-id');
2016-06-07 22:24:25 -07:00
showProviderOptions(page, id, this);
});
}
2016-06-09 09:13:25 -07:00
function showProviderOptions(page, providerId, button) {
2016-06-07 22:24:25 -07:00
var items = [];
items.push({
name: Globalize.translate('ButtonDelete'),
id: 'delete'
});
items.push({
name: Globalize.translate('MapChannels'),
id: 'map'
});
require(['actionsheet'], function (actionsheet) {
actionsheet.show({
items: items,
positionTo: button
}).then(function (id) {
switch (id) {
case 'delete':
2016-06-09 09:13:25 -07:00
deleteProvider(page, providerId);
2016-06-07 22:24:25 -07:00
break;
case 'map':
2016-06-09 09:13:25 -07:00
mapChannels(page, providerId);
2016-06-07 22:24:25 -07:00
break;
default:
break;
}
});
2015-07-23 06:23:22 -07:00
});
}
2016-06-08 14:04:52 -07:00
function mapChannels(page, providerId) {
require(['components/channelmapper/channelmapper'], function (channelmapper) {
2016-06-09 23:54:03 -07:00
new channelmapper({
2016-06-08 14:04:52 -07:00
serverId: ApiClient.serverInfo().Id,
providerId: providerId
2016-06-09 23:54:03 -07:00
}).show();
2016-06-08 14:04:52 -07:00
});
}
2015-07-23 06:23:22 -07:00
function deleteProvider(page, id) {
var message = Globalize.translate('MessageConfirmDeleteGuideProvider');
2016-02-22 12:31:28 -07:00
require(['confirm'], function (confirm) {
2015-07-23 06:23:22 -07:00
2016-02-22 12:31:28 -07:00
confirm(message, Globalize.translate('HeaderDeleteProvider')).then(function () {
2015-07-23 06:23:22 -07:00
Dashboard.showLoadingMsg();
ApiClient.ajax({
type: "DELETE",
url: ApiClient.getUrl('LiveTv/ListingProviders', {
Id: id
})
2015-12-14 08:43:03 -07:00
}).then(function () {
reload(page);
}, function () {
2015-07-23 06:23:22 -07:00
reload(page);
});
2016-02-22 12:31:28 -07:00
});
});
2015-07-23 06:23:22 -07:00
}
2015-07-25 11:42:39 -07:00
function getTunerName(providerId) {
providerId = providerId.toLowerCase();
switch (providerId) {
case 'm3u':
2015-08-23 19:08:20 -07:00
return 'M3U Playlist';
2015-07-25 11:42:39 -07:00
case 'hdhomerun':
return 'HDHomerun';
2016-03-13 00:34:17 -07:00
case 'satip':
return 'DVB';
2015-07-25 11:42:39 -07:00
default:
return 'Unknown';
}
}
2015-07-23 06:23:22 -07:00
function getProviderName(providerId) {
providerId = providerId.toLowerCase();
2015-07-23 06:23:22 -07:00
switch (providerId) {
case 'schedulesdirect':
return 'Schedules Direct';
2016-06-01 23:40:16 -07:00
case 'xmltv':
return 'Xml TV';
2015-08-10 12:55:33 -07:00
case 'emby':
return 'Emby Guide';
2015-07-23 06:23:22 -07:00
default:
return 'Unknown';
}
}
function getProviderConfigurationUrl(providerId) {
providerId = providerId.toLowerCase();
switch (providerId) {
2016-06-01 23:40:16 -07:00
case 'xmltv':
return 'livetvguideprovider.html?type=xmltv';
2015-07-23 06:23:22 -07:00
case 'schedulesdirect':
2015-08-21 19:59:10 -07:00
return 'livetvguideprovider.html?type=schedulesdirect';
2015-08-10 10:37:50 -07:00
case 'emby':
2015-08-21 19:59:10 -07:00
return 'livetvguideprovider.html?type=emby';
2015-07-23 06:23:22 -07:00
default:
break;
}
}
function addProvider(button) {
var menuItems = [];
2015-08-15 13:33:53 -07:00
menuItems.push({
name: 'Schedules Direct',
id: 'SchedulesDirect'
});
2015-08-10 10:37:50 -07:00
2015-08-15 11:46:57 -07:00
//menuItems.push({
// name: 'Emby Guide',
// id: 'emby'
//});
2015-07-23 06:23:22 -07:00
2016-06-01 23:40:16 -07:00
menuItems.push({
name: 'Xml TV',
id: 'xmltv'
});
2015-08-25 19:13:28 -07:00
menuItems.push({
name: Globalize.translate('ButtonOther'),
id: 'other'
});
2016-01-30 21:04:00 -07:00
require(['actionsheet'], function (actionsheet) {
2015-07-23 06:23:22 -07:00
2016-01-30 21:04:00 -07:00
actionsheet.show({
2015-07-23 06:23:22 -07:00
items: menuItems,
positionTo: button,
callback: function (id) {
2015-08-25 19:13:28 -07:00
if (id == 'other') {
Dashboard.alert({
message: Globalize.translate('ForAdditionalLiveTvOptions')
});
} else {
Dashboard.navigate(getProviderConfigurationUrl(id));
}
2015-07-23 06:23:22 -07:00
}
});
});
2015-07-20 21:22:46 -07:00
}
2015-07-25 11:11:46 -07:00
function addDevice(button) {
var menuItems = [];
2016-04-01 21:29:48 -07:00
//menuItems.push({
// name: getTunerName('satip'),
// id: 'satip'
//});
2016-03-13 00:34:17 -07:00
2015-07-25 11:11:46 -07:00
menuItems.push({
2015-07-25 11:42:39 -07:00
name: 'HDHomerun',
2015-07-25 11:11:46 -07:00
id: 'hdhomerun'
});
menuItems.push({
2015-08-23 19:08:20 -07:00
name: getTunerName('m3u'),
2015-07-25 11:11:46 -07:00
id: 'm3u'
});
2015-08-25 19:13:28 -07:00
menuItems.push({
name: Globalize.translate('ButtonOther'),
id: 'other'
});
2016-01-30 21:04:00 -07:00
require(['actionsheet'], function (actionsheet) {
2015-07-25 11:11:46 -07:00
2016-01-30 21:04:00 -07:00
actionsheet.show({
2015-07-25 11:11:46 -07:00
items: menuItems,
positionTo: button,
callback: function (id) {
2015-08-25 19:13:28 -07:00
if (id == 'other') {
Dashboard.alert({
message: Globalize.translate('ForAdditionalLiveTvOptions')
});
} else {
Dashboard.navigate('livetvtunerprovider-' + id + '.html');
}
2015-07-25 11:11:46 -07:00
}
});
});
}
2016-04-12 23:02:07 -07:00
function getTabs() {
return [
{
href: 'livetvstatus.html',
name: Globalize.translate('TabDevices')
},
{
href: 'livetvsettings.html',
name: Globalize.translate('TabSettings')
},
{
href: 'appservices.html?context=livetv',
name: Globalize.translate('TabServices')
}];
}
2015-09-01 07:01:59 -07:00
$(document).on('pageinit', "#liveTvStatusPage", function () {
var page = this;
2015-07-20 21:22:46 -07:00
$('.btnAddDevice', page).on('click', function () {
2015-07-25 11:11:46 -07:00
addDevice(this);
2015-07-20 21:22:46 -07:00
});
2015-07-22 22:25:55 -07:00
$('.formAddDevice', page).on('submit', function () {
2015-07-20 21:22:46 -07:00
submitAddDeviceForm(page);
return false;
2015-01-20 13:19:54 -07:00
});
2015-07-23 06:23:22 -07:00
$('.btnAddProvider', page).on('click', function () {
addProvider(this);
});
2015-09-24 10:08:10 -07:00
}).on('pageshow', "#liveTvStatusPage", function () {
2015-07-20 21:22:46 -07:00
2016-04-12 23:02:07 -07:00
LibraryMenu.setTabs('livetvadmin', 0, getTabs);
2015-07-20 21:22:46 -07:00
var page = this;
reload(page);
2015-09-12 09:39:24 -07:00
2015-10-16 15:21:03 -07:00
// on here
2016-08-17 13:32:39 -07:00
taskButton({
2015-10-16 15:21:03 -07:00
mode: 'on',
progressElem: page.querySelector('.refreshGuideProgress'),
2016-08-17 13:32:39 -07:00
taskKey: 'RefreshGuide',
button: page.querySelector('.btnRefresh')
2015-10-16 15:21:03 -07:00
});
}).on('pagehide', "#liveTvStatusPage", function () {
var page = this;
// off here
2016-08-17 13:32:39 -07:00
taskButton({
mode: 'off',
progressElem: page.querySelector('.refreshGuideProgress'),
taskKey: 'RefreshGuide',
button: page.querySelector('.btnRefresh')
2015-10-16 15:21:03 -07:00
});
2014-01-22 13:46:01 -07:00
});
});