Skip to content

Commit

Permalink
#1571 frontend
Browse files Browse the repository at this point in the history
  • Loading branch information
hansmorb committed Apr 7, 2024
1 parent ebc6b0b commit ef6cff5
Show file tree
Hide file tree
Showing 10 changed files with 123 additions and 1 deletion.
6 changes: 6 additions & 0 deletions assets/admin/css/admin.css
Original file line number Diff line number Diff line change
Expand Up @@ -5063,6 +5063,12 @@ a.disabled {
}

/** Migration Settings */
#upgrade-in-progress,
#upgrade-done {
margin-top: 1rem;
display: none;
}

#migration-in-progress,
#migration-state,
#migration-done {
Expand Down
24 changes: 24 additions & 0 deletions assets/admin/js/admin.js
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,30 @@
(function($) {
"use strict";
$(function() {
$("#cmb2-metabox-migration #run-upgrade").on("click", function(event) {
event.preventDefault();
$("#upgrade-in-progress").show();
$("#run-upgrade").hide();
let data = {
task: 0,
"page:": 1
};
const runUpgrade = data => {
$.post(cb_ajax_run_upgrade.ajax_url, {
_ajax_nonce: cb_ajax_run_upgrade.nonce,
action: "cb_run_upgrade",
data: data
}, function(data) {
if (data.success) {
$("#upgrade-in-progress").hide();
$("#upgrade-done").show();
} else {
runUpgrade(data);
}
});
};
runUpgrade(data);
});
$("#cmb2-metabox-migration #migration-start").on("click", function(event) {
event.preventDefault();
$("#migration-state").show();
Expand Down
2 changes: 1 addition & 1 deletion assets/admin/js/admin.min.js

Large diffs are not rendered by default.

29 changes: 29 additions & 0 deletions assets/admin/js/src/migration.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,35 @@
(function ($) {
'use strict';
$(function () {
$('#cmb2-metabox-migration #run-upgrade').on('click', function (event) {
event.preventDefault();
$('#upgrade-in-progress').show();
$('#run-upgrade').hide();
let data = {
'task': 0,
'page:': 1,
};

const runUpgrade = (data) => {
$.post(
cb_ajax_run_upgrade.ajax_url,
{
_ajax_nonce: cb_ajax_run_upgrade.nonce,
action: "cb_run_upgrade",
data: data
},
function (data) {
if (data.success) {
$('#upgrade-in-progress').hide();
$('#upgrade-done').show();
} else {
runUpgrade(data)
}
});
};
runUpgrade(data);
});

$('#cmb2-metabox-migration #migration-start').on('click', function (event) {
event.preventDefault();
$('#migration-state').show();
Expand Down
7 changes: 7 additions & 0 deletions assets/admin/sass/partials/_migration.scss
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
#upgrade-in-progress,
#upgrade-done,
{
margin-top: 1rem;
display: none;
}

#migration-in-progress,
#migration-state,
#migration-done
Expand Down
10 changes: 10 additions & 0 deletions includes/Admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,16 @@ function commonsbooking_admin() {
)
);

// \CommonsBooking\Service\Upgrade Ajax tasks
wp_localize_script(
'cb-scripts-admin',
'cb_ajax_run_upgrade',
array(
'ajax_url' => admin_url( 'admin-ajax.php' ),
'nonce' => wp_create_nonce( 'cb_run_upgrade' ),
)
);

// Additional info for CMB2 to handle booking rules
wp_add_inline_script(
'cb-scripts-admin',
Expand Down
15 changes: 15 additions & 0 deletions includes/OptionsArray.php
Original file line number Diff line number Diff line change
Expand Up @@ -916,6 +916,21 @@
'title' => __( 'Migration', 'commonsbooking' ),
'id' => 'migration',
'field_groups' => array(
'upgrade' => array(
'title' => esc_html__( 'Finish upgrade to latest version', 'commonsbooking' ),
'id' => 'upgrade',
'desc' => commonsbooking_sanitizeHTML( __( 'Click here to finish the upgrade to the latest version. <br> This needs to be done after updating the plugin to a new version. <br> If you do not do this, the plugin may not work correctly.', 'commonsbooking' ) ),
'fields' => [
array(
'name' => commonsbooking_sanitizeHTML( __( 'Finish upgrade', 'commonsbooking' ) ),
'id' => 'upgrade-custom-field',
'type' => 'text',
'render_row_cb' => array( Migration::class, 'renderUpgradeForm' ),
)
],
'show_on_cb' => array( \CommonsBooking\Service\Upgrade::class, 'isAJAXUpgrade' )
),
// migration cb1 -> cb2
'migration' => array(
'title' => esc_html__( 'Migrate from Commons Booking Version 0.X', 'commonsbooking' ),
'id' => 'migration',
Expand Down
1 change: 1 addition & 0 deletions includes/Public.php
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@ function commonsbooking_public() {
if ( is_admin() ) {
add_action( 'wp_ajax_cb_start_migration', array( Migration::class, 'migrateAll' ) );
add_action( 'wp_ajax_cb_start_booking_migration', array( \CommonsBooking\Migration\Booking::class, 'ajaxMigrate' ) );
add_action( 'wp_ajax_cb_run_upgrade', array( \CommonsBooking\Service\Upgrade::class, 'runAJAXUpgradeTasks' ) );
}

// Map ajax
Expand Down
10 changes: 10 additions & 0 deletions src/Service/Upgrade.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace CommonsBooking\Service;

use CommonsBooking\Messages\AdminMessage;
use CommonsBooking\Model\Timeframe;
use CommonsBooking\Plugin;
use CommonsBooking\Settings\Settings;
Expand Down Expand Up @@ -124,6 +125,15 @@ public function run(): bool {
}
//upgrade needs to be run in AJAX
if ( $this->getTasksForUpgrade( self::$ajaxUpgradeTasks ) ) {
new AdminMessage(
'<b>CommonsBooking:</b> ' .
__( 'There are some tasks that need to be run to complete the update process. <br> This needs to be done so that the plugin can function correctly.', 'commonsbooking' )
. '<br>'
. '<a href=' . esc_url( admin_url( 'admin.php?page=commonsbooking_options_migration' ) ) . '>'
. __( 'Click here to run the upgrade tasks.', 'commonsbooking' ) . '</a>',
'warning'
);

return false;
}
}
Expand Down
20 changes: 20 additions & 0 deletions src/View/Migration.php
Original file line number Diff line number Diff line change
Expand Up @@ -110,4 +110,24 @@ public static function renderBookingMigrationForm( array $field_args, CMB2_Field
);
}

public static function renderUpgradeForm( array $field_args, CMB2_Field $field ) {
?>
<div class="cmb-row cmb-type-text">
<div id="upgrade-in-progress" class="blinking">
<strong style="color: red">
<?php echo esc_html__( 'upgrade in process .. please wait ...', 'commonsbooking' ); ?>
</strong>
</div>
<div id="upgrade-done">
<strong style="color: green">
<?php echo esc_html__( 'Upgrade finished', 'commonsbooking' ); ?>
</strong>
</div>
<a id="run-upgrade" class="button button-secondary" href="#">
<?php echo esc_html__( 'Start Upgrade', 'commonsbooking' ); ?>
</a>
</div>
<?php
}

}

0 comments on commit ef6cff5

Please sign in to comment.