@@ -73,6 +73,7 @@ gem 'hirb' |
||
| 73 | 73 |
gem 'wirble' |
| 74 | 74 |
gem 'roadie-rails' |
| 75 | 75 |
gem 'acts_as_list' |
| 76 |
+gem 'deep_cloneable', '~> 2.1.1' |
|
| 76 | 77 |
|
| 77 | 78 |
group :development do |
| 78 | 79 |
gem "rename" |
@@ -73,6 +73,8 @@ GEM |
||
| 73 | 73 |
nokogiri (~> 1.5) |
| 74 | 74 |
rails (>= 3, < 5) |
| 75 | 75 |
database_cleaner (1.3.0) |
| 76 |
+ deep_cloneable (2.1.1) |
|
| 77 |
+ activerecord (>= 3.1.0, < 5.0.0) |
|
| 76 | 78 |
devise (3.2.4) |
| 77 | 79 |
bcrypt (~> 3.0) |
| 78 | 80 |
orm_adapter (~> 0.1) |
@@ -341,6 +343,7 @@ DEPENDENCIES |
||
| 341 | 343 |
coffee-rails (~> 4.0.0) |
| 342 | 344 |
cucumber-rails |
| 343 | 345 |
database_cleaner |
| 346 |
+ deep_cloneable (~> 2.1.1) |
|
| 344 | 347 |
devise |
| 345 | 348 |
devise-async |
| 346 | 349 |
devise_invitable (~> 1.3.4) |
@@ -6,7 +6,7 @@ class MissionEditor::AgentsController < ApplicationController |
||
| 6 | 6 |
# GET /mission_agents |
| 7 | 7 |
# GET /mission_agents.json |
| 8 | 8 |
def index |
| 9 |
- @mission_agents = MissionAgent.where(mission: @mission) |
|
| 9 |
+ @mission_agents = MissionAgent.where(mission: @mission).where("instance_source_id is NULL")
|
|
| 10 | 10 |
end |
| 11 | 11 |
|
| 12 | 12 |
# GET /mission_agents/1 |
@@ -26,6 +26,7 @@ class MissionsController < ApplicationController |
||
| 26 | 26 |
end |
| 27 | 27 |
|
| 28 | 28 |
def show_agents |
| 29 |
+ @agents = @mission.mission_agents.order('instance_source_id DESC')
|
|
| 29 | 30 |
end |
| 30 | 31 |
|
| 31 | 32 |
def show_agent_details |
@@ -90,12 +91,25 @@ class MissionsController < ApplicationController |
||
| 90 | 91 |
mission = Mission.friendly.find(params[:id]) |
| 91 | 92 |
agent = mission.mission_agents.friendly.find(params[:agent]) |
| 92 | 93 |
candidate = MissionCandidate.create!(user: current_user, mission_agent: agent, status: 1, mode: 'take_agent_role') |
| 93 |
- agent.user = current_user |
|
| 94 |
- if agent.save |
|
| 94 |
+ agents = [] |
|
| 95 |
+ if agent.instances > 1 |
|
| 96 |
+ new_agent = agent.deep_clone :include => [{:agent_steps => :step_validations}]
|
|
| 97 |
+ new_agent.user = current_user |
|
| 98 |
+ new_agent.instances = 1 |
|
| 99 |
+ new_agent.instance_source = agent |
|
| 100 |
+ agent.instances = agent.instances - 1 |
|
| 101 |
+ agents << agent |
|
| 102 |
+ agents << new_agent |
|
| 103 |
+ else |
|
| 104 |
+ agent.user = current_user |
|
| 105 |
+ new_agent = agent |
|
| 106 |
+ agents << new_agent |
|
| 107 |
+ end |
|
| 108 |
+ if agents.each { |agent| agent.save }
|
|
| 95 | 109 |
@analytics.track('Agent role selected')
|
| 96 |
- redirect_to mission_agent_details_path(mission, agent), notice: (t 'mission.take_agent_profile_confirmation') |
|
| 110 |
+ redirect_to mission_agent_details_path(mission, new_agent), notice: (t 'mission.take_agent_profile_confirmation') |
|
| 97 | 111 |
else |
| 98 |
- redirect_to mission_agent_details_path(mission, agent), alert: (t 'mission.take_agent_profile_error') |
|
| 112 |
+ redirect_to mission_agent_details_path(mission, new_agent), alert: (t 'mission.take_agent_profile_error') |
|
| 99 | 113 |
end |
| 100 | 114 |
else |
| 101 | 115 |
redirect_to new_user_session_path, notice: (t 'user.not_logged_in') |
@@ -6,6 +6,7 @@ class MissionAgent < ActiveRecord::Base |
||
| 6 | 6 |
|
| 7 | 7 |
belongs_to :mission |
| 8 | 8 |
belongs_to :user |
| 9 |
+ belongs_to :instance_source, :class_name => "MissionAgent", :foreign_key => "instance_source_id" |
|
| 9 | 10 |
|
| 10 | 11 |
has_many :agent_steps, -> { order("position ASC") }, :dependent => :destroy
|
| 11 | 12 |
has_many :mission_candidates, :dependent => :destroy |
@@ -13,6 +13,7 @@ |
||
| 13 | 13 |
<%= f.text_field :role, label: (t 'mission_editor.agents.role'), class: 'input-block-level' %> |
| 14 | 14 |
<% f.text_area :objective, label: (t 'mission_editor.agents.objective'), class: 'input-block-level', rows: 5 %> |
| 15 | 15 |
<%= f.text_area :briefing, label: (t 'mission_editor.mission_details.briefing'), class: 'input-block-level summernote', rows: 15, id: 'briefing_content' %> |
| 16 |
+ <%= f.number_field :instances, label: (t 'mission_editor.agents.instances'), placeholder: 1, class: 'span1' %> |
|
| 16 | 17 |
<% end %> |
| 17 | 18 |
<% end %> |
| 18 | 19 |
<% end %> |
@@ -13,12 +13,13 @@ |
||
| 13 | 13 |
<%= bootstrap_flash %> |
| 14 | 14 |
|
| 15 | 15 |
<%= content_tag(:ul, class: 'thumbnails mission-list') do %> |
| 16 |
- <% @mission.mission_agents.each do |agent| %> |
|
| 16 |
+ <% @agents.each do |agent| %> |
|
| 17 | 17 |
<% role = agent.role.to_s %> |
| 18 | 18 |
<%= content_tag(:li, class: 'span4 mission-agent-thumb', id: "agent-#{role.tr(' ', '-').tr('.', '')}".downcase) do %>
|
| 19 | 19 |
<% content_tag(:div, class: 'thumbnail') do %> |
| 20 | 20 |
<%= content_tag(:div, class: 'thumbnail-content agent-box-header') do%> |
| 21 |
- <%= content_tag(:h3, (link_to agent.role, mission_agent_details_path(@mission, agent))) %> |
|
| 21 |
+ <% agent_role = agent.role + (agent.instances > 1 ? " (#{agent.instances})" : "")%>
|
|
| 22 |
+ <%= content_tag(:h3, (link_to agent_role, mission_agent_details_path(@mission, agent))) %> |
|
| 22 | 23 |
<%= content_tag(:p, agent.objective, class: 'thumbnail-agent-description') %> |
| 23 | 24 |
<% end %> |
| 24 | 25 |
<% # Steps %> |
@@ -69,6 +69,7 @@ en: |
||
| 69 | 69 |
text_validation_description: 'Validation description' |
| 70 | 70 |
step_title: 'Step Title' |
| 71 | 71 |
add_validation: 'Add Validation' |
| 72 |
+ instances: "Instances" |
|
| 72 | 73 |
launch: |
| 73 | 74 |
before_launch: 'Before Launch Tips' |
| 74 | 75 |
before_launch_help: '<p>Check out this tips for some things to do before launching your mission.</p><ul><li>Review Your mission in the public view</li><li>Make sure you can deliver the rewards you promisse</li><li>Review agents and make sure everyone has steps with at least one validation</li></ul>' |
@@ -66,6 +66,7 @@ pt-BR: |
||
| 66 | 66 |
text_validation_description: 'Descreva a validação' |
| 67 | 67 |
step_title: 'Titulo do passo' |
| 68 | 68 |
add_validation: 'Adicionar Validação' |
| 69 |
+ instances: 'Instancias' |
|
| 69 | 70 |
launch: |
| 70 | 71 |
before_launch: 'Before Launch Tips' |
| 71 | 72 |
before_launch_help: '<p>Check out this tips for some things to do before launching your mission.</p><ul><li>Review Your mission in the public view</li><li>Make sure you can deliver the rewards you promisse</li><li>Review agents and make sure everyone has steps with at least one validation</li></ul>' |
@@ -0,0 +1,6 @@ |
||
| 1 |
+class AddInstancesToMissionAgent < ActiveRecord::Migration |
|
| 2 |
+ def change |
|
| 3 |
+ add_column :mission_agents, :instances, :integer |
|
| 4 |
+ add_reference :mission_agents, :instance_source, index: true |
|
| 5 |
+ end |
|
| 6 |
+end |
@@ -11,7 +11,7 @@ |
||
| 11 | 11 |
# |
| 12 | 12 |
# It's strongly recommended that you check this file into your version control system. |
| 13 | 13 |
|
| 14 |
-ActiveRecord::Schema.define(version: 20150420024128) do |
|
| 14 |
+ActiveRecord::Schema.define(version: 20150427031924) do |
|
| 15 | 15 |
|
| 16 | 16 |
# These are extensions that must be enabled in order to support this database |
| 17 | 17 |
enable_extension "plpgsql" |
@@ -124,9 +124,12 @@ ActiveRecord::Schema.define(version: 20150420024128) do |
||
| 124 | 124 |
t.datetime "updated_at" |
| 125 | 125 |
t.string "slug" |
| 126 | 126 |
t.integer "rewards_id" |
| 127 |
+ t.integer "instances" |
|
| 128 |
+ t.integer "instance_source_id" |
|
| 127 | 129 |
end |
| 128 | 130 |
|
| 129 | 131 |
add_index "mission_agents", ["agent_steps_id"], name: "index_mission_agents_on_agent_steps_id", using: :btree |
| 132 |
+ add_index "mission_agents", ["instance_source_id"], name: "index_mission_agents_on_instance_source_id", using: :btree |
|
| 130 | 133 |
add_index "mission_agents", ["mission_candidates_id"], name: "index_mission_agents_on_mission_candidates_id", using: :btree |
| 131 | 134 |
add_index "mission_agents", ["mission_id"], name: "index_mission_agents_on_mission_id", using: :btree |
| 132 | 135 |
add_index "mission_agents", ["rewards_id"], name: "index_mission_agents_on_rewards_id", using: :btree |