mirror of
https://github.com/Fishwaldo/huginn.git
synced 2025-03-15 19:31:26 +00:00
Export/import scenario tag colors.
This commit is contained in:
parent
f55098fd6a
commit
8b8fdb5f56
6 changed files with 31 additions and 7 deletions
|
@ -45,6 +45,8 @@ class ScenariosController < ApplicationController
|
|||
@exporter = AgentsExporter.new(:name => @scenario.name,
|
||||
:description => @scenario.description,
|
||||
:guid => @scenario.guid,
|
||||
:tag_fg_color => @scenario.tag_fg_color,
|
||||
:tag_bg_color => @scenario.tag_bg_color,
|
||||
:source_url => @scenario.public? && export_scenario_url(@scenario),
|
||||
:agents => @scenario.agents)
|
||||
response.headers['Content-Disposition'] = 'attachment; filename="' + @exporter.filename + '"'
|
||||
|
|
|
@ -60,10 +60,14 @@ class ScenarioImport
|
|||
description = parsed_data['description']
|
||||
name = parsed_data['name']
|
||||
links = parsed_data['links']
|
||||
tag_fg_color = parsed_data['tag_fg_color']
|
||||
tag_bg_color = parsed_data['tag_bg_color']
|
||||
source_url = parsed_data['source_url'].presence || nil
|
||||
@scenario = user.scenarios.where(:guid => guid).first_or_initialize
|
||||
@scenario.update_attributes!(:name => name, :description => description,
|
||||
:source_url => source_url, :public => false)
|
||||
:source_url => source_url, :public => false,
|
||||
:tag_fg_color => tag_fg_color,
|
||||
:tag_bg_color => tag_bg_color)
|
||||
|
||||
unless options[:skip_agents]
|
||||
created_agents = agent_diffs.map do |agent_diff|
|
||||
|
|
|
@ -16,6 +16,8 @@ class AgentsExporter
|
|||
:description => options[:description].presence || 'No description provided',
|
||||
:source_url => options[:source_url],
|
||||
:guid => options[:guid],
|
||||
:tag_fg_color => options[:tag_fg_color],
|
||||
:tag_bg_color => options[:tag_bg_color],
|
||||
:exported_at => Time.now.utc.iso8601,
|
||||
:agents => agents.map { |agent| agent_as_json(agent) },
|
||||
:links => links
|
||||
|
@ -51,4 +53,4 @@ class AgentsExporter
|
|||
options[:propagate_immediately] = agent.propagate_immediately if agent.can_receive_events?
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -50,6 +50,8 @@ describe ScenariosController do
|
|||
assigns(:exporter).options[:description].should == scenarios(:bob_weather).description
|
||||
assigns(:exporter).options[:agents].should == scenarios(:bob_weather).agents
|
||||
assigns(:exporter).options[:guid].should == scenarios(:bob_weather).guid
|
||||
assigns(:exporter).options[:tag_fg_color].should == scenarios(:bob_weather).tag_fg_color
|
||||
assigns(:exporter).options[:tag_bg_color].should == scenarios(:bob_weather).tag_bg_color
|
||||
assigns(:exporter).options[:source_url].should be_falsey
|
||||
response.headers['Content-Disposition'].should == 'attachment; filename="bob-s-weather-alert-scenario.json"'
|
||||
response.headers['Content-Type'].should == 'application/json; charset=utf-8'
|
||||
|
|
|
@ -7,9 +7,13 @@ describe AgentsExporter do
|
|||
let(:name) { "My set of Agents" }
|
||||
let(:description) { "These Agents work together nicely!" }
|
||||
let(:guid) { "some-guid" }
|
||||
let(:tag_fg_color) { "#ffffff" }
|
||||
let(:tag_bg_color) { "#000000" }
|
||||
let(:source_url) { "http://yourhuginn.com/scenarios/2/export.json" }
|
||||
let(:agent_list) { [agents(:jane_weather_agent), agents(:jane_rain_notifier_agent)] }
|
||||
let(:exporter) { AgentsExporter.new(:agents => agent_list, :name => name, :description => description, :source_url => source_url, :guid => guid) }
|
||||
let(:exporter) { AgentsExporter.new(
|
||||
:agents => agent_list, :name => name, :description => description, :source_url => source_url,
|
||||
:guid => guid, :tag_fg_color => tag_fg_color, :tag_bg_color => tag_bg_color) }
|
||||
|
||||
it "outputs a structure containing name, description, the date, all agents & their links" do
|
||||
data = exporter.as_json
|
||||
|
@ -17,6 +21,8 @@ describe AgentsExporter do
|
|||
data[:description].should == description
|
||||
data[:source_url].should == source_url
|
||||
data[:guid].should == guid
|
||||
data[:tag_fg_color].should == tag_fg_color
|
||||
data[:tag_bg_color].should == tag_bg_color
|
||||
Time.parse(data[:exported_at]).should be_within(2).of(Time.now.utc)
|
||||
data[:links].should == [{ :source => 0, :receiver => 1 }]
|
||||
data[:agents].should == agent_list.map { |agent| exporter.agent_as_json(agent) }
|
||||
|
@ -58,4 +64,4 @@ describe AgentsExporter do
|
|||
AgentsExporter.new(:name => ",,").filename.should == "exported-agents.json"
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -3,6 +3,8 @@ require 'spec_helper'
|
|||
describe ScenarioImport do
|
||||
let(:user) { users(:bob) }
|
||||
let(:guid) { "somescenarioguid" }
|
||||
let(:tag_fg_color) { "#ffffff" }
|
||||
let(:tag_bg_color) { "#000000" }
|
||||
let(:description) { "This is a cool Huginn Scenario that does something useful!" }
|
||||
let(:name) { "A useful Scenario" }
|
||||
let(:source_url) { "http://example.com/scenarios/2/export.json" }
|
||||
|
@ -46,10 +48,12 @@ describe ScenarioImport do
|
|||
}
|
||||
end
|
||||
let(:valid_parsed_data) do
|
||||
{
|
||||
{
|
||||
:name => name,
|
||||
:description => description,
|
||||
:guid => guid,
|
||||
:tag_fg_color => tag_fg_color,
|
||||
:tag_bg_color => tag_bg_color,
|
||||
:source_url => source_url,
|
||||
:exported_at => 2.days.ago.utc.iso8601,
|
||||
:agents => [
|
||||
|
@ -142,7 +146,7 @@ describe ScenarioImport do
|
|||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
describe "#dangerous?" do
|
||||
it "returns false on most Agents" do
|
||||
ScenarioImport.new(:data => valid_data).should_not be_dangerous
|
||||
|
@ -171,6 +175,8 @@ describe ScenarioImport do
|
|||
scenario_import.scenario.name.should == name
|
||||
scenario_import.scenario.description.should == description
|
||||
scenario_import.scenario.guid.should == guid
|
||||
scenario_import.scenario.tag_fg_color.should == tag_fg_color
|
||||
scenario_import.scenario.tag_bg_color.should == tag_bg_color
|
||||
scenario_import.scenario.source_url.should == source_url
|
||||
scenario_import.scenario.public.should be_falsey
|
||||
end
|
||||
|
@ -269,6 +275,8 @@ describe ScenarioImport do
|
|||
|
||||
existing_scenario.reload
|
||||
existing_scenario.guid.should == guid
|
||||
existing_scenario.tag_fg_color.should == tag_fg_color
|
||||
existing_scenario.tag_bg_color.should == tag_bg_color
|
||||
existing_scenario.description.should == description
|
||||
existing_scenario.name.should == name
|
||||
existing_scenario.source_url.should == source_url
|
||||
|
@ -408,4 +416,4 @@ describe ScenarioImport do
|
|||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Add table
Reference in a new issue