gantt_edit_v1-1-1.patch

Hiroyuki Yoshioka, 2011-02-26 17:16

Download (33.7 KB)

View differences:

app/controllers/gantts_controller.rb (working copy)
33 33
    show
34 34
  end
35 35

  
36
  def edit_gantt
37
    date_from = Date.parse(params[:date_from])
38
    date_to = Date.parse(params[:date_to])
39
    months = date_to.month - date_from.month + 1
40
    params[:year] = date_from.year
41
    params[:month] = date_from.month
42
    params[:months] = months
43
    @gantt = Redmine::Helpers::Gantt.new(params)
44
    @gantt.project = @project
45
    text, status = @gantt.edit(params)
46
    render :text=>text, :status=>status
47
  end
48

  
49
  def find_optional_project
50
    if params[:action] && params[:action].to_s == "edit_gantt"
51
      @project = Project.find(params[:project_id]) unless params[:project_id].blank?
52
      allowed = User.current.allowed_to?(:edit_issues, @project, :global => true)
53
      if allowed
54
        return true
55
      else
56
        render :text=>"lack of permission to edit issues", :status=>403
57
      end
58
    else
59
      super
60
    end
61
  rescue ActiveRecord::RecordNotFound
62
    render_404
63
  end
36 64
end
app/helpers/issues_helper.rb (working copy)
49 49
    link_to_issue(issue) + "<br /><br />" +
50 50
      "<strong>#{@cached_label_project}</strong>: #{link_to_project(issue.project)}<br />" +
51 51
      "<strong>#{@cached_label_status}</strong>: #{issue.status.name}<br />" +
52
      "<strong>#{@cached_label_start_date}</strong>: #{format_date(issue.start_date)}<br />" +
53
      "<strong>#{@cached_label_due_date}</strong>: #{format_date(issue.due_date)}<br />" +
52
      "<strong>#{@cached_label_start_date}</strong>: <span id='tooltip_start_date_i#{issue.id}'>#{format_date(issue.start_date)}</span><br />" +
53
      "<strong>#{@cached_label_due_date}</strong>: <span id='tooltip_due_date_i#{issue.id}'>#{format_date(issue.due_date)}</span><br />" +
54 54
      "<strong>#{@cached_label_assigned_to}</strong>: #{issue.assigned_to}<br />" +
55 55
      "<strong>#{@cached_label_priority}</strong>: #{issue.priority.name}"
56 56
  end
app/models/issue.rb (working copy)
465 465
    dependencies
466 466
  end
467 467
  
468
  def all_precedes_issues
469
    dependencies = []
470
    relations_from.each do |relation|
471
      next unless relation.relation_type == IssueRelation::TYPE_PRECEDES
472
      dependencies << relation.issue_to
473
      dependencies += relation.issue_to.all_dependent_issues
474
    end
475
    dependencies
476
  end
477

  
468 478
  # Returns an array of issues that duplicate this one
469 479
  def duplicates
470 480
    relations_to.select {|r| r.relation_type == IssueRelation::TYPE_DUPLICATES}.collect {|r| r.issue_from}
app/views/gantts/show.html.erb (working copy)
1
<% include_calendar_headers_tags %>
1 2
<% @gantt.view = self %>
2 3
<h2><%= l(:label_gantt) %></h2>
3 4

  
......
41 42
<% zoom = 1
42 43
@gantt.zoom.times { zoom = zoom * 2 }
43 44

  
44
subject_width = 330
45
subject_width = 280
45 46
header_heigth = 18
46 47

  
47 48
headers_height = header_heigth
......
67 68

  
68 69

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

  
93
  }
94

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

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

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

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

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

  
71 210
<% if @gantt.truncated %>
72 211
	<p class="warning"><%= l(:notice_gantt_chart_truncated, :max => @gantt.max_rows) %></p>
73 212
<% end %>
......
86 225

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

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

  
237
</div>
238
</td>
89 239
<td>
90 240

  
91
<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">
92 242
<div style="width:<%= g_width-1 %>px;height:<%= headers_height %>px;background: #eee;" class="gantt_hdr">&nbsp;</div>
93 243
<% 
94 244
#
......
148 298
	left = 0
149 299
	height = g_height + header_heigth - 1
150 300
	wday = @gantt.date_from.cwday
301
        dt = @gantt.date_from
151 302
	(@gantt.date_to - @gantt.date_from + 1).to_i.times do 
152 303
	width =  zoom - 1
