Project

General

Profile

Feature #2024 » gantt_edit_v1.4.3.patch

Toshi MARUYAMA, 2012-06-16 07:06

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
1018 1018
    javascript_tag("Calendar.setup({inputField : '#{field_id}', ifFormat : '%Y-%m-%d', button : '#{field_id}_trigger' });")
1019 1019
  end
1020 1020

  
1021
  def g_calendar_for(field_id)
1022
    include_calendar_headers_tags
1023
    image_tag("calendar.png", {:id => "#{field_id}_trigger",:class => "calendar-trigger"}) +
1024
    javascript_tag("Calendar.setup({inputField : '#{field_id}', electric : false, ifFormat : '%Y-%m-%d', button : '#{field_id}_trigger' });")
1025
  end
1026

  
1021 1027
  def include_calendar_headers_tags
1022 1028
    unless @calendar_headers_tags_included
1023 1029
      @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
618 618
    dependencies
619 619
  end
620 620

  
621
  def all_precedes_issues
622
    dependencies = []
623
    relations_from.each do |relation|
624
      next unless relation.relation_type == IssueRelation::TYPE_PRECEDES
625
      dependencies << relation.issue_to
626
      dependencies += relation.issue_to.all_dependent_issues
627
    end
628
    dependencies
629
  end
630

  
621 631
  # Returns an array of issues that duplicate this one
622 632
  def duplicates
623 633
    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

  
......
32 33
<% zoom = 1
33 34
@gantt.zoom.times { zoom = zoom * 2 }
34 35

  
35
subject_width = 330
36
subject_width = 280
36 37
header_heigth = 18
37 38

  
38 39
headers_height = header_heigth
......
59 60

  
60 61
%>
61 62

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

  
87
  }
88

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

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

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

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

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

  
62 208
<% if @gantt.truncated %>
63 209
  <p class="warning"><%= l(:notice_gantt_chart_truncated, :max => @gantt.max_rows) %></p>
64 210
<% end %>
......
77 223

  
78 224
</div>
79 225
</td>
226

  
227
<td style="width:225px; padding:0px;">
228
<div style="position:relative;height:<%= t_height + 24 %>px;width:225px;">
229
<div style="width:225px;height:<%= headers_height %>px;background: #eee;" class="gantt_hdr"></div>
230
<div style="width:225px;height:<%= t_height %>px;border-left: 1px solid #c0c0c0;overflow:hidden;" class="gantt_hdr"></div>
231

  
232
<div class="gantt_subjects">
233
<%= @gantt.calendars %>
234
</div>
235

  
236
</div>
237
</td>
238

  
80 239
<td>
81 240

  
82
<div style="position:relative;height:<%= t_height + 24 %>px;overflow:auto;">
241
<div style="position:relative;height:<%= t_height + 24 %>px;overflow:auto;" id="gantt-container">
83 242
<div style="width:<%= g_width - 1 %>px;height:<%= headers_height %>px;background: #eee;" class="gantt_hdr">&nbsp;</div>
84 243
<%
85 244
#
......
139 298
  left = 0
140 299
  height = g_height + header_heigth - 1
141 300
  wday = @gantt.date_from.cwday
301
  dt = @gantt.date_from
142 302
  (@gantt.date_to - @gantt.date_from + 1).to_i.times do
143 303
  width =  zoom - 1
144 304
  %>
145 305
  <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">
146 306
  <%= day_name(wday).first %>
307
  <%=  "#{dt.day}<br>"if @gantt.zoom == 4 %><%= day_name(wday).first %>
147 308
  </div>
148 309
  <%
149 310
  left = left + width + 1
150 311
  wday = wday + 1
312
  dt = dt + 1
151 313
  wday = 1 if wday > 7
152 314
  end
153 315
end %>
config/routes.rb
65 65
    gantts_routes.connect '/projects/:project_id/issues/gantt.:format'
66 66
    gantts_routes.connect '/issues/gantt.:format'
67 67
  end
68
  map.connect '/gantts/edit_gantt', :controller => 'gantts', :action => 'edit_gantt',
69
              :conditions => { :method => :get}
70
  map.connect '/gantts/edit_gantt/:id', :controller => 'gantts', :action => 'edit_gantt',
