-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtutorial.js
More file actions
531 lines (462 loc) · 20.6 KB
/
Copy pathtutorial.js
File metadata and controls
531 lines (462 loc) · 20.6 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
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
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
// Interactive Tutorial System for TO-DO Board
// Shows step-by-step guidance for new users
class TutorialSystem {
constructor(app) {
this.app = app;
this.currentStep = 0;
this.isActive = false;
this.overlay = null;
this.dialog = null;
this.steps = [
{
title: "Welcome to TO-DO Board! 👋",
description: "Let's take a quick tour to help you get started. You can skip this at any time.",
target: null,
action: null,
highlightClass: null,
position: 'center'
},
{
title: "Board View",
description: "This is your Kanban board with three columns: Not Started, In Progress, and Done. Tasks move through these stages as you work on them.",
target: ".board",
action: null,
highlightClass: "board",
position: 'center'
},
{
title: "Create Your First Task",
description: "Click the '+ New task' button in any column to create a task. Try clicking it now!",
target: ".new-page-btn[data-status='not-started']",
action: "waitForModal",
highlightClass: "new-page-btn",
position: 'bottom'
},
{
title: "Task Details",
description: "Give your task a name and optionally add an emoji. You can also organize tasks into groups. Fill in the task name and click 'Save' to continue.",
target: "#taskModal",
action: "waitForTaskCreation",
highlightClass: "modal-content",
position: 'center'
},
{
title: "Manage Your Tasks",
description: "Great! You can now drag and drop tasks between columns, click to edit them, or delete them using the × button.",
target: ".card",
action: null,
highlightClass: "card",
position: 'top'
},
{
title: "Task Groups",
description: "Organize your tasks by creating groups. Tasks from the same group are displayed together with a colored indicator.",
target: "#groupSelect",
action: null,
highlightClass: "groupSelect",
position: 'bottom'
},
{
title: "Workflow View",
description: "Switch to Workflow view to visualize task dependencies and create flowcharts. Click here to switch views.",
target: "#workflowViewBtn",
action: "waitForWorkflowView",
highlightClass: "view-option",
position: 'right'
},
{
title: "Workflow Canvas",
description: "In Workflow view, you can create tasks and connect them to show dependencies. Use the toolbar to add tasks and create connections.",
target: ".workflow-toolbar",
action: null,
highlightClass: "workflow-toolbar",
position: 'bottom'
},
{
title: "You're All Set! 🎉",
description: "That's it! You now know the basics. Your tasks are automatically synced to the cloud, so you can access them from anywhere.",
target: null,
action: null,
highlightClass: null,
position: 'center'
}
];
this.initializeElements();
}
// Initialize tutorial overlay and dialog elements
initializeElements() {
// Create overlay
this.overlay = document.createElement('div');
this.overlay.id = 'tutorialOverlay';
this.overlay.className = 'tutorial-overlay';
// Create dialog
this.dialog = document.createElement('div');
this.dialog.id = 'tutorialDialog';
this.dialog.className = 'tutorial-dialog';
this.dialog.innerHTML = `
<div class="tutorial-header">
<h3 id="tutorialTitle"></h3>
<button class="tutorial-close" id="tutorialSkip">Skip</button>
</div>
<div class="tutorial-content">
<p id="tutorialDescription"></p>
<div class="tutorial-progress">
<div class="tutorial-progress-bar">
<div class="tutorial-progress-fill" id="tutorialProgress"></div>
</div>
<span class="tutorial-step-counter" id="tutorialStepCounter"></span>
</div>
</div>
<div class="tutorial-footer">
<button class="tutorial-btn tutorial-btn-secondary" id="tutorialPrev">Previous</button>
<button class="tutorial-btn tutorial-btn-primary" id="tutorialNext">Next</button>
</div>
`;
document.body.appendChild(this.overlay);
document.body.appendChild(this.dialog);
// Add event listeners
document.getElementById('tutorialSkip').addEventListener('click', () => this.skip());
document.getElementById('tutorialPrev').addEventListener('click', () => this.previousStep());
document.getElementById('tutorialNext').addEventListener('click', () => this.nextStep());
// Hide initially
this.overlay.style.display = 'none';
this.dialog.style.display = 'none';
}
// Check if user should see tutorial
shouldShowTutorial() {
const tutorialCompleted = localStorage.getItem('tutorialCompleted');
const isNewUser = localStorage.getItem('isNewUser');
// Show tutorial if:
// 1. Never completed tutorial before
// 2. User just registered (isNewUser flag set)
return !tutorialCompleted || isNewUser === 'true';
}
// Start the tutorial
start(force = false) {
if (!force && !this.shouldShowTutorial()) {
return;
}
this.isActive = true;
this.currentStep = 0;
this.overlay.style.display = 'block';
this.dialog.style.display = 'block';
this.showStep(0);
// Remove the new user flag
localStorage.removeItem('isNewUser');
}
// Hide overlay/dialog + remove highlights (no persistence)
hide() {
this.isActive = false;
document.querySelectorAll('.tutorial-highlight').forEach(el => {
el.classList.remove('tutorial-highlight');
});
if (this.overlay) this.overlay.style.display = 'none';
if (this.dialog) this.dialog.style.display = 'none';
}
// Show a specific step
showStep(stepIndex) {
if (stepIndex < 0 || stepIndex >= this.steps.length) {
return;
}
this.currentStep = stepIndex;
const step = this.steps[stepIndex];
// Update dialog content
document.getElementById('tutorialTitle').textContent = step.title;
document.getElementById('tutorialDescription').textContent = step.description;
document.getElementById('tutorialStepCounter').textContent = `${stepIndex + 1} of ${this.steps.length}`;
// Update progress bar
const progress = ((stepIndex + 1) / this.steps.length) * 100;
document.getElementById('tutorialProgress').style.width = `${progress}%`;
// Update button states
const prevBtn = document.getElementById('tutorialPrev');
const nextBtn = document.getElementById('tutorialNext');
prevBtn.disabled = stepIndex === 0;
prevBtn.style.opacity = stepIndex === 0 ? '0.5' : '1';
if (stepIndex === this.steps.length - 1) {
nextBtn.textContent = 'Finish';
} else {
nextBtn.textContent = 'Next';
}
// Remove previous highlights
document.querySelectorAll('.tutorial-highlight').forEach(el => {
el.classList.remove('tutorial-highlight');
});
// Highlight target element
if (step.target) {
const targetEl = document.querySelector(step.target);
if (targetEl) {
targetEl.classList.add('tutorial-highlight');
this.positionDialog(targetEl, step.position);
// Scroll target into view
targetEl.scrollIntoView({ behavior: 'smooth', block: 'center' });
}
} else {
// Center the dialog
this.positionDialog(null, 'center');
}
// Handle step-specific actions
if (step.action) {
this.handleStepAction(step.action);
}
}
// Position dialog relative to target
positionDialog(targetEl, position) {
const dialog = this.dialog;
if (!targetEl || position === 'center') {
// Center dialog
dialog.style.position = 'fixed';
dialog.style.top = '50%';
dialog.style.left = '50%';
dialog.style.transform = 'translate(-50%, -50%)';
dialog.style.maxWidth = '500px';
return;
}
const rect = targetEl.getBoundingClientRect();
const dialogWidth = 400;
const dialogHeight = 260;
const spacing = 16;
const margin = 12;
dialog.style.position = 'fixed';
dialog.style.maxWidth = `${dialogWidth}px`;
const viewportW = window.innerWidth;
const viewportH = window.innerHeight;
const setPos = (leftPx, topPx) => {
const clampedLeft = Math.max(margin, Math.min(leftPx, viewportW - dialogWidth - margin));
const clampedTop = Math.max(margin, Math.min(topPx, viewportH - dialogHeight - margin));
dialog.style.left = `${clampedLeft}px`;
dialog.style.top = `${clampedTop}px`;
dialog.style.transform = 'none';
};
// Preferred placement
const centerX = rect.left + rect.width / 2;
const centerY = rect.top + rect.height / 2;
const candidates = {
top: { left: centerX - dialogWidth / 2, top: rect.top - dialogHeight - spacing },
bottom: { left: centerX - dialogWidth / 2, top: rect.bottom + spacing },
left: { left: rect.left - dialogWidth - spacing, top: centerY - dialogHeight / 2 },
right: { left: rect.right + spacing, top: centerY - dialogHeight / 2 }
};
const scorePlacement = (p) => {
// Higher score is better; penalize off-screen
const offLeft = Math.max(0, margin - p.left);
const offTop = Math.max(0, margin - p.top);
const offRight = Math.max(0, (p.left + dialogWidth + margin) - viewportW);
const offBottom = Math.max(0, (p.top + dialogHeight + margin) - viewportH);
const offPenalty = offLeft + offTop + offRight + offBottom;
return -offPenalty;
};
const preferred = candidates[position] || candidates.bottom;
const fallbacks = ['bottom', 'top', 'right', 'left']
.filter((p) => p !== position)
.map((p) => ({ key: p, val: candidates[p] }));
let best = { key: position, val: preferred, score: scorePlacement(preferred) };
for (const fb of fallbacks) {
const score = scorePlacement(fb.val);
if (score > best.score) {
best = { key: fb.key, val: fb.val, score };
}
}
setPos(best.val.left, best.val.top);
}
// Handle step-specific actions
handleStepAction(action) {
switch (action) {
case 'waitForModal':
// Wait for user to click new task button
this.waitForModalOpen();
break;
case 'waitForTaskCreation':
// Wait for user to create a task
this.waitForTaskCreation();
break;
case 'waitForWorkflowView':
// Wait for user to switch to workflow view
this.waitForViewSwitch();
break;
}
}
// Wait for modal to open
waitForModalOpen() {
const nextBtn = document.getElementById('tutorialNext');
nextBtn.disabled = true;
nextBtn.style.opacity = '0.5';
nextBtn.textContent = 'Waiting...';
const checkModal = () => {
const modal = document.getElementById('taskModal');
const isOpen = !!modal && modal.classList.contains('active');
if (isOpen) {
nextBtn.disabled = false;
nextBtn.style.opacity = '1';
nextBtn.textContent = 'Next';
this.nextStep();
} else {
setTimeout(checkModal, 100);
}
};
checkModal();
}
// Wait for task creation
waitForTaskCreation() {
const nextBtn = document.getElementById('tutorialNext');
nextBtn.disabled = true;
nextBtn.style.opacity = '0.5';
nextBtn.textContent = 'Waiting for task...';
const modal = document.getElementById('taskModal');
const saveBtn = document.getElementById('saveTaskBtn');
// Snapshot tasks at step start
const initialIds = new Set((this.app.tasks || []).map(t => t?._id).filter(Boolean));
let saveClicked = false;
let sawModalOpen = false;
const onSave = () => {
saveClicked = true;
nextBtn.textContent = 'Saving...';
};
// Use capture so we see it even if save handler stops propagation
saveBtn?.addEventListener('click', onSave, true);
const check = () => {
const isOpen = !!modal && modal.classList.contains('active');
if (isOpen) sawModalOpen = true;
const hasNewTask = (this.app.tasks || []).some(t => t?._id && !initialIds.has(t._id));
// Advance only after user clicked Save, modal closed, and new task exists
if (saveClicked && sawModalOpen && !isOpen && hasNewTask) {
saveBtn?.removeEventListener('click', onSave, true);
nextBtn.disabled = false;
nextBtn.style.opacity = '1';
nextBtn.textContent = 'Next';
setTimeout(() => this.nextStep(), 300);
return;
}
setTimeout(check, 150);
};
check();
}
// Wait for view switch
waitForViewSwitch() {
const nextBtn = document.getElementById('tutorialNext');
nextBtn.disabled = true;
nextBtn.style.opacity = '0.5';
nextBtn.textContent = 'Waiting...';
const checkViewSwitch = () => {
if (this.app.currentView === 'workflow') {
nextBtn.disabled = false;
nextBtn.style.opacity = '1';
nextBtn.textContent = 'Next';
this.nextStep();
} else {
setTimeout(checkViewSwitch, 100);
}
};
checkViewSwitch();
}
// Go to next step
nextStep() {
if (this.currentStep >= this.steps.length - 1) {
this.complete();
} else {
this.showStep(this.currentStep + 1);
}
}
// Go to previous step
previousStep() {
if (this.currentStep > 0) {
this.showStep(this.currentStep - 1);
}
}
// Skip tutorial
skip() {
const confirmed = confirm('Are you sure you want to skip the tutorial? You can always access help later.');
if (confirmed) {
this.complete();
}
}
// Complete tutorial
complete() {
localStorage.setItem('tutorialCompleted', 'true');
this.hide();
// Show completion message
if (this.currentStep === this.steps.length - 1) {
// User completed the tutorial
alert('Tutorial completed! You\'re ready to start organizing your tasks. 🎉');
}
// Reset to board view if in workflow
if (this.app.currentView === 'workflow') {
this.app.switchView('board');
}
}
// Reset tutorial (for testing or user request)
reset() {
localStorage.removeItem('tutorialCompleted');
localStorage.removeItem('isNewUser');
this.hide();
this.currentStep = 0;
}
}
// Global function to restart tutorial
function restartTutorial() {
// If tutorial instance exists, restart it
if (window.tutorial) {
window.tutorial.reset();
window.tutorial.start(true);
return;
}
// If app exists and TutorialSystem is loaded, create it on demand
if (window.app && typeof TutorialSystem !== 'undefined') {
window.tutorial = new TutorialSystem(window.app);
window.tutorial.reset();
window.tutorial.start(true);
return;
}
alert('Tutorial is still loading. Please try again in a moment.');
}
// Ensure global access even in some bundling/caching edge cases
try {
window.restartTutorial = restartTutorial;
} catch {
// ignore
}
/*
::::::::::::::::::::
-::::::::::::::::::::::::::::::-
::::::::::::::::::::::::::::::::::::::-
:::::-+%@@+::::::::::::::::::::::-%#+-::::::-
:::::=%@@@@@@@-:::::::::::::::::::::%@@@@@%=:::::-
:::::#@@@@@@@@#::::-*%@@@@@@@@@@@*-:::*@@@@@@@@@=::::-
::::-%@@@@@@@@=:::*@@@@@@@@@@@@@@@@@@@@*:::#@@@@@@@@+::::-
:::::#@@@@@@@@+::-%@@@@@@@@@@@@@@@@@@@@@@@@%-:-#@@@@@@@@+::::=
::::+@@@@@@@@%-:-%@@@@@@@@@@@@@@@@@@@@@@@@@@@@%-:=%@@@@@@@%-:::-
::::*@@@@@@@@*::+@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@+::#@@@@@@@@+::::+
::::-%@@@@@@@@*::*@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@*::%@@@@@@@@#::::=
:::::%@@@@@@@@#::+@@@@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::+@@@@@@@@@@@@@@@@@@@@@@@%-::::::::-#@@@@@@@@@@+:::=
:::::%@@@@@@+:::::::::::::::::::-+%@@@@@@@@@@%+-:=%@@@@%-:::::::::=%@@@@@@@::::=
::::-%@@#-::::::::::::::::::::::::::::::::::::::::=%@@@@%+:::::::::-+%@@@+::::#
-::::==::::::::::::-#-::::::::::::::::::::::::::::::-#@@@@@*::::::::::-##::::+
::::::::::::::::=@@@@@#-::::::::::::::::::::::::::::::*@@@@@#-:::::::::::::-
:::::::::::::*@@@@@@@@@@@*-:::::::::::::::::::=*:::::::+%@@@@%-:::::::::::*
:::::::::-%@@@@@*::+%@@@@@@@@%#+-:::::-=*%%@@@@@#:::::::-%@@@@%=::::::::%
-::::::+%@@@@%=:::::::-+%@@@@@@@@@@@@@@@@@@@@@%=::::::::::-#@@@@@*:::::=
-:::*@@@@@#-::::::::::::::-=+#%@@@@@@@%#*=-:::::::::::::::#@@@@*:::::+
-*@@@@@*::::::::::::::::::::::::::::::::::::::::::::::-#@@@@%-::::-*
#@%=:::::::::--:::::::::::::::::::::::::::::::::::=%@@@@%=:::::-
:::::::::::#@@@#-:::::::::::::::::::::::::::::=%@@@@@%=::::::+
-:::::::=@@@@@@@@%+:::::::::::::::::::::+%@@@@@@@%-::::::=
:::::::::=%@@@@@@@@@%%%#**+++**#%%%@@@@@@@@@%=:::::::=
-::::::::::=*%@@@@@@@@@@@@@@@@@@@@@@@@%+-::::::::=
=:::::::::::::-=+*#%%@@@@@@%%#*+=-::::::::::-+
=-::::::::::::::::::::::::::::::::::::-+
=-::::::::::::::::::::::::::::-*
+-::::::::::::::::-+
*/