mirror of https://github.com/fspc/BikeShed-1.git
Jason Denney
12 years ago
11 changed files with 160 additions and 10 deletions
@ -0,0 +1,39 @@ |
|||
class BikeLogs < Netzke::Basepack::Grid |
|||
def configure(c) |
|||
super |
|||
|
|||
c.model = "ActsAsLoggable::Log" |
|||
c.title = "Bike History" |
|||
c.data_store = {auto_load: false} |
|||
c.scope = lambda { |rel| puts session.inspect; rel.where(:loggable_type => 'Bike',:loggable_id => session[:selected_bike_id]);} |
|||
c.strong_default_attrs = { |
|||
:loggable_type => 'Bike', |
|||
:loggable_id => session[:selected_bike_id], |
|||
:log_action_type => 'ActsAsLoggable::BikeAction' |
|||
} |
|||
|
|||
c.columns = [ |
|||
{ :name => :start_date, :format => "g:ia - D, M j - Y", :width => 165 }, |
|||
{ :name => :hours, :getter => lambda { |rec| (rec.end_date - rec.start_date)/3600 }, :sorting_scope => :sort_by_duration}, |
|||
:description, |
|||
{ :name => :bike_action__action}, |
|||
{ :name => :created_at, :read_only => true}, |
|||
{ :name => :updated_at, :read_only => true} |
|||
] |
|||
|
|||
end |
|||
|
|||
def default_fields_for_forms |
|||
[ |
|||
:start_date, |
|||
{ :name => :end_date, :xtype => 'datetime', :value => Time.now.to_s }, |
|||
:description, |
|||
{ :name => :bike_action__action} |
|||
] |
|||
end |
|||
|
|||
#override with nil to remove actions |
|||
def default_bbar |
|||
[ :apply, :add_in_form, :search ] |
|||
end |
|||
end |
@ -0,0 +1,43 @@ |
|||
class BikesBorder < Netzke::Base |
|||
# Remember regions collapse state and size |
|||
include Netzke::Basepack::ItemPersistence |
|||
component :bikes |
|||
component :bike_logs |
|||
|
|||
def configure(c) |
|||
super |
|||
c.title = "Bikes" |
|||
c.items = [ |
|||
{ netzke_component: :bikes, region: :center, split: true }, |
|||
{ netzke_component: :bike_logs, region: :south, height: 300, split: true} |
|||
] |
|||
end |
|||
|
|||
js_configure do |c| |
|||
c.layout = :border |
|||
c.border = false |
|||
|
|||
# Overriding initComponent |
|||
c.init_component = <<-JS |
|||
function(){ |
|||
// calling superclass's initComponent |
|||
this.callParent(); |
|||
|
|||
// setting the 'rowclick' event |
|||
var view = this.getComponent('bikes').getView(); |
|||
view.on('itemclick', function(view, record){ |
|||
// The beauty of using Ext.Direct: calling 3 endpoints in a row, which results in a single call to the server! |
|||
this.selectBike({bike_id: record.get('id')}); |
|||
this.getComponent('bike_logs').getStore().load(); |
|||
}, this); |
|||
} |
|||
JS |
|||
end |
|||
|
|||
endpoint :select_bike do |params, this| |
|||
# store selected boss id in the session for this component's instance |
|||
session[:selected_bike_id] = params[:bike_id] |
|||
puts "BikeID-----------------------------" |
|||
puts session.inspect |
|||
end |
|||
end |
@ -0,0 +1,24 @@ |
|||
class Logs < Netzke::Basepack::Grid |
|||
|
|||
def configure(c) |
|||
super |
|||
c.model = "ActsAsLoggable::Log" |
|||
c.columns = [ |
|||
:loggable_id, |
|||
:loggable_type, |
|||
:logger_id, |
|||
:logger_type, |
|||
:context, |
|||
:start_date, |
|||
:end_date, |
|||
:description, |
|||
:log_action_id, |
|||
:log_action_type, |
|||
:created_at, |
|||
:updated_at, |
|||
{ :name => :s_date, :getter => lambda { |rec| rec.start_date.strftime("%b %d '%y")}, :width => 75, :sorting_scope => :sort_by_start_date }, |
|||
{ :name => :s_time, :getter => lambda { |rec| rec.start_date.strftime("%I:%M %p")}, :width => 75 }, |
|||
{ :name => :hours, :getter => lambda { |rec| (rec.end_date - rec.start_date)/3600 }, :sorting_scope => :sort_by_duration} |
|||
] |
|||
end |
|||
end |
@ -0,0 +1,37 @@ |
|||
class UserLogs < Netzke::Basepack::Grid |
|||
def configure(c) |
|||
super |
|||
|
|||
c.model = "ActsAsLoggable::Log" |
|||
c.title = "User History" |
|||
c.data_store = {auto_load: false} |
|||
c.scope = lambda { |rel| puts session.inspect; rel.where(:loggable_type => 'User',:loggable_id => session[:selected_user_id]);} |
|||
c.strong_default_attrs = { |
|||
:loggable_type => 'User', |
|||
:loggable_id => session[:selected_user_id], |
|||
:log_action_type => 'ActsAsLoggable::UserAction' |
|||
} |
|||
c.columns = [ |
|||
{ :name => :start_date, :format => "g:ia - D, M j - Y", :width => 165 }, |
|||
{ :name => :hours, :getter => lambda { |rec| (rec.end_date - rec.start_date)/3600 }, :sorting_scope => :sort_by_duration}, |
|||
:description, |
|||
{ :name => :user_action__action }, |
|||
:created_at, |
|||
:updated_at |
|||
] |
|||
end |
|||
|
|||
def default_fields_for_forms |
|||
[ |
|||
:start_date, |
|||
:end_date, |
|||
:description, |
|||
{ :name => :user_action__action} |
|||
] |
|||
end |
|||
|
|||
#override with nil to remove actions |
|||
def default_bbar |
|||
[ :apply, :add_in_form, :search ] |
|||
end |
|||
end |
@ -1,9 +1,10 @@ |
|||
class ActsAsLoggable::UserAction < ActiveRecord::Base |
|||
attr_accessible :action |
|||
|
|||
belongs_to :bike |
|||
has_many :logs |
|||
|
|||
def to_s |
|||
self.action |
|||
end |
|||
end |
|||
|
|||
|
Loading…
Reference in new issue