odant-work 1.0.72 → 1.0.74

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (27) hide show
  1. package/#system/package-manifest.json +29 -27
  2. package/$server/$folder/$class/$structure/handlers/pages/explorer/$handler/explorer.js +1 -1
  3. package/$server/$folder/$class/$structure/handlers/pages/form/calendar/$handler/calendar.js +1004 -1011
  4. package/$server/$folder/$class/$structure/handlers/pages/form/email/$handler/class.js +7 -90
  5. package/$server/$folder/$class/$structure/handlers/pages/form/email/$handler/email.js +913 -705
  6. package/$server/$folder/$class/$structure/handlers/pages/form/email/$handler/methods/refresh/$method/class.js +30 -1
  7. package/$server/$folder/$class/$structure/handlers/pages/form/search/$handler/class.js +1 -1
  8. package/$server/$folder/$class/$structure/handlers/pages/form/system/$handler/tabs/staff.js +78 -5
  9. package/$server/$folder/$class/ai/skills/email-mailbox.md +10 -7
  10. package/$server/$folder/$class/ai/skills/meeting-minutes.md +1 -1
  11. package/$server/$folder/$file/$eml/triggers/on_save/$trigger/class.js +17 -1
  12. package/$server/$folder/lib/calendar-form/calendar-form.js +482 -296
  13. package/$server/$folder/lib/icon/icon.js +50 -0
  14. package/$server/$folder/lib/tree/tree.js +9 -7
  15. package/USERS/$users/class.js +4 -3
  16. package/oda/components/icon/icon.js +6 -1
  17. package/package.json +1 -1
  18. package/sources/host/email-utils.js +25 -1
  19. package/sources/modules/agent/index.js +3 -1
  20. package/sources/modules/agent/node-rules.js +51 -0
  21. package/sources/modules/agent/scheduler.js +7 -0
  22. package/sources/modules/agent/tools/calendar-mail.js +273 -0
  23. package/sources/server/access/gateway.js +3 -0
  24. package/sources/server/class/feed.js +46 -0
  25. package/sources/server/class/mail-calendar.js +867 -0
  26. package/sources/server/class/security.js +44 -0
  27. package/sources/server/folder.js +1 -1