153 304
	%>
154 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">
155
	<%= day_name(wday).first %>
306
	<%=  "#{dt.day}<br>"if @gantt.zoom == 4 %><%= day_name(wday).first %>
156 307
	</div>
157 308
	<% 
158 309
	left = left + width+1
159 310
	wday = wday + 1
311
        dt = dt + 1
160 312
	wday = 1 if wday > 7
161 313
	end
162 314
end %>
163

  
164 315
<%= @gantt.lines %>
165 316

  
166 317
<%
config/routes.rb (working copy)
80 80
  map.quoted_issue '/issues/:id/quoted', :controller => 'journals', :action => 'new', :id => /\d+/, :conditions => { :method => :post }
81 81
  map.connect '/issues/:id/destroy', :controller => 'issues', :action => 'destroy', :conditions => { :method => :post } # legacy
82 82

  
83
  map.resource :gantt, :path_prefix => '/issues', :controller => 'gantts', :only => [:show, :update]
84
  map.resource :gantt, :path_prefix => '/projects/:project_id/issues', :controller => 'gantts', :only => [:show, :update]
83
  map.resource :gantt, :path_prefix => '/issues', :controller => 'gantts', :only => [:show, :update, :edit_gantt]
84
  map.resource :gantt, :path_prefix => '/projects/:project_id/issues', :controller => 'gantts', :only => [:show, :update, :edit_gantt]
85 85
  map.resource :calendar, :path_prefix => '/issues', :controller => 'calendars', :only => [:show, :update]
86 86
  map.resource :calendar, :path_prefix => '/projects/:project_id/issues', :controller => 'calendars', :only => [:show, :update]
87 87

  
lib/redmine/helpers/gantt.rb (working copy)
70 70
        
71 71
        @subjects = ''
72 72
        @lines = ''
73
        @calendars = ''
73 74
        @number_of_rows = nil
74 75
        
75 76
        @issue_ancestors = []
......
154 155
        render(options.merge(:only => :lines)) unless @lines_rendered
155 156
        @lines
156 157
      end
158

  
159
      # Renders the calendars of the Gantt chart, the right side
160
      def calendars(options={})
161
        render(options.merge(:only => :calendars)) unless @calendars_rendered
162
        @calendars
163
      end
157 164
      
158 165
      def render(options={})
159 166
        options = {:indent => 4, :render => :subject, :format => :html}.merge(options)
160 167
        
161
        @subjects = '' unless options[:only] == :lines
162
        @lines = '' unless options[:only] == :subjects
168
        @subjects = '' unless options[:only] == :lines && options[:only] == :calendars
169
        @lines = '' unless options[:only] == :subjects && options[:only] == :calendars
170
        @calendars = '' unless options[:only] == :lines && options[:only] == :subjects
163 171
        @number_of_rows = 0
164 172
        
165 173
        if @project
......
171 179
          end
172 180
        end
173 181
        
174
        @subjects_rendered = true unless options[:only] == :lines
175
        @lines_rendered = true unless options[:only] == :subjects
182
        @subjects_rendered = true unless options[:only] == :lines && options[:only] == :calendars
183
        @lines_rendered = true unless options[:only] == :subjects && options[:only] == :calendars
184
        @calendars_rendered = true unless options[:only] == :lines && options[:only] == :subjects
176 185
        
177 186
        render_end(options)
178 187
      end
......
182 191
        options[:indent_increment] = 20 unless options.key? :indent_increment
183 192
        options[:top_increment] = 20 unless options.key? :top_increment
184 193

  
185
        subject_for_project(project, options) unless options[:only] == :lines
186
        line_for_project(project, options) unless options[:only] == :subjects
194
        subject_for_project(project, options) unless options[:only] == :lines && options[:only] == :calendars
195
        line_for_project(project, options) unless options[:only] == :subjects && options[:only] == :calendars
196
        calendar_for_project(project, options) unless options[:only] == :lines && options[:only] == :subjects
187 197
        
188 198
        options[:top] += options[:top_increment]
189 199
        options[:indent] += options[:indent_increment]
......
218 228
        @issue_ancestors = []
219 229
        
220 230
        issues.each do |i|
221
          subject_for_issue(i, options) unless options[:only] == :lines
222
          line_for_issue(i, options) unless options[:only] == :subjects
231
          subject_for_issue(i, options) unless options[:only] == :lines && options[:only] == :calendars
232
          line_for_issue(i, options) unless options[:only] == :subjects && options[:only] == :calendars
