Revision 912:5e80956cc792 lib/redmine/helpers

View differences:

lib/redmine/helpers/calendar.rb
1
# redMine - project management software
2
# Copyright (C) 2006-2007  Jean-Philippe Lang
1
# Redmine - project management software
2
# Copyright (C) 2006-2011  Jean-Philippe Lang
3 3
#
4 4
# This program is free software; you can redistribute it and/or
5 5
# modify it under the terms of the GNU General Public License
6 6
# as published by the Free Software Foundation; either version 2
7 7
# of the License, or (at your option) any later version.
8
# 
8
#
9 9
# This program is distributed in the hope that it will be useful,
10 10
# but WITHOUT ANY WARRANTY; without even the implied warranty of
11 11
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12 12
# GNU General Public License for more details.
13
# 
13
#
14 14
# You should have received a copy of the GNU General Public License
15 15
# along with this program; if not, write to the Free Software
16 16
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
17 17

  
18 18
module Redmine
19 19
  module Helpers
20
    
20

  
21 21
    # Simple class to compute the start and end dates of a calendar
22 22
    class Calendar
23 23
      include Redmine::I18n
24 24
      attr_reader :startdt, :enddt
25
      
25

  
26 26
      def initialize(date, lang = current_language, period = :month)
27 27
        @date = date
28 28
        @events = []
29 29
        @ending_events_by_days = {}
30 30
        @starting_events_by_days = {}
31
        set_language_if_valid lang        
31
        set_language_if_valid lang
32 32
        case period
33 33
        when :month
34 34
          @startdt = Date.civil(date.year, date.month, 1)
......
44 44
          raise 'Invalid period'
45 45
        end
46 46
      end
47
      
47

  
48 48
      # Sets calendar events
49 49
      def events=(events)
50 50
        @events = events
51 51
        @ending_events_by_days = @events.group_by {|event| event.due_date}
52 52
        @starting_events_by_days = @events.group_by {|event| event.start_date}
53 53
      end
54
      
54

  
55 55
      # Returns events for the given day
56 56
      def events_on(day)
57 57
        ((@ending_events_by_days[day] || []) + (@starting_events_by_days[day] || [])).uniq
58 58
      end
59
      
59

  
60 60
      # Calendar current month
61 61
      def month
62 62
        @date.month
63 63
      end
64
      
64

  
65 65
      # Return the first day of week
66 66
      # 1 = Monday ... 7 = Sunday
67 67
      def first_wday
......
76 76
          @first_dow ||= (l(:general_first_day_of_week).to_i - 1)%7 + 1
77 77
        end
78 78
      end
79
      
79

  
80 80
      def last_wday
81 81
        @last_dow ||= (first_wday + 5)%7 + 1
82 82
      end
83
    end    
83
    end
84 84
  end
85 85
end
lib/redmine/helpers/diff.rb
5 5
# modify it under the terms of the GNU General Public License
6 6
# as published by the Free Software Foundation; either version 2
7 7
# of the License, or (at your option) any later version.
8
# 
8
#
9 9
# This program is distributed in the hope that it will be useful,
10 10
# but WITHOUT ANY WARRANTY; without even the implied warranty of
11 11
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12 12
# GNU General Public License for more details.
13
# 
13
#
14 14
# You should have received a copy of the GNU General Public License
15 15
# along with this program; if not, write to the Free Software
16 16
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
......
22 22
      include ActionView::Helpers::TagHelper
23 23
      include ActionView::Helpers::TextHelper
24 24
      attr_reader :diff, :words
25
      
25

  
26 26
      def initialize(content_to, content_from)
27 27
        @words = content_to.to_s.split(/(\s+)/)
28 28
        @words = @words.select {|word| word != ' '}
29 29
        words_from = content_from.to_s.split(/(\s+)/)
30
        words_from = words_from.select {|word| word != ' '}    
30
        words_from = words_from.select {|word| word != ' '}
31 31
        @diff = words_from.diff @words
32 32
      end
33
  
33

  
34 34
      def to_html
35 35
        words = self.words.collect{|word| h(word)}
36 36
        words_add = 0
......
41 41
          add_at = nil
42 42
          add_to = nil
43 43
          del_at = nil
44
          deleted = ""      
44
          deleted = ""
45 45
          diff.each do |change|
46 46
            pos = change[1]
47 47
            if change[0] == "+"
......
65 65
            words_del = 0
66 66
          end
67 67
        end
68
        words.join(' ')
68
        words.join(' ').html_safe
69 69
      end
70 70
    end
71 71
  end
lib/redmine/helpers/gantt.rb
260 260
      def subject_for_project(project, options)
261 261
        case options[:format]
262 262
        when :html
263
          subject = "<span class='icon icon-projects #{project.overdue? ? 'project-overdue' : ''}'>"
264
          subject << view.link_to_project(project)
265
          subject << '</span>'
263
          subject = "<span class='icon icon-projects #{project.overdue? ? 'project-overdue' : ''}'>".html_safe
264
          subject << view.link_to_project(project).html_safe
265
          subject << '</span>'.html_safe
266 266
          html_subject(options, subject, :css => "project-name")
267 267
        when :image
268 268
          image_subject(options, project.name)
......
298 298
      def subject_for_version(version, options)
299 299
        case options[:format]
300 300
        when :html
301
          subject = "<span class='icon icon-package #{version.behind_schedule? ? 'version-behind-schedule' : ''} #{version.overdue? ? 'version-overdue' : ''}'>"
302
          subject << view.link_to_version(version)
303
          subject << '</span>'
301
          subject = "<span class='icon icon-package #{version.behind_schedule? ? 'version-behind-schedule' : ''} #{version.overdue? ? 'version-overdue' : ''}'>".html_safe
