2
0
mirror of https://github.com/tenrok/vue-ganttastic.git synced 2026-06-25 13:50:33 +03:00

HTML content can be dropped on g-gantt-rows now.

The drop event returns the native event, the bar dropped on and the time dropped on
This commit is contained in:
Marko Zunic
2020-06-02 14:20:56 +02:00
parent c1be46fd8e
commit ba318235a9
+24 -1
View File
@@ -3,6 +3,7 @@
class="g-gantt-row" class="g-gantt-row"
ref="g-gantt-row" ref="g-gantt-row"
:style="{height: `${$parent.rowHeight}px`}" :style="{height: `${$parent.rowHeight}px`}"
v-on="$listeners"
> >
<div <div
class="g-gantt-row-label" class="g-gantt-row-label"
@@ -16,6 +17,8 @@
class="g-gantt-row-bars-container" class="g-gantt-row-bars-container"
ref="barContainer" ref="barContainer"
:style="barsContainerStyle" :style="barsContainerStyle"
@dragover="onDragover($event)"
@drop="onDrop($event)"
@mouseover="onMouseover()" @mouseover="onMouseover()"
@mouseleave="onMouseleave()" @mouseleave="onMouseleave()"
> >
@@ -42,6 +45,7 @@
<script> <script>
import GGanttBar from './GGanttBar.vue' import GGanttBar from './GGanttBar.vue'
import moment from 'moment'
export default { export default {
@@ -59,7 +63,13 @@ export default {
highlightOnHover: Boolean, highlightOnHover: Boolean,
}, },
inject: ["ganttChartProps", "getThemeColors"], inject: [
"ganttChartProps",
"getThemeColors",
"getHourCount",
"getChartStart",
"getChartEnd"
],
data(){ data(){
return { return {
@@ -93,6 +103,19 @@ export default {
methods:{ methods:{
onDragover(e) {
e.preventDefault() // enables dropping content on row
},
onDrop(e){
let barContainer = this.$refs.barContainer.getBoundingClientRect()
let xPos = e.clientX - barContainer.left
let hourDiffFromStart = (xPos/barContainer.width) * this.getHourCount()
let time = moment(this.getChartStart()).add(hourDiffFromStart, "hours")
let bar = this.bars.find(bar => time.isBetween(bar[this.barStart], bar[this.barEnd]))
this.$emit("drop", {event: e, bar, time: time.format("YYYY-MM-DD HH:mm:ss")})
},
onMouseover(){ onMouseover(){
if(this.highlightOnHover){ if(this.highlightOnHover){
this.$refs["g-gantt-row"].style.backgroundColor = this.getThemeColors().hoverHighlight this.$refs["g-gantt-row"].style.backgroundColor = this.getThemeColors().hoverHighlight