233
          calendar_for_issue(i, options) unless options[:only] == :lines && options[:only] == :subjects
223 234
          
224 235
          options[:top] += options[:top_increment]
225 236
          @number_of_rows += 1
......
231 242

  
232 243
      def render_version(version, options={})
233 244
        # Version header
234
        subject_for_version(version, options) unless options[:only] == :lines
235
        line_for_version(version, options) unless options[:only] == :subjects
236
        
245
        subject_for_version(version, options) unless options[:only] == :lines && options[:only] == :calendars
246
        line_for_version(version, options) unless options[:only] == :subjects && options[:only] == :calendars
247
        calendar_for_version(version, options) unless options[:only] == :lines && options[:only] == :subjects
248

  
237 249
        options[:top] += options[:top_increment]
238 250
        @number_of_rows += 1
239 251
        return if abort?
......
286 298
          
287 299
          case options[:format]
288 300
          when :html
289
            html_task(options, coords, :css => "project task", :label => label, :markers => true)
301
            html_task(options, coords, :css => "project task", :label => label, :markers => true, :id => project.id, :kind => "p")
290 302
          when :image
291 303
            image_task(options, coords, :label => label, :markers => true, :height => 3)
292 304
          when :pdf
......
325 337

  
326 338
          case options[:format]
327 339
          when :html
328
            html_task(options, coords, :css => "version task", :label => label, :markers => true)
340
            html_task(options, coords, :css => "version task", :label => label, :markers => true, :id => version.id, :kind => "v")
329 341
          when :image
330 342
            image_task(options, coords, :label => label, :markers => true, :height => 3)
331 343
          when :pdf
......
378 390
        if issue.is_a?(Issue) && issue.due_before
379 391
          coords = coordinates(issue.start_date, issue.due_before, issue.done_ratio, options[:zoom])
380 392
          label = "#{ issue.status.name } #{ issue.done_ratio }%"
393
          if !issue.due_date && issue.fixed_version
394
            label += "-&nbsp;<strong>#{h(issue.fixed_version.name)}</strong>"
395
          end
381 396
          
382 397
          case options[:format]
383 398
          when :html
384
            html_task(options, coords, :css => "task " + (issue.leaf? ? 'leaf' : 'parent'), :label => label, :issue => issue, :markers => !issue.leaf?)
399
            html_task(options, coords, :css => "task " + (issue.leaf? ? 'leaf' : 'parent'), :label => label, :issue => issue, :markers => !issue.leaf?, :id => issue.id, :kind => "i")
385 400
          when :image
386 401
            image_task(options, coords, :label => label)
387 402
          when :pdf
......
393 408
        end
394 409
      end
395 410

  
396
      # Generates a gantt image
411
    # Generates a gantt image
397 412
      # Only defined if RMagick is avalaible
398 413
      def to_image(format='PNG')
399 414
        date_to = (@date_from >> @months)-1    
......
621 636
        pdf.Output
622 637
      end
623 638
      
639
      def edit(pms)
640
        id = pms[:id]
641
        kind = id.slice!(0).chr
642
        begin
643
          case kind
644
          when 'i'
645
            @issue = Issue.find(pms[:id], :include => [:project, :tracker, :status, :author, :priority, :category])
646
          when 'p'
647
            @issue = Project.find(pms[:id])
648
          when 'v'
649
            @issue = Version.find(pms[:id], :include => [:project])
650
          end
651
        rescue ActiveRecord::RecordNotFound
652
          return "issue not found : #{pms[:id]}", 400
653
        end
654

  
655
        if !@issue.start_date || !@issue.due_before
656
          #render :text=>l(:notice_locking_conflict), :status=>400
657
          return l(:notice_locking_conflict), 400
658
        end
659
        @issue.init_journal(User.current)
660
        date_from = Date.parse(pms[:date_from])
661
        old_start_date = @issue.start_date
662
        o = get_issue_position(@issue, pms[:zoom])
663
        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]}"
664

  
665
        if pms[:day]
666
          #bar moved
667
          day = pms[:day].to_i
668
          duration = @issue.due_before - @issue.start_date
669
          @issue.start_date = date_from + day
670
          @issue.due_date = @issue.start_date + duration.to_i if @issue.due_date
671
        elsif pms[:start_date]
672
          #start date changed
673
          start_date = Date.parse(pms[:start_date])
674
          if @issue.start_date == start_date
