diff --git a/app/controllers/admin/clients_controller.rb b/app/controllers/admin/clients_controller.rb index dc1b184..56eaf2e 100644 --- a/app/controllers/admin/clients_controller.rb +++ b/app/controllers/admin/clients_controller.rb @@ -1,68 +1,73 @@ class Admin::ClientsController < Admin::BaseController before_action :fetch_client, only: [:show, :jobs, :logs, :stats, :configuration, :disable] before_action :fetch_logs, only: [:logs] # Shows all available clients # # GET /admin/clients def index @clients = Client.includes(:jobs).all @client_ids = @clients.map(&:id) fetch_jobs_info end # Shows a specific client # # GET /admin/clients/1 def show + if !@client.host.present? + flash[:alert] = 'Client not configured through Archiving' + return redirect_to admin_clients_path + end + get_charts end # GET /admin/clients/1/jobs def jobs @jobs = @client.recent_jobs.page(params[:page]) end # GET /admin/clients/1/logs def logs end # GET /admin/clients/1/stats # POST /admin/clients/1/stats def stats get_charts end # GET /admin/clients/1/configuration def configuration end # POST /admin/clients/1/disable def disable if @client.host.disable_jobs_and_update flash[:success] = 'Client disabled' else flash[:error] = 'Something went wrong, try again later' end redirect_to admin_client_path(@client) end private # Fetches the client based on the given id def fetch_client @client = Client.find(params[:id]) @client_ids = [@client.id] end def fetch_jobs_info @stats = JobStats.new end def get_charts days_ago = params.fetch(:days_back, 7).to_i rescue 7 @job_status = ChartGenerator.job_statuses(@client_ids, days_ago) @job_stats = ChartGenerator.job_stats(@client_ids, days_ago - 1) end end diff --git a/app/helpers/hosts_helper.rb b/app/helpers/hosts_helper.rb index 6465429..ff2f1ac 100644 --- a/app/helpers/hosts_helper.rb +++ b/app/helpers/hosts_helper.rb @@ -1,25 +1,27 @@ module HostsHelper # Returns an html span with the host's status def host_status_label(host) + return unless host + case when host.pending? klass = "default" when host.configured? klass = "warning" when host.dispatched? klass = "info" when host.deployed? klass = "success" when host.updated? klass = "info" when host.redispatched? klass = "primary" when host.for_removal? klass = "danger" when host.inactive? klass = "warning" end content_tag(:span, class: "label label-#{klass}") { host.human_status_name.upcase } end end diff --git a/app/views/admin/clients/_client.html.erb b/app/views/admin/clients/_client.html.erb index bfc21bf..f6b79ef 100644 --- a/app/views/admin/clients/_client.html.erb +++ b/app/views/admin/clients/_client.html.erb @@ -1,12 +1,12 @@