-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTimeTracker.html
More file actions
1533 lines (1328 loc) · 65.1 KB
/
TimeTracker.html
File metadata and controls
1533 lines (1328 loc) · 65.1 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
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<!DOCTYPE html>
<html lang="ru">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Work Time Tracker</title>
<script src="https://cdnjs.cloudflare.com/ajax/libs/xlsx/0.18.5/xlsx.full.min.js"></script>
<style>
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
body {
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
background: linear-gradient(135deg, #1e293b 0%, #581c87 50%, #1e293b 100%);
min-height: 100vh;
padding: 20px;
color: white;
}
.container {
max-width: 1200px;
margin: 0 auto;
}
.header {
display: flex;
justify-content: space-between;
align-items: center;
margin-bottom: 30px;
flex-wrap: wrap;
gap: 15px;
}
.title {
font-size: 2.5rem;
font-weight: bold;
}
.nav-tabs {
display: flex;
gap: 10px;
}
.btn {
padding: 12px 24px;
border: none;
border-radius: 8px;
cursor: pointer;
font-size: 14px;
font-weight: 500;
transition: all 0.3s;
}
.btn-primary {
background: #9333ea;
color: white;
}
.btn-primary:hover {
background: #7e22ce;
}
.btn-secondary {
background: rgba(255,255,255,0.1);
color: rgba(255,255,255,0.7);
}
.btn-secondary:hover {
background: rgba(255,255,255,0.2);
}
.btn-secondary.active {
background: #9333ea;
color: white;
}
.btn-success {
background: #16a34a;
color: white;
}
.btn-success:hover {
background: #15803d;
}
.btn-danger {
background: #dc2626;
color: white;
}
.btn-danger:hover {
background: #b91c1c;
}
.btn:disabled {
background: #4b5563;
cursor: not-allowed;
opacity: 0.5;
}
.btn-small {
padding: 8px 16px;
font-size: 13px;
}
.card {
background: rgba(255,255,255,0.1);
backdrop-filter: blur(10px);
border-radius: 12px;
padding: 24px;
margin-bottom: 20px;
border: 1px solid rgba(255,255,255,0.2);
}
.card.active-task {
border: 2px solid #10b981;
box-shadow: 0 0 20px rgba(16, 185, 129, 0.3);
}
.form-group {
margin-bottom: 15px;
}
.form-control {
width: 100%;
padding: 12px;
border-radius: 8px;
border: 1px solid rgba(255,255,255,0.2);
background: rgba(255,255,255,0.1);
color: white;
font-size: 14px;
}
.form-control::placeholder {
color: rgba(255,255,255,0.5);
}
.form-control:focus {
outline: none;
border-color: #9333ea;
}
.task-header {
display: flex;
justify-content: space-between;
align-items: flex-start;
margin-bottom: 20px;
}
.task-title {
font-size: 1.5rem;
font-weight: bold;
margin-bottom: 5px;
}
.task-project {
color: #c084fc;
font-size: 0.9rem;
}
.task-actions {
display: flex;
gap: 10px;
}
.stats-grid {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
gap: 15px;
margin-bottom: 20px;
}
.stat-box {
background: rgba(255,255,255,0.05);
padding: 15px;
border-radius: 8px;
}
.stat-label {
color: rgba(255,255,255,0.7);
font-size: 0.85rem;
margin-bottom: 5px;
}
.stat-value {
font-size: 2rem;
font-weight: bold;
}
.sessions-list {
max-height: 200px;
overflow-y: auto;
margin-top: 15px;
}
.session-item {
background: rgba(255,255,255,0.05);
padding: 12px;
border-radius: 8px;
margin-bottom: 8px;
font-size: 0.9rem;
}
.session-header {
display: flex;
justify-content: space-between;
margin-bottom: 5px;
}
.active-indicator {
background: rgba(16, 185, 129, 0.2);
border: 1px solid #10b981;
padding: 12px;
border-radius: 8px;
margin-top: 15px;
}
.export-buttons {
display: flex;
gap: 10px;
margin-bottom: 20px;
flex-wrap: wrap;
}
.progress-bar {
background: rgba(255,255,255,0.1);
height: 8px;
border-radius: 4px;
overflow: hidden;
margin-top: 5px;
}
.progress-fill {
background: linear-gradient(90deg, #9333ea, #3b82f6);
height: 100%;
border-radius: 4px;
transition: width 0.3s;
}
.empty-state {
text-align: center;
padding: 60px 20px;
color: rgba(255,255,255,0.7);
}
.hidden {
display: none;
}
@keyframes pulse {
0%, 100% { opacity: 1; }
50% { opacity: 0.7; }
}
.pulse {
animation: pulse 2s infinite;
}
.session-comment {
color: rgba(255,255,255,0.7);
font-size: 0.85rem;
font-style: italic;
margin-top: 5px;
padding: 8px;
background: rgba(255,255,255,0.05);
border-radius: 4px;
}
textarea.form-control {
min-height: 80px;
resize: vertical;
}
.month-group {
margin-bottom: 25px;
}
.month-header {
background: linear-gradient(135deg, rgba(147, 51, 234, 0.3), rgba(59, 130, 246, 0.3));
padding: 15px 20px;
border-radius: 10px;
cursor: pointer;
display: flex;
justify-content: space-between;
align-items: center;
margin-bottom: 15px;
transition: all 0.3s;
border: 1px solid rgba(147, 51, 234, 0.4);
}
.month-header:hover {
background: linear-gradient(135deg, rgba(147, 51, 234, 0.4), rgba(59, 130, 246, 0.4));
transform: translateY(-2px);
}
.month-title {
font-size: 1.3rem;
font-weight: bold;
}
.month-stats {
display: flex;
gap: 20px;
font-size: 0.9rem;
color: rgba(255,255,255,0.8);
}
.accordion-icon {
font-size: 1.2rem;
transition: transform 0.3s;
}
.accordion-icon.collapsed {
transform: rotate(-90deg);
}
.tasks-grid {
display: none;
}
.tasks-grid.expanded {
display: block;
}
.task-row {
background: rgba(255,255,255,0.05);
border: 1px solid rgba(255,255,255,0.1);
border-radius: 8px;
padding: 15px;
margin-bottom: 10px;
transition: all 0.3s;
}
.task-row:hover {
background: rgba(255,255,255,0.08);
border-color: rgba(147, 51, 234, 0.5);
}
.task-row.active-task {
border: 2px solid #10b981;
background: rgba(16, 185, 129, 0.1);
}
.task-row.has-deadline {
border-left: 4px solid #f59e0b;
}
.task-row.overdue {
border-left: 4px solid #ef4444;
}
.task-grid-header {
display: grid;
grid-template-columns: 2fr 1fr 1fr 1fr 1fr 120px;
gap: 15px;
align-items: center;
margin-bottom: 10px;
}
.task-grid-row {
display: grid;
grid-template-columns: 2fr 1fr 1fr 1fr 1fr 120px;
gap: 15px;
align-items: center;
}
.task-details {
margin-top: 15px;
padding-top: 15px;
border-top: 1px solid rgba(255,255,255,0.1);
}
.deadline-badge {
display: inline-block;
padding: 4px 10px;
border-radius: 12px;
font-size: 0.85rem;
font-weight: 500;
}
.deadline-badge.upcoming {
background: rgba(245, 158, 11, 0.2);
color: #fbbf24;
border: 1px solid #f59e0b;
}
.deadline-badge.overdue {
background: rgba(239, 68, 68, 0.2);
color: #fca5a5;
border: 1px solid #ef4444;
}
.deadline-badge.completed {
background: rgba(34, 197, 94, 0.2);
color: #86efac;
border: 1px solid #22c55e;
}
@media (max-width: 1200px) {
.task-grid-header, .task-grid-row {
grid-template-columns: 2fr 1fr 1fr 100px;
}
.hide-mobile {
display: none;
}
}
</style>
</head>
<body>
<div class="container">
<div class="header">
<h1 class="title">⏱️ Work Time Tracker</h1>
<div class="nav-tabs">
<button class="btn btn-secondary active" id="tabTasks">Задачи</button>
<button class="btn btn-secondary" id="tabReports">Отчеты</button>
</div>
</div>
<div class="export-buttons">
<button class="btn btn-success btn-small" id="btnExportJSON">📥 Экспорт JSON</button>
<button class="btn btn-success btn-small" id="btnExportExcel">📊 Экспорт Excel</button>
<button class="btn btn-success btn-small" id="btnExportMonthReport">📑 Отчет за месяц</button>
<button class="btn btn-secondary btn-small" id="btnImportJSON">📤 Импорт JSON</button>
<input type="file" id="fileInput" accept=".json" class="hidden">
</div>
<!-- Вид задач -->
<div id="viewTasks">
<div style="display: flex; justify-content: flex-end; margin-bottom: 20px;">
<button class="btn btn-primary" id="btnAddTask">➕ Новая задача</button>
</div>
<div id="taskForm" class="card hidden">
<h2 style="margin-bottom: 20px;">Создать задачу</h2>
<div class="form-group">
<input type="text" class="form-control" id="inputTaskName" placeholder="Название задачи *">
</div>
<div class="form-group">
<input type="text" class="form-control" id="inputProjectName" placeholder="Проект">
</div>
<div class="form-group">
<label style="display: block; margin-bottom: 5px; color: rgba(255,255,255,0.8);">Дедлайн (необязательно):</label>
<input type="datetime-local" class="form-control" id="inputTaskDeadline">
</div>
<div style="display: flex; gap: 10px;">
<button class="btn btn-success" id="btnSaveTask">Добавить</button>
<button class="btn btn-secondary" id="btnCancelTask">Отмена</button>
</div>
</div>
<div id="manualSessionForm" class="card hidden">
<h2 style="margin-bottom: 20px;">Добавить сессию вручную</h2>
<div class="form-group">
<label style="display: block; margin-bottom: 5px; color: rgba(255,255,255,0.8);">Дата начала:</label>
<input type="datetime-local" class="form-control" id="inputSessionStart">
</div>
<div class="form-group">
<label style="display: block; margin-bottom: 5px; color: rgba(255,255,255,0.8);">Дата окончания:</label>
<input type="datetime-local" class="form-control" id="inputSessionStop">
</div>
<div class="form-group">
<label style="display: block; margin-bottom: 5px; color: rgba(255,255,255,0.8);">Комментарий (необязательно):</label>
<textarea class="form-control" id="inputSessionComment" placeholder="Описание работы, заметки..."></textarea>
</div>
<div style="display: flex; gap: 10px;">
<button class="btn btn-success" id="btnSaveManualSession">Добавить сессию</button>
<button class="btn btn-secondary" id="btnCancelManualSession">Отмена</button>
</div>
</div>
<div id="editSessionForm" class="card hidden">
<h2 style="margin-bottom: 20px;">Редактировать сессию</h2>
<div class="form-group">
<label style="display: block; margin-bottom: 5px; color: rgba(255,255,255,0.8);">Дата начала:</label>
<input type="datetime-local" class="form-control" id="inputEditSessionStart">
</div>
<div class="form-group">
<label style="display: block; margin-bottom: 5px; color: rgba(255,255,255,0.8);">Дата окончания:</label>
<input type="datetime-local" class="form-control" id="inputEditSessionStop">
</div>
<div class="form-group">
<label style="display: block; margin-bottom: 5px; color: rgba(255,255,255,0.8);">Комментарий:</label>
<textarea class="form-control" id="inputEditSessionComment" placeholder="Описание работы, заметки..."></textarea>
</div>
<div style="display: flex; gap: 10px;">
<button class="btn btn-success" id="btnSaveEditSession">Сохранить изменения</button>
<button class="btn btn-secondary" id="btnCancelEditSession">Отмена</button>
</div>
</div>
<div id="tasksList"></div>
</div>
<!-- Вид отчетов -->
<div id="viewReports" class="hidden">
<div style="display: flex; gap: 10px; margin-bottom: 20px;">
<button class="btn btn-secondary active" id="btnDay">По дням</button>
<button class="btn btn-secondary" id="btnWeek">По неделям</button>
<button class="btn btn-secondary" id="btnMonth">По месяцам</button>
</div>
<div id="reportsContent"></div>
</div>
</div>
<script>
// Глобальные переменные
let tasks = [];
let activeTaskId = null;
let currentView = 'tasks';
let reportPeriod = 'day';
let updateInterval = null;
let currentManualTaskId = null;
let currentEditTaskId = null;
let currentEditSessionIndex = null;
// Загрузка данных
function loadData() {
const saved = localStorage.getItem('workTimeTrackerData');
if (saved) {
try {
const data = JSON.parse(saved);
tasks = data.tasks || [];
activeTaskId = data.activeTaskId || null;
} catch (e) {
console.error('Ошибка загрузки данных:', e);
}
}
}
// Сохранение данных
function saveData() {
const data = {
tasks: tasks,
activeTaskId: activeTaskId
};
localStorage.setItem('workTimeTrackerData', JSON.stringify(data));
}
// Форматирование даты и времени
function formatDateTime(isoString) {
const date = new Date(isoString);
const day = String(date.getDate()).padStart(2, '0');
const month = String(date.getMonth() + 1).padStart(2, '0');
const year = date.getFullYear();
const hours = String(date.getHours()).padStart(2, '0');
const minutes = String(date.getMinutes()).padStart(2, '0');
return `${day}.${month}.${year} ${hours}:${minutes}`;
}
function formatDate(isoString) {
const date = new Date(isoString);
const day = String(date.getDate()).padStart(2, '0');
const month = String(date.getMonth() + 1).padStart(2, '0');
const year = date.getFullYear();
return `${day}.${month}.${year}`;
}
// Расчеты времени
function calculateTotalMinutes(task) {
let total = 0;
task.timeSegments.forEach(segment => {
const start = new Date(segment.start);
const stop = new Date(segment.stop);
total += (stop - start) / (1000 * 60);
});
if (task.isActive && task.currentStartTime) {
const start = new Date(task.currentStartTime);
const now = new Date();
total += (now - start) / (1000 * 60);
}
return Math.round(total);
}
function calculateTotalHours(task) {
const minutes = calculateTotalMinutes(task);
return (minutes / 60).toFixed(2);
}
// Переключение видов
function switchView(view) {
currentView = view;
document.getElementById('viewTasks').classList.toggle('hidden', view !== 'tasks');
document.getElementById('viewReports').classList.toggle('hidden', view !== 'reports');
document.getElementById('tabTasks').classList.toggle('active', view === 'tasks');
document.getElementById('tabReports').classList.toggle('active', view === 'reports');
if (view === 'reports') {
renderReports();
}
}
// Показать/скрыть форму
function showTaskForm(show) {
document.getElementById('taskForm').classList.toggle('hidden', !show);
if (show) {
document.getElementById('inputTaskName').focus();
}
}
// Добавить задачу
function addTask() {
const taskName = document.getElementById('inputTaskName').value.trim();
const projectName = document.getElementById('inputProjectName').value.trim();
const deadlineValue = document.getElementById('inputTaskDeadline').value;
if (!taskName) {
alert('Введите название задачи');
return;
}
const task = {
id: Date.now(),
task: taskName,
project: projectName,
createDate: new Date().toISOString(),
deadline: deadlineValue ? new Date(deadlineValue).toISOString() : null,
timeSegments: [],
isActive: false,
currentStartTime: null
};
tasks.push(task);
saveData();
document.getElementById('inputTaskName').value = '';
document.getElementById('inputProjectName').value = '';
document.getElementById('inputTaskDeadline').value = '';
showTaskForm(false);
renderTasks();
}
// Старт задачи
function startTask(taskId) {
if (activeTaskId) {
stopTask(activeTaskId);
}
const task = tasks.find(t => t.id === taskId);
if (task) {
task.isActive = true;
task.currentStartTime = new Date().toISOString();
activeTaskId = taskId;
saveData();
renderTasks();
startTimer();
}
}
// Стоп задачи
function stopTask(taskId) {
const task = tasks.find(t => t.id === taskId);
if (task && task.isActive) {
const segment = {
start: task.currentStartTime,
stop: new Date().toISOString()
};
task.timeSegments.push(segment);
task.isActive = false;
task.currentStartTime = null;
if (activeTaskId === taskId) {
activeTaskId = null;
stopTimer();
}
saveData();
renderTasks();
}
}
// Удалить задачу
function deleteTask(taskId) {
if (!confirm('Удалить задачу?')) return;
if (activeTaskId === taskId) {
stopTask(taskId);
}
tasks = tasks.filter(t => t.id !== taskId);
saveData();
renderTasks();
}
// Удалить сессию
function deleteSession(taskId, sessionIndex) {
if (!confirm('Удалить эту сессию?')) return;
const task = tasks.find(t => t.id === taskId);
if (task) {
task.timeSegments.splice(sessionIndex, 1);
saveData();
renderTasks();
}
}
// Показать форму ручного добавления сессии
function showManualSessionForm(taskId) {
currentManualTaskId = taskId;
const form = document.getElementById('manualSessionForm');
form.classList.remove('hidden');
// Установить текущую дату и время
const now = new Date();
const oneHourAgo = new Date(now.getTime() - 60 * 60 * 1000);
document.getElementById('inputSessionStart').value = formatDateTimeLocal(oneHourAgo);
document.getElementById('inputSessionStop').value = formatDateTimeLocal(now);
// Прокрутить к форме
form.scrollIntoView({ behavior: 'smooth', block: 'center' });
}
// Скрыть форму ручного добавления сессии
function hideManualSessionForm() {
document.getElementById('manualSessionForm').classList.add('hidden');
currentManualTaskId = null;
}
// Добавить сессию вручную
function addManualSession() {
if (!currentManualTaskId) return;
const startValue = document.getElementById('inputSessionStart').value;
const stopValue = document.getElementById('inputSessionStop').value;
const comment = document.getElementById('inputSessionComment').value.trim();
if (!startValue || !stopValue) {
alert('Заполните дату начала и окончания');
return;
}
const start = new Date(startValue);
const stop = new Date(stopValue);
if (start >= stop) {
alert('Дата окончания должна быть позже даты начала');
return;
}
const task = tasks.find(t => t.id === currentManualTaskId);
if (task) {
const segment = {
start: start.toISOString(),
stop: stop.toISOString()
};
if (comment) {
segment.comment = comment;
}
task.timeSegments.push(segment);
saveData();
renderTasks();
hideManualSessionForm();
}
}
// Показать форму редактирования сессии
function editSession(taskId, sessionIndex) {
currentEditTaskId = taskId;
currentEditSessionIndex = sessionIndex;
const task = tasks.find(t => t.id === taskId);
if (!task) return;
const segment = task.timeSegments[sessionIndex];
if (!segment) return;
document.getElementById('inputEditSessionStart').value = formatDateTimeLocal(new Date(segment.start));
document.getElementById('inputEditSessionStop').value = formatDateTimeLocal(new Date(segment.stop));
document.getElementById('inputEditSessionComment').value = segment.comment || '';
const form = document.getElementById('editSessionForm');
form.classList.remove('hidden');
form.scrollIntoView({ behavior: 'smooth', block: 'center' });
}
// Скрыть форму редактирования сессии
function hideEditSessionForm() {
document.getElementById('editSessionForm').classList.add('hidden');
currentEditTaskId = null;
currentEditSessionIndex = null;
}
// Сохранить изменения сессии
function saveEditSession() {
if (currentEditTaskId === null || currentEditSessionIndex === null) return;
const startValue = document.getElementById('inputEditSessionStart').value;
const stopValue = document.getElementById('inputEditSessionStop').value;
const comment = document.getElementById('inputEditSessionComment').value.trim();
if (!startValue || !stopValue) {
alert('Заполните дату начала и окончания');
return;
}
const start = new Date(startValue);
const stop = new Date(stopValue);
if (start >= stop) {
alert('Дата окончания должна быть позже даты начала');
return;
}
const task = tasks.find(t => t.id === currentEditTaskId);
if (task && task.timeSegments[currentEditSessionIndex]) {
task.timeSegments[currentEditSessionIndex] = {
start: start.toISOString(),
stop: stop.toISOString()
};
if (comment) {
task.timeSegments[currentEditSessionIndex].comment = comment;
}
saveData();
renderTasks();
hideEditSessionForm();
}
}
// Форматирование для datetime-local input
function formatDateTimeLocal(date) {
const year = date.getFullYear();
const month = String(date.getMonth() + 1).padStart(2, '0');
const day = String(date.getDate()).padStart(2, '0');
const hours = String(date.getHours()).padStart(2, '0');
const minutes = String(date.getMinutes()).padStart(2, '0');
return `${year}-${month}-${day}T${hours}:${minutes}`;
}
// Таймер для обновления активных задач
function startTimer() {
if (!updateInterval) {
updateInterval = setInterval(() => {
if (activeTaskId) {
renderTasks();
}
}, 1000);
}
}
function stopTimer() {
if (updateInterval) {
clearInterval(updateInterval);
updateInterval = null;
}
}
// Рендер списка задач
function renderTasks() {
const container = document.getElementById('tasksList');
if (tasks.length === 0) {
container.innerHTML = '<div class="card empty-state"><p>Нет задач. Создайте первую задачу!</p></div>';
return;
}
// Группировка задач по месяцам создания
const tasksByMonth = {};
tasks.forEach(task => {
const createDate = new Date(task.createDate || task.id);
const monthKey = getMonthYear(createDate);
if (!tasksByMonth[monthKey]) {
tasksByMonth[monthKey] = [];
}
tasksByMonth[monthKey].push(task);
});
// Сортировка месяцев по убыванию
const sortedMonths = Object.keys(tasksByMonth).sort().reverse();
let html = '';
sortedMonths.forEach(monthKey => {
const monthTasks = tasksByMonth[monthKey];
const monthTotal = monthTasks.reduce((sum, task) => sum + calculateTotalMinutes(task), 0);
const parts = monthKey.split('-');
const monthNames = ['Январь', 'Февраль', 'Март', 'Апрель', 'Май', 'Июнь',
'Июль', 'Август', 'Сентябрь', 'Октябрь', 'Ноябрь', 'Декабрь'];
const monthLabel = `${monthNames[parseInt(parts[1]) - 1]} ${parts[0]}`;
html += `
<div class="month-group">
<div class="month-header" onclick="toggleMonth('${monthKey}')">
<div>
<div class="month-title">📅 ${monthLabel}</div>
<div class="month-stats">
<span>Задач: ${monthTasks.length}</span>
<span>•</span>
<span>Всего: ${(monthTotal / 60).toFixed(1)} ч</span>
</div>
</div>
<div class="accordion-icon" id="icon-${monthKey}">▼</div>
</div>
<div class="tasks-grid expanded" id="month-${monthKey}">
<div class="task-grid-header" style="color: rgba(255,255,255,0.6); font-size: 0.9rem; font-weight: 500;">
<div>Задача / Проект</div>
<div>Дедлайн</div>
<div class="hide-mobile">Создана</div>
<div class="hide-mobile">Время</div>
<div>Статус</div>
<div>Действия</div>
</div>
${monthTasks.map(task => renderTaskRow(task)).join('')}
</div>
</div>
`;
});
container.innerHTML = html;
}
// Рендер строки задачи
function renderTaskRow(task) {
const isActive = task.isActive;
const minutes = calculateTotalMinutes(task);
const hours = calculateTotalHours(task);
const createDate = new Date(task.createDate || task.id);
const now = new Date();
let deadlineHTML = '<span style="color: rgba(255,255,255,0.4);">—</span>';
let rowClass = 'task-row';
if (task.deadline) {
const deadline = new Date(task.deadline);
const isOverdue = deadline < now && !isActive;
const daysUntil = Math.ceil((deadline - now) / (1000 * 60 * 60 * 24));
if (isOverdue) {
deadlineHTML = `<span class="deadline-badge overdue">⚠️ Просрочен</span>`;
rowClass += ' overdue';
} else if (daysUntil <= 3) {
deadlineHTML = `<span class="deadline-badge upcoming">⏰ ${formatDate(task.deadline)}</span>`;
rowClass += ' has-deadline';
} else {
deadlineHTML = `<span class="deadline-badge completed">📅 ${formatDate(task.deadline)}</span>`;
}
}
if (isActive) {
rowClass += ' active-task';
}
return `
<div class="${rowClass}" id="task-${task.id}">
<div class="task-grid-row">
<div>
<div style="font-weight: bold; margin-bottom: 3px;">${escapeHtml(task.task)}</div>
${task.project ? `<div style="color: #c084fc; font-size: 0.85rem;">📂 ${escapeHtml(task.project)}</div>` : ''}
</div>
<div>${deadlineHTML}</div>
<div class="hide-mobile" style="font-size: 0.85rem; color: rgba(255,255,255,0.6);">${formatDate(createDate.toISOString())}</div>
<div class="hide-mobile">
<div style="font-weight: bold;">${hours} ч</div>
<div style="font-size: 0.85rem; color: rgba(255,255,255,0.6);">${minutes} мин</div>
</div>
<div>
${isActive ?
'<span style="color: #10b981; font-weight: 500;">● Активна</span>' :
'<span style="color: rgba(255,255,255,0.4);">○ Остановлена</span>'
}
</div>
<div style="display: flex; gap: 5px;">
${!isActive ?
`<button class="btn btn-success btn-small" onclick="startTask(${task.id})" ${activeTaskId ? 'disabled' : ''} style="padding: 6px 12px;">▶️</button>` :
`<button class="btn btn-danger btn-small pulse" onclick="stopTask(${task.id})" style="padding: 6px 12px;">⏹️</button>`
}
<button class="btn btn-secondary btn-small" onclick="toggleTaskDetails(${task.id})" style="padding: 6px 12px;">📊</button>
<button class="btn btn-danger btn-small" onclick="deleteTask(${task.id})" style="padding: 6px 12px;">🗑️</button>
</div>
</div>
<div class="task-details hidden" id="details-${task.id}">
<div class="stats-grid" style="margin-bottom: 15px;">
<div class="stat-box">
<div class="stat-label">Минуты</div>
<div class="stat-value">${minutes}</div>
</div>
<div class="stat-box">
<div class="stat-label">Часы</div>
<div class="stat-value">${hours}</div>
</div>
<div class="stat-box">
<div class="stat-label">Сессий</div>
<div class="stat-value">${task.timeSegments.length}</div>
</div>
<div class="stat-box">
<div class="stat-label">Создана</div>
<div style="font-size: 1rem; font-weight: bold;">${formatDate(createDate.toISOString())}</div>
</div>
</div>
<div style="margin-top: 15px;">
<button class="btn btn-secondary btn-small" onclick="showManualSessionForm(${task.id})">➕ Добавить сессию вручную</button>