Verified Commit 48332249 authored by Tam Le's avatar Tam Le
Browse files

Refactor Assigns#show view

Showing with 25 additions and 22 deletions
+25 -22
......@@ -18,7 +18,7 @@ class AssignsController < ApplicationController
if @service_pack.available?
assign_to(@service_pack, @project)
flash[:notice] = "Service Pack #{@service_pack.name} successfully assigned to project #{@project.name}"
redirect_to action: :show and return
render 'show' and return
else
# already assigned for another project
# constraint need
......@@ -47,7 +47,6 @@ class AssignsController < ApplicationController
User.current.allowed_to?(:see_assigned_service_packs, @project) ||
(@can_assign = User.current.allowed_to?(:assign_service_packs, @project)) ||
(@can_unassign = User.current.allowed_to?(:unassign_service_packs, @project))
# binding.pry
if @assignment = @project.assigns.find_by(assigned: true)
if @assignment.service_pack.unavailable?
......@@ -59,10 +58,13 @@ class AssignsController < ApplicationController
# binding.pry
if @assignment.nil?
if @can_assign ||= User.current.allowed_to?(:assign_service_packs, @project)
@assignment = Assign.new
@assignables = ServicePack.availables
if @assignables.exists?
@assignment = Assign.new
render -'not_assigned_yet' and return
end
end
render -'not_assigned_yet'
render -'unassignable'
# binding.pry
else
@service_pack = @assignment.service_pack
......
<%= javascript_include_tag 'assigns.js', plugin: :openproject_service_packs if @can_assign ||= User.current.allowed_to?(:assign_service_packs, @project) %>
<%= javascript_include_tag 'assigns.js', plugin: :openproject_service_packs %>
<div id="sp-assign">
<h2>No Service Pack is assigned to this project.</h2>
<br/>
<% if @can_assign && @assignables.any? %>
<%= form_with model: @assignment, url: assigns_assign_path(@project), local: true, method: :post do |f| %>
Choose a Service Pack to apply:
<%= f.select :service_pack_id, {},{},{id: "select-sp"} do %>
<option selected>--Pick one Service Pack--</option>
<% @assignables.find_each do |assignable| %>
<%= content_tag(:option, assignable.name, value: assignable.id, data: {start: assignable.started_date.to_s, end: assignable.expired_date.to_s, cap: assignable.total_units, rem: assignable.remained_units}) %>
<% end %>
<% end %>
<br/>
<%= f.submit -'Assign a Service Pack', class: -'button -alt-highlight', id: 'sp-assign-button' %>
<h2>No Service Pack is assigned to this project.</h2>
<br/>
<%= form_with model: @assignment, url: assigns_assign_path(@project), local: true, method: :post do |f| %>
Choose a Service Pack to apply:
<%= f.select :service_pack_id, {},{},{id: "select-sp"} do %>
<option selected>--Pick one Service Pack--</option>
<% @assignables.find_each do |assignable| %>
<%= content_tag(:option, assignable.name, value: assignable.id, data: {start: assignable.started_date.to_s, end: assignable.expired_date.to_s, cap: assignable.total_units, rem: assignable.remained_units}) %>
<% end %>
<% else %>
<h3>No Service Pack can be assigned.</h3>
<% end %>
</div>
<div id="sp-content"><!-- todo: ajax --></div>
\ No newline at end of file
<br/>
<%= f.submit -'Assign a Service Pack', class: -'button -alt-highlight', id: 'sp-assign-button' %>
<% end %>
</div>
<div id="sp-content"></div>
\ No newline at end of file
<div id='sp-assign'>
<h2>No Service Pack is assigned to this project.</h2><br/>
<h3>No Service Pack can be assigned.</h3>
</div>
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment