-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathindex.html
452 lines (416 loc) · 16.8 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
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
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
<!doctype html>
<html lang="en">
<head>
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css" integrity="sha384-Vkoo8x4CGsO3+Hhxv8T/Q5PaXtkKtu6ug5TOeNV6gBiFeWPGFN9MuhOf23Q9Ifjh" crossorigin="anonymous">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.13.0/css/all.min.css">
<link rel="stylesheet" href="https://unpkg.com/[email protected]/dist/bootstrap-vue.min.css">
</head>
<body>
<div id="app">
<!------------------------------------------------------------------------------------------------------------------------->
<!-- Modal popup to see and manage all sessions --------------------------------------------------------------------------->
<!------------------------------------------------------------------------------------------------------------------------->
<b-modal
id="sessions-modal"
size="xl"
hide-footer
scrollable
>
<!-- Hidden tables to support the copy table feature --->
<b-table id="tableAllSessions" class="visuallyhidden" small :items="allSessions" ></b-table>
<b-table id="tableAllLogs" class="visuallyhidden" small :items="allLogs" ></b-table>
<!-- Title and copy/delete data buttons --->
<template v-slot:modal-title>
<b-container>
<b-row>
<b-col cols="12" lg="3">
<h4 class="modal-title">Sessions</h4>
</b-col>
<b-col>
<b-button pill size="sm" v-on:click="copyTable('tableAllSessions');">Copy All Sessions</b-button>
<b-button pill size="sm" v-on:click="copyTable('tableAllLogs');">Copy All Logs</b-button>
<b-button pill size="sm" variant="danger" v-on:click="resetApp">Delete All Data</b-button>
</b-col>
</b-row>
</b-container>
</template>
<!-- Container to select and view sessions --->
<b-container>
<b-row>
<!-- Selectable list of all sessions --->
<b-col cols="12" md="4">
<b-list-group>
<b-list-group-item button v-for="(session, i) in sessions" v-on:click="sessionClicked(i);" :active="i === selectedSession" :key="i">
<span v-show="session.editName == false" v-on:dblclick="session.editName = true">{{ session.name }}</span>
<input v-show="session.editName == true" v-model="session.name" v-on:blur="session.editName=false" v-on:keyup.enter="session.editName=false" v-on:click.stop="">
<b-badge variant="info" v-if="i === 0">Current</b-badge>
<b-button variant="danger" size="sm" class="float-right" v-on:click.stop="deleteSession(i)" v-if="i !== 0"><i class="fas fa-trash fa-sm"></i></b-button>
</b-list-group-item>
</b-list-group>
</b-col>
<!-- Display selected session data in tables --->
<b-col>
<div v-if="sessions.length">
<div>
<b-table striped hover :items="sessions[selectedSession]['tasks']" :fields="['name', 'time']"></b-table>
</div>
<div>
<h4>Logs:</h4>
<b-table small :items="sessions[selectedSession]['log']" :fields="['time', 'message']"></b-table>
</div>
</div>
</b-col>
</b-row>
</b-container>
</b-modal>
<!------------------------------------------------------------------------------------------------------------------------->
<!-- Main app container --------------------------------------------------------------------------------------------------->
<!------------------------------------------------------------------------------------------------------------------------->
<b-container style="margin-top: 10px;">
<!-- Current session management --->
<b-row>
<!-- Current session name (dblclick to edit) --->
<b-col cols="12" md="4" align-h="end">
<h3 v-if="sessions.length > 0">
<span v-show="sessions[0].editName == false" v-on:dblclick="sessions[0].editName = true">{{ sessions[0].name }}</span>
<input v-show="sessions[0].editName == true" v-model="sessions[0].name" v-on:blur="sessions[0].editName=false" v-on:keyup.enter="sessions[0].editName=false" v-on:click.stop="">
</h3>
</b-col>
<!-- New/manage sessions --->
<b-col>
<b-button-group class="float-right">
<b-button variant="outline-dark" v-on:click="newSessionClicked">New Session</b-button>
<b-button variant="outline-dark" v-b-modal="'sessions-modal'">View All Sessions</b-button>
</b-button-group>
</b-col>
</b-row>
<!-- Task cards --->
<b-row>
<!--- One task card for each task in this.tasks -->
<b-col cols="6" md="4" v-for="(task, i) in tasks" :key="i">
<b-container class="task-card" v-bind:class="{'task-card-active': task.active}" v-bind:style="{backgroundColor: task.active ? colors[i] : fadedColors[i]}" v-on:click="taskClicked(i)">
<b-row align-h="end">
<!--- Task Controls -->
<b-col cols="1">
<b-dropdown dropleft no-caret size="sm" variant="outline-secondary" style="position: relative; left:-7px; top: -1px" v-on:click.stop="">
<template slot="button-content">
<i class="fas fa-ellipsis-v"></i>
</template>
<b-dropdown-form>
<b-form-checkbox switch class="mb-3" v-model="task.exclusive">Exclusive</b-form-checkbox>
<b-button block variant="outline-danger" size="sm" v-on:click.stop="deleteTask(i)"><i class="fas fa-trash"></i> Delete</b-button>
</b-dropdown-form>
</b-dropdown>
</b-col>
</b-row>
<b-row>
<!--- Task Name -->
<b-col>
<h4>
<span v-show="task.editName == false" v-on:dblclick="task.editName = true">{{ task.name }}</span>
<input v-bind:id="'editName' + i" v-if="task.editName == true" v-model="task.name" v-on:blur="task.editName=false" v-on:keyup.enter="task.editName=false" v-on:click.stop="">
</h4>
</b-col>
</b-row>
<b-row>
<!--- Task Time -->
<b-col>
<h5>
<span v-show="task.editTime == false" v-on:dblclick="task.editTime = true"><i class="fas fa-stopwatch"></i> {{ task.time | formatTime }}</span>
<b-input-group append="seconds" v-show="task.editTime == true" >
<input v-model.number="task.time" v-on:blur="task.editTime=false" v-on:keyup.enter="task.editTime=false" v-on:click.stop="" append="seconds">
</b-input-group>
</h5>
</b-col>
</b-row>
</b-container>
</b-col>
<!-- New Task form -->
<b-col cols="6" md="4">
<b-container class="task-card" style="padding-top: 15px;">
<h4>
<b-input v-model="newTaskName" class="mb-2 mr-sm-2 mb-sm-0" v-on:keyup.enter="createNewTaskClicked" placeholder="New Task" ></b-input>
</h4>
<b-button block variant="outline-secondary" v-on:click="createNewTaskClicked">Create</b-button>
</b-container>
</b-col>
</b-row>
</b-container>
</div>
<script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
<script src="https://code.jquery.com/jquery-3.4.1.slim.min.js" integrity="sha384-J6qa4849blE2+poT4WnyKhv5vZF5SrPo0iEjwBvKU7imGFAV0wwj1yYfoRSJoZ+n" crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/umd/popper.min.js" integrity="sha384-Q6E9RHvbIyZFJoft+2mJbHaEWldlvI9IOYy5n3zV9zzTtmI3UksdQRVvoxMfooAo" crossorigin="anonymous"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/js/bootstrap.min.js" integrity="sha384-wfSDF2E50Y2D1uUdj0O3uMBJnjuUD4Ih7YwaYd1iqfktj0Uod8GCExl3Og8ifwB6" crossorigin="anonymous"></script>
<script src="https://unpkg.com/[email protected]/dist/bootstrap-vue.min.js"></script>
<!------------------------------------------------------------------------------------------------------------------------->
<!-- CSS ------------------------------------------------------------------------------------------------------------------>
<!------------------------------------------------------------------------------------------------------------------------->
<style>
.task-card {
margin-top: 10px;
color: rgb(107, 107, 107);
border-radius: 4px;
border: 1px solid grey;
padding-bottom: 40px;
}
.task-card:hover {
box-shadow: 0px 0px 5px rgb(177, 177, 177);
color: black;
}
.task-card-active {
position: relative;
left: -4px;
top: -4px;
box-shadow: 2px 2px 5px rgb(177, 177, 177);
color: black;
}
.float-right {
position: relative;
float: right;
}
.visuallyhidden:not(:focus):not(:active) {
position: absolute;
width: 1px;
height: 1px;
margin: -1px;
border: 0;
padding: 0;
white-space: nowrap;
clip-path: inset(100%);
clip: rect(0 0 0 0);
overflow: hidden;
font-size: 12px;
}
</style>
<!------------------------------------------------------------------------------------------------------------------------->
<!-- Javascript ----------------------------------------------------------------------------------------------------------->
<!------------------------------------------------------------------------------------------------------------------------->
<script type="text/javascript">
Vue.use(BootstrapVue)
Vue.filter('formatTime', function(value) {
return new Date(value * 1000).toISOString().substr(11, 8);
});
var vm = new Vue({
el: '#app',
data: function() {
return {
tasks: this.load('tasks', this.defaultTasks()),
log: this.load('log', []),
newTaskName: "",
sessions: this.load('sessions', []),
selectedSession: 0,
sessionNameIndex: this.load('sessionNameIndex', 1),
}},
computed: {
colors: function() {return this.interpolateColors("rgb(255,95,109)", "rgb(255,195,113)", this.tasks ? this.tasks.length : 1, 0.85)},
fadedColors: function() {return this.interpolateColors("rgb(255,95,109)", "rgb(255,195,113)", this.tasks ? this.tasks.length : 1, 0.15)},
allSessions: function() {
allTaskNames = [];
this.sessions.forEach(session => {
session.tasks.forEach(task => {
if (!allTaskNames.includes(task.name)) {
allTaskNames.push(task.name);
}
})
})
var allSessions = []
this.sessions.forEach(session => {
var s = {name: session.name}
allTaskNames.forEach(name => {
session.tasks.forEach(task => {
if (task.name == name) {
s[name] = task.time || 0;
}
})
})
allSessions.push(s);
})
return allSessions
},
allLogs: function() {
var allLogs = []
this.sessions.forEach(s => {
s.log.forEach(l => {
var log = {
session: s.name,
time: l.time,
message: l.message
}
allLogs.push(log);
})
})
return allLogs
},
},
mounted: function() {
window.setInterval(() => {this.increaseActiveTasks()}, 1000)
// first session is "current" and has live references to the log and tasks
this.sessions.splice(0, 1, {log: this.log, tasks: this.tasks, name:"Session " + this.sessionNameIndex, editName:false});
if (this.log.length === 0) this.logMsg('Session Started');
},
watch: {
tasks: {handler(){localStorage.setItem('tasks', JSON.stringify(this.tasks))}, deep: true},
log: {handler(){localStorage.setItem('log', JSON.stringify(this.log))}, deep: true},
sessions: {handler(){localStorage.setItem('sessions', JSON.stringify(this.sessions))}, deep: true},
sessionNameIndex: {handler(){localStorage.setItem('sessionNameIndex', JSON.stringify(this.sessionNameIndex))}},
},
methods: {
task: function(name, exclusive) {
var task = {
name: name,
time: 0,
active: false,
editName: false,
editTime: false,
exclusive: exclusive,
}
return task
},
defaultTasks: function() {
return [
this.task("Phone Call", false),
this.task('Chart Review', true),
this.task("Reaching Patient", true),
this.task("Medical Visit", true),
this.task("Followup Coordination", true),
this.task("Patient Forms", true),
this.task("Note Writing", true),
this.task("Talk with Preceptor", true),
];
},
taskClicked: function(i) {
var task = this.tasks[i];
if (task.exclusive) {
this.tasks.forEach(t => {if (t !== task & t.exclusive & t.active === true) {
t.active = false
this.logMsg('Stopped ' + task.name)
}
});
}
task.active = !task.active;
this.logMsg((task.active ? 'Started ' : 'Stopped ') + task.name)
},
createNewTaskClicked: function() {
this.tasks.push(this.task(this.newTaskName || "New Task"))
},
newSessionClicked: function() {
var session = {
log: JSON.parse(JSON.stringify(this.log)),
tasks: JSON.parse(JSON.stringify(this.tasks)),
editName: false,
name: this.sessions[0].name,
}
this.sessionNameIndex += 1;
// insert second to last so "current session" object is always the most recent
this.sessions.splice(1, 0, session)
this.sessions[0].name = "Session " + this.sessionNameIndex;
this.log.length = 0;
this.tasks.forEach(task => {
task.time = 0;
if (task.active) {task.active = false; this.logMsg('Stopped ' + task.name)}
})
this.logMsg('Session Started')
},
sessionClicked: function(i) {
this.selectedSession = i;
},
deleteTask: function(i) {
this.confirmBefore('Please confirm that you want to delete "' + this.tasks[i].name + '"', function() {
vm.tasks.splice(i, 1)
}.bind(this));
},
deleteSession: function(i) {
if (i === 0) {
return;
}
this.confirmBefore('Please confirm that you want to delete "' + (this.sessions[i].name) + '"', function() {
this.selectedSession = 0;
this.sessions.splice(i, 1)
}.bind(this))
},
resetApp: function() {
this.confirmBefore('This will clear out all sessions and logs.', function() {
localStorage.clear(); location.reload();
}.bind(this))
},
//////////////////////////////////////////////////////////////////////////////
// Helpers
//////////////////////////////////////////////////////////////////////////////
logMsg: function(msg) {
this.log.push({time: Date(Date.now()).toString(), message: msg});
},
increaseActiveTasks: function() {
this.tasks.forEach(task => {
if (task.active & task.editTime == false) {
task.time += 1;
}
});
},
load: function(key, defaultVal) {
if (localStorage.getItem(key)) {
return JSON.parse(localStorage.getItem(key));
} else {
return defaultVal;
}
},
confirmBefore: function(message, func) {
this.$bvModal.msgBoxConfirm(message, {
title: 'Are you sure?',
okVariant: 'danger',
okTitle: 'Delete',
footerClass: 'p-2',
hideHeaderClose: false,
centered: true
})
.then(value => {
if (value) { func() }
})
.catch(err => { console.log(err) })
},
copyTable: function(id) {
var el = document.getElementById(id);
var body = document.body, range, sel;
if (document.createRange && window.getSelection) {
range = document.createRange();
sel = window.getSelection();
sel.removeAllRanges();
try {
range.selectNodeContents(el);
sel.addRange(range);
} catch (e) {
range.selectNode(el);
sel.addRange(range);
}
document.execCommand("copy");
} else if (body.createTextRange) {
range = body.createTextRange();
range.moveToElementText(el);
range.select();
range.execCommand("Copy");
}
},
interpolateColor: function (color1, color2, factor, a) {
if (arguments.length < 3) {factor = 0.5;}
var result = color1.slice();
for (var i = 0; i < 3; i++) {
result[i] = Math.round(result[i] + factor * (color2[i] - color1[i]));
}
return 'rgba(' + result[0] +','+ result[1] +','+ result[2] +','+ a + ')';
},
interpolateColors: function (color1, color2, steps, a) {
var stepFactor = 1 / (steps - 1),
interpolatedColorArray = [];
color1 = color1.match(/\d+/g).map(Number);
color2 = color2.match(/\d+/g).map(Number);
for(var i = 0; i < steps; i++) {
interpolatedColorArray.push(this.interpolateColor(color1, color2, stepFactor * i, a));
}
return interpolatedColorArray;
},
}
})
window.vm = vm;
</script>
</body>
</html>