fix: more bugs

This commit is contained in:
Safwan Samsudeen 2024-05-02 16:05:08 +05:30
parent 30a8d5a78b
commit e648769ec5
5 changed files with 67 additions and 71 deletions

118
dist/frappe-gantt.js vendored
View File

@ -13,8 +13,8 @@ const M = "year", D = "month", v = "day", E = "hour", Y = "minute", A = "second"
December: "Dec"
}, h = {
parse_duration(n) {
const e = /([0-9])+(y|m|d|h|min|s|ms)/gm.exec(n);
if (e !== null) {
const e = /([0-9]+)(y|m|d|h|min|s|ms)/gm.exec(n);
if (console.log(e), e !== null) {
if (e[2] === "y")
return { duration: parseInt(e[1]), scale: "year" };
if (e[2] === "m")
@ -63,25 +63,25 @@ const M = "year", D = "month", v = "day", E = "hour", Y = "minute", A = "second"
MMMM: r,
MMM: T[r]
};
let p = t;
const d = [];
let d = t;
const p = [];
return Object.keys(a).sort((g, u) => u.length - g.length).forEach((g) => {
p.includes(g) && (p = p.replaceAll(g, `$${d.length}`), d.push(a[g]));
}), d.forEach((g, u) => {
p = p.replaceAll(`$${u}`, g);
}), p;
d.includes(g) && (d = d.replaceAll(g, `$${p.length}`), p.push(a[g]));
}), p.forEach((g, u) => {
d = d.replaceAll(`$${u}`, g);
}), d;
},
diff(n, t, e = v) {
let s, i, r, o, a, p, d;
return s = n - t, i = s / 1e3, o = i / 60, r = o / 60, a = r / 24, p = a / 30, d = p / 12, e.endsWith("s") || (e += "s"), Math.floor(
let s, i, r, o, a, d, p;
return s = n - t, i = s / 1e3, o = i / 60, r = o / 60, a = r / 24, d = a / 30, p = d / 12, e.endsWith("s") || (e += "s"), Math.floor(
{
milliseconds: s,
seconds: i,
minutes: o,
hours: r,
days: a,
months: p,
years: d
months: d,
years: p
}[e]
);
},
@ -456,8 +456,8 @@ class O {
}
update_label_position_on_horizontal_scroll({ x: t, sx: e }) {
const s = document.querySelector(".gantt-container"), i = this.group.querySelector(".bar-label"), r = this.group.querySelector(".bar-img") || "", o = this.bar_group.querySelector(".img_mask") || "";
let a = this.$bar.getX() + this.$bar.getWidth(), p = i.getX() + t, d = r && r.getX() + t || 0, g = r && r.getBBox().width + 7 || 7, u = p + i.getBBox().width + 7, f = e + s.clientWidth / 2;
i.classList.contains("big") || (u < a && t > 0 && u < f || p - g > this.$bar.getX() && t < 0 && u > f) && (i.setAttribute("x", p), r && (r.setAttribute("x", d), o.setAttribute("x", d)));
let a = this.$bar.getX() + this.$bar.getWidth(), d = i.getX() + t, p = r && r.getX() + t || 0, g = r && r.getBBox().width + 7 || 7, u = d + i.getBBox().width + 7, f = e + s.clientWidth / 2;
i.classList.contains("big") || (u < a && t > 0 && u < f || d - g > this.$bar.getX() && t < 0 && u > f) && (i.setAttribute("x", d), r && (r.setAttribute("x", p), o.setAttribute("x", p)));
}
date_changed() {
let t = !1;
@ -533,8 +533,8 @@ class O {
update_label_position() {
const t = this.bar_group.querySelector(".img_mask") || "", e = this.$bar, s = this.group.querySelector(".bar-label"), i = this.group.querySelector(".bar-img");
let r = 5, o = this.image_size + 10;
const a = s.getBBox().width, p = e.getWidth();
a > p ? (s.classList.add("big"), i ? (i.setAttribute("x", e.getX() + e.getWidth() + r), t.setAttribute(
const a = s.getBBox().width, d = e.getWidth();
a > d ? (s.classList.add("big"), i ? (i.setAttribute("x", e.getX() + e.getWidth() + r), t.setAttribute(
"x",
e.getX() + e.getWidth() + r
), s.setAttribute(
@ -542,10 +542,10 @@ class O {
e.getX() + e.getWidth() + o
)) : s.setAttribute("x", e.getX() + e.getWidth() + r)) : (s.classList.remove("big"), i ? (i.setAttribute("x", e.getX() + r), t.setAttribute("x", e.getX() + r), s.setAttribute(
"x",
e.getX() + p / 2 + o
e.getX() + d / 2 + o
)) : s.setAttribute(
"x",
e.getX() + p / 2 - a / 2
e.getX() + d / 2 - a / 2
));
}
update_handle_position() {
@ -554,7 +554,7 @@ class O {
const t = this.$bar;
this.handle_group.querySelector(".handle.left").setAttribute("x", t.getX() - 12), this.handle_group.querySelector(".handle.right").setAttribute("x", t.getEndX() + 4);
const e = this.group.querySelector(".handle.progress");
console.log(e, this.$bar_progress.getEndX()), e && e.setAttribute("cx", this.$bar_progress.getEndX());
e && e.setAttribute("cx", this.$bar_progress.getEndX());
}
update_arrow_position() {
this.arrows = this.arrows || [];
@ -571,24 +571,24 @@ class C {
const e = () => this.to_task.$bar.getX() < t + this.gantt.options.padding && t > this.from_task.$bar.getX() + this.gantt.options.padding;
for (; e(); )
t -= 10;
const s = this.gantt.options.header_height + this.gantt.options.bar_height + (this.gantt.options.padding + this.gantt.options.bar_height) * this.from_task.task._index + this.gantt.options.padding, i = this.to_task.$bar.getX() - this.gantt.options.padding / 2 - 7, r = this.gantt.options.header_height + this.gantt.options.bar_height / 2 + (this.gantt.options.padding + this.gantt.options.bar_height) * this.to_task.task._index + this.gantt.options.padding, o = this.from_task.task._index > this.to_task.task._index, a = this.gantt.options.arrow_curve, p = o ? 1 : 0, d = o ? -a : a, g = o ? r + this.gantt.options.arrow_curve : r - this.gantt.options.arrow_curve;
const s = this.gantt.options.header_height + this.gantt.options.bar_height + (this.gantt.options.padding + this.gantt.options.bar_height) * this.from_task.task._index + this.gantt.options.padding, i = this.to_task.$bar.getX() - this.gantt.options.padding / 2 - 7, r = this.gantt.options.header_height + this.gantt.options.bar_height / 2 + (this.gantt.options.padding + this.gantt.options.bar_height) * this.to_task.task._index + this.gantt.options.padding, o = this.from_task.task._index > this.to_task.task._index, a = this.gantt.options.arrow_curve, d = o ? 1 : 0, p = o ? -a : a, g = o ? r + this.gantt.options.arrow_curve : r - this.gantt.options.arrow_curve;
if (this.path = `
M ${t} ${s}
V ${g}
a ${a} ${a} 0 0 ${p} ${a} ${d}
a ${a} ${a} 0 0 ${d} ${a} ${p}
L ${i} ${r}
m -5 -5
l 5 5
l -5 5`, this.to_task.$bar.getX() < this.from_task.$bar.getX() + this.gantt.options.padding) {
const u = this.gantt.options.padding / 2 - a, f = this.to_task.$bar.getY() + this.to_task.$bar.getHeight() / 2 - d, w = this.to_task.$bar.getX() - this.gantt.options.padding;
const u = this.gantt.options.padding / 2 - a, f = this.to_task.$bar.getY() + this.to_task.$bar.getHeight() / 2 - p, w = this.to_task.$bar.getX() - this.gantt.options.padding;
this.path = `
M ${t} ${s}
v ${u}
a ${a} ${a} 0 0 1 -${a} ${a}
H ${w}
a ${a} ${a} 0 0 ${p} -${a} ${d}
a ${a} ${a} 0 0 ${d} -${a} ${p}
V ${f}
a ${a} ${a} 0 0 ${p} ${a} ${d}
a ${a} ${a} 0 0 ${d} ${a} ${p}
L ${i} ${r}
m -5 -5
l 5 5
@ -652,7 +652,6 @@ const l = {
}, R = {
header_height: 65,
column_width: 30,
step: 24,
view_modes: [...Object.values(l)],
bar_height: 30,
bar_corner_radius: 3,
@ -704,8 +703,8 @@ class F {
setup_tasks(t) {
this.tasks = t.map((e, s) => {
if (e._start = h.parse(e.start), e.end === void 0 && e.duration !== void 0 && (e.end = e._start, e.duration.split(" ").forEach((a) => {
let { duration: p, scale: d } = h.parse_duration(a);
e.end = h.add(e.end, p, d);
let { duration: d, scale: p } = h.parse_duration(a);
e.end = h.add(e.end, d, p);
})), e._end = h.parse(e.end), h.diff(e._end, e._start, "year") < 0)
throw Error(
"start of task can't be after end of task: in task #, " + (s + 1)
@ -746,8 +745,8 @@ class F {
let t, e;
this.gantt_start ? t = h.start_of(this.gantt_start, "day") : t = /* @__PURE__ */ new Date(), this.gantt_end ? e = h.start_of(this.gantt_end, "day") : e = /* @__PURE__ */ new Date();
let s;
for (let [a, p] of Object.entries(l))
p === this.options.view_mode && (s = a);
for (let [a, d] of Object.entries(l))
d === this.options.view_mode && (s = a);
const [i, r] = this.options.view_mode_padding[s].map(h.parse_duration);
t = h.add(
t,
@ -838,8 +837,8 @@ class F {
const o = document.createElement("option");
o.selected = !0, o.disabled = !0, o.textContent = "Mode", r.appendChild(o);
for (const a in l) {
const p = document.createElement("option");
p.value = l[a], p.textContent = l[a], r.appendChild(p);
const d = document.createElement("option");
d.value = l[a], d.textContent = l[a], r.appendChild(d);
}
r.addEventListener(
"change",
@ -868,7 +867,7 @@ class F {
}), r = this.options.header_height + this.options.padding / 2;
const o = this.dates.length * this.options.column_width, a = this.options.bar_height + this.options.padding;
if (this.options.lines !== "vertical")
for (let p of this.tasks)
for (let d of this.tasks)
c("line", {
x1: 0,
y1: r + a,
@ -878,13 +877,13 @@ class F {
append_to: i
}), r += a;
if (this.options.lines !== "horizontal")
for (let p of this.dates) {
let d = "tick";
this.view_is(l.DAY) && p.getDate() === 1 && (d += " thick"), this.view_is(l.WEEK) && p.getDate() >= 1 && p.getDate() < 8 && (d += " thick"), this.view_is(l.MONTH) && p.getMonth() % 3 === 0 && (d += " thick"), c("path", {
for (let d of this.dates) {
let p = "tick";
this.view_is(l.DAY) && d.getDate() === 1 && (p += " thick"), this.view_is(l.WEEK) && d.getDate() >= 1 && d.getDate() < 8 && (p += " thick"), this.view_is(l.MONTH) && d.getMonth() % 3 === 0 && (p += " thick"), c("path", {
d: `M ${t} ${e} v ${s}`,
class: d,
class: p,
append_to: this.layers.grid
}), this.view_is(l.MONTH) ? t += h.get_days_in_month(p) * this.options.column_width / 30 : t += this.options.column_width;
}), this.view_is(l.MONTH) ? t += h.get_days_in_month(d) * this.options.column_width / 30 : t += this.options.column_width;
}
}
highlightWeekends() {
@ -946,12 +945,12 @@ class F {
let r = document.getElementById(
h.format(e).replaceAll(" ", "_")
);
r.classList.add("current-date-highlight"), r.style.top = +r.style.top.slice(0, -2) - 4 + "px", r.style.left = +r.style.left.slice(0, -2) - 8 + "px";
r && (r.classList.add("current-date-highlight"), r.style.top = +r.style.top.slice(0, -2) - 4 + "px", r.style.left = +r.style.left.slice(0, -2) - 8 + "px");
}
}
create_el({ left: t, top: e, width: s, height: i, id: r, classes: o, append_to: a }) {
let p = document.createElement("div");
return p.classList.add(o), p.style.top = e + "px", p.style.left = t + "px", r && (p.id = r), s && (p.style.width = i + "px"), i && (p.style.height = i + "px"), a.appendChild(p), p;
let d = document.createElement("div");
return d.classList.add(o), d.style.top = e + "px", d.style.left = t + "px", r && (d.id = r), s && (d.style.width = i + "px"), i && (d.style.height = i + "px"), a.appendChild(d), d;
}
make_dates() {
this.upper_texts_x = {}, this.get_dates_to_draw().forEach((t, e) => {
@ -1111,26 +1110,26 @@ class F {
bind_bar_events() {
let t = !1, e = 0, s = 0, i = !1, r = !1, o = null, a = [];
this.bar_being_dragged = null;
function p() {
function d() {
return t || i || r;
}
this.$svg.onclick = (d) => {
d.target.classList.contains("grid-row") && this.unselect_all();
}, _.on(this.$svg, "mousedown", ".bar-wrapper, .handle", (d, g) => {
this.$svg.onclick = (p) => {
p.target.classList.contains("grid-row") && this.unselect_all();
}, _.on(this.$svg, "mousedown", ".bar-wrapper, .handle", (p, g) => {
const u = _.closest(".bar-wrapper", g);
a.forEach((w) => w.group.classList.remove("active")), g.classList.contains("left") ? i = !0 : g.classList.contains("right") ? r = !0 : g.classList.contains("bar-wrapper") && (t = !0), u.classList.add("active"), this.popup && this.popup.parent.classList.add("hidden"), e = d.offsetX || d.layerX, d.offsetY || d.layerY, o = u.getAttribute("data-id"), a = [
a.forEach((w) => w.group.classList.remove("active")), g.classList.contains("left") ? i = !0 : g.classList.contains("right") ? r = !0 : g.classList.contains("bar-wrapper") && (t = !0), u.classList.add("active"), this.popup && this.popup.parent.classList.add("hidden"), e = p.offsetX || p.layerX, p.offsetY || p.layerY, o = u.getAttribute("data-id"), a = [
o,
...this.get_all_dependent_tasks(o)
].map((w) => this.get_bar(w)), this.bar_being_dragged = o, a.forEach((w) => {
const b = w.$bar;
b.ox = b.getX(), b.oy = b.getY(), b.owidth = b.getWidth(), b.finaldx = 0;
});
}), _.on(this.$container, "scroll", (d) => {
}), _.on(this.$container, "scroll", (p) => {
let g = document.querySelectorAll(".bar-wrapper"), u = [];
const f = [];
let w;
s && (w = d.currentTarget.scrollLeft - s);
const b = d.currentTarget.scrollLeft / this.options.column_width * this.options.step / 24;
s && (w = p.currentTarget.scrollLeft - s);
const b = p.currentTarget.scrollLeft / this.options.column_width * this.options.step / 24;
let y = "D MMM";
["Year", "Month"].includes(this.options.view_mode) ? y = "YYYY" : ["Day", "Week"].includes(this.options.view_mode) ? y = "MMMM" : this.view_is("Half Day") ? y = "D" : this.view_is("Hour") && (y = "D MMMM");
let S = h.format(
@ -1153,14 +1152,13 @@ class F {
}), w && (u = f.map((m) => this.get_bar(m)), this.options.auto_move_label && u.forEach((m) => {
m.update_label_position_on_horizontal_scroll({
x: w,
sx: d.currentTarget.scrollLeft
sx: p.currentTarget.scrollLeft
});
})), s = d.currentTarget.scrollLeft;
}), _.on(this.$svg, "mousemove", (d) => {
if (!p())
})), s = p.currentTarget.scrollLeft;
}), _.on(this.$svg, "mousemove", (p) => {
if (!d())
return;
console.log(d);
const g = (d.offsetX || d.layerX) - e;
const g = (p.offsetX || p.layerX) - e;
a.forEach((u) => {
const f = u.$bar;
f.finaldx = this.get_snap_position(g), this.hide_popup(), i ? o === u.task.id ? u.update_bar_position({
@ -1172,9 +1170,9 @@ class F {
width: f.owidth + f.finaldx
}) : t && !this.options.readonly && !this.options.dates_readonly && u.update_bar_position({ x: f.ox + f.finaldx });
});
}), document.addEventListener("mouseup", (d) => {
}), document.addEventListener("mouseup", (p) => {
t = !1, i = !1, r = !1;
}), _.on(this.$svg, "mouseup", (d) => {
}), _.on(this.$svg, "mouseup", (p) => {
this.bar_being_dragged = null, a.forEach((g) => {
g.$bar.finaldx && (g.date_changed(), g.set_action_completed());
});
@ -1184,15 +1182,15 @@ class F {
let t = 0, e = null, s = null, i = null, r = null;
_.on(this.$svg, "mousedown", ".handle.progress", (o, a) => {
e = !0, t = o.offsetX || o.layerX, o.offsetY || o.layerY;
const d = _.closest(".bar-wrapper", a).getAttribute("data-id");
s = this.get_bar(d), i = s.$bar_progress, r = s.$bar, i.finaldx = 0, i.owidth = i.getWidth(), i.min_dx = -i.getWidth(), i.max_dx = r.getWidth() - i.getWidth();
const p = _.closest(".bar-wrapper", a).getAttribute("data-id");
s = this.get_bar(p), i = s.$bar_progress, r = s.$bar, i.finaldx = 0, i.owidth = i.getWidth(), i.min_dx = -i.getWidth(), i.max_dx = r.getWidth() - i.getWidth();
}), _.on(this.$svg, "mousemove", (o) => {
if (!e)
return;
let a = (o.offsetX || o.layerX) - t;
a > i.max_dx && (a = i.max_dx), a < i.min_dx && (a = i.min_dx);
const p = s.$handle_progress;
_.attr(i, "width", i.owidth + a), _.attr(p, "cx", i.getEndX()), i.finaldx = a;
const d = s.$handle_progress;
_.attr(i, "width", i.owidth + a), _.attr(d, "cx", i.getEndX()), i.finaldx = a;
}), _.on(this.$svg, "mouseup", () => {
e = !1, i && i.finaldx && (i.finaldx = 0, s.progress_changed(), s.set_action_completed(), s = null, i = null, r = null);
});

File diff suppressed because one or more lines are too long

View File

@ -634,7 +634,6 @@ export default class Bar {
.querySelector('.handle.right')
.setAttribute('x', bar.getEndX() + 4);
const handle = this.group.querySelector('.handle.progress');
console.log(handle, this.$bar_progress.getEndX())
handle &&
handle.setAttribute('cx', this.$bar_progress.getEndX());
}

View File

@ -23,9 +23,9 @@ const SHORTENED = {
export default {
parse_duration(duration) {
const regex = /([0-9])+(y|m|d|h|min|s|ms)/gm;
const regex = /([0-9]+)(y|m|d|h|min|s|ms)/gm;
const matches = regex.exec(duration);
console.log(matches)
if (matches !== null) {
if (matches[2] === 'y') {
return { duration: parseInt(matches[1]), scale: `year` };

View File

@ -29,7 +29,6 @@ const VIEW_MODE_PADDING = {
const DEFAULT_OPTIONS = {
header_height: 65,
column_width: 30,
step: 24,
view_modes: [...Object.values(VIEW_MODE)],
bar_height: 30,
bar_corner_radius: 3,
@ -676,10 +675,11 @@ export default class Gantt {
let $today = document.getElementById(
date_utils.format(date).replaceAll(' ', '_'),
);
$today.classList.add('current-date-highlight');
$today.style.top = +$today.style.top.slice(0, -2) - 4 + 'px';
$today.style.left = +$today.style.left.slice(0, -2) - 8 + 'px';
if ($today) {
$today.classList.add('current-date-highlight');
$today.style.top = +$today.style.top.slice(0, -2) - 4 + 'px';
$today.style.left = +$today.style.left.slice(0, -2) - 8 + 'px';
}
}
}
@ -1064,7 +1064,6 @@ export default class Gantt {
$.on(this.$svg, 'mousemove', (e) => {
if (!action_in_progress()) return;
console.log(e);
const dx = (e.offsetX || e.layerX) - x_on_start;
bars.forEach((bar) => {