-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
277 lines (227 loc) · 8.45 KB
/
index.html
File metadata and controls
277 lines (227 loc) · 8.45 KB
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<link href="https://unpkg.com/tabulator-tables@6.2.1/dist/css/tabulator.min.css" rel="stylesheet">
<script type="text/javascript" src="https://unpkg.com/tabulator-tables@6.2.1/dist/js/tabulator.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/luxon@3.4.4/build/global/luxon.min.js"></script>
<script type="text/javascript" src="js/jsonpath-0.8.0.js"></script>
</head>
<body>
<script type="module">
// const jsonUrl = "./test-data.json";
// const jsonUrl = "./oct-2024-data.json";
// const jsonUrl = "https://uscms-software-and-computing.github.io/OpenProject_data/data/all_results.json";
const jsonUrl = "https://uscms-software-and-computing.github.io/openproject-data/data/data.json";
const DateTime = luxon.DateTime;
async function getLiveData() {
try {
const response = await fetch(jsonUrl, { mode: 'cors'});
if (!response.ok) {
throw new Error(`HTTP error! status: ${response.status}`);
}
const jsonData = await response.json();
return processData(jsonData);
// return jsonData;
} catch (error) {
console.error("Error fetching or processing data:", error);
// Handle the error here, maybe show an error message to the user
}
}
function processData(data) {
const workPackages = data._embedded?.elements || []; // Use optional chaining
const workActivities = jsonPath(data, "$._embedded.elements[?(@._links.type.title==\"Activity\")]");
console.log(workActivities);
const workPackageById = workPackages.reduce((map, item) => {
// console.log(item.subject);
map[item.id] = item;
return map;
}, {});
const parentId = (parentHref) => Number((parentHref?.href?.match(/.*\/(\d+)/) || [])[1] || 0);
function getChildren(childrenList) {
let children = [];
childrenList.forEach(child => {
const regex = /.*\/(\d+)/gm;
const match = regex.exec(child?.href);
const childId = Number(match[1]);
children.push(workPackageById[childId]);
})
// console.log(workPackageById[45]);
// console.log(childrenList);
// console.log(children);
return children.map(item => ({
id: item.id,
name: item.subject,
project: item._links.project.title,
parent: parentId(item._links?.parent?.href),
children: item._links.children ? getChildren(item._links.children) : undefined,
startDate: item.startDate ? formatDate(item.startDate) : formatDate(item.date),
endDate: item.dueDate ? formatDate(item.dueDate) : formatDate(item.date),
progress: item.percentageDone
}));
}
const formatDate = (date) => DateTime.fromISO(date); // Remove unused arguments
return workActivities.map(item => ({
id: item.id,
name: item.subject,
project: item._links.project.title,
parent: parentId(item._links?.parent?.href),
children: item._links.children ? getChildren(item._links.children) : undefined,
startDate: item.startDate ? formatDate(item.startDate) : formatDate(item.date),
endDate: item.dueDate ? formatDate(item.dueDate) : formatDate(item.date),
progress: item.percentageDone
}))
}
const minMaxFilterEditor = function(cell, onRendered, success, cancel, editorParams){
let end;
let container = document.createElement("span");
//create and style inputs
const start = document.createElement("input");
start.setAttribute("type", "number");
start.setAttribute("placeholder", "Min");
start.setAttribute("min", 0);
start.setAttribute("max", 100);
start.style.padding = "4px";
start.style.width = "50%";
start.style.boxSizing = "border-box";
start.value = cell.getValue();
function buildValues(){
success({
start:start.value,
end:end.value,
});
}
function keypress(e){
if(e.keyCode === 13){
buildValues();
}
if(e.keyCode === 27){
cancel();
}
}
end = start.cloneNode();
end.setAttribute("placeholder", "Max");
start.addEventListener("change", buildValues);
start.addEventListener("blur", buildValues);
start.addEventListener("keydown", keypress);
end.addEventListener("change", buildValues);
end.addEventListener("blur", buildValues);
end.addEventListener("keydown", keypress);
container.appendChild(start);
container.appendChild(end);
// console.log(container);
return container;
}
//custom max min filter function
function minMaxFilterFunction(headerValue, rowValue, rowData, filterParams){
//headerValue - the value of the header filter element
//rowValue - the value of the column in this row
//rowData - the data for the row being filtered
//filterParams - params object passed to the headerFilterFuncParams property
if(rowValue){
if(headerValue.start !== ""){
if(headerValue.end !== ""){
return rowValue >= headerValue.start && rowValue <= headerValue.end;
}else{
return rowValue >= headerValue.start;
}
}else{
if(headerValue.end !== ""){
return rowValue <= headerValue.end;
}
}
}
return true; //must return a boolean, true if it passes the filter.
}
function dateRangeFilter(headerValue, rowValue) {
const start = DateTime.fromISO(headerValue.start);
const end = DateTime.fromISO(headerValue.end);
const endDate = DateTime.fromISO(rowValue);
return endDate >= start && endDate <= end;
}
const dateRangeFilterEditor = function(cell, onRendered, success, cancel, editorParams){
let end;
let container = document.createElement("span");
//create and style inputs
const start = document.createElement("input");
start.setAttribute("type", "date");
start.setAttribute("placeholder", "Start Date");
// start.setAttribute("min", 0);
// start.setAttribute("max", 100);
start.style.padding = "4px";
start.style.width = "50%";
start.style.boxSizing = "border-box";
start.value = cell.getValue();
function buildValues(){
success({
start: start.value,
end: end.value
});
}
function keypress(e){
if(e.keyCode === 13){
buildValues();
// console.log(start.value);
// console.log(end.value);
}
if(e.keyCode === 27){
cancel();
}
}
end = start.cloneNode();
end.setAttribute("placeholder", "End Date");
start.addEventListener("change", buildValues);
start.addEventListener("blur", buildValues);
start.addEventListener("keydown", keypress);
end.addEventListener("change", buildValues);
end.addEventListener("blur", buildValues);
end.addEventListener("keydown", keypress);
container.appendChild(start);
container.appendChild(end);
// console.log(container);
return container;
}
const tableColumns = [
{title: "Name", field:"name", width:500},
// {title: "ID", field: "id"},
{title: "Project", field: "project", editor:"input", headerFilter:true},
// {title: "Start Date", field: "startDate", sorter: "date", editor:"input", headerFilter:true},
{title: "End Date", field: "endDate", sorter: "date", editor:"input", width:150,
formatter: function(cell, formatterParams, onRendered){
let value = cell.getValue();
value = DateTime.fromISO(value).toFormat("LL/dd/yyyy");
return value;
},
headerFilter: dateRangeFilterEditor,
headerFilterFunc: dateRangeFilter,
// headerFilterLiveFilter:false
},
{title: "Progress", field: "progress", editor:"input", headerFilter:true, width:150, formatter:"progress", sorter:"number", headerFilter:minMaxFilterEditor, headerFilterFunc:minMaxFilterFunction, headerFilterLiveFilter:false}
];
getLiveData().then(data => {
return data
}).then(tableData => {
Tabulator.extendModule("filter", "filters", {
"dateRange": dateRangeFilter
});
let table = new Tabulator("#example-table", {
data: tableData,
dataTree: true,
dataTreeChildField: "children",
dataTreeSort:false,
columns: tableColumns,
groupBy:["project"],
initialSort:[
{column:"endDate", dir:"asc"},
{column: "project", dir:"asc"},
],
// initialFilter:[
// {field: "endDate", type:"dateRange", value: {start: "2024-01-01", end: "2024-12-31"}}
// ]
});
});
</script>
<div id="example-table"></div>
</body>
</html>