Skip to content

Commit

Permalink
Fixed issue: pjax not active in production mdoe
Browse files Browse the repository at this point in the history
  • Loading branch information
lacrioque committed Nov 23, 2017
1 parent 9f93b5d commit ba8f558
Show file tree
Hide file tree
Showing 7 changed files with 86 additions and 23 deletions.
53 changes: 53 additions & 0 deletions application/commands/FlushAssetsCommand.php
@@ -0,0 +1,53 @@
<?php
/*
* LimeSurvey (tm)
* Copyright (C) 2011 The LimeSurvey Project Team / Carsten Schmitz
* All rights reserved.
* License: GNU/GPL License v2 or later, see LICENSE.php
* LimeSurvey is free software. This version may have been modified pursuant
* to the GNU General Public License, and as distributed it includes or
* is derivative of works licensed under the GNU General Public License or
* other free or open source software licenses.
* See COPYRIGHT.php for copyright notices and details.
*
*/
class FlushAssetsCommand extends CConsoleCommand
{

/**
* @param array $aArguments
* @return void
*/
public function run($aArguments)
{
$sCurrentDir = dirname(__FILE__);
$tmpFolder = realpath( $sCurrentDir.'/../../tmp/' );
echo "Flushing assets in ".$tmpFolder;
echo "\n";

$this->_sureRemoveFiles($tmpFolder.'/assets/', false, ['index.html']);
$this->_sureRemoveFiles($tmpFolder.'/runtime/cache/', false, ['index.html']);

}
private function _sureRemoveFiles($dir, $DeleteMe, $exclude = array() ) {
if (!$dh = @opendir($dir)) {
return;
}
while (false !== ($obj = readdir($dh))) {
if ($obj == '.' || $obj == '..' || in_array($obj, $exclude)) {
continue;
}
if (!@unlink($dir.'/'.$obj)) {
$this->_sureRemoveFiles($dir.'/'.$obj, true);
}
}
closedir($dh);
if ($DeleteMe) {
if (!@rmdir($dir))
{
echo "Error: could not delete ".$dir;
}

}
}
}
10 changes: 6 additions & 4 deletions assets/packages/adminpanel/build/lsadminpanel.js
Expand Up @@ -36367,22 +36367,23 @@ $(document).on('ready', function () {
});
},
mounted() {
window.singletonPjax();
const surveyid = $(this.$el).data('surveyid');
if (surveyid != 0) {
this.$store.commit('updateSurveyId', surveyid);
}
const maxHeight = ($('#in_survey_common').height() - 35) || 400;
this.$store.commit('changeMaxHeight', maxHeight);
this.updatePjaxLinks();

$(document).on('click', 'ul.pagination>li>a', ()=>{
this.updatePjaxLinks();
});

$(document).on('vue-redraw', ()=>{
this.$forceUpdate();
this.updatePjaxLinks();
});
window.singletonPjax();

}
});
Expand Down Expand Up @@ -40738,7 +40739,8 @@ exports.install = function (Vue) {
debugConsole.error.apply(Vue, ['LoggingSystem ERROR:\n', arguments]);
},
log: function () {
debugConsole.log.apply(Vue, ['LoggingSystem LOG:\n', arguments]);
if (debugmode)
debugConsole.log.apply(Vue, ['LoggingSystem LOG:\n', arguments]);
}
};
};
Expand Down
2 changes: 1 addition & 1 deletion assets/packages/adminpanel/build/lsadminpanel.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion assets/packages/adminpanel/build/lsadminpanel.min.js

Large diffs are not rendered by default.

7 changes: 4 additions & 3 deletions assets/packages/adminpanel/src/main.js
Expand Up @@ -56,22 +56,23 @@ $(document).on('ready', function () {
});
},
mounted() {
window.singletonPjax();
const surveyid = $(this.$el).data('surveyid');
if (surveyid != 0) {
this.$store.commit('updateSurveyId', surveyid);
}
const maxHeight = ($('#in_survey_common').height() - 35) || 400;
this.$store.commit('changeMaxHeight', maxHeight);
this.updatePjaxLinks();

$(document).on('click', 'ul.pagination>li>a', ()=>{
this.updatePjaxLinks();
});

$(document).on('vue-redraw', ()=>{
this.$forceUpdate();
this.updatePjaxLinks();
});
window.singletonPjax();

}
});
Expand Down
3 changes: 2 additions & 1 deletion assets/packages/adminpanel/src/mixins/logSystem.js
Expand Up @@ -136,7 +136,8 @@ exports.install = function (Vue) {
debugConsole.error.apply(Vue, ['LoggingSystem ERROR:\n', arguments]);
},
log: function () {
debugConsole.log.apply(Vue, ['LoggingSystem LOG:\n', arguments]);
if (debugmode)
debugConsole.log.apply(Vue, ['LoggingSystem LOG:\n', arguments]);
}
};
};
32 changes: 19 additions & 13 deletions assets/packages/pjax/loadPjax.min.js
Expand Up @@ -6,10 +6,10 @@ var switchInnerHTML = function (oldEl, newEl, opt) {
this.onSwitch();
},
singletonPjax = function () {
console.log('createing a Pjax instance on the window object');
window.activePjax = window.activePjax || null;

if (window.activePjax !== null) {

if (window.activePjax === null) {
console.log('creating a Pjax instance on the window object');
window.activePjax = new Pjax({
elements: ['a.pjax', 'form.pjax'], // default is "a[href], form[action]"
selectors: [
Expand All @@ -23,27 +23,33 @@ var switchInnerHTML = function (oldEl, newEl, opt) {
'#beginScripts': switchInnerHTML,
'#pjax-content': switchInnerHTML,
'#breadcrumb-container': switchInnerHTML,
},
debug: false
}
});
}

return window.activePjax;
},
forceRefreshPjax = function () {
window.activePjax = null;
singletonPjax();
},
triggerLoadUrl = function(e){
singletonPjax().loadUrl(e.url, singletonPjax().options);
},
reparseDocument = function(){
singletonPjax().parseDom(document);
};

window.singletonPjax = singletonPjax;

window.addEventListener('pjax:reload', forceRefreshPjax);
window.addEventListener('pjax:create', singletonPjax);

window.addEventListener('pjax:refresh', function () {
singletonPjax().parseDom(document);
});
window.removeEventListener('pjax:reload', forceRefreshPjax);
window.removeEventListener('pjax:create', singletonPjax);
window.removeEventListener('pjax:refresh', reparseDocument);
window.removeEventListener('pjax:load', triggerLoadUrl);

window.addEventListener('pjax:load', function (url) {
singletonPjax().loadUrl(url, singletonPjax().options);
});
window.addEventListener('pjax:reload', forceRefreshPjax);
window.addEventListener('pjax:create', singletonPjax);
window.addEventListener('pjax:refresh', reparseDocument);
window.addEventListener('pjax:load', triggerLoadUrl);

0 comments on commit ba8f558

Please sign in to comment.