Routes have been refactored
Dashboard routes have been refactored. Now instead of having resources for dashboard and routes inside a dashboard namespace the proposal routes contain a dashboar singleton containing everything related to it.
This commit is contained in:
42
app/controllers/dashboard/actions_controller.rb
Normal file
42
app/controllers/dashboard/actions_controller.rb
Normal file
@@ -0,0 +1,42 @@
|
||||
class Dashboard::ActionsController < Dashboard::BaseController
|
||||
helper_method :dashboard_action
|
||||
|
||||
def new_request
|
||||
authorize! :dashboard, proposal
|
||||
@dashboard_executed_action = Dashboard::ExecutedAction.new
|
||||
end
|
||||
|
||||
def create_request
|
||||
authorize! :dashboard, proposal
|
||||
|
||||
source_params = {
|
||||
proposal: proposal,
|
||||
action: dashboard_action,
|
||||
executed_at: Time.now
|
||||
}
|
||||
|
||||
@dashboard_executed_action = Dashboard::ExecutedAction.new(source_params)
|
||||
if @dashboard_executed_action.save
|
||||
Dashboard::AdministratorTask.create(source: @dashboard_executed_action)
|
||||
|
||||
redirect_to progress_proposal_dashboard_path(proposal.to_param), { flash: { info: t('dashboard.create_request.success') } }
|
||||
else
|
||||
flash.now[:alert] = @dashboard_executed_action.errors.full_messages.join('<br>')
|
||||
render :new_request
|
||||
end
|
||||
end
|
||||
|
||||
def execute
|
||||
authorize! :dashboard, proposal
|
||||
|
||||
Dashboard::ExecutedAction.create(proposal: proposal, action: dashboard_action, executed_at: Time.now)
|
||||
redirect_to progress_proposal_dashboard_path(proposal.to_param)
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def dashboard_action
|
||||
@dashboard_action ||= Dashboard::Action.find(params[:id])
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
class DashboardController < Dashboard::BaseController
|
||||
helper_method :dashboard_action, :active_resources, :course
|
||||
|
||||
def index
|
||||
def show
|
||||
authorize! :dashboard, proposal
|
||||
end
|
||||
|
||||
@@ -9,41 +9,9 @@ class DashboardController < Dashboard::BaseController
|
||||
authorize! :publish, proposal
|
||||
|
||||
proposal.publish
|
||||
redirect_to proposal_dashboard_index_path(proposal), notice: t('proposals.notice.published')
|
||||
redirect_to proposal_dashboard_path(proposal), notice: t('proposals.notice.published')
|
||||
end
|
||||
|
||||
def execute
|
||||
authorize! :dashboard, proposal
|
||||
|
||||
Dashboard::ExecutedAction.create(proposal: proposal, action: dashboard_action, executed_at: Time.now)
|
||||
redirect_to progress_proposal_dashboard_index_path(proposal.to_param)
|
||||
end
|
||||
|
||||
def new_request
|
||||
authorize! :dashboard, proposal
|
||||
@dashboard_executed_action = Dashboard::ExecutedAction.new
|
||||
end
|
||||
|
||||
def create_request
|
||||
authorize! :dashboard, proposal
|
||||
|
||||
source_params = {
|
||||
proposal: proposal,
|
||||
action: dashboard_action,
|
||||
executed_at: Time.now
|
||||
}
|
||||
|
||||
@dashboard_executed_action = Dashboard::ExecutedAction.new(source_params)
|
||||
if @dashboard_executed_action.save
|
||||
Dashboard::AdministratorTask.create(source: @dashboard_executed_action)
|
||||
|
||||
redirect_to progress_proposal_dashboard_index_path(proposal.to_param), { flash: { info: t('dashboard.create_request.success') } }
|
||||
else
|
||||
flash.now[:alert] = @dashboard_executed_action.errors.full_messages.join('<br>')
|
||||
render :new_request
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
def progress
|
||||
authorize! :dashboard, proposal
|
||||
end
|
||||
@@ -53,11 +21,7 @@ class DashboardController < Dashboard::BaseController
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def dashboard_action
|
||||
@dashboard_action ||= Dashboard::Action.find(params[:id])
|
||||
end
|
||||
|
||||
|
||||
def active_resources
|
||||
@active_resources ||= Dashboard::Action.active.resources.order(required_supports: :asc, day_offset: :asc)
|
||||
end
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
<% if dashboard_action.request_to_administrators && !dashboard_action.requested_for?(proposal) %>
|
||||
<%= form_for @dashboard_executed_action,
|
||||
url: create_request_proposal_dashboard_url(proposal, dashboard_action) do |f| %>
|
||||
url: create_request_proposal_dashboard_action_url(proposal, dashboard_action) do |f| %>
|
||||
<div class="actions">
|
||||
<%= f.submit(class: 'button', value: t("dashboard.form.request")) %>
|
||||
</div>
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
<ul id="proposal_dashboard_menu" data-multi-open="false">
|
||||
<li class="section-title">
|
||||
<%= link_to proposal_dashboard_index_path(proposal.to_param), class: my_proposal_menu_class do %>
|
||||
<%= link_to proposal_dashboard_path(proposal.to_param), class: my_proposal_menu_class do %>
|
||||
<i class="fi-lightbulb"></i>
|
||||
<strong><%= t("dashboard.menu.my_proposal") %></strong>
|
||||
<% end %>
|
||||
</li>
|
||||
|
||||
<li class="section-title">
|
||||
<%= link_to progress_proposal_dashboard_index_path(proposal.to_param),
|
||||
<%= link_to progress_proposal_dashboard_path(proposal.to_param),
|
||||
class: progress_menu_class do %>
|
||||
<span class="fi-graph-trend"></span>
|
||||
<strong><%= t("dashboard.menu.progress") %></strong>
|
||||
@@ -54,7 +54,7 @@
|
||||
|
||||
<% resources.each do |resource| %>
|
||||
<li <%= 'class=is-active' if is_request_active(resource.id) %>>
|
||||
<%= link_to new_request_proposal_dashboard_path(proposal, resource) do %>
|
||||
<%= link_to new_request_proposal_dashboard_action_path(proposal, resource) do %>
|
||||
<span data-tooltip title="<%= resource.short_description %>">
|
||||
<%= resource.title %>
|
||||
</span>
|
||||
@@ -66,7 +66,7 @@
|
||||
<% end %>
|
||||
|
||||
<li class="section-title">
|
||||
<%= link_to community_proposal_dashboard_index_path(proposal.to_param),
|
||||
<%= link_to community_proposal_dashboard_path(proposal.to_param),
|
||||
class: community_menu_class do %>
|
||||
<span class="fi-torsos-all"></span>
|
||||
<strong><%= t("dashboard.menu.community") %></strong>
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
<% if proposed_action.proposals.where(id: proposal.id).any? %>
|
||||
<i class="fi-check success"></i>
|
||||
<% else %>
|
||||
<%= link_to execute_proposal_dashboard_path(proposal, proposed_action), method: :post, id: "#{dom_id(proposed_action)}_execute" do %>
|
||||
<%= link_to execute_proposal_dashboard_action_path(proposal, proposed_action), method: :post, id: "#{dom_id(proposed_action)}_execute" do %>
|
||||
<div class="checkbox-unchecked">
|
||||
</div>
|
||||
<% end %>
|
||||
|
||||
@@ -22,7 +22,7 @@
|
||||
<% if resource.executed_for?(proposal) %>
|
||||
<div class="bottom-element text-center">
|
||||
<%= link_to t("dashboard.resource.view_resource"),
|
||||
new_request_proposal_dashboard_path(proposal, resource),
|
||||
new_request_proposal_dashboard_action_path(proposal, resource),
|
||||
class: 'button success' %>
|
||||
</div>
|
||||
<% elsif resource.requested_for?(proposal) %>
|
||||
@@ -30,7 +30,7 @@
|
||||
<% elsif resource.active_for?(proposal) %>
|
||||
<div class="bottom-element text-center">
|
||||
<%= link_to t("dashboard.resource.request_resource"),
|
||||
new_request_proposal_dashboard_path(proposal, resource),
|
||||
new_request_proposal_dashboard_action_path(proposal, resource),
|
||||
class: 'button primary' %>
|
||||
</div>
|
||||
<% else %>
|
||||
|
||||
@@ -5,13 +5,13 @@
|
||||
<div class="small-12 column">
|
||||
<div class="button-group">
|
||||
<%= link_to t("dashboard.progress.group_by_date"),
|
||||
progress_proposal_dashboard_index_path(proposal),
|
||||
progress_proposal_dashboard_path(proposal),
|
||||
class: "button #{daily_selected_class}" %>
|
||||
<%= link_to t("dashboard.progress.group_by_week"),
|
||||
progress_proposal_dashboard_index_path(proposal, group_by: 'week'),
|
||||
progress_proposal_dashboard_path(proposal, group_by: 'week'),
|
||||
class: "button #{weekly_selected_class}" %>
|
||||
<%= link_to t("dashboard.progress.group_by_month"),
|
||||
progress_proposal_dashboard_index_path(proposal, group_by: 'month'),
|
||||
progress_proposal_dashboard_path(proposal, group_by: 'month'),
|
||||
class: "button #{monthly_selected_class}" %>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -20,6 +20,6 @@
|
||||
<% end %>
|
||||
|
||||
<% if can?(:publish, proposal) %>
|
||||
<%= link_to t("dashboard.index.publish"), publish_proposal_dashboard_index_path(proposal), class: 'button success', method: :patch %>
|
||||
<%= link_to t("dashboard.index.publish"), publish_proposal_dashboard_path(proposal), class: 'button success', method: :patch %>
|
||||
<% end %>
|
||||
|
||||
@@ -33,7 +33,7 @@
|
||||
<div class="off-canvas position-left" id="offCanvas" data-off-canvas>
|
||||
<div class="show-for-small-only">
|
||||
<div class="dashboard-sidebar" data-equalizer-watch>
|
||||
<%= render partial: 'dashboard/menu' %>
|
||||
<%= render partial: "dashboard/menu" %>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@@ -50,14 +50,14 @@
|
||||
|
||||
<div id="side_menu" class="hide-for-small-only">
|
||||
<div class="dashboard-sidebar" data-equalizer-watch>
|
||||
<%= render partial: 'dashboard/menu' %>
|
||||
<%= render partial: "dashboard/menu" %>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="admin-content small-12 medium-9 column" data-equalizer-watch>
|
||||
<%= render partial: 'layouts/flash' %>
|
||||
<%= render partial: 'layouts/dashboard/proposal_totals' %>
|
||||
<%= render partial: 'layouts/dashboard/proposal_header' %>
|
||||
<%= render partial: "layouts/flash" %>
|
||||
<%= render partial: "layouts/dashboard/proposal_totals" %>
|
||||
<%= render partial: "layouts/dashboard/proposal_header" %>
|
||||
<%= yield %>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
|
||||
<%= raw t("proposals.created.motivation_html") %>
|
||||
|
||||
<%= link_to t("proposals.created.dashboard"), proposal_dashboard_index_path(@proposal), class: "button" if can?(:dashboard, @proposal) %>
|
||||
<%= link_to t("proposals.created.dashboard"), proposal_dashboard_path(@proposal), class: "button" if can?(:dashboard, @proposal) %>
|
||||
<%= link_to t("proposals.created.publish"), publish_proposal_path(@proposal), method: :patch, class: "button" if can?(:publish, @proposal) %>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -33,7 +33,7 @@
|
||||
<strong><%= t('.improve_it') %></strong>
|
||||
</p>
|
||||
<div class="centered">
|
||||
<%= link_to t('.dashboard'), proposal_dashboard_index_path(@proposal), class: 'button' %>
|
||||
<%= link_to t('.dashboard'), proposal_dashboard_path(@proposal), class: 'button' %>
|
||||
</div>
|
||||
</div>
|
||||
<% end %>
|
||||
|
||||
@@ -130,7 +130,7 @@
|
||||
<div class="sidebar-divider"></div>
|
||||
<h2><%= t("proposals.show.author") %></h2>
|
||||
<div class="show-actions-menu">
|
||||
<%= link_to proposal_dashboard_index_path(@proposal), class: 'button hollow expanded', id: "proposal-dashboard-#{@proposal.id}" do %>
|
||||
<%= link_to proposal_dashboard_path(@proposal), class: 'button hollow expanded', id: "proposal-dashboard-#{@proposal.id}" do %>
|
||||
<span class="icon-edit"></span>
|
||||
<%= t("proposals.show.dashboard_proposal_link") %>
|
||||
<% end %>
|
||||
|
||||
@@ -19,7 +19,7 @@
|
||||
<% elsif can?(:dashboard, proposal) %>
|
||||
<td>
|
||||
<%= link_to t("proposals.show.dashboard_proposal_link"),
|
||||
proposal_dashboard_index_path(proposal), class: 'button hollow expanded' %>
|
||||
proposal_dashboard_path(proposal), class: 'button hollow expanded' %>
|
||||
</td>
|
||||
<% else %>
|
||||
<td class="text-center">
|
||||
|
||||
@@ -1,28 +1,27 @@
|
||||
resources :proposals do
|
||||
resources :dashboard, only: [:index] do
|
||||
resource :dashboard, only: [:show], controller: 'dashboard' do
|
||||
collection do
|
||||
patch :publish
|
||||
get :progress
|
||||
get :community
|
||||
end
|
||||
|
||||
member do
|
||||
post :execute
|
||||
get :new_request
|
||||
post :create_request
|
||||
resources :resources, only: [:index], controller: 'dashboard/resources'
|
||||
resources :achievements, only: [:index], controller: 'dashboard/achievements'
|
||||
resources :successful_supports, only: [:index], controller: 'dashboard/successful_supports'
|
||||
resources :supports, only: [:index], controller: 'dashboard/supports'
|
||||
resources :polls, except: [:show, :destroy], controller: 'dashboard/polls'
|
||||
resources :mailing, only: [:index, :new, :create], controller: 'dashboard/mailing'
|
||||
resources :poster, only: [:index, :new], controller: 'dashboard/poster'
|
||||
resources :actions, only: [], controller: 'dashboard/actions' do
|
||||
member do
|
||||
post :execute
|
||||
get :new_request
|
||||
post :create_request
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
namespace :dashboard do
|
||||
resources :resources, only: [:index]
|
||||
resources :achievements, only: [:index]
|
||||
resources :successful_supports, only: [:index]
|
||||
resources :supports, only: [:index]
|
||||
resources :polls, except: [:show, :destroy]
|
||||
resources :mailing, only: [:index, :new, :create]
|
||||
resources :poster, only: [:index, :new]
|
||||
end
|
||||
|
||||
member do
|
||||
post :vote
|
||||
post :vote_featured
|
||||
|
||||
@@ -5,7 +5,7 @@ feature "Proposal's dashboard" do
|
||||
|
||||
before do
|
||||
login_as(proposal.author)
|
||||
visit proposal_dashboard_index_path(proposal)
|
||||
visit proposal_dashboard_path(proposal)
|
||||
end
|
||||
|
||||
scenario 'Dashboard has a link to my proposal' do
|
||||
@@ -33,7 +33,7 @@ feature "Proposal's dashboard" do
|
||||
goal = create(:dashboard_action, :resource, :active, required_supports: proposal.votes_for.size + 1_000)
|
||||
future_goal = create(:dashboard_action, :resource, :active, required_supports: proposal.votes_for.size + 2_000)
|
||||
|
||||
visit progress_proposal_dashboard_index_path(proposal)
|
||||
visit progress_proposal_dashboard_path(proposal)
|
||||
|
||||
within 'div#goals-section' do
|
||||
expect(page).to have_content(goal.title)
|
||||
@@ -49,7 +49,7 @@ feature "Proposal's dashboard" do
|
||||
scenario 'Dashboard progress show proposed actions' do
|
||||
action = create(:dashboard_action, :proposed_action, :active)
|
||||
|
||||
visit progress_proposal_dashboard_index_path(proposal)
|
||||
visit progress_proposal_dashboard_path(proposal)
|
||||
expect(page).to have_content(action.title)
|
||||
|
||||
find(:css, "#dashboard_action_#{action.id}_execute").click
|
||||
@@ -69,7 +69,7 @@ feature "Proposal's dashboard" do
|
||||
|
||||
unavailable = create(:dashboard_action, :resource, :active, required_supports: proposal.votes_for.size + 1_000)
|
||||
|
||||
visit progress_proposal_dashboard_index_path(proposal)
|
||||
visit progress_proposal_dashboard_path(proposal)
|
||||
within 'div#available-resources-section' do
|
||||
expect(page).to have_content('Polls')
|
||||
expect(page).to have_content('E-mail')
|
||||
@@ -112,14 +112,14 @@ feature "Proposal's dashboard" do
|
||||
scenario 'Dashboard has a link to resources on main menu' do
|
||||
feature = create(:dashboard_action, :resource, :active)
|
||||
|
||||
visit proposal_dashboard_index_path(proposal)
|
||||
visit proposal_dashboard_path(proposal)
|
||||
expect(page).to have_link(feature.title)
|
||||
end
|
||||
|
||||
scenario 'Request resource with admin request', js: true do
|
||||
feature = create(:dashboard_action, :resource, :active, :admin_request)
|
||||
|
||||
visit proposal_dashboard_index_path(proposal)
|
||||
visit proposal_dashboard_path(proposal)
|
||||
click_link(feature.title)
|
||||
|
||||
click_button 'Request'
|
||||
@@ -129,7 +129,7 @@ feature "Proposal's dashboard" do
|
||||
scenario 'Request already requested resource with admin request', js: true do
|
||||
feature = create(:dashboard_action, :resource, :active, :admin_request)
|
||||
|
||||
visit proposal_dashboard_index_path(proposal)
|
||||
visit proposal_dashboard_path(proposal)
|
||||
click_link(feature.title)
|
||||
|
||||
create(:dashboard_executed_action, action: feature, proposal: proposal)
|
||||
@@ -141,7 +141,7 @@ feature "Proposal's dashboard" do
|
||||
scenario 'Resource without admin request do not have a request link', js: true do
|
||||
feature = create(:dashboard_action, :resource, :active)
|
||||
|
||||
visit proposal_dashboard_index_path(proposal)
|
||||
visit proposal_dashboard_path(proposal)
|
||||
click_link(feature.title)
|
||||
|
||||
expect(page).not_to have_button('Request')
|
||||
|
||||
@@ -5,7 +5,7 @@ feature 'Polls' do
|
||||
|
||||
before do
|
||||
login_as(proposal.author)
|
||||
visit proposal_dashboard_index_path(proposal)
|
||||
visit proposal_dashboard_path(proposal)
|
||||
end
|
||||
|
||||
scenario 'Has a link to polls feature' do
|
||||
|
||||
Reference in New Issue
Block a user