Browse Source

Almost usable, still a lot of work left

-Moved bikes to User model instead of profile
-User can copy user log to a bike log with new actsasloggable
-Added user stats
-some css was messing up checkboxes, need to figure out which stylesheet was doing that
denney-disable-on-select
Jason Denney 12 years ago
parent
commit
189137ba9d
  1. 15
      app/components/bike_logs.rb
  2. 9
      app/components/bikes.rb
  3. 20
      app/components/user_logs.rb
  4. 2
      app/components/user_profile_border.rb
  5. 1
      app/components/user_profiles.rb
  6. 17
      app/components/user_stats.rb
  7. 3
      app/components/users.rb
  8. 16
      app/models/user.rb
  9. 30
      app/views/layouts/application.html.haml
  10. 9
      db/migrate/20120227024410_devise_create_users.rb
  11. 2
      db/migrate/20121204221242_create_bike.rb
  12. 1
      db/migrate/20121204223403_create_user_profile.rb
  13. 7
      db/schema.rb
  14. 1
      spec/factories/user_profiles.rb
  15. 1
      spec/factories/users.rb

15
app/components/bike_logs.rb

@ -11,7 +11,9 @@ class BikeLogs < Netzke::Basepack::Grid
c.strong_default_attrs = {
:loggable_type => 'Bike',
:loggable_id => session[:selected_bike_id],
:log_action_type => 'ActsAsLoggable::BikeAction'
:log_action_type => 'ActsAsLoggable::BikeAction',
:logger_type => 'User',
:logger_id => controller.current_user.id
}
c.columns = [
@ -21,7 +23,12 @@ class BikeLogs < Netzke::Basepack::Grid
:description,
{ :name => :bike_action__action, :text => 'Action'},
{ :name => :created_at, :read_only => true},
{ :name => :updated_at, :read_only => true}
{ :name => :updated_at, :read_only => true},
{ :name => :logged_by, :getter => lambda{ |rec|
user = User.find_by_id(rec.logger_id)
user.nil? ? "" : "#{user.first_name} #{user.last_name}"
}
}
]
if controller.current_user.user?
@ -36,15 +43,17 @@ class BikeLogs < Netzke::Basepack::Grid
[
{ :name => :start_date},
{ :name => :end_date},
:description,
{ :name => :description},
{ :name => :bike_action__action, :field_label => 'Action'}
]
end
=begin
#override with nil to remove actions
def default_bbar
bbar = [ :search ]
bbar.concat [ :apply, :add_in_form ] if not controller.current_user.user?
bbar
end
=end
end

9
app/components/bikes.rb

@ -22,13 +22,18 @@ class Bikes < Netzke::Basepack::Grid
:wheel_size,
:value,
{ :name => :bike_condition__condition, :text => 'Condition'},
{ :name => :bike_status__status, :text => 'Status'}
{ :name => :bike_status__status, :text => 'Status'},
{ :name => :owner, :getter => lambda { |rec|
user = rec.owner
user.nil? ? "" : "#{user.first_name} #{user.last_name}"
}
}
]
end
#override with nil to remove actions
def default_bbar
[ :apply, :add_in_form ]
[ :apply, :add_in_form, :search ]
end
js_configure do |c|

20
app/components/user_logs.rb

