translation_center 1.6.10 → 1.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- NzYxMGNlNTM2ZDE2MTczZTAzM2VlYzA0NjJhM2ZmYWQ0N2RkZTczMg==
4
+ MTg1YzRkNDU5ZGY0M2ZiMjAwMzExNTRlMTgxZjUwYzI3NjNhNThkNQ==
5
5
  data.tar.gz: !binary |-
6
- YmM4YjI1OTQ1NjM3NGVmMmQ0M2YzYmI3YjQ0MmZlZDQ1NjMwMzgzNQ==
6
+ MzYxOTMyNTQyMmE1MjUxMTIwZDhkOTFjMmM2ZGI3NzIzZjE0NDg3NA==
7
7
  !binary "U0hBNTEy":
8
8
  metadata.gz: !binary |-
9
- Yzc4NDJlNTNjNWNjYzM0MDVlNDJiYTRhYWFmOWRjNDQ4MDlhZjVmZDViYWE2
10
- OGY1ZGE0Y2MwOTgyNjM3OTkyZTYwNmFhYTM5ODUxMTExOTAxZTcwZmM2MTgy
11
- ZWEwMzNlODNlZmUyYTM0Y2Y2NDVjYzE1OTAzYjFlN2ZjODNlMjQ=
9
+ NjMxYzgyNWM5ZGEyM2ExZTBmNzA2MTQ3ZDM0Y2ZkMGJmODI0ZTk3Y2ZkZDdi
10
+ ZTBjZGUwZTZlZjY2ZmE1NGE5Y2M5ZGNmMTU1MTRhMzJiMzc2NGZkNmY5NzFl
11
+ YjU2ZDc0Y2EzYTg5MTIwMzk2MjdhNzZiMWI3Y2RjMTk2Mzc4MzM=
12
12
  data.tar.gz: !binary |-
13
- MDE3YmNhOGM5ZjhiNjUxOWI5ZGMzMzNjYWQ1M2ExNmNmYTc2ODAyOTIzMmY3
14
- NmExMDUzNjBhN2NhZjMzYTdlZDE4Njk4ZGU2NzU4OGQ0MDRkZTg1YjUyNGY1
15
- MTAyNjdjOWY0OTg0MjdkMTMxMTg2NzgzYjA2YmRiYjYyZmQ3NDU=
13
+ ODBjNGMzNGE1MzZjYTk0YTc1Mjk2OTM1ZDdhYmM4NzQ5ZWFmZmE0ZDY3ZTZi
14
+ ODA0MzhjMTMzNjUxOGY4Y2NmOWRjMjc2YWVkMzNhYWQ3NzNiNjEyMGJmNTZl
15
+ MGNmMDJlMWNjZWU5N2JiM2RkMzdiODEzZmYyZjUwNGNjOTE2NTM=
data/README.md CHANGED
@@ -76,17 +76,17 @@ And run the migrations
76
76
  rake db:migrate
77
77
  ```
78
78
 
79
- And then run this rake to get all current translations to the db
80
- ```ruby
81
- rake translation_center:synch
82
- ```
83
-
84
79
  Add this line to the translator model (typically `User`)
85
80
 
86
81
  ```ruby
87
82
  acts_as_translator
88
83
  ```
89
84
 
85
+ And then run this rake to get all current translations to the db
86
+ ```ruby
87
+ rake translation_center:synch
88
+ ```
89
+
90
90
  and change the `translator_type` in `translation_center.yml` to the translator model name (if it is `User` keep it commented)
91
91
 
92
92
  ```ruby
@@ -26,11 +26,13 @@ module TranslationCenter
26
26
  def dashboard
27
27
  @stats = TranslationKey.langs_stats
28
28
  @langs = @stats.keys
29
- # to be used for meta search
30
- @search = Audited::Adapters::ActiveRecord::Audit.search(params[:search])
29
+
30
+ # build an empty activity query
31
+ @activity_query = ActivityQuery.new(params[:activity_query])
32
+
31
33
  #TODO perpage constant should be put somewhere else
32
- @translations_changes = Translation.recent_changes.offset(Translation::CHANGES_PER_PAGE * (@page - 1)).limit(Translation::CHANGES_PER_PAGE)
33
- @total_pages = (Translation.recent_changes.count / (Translation::CHANGES_PER_PAGE * 1.0)).ceil
34
+ @translations_changes = @activity_query.activities.offset(Translation::CHANGES_PER_PAGE * (@page - 1)).limit(Translation::CHANGES_PER_PAGE)
35
+ @total_pages = (@activity_query.activities.count / (Translation::CHANGES_PER_PAGE * 1.0)).ceil
34
36
 
35
37
  respond_to do |format|
36
38
  format.html
@@ -39,8 +41,8 @@ module TranslationCenter
39
41
  end
40
42
 
41
43
  def search_activity
