From 65d3181e4422e824c136c08efd77e3b4d97fd512 Mon Sep 17 00:00:00 2001 From: Larissa Reis Date: Fri, 25 Jul 2014 19:26:36 -0300 Subject: [PATCH] Adds a label string to SEARCHABLE_FIELDS --- app/controllers/public/invite_controller.rb | 7 +------ app/models/article.rb | 10 +++++----- app/models/category.rb | 8 ++++---- app/models/certifier.rb | 6 +++--- app/models/comment.rb | 6 +++--- app/models/license.rb | 4 ++-- app/models/national_region.rb | 4 ++-- app/models/product.rb | 4 ++-- app/models/profile.rb | 6 +++--- app/models/qualifier.rb | 2 +- app/models/scrap.rb | 2 +- app/models/user.rb | 2 +- plugins/stoa/lib/ext/person.rb | 2 +- 13 files changed, 29 insertions(+), 34 deletions(-) diff --git a/app/controllers/public/invite_controller.rb b/app/controllers/public/invite_controller.rb index b023a51..7e7fa51 100644 --- a/app/controllers/public/invite_controller.rb +++ b/app/controllers/public/invite_controller.rb @@ -8,12 +8,7 @@ class InviteController < PublicController @import_from = params[:import_from] || "manual" @mail_template = params[:mail_template] || environment.invitation_mail_template(profile) - extra_labels = Profile::SEARCHABLE_FIELDS.keys - [:name, :identifier, :nickname] - labels = [ - _('Name'), - _('Username'), - _('Email'), - ] + extra_labels.map { |label| Profile.human_attribute_name(label) } + labels = Profile::SEARCHABLE_FIELDS.except(:nickname).merge(User::SEARCHABLE_FIELDS).map { |name,info| info[:label] } last = labels.pop label = labels.join(', ') @search_friend_fields = "#{label} #{_('or')} #{last}" diff --git a/app/models/article.rb b/app/models/article.rb index d667bce..c92166f 100644 --- a/app/models/article.rb +++ b/app/models/article.rb @@ -7,11 +7,11 @@ class Article < ActiveRecord::Base acts_as_having_image SEARCHABLE_FIELDS = { - :name => 10, - :abstract => 3, - :body => 2, - :slug => 1, - :filename => 1, + :name => {:label => _('Name'), :weight => 10}, + :abstract => {:label => _('Abstract'), :weight => 3}, + :body => {:label => _('Content'), :weight => 2}, + :slug => {:label => _('Slug'), :weight => 1}, + :filename => {:label => _('Filename'), :weight => 1}, } SEARCH_FILTERS = %w[ diff --git a/app/models/category.rb b/app/models/category.rb index 11da1a8..0aeec31 100644 --- a/app/models/category.rb +++ b/app/models/category.rb @@ -3,10 +3,10 @@ class Category < ActiveRecord::Base attr_accessible :name, :parent_id, :display_color, :display_in_menu, :image_builder, :environment, :parent SEARCHABLE_FIELDS = { - :name => 10, - :acronym => 5, - :abbreviation => 5, - :slug => 1, + :name => {:label => _('Name'), :weight => 10}, + :acronym => {:label => _('Acronym'), :weight => 5}, + :abbreviation => {:label => _('Abbreviation'), :weight => 5}, + :slug => {:label => _('Slug'), :weight => 1}, } validates_exclusion_of :slug, :in => [ 'index' ], :message => N_('{fn} cannot be like that.').fix_i18n diff --git a/app/models/certifier.rb b/app/models/certifier.rb index bb08b59..0412d3e 100644 --- a/app/models/certifier.rb +++ b/app/models/certifier.rb @@ -3,9 +3,9 @@ class Certifier < ActiveRecord::Base attr_accessible :name, :environment SEARCHABLE_FIELDS = { - :name => 10, - :description => 3, - :link => 1, + :name => {:label => _('Name'), :weight => 10}, + :description => {:label => _('Description'), :weight => 3}, + :link => {:label => _('Link'), :weight => 1}, } belongs_to :environment diff --git a/app/models/comment.rb b/app/models/comment.rb index e41b932..94b50a2 100644 --- a/app/models/comment.rb +++ b/app/models/comment.rb @@ -1,9 +1,9 @@ class Comment < ActiveRecord::Base SEARCHABLE_FIELDS = { - :title => 10, - :name => 4, - :body => 2, + :title => {:label => _('Title'), :weight => 10}, + :name => {:label => _('Name'), :weight => 4}, + :body => {:label => _('Content'), :weight => 2}, } attr_accessible :body, :author, :name, :email, :title, :reply_of_id, :source diff --git a/app/models/license.rb b/app/models/license.rb index 9ba32ae..6e25375 100644 --- a/app/models/license.rb +++ b/app/models/license.rb @@ -3,8 +3,8 @@ class License < ActiveRecord::Base attr_accessible :name, :url SEARCHABLE_FIELDS = { - :name => 10, - :url => 5, + :name => {:label => _('Name'), :weight => 10}, + :url => {:label => _('URL'), :weight => 5}, } belongs_to :environment diff --git a/app/models/national_region.rb b/app/models/national_region.rb index 6990986..ca1b2a0 100644 --- a/app/models/national_region.rb +++ b/app/models/national_region.rb @@ -1,8 +1,8 @@ class NationalRegion < ActiveRecord::Base SEARCHABLE_FIELDS = { - :name => 1, - :national_region_code => 1, + :name => {:label => _('Name'), :weight => 1}, + :national_region_code => {:label => _('Region Code'), :weight => 1}, } def self.search_city(city_name, like = false, state = nil) diff --git a/app/models/product.rb b/app/models/product.rb index 7a8070e..bacd63c 100644 --- a/app/models/product.rb +++ b/app/models/product.rb @@ -1,8 +1,8 @@ class Product < ActiveRecord::Base SEARCHABLE_FIELDS = { - :name => 10, - :description => 1, + :name => {:label => _('Name'), :weight => 10}, + :description => {:label => _('Description'), :weight => 1}, } SEARCH_FILTERS = %w[ diff --git a/app/models/profile.rb b/app/models/profile.rb index b14e593..2a06ec9 100644 --- a/app/models/profile.rb +++ b/app/models/profile.rb @@ -12,9 +12,9 @@ class Profile < ActiveRecord::Base end SEARCHABLE_FIELDS = { - :name => 10, - :identifier => 5, - :nickname => 2, + :name => {:label => _('Name'), :weight => 10}, + :identifier => {:label => _('Username'), :weight => 5}, + :nickname => {:label => _('Nickname'), :weight => 2}, } SEARCH_FILTERS = %w[ diff --git a/app/models/qualifier.rb b/app/models/qualifier.rb index 2f62cfb..8469971 100644 --- a/app/models/qualifier.rb +++ b/app/models/qualifier.rb @@ -3,7 +3,7 @@ class Qualifier < ActiveRecord::Base attr_accessible :name, :environment SEARCHABLE_FIELDS = { - :name => 1, + :name => {:label => _('Name'), :weight => 1}, } belongs_to :environment diff --git a/app/models/scrap.rb b/app/models/scrap.rb index 6f0e640..c1a48f5 100644 --- a/app/models/scrap.rb +++ b/app/models/scrap.rb @@ -3,7 +3,7 @@ class Scrap < ActiveRecord::Base attr_accessible :content, :sender_id, :receiver_id, :scrap_id SEARCHABLE_FIELDS = { - :content => 1, + :content => {:label => _('Content'), :weight => 1}, } validates_presence_of :content validates_presence_of :sender_id, :receiver_id diff --git a/app/models/user.rb b/app/models/user.rb index 5785c0c..f47df09 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -12,7 +12,7 @@ class User < ActiveRecord::Base N_('Terms accepted') SEARCHABLE_FIELDS = { - :email => 5, + :email => {:label => _('Email'), :weight => 5}, } def self.[](login) diff --git a/plugins/stoa/lib/ext/person.rb b/plugins/stoa/lib/ext/person.rb index 2d6aa2e..4c2de54 100644 --- a/plugins/stoa/lib/ext/person.rb +++ b/plugins/stoa/lib/ext/person.rb @@ -3,7 +3,7 @@ require_dependency 'person' class Person attr_accessible :usp_id, :invitation_code - SEARCHABLE_FIELDS[:usp_id] = 5 + SEARCHABLE_FIELDS[:usp_id] = {:label => _('USP Number'), :weight => 5} validates_uniqueness_of :usp_id, :allow_nil => true settings_items :invitation_code -- libgit2 0.21.2