Project

General

Profile

Feature #2024 » gantt_edit.trunk-r10055.diff

Toshi MARUYAMA, 2012-07-20 15:39

View differences:

app/controllers/gantts_controller.rb
45 45
      format.pdf  { send_data(@gantt.to_pdf, :type => 'application/pdf', :filename => "#{basename}.pdf") }
46 46
    end
47 47
  end
48

  
49
  def edit_gantt
50
    date_from = Date.parse(params[:date_from])
51
    date_to = Date.parse(params[:date_to])
52
    months = date_to.month - date_from.month + 1
53
    params[:year] = date_from.year
54
    params[:month] = date_from.month
55
    params[:months] = months
56
    @gantt = Redmine::Helpers::Gantt.new(params)
57
    @gantt.project = @project
58
    text, status = @gantt.edit(params)
59
    render :text=>text, :status=>status
60
  end
61

  
62
  def find_optional_project
63
    begin
64
      if params[:action] && params[:action].to_s == "edit_gantt"
65
        @project = Project.find(params[:project_id]) unless params[:project_id].blank?
66
        allowed = User.current.allowed_to?(:edit_issues, @project, :global => true)
67
        if allowed
68
          return true
69
        else
70
          render :text=>"lack of permission to edit issues", :status=>403
71
        end
72
      else
73
        super
74
      end
75
    rescue => e
76
      return e.to_s + "\n===\n" + [$!,$@.join("\n")].join("\n")
77
    end
78
  end
48 79
end
app/helpers/application_helper.rb
1051 1051
    javascript_tag("Calendar.setup({inputField : '#{field_id}', ifFormat : '%Y-%m-%d', button : '#{field_id}_trigger' });")
1052 1052
  end
1053 1053

  
1054
  def g_calendar_for(field_id)
1055
    include_calendar_headers_tags
1056
    image_tag("calendar.png", {:id => "#{field_id}_trigger",:class => "calendar-trigger"}) +
1057
    javascript_tag("Calendar.setup({inputField : '#{field_id}', electric : false, ifFormat : '%Y-%m-%d', button : '#{field_id}_trigger' });")
1058
  end
1059

  
1054 1060
  def include_calendar_headers_tags
1055 1061
    unless @calendar_headers_tags_included
1056 1062
      @calendar_headers_tags_included = true
app/helpers/issues_helper.rb
51 51
    link_to_issue(issue) + "<br /><br />".html_safe +
52 52
      "<strong>#{@cached_label_project}</strong>: #{link_to_project(issue.project)}<br />".html_safe +
53 53
      "<strong>#{@cached_label_status}</strong>: #{h(issue.status.name)}<br />".html_safe +
54
      "<strong>#{@cached_label_start_date}</strong>: #{format_date(issue.start_date)}<br />".html_safe +
55
      "<strong>#{@cached_label_due_date}</strong>: #{format_date(issue.due_date)}<br />".html_safe +
54
      "<strong>#{@cached_label_start_date}</strong>: <span id='tooltip_start_date_i#{issue.id}'>#{format_date(issue.start_date)}</span><br />".html_safe +
55
      "<strong>#{@cached_label_due_date}</strong>: <span id='tooltip_due_date_i#{issue.id}'>#{format_date(issue.due_date)}</span><br />".html_safe +
56 56
      "<strong>#{@cached_label_assigned_to}</strong>: #{h(issue.assigned_to)}<br />".html_safe +
57 57
      "<strong>#{@cached_label_priority}</strong>: #{h(issue.priority.name)}".html_safe
58 58
  end
app/models/issue.rb
756 756
    dependencies
757 757
  end
758 758

  
759
  def all_precedes_issues
760
    dependencies = []
761
    relations_from.each do |relation|
762
      next unless relation.relation_type == IssueRelation::TYPE_PRECEDES
763
      dependencies << relation.issue_to
764
      dependencies += relation.issue_to.all_dependent_issues
765
    end
766
    dependencies
767
  end
768

  
759 769
  # Returns an array of issues that duplicate this one
760 770
  def duplicates
761 771
    relations_to.select {|r| r.relation_type == IssueRelation::TYPE_DUPLICATES}.collect {|r| r.issue_from}
app/views/gantts/show.html.erb
1
<% include_calendar_headers_tags %>
1 2
<% @gantt.view = self %>
2 3
<h2><%= @query.new_record? ? l(:label_gantt) : h(@query.name) %></h2>
3 4

  
......
35 36
<% zoom = 1
36 37
@gantt.zoom.times { zoom = zoom * 2 }
37 38

  
38
subject_width = 330
39
subject_width = 280
39 40
header_heigth = 18
40 41

  
41 42
headers_height = header_heigth
......
62 63

  
63 64
%>
64 65

  
66
<input type="hidden" name="_date_from" id="i_date_from" value="<%=h(@gantt.date_from)%>" />
67
<input type="hidden" name="_date_to" id="i_date_to" value="<%=h(@gantt.date_to)%>" />
68
<input type="hidden" name="zm" id="i_zm" value="<%=zoom%>" />
69
<input type="hidden" name="pzm" id="i_pzm" value="<%=@gantt.zoom%>" />
70
<script type='text/javascript'>
71
  function issue_moved(elem) {
72
    var id_str = elem.id.substring(3, elem.id.length);
73
    var v_date_from = document.getElementById('i_date_from').getAttribute("value");
74
    var v_date_to = document.getElementById('i_date_to').getAttribute("value");
75
    var v_zm = document.getElementById('i_zm').getAttribute("value");
76
    var v_pzm = document.getElementById('i_pzm').getAttribute("value");
77
    var url_str = '<%=  url_for(:controller=>:gantts, :action => :edit_gantt) %>';
78
    url_str = url_str + "/" + id_str;
79
    var day = parseInt(elem.style.left)/parseInt(v_zm);
80
    new Ajax.Request(url_str, {asynchronous:true, evalScripts:true,
81
      parameters: 'day='+day+'&date_from='+v_date_from+'&date_to='+v_date_to+'&zoom='+v_pzm+"&project_id=<%= @project.to_param %>",
82
      onSuccess:function(obj) {
83
        change_dates(obj.responseText);
84
      },
85
      onFailure:function(obj) {
86
        handle_failure(obj.responseText);
87
      }
88
    });
89

  
90
  }
