From 74d3fc45dd2f8941f1e6c4c0aad17e8db7bf4179 Mon Sep 17 00:00:00 2001 From: Will Bradley Date: Thu, 10 Apr 2014 19:19:28 -0700 Subject: [PATCH 1/6] Adding faker --- Gemfile | 2 +- Gemfile.lock | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/Gemfile b/Gemfile index 8ceeaea..58016d9 100644 --- a/Gemfile +++ b/Gemfile @@ -3,7 +3,7 @@ source 'https://rubygems.org' ruby '1.9.3' gem 'rails', '3.2.8' - +gem 'faker' gem 'dotenv-rails' # Bundle edge Rails instead: diff --git a/Gemfile.lock b/Gemfile.lock index e597316..2bed00e 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -58,6 +58,8 @@ GEM dotenv (= 0.10.0) erubis (2.7.0) execjs (2.0.2) + faker (1.3.0) + i18n (~> 0.5) gravtastic (3.2.6) hike (1.2.3) i18n (0.6.5) @@ -162,6 +164,7 @@ DEPENDENCIES coffee-rails (~> 3.2.1) devise dotenv-rails + faker gravtastic jquery-rails json From 13e72fef231b670a2cea57ccc3d4cf5185a9540f Mon Sep 17 00:00:00 2001 From: Will Bradley Date: Thu, 10 Apr 2014 19:45:29 -0700 Subject: [PATCH 2/6] Fixing issue #19 and also styling homepage --- app/controllers/contracts_controller.rb | 3 +- app/controllers/home_controller.rb | 77 ++++++++++------- app/models/contract.rb | 5 +- app/views/home/index.html.erb | 86 ++++++++----------- app/views/layouts/application.html.erb | 1 + app/views/layouts/resources.html.erb | 1 + ...140411022819_add_created_by_to_contract.rb | 5 ++ db/schema.rb | 3 +- 8 files changed, 98 insertions(+), 83 deletions(-) create mode 100644 db/migrate/20140411022819_add_created_by_to_contract.rb diff --git a/app/controllers/contracts_controller.rb b/app/controllers/contracts_controller.rb index 0b66c9c..02c8104 100644 --- a/app/controllers/contracts_controller.rb +++ b/app/controllers/contracts_controller.rb @@ -18,6 +18,7 @@ class ContractsController < ApplicationController def create Rails.logger.info "CONTRACT" Rails.logger.info @contract.inspect + @contract.created_by = current_user.id respond_to do |format| if @contract.save format.html { redirect_to @contract, :notice => 'Contract was successfully created.' } @@ -51,6 +52,6 @@ class ContractsController < ApplicationController end def load_users - @users = @users = User.accessible_by(current_ability).sort_by(&:name) + @users = User.accessible_by(current_ability).sort_by(&:name) end end diff --git a/app/controllers/home_controller.rb b/app/controllers/home_controller.rb index 61422ed..7f7490c 100755 --- a/app/controllers/home_controller.rb +++ b/app/controllers/home_controller.rb @@ -1,38 +1,53 @@ class HomeController < ApplicationController + layout 'resources' -def index - @num_certs = UserCertification.count - @recent_certs = UserCertification.where("created_at > ?", DateTime.now - 7.days).count - @num_users = User.count - @recent_users = User.where("created_at > ?", DateTime.now - 7.days).count - # Payments: member levels are multipled by 10 to indicate current payment; 25 x 10 = 250 - @num_paid_users = User.all.select{|u| u.member_status >= 250 }.count - @num_plus_users = User.all.select{|u| u.member_status == 1000 }.count - @num_basic_users = User.all.select{|u| u.member_status == 500 }.count - @num_associate_users = User.all.select{|u| u.member_status == 250 }.count - @num_delinquent_users = User.all.select{|u| !u.payment_status }.count - if can? :read, User then - @recent_user_names = User.where("member_level > 10").accessible_by(current_ability).order('created_at desc').limit(5) - end - @num_door_opens = DoorLog.where("key = 'G'").count - @today_door_opens = DoorLog.where("key = 'G' AND created_at > ?", DateTime.now - 1.day).count - @recent_door_opens = DoorLog.where("key = 'G' AND created_at > ?", DateTime.now - 7.days).count - @num_door_denieds = DoorLog.where("key = 'D'").count - @recent_door_denieds = DoorLog.where("key = 'D' AND created_at > ?", DateTime.now - 1.month).count - @num_logins = User.sum('sign_in_count') - @recent_logins = User.where('current_sign_in_at > ?',Date.today - 7.days).count - @num_macs = Mac.count - @recent_macs = Mac.where("since > ?", DateTime.now - 1.day).count - - respond_to do |format| - format.html # index.html.erb + def index + # Alerts + if user_signed_in? && current_user.orientation.blank? then + flash[:alert] = "There's a lot more to see here, but our records show you haven't completed the new member orientation yet. If that's incorrect, please contact a volunteer." + end + if user_signed_in? && current_user.member_status.between?(2,100) then + flash[:alert] = " + Looks like we haven't acknowledged a recent payment for you yet. This could be because we're slow, but if in doubt please see your profile for payment instructions, consider updating your membership level to something accurate, or contact us.
Thanks for supporting us!" end -end -def more_info - respond_to do |format| - format.html # more_info.html.erb + # Fun Stats + + @num_certs = UserCertification.count + @recent_certs = UserCertification.where("created_at > ?", DateTime.now - 7.days).count + @num_users = User.count + @recent_users = User.where("created_at > ?", DateTime.now - 7.days).count + # Payments: member levels are multipled by 10 to indicate current payment; 25 x 10 = 250 + @num_paid_users = User.all.select{|u| u.member_status >= 250 }.count + @num_plus_users = User.all.select{|u| u.member_status == 1000 }.count + @num_basic_users = User.all.select{|u| u.member_status == 500 }.count + @num_associate_users = User.all.select{|u| u.member_status == 250 }.count + @num_delinquent_users = User.all.select{|u| !u.payment_status }.count + if can? :read, User then + @recent_user_names = User.where("member_level > 10").accessible_by(current_ability).order('created_at desc').limit(5) + end + @num_door_opens = DoorLog.where("key = 'G'").count + @today_door_opens = DoorLog.where("key = 'G' AND created_at > ?", DateTime.now - 1.day).count + @recent_door_opens = DoorLog.where("key = 'G' AND created_at > ?", DateTime.now - 7.days).count + @num_door_denieds = DoorLog.where("key = 'D'").count + @recent_door_denieds = DoorLog.where("key = 'D' AND created_at > ?", DateTime.now - 1.month).count + @num_logins = User.sum('sign_in_count') + @recent_logins = User.where('current_sign_in_at > ?',Date.today - 7.days).count + @num_macs = Mac.count + @recent_macs = Mac.where("since > ?", DateTime.now - 1.day).count + + respond_to do |format| + format.html # index.html.erb + end + end + + def more_info + respond_to do |format| + format.html # more_info.html.erb + end end -end end diff --git a/app/models/contract.rb b/app/models/contract.rb index a588fe3..5df4b68 100644 --- a/app/models/contract.rb +++ b/app/models/contract.rb @@ -1,6 +1,9 @@ class Contract < ActiveRecord::Base belongs_to :user - attr_accessible :user_id, :first_name, :last_name, :cosigner, :signed_at, :document, :document_file_name, :document_content_type, :document_file_size, :document_updated_at + attr_accessible :user_id, :first_name, :last_name, :cosigner, + :signed_at, :document, :document_file_name, :document_content_type, + :document_file_size, :document_updated_at + # :created_by not accessible for security purposes validates_presence_of :first_name, :signed_at #, :last_name diff --git a/app/views/home/index.html.erb b/app/views/home/index.html.erb index 70a0ed8..abdc4e6 100755 --- a/app/views/home/index.html.erb +++ b/app/views/home/index.html.erb @@ -3,55 +3,43 @@ <%= simple_format Setting.welcome_body %> <% end %> - -<% if user_signed_in? && current_user.orientation.blank? then %> -

