Page Menu
Home
GRNET
Search
Configure Global Search
Log In
Files
F1090761
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Subscribers
None
File Metadata
Details
File Info
Storage
Attached
Created
Wed, Oct 15, 11:26 AM
Size
10 KB
Mime Type
text/x-diff
Expires
Fri, Oct 17, 11:26 AM (1 d, 16 h)
Engine
blob
Format
Raw Data
Handle
278100
Attached To
rARCHIVING archiving
View Options
diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb
index bd0964e..35b43c5 100644
--- a/app/helpers/application_helper.rb
+++ b/app/helpers/application_helper.rb
@@ -1,133 +1,149 @@
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-5 required')
select_div = content_tag(:div, class: 'col-xs-5') do
select_part = select_tag([resource, attr].join('_').to_sym,
options,
include_blank: true,
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 path do
content_tag(:span, class: 'glyphicon glyphicon-plus text-success') {}
end
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'
when 'f' then 'fatal'
end
end
# Fetches the html class for a given path
#
# @param path[String] the path to check for
# @param partial[Boolean] forces a left partial match
#
# @return [Hash] { class: 'active' } if the given path is the current page
def active_class(path, partial = false)
if current_page?(path) || (partial && request.path.starts_with?(path))
{ class: 'active' }
else
{}
end
end
# Constructs a breadcrumb out the given options
#
# @param options[Hash] a hash containing the breadcrumb links in name: path sets
# @return an html ol breadcrumb
def breadcrumb_with(options)
content_tag(:ol, class: 'breadcrumb') do
options.map { |name, path|
content_tag(:li, active_class(path)) do
link_to_if !current_page?(path), name, path
end
}.inject { |result, element| result.concat(element) }
end
end
# Constructs a list with the given array elements
#
# @example:
# inline_list([:foo, :bar])
#
# <ul class="list-inline'>
# <li><span class="label label-default">foo</span></li>
# <li><span class="label label-default">bar</span></li>
# </ul>
#
# @param arr[Array]
# @return an html ul list
def inline_list(arr)
content_tag(:ul, class: 'list-inline') do
arr.map { |element|
content_tag(:li) do
content_tag(:span, class: 'label label-default') do
element
end
end
}.inject { |result, element| result.concat(element) }
end
end
# Generates a span with a yes or no and the corresponding formatting
# according to the value's falseness
#
# @param value[Integer]
def yes_no(value)
klass = value == 1 ? 'label label-success' : 'label label-danger'
text = value == 1 ? 'yes' : 'no'
content_tag(:span, class: klass) { text }
end
# Generates a percentage and adds some color coding for better visibility
#
# @param ratio [Numeric] the ratio
# @param quota [Integer] the client's space quota
#
# @return [String] an html label tag
def pretty_percentage(ratio, quota)
color = ([[ratio, 0.2].max, 0.99].min * 256).to_i.to_s(16) << '0000'
content_tag(:label, class: 'label', style: "background-color:##{color}") do
number_to_percentage(100 * ratio, precision: 1)
end
end
+
+ # Generates a button that may be disabled
+ #
+ # @param disabled[Boolean]
+ # @param display_text[String]
+ # @param url[String]
+ # @param opts[Hash]
+ def button_or_disabled(disabled, display_text, url, opts = {})
+ if disabled
+ url = '#'
+ opts.merge!(disabled: true, title: 'Client is disabled')
+ opts.delete(:method)
+ end
+
+ link_to display_text, url, opts
+ end
end
diff --git a/app/views/clients/_client_details.html.erb b/app/views/clients/_client_details.html.erb
index 46217d7..d82e4e9 100644
--- a/app/views/clients/_client_details.html.erb
+++ b/app/views/clients/_client_details.html.erb
@@ -1,58 +1,59 @@
<div class="col-xs-4">
<div class="table-responsive">
<table class="table table-striped table-bordered table-condensed ">
<tr>
<td>Name</td>
<td><%= @client.name %></td>
</tr>
<tr>
<td>Uname</td>
<td><%= @client.uname %></td>
</tr>
<tr>
<td>Active Jobs</td>
<td><%= @client.running_jobs %></td>
</tr>
<tr>
<td>Last Backup</td>
<td>
<%= @client.last_job_date_formatted %>
</td>
</tr>
<tr>
<td>File Retention</td>
<td><%= @client.file_retention_days %> days</td>
</tr>
<tr>
<td>Job Retention</td>
<td><%= @client.job_retention_days %> days</td>
</tr>
<tr>
<td>Total Space Used</td>
<td><%= number_to_human_size @client.backup_jobs_size %></td>
</tr>
<tr>
<td>Client Quota</td>
<td><%= number_to_human_size @client.quota %></td>
</tr>
<tr>
<td>Space Used %</td>
<td>
<% if @client.quota.to_f > 0 %>
<%= pretty_percentage(@client.backup_jobs_size.to_f / @client.quota, @client.quota) %>
<% end %>
</td>
</tr>
<tr>
<td>Files count</td>
<td><%= number_by_magnitude(@client.files_count) %></td>
</tr>
</table>
</div>
<div>
<% if @client.is_backed_up? %>
- <%= link_to 'Restore Files', restore_client_path(@client),
- class: "btn btn-warning", role: "button" %>
+ <%= button_or_disabled(@client.host.blocked?, 'Restore Files',
+ restore_client_path(@client),
+ class: "btn btn-warning", role: "button") %>
<% end %>
</div>
</div>
diff --git a/app/views/clients/_job.html.erb b/app/views/clients/_job.html.erb
index 48f8c1d..197e317 100644
--- a/app/views/clients/_job.html.erb
+++ b/app/views/clients/_job.html.erb
@@ -1,19 +1,20 @@
<tr>
<td><%= job.name %></td>
<td><%= job.job_type %></td>
<td>
<%= link_to job.fileset.name, '#',
data: { toggle: 'modal', target: ".js-fileset-#{job.fileset_id}:first"} %>
</td>
<td>
<%= link_to job.schedule_human, '#',
data: { toggle: 'modal', target: ".js-schedule-#{job.schedule_id}:first"} %>
</td>
<td><%= I18n.l(job.created_at, format: :long) %></td>
<td>
<% if job.enabled? && job.baculized? && job.backup? %>
- <%= link_to 'Full Backup Now', backup_now_host_job_path(job.host, job),
- method: :post, class: "btn btn-success", role: "button" %>
+ <%= button_or_disabled(@client.host.blocked?, 'Full Backup Now',
+ backup_now_host_job_path(job.host, job), method: :post,
+ class: "btn btn-success", role: "button") %>
<% end %>
</td>
</tr>
diff --git a/app/views/jobs/_job_template_details.html.erb b/app/views/jobs/_job_template_details.html.erb
index 6c8551c..8d358b2 100644
--- a/app/views/jobs/_job_template_details.html.erb
+++ b/app/views/jobs/_job_template_details.html.erb
@@ -1,23 +1,23 @@
<tr>
<td><%= link_to job.name, host_job_path(@host, job) %></td>
<td><%= job.job_type %></td>
<td>
<%= link_to job.fileset.name, '#',
data: { toggle: 'modal', target: ".js-fileset-#{job.fileset_id}:first"} %>
</td>
<td>
<%= link_to job.schedule_human, '#',
data: { toggle: 'modal', target: ".js-schedule-#{job.schedule_id}:first"} %>
</td>
<td><%= job.client_before_run_file %></td>
<td><%= job.client_after_run_file %></td>
<td>
<% if job.enabled? %>
- <%= link_to 'Disable', toggle_enable_host_job_path(@host, job), method: :patch,
- class: "btn btn-warning", role: "button" %>
+ <%= button_or_disabled(@host.blocked?, '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" %>
+ <%= button_or_disabled(@host.blocked?, 'Enable', toggle_enable_host_job_path(@host, job),
+ method: :patch, class: "btn btn-info", role: "button") %>
<% end %>
</td>
</tr>
diff --git a/app/views/jobs/_job_templates.html.erb b/app/views/jobs/_job_templates.html.erb
index 3620112..7752013 100644
--- a/app/views/jobs/_job_templates.html.erb
+++ b/app/views/jobs/_job_templates.html.erb
@@ -1,24 +1,24 @@
<div class="col-xs-6">
<div class="table-responsive">
<table class="table table-striped table-bordered table-condensed">
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th>FileSet</th>
<th>Schedule</th>
<th>Client Before Run Job</th>
<th>Client After Run Job</th>
<th>Enabled</th>
</tr>
</thead>
<tbody>
<%= render partial: 'jobs/job_template_details',
collection: @host.job_templates, as: :job %>
</tbody>
</table>
</div>
- <%= link_to 'Add Job', new_host_job_path(host_id: @host.id),
- class: "btn btn-success", role: "button" %>
+ <%= button_or_disabled(@host.blocked?, 'Add Job', new_host_job_path(host_id: @host.id),
+ class: "btn btn-success", role: "button") %>
</div>
Event Timeline
Log In to Comment