Skip to content

Commit

Permalink
added basic admin list and view for analysis jobs
Browse files Browse the repository at this point in the history
  • Loading branch information
cofiem committed Feb 26, 2016
1 parent 7281a9b commit 43da10a
Show file tree
Hide file tree
Showing 7 changed files with 203 additions and 2 deletions.
38 changes: 38 additions & 0 deletions app/controllers/admin/analysis_jobs_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
module Admin
class AnalysisJobsController < BaseController

# GET /admin/analysis_jobs
def index
page = paging_params[:page].blank? ? 1 : paging_params[:page].to_i
order_by = paging_params[:order_by].blank? ? :id : paging_params[:order_by].to_s.to_sym
order_dir = paging_params[:order_dir].blank? ? :desc : paging_params[:order_dir].to_s.to_sym

commit = (paging_params[:commit].blank? ? 'filter' : paging_params[:commit]).to_s

fail 'Invalid order by.' unless [:id, :name, :started_at, :overall_status, :overall_status_modified_at].include?(order_by)
fail 'Invalid order dir.' unless [:asc, :desc].include?(order_dir)

redirect_to admin_analysis_jobs_path if commit.downcase == 'clear'

@analysis_jobs_info = {
order_by: order_by,
order_dir: order_dir
}

query = AnalysisJob.includes(:script, :creator).all
@analysis_jobs = query.order(order_by => order_dir).page(page)
end

# GET /admin/analysis_jobs/:id
def show
@analysis_job = AnalysisJob.find(params[:id])
end

private

def paging_params
params.permit(:page, :order_by, :order_dir)
end

end
end
2 changes: 1 addition & 1 deletion app/controllers/admin/audio_recordings_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ def index
fail 'Invalid order by.' unless [:id, :site, :duration_seconds, :recorded_date, :created_at, :audio_event_count].include?(order_by)
fail 'Invalid order dir.' unless [:asc, :desc].include?(order_dir)

redirect_to admin_tags_path if commit.downcase == 'clear'
redirect_to admin_audio_recordings_path if commit.downcase == 'clear'

