Skip to content

Commit

Permalink
Fixes #26349 - Create tasks details page in react
Browse files Browse the repository at this point in the history
  • Loading branch information
lzap authored and MariaAga committed Jul 1, 2019
1 parent b05f263 commit ffbd21f
Show file tree
Hide file tree
Showing 57 changed files with 3,302 additions and 456 deletions.
12 changes: 8 additions & 4 deletions app/controllers/foreman_tasks/api/tasks_controller.rb
Expand Up @@ -16,7 +16,7 @@ class TasksController < ::Api::V2::BaseController
class BadRequest < Apipie::ParamError
end

before_action :find_task, :only => [:show]
before_action :find_task, :only => [:show, :details]

api :GET, '/tasks/summary', 'Show task summary'
def summary
Expand All @@ -27,6 +27,10 @@ def summary
param :id, :identifier, desc: 'UUID of the task'
def show; end

api :GET, '/tasks/:id/details', 'Show task extended details'
param :id, :identifier, desc: 'UUID of the task'
def details; end

api :POST, '/tasks/bulk_search', 'List dynflow tasks for uuids'
param :searches, Array, :desc => 'List of uuids to fetch info about' do
param :search_id, String, :desc => <<-DESC
Expand Down Expand Up @@ -117,10 +121,10 @@ def bulk_resume
param :order, String, :desc => N_('How to order the sorted results (e.g. ASC for ascending)')
end
def index
scope = resource_scope.search_for(params[:search]).select('DISTINCT foreman_tasks_tasks.*')

total = resource_scope.count
subtotal = scope.count
subtotal = resource_scope.search_for(params[:search]).select('DISTINCT foreman_tasks_tasks.id').count

scope = resource_scope.search_for(params[:search]).select('DISTINCT foreman_tasks_tasks.*')

ordering_params = {
sort_by: params[:sort_by] || 'started_at',
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/foreman_tasks/tasks_controller.rb
Expand Up @@ -65,7 +65,7 @@ def resume
task = find_dynflow_task
if task.resumable?
ForemanTasks.dynflow.world.execute(task.execution_plan.id)
flash[:notice] = _('The execution was resumed.')
flash[:info] = _('The execution was resumed.')
else
flash[:warning] = _('The execution has to be resumable.')
end
Expand Down
14 changes: 14 additions & 0 deletions app/helpers/foreman_tasks/foreman_tasks_helper.rb
Expand Up @@ -25,6 +25,20 @@ def troubleshooting_info
ret.html_safe
end

def troubleshooting_info_text
return if @task.state != 'paused' || @task.main_action.nil?
helper = TroubleshootingHelpGenerator.new(@task.main_action)
helper.generate_text
end

def username_link_task(owner, username)
if owner.present? && username != User::ANONYMOUS_API_ADMIN && username != User::ANONYMOUS_ADMIN
link_to_if_authorized(username, hash_for_edit_user_path(owner))
else
username
end
end

def task_result_icon_class(task)
return 'task-status pficon-help' if task.state != 'stopped'

Expand Down
26 changes: 26 additions & 0 deletions app/models/foreman_tasks/task/dynflow_task.rb
Expand Up @@ -99,6 +99,32 @@ def running_steps
execution_plan.try(:steps_in_state, :running, :suspended) || []
end

def input_output_failed_steps
@failed_steps = failed_steps
@failed_steps.map do |f|
{
error: ({ exception_class: f.error.exception_class, message: f.error.message, backtrace: f.error.backtrace } if f.error),
action_class: f.action_class.name,
state: f.state,
input: f.action(execution_plan).input.pretty_inspect,
output: f.action(execution_plan).output.pretty_inspect
}.compact
end
end

def input_output_running_steps
@running_steps = running_steps
@running_steps.map do |f|
{
action_class: f.action_class.name,
state: f.state,
input: f.action(execution_plan).input.pretty_inspect,
output: f.action(execution_plan).output.pretty_inspect,
cancellable: cancellable_action?(f.action(execution_plan))
}
end
end

def humanized
{ action: get_humanized(:humanized_name),
input: get_humanized(:humanized_input),
Expand Down
4 changes: 4 additions & 0 deletions app/services/foreman_tasks/troubleshooting_help_generator.rb
Expand Up @@ -44,6 +44,10 @@ def generate_html
# rubocop:enable Rails/OutputSafety
end

def generate_text
(description + link_descriptions_html).join("\n")
end

def link_descriptions_html
links.map do |link|
link.description % { link: %(<a href="%{href}">%{title}</a>) % link.to_h }
Expand Down
19 changes: 19 additions & 0 deletions app/views/foreman_tasks/api/tasks/details.json.rabl
@@ -0,0 +1,19 @@
object @task if @task

extends 'foreman_tasks/api/tasks/show'

attributes :start_at
node(:action) { @task.action }
node(:execution_plan) { { state: @task.execution_plan.state, cancellable: @task.execution_plan.cancellable? } }
node(:failed_steps) { @task.input_output_failed_steps }
node(:running_steps) { @task.input_output_running_steps }
node(:help) { troubleshooting_info_text }
node(:has_sub_tasks) { @task.sub_tasks.any? }
node(:allowDangerousActions) { Setting['dynflow_allow_dangerous_actions'] }
node(:locks) do
@task.locks.map do |lock|
{ name: lock.name, exclusive: lock.exclusive, resource_type: lock.resource_type, resource_id: lock.resource_id }
end
end
node(:username_path) { username_link_task(@task.owner, @task.username) }
node(:parent_task_id) { @task.parent_task_id }
2 changes: 1 addition & 1 deletion app/views/foreman_tasks/layouts/react.html.erb
Expand Up @@ -9,4 +9,4 @@
<div id="foremanTasksReactRoot"></div>
<% end %>
<%= render file: "layouts/base" %>
<%= mount_react_component('ForemanTasks', '#foremanTasksReactRoot') %>
<%= mount_react_component('ForemanTasks', '#foremanTasksReactRoot',{ :flatten_data => true }) %>
195 changes: 0 additions & 195 deletions app/views/foreman_tasks/tasks/_details.html.erb

This file was deleted.

42 changes: 0 additions & 42 deletions app/views/foreman_tasks/tasks/_errors.html.erb

This file was deleted.

19 changes: 0 additions & 19 deletions app/views/foreman_tasks/tasks/_locks.html.erb

This file was deleted.

0 comments on commit ffbd21f

Please sign in to comment.