Usability tweaks, creating merges, fixing issues
This commit is contained in:
parent
20a007cac5
commit
75e4907a9c
|
@ -10,12 +10,16 @@ class CardsController < ApplicationController
|
||||||
@cards = @cards.sort_by{|e| e[:id]}
|
@cards = @cards.sort_by{|e| e[:id]}
|
||||||
|
|
||||||
if can? :read, DoorLog then
|
if can? :read, DoorLog then
|
||||||
|
Rails.logger.info "CARD STATS:"
|
||||||
most_active_count = 0
|
most_active_count = 0
|
||||||
@most_active_card = nil
|
@most_active_card = nil
|
||||||
@cards.each do |card|
|
@cards.each do |card|
|
||||||
card_num_R = card.card_number.to_i(16)%32767
|
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
|
Rails.logger.info card_num_R
|
||||||
|
card[:accesses_this_week] = DoorLog.where('key = "G" AND data =? AND created_at > ?', card_num_R, DateTime.now - 7.days).order("created_at DESC").count
|
||||||
|
Rails.logger.info card[:accesses_this_week]
|
||||||
if(card[:accesses_this_week] > most_active_count) then
|
if(card[:accesses_this_week] > most_active_count) then
|
||||||
|
Rails.logger.info "ACTIVE"
|
||||||
most_active_count = card[:accesses_this_week]
|
most_active_count = card[:accesses_this_week]
|
||||||
@most_active_card = card
|
@most_active_card = card
|
||||||
end
|
end
|
||||||
|
|
|
@ -43,6 +43,14 @@ class UsersController < ApplicationController
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# GET /user_summary/1
|
||||||
|
def user_summary
|
||||||
|
respond_to do |format|
|
||||||
|
format.html { render :partial => "user_summary" } # show.html.erb
|
||||||
|
format.json { render :json => @user }
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
# GET /users/new
|
# GET /users/new
|
||||||
# GET /users/new.json
|
# GET /users/new.json
|
||||||
def new
|
def new
|
||||||
|
@ -84,6 +92,37 @@ class UsersController < ApplicationController
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# GET /users/merge
|
||||||
|
def merge_view
|
||||||
|
@users = @users.sort_by(&:name)
|
||||||
|
|
||||||
|
respond_to do |format|
|
||||||
|
format.html # merge_view.html.erb
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
# POST /users/merge
|
||||||
|
def merge_action
|
||||||
|
@user_to_keep = User.find(params[:user][:to_keep])
|
||||||
|
Rails.logger.info "USER TO KEEP:"
|
||||||
|
Rails.logger.info @user_to_keep.inspect
|
||||||
|
@user_to_merge = User.find(params[:user][:to_merge])
|
||||||
|
Rails.logger.info "USER TO MERGE:"
|
||||||
|
Rails.logger.info @user_to_merge.inspect
|
||||||
|
|
||||||
|
@user_to_keep.absorb_user(@user_to_merge)
|
||||||
|
|
||||||
|
Rails.logger.info "RESULT:"
|
||||||
|
Rails.logger.info @user_to_keep.inspect
|
||||||
|
Rails.logger.info @user_to_keep.cards.inspect
|
||||||
|
Rails.logger.info @user_to_keep.user_certifications.inspect
|
||||||
|
Rails.logger.info @user_to_keep.payments.inspect
|
||||||
|
|
||||||
|
respond_to do |format|
|
||||||
|
format.html { redirect_to @user_to_keep, :notice => 'Users successfully merged.' }
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
# DELETE /users/1
|
# DELETE /users/1
|
||||||
# DELETE /users/1.json
|
# DELETE /users/1.json
|
||||||
def destroy
|
def destroy
|
||||||
|
|
|
@ -40,8 +40,8 @@ class Ability
|
||||||
end
|
end
|
||||||
|
|
||||||
# Prevent all destruction for now
|
# Prevent all destruction for now
|
||||||
cannot :destroy, User
|
#cannot :destroy, User
|
||||||
cannot :destroy, Card
|
#cannot :destroy, Card
|
||||||
cannot :destroy, Certification
|
cannot :destroy, Certification
|
||||||
cannot :destroy, Mac
|
cannot :destroy, Mac
|
||||||
cannot :destroy, MacLog
|
cannot :destroy, MacLog
|
||||||
|
|
|
@ -18,6 +18,48 @@ class User < ActiveRecord::Base
|
||||||
|
|
||||||
after_create :send_new_user_email
|
after_create :send_new_user_email
|
||||||
|
|
||||||
|
def absorb_user(user_to_absorb)
|
||||||
|
# copy all attributes except email, password, name, and anything that isn't blank on the destination
|
||||||
|
user_to_absorb.attributes.each_pair {|k,v|
|
||||||
|
unless (v.nil? || k == :id || k == :email || k == :password || k == :name || k == :password_confirmation || k == :hidden || k == 'hidden' || k == :encrypted_password || !self.attributes[k].blank? )
|
||||||
|
Rails.logger.info "Updating "+k.to_s+" from "+self[k].to_s
|
||||||
|
self[k] = v
|
||||||
|
Rails.logger.info "Updated "+k.to_s+" to "+self[k].to_s
|
||||||
|
end
|
||||||
|
}
|
||||||
|
|
||||||
|
self.save!
|
||||||
|
|
||||||
|
user_to_absorb.cards.each {|card|
|
||||||
|
Rails.logger.info "CARD BEFORE: "+card.inspect
|
||||||
|
card.user_id = self.id
|
||||||
|
card.save!
|
||||||
|
Rails.logger.info "CARD AFTER: "+card.inspect
|
||||||
|
}
|
||||||
|
user_to_absorb.user_certifications.each {|user_cert|
|
||||||
|
Rails.logger.info "CERT BEFORE: "+user_cert.inspect
|
||||||
|
user_cert.user_id = self.id
|
||||||
|
user_cert.save!
|
||||||
|
Rails.logger.info "CERT AFTER: "+user_cert.inspect
|
||||||
|
}
|
||||||
|
user_to_absorb.payments.each {|payment|
|
||||||
|
Rails.logger.info "PAYMENT BEFORE: "+payment.inspect
|
||||||
|
payment.user_id = self.id
|
||||||
|
payment.save!
|
||||||
|
Rails.logger.info "PAYMENT AFTER: "+payment.inspect
|
||||||
|
}
|
||||||
|
|
||||||
|
user_to_absorb.destroy
|
||||||
|
end
|
||||||
|
|
||||||
|
def name_with_email_and_visibility
|
||||||
|
if hidden then
|
||||||
|
"#{name} (#{email}) HIDDEN"
|
||||||
|
else
|
||||||
|
"#{name} (#{email})"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def name_with_payee_and_member_level
|
def name_with_payee_and_member_level
|
||||||
if payee.blank? then
|
if payee.blank? then
|
||||||
"#{name} - #{member_level_string}"
|
"#{name} - #{member_level_string}"
|
||||||
|
|
|
@ -28,7 +28,13 @@
|
||||||
<% if !@cards.blank? %>
|
<% if !@cards.blank? %>
|
||||||
<% @cards.each do |card| %>
|
<% @cards.each do |card| %>
|
||||||
<tr>
|
<tr>
|
||||||
<td><%= link_to card.user.name, card %></td>
|
<td>
|
||||||
|
<% if card.user.nil? %>
|
||||||
|
n/a
|
||||||
|
<% else %>
|
||||||
|
<%= link_to card.user.name , card %>
|
||||||
|
<% end %>
|
||||||
|
</td>
|
||||||
<td><%= card.name %></td>
|
<td><%= card.name %></td>
|
||||||
<td><%= card.id %></td>
|
<td><%= card.id %></td>
|
||||||
<td><%= card.card_number %></td>
|
<td><%= card.card_number %></td>
|
||||||
|
|
95
app/views/users/_user_summary.html.erb
Normal file
95
app/views/users/_user_summary.html.erb
Normal file
|
@ -0,0 +1,95 @@
|
||||||
|
<% user ||= @user #unless @user.blank? %>
|
||||||
|
|
||||||
|
<p>
|
||||||
|
<b>Name:</b>
|
||||||
|
<%= user.name %>
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<% if current_user.admin? then %>
|
||||||
|
<p>
|
||||||
|
<b>Email:</b>
|
||||||
|
<%= user.email %>
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<p>
|
||||||
|
<b>Orientation?</b>
|
||||||
|
<%= user.orientation.strftime("%B %d %Y") unless user.orientation.blank? %>
|
||||||
|
</p>
|
||||||
|
<% end %>
|
||||||
|
|
||||||
|
<p>
|
||||||
|
<b>Waiver?</b>
|
||||||
|
<%= user.waiver.strftime("%B %d %Y") unless user.waiver.blank? %>
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<p>
|
||||||
|
<b>Current Member?</b>
|
||||||
|
<%= raw(user.member_status_symbol) %>
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<% if current_user.admin? then %>
|
||||||
|
<p>
|
||||||
|
<b>Desired Member Level:</b>
|
||||||
|
<%= user.member_level %>
|
||||||
|
</p>
|
||||||
|
<p>
|
||||||
|
<b>Payment Method:</b>
|
||||||
|
<%= user.payment_method %>
|
||||||
|
</p>
|
||||||
|
<p>
|
||||||
|
<b>Payee:</b>
|
||||||
|
<%= user.payee %>
|
||||||
|
</p>
|
||||||
|
<p>
|
||||||
|
<b>Phone:</b>
|
||||||
|
<%= user.phone %>
|
||||||
|
</p>
|
||||||
|
<% end %>
|
||||||
|
<p>
|
||||||
|
<b>Current Skills:</b>
|
||||||
|
<%= simple_format user.current_skills %>
|
||||||
|
</p>
|
||||||
|
<p>
|
||||||
|
<b>Desired Skills:</b>
|
||||||
|
<%= simple_format user.desired_skills %>
|
||||||
|
</p>
|
||||||
|
<p>
|
||||||
|
<b>Card:</b>
|
||||||
|
<% if current_user.admin? then %>
|
||||||
|
<% user.cards.each do |c| %>
|
||||||
|
<%= link_to c.card_number, c %><%= "," unless c == user.cards.last %>
|
||||||
|
<% end %>
|
||||||
|
<% else %>
|
||||||
|
<%= unless user.cards.blank? then raw("✓") end %>
|
||||||
|
<% end %>
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<b>Certifications:</b>
|
||||||
|
<ul>
|
||||||
|
<% user.certifications.each do |certification| %>
|
||||||
|
<li><%= link_to certification.name, certification %></li>
|
||||||
|
<% end %>
|
||||||
|
<% if user.certifications.blank? %><li>n/a</li><% end %>
|
||||||
|
</ul>
|
||||||
|
|
||||||
|
<% if current_user.admin? then %>
|
||||||
|
<p>
|
||||||
|
<b>Payments:</b>
|
||||||
|
<ul>
|
||||||
|
<% user.payments.each do |payment| %>
|
||||||
|
<li><%= payment.date %></li>
|
||||||
|
<% end %>
|
||||||
|
</ul>
|
||||||
|
</p>
|
||||||
|
<% end %>
|
||||||
|
|
||||||
|
<% if current_user.admin? then %>
|
||||||
|
<p>
|
||||||
|
<b>Created:</b>
|
||||||
|
<%= user.created_at %>
|
||||||
|
</p>
|
||||||
|
<p>
|
||||||
|
<b>Last signed in:</b>
|
||||||
|
<%= user.current_sign_in_at %>
|
||||||
|
</p>
|
||||||
|
<% end %>
|
|
@ -3,6 +3,9 @@
|
||||||
<% if can? :create, User %>
|
<% if can? :create, User %>
|
||||||
<%= link_to 'New User', new_user_path %>
|
<%= link_to 'New User', new_user_path %>
|
||||||
<% end %>
|
<% end %>
|
||||||
|
<% if can? :manage, User %>
|
||||||
|
| <%= link_to 'Merge Users', users_merge_path %>
|
||||||
|
<% end %>
|
||||||
<table>
|
<table>
|
||||||
<col />
|
<col />
|
||||||
<col />
|
<col />
|
||||||
|
|
48
app/views/users/merge_view.html.erb
Normal file
48
app/views/users/merge_view.html.erb
Normal file
|
@ -0,0 +1,48 @@
|
||||||
|
<style type="text/css">
|
||||||
|
#user_to_merge_details, #user_to_keep_details,
|
||||||
|
#user_to_merge_details p, #user_to_keep_details p {
|
||||||
|
font-size: 12px;
|
||||||
|
margin: 0;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
|
||||||
|
<h1>Merging users</h1>
|
||||||
|
|
||||||
|
<%= form_tag('/users/merge', :method => :post) do %>
|
||||||
|
<b>Everything except the email, password, name, id, hidden, and blank values will be moved to the "user to keep" UNLESS there is a value already there. The "user to merge" will be deleted.</b>
|
||||||
|
<table>
|
||||||
|
<tr>
|
||||||
|
<td>
|
||||||
|
<div class="field">
|
||||||
|
<%= label_tag :user_to_keep, "User to Keep" %><br />
|
||||||
|
<%= collection_select(:user, :to_keep, @users, :id, :name_with_email_and_visibility, :include_blank => true) %>
|
||||||
|
</div>
|
||||||
|
<div id="user_to_keep_details"></div>
|
||||||
|
</td>
|
||||||
|
<td style="font-size: 16px">◀◀</td>
|
||||||
|
<td>
|
||||||
|
<div class="field">
|
||||||
|
<%= label_tag :user_to_merge, "User to Merge" %><br />
|
||||||
|
<%= collection_select(:user, :to_merge, @users, :id, :name_with_email_and_visibility, :include_blank => true) %>
|
||||||
|
</div>
|
||||||
|
<div id="user_to_merge_details"></div>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
</table>
|
||||||
|
|
||||||
|
<hr/>
|
||||||
|
<div class="actions">
|
||||||
|
<%= submit_tag "Merge" %>
|
||||||
|
</div>
|
||||||
|
<% end %>
|
||||||
|
|
||||||
|
<%= link_to 'Back', users_path %>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
$("#user_to_keep").change(function(event,handler){
|
||||||
|
$("#user_to_keep_details").load("/user_summary/"+event.target.value);
|
||||||
|
});
|
||||||
|
$("#user_to_merge").change(function(event,handler){
|
||||||
|
$("#user_to_merge_details").load("/user_summary/"+event.target.value);
|
||||||
|
});
|
||||||
|
</script>
|
|
@ -18,6 +18,9 @@ Dooraccess::Application.routes.draw do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
match 'user_summary/:id' => 'users#user_summary' # User summary view
|
||||||
|
match 'users/merge' => 'users#merge_view', :via => :get # Merge view
|
||||||
|
match 'users/merge' => 'users#merge_action', :via => :post # Merge action
|
||||||
resources :users
|
resources :users
|
||||||
match 'users/create' => 'users#create', :via => :post # Use POST users/create instead of POST users to avoid devise conflict
|
match 'users/create' => 'users#create', :via => :post # Use POST users/create instead of POST users to avoid devise conflict
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user