Parcourir la source

add better search function

Christian Mague il y a 7 ans
Parent
commit
9f3ff68bdc
3 fichiers modifiés avec 65 ajouts et 0 suppressions
  1. 12 0
      lib/neoinfra/nodes.rb
  2. 9 0
      web/controllers/search.rb
  3. 44 0
      web/views/view_nodes.erb

+ 12 - 0
lib/neoinfra/nodes.rb

@@ -34,6 +34,18 @@ module NeoInfra
       }
     end
 
+    def search_nodes_by_name(name)
+      results = {:nodes => [], :errors => []}
+      if !Node.where(name: name).empty?
+        Node.where(name: name).each do |k|
+          results[:nodes] << display_node(k.node_id)
+        end
+      else
+        results[:errors] << "Could not find a node with name: #{name}"
+      end
+      return results
+    end
+
     def search_nodes_by_ip(ip)
       if !Node.where(ip: ip).empty?
         display_node(Node.where(ip: ip).first.node_id)

+ 9 - 0
web/controllers/search.rb

@@ -34,6 +34,15 @@ class Search < Sinatra::Base
               locals: { node: n.search_nodes_by_node_id(params['search']) }
         end
       end
+    else
+      n = NeoInfra::Nodes.new
+      respond_to do |wants|
+        wants.html do
+          erb :view_nodes,
+              layout: :base_layout,
+              locals: { nodes: n.search_nodes_by_name(params['search']) }
+        end
+      end
     end
   end
 end

+ 44 - 0
web/views/view_nodes.erb

@@ -0,0 +1,44 @@
+<h2 class="title"><br><br><center>Node Information</center><br><br></h2>
+<div class="container">
+
+<% if nodes[:errors].length > 0 %>
+<% nodes[:errors].each do |e| %>
+	<br><%= e %>
+<% end %>
+<% else %>
+
+<table class="table table-hover">
+<tbody>
+<tr> <th>Name</th>
+<th>IP</th>
+<th>Public IP</th>
+<th>Account</th>
+<th>Size</th>
+<th>Subnet</th>
+<th>AZ</th>
+<th>VPC</th>
+<th>AMI</th>
+<th>State</th>
+<th>Security Group</th>
+<tr>
+<% nodes[:nodes].each do |n| %>
+<tr>
+	<td><%= n['Name'] %></td>
+	<td><%= n['IP'] %></td>
+	<td><%= n['Public_IP'] %></td>
+	<td><%= n['Account'] %></td>
+	<td><%= n['Size'] %></td>
+	<td><%= n['Subnet'] %></td>
+	<td><%= n['AZ'] %></td>
+	<td><%= n['VPC'] %></td>
+	<td><%= n['AMI'] %></td>
+	<td><%= n['State'] %></td>
+	<td><%= n['SecurityGroup'] %></td>
+</tr>
+<% end %>
+</tbody>
+</table>
+
+<% end %>
+
+</div>