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

Merge pull request #1771 from Camc314/migrate-to-ES6-68

Migration of themeMediaPLayer, viewSettings and notification to ES6 modules
This commit is contained in:
Anthony Lavado 2020-08-12 15:58:00 -04:00 committed by GitHub
commit c7b983a563
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 357 additions and 351 deletions

View file

@ -142,6 +142,7 @@
"src/components/metadataEditor/metadataEditor.js",
"src/components/metadataEditor/personEditor.js",
"src/components/multiSelect/multiSelect.js",
"src/components/notifications/notifications.js",
"src/components/nowPlayingBar/nowPlayingBar.js",
"src/components/playback/brightnessosd.js",
"src/components/playback/mediasession.js",
@ -187,6 +188,7 @@
"src/components/syncPlay/playbackPermissionManager.js",
"src/components/syncPlay/syncPlayManager.js",
"src/components/syncPlay/timeSyncManager.js",
"src/components/themeMediaPlayer.js",
"src/components/tabbedview/tabbedview.js",
"src/components/viewManager/viewManager.js",
"src/components/tvproviders/schedulesdirect.js",
@ -194,6 +196,7 @@
"src/components/toast/toast.js",
"src/components/upnextdialog/upnextdialog.js",
"src/components/viewContainer.js",
"src/components/viewSettings/viewSettings.js",
"src/components/castSenderApi.js",
"src/controllers/session/addServer/index.js",
"src/controllers/session/forgotPassword/index.js",
@ -221,8 +224,8 @@
"src/controllers/dashboard/metadataImages.js",
"src/controllers/dashboard/metadatanfo.js",
"src/controllers/dashboard/networking.js",
"src/controllers/dashboard/notifications/notification.js",
"src/controllers/dashboard/notifications/notifications.js",
"src/controllers/dashboard/notifications/notification/index.js",
"src/controllers/dashboard/notifications/notifications/index.js",
"src/controllers/dashboard/playback.js",
"src/controllers/dashboard/plugins/add/index.js",
"src/controllers/dashboard/plugins/installed/index.js",

View file

