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 Aug 13, 2019
1 parent 3829ad6 commit 07e1c8c
Show file tree
Hide file tree
Showing 61 changed files with 3,386 additions and 501 deletions.
37 changes: 0 additions & 37 deletions app/assets/stylesheets/foreman_tasks/application.css.scss
Expand Up @@ -12,43 +12,6 @@
*= require_tree .
*/

.spin {
-webkit-animation: spin 1s infinite linear;
-moz-animation: spin 1s infinite linear;
-o-animation: spin 1s infinite linear;
animation: spin 1s infinite linear;
-webkit-transform-origin: 50% 50%;
transform-origin: 50% 50%;
-ms-transform-origin: 50% 50%; /* IE 9 */
}

@-moz-keyframes spin {
from {
-moz-transform: rotate(0deg);
}
to {
-moz-transform: rotate(360deg);
}
}

@-webkit-keyframes spin {
from {
-webkit-transform: rotate(0deg);
}
to {
-webkit-transform: rotate(360deg);
}
}

@keyframes spin {
from {
transform: rotate(0deg);
}
to {
transform: rotate(360deg);
}
}

div.form-group div.trigger_fields {
margin-top: 15px;
}
Expand Down
14 changes: 9 additions & 5 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 Expand Up @@ -276,7 +280,7 @@ def resource_scope(_options = {})

def action_permission
case params[:action]
when 'bulk_search', 'summary'
when 'bulk_search', 'summary', 'details'
:view
when 'bulk_resume'
:edit
Expand Down
12 changes: 6 additions & 6 deletions app/controllers/foreman_tasks/tasks_controller.rb
Expand Up @@ -27,15 +27,15 @@ def sub_tasks

def cancel_step
task = find_dynflow_task
flash[:notice] = _('Trying to cancel step %s') % params[:step_id]
flash[:info] = _('Trying to cancel step %s') % params[:step_id]
ForemanTasks.dynflow.world.event(task.external_id, params[:step_id].to_i, ::Dynflow::Action::Cancellable::Cancel).wait
redirect_to foreman_tasks_task_path(task)
end

def cancel
task = find_dynflow_task
if task.cancel
flash[:notice] = _('Trying to cancel the task')
flash[:info] = _('Trying to cancel the task')
else
flash[:warning] = _('The task cannot be cancelled at the moment.')
end
Expand All @@ -45,7 +45,7 @@ def cancel
def abort
task = find_dynflow_task
if task.abort
flash[:notice] = _('Trying to abort the task')
flash[:info] = _('Trying to abort the task')
else
flash[:warning] = _('The task cannot be aborted at the moment.')
end
Expand All @@ -56,7 +56,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 All @@ -68,7 +68,7 @@ def unlock
if task.paused?
task.state = :stopped
task.save!
flash[:notice] = _('The task resources were unlocked.')
flash[:info] = _('The task resources were unlocked.')
else
flash[:warning] = _('The execution has to be paused.')
end
Expand All @@ -79,7 +79,7 @@ def force_unlock
task = find_dynflow_task
task.state = :stopped
task.save!
flash[:notice] = _('The task resources were unlocked with force.')
flash[:info] = _('The task resources were unlocked with force.')
redirect_back(:fallback_location => foreman_tasks_task_path(task))
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
30 changes: 30 additions & 0 deletions app/models/foreman_tasks/task/dynflow_task.rb
Expand Up @@ -99,6 +99,36 @@ def running_steps
execution_plan.try(:steps_in_state, :running, :suspended) || []
end

def input_output_failed_steps
failed_steps.map do |f|
begin
f_action = f.action(execution_plan)
{
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.input.pretty_inspect,
output: f_action.output.pretty_inspect
}
end
end
end

def input_output_running_steps
running_steps.map do |f|
begin
f_action = f.action(execution_plan)
{
action_class: f.action_class.name,
state: f.state,
input: f_action.input.pretty_inspect,
output: f_action.output.pretty_inspect,
cancellable: cancellable_action?(f_action)
}
end
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
18 changes: 18 additions & 0 deletions app/views/foreman_tasks/api/tasks/details.json.rabl
@@ -0,0 +1,18 @@
object @task if @task

extends 'foreman_tasks/api/tasks/show'

attributes :parent_task_id, :start_at, :start_before, :external_id
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) }
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 }) %>

0 comments on commit 07e1c8c

Please sign in to comment.