675
            #render :text=>""
676
            return "", 200 #nothing has changed
677
          end
678
          @issue.start_date = start_date
679
          @issue.due_date = start_date if @issue.due_date && start_date > @issue.due_date
680
        elsif pms[:due_date]
681
          #due date changed
682
          due_date = Date.parse(pms[:due_date])
683
          if @issue.due_date == due_date
684
            #render :text=>""
685
            return "", 200 #nothing has changed
686
          end
687
          @issue.due_date = due_date
688
          @issue.start_date = due_date if due_date < @issue.start_date
689
        end
690
        fv = @issue.fixed_version
691
        if fv && fv.effective_date && !@issue.due_date && fv.effective_date < @issue.start_date
692
          @issue.start_date = old_start_date
693
        end
694

  
695
        begin
696
          @issue.save!
697
          o = get_issue_position(@issue, pms[:zoom])
698
          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]}"
699

  
700
          prj_map = {}
701
          text = set_project_data(@issue.project, pms[:zoom], text, prj_map)
702
          version_map = {}
703
          text = set_version_data(@issue.fixed_version, pms[:zoom], text, version_map)
704

  
705
          #check dependencies
706
          issues = @issue.all_precedes_issues
707
          issues.each do |i|
708
            o = get_issue_position(i, pms[:zoom])
709
            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]}"
710
            text = set_project_data(i.project, pms[:zoom], text, prj_map)
711
            text = set_version_data(i.fixed_version, pms[:zoom], text, version_map)
712
          end
713
          #render :text=>text
714
          return text, 200
715
        rescue => e
716
          #render :text=>@issue.errors.full_messages.join("\n") + "|" + text_for_revert  , :status=>400
717
          return @issue.errors.full_messages.join("\n") + "|" + text_for_revert, 400
718
        end
719
      end
720

  
624 721
      private
625 722
      
626 723
      def coordinates(start_date, end_date, progress, zoom=nil)
......
739 836
        output = ''
740 837
        # Renders the task bar, with progress and late
741 838
        if coords[:bar_start] && coords[:bar_end]
742
          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>"
839
          i_width = coords[:bar_end] - coords[:bar_start] - 2
840
          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'" : ""}>"
841
          output << "<div id='task_todo_#{options[:kind]}#{options[:id]}' style='float:left:0px; width:#{ i_width}px;' class='#{options[:css]} task_todo'>&nbsp;</div>"
743 842
          
744 843
          if coords[:bar_late_end]
745
            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>"
844
            l_width = coords[:bar_late_end] - coords[:bar_start] - 2
845
            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>"
846
          else
847
            output << "<div id='task_late_#{options[:kind]}#{options[:id]}' style='float:left:0px; width:0px;' class='#{ options[:css] + " task_none"}'>&nbsp;</div>"
746 848
          end
747 849
          if coords[:bar_progress_end]
748
            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>"
850
            d_width = coords[:bar_progress_end] - coords[:bar_start] - 2
851
            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>"
852
          else
853
            output << "<div id='task_done_#{options[:kind]}#{options[:id]}' style='float:left:0px; width:0px;' class='#{ options[:css] + " task_none"}'>&nbsp;</div>"
749 854
          end
855
          output << "</div>"
856
        else
857
          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'" : ""}>"
858
          output << "<div id='task_todo_#{options[:kind]}#{options[:id]}' style='float:left:0px; width:0px;' class='#{ options[:css]} task_todo'>&nbsp;</div>"
859
          output << "<div id='task_late_#{options[:kind]}#{options[:id]}' style='float:left:0px; width:0px;' class='#{ options[:css] + " task_none"}'>&nbsp;</div>"
860
          output << "<div id='task_done_#{options[:kind]}#{options[:id]}' style='float:left:0px; width:0px;' class='#{ options[:css] + " task_none"}'>&nbsp;</div>"
861
          output << "</div>"
750 862
        end
751 863
        # Renders the markers
752 864
        if options[:markers]
753 865
          if coords[:start]
754
            output << "<div style='top:#{ params[:top] }px;left:#{ coords[:start] }px;width:15px;' class='#{options[:css]} marker starting'>&nbsp;</div>"
866
            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>"
755 867
          end
756 868
          if coords[:end]
757
            output << "<div style='top:#{ params[:top] }px;left:#{ coords[:end] + params[:zoom] }px;width:15px;' class='#{options[:css]} marker ending'>&nbsp;</div>"
869
            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>"