42
- @translations_changes = Translation.recent_changes(params[:search]).offset(Translation::CHANGES_PER_PAGE * (@page - 1)).limit(Translation::CHANGES_PER_PAGE)
43
- @total_pages = (Translation.recent_changes(params[:search]).count / (Translation::CHANGES_PER_PAGE * 1.0)).ceil
44
+ @translations_changes = ActivityQuery.new(params[:activity_query]).activities.offset(Translation::CHANGES_PER_PAGE * (@page - 1)).limit(Translation::CHANGES_PER_PAGE)
45
+ @total_pages = (ActivityQuery.new(params[:activity_query]).activities.count / (Translation::CHANGES_PER_PAGE * 1.0)).ceil
44
46
 
45
47
  respond_to do |format|
46
48
  format.js
@@ -11,5 +11,9 @@ module TranslationCenter
11
11
  "<span class=\"label label-info\">#{attribute}</span> has new value <span class=\"label label-success\">#{value}</span>".html_safe
12
12
  end
13
13
  end
14
+
15
+ def translator_identifier_placeholder
16
+ "#{TranslationCenter::CONFIG['translator_type']} #{TranslationCenter::CONFIG['identifier_type']}".upcase
17
+ end
14
18
  end
15
19
  end
@@ -0,0 +1,46 @@
1
+ module TranslationCenter
2
+ class ActivityQuery
3
+ extend ActiveModel::Naming
4
+ include ActiveModel::Conversion
5
+
6
+ attr_accessor :translation_key_name, :translator_identifier, :lang, :created_at_gteq, :created_at_lteq
7
+
8
+ def persisted?
9
+ false
10
+ end
11
+
12
+ def initialize args={}
13
+ args ||= {}
14
+ args.each do |k,v|
15
+ instance_variable_set("@#{k}", v) unless v.blank?
16
+ end
17
+ end
18
+
19
+ # retuns and ActiveRecord Relation of Audit(s) that matches this search criteria
20
+ def activities
21
+ query = Audited::Adapters::ActiveRecord::Audit.where(auditable_id: translation_ids).scoped
22
+ query = query.where("DATE(created_at) <= DATE(?)", created_at_lteq) unless created_at_lteq.blank?
23
+ query = query.where("DATE(created_at) >= DATE(?)", created_at_gteq) unless created_at_gteq.blank?
24
+ query.order('created_at DESC')
25
+ end
26
+
27
+ protected
28
+
29
+ # return translation ids that matches this search criteria
30
+ def translation_ids
31
+ query = Translation.scoped
32
+ query = query.where(lang: lang) unless lang.blank?
33
+ query = query.joins(:translation_key).where("translation_center_translation_keys.name LIKE ?", "%#{translation_key_name}%") unless translation_key_name.blank?
34
+
35
+ if translator_identifier
36
+ translator_class = TranslationCenter::CONFIG['translator_type'].camelize.constantize
37
+ translators_ids = translator_class.where("#{TranslationCenter::CONFIG['identifier_type']} LIKE ? ", "%#{translator_identifier}%").map(&:id)
38
+
39
+ query = query.where(translator_id: translators_ids)
40
+ end
41
+
42
+ query.map(&:id)
43
+ end
44
+
45
+ end
46
+ end
@@ -71,7 +71,8 @@ module TranslationCenter
71
71
  end
72
72
 
73
73
  # gets recent changes on translations
74
- def self.recent_changes(params = {})
74
+ # TODO: remove this method as it is not being used elsewhere
75
+ def self.recent_changes
75
76
  Audited::Adapters::ActiveRecord::Audit.where('auditable_type = ?', 'TranslationCenter::Translation').search(params).relation.reorder('created_at DESC')
76
77
  end
77
78
 
@@ -34,15 +34,16 @@
34
34
  = distance_of_time_in_words_to_now change.created_at
35
35
  = t('.ago')
36
36
  .pagination
37
- = link_to t('pagination.first'), "#{request.protocol}#{request.host_with_port}#{request.fullpath.gsub('&page=' + @page.to_s, '')}?&page=1"
37
+ - query_without_page_param = request.query_string.gsub(/&?page=\d*/, '')
38
+ = link_to t('pagination.first'), "#{request.protocol}#{request.host_with_port}#{request.path}?#{query_without_page_param}&page=1"
38
39
  - if @page != 1
39
40
  |
40
- = link_to t('pagination.prev'), "#{request.protocol}#{request.host_with_port}#{request.fullpath.gsub('&page=' + @page.to_s, '')}?&page=#{@page - 1}"
41
+ = link_to t('pagination.prev'), "#{request.protocol}#{request.host_with_port}#{request.path}?#{query_without_page_param}&page=#{@page - 1}"
41
42
  |
42
- = link_to t('pagination.next'), "#{request.protocol}#{request.host_with_port}#{request.fullpath.gsub('&page=' + @page.to_s, '')}?&page=#{@page + 1}"
43
+ = link_to t('pagination.next'), "#{request.protocol}#{request.host_with_port}#{request.path}?#{query_without_page_param}&page=#{@page + 1}"
43
44
  - if @page != @total_pages