@ -6,7 +6,10 @@ class UserLogs < Netzke::Basepack::Grid
#all users
user_log_strong_default_attrs = {
:loggable_type => 'User',
:log_action_type => 'ActsAsLoggable::UserAction'
:log_action_type => 'ActsAsLoggable::UserAction',
:copy_type => 'Bike',
:copy_action_type => 'ActsAsLoggable::BikeAction',
:copy_action_id => 3
}
#just users
@ -40,11 +43,21 @@ class UserLogs < Netzke::Basepack::Grid
end
def default_fields_for_forms
#figure out a better way to do this
bike_store = Bike.all.map { |b| [b.id, b.serial_number] }
current_user ||= User.find_by_id(session[:selected_user_id]) || controller.current_user
bike_id = current_user.bike.nil? ? nil : current_user.bike.id
puts "YOOOOO BIKE: #{bike_id}"
[
{ :name => :start_date},
{ :name => :end_date},
:description,
{ :name => :user_action__action, :field_label => 'Action'}
{ :name => :description},
{ :name => :user_action__action, :field_label => 'Action'},
{ :name => :for_bike, :title => "Copy description to a Bike's History?", :xtype => 'fieldset', :collapsible => true, :collapsed => true, :items => [
{:xtype => 'checkbox', :name => :copy_log, :inputValue => true, :read_only => false},
{:xtype => 'combo', :name => :copy_id, :fieldLabel => 'Bike', :store => bike_store, :value => bike_id}
]
}
]
end
@ -52,4 +65,5 @@ class UserLogs < Netzke::Basepack::Grid
def default_bbar
[ :apply, :add_in_form, :search ]
end
end

2
app/components/user_profile_border.rb

@ -2,6 +2,7 @@ class UserProfileBorder < Netzke::Base
# Remember regions collapse state and size
include Netzke::Basepack::ItemPersistence
component :user_logs
component :user_stats
component :user_profiles
def configure(c)
@ -9,6 +10,7 @@ class UserProfileBorder < Netzke::Base
c.title = "Profile"
c.items = [
{ netzke_component: :user_logs, region: :center, split: true},
{ netzke_component: :user_stats, region: :east, width: 350, split: true},
{ netzke_component: :user_profiles, region: :south, height: 150, split: true }
]
end

1
app/components/user_profiles.rb

@ -15,7 +15,6 @@ class UserProfiles < Netzke::Basepack::Grid
c.data_store = user_profiles_data_store
c.scope = user_profiles_scope
c.columns = [
{ :name => :bike__serial_number},
:addrStreet1,
:addrStreet2,
:addrCity,

17
app/components/user_stats.rb

@ -0,0 +1,17 @@
class UserStats < Netzke::Base
js_configure do |c|
c.body_padding = 15
c.title = "User Stats"
bike = controller.current_user.bike
c.html = %Q(
<div id="user_stats_page">
<p>Total Hours Worked: #{controller.current_user.total_hours}</p>
<p>Hours worked in #{Time.now.strftime('%B')}: #{controller.current_user.current_month_hours}</p>
<p>Current bike ID: #{bike.id if bike}</p>
<p>Current bike S/N: #{bike.serial_number if bike}</p>
</div>
)
end
end

3
app/components/users.rb

@ -8,7 +8,8 @@ class Users < Netzke::Basepack::Grid
:last_name,
:nickname,
:email,
:user_role__role
:user_role__role,
:bike__serial_number
]
end

16
app/models/user.rb

@ -7,10 +7,11 @@ class User < ActiveRecord::Base
# Setup accessible (or protected) attributes for your model
attr_accessible :email, :password, :password_confirmation, :remember_me,
:first_name, :last_name, :nickname, :role_id
:first_name, :last_name, :nickname, :user_role_id
has_many :user_profiles
belongs_to :user_role
belongs_to :bike
validates :first_name, :presence => true
validates :last_name, :presence => true
@ -32,4 +33,17 @@ class User < ActiveRecord::Base
def admin?
user_role.to_s == "admin"
end
def total_hours
ActsAsLoggable::Log.where( :loggable_type => self.class.to_s, :loggable_id => self.id).sum { |l| (l.end_date - l.start_date)/3600 }
end
def current_month_hours
#TODO need to prevent users from saving logs across months, force to create a new log if crossing month
current_month_range = (Time.now.beginning_of_month..Time.now.end_of_month)
ActsAsLoggable::Log.where( :loggable_type => self.class.to_s, :loggable_id => self.id)
.where( :start_date => current_month_range)
.where( :end_date => current_month_range)
.sum { |l| (l.end_date - l.start_date)/3600 }
end
end

30
app/views/layouts/application.html.haml

