From 024d804a4a3518fa40fa46ea6cc60ff53f8da08b 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 32b316a..9d79369 100644 --- a/app/models/article.rb +++ b/app/models/article.rb @@ -5,11 +5,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 25f3f4f..6d0687e 100644 --- a/app/models/category.rb +++ b/app/models/category.rb @@ -1,10 +1,10 @@ class Category < ActiveRecord::Base 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 1292322..e1cd92e 100644 --- a/app/models/certifier.rb +++ b/app/models/certifier.rb @@ -1,9 +1,9 @@ class Certifier < ActiveRecord::Base 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 3275582..c1440ee 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}, } validates_presence_of :body diff --git a/app/models/license.rb b/app/models/license.rb index 3db2dba..4f1ddff 100644 --- a/app/models/license.rb +++ b/app/models/license.rb @@ -1,8 +1,8 @@ class License < ActiveRecord::Base 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 e06e4ba..bec3a32 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 d2f0606..64aca88 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 dd5e0ed..2efcc88 100644 --- a/app/models/profile.rb +++ b/app/models/profile.rb @@ -4,9 +4,9 @@ class Profile < ActiveRecord::Base 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 6ae55d0..9b0af8a 100644 --- a/app/models/qualifier.rb +++ b/app/models/qualifier.rb @@ -1,7 +1,7 @@ class Qualifier < ActiveRecord::Base 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 85d100a..be4175a 100644 --- a/app/models/scrap.rb +++ b/app/models/scrap.rb @@ -1,6 +1,6 @@ class Scrap < ActiveRecord::Base 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 ed33dd9..619e9f5 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -9,7 +9,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 5ccef85..5f2cce0 100644 --- a/plugins/stoa/lib/ext/person.rb +++ b/plugins/stoa/lib/ext/person.rb @@ -1,7 +1,7 @@ require_dependency 'person' class Person - 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