mirror of
https://github.com/fspc/BikeShed-1.git
synced 2025-02-28 08:43:23 -05:00
Update stats when user log grid updated, and other stuff
This commit is contained in:
parent
189137ba9d
commit
665cc9f97a
@ -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}
|
||||
]
|
||||
}
|
||||
]
|
||||
|
@ -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
|
||||
|
@ -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(
|
||||
<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>Total Hours Worked: #{user.total_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 S/N: #{bike.serial_number if bike}</p>
|
||||
</div>
|
||||
)
|
||||
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
|
||||
|
||||
|
@ -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();
|
||||
|
Loading…
x
Reference in New Issue
Block a user