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 | 1×
1×
1×
1×
76×
76×
1×
74×
74×
823×
823×
823×
823×
74×
1×
66×
66×
1086×
1086×
1086×
1086×
66×
1×
67×
67×
1100×
1100×
1100×
1100×
1100×
37×
1100×
1100×
67×
1×
207×
207×
153×
207×
207×
207×
366×
366×
366×
86×
86×
86×
280×
280×
74×
74×
79×
79×
127×
280×
280×
366×
207×
1×
76×
76×
76×
76×
37×
76×
76×
76×
76×
76×
321×
321×
74×
74×
74×
74×
66×
66×
66×
66×
67×
67×
67×
67×
63×
63×
1049×
1049×
63×
63×
51×
37×
51×
76×
1×
1×
| define(["require", "exports", "@syncfusion/ej2-base", "../base/util"], function (require, exports, ej2_base_1, util_1) {
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var TimelineHeaderRow = (function () {
function TimelineHeaderRow(parent, renderDates) {
this.parent = parent;
this.renderDates = renderDates;
}
TimelineHeaderRow.prototype.groupByYear = function (dates) {
var result = {};
for (var _i = 0, dates_1 = dates; _i < dates_1.length; _i++) {
var d = dates_1[_i];
var key = d.getFullYear();
result[parseInt(key.toString(), 10)] = result[parseInt(key.toString(), 10)] || [];
result[parseInt(key.toString(), 10)].push(d);
}
return result;
};
TimelineHeaderRow.prototype.groupByMonth = function (dates) {
var result = {};
for (var _i = 0, dates_2 = dates; _i < dates_2.length; _i++) {
var d = dates_2[_i];
var key = (d.getFullYear() - 1970) * 12 + d.getMonth();
result[parseInt(key.toString(), 10)] = result[parseInt(key.toString(), 10)] || [];
result[parseInt(key.toString(), 10)].push(d);
}
return result;
};
TimelineHeaderRow.prototype.groupByWeek = function (dates) {
var result = {};
for (var _i = 0, dates_3 = dates; _i < dates_3.length; _i++) {
var d = dates_3[_i];
var jsDate = +new Date(1970, 0, 1);
var tzOffsetDiff = d.getTimezoneOffset() - new Date(1970, 0, 1).getTimezoneOffset();
var key = Math.ceil(((((+d - jsDate) - (tzOffsetDiff * 60 * 1000)) / util_1.MS_PER_DAY) + new Date(jsDate).getDay() + 1) / 7);
if (this.parent.activeViewOptions.firstDayOfWeek && this.parent.activeViewOptions.firstDayOfWeek > new Date(+d).getDay()) {
key = key - 1;
}
result[parseInt(key.toString(), 10)] = result[parseInt(key.toString(), 10)] || [];
result[parseInt(key.toString(), 10)].push(d);
}
return result;
};
TimelineHeaderRow.prototype.generateSlots = function (data, colspan, row, cls, type) {
var _this = this;
var dateParser = function (date, format) {
return _this.parent.globalize.formatDate(date, { format: format, calendar: _this.parent.getCalendarMode() });
};
var tdDatas = [];
var keys = Object.keys(data);
for (var i = 0; i < keys.length; i++) {
var dates = data[keys[parseInt(i.toString(), 10)]];
var htmlCol = void 0;
if (row.template) {
var args = { date: dates[0], type: type };
var templateId = this.parent.element.id + '_headerRowTemplate';
htmlCol = [].slice.call(this.parent.templateParser(row.template)(args, this.parent, 'template', templateId, false));
}
else {
var viewTemplate = void 0;
switch (row.option) {
case 'Year':
viewTemplate = "<span class=\"e-header-year\">" + dateParser(dates[0], 'y') + "</span>";
break;
case 'Month':
viewTemplate = "<span class=\"e-header-month\">" + util_1.capitalizeFirstWord(dateParser(dates[0], 'MMMM'), 'single') + "</span>";
break;
case 'Week':
viewTemplate = "<span class=\"e-header-week\">" + this.parent.getWeekNumberContent(dates) + "</span>";
}
var headerWrapper = ej2_base_1.createElement('div', { innerHTML: viewTemplate });
htmlCol = [].slice.call(headerWrapper.childNodes);
}
tdDatas.push({ date: dates[0], type: type, className: [cls], colSpan: dates.length * colspan, template: htmlCol });
}
return tdDatas;
};
TimelineHeaderRow.prototype.generateColumnLevels = function (dateSlots, hourSlots) {
var levels = [];
var rows = this.parent.activeViewOptions.headerRows;
var lastLevelColspan = 1;
if (rows[rows.length - 1].option === 'Hour' && hourSlots.length > 0) {
lastLevelColspan = hourSlots.length / dateSlots.length;
}
var tdDatas = [];
var byYear;
var byMonth;
var byWeek;
for (var _i = 0, rows_1 = rows; _i < rows_1.length; _i++) {
var row = rows_1[_i];
switch (row.option) {
case 'Year':
byYear = this.groupByYear(this.renderDates);
tdDatas = this.generateSlots(byYear, lastLevelColspan, row, 'e-header-year-cell', 'yearHeader');
levels.push(tdDatas);
break;
case 'Month':
byMonth = this.groupByMonth(this.renderDates);
tdDatas = this.generateSlots(byMonth, lastLevelColspan, row, 'e-header-month-cell', 'monthHeader');
levels.push(tdDatas);
break;
case 'Week':
byWeek = this.groupByWeek(this.renderDates);
tdDatas = this.generateSlots(byWeek, lastLevelColspan, row, 'e-header-week-cell', 'weekHeader');
levels.push(tdDatas);
break;
case 'Date':
tdDatas = dateSlots;
tdDatas = tdDatas.map(function (value) {
value.colSpan = lastLevelColspan;
return value;
});
levels.push(tdDatas);
break;
case 'Hour':
if (hourSlots.length > 0) {
levels.push(hourSlots);
}
break;
}
}
return levels;
};
return TimelineHeaderRow;
}());
exports.TimelineHeaderRow = TimelineHeaderRow;
});
|