91

  
92
  function handle_failure(res_text) {
93
    var text = res_text.split('|');
94
    alert(text[0]);
95
    if (text.length == 1) {
96
      return;
97
    }
98
    change_dates(text[1]);//revert
99
  }
100

  
101
  function change_dates(issue_infos) {
102
    if (!issue_infos) {
103
      return;
104
    }
105
    var issue_list = issue_infos.split("|");
106
    for (i = 0; i < issue_list.length; i++) {
107
      change_date(issue_list[i]);
108
    }
109
  }
110

  
111
  function change_date(text) {
112
    if (!text) {
113
      return;
114
    }
115
    var issue_info = text.split("=");
116
    var elem_id = issue_info[0];
117
    var kind = elem_id.substring(0,1);
118
    var preClassName = "";
119
    if (kind == 'v') {
120
      preClassName = "version ";
121
    } else if (kind == 'p') {
122
      preClassName = "project ";
123
    }
124
    var vals = issue_info[1].split(',');
125
    var start_date_elem = document.getElementById(elem_id + '_start_date_str');
126
    if (!start_date_elem) {
127
      //target not exists
128
      return;
129
    }
130
    start_date_elem.innerHTML = vals[0];
131
    var tooltip_start_date_elem = document.getElementById('tooltip_start_date_' + elem_id);
132
    if (tooltip_start_date_elem) {
133
      tooltip_start_date_elem.innerHTML = vals[0];
134
    }
135
    var due_date_elem = document.getElementById(elem_id + '_due_date_str');
136
    if (due_date_elem) {
137
      due_date_elem.innerHTML = vals[2];
138
    }
139
    
140
    var tooltip_due_date_elem = document.getElementById('tooltip_due_date_' + elem_id);
141
    if (tooltip_due_date_elem) {
142
      tooltip_due_date_elem.innerHTML = vals[2];
143
    }
144
    
145
    var ev_elem = document.getElementById('ev_' + elem_id);
146
    if (ev_elem) {
147
      ev_elem.style.left = vals[4] + 'px';
148
      ev_elem.style.width = (parseInt(vals[5])+100)+'px';
149
    }
150
    var todo_elem = document.getElementById('task_todo_' + elem_id);
151
    if (todo_elem) {
152
      todo_elem.style.width = vals[5] + 'px';
153
    }
154
    
155
    var late_elem = document.getElementById('task_late_' + elem_id);
156
    if (late_elem) {
157
      var parentStr = "";
158
      if (late_elem.className.indexOf("parent") > 0) parentStr = "parent ";
159
      late_elem.style.width = vals[6] + 'px';
160
      if (vals[6] == '0') {
161
        late_elem.className = preClassName + 'task ' + parentStr + 'task_none';
162
      } else {
163
        late_elem.className = preClassName + 'task ' + parentStr + 'task_late';
164
      }
165
    }
166
    var done_elem = document.getElementById('task_done_' + elem_id);
167
    if (done_elem) {
168
      var parentStr = "";
169
      if (done_elem.className.indexOf("parent") > 0) parentStr = "parent ";
170
      done_elem.style.width = vals[7] + 'px';
171
      if (vals[7] == '0') {
172
        done_elem.className = preClassName + 'task ' + parentStr + 'task_none';
173
      } else {
174
        done_elem.className = preClassName + 'task ' + parentStr + 'task_done';
175
      }
176
    }
177
    var tooltip = document.getElementById("tt_" + elem_id);
178
    if (tooltip) {
179
      tooltip.style.left = ev_elem.style.left;
180
    }
181

  
182
    var label = document.getElementById("label_" + elem_id);
183
    if (label) {
184
      label.style.left = (parseInt(vals[4]) + parseInt(vals[5]) + 8) + 'px';
185
    }
186
    var marker_start = document.getElementById("marker_start_" + elem_id);
187
    if (marker_start && vals[8]) {
188
      marker_start.style.left = vals[8] + 'px';
189
    }
190
    var marker_end = document.getElementById("marker_end_" + elem_id);
191
    if (marker_end && vals[9]) {
192
      marker_end.style.left = vals[9] + 'px';
193
    }
194

  
195
    //change calendar date
196
    var elm1 = document.getElementById(elem_id+"_hidden_start_date");
197
    if (elm1) elm1.value = vals[1];
198
    var elm2 = document.getElementById(elem_id+"_start_date");
199
    if (elm2) elm2.value = vals[1];
200
    var elm3 = document.getElementById(elem_id+"_hidden_due_date");
201
    if (elm3) elm3.value = vals[3];
202
    var elm4 = document.getElementById(elem_id+"_due_date");
203
    if (elm4) elm4.value = vals[3];
204
  }
205
</script>
206

  
65 207
<% if @gantt.truncated %>
66 208
  <p class="warning"><%= l(:notice_gantt_chart_truncated, :max => @gantt.max_rows) %></p>
67 209
<% end %>
......
80 222

  
81 223
</div>
82 224
</td>
225

  
226
<td style="width:225px; padding:0px;">
227
<div style="position:relative;height:<%= t_height + 24 %>px;width:225px;">
228
<div style="width:225px;height:<%= headers_height %>px;background: #eee;" class="gantt_hdr"></div>
229
<div style="width:225px;height:<%= t_height %>px;border-left: 1px solid #c0c0c0;overflow:hidden;" class="gantt_hdr"></div>
230
<div class="gantt_subjects">
231
  <%= @gantt.calendars.html_safe %>
232
</div>
233
</div>
234
</td>
83 235
<td>
84 236

  
85
<div style="position:relative;height:<%= t_height + 24 %>px;overflow:auto;">
237
<div style="position:relative;height:<%= t_height + 24 %>px;overflow:auto;" id="gantt-container">
86 238
<div style="width:<%= g_width - 1 %>px;height:<%= headers_height %>px;background: #eee;" class="gantt_hdr">&nbsp;</div>
87 239
<%
88 240
#
......
142 294
  left = 0
