-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.html
351 lines (293 loc) · 12.5 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
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8">
<title>Test</title>
<link rel="stylesheet" type="text/css" href="https://uicdn.toast.com/tui-calendar/latest/tui-calendar.css" />
<!-- If you use the default popups, use this. -->
<link rel="stylesheet" type="text/css" href="https://uicdn.toast.com/tui.date-picker/latest/tui-date-picker.css" />
<link rel="stylesheet" type="text/css" href="https://uicdn.toast.com/tui.time-picker/latest/tui-time-picker.css" />
<script src="https://apps.bdimg.com/libs/jquery/2.1.4/jquery.min.js"></script>
<script src="https://uicdn.toast.com/tui.code-snippet/latest/tui-code-snippet.js"></script>
<script src="https://uicdn.toast.com/tui.dom/v3.0.0/tui-dom.js"></script>
<script src="https://uicdn.toast.com/tui.time-picker/latest/tui-time-picker.min.js"></script>
<script src="https://uicdn.toast.com/tui.date-picker/latest/tui-date-picker.min.js"></script>
<script src="https://uicdn.toast.com/tui-calendar/latest/tui-calendar.js"></script>
<script src="./log_data.js"></script>
<script src="./config.js"></script>
</head>
<body>
<div id="menu">
<span id="menu-navi">
<button type="button" class="btn btn-default btn-sm move-today" data-action="move-today">Today</button>
<button type="button" class="btn btn-default btn-sm move-day" data-action="move-prev">
上个月
</button>
<button type="button" class="btn btn-default btn-sm move-day" data-action="move-next">
下个月
</button>
<li id="date">dad</li>
</span>
<span id="renderRange" class="render-range"></span>
</div>
<div id="calendar" style="height: 800px;"></div>
<script>
// https://nhn.github.io/tui.calendar/latest/Calendar#getDate
var Calendar = tui.Calendar;
prepareHolidayConfig();
var cal = new tui.Calendar('#calendar', {
defaultView: 'month',
});
cal.on('afterRenderSchedule', function(event) {
// var schedule = event.schedule;
// var element = calendar.getElement(schedule.id, schedule.calendarId);
// // use the element
// console.log(element);
// refreshDate();
// console.log(cal.getDate().toDate());
});
refreshDate();
var actions = {};
function refreshDate()
{
let dt1 = cal.getDateRangeStart().toDate();
let dt = new Date(dt1.getTime() + 10 * 24 * 3600 * 1000);
$('li#date')[0].innerHTML = dt.getFullYear() + "-" + (dt.getMonth() + 1) ;
// console.log(dt, dt.getMonth());
}
// Delegate click events on the body to those DOM nodes which have a data-action attribute
$('body').on('click', '[data-action]', function() {
var action = $(this).data('action');
if (action in actions) {
actions[action].apply(this, arguments);
}
});
actions["move-prev"] = function()
{
cal.prev();
refreshDate();
}
actions["move-next"] = function()
{
cal.next();
refreshDate();
}
actions["move-today"] = function()
{
cal.today();
refreshDate();
}
if (window._logData)
{
console.log("find commit log data");
let schedules = [];
let excludeAuthors = {};
if (window._excludeAuthors)
{
for (let i = 0; i < window._excludeAuthors.length; i++)
{
excludeAuthors[window._excludeAuthors[i]] = true;
}
}
let logData = window._logData;
for (let i = 0; i < logData.length; i++)
{
if (excludeAuthors[logData[i][1]])
{
continue;
}
let dt = new Date(logData[i][0]);
let info = checkCommitInfo(dt);
// todo : 节假日排除
if (info.isOverWork)
{
let year = info.year;
let month = info.month.toString();
if (month.length < 2)
{
month = "0" + month;
}
let date = info.date.toString();
if (date.length < 2)
{
date = "0" + date;
}
let dateString = year + '-' + month + '-' + date; // 归属时间,过夜时间将归属到前一天
let timeString = dt.getHours() + ":" + dt.getMinutes();
schedules.push({
id: (i+1).toString(),
calendarId: '1',
title: logData[i][1] + " " + timeString,
body:logData[i][0],
category: 'allday',
dueDateClass: '',
// schedule类型为allday的时候,只解析start前十个字符?
// 并且日期格式必须为yyyy-mm-dd,mm和dd必须为两位数
start: dateString,
end: dateString,
bgColor : info.color,
gravity : info.gravity,
year : info.year,
month : info.month,
date : info.date,
author : logData[i][1],
});
// console.log(dateString);
}
}
schedules.sort(function(a,b){
let s1 = a.year * 10000000 + a.month * 100 + a.date;
let s2 = b.year * 10000000 + b.month * 100 + b.date;
if (s1 != s2)
{
// 不同日的,早的时间在前
return s1 - s2;
}
// 同日的,时间晚的在前面
return b.gravity - a.gravity;
})
cal.createSchedules(schedules);
}
// cal.createSchedules([
// {
// id: '1',
// calendarId: '1',
// title: 'my schedule',
// body:'aaaaa',
// category: 'allday',
// dueDateClass: '',
// start: '2019-11-18',
// end: '2019-11-18',
// bgColor : '#ffeeee'
// },
// {
// id: '2',
// calendarId: '1',
// title: 'second schedule',
// category: 'allday',
// dueDateClass: '',
// start: "2019-11-18",
// end: "2019-11-18",
// isReadOnly: true // schedule is read-only
// }
// ]);
function prepareHolidayConfig()
{
let holidayConfig = window._holidayConfig;
for (let key in holidayConfig.extraHoliday)
{
let yearConfig = holidayConfig.extraHoliday[key];
for (let key2 in yearConfig)
{
let monthConfig = yearConfig[key2];
if (monthConfig)
{
let obj = {};
for (let i = 0; i< monthConfig.length; i++)
{
obj[monthConfig[i]] = true;
}
yearConfig[key2] = obj;
}
}
}
for (let key in holidayConfig.extraWorkingDay)
{
let yearConfig = holidayConfig.extraWorkingDay[key];
for (let key2 in yearConfig)
{
let monthConfig = yearConfig[key2];
if (monthConfig)
{
let obj = {};
for (let i = 0; i< monthConfig.length; i++)
{
obj[monthConfig[i]] = true;
}
yearConfig[key2] = obj;
}
}
}
let weekendObj = {};
for (let i = 0; i < holidayConfig.weekend.length; i++)
{
weekendObj[holidayConfig.weekend[i]] = true;
}
holidayConfig.weekend = weekendObj;
}
function isHoliday(year, month, date, day)
{
let holidayConfig = window._holidayConfig;
if (holidayConfig.extraHoliday[year] && holidayConfig.extraHoliday[year][month] && holidayConfig.extraHoliday[year][month][date])
{
return true;
}
if (holidayConfig.extraWorkingDay[year] && holidayConfig.extraWorkingDay[year][month] && holidayConfig.extraWorkingDay[year][month][date])
{
return false;
}
if (holidayConfig.weekend[day])
{
return true;
}
return false;
}
function checkCommitInfo(dt)
{
// dt = new Date();
let year = dt.getFullYear();
let month = dt.getMonth() + 1;
let date = dt.getDate();
let day = dt.getDay();
let hour = dt.getHours();
let minute = dt.getMinutes();
let hourF = hour + minute / 60;
let isOverWork = false;
let color = "";
let gravity = 0;
if (isHoliday(year, month, date,day))
{
isOverWork = true;
color = window._holidayConfig.color;
}
let hourConfig = window._hourConfig;
let result;
// console.log(hour);
if (hourConfig.customFunc)
{
result = hourConfig.customFunc(hourF);
}
else
{
result = hourConfig[hour];
}
if (result)
{
isOverWork = true;
if (result.color)
{
color = result.color;
}
}
let dt2;
gravity = hour;
if (result && result.overnight)
{
gravity += 24;
dt2 = new Date(dt.getTime() - 1000 * 24 * 3600);
}
else
{
dt2 = dt;
}
return {
isOverWork : isOverWork,
color : color,
gravity : gravity,
year : dt2.getFullYear(),
month : dt2.getMonth() + 1,
date : dt2.getDate(),
}
}
</script>
</body>
</html>