@audio_recordings_info = {
order_by: order_by,
Expand Down
70 changes: 70 additions & 0 deletions app/views/admin/analysis_jobs/index.html.haml
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
- content_for :title, 'Analysis Jobs'

= render partial: 'shared/admin/sidebar_analysis_jobs'

- content_for :right_sidebar do
= render partial: 'shared/sidebar_metadata_heading', locals: {title: 'Analysis Jobs', icon_class: 'tasks'}

- order_dir_icon = @analysis_jobs_info[:order_dir] == :asc ? 'caret-down' : 'caret-up'
- order_by_opposite = @analysis_jobs_info[:order_dir] == :asc ? :desc : :asc
- order_by = @analysis_jobs_info[:order_by]

.col-sm-12
.row
.col-sm-6
%p= page_entries_info @analysis_jobs

.row
.col-sm-12
= paginate @analysis_jobs

%table.table.table-striped.table-hover
%thead
%tr
%th
= link_to admin_analysis_jobs_path order_by: :id, order_dir: order_by_opposite do
%span.fa.fa-thumb-tack{aria: {hidden: 'true' }}
Id
- if order_by == :id
%span.fa{class: "fa-#{order_dir_icon}"}
%th
= link_to admin_analysis_jobs_path order_by: :name, order_dir: order_by_opposite do
%span.fa.fa-tasks{aria: {hidden: 'true' }}
Name
- if order_by == :name
%span.fa{class: "fa-#{order_dir_icon}"}
%th
%span.fa.fa-file-text-o{aria: {hidden: 'true' }}
Script
%th
%span.fa.fa-user{aria: {hidden: 'true' }}
Creator
%th
= link_to admin_analysis_jobs_path order_by: :started_at, order_dir: order_by_opposite do
%span.fa.fa-calendar{aria: {hidden: 'true' }}
Started
- if order_by == :started_at
%span.fa{class: "fa-#{order_dir_icon}"}
%th
= link_to admin_analysis_jobs_path order_by: :overall_status, order_dir: order_by_opposite do
%span.fa.fa-flag{aria: {hidden: 'true' }}
Status
- if order_by == :overall_status
%span.fa{class: "fa-#{order_dir_icon}"}
%th
= link_to admin_analysis_jobs_path order_by: :overall_status_modified_at, order_dir: order_by_opposite do
%span.fa.fa-calendar{aria: {hidden: 'true' }}
Status Updated
- if order_by == :overall_status_modified_at
%span.fa{class: "fa-#{order_dir_icon}"}

%tbody
- @analysis_jobs.each do |item|
%tr
%td= link_to item.id, admin_analysis_job_path(item)
%td= item.name
%td= link_to item.script.name, admin_script_path(item.script)
%td= link_to item.creator.user_name, user_account_path(item.creator)
%td= format_sidebar_datetime(item.started_at)
%td= item.overall_status
%td= format_sidebar_datetime(item.overall_status_modified_at)
80 changes: 80 additions & 0 deletions app/views/admin/analysis_jobs/show.html.haml
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
- content_for :title, 'Analysis Job Details'

= render partial: 'shared/admin/sidebar_analysis_jobs', locals: {aj_to_manage: @analysis_job}

- content_for :right_sidebar do
= render partial: 'shared/sidebar_metadata_heading', locals: {title: 'Analysis Jobs', icon_class: 'tasks'}

.col-sm-12

= simple_form_for(@analysis_job, url: admin_analysis_job_path(@analysis_job), html: {class: 'form-horizontal', multipart: true, method: :put }) do |f|
= field_set_tag do
= f.error_notification

- [:id, :name, :description, :annotation_name,
:creator_id, :updater_id, :deleter_id,
:created_at, :updated_at, :deleted_at,
:started_at,
:overall_status, :overall_status_modified_at,
:overall_progress, :overall_progress_modified_at,
:overall_count, :overall_duration_seconds,
:script_id, :saved_search_id,
:custom_settings].each do |item|
- human_ed = item.to_s.humanize
- param_ed = item.to_s.parameterize
- sym_ed = item
- str_ed = item.to_s
- value = begin @analysis_job[sym_ed]; rescue => e; "Error: #{e.inspect}"; end
.form-group.optional{class:param_ed}
%label.optional.control-label.col-sm-3{class:param_ed, for: param_ed}
= human_ed
.col-sm-8
%p.form-control-static{id: param_ed}
- unless value.blank?
- if value.is_a?(Time)
= value.iso8601
%small
="(#{time_ago_in_words(value)} ago)"
- elsif str_ed.end_with?('er_id') || str_ed.end_with?('or_id')
- user = User.find(value)
= link_to user.user_name, user_account_path(user)
%small
="(#{value})"
- elsif sym_ed == :overall_duration_seconds
= distance_of_time_in_words(value)
%small
= "(#{value})"
- elsif sym_ed == :overall_data_length_bytes
= number_to_human_size(value)
- elsif sym_ed == :script_id
= link_to @analysis_job.script.name, admin_script_path(@analysis_job.script)
%small
="(#{value})"
- elsif sym_ed == :saved_search_id
= @analysis_job.saved_search.name
%small
="(#{value})"
%pre
= @analysis_job.saved_search.description
%pre
= @analysis_job.saved_search.stored_query
- elsif sym_ed == :overall_progress || sym_ed == :custom_settings
%pre
= value
- else
= value
- else
%small
(no value)


.form-group.optional{class: 'projects'}
%label.optional.control-label.col-sm-3{class:'projects', for: 'projects'}
Saved Search Projects
.col-sm-8
%p.form-control-static{id: 'projects'}
- @analysis_job.saved_search.projects.each do |project|
= link_to project.name, project_path(project)
&nbsp;
- if @analysis_job.saved_search.projects.blank?
No projects
11 changes: 11 additions & 0 deletions app/views/shared/admin/_sidebar_analysis_jobs.html.haml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
-# locals: aj_to_manage
- content_for(:left_sidebar_header, 'Analysis Jobs')
- content_for(:left_sidebar) do
%li{class: ('active' if current_page?(admin_dashboard_path))}
= link_to 'Admin Home', admin_dashboard_path
%li{class: ('active' if current_page?(admin_analysis_jobs_path))}
= link_to 'Analysis Jobs', admin_analysis_jobs_path, title: 'Manage audio recordings', data: {toggle: 'tooltip', placement: 'right'}
- if defined?(aj_to_manage)
- if can?(:show, aj_to_manage)
%li{class: ('active' if current_page?(admin_analysis_job_path(aj_to_manage)))}
= link_to 'View Analysis Job', admin_analysis_job_path(aj_to_manage), title: 'View analysis job details', data: {toggle: 'tooltip', placement: 'right'}
2 changes: 2 additions & 0 deletions app/views/shared/admin/_sidebar_home.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,7 @@
= link_to t('baw.shared.links.admin_tag_groups.title'), admin_tag_groups_path
%li{class: ('active' if current_page?(admin_audio_recordings_path))}
= link_to 'Audio Recordings', admin_audio_recordings_path
%li{class: ('active' if current_page?(admin_analysis_jobs_path))}
= link_to 'Analysis Jobs', admin_analysis_jobs_path
%li
= link_to t('baw.shared.links.job_status.title'), '/job_queue_status'
2 changes: 1 addition & 1 deletion config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,7 @@
namespace :admin do
get '/' => 'home#index', as: :dashboard
resources :tags, :tag_groups
resources :audio_recordings, only: [:index, :show]
resources :audio_recordings, :analysis_jobs, only: [:index, :show]

resources :scripts, except: [:update] do
member do
Expand Down

0 comments on commit 43da10a

Please sign in to comment.