forked from namespace-ee/react-calendar-timeline
-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.html
233 lines (202 loc) · 7.49 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
<!doctype html>
<html>
<head>
<title>react calendar timeline Demo</title>
<link href='https://fonts.googleapis.com/css?family=Lato' rel='stylesheet' type='text/css'>
<script src="https://use.fontawesome.com/742757c98f.js"></script>
</head>
<body style='font-family: "Lato";margin: 0;font-size: 13px;'>
<div id="main"></div>
<i class="draggable fa fa-leaf"></i>
<div class="draggable" >A New Group</div>
<script src="https://cdnjs.cloudflare.com/ajax/libs/babel-polyfill/6.13.0/polyfill.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/15.0.2/react.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/15.0.2/react-dom.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.10.6/moment.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/interact.js/1.2.6/interact.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/immutable/3.7.6/immutable.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/Faker/3.0.1/faker.js"></script>
<!-- <link href='build/dist/react-calendar-timeline.min.css' rel='stylesheet' type='text/css'>
<script src="build/dist/react-calendar-timeline.min.js"></script> -->
<link href='build/dist/react-calendar-timeline.css' rel='stylesheet' type='text/css'>
<script src="build/dist/react-calendar-timeline.js"></script>
<style>
.react-calendar-timeline .rct-item.item-weekend {
background: #21F32C;
border-color: #29B31A;
}
.draggable {
position: absolute;
background: red;
width: 100px;
z-index: 10;
}
</style>
<script>
function dragMoveListener (event) {
var target = event.target,
// keep the dragged position in the data-x/data-y attributes
x = (parseFloat(target.getAttribute('data-x')) || 0) + event.dx,
y = (parseFloat(target.getAttribute('data-y')) || 0) + event.dy;
// translate the element
target.style.webkitTransform =
target.style.transform =
'translate(' + x + 'px, ' + y + 'px)';
// update the posiion attributes
target.setAttribute('data-x', x);
target.setAttribute('data-y', y);
}
interact('.draggable')
.draggable({
// enable inertial throwing
inertia: true,
// keep the element within the area of it's parent
restrict: {
//restriction: "parent",
endOnly: true,
//elementRect: { top: 0, left: 0, bottom: 1, right: 1 }
},
autoScroll: true,
onmove: dragMoveListener,
})
;
</script>
<script>
GROUP_COUNT = 100
ITEM_COUNT = 1000
DAYS_IN_PAST = 30
var groups = []
for (var i = 0; i < GROUP_COUNT; i++) {
groups.push({
id: (i+1)+'',
title: faker.name.firstName(),
canSelect: Math.random() >= 0.5,
dropTarget: Math.random() >= 0.5,
})
};
var items = []
var i = 0;
for (i = 0; i < ITEM_COUNT; i++) {
var startDate = faker.date.recent(DAYS_IN_PAST).valueOf() + (DAYS_IN_PAST * 0.3) * 86400 * 1000;
var startValue = Math.floor(moment(startDate).valueOf() / 10000000) * 10000000;
var endValue = moment(startDate + faker.random.number({min: 2, max: 20})*15*60*1000).valueOf();
console.log(startValue);
console.log(endValue);
items.push({
id: i+'',
group: 1+'', //faker.random.number({min: 1, max: groups.length})+'',
title: faker.hacker.phrase(),
start: startValue,
end: endValue,
canMove: startValue > new Date().getTime(),
canResize: startValue > new Date().getTime() ? (endValue > new Date().getTime() ? 'both' : 'left') : (endValue > new Date().getTime() ? 'right' : false),
className: (moment(startDate).day() === 6 || moment(startDate).day() === 0) ? 'item-weekend' : '',
dropTarget: Math.random() >= 0.5,
itemProps: {
'data-tip': 'Boo' + faker.hacker.phrase()
}
})
}
console.log(moment("2017-01-05T09:00:00").unix()*1000)
items = items.sort(function(a, b) { return b - a; })
groups = [
{id:1+'',title:"Boo A03"}];
var minTime = moment().add(-6, 'months').valueOf()
var maxTime = moment().add(6, 'months').valueOf()
var props = {
groups: groups,
items: items,
fixedHeader: 'fixed',
fullUpdate: true,
canMove: true, // defaults
canResize: 'right',
canSelect: true,
canSelectGroups: false,
dragSnap: 60*1000,
itemsSorted: true,
itemTouchSendsClick: false,
stackItems: true,
itemHeightRatio: 0.75,
defaultTimeStart: moment().startOf('day').toDate(),
defaultTimeEnd: moment().startOf('day').add(1, 'day').toDate(),
keys: {
groupIdKey: 'id',
groupTitleKey: 'title',
itemIdKey: 'id',
itemTitleKey: 'title',
itemDivTitleKey: 'title',
itemGroupKey: 'group',
itemTimeStartKey: 'start',
itemTimeEndKey: 'end'
},
onCanvasClick: function(event) {
console.log("Canvas clicked");
},
onItemClick: function(item) {
console.log("Clicked: " + item);
},
onItemSelect: function(item) {
console.log("Selected: " + item);
},
onItemContextMenu: function (item) {
console.log("Context Menu: " + item);
},
onItemMove: function (item, time) {
console.log("Moved", item, time);
},
onItemDrop: function (item) {
console.log("Item Drop", item);
},
onItemResize: function (item, time, edge) {
console.log("Resized", item, time, edge);
},
onGroupContextMenu: function (group) {
console.log("Group Context menu", group);
},
onGroupDrop: function (group) {
console.log("Group drop", group);
},
onGroupSelect: function (group) {
console.log("Group select", group);
},
onGroupClick: function (group) {
console.log("Group click", group);
},
onGroupTimelineDrop: function (group) {
console.log("Timeline Drop", group);
},
onGroupTimelineContextMenu: function (group) {
console.log("Timeline Context Menu", group);
},
onGroupTimelineSelect: function (group) {
console.log("Timeline Select", group);
},
onGroupTimelineClick: function (group) {
console.log("Timeline Click", group);
},
moveResizeValidator: function(action, item, time, resizeEdge) {
if (time < new Date().getTime()) {
var newTime = Math.ceil(new Date().getTime() / (15*60*1000)) * (15*60*1000);
return newTime;
}
return time
},
// this limits the timeline to -6 months ... +6 months
onTimeChange: function (visibleTimeStart, visibleTimeEnd, updateScrollCanvas) {
if (visibleTimeStart < minTime && visibleTimeEnd > maxTime) {
updateScrollCanvas(minTime, maxTime)
} else if (visibleTimeStart < minTime) {
updateScrollCanvas(minTime, minTime + (visibleTimeEnd - visibleTimeStart))
} else if (visibleTimeEnd > maxTime) {
updateScrollCanvas(maxTime - (visibleTimeEnd - visibleTimeStart), maxTime)
} else {
updateScrollCanvas(visibleTimeStart, visibleTimeEnd)
}
}
}
var filter = React.createElement("div", {}, "The filter");
/* jshint undef:false */
ReactDOM.render(React.createElement(ReactCalendarTimeline['default'], props, filter), document.getElementById('main'));
</script>
</body>
</html>