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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

New badges #4033

Merged
merged 4 commits into from Aug 28, 2018
Merged
Show file tree
Hide file tree
Changes from 2 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
4 changes: 1 addition & 3 deletions .codeclimate.yml
@@ -1,5 +1,3 @@
---

version: "2"

checks:
Expand Down Expand Up @@ -98,7 +96,7 @@ plugins:
exclude_patterns:
- "decidim_app-design/**/*"
- "**/*/locales/*.yml"

- "**/*/*.svg"

markdownlint:
enabled: true
Expand Down
4 changes: 4 additions & 0 deletions CHANGELOG.md
Expand Up @@ -65,6 +65,10 @@
- **decidim-participatory_processes**: Display a big card when there's just one process at the homepage [\#3970](https://github.com/decidim/decidim/pull/3970)
- **decidim-core**: Adds support for earning badges. [\#3975](https://github.com/decidim/decidim/pull/3975)
- **decidim-proposals**: Adds the *proposal* badge. [\#3975](https://github.com/decidim/decidim/pull/3975)
- **decidim-proposals**: Adds the *proposal supports* badge. [\#4033](https://github.com/decidim/decidim/pull/4033)
- **decidim-proposals**: Adds the *accepted proposals* badge. [\#4033](https://github.com/decidim/decidim/pull/4033)
- **decidim-core**: Adds the *invitations* badge. [\#4033](https://github.com/decidim/decidim/pull/4033)
- **decidim-initiatives**: Adds the *published initiatives* badge. [\#4033](https://github.com/decidim/decidim/pull/4033)
- **decidim-core**: Add link to admin edit from public pages. [\#3978](https://github.com/decidim/decidim/pull/3978)

**Changed**:
Expand Down
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
62 changes: 31 additions & 31 deletions decidim-core/app/cells/decidim/badge/show.erb
@@ -1,36 +1,36 @@
<div class="column">
<article class="card card--badge absolutes badge-<%= badge.name %>">
<div class="right badge-tip">
<div data-tooltip data-position="top" title="<%= tooltip %>" aria-describedby="<%= badge.name %>-tooltip" data-yeti-box="<%= badge.name %>-tooltip" data-toggle="<%= badge.name %>-tooltip" data-resize="<%= badge.name %>-tooltip" class="has-tip" data-t="<%= badge.name %>-t">
<%= icon "info" %>
</div>
<div class="column">
<article class="card card--badge absolutes badge-<%= badge.name %>">
<div class="right badge-tip">
<div data-tooltip data-position="top" title="<%= tooltip %>" aria-describedby="<%= badge.name %>-tooltip" data-yeti-box="<%= badge.name %>-tooltip" data-toggle="<%= badge.name %>-tooltip" data-resize="<%= badge.name %>-tooltip" class="has-tip" data-t="<%= badge.name %>-t">
<%= icon "info" %>
</div>
<div class="card__content">
<div class="card__header">
<div class="badge-container">
<%= image_tag badge.image, class: "badge__logo" %>
</div>
</div>
<div class="card__text text-center">
<strong><%= badge_name %></strong>
</div>
<div class="card__text text-center">
<%= description %>
</div>
<div class="card__content">
<div class="card__header">
<div class="badge-container">
<%= image_tag badge.image, class: "badge__logo" %>
</div>
</div>
<div class="card__footer card__footer--transparent">
<div class="p-xs">
<div class="flex--sbc">
<strong class="text-uppercase muted">
<%= t "decidim.gamification.level", level: status.level %>
</strong>
<div class="badge-level">
<% badge.levels.each_with_index do |_threshold, level| %>
<div class="<%= "is-achieved" if status.level >= (level + 1) %>"></div>
<% end %>
</div>
</div>
</div>
<div class="card__text text-center">
<strong><%= badge_name %></strong>
</div>
<div class="card__text text-center">
<%= description %>
</div>
</div>
<div class="card__footer card__footer--transparent">
<div class="p-xs">
<div class="flex--sbc">
<strong class="text-uppercase muted">
<%= t "decidim.gamification.level", level: status.level %>
</strong>
<div class="badge-level">
<% badge.levels.each_with_index do |_threshold, level| %>
<div class="<%= "is-achieved" if status.level >= (level + 1) %>"></div>
<% end %>
</div>
</div>
</div>
</div>
</div>
</article>
</div>
2 changes: 1 addition & 1 deletion decidim-core/app/cells/decidim/badges/show.erb
@@ -1,6 +1,6 @@
<p><%= t "decidim.gamification.description" %></p>
<div class="row small-up-2 medium-up-4 card-grid badges">
<% Decidim::Gamification.badges.each do |badge| %>
<% Decidim::Gamification.badges.sort_by(&:name).each do |badge| %>
<%= cell "decidim/badge", user, badge: badge %>
<% end %>
</div>
Expand Up @@ -28,6 +28,7 @@ def accept_resource
resource.update!(newsletter_notifications_at: Time.current) if update_resource_params[:newsletter_notifications]
resource.update!(managed: false) if resource.managed?
resource.update!(accepted_tos_version: resource.organization.tos_version)
Decidim::Gamification.increment_score(resource.invited_by, :invitations) if resource.invited_by
resource
end

Expand Down
9 changes: 9 additions & 0 deletions decidim-core/config/locales/en.yml
Expand Up @@ -385,6 +385,15 @@ en:
error: There's an error in this field.
remove_this_file: Remove this file
gamification:
badges:
invitations:
description_another: This user has invited %{score} users.
description_own: You have invited %{score} users.
explanation: Users get this badge by inviting other users.
name: Invitations
next_level_in: Invite %{score} more users to reach the next level!
unearned_another: This user hasn't invited any user yet.
unearned_own: You have invited no users yet.
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.
Expand Down
7 changes: 7 additions & 0 deletions decidim-core/lib/decidim/core/engine.rb
Expand Up @@ -313,6 +313,13 @@ class Engine < ::Rails::Engine
content_block.public_name_key "decidim.content_blocks.footer_sub_hero.name"
end
end

initializer "decidim.core.add_badges" do
Decidim::Gamification.register_badge(:invitations) do |badge|
badge.levels = [1, 5, 10, 30, 50]
badge.reset = ->(user) { Decidim::User.where(invited_by: user.id).count }
end
end
end
end
end