Project

General

Profile

Feature #43678 » 0003-Update-Gantt-collapse-expand-handler-to-use-CSS-logi.patch

Go MAEDA, 2026-01-25 06:08

View differences:

app/javascript/controllers/gantt/subjects_controller.js
17 17
  handleEntryClick(event) {
18 18
    const iconExpander = event.currentTarget
19 19
    const $subject = this.$(iconExpander.parentElement)
20
    const subjectLeft =
21
      parseInt($subject.css("left"), 10) + parseInt(iconExpander.offsetWidth, 10)
20
    const subjectInlineStart =
21
      this.#readInlineStart($subject) + parseInt(iconExpander.offsetWidth, 10)
22 22

  
23 23
    let targetShown = null
24 24
    let targetTop = 0
......
36 36
      const barsSelector = `#gantt_area form > div[data-collapse-expand='${json.obj_id}'][data-number-of-rows='${numberOfRows}']`
37 37
      const selectedColumnsSelector = `td.gantt_selected_column div[data-collapse-expand='${json.obj_id}'][data-number-of-rows='${numberOfRows}']`
38 38

  
39
      if (outOfHierarchy || parseInt($element.css("left"), 10) <= subjectLeft) {
39
      if (outOfHierarchy || this.#readInlineStart($element) <= subjectInlineStart) {
40 40
        outOfHierarchy = true
41 41

  
42 42
        if (targetShown === null) return false
43 43

  
44
        const newTopVal = parseInt($element.css("top"), 10) + totalHeight * (targetShown ? -1 : 1)
44
        const newTopVal = this.#readBlockStart($element) + totalHeight * (targetShown ? -1 : 1)
45 45

  
46
        $element.css("top", newTopVal)
46
        this.#setBlockStart($element, newTopVal)
47 47
        this.$([barsSelector, selectedColumnsSelector].join()).each((__, el) => {
48
          this.$(el).css("top", newTopVal)
48
          this.#setBlockStart(this.$(el), newTopVal)
49 49
        })
50 50

  
51 51
        return true
......
55 55

  
56 56
      if (targetShown === null) {
57 57
        targetShown = isShown
58
        targetTop = parseInt($element.css("top"), 10)
58
        targetTop = this.#readBlockStart($element)
59 59
        totalHeight = 0
60 60
      }
61 61

  
......
64 64
          const $task = this.$(task)
65 65

  
66 66
          if (!isShown && willOpen) {
67
            $task.css("top", targetTop + totalHeight)
67
            this.#setBlockStart($task, targetTop + totalHeight)
68 68
          }
69 69
          if (!$task.hasClass("tooltip")) {
70 70
            $task.toggle(willOpen)
......
75 75
          const $attr = this.$(attr)
76 76

  
77 77
          if (!isShown && willOpen) {
78
            $attr.css("top", targetTop + totalHeight)
78
            this.#setBlockStart($attr, targetTop + totalHeight)
79 79
          }
80 80
          $attr.toggle(willOpen)
81 81
        })
82 82

  
83 83
        if (!isShown && willOpen) {
84
          $element.css("top", targetTop + totalHeight)
84
          this.#setBlockStart($element, targetTop + totalHeight)
85 85
        }
86 86

  
87 87
        this.#setIconState($element, willOpen)
......
93 93
    this.dispatch("toggle-tree", { bubbles: true })
94 94
  }
95 95

  
96
  #getComputedPx(el, property) {
97
    const node = el.jquery ? el[0] : el    
98
    const styles = window.getComputedStyle(node)
99
    const val = styles.getPropertyValue(property)
100
    if (val) {
101
      const num = parseFloat(val)
102
      if (!Number.isNaN(num)) return num
103
    }
104
    return NaN
105
  }
106

  
107
  #readInlineStart(el) {
108
    return this.#getComputedPx(el, "inset-inline-start")
109
  }
110

  
111
  #readBlockStart(el) {
112
    return this.#getComputedPx(el, "inset-block-start")
113
  }
114

  
115
  #setBlockStart(el, value) {
116
    const node = el.jquery ? el[0] : el
117
    const px = typeof value === "number" ? `${value}px` : value
118
    node.style.setProperty("inset-block-start", px)
119
  }
120

  
96 121
  #setIconState(element, open) {
97 122
    const $element = element.jquery ? element : this.$(element)
98 123
    const expander = $element.find(".expander")
lib/redmine/helpers/gantt.rb
817 817
        end
818 818
        if has_children
819 819
          content = view.content_tag(:span,
820
                                     view.sprite_icon('angle-down').html_safe,
820
                                     view.sprite_icon('angle-down', rtl: true).html_safe,
821 821
                                     :class => 'icon icon-expanded expander',
822 822
                                     :data => {:action => 'click->gantt--subjects#handleEntryClick'}) + content
823 823
          tag_options[:class] += ' open'
(4-4/5)