71
              :conditions => { :method => :post}
68 72

  
69 73
  map.with_options :controller => 'calendars', :action => 'show' do |calendars_routes|
70 74
    calendars_routes.connect '/projects/:project_id/issues/calendar'
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
202
        #pstart
203
        if options[:format] == :html
204
          @subjects_rendered = true unless options[:only] == :lines && options[:only] == :calendars
205
          @lines_rendered = true unless options[:only] == :subjects && options[:only] == :calendars
206
          @calendars_rendered = true unless options[:only] == :lines && options[:only] == :subjects
207
        else
208
          @subjects_rendered = true unless options[:only] == :lines
209
          @lines_rendered = true unless options[:only] == :subjects
210
        end
211
        #pend
190 212

  
191 213
        render_end(options)
192 214
      end
193 215

  
194 216
      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
217

  
218
        #pstart
219
        if options[:format] == :html
220
          subject_for_project(project, options) unless options[:only] == :lines && options[:only] == :calendars
221
          line_for_project(project, options) unless options[:only] == :subjects && options[:only] == :calendars
222
          calendar_for_project(project, options) unless options[:only] == :lines && options[:only] == :subjects
223
        else
224
          subject_for_project(project, options) unless options[:only] == :lines
225
          line_for_project(project, options) unless options[:only] == :subjects
226
        end
227
        #pend
197 228

  
198 229
        options[:top] += options[:top_increment]
199 230
        options[:indent] += options[:indent_increment]
......
220 251
        @issue_ancestors = []
221 252

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

  
255
          #pstart
256
          if options[:format] == :html
257
            subject_for_issue(i, options) unless options[:only] == :lines && options[:only] == :calendars
258
            line_for_issue(i, options) unless options[:only] == :subjects && options[:only] == :calendars
259
            calendar_for_issue(i, options) unless options[:only] == :lines && options[:only] == :subjects
260
          else
261
            subject_for_issue(i, options) unless options[:only] == :lines
262
            line_for_issue(i, options) unless options[:only] == :subjects
263
          end
264
          #pend
225 265

  
226 266
          options[:top] += options[:top_increment]
227 267
          @number_of_rows += 1
......
233 273

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

  
277
          #pstart
278
          if options[:format] == :html
279
            subject_for_version(version, options) unless options[:only] == :lines && options[:only] == :calendars
280
            line_for_version(version, options) unless options[:only] == :subjects && options[:only] == :calendars
281
            calendar_for_version(version, options) unless options[:only] == :lines && options[:only] == :subjects
282
          else
283
            subject_for_version(version, options) unless options[:only] == :lines
284
            line_for_version(version, options) unless options[:only] == :subjects
285
          end
286
          #pend
238 287

  
239 288
        options[:top] += options[:top_increment]
240 289
        @number_of_rows += 1
......
283 332

  
284 333
          case options[:format]
285 334
          when :html
286
            html_task(options, coords, :css => "project task", :label => label, :markers => true)
335

  
336
            #pstart
337
            html_task(options, coords, :css => "project task", :label => label, :markers => true, :id => project.id, :kind => "p")
338
            #pend
339

  
287 340
          when :image
288 341
            image_task(options, coords, :label => label, :markers => true, :height => 3)
289 342
          when :pdf
......
322 375

  
323 376
          case options[:format]
324 377
          when :html
325
            html_task(options, coords, :css => "version task", :label => label, :markers => true)
378

  
379
            #pstart
380
            html_task(options, coords, :css => "version task", :label => label, :markers => true, :id => version.id, :kind => "v")
381
            #pend
382

  
326 383
          when :image
327 384
            image_task(options, coords, :label => label, :markers => true, :height => 3)
328 385
          when :pdf
......
376 433
          coords = coordinates(issue.start_date, issue.due_before, issue.done_ratio, options[:zoom])
377 434
          label = "#{ issue.status.name } #{ issue.done_ratio }%"
378 435

  
436
          #pstart
437
          if !issue.due_date && issue.fixed_version
438
            if options[:format] == :html
439
              label += "-&nbsp;<strong>#{h(issue.fixed_version.name)}</strong>"
440
            else
