mirror of
https://github.com/discourse/discourse.git
synced 2024-12-16 04:33:48 +08:00
4b71fd253b
Properly support Categories so it updates the search box correctly Use category id, as it is more consistent with search results than using the slugs, especially for parent/subcategory Added Status Improve AutoComplete so it can receive updates Added the ability for AutoComplete to receive updates to badge-selector and group-selector Respect null, which is set via web-hooks Support both # and category: for category detection. Only update the searchedTerms if they differ from its current value (this helps the Category Selector receive updates) Opt in receive updates (#3) * Make the selectors opt-in for receiving updates * Opt-in to receive updates * Fix category detection for search-advanced-options Fix eslint error Update user-selector so it can receive updates live too Make the canReceiveUpdates check validate against 'true' Converted to use template literals Refactor the regex involved with this feature Split apart the init to make it a bit more manageable/testable Switch the category selector to category-chooser, so it is a dropdown of categories instead of auto-complete Reduce RegEx to make this happier with unicode languages and reduce some of the complexity
60 lines
1.7 KiB
Ruby
60 lines
1.7 KiB
Ruby
class BadgesController < ApplicationController
|
|
skip_before_filter :check_xhr, only: [:index, :show]
|
|
|
|
def index
|
|
raise Discourse::NotFound unless SiteSetting.enable_badges
|
|
|
|
badges = Badge.all
|
|
|
|
if search = params[:search]
|
|
search = search.to_s
|
|
badges = badges.where("name ILIKE ?", "%#{search}%")
|
|
end
|
|
|
|
if (params[:only_listable] == "true") || !request.xhr?
|
|
# NOTE: this is sorted client side if needed
|
|
badges = badges.includes(:badge_grouping)
|
|
.where(enabled: true, listable: true)
|
|
|
|
end
|
|
|
|
badges = badges.to_a
|
|
|
|
user_badges = nil
|
|
if current_user
|
|
user_badges = Set.new(current_user.user_badges.select('distinct badge_id').pluck(:badge_id))
|
|
end
|
|
serialized = MultiJson.dump(serialize_data(badges, BadgeIndexSerializer, root: "badges", user_badges: user_badges, include_long_description: true))
|
|
respond_to do |format|
|
|
format.html do
|
|
store_preloaded "badges", serialized
|
|
render "default/empty"
|
|
end
|
|
format.json { render json: serialized }
|
|
end
|
|
end
|
|
|
|
def show
|
|
raise Discourse::NotFound unless SiteSetting.enable_badges
|
|
|
|
params.require(:id)
|
|
badge = Badge.enabled.find(params[:id])
|
|
|
|
if current_user
|
|
user_badge = UserBadge.find_by(user_id: current_user.id, badge_id: badge.id)
|
|
if user_badge && user_badge.notification
|
|
user_badge.notification.update_attributes read: true
|
|
end
|
|
end
|
|
|
|
serialized = MultiJson.dump(serialize_data(badge, BadgeSerializer, root: "badge", include_long_description: true))
|
|
respond_to do |format|
|
|
format.html do
|
|
store_preloaded "badge", serialized
|
|
render "default/empty"
|
|
end
|
|
format.json { render json: serialized }
|
|
end
|
|
end
|
|
end
|