diff --git a/app/controllers/admin/base_controller.rb b/app/controllers/admin/base_controller.rb
index 835b2df..968a0c2 100644
--- a/app/controllers/admin/base_controller.rb
+++ b/app/controllers/admin/base_controller.rb
@@ -1,24 +1,26 @@
class Admin::BaseController < ApplicationController
before_action :require_admin
+ # GET /admin
+ # POST /admin
def index
@client_ids = Client.pluck(:ClientId)
get_charts
render 'admin/index'
end
protected
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
def require_admin
return if current_user.try(:admin?)
flash[:alert] = 'You need to log in first'
redirect_to root_path
end
end
diff --git a/app/controllers/clients_controller.rb b/app/controllers/clients_controller.rb
index c30aa6c..e18d752 100644
--- a/app/controllers/clients_controller.rb
+++ b/app/controllers/clients_controller.rb
@@ -1,45 +1,47 @@
class ClientsController < ApplicationController
before_action :set_client, only: [:show, :jobs, :logs, :stats]
before_action :fetch_logs, only: [:logs]
# GET /clients
+ # POST /clients
def index
@client_ids = Client.for_user(current_user.id).pluck(:ClientId)
@clients = Client.where(ClientId: @client_ids).includes(:jobs)
@hosts = current_user.hosts.not_baculized
fetch_jobs_info
get_charts
end
# GET /clients/1
def show
end
# GET /clients/1/jobs
def jobs; end
# GET /clients/1/logs
def logs; end
# GET /clients/1/stats
+ # POST /clients/1/stats
def stats
get_charts
end
private
def set_client
@client = Client.for_user(current_user.id).find(params[:id])
@client_ids = [@client.id]
end
def fetch_jobs_info
@stats = JobStats.new(@client_ids)
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/views/admin/clients/_client_graphs.html.erb b/app/views/admin/clients/_client_graphs.html.erb
index 0d1a682..87999e2 100644
--- a/app/views/admin/clients/_client_graphs.html.erb
+++ b/app/views/admin/clients/_client_graphs.html.erb
@@ -1,18 +1,18 @@
- <%= bootstrap_form_tag(url: path, method: :get, layout: :inline) do |f| %>
+ <%= bootstrap_form_tag(url: path, method: :post, layout: :inline) do |f| %>
<%= f.select(:days_back, [['1 week', 7], ['2 weeks', 14], ['1 month', 30]]) %>
<%= f.submit 'See Stats', class: "btn btn-primary" %>
<% end %>
<%= baas_chart('jobs_status', @job_status) %>
<%= baas_chart('jobs_stats', @job_stats) %>
diff --git a/app/views/clients/_client_graphs.html.erb b/app/views/clients/_client_graphs.html.erb
index eadc1cd..a84a14b 100644
--- a/app/views/clients/_client_graphs.html.erb
+++ b/app/views/clients/_client_graphs.html.erb
@@ -1,18 +1,18 @@
- <%= bootstrap_form_tag(url: path, method: :get, layout: :inline) do |f| %>
+ <%= bootstrap_form_tag(url: path, method: :post, layout: :inline) do |f| %>
<%= f.select(:days_back, [['1 week', 7], ['2 weeks', 14], ['1 month', 30]], selected: params[:days_back]) %>
<%= f.submit 'See Stats', class: "btn btn-primary" %>
<% end %>
<%= baas_chart('jobs_status', @job_status) %>
<%= baas_chart('jobs_stats', @job_stats) %>
diff --git a/config/routes.rb b/config/routes.rb
index 91af38a..aeed8c5 100644
--- a/config/routes.rb
+++ b/config/routes.rb
@@ -1,43 +1,48 @@
Rails.application.routes.draw do
root 'clients#index'
resources :clients, only: [:index, :show] do
member do
get :jobs
get :logs
get :stats
+ post :stats
+ end
+
+ collection do
+ post :index
end
end
resources :hosts, only: [:new, :create, :show, :edit, :update, :destroy] do
member do
post :submit_config
get :restore
post :run_restore
delete :revoke
end
resources :jobs, only: [:new, :create, :show, :edit, :update, :destroy] do
member do
patch :toggle_enable
post :backup_now
end
end
resources :filesets, only: [:show, :new, :create, :destroy]
resources :schedules, only: [:show, :new, :edit, :create, :update, :destroy]
end
namespace :admin do
- get '/' => 'base#index'
+ match '/', to: 'base#index', via: [:get, :post]
resources :clients, only: [:index, :show] do
member do
get :jobs
get :logs
get :stats
post :stats
end
end
end
end
diff --git a/spec/routing/client_routing_spec.rb b/spec/routing/client_routing_spec.rb
index 3fde0a8..0e3a5ba 100644
--- a/spec/routing/client_routing_spec.rb
+++ b/spec/routing/client_routing_spec.rb
@@ -1,31 +1,40 @@
require 'spec_helper'
describe ClientsController do
it 'routes /clients' do
expect(get('/clients')).to route_to(controller: 'clients', action: 'index')
end
+ it 'routes /clients' do
+ expect(post('/clients')).to route_to(controller: 'clients', action: 'index')
+ end
+
it 'routes GET /' do
expect(get('/')).to route_to(controller: 'clients', action: 'index')
end
it 'routes GET /clients/1' do
expect(get('/clients/1')).to route_to(controller: 'clients', action: 'show', id: '1')
end
it 'routes GET /clients/1/stats' do
expect(get('/clients/1/stats')).
to route_to(controller: 'clients', action: 'stats', id: '1')
end
+ it 'routes POST /clients/1/stats' do
+ expect(post('/clients/1/stats')).
+ to route_to(controller: 'clients', action: 'stats', id: '1')
+ end
+
it 'routes GET /clients/1/logs' do
expect(get('/clients/1/logs')).
to route_to(controller: 'clients', action: 'logs', id: '1')
end
it 'routes GET /clients/1/jobs' do
expect(get('/clients/1/jobs')).
to route_to(controller: 'clients', action: 'jobs', id: '1')
end
end