-
Notifications
You must be signed in to change notification settings - Fork 2
/
togglwdc_19.3.html
431 lines (389 loc) · 13 KB
/
togglwdc_19.3.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
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
<!DOCTYPE html>
<html>
<!-- Note this version is labeled "19.3" but only works with Tableau 2019.4 and higher. I am leaving this version here in case someone is already using it. -->
<head>
<meta charset="utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<title>Toggl Web Data Connector</title>
<meta name="viewport" content="width=device-width, initial-scale=1" />
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://connectors.tableau.com/libs/tableauwdc-2.3.latest.js" type="text/javascript"></script>
<style>
html,
body {
margin: 0;
padding: 0;
height: 100%;
width: 100%;
font-family: 'Benton Sans', 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
background-color: #fff;
color: rgba(0, 0, 0, 0.8);
font-size: 16px;
}
.container {
height: 100%;
width: 100%;
display: flex;
justify-content: center;
align-items: center;
}
.content {
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
width: 350px;
box-sizing: border-box;
}
.logo {
width: 12.1rem;
margin: 10px;
}
label {
width: 100%;
font-weight: bold;
font-size: 14px;
margin-bottom: 5px;
}
.hint {
width: 100%;
font-size: 12px;
font-style: italic;
margin-bottom: 5px;
}
.row {
margin: 15px;
display: flex;
flex-wrap: wrap;
}
.splitrow {
margin: 15px 10px;
display: flex;
}
.split {
flex: 1;
margin: 0 5px;
}
.footer {
font-size: 12px;
font-style: italic;
text-align: center;
}
.error {
color: #e24f54;
font-weight: bold;
margin: 10px 0 0 10px;
display: flex;
align-items: center;
}
.check {
font-size: 14px;
display: flex;
justify-content: flex-start;
align-items: center;
padding-top: 15px;
}
input[type='checkbox'] {
padding: 0;
margin: 0 5px 0 0;
width: 25px;
height: 25px;
}
input[type='text'],
input[type='email'],
input[type='date'] {
padding: 8px;
height: 36px;
width: 100%;
font-size: 18px;
background-color: #eeeeee;
border-radius: 4px;
border: 0;
box-sizing: border-box;
font-family: 'Benton Sans', 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
}
input:disabled {
background-color: #ffffff;
color: #eeeeee;
text-decoration: line-through;
}
button {
background-color: #e24f54;
color: #ffffff;
border: 0;
border-radius: 5px;
height: 35px;
padding: 0 15px;
font-size: 16px;
cursor: pointer;
margin-top: 10px;
}
button:hover {
background-color: #c9282d;
}
p {
width: 100%;
margin: 5px 0;
}
a {
color: #e1393f;
font-weight: bold;
}
</style>
</head>
<body>
<div class="container">
<div class="content">
<div class="logo">
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 240 72.1">
<path
d="M234.9 57.6c-3.5 0-5.2-2.5-5.2-7.5V14.7c0-5.1 1.6-7.5 5.2-7.5s5.1 2.5 5.1 7.5v35.4c0 5-1.6 7.5-5.1 7.5zm-30.8 14.5c-9.5 0-15.2-3.5-15.2-7.5a4.4 4.4 0 0 1 4.2-4.5h.3c2.6 0 5.7 2.8 11.1 2.8s8.1-3.1 8.1-8.7c0-.4-.1-.8-.1-1.3a10.8 10.8 0 0 1-9.4 4.9c-8.2 0-15-7.5-15-18s7.3-18.3 16.1-18.3a10.1 10.1 0 0 1 8.3 3.7 5.6 5.6 0 0 1 4.6-3.3c3.5 0 5.2 2.4 5.2 7.5v20.7c0 6.2-.4 11-2.4 14.3-3.1 5-8.5 7.7-15.8 7.7zm1.5-40.9c-3.8 0-6.8 3.3-6.8 8.5s2.9 8.7 6.8 8.7 6.8-3.4 6.8-8.7-3-8.5-6.8-8.5zm-40.8 40.9c-9.5 0-15.2-3.5-15.2-7.5a4.4 4.4 0 0 1 4.2-4.5h.3c2.6 0 5.7 2.8 11.1 2.8s8.1-3.1 8.1-8.7c0-.4-.1-.8-.1-1.3a10.8 10.8 0 0 1-9.4 4.9c-8.1 0-15-7.5-15-18s7.3-18.3 16.1-18.3a10.1 10.1 0 0 1 8.3 3.7 5.6 5.6 0 0 1 4.6-3.3c3.5 0 5.2 2.4 5.2 7.5v20.7c0 6.2-.4 11-2.4 14.3-3 5-8.4 7.7-15.8 7.7zm1.5-40.9c-3.8 0-6.8 3.3-6.8 8.5s2.9 8.7 6.8 8.7 6.8-3.4 6.8-8.7-3-8.5-6.8-8.5zm-38.1 27c-10.2 0-17.5-7.7-17.5-18.5s7.4-18.5 17.5-18.5 17.5 7.7 17.5 18.5-7.2 18.5-17.4 18.5zm0-27.3c-3.8 0-6.8 3.3-6.8 8.7s2.9 8.8 6.8 8.8 6.8-3.4 6.8-8.8-3-8.7-6.8-8.7zm-24.1.9h-.9v18.3c0 5-1.6 7.5-5.1 7.5S93 55.1 93 50.1V31.8h-.4c-3.7 0-5.8-1.8-5.8-4.5s2.1-4.4 6.2-4.6v-4.5c0-5 1.6-7.5 5.2-7.5s5.1 2.5 5.1 7.5v4.5h.9c4.1 0 6.5 1.8 6.5 4.6s-2.2 4.5-6.6 4.5z">
</path>
<circle cx="35.6" cy="35.6" r="35.6" fill="#e1393f"></circle>
<path
d="M38 14.1h-5v25h5zm-2.5 40A17.5 17.5 0 0 1 31 19.7v5.2a12.5 12.5 0 1 0 9 0v-5.2a17.5 17.5 0 0 1-4.5 34.4z"
fill="#fff"></path>
</svg>
</div>
<p style="text-align: center;"><a href="https://keshiarose.github.io/Toggl-Web-Data-Connector/"
target="_blank">PLEASE USE THE 2019.4 VERSION!</a></p>
<div>
<div class="row">
<label>Email</label>
<input type="email" id="email" placeholder="jane@janedoe.com" required />
</div>
<div class="row">
<label>Workspace ID</label>
<span class="hint">For example: https://toggl.com/app/workspaces/<b>999999</b>/settings (Workspace Settings
page)</span>
<input type="text" id="workspace" placeholder="999999" required />
</div>
<div class="row">
<label>API Token</label>
<span class="hint">This can be found at the bottom of your '<a href="https://toggl.com/app/profile"
target="_blank">My Profile</a>' page</span>
<input type="text" id="token" placeholder="vz0dt5uu9n2ff4lubls1kgfi3e2l5d8t" required />
</div>
<div class="splitrow">
<div class="split">
<label>Start Date</label>
<input type="date" id="startdate" required />
</div>
<div class="split">
<label>End Date</label>
<input type="date" id="enddate" required disabled />
</div>
<div class="split check">
<input type="checkbox" id="today" checked />
<span>Always today</span>
</div>
</div>
<div class="row">
<button id="submit" type="submit">Get Toggl Data</button>
<span class="error" id="error"></span>
</div>
<div class="row footer">
<p>Made by <a href="https://keshiarose.github.io/Toggl-Web-Data-Connector/" target="_blank">Keshia Rose</a>
</p>
</div>
</div>
</div>
</div>
<script>
(function () {
Date.prototype.toDateInputValue = function () {
var local = new Date(this);
local.setMinutes(this.getMinutes() - this.getTimezoneOffset());
return local.toJSON().slice(0, 10);
};
let myConnector = tableau.makeConnector();
myConnector.getSchema = function (schemaCallback) {
var cols = [{
id: 'id',
alias: 'Entry ID',
dataType: tableau.dataTypeEnum.int,
},
{
id: 'desc',
alias: 'Description',
dataType: tableau.dataTypeEnum.string,
},
{
id: 'start',
alias: 'Start Date',
dataType: tableau.dataTypeEnum.datetime,
},
{
id: 'end',
alias: 'End Date',
dataType: tableau.dataTypeEnum.datetime,
},
{
id: 'proj',
alias: 'Project',
dataType: tableau.dataTypeEnum.string,
},
{
id: 'task',
alias: 'Task',
dataType: tableau.dataTypeEnum.string,
},
{
id: 'client',
alias: 'Client',
dataType: tableau.dataTypeEnum.string,
},
{
id: 'bill',
alias: 'Billable',
dataType: tableau.dataTypeEnum.float,
},
{
id: 'isbill',
alias: 'Is Billable',
dataType: tableau.dataTypeEnum.bool,
},
{
id: 'user',
alias: 'User',
dataType: tableau.dataTypeEnum.string,
},
{
id: 'dur',
alias: 'Duration (Seconds)',
dataType: tableau.dataTypeEnum.int,
},
{
id: 'tags',
alias: 'Tags',
dataType: tableau.dataTypeEnum.string,
},
];
var tableInfo = {
id: 'toggl',
alias: 'Toggl Detailed Report',
columns: cols,
};
schemaCallback([tableInfo]);
};
let pagescount = 0;
let tasks = [];
myConnector.getData = function (table, doneCallback) {
const cd = JSON.parse(tableau.connectionData);
const end = cd.check ? new Date().toDateInputValue() : cd.end;
const start = new Date(Math.max(new Date(cd.start), new Date(cd.end).setYear(new Date(cd.end)
.getFullYear() - 1))).toDateInputValue();
var url = 'https://toggl.com/reports/api/v2/details?user_agent=' + cd.email + '&workspace_id=' + cd
.workspace + '&since=' + start + '&until=' + end;
$.ajax({
type: 'GET',
url: url,
dataType: 'json',
beforeSend: function (xhr) {
xhr.setRequestHeader('Authorization', 'Basic ' + btoa(cd.token + ':api_token'));
},
}).done(function (data) {
totalPages = String(Math.ceil(data['total_count'] / data['per_page']));
getData(url, cd.token, totalPages, table, doneCallback);
});
};
function getData(url, token, totalPages, table, doneCallback) {
$.ajax({
url: `${url}&page=${pagescount}`,
method: 'GET',
cache: false,
beforeSend: function (xhr) {
xhr.setRequestHeader('Authorization', 'Basic ' + btoa(token + ':api_token'));
},
success: function (response) {
tasks = tasks.concat(response.data);
pagescount++;
if (pagescount < totalPages) {
getData(url);
} else {
buildTable(tasks, table, doneCallback);
}
},
});
}
function buildTable(tasks, table, doneCallback) {
let tableData = [];
for (task of tasks) {
tags = [];
for (tag of task.tags) {
tags.push(tag);
}
tags = tags.join(', ');
tableData.push({
id: task.id,
desc: task.description,
start: task.start.substring(0, 10) + ' ' + task.start.substring(11, 18),
end: task.end.substring(0, 10) + ' ' + task.end.substring(11, 18),
proj: task.project,
task: task.task,
client: task.client,
bill: task.billable,
isbill: task.is_billable,
user: task.user,
dur: task.dur / 1000,
tags: tags,
});
}
table.appendRows(tableData);
doneCallback();
}
tableau.registerConnector(myConnector);
function validateInputs() {
let output = $('#error');
let start = new Date($('#startdate').val());
let end = $('#today').is(':checked') ? new Date() : new Date($('#enddate').val());
var timeDiff = Math.abs(end.getTime() - start.getTime());
var diffDays = Math.ceil(timeDiff / (1000 * 3600 * 24));
if (!$('#email').val().trim() || !$('#workspace').val().trim() || !$('#token').val().trim() || !$(
'#startdate').val() || !$('#enddate').val()) {
output.html('Please fill in all fields.');
return false;
} else if (!$('#email').is(':valid')) {
output.html('Invalid email.');
return false;
} else if (diffDays > 366) {
output.html('Maximum date span is one year.');
return false;
} else {
return true;
}
}
$(document).ready(function () {
inputdate = new Date();
$('#enddate').val(inputdate.toDateInputValue());
inputdate.setDate(inputdate.getDate() - 30);
$('#startdate').val(inputdate.toDateInputValue());
$('#today').change(function () {
if (this.checked) {
$('#enddate').prop('disabled', true);
} else {
$('#enddate').prop('disabled', false);
}
});
$('#submit').click(function () {
let valid = validateInputs();
if (valid) {
tableau.connectionData = JSON.stringify({
email: $('#email').val().trim(),
workspace: $('#workspace').val().trim(),
token: $('#token').val().trim(),
start: $('#startdate').val(),
end: $('#enddate').val(),
check: $('#today').is(':checked'),
});
tableau.connectionName = 'Toggl';
tableau.submit();
}
});
});
})();
</script>
<img src="https://devplat-hit-counter.herokuapp.com/counter.png" alt="" style="display:none;" aria-hidden="true">
<!-- Hit tracker -->
</body>
</html>