758 870
          end
759 871
        end
760 872
        # Renders the label on the right
761 873
        if options[:label]
762
          output << "<div style='top:#{ params[:top] }px;left:#{ (coords[:bar_end] || 0) + 8 }px;' class='#{options[:css]} label'>"
874
          output << "<div id='label_#{options[:kind]}#{options[:id]}' style='top:#{ params[:top] }px;left:#{ (coords[:bar_end] || 0) + 8 }px;' class='#{options[:css]} label'>"
763 875
          output << options[:label]
764 876
          output << "</div>"
765 877
        end
766 878
        # Renders the tooltip
767 879
        if options[:issue] && coords[:bar_start] && coords[:bar_end]
768
          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;'>"
880
          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;'>"
769 881
          output << '<span class="tip">'
770 882
          output << view.render_issue_tooltip(options[:issue])
771 883
          output << "</span></div>"
884

  
885
          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);}')
772 886
        end
773 887
        @lines << output
774 888
        output
......
857 971
          params[:image].text(params[:subject_width] + (coords[:bar_end] || 0) + 5,params[:top] + 1, options[:label])
858 972
        end
859 973
      end
974

  
975
      ##
976
      ##  for edit gantt
977
      ##
978
      def set_project_data(prj, zoom, text, prj_map = {})
979
        if !prj
980
          return text
981
        end
982
        if !prj_map[prj.id]
983
          o = get_project_position(prj, zoom)
984
          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]}"
985
          prj_map[prj.id] = prj
986
        end
987
        text = set_project_data(prj.parent, zoom, text, prj_map)
988
      end
989

  
990
      def set_version_data(version, zoom, text, version_map = {})
991
        if !version
992
          return text
993
        end
994
        if !version_map[version.id]
995
          o = get_version_position(version, zoom)
996
          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]}"
997
          version_map[version.id] = version
998
        end
999
        return text
1000
      end
1001

  
1002
      def get_pos(coords)
1003
        i_left = 0
1004
        i_width = 0
1005
        l_width = 0
1006
        d_width = 0
1007
        if coords[:bar_start]
1008
          i_left = coords[:bar_start]
1009
          if coords[:bar_end]
1010
            i_width = coords[:bar_end] - coords[:bar_start] - 2
1011
            i_width = 0 if i_width < 0
1012
          end
1013
          if coords[:bar_late_end]
1014
            l_width = coords[:bar_late_end] - coords[:bar_start] - 2
1015
          end
1016
          if coords[:bar_progress_end]
1017
            d_width = coords[:bar_progress_end] - coords[:bar_start] - 2
1018
          end
1019
        end
1020
        return i_left, i_width, l_width, d_width
1021
      end
1022

  
1023
      def get_issue_position(issue, zoom_str)
1024
        zoom = zoom_str.to_i
1025
        coords = coordinates(issue.start_date, issue.due_before, issue.done_ratio, zoom)
1026

  
1027
        return get_pos(coords)
1028
      end
1029

  
1030
      def get_project_position(project, zoom_str)
1031
        zoom = zoom_str.to_i
1032
        coords = coordinates(project.start_date, project.due_date, nil, zoom)
1033
        i_left, i_width, l_width, d_width = get_pos(coords)
1034
        return i_left, i_width, l_width, d_width, coords[:start], coords[:end] + zoom
1035
      end
1036

  
1037
      def get_version_position(version, zoom_str)
1038
        zoom = zoom_str.to_i
1039
        coords = coordinates(version.start_date, version.due_date, version.completed_pourcent, zoom)
1040
        i_left, i_width, l_width, d_width = get_pos(coords)
1041
        return i_left, i_width, l_width, d_width, coords[:start], coords[:end] + zoom
1042
      end
1043

  
1044
      def calendar_for_issue(issue, options)
1045
        # Skip issues that don't have a due_before (due_date or version's due_date)
1046
        if issue.is_a?(Issue) && issue.due_before
1047

  
1048
          case options[:format]
1049
          when :html
1050
            start_date = issue.start_date
1051
            if start_date
1052
              @calendars << "<div style='position: absolute;line-height:1.2em;height:16px;top:#{options[:top]}px;left:4px;overflow:hidden;'>"
1053
              @calendars << "<span id='i#{issue.id}_start_date_str'>"
1054
              @calendars << format_date(start_date)
1055
              @calendars << "</span>"
1056
              @calendars << "<input type='hidden' size='12' id='i#{issue.id}_hidden_start_date' value='#{start_date}' />"