44
45
  |
45
- = link_to t('pagination.last'), "#{request.protocol}#{request.host_with_port}#{request.fullpath.gsub('&page=' + @page.to_s, '')}?&page=#{@total_pages}"
46
+ = link_to t('pagination.last'), "#{request.protocol}#{request.host_with_port}#{request.path}?#{query_without_page_param}&page=#{@total_pages}"
46
47
  = @page
47
48
  = t('.of')
48
49
  = @total_pages
@@ -51,13 +51,13 @@
51
51
  %h1
52
52
  = t('.activity')
53
53
  .span12
54
-
55
- = form_for @search, url: :search_activity, html: { method: :get, id: :search_form, class: 'pull-left form-search' } do |f|
56
- = f.text_field 'auditable_TranslationCenter::Translation_type_translation_key_name_matches', class: 'search_field input-medium', placeholder: 'KEY'
57
54
 
58
- = f.select 'auditable_TranslationCenter::Translation_type_lang_equals', I18n.available_locales.collect { |locale| [locale.to_s, locale.to_s] }, {:include_blank => t('.select_locale')}, class: 'search_field'
55
+ = form_for @activity_query, url: :search_activity, html: { method: :get, id: :search_form, class: 'pull-left form-search' } do |f|
56
+ = f.text_field :translation_key_name, class: 'search_field input-medium', placeholder: 'KEY'
57
+
58
+ = f.select :lang, I18n.available_locales.collect { |locale| [locale.to_s, locale.to_s] }, {:include_blank => t('.select_locale')}, class: 'search_field'
59
59
 
60
- = f.text_field 'user_user_type_email_matches', class: 'search_field input-medium', placeholder: 'USER'
60
+ = f.text_field :translator_identifier, class: 'search_field input-medium', placeholder: translator_identifier_placeholder
61
61
 
62
62
  = f.text_field :created_at_gteq, class: 'search_field datepicker input-medium', placeholder: 'FROM DATE'
63
63
 
@@ -88,6 +88,13 @@
88
88
  return false;
89
89
  })
90
90
 
91
+ // hit search directly when pressing enter
92
+ $(".search_field").keyup(function(event){
93
+ if(event.keyCode == 13){
94
+ $('#search_activity').click();
95
+ }
96
+ });
97
+
91
98
 
92
99
 
93
100
 
@@ -6,7 +6,6 @@ require 'acts_as_votable'
6
6
  require 'ya2yaml'
7
7
  require 'font-awesome-rails'
8
8
  require 'audited-activerecord'
9
- require 'meta_search'
10
9
 
11
10
  module TranslationCenter
12
11
 
@@ -7,7 +7,8 @@ module TranslationCenter
7
7
 
8
8
  # if translator doesn't exist then create him
9
9
  if translator.blank?
10
- translator = TranslationCenter::CONFIG['translator_type'].camelize.constantize.new(TranslationCenter::CONFIG['identifier_type'] => TranslationCenter::CONFIG['yaml_translator_identifier'])
10
+ translator = TranslationCenter::CONFIG['translator_type'].camelize.constantize.new
11
+ translator.send "#{TranslationCenter::CONFIG['identifier_type']}=", TranslationCenter::CONFIG['yaml_translator_identifier']
11
12
  begin
12
13
  translator.save(validate: false)
13
14
  # needed if the user is using confirmable with devise
@@ -1,3 +1,3 @@
1
1
  module TranslationCenter
2
- VERSION = "1.6.10"
2
+ VERSION = "1.7.0"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: translation_center
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.6.10
4
+ version: 1.7.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - BadrIT
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2013-08-21 00:00:00.000000000 Z
13
+ date: 2013-08-25 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: rails
@@ -96,20 +96,6 @@ dependencies:
96
96
  - - ! '>='
97
97
  - !ruby/object:Gem::Version
98
98
  version: '0'
99
- - !ruby/object:Gem::Dependency
100
- name: meta_search
101
- requirement: !ruby/object:Gem::Requirement
102
- requirements:
103
- - - ! '>='
104
- - !ruby/object:Gem::Version
105
- version: '0'
106
- type: :runtime
107
- prerelease: false
108
- version_requirements: !ruby/object:Gem::Requirement
109
- requirements:
110
- - - ! '>='
111
- - !ruby/object:Gem::Version
112
- version: '0'
113
99
  - !ruby/object:Gem::Dependency
114
100
  name: font-awesome-rails
115
101
  requirement: !ruby/object:Gem::Requirement
@@ -171,6 +157,7 @@ files:
171
157
  - app/controllers/translation_center/center_controller.rb
172
158
  - app/controllers/translation_center/translations_controller.rb
173
159
  - app/controllers/translation_center/application_controller.rb
160
+ - app/models/translation_center/activity_query.rb
174
161
  - app/models/translation_center/translation_key.rb
175
162
  - app/models/translation_center/category.rb
176
163
  - app/models/translation_center/translation.rb