From af494e14c598b13f7d25b44cf0906f7b5304bf78 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Calvi=C3=B1o=20S=C3=A1nchez?= Date: Fri, 4 Aug 2017 14:41:44 +0200 Subject: [PATCH] Fix preview of theming MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Pull request #5429 made cached SCSS files depend on a hash of the base URL, so the "/css/core/server.css" file does no longer exist; as the file can not be loaded the "Loading preview" message is never removed and the "Saved" message is never shown. As it now depends on the hash of the base URL the file to be reloaded can no longer be hardcoded, so the DataResponse from the controller now provides the full URL to the "server.css" file that has to be reloaded (if any). Fixes #5975 Signed-off-by: Daniel Calviño Sánchez --- apps/theming/js/settings-admin.js | 20 ++++++++++++++----- .../lib/Controller/ThemingController.php | 6 ++++-- 2 files changed, 19 insertions(+), 7 deletions(-) diff --git a/apps/theming/js/settings-admin.js b/apps/theming/js/settings-admin.js index 9d8e706e124b5..e64311b62addf 100644 --- a/apps/theming/js/settings-admin.js +++ b/apps/theming/js/settings-admin.js @@ -30,7 +30,7 @@ function setThemingValue(setting, value) { OC.generateUrl('/apps/theming/ajax/updateStylesheet'), {'setting' : setting, 'value' : value} ).done(function(response) { hideUndoButton(setting, value); - preview(setting, value); + preview(setting, value, response.data.serverCssUrl); }).fail(function(response) { OC.msg.finishedSaving('#theming_settings_msg', response); $('#theming_settings_loading').hide(); @@ -38,9 +38,9 @@ function setThemingValue(setting, value) { } -function preview(setting, value) { +function preview(setting, value, serverCssUrl) { OC.msg.startAction('#theming_settings_msg', t('theming', 'Loading preview…')); - var stylesheetsLoaded = 2; + var stylesheetsLoaded = 1; var reloadStylesheets = function(cssFile) { var queryString = '?reload=' + new Date().getTime(); var url = cssFile + queryString; @@ -62,7 +62,17 @@ function preview(setting, value) { stylesheet.appendTo("head"); }; - reloadStylesheets(OC.generateUrl('/css/core/server.css')); + if (serverCssUrl !== undefined) { + stylesheetsLoaded++; + + // Ensure that the URL starts by '/' to prevent "stylesheet.load" from + // prepending the URL of the current page. + if (serverCssUrl[0] !== '/') { + serverCssUrl = '/' + serverCssUrl; + } + + reloadStylesheets(serverCssUrl); + } reloadStylesheets(OC.generateUrl('/apps/theming/styles')); // Preview images @@ -218,7 +228,7 @@ $(document).ready(function () { var input = document.getElementById('theming-'+setting); input.value = response.data.value; } - preview(setting, response.data.value); + preview(setting, response.data.value, response.data.serverCssUrl); }); }); diff --git a/apps/theming/lib/Controller/ThemingController.php b/apps/theming/lib/Controller/ThemingController.php index 225673079a3f6..866229353d465 100644 --- a/apps/theming/lib/Controller/ThemingController.php +++ b/apps/theming/lib/Controller/ThemingController.php @@ -172,7 +172,8 @@ public function updateStylesheet($setting, $value) { [ 'data' => [ - 'message' => $this->l10n->t('Saved') + 'message' => $this->l10n->t('Saved'), + 'serverCssUrl' => $this->scssCacher->getCachedSCSS('core', '/core/css/server.scss') ], 'status' => 'success' ] @@ -303,7 +304,8 @@ public function undo($setting) { 'data' => [ 'value' => $value, - 'message' => $this->l10n->t('Saved') + 'message' => $this->l10n->t('Saved'), + 'serverCssUrl' => $this->scssCacher->getCachedSCSS('core', '/core/css/server.scss') ], 'status' => 'success' ]