Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
grosser committed Sep 11, 2018
1 parent 1747ef2 commit 3998059
Show file tree
Hide file tree
Showing 5 changed files with 209 additions and 261 deletions.
34 changes: 18 additions & 16 deletions app/controllers/mass_rollouts_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,30 +16,28 @@ def create
end

def deploy
stages_to_deploy = deploy_group.stages
stages_to_deploy = deploy_group.stages.to_a

case params[:status]
when ->(type) { type.blank? }
# no-op
case params[:status].presence
when nil # rubocop:disable Lint/EmptyWhen
# all
when 'successful'
stages_to_deploy.select!(&:last_successful_deploy)
when 'missing'
stages_to_deploy.reject!(&:last_successful_deploy)
else
return render status: :bad_request
return unsupported_option(:status)
end

if defined?(SamsonKubernetes::Engine)
case params[:type]
when ->(type) { type.blank? }
# no-op
when 'kubernetes'
stages_to_deploy.select!(&:kubernetes?)
when 'non_kubernetes'
stages_to_deploy.reject!(&:kubernetes?)
else
return render status: :bad_request
end
case params[:kubernetes].to_s.presence
when nil # rubocop:disable Lint/EmptyWhen
# all
when 'true'
stages_to_deploy.select!(&:kubernetes?)
when 'false'
stages_to_deploy.reject!(&:kubernetes?)
else
return unsupported_option(:kubernetes)
end

deploy_references = stages_to_deploy.map do |stage|
Expand Down Expand Up @@ -70,6 +68,10 @@ def destroy

private

def unsupported_option(option)
render status: :bad_request, plain: "Unsupported #{option}"
end

def create_all_stages
_, missing_stages = stages_for_creation
missing_stages.map do |template_stage|
Expand Down
61 changes: 61 additions & 0 deletions app/views/deploy_groups/_mass_rollout_form.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
<label class="col-lg-2 control-label">Mass Rollout</label>
<div class="col-lg-10">
<%= form_tag deploy_deploy_group_mass_rollouts_path(@deploy_group) do %>

<% if defined?(SamsonKubernetes::Engine) %>
<div class="form-group">
<div class="col-lg-10">
<label>Kubernetes</label>
<div class="form-group">
<div class="col-lg-4 radio">
<%= label_tag do %>
<%= radio_button_tag :kubernetes, '', :checked %>
All
<% end %>
</div>
<div class="col-lg-4 radio">
<%= label_tag do %>
<%= radio_button_tag :kubernetes, 'true' %>
Only Kubernetes
<% end %>
</div>

<div class="col-lg-4 radio">
<%= label_tag do %>
<%= radio_button_tag :kubernetes, 'false' %>
Only Non-Kubernetes
<% end %>
</div>
</div>
</div>
</div>
<% end %>

<div class="form-group">
<div class="col-lg-10">
<label>Stage Status Filter</label>
<div class="form-group">
<div class="col-lg-4 radio">
<%= label_tag do %>
<%= radio_button_tag :status, '', :checked %>
All
<% end %>
</div>
<div class="col-lg-4 radio">
<%= label_tag do %>
<%= radio_button_tag :status, 'successful' %>
Previously successful
<% end %>
</div>
<div class="col-lg-4 radio">
<%= label_tag do %>
<%= radio_button_tag :status, 'missing' %>
<abbr title="Any stages that haven't yet been deployed or have failed all their deploys">Missing</abbr>
<% end %>
</div>
</div>
</div>
</div>
<%= submit_tag "Start Deploys", class: "btn btn-default", data: { confirm: "Deploys will be started for all matching stages", disable_with: "Deploying..." } %>
<% end %>
</div>
25 changes: 25 additions & 0 deletions app/views/deploy_groups/_mass_stage_creation_form.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<label class="col-lg-2 control-label">Mass Stage Creation</label>
<div class="col-lg-10">
<%= link_to "Create Stages ...",
new_deploy_group_mass_rollouts_path(@deploy_group),
class: "btn btn-default"
%>
<% cloned_stage_count = @deploy_group.stages.cloned.count %>
<%= link_to "Merge #{cloned_stage_count} Cloned Stages",
merge_deploy_group_mass_rollouts_path(@deploy_group),
class: "btn btn-default #{ 'disabled' if cloned_stage_count.zero? }",
data: {
method: "post",
confirm: "Stages will be deleted. Before deleting, each stage will have its Deploy Group added to the stage it was copied from. Stages affected are those cloned from a template stage, have exactly this deploy group, and are on a project that uses include_new_deploy_groups.\n\n" \
"Merge #{@deploy_group.stages.cloned.count} cloned stages now?"
}
%>
<%= link_to "Delete #{cloned_stage_count} Cloned Stages",
deploy_group_mass_rollouts_path(@deploy_group),
class: "btn btn-default #{ 'disabled' if cloned_stage_count.zero? }",
data: {
method: "delete",
confirm: "Cloned stages will be deleted. No stages will be merged into their templates. You will need to create a new stage to deploy the project to this deploy group."
}
%>
</div>
89 changes: 2 additions & 87 deletions app/views/deploy_groups/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -74,95 +74,10 @@