143 295
  height = g_height + header_heigth - 1
144 296
  wday = @gantt.date_from.cwday
297
  dt = @gantt.date_from
145 298
  (@gantt.date_to - @gantt.date_from + 1).to_i.times do
146 299
  width =  zoom - 1
147 300
  %>
148 301
  <div style="left:<%= left %>px;top:37px;width:<%= width %>px;height:<%= height %>px;font-size:0.7em;<%= "background:#f1f1f1;" if wday > 5 %>" class="gantt_hdr">
149 302
  <%= day_name(wday).first %>
303
    <%= "#{dt.day}<br>".html_safe if @gantt.zoom == 4 %><%= day_name(wday).first %>
150 304
  </div>
151 305
  <%
152 306
  left = left + width + 1
153 307
  wday = wday + 1
308
  dt = dt + 1
154 309
  wday = 1 if wday > 7
155 310
  end
156 311
end %>
config/routes.rb
53 53

  
54 54
  match '/projects/:project_id/issues/gantt', :to => 'gantts#show'
55 55
  match '/issues/gantt', :to => 'gantts#show'
56
  match '/gantts/edit_gantt', :controller => 'gantts', :action => 'edit_gantt',
57
         :via => [:get]
58
  match '/gantts/edit_gantt/:id', :controller => 'gantts', :action => 'edit_gantt',
59
         :via => [:post]
56 60

  
57 61
  match '/projects/:project_id/issues/calendar', :to => 'calendars#show'
58 62
  match '/issues/calendar', :to => 'calendars#show'
lib/redmine/helpers/gantt.rb
70 70

  
71 71
        @subjects = ''
72 72
        @lines = ''
73
        @calendars = ''
73 74
        @number_of_rows = nil
74 75

  
75 76
        @issue_ancestors = []
......
129 130
        @lines
130 131
      end
131 132

  
133
      # Renders the calendars of the Gantt chart, the right side
134
      def calendars(options={})
135
        render(options.merge(:only => :calendars)) unless @calendars_rendered
136
        @calendars
137
      end
138

  
132 139
      # Returns issues that will be rendered
133 140
      def issues
