_step_two.html.erb 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  1. <div class="row">
  2. <div class="col-md-12">
  3. <% if @scenario_import.dangerous? %>
  4. <div class="alert alert-danger">
  5. <span class='glyphicon glyphicon-warning-sign'></span>
  6. This Scenario contains one or more potentially dangerous Agents.
  7. These may be able to run local commands or execute code.
  8. Please be sure that you understand the Agent configurations before importing!
  9. </div>
  10. <% end %>
  11. <% if @scenario_import.existing_scenario.present? %>
  12. <div class="alert alert-warning">
  13. <span class='glyphicon glyphicon-warning-sign'></span>
  14. This Scenario already exists in your system. The import will update your existing
  15. <%= scenario_label(@scenario_import.existing_scenario) %> Scenario's title,
  16. description, and tag colors. Below you can customize how the individual agents get updated.
  17. </div>
  18. <% end %>
  19. <div class="page-header">
  20. <h2>
  21. <%= @scenario_import.parsed_data["name"] %>
  22. <span class='text-muted'>
  23. (<%= pluralize @scenario_import.parsed_data["agents"].length, "Agent" %>;
  24. exported <%= time_ago_in_words Time.parse(@scenario_import.parsed_data["exported_at"]) %> ago)
  25. </span>
  26. </h2>
  27. </div>
  28. <% if @scenario_import.parsed_data["description"].present? %>
  29. <blockquote><%= markdown(@scenario_import.parsed_data["description"]) %></blockquote>
  30. <% end %>
  31. </div>
  32. </div>
  33. <div class='agent-import-list'>
  34. <% @scenario_import.agent_diffs.each.with_index do |agent_diff, index| %>
  35. <div class='agent-import' data-index='<%= index %>'>
  36. <div class='row'>
  37. <div class='col-md-12'>
  38. <h3>
  39. <a href='#' data-toggle="modal" data-target="#agent_options_<%= index %>"><%= agent_diff.name.incoming %></a>
  40. <span class='text-muted'>
  41. (<%= agent_diff.type.incoming %><% " -- WARNING: this Agent's type has been changed. This import will likely fail!" if agent_diff.type.requires_merge? %>)
  42. </span>
  43. </h3>
  44. <% if agent_diff.agent_exists? %>
  45. <div class="instructions">
  46. This Agent exists in your Huginn system.
  47. <% if agent_diff.requires_merge? %>
  48. Here are the differences between the incoming version and the one you have now. For each field, please
  49. select which value you'd like to keep.
  50. <% else %>
  51. It's already up-to-date.
  52. <% end %>
  53. </div>
  54. <% end %>
  55. </div>
  56. </div>
  57. <div class="modal fade" id="agent_options_<%= index %>" tabindex="-1" role="dialog" aria-labelledby="modalLabel<%= index %>" aria-hidden="true">
  58. <div class="modal-dialog modal-lg">
  59. <div class="modal-content">
  60. <div class="modal-header">
  61. <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
  62. <h4 class="modal-title" id="modalLabel<%= index %>">Options for '<%= agent_diff.name.updated %>'</h4>
  63. </div>
  64. <div class="modal-body">
  65. <pre class='options'><%= Utils.pretty_jsonify agent_diff.options.incoming %></pre>
  66. </div>
  67. </div>
  68. </div>
  69. </div>
  70. <% agent_diff.each_field do |field, value, selection_options| %>
  71. <div class='row'>
  72. <div class='col-md-4'>
  73. <div class="form-group">
  74. <%= label_tag "scenario_import[merges][#{index}][#{field}]", field.titleize %>
  75. <% if selection_options.present? %>
  76. <div>
  77. Your current Agent's value is:
  78. <span class='current'><%= selection_options.find { |s| s.last.to_s == value.current.to_s }.first %></span>
  79. </div>
  80. <%= select_tag "scenario_import[merges][#{index}][#{field}]", options_for_select(selection_options, value.updated), :class => 'form-control' %>
  81. <% else %>
  82. <div>
  83. Your current Agent's value is: <span class='current'><%= value.current.to_s %></span>
  84. </div>
  85. <%= text_field_tag "scenario_import[merges][#{index}][#{field}]", value.updated, :class => 'form-control' %>
  86. <% end %>
  87. </div>
  88. </div>
  89. </div>
  90. <% end %>
  91. <div class='row'>
  92. <% if agent_diff.options.requires_merge? %>
  93. <div class='col-md-12'>
  94. <label>Options</label>
  95. </div>
  96. <div class='col-md-6'>
  97. <textarea name="scenario_import[merges][<%= index %>][options]" rows='15' class="form-control live-json-editor">
  98. <%= Utils.pretty_jsonify(agent_diff.options.updated) %>
  99. </textarea>
  100. </div>
  101. <div class='col-md-6'>
  102. <div>
  103. Your current options:
  104. </div>
  105. <pre class='options'><%= Utils.pretty_jsonify agent_diff.options.current %></pre>
  106. </div>
  107. <% end %>
  108. </div>
  109. <% if agent_diff.requires_service? %>
  110. <div class='row'>
  111. <div class='col-md-4'>
  112. <div class="form-group type-select">
  113. <%= label_tag "scenario_import[merges][#{index}][service_id]", 'Service' %>
  114. <%= select_tag "scenario_import[merges][#{index}][service_id]", options_for_select(agent_diff.agent_instance.valid_services_for(current_user).collect { |s| ["(#{s.provider}) #{s.name}", s.id]}, agent_diff.agent.try(:service_id)), class: 'form-control' %>
  115. </div>
  116. </div>
  117. </div>
  118. <% end %>
  119. </div>
  120. <% end %>
  121. </div>
  122. <div class='row'>
  123. <div class='col-md-12'>
  124. <div class="checkbox">
  125. <%= f.label :do_import do %>
  126. <%= f.check_box :do_import %> I confirm that I want to import these Agents.
  127. <% end %>
  128. </div>
  129. <div class='form-actions'>
  130. <%= f.submit "Finish Import", :class => "btn btn-primary" %>
  131. </div>
  132. </div>
  133. </div>
  134. <script>
  135. // $(function() {
  136. // $('.agent-import-list .options-toggle').on('click', function (e) {
  137. // e.preventDefault();
  138. // $(this).siblings('.options').slideToggle()
  139. // if ($(this).text() == "Show Options") {
  140. // $(this).text("Hide Options");
  141. // } else {
  142. // $(this).text("Show Options");
  143. // }
  144. // });
  145. // });
  146. </script>