app/helpers/naf/application_helper.rb in naf-2.0.4 vs app/helpers/naf/application_helper.rb in naf-2.1.0
- old
+ new
@@ -19,11 +19,12 @@
"janitorial_assignments"]
NAF_READ_ONLY_RESOURCES = []
NAF_CREATE_BLOCKED_RESOURCES = []
NAF_ALL_VISIBLE_RESOURCES = {
'historical_jobs' => '',
- 'applications' => '',
+ 'scripts' => ['applications',
+ 'application_schedules'],
'machines' => '',
'runners' => ['machine_runners',
'machine_runner_invocations'],
'affinities' => '',
'loggers' => ['logger_styles', 'logger_names'],
@@ -37,29 +38,37 @@
NAF_ALL_VISIBLE_RESOURCES
end
def naf_last_queued_at_link(app)
if historical_job = app.last_queued_job
- link_to "#{time_ago_in_words(historical_job.created_at, true)} ago, #{historical_job.created_at.localtime.strftime("%Y-%m-%d %r")}",
+ link_to "#{time_ago_in_words(historical_job.created_at, true)} ago, " +
+ "#{historical_job.created_at.localtime.strftime("%Y-%m-%d %r")}",
naf.historical_job_path(historical_job)
else
""
end
end
def naf_highlight_tab?(tab)
case tab
when "machines"
- [tab, "machine_affinity_slots"].include?(controller_name)
+ [tab,
+ "machine_affinity_slots"].include?(controller_name)
when "runners"
- ["machine_runners", "machine_runner_invocations"].include?(controller_name)
+ ["machine_runners",
+ "machine_runner_invocations"].include?(controller_name)
when "historical_jobs"
- [tab, "historical_job_affinity_tabs"].include?(controller_name)
- when "applications"
- [tab, "application_schedule_affinity_tabs"].include?(controller_name)
+ [tab,
+ "historical_job_affinity_tabs"].include?(controller_name)
+ when "scripts"
+ [tab,
+ "applications",
+ "application_schedules",
+ "application_schedule_affinity_tabs"].include?(controller_name)
when "loggers"
- ["logger_styles", "logger_names"].include?(controller_name)
+ ["logger_styles",
+ "logger_names"].include?(controller_name)
when "janitorial_assignments"
["Naf::JanitorialArchiveAssignment",
"Naf::JanitorialCreateAssignment",
"Naf::JanitorialDropAssignment"].include?(params[:type])
when "janitorial_archive_assignments"
@@ -79,14 +88,14 @@
link_to "Back to Historical Job",
controller: 'historical_jobs',
action: 'show',
id: params[:historical_job_id]
when "application_schedule_affinity_tabs"
- link_to "Back to Application",
- controller: 'applications',
+ link_to "Back to Application Schedule",
+ controller: 'application_schedules',
action: 'show',
- id: params[:application_id]
+ id: params[:application_schedule_id]
when "machine_affinity_slots"
link_to "Back to Machine",
controller: 'machines',
action: 'show',
id: params[:machine_id]
@@ -96,11 +105,12 @@
end
def naf_nested_resource_index?
["historical_job_affinity_tabs",
"application_schedule_affinity_tabs",
- "machine_affinity_slots"].include?(controller_name) and !params[:id]
+ "machine_affinity_slots",
+ "application_schedules"].include?(controller_name) and !params[:id]
end
def naf_table_title
if current_page?(naf.janitorial_archive_assignments_path)
"Janitorial Archive Assignment"
@@ -110,12 +120,10 @@
"Janitorial Drop Assignment"
elsif current_page?(main_app.naf_path)
"Jobs"
else
case controller_name
- when "application_schedule_affinity_tabs"
- Application.find(params[:application_id]).title + ", Affinity Tabs"
when "machine_affinity_slots"
machine = Machine.find(params[:machine_id])
name = machine.server_name
((name and name.length > 0) ? name : machine.server_address) + ", Affinity Slots"
else
@@ -157,10 +165,12 @@
link_to "Jobs", main_app.naf_path
when "loggers"
link_to "Loggers", naf.logger_styles_path
when "runners"
link_to "Runners", naf.machine_runners_path
+ when "scripts"
+ link_to "Scripts", naf.applications_path
when "janitorial_assignments"
link_to "Janitorial Assignments", naf.janitorial_archive_assignments_path
when "janitorial_archive_assignments"
link_to "Janitorial Archive Assignments", naf.janitorial_archive_assignments_path
when "janitorial_create_assignments"
@@ -171,13 +181,18 @@
link_to name.split('_').map(&:capitalize).join(' '), { controller: name, action: 'index'}
end
end
def naf_generate_create_link
- return "" if NAF_READ_ONLY_RESOURCES.include?(controller_name) or NAF_CREATE_BLOCKED_RESOURCES.include?(controller_name)
- return link_to "Add a Job", naf.new_historical_job_path, { class: 'add_job' } if naf_display_job_search_link?
- link_to "Create new #{naf_model_name}", { controller: controller_name, action: 'new' }
+ return '' if NAF_READ_ONLY_RESOURCES.include?(controller_name) ||
+ NAF_CREATE_BLOCKED_RESOURCES.include?(controller_name)
+
+ return link_to "Add a Job",
+ naf.new_historical_job_path,
+ { class: 'add_job' } if naf_display_job_search_link?
+
+ return link_to "Create new #{naf_model_name}", { controller: controller_name, action: 'new' }
end
def naf_display_job_search_link?
current_page?(naf.root_url) or current_page?(controller: 'historical_jobs', action: 'index')
end
@@ -192,22 +207,29 @@
attribute.to_s.split('_').map(&:capitalize).join(' ')
end
def naf_generate_edit_link
return "" if NAF_READ_ONLY_RESOURCES.include?(controller_name)
- link_to "Edit", { controller: controller_name, action: 'edit', id: params[:id] }, class: 'edit'
+ link_to "Edit",
+ { controller: controller_name, action: 'edit', id: params[:id] },
+ class: 'edit'
end
def naf_generate_back_link
- link_to "Back to #{naf_make_header(controller_name)}", { controller: controller_name, action: 'index' }, class: 'back'
+ link_to "Back to #{naf_make_header(controller_name)}",
+ { controller: controller_name, action: 'index' },
+ class: 'back'
end
def naf_generate_destroy_link
- return "" if NAF_READ_ONLY_RESOURCES.include?(controller_name) or NAF_DESTROY_BLOCKED_RESOURCES.include?(controller_name)
+ return '' if NAF_READ_ONLY_RESOURCES.include?(controller_name) ||
+ NAF_DESTROY_BLOCKED_RESOURCES.include?(controller_name)
+
case controller_name
when "application_schedule_affinity_tabs"
- link_to "Destroy", application_application_schedule_application_schedule_affinity_tab_url(@application, @application_schedule, @record),
+ link_to "Destroy",
+ application_schedule_application_schedule_affinity_tab_url(@application_schedule, @record),
{ confirm: "Are you sure you want to destroy this #{naf_model_name}?",
method: :delete,
class: 'destroy' }
when "machine_affinity_slots"
link_to "Destroy", machine_machine_affinity_slot_url(@machine, @record),
@@ -229,10 +251,13 @@
def naf_link_to_add_fields(name, f, association)
new_object = f.object.class.reflect_on_association(association).klass.new
fields = f.fields_for(association, new_object, child_index: "new_#{association}") do |builder|
render(association.to_s, f: builder)
end
- link_to_function(name, "add_fields(this, \"#{association}\", \"#{escape_javascript(fields)}\")", id: 'add_prerequisite')
+ link_to_function(
+ name,
+ "add_fields(this, \"#{association}\", \"#{escape_javascript(fields)}\")", id: 'add_prerequisite'
+ )
end
def add_color(status)
if status == 'Running'
'running'