Browse Source

show description; allow updating of existing scenarios by URL

Andrew Cantino 10 năm trước cách đây
mục cha
commit
bdc5638755

+ 5 - 1
app/controllers/scenario_imports_controller.rb

@@ -1,12 +1,16 @@
 class ScenarioImportsController < ApplicationController
   def new
-    @scenario_import = ScenarioImport.new
+    @scenario_import = ScenarioImport.new(:url => params[:url])
   end
 
   def create
     @scenario_import = ScenarioImport.new(params[:scenario_import])
     @scenario_import.set_user(current_user)
 
+    if @scenario_import.will_request_local?(scenarios_url)
+      render :text => 'Sorry, you cannot import a Scenario by URL from your own Huginn server.' and return
+    end
+
     if @scenario_import.valid?
       if @scenario_import.do_import?
         @scenario_import.import!

+ 5 - 1
app/models/scenario_import.rb

@@ -11,8 +11,8 @@ class ScenarioImport
 
   attr_reader :user
 
-  before_validation :fetch_url
   before_validation :parse_file
+  before_validation :fetch_url
 
   validate :validate_presence_of_file_url_or_data
   validates_format_of :url, :with => URL_REGEX, :allow_nil => true, :allow_blank => true, :message => "appears to be invalid"
@@ -84,6 +84,10 @@ class ScenarioImport
     @scenario || @existing_scenario
   end
 
+  def will_request_local?(url_root)
+    data.blank? && file.blank? && url.present? && url.starts_with?(url_root)
+  end
+
   protected
 
   def parse_file

+ 10 - 3
app/views/scenarios/show.html.erb

@@ -5,6 +5,10 @@
         <h2><%= "Public" if @scenario.public? %> Scenario <span class='label label-info scenario'><%= @scenario.name %></span></h2>
       </div>
 
+      <% if @scenario.description.present? %>
+        <blockquote><%= @scenario.description %></blockquote>
+      <% end %>
+
       <%= render 'agents/table', :returnTo => scenario_path(@scenario) %>
 
       <br/>
@@ -12,9 +16,12 @@
       <div class="btn-group">
         <%= link_to '<span class="glyphicon glyphicon-chevron-left"></span> Back'.html_safe, scenarios_path, class: "btn btn-default" %>
         <%= link_to '<span class="glyphicon glyphicon-random"></span> View Diagram'.html_safe, diagram_agents_path(:scenario_id => @scenario.to_param), class: "btn btn-default" %>
-        <%= link_to '<span class="glyphicon glyphicon-edit"></span> Edit Scenario'.html_safe, edit_scenario_path(@scenario), class: "btn btn-default" %>
-        <%= link_to '<span class="glyphicon glyphicon-share-alt"></span> Share Scenario'.html_safe, share_scenario_path(@scenario), class: "btn btn-default" %>
-        <%= link_to '<span class="glyphicon glyphicon-trash"></span> Delete Scenario'.html_safe, scenario_path(@scenario), method: :delete, data: { confirm: "This will remove the '#{@scenario.name}' Scenerio from all Agents and delete it.  Are you sure?" }, class: "btn btn-default" %>
+        <%= link_to '<span class="glyphicon glyphicon-edit"></span> Edit'.html_safe, edit_scenario_path(@scenario), class: "btn btn-default" %>
+        <% if @scenario.source_url.present? %>
+          <%= link_to '<span class="glyphicon glyphicon-plus"></span> Update'.html_safe, new_scenario_imports_path(:url => @scenario.source_url), class: "btn btn-default" %>
+        <% end %>
+        <%= link_to '<span class="glyphicon glyphicon-share-alt"></span> Share'.html_safe, share_scenario_path(@scenario), class: "btn btn-default" %>
+        <%= link_to '<span class="glyphicon glyphicon-trash"></span> Delete'.html_safe, scenario_path(@scenario), method: :delete, data: { confirm: "This will remove the '#{@scenario.name}' Scenerio from all Agents and delete it.  Are you sure?" }, class: "btn btn-default" %>
       </div>
     </div>
   </div>