1057
              @calendars << "<input type='hidden' size='12' id='i#{issue.id}_start_date' value='#{start_date}'>#{view.calendar_for('i' + issue.id.to_s + '_start_date')}"
1058
              @calendars << observe_date_field("i#{issue.id}", 'start')
1059
            end
1060
            due_date = issue.due_date
1061
            if due_date
1062
              @calendars << "<span id='i#{issue.id}_due_date_str'>"
1063
              @calendars << format_date(due_date)
1064
              @calendars << "</span>"
1065
              @calendars << "<input type='hidden' size='12' id='i#{issue.id}_hidden_due_date' value='#{due_date}' />"
1066
              @calendars << "<input type='hidden' size='12' id='i#{issue.id}_due_date' value='#{due_date}'>#{view.calendar_for('i' + issue.id.to_s + '_due_date')}"
1067
              @calendars << observe_date_field("i#{issue.id}", 'due')
1068
              @calendars << "</div>"
1069
            end
1070
          when :image
1071
            #nop
1072
          when :pdf
1073
            #nop
1074
          end
1075
        else
1076
          ActiveRecord::Base.logger.debug "GanttHelper#line_for_issue was not given an issue with a due_before"
1077
          ''
1078
        end
1079
      end
1080

  
1081
      def calendar_for_version(version, options)
1082
        # Skip version that don't have a due_before (due_date or version's due_date)
1083
        if version.is_a?(Version) && version.start_date && version.due_date
1084

  
1085
          case options[:format]
1086
          when :html
1087
            @calendars << "<div style='position: absolute;line-height:1.2em;height:16px;top:#{options[:top]}px;left:4px;overflow:hidden;'>"
1088
            @calendars << "<span id='v#{version.id}_start_date_str'>"
1089
            @calendars << format_date(version.effective_date)
1090
            @calendars << "</span>"
1091
            @calendars << "</div>"
1092
          when :image
1093
            #nop
1094
          when :pdf
1095
            #nop
1096
          end
1097
        else
1098
          ActiveRecord::Base.logger.debug "GanttHelper#line_for_issue was not given an issue with a due_before"
1099
          ''
1100
        end
1101
      end
1102

  
1103
      def calendar_for_project(project, options)
1104
        case options[:format]
1105
        when :html
1106
          @calendars << "<div style='position: absolute;line-height:1.2em;height:16px;top:#{options[:top]}px;left:4px;overflow:hidden;'>"
1107
          @calendars << "<span id='p#{project.id}_start_date_str'>"
1108
          @calendars << format_date(project.start_date) if project.start_date
1109
          @calendars << "</span>"
1110
          @calendars << "&nbsp;&nbsp;&nbsp;"
1111
          @calendars << "<span id='p#{project.id}_due_date_str'>"
1112
          @calendars << format_date(project.due_date) if project.due_date
1113
          @calendars << "</span>"
1114
          @calendars << "</div>"
1115
        when :image
1116
          # nop
1117
        when :pdf
1118
          # nop
1119
        end
1120
      end
1121

  
1122
      def observe_date_field(id, type)
1123
        output = ''
1124
        prj_id = ''
1125
        prj_id = @project.to_param if @project
1126
        output << "<script type='text/javascript'>\n"
1127
        output << "//<![CDATA[\n"
1128
        output << "new Form.Element.Observer('#{id}_#{type}_date', 0.25,\n"
1129
        output << "  function(element, value) {\n"
1130
        output << "    if (value == document.getElementById('#{id}_hidden_#{type}_date').value) {\n"
1131
        output << "      return ;\n"
1132
        output << "    }\n"
1133
        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*4, :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)});"
1134
        output << "  })\n"
1135
        output << "//]]>\n"
1136
        output << "</script>"
1137
      end
860 1138
    end
861 1139
  end
862 1140
end
public/stylesheets/application.css (working copy)
801 801
.task_late { background:#f66 url(../images/task_late.png); border: 1px solid #f66; }
802 802
.task_done { background:#00c600 url(../images/task_done.png); border: 1px solid #00c600; }  
803 803
.task_todo { background:#aaa url(../images/task_todo.png); border: 1px solid #aaa; }
804
.task_none { background:transparent; border-style: none; }
804 805

  
805 806
.task_todo.parent { background: #888; border: 1px solid #888; height: 3px;}
806 807
.task_late.parent, .task_done.parent { height: 3px;}