441
              label += "-#{h(issue.fixed_version.name)}"
442
            end
443
          end
444
          #pend
445

  
379 446
          case options[:format]
380 447
          when :html
381
            html_task(options, coords, :css => "task " + (issue.leaf? ? 'leaf' : 'parent'), :label => label, :issue => issue, :markers => !issue.leaf?)
448

  
449
            #pstart
450
            html_task(options, coords, :css => "task " + (issue.leaf? ? 'leaf' : 'parent'), :label => label, :issue => issue, :markers => !issue.leaf?, :id => issue.id, :kind => "i")
451
            #pend
452

  
382 453
          when :image
383 454
            image_task(options, coords, :label => label)
384 455
          when :pdf
......
618 689
        pdf.Output
619 690
      end
620 691

  
692
      #pstart
693
      def edit(pms)
694
        id = pms[:id]
695
        kind = id.slice!(0).chr
696
        begin
697
          case kind
698
          when 'i'
699
            @issue = Issue.find(pms[:id], :include => [:project, :tracker, :status, :author, :priority, :category])
700
          when 'p'
701
            @issue = Project.find(pms[:id])
702
          when 'v'
703
            @issue = Version.find(pms[:id], :include => [:project])
704
          end
705
        rescue ActiveRecord::RecordNotFound
706
          return "issue not found : #{pms[:id]}", 400
707
        end
708

  
709
        if !@issue.start_date || !@issue.due_before
710
          #render :text=>l(:notice_locking_conflict), :status=>400
711
          return l(:notice_locking_conflict), 400
712
        end
713
        @issue.init_journal(User.current)
714
        date_from = Date.parse(pms[:date_from])
715
        old_start_date = @issue.start_date
716
        o = get_issue_position(@issue, pms[:zoom])
717
        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]}"
718

  
719
        if pms[:day]
720
          #bar moved
721
          day = pms[:day].to_i
722
          duration = @issue.due_before - @issue.start_date
723
          @issue.start_date = date_from + day
724
          @issue.due_date = @issue.start_date + duration.to_i if @issue.due_date
725
        elsif pms[:start_date]
726
          #start date changed
727
          start_date = Date.parse(pms[:start_date])
728
          if @issue.start_date == start_date
729
            #render :text=>""
730
            return "", 200 #nothing has changed
731
          end
732
          @issue.start_date = start_date
733
          @issue.due_date = start_date if @issue.due_date && start_date > @issue.due_date
734
        elsif pms[:due_date]
735
          #due date changed
736
          due_date = Date.parse(pms[:due_date])
737
          if @issue.due_date == due_date
738
            #render :text=>""
739
            return "", 200 #nothing has changed
740
          end
741
          @issue.due_date = due_date
742
          @issue.start_date = due_date if due_date < @issue.start_date
743
        end
744
        fv = @issue.fixed_version
745
        if fv && fv.effective_date && !@issue.due_date && fv.effective_date < @issue.start_date
746
          @issue.start_date = old_start_date
747
        end
748

  
749
        begin
750
          @issue.save!
751
          o = get_issue_position(@issue, pms[:zoom])
752
          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]}"
753

  
754
          prj_map = {}
755
          text = set_project_data(@issue.project, pms[:zoom], text, prj_map)
756
          version_map = {}
757
          text = set_version_data(@issue.fixed_version, pms[:zoom], text, version_map)
758

  
759
          #check dependencies
760
          issues = @issue.all_precedes_issues
761
          issues.each do |i|
762
            o = get_issue_position(i, pms[:zoom])
763
            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]}"
764
            text = set_project_data(i.project, pms[:zoom], text, prj_map)
765
            text = set_version_data(i.fixed_version, pms[:zoom], text, version_map)
766
          end
767

  
768
          #check parent
769
          is = @issue
770
          while
771
            pid = is.parent_issue_id
772
            break if !pid
773
            i = Issue.find(pid)
774
            o = get_issue_position(i, pms[:zoom])
775
            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]}"
776
            text = set_project_data(i.project, pms[:zoom], text, prj_map)
777
            text = set_version_data(i.fixed_version, pms[:zoom], text, version_map)
778
            is = i
779
          end
780
          #render :text=>text
