From 3e98d2f90858a416cdea78982a85e354d6662c18 Mon Sep 17 00:00:00 2001 From: Kyle Le Date: Mon, 2 Mar 2026 15:17:58 +0700 Subject: [PATCH] Improve install plugin screen --- app/controllers/kpm/nodes_info_controller.rb | 28 ++++++++++++- app/views/kpm/nodes_info/index.html.erb | 42 +++++++++++++++++++- config/routes.rb | 1 + 3 files changed, 68 insertions(+), 3 deletions(-) diff --git a/app/controllers/kpm/nodes_info_controller.rb b/app/controllers/kpm/nodes_info_controller.rb index 2f6b255..8a256bb 100644 --- a/app/controllers/kpm/nodes_info_controller.rb +++ b/app/controllers/kpm/nodes_info_controller.rb @@ -78,7 +78,33 @@ def refresh def install_plugin trigger_node_plugin_command('INSTALL_PLUGIN') - redirect_to nodes_info_index_path(i: 1) + redirect_to nodes_info_index_path(i: 1, plugin_key: params[:plugin_key], plugin_version: params[:plugin_version]) + end + + def plugin_status + plugin_key = params[:plugin_key] + plugin_version = params[:plugin_version] + + nodes_info = ::KillBillClient::Model::NodesInfo.nodes_info(options_for_klient) + installed = false + + nodes_info.each do |node_info| + next if node_info.plugins_info.nil? + + node_info.plugins_info.each do |plugin_info| + if plugin_info.plugin_key == plugin_key + # If plugin_version is specified, check for exact version match + # Otherwise, just check if any version of the plugin exists + if plugin_version.blank? || plugin_info.version == plugin_version + installed = true + break + end + end + end + break if installed + end + + render json: { installed: installed } end def uninstall_plugin diff --git a/app/views/kpm/nodes_info/index.html.erb b/app/views/kpm/nodes_info/index.html.erb index 0d00f4d..d08fbc5 100644 --- a/app/views/kpm/nodes_info/index.html.erb +++ b/app/views/kpm/nodes_info/index.html.erb @@ -112,14 +112,48 @@ }); <% if @installing %> + var pluginKey = '<%= params[:plugin_key].to_s.gsub("'", "\\'") %>'; + var pluginVersion = '<%= params[:plugin_version].to_s.gsub("'", "\\'") %>'; + var pollAttempts = 0; + var maxPollAttempts = 60; + var pollInterval = 1000; + $('.plugin-link').removeAttr('data-remote').removeAttr('data-method').removeAttr('href'); $('#nodes-table-wrapper').css({ opacity: 0.5 }); $('#install-in-progress').show(); $('#install-in-progress').children().addClass('fa-spin'); - setTimeout(fakeOperationComplete, 6000); + + function pollPluginStatus() { + pollAttempts++; + + if (pollAttempts > maxPollAttempts) { + operationComplete(); + return; + } + + $.ajax({ + url: '<%= plugin_status_path %>', + type: 'GET', + data: { plugin_key: pluginKey, plugin_version: pluginVersion }, + dataType: 'json', + success: function(response) { + if (response.installed) { + operationComplete(); + } else { + setTimeout(pollPluginStatus, pollInterval); + } + }, + error: function() { + setTimeout(pollPluginStatus, pollInterval); + } + }); + } + + // Start polling after a short initial delay + setTimeout(pollPluginStatus, 2000); <% end %> - function fakeOperationComplete() { + function operationComplete() { $('#install-in-progress').hide(); $('.plugin-link').removeClass('loading'); $('.official-plugin').removeClass('loading'); @@ -127,5 +161,9 @@ $('#nodes-table-wrapper').fadeTo("slow", 0.5); $('#reload-page').fadeIn("slow"); } + + function fakeOperationComplete() { + operationComplete(); + } }); <% end %> diff --git a/config/routes.rb b/config/routes.rb index 370a9f6..a41f07e 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -14,5 +14,6 @@ match '/plugin/start' => 'nodes_info#start_plugin', :via => :post, :as => 'plugin_start' match '/plugin/stop' => 'nodes_info#stop_plugin', :via => :post, :as => 'plugin_stop' match '/plugin/restart' => 'nodes_info#restart_plugin', :via => :post, :as => 'plugin_restart' + match '/plugin/status' => 'nodes_info#plugin_status', :via => :get, :as => 'plugin_status' end end