Browse Source

Update stats when user log grid updated, and other stuff

denney-disable-on-select
Jason Denney 12 years ago
parent
commit
665cc9f97a
  1. 18
      app/components/user_logs.rb
  2. 37
      app/components/user_profile_border.rb
  3. 37
      app/components/user_stats.rb
  4. 1
      app/components/users_and_profiles_border.rb

18
app/components/user_logs.rb

@ -7,6 +7,8 @@ class UserLogs < Netzke::Basepack::Grid
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',
:logger_type => 'User',
:logger_id => controller.current_user.id,
:copy_type => 'Bike', :copy_type => 'Bike',
:copy_action_type => 'ActsAsLoggable::BikeAction', :copy_action_type => 'ActsAsLoggable::BikeAction',
:copy_action_id => 3 :copy_action_id => 3
@ -38,7 +40,12 @@ class UserLogs < Netzke::Basepack::Grid
:description, :description,
{ :name => :user_action__action, :text => 'Action' }, { :name => :user_action__action, :text => 'Action' },
:created_at, :created_at,
:updated_at :updated_at,
{ :name => :logged_by, :getter => lambda{ |rec|
user = User.find_by_id(rec.logger_id)
user.nil? ? "" : "#{user.first_name} #{user.last_name}"
}
}
] ]
end end
@ -47,15 +54,14 @@ class UserLogs < Netzke::Basepack::Grid
bike_store = Bike.all.map { |b| [b.id, b.serial_number] } bike_store = Bike.all.map { |b| [b.id, b.serial_number] }
current_user ||= User.find_by_id(session[:selected_user_id]) || controller.current_user current_user ||= User.find_by_id(session[:selected_user_id]) || controller.current_user
bike_id = current_user.bike.nil? ? nil : current_user.bike.id bike_id = current_user.bike.nil? ? nil : current_user.bike.id
puts "YOOOOO BIKE: #{bike_id}" action_id = current_user.user_role.id
[ [
{ :name => :start_date}, { :name => :start_date},
{ :name => :end_date}, { :name => :end_date},
{ :name => :description}, { :name => :description},
{ :name => :user_action__action, :field_label => 'Action'}, { :name => :user_action__action, :field_label => 'Action', :value => action_id},
{ :name => :for_bike, :title => "Copy description to a Bike's History?", :xtype => 'fieldset', :collapsible => true, :collapsed => true, :items => [ { :name => :for_bike, :checkboxName => :copy_log, :inputValue => true, :title => "Copy description to a Bike's History?", :xtype => 'fieldset', :checkboxToggle => true, :collapsed => true, :items => [
{:xtype => 'checkbox', :name => :copy_log, :inputValue => true, :read_only => false}, {:xtype => 'combo', :no_binding => true, :name => :copy_id, :title => 'Bike', :fieldLabel => 'Bike', :store => bike_store, :value => bike_id}
{:xtype => 'combo', :name => :copy_id, :fieldLabel => 'Bike', :store => bike_store, :value => bike_id}
] ]
} }
] ]

37
app/components/user_profile_border.rb

@ -18,6 +18,43 @@ class UserProfileBorder < Netzke::Base
js_configure do |c| js_configure do |c|
c.layout = :border c.layout = :border
c.border = false c.border = false
# Overriding initComponent
c.init_component = <<-JS
function(){
// calling superclass's initComponent
this.callParent();
console.log("init component");
console.log(this);
this.getComponent('user_stats').updateStats();
var store = this.getComponent('user_logs').getStore()
store.on('load', function (store, records, operation, success){
console.log("Bitches");
this.getComponent('user_stats').updateStats();
}, this);
/**
this.getComponent('user_logs').getStore().load({
callback : function(records, operation, success) {
console.log(self);
console.log(this);
console.log("records");
console.log(records);
console.log("operation");
console.log(operation);
console.log("success");
console.log(success);
self.getComponent('user_stats').updateStats();
}
});*/
// var view = this.getComponent('user_logs').getView();
// view.on('itemclick', function(view, record){
// this.getComponent('user_stats').updateStats();
// }, this);
}
JS
end end
end end

37
app/components/user_stats.rb

@ -1,17 +1,40 @@
class UserStats < Netzke::Base class UserStats < Netzke::Base
js_configure do |c| def body_content(user)
c.body_padding = 15 bike = user.bike
c.title = "User Stats" %Q(
bike = controller.current_user.bike
c.html = %Q(
<div id="user_stats_page"> <div id="user_stats_page">
<p>Total Hours Worked: #{controller.current_user.total_hours}</p> <p>Total Hours Worked: #{user.total_hours}</p>
<p>Hours worked in #{Time.now.strftime('%B')}: #{controller.current_user.current_month_hours}</p> <p>Hours worked in #{Time.now.strftime('%B')}: #{user.current_month_hours}</p>
<p>Current bike ID: #{bike.id if bike}</p> <p>Current bike ID: #{bike.id if bike}</p>
<p>Current bike S/N: #{bike.serial_number if bike}</p> <p>Current bike S/N: #{bike.serial_number if bike}</p>
</div> </div>
) )
end end
js_configure do |c|
c.body_padding = 15
c.title = "User Stats"
#c.html = body_content()
c.update_stats = <<-JS
function(){
// Call endpoint
this.serverUpdate({}, function(){
//success callback
}, this);
}
JS
end
endpoint :server_update do |params, this|
# updateBodyHtml is a JS-side method we inherit from Netkze::Basepack::Panel
this[:update] = [body_content(user)]
end
private
def user
controller.current_user
end
end end

1
app/components/users_and_profiles_border.rb

@ -24,6 +24,7 @@ class UsersAndProfilesBorder < Netzke::Base
function(){ function(){
// calling superclass's initComponent // calling superclass's initComponent
this.callParent(); this.callParent();
this.getComponent('user_stats').updateStats();
// setting the 'rowclick' event // setting the 'rowclick' event
var view = this.getComponent('users').getView(); var view = this.getComponent('users').getView();

Loading…
Cancel
Save