Skip to content

Commit 4d02d7a

Browse files
committed
Feature to update old plugin version
1 parent ed44fcf commit 4d02d7a

File tree

2 files changed

+23
-6
lines changed

2 files changed

+23
-6
lines changed

app/controllers/kpm/plugins_controller.rb

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,21 @@ def index
1010
@plugins = {}
1111

1212
@installed_plugin_keys = Set.new
13+
# Map of installed plugin_key => highest installed version found across nodes
14+
@installed_plugins = {}
1315
(nodes_info || []).each do |node_info|
1416
(node_info.plugins_info || []).each do |plugin_info|
15-
@installed_plugin_keys.add(plugin_info.plugin_key) unless plugin_info.plugin_key.nil?
17+
next if plugin_info.plugin_key.nil?
18+
19+
@installed_plugin_keys.add(plugin_info.plugin_key)
20+
next if plugin_info.version.nil?
21+
22+
current = @installed_plugins[plugin_info.plugin_key]
23+
begin
24+
@installed_plugins[plugin_info.plugin_key] = plugin_info.version if current.nil? || Gem::Version.new(plugin_info.version) > Gem::Version.new(current)
25+
rescue ArgumentError
26+
@installed_plugins[plugin_info.plugin_key] ||= plugin_info.version
27+
end
1628
end
1729
end
1830

app/views/kpm/plugins/_plugins_table.html.erb

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,16 @@
1313
<td><%= name %></td>
1414
<td><%= version %></td>
1515
<td>
16-
<% if @installed_plugin_keys.include?(name) %>
17-
<span class="label label-success">Installed</span>
18-
<% else %>
19-
<%= link_to 'Install', plugin_install_path(:plugin_key => name), :method => :post, :title => 'Install' %>
20-
<% end %>
16+
<% if @installed_plugin_keys.include?(name) %>
17+
<% installed_version = @installed_plugins && @installed_plugins[name] %>
18+
<% if installed_version.present? && version.present? && Gem::Version.new(installed_version) < Gem::Version.new(version) %>
19+
<%= link_to 'Update', plugin_install_path(:plugin_key => name), :method => :post, :title => 'Update' %>
20+
<% else %>
21+
<span class="label label-success">Installed</span>
22+
<% end %>
23+
<% else %>
24+
<%= link_to 'Install', plugin_install_path(:plugin_key => name), :method => :post, :title => 'Install' %>
25+
<% end %>
2126
</td>
2227
</tr>
2328
<% end %>

0 commit comments

Comments
 (0)