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

Show count on highlighted resources #4456

Merged
merged 7 commits into from Nov 15, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Expand Up @@ -58,6 +58,9 @@ end
- **decidim-core**: Improve user groups form [\#4458](https://github.com/decidim/decidim/pull/4458)
- **decidim-surveys**: Extract surveys logic to decidim-forms [\#3877](https://github.com/decidim/decidim/pull/3877)
- **decidim-core**: Move Omniauth login buttons to before the signup/sign in forms to improve usability [\#4457](https://github.com/decidim/decidim/pull/4457)
- **decidim-accountability**: Show one highlighted resources block per component in process page [\#4456](https://github.com/decidim/decidim/pull/4456)
- **decidim-meetings**: Show one highlighted resources block per component in process page [\#4456](https://github.com/decidim/decidim/pull/4456)
- **decidim-proposals**: Show one highlighted resources block per component in process page [\#4456](https://github.com/decidim/decidim/pull/4456)

**Fixed**:

Expand Down
@@ -0,0 +1,3 @@
<% published_components.each do |component| %>
<%= cell "decidim/accountability/highlighted_results_for_component", component %>
<% end %>
@@ -0,0 +1,23 @@
# frozen_string_literal: true

require "cell/partial"

module Decidim
module Accountability
# This cell renders the highlighted results for a given participatory
# space. It is intended to be used in the `participatory_space_highlighted_elements`
# view hook.
class HighlightedResultsCell < Decidim::ViewModel
private

def published_components
Decidim::Component
.where(
participatory_space: model,
manifest_name: :accountability
)
.published
end
end
end
end
@@ -0,0 +1,21 @@
<section class="section row collapse highlighted_results">
<h4 class="section-heading">
<%= translated_attribute(model.name) %> <a href="<%= main_component_path(model) %>" class="text-small"><%= t("decidim.participatory_spaces.highlighted_results.see_all", count: results_count) %></a>
</h4>

<div class="row">
<div class="columns accountability">
<div class="card card--action card--list">
<% results_to_render.each do |result| %>
<%= render partial: "decidim/participatory_spaces/result.html", locals: { result: result } %>
<% end %>
</div>
</div>
</div>

<%= link_to(
t("decidim.participatory_spaces.highlighted_results.see_all", count: results_count),
main_component_path(model),
class: "button button--sc light secondary button--right"
) %>
</section>
@@ -0,0 +1,36 @@
# frozen_string_literal: true

require "cell/partial"

module Decidim
module Accountability
# This cell renders the highlighted results for a given component.
# It is intended to be used in the `participatory_space_highlighted_elements`
# view hook.
class HighlightedResultsForComponentCell < Decidim::ViewModel
include ActiveSupport::NumberHelper
include Decidim::Accountability::ApplicationHelper
include Decidim::ComponentPathHelper
include Decidim::LayoutHelper
include Cell::ViewModel::Partial

def show
render unless results_count.zero?
end

private

def results
@results ||= Decidim::Accountability::Result.where(component: model).order_randomly(rand * 2 - 1)
end

def results_to_render
@results_to_render ||= results.limit(4)
end

def results_count
@results_count ||= results.count
end
end
end
end

This file was deleted.

3 changes: 1 addition & 2 deletions decidim-accountability/config/locales/en.yml
Expand Up @@ -218,8 +218,7 @@ en:
results: Results
participatory_spaces:
highlighted_results:
results: Results
see_all_results: See all results
see_all: See all (%{count})
resource_links:
included_projects:
result_project: Projects included in this result
Expand Down
18 changes: 6 additions & 12 deletions decidim-accountability/lib/decidim/accountability/engine.rb
Expand Up @@ -25,18 +25,7 @@ class Engine < ::Rails::Engine

initializer "decidim_accountability.view_hooks" do
Decidim.view_hooks.register(:participatory_space_highlighted_elements, priority: Decidim::ViewHooks::LOW_PRIORITY) do |view_context|
published_components = Decidim::Component.where(participatory_space: view_context.current_participatory_space).published
results = Decidim::Accountability::Result.where(component: published_components).order_randomly(rand * 2 - 1).limit(4)

next unless results.any?

view_context.extend Decidim::Accountability::ApplicationHelper
view_context.render(
partial: "decidim/participatory_spaces/highlighted_results",
locals: {
results: results
}
)
view_context.cell("decidim/accountability/highlighted_results", view_context.current_participatory_space)
end

if defined? Decidim::ParticipatoryProcesses
Expand All @@ -57,6 +46,11 @@ class Engine < ::Rails::Engine
end
end

initializer "decidim_accountability.add_cells_view_paths" do
Cell::ViewModel.view_paths << File.expand_path("#{Decidim::Accountability::Engine.root}/app/cells")
Cell::ViewModel.view_paths << File.expand_path("#{Decidim::Accountability::Engine.root}/app/views")
end

initializer "decidim_accountability.register_metrics" do
Decidim.metrics_registry.register(
:results,
Expand Down
Expand Up @@ -21,6 +21,10 @@
letter-spacing: 0;
}
}

&.button--right{
float: right;
}
}

// Overwrite Foundation hover styles in hollow disabled buttons
Expand Down
@@ -0,0 +1,3 @@
<% published_components.each do |component| %>
<%= cell "decidim/meetings/highlighted_meetings_for_component", component %>
<% end %>
@@ -0,0 +1,25 @@
# frozen_string_literal: true

require "cell/partial"

module Decidim
module Meetings
# This cell renders the highlighted meetings for a given participatory
# space. It is intended to be used in the `participatory_space_highlighted_elements`
# view hook.
class HighlightedMeetingsCell < Decidim::ViewModel
include MeetingCellsHelper

private

def published_components
Decidim::Component
.where(
participatory_space: model,
manifest_name: :meetings
)
.published
end
end
end
end
@@ -0,0 +1,33 @@
<% if upcoming_meetings.any? %>
<div class="section row collapse upcoming_meetings">
<h4 class="section-heading">
<%= translated_attribute(model.name) %> - <%= t("decidim.participatory_spaces.highlighted_meetings.upcoming_meetings") %> <a href="<%= main_component_path(model) %>" class="text-small"><%= t("decidim.participatory_spaces.highlighted_meetings.see_all", count: meetings_count) %></a>
</h4>
<div class="card card--list">
<% upcoming_meetings.each do |meeting| %>
<%= card_for meeting, size: :list_item %>
<% end %>
</div>
<%= link_to(
t("decidim.participatory_spaces.highlighted_meetings.see_all", count: meetings_count),
main_component_path(model),
class: "button button--sc light secondary button--right"
) %>
</div>
<% elsif past_meetings.any? %>
<div class="section row collapse past_meetings">
<h4 class="section-heading">
<%= translated_attribute(model.name) %> - <%= t("decidim.participatory_spaces.highlighted_meetings.past_meetings") %> <a href="<%= main_component_path(model) %>" class="text-small"><%= t("decidim.participatory_spaces.highlighted_meetings.see_all", count: meetings_count) %></a>
</h4>
<div class="card card--list">
<% past_meetings.each do |meeting| %>
<%= card_for meeting, size: :list_item %>
<% end %>
</div>
<%= link_to(
t("decidim.participatory_spaces.highlighted_meetings.see_all", count: meetings_count),
main_component_path(model),
class: "button button--sc light secondary button--right"
) %>
</div>
<% end %>
@@ -0,0 +1,37 @@
# frozen_string_literal: true

require "cell/partial"

module Decidim
module Meetings
# This cell renders the highlighted meetings for a given component.
# It is intended to be used in the `participatory_space_highlighted_elements`
# view hook.
class HighlightedMeetingsForComponentCell < Decidim::ViewModel
include Decidim::ComponentPathHelper
include Decidim::CardHelper

def show
render unless meetings_count.zero?
end

private

def meetings
@meetings ||= Decidim::Meetings::Meeting.where(component: model)
end

def past_meetings
@past_meetings ||= meetings.past.order(end_time: :desc, start_time: :desc).limit(3)
end

def upcoming_meetings
@upcoming_meetings ||= meetings.upcoming.order(:start_time, :end_time).limit(3)
end

def meetings_count
@meetings_count ||= meetings.count
end
end
end
end

This file was deleted.

This file was deleted.

2 changes: 1 addition & 1 deletion decidim-meetings/config/locales/en.yml
Expand Up @@ -418,7 +418,7 @@ en:
participatory_spaces:
highlighted_meetings:
past_meetings: Past meetings
see_all_meetings: See all meetings
see_all: See all (%{count})
upcoming_meetings: Upcoming meetings
upcoming_meeting_for_card:
upcoming_meeting: Upcoming meeting
Expand Down
13 changes: 1 addition & 12 deletions decidim-meetings/lib/decidim/meetings/engine.rb
Expand Up @@ -34,18 +34,7 @@ class Engine < ::Rails::Engine

initializer "decidim_meetings.view_hooks" do
Decidim.view_hooks.register(:participatory_space_highlighted_elements, priority: Decidim::ViewHooks::HIGH_PRIORITY) do |view_context|
published_components = Decidim::Component.where(participatory_space: view_context.current_participatory_space).published
meetings = Decidim::Meetings::Meeting.where(component: published_components)

next unless meetings.any?

view_context.render(
partial: "decidim/participatory_spaces/highlighted_meetings",
locals: {
past_meetings: meetings.past.order(end_time: :desc, start_time: :desc).limit(3),
upcoming_meetings: meetings.upcoming.order(:start_time, :end_time).limit(3)
}
)
view_context.cell("decidim/meetings/highlighted_meetings", view_context.current_participatory_space)
end

if defined? Decidim::ParticipatoryProcesses
Expand Down
@@ -0,0 +1,3 @@
<% published_components.each do |component| %>
<%= cell "decidim/proposals/highlighted_proposals_for_component", component %>
<% end %>
@@ -0,0 +1,25 @@
# frozen_string_literal: true

require "cell/partial"

module Decidim
module Proposals
# This cell renders the highlighted proposals for a given participatory
# space. It is intended to be used in the `participatory_space_highlighted_elements`
# view hook.
class HighlightedProposalsCell < Decidim::ViewModel
include ProposalCellsHelper

private

def published_components
Decidim::Component
.where(
participatory_space: model,
manifest_name: :proposals
)
.published
end
end
end
end
@@ -0,0 +1,19 @@
<section class="section row collapse highlighted_proposals">
<h4 class="section-heading">
<%= translated_attribute(model.name) %> <a href="<%= main_component_path(model) %>" class="text-small"><%= t("decidim.participatory_spaces.highlighted_proposals.see_all", count: proposals_count) %></a>
</h4>

<%= cell(
"decidim/collapsible_list",
proposals_to_render,
cell_options: {},
list_class: "row small-up-1 medium-up-2 card-grid",
size: proposals_count
) %>

<%= link_to(
t("decidim.participatory_spaces.highlighted_proposals.see_all", count: proposals_count),
main_component_path(model),
class: "button button--sc light secondary button--right"
) %>
</section>