From 1ac3ecbfa7fee4b2301d66f4399704237badea5d Mon Sep 17 00:00:00 2001 From: Cameron Date: Wed, 8 Jul 2020 19:58:28 +0100 Subject: [PATCH 1/3] Migrate networking.js, playback.js, serveractivity.js to ES6 modules --- package.json | 3 +++ src/controllers/dashboard/networking.js | 14 ++++++++++---- src/controllers/dashboard/playback.js | 11 ++++++++--- src/controllers/dashboard/serveractivity.js | 11 +++++++---- 4 files changed, 28 insertions(+), 11 deletions(-) diff --git a/package.json b/package.json index 230eee3f21..152498a759 100644 --- a/package.json +++ b/package.json @@ -124,6 +124,9 @@ "src/components/settingshelper.js", "src/components/subtitlesettings/subtitlesettings.js", "src/components/subtitlesettings/subtitleappearancehelper.js", + "src/controllers/dashboard/playback.js", + "src/controllers/dashboard/serveractivity.js", + "src/controllers/dashboard/networking.js", "src/components/shortcuts.js", "src/components/syncPlay/groupSelectionMenu.js", "src/components/syncPlay/playbackPermissionManager.js", diff --git a/src/controllers/dashboard/networking.js b/src/controllers/dashboard/networking.js index 4ddde7f24c..e9fdec6391 100644 --- a/src/controllers/dashboard/networking.js +++ b/src/controllers/dashboard/networking.js @@ -1,5 +1,10 @@ -define(['loading', 'libraryMenu', 'globalize', 'emby-checkbox', 'emby-select'], function (loading, libraryMenu, globalize) { - 'use strict'; +import loading from 'loading'; +import libraryMenu from 'libraryMenu'; +import globalize from 'globalize'; +import 'emby-checkbox'; +import 'emby-select'; + +/* eslint-disable indent */ function onSubmit(e) { var form = this; @@ -97,7 +102,7 @@ define(['loading', 'libraryMenu', 'globalize', 'emby-checkbox', 'emby-select'], } } - return function (view, params) { + export default function (view, params) { function loadPage(page, config) { page.querySelector('#txtPortNumber').value = config.HttpServerPortNumber; page.querySelector('#txtPublicPort').value = config.PublicPort; @@ -159,4 +164,5 @@ define(['loading', 'libraryMenu', 'globalize', 'emby-checkbox', 'emby-select'], }); }); }; -}); + +/* eslint-enable indent */ diff --git a/src/controllers/dashboard/playback.js b/src/controllers/dashboard/playback.js index d5b67a2961..9c7bc00b4f 100644 --- a/src/controllers/dashboard/playback.js +++ b/src/controllers/dashboard/playback.js @@ -1,5 +1,9 @@ -define(['jQuery', 'loading', 'libraryMenu', 'globalize'], function ($, loading, libraryMenu, globalize) { - 'use strict'; +import $ from 'jQuery'; +import loading from 'loading'; +import libraryMenu from 'libraryMenu'; +import globalize from 'globalize'; + +/* eslint-disable indent */ function loadPage(page, config) { $('#txtMinResumePct', page).val(config.MinResumePct); @@ -45,4 +49,5 @@ define(['jQuery', 'loading', 'libraryMenu', 'globalize'], function ($, loading, loadPage(page, config); }); }); -}); + +/* eslint-enable indent */ diff --git a/src/controllers/dashboard/serveractivity.js b/src/controllers/dashboard/serveractivity.js index c48a2903ae..2bd98836e0 100644 --- a/src/controllers/dashboard/serveractivity.js +++ b/src/controllers/dashboard/serveractivity.js @@ -1,7 +1,9 @@ -define(['components/activitylog', 'globalize'], function (ActivityLog, globalize) { - 'use strict'; +import ActivityLog from 'components/activitylog'; +import globalize from 'globalize'; - return function (view, params) { +/* eslint-disable indent */ + + export default function (view, params) { var activityLog; if (params.useractivity !== 'false') { @@ -28,4 +30,5 @@ define(['components/activitylog', 'globalize'], function (ActivityLog, globalize activityLog = null; }); }; -}); + +/* eslint-ensable indent */ From e230e05e6ec670bca8d2498685c4885ff273d07e Mon Sep 17 00:00:00 2001 From: Cameron Date: Wed, 8 Jul 2020 20:24:44 +0100 Subject: [PATCH 2/3] migrate mediaLibrary to ES6 module --- package.json | 7 +++-- src/controllers/dashboard/mediaLibrary.js | 32 ++++++++++++++------- src/controllers/dashboard/serveractivity.js | 2 +- 3 files changed, 27 insertions(+), 14 deletions(-) diff --git a/package.json b/package.json index 152498a759..56aeb4c004 100644 --- a/package.json +++ b/package.json @@ -124,9 +124,6 @@ "src/components/settingshelper.js", "src/components/subtitlesettings/subtitlesettings.js", "src/components/subtitlesettings/subtitleappearancehelper.js", - "src/controllers/dashboard/playback.js", - "src/controllers/dashboard/serveractivity.js", - "src/controllers/dashboard/networking.js", "src/components/shortcuts.js", "src/components/syncPlay/groupSelectionMenu.js", "src/components/syncPlay/playbackPermissionManager.js", @@ -134,7 +131,11 @@ "src/components/syncPlay/timeSyncManager.js", "src/controllers/dashboard/logs.js", "src/controllers/user/subtitles.js", + "src/controllers/dashboard/mediaLibrary.js", + "src/controllers/dashboard/networking.js", + "src/controllers/dashboard/playback.js", "src/controllers/dashboard/plugins/repositories.js", + "src/controllers/dashboard/serveractivity.js", "src/plugins/bookPlayer/plugin.js", "src/plugins/bookPlayer/tableOfContents.js", "src/plugins/photoPlayer/plugin.js", diff --git a/src/controllers/dashboard/mediaLibrary.js b/src/controllers/dashboard/mediaLibrary.js index d9b288c62a..1284602e4c 100644 --- a/src/controllers/dashboard/mediaLibrary.js +++ b/src/controllers/dashboard/mediaLibrary.js @@ -1,8 +1,19 @@ -define(['jQuery', 'apphost', 'scripts/taskbutton', 'loading', 'libraryMenu', 'globalize', 'dom', 'indicators', 'scripts/imagehelper', 'cardStyle', 'emby-itemrefreshindicator'], function ($, appHost, taskButton, loading, libraryMenu, globalize, dom, indicators, imageHelper) { - 'use strict'; +import $ from 'jQuery'; +import appHost from 'apphost'; +import taskButton from 'scripts/taskbutton'; +import loading from 'loading'; +import libraryMenu from 'libraryMenu'; +import globalize from 'globalize'; +import dom from 'dom'; +import indicators from 'indicators'; +import imageHelper from 'scripts/imagehelper'; +import 'cardStyle'; +import 'emby-itemrefreshindicator'; + +/* eslint-disable indent */ function addVirtualFolder(page) { - require(['medialibrarycreator'], function (medialibrarycreator) { + import('medialibrarycreator').then(({default: medialibrarycreator}) => { new medialibrarycreator.showEditor({ collectionTypeOptions: getCollectionTypeOptions().filter(function (f) { return !f.hidden; @@ -17,7 +28,7 @@ define(['jQuery', 'apphost', 'scripts/taskbutton', 'loading', 'libraryMenu', 'gl } function editVirtualFolder(page, virtualFolder) { - require(['medialibraryeditor'], function (medialibraryeditor) { + import('medialibraryeditor').then(({default:medialibraryeditor }) => { new medialibraryeditor.showEditor({ refresh: shouldRefreshLibraryAfterChanges(page), library: virtualFolder @@ -37,7 +48,7 @@ define(['jQuery', 'apphost', 'scripts/taskbutton', 'loading', 'libraryMenu', 'gl msg += virtualFolder.Locations.join('
'); } - require(['confirm'], function (confirm) { + import('confirm').then(({default: confirm}) => { confirm({ text: msg, @@ -55,7 +66,7 @@ define(['jQuery', 'apphost', 'scripts/taskbutton', 'loading', 'libraryMenu', 'gl } function refreshVirtualFolder(page, virtualFolder) { - require(['refreshDialog'], function (refreshDialog) { + import('refreshDialog').then(({default: refreshDialog}) => { new refreshDialog({ itemIds: [virtualFolder.ItemId], serverId: ApiClient.serverId(), @@ -65,7 +76,7 @@ define(['jQuery', 'apphost', 'scripts/taskbutton', 'loading', 'libraryMenu', 'gl } function renameVirtualFolder(page, virtualFolder) { - require(['prompt'], function (prompt) { + import('prompt').then(({default: prompt}) => { prompt({ label: globalize.translate('LabelNewName'), confirmText: globalize.translate('ButtonRename') @@ -111,7 +122,7 @@ define(['jQuery', 'apphost', 'scripts/taskbutton', 'loading', 'libraryMenu', 'gl icon: 'refresh' }); - require(['actionsheet'], function (actionsheet) { + import('actionsheet').then(({default: actionsheet}) => { actionsheet.show({ items: menuItems, positionTo: elem, @@ -192,7 +203,7 @@ define(['jQuery', 'apphost', 'scripts/taskbutton', 'loading', 'libraryMenu', 'gl } function editImages(page, virtualFolder) { - require(['imageEditor'], function (imageEditor) { + import('imageEditor').then(({default: imageEditor}) => { imageEditor.show({ itemId: virtualFolder.ItemId, serverId: ApiClient.serverId() @@ -388,4 +399,5 @@ define(['jQuery', 'apphost', 'scripts/taskbutton', 'loading', 'libraryMenu', 'gl button: page.querySelector('.btnRefresh') }); }); -}); + +/* eslint-enable indent */ diff --git a/src/controllers/dashboard/serveractivity.js b/src/controllers/dashboard/serveractivity.js index 2bd98836e0..624c5cc4ad 100644 --- a/src/controllers/dashboard/serveractivity.js +++ b/src/controllers/dashboard/serveractivity.js @@ -31,4 +31,4 @@ import globalize from 'globalize'; }); }; -/* eslint-ensable indent */ +/* eslint-enable indent */ From fd21f2198df4cc198feb06206d22c1ee0586c733 Mon Sep 17 00:00:00 2001 From: Cameron Date: Thu, 9 Jul 2020 11:36:54 +0100 Subject: [PATCH 3/3] fix medialibrary.js, lint and convert variable declerations --- src/controllers/dashboard/mediaLibrary.js | 48 ++++++++++----------- src/controllers/dashboard/networking.js | 20 ++++----- src/controllers/dashboard/playback.js | 4 +- src/controllers/dashboard/serveractivity.js | 4 +- 4 files changed, 38 insertions(+), 38 deletions(-) diff --git a/src/controllers/dashboard/mediaLibrary.js b/src/controllers/dashboard/mediaLibrary.js index 1284602e4c..e7f00e8358 100644 --- a/src/controllers/dashboard/mediaLibrary.js +++ b/src/controllers/dashboard/mediaLibrary.js @@ -14,7 +14,7 @@ import 'emby-itemrefreshindicator'; function addVirtualFolder(page) { import('medialibrarycreator').then(({default: medialibrarycreator}) => { - new medialibrarycreator.showEditor({ + new medialibrarycreator({ collectionTypeOptions: getCollectionTypeOptions().filter(function (f) { return !f.hidden; }), @@ -28,8 +28,8 @@ import 'emby-itemrefreshindicator'; } function editVirtualFolder(page, virtualFolder) { - import('medialibraryeditor').then(({default:medialibraryeditor }) => { - new medialibraryeditor.showEditor({ + import('medialibraryeditor').then(({default: medialibraryeditor}) => { + new medialibraryeditor({ refresh: shouldRefreshLibraryAfterChanges(page), library: virtualFolder }).then(function (hasChanges) { @@ -41,7 +41,7 @@ import 'emby-itemrefreshindicator'; } function deleteVirtualFolder(page, virtualFolder) { - var msg = globalize.translate('MessageAreYouSureYouWishToRemoveMediaFolder'); + let msg = globalize.translate('MessageAreYouSureYouWishToRemoveMediaFolder'); if (virtualFolder.Locations.length) { msg += '

' + globalize.translate('MessageTheFollowingLocationWillBeRemovedFromLibrary') + '

'; @@ -57,7 +57,7 @@ import 'emby-itemrefreshindicator'; primary: 'delete' }).then(function () { - var refreshAfterChange = shouldRefreshLibraryAfterChanges(page); + const refreshAfterChange = shouldRefreshLibraryAfterChanges(page); ApiClient.removeVirtualFolder(virtualFolder.Name, refreshAfterChange).then(function () { reloadLibrary(page); }); @@ -82,7 +82,7 @@ import 'emby-itemrefreshindicator'; confirmText: globalize.translate('ButtonRename') }).then(function (newName) { if (newName && newName != virtualFolder.Name) { - var refreshAfterChange = shouldRefreshLibraryAfterChanges(page); + const refreshAfterChange = shouldRefreshLibraryAfterChanges(page); ApiClient.renameVirtualFolder(virtualFolder.Name, newName, refreshAfterChange).then(function () { reloadLibrary(page); }); @@ -92,10 +92,10 @@ import 'emby-itemrefreshindicator'; } function showCardMenu(page, elem, virtualFolders) { - var card = dom.parentWithClass(elem, 'card'); - var index = parseInt(card.getAttribute('data-index')); - var virtualFolder = virtualFolders[index]; - var menuItems = []; + const card = dom.parentWithClass(elem, 'card'); + const index = parseInt(card.getAttribute('data-index')); + const virtualFolder = virtualFolders[index]; + const menuItems = []; menuItems.push({ name: globalize.translate('ButtonEditImages'), id: 'editimages', @@ -164,7 +164,7 @@ import 'emby-itemrefreshindicator'; } function reloadVirtualFolders(page, virtualFolders) { - var html = ''; + let html = ''; virtualFolders.push({ Name: globalize.translate('ButtonAddMediaLibrary'), icon: 'add_circle', @@ -175,12 +175,12 @@ import 'emby-itemrefreshindicator'; showNameWithIcon: true }); - for (var i = 0; i < virtualFolders.length; i++) { - var virtualFolder = virtualFolders[i]; + for (let i = 0; i < virtualFolders.length; i++) { + const virtualFolder = virtualFolders[i]; html += getVirtualFolderHtml(page, virtualFolder, i); } - var divVirtualFolders = page.querySelector('#divVirtualFolders'); + const divVirtualFolders = page.querySelector('#divVirtualFolders'); divVirtualFolders.innerHTML = html; divVirtualFolders.classList.add('itemsContainer'); divVirtualFolders.classList.add('vertical-wrap'); @@ -191,9 +191,9 @@ import 'emby-itemrefreshindicator'; addVirtualFolder(page); }); $('.editLibrary', divVirtualFolders).on('click', function () { - var card = $(this).parents('.card')[0]; - var index = parseInt(card.getAttribute('data-index')); - var virtualFolder = virtualFolders[index]; + const card = $(this).parents('.card')[0]; + const index = parseInt(card.getAttribute('data-index')); + const virtualFolder = virtualFolders[index]; if (virtualFolder.ItemId) { editVirtualFolder(page, virtualFolder); @@ -251,8 +251,8 @@ import 'emby-itemrefreshindicator'; } function getVirtualFolderHtml(page, virtualFolder, index) { - var html = ''; - var style = ''; + let html = ''; + let style = ''; if (page.classList.contains('wizardPage')) { style += 'min-width:33.3%;'; @@ -263,7 +263,7 @@ import 'emby-itemrefreshindicator'; html += '
'; html += '
'; html += '
'; - var imgUrl = ''; + let imgUrl = ''; if (virtualFolder.PrimaryImageItemId) { imgUrl = ApiClient.getScaledImageUrl(virtualFolder.PrimaryImageItemId, { @@ -272,7 +272,7 @@ import 'emby-itemrefreshindicator'; }); } - var hasCardImageContainer; + let hasCardImageContainer; if (imgUrl) { html += '
"; @@ -322,7 +322,7 @@ import 'emby-itemrefreshindicator'; } html += '
'; - var typeName = getCollectionTypeOptions().filter(function (t) { + let typeName = getCollectionTypeOptions().filter(function (t) { return t.value == virtualFolder.CollectionType; })[0]; typeName = typeName ? typeName.name : globalize.translate('FolderTypeUnset'); @@ -382,7 +382,7 @@ import 'emby-itemrefreshindicator'; }); pageIdOn('pageshow', 'mediaLibraryPage', function () { libraryMenu.setTabs('librarysetup', 0, getTabs); - var page = this; + const page = this; taskButton({ mode: 'on', progressElem: page.querySelector('.refreshProgress'), @@ -391,7 +391,7 @@ import 'emby-itemrefreshindicator'; }); }); pageIdOn('pagebeforehide', 'mediaLibraryPage', function () { - var page = this; + const page = this; taskButton({ mode: 'off', progressElem: page.querySelector('.refreshProgress'), diff --git a/src/controllers/dashboard/networking.js b/src/controllers/dashboard/networking.js index e9fdec6391..5b0342ec2a 100644 --- a/src/controllers/dashboard/networking.js +++ b/src/controllers/dashboard/networking.js @@ -7,11 +7,11 @@ import 'emby-select'; /* eslint-disable indent */ function onSubmit(e) { - var form = this; - var localAddress = form.querySelector('#txtLocalAddress').value; - var enableUpnp = form.querySelector('#chkEnableUpnp').checked; + const form = this; + const localAddress = form.querySelector('#txtLocalAddress').value; + const enableUpnp = form.querySelector('#chkEnableUpnp').checked; confirmSelections(localAddress, enableUpnp, function () { - var validationResult = getValidationAlert(form); + const validationResult = getValidationAlert(form); if (validationResult) { showAlertText(validationResult); @@ -52,7 +52,7 @@ import 'emby-select'; } function triggerChange(select) { - var evt = document.createEvent('HTMLEvents'); + const evt = document.createEvent('HTMLEvents'); evt.initEvent('change', false, true); select.dispatchEvent(evt); } @@ -70,8 +70,8 @@ import 'emby-select'; } function validateHttps(form) { - var certPath = form.querySelector('#txtCertificatePath').value || null; - var httpsEnabled = form.querySelector('#chkEnableHttps').checked; + const certPath = form.querySelector('#txtCertificatePath').value || null; + const httpsEnabled = form.querySelector('#chkEnableHttps').checked; if (httpsEnabled && !certPath) { return showAlertText({ @@ -116,7 +116,7 @@ import 'emby-select'; page.querySelector('#chkEnableHttps').checked = config.EnableHttps; page.querySelector('#chkRequireHttps').checked = config.RequireHttps; page.querySelector('#txtBaseUrl').value = config.BaseUrl || ''; - var txtCertificatePath = page.querySelector('#txtCertificatePath'); + const txtCertificatePath = page.querySelector('#txtCertificatePath'); txtCertificatePath.value = config.CertificatePath || ''; page.querySelector('#txtCertPassword').value = config.CertificatePassword || ''; page.querySelector('#chkEnableUpnp').checked = config.EnableUPnP; @@ -141,7 +141,7 @@ import 'emby-select'; }); view.querySelector('#btnSelectCertPath').addEventListener('click', function () { require(['directorybrowser'], function (directoryBrowser) { - var picker = new directoryBrowser(); + const picker = new directoryBrowser(); picker.show({ includeFiles: true, includeDirectories: true, @@ -163,6 +163,6 @@ import 'emby-select'; loadPage(view, config); }); }); - }; + } /* eslint-enable indent */ diff --git a/src/controllers/dashboard/playback.js b/src/controllers/dashboard/playback.js index 9c7bc00b4f..0406c21926 100644 --- a/src/controllers/dashboard/playback.js +++ b/src/controllers/dashboard/playback.js @@ -14,7 +14,7 @@ import globalize from 'globalize'; function onSubmit() { loading.show(); - var form = this; + const form = this; ApiClient.getServerConfiguration().then(function (config) { config.MinResumePct = $('#txtMinResumePct', form).val(); config.MaxResumePct = $('#txtMaxResumePct', form).val(); @@ -44,7 +44,7 @@ import globalize from 'globalize'; }).on('pageshow', '#playbackConfigurationPage', function () { loading.show(); libraryMenu.setTabs('playback', 1, getTabs); - var page = this; + const page = this; ApiClient.getServerConfiguration().then(function (config) { loadPage(page, config); }); diff --git a/src/controllers/dashboard/serveractivity.js b/src/controllers/dashboard/serveractivity.js index 624c5cc4ad..ed56126267 100644 --- a/src/controllers/dashboard/serveractivity.js +++ b/src/controllers/dashboard/serveractivity.js @@ -4,7 +4,7 @@ import globalize from 'globalize'; /* eslint-disable indent */ export default function (view, params) { - var activityLog; + let activityLog; if (params.useractivity !== 'false') { view.querySelector('.activityItems').setAttribute('data-useractivity', 'true'); @@ -29,6 +29,6 @@ import globalize from 'globalize'; activityLog = null; }); - }; + } /* eslint-enable indent */