There's a lot more to see here, but our records show you haven't completed the new member orientation yet. If that's incorrect, please contact a volunteer.

-<% end %> -<% if user_signed_in? && current_user.member_status.between?(2,100) then %> -<%= current_user.member.inspect %> -<%= current_user.member_level.inspect %> -

Looks like we haven't acknowledged a recent payment for you yet. This could be because we're slow, or this app just got started, but if in doubt please see your profile for payment instructions, or consider updating your membership level to something accurate.
Thanks for supporting HeatSync!

-<% end %> - - - - - -
-<% if ((can? :read, User) && (@recent_user_names.count > 1)) then %> -

New People: (say hi!)

-
    -<% @recent_user_names.each do |user| %> - <% if can? :read, user %> -
  • <%= link_to user.name, user %> <%= raw(user.member_status_symbol) %> (Signed up <%= user.created_at.strftime("%b %d") %>)
  • +
    + <% if ((can? :read, User) && (@recent_user_names.count > 1)) then %> +

    New People: (say hi!)

    +
      + <% @recent_user_names.each do |user| %> + <% if can? :read, user %> +
    • <%= link_to user.name, user %> <%= raw(user.member_status_symbol) %> (Signed up <%= user.created_at.strftime("%b %d") %>)
    • + <% end %> + <% end %> +
    <% end %> -<% end %> -
-<% end %> -

Cool Stats:

-
-
# of People in this DB:
-
<%= @num_users %> (<%= @recent_users %> new in the last 7 days)
-
# of People Certified:
-
<%= @num_certs %> (<%= @recent_certs %> new in the last 7 days)
-
# of Current Paying Members:
-
<%= @num_paid_users %> (<%= @num_plus_users %> plus, <%= @num_basic_users %> basic, <%= @num_associate_users %> associate. <%= @num_delinquent_users %> not-current)
-
# of Door Accesses Granted:
-
<%= @num_door_opens %> (<%= @today_door_opens %> today, <%= @recent_door_opens %> in the last 7 days)
-
# of Door Accesses Denied:
-
<%= @num_door_denieds %> (<%= @recent_door_denieds %> in the last month)
-
# of Members DB Logins:
-
<%= @num_logins %> (<%= @recent_logins %> users last 7 days)
-
# of Computers in this DB:
-
<%= @num_macs %> (<%= @recent_macs %> seen today)
-
+ -
+
+

Cool Stats:

+
+
# of People in this DB:
+
<%= @num_users %> (<%= @recent_users %> new in the last 7 days)
+
# of People Certified:
+
<%= @num_certs %> (<%= @recent_certs %> new in the last 7 days)
+
# of Current Paying Members:
+
<%= @num_paid_users %> (<%= @num_plus_users %> plus, <%= @num_basic_users %> basic, <%= @num_associate_users %> associate. <%= @num_delinquent_users %> not-current)
+
# of Door Accesses Granted:
+
<%= @num_door_opens %> (<%= @today_door_opens %> today, <%= @recent_door_opens %> in the last 7 days)
+
# of Door Accesses Denied:
+
<%= @num_door_denieds %> (<%= @recent_door_denieds %> in the last month)
+
# of Members DB Logins:
+
<%= @num_logins %> (<%= @recent_logins %> users last 7 days)
+
# of Computers in this DB:
+
<%= @num_macs %> (<%= @recent_macs %> seen today)
+
+
-

Member Resources

-<% if can? :access_doors_remotely, :door_access %> -
  • <%= link_to "Remote Door Access", space_api_access_path %>
-<% end %> -<%= simple_format Setting.member_resources_inset %> - -
+
+

Member Resources

+ <% if can? :access_doors_remotely, :door_access %> +
  • <%= link_to "Remote Door Access", space_api_access_path %>
+ <% end %> + <%= simple_format Setting.member_resources_inset %> +
\ No newline at end of file diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb index 1e83331..a7f78e8 100755 --- a/app/views/layouts/application.html.erb +++ b/app/views/layouts/application.html.erb @@ -2,6 +2,7 @@ hsl_members(<%= controller.controller_name %>.<%= controller.action_name %><%= "["+params[:id]+"]" unless params[:id].blank? %>) + <% if params[:controller] == "resources" %> diff --git a/app/views/layouts/resources.html.erb b/app/views/layouts/resources.html.erb index 2af4f5a..857eef0 100755 --- a/app/views/layouts/resources.html.erb +++ b/app/views/layouts/resources.html.erb @@ -10,6 +10,7 @@ + diff --git a/app/views/users/index.html.erb b/app/views/users/index.html.erb index 26e6b62..2f0f59c 100755 --- a/app/views/users/index.html.erb +++ b/app/views/users/index.html.erb @@ -1,23 +1,25 @@