@ -1,10 +1,9 @@
define(['serverNotifications', 'playbackManager', 'events', 'globalize', 'require'], function (serverNotifications, playbackManager, events, globalize, require) {
'use strict';
import serverNotifications from 'serverNotifications';
import playbackManager from 'playbackManager';
import events from 'events';
import globalize from 'globalize';
playbackManager = playbackManager.default || playbackManager;
serverNotifications = serverNotifications.default || serverNotifications;
function onOneDocumentClick() {
function onOneDocumentClick() {
document.removeEventListener('click', onOneDocumentClick);
document.removeEventListener('keydown', onOneDocumentClick);
@ -13,14 +12,14 @@ define(['serverNotifications', 'playbackManager', 'events', 'globalize', 'requir
/* eslint-disable-next-line compat/compat */
Notification.requestPermission();
}
}
}
document.addEventListener('click', onOneDocumentClick);
document.addEventListener('keydown', onOneDocumentClick);
document.addEventListener('click', onOneDocumentClick);
document.addEventListener('keydown', onOneDocumentClick);
var serviceWorkerRegistration;
let serviceWorkerRegistration;
function closeAfter(notification, timeoutMs) {
function closeAfter(notification, timeoutMs) {
setTimeout(function () {
if (notification.close) {
notification.close();
@ -28,27 +27,27 @@ define(['serverNotifications', 'playbackManager', 'events', 'globalize', 'requir
notification.cancel();
}
}, timeoutMs);
}
}
function resetRegistration() {
function resetRegistration() {
/* eslint-disable-next-line compat/compat */
var serviceWorker = navigator.serviceWorker;
let serviceWorker = navigator.serviceWorker;
if (serviceWorker) {
serviceWorker.ready.then(function (registration) {
serviceWorkerRegistration = registration;
});
}
}
}
resetRegistration();
resetRegistration();
function showPersistentNotification(title, options, timeoutMs) {
function showPersistentNotification(title, options, timeoutMs) {
serviceWorkerRegistration.showNotification(title, options);
}
}
function showNonPersistentNotification(title, options, timeoutMs) {
function showNonPersistentNotification(title, options, timeoutMs) {
try {
var notif = new Notification(title, options); /* eslint-disable-line compat/compat */
let notif = new Notification(title, options); /* eslint-disable-line compat/compat */
if (notif.show) {
notif.show();
@ -65,10 +64,10 @@ define(['serverNotifications', 'playbackManager', 'events', 'globalize', 'requir
throw err;
}
}
}
}
function showNotification(options, timeoutMs, apiClient) {
var title = options.title;
function showNotification(options, timeoutMs, apiClient) {
let title = options.title;
options.data = options.data || {};
options.data.serverId = apiClient.serverInfo().Id;
@ -83,20 +82,20 @@ define(['serverNotifications', 'playbackManager', 'events', 'globalize', 'requir
}
showNonPersistentNotification(title, options, timeoutMs);
}
}
function showNewItemNotification(item, apiClient) {
function showNewItemNotification(item, apiClient) {
if (playbackManager.isPlayingLocally(['Video'])) {
return;
}
var body = item.Name;
let body = item.Name;
if (item.SeriesName) {
body = item.SeriesName + ' - ' + body;
}
var notification = {
let notification = {
title: 'New ' + item.Type,
body: body,
vibrate: true,
@ -104,7 +103,7 @@ define(['serverNotifications', 'playbackManager', 'events', 'globalize', 'requir
data: {}
};
var imageTags = item.ImageTags || {};
let imageTags = item.ImageTags || {};
if (imageTags.Primary) {
notification.icon = apiClient.getScaledImageUrl(item.Id, {
@ -115,10 +114,10 @@ define(['serverNotifications', 'playbackManager', 'events', 'globalize', 'requir
}
showNotification(notification, 15000, apiClient);
}
}
function onLibraryChanged(data, apiClient) {
var newItems = data.ItemsAdded;
function onLibraryChanged(data, apiClient) {
let newItems = data.ItemsAdded;
if (!newItems.length) {
return;
@ -141,26 +140,26 @@ define(['serverNotifications', 'playbackManager', 'events', 'globalize', 'requir
EnableTotalRecordCount: false
}).then(function (result) {
var items = result.Items;
let items = result.Items;
for (var i = 0, length = items.length ; i < length; i++) {
showNewItemNotification(items[i], apiClient);
for (const item of items) {
showNewItemNotification(item, apiClient);
}
});
}
}
function getIconUrl(name) {
function getIconUrl(name) {
name = name || 'notificationicon.png';
return require.toUrl('.').split('?')[0] + '/' + name;
}
return './components/notifications/' + name;
}
function showPackageInstallNotification(apiClient, installation, status) {
function showPackageInstallNotification(apiClient, installation, status) {
apiClient.getCurrentUser().then(function (user) {
if (!user.Policy.IsAdministrator) {
return;
}
var notification = {
let notification = {
tag: 'install' + installation.Id,
data: {}
};
@ -189,58 +188,58 @@ define(['serverNotifications', 'playbackManager', 'events', 'globalize', 'requir
}
if (status === 'progress') {
var percentComplete = Math.round(installation.PercentComplete || 0);
let percentComplete = Math.round(installation.PercentComplete || 0);
notification.body = percentComplete + '% complete.';
}
var timeout = status === 'cancelled' ? 5000 : 0;
let timeout = status === 'cancelled' ? 5000 : 0;
showNotification(notification, timeout, apiClient);
});
}
}
events.on(serverNotifications, 'LibraryChanged', function (e, apiClient, data) {
events.on(serverNotifications, 'LibraryChanged', function (e, apiClient, data) {
onLibraryChanged(data, apiClient);
});
});
events.on(serverNotifications, 'PackageInstallationCompleted', function (e, apiClient, data) {
events.on(serverNotifications, 'PackageInstallationCompleted', function (e, apiClient, data) {
showPackageInstallNotification(apiClient, data, 'completed');
});
});
events.on(serverNotifications, 'PackageInstallationFailed', function (e, apiClient, data) {
events.on(serverNotifications, 'PackageInstallationFailed', function (e, apiClient, data) {
showPackageInstallNotification(apiClient, data, 'failed');
});
});
events.on(serverNotifications, 'PackageInstallationCancelled', function (e, apiClient, data) {
events.on(serverNotifications, 'PackageInstallationCancelled', function (e, apiClient, data) {
showPackageInstallNotification(apiClient, data, 'cancelled');
});
});
events.on(serverNotifications, 'PackageInstalling', function (e, apiClient, data) {
events.on(serverNotifications, 'PackageInstalling', function (e, apiClient, data) {
showPackageInstallNotification(apiClient, data, 'progress');
});
});
events.on(serverNotifications, 'ServerShuttingDown', function (e, apiClient, data) {
var serverId = apiClient.serverInfo().Id;
var notification = {
events.on(serverNotifications, 'ServerShuttingDown', function (e, apiClient, data) {
let serverId = apiClient.serverInfo().Id;
let notification = {
tag: 'restart' + serverId,
title: globalize.translate('ServerNameIsShuttingDown', apiClient.serverInfo().Name)
};
showNotification(notification, 0, apiClient);
});
});
events.on(serverNotifications, 'ServerRestarting', function (e, apiClient, data) {
var serverId = apiClient.serverInfo().Id;
var notification = {
events.on(serverNotifications, 'ServerRestarting', function (e, apiClient, data) {
let serverId = apiClient.serverInfo().Id;
let notification = {
tag: 'restart' + serverId,
title: globalize.translate('ServerNameIsRestarting', apiClient.serverInfo().Name)
};
showNotification(notification, 0, apiClient);
});
});
events.on(serverNotifications, 'RestartRequired', function (e, apiClient) {
var serverId = apiClient.serverInfo().Id;
var notification = {
events.on(serverNotifications, 'RestartRequired', function (e, apiClient) {
let serverId = apiClient.serverInfo().Id;
let notification = {
tag: 'restart' + serverId,
title: globalize.translate('PleaseRestartServerName', apiClient.serverInfo().Name)
};
@ -255,5 +254,5 @@ define(['serverNotifications', 'playbackManager', 'events', 'globalize', 'requir
];
showNotification(notification, 0, apiClient);
});
});

View file

@ -1,13 +1,12 @@
define(['playbackManager', 'userSettings', 'connectionManager'], function (playbackManager, userSettings, connectionManager) {
'use strict';
import playbackManager from 'playbackManager';
import * as userSettings from 'userSettings';
import connectionManager from 'connectionManager';
playbackManager = playbackManager.default || playbackManager;
let currentOwnerId;
let currentThemeIds = [];
var currentOwnerId;
var currentThemeIds = [];
function playThemeMedia(items, ownerId) {
var currentThemeItems = items.filter(function (i) {
function playThemeMedia(items, ownerId) {
const currentThemeItems = items.filter(function (i) {
return enabled(i.MediaType);
});
@ -32,27 +31,27 @@ define(['playbackManager', 'userSettings', 'connectionManager'], function (playb
} else {
stopIfPlaying();
}
}
}
function stopIfPlaying() {
function stopIfPlaying() {
if (currentOwnerId) {
playbackManager.stop();
}
currentOwnerId = null;
}
}
function enabled(mediaType) {
function enabled(mediaType) {
if (mediaType === 'Video') {
return userSettings.enableThemeVideos();
}
return userSettings.enableThemeSongs();
}
}
var excludeTypes = ['CollectionFolder', 'UserView', 'Program', 'SeriesTimer', 'Person', 'TvChannel', 'Channel'];
const excludeTypes = ['CollectionFolder', 'UserView', 'Program', 'SeriesTimer', 'Person', 'TvChannel', 'Channel'];
function loadThemeMedia(item) {
function loadThemeMedia(item) {
if (item.CollectionType) {
stopIfPlaying();
return;
@ -63,41 +62,40 @@ define(['playbackManager', 'userSettings', 'connectionManager'], function (playb
return;
}
var apiClient = connectionManager.getApiClient(item.ServerId);
const apiClient = connectionManager.getApiClient(item.ServerId);
apiClient.getThemeMedia(apiClient.getCurrentUserId(), item.Id, true).then(function (themeMediaResult) {
var ownerId = themeMediaResult.ThemeVideosResult.Items.length ? themeMediaResult.ThemeVideosResult.OwnerId : themeMediaResult.ThemeSongsResult.OwnerId;
const ownerId = themeMediaResult.ThemeVideosResult.Items.length ? themeMediaResult.ThemeVideosResult.OwnerId : themeMediaResult.ThemeSongsResult.OwnerId;
if (ownerId !== currentOwnerId) {
var items = themeMediaResult.ThemeVideosResult.Items.length ? themeMediaResult.ThemeVideosResult.Items : themeMediaResult.ThemeSongsResult.Items;
const items = themeMediaResult.ThemeVideosResult.Items.length ? themeMediaResult.ThemeVideosResult.Items : themeMediaResult.ThemeSongsResult.Items;
playThemeMedia(items, ownerId);
}
});
}
}
document.addEventListener('viewshow', function (e) {
var state = e.detail.state || {};
var item = state.item;
document.addEventListener('viewshow', function (e) {
const state = e.detail.state || {};
const item = state.item;
if (item && item.ServerId) {
loadThemeMedia(item);
return;
}
var viewOptions = e.detail.options || {};
const viewOptions = e.detail.options || {};
if (viewOptions.supportsThemeMedia) {
// Do nothing here, allow it to keep playing
} else {
playThemeMedia([], null);
}
}, true);
}, true);
Events.on(playbackManager, 'playbackstart', function (e, player) {
var item = playbackManager.currentItem(player);
Events.on(playbackManager, 'playbackstart', function (e, player) {
const item = playbackManager.currentItem(player);
// User played something manually
if (currentThemeIds.indexOf(item.Id) == -1) {
currentOwnerId = null;
}
});
});

View file

@ -1,60 +1,66 @@
define(['require', 'dialogHelper', 'loading', 'apphost', 'layoutManager', 'connectionManager', 'appRouter', 'globalize', 'userSettings', 'emby-checkbox', 'emby-input', 'paper-icon-button-light', 'emby-select', 'material-icons', 'css!./../formdialog', 'emby-button', 'flexStyles'], function (require, dialogHelper, loading, appHost, layoutManager, connectionManager, appRouter, globalize, userSettings) {
'use strict';
import dialogHelper from 'dialogHelper';
import layoutManager from 'layoutManager';
import globalize from 'globalize';
import * as userSettings from 'userSettings';
import 'emby-checkbox';
import 'emby-input';
import 'paper-icon-button-light';
import 'emby-select';
import 'material-icons';
import 'css!./../formdialog';
import 'emby-button';
import 'flexStyles';
layoutManager = layoutManager.default || layoutManager;
function onSubmit(e) {
function onSubmit(e) {
e.preventDefault();
return false;
}
}
function initEditor(context, settings) {
function initEditor(context, settings) {
context.querySelector('form').addEventListener('submit', onSubmit);
var elems = context.querySelectorAll('.viewSetting-checkboxContainer');
const elems = context.querySelectorAll('.viewSetting-checkboxContainer');
for (var i = 0, length = elems.length; i < length; i++) {
elems[i].querySelector('input').checked = settings[elems[i].getAttribute('data-settingname')] || false;
for (const elem of elems) {
elem.querySelector('input').checked = settings[elem.getAttribute('data-settingname')] || false;
}
context.querySelector('.selectImageType').value = settings.imageType || 'primary';
}
}
function saveValues(context, settings, settingsKey) {
var elems = context.querySelectorAll('.viewSetting-checkboxContainer');
for (var i = 0, length = elems.length; i < length; i++) {
userSettings.set(settingsKey + '-' + elems[i].getAttribute('data-settingname'), elems[i].querySelector('input').checked);
function saveValues(context, settings, settingsKey) {
const elems = context.querySelectorAll('.viewSetting-checkboxContainer');
for (const elem of elems) {
userSettings.set(settingsKey + '-' + elem.getAttribute('data-settingname'), elem.querySelector('input').checked);
}
userSettings.set(settingsKey + '-imageType', context.querySelector('.selectImageType').value);
}
}
function centerFocus(elem, horiz, on) {
require(['scrollHelper'], function (scrollHelper) {
scrollHelper = scrollHelper.default || scrollHelper;
var fn = on ? 'on' : 'off';
function centerFocus(elem, horiz, on) {
import('scrollHelper').then(({default: scrollHelper}) => {
const fn = on ? 'on' : 'off';
scrollHelper.centerFocus[fn](elem, horiz);
});
}
}
function showIfAllowed(context, selector, visible) {
var elem = context.querySelector(selector);
function showIfAllowed(context, selector, visible) {
const elem = context.querySelector(selector);
if (visible && !elem.classList.contains('hiddenFromViewSettings')) {
elem.classList.remove('hide');
} else {
elem.classList.add('hide');
}
}
class ViewSettings {
constructor() {
}
function ViewSettings() {
}
ViewSettings.prototype.show = function (options) {
show(options) {
return new Promise(function (resolve, reject) {
require(['text!./viewSettings.template.html'], function (template) {
var dialogOptions = {
import('text!./viewSettings.template.html').then(({default: template}) => {
const dialogOptions = {
removeOnClose: true,
scrollY: false
};
@ -65,11 +71,11 @@ define(['require', 'dialogHelper', 'loading', 'apphost', 'layoutManager', 'conne
dialogOptions.size = 'small';
}
var dlg = dialogHelper.createDialog(dialogOptions);
const dlg = dialogHelper.createDialog(dialogOptions);
dlg.classList.add('formDialog');
var html = '';
let html = '';
html += '<div class="formDialogHeader">';
html += '<button is="paper-icon-button-light" class="btnCancel hide-mouse-idle-tv" tabindex="-1"><span class="material-icons arrow_back"></span></button>';
@ -81,14 +87,14 @@ define(['require', 'dialogHelper', 'loading', 'apphost', 'layoutManager', 'conne
dlg.innerHTML = globalize.translateHtml(html, 'core');
var settingElements = dlg.querySelectorAll('.viewSetting');
for (var i = 0, length = settingElements.length; i < length; i++) {
if (options.visibleSettings.indexOf(settingElements[i].getAttribute('data-settingname')) === -1) {
settingElements[i].classList.add('hide');
settingElements[i].classList.add('hiddenFromViewSettings');
const settingElements = dlg.querySelectorAll('.viewSetting');
for (const settingElement of settingElements) {
if (options.visibleSettings.indexOf(settingElement.getAttribute('data-settingname')) === -1) {
settingElement.classList.add('hide');
settingElement.classList.add('hiddenFromViewSettings');
} else {
settingElements[i].classList.remove('hide');
settingElements[i].classList.remove('hiddenFromViewSettings');
settingElement.classList.remove('hide');
settingElement.classList.remove('hiddenFromViewSettings');
}
}
@ -107,7 +113,7 @@ define(['require', 'dialogHelper', 'loading', 'apphost', 'layoutManager', 'conne
centerFocus(dlg.querySelector('.formDialogContent'), false, true);
}
var submitted;
let submitted;
dlg.querySelector('.selectImageType').dispatchEvent(new CustomEvent('change', {}));
@ -130,7 +136,7 @@ define(['require', 'dialogHelper', 'loading', 'apphost', 'layoutManager', 'conne
});
});
});
};
}
}
return ViewSettings;
});
export default ViewSettings;