Skip to content

Commit

Permalink
Update migrate-up.php
Browse files Browse the repository at this point in the history
Signed-off-by: ArchBlood <[email protected]>
  • Loading branch information
ArchBlood authored Apr 9, 2024
1 parent a6b83fa commit 24cc37f
Showing 1 changed file with 55 additions and 7 deletions.
62 changes: 55 additions & 7 deletions views/grunt/migrate-up.php
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
<?php

use yii\helpers\Html;
use yii\widgets\ActiveForm;
use yii\web\View;

/* @var $this yii\web\View */
/* @var $output array */

$this->title = 'Migrate Up';
$this->pageTitle = $this->title;
$this->params['breadcrumbs'][] = $this->title;

// Register PJAX library
$this->registerJsFile('@web/static/js/jquery.pjax.modified.js', ['position' => View::POS_HEAD]);
?>

<div id="migrate-up" class="panel panel-default">
Expand All @@ -16,10 +20,54 @@
<?= Html::encode($this->title) ?>
</div>
</div>
<div class="panel-body">
<?php if (isset($output)): ?>
<?= Html::tag('h2', 'Output'); ?>
<?= Html::tag('pre', implode("\n", $output)); ?>
<?php endif; ?>
<div class="panel-body" data-ui-widget="pjax-container">
<div id="output-container">
<?php if(isset($output)): ?>
<?= Html::tag('h2', 'Output'); ?>
<?= Html::tag('pre', implode("\n", $output)); ?>
<?php endif; ?>
</div>

<?php $form = ActiveForm::begin(['id' => 'migrate-up-form']); ?>

<div class="form-group">
<?= Html::submitButton('Run Command', ['id' => 'run-command-btn', 'class' => 'btn btn-primary']) ?>
</div>

<?php ActiveForm::end(); ?>
</div>
</div>
</div>

<?php
// Register JS to handle the PJAX button click
$this->registerJs('
$(document).on("submit", "#migrate-up-form", function(event) {
event.preventDefault();
var $form = $(this);
var $btn = $form.find(":submit");
var formData = $form.serialize();
$btn.button("loading");
$.ajax({
type: "POST",
url: $form.attr("action"),
data: formData,
success: function(response) {
if (response.success) {
// Update the container with the command output
$("#output-container").html("<h2>Output</h2><pre>" + response.output.join("\n") + "</pre>");
} else {
console.error(response.error);
}
},
error: function(xhr, status, error) {
console.error(error);
},
complete: function() {
$btn.button("reset");
}
});
});
');
?>

0 comments on commit 24cc37f

Please sign in to comment.