Class: UserPreference
Overview
Constant Summary
collapse
- TEXTAREA_FONT_OPTIONS =
['monospace', 'proportional']
Instance Method Summary
collapse
#delete_unsafe_attributes, #safe_attribute?, #safe_attribute_names, #safe_attributes=
Constructor Details
#initialize(attributes = nil, *args) ⇒ UserPreference
Returns a new instance of UserPreference
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
|
# File 'app/models/user_preference.rb', line 37
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 = true
end
end
self.others ||= {}
end
|
Instance Method Details
#[](attr_name) ⇒ Object
57
58
59
60
61
62
63
|
# File 'app/models/user_preference.rb', line 57
def [](attr_name)
if has_attribute? attr_name
super
else
others ? others[attr_name] : nil
end
end
|
#[]=(attr_name, value) ⇒ Object
65
66
67
68
69
70
71
72
73
74
|
# File 'app/models/user_preference.rb', line 65
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
85
|
# File 'app/models/user_preference.rb', line 85
def activity_scope; Array(self[:activity_scope]) ; end
|
#activity_scope=(value) ⇒ Object
86
|
# File 'app/models/user_preference.rb', line 86
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
134
135
136
137
138
139
140
141
142
143
|
# File 'app/models/user_preference.rb', line 134
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
|
76
|
# File 'app/models/user_preference.rb', line 76
def ; self[:comments_sorting] end
|
77
|
# File 'app/models/user_preference.rb', line 77
def (order); self[:comments_sorting]=order end
|
#my_page_groups ⇒ Object
Returns the names of groups that are displayed on user's page Example:
preferences.my_page_groups
95
96
97
|
# File 'app/models/user_preference.rb', line 95
def my_page_groups
Redmine::MyPage.groups
end
|
#my_page_layout ⇒ Object
99
100
101
|
# File 'app/models/user_preference.rb', line 99
def my_page_layout
self[:my_page_layout] ||= Redmine::MyPage.default_layout.deep_dup
end
|
#my_page_layout=(arg) ⇒ Object
103
104
105
|
# File 'app/models/user_preference.rb', line 103
def my_page_layout=(arg)
self[:my_page_layout] = arg
end
|
#my_page_settings(block = nil) ⇒ Object
107
108
109
110
111
112
113
114
|
# File 'app/models/user_preference.rb', line 107
def my_page_settings(block=nil)
s = self[:my_page_settings] ||= {}
if block
s[block] ||= {}
else
s
end
end
|
#my_page_settings=(arg) ⇒ Object
116
117
118
|
# File 'app/models/user_preference.rb', line 116
def my_page_settings=(arg)
self[:my_page_settings] = arg
end
|
#no_self_notified ⇒ Object
82
|
# File 'app/models/user_preference.rb', line 82
def no_self_notified; (self[:no_self_notified] == true || self[:no_self_notified] == '1'); end
|
#no_self_notified=(value) ⇒ Object
83
|
# File 'app/models/user_preference.rb', line 83
def no_self_notified=(value); self[:no_self_notified]=value; end
|
#order_blocks(group, blocks) ⇒ Object
Sets the block order for the given group. Example:
preferences.order_blocks('left', ['issueswatched', 'news'])
148
149
150
151
152
153
154
155
|
# File 'app/models/user_preference.rb', line 148
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
|
#remove_block(block) ⇒ Object
Removes block from the user page layout Example:
preferences.remove_block('news')
123
124
125
126
127
128
129
|
# File 'app/models/user_preference.rb', line 123
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
53
54
55
|
# File 'app/models/user_preference.rb', line 53
def set_others_hash
self.others ||= {}
end
|
#textarea_font ⇒ Object
88
|
# File 'app/models/user_preference.rb', line 88
def textarea_font; self[:textarea_font] end
|
#textarea_font=(value) ⇒ Object
89
|
# File 'app/models/user_preference.rb', line 89
def textarea_font=(value); self[:textarea_font]=value; end
|
#update_block_settings(block, settings) ⇒ Object
157
158
159
160
161
|
# File 'app/models/user_preference.rb', line 157
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
79
|
# File 'app/models/user_preference.rb', line 79
def warn_on_leaving_unsaved; self[:warn_on_leaving_unsaved] || '1'; end
|
#warn_on_leaving_unsaved=(value) ⇒ Object
80
|
# File 'app/models/user_preference.rb', line 80
def warn_on_leaving_unsaved=(value); self[:warn_on_leaving_unsaved]=value; end
|