diff --git a/app/controllers/clients_controller.rb b/app/controllers/clients_controller.rb index 6cf35fb..006e9f4 100644 --- a/app/controllers/clients_controller.rb +++ b/app/controllers/clients_controller.rb @@ -1,17 +1,18 @@ class ClientsController < ApplicationController before_action :set_client, only: :show # GET /clients def index - @clients = Client.all + @clients = Client.includes(:jobs).all + @active_jobs = Job.running.group(:ClientId).count end # GET /clients/1 def show; end private def set_client @client = Client.find(params[:id]) end end diff --git a/app/models/client.rb b/app/models/client.rb index c1d896d..8271b76 100644 --- a/app/models/client.rb +++ b/app/models/client.rb @@ -1,31 +1,63 @@ class Client < ActiveRecord::Base self.table_name = :Client self.primary_key = :ClientId alias_attribute :name, :Name alias_attribute :uname, :Uname alias_attribute :auto_prune, :AutoPrune alias_attribute :file_retention, :FileRetention alias_attribute :job_retention, :JobRetention has_many :jobs, foreign_key: :ClientId DAY_SECS = 60 * 60 * 24 # Helper method. It shows the client's job retention, # (which is expressed in seconds) in days. # # @return [Integer] def job_retention_days job_retention / DAY_SECS end # Helper method. It shows the client's file retention, # (which is expressed in seconds) in days. # # @return [Integer] def file_retention_days file_retention / DAY_SECS end + + # Helper method for auto_prune + # + # @return [String] 'yes' or 'no' + def auto_prune_human + auto_prune == 1 ? 'yes' : 'no' + end + + def last_job_date + jobs.maximum(:EndTime) + end + + # Shows the total file size of the jobs that run for a specific client + # + # @return [Integer] Size in Bytes + def backup_jobs_size + jobs.backup_type.map(&:job_bytes).sum + end + + # Shows the total files' count for the jobs that run for a specific client + # + # @return [Integer] File count + def files_count + jobs.map(&:job_files).sum + end + + # Fetches the client's jobs that are running at the moment + # + # @return [Integer] + def running_jobs + jobs.running.count + end end diff --git a/app/models/job.rb b/app/models/job.rb index a2d904a..1403f47 100644 --- a/app/models/job.rb +++ b/app/models/job.rb @@ -1,41 +1,45 @@ class Job < ActiveRecord::Base self.table_name = :Job self.primary_key = :JobId alias_attribute :job_id, :JobId alias_attribute :job, :Job alias_attribute :name, :Name alias_attribute :type, :Type alias_attribute :level, :Level alias_attribute :client_id, :ClientId alias_attribute :job_status, :JobStatus alias_attribute :sched_time, :SchedTime alias_attribute :start_time, :StartTime alias_attribute :end_time, :EndTime alias_attribute :real_end_time, :RealEndTime alias_attribute :job_t_date, :JobTDate alias_attribute :vol_session_id, :VolSessionId alias_attribute :vol_session_time, :VolSessionTime alias_attribute :job_files, :JobFiles alias_attribute :job_bytes, :JobBytes alias_attribute :read_bytes, :ReadBytes alias_attribute :job_errors, :JobErrors alias_attribute :job_missing_files, :JobMissingFiles alias_attribute :pool_id, :PoolId alias_attribute :file_set_id, :FileSetId alias_attribute :prior_job_id, :PriorJobId alias_attribute :purged_files, :PurgedFiles alias_attribute :has_base, :HasBase alias_attribute :has_cache, :HasCache alias_attribute :reviewed, :Reviewed alias_attribute :comment, :Comment belongs_to :pool, foreign_key: :PoolId belongs_to :file_set, foreign_key: :FileSetId belongs_to :client, foreign_key: :ClientId has_many :bacula_files, foreign_key: :JobId has_many :base_files, foreign_key: :BaseJobId has_many :job_media, foreign_key: :JobId has_many :logs, foreign_key: :JobId + + scope :running, -> { where(job_status: 'R') } + scope :backup_type, -> { where(type: 'B') } + scope :restore_type, -> { where(type: 'R') } end diff --git a/app/views/clients/_client.html.erb b/app/views/clients/_client.html.erb index b5e9fda..2a21339 100644 --- a/app/views/clients/_client.html.erb +++ b/app/views/clients/_client.html.erb @@ -1,7 +1,13 @@
Name | Uname | -AutoPrune | +Active Jobs | +Last Backup | FileRetention (days) | JobRetention (days) | +Space Used | +File count | +AutoPrune |
---|