Open-Source-Access-Control-.../app/views/macs/index.html.erb
2014-02-09 00:56:48 -07:00

79 lines
2.9 KiB
Plaintext
Executable File

<% if can? :read_details, Mac %>
<% if @mac_time_start_date.present? %>
<b>Most Active Machine Last <%= distance_of_time_in_words DateTime.now, @mac_time_start_date %>:</b>
<span title="<%= @most_active_mac.mac %><%= " - "+@most_active_mac.ip.to_s if can? :read_details, @most_active_mac %>">
<% if @most_active_mac.user.blank? %>
<%= @most_active_mac.mac %>
<% else %>
<%= @most_active_mac.user.name %>
<% end %>
<%= "("+@most_active_mac.note+")" unless @most_active_mac.note.blank? %>
- <%= (@most_active.last[:time] / 1.hour).round %> hrs
</span>
<br/>
<b>Runner Up:</b>
<span title="<%= @runner_up_mac.mac %><%= " - "+@runner_up_mac.ip.to_s if can? :read_details, @runner_up_mac %>">
<% if @runner_up_mac.user.blank? %>
<%= @runner_up_mac.mac %>
<% else %>
<%= @runner_up_mac.user.name %>
<% end %>
<%= "("+@runner_up_mac.note+")" unless @runner_up_mac.note.blank? %>
- <%= (@runner_up.last[:time] / 1.hour).round %> hrs
</span>
<% end %>
<% end %>
<h2>What machines are on our network?</h2>
<%= link_to "New MAC registration", new_mac_path, :class => 'btn' if can? :create, Mac %>
<%= link_to 'Activity Graph', macs_history_path, :class => 'btn' if can? :read_details, Mac %>
<ul class="mac_list">
<%
@active_macs.each do |mac|
Rails.logger.info mac.inspect %>
<li>
<span title="<%= mac.mac if user_signed_in? %><%= " - "+mac.ip.to_s if can? :read_details, mac %><%= " - "+((Time.now - mac.since) / 1.hour).round(1).to_s+" hours" if can? :manage, mac %>">
<%= mac.user.name unless mac.user.blank? %>
<%= mac.mac if mac.user.blank? %>
<%= "("+mac.note+")" unless mac.note.blank? %></span>
<%= link_to ' Edit', edit_mac_path(mac) if can? :update, mac %> <br/>
</li>
<% end %>
</ul>
<% unless can? :read_details, Mac %>
<p>To see more or register your own, login!</p>
<% end %>
<% if can? :read_details, Mac %>
<ul class="mac_list hidden">
<% @hidden_macs.each do |mac| %>
<li>
<span title="<%= mac.mac %><%= " - "+mac.ip.to_s if can? :read_details, mac %><%= " - "+((Time.now - mac.since) / 1.hour).round(1).to_s+" hours" if can? :manage, mac %>">
<%= mac.user.name unless mac.user.blank? %>
<%= "("+mac.note+")" unless mac.note.blank? %></span>
<%= link_to ' Edit', edit_mac_path(mac) if can? :update, mac %> <br/>
</li>
<% end %>
</ul>
<% end %>
<% if can? :manage, Mac %>
<h3>All MACs</h3>
<table>
<% @all_macs.each do |mac| %>
<tr <%= raw('class="hidden"') if mac.hidden? %>>
<td><%= mac.mac.downcase %> </td>
<td><%= mac.user.name unless mac.user.blank? %></td>
<td><%= "("+mac.note+")" unless mac.note.blank? %></td>
<td><%= if mac.active? then raw("<strong>Here</strong>") else "Gone" end %></td>
<td><%= ((Time.now - mac.since) / 1.hour).round(1).to_s+" hours" unless mac.since.blank? %></td>
<td><%= link_to 'Edit', edit_mac_path(mac) %></td>
</tr>
<% end %>
</table>
<% end %>