Browse Source

Still a work in progress

denney-disable-on-select
Jason Denney 12 years ago
parent
commit
4ebcbca081
  1. 8
      app/components/app_tab_panel.rb
  2. 39
      app/components/bike_logs.rb
  3. 43
      app/components/bikes_border.rb
  4. 24
      app/components/logs.rb
  5. 37
      app/components/user_logs.rb
  6. 1
      app/components/user_profiles.rb
  7. 8
      app/components/users_and_profiles_border.rb
  8. 3
      app/models/acts_as_loggable/bike_action.rb
  9. 2
      app/models/acts_as_loggable/log_action.rb
  10. 3
      app/models/acts_as_loggable/user_action.rb
  11. 2
      db/migrate/20121204220660_acts_as_loggable_migration.rb

8
app/components/app_tab_panel.rb

@ -1,12 +1,14 @@
class AppTabPanel < Netzke::Basepack::TabPanel class AppTabPanel < Netzke::Basepack::TabPanel
component :bikes component :bikes_border
component :brands_and_models_border component :brands_and_models_border
component :users_and_profiles_border component :users_and_profiles_border
component :logs
component :bike_log_form
def configure(c) def configure(c)
c.active_tab = 0 c.active_tab = 3
c.prevent_header = true c.prevent_header = true
c.items = [ :bikes, :brands_and_models_border, :users_and_profiles_border] c.items = [ :bikes_border, :brands_and_models_border, :users_and_profiles_border, :logs, :bike_log_form]
super super
end end
end end

39
app/components/bike_logs.rb

@ -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

43
app/components/bikes_border.rb

@ -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

24
app/components/logs.rb

@ -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

37
app/components/user_logs.rb

@ -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
app/components/user_profiles.rb

@ -2,6 +2,7 @@ class UserProfiles < Netzke::Basepack::Grid
def configure(c) def configure(c)
super super
c.model = "UserProfile" c.model = "UserProfile"
c.title = "User Profiles"
c.data_store = {auto_load: false} c.data_store = {auto_load: false}
c.scope = lambda { |rel| puts session.inspect; rel.where(:user_id => session[:selected_user_id]);} c.scope = lambda { |rel| puts session.inspect; rel.where(:user_id => session[:selected_user_id]);}
c.columns = [ c.columns = [

8
app/components/users_and_profiles_border.rb

@ -3,12 +3,15 @@ class UsersAndProfilesBorder < Netzke::Base
include Netzke::Basepack::ItemPersistence include Netzke::Basepack::ItemPersistence
component :users component :users
component :user_profiles component :user_profiles
component :user_logs
def configure(c) def configure(c)
super super
c.title = "Users/Profiles" c.title = "Users/Profiles"
c.items = [ c.items = [
{ netzke_component: :users, region: :center, split: true }, { netzke_component: :users, region: :center, width: 300, split: true },
{ netzke_component: :user_profiles, region: :south, height: 300, split: true} { netzke_component: :user_profiles, region: :south, height: 150, split: true},
{ netzke_component: :user_logs, region: :east, split: true}
] ]
end end
@ -28,6 +31,7 @@ class UsersAndProfilesBorder < Netzke::Base
// The beauty of using Ext.Direct: calling 3 endpoints in a row, which results in a single call to the server! // The beauty of using Ext.Direct: calling 3 endpoints in a row, which results in a single call to the server!
this.selectUser({user_id: record.get('id')}); this.selectUser({user_id: record.get('id')});
this.getComponent('user_profiles').getStore().load(); this.getComponent('user_profiles').getStore().load();
this.getComponent('user_logs').getStore().load();
}, this); }, this);
} }
JS JS

3
app/models/acts_as_loggable/bike_action.rb

@ -1,7 +1,6 @@
class ActsAsLoggable::BikeAction < ActiveRecord::Base class ActsAsLoggable::BikeAction < ActiveRecord::Base
attr_accessible :action attr_accessible :action
has_many :logs
belongs_to :bike
def to_s def to_s
self.action self.action

2
app/models/acts_as_loggable/log_action.rb

@ -2,7 +2,7 @@
class ActsAsLoggable::LogAction < ActiveRecord::Base class ActsAsLoggable::LogAction < ActiveRecord::Base
attr_accessible :action attr_accessible :action
belongs_to :log has_many :logs
def to_s def to_s
self.action self.action

3
app/models/acts_as_loggable/user_action.rb

@ -1,9 +1,10 @@
class ActsAsLoggable::UserAction < ActiveRecord::Base class ActsAsLoggable::UserAction < ActiveRecord::Base
attr_accessible :action attr_accessible :action
belongs_to :bike has_many :logs
def to_s def to_s
self.action self.action
end end
end end

2
db/migrate/20121204220660_acts_as_loggable_migration.rb

@ -10,7 +10,7 @@ class ActsAsLoggableMigration < ActiveRecord::Migration
t.datetime "end_date", :null => false t.datetime "end_date", :null => false
t.text :description, :default => "" t.text :description, :default => ""
t.integer :action_id, :default => 0 t.references :log_action, :polymorphic => true
t.timestamps t.timestamps
end end

Loading…
Cancel
Save