Skip to content

Commit

Permalink
Fixed #239
Browse files Browse the repository at this point in the history
Proposals dashboard refactored to dashboard.
Added missing specs for the dashboard.
  • Loading branch information
jsperezg committed Jul 24, 2018
1 parent 0ea0a00 commit e5f9cf6
Show file tree
Hide file tree
Showing 82 changed files with 1,131 additions and 694 deletions.
6 changes: 3 additions & 3 deletions app/assets/stylesheets/proposal.scss
Original file line number Diff line number Diff line change
Expand Up @@ -284,10 +284,10 @@

i {
display: inline-block;
width: rem-calc(20);
height: rem-calc(20);
width: rem-calc(24);
height: rem-calc(24);
border-radius: rem-calc(10);
padding-right: rem-calc(4);
padding-right: rem-calc(5);
}
}

Expand Down
67 changes: 67 additions & 0 deletions app/controllers/admin/dashboard/actions_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
class Admin::Dashboard::ActionsController < Admin::Dashboard::BaseController
helper_method :dashboard_action, :resource

def index
@dashboard_actions = ::Dashboard::Action.order(required_supports: :asc)
end

def new
@dashboard_action = ::Dashboard::Action.new(
active: true,
day_offset: 0,
required_supports: 0,
request_to_administrators: true,
action_type: 'proposed_action'
)
end

def create
@dashboard_action = ::Dashboard::Action.new(dashboard_action_params)
if @dashboard_action.save
redirect_to admin_dashboard_actions_path, notice: t('admin.dashboard.actions.create.notice')
else
render :new
end
end

def edit; end

def update
if dashboard_action.update(dashboard_action_params)
redirect_to admin_dashboard_actions_path
else
render :edit
end
end

def destroy
if dashboard_action.destroy
flash[:notice] = t('admin.dashboard.actions.delete.success')
else
flash[:error] = dashboard_action.errors.full_messages.join(',')
end

redirect_to admin_dashboard_actions_path
end

private

def resource
@dashboard_action
end

def dashboard_action_params
params
.require(:dashboard_action)
.permit(
:title, :description, :short_description, :request_to_administrators, :day_offset,
:required_supports, :order, :active, :action_type,
documents_attributes: [:id, :title, :attachment, :cached_attachment, :user_id, :_destroy],
links_attributes: [:id, :label, :url, :open_in_new_tab, :_destroy]
)
end

def dashboard_action
@dashboard_action ||= ::Dashboard::Action.find(params[:id])
end
end
26 changes: 26 additions & 0 deletions app/controllers/admin/dashboard/administrator_tasks_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
class Admin::Dashboard::AdministratorTasksController < Admin::Dashboard::BaseController
helper_method :administrator_task

def index
authorize! :index, ::Dashboard::AdministratorTask
@administrator_tasks = ::Dashboard::AdministratorTask.pending
end

def edit
authorize! :edit, administrator_task
end

def update
authorize! :update, administrator_task

administrator_task.update(user: current_user, executed_at: Time.now)
redirect_to admin_dashboard_administrator_tasks_path,
{ flash: { notice: t("admin.dashboard.administrator_tasks.update.success") } }
end

private

def administrator_task
@administrator_task ||= ::Dashboard::AdministratorTask.find(params[:id])
end
end
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
class Admin::ProposalDashboard::BaseController < Admin::BaseController
class Admin::Dashboard::BaseController < Admin::BaseController
helper_method :namespace

private
Expand Down
67 changes: 0 additions & 67 deletions app/controllers/admin/proposal_dashboard/actions_controller.rb

This file was deleted.

This file was deleted.

8 changes: 4 additions & 4 deletions app/controllers/dashboard/base_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ class Dashboard::BaseController < ApplicationController
helper_method :proposal, :proposed_actions, :resource, :resources, :next_goal, :next_goal_supports, :next_goal_progress, :community_members_count

