Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add form-assign-proposal-to-valuator to proposal page #24

Draft
wants to merge 12 commits into
base: release/0.26-stable
Choose a base branch
from
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ def create
Admin::AssignProposalsToValuator.call(@form) do
on(:ok) do |_proposal|
flash[:notice] = I18n.t("valuation_assignments.create.success", scope: "decidim.proposals.admin")
redirect_to EngineRouter.admin_proxy(current_component).root_path
redirect_to after_add_evaluator_url
end

on(:invalid) do
Expand Down Expand Up @@ -52,6 +52,12 @@ def destroy_params
def skip_manage_component_permission
true
end

def after_add_evaluator_url
return request.referer if request.referer.present? && request.referer.include?(:proposal_id.to_s)

request.referer
antopalidi marked this conversation as resolved.
Show resolved Hide resolved
end
end
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@
<div id="photos" class="gallery row">
<% proposal.photos.each do |photo| %>
<%= link_to photo.big_url, target: "_blank", rel: "noopener" do %>
<%= image_tag photo.thumbnail_url, class:"thumbnail", alt: strip_tags(translated_attribute(photo.title)) %>
<%= image_tag photo.thumbnail_url, class: "thumbnail", alt: strip_tags(translated_attribute(photo.title)) %>
<% end %>
<% end %>
</div>
Expand All @@ -138,44 +138,61 @@
</div>
</div>

<% if proposal.valuators.any? %>
<div class="card">
<div class="card-divider">
<h2 class="card-title">
<%= t ".valuators" %>
</h2>
</div>

<div class="card-section">
<div class="row column">
<strong><%= t ".assigned_valuators" %>:</strong>
<ul id="valuators">
<% proposal.valuation_assignments.each do |assignment| %>
<% presented_valuator = present(assignment.valuator) %>
<% if proposal.valuators.any? %>
<div class="row column">
<strong><%= t ".assigned_valuators" %>:</strong>
<ul id="valuators">
<% proposal.valuation_assignments.each do |assignment| %>
<% presented_valuator = present(assignment.valuator) %>
<li>
<%= link_to(
presented_valuator.name,
presented_valuator.profile_path,
target: :blank
) %>
presented_valuator.name,
presented_valuator.profile_path,
target: :blank
) %>

<% if allowed_to? :unassign_from_valuator, :proposals, valuator: assignment.valuator %>
<%= icon_link_to(
"circle-x",
proposal_valuation_assignment_path(proposal, assignment.valuator_role),
t(".remove_assignment"),
method: :delete,
data: { confirm: t(".remove_assignment_confirmation") },
class: "red-icon"
) %>
"circle-x",
proposal_valuation_assignment_path(proposal, assignment.valuator_role),
t(".remove_assignment"),
method: :delete,
data: { confirm: t(".remove_assignment_confirmation") },
class: "red-icon"
) %>
<% end %>
</li>
<% end %>
</ul>
</div>
<% end %>
<% if allowed_to? :assign_to_valuator, :proposals %>
<div id="js-assign-proposal-to-valuator-actions" class="js-bulk-action-form form-single-proposal"
style="max-width:400px">
<%= form_tag(valuation_assignment_path, method: :post, id: "js-form-assign-proposal-to-valuator",
class: "flex--lc flex-gap--1") do %>
<div class="checkboxes hide">
<%= check_box_tag "proposal_ids[]", proposal.id, true,
class: "js-check-all-proposal js-proposal-id-#{proposal.id}" %>
</div>

<%= bulk_valuators_select(current_participatory_space, t("decidim.proposals.admin.proposals.index.assign_to_valuator")) %>

<%= submit_tag(t("decidim.proposals.admin.proposals.index.assign_to_valuator_button"),
id: "js-submit-assign-proposal-to-valuator",
class: "button small button--simple float-left") %>
<% end %>
</ul>
</div>
</div>
<% end %>
</div>
</div>
<% end %>

<% if allowed_to?(:create, :proposal_note, proposal: proposal) %>
<%= render "decidim/proposals/admin/proposal_notes/proposal_notes" %>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,4 +147,26 @@
expect(page).to have_no_selector("#valuators")
end
end

context "when assigning valuators to proposal from the proposal show page" do
let(:unassigned_proposal) { proposal }

before do
visit current_path

find("a", text: translated(proposal.title)).click
end

it "stay in the same url and add valuator user to list after assignment evaluator" do
within "#js-form-assign-proposal-to-valuator" do
find("#valuator_role_id").click
find("option", text: valuator.name).click
end

click_button "Assign"

expect(current_url).to end_with(current_path)
expect(page).to have_selector(".red-icon")
antopalidi marked this conversation as resolved.
Show resolved Hide resolved
end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -113,5 +113,9 @@
end
expect(page).to have_content("successfully")
end

it "don't have assign button" do
expect(page).not_to have_selector("button#js-submit-assign-proposal-to-valuator")
end
end
end