HeatSync People

+

<% if can? :create, User %> - <%= link_to 'New User', new_user_path %> | + <%= link_to 'New User', new_user_path, class: "btn btn-success" %> <% end %> <% if can? :manage, User %> - <%= link_to 'Merge Users', users_merge_path %> | + <%= link_to 'Merge Users', users_merge_path, class: "btn btn-primary" %> <% end %> <% if current_user.admin? %> - <%= link_to 'Inactive Users', users_inactive_path %> | + <%= link_to 'Inactive Users', users_inactive_path, class: "btn btn-default" %> <% end %> <% if can? :activity, User %> - <%= link_to 'Recent Activity', users_activity_path %> | + <%= link_to 'Recent Activity', users_activity_path, class: "btn btn-default" %> <% end %> <% if can? :new_member_report, User %> - <%= link_to 'New Members Report', users_new_member_report_path %> + <%= link_to 'New Members Report', users_new_member_report_path, class: "btn btn-default" %> <% end %> +

<% @certifications = Certification.all.sort_by(&:id) %> - +
<% if current_user.admin? then %><% end %> @@ -47,14 +49,12 @@ <% @certifications.each do |c| %> <% end %> - - <% if !@users.blank? %> <% @users.each do |user| %> > - + <% if current_user.admin? then %><% end %> @@ -74,8 +74,6 @@ <% end %> <% end %> - - <% end %> <% end %> diff --git a/app/views/users/show.html.erb b/app/views/users/show.html.erb index 186c29b..b74800e 100755 --- a/app/views/users/show.html.erb +++ b/app/views/users/show.html.erb @@ -6,9 +6,12 @@ <%= link_to image_tag('/facebook.png', :class => 'social-icon', :title => "Facebook"), @user.facebook_url, :class => 'social-link' if @user.facebook_url.present? %> <%= link_to image_tag('/github.png', :class => 'social-icon', :title => "Github"), @user.github_url, :class => 'social-link' if @user.github_url.present? %> <%= link_to image_tag('/website.png', :class => 'social-icon', :title => "Website"), @user.website_url, :class => 'social-link' if @user.website_url.present? %> -<%= link_to "Email User", user_compose_email_path(@user), :class => 'btn' %> - + <%= link_to 'Back', :back, :class => 'btn btn-default' %> + <%= link_to 'Email User', user_compose_email_path(@user), :class => 'btn btn-default' %> + <%= link_to 'Edit', edit_user_path(@user), class: "btn btn-primary" if can? :update, @user %> + <%= link_to 'Destroy', @user, class: "btn btn-danger", :confirm => 'Are you sure? WARNING: THIS DOES NOT REMOVE THE USER FROM THE DOOR SYSTEM! DISABLE THEM FIRST.', :method => :delete if can? :destroy, @user %> + <% if current_user.admin? || @user.email_visible %>

@@ -77,7 +80,7 @@

<% end %> -Certifications: <%= link_to "+ Add", (new_user_certification_path+"?user="+@user.id.to_s), :class => 'btn' if can? :create, UserCertification %> +Certifications: <%= link_to "+ Add", (new_user_certification_path+"?user="+@user.id.to_s), :class => 'btn btn-default' if can? :create, UserCertification %>

- Card: <%= link_to "+ Add", (new_card_path+"?user="+@user.id.to_s), :class => 'btn' if can? :create, Card %> + Card: <%= link_to "+ Add", (new_card_path+"?user="+@user.id.to_s), :class => 'btn btn-default' if can? :create, Card %> <% if current_user.admin? then %>

<%= c.name %>
<%= image_tag user.gravatar_url(:default => "http://members.heatsynclabs.org/assets/nil.png"), :class => :avatar %><%= image_tag user.gravatar_url(:size => 25,:default => "http://members.heatsynclabs.org/assets/nil.png"), :class => :avatar %> <%= link_to user.name, user %> <%= raw(user.member_status_symbol) %><%= user.email %><%= link_to 'Edit', edit_user_path(user) if can? :update, user %><%= link_to 'Destroy', user, :confirm => 'Are you sure? WARNING: THIS DOES NOT REMOVE THE USER FROM THE DOOR SYSTEM! DISABLE THEM FIRST.', :method => :delete if can? :destroy, user %>
+
@@ -25,22 +25,22 @@ <% end %> @@ -48,7 +48,7 @@
Name Member Level<% if user.created_at.present? %> <%= distance_of_time_in_words(DateTime.now, user.created_at.to_date)+" ago" %> <% else %> - × + × <% end %> <% if user.waiver.present? %> <%= distance_of_time_in_words(DateTime.now, user.waiver.to_date)+" ago" %> <% else %> - × + × <% end %> <% if user.orientation.present? %> <%= distance_of_time_in_words(DateTime.now, user.orientation.to_date)+" ago" %> <% else %> - × + × <% end %> <% if user.payments.present? %> <%= distance_of_time_in_words(Date.today, user.payments.maximum(:date))+" ago" %> <% else %> - × + × <% end %>

Basic+ Members Without Cards

- +
@@ -67,19 +67,19 @@ <% end %> @@ -88,7 +88,7 @@

Logins

-
Name Account Created<% if user.payments.present? %> <% last_payment = user.payments.maximum(:date) %> <% if Date.today-last_payment > 60 %> - + <% else %> - + <% end %> <%= distance_of_time_in_words(Date.today, user.payments.maximum(:date))+" ago" %> <% else %> - × + × <% end %> <% if user.cards.present? %> - + <% else %> - × + × <% end %>
+
@@ -118,7 +118,7 @@

Never-Logged-In Members

Excluding non-members -
Name Current Sign In
+
diff --git a/app/views/users/inactive.html.erb b/app/views/users/inactive.html.erb index 35c7911..54b360c 100755 --- a/app/views/users/inactive.html.erb +++ b/app/views/users/inactive.html.erb @@ -1,6 +1,6 @@

Inactive Users

-
Name Member Level
+
<% if current_user.admin? then %><% end %> @@ -24,14 +24,12 @@ - - <% if !@users.blank? %> <% @users.each do |user| %> + <% if current_user.admin? then %><% end %> - - <% end %> <% end %> diff --git a/app/views/users/index.html.erb b/app/views/users/index.html.erb index 2f0f59c..91e087d 100755 --- a/app/views/users/index.html.erb +++ b/app/views/users/index.html.erb @@ -54,7 +54,7 @@ <% if !@users.blank? %> <% @users.each do |user| %> > - + <% if current_user.admin? then %><% end %>
Desired Level Last Payment Joined
<%= image_tag user.gravatar_url(:default => "http://members.heatsynclabs.org/assets/nil.png"), :class => :avatar %><%= image_tag user.gravatar_url(:size => 25, :default => "http://members.heatsynclabs.org/assets/nil.png"), :class => :avatar %> <%= link_to user.name, user %><%= user.email %><% user.certifications.each do |c| %> @@ -51,8 +49,6 @@ <% end %> <%= user.created_at.to_date %><%= link_to 'Edit', edit_user_path(user) if can? :update, user %><%= link_to 'Destroy', user, :confirm => 'Are you sure? WARNING: THIS DOES NOT REMOVE THE USER FROM THE DOOR SYSTEM! DISABLE THEM FIRST.', :method => :delete if can? :destroy, user %>
<%= image_tag user.gravatar_url(:size => 25,:default => "http://members.heatsynclabs.org/assets/nil.png"), :class => :avatar %><%= image_tag user.gravatar_url(:size => 25, :default => "http://members.heatsynclabs.org/assets/nil.png"), :class => :avatar %> <%= link_to user.name, user %> <%= raw(user.member_status_symbol) %><%= user.email %>