6417-collapse-expand-gantt.patch

Yuichi HARADA, 2019-01-31 03:38

Download (11.1 KB)

View differences:

app/views/gantts/show.html.erb
375 375
    resizableSubjectColumn();
376 376
    $("#draw_relations").change(drawGanttHandler);
377 377
    $("#draw_progress_line").change(drawGanttHandler);
378
    $('div.gantt_subjects .expander').on('click', collapseOrExpandGantt);
378 379
  });
379 380
  $(window).resize(function() {
380 381
    drawGanttHandler();
lib/redmine/helpers/gantt.rb
195 195
        options = {:top => 0, :top_increment => 20,
196 196
                   :indent_increment => 20, :render => :subject,
197 197
                   :format => :html}.merge(options)
198
        options[:indent_increment ] += 12 if options[:format] == :html
198 199
        indent = options[:indent] || 4
199 200
        @subjects = '' unless options[:only] == :lines
200 201
        @lines = '' unless options[:only] == :subjects
......
221 222
          # then render project versions and their issues
222 223
          versions = project_versions(project)
223 224
          self.class.sort_versions!(versions)
225
          indent = options[:indent]
224 226
          versions.each do |version|
227
            options[:indent] = indent
225 228
            render_version(project, version, options)
226 229
          end
227 230
        end
......
698 701
      end
699 702

  
700 703
      def html_subject(params, subject, object)
701
        style = "position: absolute;top:#{params[:top]}px;left:#{params[:indent]}px;"
702
        style << "width:#{params[:subject_width] - params[:indent]}px;" if params[:subject_width]
703 704
        content = html_subject_content(object) || subject
704
        tag_options = {:style => style}
705
        tag_options = {}
705 706
        case object
706 707
        when Issue
707 708
          tag_options[:id] = "issue-#{object.id}"
708 709
          tag_options[:class] = "issue-subject hascontextmenu"
709 710
          tag_options[:title] = object.subject
711
          has_children = object.children?
710 712
        when Version
711 713
          tag_options[:id] = "version-#{object.id}"
712 714
          tag_options[:class] = "version-name"
715
          has_children = object.fixed_issues.exists?
713 716
        when Project
714 717
          tag_options[:class] = "project-name"
718
          has_children = object.issues.exists? || object.versions.exists?
719
        end
720
        tag_options[:data] = {
721
          :collapse_expand => {
722
            :top_increment => params[:top_increment],
723
            :obj_id => "#{object.class}-#{object.id}".downcase,
724
          },
725
        }
726
        if has_children
727
          content = view.content_tag(:span, nil, :class => :expander) + content
728
          params[:indent] -= 12 if params[:indent] >= 12
729
          tag_options[:class] << ' open'
715 730
        end
731
        style = "position: absolute;top:#{params[:top]}px;left:#{params[:indent]}px;"
732
        style << "width:#{params[:subject_width] - params[:indent]}px;" if params[:subject_width]
733
        tag_options[:style] = style
716 734
        output = view.content_tag(:div, content, tag_options)
717 735
        @subjects << output
718 736
        output
......
751 769

  
752 770
      def html_task(params, coords, markers, label, object)
753 771
        output = ''
772
        data_options = {
773
          :collapse_expand => "#{object.class}-#{object.id}".downcase,
774
        }
754 775

  
755 776
        css = "task " + case object
756 777
          when Project
......
774 795
          html_id = "task-todo-version-#{object.id}" if object.is_a?(Version)
775 796
          content_opt = {:style => style,
776 797
                         :class => "#{css} task_todo",
777
                         :id => html_id}
798
                         :id => html_id,
799
                         :data => {}}
778 800
          if object.is_a?(Issue)
779 801
            rels = issue_relations(object)
780 802
            if rels.present?
781 803
              content_opt[:data] = {"rels" => rels.to_json}
782 804
            end
783 805
          end
806
          content_opt[:data].merge!(data_options)
784 807
          output << view.content_tag(:div, '&nbsp;'.html_safe, content_opt)
785 808
          if coords[:bar_late_end]
786 809
            width = coords[:bar_late_end] - coords[:bar_start] - 2
......
790 813
            style << "width:#{width}px;"
791 814
            output << view.content_tag(:div, '&nbsp;'.html_safe,
792 815
                                       :style => style,
793
                                       :class => "#{css} task_late")
816
                                       :class => "#{css} task_late",
817
                                       :data => data_options)
794 818
          end
795 819
          if coords[:bar_progress_end]
796 820
            width = coords[:bar_progress_end] - coords[:bar_start] - 2
......
803 827
            output << view.content_tag(:div, '&nbsp;'.html_safe,
804 828
                                       :style => style,
805 829
                                       :class => "#{css} task_done",
806
                                       :id => html_id)
830
                                       :id => html_id,
831
                                       :data => data_options)
807 832
          end
808 833
        end
809 834
        # Renders the markers
......
815 840
            style << "width:15px;"
816 841
            output << view.content_tag(:div, '&nbsp;'.html_safe,
817 842
                                       :style => style,
818
                                       :class => "#{css} marker starting")
843
                                       :class => "#{css} marker starting",
844
                                       :data => data_options)
819 845
          end
820 846
          if coords[:end]
821 847
            style = ""
......
824 850
            style << "width:15px;"
