Merge pull request #512 from cantino/fix_schedule_reset

Fix schedule reset AKA refactor all the JavaScript!
This commit is contained in:
Andrew Cantino 2014-09-23 20:24:02 -07:00
commit 96e74ef02a
17 changed files with 372 additions and 330 deletions

View file

@ -0,0 +1,12 @@
#= require jquery
#= require jquery_ujs
#= require typeahead.bundle
#= require bootstrap
#= require select2
#= require json2
#= require jquery.json-editor
#= require latlon_and_geo
#= require spectrum
#= require_tree ./components
#= require_tree ./pages
#= require_self

View file

@ -1,226 +0,0 @@
#= require jquery
#= require jquery_ujs
#= require typeahead.bundle
#= require bootstrap
#= require select2
#= require json2
#= require jquery.json-editor
#= require latlon_and_geo
#= require spectrum
#= require ./worker-checker
#= require_self
window.setupJsonEditor = ($editors = $(".live-json-editor")) ->
JSONEditor.prototype.ADD_IMG = '<%= image_path 'json-editor/add.png' %>'
JSONEditor.prototype.DELETE_IMG = '<%= image_path 'json-editor/delete.png' %>'
editors = []
$editors.each ->
$editor = $(this)
jsonEditor = new JSONEditor($editor, $editor.data('width') || 400, $editor.data('height') || 500)
jsonEditor.doTruncation true
jsonEditor.showFunctionButtons()
editors.push jsonEditor
return editors
hideSchedule = ->
$(".schedule-region .can-be-scheduled").hide()
$(".schedule-region .cannot-be-scheduled").show()
showSchedule = (defaultSchedule = null) ->
if defaultSchedule?
$(".schedule-region select").val(defaultSchedule).change()
$(".schedule-region .can-be-scheduled").show()
$(".schedule-region .cannot-be-scheduled").hide()
hideLinks = ->
$(".link-region .select2-container").hide()
$(".link-region .propagate-immediately").hide()
$(".link-region .cannot-receive-events").show()
showLinks = ->
$(".link-region .select2-container").show()
$(".link-region .propagate-immediately").show()
$(".link-region .cannot-receive-events").hide()
showEventDescriptions()
hideControlLinks = ->
$(".control-link-region").hide()
showControlLinks = ->
$(".control-link-region").show()
hideEventCreation = ->
$(".event-related-region").hide()
showEventCreation = ->
$(".event-related-region").show()
showEventDescriptions = ->
if $("#agent_source_ids").val()
$.getJSON "/agents/event_descriptions", { ids: $("#agent_source_ids").val().join(",") }, (json) =>
if json.description_html?
$(".event-descriptions").show().html(json.description_html)
else
$(".event-descriptions").hide()
else
$(".event-descriptions").html("").hide()
$(document).ready ->
$('.navbar .dropdown.dropdown-hover').hover \
-> $(this).addClass('open'),
-> $(this).removeClass('open')
# JSON Editor
window.jsonEditor = setupJsonEditor()[0]
# Flash
if $(".flash").length
setTimeout((-> $(".flash").slideUp(-> $(".flash").remove())), 5000)
# Help popovers
$('.hover-help').popover(trigger: 'hover', html: true)
# Agent Navigation
$agentNavigate = $('#agent-navigate')
# initialize typeahead listener
$agentNavigate.bind "typeahead:selected", (event, object, name) ->
item = object['value']
$agentNavigate.typeahead('val', '')
if agentPaths[item]
$(".spinner").show()
navigationData = agentPaths[item]
if !(navigationData instanceof Object) || !navigationData.method || navigationData.method == 'GET'
window.location = navigationData.url || navigationData
else
$("<a href='#{navigationData.url}' data-method='#{navigationData.method}'></a>").appendTo($("body")).click()
# substring matcher for typeahead
substringMatcher = (strings)->
findMatches = (query, callback) ->
matches = []
substrRegex = new RegExp(query, "i")
$.each strings, (i, str) ->
matches.push value: str if substrRegex.test(str)
callback(matches.slice(0,6))
$agentNavigate.typeahead
minLength: 1,
highlight: true,
,
source: substringMatcher(agentNames)
# Pressing '/' selects the search box.
$("body").on "keypress", (e) ->
if e.keyCode == 47 # The '/' key
if e.target.nodeName == "BODY"
e.preventDefault()
$agentNavigate.focus()
# Agent Show
fetchLogs = (e) ->
agentId = $(e.target).closest("[data-agent-id]").data("agent-id")
e.preventDefault()
$("#logs .spinner").show()
$("#logs .refresh, #logs .clear").hide()
$.get "/agents/#{agentId}/logs", (html) =>
$("#logs .logs").html html
$("#logs .spinner").stop(true, true).fadeOut ->
$("#logs .refresh, #logs .clear").show()
clearLogs = (e) ->
if confirm("Are you sure you want to clear all logs for this Agent?")
agentId = $(e.target).closest("[data-agent-id]").data("agent-id")
e.preventDefault()
$("#logs .spinner").show()
$("#logs .refresh, #logs .clear").hide()
$.post "/agents/#{agentId}/logs/clear", { "_method": "DELETE" }, (html) =>
$("#logs .logs").html html
$("#show-tabs li a.recent-errors").removeClass 'recent-errors'
$("#logs .spinner").stop(true, true).fadeOut ->
$("#logs .refresh, #logs .clear").show()
$(".agent-show #show-tabs a[href='#logs'], #logs .refresh").on "click", fetchLogs
$(".agent-show #logs .clear").on "click", clearLogs
if tab = window.location.href.match(/tab=(\w+)\b/i)?[1]
if tab in ["details", "logs"]
$(".agent-show .nav-pills li a[href='##{tab}']").click()
# Editing Agents
$("#agent_source_ids").on "change", showEventDescriptions
$("#agent_type").on "change", ->
if window.jsonEditor?
$("#agent-spinner").fadeIn();
$("#agent_source_ids").select2("val", {});
$(".event-descriptions").html("").hide()
$.getJSON "/agents/type_details", { type: $(@).val() }, (json) =>
if json.can_be_scheduled
showSchedule(json.default_schedule)
else
hideSchedule()
if json.can_receive_events
showLinks()
else
hideLinks()
if json.can_control_other_agents
showControlLinks()
else
hideControlLinks()
if json.can_create_events
showEventCreation()
else
hideEventCreation()
$(".description").html(json.description_html) if json.description_html?
$('.oauthable-form').html(json.form) if json.form?
if $("#agent_options").hasClass("showing-default") || $("#agent_options").val().match(/\A\s*(\{\s*\}|)\s*\Z/g)
window.jsonEditor.json = json.options
window.jsonEditor.rebuild()
$("#agent-spinner").stop(true, true).fadeOut();
$("#agent_type").change() if $("#agent_type").length
# Select2 Selects
$(".select2").select2(width: 'resolve')
if $(".schedule-region")
if $(".schedule-region").data("can-be-scheduled") == true
showSchedule()
else
hideSchedule()
if $(".link-region")
if $(".link-region").data("can-receive-events") == true
showLinks()
else
hideLinks()
if $(".control-link-region")
if $(".control-link-region").data("can-control-other-agents") == true
showControlLinks()
else
hideControlLinks()
if $(".event-related-region")
if $(".event-related-region").data("can-create-events") == true
showEventCreation()
else
hideEventCreation()
$('.selectable-text').each ->
$(this).click ->
range = document.createRange()
range.setStartBefore(this.firstChild)
range.setEndAfter(this.lastChild)
sel = window.getSelection()
sel.removeAllRanges();
sel.addRange(range)