@@ -1,30 +1,411 @@
1
+ const HOUR_HEIGHT = 56;
2
+ const HALF_HEIGHT = HOUR_HEIGHT / 2;
3
+
4
+ const CAT_COLORS = {
5
+ meeting: { bg: '#eff6ff', border: '#2563eb', text: '#1e3a8a' },
6
+ important: { bg: '#fef2f2', border: '#dc2626', text: '#991b1b' },
7
+ personal: { bg: '#f5f3ff', border: '#7c3aed', text: '#5b21b6' },
8
+ client: { bg: '#ecfdf5', border: '#059669', text: '#065f46' },
9
+ task: { bg: '#fff7ed', border: '#ea580c', text: '#9a3412' },
10
+ ai: { bg: '#f0fdf4', border: '#16a34a', text: '#166534' },
11
+ };
12
+
13
+ function _newUid() {
14
+ if (globalThis.crypto?.randomUUID)
15
+ return globalThis.crypto.randomUUID();
16
+ return Date.now().toString(36) + '-' + Math.random().toString(36).slice(2, 10);
17
+ }
18
+
19
+ function _asDate(v) {
20
+ if (v instanceof Date && !isNaN(v))
21
+ return new Date(v.getTime());
22
+ if (typeof v === 'string' && /^\d{4}-\d{2}-\d{2}$/.test(v)) {
23
+ const [y, m, d] = v.split('-').map(Number);
24
+ return new Date(y, m - 1, d);
25
+ }
26
+ const d = v ? new Date(v) : new Date();
27
+ return isNaN(d) ? new Date() : d;
28
+ }
29
+
30
+ function _formatDate(date) {
31
+ const pad = n => String(n).padStart(2, '0');
32
+ return `${date.getFullYear()}-${pad(date.getMonth() + 1)}-${pad(date.getDate())}`;
33
+ }
34
+
35
+ function _weekStart(date) {
36
+ const d = new Date(date.getFullYear(), date.getMonth(), date.getDate());
37
+ const day = d.getDay();
38
+ d.setDate(d.getDate() - (day === 0 ? 6 : day - 1));
39
+ return d;
40
+ }
41
+
42
+ function _weekEnd(date) {
43
+ const d = _weekStart(date);
44
+ d.setDate(d.getDate() + 6);
45
+ return d;
46
+ }
47
+
48
+ function _parseDay(str) {
49
+ const [y, m, d] = String(str).split('-').map(Number);
50
+ return new Date(y, m - 1, d);
51
+ }
52
+
53
+ function _formatTime(iso) {
54
+ if (!iso) return '';
55
+ const d = new Date(iso);
56
+ if (isNaN(d)) return '';
57
+ const pad = n => String(n).padStart(2, '0');
58
+ return `${pad(d.getHours())}:${pad(d.getMinutes())}`;
59
+ }
60
+
61
+ function _eventStyleVars(ev) {
62
+ const key = ev.kind === 'task' ? 'task' : ev.kind === 'schedule' ? 'ai' : (ev.category || 'meeting');
63
+ return CAT_COLORS[key] || CAT_COLORS.meeting;
64
+ }
65
+
66
+ function _layoutDayEvents(dayEvents, dayDate) {
67
+ const dayStart = new Date(dayDate.getFullYear(), dayDate.getMonth(), dayDate.getDate()).getTime();
68
+ const dayEnd = dayStart + 86400_000;
69
+ const minHeight = 20;
70
+ const items = [];
71
+ for (const ev of dayEvents) {
72
+ if (ev.allDay) continue;
73
+ const s = Date.parse(ev.start);
74
+ const e = Date.parse(ev.end);
75
+ if (!Number.isFinite(s) || !Number.isFinite(e) || e <= dayStart || s >= dayEnd)
76
+ continue;
77
+ const cs = Math.max(s, dayStart);
78
+ const ce = Math.min(e, dayEnd);
79
+ const startMin = (cs - dayStart) / 60000;
80
+ const endMin = Math.max(startMin + 20, (ce - dayStart) / 60000);
81
+ items.push({
82
+ ev,
83
+ startMin,
84
+ endMin,
85
+ top: (startMin / 60) * HOUR_HEIGHT,
86
+ height: Math.max(minHeight, ((endMin - startMin) / 60) * HOUR_HEIGHT - 2),
87
+ });
88
+ }
89
+ items.sort((a, b) => a.startMin - b.startMin || b.endMin - a.endMin);
90
+
91
+ // Группируем пересекающиеся события в кластеры и раскладываем по столбцам
92
+ const clusters = [];
93
+ let curCluster = [];
94
+ let clusterEnd = -1;
95
+ for (const it of items) {
96
+ if (!curCluster.length || it.startMin < clusterEnd) {
97
+ curCluster.push(it);
98
+ clusterEnd = Math.max(clusterEnd, it.endMin);
99
+ }
100
+ else {
101
+ clusters.push(curCluster);
102
+ curCluster = [it];
103
+ clusterEnd = it.endMin;
104
+ }
105
+ }
106
+ if (curCluster.length) clusters.push(curCluster);
107
+
108
+ const out = [];
109
+ for (const cluster of clusters) {
110
+ const cols = [];
111
+ for (const it of cluster) {
112
+ let colIdx = cols.findIndex(endT => endT <= it.startMin);
113
+ if (colIdx < 0) {
114
+ colIdx = cols.length;
115
+ cols.push(it.endMin);
116
+ }
117
+ else {
118
+ cols[colIdx] = it.endMin;
119
+ }
120
+ it.col = colIdx;
121
+ }
122
+ const totalCols = Math.max(1, cols.length);
123
+ for (const it of cluster) {
124
+ const widthPct = 100 / totalCols;
125
+ const leftPct = it.col * widthPct;
126
+ out.push({
127
+ ...it.ev,
128
+ top: it.top,
129
+ height: it.height,
130
+ leftPct,
131
+ widthPct,
132
+ timeLabel: `${_formatTime(it.ev.start)}–${_formatTime(it.ev.end)}`,
133
+ });
134
+ }
135
+ }
136
+ return out;
137
+ }
138
+
1
139
  export default {
2
- imports: 'oda//app-layout, ~/lib//calendar-form.js',
3
- extends: 'oda-app-layout',
140
+ imports: 'oda//icon, oda//button, ~/lib//calendar-form.js',
4
141
  icon: 'enterprise:calendar',
5
- template: /*html*/`
6
- <oda-form-calendar slot="main" flex :$item style="overflow-y: auto;" :events ::view-mode ::current-date ::selected_users></oda-form-calendar>
7
- <div slot="right-panel" vertical flex icon="carbon:table-of-contents:180" style="overflow-y: auto; height: 0; padding: 4px 0;">
8
- <oda-form-calendar-list-view flex label="Встречи" :events></oda-form-calendar-list-view>
142
+ template: /* html */`
143
+ <style>
144
+ :host {
145
+ @apply --vertical;
146
+ @apply --flex;
147
+ overflow: hidden;
148
+ background: var(--content-background, #ffffff);
149
+ color: var(--content-color, #1e293b);
150
+ position: relative;
151
+ }
152
+ .cal-header {
153
+ @apply --horizontal;
154
+ align-items: center;
155
+ gap: 10px;
156
+ padding: 8px 14px;
157
+ border-bottom: 1px solid var(--subtle-border, #e2e8f0);
158
+ background: var(--subtle-background, #f8fafc);
159
+ flex-wrap: wrap;
160
+ flex-shrink: 0;
161
+ }
162
+ .cal-group {
163
+ @apply --horizontal;
164
+ align-items: center;
165
+ gap: 4px;
166
+ }
167
+ .btn-new {
168
+ @apply --horizontal;
169
+ align-items: center;
170
+ gap: 5px;
171
+ padding: 6px 13px;
172
+ border-radius: 8px;
173
+ border: none;
174
+ background: var(--accent-color, #2563eb);
175
+ color: var(--accent-back, #ffffff);
176
+ font: inherit;
177
+ font-size: 13px;
178
+ font-weight: 600;
179
+ cursor: pointer;
180
+ box-shadow: 0 1px 3px rgba(0, 0, 0, 0.14);
181
+ }
182
+ .btn-new:hover { filter: brightness(1.06); }
183
+ .btn-outline {
184
+ @apply --horizontal;
185
+ align-items: center;
186
+ gap: 5px;
187
+ padding: 5px 10px;
188
+ border-radius: 7px;
189
+ border: 1px solid var(--subtle-border, #cbd5e1);
190
+ background: var(--content-background, #ffffff);
191
+ color: inherit;
192
+ font: inherit;
193
+ font-size: 12.5px;
194
+ font-weight: 500;
195
+ cursor: pointer;
196
+ }
197
+ .btn-outline:hover { background: var(--accent-soft); }
198
+ .btn-outline.active {
199
+ border-color: var(--accent-color, #2563eb);
200
+ color: var(--accent-color, #2563eb);
201
+ background: color-mix(in srgb, var(--accent-color, #2563eb) 10%, var(--content-background, #ffffff));
202
+ font-weight: 600;
203
+ }
204
+ .period-title {
205
+ font-size: 15px;
206
+ font-weight: 700;
207
+ margin: 0 4px;
208
+ white-space: nowrap;
209
+ }
210
+ .date-jump {
211
+ border: 1px solid var(--subtle-border, #cbd5e1);
212
+ border-radius: 6px;
213
+ padding: 3px 6px;
214
+ font: inherit;
215
+ font-size: 12px;
216
+ background: var(--content-background, #ffffff);
217
+ color: inherit;
218
+ cursor: pointer;
219
+ }
220
+ .layer-pill {
221
+ @apply --horizontal;
222
+ align-items: center;
223
+ gap: 5px;
224
+ padding: 4px 9px;
225
+ border-radius: 999px;
226
+ border: 1px solid var(--subtle-border, #cbd5e1);
227
+ background: var(--content-background, #ffffff);
228
+ font: inherit;
229
+ font-size: 12px;
230
+ cursor: pointer;
231
+ opacity: 0.65;
232
+ transition: opacity 0.12s ease, border-color 0.12s ease;
233
+ }
234
+ .layer-pill.on {
235
+ opacity: 1;
236
+ font-weight: 600;
237
+ border-color: var(--border-color, #94a3b8);
238
+ }
239
+ .layer-dot {
240
+ width: 8px;
241
+ height: 8px;
242
+ border-radius: 50%;
243
+ }
244
+ .seg-tabs {
245
+ @apply --horizontal;
246
+ align-items: center;
247
+ padding: 2px;
248
+ border-radius: 8px;
249
+ border: 1px solid var(--subtle-border, #cbd5e1);
250
+ background: var(--content-background, #ffffff);
251
+ gap: 2px;
252
+ }
253
+ .seg-btn {
254
+ border: none;
255
+ background: transparent;
256
+ color: inherit;
257
+ font: inherit;
258
+ font-size: 12.5px;
259
+ font-weight: 500;
260
+ padding: 4px 10px;
261
+ border-radius: 6px;
262
+ cursor: pointer;
263
+ }
264
+ .seg-btn.active {
265
+ background: var(--accent-color, #2563eb);
266
+ color: var(--accent-back, #ffffff);
267
+ font-weight: 600;
268
+ }
269
+ .att-popover {
270
+ position: absolute;
271
+ top: 50px;
272
+ right: 16px;
273
+ z-index: 20;
274
+ width: 250px;
275
+ max-height: 320px;
276
+ overflow-y: auto;
277
+ background: var(--content-background, #ffffff);
278
+ border: 1px solid var(--border-color, #cbd5e1);
279
+ border-radius: 10px;
280
+ box-shadow: 0 8px 24px rgba(0, 0, 0, 0.15);
281
+ padding: 10px;
282
+ display: flex;
283
+ flex-direction: column;
284
+ gap: 6px;
285
+ font-size: 12.5px;
286
+ }
287
+ .att-row {
288
+ @apply --horizontal;
289
+ align-items: center;
290
+ gap: 8px;
291
+ padding: 5px 8px;
292
+ border-radius: 6px;
293
+ cursor: pointer;
294
+ }
295
+ .att-row:hover { background: var(--subtle-background, #f1f5f9); }
296
+ .att-row.selected {
297
+ background: color-mix(in srgb, var(--accent-color, #2563eb) 12%, transparent);
298
+ color: var(--accent-color, #2563eb);
299
+ font-weight: 600;
300
+ }
301
+ </style>
302
+
303
+ <div class="cal-header">
304
+ <div class="cal-group">
305
+ <button type="button" class="btn-new" @tap="openCreate()" title="Создать новую встречу">
306
+ <oda-icon icon="icons:add" icon-size="16"></oda-icon>
307
+ <span>Встреча</span>
308
+ </button>
309
+ <button type="button" class="btn-outline" @tap="goToday()">Сегодня</button>
310
+ <button type="button" class="btn-outline" @tap="stepDate(-1)" title="Назад" style="padding: 5px 7px;">
311
+ <oda-icon icon="icons:chevron-left" icon-size="16"></oda-icon>
312
+ </button>
313
+ <button type="button" class="btn-outline" @tap="stepDate(1)" title="Вперёд" style="padding: 5px 7px;">
314
+ <oda-icon icon="icons:chevron-right" icon-size="16"></oda-icon>
315
+ </button>
316
+ <span class="period-title">{{periodTitle}}</span>
317
+ <input class="date-jump" type="date" :value="day" @change="onDateJump($event)" title="Перейти к дате">
318
+ </div>
319
+
320
+ <div style="flex: 1;"></div>
321
+
322
+ <div class="cal-group">
323
+ <button type="button" class="layer-pill" ~class="{ on: showEvents }" @tap="showEvents = !showEvents" title="Встречи и события">
324
+ <span class="layer-dot" style="background:#2563eb;"></span>
325
+ <span>Встречи</span>
326
+ </button>
327
+ <button type="button" class="layer-pill" ~class="{ on: showTasks }" @tap="showTasks = !showTasks" title="Задачи узла">
328
+ <span class="layer-dot" style="background:#ea580c;"></span>
329
+ <span>Задачи</span>
330
+ </button>
331
+ <button type="button" class="layer-pill" ~class="{ on: showSchedules }" @tap="showSchedules = !showSchedules" title="Расписания ИИ-двойника">
332
+ <span class="layer-dot" style="background:#16a34a;"></span>
333
+ <span>Расписания ИИ</span>
334
+ </button>
335
+ </div>
336
+
337
+ <div class="cal-group" ~if="contacts.length">
338
+ <button type="button" class="btn-outline" ~class="{ active: selected_users.length > 0 || showPeopleMenu }" @tap="showPeopleMenu = !showPeopleMenu" title="Фильтр по участникам">
339
+ <oda-icon icon="icons:supervisor-account" icon-size="15"></oda-icon>
340
+ <span>{{selected_users.length ? 'Участники (' + selected_users.length + ')' : 'Участники'}}</span>
341
+ </button>
342
+ </div>
343
+
344
+ <div class="seg-tabs">
345
+ <button type="button" class="seg-btn" ~class="{ active: viewMode === 'day' }" @tap="viewMode = 'day'">День</button>
346
+ <button type="button" class="seg-btn" ~class="{ active: viewMode === 'workweek' }" @tap="viewMode = 'workweek'">Раб. неделя</button>
347
+ <button type="button" class="seg-btn" ~class="{ active: viewMode === 'week' }" @tap="viewMode = 'week'">Неделя</button>
348
+ <button type="button" class="seg-btn" ~class="{ active: viewMode === 'month' }" @tap="viewMode = 'month'">Месяц</button>
349
+ </div>
350
+
351
+ <button type="button" class="btn-outline" @tap="reloadEvents()" title="Обновить календарь" style="padding: 5px 8px;">
352
+ <oda-icon icon="icons:refresh" icon-size="15"></oda-icon>
353
+ </button>
354
+ </div>
355
+
356
+ <div ~if="showPeopleMenu" class="att-popover">
357
+ <div style="display:flex;align-items:center;justify-content:space-between;font-weight:700;">
358
+ <span>Фильтр по сотрудникам</span>
359
+ <button type="button" class="btn-outline" style="padding:2px 6px;font-size:11px;" ~if="selected_users.length" @tap="clearUsers()">Сбросить</button>
360
+ </div>
361
+ <div ~for="contacts" class="att-row" ~class="{ selected: selected_users.includes($for.item.id) }" @tap="toggleUserFilter($for.item.id)">
362
+ <span>{{selected_users.includes($for.item.id) ? '☑' : '☐'}}</span>
363
+ <span>{{$for.item.label || $for.item.id}}</span>
364
+ </div>
9
365
  </div>
366
+
367
+ <oda-calendar-month-view ~if="viewMode === 'month'" flex :events="visibleEvents" :current-date="currentDate"
368
+ @add-event="onAddEvent($event)" @open-event="onOpenEvent($event)"></oda-calendar-month-view>
369
+
370
+ <oda-calendar-time-grid ~if="viewMode !== 'month'" flex :events="visibleEvents" :current-date="currentDate" :view-mode="viewMode"
371
+ @add-event="onAddEvent($event)" @open-event="onOpenEvent($event)" @move-event="onMoveEvent($event)"></oda-calendar-time-grid>
10
372
  `,
11
373
  viewMode: {
12
- $def: 'day',
374
+ $def: 'week',
13
375
  $save: true,
14
- set() {
15
- this.events = undefined;
16
- }
376
+ set() { this.events = undefined; }
17
377
  },
18
378
  currentDate: {
19
379
  $def: null,
20
- set() {
21
- this.events = undefined;
22
- }
380
+ set() { this.events = undefined; }
23
381
  },
24
382
  selected_users: {
25
383
  $def: [],
26
- set() {
27
- this.events = undefined;
384
+ set() { this.events = undefined; }
385
+ },
386
+ showEvents: true,
387
+ showTasks: {
388
+ $def: true,
389
+ $save: true,
390
+ set() { this.events = undefined; }
391
+ },
392
+ showSchedules: {
393
+ $def: true,
394
+ $save: true,
395
+ set() { this.events = undefined; }
396
+ },
397
+ showPeopleMenu: false,
398
+ contacts: [],
399
+ async attached() {
400
+ if (!this.currentDate)
401
+ this.currentDate = new Date();
402
+ if (typeof globalThis.WORK?.visible_contacts === 'function') {
403
+ try {
404
+ const list = await globalThis.WORK.visible_contacts();
405
+ if (Array.isArray(list))
406
+ this.contacts = list.filter(c => c && c.id && !c.external);
407
+ }
408
+ catch { /* ignore */ }
28
409
  }
29
410
  },
30
411
  get day() {
@@ -57,10 +438,35 @@ export default {
57
438
  }
58
439
  return this.day;
59
440
  },
441
+ get periodTitle() {
442
+ const d = _asDate(this.currentDate);
443
+ if (this.viewMode === 'day') {
444
+ return d.toLocaleDateString('ru-RU', { day: 'numeric', month: 'long', year: 'numeric' });
445
+ }
446
+ if (this.viewMode === 'month') {
447
+ const s = d.toLocaleDateString('ru-RU', { month: 'long', year: 'numeric' });
448
+ return s.charAt(0).toUpperCase() + s.slice(1);
449
+ }
450
+ const f = _parseDay(this.dayFrom);
451
+ const t = _parseDay(this.dayTo);
452
+ if (f.getMonth() === t.getMonth())
453
+ return `${f.getDate()}–${t.getDate()} ${t.toLocaleDateString('ru-RU', { month: 'long', year: 'numeric' })}`;
454
+ return `${f.toLocaleDateString('ru-RU', { day: 'numeric', month: 'short' })} – ${t.toLocaleDateString('ru-RU', { day: 'numeric', month: 'short', year: 'numeric' })}`;
455
+ },
456
+ get visibleEvents() {
457
+ const all = Array.isArray(this.events) ? this.events : [];
458
+ return all.filter(ev => {
459
+ if (ev.kind === 'task') return this.showTasks;
460
+ if (ev.kind === 'schedule') return this.showSchedules;
461
+ return this.showEvents;
462
+ });
463
+ },
60
464
  get events() {
61
465
  const dayFrom = this.dayFrom;
62
466
  const dayTo = this.dayTo;
63
467
  const selected_users = this.selected_users;
468
+ const includeTasks = this.showTasks;
469
+ const includeSchedules = this.showSchedules;
64
470
  const source = this.$item;
65
471
  if (!dayFrom || !dayTo || !source)
66
472
  return [];
@@ -71,1133 +477,720 @@ export default {
71
477
  source?.listen?.('changed', this._boundOnLogsChanged);
72
478
  this._historyFolder = source;
73
479
  }
74
- const rows = await source.logs({
75
- mode: 'bodies',
76
- from: dayFrom,
77
- to: dayTo,
78
- ext: 'ics',
79
- });
80
- // rows отсортированы по убыванию time: первая строка uid — последняя версия встречи
81
- const latest = new Map();
82
- for (const row of rows || []) {
83
- const content = _parseContent(row.content);
84
- if (!content)
85
- continue;
86
- const key = meetingKey(row, content);
87
- if (!latest.has(key))
88
- latest.set(key, { row, content });
89
- }
90
- const parsed = [];
91
- for (const { row, content } of latest.values()) {
92
- if (content.status === 'cancelled')
93
- continue;
94
- if (!content.start || !content.end)
95
- continue;
96
- if (selected_users.length && !selected_users.includes(row.sender))
97
- continue;
98
- parsed.push({ row, content });
480
+ if (typeof source.fetch === 'function') {
481
+ try {
482
+ const res = await source.fetch('calendar_list', {}, JSON.stringify({
483
+ from: dayFrom,
484
+ to: dayTo,
485
+ includeTasks,
486
+ includeSchedules,
487
+ attendees: selected_users,
488
+ }));
489
+ const list = Array.isArray(res?.events) ? res.events : [];
490
+ return this.events = list;
491
+ }
492
+ catch { /* fallback to logs */ }
99
493
  }
100
- const events = await Promise.all(parsed.map(async ({ row, content }) => ({
101
- uid: meetingKey(row, content),
102
- start: content.start,
103
- end: content.end,
104
- summary: content.summary ?? '',
105
- location: content.location ?? '',
106
- allDay: !!content.allDay,
107
- $item: {
108
- id: `${row.time || 0}.${row.sender || 'system'}.logs`,
109
- ext: 'logs',
110
- path: row.logsFilePath,
111
- logRow: row,
112
- load: async () => ({ ...row }),
494
+ const rows = await source.logs?.({ mode: 'bodies', from: dayFrom, to: dayTo, ext: 'ics' }).catch(() => []);
495
+ const out = [];
496
+ for (const row of rows || []) {
497
+ try {
498
+ const c = typeof row.content === 'string' ? JSON.parse(row.content) : row.content;
499
+ if (!c || c.status === 'cancelled' || !c.start || !c.end) continue;
500
+ out.push({ kind: 'event', ...c, path: row.path, row });
113
501
  }
114
- })));
115
- events.sort((a, b) => String(a.start).localeCompare(String(b.start)));
116
- return this.events = events;
502
+ catch { /* ignore */ }
503
+ }
504
+ return this.events = out;
117
505
  })();
118
506
  },
119
507
  detached() {
120
508
  this._historyFolder?.unlisten?.('changed', this._boundOnLogsChanged);
121
509
  this._historyFolder = null;
122
510
  },
511
+ reloadEvents() {
512
+ this.events = undefined;
513
+ },
514
+ goToday() {
515
+ this.currentDate = new Date();
516
+ },
517
+ stepDate(dir) {
518
+ const d = _asDate(this.currentDate);
519
+ if (this.viewMode === 'day') d.setDate(d.getDate() + dir);
520
+ else if (this.viewMode === 'week' || this.viewMode === 'workweek') d.setDate(d.getDate() + 7 * dir);
521
+ else d.setMonth(d.getMonth() + dir);
522
+ this.currentDate = d;
523
+ },
524
+ onDateJump(e) {
525
+ if (e.target.value)
526
+ this.currentDate = _parseDay(e.target.value);
527
+ },
528
+ toggleUserFilter(uid) {
529
+ const cur = [...this.selected_users];
530
+ const i = cur.indexOf(uid);
531
+ if (i >= 0) cur.splice(i, 1);
532
+ else cur.push(uid);
533
+ this.selected_users = cur;
534
+ },
535
+ clearUsers() {
536
+ this.selected_users = [];
537
+ },
538
+ openCreate() {
539
+ const start = _asDate(this.currentDate);
540
+ const now = new Date();
541
+ start.setHours(Math.max(9, Math.min(18, now.getHours() + 1)), 0, 0, 0);
542
+ const end = new Date(start.getTime() + 60 * 60_000);
543
+ this.showMeeting({ start, end, allDay: false });
544
+ },
545
+ onAddEvent(e) {
546
+ this.showMeeting(e?.detail?.value || e?.detail || {});
547
+ },
548
+ async onOpenEvent(e) {
549
+ const ev = e?.detail?.value || e?.detail;
550
+ if (!ev) return;
551
+ if (ev.kind === 'task' && ev.path) {
552
+ const item = await globalThis.WORK?.get_item?.(ev.path).catch(() => null);
553
+ if (item && typeof window?.execute === 'function')
554
+ window.execute(item);
555
+ return;
556
+ }
557
+ if (ev.kind === 'schedule') {
558
+ ODA.showMessage?.(`Расписание ИИ: «${ev.summary}» (${_formatTime(ev.start)})`);
559
+ return;
560
+ }
561
+ await this.showMeeting(ev);
562
+ },
563
+ async onMoveEvent(e) {
564
+ const d = e?.detail?.value || e?.detail;
565
+ if (!d?.ev || !d.start || !d.end || d.ev.kind !== 'event')
566
+ return;
567
+ const payload = {
568
+ ...d.ev,
569
+ start: d.start,
570
+ end: d.end,
571
+ status: 'confirmed',
572
+ };
573
+ try {
574
+ await this.$item.fetch('calendar_save', {}, JSON.stringify(payload));
575
+ this.events = undefined;
576
+ }
577
+ catch (err) {
578
+ ODA.showMessage?.(err?.message || String(err));
579
+ }
580
+ },
123
581
  async showMeeting(arg) {
124
- const isEdit = arg && typeof arg.load === 'function';
582
+ const isEdit = Boolean(arg && arg.uid && arg.start);
125
583
  let el;
126
584
  let uid;
127
- let filename;
128
585
 
129
586
  if (isEdit) {
130
- const raw = await arg.load();
131
- const log = typeof raw === 'string' ? JSON.parse(raw) : raw;
132
- const content = _parseContent(log.content) || {};
133
- uid = meetingKey(log, content);
134
- // новые встречи — <uid>.ics; старые (без uid) — прежнее имя файла
135
- filename = content.uid && !String(content.uid).startsWith('file:')
136
- ? `${content.uid}.ics`
137
- : filenameFromHistoryPath(log.path);
138
- const file = await WORK.get_item(log.path);
139
- el = ODA.createElement('calendar-form', { $item: file, canCancel: true });
140
- } else {
587
+ uid = arg.uid;
588
+ const editPayload = {
589
+ ...arg,
590
+ start: arg.masterStart || arg.start,
591
+ end: arg.masterEnd || arg.end,
592
+ };
593
+ el = ODA.createElement('calendar-form', {
594
+ events: [editPayload],
595
+ canCancel: true,
596
+ });
597
+ }
598
+ else {
141
599
  uid = _newUid();
142
- filename = `${uid}.ics`;
143
600
  const detail = arg || {};
144
601
  const start = detail.start ? new Date(detail.start) : new Date();
145
602
  let end;
146
603
  if (detail.allDay) {
147
604
  start.setHours(0, 0, 0, 0);
148
605
  end = detail.end ? new Date(detail.end) : new Date(start);
149
- if (!detail.end)
150
- end.setDate(end.getDate() + 1);
151
- else
152
- end.setHours(0, 0, 0, 0);
153
- if (end <= start)
154
- end.setDate(start.getDate() + 1);
155
- } else {
156
- end = detail.end ? new Date(detail.end) : new Date(start.getTime() + 30 * 60 * 1000);
606
+ if (!detail.end) end.setDate(end.getDate() + 1);
607
+ else end.setHours(0, 0, 0, 0);
608
+ if (end <= start) end.setDate(start.getDate() + 1);
609
+ }
610
+ else {
611
+ end = detail.end ? new Date(detail.end) : new Date(start.getTime() + 60 * 60_000);
157
612
  }
158
613
  el = ODA.createElement('calendar-form', {
159
614
  events: [{
160
615
  start: start.toISOTimezoneString(),
161
616
  end: end.toISOTimezoneString(),
162
- allDay: !!detail.allDay
163
- }]
617
+ allDay: !!detail.allDay,
618
+ category: 'meeting',
619
+ recurrence: 'none',
620
+ reminderMin: 15,
621
+ attendees: [],
622
+ externalEmails: [],
623
+ }],
164
624
  });
165
625
  }
166
626
 
167
627
  try {
168
628
  await WORK.showDialog(el, {
169
- TITLE: { label: isEdit ? 'Встреча' : 'Новая встреча', icon: 'enterprise:calendar' },
629
+ TITLE: { label: isEdit ? 'Редактирование встречи' : 'Новая встреча', icon: 'enterprise:calendar' },
170
630
  OK: { label: 'Сохранить', icon: 'icons:save' },
171
631
  CANCEL: { label: 'Отмена', icon: 'icons:close' },
172
632
  });
173
- } catch {
633
+ }
634
+ catch {
174
635
  return;
175
636
  }
176
637
 
177
638
  const persist = el.eventToPersist(el.events[0]);
178
639
  const startDate = new Date(persist.start);
179
640
  const endDate = new Date(persist.end);
180
- if (isNaN(startDate) || isNaN(endDate) || endDate <= startDate)
641
+ if (isNaN(startDate) || isNaN(endDate) || endDate <= startDate) {
642
+ ODA.showMessage?.('Время окончания должно быть позже начала');
181
643
  return;
182
-
183
- persist.uid = uid;
184
- persist.time = startDate.getTime();
185
- persist.status = el.cancelled ? 'cancelled' : 'confirmed';
186
- const body = JSON.stringify(persist);
187
- const file = new File([body], filename, { type: 'text/plain' });
188
- const message = JSON.stringify({
644
+ }
645
+ const status = el.cancelled ? 'cancelled' : 'confirmed';
646
+ const payload = {
647
+ ...persist,
189
648
  uid,
190
- status: persist.status,
191
- start: persist.start,
192
- end: persist.end,
193
- summary: persist.summary,
194
- location: persist.location,
195
- allDay: !!persist.allDay,
196
- time: persist.time
197
- });
198
- await this.$item.save_file(file, { message, time: persist.time });
199
- this.events = undefined;
200
- }
201
- }
202
-
203
- ODA({
204
- is: 'oda-form-calendar', imports: '~/lib//users.js',
205
- template: /*html*/`
206
- <style>
207
- :host {
208
- @apply --vertical;
209
- @apply --flex;
210
- }
211
- .toolbar {
212
- padding: 4px;
213
- align-items: normal;
214
- }
215
- .calendar-container {
216
- overflow: auto;
649
+ status,
650
+ summary: persist.summary || (status === 'cancelled' ? 'Отменено' : 'Встреча'),
651
+ time: startDate.getTime(),
652
+ };
653
+ try {
654
+ if (typeof this.$item.fetch === 'function') {
655
+ await this.$item.fetch('calendar_save', {}, JSON.stringify(payload));
217
656
  }
218
- .btn_mode {
219
- border-radius: var(--radius-s);
657
+ else {
658
+ await this.$item.save_file(
659
+ new File([JSON.stringify(payload)], `${uid}.ics`, { type: 'application/json' }),
660
+ { time: startDate.getTime(), encoding: 'utf-8', message: JSON.stringify(payload) }
661
+ );
220
662
  }
221
- </style>
222
- <item-users accent-invert flex :$item ::selected_users slot="top"></item-users>
223
- <div vertical header class="toolbar">
224
- <div horizontal>
225
- <oda-date-nav :view-mode ::current-date></oda-date-nav>
226
- <div horizontal>
227
- <oda-button class="btn_mode" icon="bootstrap:calendar2-day" :info="viewMode==='day'" title="День" @tap="viewMode='day'"></oda-button>
228
- <oda-button class="btn_mode" icon="bootstrap:calendar2-range" :info="viewMode==='workweek'" title="Рабочая неделя" @tap="viewMode='workweek'"></oda-button>
229
- <oda-button class="btn_mode" icon="bootstrap:calendar2-week" :info="viewMode==='week'" title="Неделя" @tap="viewMode='week'"></oda-button>
230
- <oda-button class="btn_mode" icon="bootstrap:calendar2-month" :info="viewMode==='month'" title="Месяц" @tap="viewMode='month'"></oda-button>
231
- </div>
232
- </div>
233
- </div>
234
- <div class="calendar-container" vertical flex>
235
- <oda-calendar-month-view ~if="viewMode==='month'" :events :current-date></oda-calendar-month-view>
236
- <oda-calendar-time-grid ~if="viewMode!=='month'" :events :current-date :view-mode></oda-calendar-time-grid>
237
- </div>
238
- `,
239
- $item: null,
240
- events: [],
241
- selected_users: [],
242
- // состояние хранит handler (viewMode с $save), здесь — только двусторонняя привязка
243
- viewMode: 'day',
244
- currentDate: null,
245
- $listeners: {
246
- 'add-event'(e) {
247
- this._addEvent(e);
663
+ this.events = undefined;
248
664
  }
249
- },
250
- async _addEvent(e) {
251
- const detail = e?.detail?.value || {};
252
- await this.$pdp.showMeeting(detail);
253
- },
254
- })
255
-
256
- ODA({
257
- is: 'oda-calendar-event',
258
- template: /*html*/`
259
- <style>
260
- :host {
261
- display: block;
262
- box-sizing: border-box;
263
- @apply --accent-invert;
264
- padding: 2px 4px;
265
- border-radius: var(--radius-s);
266
- font-size: small;
267
- overflow: hidden;
268
- cursor: pointer;
269
- }
270
- :host(:hover) {
271
- @apply --hover;
272
- }
273
- :host([block]) {
274
- position: absolute;
275
- z-index: 1;
276
- /* цвет рамки задаёт роль accent-invert */
277
- border: 1px solid;
278
- pointer-events: auto;
279
- }
280
- :host([badge]) {
281
- font-size: xx-small;
282
- margin: 2px 0;
283
- }
284
- .row {
285
- align-items: center;
286
- gap: 8px;
287
- min-width: 0;
288
- }
289
- .interval {
290
- white-space: nowrap;
291
- opacity: .8;
292
- font-size: xx-small;
293
- }
294
- .summary {
295
- @apply --bold;
296
- overflow: hidden;
297
- text-overflow: ellipsis;
298
- white-space: nowrap;
299
- min-width: 0;
300
- }
301
- </style>
302
- <div horizontal class="row">
303
- <div class="interval">{{interval}}</div>
304
- <div class="summary">{{summary}}</div>
305
- </div>
306
- `,
307
- data: null,
308
- $item: null,
309
- get interval() {
310
- return eventInterval(this.data);
311
- },
312
- get summary() {
313
- return this.data?.summary ?? '';
314
- },
315
- $listeners: {
316
- tap(e) {
317
- e.stopPropagation();
318
- this.$pdp.showMeeting(this.$item);
665
+ catch (err) {
666
+ ODA.showMessage?.(err?.message || String(err));
319
667
  }
320
- }
321
- })
668
+ },
669
+ };
322
670
 
323
671
  ODA({
324
672
  is: 'oda-calendar-time-grid',
325
- template: /*html*/`
673
+ imports: 'oda//icon',
674
+ template: /* html */`
326
675
  <style>
327
676
  :host {
328
677
  @apply --vertical;
329
678
  @apply --flex;
330
679
  overflow: auto;
680
+ position: relative;
681
+ user-select: none;
331
682
  }
332
- .time-grid {
333
- display: grid;
334
- gap: 1px;
335
- background: var(--subtle-border);
336
- border-bottom: 1px solid var(--subtle-border);
337
- color: var(--dark-color);
683
+ .sticky-top {
338
684
  position: sticky;
339
685
  top: 0;
340
- z-index: 3;
686
+ z-index: 5;
687
+ background: var(--content-background, #ffffff);
688
+ border-bottom: 1px solid var(--subtle-border, #e2e8f0);
341
689
  flex-shrink: 0;
342
690
  }
343
- .time-header {
344
- @apply --header;
345
- padding: 8px;
346
- position: sticky;
347
- left: 0;
348
- z-index: 1;
691
+ .grid-row {
692
+ display: grid;
693
+ grid-template-columns: 56px repeat(var(--cols, 7), minmax(0, 1fr));
694
+ }
695
+ .time-corner {
696
+ border-right: 1px solid var(--subtle-border, #e2e8f0);
697
+ font-size: 11px;
698
+ color: var(--muted-color);
699
+ display: flex;
700
+ align-items: flex-end;
701
+ justify-content: flex-end;
702
+ padding: 4px 6px;
349
703
  }
350
- .day-header {
351
- @apply --header;
352
- padding: 0;
353
- font-weight: normal;
704
+ .day-head {
705
+ display: flex;
706
+ flex-direction: column;
707
+ border-right: 1px solid var(--subtle-border, #e2e8f0);
354
708
  min-width: 0;
355
- height: 100%;
356
- box-sizing: border-box;
357
709
  }
358
- .day-header[today] {
359
- @apply --info;
710
+ .day-head:last-child { border-right: none; }
711
+ .day-label {
712
+ display: flex;
713
+ align-items: center;
714
+ justify-content: center;
715
+ gap: 6px;
716
+ padding: 8px 4px 6px;
717
+ font-size: 12.5px;
718
+ font-weight: 600;
719
+ }
720
+ .day-num {
721
+ width: 26px;
722
+ height: 26px;
723
+ border-radius: 50%;
724
+ display: inline-flex;
725
+ align-items: center;
726
+ justify-content: center;
727
+ font-weight: 700;
360
728
  }
361
- .day-title {
362
- padding: 8px;
363
- align-items: baseline;
364
- gap: 8px;
365
- min-width: 0;
729
+ .day-head[today] .day-num {
730
+ background: var(--accent-color, #2563eb);
731
+ color: #ffffff;
366
732
  }
367
- .day-name {
368
- text-align: center;
733
+ .day-head[today] .day-name {
734
+ color: var(--accent-color, #2563eb);
369
735
  }
370
- .all-day {
371
- @apply --flex;
372
- min-height: 32px;
373
- cursor: pointer;
374
- border-top: 1px solid var(--subtle-border);
736
+ .all-day-cell {
737
+ min-height: 26px;
375
738
  padding: 2px 4px;
376
- box-sizing: border-box;
377
- }
378
- .all-day:hover {
379
- background: var(--subtle-background);
739
+ border-top: 1px solid var(--subtle-border, #e2e8f0);
740
+ display: flex;
741
+ flex-direction: column;
742
+ gap: 2px;
743
+ cursor: pointer;
744
+ background: var(--subtle-background, #f8fafc);
745
+ }
746
+ .all-day-chip {
747
+ font-size: 11px;
748
+ font-weight: 600;
749
+ padding: 2px 6px;
750
+ border-radius: 4px;
751
+ border-left: 3px solid;
752
+ overflow: hidden;
753
+ text-overflow: ellipsis;
754
+ white-space: nowrap;
755
+ cursor: pointer;
380
756
  }
381
- .time-body {
757
+ .body-grid {
382
758
  display: grid;
759
+ grid-template-columns: 56px repeat(var(--cols, 7), minmax(0, 1fr));
383
760
  position: relative;
761
+ flex: 1 0 auto;
384
762
  }
385
- .time-col {
386
- @apply --content;
387
- position: sticky;
388
- left: 0;
389
- z-index: 2;
763
+ .hours-col {
764
+ border-right: 1px solid var(--subtle-border, #e2e8f0);
765
+ background: var(--content-background, #ffffff);
390
766
  }
391
- .slot-label {
392
- height: 32px;
767
+ .hour-mark {
768
+ height: 56px;
393
769
  box-sizing: border-box;
394
- border-top: 1px dotted var(--subtle-border);
395
- font-size: 10px;
396
- align-items: center;
397
- justify-content: flex-end;
398
- padding-right: 4px;
399
- gap: 4px;
770
+ padding: 2px 6px 0 0;
771
+ text-align: right;
772
+ font-size: 11px;
773
+ color: var(--muted-color, #64748b);
774
+ border-top: 1px solid transparent;
400
775
  }
401
- .slot-label[hour-start] {
402
- border-top: 1px solid var(--subtle-border);
776
+ .day-col {
777
+ position: relative;
778
+ border-right: 1px solid var(--subtle-border, #e2e8f0);
779
+ height: 1344px;
403
780
  }
404
- .slot-label:first-of-type {
405
- border-top: none;
781
+ .day-col:last-child { border-right: none; }
782
+ .day-col[today] {
783
+ background: color-mix(in srgb, var(--accent-color, #2563eb) 3%, transparent);
406
784
  }
407
- .hour-label {
408
- font-size: 12px;
409
- text-align: center;
785
+ .half-slot {
786
+ height: 28px;
787
+ box-sizing: border-box;
788
+ cursor: pointer;
789
+ border-top: 1px dotted var(--subtle-border, #e2e8f0);
410
790
  }
411
- .minute-label {
412
- width: 14px;
413
- text-align: right;
414
- overflow: hidden;
791
+ .half-slot.hour-start {
792
+ border-top: 1px solid var(--subtle-border, #e2e8f0);
415
793
  }
416
- .day-col {
417
- @apply --content;
418
- position: relative;
419
- min-width: 0;
420
- overflow: hidden;
794
+ .half-slot:first-child { border-top: none; }
795
+ .half-slot:hover {
796
+ background: color-mix(in srgb, var(--accent-color, #2563eb) 7%, transparent);
421
797
  }
422
- .slot {
423
- height: 32px;
798
+ .ev-card {
799
+ position: absolute;
424
800
  box-sizing: border-box;
801
+ padding: 3px 6px 6px;
802
+ border-radius: 6px;
803
+ border-left: 3px solid;
804
+ box-shadow: 0 1px 2px rgba(0, 0, 0, 0.08);
805
+ font-size: 11.5px;
806
+ overflow: hidden;
425
807
  cursor: pointer;
426
- border-top: 1px dotted var(--subtle-border);
427
- border-left: 1px solid var(--subtle-border);
808
+ z-index: 2;
809
+ transition: box-shadow 0.12s ease;
428
810
  }
429
- .slot:first-child {
430
- border-top: none;
811
+ .ev-card:hover {
812
+ z-index: 4;
813
+ box-shadow: 0 3px 10px rgba(0, 0, 0, 0.16);
431
814
  }
432
- .slot[hour-start] {
433
- border-top: 1px solid var(--subtle-border);
815
+ .ev-title {
816
+ font-weight: 700;
817
+ line-height: 1.2;
818
+ overflow: hidden;
819
+ text-overflow: ellipsis;
820
+ white-space: nowrap;
434
821
  }
435
- .slot[hour-start]:first-child {
436
- border-top: none;
822
+ .ev-meta {
823
+ font-size: 10.5px;
824
+ opacity: 0.85;
825
+ overflow: hidden;
826
+ text-overflow: ellipsis;
827
+ white-space: nowrap;
437
828
  }
438
- .day-col > .slot:first-of-type {
439
- border-top: none;
829
+ .ev-resize {
830
+ position: absolute;
831
+ left: 0;
832
+ right: 0;
833
+ bottom: 0;
834
+ height: 6px;
835
+ cursor: ns-resize;
440
836
  }
441
- .slot:hover {
442
- background: var(--subtle-background);
837
+ .now-line {
838
+ position: absolute;
839
+ left: 0;
840
+ right: 0;
841
+ height: 2px;
842
+ background: #dc2626;
843
+ z-index: 3;
844
+ pointer-events: none;
845
+ }
846
+ .now-line::before {
847
+ content: '';
848
+ position: absolute;
849
+ left: -4px;
850
+ top: -3px;
851
+ width: 8px;
852
+ height: 8px;
853
+ border-radius: 50%;
854
+ background: #dc2626;
443
855
  }
444
856
  </style>
445
- <div class="time-grid" style="border-top: 1px solid var(--subtle-border);" ~style="gridStyle">
446
- <div class="time-header"></div>
447
- <div ~for="columns" class="day-header" vertical :today="$for.item.isToday">
448
- <div horizontal class="day-title">
449
- <div>{{$for.item.day}}</div>
450
- <div class="day-name flex">{{$for.item.dayName}}</div>
451
- </div>
452
- <div class="all-day" vertical @tap="selectAllDay($for.item)">
453
- <oda-calendar-event badge ~for="$for.item.allDayBlocks" :data="$for.$for.item" :title="$for.$for.item.title" :$item="$for.$for.item.$item"></oda-calendar-event>
857
+
858
+ <div class="sticky-top">
859
+ <div class="grid-row" ~style="colsStyle">
860
+ <div class="time-corner">Весь день</div>
861
+ <div ~for="columns" class="day-head" :today="$for.item.isToday">
862
+ <div class="day-label">
863
+ <span class="day-name">{{$for.item.dayName}}</span>
864
+ <span class="day-num">{{$for.item.dayNum}}</span>
865
+ </div>
866
+ <div class="all-day-cell" @tap="onAllDayTap($for.item)">
867
+ <div ~for="$for.item.allDayEvents" class="all-day-chip"
868
+ :style="cardStyle($for.item)"
869
+ @tap.stop="openEv($for.item)">
870
+ {{$for.item.summary || 'Событие'}}
871
+ </div>
872
+ </div>
454
873
  </div>
455
874
  </div>
456
875
  </div>
457
- <div class="time-body" ~style="gridStyle">
458
- <div vertical class="time-col">
459
- <div ~for="hourSlots" class="slot-label" horizontal :hour-start="$for.item.isHourStart">
460
- <span class="hour-label">{{$for.item.hourLabel}}</span>
461
- <span class="minute-label" disabled>{{$for.item.minuteLabel}}</span>
462
- </div>
876
+
877
+ <div class="body-grid" ~style="colsStyle">
878
+ <div class="hours-col">
879
+ <div ~for="hours" class="hour-mark">{{$for.item}}</div>
463
880
  </div>
464
- <div ~for="columns" class="day-col" vertical>
465
- <div ~for="hourSlots" class="slot" :hour-start="$for.$for.item.isHourStart"
466
- @tap="selectSlot($for.item, $for.$for.item)"></div>
467
- <oda-calendar-event block ~for="$for.item.blocks" :data="$for.$for.item" ~style="$for.$for.item.style" :title="$for.$for.item.title" :$item="$for.$for.item.$item"></oda-calendar-event>
881
+ <div ~for="columns" class="day-col" :today="$for.item.isToday"
882
+ @dragover.prevent="onDragOver($event)"
883
+ @drop.prevent="onDrop($event, $for.item)">
884
+ <div ~for="halfSlots" class="half-slot" ~class="{ 'hour-start': $for.item.isHour }"
885
+ @tap="onSlotTap($for.$for.item, $for.item)"></div>
886
+
887
+ <div ~if="$for.item.isToday && nowTop >= 0" class="now-line" :style="'top:' + nowTop + 'px;'"></div>
888
+
889
+ <div ~for="$for.item.timedEvents" class="ev-card"
890
+ :draggable="$for.item.kind === 'event'"
891
+ :style="timedCardStyle($for.item)"
892
+ @dragstart="onDragStart($event, $for.item)"
893
+ @tap.stop="openEv($for.item)">
894
+ <div class="ev-title">{{$for.item.summary || 'Событие'}}</div>
895
+ <div class="ev-meta">{{$for.item.timeLabel}}{{$for.item.location ? ' · ' + $for.item.location : ''}}</div>
896
+ <div ~if="$for.item.kind === 'event'" class="ev-resize" @pointerdown.stop="startResize($event, $for.item)"></div>
897
+ </div>
468
898
  </div>
469
899
  </div>
470
900
  `,
471
- interval: 30,
472
- currentDate: {
473
- $def: null,
474
- set(n) {
475
- this.gridDays = undefined;
476
- this.columns = undefined;
477
- this.gridStyle = undefined;
478
- }
901
+ events: [],
902
+ currentDate: null,
903
+ viewMode: 'week',
904
+ nowTop: -1,
905
+ _scrolledOnce: false,
906
+ _dragEv: null,
907
+ attached() {
908
+ this._updateNowLine();
909
+ this._nowTimer = setInterval(() => this._updateNowLine(), 60_000);
910
+ requestAnimationFrame(() => {
911
+ if (!this._scrolledOnce) {
912
+ this._scrolledOnce = true;
913
+ this.scrollTop = 8 * HOUR_HEIGHT;
914
+ }
915
+ });
479
916
  },
480
- viewMode: {
481
- $def: 'day',
482
- set(n) {
483
- this.gridDays = undefined;
484
- this.columns = undefined;
485
- this.gridStyle = undefined;
486
- }
917
+ detached() {
918
+ clearInterval(this._nowTimer);
487
919
  },
488
- events: [],
489
- get gridStyle() {
490
- const n = this.columns?.length || 1;
491
- return { gridTemplateColumns: `48px repeat(${n}, 1fr)` };
920
+ _updateNowLine() {
921
+ const d = new Date();
922
+ this.nowTop = ((d.getHours() * 60 + d.getMinutes()) / 60) * HOUR_HEIGHT;
492
923
  },
493
- get hourSlots() {
494
- const interval = this.interval;
495
- const perHour = 60 / interval;
496
- const slots = [];
497
- for (let h = 0; h < 24; h++) {
498
- for (let i = 0; i < perHour; i++) {
499
- slots.push({
500
- hour: h,
501
- intervalIdx: i,
502
- hourLabel: i === 0 ? String(h).padStart(2, '0') : '',
503
- minuteLabel: String(interval * i).padStart(2, '0'),
504
- isHourStart: i === 0
505
- });
506
- }
507
- }
508
- return slots;
924
+ get hours() {
925
+ const out = [];
926
+ for (let h = 0; h < 24; h++)
927
+ out.push(String(h).padStart(2, '0') + ':00');
928
+ return out;
509
929
  },
510
- get gridDays() {
511
- const date = _asDate(this.currentDate);
512
- const mode = this.viewMode;
513
- const today = new Date();
514
- today.setHours(0, 0, 0, 0);
515
- const toDay = (d) => {
516
- const check = new Date(d.getFullYear(), d.getMonth(), d.getDate());
517
- return {
518
- day: d.getDate(),
519
- dayName: dayNames[d.getDay()],
520
- fullDate: d,
521
- isToday: check.getTime() === today.getTime()
522
- };
523
- };
524
- if (mode === 'day')
525
- return [toDay(new Date(date.getFullYear(), date.getMonth(), date.getDate()))];
526
- const start = _weekStart(date);
527
- const count = mode === 'workweek' ? 5 : 7;
528
- const days = [];
930
+ get halfSlots() {
931
+ const out = [];
932
+ for (let i = 0; i < 48; i++)
933
+ out.push({ idx: i, isHour: i % 2 === 0 });
934
+ return out;
935
+ },
936
+ get columns() {
937
+ const cur = _asDate(this.currentDate);
938
+ const todayStr = _formatDate(new Date());
939
+ const count = this.viewMode === 'day' ? 1 : this.viewMode === 'workweek' ? 5 : 7;
940
+ const start = this.viewMode === 'day' ? new Date(cur.getFullYear(), cur.getMonth(), cur.getDate()) : _weekStart(cur);
941
+ const list = Array.isArray(this.events) ? this.events : [];
942
+ const cols = [];
529
943
  for (let i = 0; i < count; i++) {
530
944
  const d = new Date(start.getFullYear(), start.getMonth(), start.getDate() + i);
531
- days.push(toDay(d));
945
+ const ds = _formatDate(d);
946
+ const dayStartMs = d.getTime();
947
+ const dayEndMs = dayStartMs + 86400_000;
948
+ const dayEvents = list.filter(ev => {
949
+ const s = Date.parse(ev.start);
950
+ const e = Date.parse(ev.end);
951
+ return Number.isFinite(s) && Number.isFinite(e) && e > dayStartMs && s < dayEndMs;
952
+ });
953
+ cols.push({
954
+ dateStr: ds,
955
+ fullDate: d,
956
+ dayNum: d.getDate(),
957
+ dayName: d.toLocaleDateString('ru-RU', { weekday: 'short' }),
958
+ isToday: ds === todayStr,
959
+ allDayEvents: dayEvents.filter(ev => ev.allDay),
960
+ timedEvents: _layoutDayEvents(dayEvents, d),
961
+ });
532
962
  }
533
- return days;
534
- },
535
- get columns() {
536
- const days = this.gridDays;
537
- const events = this.events;
538
- const list = (!events || events.then) ? [] : events;
539
- return days.map(day => ({
540
- ...day,
541
- allDayBlocks: _allDayEvents(list, day.fullDate),
542
- blocks: _layoutDayEvents(list, day.fullDate)
543
- }));
963
+ return cols;
544
964
  },
545
- selectSlot(column, slot) {
546
- const start = new Date(column.fullDate);
547
- start.setHours(slot.hour, this.interval * slot.intervalIdx, 0, 0);
548
- const end = new Date(start.getTime() + this.interval * 60 * 1000);
549
- this.fire('add-event', { start, end });
965
+ get colsStyle() {
966
+ return `--cols: ${this.columns.length};`;
550
967
  },
551
- selectAllDay(column) {
552
- const start = new Date(column.fullDate);
553
- start.setHours(0, 0, 0, 0);
554
- const end = new Date(start);
555
- end.setDate(end.getDate() + 1);
556
- this.fire('add-event', { start, end, allDay: true });
557
- }
558
- })
559
-
560
- ODA({
561
- is: 'oda-calendar-month-view',
562
- template: /*html*/`
563
- <style>
564
- :host {
565
- @apply --vertical;
566
- overflow: auto;
567
- }
568
- .calendar-grid {
569
- display: grid;
570
- grid-template-columns: auto repeat(7, 1fr);
571
- gap: 1px;
572
- background: var(--subtle-border);
573
- border: 1px solid var(--subtle-border);
574
- }
575
- .weekday-header {
576
- @apply --header;
577
- padding: 8px;
578
- text-align: center;
579
- font-weight: normal;
580
- font-size: small;
581
- }
582
- </style>
583
- <div class="calendar-grid">
584
- <div class="weekday-header"></div>
585
- <div ~for="weekdays" class="weekday-header">{{$for.item}}</div>
586
- <oda-calendar-month-week ~for="weeks" :item="$for.item"></oda-calendar-month-week>
587
- </div>
588
- `,
589
- currentDate: null,
590
- events: [],
591
- weekdays: ['Пн', 'Вт', 'Ср', 'Чт', 'Пт', 'Сб', 'Вс'],
592
- get dayFrom() {
593
- const date = _asDate(this.currentDate);
594
- return _formatDate(_weekStart(new Date(date.getFullYear(), date.getMonth(), 1)));
968
+ cardStyle(ev) {
969
+ const c = _eventStyleVars(ev);
970
+ return `background:${c.bg};border-left-color:${c.border};color:${c.text};`;
595
971
  },
596
- get dayTo() {
597
- const date = _asDate(this.currentDate);
598
- return _formatDate(_weekEnd(new Date(date.getFullYear(), date.getMonth() + 1, 0)));
972
+ timedCardStyle(ev) {
973
+ const c = _eventStyleVars(ev);
974
+ return `top:${ev.top}px;height:${ev.height}px;left:calc(${ev.leftPct}% + 2px);width:calc(${ev.widthPct}% - 4px);background:${c.bg};border-left-color:${c.border};color:${c.text};`;
599
975
  },
600
- get calendarDays() {
601
- const from = this.dayFrom;
602
- const to = this.dayTo;
603
- if (!from || !to)
604
- return [];
605
- const month = _asDate(this.currentDate).getMonth();
606
- const today = new Date();
607
- today.setHours(0, 0, 0, 0);
608
- const days = [];
609
- const cur = _parseDay(from);
610
- const end = _parseDay(to);
611
- while (cur <= end) {
612
- const date = new Date(cur.getFullYear(), cur.getMonth(), cur.getDate());
613
- days.push({
614
- day: date.getDate(),
615
- date,
616
- otherMonth: date.getMonth() !== month,
617
- isToday: date.getTime() === today.getTime(),
618
- events: this.getEventsForDay(date)
619
- });
620
- cur.setDate(cur.getDate() + 1);
621
- }
622
- return days;
976
+ onAllDayTap(col) {
977
+ const s = new Date(col.fullDate);
978
+ s.setHours(0, 0, 0, 0);
979
+ const e = new Date(s);
980
+ e.setDate(e.getDate() + 1);
981
+ this.fire('add-event', { start: s, end: e, allDay: true });
623
982
  },
624
- get weeks() {
625
- const days = this.calendarDays;
626
- const weeks = [];
627
- for (let i = 0; i < days.length; i += 7) {
628
- const row = days.slice(i, i + 7);
629
- weeks.push({
630
- label: _weekRangeLabel(row[0].date, row[row.length - 1].date),
631
- days: row
632
- });
633
- }
634
- return weeks;
983
+ onSlotTap(col, slot) {
984
+ const s = new Date(col.fullDate);
985
+ const h = Math.floor(slot.idx / 2);
986
+ const m = (slot.idx % 2) * 30;
987
+ s.setHours(h, m, 0, 0);
988
+ const e = new Date(s.getTime() + 60 * 60_000);
989
+ this.fire('add-event', { start: s, end: e, allDay: false });
635
990
  },
636
- getEventsForDay(date) {
637
- const events = this.events;
638
- if (!events?.length || events.then)
639
- return [];
640
- const dayStart = new Date(date.getFullYear(), date.getMonth(), date.getDate()).getTime();
641
- const next = new Date(date.getFullYear(), date.getMonth(), date.getDate() + 1).getTime();
642
- return events.filter(event => {
643
- const start = new Date(event.start).getTime();
644
- const end = new Date(event.end).getTime();
645
- return !isNaN(start) && !isNaN(end) && end > dayStart && start < next;
646
- }).map(event => ({ ...event, title: eventTitle(event) }));
991
+ openEv(ev) {
992
+ this.fire('open-event', ev);
647
993
  },
648
- selectMonthDay(date) {
649
- const start = new Date(date);
650
- start.setHours(0, 0, 0, 0);
651
- const end = new Date(start);
652
- end.setDate(end.getDate() + 1);
653
- this.fire('add-event', { start, end, allDay: true });
654
- }
655
- })
656
-
657
- ODA({
658
- is: 'oda-calendar-month-week',
659
- template: /*html*/`
660
- <style>
661
- :host {
662
- display: contents;
663
- }
664
- .week-label {
665
- @apply --content;
666
- writing-mode: vertical-rl;
667
- transform: rotate(180deg);
668
- text-align: center;
669
- font-size: small;
670
- white-space: nowrap;
671
- }
672
- oda-calendar-month-day:hover {
673
- background: var(--subtle-background);
674
- }
675
- oda-calendar-month-day[today] {
676
- @apply --info;
677
- }
678
- oda-calendar-month-day[today]:hover {
679
- @apply --hover;
680
- }
681
- </style>
682
- <div class="week-label">{{item?.label}}</div>
683
- <oda-calendar-month-day ~for="item?.days" :item="$for.item" :date="$for.item.date" :other-month="$for.item.otherMonth" :today="$for.item.isToday"></oda-calendar-month-day>
684
- `,
685
- item: null,
686
- })
687
-
688
- ODA({
689
- is: 'oda-calendar-month-day',
690
- template: /*html*/`
691
- <style>
692
- :host {
693
- @apply --content;
694
- min-height: 100px;
695
- padding: 4px;
696
- position: relative;
697
- cursor: pointer;
698
- overflow: hidden;
699
- }
700
- .day-number {
701
- font-weight: normal;
702
- margin-bottom: 4px;
703
- }
704
- /* дни соседнего месяца: ослабляем только номер, встречи остаются яркими */
705
- :host([other-month]) .day-number {
706
- opacity: .5;
707
- }
708
- </style>
709
- <div class="day-number">{{item?.day}}</div>
710
- <oda-calendar-event badge ~for="item?.events" :data="$for.item" :title="$for.item.title" :$item="$for.item.$item"></oda-calendar-event>
711
- `,
712
- item: null,
713
- date: null,
714
- $listeners: {
715
- tap(e) {
716
- this.$pdp.selectMonthDay(this.date)
994
+ onDragStart(e, ev) {
995
+ if (ev.kind !== 'event') {
996
+ e.preventDefault();
997
+ return;
717
998
  }
718
- }
719
- })
720
-
721
- ODA({
722
- is: 'oda-form-calendar-list-view',
723
- template: /*html*/`
724
- <oda-log-group ~for="groups" :item="$for.item" vertical flex>
725
- </oda-log-group>
726
- `,
727
- events: [],
728
- _collapsed: {},
729
- _toggleGroup(dateKey) {
730
- this._collapsed = { ...this._collapsed, [dateKey]: !this._collapsed[dateKey] };
999
+ this._dragEv = ev;
1000
+ e.dataTransfer?.setData('text/plain', ev.uid || 'event');
731
1001
  },
732
- get groups() {
733
- const events = this.events;
734
- if (!events || events.then)
735
- return [];
736
- const map = new Map();
737
- for (const ev of events) {
738
- const key = _formatDate(_asDate(ev.start));
739
- let group = map.get(key);
740
- if (!group) {
741
- group = { dateKey: key, label: _dateGroupLabel(ev.start), events: [] };
742
- map.set(key, group);
743
- }
744
- group.events.push(ev);
745
- }
746
- const result = [...map.values()];
747
- result.sort((a, b) => a.dateKey.localeCompare(b.dateKey));
748
- const collapsed = this._collapsed;
749
- for (const g of result)
750
- g.collapsed = !!collapsed[g.dateKey];
751
- return result;
1002
+ onDragOver(e) {
1003
+ if (this._dragEv)
1004
+ e.preventDefault();
752
1005
  },
753
- open($item) {
754
- this.$pdp.showMeeting($item);
1006
+ onDrop(e, col) {
1007
+ const ev = this._dragEv;
1008
+ this._dragEv = null;
1009
+ if (!ev) return;
1010
+ const rect = e.currentTarget.getBoundingClientRect();
1011
+ const y = Math.max(0, e.clientY - rect.top);
1012
+ const halfIdx = Math.min(47, Math.floor(y / HALF_HEIGHT));
1013
+ const durMs = Math.max(30 * 60_000, Date.parse(ev.end) - Date.parse(ev.start));
1014
+ const nextStart = new Date(col.fullDate);
1015
+ nextStart.setHours(Math.floor(halfIdx / 2), (halfIdx % 2) * 30, 0, 0);
1016
+ const nextEnd = new Date(nextStart.getTime() + durMs);
1017
+ this.fire('move-event', {
1018
+ ev,
1019
+ start: nextStart.toISOTimezoneString(),
1020
+ end: nextEnd.toISOTimezoneString(),
1021
+ });
755
1022
  },
756
- })
757
-
758
- ODA({is: 'oda-log-group',
759
- template: /*html*/`
760
- <style>
761
- .group-header {
762
- padding: 4px 8px;
763
- align-items: center;
764
- gap: 6px;
765
- cursor: pointer;
766
- user-select: none;
767
- border-top: 1px solid var(--subtle-border);
768
- }
769
- .group-header:first-child {
770
- border-top: none;
771
- }
772
- .group-header:hover {
773
- background: var(--subtle-background);
774
- }
775
- .group-label {
776
- @apply --bold;
777
- }
778
- .group-count {
779
- opacity: .5;
780
- font-size: small;
781
- }
782
- .group-items {
783
- padding-left: 8px;
784
- }
785
- oda-log-view:hover {
786
- background: var(--subtle-background);
787
- }
788
- </style>
789
- <div horizontal class="group-header" @tap="$pdp._toggleGroup(item.dateKey)">
790
- <oda-button :icon="item.collapsed ? 'icons:chevron-right' : 'icons:chevron-right:90'" icon-size="16" no-padding></oda-button>
791
- <span class="group-label">{{item.label}}</span>
792
- <span class="group-count">{{item.events.length}}</span>
793
- </div>
794
- <div ~if="!item.collapsed" class="group-items" vertical flex>
795
- <oda-log-view ~for="item.events" :data="$for.item" @tap.stop="$pdp.open($for.item.$item)"></oda-log-view>
796
- </div>
797
- `,
798
- item: null,
799
- })
1023
+ startResize(e, ev) {
1024
+ e.preventDefault();
1025
+ const startY = e.clientY;
1026
+ const origStartMs = Date.parse(ev.start);
1027
+ const origEndMs = Date.parse(ev.end);
1028
+ const onMove = (mv) => {
1029
+ const dy = mv.clientY - startY;
1030
+ const deltaMin = Math.round((dy / HOUR_HEIGHT) * 60 / 15) * 15;
1031
+ const nextEndMs = Math.max(origStartMs + 30 * 60_000, origEndMs + deltaMin * 60_000);
1032
+ const card = e.target.closest('.ev-card');
1033
+ if (card)
1034
+ card.style.height = Math.max(20, ((nextEndMs - origStartMs) / 3600_000) * HOUR_HEIGHT - 2) + 'px';
1035
+ };
1036
+ const onUp = (up) => {
1037
+ window.removeEventListener('pointermove', onMove);
1038
+ window.removeEventListener('pointerup', onUp);
1039
+ const dy = up.clientY - startY;
1040
+ const deltaMin = Math.round((dy / HOUR_HEIGHT) * 60 / 15) * 15;
1041
+ if (!deltaMin) return;
1042
+ const nextEndMs = Math.max(origStartMs + 30 * 60_000, origEndMs + deltaMin * 60_000);
1043
+ this.fire('move-event', {
1044
+ ev,
1045
+ start: new Date(origStartMs).toISOTimezoneString(),
1046
+ end: new Date(nextEndMs).toISOTimezoneString(),
1047
+ });
1048
+ };
1049
+ window.addEventListener('pointermove', onMove);
1050
+ window.addEventListener('pointerup', onUp);
1051
+ },
1052
+ });
800
1053
 
801
1054
  ODA({
802
- is: 'oda-log-view',
803
- template: /*html*/`
1055
+ is: 'oda-calendar-month-view',
1056
+ template: /* html */`
804
1057
  <style>
805
1058
  :host {
806
1059
  @apply --vertical;
807
1060
  @apply --flex;
808
- min-width: 0;
809
- padding: 4px 8px;
810
- gap: 4px;
811
- cursor: pointer;
812
- }
813
- .row1 {
814
- align-items: baseline;
815
- gap: 8px;
1061
+ overflow: auto;
1062
+ padding: 8px 12px 12px;
816
1063
  }
817
- .interval {
818
- white-space: nowrap;
819
- font-size: small;
820
- opacity: .8;
1064
+ .month-grid {
1065
+ display: grid;
1066
+ grid-template-columns: repeat(7, minmax(0, 1fr));
1067
+ grid-auto-rows: minmax(105px, 1fr);
1068
+ gap: 1px;
1069
+ background: var(--subtle-border, #e2e8f0);
1070
+ border: 1px solid var(--subtle-border, #e2e8f0);
1071
+ border-radius: 8px;
1072
+ overflow: hidden;
1073
+ flex: 1 0 auto;
821
1074
  }
822
- .summary {
823
- text-align: left;
824
- justify-content: flex-start;
1075
+ .wday-head {
1076
+ background: var(--subtle-background, #f8fafc);
1077
+ padding: 6px 8px;
1078
+ text-align: center;
1079
+ font-size: 12px;
1080
+ font-weight: 600;
1081
+ color: var(--muted-color, #64748b);
1082
+ min-height: auto;
1083
+ grid-row: auto;
825
1084
  }
826
- .location {
827
- font-size: small;
1085
+ .month-head-row {
1086
+ display: grid;
1087
+ grid-template-columns: repeat(7, minmax(0, 1fr));
1088
+ gap: 1px;
1089
+ background: var(--subtle-border, #e2e8f0);
1090
+ border: 1px solid var(--subtle-border, #e2e8f0);
1091
+ border-bottom: none;
1092
+ border-radius: 8px 8px 0 0;
828
1093
  overflow: hidden;
829
- text-overflow: ellipsis;
830
- white-space: nowrap;
831
- text-align: left;
832
- justify-content: flex-start;
833
- }
834
- </style>
835
- <div class="row1" horizontal>
836
- <span class="interval">{{interval}}</span>
837
- <span class="summary" flex bold>{{summary}}</span>
838
- </div>
839
- <div class="location">{{location}}</div>
840
- `,
841
- data: null,
842
- get event() {
843
- return this.data;
844
- },
845
- get interval() {
846
- return eventInterval(this.event);
847
- },
848
- get summary() {
849
- return this.event?.summary ?? '';
850
- },
851
- get location() {
852
- return this.event?.location ?? '';
853
- }
854
- })
855
-
856
- ODA({
857
- is: 'oda-date-nav',
858
- template: /*html*/`
859
- <style>
860
- :host {
861
- @apply --horizontal;
862
- @apply --flex;
863
1094
  }
864
- .date-picker {
865
- position: relative;
1095
+ .day-cell {
1096
+ background: var(--content-background, #ffffff);
1097
+ padding: 6px;
1098
+ display: flex;
1099
+ flex-direction: column;
1100
+ gap: 3px;
866
1101
  cursor: pointer;
867
- border-radius: var(--radius-s);
868
- padding: 4px 8px;
869
- align-content: center;
1102
+ min-width: 0;
1103
+ }
1104
+ .day-cell:hover { background: var(--subtle-background, #f8fafc); }
1105
+ .day-cell.other { opacity: 0.48; }
1106
+ .cell-num {
1107
+ width: 24px;
1108
+ height: 24px;
1109
+ border-radius: 50%;
1110
+ display: inline-flex;
1111
+ align-items: center;
1112
+ justify-content: center;
1113
+ font-size: 12.5px;
1114
+ font-weight: 600;
1115
+ align-self: flex-end;
1116
+ }
1117
+ .day-cell.today .cell-num {
1118
+ background: var(--accent-color, #2563eb);
1119
+ color: #ffffff;
1120
+ }
1121
+ .chip {
1122
+ font-size: 11px;
1123
+ padding: 2px 5px;
1124
+ border-radius: 4px;
1125
+ border-left: 3px solid;
1126
+ overflow: hidden;
1127
+ text-overflow: ellipsis;
870
1128
  white-space: nowrap;
1129
+ font-weight: 500;
871
1130
  }
872
- .date-picker input {
873
- position: absolute;
874
- inset: 0;
875
- opacity: 0;
876
- pointer-events: none;
877
- width: 100%;
878
- height: 100%;
1131
+ .more {
1132
+ font-size: 11px;
1133
+ color: var(--muted-color);
1134
+ padding-left: 4px;
879
1135
  }
880
1136
  </style>
881
- <oda-button icon="icons:chevron-left" title="Назад" @tap="prevPeriod"></oda-button>
882
- <oda-button icon="icons:today" title="Сегодня" @tap="goToday"></oda-button>
883
- <oda-button icon="icons:chevron-right" title="Вперёд" @tap="nextPeriod"></oda-button>
884
- <div class="date-picker info" title="Выберите дату" @tap="openPicker">{{periodLabel}}
885
- <input type="date" tabindex="-1" ::value="datePickerValue">
1137
+ <div class="month-head-row">
1138
+ <div ~for="weekdays" class="wday-head">{{$for.item}}</div>
1139
+ </div>
1140
+ <div class="month-grid" style="border-top-left-radius:0;border-top-right-radius:0;">
1141
+ <div ~for="days" class="day-cell" ~class="{ other: $for.item.otherMonth, today: $for.item.isToday }" @tap="selectDay($for.item.date)">
1142
+ <span class="cell-num">{{$for.item.day}}</span>
1143
+ <div ~for="$for.item.visibleChips" class="chip" :style="chipStyle($for.item)" @tap.stop="openEv($for.item)">
1144
+ {{$for.item.allDay ? '' : ($for.item.timeShort + ' ')}}{{$for.item.summary || 'Событие'}}
1145
+ </div>
1146
+ <div ~if="$for.item.extraCount > 0" class="more">+ ещё {{$for.item.extraCount}}</div>
1147
+ </div>
886
1148
  </div>
887
1149
  `,
888
- viewMode: {
889
- $def: 'day'
890
- },
891
1150
  currentDate: null,
892
- get datePickerValue() {
893
- return _formatDate(_asDate(this.currentDate));
894
- },
895
- set datePickerValue(value) {
896
- if (value)
897
- this.currentDate = _parseDay(value);
898
- },
899
- get periodLabel() {
900
- return _periodLabel(_asDate(this.currentDate), this.viewMode);
1151
+ events: [],
1152
+ weekdays: ['Пн', 'Вт', 'Ср', 'Чт', 'Пт', 'Сб', 'Вс'],
1153
+ get days() {
1154
+ const cur = _asDate(this.currentDate);
1155
+ const month = cur.getMonth();
1156
+ const start = _weekStart(new Date(cur.getFullYear(), month, 1));
1157
+ const end = _weekEnd(new Date(cur.getFullYear(), month + 1, 0));
1158
+ const todayStr = _formatDate(new Date());
1159
+ const list = Array.isArray(this.events) ? this.events : [];
1160
+ const out = [];
1161
+ for (let d = new Date(start); d <= end; d.setDate(d.getDate() + 1)) {
1162
+ const date = new Date(d.getFullYear(), d.getMonth(), d.getDate());
1163
+ const ds = _formatDate(date);
1164
+ const sMs = date.getTime();
1165
+ const eMs = sMs + 86400_000;
1166
+ const dayEvs = list.filter(ev => {
1167
+ const s = Date.parse(ev.start);
1168
+ const e = Date.parse(ev.end);
1169
+ return Number.isFinite(s) && Number.isFinite(e) && e > sMs && s < eMs;
1170
+ }).map(ev => ({ ...ev, timeShort: _formatTime(ev.start) }));
1171
+ out.push({
1172
+ day: date.getDate(),
1173
+ date,
1174
+ otherMonth: date.getMonth() !== month,
1175
+ isToday: ds === todayStr,
1176
+ visibleChips: dayEvs.slice(0, 4),
1177
+ extraCount: Math.max(0, dayEvs.length - 4),
1178
+ });
1179
+ }
1180
+ return out;
901
1181
  },
902
- openPicker() {
903
- const input = this.$('input');
904
- if (input.showPicker)
905
- input.showPicker();
906
- else
907
- input.click();
1182
+ chipStyle(ev) {
1183
+ const c = _eventStyleVars(ev);
1184
+ return `background:${c.bg};border-left-color:${c.border};color:${c.text};`;
908
1185
  },
909
- prevPeriod() {
910
- this.currentDate = _shiftDate(_asDate(this.currentDate), this.viewMode, -1);
1186
+ selectDay(date) {
1187
+ const s = new Date(date);
1188
+ s.setHours(0, 0, 0, 0);
1189
+ const e = new Date(s);
1190
+ e.setDate(e.getDate() + 1);
1191
+ this.fire('add-event', { start: s, end: e, allDay: true });
911
1192
  },
912
- nextPeriod() {
913
- this.currentDate = _shiftDate(_asDate(this.currentDate), this.viewMode, 1);
1193
+ openEv(ev) {
1194
+ this.fire('open-event', ev);
914
1195
  },
915
- goToday() {
916
- this.currentDate = new Date();
917
- }
918
- })
919
-
920
- const dayNames = ['Вс', 'Пн', 'Вт', 'Ср', 'Чт', 'Пт', 'Сб'];
921
- const monthsNames = ['янв', 'фев', 'мар', 'апр', 'мая', 'июн',
922
- 'июл', 'авг', 'сен', 'окт', 'ноя', 'дек'];
923
- const monthsFullNames = ['Январь', 'Февраль', 'Март', 'Апрель', 'Май', 'Июнь',
924
- 'Июль', 'Август', 'Сентябрь', 'Октябрь', 'Ноябрь', 'Декабрь'];
925
- const LABEL_ALL_DAY = 'весь день';
926
-
927
- /** Содержимое строки лога (message) → объект или null. */
928
- function _parseContent(content) {
929
- if (content && typeof content === 'object')
930
- return content;
931
- if (typeof content !== 'string' || !content)
932
- return null;
933
- try {
934
- const parsed = JSON.parse(content);
935
- return parsed && typeof parsed === 'object' ? parsed : null;
936
- }
937
- catch {
938
- return null;
939
- }
940
- }
941
-
942
- /** Ключ встречи: uid из JSON; для старых встреч без uid — имя файла из history-пути. */
943
- function meetingKey(row, content) {
944
- if (content?.uid)
945
- return String(content.uid);
946
- // старые встречи: ключ = имя файла; при первой правке он же пишется в uid
947
- try {
948
- return 'file:' + filenameFromHistoryPath(row?.path);
949
- }
950
- catch {
951
- return 'path:' + (row?.path || row?.logsFilePath || '');
952
- }
953
- }
954
-
955
- function _newUid() {
956
- if (globalThis.crypto?.randomUUID)
957
- return crypto.randomUUID();
958
- return Date.now().toString(36) + '-' + Math.random().toString(36).slice(2, 10);
959
- }
960
- const monthsRu = ['января', 'февраля', 'марта', 'апреля', 'мая', 'июня',
961
- 'июля', 'августа', 'сентября', 'октября', 'ноября', 'декабря'];
962
- const daysRu = ['вс', 'пн', 'вт', 'ср', 'чт', 'пт', 'сб'];
963
-
964
- function _weekRangeLabel(first, last) {
965
- const d1 = first.getDate();
966
- const d2 = last.getDate();
967
- const m2 = monthsNames[last.getMonth()];
968
- if (first.getMonth() === last.getMonth())
969
- return `${d1} - ${d2} ${m2}`;
970
- return `${d1} ${monthsNames[first.getMonth()]} - ${d2} ${m2}`;
971
- }
972
-
973
- function eventHhmm(iso) {
974
- const d = new Date(iso);
975
- if (isNaN(d))
976
- return '';
977
- const pad = n => String(n).padStart(2, '0');
978
- return `${pad(d.getHours())}:${pad(d.getMinutes())}`;
979
- }
980
-
981
- function eventInterval(ev) {
982
- if (ev?.allDay)
983
- return LABEL_ALL_DAY;
984
- if (!ev?.start || !ev?.end)
985
- return '';
986
- const a = eventHhmm(ev.start);
987
- const b = eventHhmm(ev.end);
988
- if (!a || !b)
989
- return '';
990
- return `${a} - ${b}`;
991
- }
992
-
993
- function eventTitle(ev) {
994
- const interval = eventInterval(ev);
995
- const summary = (ev?.summary ?? '').trim();
996
- const location = (ev?.location ?? '').trim();
997
- let line1 = interval;
998
- if (summary)
999
- line1 = interval ? `${interval} | ${summary}` : summary;
1000
- if (location)
1001
- return line1 ? `${line1}\n${location}` : location;
1002
- return line1;
1003
- }
1004
-
1005
- function filenameFromHistoryPath(path) {
1006
- const m = String(path).match(/\/([^/]+)\/history(?:\/|$)/);
1007
- if (!m)
1008
- throw new Error('Не history-путь: ' + path);
1009
- return m[1].startsWith('.') ? m[1].slice(1) : m[1];
1010
- }
1011
-
1012
- function _asDate(value) {
1013
- if (value instanceof Date && !isNaN(value))
1014
- return value;
1015
- if (typeof value === 'string' && /^\d{4}-\d{2}-\d{2}/.test(value))
1016
- return _parseDay(value);
1017
- const d = new Date(value || Date.now());
1018
- return isNaN(d) ? new Date() : d;
1019
- }
1020
-
1021
- function _parseDay(value) {
1022
- const s = String(value);
1023
- const m = s.match(/^(\d{4})-(\d{2})-(\d{2})/);
1024
- if (m)
1025
- return new Date(+m[1], +m[2] - 1, +m[3]);
1026
- const d = new Date(value);
1027
- return new Date(d.getFullYear(), d.getMonth(), d.getDate());
1028
- }
1029
-
1030
- function _formatDate(date) {
1031
- const d = _asDate(date);
1032
- const year = d.getFullYear();
1033
- const month = String(d.getMonth() + 1).padStart(2, '0');
1034
- const day = String(d.getDate()).padStart(2, '0');
1035
- return `${year}-${month}-${day}`;
1036
- }
1037
-
1038
- function _dotDate(date, parts = 'dmy') {
1039
- const dd = String(date.getDate()).padStart(2, '0');
1040
- if (parts === 'd')
1041
- return dd;
1042
- const mm = String(date.getMonth() + 1).padStart(2, '0');
1043
- if (parts === 'dm')
1044
- return `${dd}.${mm}`;
1045
- return `${dd}.${mm}.${date.getFullYear()}`;
1046
- }
1047
-
1048
- function _periodLabel(date, viewMode) {
1049
- const d = _asDate(date);
1050
- if (viewMode === 'month')
1051
- return `${monthsFullNames[d.getMonth()]} ${d.getFullYear()}`;
1052
- if (viewMode === 'week' || viewMode === 'workweek') {
1053
- const start = _weekStart(d);
1054
- const end = new Date(start);
1055
- end.setDate(end.getDate() + (viewMode === 'workweek' ? 4 : 6));
1056
- const sameYear = start.getFullYear() === end.getFullYear();
1057
- const sameMonth = sameYear && start.getMonth() === end.getMonth();
1058
- const left = sameMonth ? _dotDate(start, 'd') : sameYear ? _dotDate(start, 'dm') : _dotDate(start);
1059
- return `${left} - ${_dotDate(end)}`;
1060
- }
1061
- return _dotDate(d);
1062
- }
1063
-
1064
- function _weekStart(date) {
1065
- const start = new Date(date.getFullYear(), date.getMonth(), date.getDate());
1066
- const dayOfWeek = start.getDay();
1067
- const diff = dayOfWeek === 0 ? -6 : 1 - dayOfWeek;
1068
- start.setDate(start.getDate() + diff);
1069
- return start;
1070
- }
1071
-
1072
- function _weekEnd(date) {
1073
- const end = _weekStart(date);
1074
- end.setDate(end.getDate() + 6);
1075
- return end;
1076
- }
1077
-
1078
- function _shiftDate(date, viewMode, dir) {
1079
- const next = new Date(date.getFullYear(), date.getMonth(), date.getDate());
1080
- if (viewMode === 'day')
1081
- next.setDate(next.getDate() + dir);
1082
- else if (viewMode === 'week' || viewMode === 'workweek')
1083
- next.setDate(next.getDate() + dir * 7);
1084
- else
1085
- next.setMonth(next.getMonth() + dir);
1086
- return next;
1087
- }
1088
-
1089
- function _dateGroupLabel(iso) {
1090
- const d = _asDate(iso);
1091
- const dayOfWeek = daysRu[d.getDay()];
1092
- const dayNum = d.getDate();
1093
- const month = monthsRu[d.getMonth()];
1094
- const year = d.getFullYear();
1095
- return `${dayOfWeek}, ${dayNum} ${month} ${year} г.`;
1096
- }
1097
-
1098
- function _allDayEvents(events, date) {
1099
- const dayStart = new Date(date.getFullYear(), date.getMonth(), date.getDate()).getTime();
1100
- const next = new Date(date.getFullYear(), date.getMonth(), date.getDate() + 1).getTime();
1101
- const result = [];
1102
- for (const e of events) {
1103
- if (!e.allDay)
1104
- continue;
1105
- const s = new Date(e.start).getTime();
1106
- const t = new Date(e.end).getTime();
1107
- if (isNaN(s) || isNaN(t) || t <= s)
1108
- continue;
1109
- if (t <= dayStart || s >= next)
1110
- continue;
1111
- result.push({
1112
- start: e.start,
1113
- end: e.end,
1114
- summary: e.summary ?? '',
1115
- location: e.location ?? '',
1116
- allDay: true,
1117
- $item: e.$item,
1118
- title: eventTitle(e)
1119
- });
1120
- }
1121
- return result;
1122
- }
1123
-
1124
- function _layoutDayEvents(events, date) {
1125
- const dayStart = new Date(date.getFullYear(), date.getMonth(), date.getDate());
1126
- const dayEnd = new Date(dayStart);
1127
- dayEnd.setDate(dayEnd.getDate() + 1);
1128
- const startMs = dayStart.getTime();
1129
- const endMs = dayEnd.getTime();
1130
- const dayMinutes = (endMs - startMs) / 60000;
1131
- const gap = 2;
1132
- const items = [];
1133
- for (const e of events) {
1134
- if (e.allDay)
1135
- continue;
1136
- const s = new Date(e.start).getTime();
1137
- const t = new Date(e.end).getTime();
1138
- if (isNaN(s) || isNaN(t) || t <= s)
1139
- continue;
1140
- if (t <= startMs || s >= endMs)
1141
- continue;
1142
- const clipStart = Math.max(s, startMs);
1143
- const clipEnd = Math.min(t, endMs);
1144
- items.push({
1145
- start: e.start,
1146
- end: e.end,
1147
- summary: e.summary ?? '',
1148
- location: e.location ?? '',
1149
- $item: e.$item,
1150
- _start: clipStart,
1151
- _end: clipEnd,
1152
- _topMin: (clipStart - startMs) / 60000,
1153
- _durMin: (clipEnd - clipStart) / 60000
1154
- });
1155
- }
1156
- items.sort((a, b) => a._start - b._start || (b._end - a._start) - (a._end - a._start));
1157
-
1158
- const result = [];
1159
- const cluster = [];
1160
- const columns = [];
1161
- let clusterEnd = 0;
1162
-
1163
- const flush = () => {
1164
- const colCount = Math.max(columns.length, 1);
1165
- for (const item of cluster) {
1166
- result.push({
1167
- start: item.start,
1168
- end: item.end,
1169
- summary: item.summary,
1170
- location: item.location,
1171
- $item: item.$item,
1172
- title: eventTitle(item),
1173
- style: {
1174
- top: `${item._topMin / dayMinutes * 100}%`,
1175
- height: `${Math.max(item._durMin / dayMinutes * 100, 100 / 48)}%`,
1176
- left: `calc(${item._col / colCount * 100}% + ${gap}px)`,
1177
- width: `calc(${100 / colCount}% - ${gap * 2}px)`
1178
- }
1179
- });
1180
- }
1181
- cluster.length = 0;
1182
- columns.length = 0;
1183
- clusterEnd = 0;
1184
- };
1185
-
1186
- for (const ev of items) {
1187
- if (cluster.length && ev._start >= clusterEnd)
1188
- flush();
1189
- let col = columns.findIndex(end => end <= ev._start);
1190
- if (col === -1) {
1191
- col = columns.length;
1192
- columns.push(ev._end);
1193
- } else {
1194
- columns[col] = ev._end;
1195
- }
1196
- ev._col = col;
1197
- cluster.push(ev);
1198
- clusterEnd = Math.max(clusterEnd, ev._end);
1199
- }
1200
- if (cluster.length)
1201
- flush();
1202
- return result;
1203
- }
1196
+ });