diff --git a/app/controllers/jobs_controller.rb b/app/controllers/jobs_controller.rb
index dfd35c3..22cf5e2 100644
--- a/app/controllers/jobs_controller.rb
+++ b/app/controllers/jobs_controller.rb
@@ -1,75 +1,76 @@
class JobsController < ApplicationController
before_action :fetch_host, only: [:new, :edit, :show, :create, :update,
:toggle_enable, :backup_now]
before_action :fetch_job, only: [:show, :edit, :update, :destroy, :toggle_enable, :backup_now]
# GET /jobs
def new
@job = @host.job_templates.new
end
# POST /jobs
def create
@job = @host.job_templates.new(fetch_params)
if @job.save
flash[:success] = 'Job created successfully'
redirect_to host_path(@host)
else
render :new
end
end
# GET /jobs/1
def show; end
# GET /jobs/1/edit
def edit;end
# PUT /jobs/1
def update
if @job.update_attributes(fetch_params)
flash[:success] = 'Job updated'
redirect_to host_job_path(@host, @job)
else
render :edit
end
end
# DELETE /jobs/1
def destroy
end
# PATCH /hosts/1/jobs/1/enable
def toggle_enable
@job.enabled = !@job.enabled
@job.save
flash[:success] = @job.enabled? ? 'Job enabled' : 'Job disabled'
redirect_to host_path(@host)
end
# POST /hosts/1/jobs/1/backup_now
def backup_now
if @job.backup_now
flash[:success] = 'Backup directive was sent to bacula. Backup will be taken in a while'
else
flash[:error] = 'Backup was not sent, try again later'
end
redirect_to client_path(@host.client)
end
private
def fetch_job
@job = @host.job_templates.find(params[:id])
end
def fetch_host
@host = current_user.hosts.find(params[:host_id])
end
def fetch_params
- params.require(:job_template).permit(:name, :fileset_id, :schedule_id)
+ params.require(:job_template).
+ permit(:name, :fileset_id, :schedule_id, :client_before_run_file, :client_after_run_file)
end
end
diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb
index ddda4a8..6379307 100644
--- a/app/helpers/application_helper.rb
+++ b/app/helpers/application_helper.rb
@@ -1,53 +1,53 @@
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-4 required')
- select_div = content_tag(:div, class: 'col-xs-6') 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,
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 'Add', path, class: 'btn btn-primary', role: 'button'
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'
end
end
end
diff --git a/app/views/jobs/_form.html.erb b/app/views/jobs/_form.html.erb
index c2151fb..e6d1e8c 100644
--- a/app/views/jobs/_form.html.erb
+++ b/app/views/jobs/_form.html.erb
@@ -1,25 +1,29 @@
-<%= bootstrap_form_for(@job, url: @job.new_record? ? host_jobs_path : host_job_path(@host, @job), layout: :horizontal, label_col: 'col-xs-4', control_col: 'col-xs-6') do |f| %>
+<%= bootstrap_form_for(@job, url: @job.new_record? ? host_jobs_path : host_job_path(@host, @job),
+ layout: :horizontal, label_col: 'col-xs-5', control_col: 'col-xs-5') do |f| %>
<%= f.text_field :name %>
<%= select_with_errors_and_button(
@job, :job_template, :fileset_id, 'Fileset',
options_from_collection_for_select(@host.filesets, :id, :name,
params[:fileset_id] || @job.fileset_id),
new_host_fileset_path(@host, job_id: @job.id))
%>
<% if !@job.restore? %>
<%= select_with_errors_and_button(
@job, :job_template, :schedule_id,
'Schedule', options_from_collection_for_select(@host.schedules, :id, :name,
params[:schedule_id] || @job.schedule_id),
new_host_schedule_path(@host, job_id: @job.id))
%>
<% end %>
+ <%= f.text_field :client_before_run_file, label: 'Client Run Before Job' %>
+ <%= f.text_field :client_after_run_file, label: 'Client Run After Job' %>
+
<% end %>
diff --git a/app/views/jobs/_job_details.html.erb b/app/views/jobs/_job_details.html.erb
index 00630e7..c5025d6 100644
--- a/app/views/jobs/_job_details.html.erb
+++ b/app/views/jobs/_job_details.html.erb
@@ -1,41 +1,49 @@
Name |
<%= @job.name %> |
Type |
<%= @job.job_type %> |
Host |
<%= @host.name %> |
Fileset |
<%= @job.fileset.name %> |
<% if @job.restore? %>
Restore Location |
<%= @job.restore_location %> |
<% else %>
Schedule |
<%= @job.schedule.name %> |
<% end %>
+ Client Run Before Job |
+ <%= @job.client_before_run_file %> |
+
+
+ Client Run After Job |
+ <%= @job.client_after_run_file %> |
+
+
Created |
<%= I18n.l(@job.created_at, format: :long) %> |
Enabled |
<%= @job.enabled_human %> |
diff --git a/app/views/jobs/_job_template_details.html.erb b/app/views/jobs/_job_template_details.html.erb
index 88f7e2a..ebc450d 100644
--- a/app/views/jobs/_job_template_details.html.erb
+++ b/app/views/jobs/_job_template_details.html.erb
@@ -1,17 +1,19 @@
<%= link_to job.name, host_job_path(@host, job) %> |
<%= job.job_type %> |
<%= job.fileset.name %> |
<%= job.schedule_human %> |
+ <%= job.client_before_run_file %> |
+ <%= job.client_after_run_file %> |
<%= job.priority %> |
<% if job.enabled? %>
<%= link_to 'Disable', toggle_enable_host_job_path(@host, job), method: :patch,
class: "btn btn-warning", role: "button" %>
<% else %>
<%= link_to 'Enable', toggle_enable_host_job_path(@host, job), method: :patch,
class: "btn btn-info", role: "button" %>
<% end %>
|
diff --git a/app/views/jobs/_job_templates.html.erb b/app/views/jobs/_job_templates.html.erb
index be9d8d4..6680673 100644
--- a/app/views/jobs/_job_templates.html.erb
+++ b/app/views/jobs/_job_templates.html.erb
@@ -1,23 +1,25 @@
Name |
Type |
FileSet |
Schedule |
+ Client Before Run Job |
+ Client After Run Job |
Priority |
Enabled |
<%= render partial: 'jobs/job_template_details',
collection: @host.job_templates, as: :job %>
<%= link_to 'Add Job', new_host_job_path(host_id: @host.id),
class: "btn btn-success", role: "button" %>