781
          return text, 200
782
        rescue => e
783
          #render :text=>@issue.errors.full_messages.join("\n") + "|" + text_for_revert  , :status=>400
784
          if @issue.errors.full_messages.to_s == ""
785
            return e.to_s + "\n" + [$!,$@.join("\n")].join("\n") + "\n" + @issue.errors.full_messages.join("\n") + "|" + text_for_revert, 400
786
          else
787
            return @issue.errors.full_messages.join("\n") + "|" + text_for_revert, 400
788
          end
789
        end
790
      end
791
      #pend
792

  
621 793
      private
622 794

  
623 795
      def coordinates(start_date, end_date, progress, zoom=nil)
......
737 909
        output = ''
738 910
        # Renders the task bar, with progress and late
739 911
        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
912
          #pstart
913
          i_width = coords[:bar_end] - coords[:bar_start] - 2
914
          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
915
          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
916
          #pend
741 917

  
742 918
          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
919
            #pstart
920
            l_width = coords[:bar_late_end] - coords[:bar_start] - 2
921
            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
922
          else
923
            output << "<div id='task_late_#{options[:kind]}#{options[:id]}' style='float:left:0px; width:0px;' class='#{ options[:css] + " task_none"}'>&nbsp;</div>".html_safe
924
            #pend
744 925
          end
745 926
          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
927
            #pstart
928
            d_width = coords[:bar_progress_end] - coords[:bar_start] - 2
929
            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
930
          else
931
            output << "<div id='task_done_#{options[:kind]}#{options[:id]}' style='float:left:0px; width:0px;' class='#{ options[:css] + " task_none"}'>&nbsp;</div>".html_safe
932
            #pend
747 933
          end
934
          #pstart
935
          output << "</div>".html_safe
936
        else
937
          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
938
          output << "<div id='task_todo_#{options[:kind]}#{options[:id]}' style='float:left:0px; width:0px;' class='#{ options[:css]} task_todo'>&nbsp;</div>".html_safe
939
          output << "<div id='task_late_#{options[:kind]}#{options[:id]}' style='float:left:0px; width:0px;' class='#{ options[:css] + " task_none"}'>&nbsp;</div>".html_safe
940
          output << "<div id='task_done_#{options[:kind]}#{options[:id]}' style='float:left:0px; width:0px;' class='#{ options[:css] + " task_none"}'>&nbsp;</div>".html_safe
941
          output << "</div>".html_safe
942
        #pend
748 943
        end
749 944
        # Renders the markers
750 945
        if options[:markers]
751 946
          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
947
            #pstart
948
            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
949
            #pend
753 950
          end
754 951
          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
952
            #pstart
953
            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
954
            #pend
756 955
          end
956
        #pstart
957
        else
958
          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 959
        end
758 960
        # Renders the label on the right
759 961
        if options[:label]
760
          output << "<div style='top:#{ params[:top] }px;left:#{ (coords[:bar_end] || 0) + 8 }px;' class='#{options[:css]} label'>".html_safe
962
          #psrat
963
          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
964
          #pend
761 965
          output << options[:label]
762 966
          output << "</div>".html_safe
763 967
        end
764 968
        # Renders the tooltip
765 969
        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
970
          #pstart
971
          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
972
          #pend
767 973
          output << '<span class="tip">'.html_safe
768 974
          output << view.render_issue_tooltip(options[:issue]).html_safe
769 975
          output << "</span></div>".html_safe
......
855 1061
          params[:image].text(params[:subject_width] + (coords[:bar_end] || 0) + 5,params[:top] + 1, options[:label])
856 1062
        end
857 1063
      end
1064

  
1065
      #pstart
1066
      ##
1067
      ##  for edit gantt
1068
      ##
1069
      def set_project_data(prj, zoom, text, prj_map = {})
1070
        if !prj
1071
          return text
1072
        end
1073
        if !prj_map[prj.id]
1074
          o = get_project_position(prj, zoom)
1075
          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]}"
1076
          prj_map[prj.id] = prj
1077
        end
1078
        text = set_project_data(prj.parent, zoom, text, prj_map)
1079
      end
1080

  
1081
      def set_version_data(version, zoom, text, version_map = {})
