diff --git a/app/controllers/cards_controller.rb b/app/controllers/cards_controller.rb index 84b92bc..e270692 100644 --- a/app/controllers/cards_controller.rb +++ b/app/controllers/cards_controller.rb @@ -9,6 +9,19 @@ class CardsController < ApplicationController #authorize! :read, @cards @cards = @cards.sort_by{|e| e[:id]} + if can? :read, DoorLog then + most_active_count = 0 + @most_active_card = nil + @cards.each do |card| + card_num_R = card.card_number.to_i(16)%32767 + card[:accesses_this_week] = DoorLog.where('key = "R" AND data =? AND created_at > ?', card_num_R, DateTime.now - 7.days).order("created_at DESC").count + if(card[:accesses_this_week] > most_active_count) then + most_active_count = card[:accesses_this_week] + @most_active_card = card + end + end + end + respond_to do |format| format.html # index.html.erb format.json { render :json => @cards } @@ -18,8 +31,10 @@ class CardsController < ApplicationController # GET /cards/1 # GET /cards/1.json def show - #@card = Card.find(params[:id]) - + if can? :read, DoorLog then + card_num_R = @card.card_number.to_i(16)%32767 + @door_logs = DoorLog.where('key = "R" AND data =?', card_num_R).order("created_at DESC") + end respond_to do |format| format.html # show.html.erb format.json { render :json => @card } diff --git a/app/views/cards/index.html.erb b/app/views/cards/index.html.erb index 1e02060..59779f6 100644 --- a/app/views/cards/index.html.erb +++ b/app/views/cards/index.html.erb @@ -2,6 +2,10 @@ <%= link_to 'New Card', new_card_path if can? :create, Card %> <%= link_to 'Upload all cards', upload_all_path if can? :upload_all, Card %> +
+Most Active Card Last 7 Days: <%= @most_active_card.name %> (<%= @most_active_card.accesses_this_week %> times) +
+DB ID | Card # | Access? | +Accesses Last 7 Days | @@ -22,11 +27,12 @@ <% if !@cards.blank? %> <% @cards.each do |card| %> | |||||
---|---|---|---|---|---|---|---|---|---|
<%= card.user.name %> | +<%= link_to card.user.name, card %> | <%= card.name %> | <%= card.id %> | <%= card.card_number %> | <%= if card.card_permissions == 1 then "Access" end %> | +<%= card.accesses_this_week unless card.accesses_this_week < 1 %> | <%= link_to 'Upload', upload_path(card) if can? :upload, card %> | <%= link_to 'Edit', edit_card_path(card) if can? :update, card %> | <%= link_to 'Destroy', card, :confirm => 'Are you sure? WARNING: THIS DOES NOT REMOVE THE CARD FROM THE DOOR SYSTEM! DISABLE AND UPLOAD IT FIRST.', :method => :delete if can? :destroy, card %> | diff --git a/app/views/cards/show.html.erb b/app/views/cards/show.html.erb index f77ec73..5d28dea 100644 --- a/app/views/cards/show.html.erb +++ b/app/views/cards/show.html.erb @@ -1,6 +1,6 @@