825 851
            output << view.content_tag(:div, '&nbsp;'.html_safe,
826 852
                                       :style => style,
827
                                       :class => "#{css} marker ending")
853
                                       :class => "#{css} marker ending",
854
                                       :data => data_options)
828 855
          end
829 856
        end
830 857
        # Renders the label on the right
......
835 862
          style << "width:15px;"
836 863
          output << view.content_tag(:div, label,
837 864
                                     :style => style,
838
                                     :class => "#{css} label")
865
                                     :class => "#{css} label",
866
                                     :data => data_options)
839 867
        end
840 868
        # Renders the tooltip
841 869
        if object.is_a?(Issue) && coords[:bar_start] && coords[:bar_end]
......
851 879
          style << "height:12px;"
852 880
          output << view.content_tag(:div, s.html_safe,
853 881
                                     :style => style,
854
                                     :class => "tooltip hascontextmenu")
882
                                     :class => "tooltip hascontextmenu",
883
                                     :data => data_options)
855 884
        end
856 885
        @lines << output
857 886
        output
public/javascripts/gantt.js
17 17
function getRelationsArray() {
18 18
  var arr = new Array();
19 19
  $.each($('div.task_todo[data-rels]'), function(index_div, element) {
20
    if(!$(element).is(':visible')) return true;
20 21
    var element_id = $(element).attr("id");
21 22
    if (element_id != null) {
22 23
      var issue_id = element_id.replace("task-todo-issue-", "");
......
106 107
  var today_left = $('#today_line').position().left;
107 108
  arr.push({left: today_left, top: 0});
108 109
  $.each($('div.issue-subject, div.version-name'), function(index, element) {
110
    if(!$(element).is(':visible')) return true;
109 111
    var t = $(element).position().top - draw_top ;
110 112
    var h = ($(element).height() / 9);
111 113
    var element_top_upper  = t - h;
......
169 171
    draw_gantt = Raphael(folder);
170 172
  setDrawArea();
171 173
  if ($("#draw_progress_line").prop('checked'))
172
    drawGanttProgressLines();
174
    try{drawGanttProgressLines();}catch(e){}
173 175
  if ($("#draw_relations").prop('checked'))
174 176
    drawRelations();
175 177
}
......
195 197
    $('td.gantt_subjects_column').resizable('enable');
196 198
  };
197 199
}
200

  
201
collapseOrExpandGantt = function(e){
202
  var subject = $(e.target.parentElement);
203
  var subject_left = parseInt(subject.css('left'));
204
  var target_shown = null;
205
  var target_top = 0;
206
  var total_height = 0;
207
  var out_of_hierarchy = false;
208
  var iconChange = null;
209
  if(subject.hasClass('open'))
210
    iconChange = function(element){
211
      $(element).removeClass('open');
212
    };
213
  else
214
    iconChange = function(element){
215
      $(element).addClass('open');
216
    };
217
  iconChange(subject);
218
  subject.nextAll('div').each(function(_, element){
219
    var el = $(element);
220
    var json = el.data('collapse-expand');
221
    if(out_of_hierarchy || parseInt(el.css('left')) <= subject_left){
222
      out_of_hierarchy = true;
223
      if(target_shown == null) return false;
224

  
225
      var new_top_val = parseInt(el.css('top')) + total_height * (target_shown ? -1 : 1);
226
      el.css('top', new_top_val);
227
      $('#gantt_area form > div[data-collapse-expand="' + json.obj_id + '"]').each(function(_, task){
228
        $(task).css('top', new_top_val);
229
      });
230
      return true;
231
    }
232

  
233
    var is_shown = el.is(':visible');
234
    if(target_shown == null){
235
      target_shown = is_shown;
236
      target_top = parseInt(el.css('top'));
237
      total_height = 0;
238
    }
239
    if(is_shown == target_shown){
240
      $('#gantt_area form > div[data-collapse-expand="' + json.obj_id + '"]').each(function(_, task){
241
        var el_task = $(task);
242
        if(!is_shown)
243
          el_task.css('top', target_top + total_height);
244
        if(!el_task.hasClass('tooltip'))
245
          el_task.toggle(!is_shown);
246
      });
247
      if(!is_shown)
248
        el.css('top', target_top + total_height);
249
      iconChange(el);
250
      el.toggle(!is_shown);
251
      total_height += parseInt(json.top_increment);
252
    }
253
  });
254
  drawGanttHandler();
255
};
public/stylesheets/application.css
290 290
tr.entry.file td.filename a { margin-left: 16px; }
291 291
tr.entry.file td.filename_no_report a { margin-left: 16px; }
292 292

  
293
tr span.expander {background: url(../images/arrow_right.png) no-repeat 2px 50%; padding-left: 8px; margin-left: 0; cursor: pointer;}
294
tr.open span.expander {background-image: url(../images/arrow_down.png);}
293
tr span.expander, .gantt_subjects div > span.expander {background: url(../images/arrow_right.png) no-repeat 2px 50%; padding-left: 8px; margin-left: 0; cursor: pointer;}
294
tr.open span.expander, .gantt_subjects div.open > span.expander {background-image: url(../images/arrow_down.png);}
295
.gantt_subjects div > span.expander {padding-left: 12px;}
295 296

  
296 297
tr.changeset { height: 20px }
297 298
tr.changeset ul, ol { margin-top: 0px; margin-bottom: 0px; }