kanbanworkflowstimelinescrumrubyroadmapproject-planningproject-managementopenprojectangularissue-trackerifcgantt-chartganttbug-trackerboardsbcf
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
84 lines
2.6 KiB
84 lines
2.6 KiB
13 years ago
|
#-- encoding: UTF-8
|
||
|
#-- copyright
|
||
11 years ago
|
# OpenProject My Project Page Plugin
|
||
|
#
|
||
|
# Copyright (C) 2011-2014 the OpenProject Foundation (OPF)
|
||
13 years ago
|
#
|
||
|
# This program is free software; you can redistribute it and/or
|
||
11 years ago
|
# modify it under the terms of the GNU General Public License version 3.
|
||
13 years ago
|
#
|
||
11 years ago
|
# This program is distributed in the hope that it will be useful,
|
||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||
|
# GNU General Public License for more details.
|
||
|
#
|
||
|
# You should have received a copy of the GNU General Public License
|
||
|
# along with this program; if not, write to the Free Software
|
||
|
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||
|
#
|
||
|
# See doc/COPYRIGHT.md for more details.
|
||
13 years ago
|
#++
|
||
|
|
||
13 years ago
|
class MyProjectsOverview < ActiveRecord::Base
|
||
11 years ago
|
after_initialize :initialize_default_values
|
||
|
|
||
13 years ago
|
DEFAULTS = {
|
||
6 years ago
|
"left" => %w(project_description project_details work_package_tracking),
|
||
|
"right" => %w(members news_latest),
|
||
13 years ago
|
"top" => [],
|
||
8 years ago
|
"hidden" => []
|
||
6 years ago
|
}.freeze
|
||
13 years ago
|
|
||
7 years ago
|
def initialize_default_values
|
||
11 years ago
|
# attributes() creates a copy every time it is called, so better not use it in a loop
|
||
|
# (this is also why we send the default-values instead of just setting it on attributes)
|
||
7 years ago
|
attr = attributes
|
||
13 years ago
|
|
||
11 years ago
|
DEFAULTS.each_key do |attribute_name|
|
||
11 years ago
|
# mysql and postgres handle serialized arrays differently: This check initializes the defaults for both cases -
|
||
|
# this especially deals properly with the case where [] is written into the db and re-read ( which
|
||
|
# is not properly handled by a .blank?- check !!!)
|
||
7 years ago
|
send("#{attribute_name}=", DEFAULTS[attribute_name]) if attr[attribute_name].nil? || attr[attribute_name] == ""
|
||
13 years ago
|
end
|
||
13 years ago
|
end
|
||
|
|
||
13 years ago
|
serialize :top
|
||
|
serialize :left
|
||
|
serialize :right
|
||
|
serialize :hidden
|
||
13 years ago
|
belongs_to :project
|
||
|
|
||
13 years ago
|
validate :fields_are_arrays
|
||
|
|
||
6 years ago
|
acts_as_attachable delete_permission: :edit_project,
|
||
|
view_permission: :view_project,
|
||
|
add_permission: :edit_project
|
||
13 years ago
|
|
||
13 years ago
|
def fields_are_arrays
|
||
|
Array === top && Array === left && Array === right && Array === hidden
|
||
|
end
|
||
|
|
||
13 years ago
|
def save_custom_element(name, title, new_content)
|
||
7 years ago
|
el = custom_elements.detect { |x| x.first == name}
|
||
8 years ago
|
return false unless el
|
||
|
return false unless title && new_content
|
||
|
|
||
13 years ago
|
el[1] = title
|
||
|
el[2] = new_content
|
||
13 years ago
|
save
|
||
|
end
|
||
|
|
||
|
def new_custom_element
|
||
|
idx = custom_elements.any? ? custom_elements.sort.last.first.next : "a"
|
||
6 years ago
|
[idx, l(:label_custom_element), "### #{I18n.t(:info_custom_text)}"]
|
||
13 years ago
|
end
|
||
|
|
||
|
def elements
|
||
|
top + left + right + hidden
|
||
|
end
|
||
|
|
||
|
def custom_elements
|
||
7 years ago
|
elements.select { |x| x.respond_to? :to_ary }
|
||
13 years ago
|
end
|
||
13 years ago
|
end
|