From 4b22a7952f32f648b0124f10dc4cd670bb49ad6f Mon Sep 17 00:00:00 2001 From: HB9HIL Date: Sun, 24 Mar 2024 15:22:25 +0100 Subject: [PATCH] updater frontend --- application/controllers/Debug.php | 4 ++ application/views/debug/index.php | 27 +++++++------- assets/js/sections/debug.js | 62 +++++++++++++++++++++++++++++++ 3 files changed, 79 insertions(+), 14 deletions(-) diff --git a/application/controllers/Debug.php b/application/controllers/Debug.php index f36a9864b..2a02817ec 100644 --- a/application/controllers/Debug.php +++ b/application/controllers/Debug.php @@ -166,6 +166,10 @@ class Debug extends CI_Controller redirect('debug'); } + public function wavelog_version() { + $version_tag = $this->optionslib->get_option('version'); + echo $version_tag; + } public function migrate_userdata() { // Check if users logged in diff --git a/application/views/debug/index.php b/application/views/debug/index.php index 9262228cb..215cbea1e 100644 --- a/application/views/debug/index.php +++ b/application/views/debug/index.php @@ -204,7 +204,7 @@ - + - - Last Fetch - - format(\DateTime::RFC850)); ?> - - - - Update Wavelog - Update - - +
+

+ +
+
+
+ + +
+
- + \ No newline at end of file diff --git a/assets/js/sections/debug.js b/assets/js/sections/debug.js index 6f9ca63fe..f0d33617f 100644 --- a/assets/js/sections/debug.js +++ b/assets/js/sections/debug.js @@ -44,3 +44,65 @@ function updateCallsign(item) { document.getElementById("station_call").innerHTML = call; } +function version_check(callback) { + var latest_tag; + $('#version_check_button').prop("disabled", true).addClass("running"); + $.ajax({ + url: base_url + 'index.php/debug/wavelog_version', + success: function(database_version) { + $.ajax({ + url: 'https://api.github.com/repos/wavelog/wavelog/tags', + type: 'GET', + success: function(tags) { + // Extract the latest tag + latest_tag = tags[0].name; + + // Compare database version with the latest tag + var is_latest_version = (database_version === latest_tag); + + // Call the callback function with the result + callback(is_latest_version, latest_tag); + $('#version_check_button').prop("disabled", false).removeClass("running"); + }, + error: function(xhr, status, error) { + console.error('ERROR fetching Git tags:', error); + callback(null, null); + $('#version_check_button').prop("disabled", false).removeClass("running"); + } + }); + }, + error: function(xhr, status, error) { + console.error('ERROR fetching database version:', error); + callback(null, null); + } + }); +} + +function update_version_check() { + version_check(function(is_latest_version, latest_tag) { + $('#version_check_result').removeClass('alert alert-success alert-warning alert-danger').text(''); + $('#version_update_button').hide(); + var timestamp = Date.now(); + + if (is_latest_version !== null) { + if (is_latest_version) { + $('#version_check_result').addClass('alert alert-success'); + $('#version_check_result').text("Wavelog is up to date!"); + } else { + $('#version_check_result').addClass('alert alert-warning'); + $('#version_check_result').text("There is a newer version available: " + latest_tag); + $('#version_update_button').show(); + } + } else { + $('#version_check_result').addClass('alert alert-danger'); + $('#version_check_result').text("Failed to determine the latest version."); + } + + $('#last_version_check').text("Last version check: " + new Date(timestamp).toUTCString()); + }); +} + +$(document).ready(function () { + update_version_check(); +}); +