1082
        if !version
1083
          return text
1084
        end
1085
        if !version_map[version.id]
1086
          o = get_version_position(version, zoom)
1087
          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]}"
1088
          version_map[version.id] = version
1089
        end
1090
        return text
1091
      end
1092

  
1093
      def get_pos(coords)
1094
        i_left = 0
1095
        i_width = 0
1096
        l_width = 0
1097
        d_width = 0
1098
        if coords[:bar_start]
1099
          i_left = coords[:bar_start]
1100
          if coords[:bar_end]
1101
            i_width = coords[:bar_end] - coords[:bar_start] - 2
1102
            i_width = 0 if i_width < 0
1103
          end
1104
          if coords[:bar_late_end]
1105
            l_width = coords[:bar_late_end] - coords[:bar_start] - 2
1106
          end
1107
          if coords[:bar_progress_end]
1108
            d_width = coords[:bar_progress_end] - coords[:bar_start] - 2
1109
          end
1110
        end
1111
        return i_left, i_width, l_width, d_width
1112
      end
1113

  
1114
      def get_issue_position(issue, zoom_str)
1115
        z = zoom_str.to_i
1116
        zoom = 1
1117
        z.times { zoom = zoom * 2}
1118
        id = issue.due_before
1119
        if id && @date_to < id
1120
          id = @date_to
1121
        end
1122
        coords = coordinates(issue.start_date, id, issue.done_ratio, zoom)
1123

  
1124
        i_left, i_width, l_width, d_width = get_pos(coords)
1125
        if coords[:end]
1126
          return i_left, i_width, l_width, d_width, coords[:start], coords[:end] + zoom
1127
        else
1128
          return i_left, i_width, l_width, d_width, coords[:start], nil
1129
        end
1130
      end
1131

  
1132
      def get_project_position(project, zoom_str)
1133
        z = zoom_str.to_i
1134
        zoom = 1
1135
        z.times { zoom = zoom * 2}
1136
        pd = project.due_date
1137
        if pd && @date_to < pd
1138
          pd = @date_to
1139
        end
1140
        coords = coordinates(project.start_date, pd, nil, zoom)
1141
        i_left, i_width, l_width, d_width = get_pos(coords)
1142
        if coords[:end]
1143
          return i_left, i_width, l_width, d_width, coords[:start], coords[:end] + zoom
1144
        else
1145
          return i_left, i_width, l_width, d_width, coords[:start], nil
1146
        end
1147
      end
1148

  
1149
      def get_version_position(version, zoom_str)
1150
        z = zoom_str.to_i
1151
        zoom = 1
1152
        z.times { zoom = zoom * 2}
1153
        vd = version.due_date
1154
        if vd &&  @date_to < vd
1155
          vd = @date_to
1156
        end
1157
        coords = coordinates(version.start_date, vd, version.completed_pourcent, zoom)
1158
        i_left, i_width, l_width, d_width = get_pos(coords)
1159
        if coords[:end]
1160
          return i_left, i_width, l_width, d_width, coords[:start], coords[:end] + zoom
1161
        else
1162
          return i_left, i_width, l_width, d_width, coords[:start], nil
1163
        end
1164
      end
1165

  
1166
      def calendar_for_issue(issue, options)
1167
        # Skip issues that don't have a due_before (due_date or version's due_date)
1168
        if issue.is_a?(Issue) && issue.due_before
1169

  
1170
          case options[:format]
1171
          when :html
1172
            @calendars << "<div style='position: absolute;line-height:1.2em;height:16px;top:#{options[:top]}px;left:4px;overflow:hidden;'>"
1173
            start_date = issue.start_date
1174
            if start_date
1175
              @calendars << "<span id='i#{issue.id}_start_date_str'>"
1176
              @calendars << format_date(start_date)
1177
              @calendars << "</span>"
1178
              @calendars << "<input type='hidden' size='12' id='i#{issue.id}_hidden_start_date' value='#{start_date}' />"
1179
              if issue.leaf?
1180
                @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')}"
1181
              else
1182
                @calendars << "<input type='hidden' size='12' id='i#{issue.id}_start_date' value='#{start_date}' />&nbsp;&nbsp;&nbsp;"
1183
              end
