diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index fbfb632..28e8cff 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -1,111 +1,112 @@ class ApplicationController < ActionController::Base # Prevent CSRF attacks by raising an exception. # For APIs, you may want to use :null_session instead. protect_from_forgery with: :exception helper_method :current_user, :warden, :days_ago # GET / def index redirect_to clients_path if current_user end # GET /faq def faq @faqs = Faq.order(priority: :desc).all end # Warden handler for authentication failure def unauthenticated flash[:error] = warden.message || 'There was an error with your login' if attempted_path == '/grnet' redirect_to admin_login_path else redirect_to root_path end end # POST /grnet def grnet if current_user warden.logout reset_current_user end begin warden.authenticate!(:admin) rescue return unauthenticated end current_user redirect_to admin_path end # GET /institutional def institutional begin warden.authenticate!(:institutional) rescue return unauthenticated end current_user redirect_to clients_path end # POST /vima def vima begin warden.authenticate!(:vima) rescue return unauthenticated end current_user redirect_to clients_path end def logout warden.logout reset_current_user redirect_to root_path end protected def warden request.env['warden'] end def current_user @current_user ||= warden.user end def reset_current_user @current_user = nil end def fetch_logs if @client @logs = Log.includes(:job).joins(job: :client).where(Client: { ClientId: @client.id }) else @logs = Log.includes(:job).joins(job: { client: { host: :users } }). where(users: { id: current_user.id }) end + @logs = @logs.where(JobId: params[:job_id]) if params[:job_id] @logs = @logs.order(Time: :desc, LogId: :desc) end def days_ago params.fetch(:days_back, 7).to_i rescue 7 end private def require_logged_in return if current_user flash[:alert] = 'You need to log in first' redirect_to root_path end def attempted_path (request.env['warden.options'] || {})[:attempted_path] end end diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 86eeaaa..f11e7fc 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -1,152 +1,152 @@ module ApplicationHelper # Custom helper for better display of big numbers # @example number_by_magnitude(4242) # "4.2K" # # @param number[Numeric] # @return [String] human friendly respresentation def number_by_magnitude(number) number_to_human(number, units: { thousand: :K, million: :M, billion: :G }) end # Creates a bootstrap form-group div with an additional 'Add' button next to the select field # # @param object[ActiveRecord::Object] the form's subject # @param resource[Symbol] the objects class # @param attr[Symbol] the select box's attribute # @param attr_name[String] the attribute's display name # @param options[Array] the select box options # @param path[String] the add button's path def select_with_errors_and_button(object, resource, attr, attr_name, options, path) has_errors = object.errors[attr].present? content_tag(:div, class: "form-group #{' has-error' if has_errors }") do attr_label = label(resource, attr, attr_name, class: 'control-label col-xs-5 required') select_div = content_tag(:div, class: 'col-xs-5') do select_part = select_tag([resource, attr].join('_').to_sym, options, include_blank: true, name: "#{resource}[#{attr}]", class: 'form-control' ) if has_errors select_part.concat(content_tag(:span, class: 'help-block') { object.errors[attr].first }) end select_part end button_part = content_tag(:div, class: 'col-xs-1') do link_to path do content_tag(:span, class: 'glyphicon glyphicon-plus text-success') {} end end attr_label.concat(select_div).concat(button_part) end end # Returns a style class depending on the given parameter # # @param status[Char] def success_class(status) case status when 'T' then 'success' when 'E' then 'danger' when 'f' then 'fatal' end end # Fetches the html class for a given path # # @param path[String] the path to check for # @param partial[Boolean] forces a left partial match # # @return [Hash] { class: 'active' } if the given path is the current page def active_class(path, partial = false) if current_page?(path) || (partial && request.path.starts_with?(path)) { class: 'active' } else {} end end # Constructs a breadcrumb out the given options # # @param options[Hash] a hash containing the breadcrumb links in name: path sets # @return an html ol breadcrumb def breadcrumb_with(options) content_tag(:ol, class: 'breadcrumb') do options.map { |name, path| content_tag(:li, active_class(path)) do - link_to_if !current_page?(path), name, path + link_to name, path end }.inject { |result, element| result.concat(element) } end end # Constructs a list with the given array elements # # @example: # inline_list([:foo, :bar]) # # # # @param arr[Array] # @return an html ul list def inline_list(arr) content_tag(:ul, class: 'list-inline') do arr.map { |element| content_tag(:li) do content_tag(:span, class: 'label label-default') do element end end }.inject { |result, element| result.concat(element) } end end # Generates a span with a yes or no and the corresponding formatting # according to the value's falseness # # @param value[Integer] def yes_no(value) klass = value == 1 ? 'label label-success' : 'label label-danger' text = value == 1 ? 'yes' : 'no' content_tag(:span, class: klass) { text } end # Generates a percentage and adds some color coding for better visibility # # @param ratio [Numeric] the ratio # @param quota [Integer] the client's space quota # # @return [String] an html label tag def pretty_percentage(ratio, quota) color = ([[ratio, 0.2].max, 0.99].min * 256).to_i.to_s(16) << '0000' content_tag(:label, class: 'label', style: "background-color:##{color}") do number_to_percentage(100 * ratio, precision: 1) end end # Generates a button that may be disabled # # @param disabled[Boolean] # @param display_text[String] # @param url[String] # @param opts[Hash] def button_or_disabled(disabled, display_text, url, opts = {}) if disabled url = '#' opts.merge!(disabled: true) opts.reverse_merge!(title: 'Client is blocked') opts.delete(:method) else opts.delete(:title) end link_to display_text, url, opts end end diff --git a/app/views/admin/clients/logs.html.erb b/app/views/admin/clients/logs.html.erb index 77554eb..d144f20 100644 --- a/app/views/admin/clients/logs.html.erb +++ b/app/views/admin/clients/logs.html.erb @@ -1,30 +1,30 @@ <%= render partial: 'header' %>

Logs (<%= @logs.count %>)

- <%= render partial: 'log', collection: @logs %>
LogIdJobId + JobId Job Time Text
diff --git a/app/views/admin/jobs/_recent_job.html.erb b/app/views/admin/jobs/_recent_job.html.erb index a0ce173..1c4c8e5 100644 --- a/app/views/admin/jobs/_recent_job.html.erb +++ b/app/views/admin/jobs/_recent_job.html.erb @@ -1,15 +1,18 @@ <%= recent_job.name %> <%= recent_job.client.name %> - <%= link_to recent_job.job_id, logs_admin_client_path(recent_job.client) %> + + <%= link_to recent_job.job_id, + logs_admin_client_path(recent_job.client, job_id: recent_job.id) %> + <%= recent_job.level_human %> <%= recent_job.fileset %> <%= recent_job.start_time_formatted %> <%= recent_job.end_time_formatted %> <%= recent_job.duration %> <%= number_to_human_size(recent_job.job_bytes) %> <%= number_by_magnitude(recent_job.job_files) %> <%= recent_job.status_human %> <%= recent_job.encryption %> <%= recent_job.compression %>