From 665cc9f97a8cf7bd31e2ec950a1bf7c96596c5ab Mon Sep 17 00:00:00 2001 From: Jason Denney Date: Tue, 1 Jan 2013 20:48:57 -0500 Subject: [PATCH] Update stats when user log grid updated, and other stuff --- app/components/user_logs.rb | 18 ++++++---- app/components/user_profile_border.rb | 37 +++++++++++++++++++++ app/components/user_stats.rb | 37 +++++++++++++++++---- app/components/users_and_profiles_border.rb | 1 + 4 files changed, 80 insertions(+), 13 deletions(-) diff --git a/app/components/user_logs.rb b/app/components/user_logs.rb index cd75906..876bb60 100644 --- a/app/components/user_logs.rb +++ b/app/components/user_logs.rb @@ -7,6 +7,8 @@ class UserLogs < Netzke::Basepack::Grid user_log_strong_default_attrs = { :loggable_type => 'User', :log_action_type => 'ActsAsLoggable::UserAction', + :logger_type => 'User', + :logger_id => controller.current_user.id, :copy_type => 'Bike', :copy_action_type => 'ActsAsLoggable::BikeAction', :copy_action_id => 3 @@ -38,7 +40,12 @@ class UserLogs < Netzke::Basepack::Grid :description, { :name => :user_action__action, :text => 'Action' }, :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 @@ -47,15 +54,14 @@ class UserLogs < Netzke::Basepack::Grid 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}" + action_id = current_user.user_role.id [ { :name => :start_date}, { :name => :end_date}, { :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} + { :name => :user_action__action, :field_label => 'Action', :value => action_id}, + { :name => :for_bike, :checkboxName => :copy_log, :inputValue => true, :title => "Copy description to a Bike's History?", :xtype => 'fieldset', :checkboxToggle => true, :collapsed => true, :items => [ + {:xtype => 'combo', :no_binding => true, :name => :copy_id, :title => 'Bike', :fieldLabel => 'Bike', :store => bike_store, :value => bike_id} ] } ] diff --git a/app/components/user_profile_border.rb b/app/components/user_profile_border.rb index 3de51c9..49189b7 100644 --- a/app/components/user_profile_border.rb +++ b/app/components/user_profile_border.rb @@ -18,6 +18,43 @@ class UserProfileBorder < Netzke::Base js_configure do |c| c.layout = :border 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 diff --git a/app/components/user_stats.rb b/app/components/user_stats.rb index c7a07e2..554269a 100644 --- a/app/components/user_stats.rb +++ b/app/components/user_stats.rb @@ -1,17 +1,40 @@ class UserStats < Netzke::Base - js_configure do |c| - c.body_padding = 15 - c.title = "User Stats" - bike = controller.current_user.bike - c.html = %Q( + def body_content(user) + bike = user.bike + %Q(
-

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

-

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

+

Total Hours Worked: #{user.total_hours}

+

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

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

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

) 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 diff --git a/app/components/users_and_profiles_border.rb b/app/components/users_and_profiles_border.rb index f99c891..f5bb36d 100644 --- a/app/components/users_and_profiles_border.rb +++ b/app/components/users_and_profiles_border.rb @@ -24,6 +24,7 @@ class UsersAndProfilesBorder < Netzke::Base function(){ // calling superclass's initComponent this.callParent(); + this.getComponent('user_stats').updateStats(); // setting the 'rowclick' event var view = this.getComponent('users').getView();