Skip to content

Commit

Permalink
Fix preview of theming
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
danxuliu committed Aug 4, 2017
1 parent afadefb commit af494e1
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 7 deletions.
20 changes: 15 additions & 5 deletions apps/theming/js/settings-admin.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,17 +30,17 @@ 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();
});

}

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;
Expand All @@ -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
Expand Down Expand Up @@ -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);
});
});

Expand Down
6 changes: 4 additions & 2 deletions apps/theming/lib/Controller/ThemingController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'
]
Expand Down Expand Up @@ -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'
]
Expand Down

0 comments on commit af494e1

Please sign in to comment.