# HG changeset patch # User Nattee Niparnan # Date 2015-09-14 22:10:42 # Node ID 11c20f65a6b8679f5bef1379f81d83b32d700144 # Parent 7fdec87758d5563a9655593641f168534f2138c0 more heart beat feature add reset last login ip (grafted from 6efa41a1cfdc5e910b85eec6d8b874ed651776bd) diff --git a/app/controllers/heartbeat_controller.rb b/app/controllers/heartbeat_controller.rb --- a/app/controllers/heartbeat_controller.rb +++ b/app/controllers/heartbeat_controller.rb @@ -1,14 +1,29 @@ class HeartbeatController < ApplicationController + before_filter :admin_authorization, :only => ['index'] + def edit - render layout: 'empty' @user = User.find_by_login(params[:id]) - return unless @user - + unless @user + render text: "LOGIN_NOT_FOUND" + return + end + hb = HeartBeat.where(user_id: @user.id, ip_address: request.remote_ip).first + puts "status = #{params[:status]}" if hb + if params[:status] + hb.status = params[:status] + hb.save + end hb.touch else - HeartBeat.create(user_id: @user.id, ip_address: request.remote_ip) + HeartBeat.creae(user_id: @user.id, ip_address: request.remote_ip) end + render text: "OK" + end + + def index + @hb = HeartBeat.includes(:user).order(:user_id).all + @num = HeartBeat.where("updated_at >= ?",Time.zone.now-5.minutes).count end end diff --git a/app/controllers/user_admin_controller.rb b/app/controllers/user_admin_controller.rb --- a/app/controllers/user_admin_controller.rb +++ b/app/controllers/user_admin_controller.rb @@ -62,6 +62,13 @@ end end + def clear_last_ip + @user = User.find(params[:id]) + @user.last_ip = nil + @user.save + redirect_to action: 'list', page: params[:page] + end + def create_from_list lines = params[:user_list] @@ -213,7 +220,7 @@ @changed = true end end - + # contest management def contests diff --git a/app/views/heartbeat/edit.html.haml b/app/views/heartbeat/edit.html.haml deleted file mode 100644 --- a/app/views/heartbeat/edit.html.haml +++ /dev/null @@ -1,1 +0,0 @@ -OK diff --git a/app/views/heartbeat/index.html.haml b/app/views/heartbeat/index.html.haml new file mode 100644 --- /dev/null +++ b/app/views/heartbeat/index.html.haml @@ -0,0 +1,30 @@ +- content_for :header do + = javascript_include_tag 'local_jquery' + = stylesheet_link_tag 'tablesorter-theme.cafe' + +%script{:type=>"text/javascript"} + $(function () { + $('#since_datetime').datetimepicker({ showButtonPanel: true, dateFormat: "yy-mm-dd", controlType: "slider"} ); + $('#until_datetime').datetimepicker({ showButtonPanel: true, dateFormat: "yy-mm-dd", controlType: "slider"} ); + $('#my_table').tablesorter({widgets: ['zebra']}); + }); + +%h1 Heart Beat Count += "Last 5 minutes distinct user count = #{@num}" + +%h1 Heart Beat List + +%table.tablesorter-cafe#my_table + %thead + %tr + %th Login + %th Full name + %th IP + %th Last Update + %tbody + - @hb.each do |hb| + %tr{class: cycle('info-even','info-odd')} + %td= link_to hb.user.login, controller: :users, :action => 'profile', :id => hb.user.id + %td= hb.user.full_name + %td= hb.ip_address + %td= "#{time_ago_in_words(hb.updated_at)} ago" diff --git a/app/views/user_admin/list.html.erb b/app/views/user_admin/list.html.erb --- a/app/views/user_admin/list.html.erb +++ b/app/views/user_admin/list.html.erb @@ -64,6 +64,7 @@ + <% for user in @users %> @@ -74,6 +75,7 @@ <%=h user.send(column.name) %> <% end %> <% end %> + <%= link_to 'Clear IP', {:action => 'clear_last_ip', :id => user, :page=>params[:page]}, :confirm => 'This will reset last logging in ip of the user, are you sure?' %> <%= link_to 'Show', :action => 'show', :id => user %> <%= link_to 'Edit', :action => 'edit', :id => user %> <%= link_to 'Destroy', { :action => 'destroy', :id => user }, :confirm => 'Are you sure?', :method => :post %> diff --git a/db/migrate/20150914155101_add_status_to_heart_beat.rb b/db/migrate/20150914155101_add_status_to_heart_beat.rb new file mode 100644 --- /dev/null +++ b/db/migrate/20150914155101_add_status_to_heart_beat.rb @@ -0,0 +1,5 @@ +class AddStatusToHeartBeat < ActiveRecord::Migration + def change + add_column :heart_beats, :status, :string + end +end diff --git a/db/schema.rb b/db/schema.rb --- a/db/schema.rb +++ b/db/schema.rb @@ -11,16 +11,16 @@ # # It's strongly recommended to check this file into your version control system. -ActiveRecord::Schema.define(:version => 20150914090545) do +ActiveRecord::Schema.define(:version => 20150914155101) do create_table "announcements", :force => true do |t| t.string "author" - t.text "body" + t.text "body", :limit => 16777215 t.boolean "published" - t.datetime "created_at", :null => false - t.datetime "updated_at", :null => false - t.boolean "frontpage", :default => false - t.boolean "contest_only", :default => false + t.datetime "created_at", :null => false + t.datetime "updated_at", :null => false + t.boolean "frontpage", :default => false + t.boolean "contest_only", :default => false t.string "title" t.string "notes" end @@ -50,19 +50,19 @@ end create_table "descriptions", :force => true do |t| - t.text "body" + t.text "body", :limit => 16777215 t.boolean "markdowned" - t.datetime "created_at", :null => false - t.datetime "updated_at", :null => false + t.datetime "created_at", :null => false + t.datetime "updated_at", :null => false end create_table "grader_configurations", :force => true do |t| t.string "key" t.string "value_type" t.string "value" - t.datetime "created_at", :null => false - t.datetime "updated_at", :null => false - t.text "description" + t.datetime "created_at", :null => false + t.datetime "updated_at", :null => false + t.text "description", :limit => 16777215 end create_table "grader_processes", :force => true do |t| @@ -84,6 +84,7 @@ t.string "ip_address" t.datetime "created_at", :null => false t.datetime "updated_at", :null => false + t.string "status" end create_table "languages", :force => true do |t| @@ -104,10 +105,10 @@ t.integer "sender_id" t.integer "receiver_id" t.integer "replying_message_id" - t.text "body" + t.text "body", :limit => 16777215 t.boolean "replied" - t.datetime "created_at", :null => false - t.datetime "updated_at", :null => false + t.datetime "created_at", :null => false + t.datetime "updated_at", :null => false end create_table "problems", :force => true do |t| @@ -149,7 +150,7 @@ create_table "sessions", :force => true do |t| t.string "session_id" - t.text "data" + t.text "data", :limit => 16777215 t.datetime "updated_at" end @@ -177,14 +178,14 @@ t.integer "user_id" t.integer "problem_id" t.integer "language_id" - t.text "source" + t.text "source", :limit => 16777215 t.binary "binary" t.datetime "submitted_at" t.datetime "compiled_at" - t.text "compiler_message" + t.text "compiler_message", :limit => 16777215 t.datetime "graded_at" t.integer "points" - t.text "grader_comment" + t.text "grader_comment", :limit => 16777215 t.integer "number" t.string "source_filename" t.float "max_runtime" @@ -205,10 +206,10 @@ create_table "test_pairs", :force => true do |t| t.integer "problem_id" - t.text "input", :limit => 16777215 - t.text "solution", :limit => 16777215 - t.datetime "created_at", :null => false - t.datetime "updated_at", :null => false + t.text "input", :limit => 2147483647 + t.text "solution", :limit => 2147483647 + t.datetime "created_at", :null => false + t.datetime "updated_at", :null => false end create_table "test_requests", :force => true do |t| @@ -219,13 +220,13 @@ t.string "output_file_name" t.string "running_stat" t.integer "status" - t.datetime "updated_at", :null => false + t.datetime "updated_at", :null => false t.datetime "submitted_at" t.datetime "compiled_at" - t.text "compiler_message" + t.text "compiler_message", :limit => 16777215 t.datetime "graded_at" t.string "grader_comment" - t.datetime "created_at", :null => false + t.datetime "created_at", :null => false t.float "running_time" t.string "exit_status" t.integer "memory_usage" @@ -253,10 +254,10 @@ t.boolean "activated", :default => false t.datetime "created_at" t.datetime "updated_at" + t.string "section" t.boolean "enabled", :default => true t.string "remark" t.string "last_ip" - t.string "section" end add_index "users", ["login"], :name => "index_users_on_login", :unique => true