Skip to content

Commit

Permalink
List groups on user profile (#4236)
Browse files Browse the repository at this point in the history
* Differentiate profile tabs for users and groups

* Add groups tab to user profiles

* Add specs for profile groups tab

* Add changelog

* Fix pagination
  • Loading branch information
mrcasals committed Oct 5, 2018
1 parent 01a73a3 commit f8ba6bd
Show file tree
Hide file tree
Showing 11 changed files with 73 additions and 9 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ Decidim::User.where(**search for old subscribed users**).update(newsletter_notif
- **decidim-core**: Added metrics visualization for Users and Proposals (all, accepted and votes) [\#3603](https://github.com/decidim/decidim/pull/3603)
- **decidim-participatory_processes**: Add a Call to Action button to process steps[\#4184](https://github.com/decidim/decidim/pull/4184)
- **decidim-core**: Show user groups profiles [\#4196](https://github.com/decidim/decidim/pull/4196)
- **decidim-core**: Show user groups on users profiles [\#4236](https://github.com/decidim/decidim/pull/4236)

**Changed**:

Expand Down
9 changes: 9 additions & 0 deletions decidim-core/app/cells/decidim/groups/show.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<div class="empty-notifications callout secondary <%= "hide" if user_groups.any? %>">
<p><%= t("decidim.groups.no_user_groups") %></p>
</div>
<div class="row small-up-1 medium-up-2 card-grid">
<% user_groups.each do |user_group| %>
<%= card_for user_group %>
<% end %>
</div>
<%= decidim_paginate user_groups %>
19 changes: 19 additions & 0 deletions decidim-core/app/cells/decidim/groups_cell.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# frozen_string_literal: true

module Decidim
# This cell is intended to be used on profiles.
class GroupsCell < Decidim::ViewModel
include Decidim::CellsPaginateHelper
include Decidim::ApplicationHelper
include Decidim::Core::Engine.routes.url_helpers
include Decidim::CardHelper

def show
render :show
end

def user_groups
@user_groups ||= model.user_groups.page(params[:page]).per(20)
end
end
end
10 changes: 1 addition & 9 deletions decidim-core/app/cells/decidim/profile/show.erb
Original file line number Diff line number Diff line change
@@ -1,15 +1,7 @@
<main class="wrapper">
<div class="row">
<div class="columns medium-9 medium-offset-3">
<ul class="tabs" id="profile-tabs">
<% if own_profile? %>
<%= user_profile_tab t("decidim.profiles.show.notifications"), notifications_path %>
<%= user_profile_tab t("decidim.profiles.show.conversations"), conversations_path %>
<% end %>
<%= user_profile_tab t("decidim.profiles.show.following"), profile_following_path(nickname: profile_holder.nickname) %>
<%= user_profile_tab t("decidim.profiles.show.followers"), profile_followers_path(nickname: profile_holder.nickname) %>
<%= user_profile_tab t("decidim.profiles.show.badges"), profile_badges_path(nickname: profile_holder.nickname) %>
</ul>
<%= profile_tabs %>
</div>
</div>
<div class="row">
Expand Down
5 changes: 5 additions & 0 deletions decidim-core/app/cells/decidim/profile/user_group_tabs.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<ul class="tabs" id="profile-tabs">
<%= user_profile_tab t("decidim.profiles.show.following"), profile_following_path(nickname: profile_holder.nickname) %>
<%= user_profile_tab t("decidim.profiles.show.followers"), profile_followers_path(nickname: profile_holder.nickname) %>
<%= user_profile_tab t("decidim.profiles.show.badges"), profile_badges_path(nickname: profile_holder.nickname) %>
</ul>
10 changes: 10 additions & 0 deletions decidim-core/app/cells/decidim/profile/user_tabs.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<ul class="tabs" id="profile-tabs">
<% if own_profile? %>
<%= user_profile_tab t("decidim.profiles.show.notifications"), notifications_path %>
<%= user_profile_tab t("decidim.profiles.show.conversations"), conversations_path %>
<% end %>
<%= user_profile_tab t("decidim.profiles.show.following"), profile_following_path(nickname: profile_holder.nickname) %>
<%= user_profile_tab t("decidim.profiles.show.followers"), profile_followers_path(nickname: profile_holder.nickname) %>
<%= user_profile_tab t("decidim.profiles.show.badges"), profile_badges_path(nickname: profile_holder.nickname) %>
<%= user_profile_tab t("decidim.profiles.show.groups"), profile_groups_path(nickname: profile_holder.nickname) %>
</ul>
5 changes: 5 additions & 0 deletions decidim-core/app/cells/decidim/profile_cell.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,10 @@ def active_content
def own_profile?
current_user && current_user == profile_holder
end

def profile_tabs
return render :user_group_tabs if profile_holder.is_a?(Decidim::UserGroup)
render :user_tabs
end
end
end
5 changes: 5 additions & 0 deletions decidim-core/app/controllers/decidim/profiles_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,11 @@ def badges
render :show
end

def groups
@content_cell = "decidim/groups"
render :show
end

private

def ensure_profile_holder
Expand Down
3 changes: 3 additions & 0 deletions decidim-core/config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -412,6 +412,8 @@ en:
description: Badges are recognitions to participant actions and progress in the platform. As you start discovering, participating and interacting in the platform, you will earn different badges.
level: Level %{level}
reached_top: You've reached the top level for this badge.
groups:
no_user_groups: Doesn't belong to any user group yet.
invitations:
create:
error: There were some problems while inviting your friends
Expand Down Expand Up @@ -595,6 +597,7 @@ en:
conversations: Conversations
followers: Followers
following: Follows
groups: Groups
notifications: Notifications
sidebar:
badges:
Expand Down
1 change: 1 addition & 0 deletions decidim-core/config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@
get "following", to: "profiles#following", as: "profile_following"
get "followers", to: "profiles#followers", as: "profile_followers"
get "badges", to: "profiles#badges", as: "profile_badges"
get "groups", to: "profiles#groups", as: "profile_groups"
end

resources :pages, only: [:index, :show], format: false
Expand Down
14 changes: 14 additions & 0 deletions decidim-core/spec/system/profile_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,20 @@
expect(page).to have_content(user_to_follow.name)
end
end

context "when belonging to user groups" do
let!(:user_group) { create :user_group, users: [user], organization: user.organization }

before do
visit decidim.profile_path(user.nickname)
end

it "lists the user groups" do
click_link "Groups"

expect(page).to have_content(user_group.name)
end
end
end

describe "view hooks" do
Expand Down

0 comments on commit f8ba6bd

Please sign in to comment.