@ -0,0 +1,30 @@
!!! 5
%html{:lang => "en"}
%head
%meta{:charset => "utf-8"}/
%title= content_for?(:title) ? yield(:title) : "Velocipede"
= load_netzke
= csrf_meta_tags
/[if lt IE 9]
= javascript_include_tag "http://html5shim.googlecode.com/svn/trunk/html5.js"
:css
body {
padding-top: 60px; /* 60px to make the container go all the way to the bottom of the topbar */
}
%body
.container
.content
- if flash[:notice]
%p{:class => 'notice'}= flash[:notice]
- if flash[:alert]
%p{:class => 'alert'}= flash[:alert]
.row
.span13
= yield
%footer
%p &copy; Velocipede 2013
= javascript_include_tag "application"

9
db/migrate/20120227024410_devise_create_users.rb

@ -19,8 +19,6 @@ class DeviseCreateUsers < ActiveRecord::Migration
t.string :current_sign_in_ip
t.string :last_sign_in_ip
t.integer :user_role_id
## Encryptable
# t.string :password_salt
@ -39,6 +37,11 @@ class DeviseCreateUsers < ActiveRecord::Migration
# t.string :authentication_token
#I need to move these elsewhere eventually
t.integer :user_role_id, :null => false, :default => 1
#one bike per user for now
t.integer :bike_id
t.timestamps
end
@ -47,5 +50,7 @@ class DeviseCreateUsers < ActiveRecord::Migration
# add_index :users, :confirmation_token, :unique => true
# add_index :users, :unlock_token, :unique => true
# add_index :users, :authentication_token, :unique => true
add_index :users, :bike_id, :unique => true
end
end

2
db/migrate/20121204221242_create_bike.rb

@ -14,5 +14,7 @@ class CreateBike < ActiveRecord::Migration
t.integer "bike_status_id", :null => false
t.timestamps
end
add_index :bikes, :serial_number, :unique => true
end
end

1
db/migrate/20121204223403_create_user_profile.rb

@ -2,7 +2,6 @@ class CreateUserProfile < ActiveRecord::Migration
def change
create_table :user_profiles do |t|
t.integer "user_id", :null => false
t.integer "bike_id"
t.string "first_name"
t.string "last_name"
t.string "addrStreet1"

7
db/schema.rb

@ -62,6 +62,8 @@ ActiveRecord::Schema.define(:version => 20121229160809) do
t.datetime "updated_at", :null => false
end
add_index "bikes", ["serial_number"], :name => "index_bikes_on_serial_number", :unique => true
create_table "logs", :force => true do |t|
t.integer "loggable_id"
t.string "loggable_type"
@ -99,7 +101,6 @@ ActiveRecord::Schema.define(:version => 20121229160809) do
create_table "user_profiles", :force => true do |t|
t.integer "user_id", :null => false
t.integer "bike_id"
t.string "first_name"
t.string "last_name"
t.string "addrStreet1"
@ -130,7 +131,8 @@ ActiveRecord::Schema.define(:version => 20121229160809) do
t.datetime "last_sign_in_at"
t.string "current_sign_in_ip"
t.string "last_sign_in_ip"
t.integer "user_role_id"
t.integer "user_role_id", :default => 1, :null => false
t.integer "bike_id"
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
t.integer "failed_attempts", :default => 0
@ -141,6 +143,7 @@ ActiveRecord::Schema.define(:version => 20121229160809) do
t.string "nickname"
end
add_index "users", ["bike_id"], :name => "index_users_on_bike_id", :unique => true
add_index "users", ["email"], :name => "index_users_on_email", :unique => true
add_index "users", ["reset_password_token"], :name => "index_users_on_reset_password_token", :unique => true

1
spec/factories/user_profiles.rb

@ -1,7 +1,6 @@
FactoryGirl.define do
factory :user_profile do
user_id 1
bike_id 1
addrStreet1 "Charles Street"
addrStreet2 "Apt #42"
addrCity "Baltimore"

1
spec/factories/users.rb

@ -6,6 +6,7 @@ FactoryGirl.define do
first_name 'Michael'
last_name 'Scott'
user_role_id 1
sequence(:bike_id) { |n| n }
factory :staff do
first_name 'Staff'

Loading…
Cancel
Save