-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvisualizer.html
More file actions
206 lines (183 loc) · 5.77 KB
/
visualizer.html
File metadata and controls
206 lines (183 loc) · 5.77 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
<!doctype html>
<head>
<title>Trello History Visualizer</title>
<link rel="stylesheet" href="styles.css" type="text/css" media="screen" charset="utf-8">
<script>
var wait = true;
var timeout = 750;
var jobs = [];
var startDate;
Number.prototype.AddZero= function(b,c){
var l= (String(b|| 10).length - String(this).length)+1;
return l> 0? new Array(l).join(c|| '0')+this : this;
}
function setDateTime(){
var d = new Date();
d.setDate(d.getDate()-7)
var localDateTime= [
d.getFullYear(),
(d.getMonth()+1).AddZero(),
(d.getDate()).AddZero(),
].join('-') +'T' + [
d.getHours().AddZero(),
d.getMinutes().AddZero()].join(':');
document.getElementById('startDate').value = localDateTime;
}
function loadDateTime(){
startDate = document.getElementById('startDate').value;
}
document.addEventListener("DOMContentLoaded", function(event) {
setDateTime()
loadDateTime()
});
function toggle(){
var btnToggle=document.getElementById('btnToggle');
if(wait){
btnToggle.value='Pause';
}
else {
btnToggle.value='Play';
}
timeout = document.getElementById('timeout').value;
loadDateTime()
wait = !wait;
}
function slower(){
timeout += 50;
document.getElementById('timeout').value = timeout;
}
function faster(){
timeout -= 50;
document.getElementById('timeout').value = timeout;
}
function loadFile() {
// document.getElementById('btnLoad').disabled = true;
var input, file, fr;
jobs = [];
if (typeof window.FileReader !== 'function'){
alert("The file API isn't supported on this browser yet.");
return;
}
input = document.getElementById('fileinput');
if(!input) {
alert("Couldn't file fileinput element");
} else if (!input.files) {
alert("This browser doesn't support the 'files' property of file inputs.");
} else if (!input.files[0]) {
alert("Please select a file before clicking 'Load'");
} else {
file = input.files[0];
fr = new FileReader();
fr.onload = playHistory;
fr.readAsText(file);
}
loadDateTime()
}
function JSONsort(a,b) {
return (new Date(a['date']).getTime() - new Date(b['date']).getTime());
}
function playHistory(e){
var data = JSON.parse(e.target.result);
var wrapper = document.getElementById('wrapper');
wrapper.innerHTML = "";
var cols = "";
for (var i = 0; i < data['lists'].length; i++){
cols += "1fr "
}
wrapper.style.gridTemplateColumns = cols;
for (i in data['lists']){
var h = document.createElement('section');
h.className = 'container col-'+i;
h.id = data['lists'][i]['id']
var h3 = document.createElement('h3');
h3.innerHTML = data['lists'][i]['name'];
h.appendChild(h3);
wrapper.appendChild(h);
}
var actions = data['actions'];
actions.sort(JSONsort);
for (var i = 0; i < actions.length; i++){
if (actions[i]['type'] == "createCard" || actions[i]['type'] == "updateCard" || actions[i]['type'] == "commentCard") {
if (!actions[i]['data']['card'].hasOwnProperty('pos')){
jobs.push(actions[i]);
}
}
}
timeout = document.getElementById('timeout').value;
if (startDate != "") {
while (jobs[0]['date'] < startDate) {
processCard(jobs.shift());
}
}
timedQueue(0);
}
function timedQueue(){
if (!wait) {
setTimeout(function(){
var item = jobs.shift();
if (typeof(item) !== 'undefined'){
console.log(item['type'])
processCard(item);
} else {
document.getElementById('doneMsg').style.display = 'inline';
}
timedQueue();
},timeout);
} else {
setTimeout(function(){
timedQueue();
},timeout);
}
}
function next(){
wait = true;
var item = jobs.shift();
if (typeof(item) !== 'undefined'){
console.log(item['type'])
processCard(item);
} else {
document.getElementById('doneMsg').style.display = 'inline';
}
}
function processCard(action) {
if (action['type'] == "createCard") {
var card = document.createElement('article');
card.id = action['data']['card']['id'];
card.className = 'card';
card.innerHTML = action['data']['card']['name'];
document.getElementById(action['data']['list']['id']).appendChild(card);
}
else if (action['type'] == 'updateCard') {
var card = document.getElementById(action['data']['card']['id']);
if (typeof(action['data']['card']['closed']) == 'undefined'){
if (action['data']['listAfter'] != null) {
document.getElementById(action['data']['listBefore']['id']).removeChild(card);
document.getElementById(action['data']['listAfter']['id']).appendChild(card);
}
card.innerHTML = action['data']['card']['name'];
}
else if (action['data']['card']['closed'] != null && action['data']['card']['closed'] == "true") {
card.style.display = "none";
}
}
else if (action['type'] == 'commentCard') {
var card = document.getElementById(action['data']['card']['id']);
card.style.borderColor = action['data']['text'];
}
}
</script>
</head>
<html>
<header>
Load JSON File <input type='file' id='fileinput'>
<input type="datetime-local" id='startDate'>
<input type='button' id='btnLoad' value='Load' onclick='loadFile();'>
Timeout delay (ms) <input id='timeout' type="text" value='750'>
<input type="button" id='btnSlow' value='Slower' onclick='slower();'>
<input type="button" id='btnToggle' value="Play" onclick="toggle();">
<input type="button" id='btnFast' value='Faster' onclick='faster();'>
<input type="button" id='btnNext' value='Next' onclick='next();'>
<label id="doneMsg">Done Playing History</label>
</header>
<div class="wrapper" id="wrapper"></div>
</html>