Badge Grouping work in progress
This commit is contained in:
parent
91cd4f2d66
commit
bfb37054e8
|
@ -4,12 +4,12 @@ class BadgesController < ApplicationController
|
||||||
def index
|
def index
|
||||||
badges = Badge.all
|
badges = Badge.all
|
||||||
badges = badges.where(enabled: true, listable: true) if(params[:only_listable] == "true") || !request.xhr?
|
badges = badges.where(enabled: true, listable: true) if(params[:only_listable] == "true") || !request.xhr?
|
||||||
badges = badges.to_a
|
badges = badges.includes(:badge_grouping).to_a
|
||||||
user_badges = nil
|
user_badges = nil
|
||||||
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, BadgeSerializer, root: "badges", user_badges: user_badges))
|
serialized = MultiJson.dump(serialize_data(badges, BadgeSerializer, root: "badges", user_badges: user_badges, include_grouping: true))
|
||||||
respond_to do |format|
|
respond_to do |format|
|
||||||
format.html do
|
format.html do
|
||||||
store_preloaded "badges", serialized
|
store_preloaded "badges", serialized
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
class Badge < ActiveRecord::Base
|
class Badge < ActiveRecord::Base
|
||||||
|
belongs_to :badge_grouping
|
||||||
|
|
||||||
# badge ids
|
# badge ids
|
||||||
Welcome = 5
|
Welcome = 5
|
||||||
|
@ -178,26 +179,32 @@ SQL
|
||||||
def default_name=(val)
|
def default_name=(val)
|
||||||
self.name ||= val
|
self.name ||= val
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def default_badge_grouping_id=(val)
|
||||||
|
self.badge_grouping_id ||= val
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# == Schema Information
|
# == Schema Information
|
||||||
#
|
#
|
||||||
# Table name: badges
|
# Table name: badges
|
||||||
#
|
#
|
||||||
# id :integer not null, primary key
|
# id :integer not null, primary key
|
||||||
# name :string(255) not null
|
# name :string(255) not null
|
||||||
# description :text
|
# description :text
|
||||||
# badge_type_id :integer not null
|
# badge_type_id :integer not null
|
||||||
# grant_count :integer default(0), not null
|
# grant_count :integer default(0), not null
|
||||||
# created_at :datetime
|
# created_at :datetime
|
||||||
# updated_at :datetime
|
# updated_at :datetime
|
||||||
# allow_title :boolean default(FALSE), not null
|
# allow_title :boolean default(FALSE), not null
|
||||||
# multiple_grant :boolean default(FALSE), not null
|
# multiple_grant :boolean default(FALSE), not null
|
||||||
# icon :string(255) default("fa-certificate")
|
# icon :string(255) default("fa-certificate")
|
||||||
# listable :boolean default(TRUE)
|
# listable :boolean default(TRUE)
|
||||||
# target_posts :boolean default(FALSE)
|
# target_posts :boolean default(FALSE)
|
||||||
# query :text
|
# query :text
|
||||||
# enabled :boolean default(TRUE), not null
|
# enabled :boolean default(TRUE), not null
|
||||||
|
# auto_revoke :boolean default(TRUE), not null
|
||||||
|
# badge_grouping_id :integer
|
||||||
#
|
#
|
||||||
# Indexes
|
# Indexes
|
||||||
#
|
#
|
||||||
|
|
|
@ -1,3 +1,24 @@
|
||||||
class BadgeGrouping < ActiveRecord::Base
|
class BadgeGrouping < ActiveRecord::Base
|
||||||
|
|
||||||
|
module Position
|
||||||
|
GettingStarted = 10
|
||||||
|
Community = 11
|
||||||
|
Posting = 12
|
||||||
|
TrustLevel = 13
|
||||||
|
Other = 14
|
||||||
|
end
|
||||||
|
|
||||||
has_many :badges
|
has_many :badges
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# == Schema Information
|
||||||
|
#
|
||||||
|
# Table name: badge_groupings
|
||||||
|
#
|
||||||
|
# id :integer not null, primary key
|
||||||
|
# name :string(255) not null
|
||||||
|
# description :string(255) not null
|
||||||
|
# position :integer not null
|
||||||
|
# created_at :datetime
|
||||||
|
# updated_at :datetime
|
||||||
|
#
|
||||||
|
|
|
@ -193,7 +193,7 @@ end
|
||||||
#
|
#
|
||||||
# id :integer not null, primary key
|
# id :integer not null, primary key
|
||||||
# invite_key :string(32) not null
|
# invite_key :string(32) not null
|
||||||
# email :string(255) not null
|
# email :string(255)
|
||||||
# invited_by_id :integer not null
|
# invited_by_id :integer not null
|
||||||
# user_id :integer
|
# user_id :integer
|
||||||
# redeemed_at :datetime
|
# redeemed_at :datetime
|
||||||
|
|
|
@ -602,5 +602,5 @@ end
|
||||||
# idx_posts_created_at_topic_id (created_at,topic_id)
|
# idx_posts_created_at_topic_id (created_at,topic_id)
|
||||||
# idx_posts_user_id_deleted_at (user_id)
|
# idx_posts_user_id_deleted_at (user_id)
|
||||||
# index_posts_on_reply_to_post_number (reply_to_post_number)
|
# index_posts_on_reply_to_post_number (reply_to_post_number)
|
||||||
# index_posts_on_topic_id_and_post_number (topic_id,post_number)
|
# index_posts_on_topic_id_and_post_number (topic_id,post_number) UNIQUE
|
||||||
#
|
#
|
||||||
|
|
|
@ -46,3 +46,19 @@ class QuotedPost < ActiveRecord::Base
|
||||||
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# == Schema Information
|
||||||
|
#
|
||||||
|
# Table name: quoted_posts
|
||||||
|
#
|
||||||
|
# id :integer not null, primary key
|
||||||
|
# post_id :integer not null
|
||||||
|
# quoted_post_id :integer not null
|
||||||
|
# created_at :datetime
|
||||||
|
# updated_at :datetime
|
||||||
|
#
|
||||||
|
# Indexes
|
||||||
|
#
|
||||||
|
# index_quoted_posts_on_post_id_and_quoted_post_id (post_id,quoted_post_id) UNIQUE
|
||||||
|
# index_quoted_posts_on_quoted_post_id_and_post_id (quoted_post_id,post_id) UNIQUE
|
||||||
|
#
|
||||||
|
|
|
@ -787,7 +787,6 @@ end
|
||||||
# Indexes
|
# Indexes
|
||||||
#
|
#
|
||||||
# index_users_on_auth_token (auth_token)
|
# index_users_on_auth_token (auth_token)
|
||||||
# index_users_on_email (email) UNIQUE
|
|
||||||
# index_users_on_last_posted_at (last_posted_at)
|
# index_users_on_last_posted_at (last_posted_at)
|
||||||
# index_users_on_username (username) UNIQUE
|
# index_users_on_username (username) UNIQUE
|
||||||
# index_users_on_username_lower (username_lower) UNIQUE
|
# index_users_on_username_lower (username_lower) UNIQUE
|
||||||
|
|
|
@ -0,0 +1,3 @@
|
||||||
|
class BadgeGroupingSerializer < ApplicationSerializer
|
||||||
|
attributes :id, :name, :description
|
||||||
|
end
|
|
@ -1,6 +1,7 @@
|
||||||
class BadgeSerializer < ApplicationSerializer
|
class BadgeSerializer < ApplicationSerializer
|
||||||
attributes :id, :name, :description, :grant_count, :allow_title, :multiple_grant, :icon, :listable, :enabled, :has_badge
|
attributes :id, :name, :description, :grant_count, :allow_title, :multiple_grant, :icon, :listable, :enabled, :has_badge
|
||||||
has_one :badge_type
|
has_one :badge_type
|
||||||
|
has_one :badge_grouping
|
||||||
|
|
||||||
def include_has_badge?
|
def include_has_badge?
|
||||||
@options[:user_badges]
|
@options[:user_badges]
|
||||||
|
|
|
@ -1,3 +1,34 @@
|
||||||
|
|
||||||
|
BadgeGrouping.seed do |g|
|
||||||
|
g.id = 1
|
||||||
|
g.name = "Getting Started"
|
||||||
|
g.position = BadgeGrouping::Position::GettingStarted
|
||||||
|
end
|
||||||
|
|
||||||
|
BadgeGrouping.seed do |g|
|
||||||
|
g.id = 2
|
||||||
|
g.name = "Community"
|
||||||
|
g.position = BadgeGrouping::Position::Community
|
||||||
|
end
|
||||||
|
|
||||||
|
BadgeGrouping.seed do |g|
|
||||||
|
g.id = 3
|
||||||
|
g.name = "Posting"
|
||||||
|
g.position = BadgeGrouping::Position::Posting
|
||||||
|
end
|
||||||
|
|
||||||
|
BadgeGrouping.seed do |g|
|
||||||
|
g.id = 4
|
||||||
|
g.name = "Trust Level"
|
||||||
|
g.position = BadgeGrouping::Position::TrustLevel
|
||||||
|
end
|
||||||
|
|
||||||
|
BadgeGrouping.seed do |g|
|
||||||
|
g.id = 5
|
||||||
|
g.name = "Other"
|
||||||
|
g.position = BadgeGrouping::Position::Other
|
||||||
|
end
|
||||||
|
|
||||||
# Trust level system badges.
|
# Trust level system badges.
|
||||||
trust_level_badges = [
|
trust_level_badges = [
|
||||||
{id: 1, name: "Basic User", type: BadgeType::Bronze},
|
{id: 1, name: "Basic User", type: BadgeType::Bronze},
|
||||||
|
@ -12,6 +43,7 @@ trust_level_badges.each do |spec|
|
||||||
b.default_name = spec[:name]
|
b.default_name = spec[:name]
|
||||||
b.badge_type_id = spec[:type]
|
b.badge_type_id = spec[:type]
|
||||||
b.query = Badge::Queries.trust_level(spec[:id])
|
b.query = Badge::Queries.trust_level(spec[:id])
|
||||||
|
b.default_badge_grouping_id = BadgeGrouping::Position::TrustLevel
|
||||||
|
|
||||||
# allow title for leader and elder
|
# allow title for leader and elder
|
||||||
b.allow_title = spec[:id] > 2
|
b.allow_title = spec[:id] > 2
|
||||||
|
@ -25,6 +57,7 @@ Badge.seed do |b|
|
||||||
b.multiple_grant = false
|
b.multiple_grant = false
|
||||||
b.target_posts = false
|
b.target_posts = false
|
||||||
b.query = Badge::Queries::Reader
|
b.query = Badge::Queries::Reader
|
||||||
|
b.default_badge_grouping_id = BadgeGrouping::Position::GettingStarted
|
||||||
b.auto_revoke = false
|
b.auto_revoke = false
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -35,6 +68,7 @@ Badge.seed do |b|
|
||||||
b.multiple_grant = false
|
b.multiple_grant = false
|
||||||
b.target_posts = false
|
b.target_posts = false
|
||||||
b.query = Badge::Queries::ReadGuidelines
|
b.query = Badge::Queries::ReadGuidelines
|
||||||
|
b.default_badge_grouping_id = BadgeGrouping::Position::GettingStarted
|
||||||
end
|
end
|
||||||
|
|
||||||
Badge.seed do |b|
|
Badge.seed do |b|
|
||||||
|
@ -44,6 +78,7 @@ Badge.seed do |b|
|
||||||
b.multiple_grant = false
|
b.multiple_grant = false
|
||||||
b.target_posts = true
|
b.target_posts = true
|
||||||
b.query = Badge::Queries::FirstLink
|
b.query = Badge::Queries::FirstLink
|
||||||
|
b.default_badge_grouping_id = BadgeGrouping::Position::GettingStarted
|
||||||
end
|
end
|
||||||
|
|
||||||
Badge.seed do |b|
|
Badge.seed do |b|
|
||||||
|
@ -53,6 +88,7 @@ Badge.seed do |b|
|
||||||
b.multiple_grant = false
|
b.multiple_grant = false
|
||||||
b.target_posts = true
|
b.target_posts = true
|
||||||
b.query = Badge::Queries::FirstQuote
|
b.query = Badge::Queries::FirstQuote
|
||||||
|
b.default_badge_grouping_id = BadgeGrouping::Position::GettingStarted
|
||||||
end
|
end
|
||||||
|
|
||||||
Badge.seed do |b|
|
Badge.seed do |b|
|
||||||
|
@ -62,6 +98,7 @@ Badge.seed do |b|
|
||||||
b.multiple_grant = false
|
b.multiple_grant = false
|
||||||
b.target_posts = true
|
b.target_posts = true
|
||||||
b.query = Badge::Queries::FirstLike
|
b.query = Badge::Queries::FirstLike
|
||||||
|
b.default_badge_grouping_id = BadgeGrouping::Position::GettingStarted
|
||||||
end
|
end
|
||||||
|
|
||||||
Badge.seed do |b|
|
Badge.seed do |b|
|
||||||
|
@ -71,6 +108,7 @@ Badge.seed do |b|
|
||||||
b.multiple_grant = false
|
b.multiple_grant = false
|
||||||
b.target_posts = false
|
b.target_posts = false
|
||||||
b.query = Badge::Queries::FirstFlag
|
b.query = Badge::Queries::FirstFlag
|
||||||
|
b.default_badge_grouping_id = BadgeGrouping::Position::Community
|
||||||
end
|
end
|
||||||
|
|
||||||
Badge.seed do |b|
|
Badge.seed do |b|
|
||||||
|
@ -80,6 +118,7 @@ Badge.seed do |b|
|
||||||
b.multiple_grant = false
|
b.multiple_grant = false
|
||||||
b.target_posts = true
|
b.target_posts = true
|
||||||
b.query = Badge::Queries::FirstShare
|
b.query = Badge::Queries::FirstShare
|
||||||
|
b.default_badge_grouping_id = BadgeGrouping::Position::GettingStarted
|
||||||
end
|
end
|
||||||
|
|
||||||
Badge.seed do |b|
|
Badge.seed do |b|
|
||||||
|
@ -89,6 +128,7 @@ Badge.seed do |b|
|
||||||
b.multiple_grant = false
|
b.multiple_grant = false
|
||||||
b.target_posts = true
|
b.target_posts = true
|
||||||
b.query = Badge::Queries::Welcome
|
b.query = Badge::Queries::Welcome
|
||||||
|
b.default_badge_grouping_id = BadgeGrouping::Position::Community
|
||||||
end
|
end
|
||||||
|
|
||||||
Badge.seed do |b|
|
Badge.seed do |b|
|
||||||
|
@ -97,6 +137,7 @@ Badge.seed do |b|
|
||||||
b.badge_type_id = BadgeType::Bronze
|
b.badge_type_id = BadgeType::Bronze
|
||||||
b.multiple_grant = false
|
b.multiple_grant = false
|
||||||
b.query = Badge::Queries::Autobiographer
|
b.query = Badge::Queries::Autobiographer
|
||||||
|
b.default_badge_grouping_id = BadgeGrouping::Position::GettingStarted
|
||||||
end
|
end
|
||||||
|
|
||||||
Badge.seed do |b|
|
Badge.seed do |b|
|
||||||
|
@ -105,6 +146,7 @@ Badge.seed do |b|
|
||||||
b.badge_type_id = BadgeType::Bronze
|
b.badge_type_id = BadgeType::Bronze
|
||||||
b.multiple_grant = false
|
b.multiple_grant = false
|
||||||
b.query = Badge::Queries::Editor
|
b.query = Badge::Queries::Editor
|
||||||
|
b.default_badge_grouping_id = BadgeGrouping::Position::Community
|
||||||
end
|
end
|
||||||
|
|
||||||
#
|
#
|
||||||
|
@ -123,5 +165,6 @@ like_badges.each do |spec|
|
||||||
b.multiple_grant = spec[:multiple]
|
b.multiple_grant = spec[:multiple]
|
||||||
b.target_posts = true
|
b.target_posts = true
|
||||||
b.query = Badge::Queries.like_badge(Badge.like_badge_counts[spec[:id]])
|
b.query = Badge::Queries.like_badge(Badge.like_badge_counts[spec[:id]])
|
||||||
|
b.default_badge_grouping_id = BadgeGrouping::Position::Posting
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -0,0 +1,5 @@
|
||||||
|
class DescriptionOptionalInBadgeGrouping < ActiveRecord::Migration
|
||||||
|
def change
|
||||||
|
change_column :badge_groupings, :description, :text, null: true
|
||||||
|
end
|
||||||
|
end
|
Loading…
Reference in New Issue