1184
              @calendars << observe_date_field("i#{issue.id}", 'start')
1185
            end
1186
            due_date = issue.due_date
1187
            if due_date
1188
              @calendars << "<span id='i#{issue.id}_due_date_str'>"
1189
              @calendars << format_date(due_date)
1190
              @calendars << "</span>"
1191
              @calendars << "<input type='hidden' size='12' id='i#{issue.id}_hidden_due_date' value='#{due_date}' />"
1192
              if issue.leaf?
1193
                @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')}"
1194
              else
1195
                @calendars << "<input type='hidden' size='12' id='i#{issue.id}_due_date' value='#{due_date}' />"
1196
              end
1197
              @calendars << observe_date_field("i#{issue.id}", 'due')
1198
            end
1199
            @calendars << "</div>"
1200
          when :image
1201
            #nop
1202
          when :pdf
1203
            #nop
1204
          end
1205
        else
1206
          ActiveRecord::Base.logger.debug "GanttHelper#line_for_issue was not given an issue with a due_before"
1207
          ''
1208
        end
1209
      end
1210

  
1211
      def calendar_for_version(version, options)
1212
        # Skip version that don't have a due_before (due_date or version's due_date)
1213
        if version.is_a?(Version) && version.start_date && version.due_date
1214

  
1215
          case options[:format]
1216
          when :html
1217
            @calendars << "<div style='position: absolute;line-height:1.2em;height:16px;top:#{options[:top]}px;left:4px;overflow:hidden;'>"
1218
            @calendars << "<span id='v#{version.id}_start_date_str'>"
1219
            @calendars << format_date(version.effective_date)
1220
            @calendars << "</span>"
1221
            @calendars << "</div>"
1222
          when :image
1223
            #nop
1224
          when :pdf
1225
            #nop
1226
          end
1227
        else
1228
          ActiveRecord::Base.logger.debug "GanttHelper#line_for_issue was not given an issue with a due_before"
1229
          ''
1230
        end
1231
      end
1232

  
1233
      def calendar_for_project(project, options)
1234
        case options[:format]
1235
        when :html
1236
          @calendars << "<div style='position: absolute;line-height:1.2em;height:16px;top:#{options[:top]}px;left:4px;overflow:hidden;'>"
1237
          @calendars << "<span id='p#{project.id}_start_date_str'>"
1238
          @calendars << format_date(project.start_date) if project.start_date
1239
          @calendars << "</span>"
1240
          @calendars << "&nbsp;&nbsp;&nbsp;"
1241
          @calendars << "<span id='p#{project.id}_due_date_str'>"
1242
          @calendars << format_date(project.due_date) if project.due_date
1243
          @calendars << "</span>"
1244
          @calendars << "</div>"
1245
        when :image
1246
          # nop
1247
        when :pdf
1248
          # nop
1249
        end
1250
      end
1251

  
1252
      def observe_date_field(id, type)
1253
        output = ''
1254
        prj_id = ''
1255
        prj_id = @project.to_param if @project
1256
        output << "<script type='text/javascript'>\n"
1257
        output << "//<![CDATA[\n"
1258
        output << "new Form.Element.Observer('#{id}_#{type}_date', 0.25,\n"
1259
        output << "  function(element, value) {\n"
1260
        output << "    if (value == document.getElementById('#{id}_hidden_#{type}_date').value) {\n"
1261
        output << "      return ;\n"
1262
        output << "    }\n"
1263
        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)});"
1264
        output << "  })\n"
1265
        output << "//]]>\n"
1266
        output << "</script>"
1267
      end
1268
    #pend
1269

  
858 1270
    end
859 1271
  end
860 1272
end
public/stylesheets/application.css
912 912
.task_late { background:#f66 url(../images/task_late.png); border: 1px solid #f66; }
913 913
.task_done { background:#00c600 url(../images/task_done.png); border: 1px solid #00c600; }
914 914
.task_todo { background:#aaa url(../images/task_todo.png); border: 1px solid #aaa; }
915
.task_none { background:transparent; border-style: none; }
915 916

  
916 917
.task_todo.parent { background: #888; border: 1px solid #888; height: 3px;}
917 918
.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
(22-22/35)