Revision 1297:0a574315af3e .svn/pristine/90
| .svn/pristine/90/909b4c2f7af619477e53217e316d2fc57f7fba01.svn-base | ||
|---|---|---|
| 1 |
# encoding: utf-8 |
|
| 2 |
# |
|
| 3 |
# Redmine - project management software |
|
| 4 |
# Copyright (C) 2006-2012 Jean-Philippe Lang |
|
| 5 |
# |
|
| 6 |
# This program is free software; you can redistribute it and/or |
|
| 7 |
# modify it under the terms of the GNU General Public License |
|
| 8 |
# as published by the Free Software Foundation; either version 2 |
|
| 9 |
# of the License, or (at your option) any later version. |
|
| 10 |
# |
|
| 11 |
# This program is distributed in the hope that it will be useful, |
|
| 12 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
| 13 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
| 14 |
# GNU General Public License for more details. |
|
| 15 |
# |
|
| 16 |
# You should have received a copy of the GNU General Public License |
|
| 17 |
# along with this program; if not, write to the Free Software |
|
| 18 |
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
|
| 19 |
|
|
| 20 |
module QueriesHelper |
|
| 21 |
def filters_options_for_select(query) |
|
| 22 |
options_for_select(filters_options(query)) |
|
| 23 |
end |
|
| 24 |
|
|
| 25 |
def filters_options(query) |
|
| 26 |
options = [[]] |
|
| 27 |
sorted_options = query.available_filters.sort do |a, b| |
|
| 28 |
ord = 0 |
|
| 29 |
if !(a[1][:order] == 20 && b[1][:order] == 20) |
|
| 30 |
ord = a[1][:order] <=> b[1][:order] |
|
| 31 |
else |
|
| 32 |
cn = (CustomField::CUSTOM_FIELDS_NAMES.index(a[1][:field].class.name) <=> |
|
| 33 |
CustomField::CUSTOM_FIELDS_NAMES.index(b[1][:field].class.name)) |
|
| 34 |
if cn != 0 |
|
| 35 |
ord = cn |
|
| 36 |
else |
|
| 37 |
f = (a[1][:field] <=> b[1][:field]) |
|
| 38 |
if f != 0 |
|
| 39 |
ord = f |
|
| 40 |
else |
|
| 41 |
# assigned_to or author |
|
| 42 |
ord = (a[0] <=> b[0]) |
|
| 43 |
end |
|
| 44 |
end |
|
| 45 |
end |
|
| 46 |
ord |
|
| 47 |
end |
|
| 48 |
options += sorted_options.map do |field, field_options| |
|
| 49 |
[field_options[:name], field] |
|
| 50 |
end |
|
| 51 |
end |
|
| 52 |
|
|
| 53 |
def available_block_columns_tags(query) |
|
| 54 |
tags = ''.html_safe |
|
| 55 |
query.available_block_columns.each do |column| |
|
| 56 |
tags << content_tag('label', check_box_tag('c[]', column.name.to_s, query.has_column?(column)) + " #{column.caption}", :class => 'inline')
|
|
| 57 |
end |
|
| 58 |
tags |
|
| 59 |
end |
|
| 60 |
|
|
| 61 |
def column_header(column) |
|
| 62 |
column.sortable ? sort_header_tag(column.name.to_s, :caption => column.caption, |
|
| 63 |
:default_order => column.default_order) : |
|
| 64 |
content_tag('th', h(column.caption))
|
|
| 65 |
end |
|
| 66 |
|
|
| 67 |
def column_content(column, issue) |
|
| 68 |
value = column.value(issue) |
|
| 69 |
if value.is_a?(Array) |
|
| 70 |
value.collect {|v| column_value(column, issue, v)}.compact.join(', ').html_safe
|
|
| 71 |
else |
|
| 72 |
column_value(column, issue, value) |
|
| 73 |
end |
|
| 74 |
end |
|
| 75 |
|
|
| 76 |
def column_value(column, issue, value) |
|
| 77 |
case value.class.name |
|
| 78 |
when 'String' |
|
| 79 |
if column.name == :subject |
|
| 80 |
link_to(h(value), :controller => 'issues', :action => 'show', :id => issue) |
|
| 81 |
elsif column.name == :description |
|
| 82 |
issue.description? ? content_tag('div', textilizable(issue, :description), :class => "wiki") : ''
|
|
| 83 |
else |
|
| 84 |
h(value) |
|
| 85 |
end |
|
| 86 |
when 'Time' |
|
| 87 |
format_time(value) |
|
| 88 |
when 'Date' |
|
| 89 |
format_date(value) |
|
| 90 |
when 'Fixnum', 'Float' |
|
| 91 |
if column.name == :done_ratio |
|
| 92 |
progress_bar(value, :width => '80px') |
|
| 93 |
elsif column.name == :spent_hours |
|
| 94 |
sprintf "%.2f", value |
|
| 95 |
else |
|
| 96 |
h(value.to_s) |
|
| 97 |
end |
|
| 98 |
when 'User' |
|
| 99 |
link_to_user value |
|
| 100 |
when 'Project' |
|
| 101 |
link_to_project value |
|
| 102 |
when 'Version' |
|
| 103 |
link_to(h(value), :controller => 'versions', :action => 'show', :id => value) |
|
| 104 |
when 'TrueClass' |
|
| 105 |
l(:general_text_Yes) |
|
| 106 |
when 'FalseClass' |
|
| 107 |
l(:general_text_No) |
|
| 108 |
when 'Issue' |
|
| 109 |
link_to_issue(value, :subject => false) |
|
| 110 |
when 'IssueRelation' |
|
| 111 |
other = value.other_issue(issue) |
|
| 112 |
content_tag('span',
|
|
| 113 |
(l(value.label_for(issue)) + " " + link_to_issue(other, :subject => false, :tracker => false)).html_safe, |
|
| 114 |
:class => value.css_classes_for(issue)) |
|
| 115 |
else |
|
| 116 |
h(value) |
|
| 117 |
end |
|
| 118 |
end |
|
| 119 |
|
|
| 120 |
# Retrieve query from session or build a new query |
|
| 121 |
def retrieve_query |
|
| 122 |
if !params[:query_id].blank? |
|
| 123 |
cond = "project_id IS NULL" |
|
| 124 |
cond << " OR project_id = #{@project.id}" if @project
|
|
| 125 |
@query = Query.find(params[:query_id], :conditions => cond) |
|
| 126 |
raise ::Unauthorized unless @query.visible? |
|
| 127 |
@query.project = @project |
|
| 128 |
session[:query] = {:id => @query.id, :project_id => @query.project_id}
|
|
| 129 |
sort_clear |
|
| 130 |
elsif api_request? || params[:set_filter] || session[:query].nil? || session[:query][:project_id] != (@project ? @project.id : nil) |
|
| 131 |
# Give it a name, required to be valid |
|
| 132 |
@query = Query.new(:name => "_") |
|
| 133 |
@query.project = @project |
|
| 134 |
build_query_from_params |
|
| 135 |
session[:query] = {:project_id => @query.project_id, :filters => @query.filters, :group_by => @query.group_by, :column_names => @query.column_names}
|
|
| 136 |
else |
|
| 137 |
# retrieve from session |
|
| 138 |
@query = Query.find_by_id(session[:query][:id]) if session[:query][:id] |
|
| 139 |
@query ||= Query.new(:name => "_", :filters => session[:query][:filters], :group_by => session[:query][:group_by], :column_names => session[:query][:column_names]) |
|
| 140 |
@query.project = @project |
|
| 141 |
end |
|
| 142 |
end |
|
| 143 |
|
|
| 144 |
def retrieve_query_from_session |
|
| 145 |
if session[:query] |
|
| 146 |
if session[:query][:id] |
|
| 147 |
@query = Query.find_by_id(session[:query][:id]) |
|
| 148 |
return unless @query |
|
| 149 |
else |
|
| 150 |
@query = Query.new(:name => "_", :filters => session[:query][:filters], :group_by => session[:query][:group_by], :column_names => session[:query][:column_names]) |
|
| 151 |
end |
|
| 152 |
if session[:query].has_key?(:project_id) |
|
| 153 |
@query.project_id = session[:query][:project_id] |
|
| 154 |
else |
|
| 155 |
@query.project = @project |
|
| 156 |
end |
|
| 157 |
@query |
|
| 158 |
end |
|
| 159 |
end |
|
| 160 |
|
|
| 161 |
def build_query_from_params |
|
| 162 |
if params[:fields] || params[:f] |
|
| 163 |
@query.filters = {}
|
|
| 164 |
@query.add_filters(params[:fields] || params[:f], params[:operators] || params[:op], params[:values] || params[:v]) |
|
| 165 |
else |
|
| 166 |
@query.available_filters.keys.each do |field| |
|
| 167 |
@query.add_short_filter(field, params[field]) if params[field] |
|
| 168 |
end |
|
| 169 |
end |
|
| 170 |
@query.group_by = params[:group_by] || (params[:query] && params[:query][:group_by]) |
|
| 171 |
@query.column_names = params[:c] || (params[:query] && params[:query][:column_names]) |
|
| 172 |
end |
|
| 173 |
end |
|
| .svn/pristine/90/90aec66985f72f5aae2d43342147a899e2ef0d82.svn-base | ||
|---|---|---|
| 1 |
# Redmine - project management software |
|
| 2 |
# Copyright (C) 2006-2012 Jean-Philippe Lang |
|
| 3 |
# |
|
| 4 |
# This program is free software; you can redistribute it and/or |
|
| 5 |
# modify it under the terms of the GNU General Public License |
|
| 6 |
# as published by the Free Software Foundation; either version 2 |
|
| 7 |
# of the License, or (at your option) any later version. |
|
| 8 |
# |
|
| 9 |
# This program is distributed in the hope that it will be useful, |
|
| 10 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
| 11 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
| 12 |
# GNU General Public License for more details. |
|
| 13 |
# |
|
| 14 |
# You should have received a copy of the GNU General Public License |
|
| 15 |
# along with this program; if not, write to the Free Software |
|
| 16 |
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
|
| 17 |
|
|
| 18 |
class Message < ActiveRecord::Base |
|
| 19 |
include Redmine::SafeAttributes |
|
| 20 |
belongs_to :board |
|
| 21 |
belongs_to :author, :class_name => 'User', :foreign_key => 'author_id' |
|
| 22 |
acts_as_tree :counter_cache => :replies_count, :order => "#{Message.table_name}.created_on ASC"
|
|
| 23 |
acts_as_attachable |
|
| 24 |
belongs_to :last_reply, :class_name => 'Message', :foreign_key => 'last_reply_id' |
|
| 25 |
|
|
| 26 |
acts_as_searchable :columns => ['subject', 'content'], |
|
| 27 |
:include => {:board => :project},
|
|
| 28 |
:project_key => "#{Board.table_name}.project_id",
|
|
| 29 |
:date_column => "#{table_name}.created_on"
|
|
| 30 |
acts_as_event :title => Proc.new {|o| "#{o.board.name}: #{o.subject}"},
|
|
| 31 |
:description => :content, |
|
| 32 |
:type => Proc.new {|o| o.parent_id.nil? ? 'message' : 'reply'},
|
|
| 33 |
:url => Proc.new {|o| {:controller => 'messages', :action => 'show', :board_id => o.board_id}.merge(o.parent_id.nil? ? {:id => o.id} :
|
|
| 34 |
{:id => o.parent_id, :r => o.id, :anchor => "message-#{o.id}"})}
|
|
| 35 |
|
|
| 36 |
acts_as_activity_provider :find_options => {:include => [{:board => :project}, :author]},
|
|
| 37 |
:author_key => :author_id |
|
| 38 |
acts_as_watchable |
|
| 39 |
|
|
| 40 |
validates_presence_of :board, :subject, :content |
|
| 41 |
validates_length_of :subject, :maximum => 255 |
|
| 42 |
validate :cannot_reply_to_locked_topic, :on => :create |
|
| 43 |
|
|
| 44 |
after_create :add_author_as_watcher, :reset_counters! |
|
| 45 |
after_update :update_messages_board |
|
| 46 |
after_destroy :reset_counters! |
|
| 47 |
|
|
| 48 |
scope :visible, lambda {|*args| { :include => {:board => :project},
|
|
| 49 |
:conditions => Project.allowed_to_condition(args.shift || User.current, :view_messages, *args) } } |
|
| 50 |
|
|
| 51 |
safe_attributes 'subject', 'content' |
|
| 52 |
safe_attributes 'locked', 'sticky', 'board_id', |
|
| 53 |
:if => lambda {|message, user|
|
|
| 54 |
user.allowed_to?(:edit_messages, message.project) |
|
| 55 |
} |
|
| 56 |
|
|
| 57 |
def visible?(user=User.current) |
|
| 58 |
!user.nil? && user.allowed_to?(:view_messages, project) |
|
| 59 |
end |
|
| 60 |
|
|
| 61 |
def cannot_reply_to_locked_topic |
|
| 62 |
# Can not reply to a locked topic |
|
| 63 |
errors.add :base, 'Topic is locked' if root.locked? && self != root |
|
| 64 |
end |
|
| 65 |
|
|
| 66 |
def update_messages_board |
|
| 67 |
if board_id_changed? |
|
| 68 |
Message.update_all("board_id = #{board_id}", ["id = ? OR parent_id = ?", root.id, root.id])
|
|
| 69 |
Board.reset_counters!(board_id_was) |
|
| 70 |
Board.reset_counters!(board_id) |
|
| 71 |
end |
|
| 72 |
end |
|
| 73 |
|
|
| 74 |
def reset_counters! |
|
| 75 |
if parent && parent.id |
|
| 76 |
Message.update_all({:last_reply_id => parent.children.maximum(:id)}, {:id => parent.id})
|
|
| 77 |
end |
|
| 78 |
board.reset_counters! |
|
| 79 |
end |
|
| 80 |
|
|
| 81 |
def sticky=(arg) |
|
| 82 |
write_attribute :sticky, (arg == true || arg.to_s == '1' ? 1 : 0) |
|
| 83 |
end |
|
| 84 |
|
|
| 85 |
def sticky? |
|
| 86 |
sticky == 1 |
|
| 87 |
end |
|
| 88 |
|
|
| 89 |
def project |
|
| 90 |
board.project |
|
| 91 |
end |
|
| 92 |
|
|
| 93 |
def editable_by?(usr) |
|
| 94 |
usr && usr.logged? && (usr.allowed_to?(:edit_messages, project) || (self.author == usr && usr.allowed_to?(:edit_own_messages, project))) |
|
| 95 |
end |
|
| 96 |
|
|
| 97 |
def destroyable_by?(usr) |
|
| 98 |
usr && usr.logged? && (usr.allowed_to?(:delete_messages, project) || (self.author == usr && usr.allowed_to?(:delete_own_messages, project))) |
|
| 99 |
end |
|
| 100 |
|
|
| 101 |
private |
|
| 102 |
|
|
| 103 |
def add_author_as_watcher |
|
| 104 |
Watcher.create(:watchable => self.root, :user => author) |
|
| 105 |
end |
|
| 106 |
end |
|
| .svn/pristine/90/90f7a65e84d2b63722e9012f61a1bb240e2683ab.svn-base | ||
|---|---|---|
| 1 |
/* Finnish initialisation for the jQuery UI date picker plugin. */ |
|
| 2 |
/* Written by Harri Kilpiö (harrikilpio@gmail.com). */ |
|
| 3 |
jQuery(function($){
|
|
| 4 |
$.datepicker.regional['fi'] = {
|
|
| 5 |
closeText: 'Sulje', |
|
| 6 |
prevText: '«Edellinen', |
|
| 7 |
nextText: 'Seuraava»', |
|
| 8 |
currentText: 'Tänään', |
|
| 9 |
monthNames: ['Tammikuu','Helmikuu','Maaliskuu','Huhtikuu','Toukokuu','Kesäkuu', |
|
| 10 |
'Heinäkuu','Elokuu','Syyskuu','Lokakuu','Marraskuu','Joulukuu'], |
|
| 11 |
monthNamesShort: ['Tammi','Helmi','Maalis','Huhti','Touko','Kesä', |
|
| 12 |
'Heinä','Elo','Syys','Loka','Marras','Joulu'], |
|
| 13 |
dayNamesShort: ['Su','Ma','Ti','Ke','To','Pe','La'], |
|
| 14 |
dayNames: ['Sunnuntai','Maanantai','Tiistai','Keskiviikko','Torstai','Perjantai','Lauantai'], |
|
| 15 |
dayNamesMin: ['Su','Ma','Ti','Ke','To','Pe','La'], |
|
| 16 |
weekHeader: 'Vk', |
|
| 17 |
dateFormat: 'dd.mm.yy', |
|
| 18 |
firstDay: 1, |
|
| 19 |
isRTL: false, |
|
| 20 |
showMonthAfterYear: false, |
|
| 21 |
yearSuffix: ''}; |
|
| 22 |
$.datepicker.setDefaults($.datepicker.regional['fi']); |
|
| 23 |
}); |
|
Also available in: Unified diff