diff --git a/app/models/client.rb b/app/models/client.rb index 8477348..730f61e 100644 --- a/app/models/client.rb +++ b/app/models/client.rb @@ -1,66 +1,73 @@ 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 has_one :host, foreign_key: :name, primary_key: :Name scope :for_user, ->(user_id) { joins(host: :users).where(users: { id: user_id }) } DAY_SECS = 60 * 60 * 24 + # Fetches the client's job_templates that are already persisted to + # Bacula's configuration + # + # @return [ActiveRecord::Relation] of `JobTemplate` + def persisted_jobs + host.job_templates.where(baculized: true).includes(:fileset, :schedule) + end + # 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/views/clients/_client_details.html.erb b/app/views/clients/_client_details.html.erb new file mode 100644 index 0000000..94cbb7d --- /dev/null +++ b/app/views/clients/_client_details.html.erb @@ -0,0 +1,42 @@ +
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Name<%= @client.name %>
Uname<%= @client.uname %>
Active Jobs<%= @client.running_jobs %>
Last Backup<%= @client.last_job_date %>
File Retention<%= @client.file_retention_days %> days
Job Retention<%= @client.job_retention_days %> days
Total Space Used<%= number_to_human_size @client.backup_jobs_size %>
Files count<%= number_by_magnitude(@client.files_count) %>
Auto Prune<%= @client.auto_prune_human %>
+
+
diff --git a/app/views/clients/_job.html.erb b/app/views/clients/_job.html.erb new file mode 100644 index 0000000..a254cd5 --- /dev/null +++ b/app/views/clients/_job.html.erb @@ -0,0 +1,8 @@ + + <%= job.name %> + <%= job.job_type %> + <%= job.fileset.try(:name) %> + <%= job.restore_location %> + <%= job.schedule_human %> + <%= I18n.l(job.created_at, format: :long) %> + diff --git a/app/views/clients/_jobs.html.erb b/app/views/clients/_jobs.html.erb new file mode 100644 index 0000000..aa1630e --- /dev/null +++ b/app/views/clients/_jobs.html.erb @@ -0,0 +1,19 @@ +
+
+ + + + + + + + + + + + + <%= render partial: 'clients/job', collection: @client.persisted_jobs, object: :job %> + +
NameTypeFilesetRestore LocationScheduleCreated
+
+
diff --git a/app/views/clients/show.html.erb b/app/views/clients/show.html.erb index ece9b7c..c3efec2 100644 --- a/app/views/clients/show.html.erb +++ b/app/views/clients/show.html.erb @@ -1,57 +1,30 @@

<%= notice %>

<% if @client.host %>
<%= link_to 'Manage Client', host_path(@client.host), class: "btn btn-primary", role: "button" %>
<% end %>

<%= @client.name %>

-
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Name<%= @client.name %>
Uname<%= @client.uname %>
Active Jobs<%= @client.running_jobs %>
Last Backup<%= @client.last_job_date %>
File Retention<%= @client.file_retention_days %> days
Job Retention<%= @client.job_retention_days %> days
Total Space Used<%= number_to_human_size @client.backup_jobs_size %>
Files count<%= number_by_magnitude(@client.files_count) %>
Auto Prune<%= @client.auto_prune_human %>
+
+
+

Client Details

+
+
+

Bacula Jobs

+
+
+ +
+ <%= render partial: 'client_details' %> + <%= render partial: 'jobs' %>
<%= link_to 'Restore Files', '#', class: "btn btn-warning", role: "button" %> <%= link_to 'Take Backup', '#', class: "btn btn-success", role: "button" %>

<%= link_to 'Back to clients', clients_path %>