diff options
author | Jean-Philippe Lang <jp_lang@yahoo.fr> | 2006-12-05 20:45:04 +0000 |
---|---|---|
committer | Jean-Philippe Lang <jp_lang@yahoo.fr> | 2006-12-05 20:45:04 +0000 |
commit | 96f83cc8f0f032554f771a59da22303cd473b878 (patch) | |
tree | 355a0d2ed653a5426c59ebf6a1fe65eba024b4d0 /app/helpers | |
parent | eabc04d8368824965d3ac8de3fa84502e9c05d38 (diff) | |
download | redmine-96f83cc8f0f032554f771a59da22303cd473b878.tar.gz redmine-96f83cc8f0f032554f771a59da22303cd473b878.zip |
trunk moved from /trunk/redmine to /trunk
git-svn-id: http://redmine.rubyforge.org/svn/trunk@67 e93f8b46-1217-0410-a6f0-8f06a7374b81
Diffstat (limited to 'app/helpers')
24 files changed, 999 insertions, 0 deletions
diff --git a/app/helpers/account_helper.rb b/app/helpers/account_helper.rb new file mode 100644 index 000000000..e18ab6ff4 --- /dev/null +++ b/app/helpers/account_helper.rb @@ -0,0 +1,19 @@ +# redMine - project management software
+# Copyright (C) 2006 Jean-Philippe Lang
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License
+# as published by the Free Software Foundation; either version 2
+# of the License, or (at your option) any later version.
+#
+# 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.
+
+module AccountHelper +end diff --git a/app/helpers/admin_helper.rb b/app/helpers/admin_helper.rb new file mode 100644 index 000000000..db2777392 --- /dev/null +++ b/app/helpers/admin_helper.rb @@ -0,0 +1,19 @@ +# redMine - project management software
+# Copyright (C) 2006 Jean-Philippe Lang
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License
+# as published by the Free Software Foundation; either version 2
+# of the License, or (at your option) any later version.
+#
+# 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.
+
+module AdminHelper +end diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb new file mode 100644 index 000000000..0f0deeb30 --- /dev/null +++ b/app/helpers/application_helper.rb @@ -0,0 +1,179 @@ +# redMine - project management software
+# Copyright (C) 2006 Jean-Philippe Lang
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License
+# as published by the Free Software Foundation; either version 2
+# of the License, or (at your option) any later version.
+#
+# 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.
+
+module ApplicationHelper
+
+ # Return current logged in user or nil
+ def loggedin?
+ @logged_in_user
+ end
+
+ # Return true if user is logged in and is admin, otherwise false
+ def admin_loggedin?
+ @logged_in_user and @logged_in_user.admin?
+ end
+
+ # Return true if user is authorized for controller/action, otherwise false
+ def authorize_for(controller, action)
+ # check if action is allowed on public projects
+ if @project.is_public? and Permission.allowed_to_public "%s/%s" % [ controller, action ]
+ return true
+ end
+ # check if user is authorized
+ if @logged_in_user and (@logged_in_user.admin? or Permission.allowed_to_role( "%s/%s" % [ controller, action ], @logged_in_user.role_for_project(@project.id) ) )
+ return true
+ end
+ return false
+ end
+
+ # Display a link if user is authorized
+ def link_to_if_authorized(name, options = {}, html_options = nil, *parameters_for_method_reference)
+ link_to(name, options, html_options, *parameters_for_method_reference) if authorize_for(options[:controller], options[:action])
+ end
+
+ # Display a link to user's account page
+ def link_to_user(user)
+ link_to user.display_name, :controller => 'account', :action => 'show', :id => user
+ end
+
+ def format_date(date)
+ l_date(date) if date
+ end
+
+ def format_time(time)
+ l_datetime(time) if time
+ end
+
+ def day_name(day)
+ l(:general_day_names).split(',')[day-1]
+ end
+
+ def pagination_links_full(paginator, options={}, html_options={})
+ html = ''
+ html << link_to_remote(('« ' + l(:label_previous)),
+ {:update => "content", :url => { :page => paginator.current.previous }},
+ {:href => url_for(:action => 'list', :params => @params.merge({:page => paginator.current.previous}))}) + ' ' if paginator.current.previous
+
+ html << (pagination_links_each(paginator, options) do |n|
+ link_to_remote(n.to_s,
+ {:url => {:action => 'list', :params => @params.merge({:page => n})}, :update => 'content'},
+ {:href => url_for(:action => 'list', :params => @params.merge({:page => n}))})
+ end || '')
+
+ html << ' ' + link_to_remote((l(:label_next) + ' »'),
+ {:update => "content", :url => { :page => paginator.current.next }},
+ {:href => url_for(:action => 'list', :params => @params.merge({:page => paginator.current.next}))}) if paginator.current.next
+ html
+ end
+
+ def textilizable(text)
+ $RDM_TEXTILE_DISABLED ? text : RedCloth.new(text).to_html
+ end
+
+ def error_messages_for(object_name, options = {})
+ options = options.symbolize_keys
+ object = instance_variable_get("@#{object_name}")
+ if object && !object.errors.empty?
+ # build full_messages here with controller current language
+ full_messages = []
+ object.errors.each do |attr, msg|
+ next if msg.nil?
+ if attr == "base"
+ full_messages << l(msg)
+ else
+ full_messages << "« " + (l_has_string?("field_" + attr) ? l("field_" + attr) : object.class.human_attribute_name(attr)) + " » " + l(msg) unless attr == "custom_values"
+ end
+ end
+ # retrieve custom values error messages
+ if object.errors[:custom_values]
+ object.custom_values.each do |v|
+ v.errors.each do |attr, msg|
+ next if msg.nil?
+ full_messages << "« " + v.custom_field.name + " » " + l(msg)
+ end
+ end
+ end
+ content_tag("div",
+ content_tag(
+ options[:header_tag] || "h2", lwr(:gui_validation_error, full_messages.length) + " :"
+ ) +
+ content_tag("ul", full_messages.collect { |msg| content_tag("li", msg) }),
+ "id" => options[:id] || "errorExplanation", "class" => options[:class] || "errorExplanation"
+ )
+ else
+ ""
+ end
+ end
+
+ def lang_options_for_select
+ (GLoc.valid_languages.sort {|x,y| x.to_s <=> y.to_s }).collect {|lang| [ l_lang_name(lang.to_s, lang), lang.to_s]}
+ end
+
+ def label_tag_for(name, option_tags = nil, options = {})
+ label_text = l(("field_"+field.to_s.gsub(/\_id$/, "")).to_sym) + (options.delete(:required) ? @template.content_tag("span", " *", :class => "required"): "")
+ content_tag("label", label_text)
+ end
+
+ def labelled_tabular_form_for(name, object, options, &proc)
+ options[:html] ||= {}
+ options[:html].store :class, "tabular"
+ form_for(name, object, options.merge({ :builder => TabularFormBuilder, :lang => current_language}), &proc)
+ end
+
+ def check_all_links(form_name)
+ link_to_function(l(:button_check_all), "checkAll('#{form_name}', true)") +
+ " | " +
+ link_to_function(l(:button_uncheck_all), "checkAll('#{form_name}', false)")
+ end
+
+ def calendar_for(field_id)
+ image_tag("calendar", {:id => "#{field_id}_trigger",:class => "calendar-trigger"}) +
+ javascript_tag("Calendar.setup({inputField : '#{field_id}', ifFormat : '%Y-%m-%d', button : '#{field_id}_trigger' });")
+ end
+end +
+class TabularFormBuilder < ActionView::Helpers::FormBuilder
+ include GLoc
+
+ def initialize(object_name, object, template, options, proc)
+ set_language_if_valid options.delete(:lang)
+ @object_name, @object, @template, @options, @proc = object_name, object, template, options, proc
+ end
+
+ (field_helpers - %w(radio_button hidden_field) + %w(date_select)).each do |selector|
+ src = <<-END_SRC
+ def #{selector}(field, options = {})
+ label_text = l(("field_"+field.to_s.gsub(/\_id$/, "")).to_sym) + (options.delete(:required) ? @template.content_tag("span", " *", :class => "required"): "")
+ label = @template.content_tag("label", label_text,
+ :class => (@object.errors[field] ? "error" : nil),
+ :for => (@object_name.to_s + "_" + field.to_s))
+ label + super
+ end
+ END_SRC
+ class_eval src, __FILE__, __LINE__
+ end
+
+ def select(field, choices, options = {})
+ label_text = l(("field_"+field.to_s.gsub(/\_id$/, "")).to_sym) + (options.delete(:required) ? @template.content_tag("span", " *", :class => "required"): "")
+ label = @template.content_tag("label", label_text,
+ :class => (@object.errors[field] ? "error" : nil),
+ :for => (@object_name.to_s + "_" + field.to_s))
+ label + super
+ end
+
+end
+
diff --git a/app/helpers/auth_sources_helper.rb b/app/helpers/auth_sources_helper.rb new file mode 100644 index 000000000..d47e9856a --- /dev/null +++ b/app/helpers/auth_sources_helper.rb @@ -0,0 +1,19 @@ +# redMine - project management software +# Copyright (C) 2006 Jean-Philippe Lang +# +# This program is free software; you can redistribute it and/or +# modify it under the terms of the GNU General Public License +# as published by the Free Software Foundation; either version 2 +# of the License, or (at your option) any later version. +# +# 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. + +module AuthSourcesHelper +end diff --git a/app/helpers/custom_fields_helper.rb b/app/helpers/custom_fields_helper.rb new file mode 100644 index 000000000..9df5c50a3 --- /dev/null +++ b/app/helpers/custom_fields_helper.rb @@ -0,0 +1,77 @@ +# redMine - project management software
+# Copyright (C) 2006 Jean-Philippe Lang
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License
+# as published by the Free Software Foundation; either version 2
+# of the License, or (at your option) any later version.
+#
+# 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.
+
+module CustomFieldsHelper
+
+ # Return custom field html tag corresponding to its format
+ def custom_field_tag(custom_value)
+ custom_field = custom_value.custom_field
+ field_name = "custom_fields[#{custom_field.id}]"
+ field_id = "custom_fields_#{custom_field.id}"
+
+ case custom_field.field_format
+ when "string", "int"
+ text_field 'custom_value', 'value', :name => field_name, :id => field_id
+ when "date"
+ text_field('custom_value', 'value', :name => field_name, :id => field_id, :size => 10) +
+ calendar_for(field_id)
+ when "text"
+ text_area 'custom_value', 'value', :name => field_name, :id => field_id, :cols => 60, :rows => 3
+ when "bool"
+ check_box 'custom_value', 'value', :name => field_name, :id => field_id
+ when "list"
+ select 'custom_value', 'value', custom_field.possible_values.split('|'), { :include_blank => true }, :name => field_name, :id => field_id
+ end
+ end
+
+ # Return custom field label tag
+ def custom_field_label_tag(custom_value)
+ content_tag "label", custom_value.custom_field.name +
+ (custom_value.custom_field.is_required? ? " <span class=\"required\">*</span>" : ""),
+ :for => "custom_fields_#{custom_value.custom_field.id}",
+ :class => (custom_value.errors.empty? ? nil : "error" )
+ end
+
+ # Return custom field tag with its label tag
+ def custom_field_tag_with_label(custom_value)
+ custom_field_label_tag(custom_value) + custom_field_tag(custom_value)
+ end
+
+ # Return a string used to display a custom value
+ def show_value(custom_value)
+ return "" unless custom_value
+ format_value(custom_value.value, custom_value.custom_field.field_format)
+ end
+
+ # Return a string used to display a custom value
+ def format_value(value, field_format)
+ return "" unless value
+ case field_format
+ when "date"
+ value.empty? ? "" : l_date(value.to_date)
+ when "bool"
+ l_YesNo(value == "1")
+ else
+ value
+ end
+ end
+
+ # Return an array of custom field formats which can be used in select_tag
+ def custom_field_formats_for_select
+ CustomField::FIELD_FORMATS.keys.collect { |k| [ l(CustomField::FIELD_FORMATS[k]), k ] }
+ end +end diff --git a/app/helpers/documents_helper.rb b/app/helpers/documents_helper.rb new file mode 100644 index 000000000..c9897647d --- /dev/null +++ b/app/helpers/documents_helper.rb @@ -0,0 +1,19 @@ +# redMine - project management software
+# Copyright (C) 2006 Jean-Philippe Lang
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License
+# as published by the Free Software Foundation; either version 2
+# of the License, or (at your option) any later version.
+#
+# 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.
+
+module DocumentsHelper +end diff --git a/app/helpers/enumerations_helper.rb b/app/helpers/enumerations_helper.rb new file mode 100644 index 000000000..11a216a82 --- /dev/null +++ b/app/helpers/enumerations_helper.rb @@ -0,0 +1,19 @@ +# redMine - project management software
+# Copyright (C) 2006 Jean-Philippe Lang
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License
+# as published by the Free Software Foundation; either version 2
+# of the License, or (at your option) any later version.
+#
+# 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.
+
+module EnumerationsHelper +end diff --git a/app/helpers/help_helper.rb b/app/helpers/help_helper.rb new file mode 100644 index 000000000..bb629316c --- /dev/null +++ b/app/helpers/help_helper.rb @@ -0,0 +1,19 @@ +# redMine - project management software
+# Copyright (C) 2006 Jean-Philippe Lang
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License
+# as published by the Free Software Foundation; either version 2
+# of the License, or (at your option) any later version.
+#
+# 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.
+
+module HelpHelper +end diff --git a/app/helpers/ifpdf_helper.rb b/app/helpers/ifpdf_helper.rb new file mode 100644 index 000000000..a0dab0f94 --- /dev/null +++ b/app/helpers/ifpdf_helper.rb @@ -0,0 +1,48 @@ +# redMine - project management software
+# Copyright (C) 2006 Jean-Philippe Lang
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License
+# as published by the Free Software Foundation; either version 2
+# of the License, or (at your option) any later version.
+#
+# 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.
+
+require 'iconv'
+
+module IfpdfHelper
+
+ class IFPDF < FPDF
+
+ attr_accessor :footer_date
+
+ def Cell(w,h=0,txt='',border=0,ln=0,align='',fill=0,link='')
+ @ic ||= Iconv.new('ISO-8859-1', 'UTF-8')
+ txt = begin
+ @ic.iconv(txt)
+ rescue
+ txt
+ end
+ super w,h,txt,border,ln,align,fill,link
+ end
+
+ def Footer
+ SetFont('Helvetica', 'I', 8)
+ SetY(-15)
+ SetX(15)
+ Cell(0, 5, @footer_date, 0, 0, 'L')
+ SetY(-15)
+ SetX(-30)
+ Cell(0, 5, PageNo().to_s + '/{nb}', 0, 0, 'C')
+ end
+
+ end +
+end
diff --git a/app/helpers/issue_categories_helper.rb b/app/helpers/issue_categories_helper.rb new file mode 100644 index 000000000..997d830d7 --- /dev/null +++ b/app/helpers/issue_categories_helper.rb @@ -0,0 +1,19 @@ +# redMine - project management software
+# Copyright (C) 2006 Jean-Philippe Lang
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License
+# as published by the Free Software Foundation; either version 2
+# of the License, or (at your option) any later version.
+#
+# 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.
+
+module IssueCategoriesHelper +end diff --git a/app/helpers/issue_statuses_helper.rb b/app/helpers/issue_statuses_helper.rb new file mode 100644 index 000000000..17704b7ba --- /dev/null +++ b/app/helpers/issue_statuses_helper.rb @@ -0,0 +1,19 @@ +# redMine - project management software
+# Copyright (C) 2006 Jean-Philippe Lang
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License
+# as published by the Free Software Foundation; either version 2
+# of the License, or (at your option) any later version.
+#
+# 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.
+
+module IssueStatusesHelper +end diff --git a/app/helpers/issues_helper.rb b/app/helpers/issues_helper.rb new file mode 100644 index 000000000..93bd6c050 --- /dev/null +++ b/app/helpers/issues_helper.rb @@ -0,0 +1,74 @@ +# redMine - project management software
+# Copyright (C) 2006 Jean-Philippe Lang
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License
+# as published by the Free Software Foundation; either version 2
+# of the License, or (at your option) any later version.
+#
+# 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.
+
+module IssuesHelper
+
+ def show_detail(detail, no_html=false)
+ case detail.property
+ when 'attr'
+ label = l(("field_" + detail.prop_key.to_s.gsub(/\_id$/, "")).to_sym)
+ case detail.prop_key
+ when 'due_date', 'start_date'
+ value = format_date(detail.value.to_date) if detail.value
+ old_value = format_date(detail.old_value.to_date) if detail.old_value
+ when 'status_id'
+ s = IssueStatus.find_by_id(detail.value) and value = s.name if detail.value
+ s = IssueStatus.find_by_id(detail.old_value) and old_value = s.name if detail.old_value
+ when 'assigned_to_id'
+ u = User.find_by_id(detail.value) and value = u.name if detail.value
+ u = User.find_by_id(detail.old_value) and old_value = u.name if detail.old_value
+ when 'priority_id'
+ e = Enumeration.find_by_id(detail.value) and value = e.name if detail.value
+ e = Enumeration.find_by_id(detail.old_value) and old_value = e.name if detail.old_value
+ when 'category_id'
+ c = IssueCategory.find_by_id(detail.value) and value = c.name if detail.value
+ c = IssueCategory.find_by_id(detail.old_value) and old_value = c.name if detail.old_value
+ when 'fixed_version_id'
+ v = Version.find_by_id(detail.value) and value = v.name if detail.value
+ v = Version.find_by_id(detail.old_value) and old_value = v.name if detail.old_value
+ end
+ when 'cf'
+ custom_field = CustomField.find_by_id(detail.prop_key)
+ if custom_field
+ label = custom_field.name
+ value = format_value(detail.value, custom_field.field_format) if detail.value
+ old_value = format_value(detail.old_value, custom_field.field_format) if detail.old_value
+ end
+ end
+
+ label ||= detail.prop_key
+ value ||= detail.value
+ old_value ||= detail.old_value
+
+ unless no_html
+ label = content_tag('strong', label)
+ old_value = content_tag("i", old_value) if old_value
+ old_value = content_tag("strike", old_value) if old_value and !value
+ value = content_tag("i", value) if value
+ end
+
+ if value
+ if old_value
+ label + " " + l(:text_journal_changed, old_value, value)
+ else
+ label + " " + l(:text_journal_set_to, value)
+ end
+ else
+ label + " " + l(:text_journal_deleted) + " (#{old_value})"
+ end
+ end +end diff --git a/app/helpers/members_helper.rb b/app/helpers/members_helper.rb new file mode 100644 index 000000000..8bf90913d --- /dev/null +++ b/app/helpers/members_helper.rb @@ -0,0 +1,19 @@ +# redMine - project management software
+# Copyright (C) 2006 Jean-Philippe Lang
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License
+# as published by the Free Software Foundation; either version 2
+# of the License, or (at your option) any later version.
+#
+# 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.
+
+module MembersHelper +end diff --git a/app/helpers/my_helper.rb b/app/helpers/my_helper.rb new file mode 100644 index 000000000..9098f67bc --- /dev/null +++ b/app/helpers/my_helper.rb @@ -0,0 +1,19 @@ +# redMine - project management software +# Copyright (C) 2006 Jean-Philippe Lang +# +# This program is free software; you can redistribute it and/or +# modify it under the terms of the GNU General Public License +# as published by the Free Software Foundation; either version 2 +# of the License, or (at your option) any later version. +# +# 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. + +module MyHelper +end diff --git a/app/helpers/news_helper.rb b/app/helpers/news_helper.rb new file mode 100644 index 000000000..f4a633f4b --- /dev/null +++ b/app/helpers/news_helper.rb @@ -0,0 +1,19 @@ +# redMine - project management software
+# Copyright (C) 2006 Jean-Philippe Lang
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License
+# as published by the Free Software Foundation; either version 2
+# of the License, or (at your option) any later version.
+#
+# 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.
+
+module NewsHelper +end diff --git a/app/helpers/projects_helper.rb b/app/helpers/projects_helper.rb new file mode 100644 index 000000000..0c85ce24c --- /dev/null +++ b/app/helpers/projects_helper.rb @@ -0,0 +1,19 @@ +# redMine - project management software
+# Copyright (C) 2006 Jean-Philippe Lang
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License
+# as published by the Free Software Foundation; either version 2
+# of the License, or (at your option) any later version.
+#
+# 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.
+
+module ProjectsHelper +end diff --git a/app/helpers/reports_helper.rb b/app/helpers/reports_helper.rb new file mode 100644 index 000000000..ed7fd7884 --- /dev/null +++ b/app/helpers/reports_helper.rb @@ -0,0 +1,32 @@ +# redMine - project management software
+# Copyright (C) 2006 Jean-Philippe Lang
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License
+# as published by the Free Software Foundation; either version 2
+# of the License, or (at your option) any later version.
+#
+# 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.
+
+module ReportsHelper
+
+ def aggregate(data, criteria)
+ a = 0
+ data.each { |row|
+ match = 1
+ criteria.each { |k, v|
+ match = 0 unless row[k].to_s == v.to_s
+ } unless criteria.nil?
+ a = a + row["total"].to_i if match == 1
+ } unless data.nil?
+ a
+ end
+ +end diff --git a/app/helpers/roles_helper.rb b/app/helpers/roles_helper.rb new file mode 100644 index 000000000..8ae339053 --- /dev/null +++ b/app/helpers/roles_helper.rb @@ -0,0 +1,19 @@ +# redMine - project management software
+# Copyright (C) 2006 Jean-Philippe Lang
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License
+# as published by the Free Software Foundation; either version 2
+# of the License, or (at your option) any later version.
+#
+# 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.
+
+module RolesHelper +end diff --git a/app/helpers/search_filter_helper.rb b/app/helpers/search_filter_helper.rb new file mode 100644 index 000000000..f17ffeebf --- /dev/null +++ b/app/helpers/search_filter_helper.rb @@ -0,0 +1,106 @@ +# redMine - project management software
+# Copyright (C) 2006 Jean-Philippe Lang
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License
+# as published by the Free Software Foundation; either version 2
+# of the License, or (at your option) any later version.
+#
+# 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.
+
+module SearchFilterHelper
+
+ def search_filter_criteria(name, options = {})
+ @search_filter ||= {}
+ @search_filter[name] ||= {}
+ @search_filter[name][:options] = []
+ @search_filter[name][:conditions] = {}
+ yield.each { |c|
+ @search_filter[name][:options] << [c[0], c[1].to_s]
+ @search_filter[name][:conditions].store(c[1].to_s, c[2])
+ }
+ end
+
+ def search_filter_update
+ session[:search_filter] ||= {}
+ @search_filter.each_key {|field| session[:search_filter][field] = params[field] }
+ end
+
+ def search_filter_clause
+ session[:search_filter] ||= {}
+ clause = ["1=1"]
+ @search_filter.each { |k, v|
+ filter_value = session[:search_filter][k] || v[:options][0][1]
+ if v[:conditions][filter_value]
+ clause[0] = clause[0] + " AND " + v[:conditions][filter_value].first
+ clause += v[:conditions][filter_value][1..-1]
+ end
+ }
+ clause
+ end
+
+ def search_filter_tag(criteria, options = {})
+ session[:search_filter] ||= {}
+ options[:name] = criteria
+ options[:class] += " active-filter" if session[:search_filter][criteria] and session[:search_filter][criteria] != @search_filter[criteria][:options][0][1]
+ content_tag("select",
+ options_for_select(@search_filter[criteria][:options], session[:search_filter][criteria]),
+ options
+ )
+ end
+
+ def search_filter_init_list_issues
+ search_filter_criteria('status_id') {
+ [ [('['+l(:label_open_issues_plural)+']'), "O", ["issue_statuses.is_closed=?", false]],
+ [('['+l(:label_closed_issues_plural)+']'), "C", ["issue_statuses.is_closed=?", true]],
+ [('['+l(:label_all)+']'), "A", nil]
+ ] + IssueStatus.find(:all).collect {|s| [s.name, s.id, ["issues.status_id=?", s.id]] }
+ }
+
+ search_filter_criteria('tracker_id') {
+ [ [('['+l(:label_all)+']'), "A", nil]
+ ] + Tracker.find(:all).collect {|s| [s.name, s.id, ["issues.tracker_id=?", s.id]] }
+ }
+
+ search_filter_criteria('priority_id') {
+ [ [('['+l(:label_all)+']'), "A", nil]
+ ] + Enumeration.find(:all, :conditions => ['opt=?','IPRI']).collect {|s| [s.name, s.id, ["issues.priority_id=?", s.id]] }
+ }
+
+ search_filter_criteria('category_id') {
+ [ [('['+l(:label_all)+']'), "A", nil],
+ [('['+l(:label_none)+']'), "N", ["issues.category_id is null"]]
+ ] + @project.issue_categories.find(:all).collect {|s| [s.name, s.id, ["issues.category_id=?", s.id]] }
+ }
+
+ search_filter_criteria('fixed_version_id') {
+ [ [('['+l(:label_all)+']'), "A", nil],
+ [('['+l(:label_none)+']'), "N", ["issues.fixed_version_id is null"]]
+ ] + @project.versions.collect {|s| [s.name, s.id, ["issues.fixed_version_id=?", s.id]] }
+ }
+
+ search_filter_criteria('author_id') {
+ [ [('['+l(:label_all)+']'), "A", nil],
+ ] + @project.users.collect {|s| [s.display_name, s.id, ["issues.author_id=?", s.id]] }
+ }
+
+ search_filter_criteria('assigned_to_id') {
+ [ [('['+l(:label_all)+']'), "A", nil],
+ [('['+l(:label_none)+']'), "N", ["issues.assigned_to_id is null"]]
+ ] + @project.users.collect {|s| [s.display_name, s.id, ["issues.assigned_to_id=?", s.id]] }
+ }
+
+ search_filter_criteria('subproject_id') {
+ [ [('['+l(:label_none)+']'), "N", ["issues.project_id=?", @project.id]],
+ [('['+l(:label_all)+']'), "A", ["(issues.project_id=? or projects.parent_id=?)", @project.id, @project.id]]
+ ]
+ }
+ end
+end
\ No newline at end of file diff --git a/app/helpers/sort_helper.rb b/app/helpers/sort_helper.rb new file mode 100644 index 000000000..04a84c8e4 --- /dev/null +++ b/app/helpers/sort_helper.rb @@ -0,0 +1,160 @@ +# Helpers to sort tables using clickable column headers. +# +# Author: Stuart Rackham <srackham@methods.co.nz>, March 2005. +# License: This source code is released under the MIT license. +# +# - Consecutive clicks toggle the column's sort order. +# - Sort state is maintained by a session hash entry. +# - Icon image identifies sort column and state. +# - Typically used in conjunction with the Pagination module. +# +# Example code snippets: +# +# Controller: +# +# helper :sort +# include SortHelper +# +# def list +# sort_init 'last_name' +# sort_update +# @items = Contact.find_all nil, sort_clause +# end +# +# Controller (using Pagination module): +# +# helper :sort +# include SortHelper +# +# def list +# sort_init 'last_name' +# sort_update +# @contact_pages, @items = paginate :contacts, +# :order_by => sort_clause, +# :per_page => 10 +# end +# +# View (table header in list.rhtml): +# +# <thead> +# <tr> +# <%= sort_header_tag('id', :title => 'Sort by contact ID') %> +# <%= sort_header_tag('last_name', :caption => 'Name') %> +# <%= sort_header_tag('phone') %> +# <%= sort_header_tag('address', :width => 200) %> +# </tr> +# </thead> +# +# - The ascending and descending sort icon images are sort_asc.png and +# sort_desc.png and reside in the application's images directory. +# - Introduces instance variables: @sort_name, @sort_default. +# - Introduces params :sort_key and :sort_order. +# +module SortHelper + + # Initializes the default sort column (default_key) and sort order + # (default_order). + # + # - default_key is a column attribute name. + # - default_order is 'asc' or 'desc'. + # - name is the name of the session hash entry that stores the sort state, + # defaults to '<controller_name>_sort'. + # + def sort_init(default_key, default_order='asc', name=nil) + @sort_name = name || @params[:controller] + @params[:action] + '_sort' + @sort_default = {:key => default_key, :order => default_order} + end + + # Updates the sort state. Call this in the controller prior to calling + # sort_clause. + # + def sort_update() + if @params[:sort_key] + sort = {:key => @params[:sort_key], :order => @params[:sort_order]} + elsif @session[@sort_name] + sort = @session[@sort_name] # Previous sort. + else + sort = @sort_default + end + @session[@sort_name] = sort + end + + # Returns an SQL sort clause corresponding to the current sort state. + # Use this to sort the controller's table items collection. + # + def sort_clause() + @session[@sort_name][:key] + ' ' + @session[@sort_name][:order] + end + + # Returns a link which sorts by the named column. + # + # - column is the name of an attribute in the sorted record collection. + # - The optional caption explicitly specifies the displayed link text. + # - A sort icon image is positioned to the right of the sort link. + # + def sort_link(column, caption=nil) + key, order = @session[@sort_name][:key], @session[@sort_name][:order] + if key == column + if order.downcase == 'asc' + icon = 'sort_asc' + order = 'desc' + else + icon = 'sort_desc' + order = 'asc' + end + else + icon = nil + order = 'desc' # changed for desc order by default + end + caption = titleize(Inflector::humanize(column)) unless caption + params = {:params => {:sort_key => column, :sort_order => order}} + link_to_remote(caption, + {:update => "content", :url => { :sort_key => column, :sort_order => order}}, + {:href => url_for(:params => { :sort_key => column, :sort_order => order})}) + + (icon ? nbsp(2) + image_tag(icon) : '') + end + + # Returns a table header <th> tag with a sort link for the named column + # attribute. + # + # Options: + # :caption The displayed link name (defaults to titleized column name). + # :title The tag's 'title' attribute (defaults to 'Sort by :caption'). + # + # Other options hash entries generate additional table header tag attributes. + # + # Example: + # + # <%= sort_header_tag('id', :title => 'Sort by contact ID', :width => 40) %> + # + # Renders: + # + # <th title="Sort by contact ID" width="40"> + # <a href="/contact/list?sort_order=desc&sort_key=id">Id</a> + # <img alt="Sort_asc" src="/images/sort_asc.png" /> + # </th> + # + def sort_header_tag(column, options = {}) + if options[:caption] + caption = options[:caption] + options.delete(:caption) + else + caption = titleize(Inflector::humanize(column)) + end + options[:title]= "Sort by #{caption}" unless options[:title] + content_tag('th', sort_link(column, caption), options) + end + + private + + # Return n non-breaking spaces. + def nbsp(n) + ' ' * n + end + + # Return capitalized title. + def titleize(title) + title.split.map {|w| w.capitalize }.join(' ') + end + +end diff --git a/app/helpers/trackers_helper.rb b/app/helpers/trackers_helper.rb new file mode 100644 index 000000000..839327efe --- /dev/null +++ b/app/helpers/trackers_helper.rb @@ -0,0 +1,19 @@ +# redMine - project management software
+# Copyright (C) 2006 Jean-Philippe Lang
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License
+# as published by the Free Software Foundation; either version 2
+# of the License, or (at your option) any later version.
+#
+# 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.
+
+module TrackersHelper +end diff --git a/app/helpers/users_helper.rb b/app/helpers/users_helper.rb new file mode 100644 index 000000000..035db3d00 --- /dev/null +++ b/app/helpers/users_helper.rb @@ -0,0 +1,19 @@ +# redMine - project management software
+# Copyright (C) 2006 Jean-Philippe Lang
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License
+# as published by the Free Software Foundation; either version 2
+# of the License, or (at your option) any later version.
+#
+# 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.
+
+module UsersHelper +end diff --git a/app/helpers/versions_helper.rb b/app/helpers/versions_helper.rb new file mode 100644 index 000000000..e2724fe84 --- /dev/null +++ b/app/helpers/versions_helper.rb @@ -0,0 +1,19 @@ +# redMine - project management software
+# Copyright (C) 2006 Jean-Philippe Lang
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License
+# as published by the Free Software Foundation; either version 2
+# of the License, or (at your option) any later version.
+#
+# 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.
+
+module VersionsHelper +end diff --git a/app/helpers/welcome_helper.rb b/app/helpers/welcome_helper.rb new file mode 100644 index 000000000..cace5f542 --- /dev/null +++ b/app/helpers/welcome_helper.rb @@ -0,0 +1,19 @@ +# redMine - project management software
+# Copyright (C) 2006 Jean-Philippe Lang
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License
+# as published by the Free Software Foundation; either version 2
+# of the License, or (at your option) any later version.
+#
+# 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.
+
+module WelcomeHelper +end |