[ARVADOS] created: 2d9d106c40b83e9a72d431bdb198ed5b8b13550a
git at public.curoverse.com
git at public.curoverse.com
Sun Mar 9 04:25:54 EDT 2014
at 2d9d106c40b83e9a72d431bdb198ed5b8b13550a (commit)
commit 2d9d106c40b83e9a72d431bdb198ed5b8b13550a
Author: Tom Clegg <tom at curoverse.com>
Date: Sun Mar 9 04:24:25 2014 -0400
Add users/activity page.
diff --git a/apps/workbench/app/controllers/users_controller.rb b/apps/workbench/app/controllers/users_controller.rb
index 3ccaa52..927637f 100644
--- a/apps/workbench/app/controllers/users_controller.rb
+++ b/apps/workbench/app/controllers/users_controller.rb
@@ -1,5 +1,5 @@
class UsersController < ApplicationController
- skip_before_filter :find_object_by_uuid, :only => :welcome
+ skip_before_filter :find_object_by_uuid, :only => [:welcome, :activity]
skip_around_filter :thread_with_mandatory_api_token, :only => :welcome
def welcome
@@ -9,6 +9,54 @@ class UsersController < ApplicationController
end
end
+ def activity
+ @breadcrumb_page_name = nil
+ @users = User.all
+ @user_activity = {}
+ @activity = {
+ logins: {},
+ jobs: {},
+ pipeline_instances: {}
+ }
+ @spans = [['This week', Time.now.beginning_of_week, Time.now],
+ ['Last week', 1.week.ago.beginning_of_week, nil],
+ ['This month', Time.now.beginning_of_month, Time.now],
+ ['Last month', 1.month.ago.beginning_of_month, nil]].
+ collect do |span|
+ span[2] ||= span[1].advance(months: 1) if span[0].match /month/
+ span[2] ||= span[1].advance(weeks: 1) if span[0].match /week/
+ span
+ end
+ @spans.each do |span, threshold_start, threshold_end|
+ @activity[:logins][span] = Log.
+ filter([[:event_type, '=', 'login'],
+ [:object_kind, '=', 'arvados#user'],
+ [:created_at, '>=', threshold_start],
+ [:created_at, '<', threshold_end]])
+ @activity[:jobs][span] = Job.
+ filter([[:created_at, '>=', threshold_start],
+ [:created_at, '<', threshold_end]])
+ @activity[:pipeline_instances][span] = PipelineInstance.
+ filter([[:created_at, '>=', threshold_start],
+ [:created_at, '<', threshold_end]])
+ @activity.each do |type, act|
+ records = act[span]
+ @users.each do |u|
+ @user_activity[u.uuid] ||= {}
+ @user_activity[u.uuid][span + ' ' + type.to_s] ||= 0
+ end
+ records.each do |record|
+ @user_activity[record.modified_by_user_uuid] ||= {}
+ @user_activity[record.modified_by_user_uuid][span + ' ' + type.to_s] ||= 0
+ @user_activity[record.modified_by_user_uuid][span + ' ' + type.to_s] += 1
+ end
+ end
+ end
+ @users = @users.sort_by do |a|
+ [- at user_activity[a.uuid].values.inject(:+), a.full_name]
+ end
+ end
+
def home
@showallalerts = false
@my_ssh_keys = AuthorizedKey.where(authorized_user_uuid: current_user.uuid)
diff --git a/apps/workbench/app/views/users/activity.html.erb b/apps/workbench/app/views/users/activity.html.erb
new file mode 100644
index 0000000..619081f
--- /dev/null
+++ b/apps/workbench/app/views/users/activity.html.erb
@@ -0,0 +1,58 @@
+<% content_for :css do %>
+table#users-activity-table th {
+ overflow-x: hidden;
+}
+<% end %>
+<table class="table table-bordered table-condensed table-fixedlayout" id="users-activity-table">
+ <colgroup>
+ <col width="28%" />
+ </colgroup>
+ <% @spans.each do |_| %>
+ <colgroup>
+ <% 3.times do %>
+ <col width="<%= (72 / @spans.count / 3).floor %>%" />
+ <% end %>
+ </colgroup>
+ <% end %>
+
+ <tr>
+ <th rowspan="2">User</th>
+ <% @spans.each do |span, start_at, end_at| %>
+ <th colspan="3" title="<%= start_at.to_s.sub(/ .*/, '') %> to <%= (end_at-1.second).to_s.sub(/ .*/, '') %>"><%= span %></th>
+ <% end %>
+ </tr>
+ <tr>
+ <% @spans.each do |span, _| %>
+ <th>Logins</th>
+ <th>Jobs</th>
+ <th>Pipelines</th>
+ <% end %>
+ </tr>
+
+ <% @users.each do |user| %>
+ <tr>
+ <td>
+ <small>
+ <%= link_to_if_arvados_object user, friendly_name: true %>
+ </small>
+ </td>
+
+ <% @spans.each do |span, _| %>
+ <% ['logins', 'jobs', 'pipeline_instances'].each do |type| %>
+ <td>
+ <small>
+ <%= @user_activity[user.uuid][span + " " + type].to_s %>
+ </small>
+ </td>
+ <% end %>
+ <% end %>
+ </tr>
+ <% end %>
+</table>
+
+<% content_for :footer_js do %>
+$('#users-activity-table td small').each(function(){
+ if ($(this).html().trim() == '0')
+ $(this).css('opacity', '0.3');
+});
+<% end %>
diff --git a/apps/workbench/config/routes.rb b/apps/workbench/config/routes.rb
index 5330a91..376934e 100644
--- a/apps/workbench/config/routes.rb
+++ b/apps/workbench/config/routes.rb
@@ -19,6 +19,7 @@ ArvadosWorkbench::Application.routes.draw do
resources :users do
get 'home', :on => :member
get 'welcome', :on => :collection
+ get 'activity', :on => :collection
end
resources :logs
resources :factory_jobs
commit acf1ba5bb4d987012030de8978cc6930e1bee654
Author: Tom Clegg <tom at curoverse.com>
Date: Sun Mar 9 04:21:59 2014 -0400
Use action_name instead of URI path as the default breadcrumb page name.
diff --git a/apps/workbench/app/controllers/application_controller.rb b/apps/workbench/app/controllers/application_controller.rb
index e94428e..9cb1716 100644
--- a/apps/workbench/app/controllers/application_controller.rb
+++ b/apps/workbench/app/controllers/application_controller.rb
@@ -147,7 +147,8 @@ class ApplicationController < ActionController::Base
def breadcrumb_page_name
(@breadcrumb_page_name ||
- (@object.friendly_link_name if @object.respond_to? :friendly_link_name))
+ (@object.friendly_link_name if @object.respond_to? :friendly_link_name) ||
+ action_name)
end
def index_pane_list
commit fca114122bb204b34414a17e278748ec8e87e136
Author: Tom Clegg <tom at curoverse.com>
Date: Sun Mar 9 04:20:58 2014 -0400
Avoid extra API lookup to get an object that is already loaded.
diff --git a/apps/workbench/app/helpers/application_helper.rb b/apps/workbench/app/helpers/application_helper.rb
index cd8e527..2927be8 100644
--- a/apps/workbench/app/helpers/application_helper.rb
+++ b/apps/workbench/app/helpers/application_helper.rb
@@ -55,11 +55,15 @@ module ApplicationHelper
link_name = link_uuid
if opts[:friendly_name]
- begin
- link_name = resource_class.find(link_uuid).friendly_link_name
- rescue RuntimeError
- # If that lookup failed, the link will too. So don't make one.
- return attrvalue
+ if attrvalue.respond_to? :friendly_link_name
+ link_name = attrvalue.friendly_link_name
+ else
+ begin
+ link_name = resource_class.find(link_uuid).friendly_link_name
+ rescue RuntimeError
+ # If that lookup failed, the link will too. So don't make one.
+ return attrvalue
+ end
end
end
if opts[:with_class_name]
commit b37cf5e27548d8af4ec355c9a102c9a5734b3306
Author: Tom Clegg <tom at curoverse.com>
Date: Sun Mar 9 04:18:27 2014 -0400
Add ArvadosModel.filter() to support filters API
diff --git a/apps/workbench/app/models/arvados_base.rb b/apps/workbench/app/models/arvados_base.rb
index 72b76a5..09e3d8c 100644
--- a/apps/workbench/app/models/arvados_base.rb
+++ b/apps/workbench/app/models/arvados_base.rb
@@ -87,6 +87,9 @@ class ArvadosBase < ActiveRecord::Base
def self.order(*args)
ArvadosResourceList.new(self).order(*args)
end
+ def self.filter(*args)
+ ArvadosResourceList.new(self).filter(*args)
+ end
def self.where(*args)
ArvadosResourceList.new(self).where(*args)
end
diff --git a/apps/workbench/app/models/arvados_resource_list.rb b/apps/workbench/app/models/arvados_resource_list.rb
index 72495cf..ebea76c 100644
--- a/apps/workbench/app/models/arvados_resource_list.rb
+++ b/apps/workbench/app/models/arvados_resource_list.rb
@@ -20,6 +20,12 @@ class ArvadosResourceList
self
end
+ def filter _filters
+ @filters ||= []
+ @filters += _filters
+ self
+ end
+
def where(cond)
cond = cond.dup
cond.keys.each do |uuid_key|
@@ -52,6 +58,7 @@ class ArvadosResourceList
api_params[:eager] = '1' if @eager
api_params[:limit] = @limit if @limit
api_params[:order] = @orderby_spec if @orderby_spec
+ api_params[:filters] = @filters if @filters
res = $arvados_api_client.api @resource_class, '', api_params
@results = $arvados_api_client.unpack_api_response res
self
-----------------------------------------------------------------------
hooks/post-receive
--
More information about the arvados-commits
mailing list