lib/perus/server/views/systems.erb in perus-0.1.7 vs lib/perus/server/views/systems.erb in perus-0.1.8

- old
+ new

@@ -1,17 +1,86 @@ -<h1><%= @title %></h1> +<h1> + <%= @title %> + <input type="text" id="system-search" placeholder="search: name, logical name, ip"> +</h1> -<% unless @systems.empty? %> - <% @systems.each do |(orientation, systems)| %> - <div class="<%= orientation %> systems"> - <% systems.each do |system| %> - <a href="<%= url_prefix %>systems/<%= system.id %>"> - <div class="screenshot" style="background-image: url(<%= system.screenshot_url %>)"></div> - <h1><%= system.name %></h1> - <p><%= system.logical_name %> - <%= system.ip || 'unknown IP' %></p> - </a> +<% @systems.each do |(orientation, systems)| %> + <div class="<%= orientation %> systems"> + <% systems.each do |system| %> + <a href="<%= url_prefix %>systems/<%= system.id %>" class="system"> + <div class="screenshot" style="background-image: url(<%= system.screenshot_url %>)"></div> + <h1 class="system-id"><%= system.name %></h1> + <p><span class="system-id"><%= system.logical_name %></span> - <span class="system-id"><%= system.ip || 'unknown IP' %></span></p> + <div class="alert <%= system.alert_class %>"></div> + </a> + <% end %> + </div> +<% end %> +<p id="no-systems" <% unless @systems.empty? %>style="display: none"<% end %>>No Systems</p> + +<p id="add-command"> + Add action to <%= @title %>: + <select id="command-select"> + <option></option> + <optgroup label="Commands"> + <% command_actions.each do |command| %> + <option value="<%= command.name %>"><%= command.human_name %></option> <% end %> - </div> - <% end %> -<% else %> - <p>No Systems</p> + </optgroup> + <optgroup label="Scripts"> + <% @scripts.each do |script| %> + <option value="<%= script.code_name %>"><%= script.name %></option> + <% end %> + </optgroup> + </select> +</p> + +<!-- new commands --> +<% command_actions.each do |command| %> + <%= erb :command_config, locals: {command: command, action: "#{url_prefix}#{@action_url}"} %> <% end %> +<% @scripts.each do |script| %> + <form class="command" data-command="<%= script.code_name %>" style="display: none" method="POST" action="<%= url_prefix %><%= @action_url %>"> + <h1><%= script.name %></h1> + <p><%= script.description %></p> + <input type="hidden" name="script_id" value="<%= script.id %>"> + <p class="actions"><input type="submit" value="Add"></p> + </form> +<% end %> + +<script> + $('#command-select').change(function() { + $('form.command').hide(); + $('form[data-command="' + $(this).val() + '"]').show(); + }); + + function filter() { + var allSystems = $('.system'); + var anyMatching = false; + var query = $.trim($('#system-search').val()).toLowerCase();; + + if (query == '') { + allSystems.show(); + anyMatching = true; + + } else { + allSystems.each(function(i, el) { + var system = $(el); + var ids = system.find('.system-id').text().toLowerCase(); + if (ids.includes(query)) { + anyMatching = true; + system.show(); + } else { + system.hide(); + } + }); + } + + if (anyMatching) + $('#no-systems').hide(); + else + $('#no-systems').show(); + } + + $('#system-search').keyup(filter); + $('#system-search').change(filter); +</script> \ No newline at end of file