mirror of
https://github.com/fspc/BikeShed-1.git
synced 2025-02-28 08:43:23 -05:00
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
This commit is contained in:
parent
922af526c1
commit
189137ba9d
@ -11,7 +11,9 @@ class BikeLogs < Netzke::Basepack::Grid
|
|||||||
c.strong_default_attrs = {
|
c.strong_default_attrs = {
|
||||||
:loggable_type => 'Bike',
|
:loggable_type => 'Bike',
|
||||||
:loggable_id => session[:selected_bike_id],
|
: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 = [
|
c.columns = [
|
||||||
@ -21,7 +23,12 @@ class BikeLogs < Netzke::Basepack::Grid
|
|||||||
:description,
|
:description,
|
||||||
{ :name => :bike_action__action, :text => 'Action'},
|
{ :name => :bike_action__action, :text => 'Action'},
|
||||||
{ :name => :created_at, :read_only => true},
|
{ :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?
|
if controller.current_user.user?
|
||||||
@ -36,15 +43,17 @@ class BikeLogs < Netzke::Basepack::Grid
|
|||||||
[
|
[
|
||||||
{ :name => :start_date},
|
{ :name => :start_date},
|
||||||
{ :name => :end_date},
|
{ :name => :end_date},
|
||||||
:description,
|
{ :name => :description},
|
||||||
{ :name => :bike_action__action, :field_label => 'Action'}
|
{ :name => :bike_action__action, :field_label => 'Action'}
|
||||||
]
|
]
|
||||||
end
|
end
|
||||||
|
|
||||||
|
=begin
|
||||||
#override with nil to remove actions
|
#override with nil to remove actions
|
||||||
def default_bbar
|
def default_bbar
|
||||||
bbar = [ :search ]
|
bbar = [ :search ]
|
||||||
bbar.concat [ :apply, :add_in_form ] if not controller.current_user.user?
|
bbar.concat [ :apply, :add_in_form ] if not controller.current_user.user?
|
||||||
bbar
|
bbar
|
||||||
end
|
end
|
||||||
|
=end
|
||||||
end
|
end
|
||||||
|
@ -22,13 +22,18 @@ class Bikes < Netzke::Basepack::Grid
|
|||||||
:wheel_size,
|
:wheel_size,
|
||||||
:value,
|
:value,
|
||||||
{ :name => :bike_condition__condition, :text => 'Condition'},
|
{ :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
|
end
|
||||||
|
|
||||||
#override with nil to remove actions
|
#override with nil to remove actions
|
||||||
def default_bbar
|
def default_bbar
|
||||||
[ :apply, :add_in_form ]
|
[ :apply, :add_in_form, :search ]
|
||||||
end
|
end
|
||||||
|
|
||||||
js_configure do |c|
|
js_configure do |c|
|
||||||
|
@ -6,7 +6,10 @@ class UserLogs < Netzke::Basepack::Grid
|
|||||||
#all users
|
#all users
|
||||||
user_log_strong_default_attrs = {
|
user_log_strong_default_attrs = {
|
||||||
:loggable_type => 'User',
|
: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
|
#just users
|
||||||
@ -40,11 +43,21 @@ class UserLogs < Netzke::Basepack::Grid
|
|||||||
end
|
end
|
||||||
|
|
||||||
def default_fields_for_forms
|
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 => :start_date},
|
||||||
{ :name => :end_date},
|
{ :name => :end_date},
|
||||||
:description,
|
{ :name => :description},
|
||||||
{ :name => :user_action__action, :field_label => 'Action'}
|
{ :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
|
end
|
||||||
|
|
||||||
@ -52,4 +65,5 @@ class UserLogs < Netzke::Basepack::Grid
|
|||||||
def default_bbar
|
def default_bbar
|
||||||
[ :apply, :add_in_form, :search ]
|
[ :apply, :add_in_form, :search ]
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
@ -2,6 +2,7 @@ class UserProfileBorder < Netzke::Base
|
|||||||
# Remember regions collapse state and size
|
# Remember regions collapse state and size
|
||||||
include Netzke::Basepack::ItemPersistence
|
include Netzke::Basepack::ItemPersistence
|
||||||
component :user_logs
|
component :user_logs
|
||||||
|
component :user_stats
|
||||||
component :user_profiles
|
component :user_profiles
|
||||||
|
|
||||||
def configure(c)
|
def configure(c)
|
||||||
@ -9,6 +10,7 @@ class UserProfileBorder < Netzke::Base
|
|||||||
c.title = "Profile"
|
c.title = "Profile"
|
||||||
c.items = [
|
c.items = [
|
||||||
{ netzke_component: :user_logs, region: :center, split: true},
|
{ 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 }
|
{ netzke_component: :user_profiles, region: :south, height: 150, split: true }
|
||||||
]
|
]
|
||||||
end
|
end
|
||||||
|
@ -15,7 +15,6 @@ class UserProfiles < Netzke::Basepack::Grid
|
|||||||
c.data_store = user_profiles_data_store
|
c.data_store = user_profiles_data_store
|
||||||
c.scope = user_profiles_scope
|
c.scope = user_profiles_scope
|
||||||
c.columns = [
|
c.columns = [
|
||||||
{ :name => :bike__serial_number},
|
|
||||||
:addrStreet1,
|
:addrStreet1,
|
||||||
:addrStreet2,
|
:addrStreet2,
|
||||||
:addrCity,
|
:addrCity,
|
||||||
|
17
app/components/user_stats.rb
Normal file
17
app/components/user_stats.rb
Normal file
@ -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
|
||||||
|
|
@ -8,7 +8,8 @@ class Users < Netzke::Basepack::Grid
|
|||||||
:last_name,
|
:last_name,
|
||||||
:nickname,
|
:nickname,
|
||||||
:email,
|
:email,
|
||||||
:user_role__role
|
:user_role__role,
|
||||||
|
:bike__serial_number
|
||||||
]
|
]
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -7,10 +7,11 @@ class User < ActiveRecord::Base
|
|||||||
|
|
||||||
# Setup accessible (or protected) attributes for your model
|
# Setup accessible (or protected) attributes for your model
|
||||||
attr_accessible :email, :password, :password_confirmation, :remember_me,
|
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
|
has_many :user_profiles
|
||||||
belongs_to :user_role
|
belongs_to :user_role
|
||||||
|
belongs_to :bike
|
||||||
|
|
||||||
validates :first_name, :presence => true
|
validates :first_name, :presence => true
|
||||||
validates :last_name, :presence => true
|
validates :last_name, :presence => true
|
||||||
@ -32,4 +33,17 @@ class User < ActiveRecord::Base
|
|||||||
def admin?
|
def admin?
|
||||||
user_role.to_s == "admin"
|
user_role.to_s == "admin"
|
||||||
end
|
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
|
end
|
||||||
|
30
app/views/layouts/application.html.haml
Normal file
30
app/views/layouts/application.html.haml
Normal file
@ -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"
|
@ -19,8 +19,6 @@ class DeviseCreateUsers < ActiveRecord::Migration
|
|||||||
t.string :current_sign_in_ip
|
t.string :current_sign_in_ip
|
||||||
t.string :last_sign_in_ip
|
t.string :last_sign_in_ip
|
||||||
|
|
||||||
t.integer :user_role_id
|
|
||||||
|
|
||||||
## Encryptable
|
## Encryptable
|
||||||
# t.string :password_salt
|
# t.string :password_salt
|
||||||
|
|
||||||
@ -39,6 +37,11 @@ class DeviseCreateUsers < ActiveRecord::Migration
|
|||||||
# t.string :authentication_token
|
# 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
|
t.timestamps
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -47,5 +50,7 @@ class DeviseCreateUsers < ActiveRecord::Migration
|
|||||||
# add_index :users, :confirmation_token, :unique => true
|
# add_index :users, :confirmation_token, :unique => true
|
||||||
# add_index :users, :unlock_token, :unique => true
|
# add_index :users, :unlock_token, :unique => true
|
||||||
# add_index :users, :authentication_token, :unique => true
|
# add_index :users, :authentication_token, :unique => true
|
||||||
|
|
||||||
|
add_index :users, :bike_id, :unique => true
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -14,5 +14,7 @@ class CreateBike < ActiveRecord::Migration
|
|||||||
t.integer "bike_status_id", :null => false
|
t.integer "bike_status_id", :null => false
|
||||||
t.timestamps
|
t.timestamps
|
||||||
end
|
end
|
||||||
|
|
||||||
|
add_index :bikes, :serial_number, :unique => true
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -2,7 +2,6 @@ class CreateUserProfile < ActiveRecord::Migration
|
|||||||
def change
|
def change
|
||||||
create_table :user_profiles do |t|
|
create_table :user_profiles do |t|
|
||||||
t.integer "user_id", :null => false
|
t.integer "user_id", :null => false
|
||||||
t.integer "bike_id"
|
|
||||||
t.string "first_name"
|
t.string "first_name"
|
||||||
t.string "last_name"
|
t.string "last_name"
|
||||||
t.string "addrStreet1"
|
t.string "addrStreet1"
|
||||||
|
@ -62,6 +62,8 @@ ActiveRecord::Schema.define(:version => 20121229160809) do
|
|||||||
t.datetime "updated_at", :null => false
|
t.datetime "updated_at", :null => false
|
||||||
end
|
end
|
||||||
|
|
||||||
|
add_index "bikes", ["serial_number"], :name => "index_bikes_on_serial_number", :unique => true
|
||||||
|
|
||||||
create_table "logs", :force => true do |t|
|
create_table "logs", :force => true do |t|
|
||||||
t.integer "loggable_id"
|
t.integer "loggable_id"
|
||||||
t.string "loggable_type"
|
t.string "loggable_type"
|
||||||
@ -99,7 +101,6 @@ ActiveRecord::Schema.define(:version => 20121229160809) do
|
|||||||
|
|
||||||
create_table "user_profiles", :force => true do |t|
|
create_table "user_profiles", :force => true do |t|
|
||||||
t.integer "user_id", :null => false
|
t.integer "user_id", :null => false
|
||||||
t.integer "bike_id"
|
|
||||||
t.string "first_name"
|
t.string "first_name"
|
||||||
t.string "last_name"
|
t.string "last_name"
|
||||||
t.string "addrStreet1"
|
t.string "addrStreet1"
|
||||||
@ -130,7 +131,8 @@ ActiveRecord::Schema.define(:version => 20121229160809) do
|
|||||||
t.datetime "last_sign_in_at"
|
t.datetime "last_sign_in_at"
|
||||||
t.string "current_sign_in_ip"
|
t.string "current_sign_in_ip"
|
||||||
t.string "last_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 "created_at", :null => false
|
||||||
t.datetime "updated_at", :null => false
|
t.datetime "updated_at", :null => false
|
||||||
t.integer "failed_attempts", :default => 0
|
t.integer "failed_attempts", :default => 0
|
||||||
@ -141,6 +143,7 @@ ActiveRecord::Schema.define(:version => 20121229160809) do
|
|||||||
t.string "nickname"
|
t.string "nickname"
|
||||||
end
|
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", ["email"], :name => "index_users_on_email", :unique => true
|
||||||
add_index "users", ["reset_password_token"], :name => "index_users_on_reset_password_token", :unique => true
|
add_index "users", ["reset_password_token"], :name => "index_users_on_reset_password_token", :unique => true
|
||||||
|
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
FactoryGirl.define do
|
FactoryGirl.define do
|
||||||
factory :user_profile do
|
factory :user_profile do
|
||||||
user_id 1
|
user_id 1
|
||||||
bike_id 1
|
|
||||||
addrStreet1 "Charles Street"
|
addrStreet1 "Charles Street"
|
||||||
addrStreet2 "Apt #42"
|
addrStreet2 "Apt #42"
|
||||||
addrCity "Baltimore"
|
addrCity "Baltimore"
|
||||||
|
@ -6,6 +6,7 @@ FactoryGirl.define do
|
|||||||
first_name 'Michael'
|
first_name 'Michael'
|
||||||
last_name 'Scott'
|
last_name 'Scott'
|
||||||
user_role_id 1
|
user_role_id 1
|
||||||
|
sequence(:bike_id) { |n| n }
|
||||||
|
|
||||||
factory :staff do
|
factory :staff do
|
||||||
first_name 'Staff'
|
first_name 'Staff'
|
||||||
|
Loading…
x
Reference in New Issue
Block a user