diff --git a/app/components/bike_logs.rb b/app/components/bike_logs.rb index 52c8e01..3e2de06 100644 --- a/app/components/bike_logs.rb +++ b/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 diff --git a/app/components/bikes.rb b/app/components/bikes.rb index ecf479f..27a5514 100644 --- a/app/components/bikes.rb +++ b/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| diff --git a/app/components/user_logs.rb b/app/components/user_logs.rb index 6bc0290..cd75906 100644 --- a/app/components/user_logs.rb +++ b/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 diff --git a/app/components/user_profile_border.rb b/app/components/user_profile_border.rb index 985a5a6..3de51c9 100644 --- a/app/components/user_profile_border.rb +++ b/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 diff --git a/app/components/user_profiles.rb b/app/components/user_profiles.rb index c8f20a8..8c7f6a9 100644 --- a/app/components/user_profiles.rb +++ b/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, diff --git a/app/components/user_stats.rb b/app/components/user_stats.rb new file mode 100644 index 0000000..c7a07e2 --- /dev/null +++ b/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( +
+

Total Hours Worked: #{controller.current_user.total_hours}

+

Hours worked in #{Time.now.strftime('%B')}: #{controller.current_user.current_month_hours}

+

Current bike ID: #{bike.id if bike}

+

Current bike S/N: #{bike.serial_number if bike}

+
+ ) + end +end + diff --git a/app/components/users.rb b/app/components/users.rb index 4bd849e..e545993 100644 --- a/app/components/users.rb +++ b/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 diff --git a/app/models/user.rb b/app/models/user.rb index 45adbfb..ac31107 100644 --- a/app/models/user.rb +++ b/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 diff --git a/app/views/layouts/application.html.haml b/app/views/layouts/application.html.haml new file mode 100644 index 0000000..70660f1 --- /dev/null +++ b/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 © Velocipede 2013 + + = javascript_include_tag "application" diff --git a/db/migrate/20120227024410_devise_create_users.rb b/db/migrate/20120227024410_devise_create_users.rb index e3e5837..12fc7b4 100644 --- a/db/migrate/20120227024410_devise_create_users.rb +++ b/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 diff --git a/db/migrate/20121204221242_create_bike.rb b/db/migrate/20121204221242_create_bike.rb index d097bc6..4338965 100644 --- a/db/migrate/20121204221242_create_bike.rb +++ b/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 diff --git a/db/migrate/20121204223403_create_user_profile.rb b/db/migrate/20121204223403_create_user_profile.rb index 476eaa8..dbc9adf 100644 --- a/db/migrate/20121204223403_create_user_profile.rb +++ b/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" diff --git a/db/schema.rb b/db/schema.rb index 0831388..0b8e94a 100644 --- a/db/schema.rb +++ b/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 diff --git a/spec/factories/user_profiles.rb b/spec/factories/user_profiles.rb index a479d79..b32f483 100644 --- a/spec/factories/user_profiles.rb +++ b/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" diff --git a/spec/factories/users.rb b/spec/factories/users.rb index 13021bb..9d74847 100644 --- a/spec/factories/users.rb +++ b/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'