Extract the updater JS to its own file, add helper to find missing dependencies

This commit is contained in:
Samuel Georges 2015-02-21 22:59:09 +11:00
parent 320f7bfb1a
commit c559db0de6
4 changed files with 138 additions and 77 deletions

View File

@ -0,0 +1,110 @@
/*
* Updates class
*
* Dependences:
* - Waterfall plugin (waterfall.js)
*/
+function ($) { "use strict";
var UpdateProcess = function () {
// Init
this.init()
}
UpdateProcess.prototype.init = function() {
var self = this
this.activeStep = null
this.updateSteps = null
}
UpdateProcess.prototype.execute = function(steps) {
this.updateSteps = steps
this.runUpdate()
}
UpdateProcess.prototype.runUpdate = function(fromStep) {
$.waterfall.apply(this, this.buildEventChain(this.updateSteps, fromStep))
.fail(function(reason){
var
template = $('#executeFailed').html(),
html = Mustache.to_html(template, { reason: reason })
$('#executeActivity').hide()
$('#executeStatus').html(html)
})
}
UpdateProcess.prototype.retryUpdate = function() {
$('#executeActivity').show()
$('#executeStatus').html('')
this.runUpdate(this.activeStep)
}
UpdateProcess.prototype.buildEventChain = function(steps, fromStep) {
var self = this,
eventChain = [],
skipStep = fromStep ? true : false
$.each(steps, function(index, step){
if (step == fromStep)
skipStep = false
if (skipStep)
return true // Continue
eventChain.push(function(){
var deferred = $.Deferred()
self.activeStep = step
self.setLoadingBar(true, step.label)
$.request('onExecuteStep', {
data: step,
success: function(data){
setTimeout(function() { deferred.resolve() }, 600)
if (step.code == 'completeUpdate' || step.code == 'completeInstall')
this.success(data)
else
self.setLoadingBar(false)
},
error: function(data){
self.setLoadingBar(false)
deferred.reject(data.responseText)
}
})
return deferred
})
})
return eventChain
}
UpdateProcess.prototype.setLoadingBar = function(state, message) {
var loadingBar = $('#executeLoadingBar'),
messageDiv = $('#executeMessage')
if (state)
loadingBar.removeClass('bar-loaded')
else
loadingBar.addClass('bar-loaded')
if (message)
messageDiv.text(message)
}
if ($.oc === undefined)
$.oc = {}
$.oc.updateProcess = new UpdateProcess;
// $(document).ready(function(){
// new $oc.updateProcess
// })
}(window.jQuery);

View File

@ -511,7 +511,32 @@ class PluginManager
// //
// Dependencies // Dependencies
// //
/**
* Scans the system plugins to locate any dependencies
* that are not currently installed.
*/
public function findMissingDependencies()
{
$missing = [];
foreach ($this->plugins as $id => $plugin) {
if (!$required = $this->getDependencies($plugin)) {
continue;
}
foreach ($required as $require) {
if ($this->hasPlugin($require)) {
continue;
}
$missing[] = $require;
}
}
return $missing;
}
/** /**
* Cross checks all plugins and their dependancies, if not met plugins * Cross checks all plugins and their dependancies, if not met plugins
* are disabled and vice versa. * are disabled and vice versa.

View File

@ -36,6 +36,7 @@ class Updates extends Controller
{ {
parent::__construct(); parent::__construct();
$this->addJs('/modules/system/assets/js/updates/updates.js', 'core');
$this->addCss('/modules/system/assets/css/updates.css', 'core'); $this->addCss('/modules/system/assets/css/updates.css', 'core');
BackendMenu::setContext('October.System', 'system', 'updates'); BackendMenu::setContext('October.System', 'system', 'updates');

View File

@ -49,85 +49,10 @@
<script> <script>
var updateSteps = <?= json_encode($updateSteps) ?>,
activeStep = null
$('#executePopup').on('popupComplete', function(){ $('#executePopup').on('popupComplete', function(){
runUpdate() $.oc.updateProcess.execute(<?= json_encode($updateSteps) ?>)
}) })
function runUpdate(fromStep) {
$.waterfall.apply(this, buildEventChain(updateSteps, fromStep))
.fail(function(reason){
var
template = $('#executeFailed').html(),
html = Mustache.to_html(template, { reason: reason })
$('#executeActivity').hide()
$('#executeStatus').html(html)
})
}
function retryUpdate() {
$('#executeActivity').show()
$('#executeStatus').html('')
runUpdate(activeStep)
}
function buildEventChain(steps, fromStep) {
var eventChain = [],
skipStep = fromStep ? true : false
$.each(steps, function(index, step){
if (step == fromStep)
skipStep = false
if (skipStep)
return true // Continue
eventChain.push(function(){
var deferred = $.Deferred()
activeStep = step
setLoadingBar(true, step.label)
$.request('onExecuteStep', {
data: step,
success: function(data){
setTimeout(function() { deferred.resolve() }, 600)
if (step.code == 'completeUpdate' || step.code == 'completeInstall')
this.success(data)
else
setLoadingBar(false)
},
error: function(data){
setLoadingBar(false)
deferred.reject(data.responseText)
}
})
return deferred
})
})
return eventChain
}
function setLoadingBar(state, message) {
var loadingBar = $('#executeLoadingBar'),
messageDiv = $('#executeMessage')
if (state)
loadingBar.removeClass('bar-loaded')
else
loadingBar.addClass('bar-loaded')
if (message)
messageDiv.text(message)
}
</script> </script>
<?php else: ?> <?php else: ?>