respond_to :html
layout 'proposals_dashboard'
layout 'dashboard'

private

Expand All @@ -13,11 +13,11 @@ def proposal
end

def proposed_actions
@proposed_actions ||= ProposalDashboardAction.proposed_actions.active_for(proposal).order(order: :asc)
@proposed_actions ||= Dashboard::Action.proposed_actions.active_for(proposal).order(order: :asc)
end

def resources
@resources ||= ProposalDashboardAction.resources.active_for(proposal).order(order: :asc)
@resources ||= Dashboard::Action.resources.active_for(proposal).order(order: :asc)
end

def next_goal_supports
Expand All @@ -35,6 +35,6 @@ def community_members_count
end

def next_goal
@next_goal ||= ProposalDashboardAction.next_goal_for(proposal)
@next_goal ||= Dashboard::Action.next_goal_for(proposal)
end
end
2 changes: 1 addition & 1 deletion app/controllers/dashboard/resources_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ class Dashboard::ResourcesController < Dashboard::BaseController
skip_authorization_check

def index
@resources = ProposalDashboardAction
@resources = Dashboard::Action
.active
.resources
.where('required_supports > 0')
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
class ProposalsDashboardController < Dashboard::BaseController
helper_method :proposal_dashboard_action, :active_resources, :course
class DashboardController < Dashboard::BaseController
helper_method :dashboard_action, :active_resources, :course

def index
authorize! :dashboard, proposal
Expand All @@ -15,31 +15,31 @@ def publish
def execute
authorize! :dashboard, proposal

ProposalExecutedDashboardAction.create(proposal: proposal, proposal_dashboard_action: proposal_dashboard_action, executed_at: Time.now)
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
@proposal_executed_dashboard_action = ProposalExecutedDashboardAction.new
@dashboard_executed_action = Dashboard::ExecutedAction.new
end

def create_request
authorize! :dashboard, proposal

source_params = {
proposal: proposal,
proposal_dashboard_action: proposal_dashboard_action,
action: dashboard_action,
executed_at: Time.now
}

@proposal_executed_dashboard_action = ProposalExecutedDashboardAction.new(source_params)
if @proposal_executed_dashboard_action.save
AdministratorTask.create(source: @proposal_executed_dashboard_action)
@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('.success') } }
else
flash.now[:alert] = @proposal_executed_dashboard_action.errors.full_messages.join('<br>')
flash.now[:alert] = @dashboard_executed_action.errors.full_messages.join('<br>')
render :new_request
end
end
Expand Down Expand Up @@ -69,15 +69,15 @@ def achievements

private

def proposal_dashboard_action
@proposal_dashboard_action ||= ProposalDashboardAction.find(params[:id])
def dashboard_action
@dashboard_action ||= Dashboard::Action.find(params[:id])
end

def active_resources
@active_resources ||= ProposalDashboardAction.active.resources.order(required_supports: :asc, day_offset: :asc)
@active_resources ||= Dashboard::Action.active.resources.order(required_supports: :asc, day_offset: :asc)
end

def course
@course ||= ProposalDashboardAction.course_for(proposal)
@course ||= Dashboard::Action.course_for(proposal)
end
end
4 changes: 2 additions & 2 deletions app/helpers/admin/proposal_dashboard_actions_helper.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module Admin::ProposalDashboardActionsHelper
def active_human_readable(active)
return t('admin.proposal_dashboard_actions.index.active') if active
t('admin.proposal_dashboard_actions.index.inactive')
return t('admin.dashboard.actions.index.active') if active
t('admin.dashboard.actions.index.inactive')
end
end
2 changes: 1 addition & 1 deletion app/helpers/admin_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def menu_homepage?
["homepage", "cards"].include?(controller_name)
end

def menu_proposals_dashboard?
def menu_dashboard?
["actions", "administrator_tasks"].include?(controller_name)
end

Expand Down
Loading

0 comments on commit e5f9cf6

Please sign in to comment.