View file

@ -0,0 +1,30 @@
$ ->
# Flash
if $(".flash").length
setTimeout((-> $(".flash").slideUp(-> $(".flash").remove())), 5000)
# Help popovers
$('.hover-help').popover(trigger: 'hover', html: true)
# Pressing '/' selects the search box.
$("body").on "keypress", (e) ->
if e.keyCode == 47 # The '/' key
if e.target.nodeName == "BODY"
e.preventDefault()
$agentNavigate.focus()
# Select2 Selects
$(".select2").select2(width: 'resolve')
# Helper for selecting text when clicked
$('.selectable-text').each ->
$(this).click ->
range = document.createRange()
range.setStartBefore(this.firstChild)
range.setEndAfter(this.lastChild)
sel = window.getSelection()
sel.removeAllRanges();
sel.addRange(range)
# Agent navbar dropdown
$('.navbar .dropdown.dropdown-hover').hover (-> $(this).addClass('open')), (-> $(this).removeClass('open'))

View file

@ -0,0 +1,14 @@
window.setupJsonEditor = ($editors = $(".live-json-editor")) ->
JSONEditor.prototype.ADD_IMG = '<%= image_path 'json-editor/add.png' %>'
JSONEditor.prototype.DELETE_IMG = '<%= image_path 'json-editor/delete.png' %>'
editors = []
$editors.each ->
$editor = $(this)
jsonEditor = new JSONEditor($editor, $editor.data('width') || 400, $editor.data('height') || 500)
jsonEditor.doTruncation true
jsonEditor.showFunctionButtons()
editors.push jsonEditor
return editors
$ ->
window.jsonEditor = setupJsonEditor()[0]

