mirror of
https://github.com/Fishwaldo/huginn.git
synced 2025-03-16 03:41:41 +00:00
Merge pull request #825 from cantino/dry_run_from_anywhere
Add "Dry Run" to the action menu
This commit is contained in:
commit
c4f67d7f68
4 changed files with 39 additions and 28 deletions
|
@ -33,3 +33,29 @@ class @Utils
|
|||
onHide?()
|
||||
body?(modal.querySelector('.modal-body'))
|
||||
$(modal).modal('show')
|
||||
|
||||
@handleDryRunButton: (button, data = $(button.form).serialize()) ->
|
||||
$(button).prop('disabled', true)
|
||||
$('body').css(cursor: 'progress')
|
||||
$.ajax type: 'POST', url: $(button).data('action-url'), dataType: 'json', data: data
|
||||
.always =>
|
||||
$('body').css(cursor: 'auto')
|
||||
.done (json) =>
|
||||
Utils.showDynamicModal """
|
||||
<h5>Log</h5>
|
||||
<pre class="agent-dry-run-log"></pre>
|
||||
<h5>Events</h5>
|
||||
<pre class="agent-dry-run-events"></pre>
|
||||
<h5>Memory</h5>
|
||||
<pre class="agent-dry-run-memory"></pre>
|
||||
""",
|
||||
body: (body) ->
|
||||
$(body).
|
||||
find('.agent-dry-run-log').text(json.log).end().
|
||||
find('.agent-dry-run-events').text(json.events).end().
|
||||
find('.agent-dry-run-memory').text(json.memory)
|
||||
title: 'Dry Run Results',
|
||||
onHide: -> $(button).prop('disabled', false)
|
||||
.fail (xhr, status, error) ->
|
||||
alert('Error: ' + error)
|
||||
$(button).prop('disabled', false)
|
||||
|
|
|
@ -142,31 +142,7 @@ class @AgentEditPage
|
|||
|
||||
invokeDryRun: (e) ->
|
||||
e.preventDefault()
|
||||
button = this
|
||||
$(button).prop('disabled', true)
|
||||
$('body').css(cursor: 'progress')
|
||||
$.ajax type: 'POST', url: $(button).data('action-url'), dataType: 'json', data: $(button.form).serialize()
|
||||
.always =>
|
||||
$("body").css(cursor: 'auto')
|
||||
.done (json) =>
|
||||
Utils.showDynamicModal """
|
||||
<h5>Log</h5>
|
||||
<pre class="agent-dry-run-log"></pre>
|
||||
<h5>Events</h5>
|
||||
<pre class="agent-dry-run-events"></pre>
|
||||
<h5>Memory</h5>
|
||||
<pre class="agent-dry-run-memory"></pre>
|
||||
""",
|
||||
body: (body) ->
|
||||
$(body).
|
||||
find('.agent-dry-run-log').text(json.log).end().
|
||||
find('.agent-dry-run-events').text(json.events).end().
|
||||
find('.agent-dry-run-memory').text(json.memory)
|
||||
title: 'Dry Run Results',
|
||||
onHide: -> $(button).prop('disabled', false)
|
||||
.fail (xhr, status, error) ->
|
||||
alert('Error: ' + error)
|
||||
$(button).prop('disabled', false)
|
||||
Utils.handleDryRunButton(this)
|
||||
|
||||
$ ->
|
||||
Utils.registerPage(AgentEditPage, forPathsMatching: /^agents/)
|
||||
|
|
|
@ -35,15 +35,18 @@ class AgentsController < ApplicationController
|
|||
end
|
||||
|
||||
def dry_run
|
||||
attrs = params[:agent]
|
||||
attrs = params[:agent] || {}
|
||||
if agent = current_user.agents.find_by(id: params[:id])
|
||||
# PUT /agents/:id/dry_run
|
||||
type = agent.type
|
||||
if attrs.present?
|
||||
type = agent.type
|
||||
agent = Agent.build_for_type(type, current_user, attrs)
|
||||
end
|
||||
else
|
||||
# POST /agents/dry_run
|
||||
type = attrs.delete(:type)
|
||||
agent = Agent.build_for_type(type, current_user, attrs)
|
||||
end
|
||||
agent = Agent.build_for_type(type, current_user, attrs)
|
||||
agent.name ||= '(Untitled)'
|
||||
|
||||
if agent.valid?
|
||||
|
|
|
@ -5,6 +5,12 @@
|
|||
</li>
|
||||
<% end %>
|
||||
|
||||
<% if agent.can_dry_run? %>
|
||||
<li>
|
||||
<%= link_to icon_tag('glyphicon-refresh') + ' Dry Run', '#', 'data-action-url' => dry_run_agent_path(agent), tabindex: "-1", onclick: "Utils.handleDryRunButton(this, '_method=PUT')" %>
|
||||
</li>
|
||||
<% end %>
|
||||
|
||||
<li>
|
||||
<%= link_to icon_tag('glyphicon-eye-open') + ' Show'.html_safe, agent_path(agent) %>
|
||||
</li>
|
||||
|
|
Loading…
Add table
Reference in a new issue