Move resource partial to a component
We're renaming it to ActiveResource in order to better differentiate it from the DefaultResource component.
This commit is contained in:
@@ -1,14 +1,12 @@
|
|||||||
<div id="<%= dom_id(resource) %>" class="small-12 medium-6 large-3 column end">
|
<div id="<%= dom_id(resource) %>" class="small-12 medium-6 large-3 column end">
|
||||||
<div class="resource-card <%= resource_card_class(resource, proposal) %>"
|
<div class="resource-card <%= resource_card_class %>"
|
||||||
data-equalizer-watch="resources"
|
data-equalizer-watch="resources"
|
||||||
title="<%= resource_tooltip(resource, proposal) %>">
|
title="<%= resource_tooltip %>">
|
||||||
<h4><%= resource.title %></h4>
|
<h4><%= resource.title %></h4>
|
||||||
<% if is_new_action_since_last_login?(resource, @new_actions_since_last_login) %>
|
<% if is_new_action_since_last_login?(resource, new_actions_since_last_login) %>
|
||||||
<span class="label"><%= t("dashboard.progress.new_action") %></span>
|
<span class="label"><%= t("dashboard.progress.new_action") %></span>
|
||||||
<% end %>
|
<% end %>
|
||||||
<p class="resource-description">
|
<p class="resource-description"><%= resource.short_description %></p>
|
||||||
<%= resource.short_description %>
|
|
||||||
</p>
|
|
||||||
|
|
||||||
<div class="small-12 column small-centered margin-top">
|
<div class="small-12 column small-centered margin-top">
|
||||||
<% if resource.executed_for?(proposal) || (!resource.request_to_administrators && resource.active_for?(proposal)) %>
|
<% if resource.executed_for?(proposal) || (!resource.request_to_administrators && resource.active_for?(proposal)) %>
|
||||||
@@ -22,9 +20,7 @@
|
|||||||
new_request_proposal_dashboard_action_path(proposal, resource),
|
new_request_proposal_dashboard_action_path(proposal, resource),
|
||||||
class: "button expanded" %>
|
class: "button expanded" %>
|
||||||
<% else %>
|
<% else %>
|
||||||
<strong>
|
<strong><%= resource_availability_label %></strong>
|
||||||
<%= resource_availability_label(resource) %>
|
|
||||||
</strong>
|
|
||||||
<% end %>
|
<% end %>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
37
app/components/dashboard/active_resource_component.rb
Normal file
37
app/components/dashboard/active_resource_component.rb
Normal file
@@ -0,0 +1,37 @@
|
|||||||
|
class Dashboard::ActiveResourceComponent < ApplicationComponent
|
||||||
|
attr_reader :resource, :proposal, :new_actions_since_last_login
|
||||||
|
use_helpers :is_new_action_since_last_login?
|
||||||
|
|
||||||
|
def initialize(resource, proposal, new_actions_since_last_login)
|
||||||
|
@resource = resource
|
||||||
|
@proposal = proposal
|
||||||
|
@new_actions_since_last_login = new_actions_since_last_login
|
||||||
|
end
|
||||||
|
|
||||||
|
def resource_card_class
|
||||||
|
return "alert" unless resource.active_for?(proposal)
|
||||||
|
return "success" if resource.executed_for?(proposal)
|
||||||
|
|
||||||
|
"primary"
|
||||||
|
end
|
||||||
|
|
||||||
|
def resource_tooltip
|
||||||
|
return t("dashboard.resource.resource_locked") unless resource.active_for?(proposal)
|
||||||
|
return t("dashboard.resource.view_resource") if resource.executed_for?(proposal)
|
||||||
|
return t("dashboard.resource.resource_requested") if resource.requested_for?(proposal)
|
||||||
|
|
||||||
|
t("dashboard.resource.request_resource")
|
||||||
|
end
|
||||||
|
|
||||||
|
def resource_availability_label
|
||||||
|
label = []
|
||||||
|
|
||||||
|
label << t("dashboard.resource.required_days",
|
||||||
|
days: resource.day_offset) if resource.day_offset > 0
|
||||||
|
label << t("dashboard.resource.required_supports",
|
||||||
|
supports: number_with_delimiter(resource.required_supports,
|
||||||
|
delimiter: ".")) if resource.required_supports > 0
|
||||||
|
|
||||||
|
safe_join label, h(" #{t("dashboard.resource.and")})") + tag(:br)
|
||||||
|
end
|
||||||
|
end
|
||||||
@@ -5,6 +5,8 @@
|
|||||||
<% default_resources.each do |resource| %>
|
<% default_resources.each do |resource| %>
|
||||||
<%= render Dashboard::DefaultResourceComponent.new(resource, proposal) %>
|
<%= render Dashboard::DefaultResourceComponent.new(resource, proposal) %>
|
||||||
<% end %>
|
<% end %>
|
||||||
<%= render partial: "resource", collection: active_resources %>
|
<% active_resources.each do |resource| %>
|
||||||
|
<%= render Dashboard::ActiveResourceComponent.new(resource, proposal, new_actions_since_last_login) %>
|
||||||
|
<% end %>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -1,9 +1,9 @@
|
|||||||
class Dashboard::ResourcesComponent < ApplicationComponent
|
class Dashboard::ResourcesComponent < ApplicationComponent
|
||||||
attr_reader :active_resources, :proposal
|
attr_reader :proposal, :new_actions_since_last_login
|
||||||
|
|
||||||
def initialize(active_resources, proposal)
|
def initialize(proposal, new_actions_since_last_login)
|
||||||
@active_resources = active_resources
|
|
||||||
@proposal = proposal
|
@proposal = proposal
|
||||||
|
@new_actions_since_last_login = new_actions_since_last_login
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
@@ -11,4 +11,11 @@ class Dashboard::ResourcesComponent < ApplicationComponent
|
|||||||
def default_resources
|
def default_resources
|
||||||
%w[polls mailing poster]
|
%w[polls mailing poster]
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def active_resources
|
||||||
|
@active_resources ||= Dashboard::Action.active
|
||||||
|
.resources
|
||||||
|
.by_proposal(proposal)
|
||||||
|
.order(required_supports: :asc, day_offset: :asc)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
class DashboardController < Dashboard::BaseController
|
class DashboardController < Dashboard::BaseController
|
||||||
helper_method :dashboard_action, :active_resources, :course
|
helper_method :dashboard_action, :course
|
||||||
before_action :set_done_and_pending_actions, only: [:recommended_actions, :progress]
|
before_action :set_done_and_pending_actions, only: [:recommended_actions, :progress]
|
||||||
before_action :authorize_dashboard, except: :publish
|
before_action :authorize_dashboard, except: :publish
|
||||||
|
|
||||||
@@ -30,13 +30,6 @@ class DashboardController < Dashboard::BaseController
|
|||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
def active_resources
|
|
||||||
@active_resources ||= Dashboard::Action.active
|
|
||||||
.resources
|
|
||||||
.by_proposal(proposal)
|
|
||||||
.order(required_supports: :asc, day_offset: :asc)
|
|
||||||
end
|
|
||||||
|
|
||||||
def course
|
def course
|
||||||
@course ||= Dashboard::Action.course_for(proposal)
|
@course ||= Dashboard::Action.course_for(proposal)
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -56,18 +56,6 @@ module ProposalsDashboardHelper
|
|||||||
controller_name == "dashboard" && action_name == "new_request" && dashboard_action&.id == id
|
controller_name == "dashboard" && action_name == "new_request" && dashboard_action&.id == id
|
||||||
end
|
end
|
||||||
|
|
||||||
def resource_availability_label(resource)
|
|
||||||
label = []
|
|
||||||
|
|
||||||
label << t("dashboard.resource.required_days",
|
|
||||||
days: resource.day_offset) if resource.day_offset > 0
|
|
||||||
label << t("dashboard.resource.required_supports",
|
|
||||||
supports: number_with_delimiter(resource.required_supports,
|
|
||||||
delimiter: ".")) if resource.required_supports > 0
|
|
||||||
|
|
||||||
safe_join label, h(" #{t("dashboard.resource.and")})") + tag(:br)
|
|
||||||
end
|
|
||||||
|
|
||||||
def daily_selected_class
|
def daily_selected_class
|
||||||
return nil if params[:group_by].blank?
|
return nil if params[:group_by].blank?
|
||||||
|
|
||||||
@@ -86,21 +74,6 @@ module ProposalsDashboardHelper
|
|||||||
"hollow"
|
"hollow"
|
||||||
end
|
end
|
||||||
|
|
||||||
def resource_card_class(resource, proposal)
|
|
||||||
return "alert" unless resource.active_for?(proposal)
|
|
||||||
return "success" if resource.executed_for?(proposal)
|
|
||||||
|
|
||||||
"primary"
|
|
||||||
end
|
|
||||||
|
|
||||||
def resource_tooltip(resource, proposal)
|
|
||||||
return t("dashboard.resource.resource_locked") unless resource.active_for?(proposal)
|
|
||||||
return t("dashboard.resource.view_resource") if resource.executed_for?(proposal)
|
|
||||||
return t("dashboard.resource.resource_requested") if resource.requested_for?(proposal)
|
|
||||||
|
|
||||||
t("dashboard.resource.request_resource")
|
|
||||||
end
|
|
||||||
|
|
||||||
def proposed_action_description(proposed_action)
|
def proposed_action_description(proposed_action)
|
||||||
sanitize proposed_action.description.truncate(200)
|
sanitize proposed_action.description.truncate(200)
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -38,4 +38,4 @@
|
|||||||
<%= render "summary_recommended_actions" %>
|
<%= render "summary_recommended_actions" %>
|
||||||
<% end %>
|
<% end %>
|
||||||
|
|
||||||
<%= render Dashboard::ResourcesComponent.new(active_resources, proposal) %>
|
<%= render Dashboard::ResourcesComponent.new(proposal, @new_actions_since_last_login) %>
|
||||||
|
|||||||
Reference in New Issue
Block a user