forked from OpenNeo/impress
basic translation infrastructure for items - search is still english-only, and probably will have to be replaced with a legit search engine
This commit is contained in:
parent
d79c225c1e
commit
9c8f7f498f
5 changed files with 27 additions and 14 deletions
|
@ -188,15 +188,17 @@ class ClosetHangersController < ApplicationController
|
|||
|
||||
def find_closet_lists_by_owned(closet_lists)
|
||||
return {} if closet_lists == []
|
||||
closet_lists.alphabetical.includes(:hangers => :item).
|
||||
closet_lists.alphabetical.includes(:hangers => {:item => :translations}).
|
||||
group_by(&:hangers_owned)
|
||||
end
|
||||
|
||||
def find_unlisted_closet_hangers_by_owned(visible_groups)
|
||||
unless visible_groups.empty?
|
||||
@user.closet_hangers.unlisted.
|
||||
owned_before_wanted.alphabetical_by_item_name.includes(:item).
|
||||
where(:owned => [visible_groups]).group_by(&:owned)
|
||||
owned_before_wanted.alphabetical_by_item_name.
|
||||
includes(:item => :translations).
|
||||
where(:owned => [visible_groups]).
|
||||
group_by(&:owned)
|
||||
else
|
||||
{}
|
||||
end
|
||||
|
|
|
@ -10,7 +10,11 @@ class ItemsController < ApplicationController
|
|||
else
|
||||
per_page = nil
|
||||
end
|
||||
@items = Item.search(@query, current_user).alphabetize.paginate :page => params[:page], :per_page => per_page
|
||||
# Note that we sort by name by hand, since we might have to use
|
||||
# fallbacks after the fact
|
||||
@items = Item.search(@query, current_user, I18n.default_locale).
|
||||
alphabetize_by_translations.
|
||||
paginate(:page => params[:page], :per_page => per_page)
|
||||
assign_closeted!
|
||||
respond_to do |format|
|
||||
format.html { render }
|
||||
|
@ -35,7 +39,7 @@ class ItemsController < ApplicationController
|
|||
respond_to do |format|
|
||||
format.html {
|
||||
unless localized_fragment_exist?('items#index newest_items')
|
||||
@newest_items = Item.newest.limit(18)
|
||||
@newest_items = Item.newest.with_translations.limit(18)
|
||||
end
|
||||
}
|
||||
format.js { render :json => {:error => '$q required'}}
|
||||
|
@ -96,7 +100,8 @@ class ItemsController < ApplicationController
|
|||
raise ActiveRecord::RecordNotFound, 'Pet type not found'
|
||||
end
|
||||
|
||||
@items = @pet_type.needed_items.alphabetize
|
||||
@items = @pet_type.needed_items.with_translations(I18n.locale).
|
||||
alphabetize_by_translations
|
||||
assign_closeted!
|
||||
|
||||
respond_to do |format|
|
||||
|
|
|
@ -47,7 +47,8 @@ class OutfitsController < ApplicationController
|
|||
end
|
||||
|
||||
unless localized_fragment_exist?('outfits#new newest_items')
|
||||
@newest_items = Item.newest.select([:id, :name, :thumbnail_url]).limit(9)
|
||||
@newest_items = Item.newest.select([:id, :name, :thumbnail_url]).
|
||||
with_translations.limit(9)
|
||||
end
|
||||
|
||||
unless localized_fragment_exist?('outfits#new latest_contribution')
|
||||
|
|
|
@ -3,7 +3,7 @@ class SitemapController < ApplicationController
|
|||
|
||||
def index
|
||||
respond_to do |format|
|
||||
format.xml { @items = Item.sitemap }
|
||||
format.xml { @items = Item.with_translations.sitemap }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -25,7 +25,11 @@ class Item < ActiveRecord::Base
|
|||
cattr_reader :per_page
|
||||
@@per_page = 30
|
||||
|
||||
scope :alphabetize, order('name ASC')
|
||||
scope :alphabetize, order(arel_table[:name])
|
||||
scope :alphabetize_by_translations, lambda {
|
||||
it = Item::Translation.arel_table
|
||||
order(it[:name])
|
||||
}
|
||||
|
||||
scope :join_swf_assets, joins(:swf_assets).group(arel_table[:id])
|
||||
|
||||
|
@ -36,7 +40,8 @@ class Item < ActiveRecord::Base
|
|||
scope :sold_in_mall, where(:sold_in_mall => true)
|
||||
scope :not_sold_in_mall, where(:sold_in_mall => false)
|
||||
|
||||
scope :sitemap, select([:id, :name]).order(:id).limit(49999)
|
||||
scope :sitemap, select([arel_table[:id], arel_table[:name]]).
|
||||
order(arel_table[:id]).limit(49999)
|
||||
|
||||
scope :with_closet_hangers, joins(:closet_hangers)
|
||||
|
||||
|
@ -155,7 +160,7 @@ class Item < ActiveRecord::Base
|
|||
Species.find(species_ids)
|
||||
end
|
||||
|
||||
def self.search(query, user=nil)
|
||||
def self.search(query, user, locale)
|
||||
raise SearchError, "Please provide a search query" unless query
|
||||
query = query.strip
|
||||
raise SearchError, "Search queries should be at least 3 characters" if query.length < 3
|
||||
|
@ -175,7 +180,7 @@ class Item < ActiveRecord::Base
|
|||
end
|
||||
end
|
||||
limited_filters_used = []
|
||||
query_conditions.inject(self.scoped) do |scope, condition|
|
||||
query_conditions.inject(self.with_translations(locale)) do |scope, condition|
|
||||
if condition.filter? && LimitedSearchFilters.include?(condition.filter)
|
||||
if limited_filters_used.include?(condition.filter)
|
||||
raise SearchError, "The #{condition.filter} filter is complex; please only use one per search. Thanks!"
|
||||
|
@ -706,11 +711,11 @@ class Item < ActiveRecord::Base
|
|||
end
|
||||
|
||||
search_filter :name do |name|
|
||||
arel_table[:name].matches("%#{name}%")
|
||||
Item::Translation.arel_table[:name].matches("%#{name}%")
|
||||
end
|
||||
|
||||
search_filter :description do |description|
|
||||
arel_table[:description].matches("%#{description}%")
|
||||
Item::Translation.arel_table[:description].matches("%#{description}%")
|
||||
end
|
||||
|
||||
def self.adjective_filters
|
||||
|
|
Loading…
Reference in a new issue