134 141
        @issues ||= @query.issues(
......
175 182
        options = {:top => 0, :top_increment => 20, :indent_increment => 20, :render => :subject, :format => :html}.merge(options)
176 183
        indent = options[:indent] || 4
177 184

  
178
        @subjects = '' unless options[:only] == :lines
179
        @lines = '' unless options[:only] == :subjects
185
        if options[:format] == :html
186
          @subjects = '' unless options[:only] == :lines && options[:only] == :calendars
187
          @lines = '' unless options[:only] == :subjects && options[:only] == :calendars
188
          @calendars = '' unless options[:only] == :lines && options[:only] == :subjects
189
        else
190
          @subjects = '' unless options[:only] == :lines
191
          @lines = '' unless options[:only] == :subjects
192
        end
193

  
180 194
        @number_of_rows = 0
181 195

  
182 196
        Project.project_tree(projects) do |project, level|
......
185 199
          break if abort?
186 200
        end
187 201

  
188
        @subjects_rendered = true unless options[:only] == :lines
189
        @lines_rendered = true unless options[:only] == :subjects
190

  
202
        if options[:format] == :html
203
          @subjects_rendered = true unless options[:only] == :lines && options[:only] == :calendars
204
          @lines_rendered = true unless options[:only] == :subjects && options[:only] == :calendars
205
          @calendars_rendered = true unless options[:only] == :lines && options[:only] == :subjects
206
        else
207
          @subjects_rendered = true unless options[:only] == :lines
208
          @lines_rendered = true unless options[:only] == :subjects
209
        end
191 210
        render_end(options)
192 211
      end
193 212

  
194 213
      def render_project(project, options={})
195
        subject_for_project(project, options) unless options[:only] == :lines
196
        line_for_project(project, options) unless options[:only] == :subjects
197

  
214
        if options[:format] == :html
215
          subject_for_project(project, options) unless options[:only] == :lines && options[:only] == :calendars
216
          line_for_project(project, options) unless options[:only] == :subjects && options[:only] == :calendars
217
          calendar_for_project(project, options) unless options[:only] == :lines && options[:only] == :subjects
218
        else
219
          subject_for_project(project, options) unless options[:only] == :lines
220
          line_for_project(project, options) unless options[:only] == :subjects
221
        end
198 222
        options[:top] += options[:top_increment]
199 223
        options[:indent] += options[:indent_increment]
200 224
        @number_of_rows += 1
......
218 242

  
219 243
      def render_issues(issues, options={})
220 244
        @issue_ancestors = []
221

  
222 245
        issues.each do |i|
223
          subject_for_issue(i, options) unless options[:only] == :lines
224
          line_for_issue(i, options) unless options[:only] == :subjects
225

  
246
          if options[:format] == :html
247
            subject_for_issue(i, options) unless options[:only] == :lines && options[:only] == :calendars
248
            line_for_issue(i, options) unless options[:only] == :subjects && options[:only] == :calendars
249
            calendar_for_issue(i, options) unless options[:only] == :lines && options[:only] == :subjects
250
          else
251
            subject_for_issue(i, options) unless options[:only] == :lines
252
            line_for_issue(i, options) unless options[:only] == :subjects
253
          end
226 254
          options[:top] += options[:top_increment]
227 255
          @number_of_rows += 1
228 256
          break if abort?
......
233 261

  
234 262
      def render_version(project, version, options={})
235 263
        # Version header
236
        subject_for_version(version, options) unless options[:only] == :lines
237
        line_for_version(version, options) unless options[:only] == :subjects
238

  
264
        if options[:format] == :html
265
            subject_for_version(version, options) unless options[:only] == :lines && options[:only] == :calendars
266
            line_for_version(version, options) unless options[:only] == :subjects && options[:only] == :calendars
267
            calendar_for_version(version, options) unless options[:only] == :lines && options[:only] == :subjects
268
        else
269
            subject_for_version(version, options) unless options[:only] == :lines
270
            line_for_version(version, options) unless options[:only] == :subjects
271
        end
239 272
        options[:top] += options[:top_increment]
240 273
        @number_of_rows += 1
241 274
        return if abort?
......
283 316

  
284 317
          case options[:format]
285 318
          when :html
286
            html_task(options, coords, :css => "project task", :label => label, :markers => true)
319
            html_task(options, coords, :css => "project task", :label => label, :markers => true, :id => project.id, :kind => "p")
287 320
          when :image
288 321
            image_task(options, coords, :label => label, :markers => true, :height => 3)
289 322
          when :pdf
......
322 355

  
323 356
          case options[:format]
324 357
          when :html
325
            html_task(options, coords, :css => "version task", :label => label, :markers => true)
358
            html_task(options, coords, :css => "version task", :label => label, :markers => true, :id => version.id, :kind => "v")
326 359
          when :image
327 360
            image_task(options, coords, :label => label, :markers => true, :height => 3)
328 361
          when :pdf
......
346 379
          css_classes << ' issue-overdue' if issue.overdue?
347 380
          css_classes << ' issue-behind-schedule' if issue.behind_schedule?
348 381
          css_classes << ' icon icon-issue' unless Setting.gravatar_enabled? && issue.assigned_to
349

  
350 382
          subject = "<span class='#{css_classes}'>".html_safe
351 383
          if issue.assigned_to.present?
352 384
            assigned_string = l(:field_assigned_to) + ": " + issue.assigned_to.name
......
375 407
        if issue.is_a?(Issue) && issue.due_before
376 408
          coords = coordinates(issue.start_date, issue.due_before, issue.done_ratio, options[:zoom])
377 409
          label = "#{ issue.status.name } #{ issue.done_ratio }%"
378

  
410
          if !issue.due_date && issue.fixed_version
411
            if options[:format] == :html
412
              label += "-&nbsp;<strong>#{h(issue.fixed_version.name)}</strong>"
413
            else
414
              label += "-#{h(issue.fixed_version.name)}"
415
            end
416
          end
379 417
          case options[:format]
380 418
          when :html
381
            html_task(options, coords, :css => "task " + (issue.leaf? ? 'leaf' : 'parent'), :label => label, :issue => issue, :markers => !issue.leaf?)
419
            html_task(options, coords, :css => "task " + (issue.leaf? ? 'leaf' : 'parent'),
420
                     :label => label, :issue => issue, :markers => !issue.leaf?, :id => issue.id, :kind => "i")
382 421
          when :image
383 422
            image_task(options, coords, :label => label)
384 423
          when :pdf
......
618 657
        pdf.Output
619 658
      end
620 659

  
660
      def edit(pms)
661
        id = pms[:id]
662
        kind = id.slice!(0).chr
663
        begin
664
          case kind
665
          when 'i'
666
            @issue = Issue.find(pms[:id], :include => [:project, :tracker, :status, :author, :priority, :category])
667
          when 'p'
668
            @issue = Project.find(pms[:id])
669
          when 'v'
670
            @issue = Version.find(pms[:id], :include => [:project])
671
          end
672
        rescue ActiveRecord::RecordNotFound
673
          return "issue not found : #{pms[:id]}", 400
674
        end
675

  
676
        if !@issue.start_date || !@issue.due_before
677
          #render :text=>l(:notice_locking_conflict), :status=>400
678
          return l(:notice_locking_conflict), 400
679
        end
680
        @issue.init_journal(User.current)
681
        date_from = Date.parse(pms[:date_from])
682
        old_start_date = @issue.start_date
683
        o = get_issue_position(@issue, pms[:zoom])
684
        text_for_revert = "#{kind}#{id}=#{format_date(@issue.start_date)},#{@issue.start_date},#{format_date(@issue.due_before)},#{@issue.due_before},#{o[0]},#{o[1]},#{o[2]},#{o[3]}".html_safe
685

  
686
        if pms[:day]
687
          #bar moved
688
          day = pms[:day].to_i
689
          duration = @issue.due_before - @issue.start_date
690
          @issue.start_date = date_from + day
691
          @issue.due_date = @issue.start_date + duration.to_i if @issue.due_date
692
        elsif pms[:start_date]
693
          #start date changed
694
          start_date = Date.parse(pms[:start_date])
695
          if @issue.start_date == start_date
696
            #render :text=>""
697
            return "", 200 #nothing has changed
698
          end
699
          @issue.start_date = start_date
700
          @issue.due_date = start_date if @issue.due_date && start_date > @issue.due_date
701
        elsif pms[:due_date]
702
          #due date changed
703
          due_date = Date.parse(pms[:due_date])
704
          if @issue.due_date == due_date
705
            #render :text=>""
706
            return "", 200 #nothing has changed
707
          end
708
          @issue.due_date = due_date
709
          @issue.start_date = due_date if due_date < @issue.start_date
710
        end
711
        fv = @issue.fixed_version
712
        if fv && fv.effective_date && !@issue.due_date && fv.effective_date < @issue.start_date
713
          @issue.start_date = old_start_date
714
        end
715

  
716
        begin
717
          @issue.save!
718
          o = get_issue_position(@issue, pms[:zoom])
719
          text = "#{kind}#{id}=#{format_date(@issue.start_date)},#{@issue.start_date},#{format_date(@issue.due_before)},#{@issue.due_before},#{o[0]},#{o[1]},#{o[2]},#{o[3]}".html_safe
720

  
721
          prj_map = {}
722
          text = set_project_data(@issue.project, pms[:zoom], text, prj_map)
723
          version_map = {}
724
          text = set_version_data(@issue.fixed_version, pms[:zoom], text, version_map)
725

  
726
          #check dependencies
727
          issues = @issue.all_precedes_issues
728
          issues.each do |i|
729
            o = get_issue_position(i, pms[:zoom])
730
            text += "|i#{i.id}=#{format_date(i.start_date)},#{i.start_date},#{format_date(i.due_before)},#{i.due_before},#{o[0]},#{o[1]},#{o[2]},#{o[3]}".html_safe
731
            text = set_project_data(i.project, pms[:zoom], text, prj_map)
732
            text = set_version_data(i.fixed_version, pms[:zoom], text, version_map)
733
          end
734

  
735
          #check parent
736
          is = @issue
737
          while
738
            pid = is.parent_issue_id
739
            break if !pid
740
            i = Issue.find(pid)
741
            o = get_issue_position(i, pms[:zoom])
742
            text += "|i#{i.id}=#{format_date(i.start_date)},#{i.start_date},#{format_date(i.due_before)},#{i.due_before},#{o[0]},#{o[1]},#{o[2]},#{o[3]},#{o[4]},#{o[5]}".html_safe
743
            text = set_project_data(i.project, pms[:zoom], text, prj_map)
744
            text = set_version_data(i.fixed_version, pms[:zoom], text, version_map)
745
            is = i
746
          end
747
          #render :text=>text
748
          return text, 200
749
        rescue => e
750
          #render :text=>@issue.errors.full_messages.join("\n") + "|" + text_for_revert  , :status=>400
751
          if @issue.errors.full_messages.to_s == ""
752
            return e.to_s + "\n" + [$!,$@.join("\n")].join("\n") + "\n" + @issue.errors.full_messages.join("\n") + "|" + text_for_revert, 400
753
          else
754
            return @issue.errors.full_messages.join("\n") + "|" + text_for_revert, 400
755
          end
756
        end
757
      end
758

  
621 759
      private
622 760

  
623 761
      def coordinates(start_date, end_date, progress, zoom=nil)
......
737 875
        output = ''
738 876
        # Renders the task bar, with progress and late
739 877
        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>".html_safe
878
          i_width = coords[:bar_end] - coords[:bar_start] - 2
879
          output << "<div id='ev_#{options[:kind]}#{options[:id]}' style='position:absolute;left:#{coords[:bar_start]}px;top:#{params[:top]}px;padding-top:3px;height:18px;width:#{ i_width + 100}px;' #{options[:kind] == 'i' ? "class='handle'" : ""}>".html_safe
880
          output << "<div id='task_todo_#{options[:kind]}#{options[:id]}' style='float:left:0px; width:#{ i_width}px;' class='#{options[:css]} task_todo'>&nbsp;</div>".html_safe
741 881

  
742 882
          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>".html_safe
883
            l_width = coords[:bar_late_end] - coords[:bar_start] - 2
884
            output << "<div id='task_late_#{options[:kind]}#{options[:id]}' style='float:left:0px; width:#{ l_width}px;' class='#{ l_width == 0 ? options[:css] + " task_none" : options[:css] + " task_late"}'>&nbsp;</div>".html_safe
885
          else
886
            output << "<div id='task_late_#{options[:kind]}#{options[:id]}' style='float:left:0px; width:0px;' class='#{ options[:css] + " task_none"}'>&nbsp;</div>".html_safe
744 887
          end
745 888
          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>".html_safe
889
            d_width = coords[:bar_progress_end] - coords[:bar_start] - 2
890
            output << "<div id='task_done_#{options[:kind]}#{options[:id]}' style='float:left:0px; width:#{ d_width}px;' class='#{ d_width == 0 ? options[:css] + " task_none" : options[:css] + " task_done"}'>&nbsp;</div>".html_safe
891
          else
892
            output << "<div id='task_done_#{options[:kind]}#{options[:id]}' style='float:left:0px; width:0px;' class='#{ options[:css] + " task_none"}'>&nbsp;</div>".html_safe
747 893
          end
894
          output << "</div>".html_safe
895
        else
896
          output << "<div id='ev_#{options[:kind]}#{options[:id]}' style='position:absolute;left:0px;top:#{params[:top]}px;padding-top:3px;height:18px;width:0px;' #{options[:kind] == 'i' ? "class='handle'" : ""}>".html_safe
897
          output << "<div id='task_todo_#{options[:kind]}#{options[:id]}' style='float:left:0px; width:0px;' class='#{ options[:css]} task_todo'>&nbsp;</div>".html_safe
898
          output << "<div id='task_late_#{options[:kind]}#{options[:id]}' style='float:left:0px; width:0px;' class='#{ options[:css] + " task_none"}'>&nbsp;</div>".html_safe
899
          output << "<div id='task_done_#{options[:kind]}#{options[:id]}' style='float:left:0px; width:0px;' class='#{ options[:css] + " task_none"}'>&nbsp;</div>".html_safe
900
          output << "</div>".html_safe
748 901
        end
749 902
        # Renders the markers
750 903
        if options[:markers]
751 904
          if coords[:start]
752
            output << "<div style='top:#{ params[:top] }px;left:#{ coords[:start] }px;width:15px;' class='#{options[:css]} marker starting'>&nbsp;</div>".html_safe
905
            output << "<div id='marker_start_#{options[:kind]}#{options[:id]}' style='top:#{ params[:top] }px;left:#{ coords[:start] }px;width:15px;' class='#{options[:css]} marker starting'>&nbsp;</div>".html_safe
753 906
          end
754 907
          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>".html_safe
908
            output << "<div id='marker_end_#{options[:kind]}#{options[:id]}' style='top:#{ params[:top] }px;left:#{ coords[:end] + params[:zoom] }px;width:15px;' class='#{options[:css]} marker ending'>&nbsp;</div>".html_safe
756 909
          end
910
        else
911
          output << view.draggable_element("ev_#{options[:kind]}#{options[:id]}", :revert =>false, :scroll=>"'gantt-container'", :constraint => "'horizontal'", :snap=>params[:zoom],:onEnd=>'function( draggable, event )  {issue_moved(draggable.element);}')         #pend
757 912
        end
758 913
        # Renders the label on the right
759 914
        if options[:label]
760
          output << "<div style='top:#{ params[:top] }px;left:#{ (coords[:bar_end] || 0) + 8 }px;' class='#{options[:css]} label'>".html_safe
915
          output << "<div id='label_#{options[:kind]}#{options[:id]}' style='top:#{ params[:top] }px;left:#{ (coords[:bar_end] || 0) + 8 }px;' class='#{options[:css]} label'>".html_safe
761 916
          output << options[:label]
762 917
          output << "</div>".html_safe
763 918
        end
764 919
        # Renders the tooltip
765 920
        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;'>".html_safe
921
          output << "<div id='tt_#{options[:kind]}#{options[:id]}' 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 922
          output << '<span class="tip">'.html_safe
768 923
          output << view.render_issue_tooltip(options[:issue]).html_safe
769 924
          output << "</span></div>".html_safe
......
855 1010
          params[:image].text(params[:subject_width] + (coords[:bar_end] || 0) + 5,params[:top] + 1, options[:label])
856 1011
        end
857 1012
      end
1013

  
1014
      ##  for edit gantt
1015
      def set_project_data(prj, zoom, text, prj_map = {})
1016
        if !prj
1017
          return text
1018
        end
1019
        if !prj_map[prj.id]
1020
          o = get_project_position(prj, zoom)
1021
          text += "|p#{prj.id}=#{format_date(prj.start_date)},#{prj.start_date},#{format_date(prj.due_date)},#{prj.due_date},#{o[0]},#{o[1]},#{o[2]},#{o[3]},#{o[4]},#{o[5]}"
1022
          prj_map[prj.id] = prj
1023
        end
1024
        text = set_project_data(prj.parent, zoom, text, prj_map)
1025
      end
1026

  
1027
      def set_version_data(version, zoom, text, version_map = {})
1028
        if !version
1029
          return text
1030
        end
1031
        if !version_map[version.id]
1032
          o = get_version_position(version, zoom)
1033
          text += "|v#{version.id}=#{format_date(version.start_date)},#{version.start_date},#{format_date(version.due_date)},#{version.due_date},#{o[0]},#{o[1]},#{o[2]},#{o[3]},#{o[4]},#{o[5]}"
1034
          version_map[version.id] = version
1035
        end
1036
        return text
1037
      end
1038

  
1039
      def get_pos(coords)
1040
        i_left = 0
1041
        i_width = 0
1042
        l_width = 0
1043
        d_width = 0
1044
        if coords[:bar_start]
1045
          i_left = coords[:bar_start]
1046
          if coords[:bar_end]
1047
            i_width = coords[:bar_end] - coords[:bar_start] - 2
1048
            i_width = 0 if i_width < 0
1049
          end
1050
          if coords[:bar_late_end]
1051
            l_width = coords[:bar_late_end] - coords[:bar_start] - 2
1052
          end
1053
          if coords[:bar_progress_end]
1054
            d_width = coords[:bar_progress_end] - coords[:bar_start] - 2
1055
          end
1056
        end
1057
        return i_left, i_width, l_width, d_width
1058
      end
1059

  
1060
      def get_issue_position(issue, zoom_str)
1061
        z = zoom_str.to_i
1062
        zoom = 1
1063
        z.times { zoom = zoom * 2}
1064
        id = issue.due_before
1065
        if id && @date_to < id
1066
          id = @date_to
1067
        end
1068
        coords = coordinates(issue.start_date, id, issue.done_ratio, zoom)
1069

  
1070
        i_left, i_width, l_width, d_width = get_pos(coords)
1071
        if coords[:end]
1072
          return i_left, i_width, l_width, d_width, coords[:start], coords[:end] + zoom
1073
        else
1074
          return i_left, i_width, l_width, d_width, coords[:start], nil
1075
        end
1076
      end
1077

  
1078
      def get_project_position(project, zoom_str)
1079
        z = zoom_str.to_i
1080
        zoom = 1
1081
        z.times { zoom = zoom * 2}
1082
        pd = project.due_date
1083
        if pd && @date_to < pd
1084
          pd = @date_to
1085
        end
1086
        coords = coordinates(project.start_date, pd, nil, zoom)
1087
        i_left, i_width, l_width, d_width = get_pos(coords)
1088
        if coords[:end]
1089
          return i_left, i_width, l_width, d_width, coords[:start], coords[:end] + zoom
1090
        else
1091
          return i_left, i_width, l_width, d_width, coords[:start], nil
1092
        end
1093
      end
1094

  
1095
      def get_version_position(version, zoom_str)
1096
        z = zoom_str.to_i
1097
        zoom = 1
1098
        z.times { zoom = zoom * 2}
1099
        vd = version.due_date
1100
        if vd &&  @date_to < vd
1101
          vd = @date_to
1102
        end
1103
        coords = coordinates(version.start_date, vd, version.completed_pourcent, zoom)
1104
        i_left, i_width, l_width, d_width = get_pos(coords)
1105
        if coords[:end]
1106
          return i_left, i_width, l_width, d_width, coords[:start], coords[:end] + zoom
1107
        else
1108
          return i_left, i_width, l_width, d_width, coords[:start], nil
1109
        end
1110
      end
1111

  
1112
      def calendar_for_issue(issue, options)
1113
        # Skip issues that don't have a due_before (due_date or version's due_date)
1114
        if issue.is_a?(Issue) && issue.due_before
1115

  
1116
          case options[:format]
1117
          when :html
1118
            @calendars << "<div style='position: absolute;line-height:1.2em;height:16px;top:#{options[:top]}px;left:4px;overflow:hidden;'>"
1119
            start_date = issue.start_date
1120
            if start_date
1121
              @calendars << "<span id='i#{issue.id}_start_date_str'>"
1122
              @calendars << format_date(start_date)
1123
              @calendars << "</span>"
1124
              @calendars << "<input type='hidden' size='12' id='i#{issue.id}_hidden_start_date' value='#{start_date}' />"
1125
              if issue.leaf?
1126
                @calendars << "<input type='hidden' size='12' id='i#{issue.id}_start_date' value='#{start_date}' />#{view.g_calendar_for('i' + issue.id.to_s + '_start_date')}"
1127
              else
1128
                @calendars << "<input type='hidden' size='12' id='i#{issue.id}_start_date' value='#{start_date}' />&nbsp;&nbsp;&nbsp;"
1129
              end
1130
              @calendars << observe_date_field("i#{issue.id}", 'start')
1131
            end
1132
            due_date = issue.due_date
1133
            if due_date
1134
              @calendars << "<span id='i#{issue.id}_due_date_str'>"
1135
              @calendars << format_date(due_date)
1136
              @calendars << "</span>"
1137
              @calendars << "<input type='hidden' size='12' id='i#{issue.id}_hidden_due_date' value='#{due_date}' />"
1138
              if issue.leaf?
1139
                @calendars << "<input type='hidden' size='12' id='i#{issue.id}_due_date' value='#{due_date}' />#{view.g_calendar_for('i' + issue.id.to_s + '_due_date')}"
1140
              else
1141
                @calendars << "<input type='hidden' size='12' id='i#{issue.id}_due_date' value='#{due_date}' />"
1142
              end
1143
              @calendars << observe_date_field("i#{issue.id}", 'due')
1144
            end
1145
            @calendars << "</div>"
1146
          when :image
1147
            #nop
1148
          when :pdf
1149
            #nop
1150
          end
1151
        else
1152
          ActiveRecord::Base.logger.debug "GanttHelper#line_for_issue was not given an issue with a due_before"
1153
          ''
1154
        end
1155
      end
1156

  
1157
      def calendar_for_version(version, options)
1158
        # Skip version that don't have a due_before (due_date or version's due_date)
1159
        if version.is_a?(Version) && version.start_date && version.due_date
1160

  
1161
          case options[:format]
1162
          when :html
1163
            @calendars << "<div style='position: absolute;line-height:1.2em;height:16px;top:#{options[:top]}px;left:4px;overflow:hidden;'>"
1164
            @calendars << "<span id='v#{version.id}_start_date_str'>"
1165
            @calendars << format_date(version.effective_date)
1166
            @calendars << "</span>"
1167
            @calendars << "</div>"
1168
          when :image
1169
            #nop
1170
          when :pdf
1171
            #nop
1172
          end
1173
        else
1174
          ActiveRecord::Base.logger.debug "GanttHelper#line_for_issue was not given an issue with a due_before"
1175
          ''
1176
        end
1177
      end
1178

  
1179
      def calendar_for_project(project, options)
1180
        case options[:format]
1181
        when :html
1182
          @calendars << "<div style='position: absolute;line-height:1.2em;height:16px;top:#{options[:top]}px;left:4px;overflow:hidden;'>"
1183
          @calendars << "<span id='p#{project.id}_start_date_str'>"
1184
          @calendars << format_date(project.start_date) if project.start_date
1185
          @calendars << "</span>"
1186
          @calendars << "&nbsp;&nbsp;&nbsp;"
1187
          @calendars << "<span id='p#{project.id}_due_date_str'>"
1188
          @calendars << format_date(project.due_date) if project.due_date
1189
          @calendars << "</span>"
1190
          @calendars << "</div>"
1191
        when :image
1192
          # nop
1193
        when :pdf
1194
          # nop
1195
        end
1196
      end
1197

  
1198
      def observe_date_field(id, type)
1199
        output = ''
1200
        prj_id = ''
1201
        prj_id = @project.to_param if @project
1202
        output << "<script type='text/javascript'>\n"
1203
        output << "//<![CDATA[\n"
1204
        output << "new Form.Element.Observer('#{id}_#{type}_date', 0.25,\n"
1205
        output << "  function(element, value) {\n"
1206
        output << "    if (value == document.getElementById('#{id}_hidden_#{type}_date').value) {\n"
1207
        output << "      return ;\n"
1208
        output << "    }\n"
1209
        output << "    new Ajax.Request('#{view.url_for(:controller=>:gantts, :action => :edit_gantt, :id=>id, :date_from=>self.date_from.strftime("%Y-%m-%d"), :date_to=>self.date_to.strftime("%Y-%m-%d"), :zoom=>self.zoom, :escape => false, :project_id=>prj_id)}', {asynchronous:true, evalScripts:true, onFailure:function(request){handle_failure(request.responseText)}, onSuccess:function(request){change_dates(request.responseText)}, parameters:'#{type}_date=' + encodeURIComponent(value)});"
1210
        output << "  })\n"
1211
        output << "//]]>\n"
1212
        output << "</script>"
1213
      end
858 1214
    end
859 1215
  end
860 1216
end
public/stylesheets/application.css
925 925
.task_late { background:#f66 url(../images/task_late.png); border: 1px solid #f66; }
926 926
.task_done { background:#00c600 url(../images/task_done.png); border: 1px solid #00c600; }
927 927
.task_todo { background:#aaa url(../images/task_todo.png); border: 1px solid #aaa; }
928
.task_none { background:transparent; border-style: none; }
928 929

  
929 930
.task_todo.parent { background: #888; border: 1px solid #888; height: 3px;}
930 931
.task_late.parent, .task_done.parent { height: 3px;}
test/integration/routing/gantts_test.rb
37 37
        { :controller => 'gantts', :action => 'show',
38 38
          :project_id => 'project-name', :format => 'pdf' }
39 39
      )
40
    assert_routing(
41
        { :method => 'get', :path => "/gantts/edit_gantt" },
42
        { :controller => 'gantts', :action => 'edit_gantt' }
43
      )
44
    assert_routing(
45
        { :method => 'post', :path => "/gantts/edit_gantt/123" },
46
        { :controller => 'gantts', :action => 'edit_gantt',
47
          :id => '123' }
48
      )
40 49
  end
41 50
end
app/views/gantts/show.html.erb
212 212
<tr>
213 213
<td style="width:<%= subject_width %>px; padding:0px;">
214 214

  
215
<div style="position:relative;height:<%= t_height + 24 %>px;width:<%= subject_width + 1 %>px;">
216
<div style="right:-2px;width:<%= subject_width %>px;height:<%= headers_height %>px;background: #eee;" class="gantt_hdr"></div>
217
<div style="right:-2px;width:<%= subject_width %>px;height:<%= t_height %>px;border-left: 1px solid #c0c0c0;overflow:hidden;" class="gantt_hdr"></div>
215
<div style="position:relative;height:<%= t_height + 24 %>px;width:<%= subject_width - 2 %>px;">
216
<div style="right:-2px;width:<%= subject_width - 2 %>px;height:<%= headers_height %>px;background: #eee;" class="gantt_hdr"></div>
217
<div style="right:-2px;width:<%= subject_width - 2 %>px;height:<%= t_height %>px;border-left: 1px solid #c0c0c0;overflow:hidden;" class="gantt_hdr"></div>
218 218

  
219 219
<div class="gantt_subjects">
220 220
<%= @gantt.subjects.html_safe %>
......
223 223
</div>
224 224
</td>
225 225

  
226
<td style="width:225px; padding:0px;">
227
<div style="position:relative;height:<%= t_height + 24 %>px;width:225px;">
228
<div style="width:225px;height:<%= headers_height %>px;background: #eee;" class="gantt_hdr"></div>
229
<div style="width:225px;height:<%= t_height %>px;border-left: 1px solid #c0c0c0;overflow:hidden;" class="gantt_hdr"></div>
226
<td style="width:180px; padding:0px;">
227
<div style="position:relative;height:<%= t_height + 24 %>px;width:180px;">
228
<div style="width:181px;height:<%= headers_height %>px;background: #eee;" class="gantt_hdr"></div>
229
<div style="width:181px;height:<%= t_height %>px;overflow:hidden;" class="gantt_hdr"></div>
230 230
<div class="gantt_subjects">
231 231
  <%= @gantt.calendars.html_safe %>
232 232
</div>
......
298 298
  (@gantt.date_to - @gantt.date_from + 1).to_i.times do
299 299
  width =  zoom - 1
300 300
  %>
301
  <div style="left:<%= left %>px;top:37px;width:<%= width %>px;height:<%= height %>px;font-size:0.7em;<%= "background:#f1f1f1;" if wday > 5 %>" class="gantt_hdr">
302
  <%= day_name(wday).first %>
303
    <%= "#{dt.day}<br>".html_safe if @gantt.zoom == 4 %><%= day_name(wday).first %>
301
  <div style="left:<%= left %>px;top:37px;width:<%= width %>px;height:<%= height %>px;font-size:0.6em;<%= "background:#f1f1f1;" if wday > 5 %>" class="gantt_hdr">
302
  <%=  "#{dt.day}<br>".html_safe if @gantt.zoom == 4 %><%= day_name(wday).first %>
304 303
  </div>
305 304
  <%
306 305
  left = left + width + 1
lib/redmine/helpers/gantt.rb
1115 1115

  
1116 1116
          case options[:format]
1117 1117
          when :html
1118
            @calendars << "<div style='position: absolute;line-height:1.2em;height:16px;top:#{options[:top]}px;left:4px;overflow:hidden;'>"
1118
            @calendars << "<div style='position: absolute;line-height:1.2em;height:16px;top:#{options[:top]}px;left:4px;overflow:hidden;width:180px;'>"
1119 1119
            start_date = issue.start_date
1120 1120
            if start_date
1121
              @calendars << "<div style='float: left; line-height: 1em; width: 90px;'>"
1121 1122
              @calendars << "<span id='i#{issue.id}_start_date_str'>"
1122 1123
              @calendars << format_date(start_date)
1123 1124
              @calendars << "</span>"
......
1128 1129
                @calendars << "<input type='hidden' size='12' id='i#{issue.id}_start_date' value='#{start_date}' />&nbsp;&nbsp;&nbsp;"
1129 1130
              end
1130 1131
              @calendars << observe_date_field("i#{issue.id}", 'start')
1132
              @calendars << "</div>"
1131 1133
            end
1132 1134
            due_date = issue.due_date
1133 1135
            if due_date
1136
              @calendars << "<div style='float: right; line-height: 1em; width: 90px;'>"
1134 1137
              @calendars << "<span id='i#{issue.id}_due_date_str'>"
1135 1138
              @calendars << format_date(due_date)
1136 1139
              @calendars << "</span>"
......
1141 1144
                @calendars << "<input type='hidden' size='12' id='i#{issue.id}_due_date' value='#{due_date}' />"
1142 1145
              end
1143 1146
              @calendars << observe_date_field("i#{issue.id}", 'due')
1147
              @calendars << "</div>"
1148
            else
1149
              @calendars << "<div style='float: right; line-height: 1em; width: 90px;'>"
1150
              @calendars << "<span id='i#{issue.id}_due_date_str'>"
1151
              @calendars << "Not set"
1152
              @calendars << "</span>"
1153
              @calendars << "<input type='hidden' size='12' id='i#{issue.id}_hidden_due_date' value='#{start_date}' />"
1154
              if issue.leaf?
1155
                @calendars << "<input type='hidden' size='12' id='i#{issue.id}_due_date' value='#{start_date}' />#{view.g_calendar_for('i' + issue.id.to_s + '_due_date')}"
1156
              else
1157
                @calendars << "<input type='hidden' size='12' id='i#{issue.id}_due_date' value='#{start_date}' />"
1158
              end
1159
              @calendars << observe_date_field("i#{issue.id}", 'due')
1160
              @calendars << "</div>"            
1144 1161
            end
1162
            
1145 1163
            @calendars << "</div>"
1146 1164
          when :image
1147 1165
            #nop
......
1179 1197
      def calendar_for_project(project, options)
1180 1198
        case options[:format]
1181 1199
        when :html
1182
          @calendars << "<div style='position: absolute;line-height:1.2em;height:16px;top:#{options[:top]}px;left:4px;overflow:hidden;'>"
1200
          @calendars << "<div style='position: absolute;line-height:1.2em;height:16px;top:#{options[:top]}px;left:4px;overflow:hidden;width:180px;'>"
1201
          @calendars << "<div style='float:left;width:90px;'>"
1183 1202
          @calendars << "<span id='p#{project.id}_start_date_str'>"
1184 1203
          @calendars << format_date(project.start_date) if project.start_date
1185 1204
          @calendars << "</span>"
1186
          @calendars << "&nbsp;&nbsp;&nbsp;"
1205
          @calendars << "</div>"
1206
          @calendars << "<div style='float:right;width:90px;'>"
1187 1207
          @calendars << "<span id='p#{project.id}_due_date_str'>"
1188 1208
          @calendars << format_date(project.due_date) if project.due_date
1189 1209
          @calendars << "</span>"
1190 1210
          @calendars << "</div>"
1211
          @calendars << "</div>"
1191 1212
        when :image
1192 1213
          # nop
1193 1214
        when :pdf
(25-25/35)