Class: UserPreference
Constant Summary
collapse
- TEXTAREA_FONT_OPTIONS =
['monospace', 'proportional']
- DEFAULT_TOOLBAR_LANGUAGE_OPTIONS =
%w[c cpp csharp css diff go groovy html java javascript objc perl php python r ruby sass scala shell sql swift xml yaml]
- AUTO_WATCH_ON_OPTIONS =
%w[issue_created issue_contributed_to]
Instance Method Summary
collapse
#delete_unsafe_attributes, included, #safe_attribute?, #safe_attribute_names, #safe_attributes=
human_attribute_name
Constructor Details
#initialize(attributes = nil, *args) ⇒ UserPreference
Returns a new instance of UserPreference.
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
|
# File 'app/models/user_preference.rb', line 49
def initialize(attributes=nil, *args)
super
if new_record?
unless attributes && attributes.key?(:hide_mail)
self.hide_mail = Setting.default_users_hide_mail?
end
unless attributes && attributes.key?(:time_zone)
self.time_zone = Setting.default_users_time_zone
end
unless attributes && attributes.key?(:no_self_notified)
self.no_self_notified = Setting.default_users_no_self_notified
end
unless attributes && attributes.key?(:auto_watch_on)
self.auto_watch_on = AUTO_WATCH_ON_OPTIONS
end
end
self.others ||= {}
end
|
Instance Method Details
#[](attr_name) ⇒ Object
72
73
74
75
76
77
78
|
# File 'app/models/user_preference.rb', line 72
def [](attr_name)
if has_attribute? attr_name
super
else
others ? others[attr_name] : nil
end
end
|
#[]=(attr_name, value) ⇒ Object
80
81
82
83
84
85
86
87
88
89
|
# File 'app/models/user_preference.rb', line 80
def []=(attr_name, value)
if has_attribute? attr_name
super
else
h = (read_attribute(:others) || {}).dup
h.update(attr_name => value)
write_attribute(:others, h)
value
end
end
|
#activity_scope ⇒ Object
103
|
# File 'app/models/user_preference.rb', line 103
def activity_scope; Array(self[:activity_scope]); end
|
#activity_scope=(value) ⇒ Object
104
|
# File 'app/models/user_preference.rb', line 104
def activity_scope=(value); self[:activity_scope]=value; end
|
#add_block(block) ⇒ Object
Adds block to the user page layout Returns nil if block is not valid or if it’s already present in the user page layout
179
180
181
182
183
184
185
186
187
188
|
# File 'app/models/user_preference.rb', line 179
def add_block(block)
block = block.to_s.underscore
return unless Redmine::MyPage.valid_block?(block, my_page_layout.values.flatten)
remove_block(block)
group = my_page_groups.first
my_page_layout[group] ||= []
my_page_layout[group].unshift(block)
end
|
#auto_watch_on ⇒ Object
132
|
# File 'app/models/user_preference.rb', line 132
def auto_watch_on; self[:auto_watch_on] || []; end
|
#auto_watch_on=(values) ⇒ Object
133
|
# File 'app/models/user_preference.rb', line 133
def auto_watch_on=(values); self[:auto_watch_on]=values; end
|
#auto_watch_on?(action) ⇒ Boolean
134
|
# File 'app/models/user_preference.rb', line 134
def auto_watch_on?(action); self.auto_watch_on.include?(action.to_s); end
|
91
|
# File 'app/models/user_preference.rb', line 91
def ; self[:comments_sorting]; end
|
92
|
# File 'app/models/user_preference.rb', line 92
def (order); self[:comments_sorting]=order; end
|
#default_issue_query ⇒ Object
126
|
# File 'app/models/user_preference.rb', line 126
def default_issue_query; self[:default_issue_query] end
|
#default_issue_query=(value) ⇒ Object
127
|
# File 'app/models/user_preference.rb', line 127
def default_issue_query=(value); self[:default_issue_query]=value; end
|
#default_project_query ⇒ Object
129
|
# File 'app/models/user_preference.rb', line 129
def default_project_query; self[:default_project_query] end
|
#default_project_query=(value) ⇒ Object
130
|
# File 'app/models/user_preference.rb', line 130
def default_project_query=(value); self[:default_project_query]=value; end
|
#history_default_tab ⇒ Object
111
|
# File 'app/models/user_preference.rb', line 111
def history_default_tab; self[:history_default_tab]; end
|
#history_default_tab=(value) ⇒ Object
112
|
# File 'app/models/user_preference.rb', line 112
def history_default_tab=(value); self[:history_default_tab]=value; end
|
#my_page_groups ⇒ Object
Returns the names of groups that are displayed on user’s page Example:
preferences.my_page_groups
140
141
142
|
# File 'app/models/user_preference.rb', line 140
def my_page_groups
Redmine::MyPage.groups
end
|
#my_page_layout ⇒ Object
144
145
146
|
# File 'app/models/user_preference.rb', line 144
def my_page_layout
self[:my_page_layout] ||= Redmine::MyPage.default_layout.deep_dup
end
|
#my_page_layout=(arg) ⇒ Object
148
149
150
|
# File 'app/models/user_preference.rb', line 148
def my_page_layout=(arg)
self[:my_page_layout] = arg
end
|
#my_page_settings(block = nil) ⇒ Object
152
153
154
155
156
157
158
159
|
# File 'app/models/user_preference.rb', line 152
def my_page_settings(block=nil)
s = self[:my_page_settings] ||= {}
if block
s[block] ||= {}
else
s
end
end
|
#my_page_settings=(arg) ⇒ Object
161
162
163
|
# File 'app/models/user_preference.rb', line 161
def my_page_settings=(arg)
self[:my_page_settings] = arg
end
|
#no_self_notified ⇒ Object
97
|
# File 'app/models/user_preference.rb', line 97
def no_self_notified; (self[:no_self_notified] == true || self[:no_self_notified] == '1'); end
|
#no_self_notified=(value) ⇒ Object
98
|
# File 'app/models/user_preference.rb', line 98
def no_self_notified=(value); self[:no_self_notified]=value; end
|
#notify_about_high_priority_issues ⇒ Object
100
|
# File 'app/models/user_preference.rb', line 100
def notify_about_high_priority_issues; (self[:notify_about_high_priority_issues] == true || self[:notify_about_high_priority_issues] == '1'); end
|
#notify_about_high_priority_issues=(value) ⇒ Object
101
|
# File 'app/models/user_preference.rb', line 101
def notify_about_high_priority_issues=(value); self[:notify_about_high_priority_issues]=value; end
|
#order_blocks(group, blocks) ⇒ Object
Sets the block order for the given group. Example:
preferences.order_blocks('left', ['issueswatched', 'news'])
193
194
195
196
197
198
199
200
|
# File 'app/models/user_preference.rb', line 193
def order_blocks(group, blocks)
group = group.to_s
if Redmine::MyPage.groups.include?(group) && blocks.present?
blocks = blocks.map(&:underscore) & my_page_layout.values.flatten
blocks.each {|block| remove_block(block)}
my_page_layout[group] = blocks
end
end
|
#recently_used_projects ⇒ Object
109
|
# File 'app/models/user_preference.rb', line 109
def recently_used_projects; (self[:recently_used_projects] || 3).to_i; end
|
#recently_used_projects=(value) ⇒ Object
110
|
# File 'app/models/user_preference.rb', line 110
def recently_used_projects=(value); self[:recently_used_projects] = value.to_i; end
|
#remove_block(block) ⇒ Object
Removes block from the user page layout Example:
preferences.remove_block('news')
168
169
170
171
172
173
174
|
# File 'app/models/user_preference.rb', line 168
def remove_block(block)
block = block.to_s.underscore
my_page_layout.each_key do |group|
my_page_layout[group].delete(block)
end
my_page_layout
end
|
#set_others_hash ⇒ Object
68
69
70
|
# File 'app/models/user_preference.rb', line 68
def set_others_hash
self.others ||= {}
end
|
#textarea_font ⇒ Object
106
|
# File 'app/models/user_preference.rb', line 106
def textarea_font; self[:textarea_font]; end
|
#textarea_font=(value) ⇒ Object
107
|
# File 'app/models/user_preference.rb', line 107
def textarea_font=(value); self[:textarea_font]=value; end
|
114
115
116
|
# File 'app/models/user_preference.rb', line 114
def toolbar_language_options
self[:toolbar_language_options].presence || DEFAULT_TOOLBAR_LANGUAGE_OPTIONS.join(',')
end
|
118
119
120
121
122
123
124
|
# File 'app/models/user_preference.rb', line 118
def toolbar_language_options=(value)
languages =
value.to_s.delete(' ').split(',').select do |lang|
Redmine::SyntaxHighlighting.language_supported?(lang)
end.compact
self[:toolbar_language_options] = languages.join(',')
end
|
#update_block_settings(block, settings) ⇒ Object
202
203
204
205
206
|
# File 'app/models/user_preference.rb', line 202
def update_block_settings(block, settings)
block = block.to_s
block_settings = my_page_settings(block).merge(settings.symbolize_keys)
my_page_settings[block] = block_settings
end
|
#warn_on_leaving_unsaved ⇒ Object
94
|
# File 'app/models/user_preference.rb', line 94
def warn_on_leaving_unsaved; self[:warn_on_leaving_unsaved] || '1'; end
|
#warn_on_leaving_unsaved=(value) ⇒ Object
95
|
# File 'app/models/user_preference.rb', line 95
def warn_on_leaving_unsaved=(value); self[:warn_on_leaving_unsaved]=value; end
|