FEATURE: long descriptions for badges to help teach people

This commit is contained in:
Sam 2015-02-27 17:19:18 +11:00
parent 6a20d12772
commit f555bbb416
9 changed files with 52 additions and 6 deletions

View File

@ -48,6 +48,10 @@ export default ObjectController.extend({
_showFooter: function() { _showFooter: function() {
this.set("controllers.application.showFooter", !this.get("canLoadMore")); this.set("controllers.application.showFooter", !this.get("canLoadMore"));
}.observes("canLoadMore") }.observes("canLoadMore"),
showLongDescription: function(){
return window.location.search.match("long-description");
}.property('userBadges')
}); });

View File

@ -17,6 +17,12 @@
</tbody> </tbody>
</table> </table>
{{#if showLongDescription}}
<div class='long-description banner'>
{{{long_description}}}
</div>
{{/if}}
{{#if userBadges}} {{#if userBadges}}
<div class={{unbound layoutClass}}> <div class={{unbound layoutClass}}>
{{#each ub in userBadges}} {{#each ub in userBadges}}

View File

@ -159,3 +159,8 @@ table.badges-listing {
text-align: left; text-align: left;
} }
} }
.long-description.banner {
width: 88%;
margin-bottom: 20px;
}

View File

@ -2,7 +2,7 @@
// Banner // Banner
// -------------------------------------------------- // --------------------------------------------------
#banner { #banner, .banner {
padding: 10px; padding: 10px;
border-radius: 5px; border-radius: 5px;
background: scale-color($tertiary, $lightness: 90%); background: scale-color($tertiary, $lightness: 90%);

View File

@ -17,7 +17,7 @@ class BadgesController < ApplicationController
if current_user if current_user
user_badges = Set.new(current_user.user_badges.select('distinct badge_id').pluck(:badge_id)) user_badges = Set.new(current_user.user_badges.select('distinct badge_id').pluck(:badge_id))
end end
serialized = MultiJson.dump(serialize_data(badges, BadgeIndexSerializer, root: "badges", user_badges: user_badges)) serialized = MultiJson.dump(serialize_data(badges, BadgeIndexSerializer, root: "badges", user_badges: user_badges, include_long_description: true))
respond_to do |format| respond_to do |format|
format.html do format.html do
store_preloaded "badges", serialized store_preloaded "badges", serialized
@ -38,7 +38,7 @@ class BadgesController < ApplicationController
end end
end end
serialized = MultiJson.dump(serialize_data(badge, BadgeSerializer, root: "badge")) serialized = MultiJson.dump(serialize_data(badge, BadgeSerializer, root: "badge", include_long_description: true))
respond_to do |format| respond_to do |format|
format.html do format.html do
store_preloaded "badge", serialized store_preloaded "badge", serialized

View File

@ -10,7 +10,7 @@ class UserBadgesController < ApplicationController
user_badges = user_badges.offset(offset.to_i) user_badges = user_badges.offset(offset.to_i)
end end
render_serialized(user_badges, UserBadgeSerializer, root: "user_badges") render_serialized(user_badges, UserBadgeSerializer, root: "user_badges", include_long_description: true)
end end
def username def username

View File

@ -1,10 +1,28 @@
class BadgeSerializer < ApplicationSerializer class BadgeSerializer < ApplicationSerializer
attributes :id, :name, :description, :grant_count, :allow_title, attributes :id, :name, :description, :grant_count, :allow_title,
:multiple_grant, :icon, :image, :listable, :enabled, :badge_grouping_id, :multiple_grant, :icon, :image, :listable, :enabled, :badge_grouping_id,
:system :system, :long_description
has_one :badge_type has_one :badge_type
def system def system
object.system? object.system?
end end
def include_long_description?
options[:include_long_description]
end
def long_description
if object.long_description.present?
object.long_description
else
key = "badges.long_descriptions.#{object.name.downcase.gsub(" ", "_")}"
if I18n.exists?(key)
I18n.t(key)
else
""
end
end
end
end end

View File

@ -2319,3 +2319,11 @@ en:
<p> <p>
<code>rainbows category:parks status:open order:latest</code> will search for topics containing the word "rainbows" in the category "parks" that are not closed or archived, ordered by date of last post. <code>rainbows category:parks status:open order:latest</code> will search for topics containing the word "rainbows" in the category "parks" that are not closed or archived, ordered by date of last post.
</p> </p>
badges:
long_descriptions:
first_flag: |
Flagging is critical to the health of your community. If you notice any posts that require moderator attention please
do not hesitate to flag. You may also use the flagging dialog to send <b>private messages</b> to users once you reach
trust level 1.

View File

@ -0,0 +1,5 @@
class AddLongDescriptionToBadges < ActiveRecord::Migration
def change
add_column :badges, :long_description, :text
end
end