302
          subject << view.link_to_version(version).html_safe
303
          subject << '</span>'.html_safe
304 304
          html_subject(options, subject, :css => "version-name")
305 305
        when :image
306 306
          image_subject(options, version.to_s_with_project)
......
347 347
          css_classes << ' issue-behind-schedule' if issue.behind_schedule?
348 348
          css_classes << ' icon icon-issue' unless Setting.gravatar_enabled? && issue.assigned_to
349 349

  
350
          subject = "<span class='#{css_classes}'>"
350
          subject = "<span class='#{css_classes}'>".html_safe
351 351
          if issue.assigned_to.present?
352 352
            assigned_string = l(:field_assigned_to) + ": " + issue.assigned_to.name
353
            subject << view.avatar(issue.assigned_to, :class => 'gravatar icon-gravatar', :size => 10, :title => assigned_string).to_s
353
            subject << view.avatar(issue.assigned_to, :class => 'gravatar icon-gravatar', :size => 10, :title => assigned_string).to_s.html_safe
354 354
          end
355
          subject << view.link_to_issue(issue)
356
          subject << '</span>'
355
          subject << view.link_to_issue(issue).html_safe
356
          subject << '</span>'.html_safe
357 357
          html_subject(options, subject, :css => "issue-subject", :title => issue.subject) + "\n"
358 358
        when :image
359 359
          image_subject(options, issue.subject)
......
737 737
        output = ''
738 738
        # Renders the task bar, with progress and late
739 739
        if coords[:bar_start] && coords[:bar_end]
740
          output << "<div style='top:#{ params[:top] }px;left:#{ coords[:bar_start] }px;width:#{ coords[:bar_end] - coords[:bar_start] - 2}px;' class='#{options[:css]} task_todo'>&nbsp;</div>"
740
          output << "<div style='top:#{ params[:top] }px;left:#{ coords[:bar_start] }px;width:#{ coords[:bar_end] - coords[:bar_start] - 2}px;' class='#{options[:css]} task_todo'>&nbsp;</div>".html_safe
741 741

  
742 742
          if coords[:bar_late_end]
743
            output << "<div style='top:#{ params[:top] }px;left:#{ coords[:bar_start] }px;width:#{ coords[:bar_late_end] - coords[:bar_start] - 2}px;' class='#{options[:css]} task_late'>&nbsp;</div>"
743
            output << "<div style='top:#{ params[:top] }px;left:#{ coords[:bar_start] }px;width:#{ coords[:bar_late_end] - coords[:bar_start] - 2}px;' class='#{options[:css]} task_late'>&nbsp;</div>".html_safe
744 744
          end
745 745
          if coords[:bar_progress_end]
746
            output << "<div style='top:#{ params[:top] }px;left:#{ coords[:bar_start] }px;width:#{ coords[:bar_progress_end] - coords[:bar_start] - 2}px;' class='#{options[:css]} task_done'>&nbsp;</div>"
746
            output << "<div style='top:#{ params[:top] }px;left:#{ coords[:bar_start] }px;width:#{ coords[:bar_progress_end] - coords[:bar_start] - 2}px;' class='#{options[:css]} task_done'>&nbsp;</div>".html_safe
747 747
          end
748 748
        end
749 749
        # Renders the markers
750 750
        if options[:markers]
751 751
          if coords[:start]
752
            output << "<div style='top:#{ params[:top] }px;left:#{ coords[:start] }px;width:15px;' class='#{options[:css]} marker starting'>&nbsp;</div>"
752
            output << "<div style='top:#{ params[:top] }px;left:#{ coords[:start] }px;width:15px;' class='#{options[:css]} marker starting'>&nbsp;</div>".html_safe
753 753
          end
754 754
          if coords[:end]
755
            output << "<div style='top:#{ params[:top] }px;left:#{ coords[:end] + params[:zoom] }px;width:15px;' class='#{options[:css]} marker ending'>&nbsp;</div>"
755
            output << "<div style='top:#{ params[:top] }px;left:#{ coords[:end] + params[:zoom] }px;width:15px;' class='#{options[:css]} marker ending'>&nbsp;</div>".html_safe
756 756
          end
757 757
        end
758 758
        # Renders the label on the right
759 759
        if options[:label]
760
          output << "<div style='top:#{ params[:top] }px;left:#{ (coords[:bar_end] || 0) + 8 }px;' class='#{options[:css]} label'>"
760
          output << "<div style='top:#{ params[:top] }px;left:#{ (coords[:bar_end] || 0) + 8 }px;' class='#{options[:css]} label'>".html_safe
761 761
          output << options[:label]
762
          output << "</div>"
762
          output << "</div>".html_safe
763 763
        end
764 764
        # Renders the tooltip
765 765
        if options[:issue] && coords[:bar_start] && coords[:bar_end]
766
          output << "<div class='tooltip' style='position: absolute;top:#{ params[:top] }px;left:#{ coords[:bar_start] }px;width:#{ coords[:bar_end] - coords[:bar_start] }px;height:12px;'>"
767
          output << '<span class="tip">'
768
          output << view.render_issue_tooltip(options[:issue])
769
          output << "</span></div>"
766
          output << "<div class='tooltip' style='position: absolute;top:#{ params[:top] }px;left:#{ coords[:bar_start] }px;width:#{ coords[:bar_end] - coords[:bar_start] }px;height:12px;'>".html_safe
767
          output << '<span class="tip">'.html_safe
768
          output << view.render_issue_tooltip(options[:issue]).html_safe
769
          output << "</span></div>".html_safe
770 770
        end
771 771
        @lines << output
772 772
        output

Also available in: Unified diff