<% if DeployGroup.enabled? %>
<div class="form-group" id="mass_stage_creation" style="display: none">
<label class="col-lg-2 control-label">Mass Stage Creation</label>
<div class="col-lg-10">
<%= link_to "Create Stages ...",
new_deploy_group_mass_rollouts_path(@deploy_group),
class: "btn btn-default"
%>
<% cloned_stage_count = @deploy_group.stages.cloned.count %>
<%= link_to "Merge #{cloned_stage_count} Cloned Stages",
merge_deploy_group_mass_rollouts_path(@deploy_group),
class: "btn btn-default #{ 'disabled' if cloned_stage_count.zero? }",
data: {
method: "post",
confirm: "Stages will be deleted. Before deleting, each stage will have its Deploy Group added to the stage it was copied from. Stages affected are those cloned from a template stage, have exactly this deploy group, and are on a project that uses include_new_deploy_groups.\n\n" \
"Merge #{@deploy_group.stages.cloned.count} cloned stages now?"
}
%>
<%= link_to "Delete #{cloned_stage_count} Cloned Stages",
deploy_group_mass_rollouts_path(@deploy_group),
class: "btn btn-default #{ 'disabled' if cloned_stage_count.zero? }",
data: {
method: "delete",
confirm: "Cloned stages will be deleted. No stages will be merged into their templates. You will need to create a new stage to deploy the project to this deploy group."
}
%>
</div>
<%= render 'mass_stage_creation_form' %>
</div>
<div class="form-group" id="mass_rollout" style="display: none">
<label class="col-lg-2 control-label">Mass Rollout</label>
<div class="col-lg-10">
<%= form_tag deploy_deploy_group_mass_rollouts_path(@deploy_group) do %>

<% if defined?(SamsonKubernetes::Engine) %>
<div class="form-group">
<div class="col-lg-10">
<label>Stage Type</label>

<div class="form-group">
<div class="col-lg-4 radio">
<%= label_tag do %>
<%= radio_button_tag :type, '', :checked %>
All
<% end %>
</div>
<div class="col-lg-4 radio">
<%= label_tag do %>
<%= radio_button_tag :type, 'kubernetes' %>
Kubernetes stages only
<% end %>
</div>

<div class="col-lg-4 radio">
<%= label_tag do %>
<%= radio_button_tag :type, 'non_kubernetes' %>
Non-Kubernetes stages only
<% end %>
</div>
</div>
</div>
</div>
<% end %>

<div class="form-group">
<div class="col-lg-10">
<label>Stage Status Filter</label>
<div class="form-group">
<div class="col-lg-4 radio">
<%= label_tag do %>
<%= radio_button_tag :status, '', :checked %>
All
<% end %>
</div>
<div class="col-lg-4 radio">
<%= label_tag do %>
<%= radio_button_tag :status, 'successful' %>
Previously successful stages only
<% end %>
</div>
<div class="col-lg-4 radio">
<%= label_tag do %>
<%= radio_button_tag :status, 'missing' %>
<abbr title="Any stages that haven't yet been deployed or have failed all their deploys">Missing</abbr> stages only
<% end %>
</div>
</div>
</div>
</div>
<%= submit_tag "Start Deploys", class: "btn btn-default", data: { confirm: "Deploys will be started for all matching stages", disable_with: "Deploying..." } %>
<% end %>
</div>
<%= render 'mass_rollout_form' %>
</div>
<% end %>

Expand Down
Loading

0 comments on commit 3998059

Please sign in to comment.