Implements #182
Implements 182. resources are shown as cards in dashboard progress view. Implements #182 Implements 182. resources are shown as cards in dashboard progress view.
This commit is contained in:
@@ -249,4 +249,49 @@
|
||||
.proposal-dashboard-action-links {
|
||||
margin-bottom: 15pt;
|
||||
}
|
||||
|
||||
.resource-card {
|
||||
min-height: 200pt;
|
||||
|
||||
.bottom-container {
|
||||
position: relative;
|
||||
padding-left: 0;
|
||||
padding-right: 0;
|
||||
|
||||
.bottom-element {
|
||||
position: absolute;
|
||||
bottom: 0;
|
||||
width: 100%;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.resource-card.success {
|
||||
background-color: #c5f6eb;
|
||||
|
||||
i {
|
||||
display: inline-block;
|
||||
width: 20pt;
|
||||
height: 20pt;
|
||||
color: #00cf96;
|
||||
border-radius: 10pt;
|
||||
border: 1pt solid #00cf96;
|
||||
padding-right: 4pt;
|
||||
}
|
||||
}
|
||||
|
||||
.resource-card.alert {
|
||||
background-color: #ffe5e8;
|
||||
|
||||
i {
|
||||
display: inline-block;
|
||||
width: 20pt;
|
||||
height: 20pt;
|
||||
color: #ff828b;
|
||||
border-radius: 10pt;
|
||||
border: 1pt solid #ff828b;
|
||||
padding-right: 4pt;
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,11 +13,11 @@ class Dashboard::BaseController < ApplicationController
|
||||
end
|
||||
|
||||
def proposed_actions
|
||||
@proposed_actions ||= ProposalDashboardAction.proposed_actions.active_for(proposal)
|
||||
@proposed_actions ||= ProposalDashboardAction.proposed_actions.active_for(proposal).order(order: :asc)
|
||||
end
|
||||
|
||||
def resources
|
||||
@resources ||= ProposalDashboardAction.resources.active_for(proposal)
|
||||
@resources ||= ProposalDashboardAction.resources.active_for(proposal).order(order: :asc)
|
||||
end
|
||||
|
||||
def next_goal_supports
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
class ProposalsDashboardController < Dashboard::BaseController
|
||||
helper_method :proposal_dashboard_action
|
||||
helper_method :proposal_dashboard_action, :active_resources
|
||||
|
||||
def index
|
||||
authorize! :dashboard, proposal
|
||||
@@ -54,8 +54,11 @@ class ProposalsDashboardController < Dashboard::BaseController
|
||||
|
||||
private
|
||||
|
||||
|
||||
def proposal_dashboard_action
|
||||
@proposal_dashboard_action ||= ProposalDashboardAction.find(params[:id])
|
||||
end
|
||||
|
||||
def active_resources
|
||||
ProposalDashboardAction.active.resources.order(required_supports: :asc, day_offset: :asc)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -61,4 +61,13 @@ module ProposalsDashboardHelper
|
||||
def is_request_active(id)
|
||||
controller_name == 'proposals_dashboard' && action_name == 'new_request' && proposal_dashboard_action&.id == id
|
||||
end
|
||||
|
||||
def resoure_availability_label(resource)
|
||||
label = []
|
||||
|
||||
label << t('.required_days', days: resource.day_offset) if resource.day_offset > 0
|
||||
label << t('.required_supports', supports: number_with_delimiter(resource.required_supports, delimiter: '.')) if resource.required_supports > 0
|
||||
|
||||
label.join(" #{t('.and')}<br>")
|
||||
end
|
||||
end
|
||||
|
||||
@@ -3,5 +3,4 @@ class Link < ActiveRecord::Base
|
||||
|
||||
validates :label, presence: true
|
||||
validates :url, presence: true
|
||||
validates :linkable, presence: true
|
||||
end
|
||||
|
||||
@@ -39,8 +39,6 @@ class ProposalDashboardAction < ActiveRecord::Base
|
||||
greater_than_or_equal_to: 0
|
||||
}
|
||||
|
||||
default_scope { order(order: :asc, title: :asc) }
|
||||
|
||||
scope :active, -> { where(active: true) }
|
||||
scope :inactive, -> { where(active: false) }
|
||||
scope :resources, -> { where(action_type: 1) }
|
||||
@@ -53,20 +51,19 @@ class ProposalDashboardAction < ActiveRecord::Base
|
||||
.where('day_offset <= ?', (Date.today - published_at).to_i)
|
||||
end
|
||||
|
||||
def self.next_goal_for(proposal)
|
||||
def active_for?(proposal)
|
||||
published_at = proposal.published_at&.to_date || Date.today
|
||||
|
||||
required_supports <= proposal.votes_for.size && day_offset <= (Date.today - published_at).to_i
|
||||
end
|
||||
|
||||
def self.next_goal_for(proposal)
|
||||
active
|
||||
.where(
|
||||
'(required_supports > ? or day_offset > ?)',
|
||||
proposal.votes_for.size,
|
||||
(Date.today - published_at).to_i)
|
||||
.where('required_supports > ?', proposal.votes_for.size)
|
||||
.order(required_supports: :asc)
|
||||
&.first
|
||||
end
|
||||
|
||||
default_scope { order(order: :asc, title: :asc) }
|
||||
|
||||
def request_to_administrators?
|
||||
request_to_administrators || false
|
||||
end
|
||||
|
||||
30
app/views/proposals_dashboard/_resource.html.erb
Normal file
30
app/views/proposals_dashboard/_resource.html.erb
Normal file
@@ -0,0 +1,30 @@
|
||||
<div class="column" id="<%= dom_id(resource) %>">
|
||||
<div class="card resource-card <%= resource.active_for?(proposal) ? 'success' : 'alert' %>">
|
||||
<div class="card-section">
|
||||
<p class="text-right">
|
||||
<% if resource.active_for?(proposal) %>
|
||||
<i class="fi-check"></i>
|
||||
<% else %>
|
||||
<i class="fi-lock"></i>
|
||||
<% end %>
|
||||
</p>
|
||||
<h4 class="text-center"><%= resource.title %></h4>
|
||||
<p class="text-center">
|
||||
<%= resource.short_description %>
|
||||
</p>
|
||||
</div>
|
||||
|
||||
<div class="card-section text-center bottom-container">
|
||||
<% if resource.active_for?(proposal) %>
|
||||
<div class="bottom-element text-center">
|
||||
<%= link_to t('.view_resource'), new_request_proposal_dashboard_path(proposal, resource), class: 'button success' %>
|
||||
</div>
|
||||
<% else %>
|
||||
<strong>
|
||||
<%== resoure_availability_label(resource) %>
|
||||
</strong>
|
||||
<% end %>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
10
app/views/proposals_dashboard/_resources.html.erb
Normal file
10
app/views/proposals_dashboard/_resources.html.erb
Normal file
@@ -0,0 +1,10 @@
|
||||
<% if active_resources.any? %>
|
||||
<div class="action-title">
|
||||
<h5><%= t('.available_resources') %></h5>
|
||||
<hr>
|
||||
</div>
|
||||
|
||||
<div class="row small-up-2 medium-up-3 large-up-4">
|
||||
<%= render partial: 'resource', collection: active_resources %>
|
||||
</div>
|
||||
<% end %>
|
||||
@@ -27,3 +27,5 @@
|
||||
<%= render partial: 'proposed_action', locals: { action: action } %>
|
||||
<% end %>
|
||||
</table>
|
||||
|
||||
<%= render 'resources' %>
|
||||
|
||||
@@ -532,6 +532,13 @@ en:
|
||||
send_notification: Send notification
|
||||
new_request:
|
||||
links: Links
|
||||
resources:
|
||||
available_resources: Available resources
|
||||
resource:
|
||||
required_days: "%{days} days required"
|
||||
required_supports: "%{supports} supports required"
|
||||
and: and
|
||||
view_resource: See resource
|
||||
dashboard:
|
||||
polls:
|
||||
index:
|
||||
|
||||
@@ -532,6 +532,13 @@ es:
|
||||
send_notification: Enviar notificación
|
||||
new_request:
|
||||
liks: Enlaces
|
||||
resources:
|
||||
available_resources: Recursos disponibles
|
||||
resource:
|
||||
required_days: "%{days} días necesarios"
|
||||
required_supports: "%{supports} apoyos necesarios"
|
||||
and: y
|
||||
view_resource: Ver recurso
|
||||
dashboard:
|
||||
polls:
|
||||
index:
|
||||
|
||||
Reference in New Issue
Block a user