View file

@ -0,0 +1,29 @@
$ ->
$agentNavigate = $('#agent-navigate')
# initialize typeahead listener
$agentNavigate.bind "typeahead:selected", (event, object, name) ->
item = object['value']
$agentNavigate.typeahead('val', '')
if window.agentPaths[item]
$(".spinner").show()
navigationData = window.agentPaths[item]
if !(navigationData instanceof Object) || !navigationData.method || navigationData.method == 'GET'
window.location = navigationData.url || navigationData
else
$("<a href='#{navigationData.url}' data-method='#{navigationData.method}'></a>").appendTo($("body")).click()
# substring matcher for typeahead
substringMatcher = (strings) ->
findMatches = (query, callback) ->
matches = []
substrRegex = new RegExp(query, "i")
$.each strings, (i, str) ->
matches.push value: str if substrRegex.test(str)
callback(matches.slice(0,6))
$agentNavigate.typeahead
minLength: 1,
highlight: true,
,
source: substringMatcher(window.agentNames)

View file

@ -0,0 +1,14 @@
class @Utils
@navigatePath: (path) ->
path = "/" + path unless path.match(/^\//)
window.location.href = path
@currentPath: ->
window.location.href.replace(/https?:\/\/.*?\//g, '')
@registerPage: (klass, options = {}) ->
if options.forPathsMatching?
if Utils.currentPath().match(options.forPathsMatching)
window.currentPage = new klass()
else
new klass()

View file

@ -1,3 +1,5 @@
# This is not included in the core application.js bundle.
$ ->
svg = document.querySelector('.agent-diagram svg.diagram')
overlay = document.querySelector('.agent-diagram .overlay')

View file

@ -2,6 +2,8 @@
#= require rickshaw
#= require_self
# This is not included in the core application.js bundle.
window.renderGraph = ($chart, data, peaks, name) ->
graph = new Rickshaw.Graph
element: $chart.find(".chart").get(0)

View file

@ -0,0 +1,126 @@
class @AgentEditPage
constructor: ->
$("#agent_source_ids").on "change", @showEventDescriptions
@showCorrectRegionsOnStartup()
# The type selector is only available on the new agent form.
if $("#agent_type").length
$("#agent_type").on "change", => @handleTypeChange(false)
@handleTypeChange(true)
handleTypeChange: (firstTime) ->
$(".event-descriptions").html("").hide()
type = $('#agent_type').val()
if type == 'Agent'
$(".agent-settings").hide()
$(".description").hide()
else
$(".agent-settings").show()
$("#agent-spinner").fadeIn()
$("#agent_source_ids").select2("val", {})
$(".model-errors").hide() unless firstTime
$.getJSON "/agents/type_details", { type: type }, (json) =>
if json.can_be_scheduled
if firstTime
@showSchedule()
else
@showSchedule(json.default_schedule)
else
@hideSchedule()
if json.can_receive_events
@showLinks()
else
@hideLinks()
if json.can_control_other_agents
@showControlLinks()
else
@hideControlLinks()
if json.can_create_events
@showEventCreation()
else
@hideEventCreation()
$(".description").show().html(json.description_html) if json.description_html?
$('.oauthable-form').html(json.form) if json.form?
unless firstTime
window.jsonEditor.json = json.options
window.jsonEditor.rebuild()
$("#agent-spinner").stop(true, true).fadeOut();
hideSchedule: ->
$(".schedule-region .can-be-scheduled").hide()
$(".schedule-region .cannot-be-scheduled").show()
showSchedule: (defaultSchedule = null) ->
if defaultSchedule?
$(".schedule-region select").val(defaultSchedule).change()
$(".schedule-region .can-be-scheduled").show()
$(".schedule-region .cannot-be-scheduled").hide()
hideLinks: ->
$(".link-region .select2-container").hide()
$(".link-region .propagate-immediately").hide()
$(".link-region .cannot-receive-events").show()
showLinks: ->
$(".link-region .select2-container").show()
$(".link-region .propagate-immediately").show()
$(".link-region .cannot-receive-events").hide()
@showEventDescriptions()
hideControlLinks: ->
$(".control-link-region").hide()
showControlLinks: ->
$(".control-link-region").show()
hideEventCreation: ->
$(".event-related-region").hide()
showEventCreation: ->
$(".event-related-region").show()
showEventDescriptions: ->
if $("#agent_source_ids").val()
$.getJSON "/agents/event_descriptions", { ids: $("#agent_source_ids").val().join(",") }, (json) =>
if json.description_html?
$(".event-descriptions").show().html(json.description_html)
else
$(".event-descriptions").hide()
else
$(".event-descriptions").html("").hide()
showCorrectRegionsOnStartup: ->
if $(".schedule-region")
if $(".schedule-region").data("can-be-scheduled") == true
@showSchedule()
else
@hideSchedule()
if $(".link-region")
if $(".link-region").data("can-receive-events") == true
@showLinks()
else
@hideLinks()
if $(".control-link-region")
if $(".control-link-region").data("can-control-other-agents") == true
@showControlLinks()
else
@hideControlLinks()
if $(".event-related-region")
if $(".event-related-region").data("can-create-events") == true
@showEventCreation()
else
@hideEventCreation()
$ ->
Utils.registerPage(AgentEditPage, forPathsMatching: /^agents/)

View file

@ -0,0 +1,35 @@
class @AgentShowPage
constructor: ->
$(".agent-show #show-tabs a[href='#logs'], #logs .refresh").on "click", @fetchLogs
$(".agent-show #logs .clear").on "click", @clearLogs
# Trigger tabs when navigated to.
if tab = window.location.href.match(/tab=(\w+)\b/i)?[1]
if tab in ["details", "logs"]
$(".agent-show .nav-pills li a[href='##{tab}']").click()
fetchLogs: (e) ->
agentId = $(e.target).closest("[data-agent-id]").data("agent-id")
e.preventDefault()
$("#logs .spinner").show()
$("#logs .refresh, #logs .clear").hide()
$.get "/agents/#{agentId}/logs", (html) =>
$("#logs .logs").html html
$("#logs .spinner").stop(true, true).fadeOut ->
$("#logs .refresh, #logs .clear").show()
clearLogs: (e) ->
if confirm("Are you sure you want to clear all logs for this Agent?")
agentId = $(e.target).closest("[data-agent-id]").data("agent-id")
e.preventDefault()
$("#logs .spinner").show()
$("#logs .refresh, #logs .clear").hide()
$.post "/agents/#{agentId}/logs/clear", { "_method": "DELETE" }, (html) =>
$("#logs .logs").html html
$("#show-tabs li a.recent-errors").removeClass 'recent-errors'
$("#logs .spinner").stop(true, true).fadeOut ->
$("#logs .refresh, #logs .clear").show()
$ ->
Utils.registerPage(AgentShowPage, forPathsMatching: /^agents\/\d+/)

View file

@ -3,6 +3,8 @@
#= require ace/mode-markdown.js
#= require_self
# This is not included in the core application.js bundle.
$ ->
editor = ace.edit("ace-credential-value")
editor.getSession().setTabSize(2)

View file

@ -43,7 +43,7 @@ class AgentsController < ApplicationController
:can_control_other_agents => @agent.can_control_other_agents?,
:options => @agent.default_options,
:description_html => @agent.html_description,
:form => render_to_string(partial: 'oauth_dropdown')
:form => render_to_string(partial: 'oauth_dropdown', locals: { agent: @agent })
}
end

View file

@ -1,6 +1,5 @@
module Agents
class AdiosoAgent < Agent
cannot_receive_events!
default_schedule "every_1d"

View file

@ -1,5 +1,5 @@
<% if @agent.errors.any? %>
<div class="row well">
<div class="row well model-errors">
<h2><%= pluralize(@agent.errors.count, "error") %> prohibited this Agent from being saved:</h2>
<% @agent.errors.full_messages.each do |msg| %>
<p class='text-warning'><%= msg %></p>
@ -21,99 +21,103 @@
<% if @agent.new_record? %>
<div class="form-group type-select">
<%= f.label :type %>
<%= f.select :type, options_for_select(Agent.types.map(&:to_s).sort.map {|type| [type.gsub(/^.*::/, ''), type] }, @agent.type), {}, :class => 'select2 form-control' %>
<%= f.select :type, options_for_select([['Select an Agent Type', 'Agent']] + Agent.types.map(&:to_s).sort.map {|type| [type.gsub(/^.*::/, ''), type] }, @agent.type), {}, :class => 'select2 form-control' %>
</div>
<% end %>
<div class="form-group type-select">
<%= f.label :name %>
<%= f.text_field :name, :class => 'form-control' %>
</div>
<div class='oauthable-form'>
<%= render partial: 'oauth_dropdown' %>
</div>
<div class="form-group">
<%= f.label :schedule, :class => 'control-label' %>
<div class="schedule-region" data-can-be-scheduled="<%= @agent.can_be_scheduled? %>">
<div class="can-be-scheduled">
<%= f.select :schedule, options_for_select(Agent::SCHEDULES.map {|s| [s.humanize.titleize, s] }, @agent.schedule), {}, :class => 'form-control' %>
</div>
<span class='cannot-be-scheduled text-info'>This type of Agent cannot be scheduled.</span>
</div>
</div>
<div class="controller-region" data-has-controllers="<%= !@agent.controllers.empty? %>">
<div class="form-group">
<%= f.label :controllers %>
<span class="glyphicon glyphicon-question-sign hover-help" data-content="Other than the system-defined schedule above, this agent may be run or controlled by these user-defined Agents."></span>
<div class="controller-list">
<%= agent_controllers(@agent) || 'None' %>
</div>
</div>
</div>
<div class="control-link-region" data-can-control-other-agents="<%= @agent.can_control_other_agents? %>">
<div class="can-control-other-agents">
<div class="form-group">
<%= f.label :control_targets %>
<% eventControlTargets = current_user.agents.select(&:can_be_scheduled?) %>
<%= f.select(:control_target_ids,
options_for_select(eventControlTargets.map {|s| [s.name, s.id] },
@agent.control_target_ids),
{}, { multiple: true, size: 5, class: 'select2 form-control' }) %>
</div>
</div>
</div>
<div class='event-related-region' data-can-create-events="<%= @agent.can_create_events? %>">
<div class="form-group">
<%= f.label :keep_events_for, "Keep events" %>
<span class="glyphicon glyphicon-question-sign hover-help" data-content="In order to conserve disk space, you can choose to have events created by this Agent expire after a certain period of time. Make sure you keep them long enough to allow any subsequent Agents to make use of them."></span>
<%= f.select :keep_events_for, options_for_select(Agent::EVENT_RETENTION_SCHEDULES, @agent.keep_events_for), {}, :class => 'form-control' %>
</div>
</div>
<div class="form-group">
<%= f.label :sources %>
<div class="link-region" data-can-receive-events="<%= @agent.can_receive_events? %>">
<% eventSources = (current_user.agents - [@agent]).find_all { |a| a.can_create_events? } %>
<%= f.select(:source_ids,
options_for_select(eventSources.map {|s| [s.name, s.id] },
@agent.source_ids),
{}, { :multiple => true, :size => 5, :class => 'select2 form-control' }) %>
<span class='cannot-receive-events text-info'>This type of Agent cannot receive events.</span>
<%= f.label :propagate_immediately, :class => 'propagate-immediately' do %>Propagate immediately
<%= f.check_box :propagate_immediately %>
<% end %>
</div>
</div>
<% if current_user.scenario_count > 0 %>
<div class="form-group">
<%= f.label :scenarios %>
<span class="glyphicon glyphicon-question-sign hover-help" data-content="Use Scenarios to group sets of Agents, both for organization, and to make them easy to export and share."></span>
<%= f.select(:scenario_ids,
options_for_select(current_user.scenarios.pluck(:name, :id), @agent.scenario_ids),
{}, { :multiple => true, :size => 5, :class => 'select2 form-control' }) %>
</div>
<% end %>
</div>
<!-- Form controls full width -->
<div class="col-md-12">
<div class="form-group">
<%= f.label :options %>
<span class="glyphicon glyphicon-question-sign hover-help" data-content="In this JSON hash, interpolation is available in almost all values using the Liquid templating language.<p>Available template variables include the following:<dl><dt><code>message</code>, <code>url</code>, etc.</dt><dd>Refers to the corresponding key's value of each incoming event's payload.</dd><dt><code>agent</code></dt><dd>Refers to the agent that created each incoming event. It has attributes like <code>type</code>, <code>name</code> and <code>options</code>, so <code>{{agent.type}}</code> will expand to <code>WebsiteAgent</code> if an incoming event is created by that agent.</dd></dl></p><p>To access user credentials, use the <code>credential</code> tag like this: <code>{% credential <em>bare_key_name</em> %}</code></p>"></span>
<textarea rows="15" id="agent_options" name="agent[options]" class="form-control live-json-editor <%= (@agent.new_record? && @agent.options == {}) ? "showing-default" : "" %>">
<%= Utils.jsonify((@agent.new_record? && @agent.options == {}) ? @agent.default_options : @agent.options) %>
</textarea>
<div class="agent-settings">
<div class="col-md-8">
<div class="form-group">
<%= f.label :name %>
<%= f.text_field :name, :class => 'form-control' %>
</div>
<div class='oauthable-form'>
<%= render partial: 'oauth_dropdown', locals: { agent: @agent } %>
</div>
<div class="form-group">
<%= f.label :schedule, :class => 'control-label' %>
<div class="schedule-region" data-can-be-scheduled="<%= @agent.can_be_scheduled? %>">
<div class="can-be-scheduled">
<%= f.select :schedule, options_for_select(Agent::SCHEDULES.map {|s| [s.humanize.titleize, s] }, @agent.schedule), {}, :class => 'form-control' %>
</div>
<span class='cannot-be-scheduled text-info'>This type of Agent cannot be scheduled.</span>
</div>
</div>
<div class="controller-region" data-has-controllers="<%= !@agent.controllers.empty? %>">
<div class="form-group">
<%= f.label :controllers %>
<span class="glyphicon glyphicon-question-sign hover-help" data-content="Other than the system-defined schedule above, this agent may be run or controlled by these user-defined Agents."></span>
<div class="controller-list">
<%= agent_controllers(@agent) || 'None' %>
</div>
</div>
</div>
<div class="control-link-region" data-can-control-other-agents="<%= @agent.can_control_other_agents? %>">
<div class="can-control-other-agents">
<div class="form-group">
<%= f.label :control_targets %>
<% eventControlTargets = current_user.agents.select(&:can_be_scheduled?) %>
<%= f.select(:control_target_ids,
options_for_select(eventControlTargets.map {|s| [s.name, s.id] },
@agent.control_target_ids),
{}, { multiple: true, size: 5, class: 'select2 form-control' }) %>
</div>
</div>
</div>
<div class='event-related-region' data-can-create-events="<%= @agent.can_create_events? %>">
<div class="form-group">
<%= f.label :keep_events_for, "Keep events" %>
<span class="glyphicon glyphicon-question-sign hover-help" data-content="In order to conserve disk space, you can choose to have events created by this Agent expire after a certain period of time. Make sure you keep them long enough to allow any subsequent Agents to make use of them."></span>
<%= f.select :keep_events_for, options_for_select(Agent::EVENT_RETENTION_SCHEDULES, @agent.keep_events_for), {}, :class => 'form-control' %>
</div>
</div>
<div class="form-group">
<%= f.label :sources %>
<div class="link-region" data-can-receive-events="<%= @agent.can_receive_events? %>">
<% eventSources = (current_user.agents - [@agent]).find_all { |a| a.can_create_events? } %>
<%= f.select(:source_ids,
options_for_select(eventSources.map {|s| [s.name, s.id] },
@agent.source_ids),
{}, { :multiple => true, :size => 5, :class => 'select2 form-control' }) %>
<span class='cannot-receive-events text-info'>This type of Agent cannot receive events.</span>
<%= f.label :propagate_immediately, :class => 'propagate-immediately' do %>Propagate immediately
<%= f.check_box :propagate_immediately %>
<% end %>
</div>
</div>
<% if current_user.scenario_count > 0 %>
<div class="form-group">
<%= f.label :scenarios %>
<span class="glyphicon glyphicon-question-sign hover-help" data-content="Use Scenarios to group sets of Agents, both for organization, and to make them easy to export and share."></span>
<%= f.select(:scenario_ids,
options_for_select(current_user.scenarios.pluck(:name, :id), @agent.scenario_ids),
{}, { :multiple => true, :size => 5, :class => 'select2 form-control' }) %>
</div>
<% end %>
</div>
<div class="form-group">
<%= f.submit "Save", :class => "btn btn-primary" %>
<!-- Form controls full width -->
<div class="col-md-12">
<div class="form-group">
<%= f.label :options %>
<span class="glyphicon glyphicon-question-sign hover-help" data-content="In this JSON hash, interpolation is available in almost all values using the Liquid templating language.<p>Available template variables include the following:<dl><dt><code>message</code>, <code>url</code>, etc.</dt><dd>Refers to the corresponding key's value of each incoming event's payload.</dd><dt><code>agent</code></dt><dd>Refers to the agent that created each incoming event. It has attributes like <code>type</code>, <code>name</code> and <code>options</code>, so <code>{{agent.type}}</code> will expand to <code>WebsiteAgent</code> if an incoming event is created by that agent.</dd></dl></p><p>To access user credentials, use the <code>credential</code> tag like this: <code>{% credential <em>bare_key_name</em> %}</code></p>"></span>
<textarea rows="15" id="agent_options" name="agent[options]" class="form-control live-json-editor">
<%= Utils.jsonify((@agent.new_record? && @agent.options == {}) ? @agent.default_options : @agent.options) %>
</textarea>
</div>
<div class="form-group">
<%= f.submit "Save", :class => "btn btn-primary" %>
</div>
</div>
</div>
</div>

View file

@ -1,6 +1,6 @@
<% if @agent.try(:oauthable?) %>
<% if agent.try(:oauthable?) %>
<div class="form-group type-select">
<%= label_tag :service %>
<%= select_tag 'agent[service_id]', options_for_select(@agent.valid_services_for(current_user).collect { |s| ["(#{s.provider}) #{s.name}", s.id]}, @agent.service_id), class: 'form-control' %>
<%= select_tag 'agent[service_id]', options_for_select(agent.valid_services_for(current_user).collect { |s| ["(#{s.provider}) #{s.name}", s.id]}, agent.service_id), class: 'form-control' %>
</div>
<% end %>

View file

@ -35,22 +35,21 @@
</div>
<script>
var agentPaths = {};
var agentNames = [];
window.agentPaths = {};
window.agentNames = [];
<% if current_user.present? -%>
var myAgents = <%= Utils.jsonify(current_user.agents.pluck(:name, :id).inject({}) {|m, a| m[a.first] = agent_path(a.last); m }) %>;
var myScenarios = <%= Utils.jsonify(current_user.scenarios.pluck(:name, :id).inject({}) {|m, s| m[s.first + " Scenario"] = scenario_path(s.last); m }) %>;
$.extend(agentPaths, myAgents);
$.extend(agentPaths, myScenarios);
agentPaths["All Agents Index"] = <%= Utils.jsonify agents_path %>;
agentPaths["New Agent"] = <%= Utils.jsonify new_agent_path %>;
agentPaths["Account"] = <%= Utils.jsonify edit_user_registration_path %>;
agentPaths["Events Index"] = <%= Utils.jsonify events_path %>;
agentPaths["View Agent Diagram"] = <%= Utils.jsonify diagram_path %>;
agentPaths["Run Event Propagation"] = { url: <%= Utils.jsonify propagate_agents_path %>, method: 'POST' };
$.extend(window.agentPaths, myAgents);
$.extend(window.agentPaths, myScenarios);
window.agentPaths["All Agents Index"] = <%= Utils.jsonify agents_path %>;
window.agentPaths["New Agent"] = <%= Utils.jsonify new_agent_path %>;
window.agentPaths["Account"] = <%= Utils.jsonify edit_user_registration_path %>;
window.agentPaths["Events Index"] = <%= Utils.jsonify events_path %>;
window.agentPaths["View Agent Diagram"] = <%= Utils.jsonify diagram_path %>;
window.agentPaths["Run Event Propagation"] = { url: <%= Utils.jsonify propagate_agents_path %>, method: 'POST' };
$.each(agentPaths, function(name, v) { agentNames.push(name); });
$.each(window.agentPaths, function(name, v) { window.agentNames.push(name); });
<% end -%>
</script>
</body>