odant-work 1.0.83 → 1.0.85

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.
@@ -1,3 +1,29 @@
1
+ const RWCD_RANK = Object.freeze({ none: 0, read: 1, write: 2, create: 3, delete: 4, admin: 5 });
2
+ const RWCD_SEGMENTS = Object.freeze([
3
+ { key: 'none', rank: 0, short: '—', title: 'Нет доступа' },
4
+ { key: 'read', rank: 1, short: 'R', title: 'Чтение (R)' },
5
+ { key: 'write', rank: 2, short: 'W', title: 'Редактирование и проведение (W)' },
6
+ { key: 'create', rank: 3, short: 'C', title: 'Создание объектов и документов (C)' },
7
+ { key: 'delete', rank: 4, short: 'D', title: 'Удаление и полный доступ к данным (D)' },
8
+ ]);
9
+
10
+ function normalizeAccess(raw) {
11
+ if (raw === undefined || raw === null)
12
+ return null;
13
+ const s = String(raw).trim().toLowerCase();
14
+ if (s === 'none' || s === '0' || s === '-') return 'none';
15
+ if (s === 'read' || s === '1' || s === 'r') return 'read';
16
+ if (s === 'write' || s === '2' || s === 'w') return 'write';
17
+ if (s === 'create' || s === '3' || s === 'c') return 'create';
18
+ if (s === 'delete' || s === '4' || s === 'd') return 'delete';
19
+ return null;
20
+ }
21
+
22
+ function normPath(p) {
23
+ const s = String(p || '').trim().replace(/\\/g, '/').replace(/\/+$/, '');
24
+ return s || '/';
25
+ }
26
+
1
27
  function parseDroppedItem(e) {
2
28
  const dt = e?.dataTransfer;
3
29
  if (!dt)
@@ -30,9 +56,17 @@ function isDroppedUser(info) {
30
56
  return info.type === '$user' || /^\/users\/[^/]+$/i.test(info.path || '');
31
57
  }
32
58
 
59
+ function isDroppedRemoteSubject(info) {
60
+ if (!info)
61
+ return false;
62
+ return /^\/NODES\/[^/]+(?:\/.+)?$/i.test(info.path || '');
63
+ }
64
+
33
65
  function isDroppedStructure(info) {
34
66
  if (!info)
35
67
  return false;
68
+ if (isDroppedRemoteSubject(info))
69
+ return false;
36
70
  if (['$structure', '$base', '$project', '$server'].includes(info.type))
37
71
  return true;
38
72
  return /^\/(?:ORGANIZATIONS|PROJECTS)\/[^/]+(?:\/[^/]+)*$/.test(info.path || '')
@@ -55,15 +89,6 @@ function isDroppedClass(info) {
55
89
  return String(info.path || '').includes('/MODULES/');
56
90
  }
57
91
 
58
- function isRoleReadonly(r) {
59
- if (typeof r?.readonly === 'boolean')
60
- return r.readonly;
61
- const links = Array.isArray(r?.LINKS) ? r.LINKS : [];
62
- if (!links.length)
63
- return false;
64
- return links.every(l => l?.access !== 'write');
65
- }
66
-
67
92
  function buildFallbackClassTree(links) {
68
93
  const out = [];
69
94
  for (const l of Array.isArray(links) ? links : []) {
@@ -76,40 +101,150 @@ function buildFallbackClassTree(links) {
76
101
  return out;
77
102
  }
78
103
 
104
+ function accessLabelRu(access) {
105
+ if (access === 'read') return 'Чтение (R)';
106
+ if (access === 'write') return 'Редактирование (W)';
107
+ if (access === 'create') return 'Создание (C)';
108
+ if (access === 'delete') return 'Удаление (D)';
109
+ if (access === 'none') return 'Нет доступа (—)';
110
+ return String(access || '');
111
+ }
112
+
113
+ // ---------------------------------------------------------------------------
114
+ // Выпадающий выбор руководителя (BOSS) из /USERS своего сервера
115
+ // ---------------------------------------------------------------------------
79
116
  if (typeof ODA === 'function' && !customElements.get('staff-boss-menu')) {
80
117
  ODA({
81
118
  is: 'staff-boss-menu',
82
119
  imports: 'oda//icon',
83
120
  template: /*html*/`
84
121
  <style>
85
- :host { @apply --vertical; padding: 6px; min-width: 260px; max-width: 360px; max-height: 360px; font-size: 13px; }
86
- .search { padding: 5px 8px; margin-bottom: 6px; border: 1px solid var(--subtle-border, #cbd5e1); border-radius: 6px; font: inherit; background: var(--content-background); color: inherit; }
87
- .list { @apply --vertical; overflow-y: auto; gap: 2px; max-height: 290px; }
88
- .it { @apply --horizontal; align-items: center; gap: 8px; padding: 6px 8px; border-radius: 6px; cursor: pointer; }
122
+ :host {
123
+ @apply --vertical;
124
+ padding: 6px;
125
+ width: min(340px, calc(100vw - 24px));
126
+ max-height: min(400px, 70dvh);
127
+ font-size: 13px;
128
+ box-sizing: border-box;
129
+ }
130
+ .search {
131
+ padding: 6px 9px;
132
+ margin-bottom: 6px;
133
+ border: 1px solid var(--subtle-border, #cbd5e1);
134
+ border-radius: 6px;
135
+ font: inherit;
136
+ background: var(--content-background);
137
+ color: inherit;
138
+ width: 100%;
139
+ box-sizing: border-box;
140
+ }
141
+ .list {
142
+ @apply --vertical;
143
+ overflow-y: auto;
144
+ gap: 2px;
145
+ min-height: 0;
146
+ flex: 1 1 auto;
147
+ }
148
+ .it {
149
+ @apply --horizontal;
150
+ align-items: center;
151
+ gap: 8px;
152
+ padding: 6px 8px;
153
+ border-radius: 6px;
154
+ cursor: pointer;
155
+ min-height: 30px;
156
+ box-sizing: border-box;
157
+ }
89
158
  .it:hover { background: var(--accent-soft, rgba(37, 99, 235, 0.1)); }
90
159
  .it.active { font-weight: 600; background: var(--subtle-background); }
91
- .sep { height: 1px; background: var(--subtle-border); margin: 4px 0; }
160
+ .it.folder { font-weight: 600; color: var(--muted-color); }
161
+ .exp {
162
+ width: 16px;
163
+ height: 16px;
164
+ display: inline-flex;
165
+ align-items: center;
166
+ justify-content: center;
167
+ flex-shrink: 0;
168
+ color: var(--muted-color);
169
+ }
170
+ .sep { height: 1px; background: var(--subtle-border); margin: 4px 0; flex-shrink: 0; }
171
+ .empty { padding: 12px 8px; color: var(--muted-color); font-size: 12.5px; text-align: center; }
92
172
  </style>
93
- <input class="search" type="text" placeholder="Поиск сотрудника…" ::value="query">
173
+ <input class="search" type="text" placeholder="Поиск пользователя…" ::value="query">
94
174
  <div class="list">
95
175
  <div class="it" ~if="hasLocalBoss" @tap="pick('')">
96
176
  <oda-icon icon="icons:undo" icon-size="16"></oda-icon>
97
177
  <span>Наследовать сверху</span>
98
178
  </div>
99
179
  <div class="sep" ~if="hasLocalBoss"></div>
100
- <div class="it" ~for="filtered" :class="{ active: $for.item.id === currentId }" @tap="pick($for.item.id)">
101
- <oda-icon round :icon="$for.item.icon" :icon-color="$for.item.iconColor" icon-size="20"></oda-icon>
180
+ <div class="it" ~for="visibleRows"
181
+ ~class="{ active: $for.item.isUser && $for.item.id === currentId, folder: !$for.item.isUser }"
182
+ :style="'padding-left:' + (8 + $for.item.depth * 18) + 'px'"
183
+ @tap="onRowTap($for.item)">
184
+ <span class="exp" ~if="$for.item.hasChildren" @tap.stop="toggleNode($for.item.key)">
185
+ {{$for.item.expanded ? '▾' : '▸'}}
186
+ </span>
187
+ <oda-icon :round="$for.item.isUser" :icon="$for.item.icon" :icon-color="$for.item.iconColor" icon-size="20"></oda-icon>
102
188
  <span>{{$for.item.label}}</span>
103
189
  </div>
190
+ <div class="empty" ~if="!visibleRows.length">Пользователи не найдены</div>
104
191
  </div>
105
192
  `,
106
193
  users: [],
194
+ usersTree: [],
107
195
  currentId: '',
108
196
  hasLocalBoss: false,
109
197
  query: '',
110
- get filtered() {
198
+ expandedMap: {},
199
+ get visibleRows() {
111
200
  const q = String(this.query || '').trim().toLowerCase();
112
- return (this.users || []).filter(u => !q || String(u.label || '').toLowerCase().includes(q));
201
+ const source = Array.isArray(this.usersTree) && this.usersTree.length
202
+ ? this.usersTree
203
+ : (this.users || []).map(u => ({ ...u, type: '$user', children: [] }));
204
+ const filterTree = (nodes) => {
205
+ const res = [];
206
+ for (const n of nodes || []) {
207
+ const kids = filterTree(n.children || []);
208
+ const selfMatch = !q || String(n.label || n.id || '').toLowerCase().includes(q);
209
+ if (selfMatch || kids.length > 0)
210
+ res.push({ ...n, children: kids });
211
+ }
212
+ return res;
213
+ };
214
+ const out = [];
215
+ const walk = (nodes, depth) => {
216
+ for (const n of nodes) {
217
+ const isUser = !n.children?.length && (n.type === '$user' || !n.type);
218
+ const hasChildren = Array.isArray(n.children) && n.children.length > 0;
219
+ const key = n.path || n.id;
220
+ const expanded = q ? true : (this.expandedMap?.[key] !== false);
221
+ out.push({
222
+ key,
223
+ id: n.id,
224
+ label: n.label || n.id,
225
+ icon: n.icon || (isUser ? 'icons:person' : 'odant:folder'),
226
+ iconColor: n.iconColor || '',
227
+ isUser,
228
+ hasChildren,
229
+ expanded,
230
+ depth,
231
+ });
232
+ if (hasChildren && expanded)
233
+ walk(n.children, depth + 1);
234
+ }
235
+ };
236
+ walk(filterTree(source), 0);
237
+ return out;
238
+ },
239
+ toggleNode(key) {
240
+ const cur = this.expandedMap?.[key] !== false;
241
+ this.expandedMap = { ...this.expandedMap, [key]: !cur };
242
+ },
243
+ onRowTap(row) {
244
+ if (row.isUser)
245
+ this.pick(row.id);
246
+ else if (row.hasChildren)
247
+ this.toggleNode(row.key);
113
248
  },
114
249
  pick(id) {
115
250
  this.parentElement?.close?.(id);
@@ -117,33 +252,259 @@ if (typeof ODA === 'function' && !customElements.get('staff-boss-menu')) {
117
252
  });
118
253
  }
119
254
 
255
+ // ---------------------------------------------------------------------------
256
+ // Иерархический выбор участника роли:
257
+ // Пользователи (/USERS), Организации (/ORGANIZATIONS), Проекты (/PROJECTS), Сеть (/NODES + ленивое раскрытие)
258
+ // ---------------------------------------------------------------------------
120
259
  if (typeof ODA === 'function' && !customElements.get('staff-member-menu')) {
121
260
  ODA({
122
261
  is: 'staff-member-menu',
123
262
  imports: 'oda//icon',
124
263
  template: /*html*/`
125
264
  <style>
126
- :host { @apply --vertical; padding: 6px; min-width: 280px; max-width: 400px; max-height: 400px; font-size: 13px; }
127
- .search { padding: 5px 8px; margin-bottom: 6px; border: 1px solid var(--subtle-border, #cbd5e1); border-radius: 6px; font: inherit; background: var(--content-background); color: inherit; }
128
- .list { @apply --vertical; overflow-y: auto; gap: 2px; max-height: 330px; }
129
- .it { @apply --horizontal; align-items: center; gap: 8px; padding: 6px 8px; border-radius: 6px; cursor: pointer; }
265
+ :host {
266
+ @apply --vertical;
267
+ padding: 6px;
268
+ width: min(400px, calc(100vw - 24px));
269
+ max-height: min(440px, 72dvh);
270
+ font-size: 13px;
271
+ box-sizing: border-box;
272
+ }
273
+ .search {
274
+ padding: 6px 9px;
275
+ margin-bottom: 6px;
276
+ border: 1px solid var(--subtle-border, #cbd5e1);
277
+ border-radius: 6px;
278
+ font: inherit;
279
+ background: var(--content-background);
280
+ color: inherit;
281
+ width: 100%;
282
+ box-sizing: border-box;
283
+ }
284
+ .list {
285
+ @apply --vertical;
286
+ overflow-y: auto;
287
+ gap: 1px;
288
+ min-height: 0;
289
+ flex: 1 1 auto;
290
+ }
291
+ .it {
292
+ @apply --horizontal;
293
+ align-items: center;
294
+ gap: 6px;
295
+ padding: 5px 8px;
296
+ border-radius: 6px;
297
+ cursor: pointer;
298
+ min-height: 29px;
299
+ box-sizing: border-box;
300
+ }
130
301
  .it:hover { background: var(--accent-soft, rgba(37, 99, 235, 0.1)); }
131
- .tag { margin-left: auto; font-size: 11px; color: var(--muted-color); }
302
+ .it.root-group { font-weight: 600; background: color-mix(in srgb, var(--subtle-background) 60%, transparent); margin-top: 2px; }
303
+ .it.disabled { opacity: .45; cursor: default; }
304
+ .it.disabled:hover { background: transparent; }
305
+ .exp {
306
+ width: 18px;
307
+ height: 18px;
308
+ display: inline-flex;
309
+ align-items: center;
310
+ justify-content: center;
311
+ flex-shrink: 0;
312
+ border-radius: 4px;
313
+ color: var(--muted-color);
314
+ user-select: none;
315
+ }
316
+ .exp:hover { background: var(--subtle-background); color: var(--content-color); }
317
+ .lbl {
318
+ flex: 1;
319
+ min-width: 0;
320
+ overflow: hidden;
321
+ text-overflow: ellipsis;
322
+ white-space: nowrap;
323
+ }
324
+ .tag {
325
+ margin-left: auto;
326
+ font-size: 11px;
327
+ color: var(--muted-color);
328
+ flex-shrink: 0;
329
+ }
330
+ .hint-row {
331
+ padding: 4px 8px;
332
+ font-size: 12px;
333
+ color: var(--muted-color);
334
+ font-style: italic;
335
+ }
336
+ .empty { padding: 14px 8px; color: var(--muted-color); font-size: 12.5px; text-align: center; }
132
337
  </style>
133
- <input class="search" type="text" placeholder="Поиск человека, отдела или сервера…" ::value="query">
338
+ <input class="search" type="text" placeholder="Поиск пользователя, организации, проекта, сервера…" ::value="query">
134
339
  <div class="list">
135
- <div class="it" ~for="filteredOptions" @tap="pick($for.item.value)">
136
- <oda-icon :round="$for.item.round" :icon="$for.item.icon" :icon-color="$for.item.iconColor" icon-size="18"></oda-icon>
137
- <span>{{$for.item.label}}</span>
138
- <span class="tag" ~if="$for.item.tag">{{$for.item.tag}}</span>
340
+ <div ~for="visibleRows">
341
+ <div ~if="$for.item.isHint" class="hint-row" :style="'padding-left:' + (10 + $for.item.depth * 18) + 'px'">
342
+ {{$for.item.label}}
343
+ </div>
344
+ <div ~if="!$for.item.isHint" class="it"
345
+ ~class="{ 'root-group': $for.item.isGroupRoot, disabled: $for.item.disabled }"
346
+ :style="'padding-left:' + (6 + $for.item.depth * 18) + 'px'"
347
+ @tap="onRowTap($for.item)">
348
+ <span class="exp" @tap.stop="toggleNode($for.item)">
349
+ {{$for.item.expandable ? ($for.item.loading ? '…' : ($for.item.expanded ? '▾' : '▸')) : ''}}
350
+ </span>
351
+ <oda-icon :round="$for.item.round" :icon="$for.item.icon" :icon-color="$for.item.iconColor" icon-size="18"></oda-icon>
352
+ <span class="lbl" :title="$for.item.title || $for.item.label">{{$for.item.label}}</span>
353
+ <span class="tag" ~if="$for.item.tag">{{$for.item.tag}}</span>
354
+ </div>
139
355
  </div>
356
+ <div class="empty" ~if="!visibleRows.length">Ничего не найдено</div>
140
357
  </div>
141
358
  `,
142
- options: [],
359
+ treeRoots: [],
143
360
  query: '',
144
- get filteredOptions() {
361
+ expandedMap: {
362
+ 'root:users': true,
363
+ 'root:orgs': true,
364
+ 'root:projects': false,
365
+ 'root:nodes': true,
366
+ },
367
+ remoteChildrenMap: {},
368
+ remoteLoadingMap: {},
369
+ remoteEmptyMap: {},
370
+ remoteMetaCollector: null,
371
+ get visibleRows() {
145
372
  const q = String(this.query || '').trim().toLowerCase();
146
- return (this.options || []).filter(o => !q || String(o.label || '').toLowerCase().includes(q) || String(o.tag || '').toLowerCase().includes(q));
373
+ const getKids = (node) => {
374
+ if (node.lazyPath && this.remoteChildrenMap?.[node.lazyPath])
375
+ return this.remoteChildrenMap[node.lazyPath];
376
+ return Array.isArray(node.children) ? node.children : [];
377
+ };
378
+ const filterNodes = (nodes) => {
379
+ const res = [];
380
+ for (const n of nodes || []) {
381
+ const kids = filterNodes(getKids(n));
382
+ const hay = `${n.label || ''} ${n.tag || ''} ${n.value || ''}`.toLowerCase();
383
+ const match = !q || hay.includes(q);
384
+ if (match || kids.length > 0)
385
+ res.push({ ...n, _filteredKids: kids });
386
+ }
387
+ return res;
388
+ };
389
+ const out = [];
390
+ const walk = (nodes, depth) => {
391
+ for (const n of nodes) {
392
+ const kids = n._filteredKids || [];
393
+ const expandable = kids.length > 0 || Boolean(n.lazyPath);
394
+ const loading = Boolean(n.lazyPath && this.remoteLoadingMap?.[n.lazyPath]);
395
+ const expanded = q ? (kids.length > 0) : Boolean(this.expandedMap?.[n.key]);
396
+ out.push({
397
+ key: n.key,
398
+ value: n.value || '',
399
+ label: n.label,
400
+ title: n.title || n.value || n.label,
401
+ icon: n.icon || 'odant:folder',
402
+ iconColor: n.iconColor || '',
403
+ round: Boolean(n.round),
404
+ tag: n.tag || '',
405
+ selectable: Boolean(n.selectable && !n.disabled),
406
+ disabled: Boolean(n.disabled),
407
+ isGroupRoot: Boolean(n.isGroupRoot),
408
+ expandable,
409
+ expanded,
410
+ loading,
411
+ lazyPath: n.lazyPath || '',
412
+ remoteNodeLabel: n.remoteNodeLabel || '',
413
+ depth,
414
+ });
415
+ if (expandable && expanded) {
416
+ if (loading) {
417
+ out.push({ isHint: true, label: 'Загрузка с удалённого сервера…', depth: depth + 1 });
418
+ }
419
+ else if (kids.length) {
420
+ walk(kids, depth + 1);
421
+ }
422
+ else if (n.lazyPath && this.remoteEmptyMap?.[n.lazyPath]) {
423
+ out.push({ isHint: true, label: 'Нет открытых разделов или пользователей', depth: depth + 1 });
424
+ }
425
+ }
426
+ }
427
+ };
428
+ walk(filterNodes(this.treeRoots || []), 0);
429
+ return out;
430
+ },
431
+ async toggleNode(row) {
432
+ if (!row?.expandable)
433
+ return;
434
+ const nextExpanded = !this.expandedMap?.[row.key];
435
+ this.expandedMap = { ...this.expandedMap, [row.key]: nextExpanded };
436
+ if (nextExpanded && row.lazyPath && !this.remoteChildrenMap?.[row.lazyPath] && !this.remoteLoadingMap?.[row.lazyPath]) {
437
+ await this._loadRemoteChildren(row.lazyPath, row.remoteNodeLabel || row.label);
438
+ }
439
+ },
440
+ async _loadRemoteChildren(remotePath, remoteNodeLabel) {
441
+ this.remoteLoadingMap = { ...this.remoteLoadingMap, [remotePath]: true };
442
+ try {
443
+ const target = typeof WORK?.get_item === 'function'
444
+ ? await WORK.get_item(remotePath).catch(() => null)
445
+ : null;
446
+ const rawItems = target ? (await Promise.resolve(target.items).catch(() => [])) : [];
447
+ const kids = [];
448
+ for (const it of Array.isArray(rawItems) ? rawItems : []) {
449
+ if (!it || !it.id || String(it.id).startsWith('$'))
450
+ continue;
451
+ const t = it.type || '';
452
+ const p = normPath(it.path || `${remotePath}/${it.id}`);
453
+ const idUpper = String(it.id).toUpperCase();
454
+ const isDomainGroup = (t === '$domain' || t === '$folder') && ['USERS', 'ORGANIZATIONS', 'PROJECTS'].includes(idUpper);
455
+ const isUser = t === '$user' || /\/USERS\/[^/]+$/i.test(p);
456
+ const isUnit = ['$base', '$project', '$structure'].includes(t);
457
+ if (!isDomainGroup && !isUser && !isUnit)
458
+ continue;
459
+ const lbl = it.DATA?.label || it.label || it.id;
460
+ const icon = it.DATA?.icon || it.icon
461
+ || (isUser ? 'icons:person' : isDomainGroup ? (idUpper === 'USERS' ? 'social:people' : idUpper === 'PROJECTS' ? 'odant:project' : 'odant:base') : 'odant:structure');
462
+ const child = {
463
+ key: `remote:${p}`,
464
+ value: isDomainGroup ? '' : p,
465
+ label: lbl,
466
+ title: `${lbl} (${remoteNodeLabel})`,
467
+ icon,
468
+ iconColor: it.iconColor || '',
469
+ round: isUser,
470
+ tag: isUser ? 'пользователь' : (t === '$base' ? 'организация' : t === '$project' ? 'проект' : isUnit ? 'подразделение' : ''),
471
+ selectable: !isDomainGroup,
472
+ lazyPath: isUser ? '' : p,
473
+ remoteNodeLabel,
474
+ children: [],
475
+ };
476
+ if (!isDomainGroup && typeof this.remoteMetaCollector === 'function') {
477
+ this.remoteMetaCollector(p, {
478
+ label: lbl,
479
+ icon,
480
+ iconColor: it.iconColor || '',
481
+ isUser,
482
+ type: t,
483
+ nodeLabel: remoteNodeLabel,
484
+ });
485
+ }
486
+ kids.push(child);
487
+ }
488
+ this.remoteChildrenMap = { ...this.remoteChildrenMap, [remotePath]: kids };
489
+ this.remoteEmptyMap = { ...this.remoteEmptyMap, [remotePath]: kids.length === 0 };
490
+ }
491
+ catch {
492
+ this.remoteChildrenMap = { ...this.remoteChildrenMap, [remotePath]: [] };
493
+ this.remoteEmptyMap = { ...this.remoteEmptyMap, [remotePath]: true };
494
+ }
495
+ finally {
496
+ this.remoteLoadingMap = { ...this.remoteLoadingMap, [remotePath]: false };
497
+ }
498
+ },
499
+ onRowTap(row) {
500
+ if (row.disabled)
501
+ return;
502
+ if (row.selectable && row.value) {
503
+ this.pick(row.value);
504
+ return;
505
+ }
506
+ if (row.expandable)
507
+ this.toggleNode(row);
147
508
  },
148
509
  pick(val) {
149
510
  this.parentElement?.close?.(val);
@@ -151,6 +512,9 @@ if (typeof ODA === 'function' && !customElements.get('staff-member-menu')) {
151
512
  });
152
513
  }
153
514
 
515
+ // ---------------------------------------------------------------------------
516
+ // Рекурсивный узел роли с двумя подгруппами: «Пользователи» и «Классы» (RWCD)
517
+ // ---------------------------------------------------------------------------
154
518
  if (typeof ODA === 'function' && !customElements.get('staff-role-node')) {
155
519
  ODA({
156
520
  is: 'staff-role-node',
@@ -168,10 +532,11 @@ if (typeof ODA === 'function' && !customElements.get('staff-role-node')) {
168
532
  padding: 5px 12px;
169
533
  min-height: 32px;
170
534
  border-bottom: 1px solid color-mix(in srgb, var(--subtle-border) 50%, transparent);
171
- flex-wrap: wrap;
535
+ box-sizing: border-box;
172
536
  }
173
537
  .tree-row.role-row {
174
538
  background: var(--content-background);
539
+ flex-wrap: wrap;
175
540
  }
176
541
  .tree-row.role-row:hover {
177
542
  background: color-mix(in srgb, var(--subtle-background) 65%, transparent);
@@ -181,15 +546,48 @@ if (typeof ODA === 'function' && !customElements.get('staff-role-node')) {
181
546
  outline: 1px dashed var(--accent-color, #2563eb);
182
547
  outline-offset: -2px;
183
548
  }
184
- .tree-row.class-row {
549
+ .tree-row.subgroup-row {
185
550
  min-height: 28px;
186
551
  padding-top: 3px;
187
552
  padding-bottom: 3px;
188
- background: color-mix(in srgb, var(--subtle-background) 32%, var(--content-background));
553
+ background: color-mix(in srgb, var(--subtle-background) 55%, var(--content-background));
554
+ font-size: 12.5px;
555
+ font-weight: 600;
556
+ color: var(--muted-color);
557
+ }
558
+ .tree-row.subgroup-row:hover {
559
+ background: var(--subtle-background);
560
+ }
561
+ .tree-row.member-row {
562
+ min-height: 29px;
563
+ padding-top: 3px;
564
+ padding-bottom: 3px;
565
+ background: var(--content-background);
566
+ font-size: 13px;
567
+ }
568
+ .tree-row.member-row:hover {
569
+ background: color-mix(in srgb, var(--subtle-background) 55%, transparent);
570
+ }
571
+ .tree-row.class-row {
572
+ min-height: 30px;
573
+ padding-top: 3px;
574
+ padding-bottom: 3px;
575
+ background: color-mix(in srgb, var(--subtle-background) 24%, var(--content-background));
576
+ flex-wrap: wrap;
577
+ gap: 6px;
189
578
  }
190
579
  .tree-row.class-row:hover {
191
580
  background: var(--subtle-background);
192
581
  }
582
+ .tree-row.empty-row {
583
+ min-height: 26px;
584
+ padding-top: 3px;
585
+ padding-bottom: 3px;
586
+ color: var(--muted-color);
587
+ font-size: 12px;
588
+ font-style: italic;
589
+ background: var(--content-background);
590
+ }
193
591
  .expander {
194
592
  width: 16px;
195
593
  height: 16px;
@@ -210,45 +608,42 @@ if (typeof ODA === 'function' && !customElements.get('staff-role-node')) {
210
608
  font-weight: 600;
211
609
  font-size: 13.5px;
212
610
  }
213
- .members-wrap {
214
- @apply --horizontal;
215
- align-items: center;
216
- gap: 5px;
217
- flex-wrap: wrap;
218
- flex: 1;
219
- min-width: 120px;
220
- }
221
- .chip {
222
- @apply --horizontal;
223
- align-items: center;
224
- gap: 5px;
225
- padding: 2px 8px 2px 4px;
226
- border-radius: 14px;
227
- background: var(--accent-soft);
228
- color: var(--content-color);
229
- font-size: 12.5px;
611
+ .sub-title {
230
612
  cursor: pointer;
613
+ user-select: none;
231
614
  }
232
- .chip.node-chip {
233
- background: color-mix(in srgb, #0284c7 13%, var(--content-background));
234
- border: 1px solid color-mix(in srgb, #0284c7 28%, transparent);
615
+ .sub-count {
616
+ font-weight: 500;
617
+ font-size: 11.5px;
618
+ opacity: .8;
235
619
  }
236
- .chip.net-chip {
237
- background: color-mix(in srgb, #7c3aed 12%, var(--content-background));
238
- border: 1px solid color-mix(in srgb, #7c3aed 28%, transparent);
620
+ .member-name {
621
+ cursor: pointer;
622
+ min-width: 0;
623
+ overflow: hidden;
624
+ text-overflow: ellipsis;
625
+ white-space: nowrap;
626
+ }
627
+ .member-name:hover {
628
+ color: var(--accent-color);
629
+ text-decoration: underline;
239
630
  }
240
- .chip:hover {
241
- filter: brightness(0.95);
631
+ .member-tag {
632
+ font-size: 11px;
633
+ color: var(--muted-color);
634
+ margin-left: auto;
635
+ padding: 1px 6px;
636
+ border-radius: 6px;
637
+ background: color-mix(in srgb, var(--subtle-background) 85%, transparent);
638
+ flex-shrink: 0;
242
639
  }
243
- .chip .rm {
244
- font-weight: 700;
245
- opacity: .6;
246
- padding: 0 2px;
247
- cursor: pointer;
640
+ .member-tag.net {
641
+ color: #7c3aed;
642
+ background: color-mix(in srgb, #7c3aed 10%, var(--content-background));
248
643
  }
249
- .chip .rm:hover {
250
- opacity: 1;
251
- color: var(--error-color, #dc2626);
644
+ .member-tag.node {
645
+ color: #0284c7;
646
+ background: color-mix(in srgb, #0284c7 10%, var(--content-background));
252
647
  }
253
648
  .badge {
254
649
  font-size: 11px;
@@ -267,13 +662,14 @@ if (typeof ODA === 'function' && !customElements.get('staff-role-node')) {
267
662
  background: transparent;
268
663
  color: var(--muted-color);
269
664
  border-radius: 6px;
270
- padding: 3px 7px;
665
+ padding: 2px 7px;
271
666
  font: inherit;
272
667
  font-size: 12px;
273
668
  cursor: pointer;
274
669
  display: inline-flex;
275
670
  align-items: center;
276
671
  gap: 4px;
672
+ flex-shrink: 0;
277
673
  }
278
674
  .icon-btn:hover {
279
675
  background: var(--subtle-background);
@@ -296,76 +692,133 @@ if (typeof ODA === 'function' && !customElements.get('staff-role-node')) {
296
692
  margin-left: auto;
297
693
  flex-wrap: wrap;
298
694
  }
299
- .ro-toggle {
695
+ .class-title {
696
+ cursor: pointer;
697
+ flex: 1;
698
+ min-width: 110px;
699
+ overflow: hidden;
700
+ text-overflow: ellipsis;
701
+ white-space: nowrap;
702
+ }
703
+ .class-title.granted {
704
+ font-weight: 500;
705
+ }
706
+ .class-title.denied {
707
+ color: var(--muted-color);
708
+ text-decoration: line-through;
709
+ }
710
+ .class-title:hover {
711
+ color: var(--accent-color);
712
+ text-decoration: underline;
713
+ }
714
+ .rwcd-wrap {
300
715
  @apply --horizontal;
301
716
  align-items: center;
302
717
  gap: 4px;
303
- font-size: 12px;
718
+ margin-left: auto;
719
+ flex-shrink: 0;
720
+ }
721
+ .rwcd-reset {
722
+ border: 1px solid transparent;
723
+ background: transparent;
304
724
  color: var(--muted-color);
725
+ border-radius: 5px;
726
+ width: 22px;
727
+ height: 22px;
728
+ padding: 0;
729
+ font-size: 12px;
730
+ line-height: 1;
305
731
  cursor: pointer;
306
- user-select: none;
307
- padding: 2px 6px;
308
- border-radius: 6px;
732
+ display: inline-flex;
733
+ align-items: center;
734
+ justify-content: center;
309
735
  }
310
- .ro-toggle:hover {
736
+ .rwcd-reset:hover {
311
737
  background: var(--subtle-background);
312
- color: var(--content-color);
738
+ border-color: var(--subtle-border);
739
+ color: var(--accent-color);
313
740
  }
314
- .class-title {
741
+ .rwcd-slider {
742
+ display: inline-flex;
743
+ align-items: stretch;
744
+ border: 1px solid var(--subtle-border, #cbd5e1);
745
+ border-radius: 6px;
746
+ overflow: hidden;
747
+ background: var(--content-background);
748
+ height: 22px;
749
+ user-select: none;
750
+ }
751
+ .rwcd-slider.inherited {
752
+ border-style: dashed;
753
+ border-color: color-mix(in srgb, var(--accent-color, #4f46e5) 40%, var(--subtle-border));
754
+ }
755
+ .rwcd-seg {
756
+ border: none;
757
+ border-right: 1px solid color-mix(in srgb, var(--subtle-border) 65%, transparent);
758
+ background: transparent;
759
+ color: var(--muted-color);
760
+ font: inherit;
761
+ font-size: 11px;
762
+ font-weight: 600;
763
+ min-width: 22px;
764
+ padding: 0 5px;
315
765
  cursor: pointer;
766
+ display: inline-flex;
767
+ align-items: center;
768
+ justify-content: center;
769
+ transition: background .1s ease, color .1s ease;
316
770
  }
317
- .class-title.checked {
318
- font-weight: 500;
771
+ .rwcd-seg:last-child {
772
+ border-right: none;
319
773
  }
320
- .class-title:hover {
321
- color: var(--accent-color);
322
- text-decoration: underline;
774
+ .rwcd-seg:hover:not(:disabled) {
775
+ background: color-mix(in srgb, var(--accent-color, #4f46e5) 14%, transparent);
776
+ color: var(--content-color);
777
+ }
778
+ .rwcd-seg:disabled {
779
+ cursor: default;
780
+ }
781
+ .rwcd-slider.explicit .rwcd-seg.filled {
782
+ background: var(--accent-color, #4f46e5);
783
+ color: #ffffff;
784
+ border-right-color: rgba(255, 255, 255, 0.22);
785
+ }
786
+ .rwcd-slider.inherited .rwcd-seg.filled {
787
+ background: color-mix(in srgb, var(--accent-color, #4f46e5) 20%, var(--content-background));
788
+ color: var(--accent-color, #4f46e5);
789
+ border-right-color: color-mix(in srgb, var(--accent-color, #4f46e5) 25%, transparent);
790
+ }
791
+ .rwcd-slider.denied .rwcd-seg.seg-none {
792
+ background: color-mix(in srgb, var(--error-color, #dc2626) 18%, var(--content-background));
793
+ color: var(--error-color, #dc2626);
794
+ }
795
+ .rwcd-slider:not(.denied) .rwcd-seg.seg-none.active-none {
796
+ background: color-mix(in srgb, var(--subtle-background) 90%, transparent);
797
+ color: var(--content-color);
798
+ }
799
+ @media (max-width: 520px) {
800
+ .tree-row { padding: 5px 8px; }
801
+ .rwcd-seg { min-width: 20px; padding: 0 4px; font-size: 10.5px; }
323
802
  }
324
803
  </style>
325
804
 
805
+ <!-- Заголовок роли -->
326
806
  <div class="tree-row role-row"
327
807
  ~class="{ 'drop-hover': dropHover }"
328
- :style="'padding-left:' + (12 + depth * 22) + 'px'"
808
+ :style="'padding-left:' + (12 + depth * 20) + 'px'"
329
809
  @dragover="onDragOver($event)"
330
810
  @dragleave="dropHover = false"
331
811
  @drop="onDrop($event)">
332
812
 
333
813
  <span class="expander" @tap="toggleExpand()">
334
- {{hasChildren ? (expanded ? '▾' : '▸') : ''}}
814
+ {{expanded ? '▾' : '▸'}}
335
815
  </span>
336
816
  <oda-icon :icon="role?.external ? 'icons:public' : 'fontawesome:s-user-tie'" icon-size="16"></oda-icon>
337
- <span class="role-name">{{role?.label || role?.id}}</span>
817
+ <span class="role-name" @tap="toggleExpand()" style="cursor:pointer;">{{role?.label || role?.id}}</span>
338
818
  <span ~if="role?.external" class="badge ext">клиент</span>
339
819
  <span ~if="role?.mine" class="badge">ваша роль</span>
340
820
 
341
- <div class="members-wrap">
342
- <div class="member-slot" ~for="memberEntries">
343
- <div class="chip"
344
- ~class="{ 'node-chip': $for.item.isNode, 'net-chip': $for.item.isNetworkNode }"
345
- @tap="controller?.openMember($for.item)">
346
- <oda-icon :round="!$for.item.isNode && !$for.item.isNetworkNode && !$for.item.isGroup" :icon="$for.item.icon" :icon-color="$for.item.iconColor" icon-size="16"></oda-icon>
347
- <span>{{$for.item.label}}</span>
348
- <span ~if="canEdit" class="rm" title="Убрать из роли" @tap.stop="controller?.removeRoleMember(trail, $for.item.id)">×</span>
349
- </div>
350
- </div>
351
- <button ~if="canEdit" type="button" class="icon-btn" title="Добавить участника (сотрудника, подразделение или сервер сети)" @tap="controller?.openMemberDropdown($event, trail)">
352
- <oda-icon icon="icons:add" icon-size="14"></oda-icon>
353
- </button>
354
- </div>
355
-
356
821
  <div ~if="canEdit" class="row-actions">
357
- <label class="ro-toggle" title="Вся роль только на чтение (без права изменения данных)">
358
- <input type="checkbox" :checked="readonly" @change="controller?.toggleRoleReadonly(trail, $event.target.checked)">
359
- <span>Только просмотр</span>
360
- </label>
361
- <button type="button" class="icon-btn" ~class="{ active: setupMode }" title="Показать полное дерево классов с чекбоксами" @tap="toggleSetup()">
362
- <oda-icon icon="icons:settings" icon-size="14"></oda-icon>
363
- <span>Настройка</span>
364
- </button>
365
- <button type="button" class="icon-btn" title="Добавить дочернюю роль" @tap="controller?.promptAddRole(trail)">
366
- <oda-icon icon="icons:add" icon-size="14"></oda-icon>
367
- <span>Подроль</span>
368
- </button>
369
822
  <button type="button" class="icon-btn" title="Переименовать роль" @tap="controller?.promptRenameRole(trail, role?.label || role?.id)">
370
823
  <oda-icon icon="editor:mode-edit" icon-size="13"></oda-icon>
371
824
  </button>
@@ -378,19 +831,117 @@ if (typeof ODA === 'function' && !customElements.get('staff-role-node')) {
378
831
  </div>
379
832
  </div>
380
833
 
381
- <div class="class-slot" ~for="visibleClassRows">
382
- <div class="tree-row class-row"
383
- :style="'padding-left:' + (28 + (depth + $for.item.classDepth) * 22) + 'px'">
384
- <span class="expander" @tap="toggleClassNode($for.item.id)">
385
- {{$for.item.hasChildren ? ($for.item.expanded ? '▾' : '▸') : ''}}
386
- </span>
387
- <input ~show="$for.item.setup" type="checkbox" :checked="$for.item.checked"
388
- @change="controller?.toggleClassInRole(trail, $for.item.id, $event.target.checked)">
389
- <oda-icon :icon="$for.item.icon" icon-size="15"></oda-icon>
390
- <span class="class-title" ~class="{ checked: $for.item.checked }" :title="$for.item.id" @tap="controller?.openClass($for.item.id)">{{$for.item.label}}</span>
834
+ <!-- Подгруппа 1: Пользователи -->
835
+ <div ~if="expanded" class="tree-row subgroup-row users-group-row"
836
+ :style="'padding-left:' + (28 + depth * 20) + 'px'"
837
+ @dragover="onDragOver($event)"
838
+ @dragleave="dropHover = false"
839
+ @drop="onDrop($event)">
840
+ <span class="expander" @tap="usersExpanded = !usersExpanded">{{usersExpanded ? '▾' : '▸'}}</span>
841
+ <oda-icon icon="social:people" icon-size="15"></oda-icon>
842
+ <span class="sub-title" @tap="usersExpanded = !usersExpanded">Пользователи</span>
843
+ <span class="sub-count">({{memberEntries.length}})</span>
844
+ <div ~if="canEdit" class="row-actions">
845
+ <button type="button" class="icon-btn add-member-btn" title="Добавить пользователя, подразделение или узел сети" @tap.stop="controller?.openMemberDropdown($event, trail)">
846
+ <oda-icon icon="icons:add" icon-size="14"></oda-icon>
847
+ <span>Добавить</span>
848
+ </button>
849
+ </div>
850
+ </div>
851
+
852
+ <div ~if="expanded && usersExpanded">
853
+ <div class="tree-row member-row" ~for="memberEntries"
854
+ :style="'padding-left:' + (48 + depth * 20) + 'px'">
855
+ <oda-icon :round="$for.item.round" :icon="$for.item.icon" :icon-color="$for.item.iconColor" icon-size="17"></oda-icon>
856
+ <span class="member-name" :title="$for.item.title || $for.item.label" @tap="controller?.openMember($for.item)">{{$for.item.label}}</span>
857
+ <span ~if="$for.item.tag" class="member-tag" ~class="{ net: $for.item.isNetworkNode || $for.item.isRemote, node: $for.item.isNode }">{{$for.item.tag}}</span>
858
+ <button ~if="canEdit" type="button" class="icon-btn danger" title="Убрать из роли" @tap.stop="controller?.removeRoleMember(trail, $for.item.id)">
859
+ <oda-icon icon="icons:close" icon-size="13"></oda-icon>
860
+ </button>
861
+ </div>
862
+ <div ~if="!memberEntries.length" class="tree-row empty-row" :style="'padding-left:' + (48 + depth * 20) + 'px'">
863
+ Нет назначенных участников
864
+ </div>
865
+ </div>
866
+
867
+ <!-- Подгруппа 2: Классы -->
868
+ <div ~if="expanded" class="tree-row subgroup-row classes-group-row"
869
+ :style="'padding-left:' + (28 + depth * 20) + 'px'">
870
+ <span class="expander" @tap="classesExpanded = !classesExpanded">{{classesExpanded ? '▾' : '▸'}}</span>
871
+ <oda-icon icon="odant:class" icon-size="15"></oda-icon>
872
+ <span class="sub-title" @tap="classesExpanded = !classesExpanded">Классы</span>
873
+ <span class="sub-count">({{grantedLinksCount}})</span>
874
+ <div ~if="canEdit" class="row-actions">
875
+ <button type="button" class="icon-btn setup-classes-btn" ~class="{ active: setupMode }" title="Показать полное дерево классов для настройки прав RWCD" @tap.stop="toggleSetup()">
876
+ <oda-icon icon="icons:settings" icon-size="14"></oda-icon>
877
+ <span>Настройка</span>
878
+ </button>
879
+ </div>
880
+ </div>
881
+
882
+ <div ~if="expanded && classesExpanded">
883
+ <div class="class-slot" ~for="visibleClassRows">
884
+ <div class="tree-row class-row"
885
+ :style="'padding-left:' + (48 + (depth + $for.item.classDepth) * 20) + 'px'">
886
+ <span class="expander" @tap="toggleClassNode($for.item.id)">
887
+ {{$for.item.hasChildren ? ($for.item.expanded ? '▾' : '▸') : ''}}
888
+ </span>
889
+ <oda-icon :icon="$for.item.icon" icon-size="15"></oda-icon>
890
+ <span class="class-title"
891
+ ~class="{ granted: $for.item.effectiveRank > 0, denied: $for.item.isExplicitDenied }"
892
+ :title="$for.item.id"
893
+ @tap="controller?.openClass($for.item.id)">{{$for.item.label}}</span>
894
+
895
+ <div class="rwcd-wrap">
896
+ <button ~if="canEdit && $for.item.canResetInherit"
897
+ type="button"
898
+ class="rwcd-reset"
899
+ title="Сбросить переопределение и наследовать от родителя"
900
+ @tap.stop="controller?.resetClassOverride(trail, $for.item.id)">↩</button>
901
+ <div class="rwcd-slider"
902
+ ~class="{ explicit: $for.item.isExplicit && !$for.item.isExplicitDenied, inherited: $for.item.isInherited, denied: $for.item.isExplicitDenied }"
903
+ :data-access="$for.item.effectiveAccess"
904
+ :data-explicit="$for.item.isExplicit ? '1' : '0'">
905
+ <button type="button"
906
+ class="rwcd-seg seg-none"
907
+ ~class="{ 'active-none': $for.item.effectiveRank === 0 }"
908
+ :disabled="!canEdit"
909
+ :title="$for.item.inheritedAccess ? 'Явно запретить доступ к этому классу (—)' : 'Нет доступа (—)'"
910
+ @tap.stop="onSelectAccess($for.item, 'none')">—</button>
911
+ <button type="button"
912
+ class="rwcd-seg seg-r"
913
+ ~class="{ filled: $for.item.effectiveRank >= 1 }"
914
+ :disabled="!canEdit"
915
+ title="Чтение (R)"
916
+ @tap.stop="onSelectAccess($for.item, 'read')">R</button>
917
+ <button type="button"
918
+ class="rwcd-seg seg-w"
919
+ ~class="{ filled: $for.item.effectiveRank >= 2 }"
920
+ :disabled="!canEdit"
921
+ title="Редактирование и проведение (W)"
922
+ @tap.stop="onSelectAccess($for.item, 'write')">W</button>
923
+ <button type="button"
924
+ class="rwcd-seg seg-c"
925
+ ~class="{ filled: $for.item.effectiveRank >= 3 }"
926
+ :disabled="!canEdit"
927
+ title="Создание объектов и документов (C)"
928
+ @tap.stop="onSelectAccess($for.item, 'create')">C</button>
929
+ <button type="button"
930
+ class="rwcd-seg seg-d"
931
+ ~class="{ filled: $for.item.effectiveRank >= 4 }"
932
+ :disabled="!canEdit"
933
+ title="Удаление и полный доступ к данным (D)"
934
+ @tap.stop="onSelectAccess($for.item, 'delete')">D</button>
935
+ </div>
936
+ </div>
937
+ </div>
938
+ </div>
939
+ <div ~if="!visibleClassRows.length" class="tree-row empty-row" :style="'padding-left:' + (48 + depth * 20) + 'px'">
940
+ {{canEdit ? 'Нет выданных классов — нажмите «Настройка»' : 'Нет выданных классов'}}
391
941
  </div>
392
942
  </div>
393
943
 
944
+ <!-- Совместимость со старыми вложенными подролями, если они есть в #security -->
394
945
  <staff-role-node ~for="visibleChildRoles"
395
946
  :role="$for.item"
396
947
  :prefix="trail"
@@ -414,15 +965,14 @@ if (typeof ODA === 'function' && !customElements.get('staff-role-node')) {
414
965
  networkNodeMap: {},
415
966
  setupMode: false,
416
967
  expanded: true,
968
+ usersExpanded: true,
969
+ classesExpanded: true,
417
970
  expandedClasses: {},
418
971
  dropHover: false,
419
972
  get trail() {
420
973
  const id = this.role?.id || '';
421
974
  return this.prefix ? `${this.prefix}/${id}` : id;
422
975
  },
423
- get readonly() {
424
- return isRoleReadonly(this.role);
425
- },
426
976
  get childRoles() {
427
977
  return Array.isArray(this.role?.ROLES) ? this.role.ROLES : [];
428
978
  },
@@ -430,32 +980,61 @@ if (typeof ODA === 'function' && !customElements.get('staff-role-node')) {
430
980
  return this.expanded ? this.childRoles : [];
431
981
  },
432
982
  get visibleClassRows() {
433
- return this.expanded ? this.classRows : [];
983
+ return this.expanded && this.classesExpanded ? this.classRows : [];
434
984
  },
435
985
  get memberEntries() {
436
986
  return this.controller ? this.controller.buildMemberEntries(this.role?.USERS) : [];
437
987
  },
988
+ get grantedLinksCount() {
989
+ const links = Array.isArray(this.role?.LINKS) ? this.role.LINKS : [];
990
+ return links.filter(l => {
991
+ const a = normalizeAccess(l?.access);
992
+ return a && a !== 'none';
993
+ }).length;
994
+ },
438
995
  get classRows() {
439
996
  const links = Array.isArray(this.role?.LINKS) ? this.role.LINKS : [];
440
- const checkedSet = new Set(links.map(l => l?.id).filter(Boolean));
997
+ const explicitMap = new Map();
998
+ for (const l of links) {
999
+ if (!l?.id)
1000
+ continue;
1001
+ const acc = normalizeAccess(l.access);
1002
+ if (acc)
1003
+ explicitMap.set(normPath(l.id), acc);
1004
+ }
441
1005
  const hasBaseTree = Array.isArray(this.baseClasses) && this.baseClasses.length > 0;
442
1006
  const source = hasBaseTree ? this.baseClasses : buildFallbackClassTree(links);
443
1007
  const setup = Boolean(this.setupMode);
444
1008
 
445
- const filterNodes = (nodes) => {
1009
+ const filterNodes = (nodes, inheritedAccess = null) => {
446
1010
  const res = [];
447
1011
  for (const n of Array.isArray(nodes) ? nodes : []) {
448
1012
  if (!n?.path)
449
1013
  continue;
450
- const kids = filterNodes(n.children || []);
451
- const checked = checkedSet.has(n.path);
452
- if (setup || checked || kids.length > 0) {
1014
+ const p = normPath(n.path);
1015
+ const explicitAccess = explicitMap.has(p) ? explicitMap.get(p) : null;
1016
+ const effectiveAccess = explicitAccess || inheritedAccess || 'none';
1017
+ const isExplicit = explicitAccess !== null;
1018
+ const isInherited = !isExplicit && Boolean(inheritedAccess && inheritedAccess !== 'none');
1019
+ const isExplicitDenied = isExplicit && explicitAccess === 'none' && Boolean(inheritedAccess && inheritedAccess !== 'none');
1020
+ const nextInherited = effectiveAccess !== 'none' ? effectiveAccess : null;
1021
+ const kids = filterNodes(n.children || [], nextInherited);
1022
+ const hasActiveDesc = kids.some(k => k.effectiveRank > 0 || k.isExplicitDenied || k.hasActiveDesc);
1023
+ const effectiveRank = RWCD_RANK[effectiveAccess] || 0;
1024
+ if (setup || effectiveRank > 0 || isExplicitDenied || kids.length > 0) {
453
1025
  res.push({
454
- id: n.path,
1026
+ id: p,
455
1027
  label: n.label || n.id,
456
1028
  icon: n.icon || 'odant:class',
457
- checked,
458
- hasCheckedDesc: kids.some(k => k.checked || k.hasCheckedDesc),
1029
+ explicitAccess,
1030
+ inheritedAccess: inheritedAccess && inheritedAccess !== 'none' ? inheritedAccess : '',
1031
+ effectiveAccess,
1032
+ effectiveRank,
1033
+ isExplicit,
1034
+ isInherited,
1035
+ isExplicitDenied,
1036
+ canResetInherit: isExplicit && Boolean(inheritedAccess && inheritedAccess !== 'none'),
1037
+ hasActiveDesc,
459
1038
  children: kids,
460
1039
  });
461
1040
  }
@@ -467,15 +1046,21 @@ if (typeof ODA === 'function' && !customElements.get('staff-role-node')) {
467
1046
  const pushRows = (nodes, classDepth) => {
468
1047
  for (const n of nodes) {
469
1048
  const hasChildren = Array.isArray(n.children) && n.children.length > 0;
470
- const explicit = this.expandedClasses?.[n.id];
471
- const defaultExpanded = setup ? (classDepth === 0 || n.hasCheckedDesc) : true;
472
- const expanded = typeof explicit === 'boolean' ? explicit : defaultExpanded;
1049
+ const explicitExp = this.expandedClasses?.[n.id];
1050
+ const defaultExpanded = setup ? (classDepth === 0 || n.hasActiveDesc || n.effectiveRank > 0) : true;
1051
+ const expanded = typeof explicitExp === 'boolean' ? explicitExp : defaultExpanded;
473
1052
  out.push({
474
1053
  id: n.id,
475
1054
  label: n.label,
476
1055
  icon: n.icon,
477
- checked: n.checked,
478
- setup: Boolean(this.canEdit && setup),
1056
+ explicitAccess: n.explicitAccess,
1057
+ inheritedAccess: n.inheritedAccess,
1058
+ effectiveAccess: n.effectiveAccess,
1059
+ effectiveRank: n.effectiveRank,
1060
+ isExplicit: n.isExplicit,
1061
+ isInherited: n.isInherited,
1062
+ isExplicitDenied: n.isExplicitDenied,
1063
+ canResetInherit: n.canResetInherit,
479
1064
  hasChildren,
480
1065
  expanded,
481
1066
  classDepth,
@@ -485,25 +1070,29 @@ if (typeof ODA === 'function' && !customElements.get('staff-role-node')) {
485
1070
  }
486
1071
  };
487
1072
 
488
- pushRows(filterNodes(source), 0);
1073
+ pushRows(filterNodes(source, null), 0);
489
1074
  return out;
490
1075
  },
491
- get hasChildren() {
492
- return this.classRows.length > 0 || this.childRoles.length > 0;
493
- },
494
1076
  toggleExpand() {
495
1077
  this.expanded = !this.expanded;
496
1078
  },
497
1079
  toggleSetup() {
498
1080
  this.setupMode = !this.setupMode;
499
- if (this.setupMode)
1081
+ if (this.setupMode) {
500
1082
  this.expanded = true;
1083
+ this.classesExpanded = true;
1084
+ }
501
1085
  },
502
1086
  toggleClassNode(clsPath) {
503
1087
  const row = (this.classRows || []).find(r => r.id === clsPath);
504
1088
  const cur = row ? Boolean(row.expanded) : true;
505
1089
  this.expandedClasses = { ...this.expandedClasses, [clsPath]: !cur };
506
1090
  },
1091
+ onSelectAccess(row, level) {
1092
+ if (!this.canEdit || !row?.id)
1093
+ return;
1094
+ this.controller?.setClassAccess(this.trail, row.id, level, row.inheritedAccess || '');
1095
+ },
507
1096
  onDragOver(e) {
508
1097
  if (!this.canEdit)
509
1098
  return;
@@ -519,6 +1108,9 @@ if (typeof ODA === 'function' && !customElements.get('staff-role-node')) {
519
1108
  });
520
1109
  }
521
1110
 
1111
+ // ---------------------------------------------------------------------------
1112
+ // Корневая вкладка «Система → Пользователи»
1113
+ // ---------------------------------------------------------------------------
522
1114
  export default {
523
1115
  imports: 'oda//icon, oda//button',
524
1116
  template: /*html*/`
@@ -532,6 +1124,7 @@ export default {
532
1124
  background: var(--content-background);
533
1125
  color: var(--content-color);
534
1126
  font-size: 13px;
1127
+ box-sizing: border-box;
535
1128
  }
536
1129
  .tree-box {
537
1130
  @apply --vertical;
@@ -564,48 +1157,75 @@ export default {
564
1157
  font-size: 12px;
565
1158
  color: var(--muted-color);
566
1159
  }
567
- .chip {
1160
+ .boss-pill {
568
1161
  @apply --horizontal;
569
1162
  align-items: center;
570
- gap: 5px;
571
- padding: 2px 8px 2px 4px;
572
- border-radius: 14px;
1163
+ gap: 6px;
1164
+ padding: 3px 10px 3px 5px;
1165
+ border-radius: 16px;
1166
+ border: 1px solid color-mix(in srgb, var(--accent-color, #4f46e5) 28%, var(--subtle-border));
573
1167
  background: var(--accent-soft);
574
1168
  color: var(--content-color);
575
1169
  font-size: 12.5px;
1170
+ max-width: 100%;
1171
+ box-sizing: border-box;
1172
+ transition: filter .12s ease, border-color .12s ease, background .12s ease;
1173
+ }
1174
+ .boss-pill.editable {
576
1175
  cursor: pointer;
577
1176
  }
578
- .chip.inherited {
579
- opacity: .8;
1177
+ .boss-pill.editable:hover {
1178
+ border-color: var(--accent-color, #4f46e5);
1179
+ filter: brightness(0.97);
1180
+ }
1181
+ .boss-pill.inherited {
1182
+ opacity: .75;
1183
+ background: color-mix(in srgb, var(--subtle-background) 70%, var(--content-background));
1184
+ border-style: dashed;
1185
+ border-color: var(--subtle-border);
1186
+ }
1187
+ .boss-pill.inherited.editable:hover {
1188
+ opacity: 1;
1189
+ border-style: solid;
1190
+ border-color: var(--accent-color, #4f46e5);
580
1191
  }
581
- .chip:hover {
582
- filter: brightness(0.95);
1192
+ .boss-pill .boss-name {
1193
+ font-weight: 500;
1194
+ overflow: hidden;
1195
+ text-overflow: ellipsis;
1196
+ white-space: nowrap;
583
1197
  }
584
- .chip .rm {
1198
+ .boss-pill .rm {
585
1199
  font-weight: 700;
586
1200
  opacity: .6;
587
- padding: 0 2px;
1201
+ padding: 0 3px;
588
1202
  cursor: pointer;
1203
+ border-radius: 4px;
589
1204
  }
590
- .chip .rm:hover {
1205
+ .boss-pill .rm:hover {
591
1206
  opacity: 1;
592
1207
  color: var(--error-color, #dc2626);
1208
+ background: rgba(220, 38, 38, 0.08);
1209
+ }
1210
+ .boss-pill .chev {
1211
+ opacity: .6;
1212
+ flex-shrink: 0;
593
1213
  }
594
1214
  .icon-btn {
595
1215
  border: 1px solid transparent;
596
1216
  background: transparent;
597
1217
  color: var(--muted-color);
598
1218
  border-radius: 6px;
599
- padding: 3px 7px;
1219
+ padding: 4px 9px;
600
1220
  font: inherit;
601
- font-size: 12px;
1221
+ font-size: 12.5px;
602
1222
  cursor: pointer;
603
1223
  display: inline-flex;
604
1224
  align-items: center;
605
1225
  gap: 4px;
606
1226
  }
607
1227
  .icon-btn:hover {
608
- background: var(--subtle-background);
1228
+ background: var(--content-background);
609
1229
  border-color: var(--subtle-border);
610
1230
  color: var(--content-color);
611
1231
  }
@@ -620,36 +1240,54 @@ export default {
620
1240
  color: var(--muted-color);
621
1241
  font-size: 12px;
622
1242
  }
1243
+ @media (max-width: 600px) {
1244
+ :host { padding: 8px 10px; }
1245
+ .root-row { padding: 8px 10px; }
1246
+ }
623
1247
  </style>
624
1248
 
625
1249
  <div class="tree-box">
626
- <!-- Корень дерева: Руководитель подразделения (BOSS) -->
1250
+ <!-- Корень дерева: Руководитель подразделения (BOSS) — сама плашка является кнопкой выбора -->
627
1251
  <div class="root-row" ~class="{ 'drop-hover': bossDropHover }"
628
1252
  @dragover="onBossDragOver" @dragleave="bossDropHover = false" @drop="onBossDrop">
629
1253
  <oda-icon :icon="$item?.icon || 'odant:structure'" icon-size="20"></oda-icon>
630
1254
  <span class="root-title">{{$item?.label || $item?.id}}</span>
631
1255
  <span class="boss-label">Руководитель (BOSS):</span>
632
1256
 
633
- <div ~if="visibleCurrentBoss" class="chip" title="Открыть профиль" @tap="openUser(visibleCurrentBoss.id)">
1257
+ <div ~if="visibleCurrentBoss"
1258
+ class="boss-pill"
1259
+ ~class="{ editable: canEdit }"
1260
+ :title="canEdit ? 'Нажмите, чтобы сменить руководителя (BOSS)' : visibleCurrentBoss.label"
1261
+ @tap="canEdit && openBossDropdown($event)">
634
1262
  <oda-icon round :icon="visibleCurrentBoss.icon" :icon-color="visibleCurrentBoss.iconColor" icon-size="18"></oda-icon>
635
- <span>{{visibleCurrentBoss.label}}</span>
636
- <span ~if="canEdit" class="rm" title="Снять локального руководителя" @tap.stop="clearBoss()">×</span>
1263
+ <span class="boss-name">{{visibleCurrentBoss.label}}</span>
1264
+ <span ~if="canEdit" class="rm" title="Снять локального руководителя (наследовать сверху)" @tap.stop="clearBoss()">×</span>
1265
+ <oda-icon ~if="canEdit" class="chev" icon="icons:chevron-right:90" icon-size="14"></oda-icon>
637
1266
  </div>
638
1267
 
639
- <div ~if="!visibleCurrentBoss && visibleInheritedBoss" class="chip inherited" title="Наследуется сверху" @tap="openUser(visibleInheritedBoss.id)">
1268
+ <div ~if="!visibleCurrentBoss && visibleInheritedBoss"
1269
+ class="boss-pill inherited"
1270
+ ~class="{ editable: canEdit }"
1271
+ :title="canEdit ? 'Унаследовано из «' + inheritedBossInfo.fromLabel + '». Нажмите, чтобы назначить локального руководителя' : ('Унаследовано из «' + inheritedBossInfo.fromLabel + '»')"
1272
+ @tap="canEdit && openBossDropdown($event)">
640
1273
  <oda-icon round :icon="visibleInheritedBoss.icon" :icon-color="visibleInheritedBoss.iconColor" icon-size="18"></oda-icon>
641
- <span>{{visibleInheritedBoss.label}}</span>
1274
+ <span class="boss-name">{{visibleInheritedBoss.label}}</span>
642
1275
  <span class="muted">(из «{{inheritedBossInfo.fromLabel}}»)</span>
1276
+ <oda-icon ~if="canEdit" class="chev" icon="icons:chevron-right:90" icon-size="14"></oda-icon>
643
1277
  </div>
644
1278
 
645
- <span ~if="!visibleCurrentBoss && !visibleInheritedBoss" class="muted">не назначен</span>
1279
+ <div ~if="!visibleCurrentBoss && !visibleInheritedBoss"
1280
+ class="boss-pill inherited empty-boss"
1281
+ ~class="{ editable: canEdit }"
1282
+ :title="canEdit ? 'Нажмите, чтобы назначить руководителя (BOSS)' : ''"
1283
+ @tap="canEdit && openBossDropdown($event)">
1284
+ <oda-icon icon="icons:person" icon-size="16"></oda-icon>
1285
+ <span>{{canEdit ? 'Выбрать руководителя' : '—'}}</span>
1286
+ <oda-icon ~if="canEdit" class="chev" icon="icons:chevron-right:90" icon-size="14"></oda-icon>
1287
+ </div>
646
1288
 
647
1289
  <div ~if="canEdit" class="row-actions">
648
- <button type="button" class="icon-btn" @tap="openBossDropdown($event)">
649
- <oda-icon icon="editor:mode-edit" icon-size="14"></oda-icon>
650
- <span>{{visibleCurrentBoss ? 'Сменить' : 'Назначить'}}</span>
651
- </button>
652
- <button type="button" class="icon-btn" @tap="promptAddRole('')">
1290
+ <button type="button" class="icon-btn add-role-btn" @tap="promptAddRole('')">
653
1291
  <oda-icon icon="icons:add" icon-size="15"></oda-icon>
654
1292
  <span>Роль</span>
655
1293
  </button>
@@ -682,19 +1320,20 @@ export default {
682
1320
  },
683
1321
  security: null,
684
1322
  allUsers: [],
1323
+ usersTree: [],
685
1324
  userMap: {},
686
1325
  userMetaMap: {},
687
1326
  availableStructures: [],
1327
+ organizationsTree: [],
1328
+ projectsTree: [],
688
1329
  structureMap: {},
689
1330
  availableNetworkNodes: [],
690
1331
  networkNodeMap: {},
1332
+ remoteSubjectMetaMap: {},
691
1333
  inheritedBossInfo: null,
692
1334
  baseClasses: [],
693
1335
  canEdit: false,
694
1336
  focusedTrail: '',
695
- expandedRoles: {},
696
- setupTrails: {},
697
- expandedClassNodes: {},
698
1337
  bossDropHover: false,
699
1338
  error: '',
700
1339
  get selfRef() {
@@ -742,27 +1381,98 @@ export default {
742
1381
  buildMemberEntries(usersList) {
743
1382
  const memberEntries = [];
744
1383
  for (const id of Array.isArray(usersList) ? usersList : []) {
745
- if (typeof id === 'string' && id.startsWith('/')) {
746
- const st = this.structureMap?.[id];
1384
+ if (typeof id !== 'string' || !id)
1385
+ continue;
1386
+ // Удалённый субъект внутри /NODES/<Узел>[/USERS/... | /ORGANIZATIONS/...]
1387
+ const remoteMatch = /^\/NODES\/([^/]+)(?:\/(.*))?$/i.exec(normPath(id));
1388
+ if (remoteMatch) {
1389
+ const nodeSeg = remoteMatch[1];
1390
+ const rest = remoteMatch[2] ? '/' + remoteMatch[2] : '';
1391
+ const nn = this.networkNodeMap?.[`/NODES/${nodeSeg}`] || this.networkNodeMap?.[nodeSeg] || this.networkNodeMap?.[nodeSeg.toUpperCase()];
1392
+ const nodeLabel = nn?.label || nodeSeg;
1393
+ const cached = this.remoteSubjectMetaMap?.[normPath(id)];
1394
+ if (!rest) {
1395
+ memberEntries.push({
1396
+ id,
1397
+ isNode: false,
1398
+ isNetworkNode: true,
1399
+ isRemote: true,
1400
+ isGroup: false,
1401
+ round: false,
1402
+ nodePath: nn?.path || `/NODES/${nodeSeg}`,
1403
+ label: nodeLabel,
1404
+ title: `/NODES/${nodeSeg}`,
1405
+ icon: nn?.icon || 'icons:dns',
1406
+ iconColor: '',
1407
+ tag: 'сервер сети',
1408
+ });
1409
+ }
1410
+ else {
1411
+ const isRemoteUser = /^\/USERS\/[^/]+$/i.test(rest);
1412
+ const segLabel = cached?.label || rest.split('/').filter(Boolean).pop() || id;
1413
+ memberEntries.push({
1414
+ id,
1415
+ isNode: !isRemoteUser,
1416
+ isNetworkNode: false,
1417
+ isRemote: true,
1418
+ isGroup: false,
1419
+ round: isRemoteUser,
1420
+ nodePath: normPath(id),
1421
+ label: segLabel,
1422
+ title: `${segLabel} (${nodeLabel}) — ${id}`,
1423
+ icon: cached?.icon || (isRemoteUser ? 'icons:person' : 'odant:structure'),
1424
+ iconColor: cached?.iconColor || '',
1425
+ tag: `${nodeLabel} · ${isRemoteUser ? 'пользователь' : 'подразделение'}`,
1426
+ });
1427
+ }
1428
+ continue;
1429
+ }
1430
+ if (id.startsWith('/')) {
1431
+ const st = this.structureMap?.[id] || this.structureMap?.[normPath(id)];
1432
+ const isBase = st?.type === '$base' || /^\/ORGANIZATIONS\/[^/]+$/i.test(normPath(id));
1433
+ const isProj = st?.type === '$project' || /^\/PROJECTS\/[^/]+$/i.test(normPath(id));
747
1434
  memberEntries.push({
748
1435
  id,
749
1436
  isNode: true,
750
1437
  isNetworkNode: false,
1438
+ isRemote: false,
751
1439
  isGroup: false,
1440
+ round: false,
752
1441
  label: st?.label || id.split('/').pop() || id,
753
- icon: st?.icon || 'odant:structure',
1442
+ title: id,
1443
+ icon: st?.icon || (isBase ? 'odant:base' : isProj ? 'odant:project' : 'odant:structure'),
754
1444
  iconColor: '',
1445
+ tag: isBase ? 'организация' : isProj ? 'проект' : 'подразделение',
755
1446
  });
756
1447
  }
757
- else if (id === 'USERS' || id === 'GUESTS' || id === 'GUEST') {
1448
+ else if (id === 'USERS') {
758
1449
  memberEntries.push({
759
1450
  id,
760
1451
  isNode: false,
761
1452
  isNetworkNode: false,
1453
+ isRemote: false,
762
1454
  isGroup: true,
763
- label: id === 'USERS' ? 'Все сотрудники' : 'Все гости',
764
- icon: id === 'USERS' ? 'social:people' : 'icons:public',
1455
+ round: false,
1456
+ label: 'Пользователи (/USERS)',
1457
+ title: 'Все зарегистрированные пользователи этого сервера',
1458
+ icon: 'social:people',
765
1459
  iconColor: '',
1460
+ tag: 'сервер',
1461
+ });
1462
+ }
1463
+ else if (id === 'GUESTS' || id === 'GUEST') {
1464
+ memberEntries.push({
1465
+ id,
1466
+ isNode: false,
1467
+ isNetworkNode: false,
1468
+ isRemote: false,
1469
+ isGroup: true,
1470
+ round: false,
1471
+ label: 'Гости (GUESTS)',
1472
+ title: 'Устаревшая групповая запись GUESTS',
1473
+ icon: 'icons:public',
1474
+ iconColor: '',
1475
+ tag: 'группа',
766
1476
  });
767
1477
  }
768
1478
  else if (this.networkNodeMap?.[id] || this.networkNodeMap?.[String(id).toUpperCase()]) {
@@ -771,11 +1481,15 @@ export default {
771
1481
  id,
772
1482
  isNode: false,
773
1483
  isNetworkNode: true,
1484
+ isRemote: true,
774
1485
  isGroup: false,
1486
+ round: false,
775
1487
  nodePath: nn.path,
776
1488
  label: nn.label || nn.id || id,
1489
+ title: nn.path || id,
777
1490
  icon: nn.icon || 'icons:dns',
778
1491
  iconColor: '',
1492
+ tag: 'сервер сети',
779
1493
  });
780
1494
  }
781
1495
  else if (this.userMap?.[id]) {
@@ -783,10 +1497,14 @@ export default {
783
1497
  id,
784
1498
  isNode: false,
785
1499
  isNetworkNode: false,
1500
+ isRemote: false,
786
1501
  isGroup: false,
1502
+ round: true,
787
1503
  label: this.userLabel(id),
1504
+ title: `/USERS/${id}`,
788
1505
  icon: this.userIcon(id),
789
1506
  iconColor: this.userColor(id),
1507
+ tag: 'пользователь',
790
1508
  });
791
1509
  }
792
1510
  }
@@ -840,7 +1558,6 @@ export default {
840
1558
  label: p.label || p.id,
841
1559
  icon: p.icon || '',
842
1560
  ...(p.external ? { external: true } : {}),
843
- ...(p.readonly ? { readonly: true } : {}),
844
1561
  ...(p.mine ? { mine: true } : {}),
845
1562
  USERS: Array.isArray(p.users) ? p.users : [],
846
1563
  LINKS: Array.isArray(p.links) ? p.links.map(l => ({ id: l.id, access: l.access || 'read', ...(l.scope ? { scope: l.scope } : {}) })) : [],
@@ -852,6 +1569,8 @@ export default {
852
1569
  };
853
1570
  this.baseClasses = [];
854
1571
  this.availableStructures = [];
1572
+ this.organizationsTree = [];
1573
+ this.projectsTree = [];
855
1574
  this.availableNetworkNodes = [];
856
1575
  }
857
1576
  }
@@ -870,15 +1589,30 @@ export default {
870
1589
  uMeta[u.id] = { icon: u.icon || '', iconColor: u.iconColor || '', label: u.label || u.id };
871
1590
  }
872
1591
  this.allUsers = users;
1592
+ this.usersTree = Array.isArray(ctx.usersTree) && ctx.usersTree.length
1593
+ ? ctx.usersTree
1594
+ : users.map(u => ({ ...u, path: `/USERS/${u.id}`, type: '$user', children: [] }));
873
1595
  this.userMap = uMap;
874
1596
  this.userMetaMap = uMeta;
875
1597
 
876
1598
  const structs = Array.isArray(ctx.structures) ? ctx.structures : [];
877
1599
  const sMap = {};
1600
+ const indexTree = (nodes) => {
1601
+ for (const n of Array.isArray(nodes) ? nodes : []) {
1602
+ if (n?.path)
1603
+ sMap[normPath(n.path)] = n;
1604
+ if (Array.isArray(n?.children) && n.children.length)
1605
+ indexTree(n.children);
1606
+ }
1607
+ };
878
1608
  for (const s of structs) {
879
1609
  if (s?.path)
880
- sMap[s.path] = s;
1610
+ sMap[normPath(s.path)] = s;
881
1611
  }
1612
+ this.organizationsTree = Array.isArray(ctx.organizationsTree) ? ctx.organizationsTree : [];
1613
+ this.projectsTree = Array.isArray(ctx.projectsTree) ? ctx.projectsTree : [];
1614
+ indexTree(this.organizationsTree);
1615
+ indexTree(this.projectsTree);
882
1616
  this.availableStructures = structs;
883
1617
  this.structureMap = sMap;
884
1618
 
@@ -890,7 +1624,7 @@ export default {
890
1624
  nMap[String(n.principalId).toUpperCase()] = n;
891
1625
  }
892
1626
  if (n?.id) nMap[n.id] = n;
893
- if (n?.path) nMap[n.path] = n;
1627
+ if (n?.path) nMap[normPath(n.path)] = n;
894
1628
  }
895
1629
  this.availableNetworkNodes = netNodes;
896
1630
  this.networkNodeMap = nMap;
@@ -914,6 +1648,7 @@ export default {
914
1648
  metaMap[u.id] = { icon: u.icon || u.DATA?.icon || '', iconColor: u.iconColor || '', label };
915
1649
  }
916
1650
  this.allUsers = list;
1651
+ this.usersTree = list.map(u => ({ ...u, path: `/USERS/${u.id}`, type: '$user', children: [] }));
917
1652
  this.userMap = map;
918
1653
  this.userMetaMap = metaMap;
919
1654
  }
@@ -965,7 +1700,7 @@ export default {
965
1700
  async openMember(entry) {
966
1701
  if (!entry || entry.isGroup || typeof window?.execute !== 'function')
967
1702
  return;
968
- if (entry.isNetworkNode && entry.nodePath) {
1703
+ if ((entry.isNetworkNode || entry.isRemote) && entry.nodePath) {
969
1704
  const target = await WORK.get_item(entry.nodePath).catch(() => null);
970
1705
  if (target)
971
1706
  window.execute(target);
@@ -986,6 +1721,17 @@ export default {
986
1721
  if (target)
987
1722
  window.execute(target);
988
1723
  },
1724
+ _enrichUsersTree(nodes) {
1725
+ return (Array.isArray(nodes) ? nodes : []).map(n => {
1726
+ const isUser = n.type === '$user' || (!n.children?.length && !n.type);
1727
+ return {
1728
+ ...n,
1729
+ icon: isUser ? this.userIcon(n.id) : (n.icon || 'odant:folder'),
1730
+ iconColor: isUser ? this.userColor(n.id) : '',
1731
+ children: this._enrichUsersTree(n.children || []),
1732
+ };
1733
+ });
1734
+ },
989
1735
  async openBossDropdown(e) {
990
1736
  const anchor = e?.currentTarget || e?.target || this;
991
1737
  const users = (this.allUsers || []).map(u => ({
@@ -996,6 +1742,7 @@ export default {
996
1742
  }));
997
1743
  const el = ODA.createComponent('staff-boss-menu', {
998
1744
  users,
1745
+ usersTree: this._enrichUsersTree(this.usersTree),
999
1746
  currentId: this.currentBoss,
1000
1747
  hasLocalBoss: Boolean(this.currentBoss),
1001
1748
  });
@@ -1012,43 +1759,128 @@ export default {
1012
1759
  if (picked !== undefined)
1013
1760
  await this.setBoss(picked);
1014
1761
  },
1015
- async openMemberDropdown(e, trail) {
1016
- const anchor = e?.currentTarget || e?.target || this;
1017
- const options = [];
1018
- for (const u of this.allUsers || []) {
1019
- options.push({
1020
- value: u.id,
1021
- label: u.label,
1022
- icon: this.userIcon(u.id),
1023
- iconColor: this.userColor(u.id),
1024
- round: true,
1025
- tag: 'сотрудник',
1762
+ _buildMemberTreeRoots() {
1763
+ const mapUsers = (nodes) => (Array.isArray(nodes) ? nodes : []).map(n => {
1764
+ const isUser = n.type === '$user' || (!n.children?.length && !n.type);
1765
+ return {
1766
+ key: isUser ? `user:${n.id}` : `ufolder:${n.path || n.id}`,
1767
+ value: isUser ? n.id : '',
1768
+ label: n.label || n.id,
1769
+ title: isUser ? `/USERS/${n.id}` : (n.path || n.label),
1770
+ icon: isUser ? this.userIcon(n.id) : (n.icon || 'odant:folder'),
1771
+ iconColor: isUser ? this.userColor(n.id) : '',
1772
+ round: isUser,
1773
+ tag: isUser ? 'пользователь' : '',
1774
+ selectable: isUser,
1775
+ children: mapUsers(n.children || []),
1776
+ };
1777
+ });
1778
+
1779
+ const mapStructures = (nodes) => (Array.isArray(nodes) ? nodes : []).map(s => ({
1780
+ key: `struct:${s.path}`,
1781
+ value: s.path,
1782
+ label: s.label || s.id,
1783
+ title: s.path,
1784
+ icon: s.icon || (s.type === '$base' ? 'odant:base' : s.type === '$project' ? 'odant:project' : 'odant:structure'),
1785
+ iconColor: '',
1786
+ round: false,
1787
+ tag: s.isSelf ? 'текущий узел' : (s.type === '$base' ? 'организация' : s.type === '$project' ? 'проект' : 'подразделение'),
1788
+ selectable: !s.isSelf,
1789
+ disabled: Boolean(s.isSelf && (!s.children || !s.children.length)),
1790
+ children: mapStructures(s.children || []),
1791
+ }));
1792
+
1793
+ // Если organizationsTree/projectsTree пусты (например, старый бэкенд или мок), собираем из плоского availableStructures
1794
+ let orgChildren = mapStructures(this.organizationsTree);
1795
+ let projChildren = mapStructures(this.projectsTree);
1796
+ if (!orgChildren.length && !projChildren.length && this.availableStructures?.length) {
1797
+ orgChildren = mapStructures(this.availableStructures.filter(s => !String(s.path || '').startsWith('/PROJECTS/')));
1798
+ projChildren = mapStructures(this.availableStructures.filter(s => String(s.path || '').startsWith('/PROJECTS/')));
1799
+ }
1800
+
1801
+ const nodeChildren = (this.availableNetworkNodes || []).map(n => ({
1802
+ key: `net:${n.path || n.id}`,
1803
+ value: n.principalId || n.path || n.id,
1804
+ label: n.label || n.id,
1805
+ title: `${n.label || n.id} (${n.path || n.principalId})`,
1806
+ icon: n.icon || 'icons:dns',
1807
+ iconColor: '',
1808
+ round: false,
1809
+ tag: 'сервер сети',
1810
+ selectable: true,
1811
+ lazyPath: n.path ? normPath(n.path) : '',
1812
+ remoteNodeLabel: n.label || n.id,
1813
+ children: Array.isArray(n.children) ? n.children : [],
1814
+ }));
1815
+
1816
+ const roots = [
1817
+ {
1818
+ key: 'root:users',
1819
+ value: 'USERS',
1820
+ label: 'Пользователи',
1821
+ title: 'Выбрать всех пользователей (/USERS) или раскрыть список',
1822
+ icon: 'social:people',
1823
+ iconColor: '',
1824
+ round: false,
1825
+ tag: 'все на сервере',
1826
+ selectable: true,
1827
+ isGroupRoot: true,
1828
+ children: mapUsers(this.usersTree),
1829
+ },
1830
+ ];
1831
+ if (orgChildren.length) {
1832
+ roots.push({
1833
+ key: 'root:orgs',
1834
+ value: '',
1835
+ label: 'Организации',
1836
+ icon: 'odant:base',
1837
+ iconColor: '',
1838
+ round: false,
1839
+ tag: '',
1840
+ selectable: false,
1841
+ isGroupRoot: true,
1842
+ children: orgChildren,
1026
1843
  });
1027
1844
  }
1028
- for (const s of this.availableStructures || []) {
1029
- options.push({
1030
- value: s.path,
1031
- label: s.label,
1032
- icon: s.icon || 'odant:structure',
1845
+ if (projChildren.length) {
1846
+ roots.push({
1847
+ key: 'root:projects',
1848
+ value: '',
1849
+ label: 'Проекты',
1850
+ icon: 'odant:project',
1033
1851
  iconColor: '',
1034
1852
  round: false,
1035
- tag: 'подразделение',
1853
+ tag: '',
1854
+ selectable: false,
1855
+ isGroupRoot: true,
1856
+ children: projChildren,
1036
1857
  });
1037
1858
  }
1038
- for (const n of this.availableNetworkNodes || []) {
1039
- options.push({
1040
- value: n.principalId || n.id,
1041
- label: n.label,
1042
- icon: n.icon || 'icons:dns',
1859
+ if (nodeChildren.length) {
1860
+ roots.push({
1861
+ key: 'root:nodes',
1862
+ value: '',
1863
+ label: 'Сеть',
1864
+ icon: 'icons:dns',
1043
1865
  iconColor: '',
1044
1866
  round: false,
1045
- tag: 'сервер сети',
1867
+ tag: '',
1868
+ selectable: false,
1869
+ isGroupRoot: true,
1870
+ children: nodeChildren,
1046
1871
  });
1047
1872
  }
1048
- options.push({ value: 'USERS', label: 'Все сотрудники', icon: 'social:people', iconColor: '', round: false, tag: 'группа' });
1049
- options.push({ value: 'GUESTS', label: 'Все гости', icon: 'icons:public', iconColor: '', round: false, tag: 'группа' });
1050
-
1051
- const el = ODA.createComponent('staff-member-menu', { options });
1873
+ return roots;
1874
+ },
1875
+ async openMemberDropdown(e, trail) {
1876
+ const anchor = e?.currentTarget || e?.target || this;
1877
+ const treeRoots = this._buildMemberTreeRoots();
1878
+ const el = ODA.createComponent('staff-member-menu', {
1879
+ treeRoots,
1880
+ remoteMetaCollector: (pathKey, meta) => {
1881
+ this.remoteSubjectMetaMap = { ...this.remoteSubjectMetaMap, [normPath(pathKey)]: meta };
1882
+ },
1883
+ });
1052
1884
  let picked;
1053
1885
  try {
1054
1886
  picked = await WORK.showDropdown(el, { TITLE: { label: 'Добавить участника' }, placement: 'bottom' }, anchor);
@@ -1087,7 +1919,7 @@ export default {
1087
1919
  e.preventDefault();
1088
1920
  const dropped = parseDroppedItem(e);
1089
1921
  if (!isDroppedUser(dropped)) {
1090
- this.error = 'Для назначения руководителя перетащите пользователя из дерева.';
1922
+ this.error = 'Для назначения руководителя перетащите пользователя из /USERS.';
1091
1923
  return;
1092
1924
  }
1093
1925
  const uid = dropped.id || dropped.path.split('/').pop();
@@ -1108,39 +1940,29 @@ export default {
1108
1940
  return;
1109
1941
  }
1110
1942
  if (isDroppedNetworkNode(dropped)) {
1111
- const byMap = this.networkNodeMap?.[dropped.path] || this.networkNodeMap?.[dropped.id];
1112
- let memberId = byMap?.principalId || byMap?.id || '';
1943
+ const byMap = this.networkNodeMap?.[normPath(dropped.path)] || this.networkNodeMap?.[dropped.id];
1944
+ let memberId = byMap?.principalId || byMap?.path || dropped.path || '';
1113
1945
  if (!memberId && dropped.path) {
1114
1946
  const item = await WORK.get_item(dropped.path).catch(() => null);
1115
- memberId = item?.DATA?.host_id ? String(item.DATA.host_id).toUpperCase() : (item?.id || dropped.id);
1947
+ memberId = item?.DATA?.host_id ? String(item.DATA.host_id).toUpperCase() : (item?.path || dropped.path);
1116
1948
  }
1117
1949
  if (memberId)
1118
1950
  await this._addMemberToRole(trail, memberId);
1119
1951
  return;
1120
1952
  }
1953
+ if (isDroppedRemoteSubject(dropped)) {
1954
+ await this._addMemberToRole(trail, normPath(dropped.path));
1955
+ return;
1956
+ }
1121
1957
  if (isDroppedStructure(dropped)) {
1122
- if (dropped.path && dropped.path !== this.$item?.path)
1123
- await this._addMemberToRole(trail, dropped.path);
1958
+ if (dropped.path && normPath(dropped.path) !== normPath(this.$item?.path || ''))
1959
+ await this._addMemberToRole(trail, normPath(dropped.path));
1124
1960
  return;
1125
1961
  }
1126
1962
  if (isDroppedClass(dropped) && dropped.path) {
1127
- await this.toggleClassInRole(trail, dropped.path, true);
1963
+ await this.setClassAccess(trail, normPath(dropped.path), 'read', '');
1128
1964
  }
1129
1965
  },
1130
- toggleRoleExpand(trail) {
1131
- const cur = this.expandedRoles?.[trail] !== false;
1132
- this.expandedRoles = { ...this.expandedRoles, [trail]: !cur };
1133
- },
1134
- toggleRoleSetup(trail) {
1135
- const cur = Boolean(this.setupTrails?.[trail]);
1136
- this.setupTrails = { ...this.setupTrails, [trail]: !cur };
1137
- if (!cur)
1138
- this.expandedRoles = { ...this.expandedRoles, [trail]: true };
1139
- },
1140
- toggleClassNodeExpand(trail, clsPath, curExpanded = true) {
1141
- const key = `${trail}::${clsPath}`;
1142
- this.expandedClassNodes = { ...this.expandedClassNodes, [key]: !curExpanded };
1143
- },
1144
1966
  _findRoleMut(sec, trail) {
1145
1967
  const steps = String(trail || '').split('/').filter(Boolean);
1146
1968
  let list = Array.isArray(sec.ROLES) ? sec.ROLES : [];
@@ -1166,10 +1988,6 @@ export default {
1166
1988
  if (!targetList.some(r => r.id === id)) {
1167
1989
  targetList.push({ id, label, USERS: [], LINKS: [] });
1168
1990
  }
1169
- if (parentTrail)
1170
- this.expandedRoles = { ...this.expandedRoles, [parentTrail]: true };
1171
- const newTrail = parentTrail ? `${parentTrail}/${id}` : id;
1172
- this.setupTrails = { ...this.setupTrails, [newTrail]: true };
1173
1991
  await this.persist(sec, `Создана роль «${label}»`, `В подразделении ${this.$item?.path || ''} добавлена роль «${label}».`);
1174
1992
  },
1175
1993
  async promptRenameRole(trail, currentLabel = '') {
@@ -1184,19 +2002,6 @@ export default {
1184
2002
  node.label = label;
1185
2003
  await this.persist(sec, `Переименована роль «${label}»`, `Роль ${trail} переименована в «${label}».`);
1186
2004
  },
1187
- async toggleRoleReadonly(trail, readonly) {
1188
- const sec = JSON.parse(JSON.stringify(this.security || {}));
1189
- const node = this._findRoleMut(sec, trail);
1190
- if (!node)
1191
- return;
1192
- if (readonly)
1193
- node.readonly = true;
1194
- else
1195
- delete node.readonly;
1196
- const access = readonly ? 'read' : 'write';
1197
- node.LINKS = (Array.isArray(node.LINKS) ? node.LINKS : []).map(l => ({ ...l, access }));
1198
- await this.persist(sec, `Режим роли «${node.label || node.id}»: ${readonly ? 'только просмотр' : 'просмотр и изменение'}`, `Для всех классов роли «${node.label || node.id}» установлен доступ: ${access}.`);
1199
- },
1200
2005
  async toggleRoleExternal(trail, checked) {
1201
2006
  const sec = JSON.parse(JSON.stringify(this.security || {}));
1202
2007
  const node = this._findRoleMut(sec, trail);
@@ -1213,9 +2018,9 @@ export default {
1213
2018
  let confirmed = false;
1214
2019
  try {
1215
2020
  if (typeof WORK?.showConfirm === 'function')
1216
- confirmed = await WORK.showConfirm(`Удалить роль «${title}» и все вложенные подроли?`);
2021
+ confirmed = await WORK.showConfirm(`Удалить роль «${title}»?`);
1217
2022
  else
1218
- confirmed = window.confirm(`Удалить роль «${title}» и все вложенные подроли?`);
2023
+ confirmed = window.confirm(`Удалить роль «${title}»?`);
1219
2024
  }
1220
2025
  catch {
1221
2026
  return;
@@ -1255,20 +2060,54 @@ export default {
1255
2060
  node.USERS = node.USERS.filter(id => id !== memberId);
1256
2061
  await this.persist(sec, `Из роли «${node.label || node.id}» исключён участник`, `Из роли «${node.label || node.id}» удалён ${memberId}.`);
1257
2062
  },
1258
- async toggleClassInRole(trail, clsPath, checked) {
2063
+ async setClassAccess(trail, clsPath, level, inheritedAccess = '') {
2064
+ const acc = normalizeAccess(level);
2065
+ if (!acc)
2066
+ return;
2067
+ const cleanPath = normPath(clsPath);
1259
2068
  const sec = JSON.parse(JSON.stringify(this.security || {}));
1260
2069
  const node = this._findRoleMut(sec, trail);
1261
2070
  if (!node)
1262
2071
  return;
2072
+ delete node.readonly;
1263
2073
  node.LINKS = Array.isArray(node.LINKS) ? node.LINKS : [];
1264
- const access = isRoleReadonly(node) ? 'read' : 'write';
1265
- if (checked) {
1266
- if (!node.LINKS.some(l => l?.id === clsPath))
1267
- node.LINKS.push({ id: clsPath, access });
2074
+ const existingIdx = node.LINKS.findIndex(l => normPath(l?.id) === cleanPath);
2075
+ const existingScope = existingIdx >= 0 ? node.LINKS[existingIdx]?.scope : undefined;
2076
+
2077
+ if (acc === 'none' && !inheritedAccess) {
2078
+ // Без унаследованного права сверху просто убираем ссылку из роли
2079
+ if (existingIdx >= 0)
2080
+ node.LINKS.splice(existingIdx, 1);
2081
+ else
2082
+ return;
1268
2083
  }
1269
2084
  else {
1270
- node.LINKS = node.LINKS.filter(l => l?.id !== clsPath);
2085
+ const nextEntry = { id: cleanPath, access: acc, ...(existingScope ? { scope: existingScope } : {}) };
2086
+ if (existingIdx >= 0)
2087
+ node.LINKS[existingIdx] = nextEntry;
2088
+ else
2089
+ node.LINKS.push(nextEntry);
1271
2090
  }
1272
- await this.persist(sec, `Обновлён доступ к классу в роли «${node.label || node.id}»`, `Роль «${node.label || node.id}»: класс ${clsPath} ${checked ? 'добавлен (' + access + ')' : 'убран'}.`);
2091
+ await this.persist(
2092
+ sec,
2093
+ `Изменён доступ к классу в роли «${node.label || node.id}»`,
2094
+ `Роль «${node.label || node.id}»: класс ${cleanPath} → ${accessLabelRu(acc)}.`
2095
+ );
2096
+ },
2097
+ async resetClassOverride(trail, clsPath) {
2098
+ const cleanPath = normPath(clsPath);
2099
+ const sec = JSON.parse(JSON.stringify(this.security || {}));
2100
+ const node = this._findRoleMut(sec, trail);
2101
+ if (!node || !Array.isArray(node.LINKS))
2102
+ return;
2103
+ const before = node.LINKS.length;
2104
+ node.LINKS = node.LINKS.filter(l => normPath(l?.id) !== cleanPath);
2105
+ if (node.LINKS.length === before)
2106
+ return;
2107
+ await this.persist(
2108
+ sec,
2109
+ `Сброшено переопределение класса в роли «${node.label || node.id}»`,
2110
+ `Роль «${node.label || node.id}»: класс ${cleanPath} возвращён к наследованию от родителя.`
2111
+ );
1273
2112
  },
1274
2113
  };