Class: LesliBabel::String
- Inherits:
-
ApplicationRecord
- Object
- Lesli::ApplicationLesliRecord
- ApplicationRecord
- LesliBabel::String
- Defined in:
- app/models/lesli_babel/string.rb
Class Method Summary collapse
-
.index(current_user, query, params) ⇒ Object
enum prefix: { # database # controllers # models # views # components # elements.
-
.log_activity_create(current_user, string) ⇒ void
Example params = … string = CloudBabel::String.create(params) CloudBabel::String.log_activity_create(User.find(1), string).
-
.log_activity_destroy(current_user, string) ⇒ void
Example string = CloudBabel::String.find(1) CloudBabel::String.log_activity_show(User.find(1), string).
-
.log_activity_update(current_user, string, old_attributes, new_attributes) ⇒ void
Example string = CloudBabel::String.find(1) old_attributes = string.attributes.merge(string.detail.attributes) string.update(user_main: User.find(33)) new_attributes = string.attributes.merge(string.detail.attributes) CloudBabel::String.log_activity_update(User.find(1), string, old_attributes, new_attributes).
- .relevant(current_user, query, params) ⇒ Object
Instance Method Summary collapse
Class Method Details
.index(current_user, query, params) ⇒ Object
enum prefix: {
# database
# controllers
# models
# views
# components
# elements
column
enum
message
navigation
toolbar
button
chart
title
form
}
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'app/models/lesli_babel/string.rb', line 30 def self.index(current_user, query, params) strings = TranslationsService.strings(params[:module], params[:bucket]) # if search string was sent if params[:search] search = params[:search].downcase.gsub(" ","%") sql_where_condition = [] # add filter to select only available languages Rails.application.config.lesli_settings["configuration"]["locales"].each do |locale| sql_where_condition.push("LOWER(#{locale}) like :search") end sql_where_condition.push("LOWER(label) like :search") sql_where_condition.push("LOWER(context) like :search") # get strings with bucket and module information strings = strings.where(sql_where_condition.join(" OR "), { search: "%#{ search }%" }) end # filters by specif ids sent as query params if params["ids"] ids = params["ids"].split(',').map{ |id| id.to_i } strings = strings.where("cloud_babel_strings.id in (?)", ids) end strings = strings.select( :id, :label, :status, :context, :priority, :need_help, :need_translation, Rails.application.config.lesli_settings["configuration"]["locales"], "cloud_babel_modules.id as engine_id", "cloud_babel_buckets.id as bucket_id", "cloud_babel_buckets.name as bucket_name", "cloud_babel_modules.name as engine_name", "cloud_babel_modules.platform as platform", "'' as path" ) strings = strings .page(query[:pagination][:page]) .per(query[:pagination][:perPage]) .order(:updated_at) end |
.log_activity_create(current_user, string) ⇒ void
This method returns an undefined value.
Example
params = {...}
string = CloudBabel::String.create(params)
CloudBabel::String.log_activity_create(User.find(1), string)
150 151 152 153 154 155 156 |
# File 'app/models/lesli_babel/string.rb', line 150 def self.log_activity_create(current_user, string) string.activities.create( user_creator: current_user, category: "action_create", reference_module_bucket_string: "#{string.reference_module_bucket}-#{string.label}" ) end |
.log_activity_destroy(current_user, string) ⇒ void
This method returns an undefined value.
Example
string = CloudBabel::String.find(1)
CloudBabel::String.log_activity_show(User.find(1), string)
211 212 213 214 215 216 217 |
# File 'app/models/lesli_babel/string.rb', line 211 def self.log_activity_destroy(current_user, string) string.activities.create( user_creator: current_user, category: "action_destroy", reference_module_bucket_string: "#{string.reference_module_bucket}-#{string.label}" ) end |
.log_activity_update(current_user, string, old_attributes, new_attributes) ⇒ void
This method returns an undefined value.
Example
string = CloudBabel::String.find(1)
old_attributes = string.attributes.merge({detail_attributes: string.detail.attributes})
string.update(user_main: User.find(33))
new_attributes = string.attributes.merge({detail_attributes: string.detail.attributes})
CloudBabel::String.log_activity_update(User.find(1), string, old_attributes, new_attributes)
170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 |
# File 'app/models/lesli_babel/string.rb', line 170 def self.log_activity_update(current_user, string, old_attributes, new_attributes) # Bucket is a special case because it's a foreign key if old_attributes["cloud_babel_buckets_id"] != new_attributes["cloud_babel_buckets_id"] string.activities.create( user_creator: current_user, category: "action_update", field_name: "cloud_babel_buckets_id", value_from: Bucket.find(old_attributes["cloud_babel_buckets_id"]).name, value_to: Bucket.find(new_attributes["cloud_babel_buckets_id"]).name ) end # We exclude certain keys that are not relevant old_attributes.except!("id", "cloud_babe_buckets_id", "created_at", "updated_at", "deleted_at", "users_id") old_attributes.each do |key, value| if value != new_attributes[key] value_from = value value_to = new_attributes[key] value_from = LC::Date.to_string_datetime(value_from) if value_from.is_a?(Time) || value_from.is_a?(Date) value_to = LC::Date.to_string_datetime(value_to) if value_to.is_a?(Time) || value_to.is_a?(Date) string.activities.create( user_creator: current_user, category: "action_update", field_name: key, value_from: value_from, value_to: value_to, reference_module_bucket_string: "#{string.reference_module_bucket}-#{string.label}" ) end end end |
.relevant(current_user, query, params) ⇒ Object
85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 |
# File 'app/models/lesli_babel/string.rb', line 85 def self.relevant current_user, query, params # relevant strings: # - missing translation for available language # - need help # - need translation locale = query.dig(:order, :by) strings = [] sql_where_condition = [] # add filter to select if is available language if locale if Rails.application.config.lesli.dig(:configuration, :locales).include?(locale.to_s) sql_where_condition.push("#{locale.to_s} is NULL") sql_where_condition.push("#{locale.to_s} = ''") end else Rails.application.config.lesli.dig(:configuration, :locales).each do |locale| sql_where_condition.push("#{locale} is NULL") sql_where_condition.push("#{locale} = ''") end end sql_where_condition.push("need_help = TRUE") sql_where_condition.push("need_translation = TRUE") strings = TranslationsService.strings.where(sql_where_condition.join(" OR ")).select( :id, :label, :status, :context, :priority, :need_help, :need_translation, Rails.application.config.lesli_settings["configuration"]["locales"], "cloud_babel_modules.id as engine_id", "cloud_babel_buckets.id as bucket_id", "cloud_babel_buckets.name as bucket_name", "cloud_babel_modules.name as engine_name", "cloud_babel_modules.platform as platform", "'' as path" ) strings .page(query[:pagination][:page]) .per(query[:pagination][:perPage]) .order(query.dig(:order, :by)) end |
Instance Method Details
#path ⇒ Object
219 220 221 222 223 224 225 226 |
# File 'app/models/lesli_babel/string.rb', line 219 def path self[:engine_code] .downcase .concat(".") .concat(self[:bucket_code]) .concat(".") .concat(self[:label]) end |