fix: bug in higher view modes
This commit is contained in:
parent
3e197c2369
commit
6f97f816f1
123
dist/frappe-gantt.es.js
vendored
123
dist/frappe-gantt.es.js
vendored
@ -1,4 +1,4 @@
|
||||
const M = "year", D = "month", $ = "day", E = "hour", Y = "minute", A = "second", L = "millisecond", S = {
|
||||
const k = "year", D = "month", $ = "day", E = "hour", Y = "minute", A = "second", L = "millisecond", S = {
|
||||
January: "Jan",
|
||||
February: "Feb",
|
||||
March: "Mar",
|
||||
@ -14,7 +14,7 @@ const M = "year", D = "month", $ = "day", E = "hour", Y = "minute", A = "second"
|
||||
}, h = {
|
||||
parse_duration(n) {
|
||||
const e = /([0-9]+)(y|m|d|h|min|s|ms)/gm.exec(n);
|
||||
if (console.log(e), e !== null) {
|
||||
if (e !== null) {
|
||||
if (e[2] === "y")
|
||||
return { duration: parseInt(e[1]), scale: "year" };
|
||||
if (e[2] === "m")
|
||||
@ -65,15 +65,17 @@ const M = "year", D = "month", $ = "day", E = "hour", Y = "minute", A = "second"
|
||||
};
|
||||
let d = t;
|
||||
const p = [];
|
||||
return Object.keys(a).sort((g, u) => u.length - g.length).forEach((g) => {
|
||||
return Object.keys(a).sort((g, c) => c.length - g.length).forEach((g) => {
|
||||
d.includes(g) && (d = d.replaceAll(g, `$${p.length}`), p.push(a[g]));
|
||||
}), p.forEach((g, u) => {
|
||||
d = d.replaceAll(`$${u}`, g);
|
||||
}), p.forEach((g, c) => {
|
||||
d = d.replaceAll(`$${c}`, g);
|
||||
}), d;
|
||||
},
|
||||
diff(n, t, e = $) {
|
||||
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(
|
||||
s = n - t, i = s / 1e3, o = i / 60, r = o / 60, a = r / 24;
|
||||
const g = n.getFullYear() - t.getFullYear(), c = n.getMonth() - t.getMonth();
|
||||
return d = g * 12 + c, n.getDate() < t.getDate() && d--, p = d / 12, e.endsWith("s") || (e += "s"), Math.floor(
|
||||
{
|
||||
milliseconds: s,
|
||||
seconds: i,
|
||||
@ -95,7 +97,7 @@ const M = "year", D = "month", $ = "day", E = "hour", Y = "minute", A = "second"
|
||||
add(n, t, e) {
|
||||
t = parseInt(t, 10);
|
||||
const s = [
|
||||
n.getFullYear() + (e === M ? t : 0),
|
||||
n.getFullYear() + (e === k ? t : 0),
|
||||
n.getMonth() + (e === D ? t : 0),
|
||||
n.getDate() + (e === $ ? t : 0),
|
||||
n.getHours() + (e === E ? t : 0),
|
||||
@ -107,7 +109,7 @@ const M = "year", D = "month", $ = "day", E = "hour", Y = "minute", A = "second"
|
||||
},
|
||||
start_of(n, t) {
|
||||
const e = {
|
||||
[M]: 6,
|
||||
[k]: 6,
|
||||
[D]: 5,
|
||||
[$]: 4,
|
||||
[E]: 3,
|
||||
@ -121,7 +123,7 @@ const M = "year", D = "month", $ = "day", E = "hour", Y = "minute", A = "second"
|
||||
}
|
||||
const i = [
|
||||
n.getFullYear(),
|
||||
s(M) ? 0 : n.getMonth(),
|
||||
s(k) ? 0 : n.getMonth(),
|
||||
s(D) ? 1 : n.getDate(),
|
||||
s($) ? 0 : n.getHours(),
|
||||
s(E) ? 0 : n.getMinutes(),
|
||||
@ -158,7 +160,7 @@ function v(n, t, e) {
|
||||
function _(n, t) {
|
||||
return typeof n == "string" ? (t || document).querySelector(n) : n || null;
|
||||
}
|
||||
function c(n, t) {
|
||||
function u(n, t) {
|
||||
const e = document.createElementNS("http://www.w3.org/2000/svg", n);
|
||||
for (let s in t)
|
||||
s === "append_to" ? t.append_to.appendChild(e) : s === "innerHTML" ? e.innerHTML = t.innerHTML : s === "clipPath" ? e.setAttribute("clip-path", "url(#" + t[s] + ")") : e.setAttribute(s, t[s]);
|
||||
@ -182,7 +184,7 @@ function W(n, t, e, s, i = "0.4s", r = "0.1s") {
|
||||
begin: "click + " + r
|
||||
// artificial click
|
||||
}), n;
|
||||
const a = c("animate", {
|
||||
const a = u("animate", {
|
||||
attributeName: t,
|
||||
from: e,
|
||||
to: s,
|
||||
@ -243,13 +245,13 @@ class O {
|
||||
this.prepare_values(), this.prepare_helpers();
|
||||
}
|
||||
prepare_values() {
|
||||
this.invalid = this.task.invalid, this.height = this.gantt.options.bar_height, this.image_size = this.height - 5, this.compute_x(), this.compute_y(), this.compute_duration(), this.corner_radius = this.gantt.options.bar_corner_radius, this.width = this.gantt.options.column_width * this.duration, this.progress_width = this.gantt.options.column_width * this.duration * (this.task.progress / 100) || 0, this.group = c("g", {
|
||||
this.invalid = this.task.invalid, this.height = this.gantt.options.bar_height, this.image_size = this.height - 5, this.compute_x(), this.compute_y(), this.compute_duration(), this.corner_radius = this.gantt.options.bar_corner_radius, this.width = this.gantt.options.column_width * this.duration, this.progress_width = this.gantt.options.column_width * this.duration * (this.task.progress / 100) || 0, this.group = u("g", {
|
||||
class: "bar-wrapper" + (this.task.custom_class ? " " + this.task.custom_class : "") + (this.task.important ? " important" : ""),
|
||||
"data-id": this.task.id
|
||||
}), this.bar_group = c("g", {
|
||||
}), this.bar_group = u("g", {
|
||||
class: "bar-group",
|
||||
append_to: this.group
|
||||
}), this.handle_group = c("g", {
|
||||
}), this.handle_group = u("g", {
|
||||
class: "handle-group",
|
||||
append_to: this.group
|
||||
});
|
||||
@ -274,7 +276,7 @@ class O {
|
||||
this.draw_bar(), this.draw_progress_bar(), this.gantt.options.show_expected_progress && (this.prepare_expected_progress_values(), this.draw_expected_progress_bar()), this.draw_label(), this.draw_resize_handles(), this.task.thumbnail && this.draw_thumbnail();
|
||||
}
|
||||
draw_bar() {
|
||||
this.$bar = c("rect", {
|
||||
this.$bar = u("rect", {
|
||||
x: this.x,
|
||||
y: this.y,
|
||||
width: this.width,
|
||||
@ -286,7 +288,7 @@ class O {
|
||||
}), H(this.$bar, "width", 0, this.width), this.invalid && this.$bar.classList.add("bar-invalid");
|
||||
}
|
||||
draw_expected_progress_bar() {
|
||||
this.invalid || (this.$expected_bar_progress = c("rect", {
|
||||
this.invalid || (this.$expected_bar_progress = u("rect", {
|
||||
x: this.x,
|
||||
y: this.y,
|
||||
width: this.expected_progress_width,
|
||||
@ -305,7 +307,7 @@ class O {
|
||||
draw_progress_bar() {
|
||||
if (this.invalid)
|
||||
return;
|
||||
this.$bar_progress = c("rect", {
|
||||
this.$bar_progress = u("rect", {
|
||||
x: this.x,
|
||||
y: this.y,
|
||||
width: this.progress_width,
|
||||
@ -321,7 +323,7 @@ class O {
|
||||
}
|
||||
draw_label() {
|
||||
let t = this.x + this.$bar.getWidth() / 2;
|
||||
this.task.thumbnail && (t = this.x + this.image_size + 5), c("text", {
|
||||
this.task.thumbnail && (t = this.x + this.image_size + 5), u("text", {
|
||||
x: t,
|
||||
y: this.y + this.height / 2,
|
||||
innerHTML: this.task.name,
|
||||
@ -331,9 +333,9 @@ class O {
|
||||
}
|
||||
draw_thumbnail() {
|
||||
let t = 10, e = 2, s, i;
|
||||
s = c("defs", {
|
||||
s = u("defs", {
|
||||
append_to: this.bar_group
|
||||
}), c("rect", {
|
||||
}), u("rect", {
|
||||
id: "rect_" + this.task.id,
|
||||
x: this.x + t,
|
||||
y: this.y + e,
|
||||
@ -342,13 +344,13 @@ class O {
|
||||
rx: "15",
|
||||
class: "img_mask",
|
||||
append_to: s
|
||||
}), i = c("clipPath", {
|
||||
}), i = u("clipPath", {
|
||||
id: "clip_" + this.task.id,
|
||||
append_to: s
|
||||
}), c("use", {
|
||||
}), u("use", {
|
||||
href: "#rect_" + this.task.id,
|
||||
append_to: i
|
||||
}), c("image", {
|
||||
}), u("image", {
|
||||
x: this.x + t,
|
||||
y: this.y + e,
|
||||
width: this.image_size,
|
||||
@ -363,7 +365,7 @@ class O {
|
||||
if (this.invalid || this.gantt.options.readonly)
|
||||
return;
|
||||
const t = this.$bar, e = 8;
|
||||
if (this.gantt.options.dates_readonly || (c("rect", {
|
||||
if (this.gantt.options.dates_readonly || (u("rect", {
|
||||
x: t.getX() + t.getWidth() + e - 4,
|
||||
y: t.getY() + 1,
|
||||
width: e,
|
||||
@ -372,7 +374,7 @@ class O {
|
||||
ry: this.corner_radius,
|
||||
class: "handle right",
|
||||
append_to: this.handle_group
|
||||
}), c("rect", {
|
||||
}), u("rect", {
|
||||
x: t.getX() - e - 4,
|
||||
y: t.getY() + 1,
|
||||
width: e,
|
||||
@ -383,7 +385,7 @@ class O {
|
||||
append_to: this.handle_group
|
||||
})), !this.gantt.options.progress_readonly) {
|
||||
const s = this.$bar_progress;
|
||||
this.$handle_progress = c("circle", {
|
||||
this.$handle_progress = u("circle", {
|
||||
cx: s.getEndX(),
|
||||
cy: s.getY() + s.getHeight() / 2,
|
||||
r: 5,
|
||||
@ -456,8 +458,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(), 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)));
|
||||
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, c = d + i.getBBox().width + 7, f = e + s.clientWidth / 2;
|
||||
i.classList.contains("big") || (c < a && t > 0 && c < f || d - g > this.$bar.getX() && t < 0 && c > f) && (i.setAttribute("x", d), r && (r.setAttribute("x", p), o.setAttribute("x", p)));
|
||||
}
|
||||
date_changed() {
|
||||
let t = !1;
|
||||
@ -505,7 +507,11 @@ class O {
|
||||
compute_x() {
|
||||
const { step: t, column_width: e } = this.gantt.options, s = this.task._start, i = this.gantt.gantt_start;
|
||||
let o = h.diff(s, i, "hour") / t * e;
|
||||
this.gantt.view_is("Month") && (o = h.diff(s, i, "day") * e / 30), this.x = o;
|
||||
if (this.gantt.view_is("Month")) {
|
||||
const a = h.diff(s, i, "month") * 30, d = Math.min(29, h.format(s, "DD"));
|
||||
o = (a + d) * e / 30;
|
||||
}
|
||||
this.x = o;
|
||||
}
|
||||
compute_y() {
|
||||
this.y = this.gantt.options.header_height + this.gantt.options.padding + this.task._index * (this.height + this.gantt.options.padding);
|
||||
@ -582,10 +588,10 @@ class C {
|
||||
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 - p, w = this.to_task.$bar.getX() - this.gantt.options.padding;
|
||||
const c = 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}
|
||||
v ${c}
|
||||
a ${a} ${a} 0 0 1 -${a} ${a}
|
||||
H ${w}
|
||||
a ${a} ${a} 0 0 ${d} -${a} ${p}
|
||||
@ -598,7 +604,7 @@ class C {
|
||||
}
|
||||
}
|
||||
draw() {
|
||||
this.element = c("path", {
|
||||
this.element = u("path", {
|
||||
d: this.path,
|
||||
"data-from": this.from_task.task.id,
|
||||
"data-to": this.to_task.task.id
|
||||
@ -688,7 +694,7 @@ class B {
|
||||
throw new TypeError(
|
||||
"Frappe Gantt only supports usage of a string CSS selector, HTML DOM element or SVG DOM element for the 'element' parameter"
|
||||
);
|
||||
e ? (this.$svg = e, this.$svg.classList.add("gantt")) : this.$svg = c("svg", {
|
||||
e ? (this.$svg = e, this.$svg.classList.add("gantt")) : this.$svg = u("svg", {
|
||||
append_to: s,
|
||||
class: "gantt"
|
||||
}), this.$container = document.createElement("div"), this.$container.classList.add("gantt-container"), this.$svg.parentElement.appendChild(this.$container), this.$container.appendChild(this.$svg), this.$popup_wrapper = document.createElement("div"), this.$popup_wrapper.classList.add("popup-wrapper"), this.$container.appendChild(this.$popup_wrapper);
|
||||
@ -719,7 +725,7 @@ class B {
|
||||
let o = [];
|
||||
e.dependencies && (o = e.dependencies.split(",").map((a) => a.trim().replaceAll(" ", "_")).filter((a) => a)), e.dependencies = o;
|
||||
}
|
||||
return e.id ? typeof e.id == "string" ? e.id = e.id.replaceAll(" ", "_") : e.id = `${e.id}` : e.id = z(e), e;
|
||||
return e.id ? typeof e.id == "string" ? e.id = e.id.replaceAll(" ", "_") : e.id = `${e.id}` : e.id = F(e), e;
|
||||
}), this.setup_dependencies();
|
||||
}
|
||||
setup_dependencies() {
|
||||
@ -784,7 +790,7 @@ class B {
|
||||
this.layers = {};
|
||||
const t = ["grid", "arrow", "progress", "bar", "details"];
|
||||
for (let e of t)
|
||||
this.layers[e] = c("g", {
|
||||
this.layers[e] = u("g", {
|
||||
class: e,
|
||||
append_to: this.$svg
|
||||
});
|
||||
@ -797,7 +803,7 @@ class B {
|
||||
}
|
||||
make_grid_background() {
|
||||
const t = this.dates.length * this.options.column_width, e = this.options.header_height + this.options.padding + (this.options.bar_height + this.options.padding) * this.tasks.length;
|
||||
c("rect", {
|
||||
u("rect", {
|
||||
x: 0,
|
||||
y: 0,
|
||||
width: t,
|
||||
@ -810,10 +816,10 @@ class B {
|
||||
});
|
||||
}
|
||||
make_grid_rows() {
|
||||
const t = c("g", { append_to: this.layers.grid }), e = this.dates.length * this.options.column_width, s = this.options.bar_height + this.options.padding;
|
||||
const t = u("g", { append_to: this.layers.grid }), e = this.dates.length * this.options.column_width, s = this.options.bar_height + this.options.padding;
|
||||
let i = this.options.header_height + this.options.padding / 2;
|
||||
for (let r of this.tasks)
|
||||
c("rect", {
|
||||
u("rect", {
|
||||
x: 0,
|
||||
y: i,
|
||||
width: e,
|
||||
@ -862,7 +868,7 @@ class B {
|
||||
}
|
||||
update_button_position() {
|
||||
const t = this.$container.getBoundingClientRect(), e = this.$side_header.getBoundingClientRect(), { left: s, y: i } = this.$header.getBoundingClientRect();
|
||||
console.log("heyy"), e.top < t.top || e.bottom > t.bottom ? (this.$side_header.style.position = "absolute", this.$side_header.style.top = `${t.scrollTop + e.top}px`) : (this.$side_header.style.position = "fixed", this.$side_header.style.top = i + 10 + "px");
|
||||
e.top < t.top || e.bottom > t.bottom ? (this.$side_header.style.position = "absolute", this.$side_header.style.top = `${t.scrollTop + e.top}px`) : (this.$side_header.style.position = "fixed", this.$side_header.style.top = i + 10 + "px");
|
||||
const r = Math.min(
|
||||
this.$header.clientWidth,
|
||||
this.$container.clientWidth
|
||||
@ -872,14 +878,14 @@ class B {
|
||||
make_grid_ticks() {
|
||||
if (!["both", "vertical", "horizontal"].includes(this.options.lines))
|
||||
return;
|
||||
let t = 0, e = this.options.header_height + this.options.padding / 2, s = (this.options.bar_height + this.options.padding) * this.tasks.length, i = c("g", {
|
||||
let t = 0, e = this.options.header_height + this.options.padding / 2, s = (this.options.bar_height + this.options.padding) * this.tasks.length, i = u("g", {
|
||||
class: "lines_layer",
|
||||
append_to: this.layers.grid
|
||||
}), 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 d of this.tasks)
|
||||
c("line", {
|
||||
u("line", {
|
||||
x1: 0,
|
||||
y1: r + a,
|
||||
x2: o,
|
||||
@ -890,7 +896,7 @@ class B {
|
||||
if (this.options.lines !== "horizontal")
|
||||
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", {
|
||||
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"), u("path", {
|
||||
d: `M ${t} ${e} v ${s}`,
|
||||
class: p,
|
||||
append_to: this.layers.grid
|
||||
@ -902,7 +908,7 @@ class B {
|
||||
for (let t = new Date(this.gantt_start); t <= this.gantt_end; t.setDate(t.getDate() + 1))
|
||||
if (t.getDay() === 0 || t.getDay() === 6) {
|
||||
const e = h.diff(t, this.gantt_start, "hour") / this.options.step * this.options.column_width, s = (this.options.bar_height + this.options.padding) * this.tasks.length;
|
||||
c("rect", {
|
||||
u("rect", {
|
||||
x: e,
|
||||
y: this.options.header_height + this.options.padding / 2,
|
||||
width: (this.view_is("Day") ? 1 : 2) * this.options.column_width,
|
||||
@ -940,13 +946,14 @@ class B {
|
||||
return { x: e, date: r };
|
||||
e += this.options.column_width;
|
||||
}
|
||||
return { x: e };
|
||||
}
|
||||
make_grid_highlights() {
|
||||
if (this.options.highlight_weekend && this.highlightWeekends(), this.view_is(l.DAY) || this.view_is(l.WEEK) || this.view_is(l.MONTH) || this.view_is(l.YEAR)) {
|
||||
const { x: t, date: e } = this.computeGridHighlightDimensions(
|
||||
this.options.view_mode
|
||||
);
|
||||
if (!this.dates.find((o) => o.getTime() == e.getTime()))
|
||||
if (!e || !this.dates.find((o) => o.getTime() == e.getTime()))
|
||||
return;
|
||||
const s = this.options.header_height + this.options.padding / 2, i = (this.options.bar_height + this.options.padding) * this.tasks.length;
|
||||
this.$current_highlight = this.create_el({
|
||||
@ -1125,8 +1132,8 @@ class B {
|
||||
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"), this.popup && this.popup.parent.classList.add("hidden"), e = p.offsetX || p.layerX, p.offsetY || p.layerY, o = u.getAttribute("data-id"), a = [
|
||||
const c = _.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), c.classList.add("active"), this.popup && this.popup.parent.classList.add("hidden"), this.popup && this.popup.parent.classList.add("hidden"), e = p.offsetX || p.layerX, p.offsetY || p.layerY, o = c.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) => {
|
||||
@ -1134,7 +1141,7 @@ class B {
|
||||
b.ox = b.getX(), b.oy = b.getY(), b.owidth = b.getWidth(), b.finaldx = 0;
|
||||
});
|
||||
}), _.on(this.$container, "scroll", (p) => {
|
||||
let g = document.querySelectorAll(".bar-wrapper"), u = [];
|
||||
let g = document.querySelectorAll(".bar-wrapper"), c = [];
|
||||
const f = [];
|
||||
let w;
|
||||
s && (w = p.currentTarget.scrollLeft - s);
|
||||
@ -1153,12 +1160,12 @@ class B {
|
||||
if (x && !x.classList.contains("current-upper")) {
|
||||
const m = document.querySelector(".current-upper");
|
||||
m && (m.classList.remove("current-upper"), m.style.left = this.upper_texts_x[m.textContent] + "px", m.style.top = this.options.header_height - 50 + "px"), x.classList.add("current-upper");
|
||||
let k = this.$svg.getBoundingClientRect();
|
||||
x.style.left = k.x + this.$container.scrollLeft + 10 + "px", x.style.top = k.y + this.options.header_height - 50 + "px";
|
||||
let M = this.$svg.getBoundingClientRect();
|
||||
x.style.left = M.x + this.$container.scrollLeft + 10 + "px", x.style.top = M.y + this.options.header_height - 50 + "px";
|
||||
}
|
||||
Array.prototype.forEach.call(g, function(m, k) {
|
||||
Array.prototype.forEach.call(g, function(m, M) {
|
||||
f.push(m.getAttribute("data-id"));
|
||||
}), w && (u = f.map((m) => this.get_bar(m)), this.options.auto_move_label && u.forEach((m) => {
|
||||
}), w && (c = f.map((m) => this.get_bar(m)), this.options.auto_move_label && c.forEach((m) => {
|
||||
m.update_label_position_on_horizontal_scroll({
|
||||
x: w,
|
||||
sx: p.currentTarget.scrollLeft
|
||||
@ -1168,16 +1175,16 @@ class B {
|
||||
if (!d())
|
||||
return;
|
||||
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({
|
||||
a.forEach((c) => {
|
||||
const f = c.$bar;
|
||||
f.finaldx = this.get_snap_position(g), this.hide_popup(), i ? o === c.task.id ? c.update_bar_position({
|
||||
x: f.ox + f.finaldx,
|
||||
width: f.owidth - f.finaldx
|
||||
}) : u.update_bar_position({
|
||||
}) : c.update_bar_position({
|
||||
x: f.ox + f.finaldx
|
||||
}) : r ? o === u.task.id && u.update_bar_position({
|
||||
}) : r ? o === c.task.id && c.update_bar_position({
|
||||
width: f.owidth + f.finaldx
|
||||
}) : t && !this.options.readonly && !this.options.dates_readonly && u.update_bar_position({ x: f.ox + f.finaldx });
|
||||
}) : t && !this.options.readonly && !this.options.dates_readonly && c.update_bar_position({ x: f.ox + f.finaldx });
|
||||
});
|
||||
}), document.addEventListener("mouseup", (p) => {
|
||||
t = !1, i = !1, r = !1;
|
||||
@ -1261,7 +1268,7 @@ class B {
|
||||
}
|
||||
}
|
||||
B.VIEW_MODE = l;
|
||||
function z(n) {
|
||||
function F(n) {
|
||||
return n.name + "_" + Math.random().toString(36).slice(2, 12);
|
||||
}
|
||||
export {
|
||||
|
||||
8
dist/frappe-gantt.umd.js
vendored
8
dist/frappe-gantt.umd.js
vendored
File diff suppressed because one or more lines are too long
@ -499,8 +499,15 @@ export default class Bar {
|
||||
const diff = date_utils.diff(task_start, gantt_start, 'hour');
|
||||
let x = (diff / step) * column_width;
|
||||
|
||||
/* Since the column width is based on 30,
|
||||
we count the month-difference, multiply it by 30 for a "pseudo-month"
|
||||
and then add the days in the month, making sure the number does not exceed 29
|
||||
so it is within the column */
|
||||
if (this.gantt.view_is('Month')) {
|
||||
const diff = date_utils.diff(task_start, gantt_start, 'day');
|
||||
const diffDaysBasedOn30DayMonths = date_utils.diff(task_start, gantt_start, 'month') * 30;
|
||||
const dayInMonth = Math.min(29, date_utils.format(task_start, "DD"));
|
||||
const diff = diffDaysBasedOn30DayMonths + dayInMonth;
|
||||
|
||||
x = (diff * column_width) / 30;
|
||||
}
|
||||
this.x = x;
|
||||
|
||||
@ -25,7 +25,6 @@ export default {
|
||||
parse_duration(duration) {
|
||||
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` };
|
||||
@ -137,13 +136,27 @@ export default {
|
||||
|
||||
diff(date_a, date_b, scale = DAY) {
|
||||
let milliseconds, seconds, hours, minutes, days, months, years;
|
||||
|
||||
|
||||
milliseconds = date_a - date_b;
|
||||
seconds = milliseconds / 1000;
|
||||
minutes = seconds / 60;
|
||||
hours = minutes / 60;
|
||||
days = hours / 24;
|
||||
months = days / 30;
|
||||
// Calculate months across years
|
||||
const yearDiff = date_a.getFullYear() - date_b.getFullYear();
|
||||
const monthDiff = date_a.getMonth() - date_b.getMonth();
|
||||
|
||||
/* If monthDiff is negative, date_b is in an earlier month than
|
||||
date_a and thus subtracted from the year difference in months */
|
||||
months = yearDiff * 12 + monthDiff;
|
||||
|
||||
/* If date_a's (e.g. march 1st) day of the month is smaller than date_b (e.g. february 28th),
|
||||
adjust the month difference */
|
||||
if (date_a.getDate() < date_b.getDate()) {
|
||||
months--;
|
||||
}
|
||||
|
||||
// Calculate years based on actual months
|
||||
years = months / 12;
|
||||
|
||||
if (!scale.endsWith('s')) {
|
||||
|
||||
@ -516,7 +516,7 @@ export default class Gantt {
|
||||
const { left, y } = this.$header.getBoundingClientRect();
|
||||
|
||||
// Check if the button is scrolled out of the container vertically
|
||||
console.log('heyy');
|
||||
|
||||
if (
|
||||
buttonRect.top < containerRect.top ||
|
||||
buttonRect.bottom > containerRect.bottom
|
||||
@ -677,10 +677,13 @@ export default class Gantt {
|
||||
x += this.options.column_width;
|
||||
}
|
||||
}
|
||||
|
||||
return { x }
|
||||
}
|
||||
|
||||
make_grid_highlights() {
|
||||
if (this.options.highlight_weekend) this.highlightWeekends();
|
||||
|
||||
// highlight today's | week's | month's | year's
|
||||
if (
|
||||
this.view_is(VIEW_MODE.DAY) ||
|
||||
@ -692,7 +695,7 @@ export default class Gantt {
|
||||
const { x: left, date } = this.computeGridHighlightDimensions(
|
||||
this.options.view_mode,
|
||||
);
|
||||
if (!this.dates.find((d) => d.getTime() == date.getTime())) return;
|
||||
if (!date || !this.dates.find((d) => d.getTime() == date.getTime())) return;
|
||||
const top = this.options.header_height + this.options.padding / 2;
|
||||
const height =
|
||||
(this.options.bar_height + this.options.padding) *
|
||||
@ -1292,7 +1295,7 @@ export default class Gantt {
|
||||
|
||||
trigger_event(event, args) {
|
||||
if (this.options['on_' + event]) {
|
||||
this.options['on_' + event].apply(this, args);
|
||||
this.options['on_' + event].apply(this, args)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user