diff --git a/app/controllers/jobs_controller.rb b/app/controllers/jobs_controller.rb
index 40afa01..02c85ef 100644
--- a/app/controllers/jobs_controller.rb
+++ b/app/controllers/jobs_controller.rb
@@ -1,52 +1,59 @@
class JobsController < ApplicationController
- before_action :fetch_job, only: [:show, :edit, :update, :destroy]
- before_action :fetch_host, only: [:new, :edit, :show, :create, :update]
+ before_action :fetch_job, only: [:show, :edit, :update, :destroy, :toggle_enable]
+ before_action :fetch_host, only: [:new, :edit, :show, :create, :update, :toggle_enable]
# GET /jobs
def new
@job = @host.job_templates.new
end
# POST /jobs
def create
@job = @host.job_templates.new(fetch_params)
if @job.save
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)
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
+ redirect_to host_path(@host)
+ end
+
private
def fetch_job
@job = JobTemplate.find(params[:id])
end
def fetch_host
@host = Host.find(params[:host_id])
end
def fetch_params
params.require(:job_template).permit(:name, :job_type, :fileset_id, :schedule_id)
end
end
diff --git a/app/views/jobs/_job_details.html.erb b/app/views/jobs/_job_details.html.erb
index 2732358..1d15ac0 100644
--- a/app/views/jobs/_job_details.html.erb
+++ b/app/views/jobs/_job_details.html.erb
@@ -1,31 +1,34 @@
Name |
<%= @job.name %> |
Type |
<%= @job.job_type %> |
Host |
<%= @host.name %> |
Fileset |
<%= @job.fileset.name %> |
Schedule |
<%= @job.schedule.name %> days |
Created |
<%= I18n.l(@job.created_at, format: :long) %> |
+
+ Enabled |
+ <%= @job.enabled_human %> |
+
- <%= link_to 'Edit', edit_host_job_path(@host, @job), class: "btn btn-primary", role: "button" %>
diff --git a/app/views/jobs/_job_template_details.html.erb b/app/views/jobs/_job_template_details.html.erb
index caadef8..6cba013 100644
--- a/app/views/jobs/_job_template_details.html.erb
+++ b/app/views/jobs/_job_template_details.html.erb
@@ -1,10 +1,18 @@
<%= link_to job.name, host_job_path(@host, job) %> |
<%= job.job_type %> |
<%= job.fileset.name %> |
<%= job.restore_location %> |
<%= job.schedule.name %> |
<%= job.priority %> |
- <%= job.enabled_human %> |
+
+ <% 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/show.html.erb b/app/views/jobs/show.html.erb
index 79c6ecd..077b71a 100644
--- a/app/views/jobs/show.html.erb
+++ b/app/views/jobs/show.html.erb
@@ -1,11 +1,18 @@
"<%= @job.name %>" Job Template
<%= render partial: 'job_details' %>
+
+
+
+ <%= link_to 'Edit', edit_host_job_path(@host, @job),
+ class: "btn btn-primary", role: "button" %>
+
+
diff --git a/config/routes.rb b/config/routes.rb
index fbaae22..b5b2595 100644
--- a/config/routes.rb
+++ b/config/routes.rb
@@ -1,11 +1,16 @@
Rails.application.routes.draw do
resources :clients, only: [:index, :show]
+
resources :hosts, only: [:new, :create, :show, :edit, :update, :destroy] do
- resources :jobs, only: [:new, :create, :show, :edit, :update, :destroy]
+ resources :jobs, only: [:new, :create, :show, :edit, :update, :destroy] do
+ member do
+ patch :toggle_enable
+ end
+ end
end
resources :schedules, only: [:show, :new, :edit, :create, :update, :destroy]
resources :filesets, only: [:show, :new, :create, :destroy]
root 'clients#index'
end
diff --git a/spec/routing/job_routing_spec.rb b/spec/routing/job_routing_spec.rb
index 1b3c155..7bff3c6 100644
--- a/spec/routing/job_routing_spec.rb
+++ b/spec/routing/job_routing_spec.rb
@@ -1,27 +1,32 @@
require 'spec_helper'
describe HostsController do
it 'routes GET /hosts/1/jobs/new' do
- expect(get('/hosts/1/jobs/new')).to route_to( { controller: 'jobs', action: 'new', host_id: '1' })
+ expect(get('/hosts/1/jobs/new')).to route_to(controller: 'jobs', action: 'new', host_id: '1')
end
it 'routes POST /hosts/1/jobs' do
- expect(post('/hosts/1/jobs')).to route_to( { controller: 'jobs', action: 'create', host_id: '1' })
+ expect(post('/hosts/1/jobs')).to route_to(controller: 'jobs', action: 'create', host_id: '1')
end
it 'routes GET /hosts/1/jobs/1' do
- expect(get('/hosts/1/jobs/1')).to route_to( { controller: 'jobs', action: 'show', host_id: '1', id: '1' })
+ expect(get('/hosts/1/jobs/1')).to route_to(controller: 'jobs', action: 'show', host_id: '1', id: '1')
end
it 'routes GET /hosts/1/jobs/1/edit' do
- expect(get('/hosts/1/jobs/1/edit')).to route_to( { controller: 'jobs', action: 'edit', host_id: '1', id: '1' })
+ expect(get('/hosts/1/jobs/1/edit')).to route_to(controller: 'jobs', action: 'edit', host_id: '1', id: '1')
end
it 'routes PUT /hosts/1/jobs/1' do
- expect(put('/hosts/1/jobs/1')).to route_to( { controller: 'jobs', action: 'update', host_id: '1', id: '1' })
+ expect(put('/hosts/1/jobs/1')).to route_to(controller: 'jobs', action: 'update', host_id: '1', id: '1')
+ end
+
+ it 'routes PATCH /hosts/1/jobs/1/toggle_enable' do
+ expect(patch('/hosts/1/jobs/1/toggle_enable')).
+ to route_to(controller: 'jobs', action: 'toggle_enable', host_id: '1', id: '1')
end
it 'routes DELETE /hosts/1/jobs/1' do
- expect(delete('/hosts/1/jobs/1')).to route_to( { controller: 'jobs', action: 'destroy', host_id: '1', id: '1' })
+ expect(delete('/hosts/1/jobs/1')).to route_to(controller: 'jobs', action: 'destroy', host_id: '1', id: '1')
end
end