odant-work 1.0.77 → 1.0.79

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.
@@ -55,16 +55,468 @@ function isDroppedClass(info) {
55
55
  return String(info.path || '').includes('/MODULES/');
56
56
  }
57
57
 
58
- function splitClassTitle(rawPath, mapEntry) {
59
- if (mapEntry && typeof mapEntry === 'object')
60
- return mapEntry;
61
- const clean = String(rawPath || '')
62
- .replace(/^\/(?:ORGANIZATIONS|PROJECTS)\/[^/]+\/MODULES\//, '')
63
- .replace(/^\/MODULES\//, '');
64
- const parts = clean.split('/').filter(Boolean);
65
- const title = parts.length ? parts[parts.length - 1] : clean;
66
- const section = parts.length > 1 ? parts.slice(0, -1).join(' / ') : '';
67
- return { title, section, icon: 'odant:class' };
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
+ function buildFallbackClassTree(links) {
68
+ const out = [];
69
+ for (const l of Array.isArray(links) ? links : []) {
70
+ if (!l?.id)
71
+ continue;
72
+ const clean = String(l.id).replace(/^\/(?:ORGANIZATIONS|PROJECTS)\/[^/]+\/MODULES\//, '').replace(/^\/MODULES\//, '');
73
+ const label = clean.split('/').filter(Boolean).pop() || clean;
74
+ out.push({ id: label, path: l.id, label, type: '$class', icon: 'odant:class', children: [] });
75
+ }
76
+ return out;
77
+ }
78
+
79
+ if (typeof ODA === 'function' && !customElements.get('staff-boss-menu')) {
80
+ ODA({
81
+ is: 'staff-boss-menu',
82
+ imports: 'oda//icon',
83
+ template: /*html*/`
84
+ <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; }
89
+ .it:hover { background: var(--accent-soft, rgba(37, 99, 235, 0.1)); }
90
+ .it.active { font-weight: 600; background: var(--subtle-background); }
91
+ .sep { height: 1px; background: var(--subtle-border); margin: 4px 0; }
92
+ </style>
93
+ <input class="search" type="text" placeholder="Поиск сотрудника…" ::value="query">
94
+ <div class="list">
95
+ <div class="it" ~if="hasLocalBoss" @tap="pick('')">
96
+ <oda-icon icon="icons:undo" icon-size="16"></oda-icon>
97
+ <span>Наследовать сверху</span>
98
+ </div>
99
+ <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>
102
+ <span>{{$for.item.label}}</span>
103
+ </div>
104
+ </div>
105
+ `,
106
+ users: [],
107
+ currentId: '',
108
+ hasLocalBoss: false,
109
+ query: '',
110
+ get filtered() {
111
+ const q = String(this.query || '').trim().toLowerCase();
112
+ return (this.users || []).filter(u => !q || String(u.label || '').toLowerCase().includes(q));
113
+ },
114
+ pick(id) {
115
+ this.parentElement?.close?.(id);
116
+ },
117
+ });
118
+ }
119
+
120
+ if (typeof ODA === 'function' && !customElements.get('staff-member-menu')) {
121
+ ODA({
122
+ is: 'staff-member-menu',
123
+ imports: 'oda//icon',
124
+ template: /*html*/`
125
+ <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; }
130
+ .it:hover { background: var(--accent-soft, rgba(37, 99, 235, 0.1)); }
131
+ .tag { margin-left: auto; font-size: 11px; color: var(--muted-color); }
132
+ </style>
133
+ <input class="search" type="text" placeholder="Поиск человека, отдела или сервера…" ::value="query">
134
+ <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>
139
+ </div>
140
+ </div>
141
+ `,
142
+ options: [],
143
+ query: '',
144
+ get filteredOptions() {
145
+ 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));
147
+ },
148
+ pick(val) {
149
+ this.parentElement?.close?.(val);
150
+ },
151
+ });
152
+ }
153
+
154
+ if (typeof ODA === 'function' && !customElements.get('staff-role-node')) {
155
+ ODA({
156
+ is: 'staff-role-node',
157
+ imports: 'oda//icon',
158
+ template: /*html*/`
159
+ <style>
160
+ :host {
161
+ @apply --vertical;
162
+ display: flex;
163
+ }
164
+ .tree-row {
165
+ @apply --horizontal;
166
+ align-items: center;
167
+ gap: 6px;
168
+ padding: 5px 12px;
169
+ min-height: 32px;
170
+ border-bottom: 1px solid color-mix(in srgb, var(--subtle-border) 50%, transparent);
171
+ flex-wrap: wrap;
172
+ }
173
+ .tree-row.role-row {
174
+ background: var(--content-background);
175
+ }
176
+ .tree-row.role-row:hover {
177
+ background: color-mix(in srgb, var(--subtle-background) 65%, transparent);
178
+ }
179
+ .tree-row.role-row.drop-hover {
180
+ background: color-mix(in srgb, var(--accent-color, #2563eb) 10%, var(--content-background));
181
+ outline: 1px dashed var(--accent-color, #2563eb);
182
+ outline-offset: -2px;
183
+ }
184
+ .tree-row.class-row {
185
+ min-height: 28px;
186
+ padding-top: 3px;
187
+ padding-bottom: 3px;
188
+ background: color-mix(in srgb, var(--subtle-background) 32%, var(--content-background));
189
+ }
190
+ .tree-row.class-row:hover {
191
+ background: var(--subtle-background);
192
+ }
193
+ .expander {
194
+ width: 16px;
195
+ height: 16px;
196
+ display: inline-flex;
197
+ align-items: center;
198
+ justify-content: center;
199
+ cursor: pointer;
200
+ color: var(--muted-color);
201
+ user-select: none;
202
+ border-radius: 4px;
203
+ flex-shrink: 0;
204
+ }
205
+ .expander:hover {
206
+ background: var(--subtle-background);
207
+ color: var(--content-color);
208
+ }
209
+ .role-name {
210
+ font-weight: 600;
211
+ font-size: 13.5px;
212
+ }
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;
230
+ cursor: pointer;
231
+ }
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);
235
+ }
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);
239
+ }
240
+ .chip:hover {
241
+ filter: brightness(0.95);
242
+ }
243
+ .chip .rm {
244
+ font-weight: 700;
245
+ opacity: .6;
246
+ padding: 0 2px;
247
+ cursor: pointer;
248
+ }
249
+ .chip .rm:hover {
250
+ opacity: 1;
251
+ color: var(--error-color, #dc2626);
252
+ }
253
+ .badge {
254
+ font-size: 11px;
255
+ font-weight: 600;
256
+ padding: 1px 6px;
257
+ border-radius: 8px;
258
+ background: var(--accent-soft);
259
+ color: var(--accent-color);
260
+ }
261
+ .badge.ext {
262
+ background: light-dark(#fef3c7, #422006);
263
+ color: light-dark(#92400e, #fcd34d);
264
+ }
265
+ .icon-btn {
266
+ border: 1px solid transparent;
267
+ background: transparent;
268
+ color: var(--muted-color);
269
+ border-radius: 6px;
270
+ padding: 3px 7px;
271
+ font: inherit;
272
+ font-size: 12px;
273
+ cursor: pointer;
274
+ display: inline-flex;
275
+ align-items: center;
276
+ gap: 4px;
277
+ }
278
+ .icon-btn:hover {
279
+ background: var(--subtle-background);
280
+ border-color: var(--subtle-border);
281
+ color: var(--content-color);
282
+ }
283
+ .icon-btn.active {
284
+ background: var(--accent-soft);
285
+ color: var(--accent-color);
286
+ border-color: color-mix(in srgb, var(--accent-color) 35%, transparent);
287
+ font-weight: 600;
288
+ }
289
+ .icon-btn.danger:hover {
290
+ color: var(--error-color, #dc2626);
291
+ }
292
+ .row-actions {
293
+ @apply --horizontal;
294
+ align-items: center;
295
+ gap: 4px;
296
+ margin-left: auto;
297
+ flex-wrap: wrap;
298
+ }
299
+ .ro-toggle {
300
+ @apply --horizontal;
301
+ align-items: center;
302
+ gap: 4px;
303
+ font-size: 12px;
304
+ color: var(--muted-color);
305
+ cursor: pointer;
306
+ user-select: none;
307
+ padding: 2px 6px;
308
+ border-radius: 6px;
309
+ }
310
+ .ro-toggle:hover {
311
+ background: var(--subtle-background);
312
+ color: var(--content-color);
313
+ }
314
+ .class-title {
315
+ cursor: pointer;
316
+ }
317
+ .class-title.checked {
318
+ font-weight: 500;
319
+ }
320
+ .class-title:hover {
321
+ color: var(--accent-color);
322
+ text-decoration: underline;
323
+ }
324
+ </style>
325
+
326
+ <div class="tree-row role-row"
327
+ ~class="{ 'drop-hover': dropHover }"
328
+ :style="'padding-left:' + (12 + depth * 22) + 'px'"
329
+ @dragover="onDragOver($event)"
330
+ @dragleave="dropHover = false"
331
+ @drop="onDrop($event)">
332
+
333
+ <span class="expander" @tap="toggleExpand()">
334
+ {{hasChildren ? (expanded ? '▾' : '▸') : ''}}
335
+ </span>
336
+ <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>
338
+ <span ~if="role?.external" class="badge ext">клиент</span>
339
+ <span ~if="role?.mine" class="badge">ваша роль</span>
340
+
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
+ <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
+ <button type="button" class="icon-btn" title="Переименовать роль" @tap="controller?.promptRenameRole(trail, role?.label || role?.id)">
370
+ <oda-icon icon="editor:mode-edit" icon-size="13"></oda-icon>
371
+ </button>
372
+ <button type="button" class="icon-btn" ~class="{ active: role?.external }" title="Внешний клиент (CLIENT)" @tap="controller?.toggleRoleExternal(trail, !role?.external)">
373
+ <oda-icon icon="icons:public" icon-size="13"></oda-icon>
374
+ </button>
375
+ <button type="button" class="icon-btn danger" title="Удалить роль" @tap="controller?.removeRole(trail, role?.label || role?.id)">
376
+ <oda-icon icon="icons:delete" icon-size="14"></oda-icon>
377
+ </button>
378
+ </div>
379
+ </div>
380
+
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>
391
+ </div>
392
+ </div>
393
+
394
+ <staff-role-node ~for="visibleChildRoles"
395
+ :role="$for.item"
396
+ :prefix="trail"
397
+ :depth="depth + 1"
398
+ :controller="controller"
399
+ :can-edit="canEdit"
400
+ :base-classes="baseClasses"
401
+ :user-map="userMap"
402
+ :structure-map="structureMap"
403
+ :network-node-map="networkNodeMap">
404
+ </staff-role-node>
405
+ `,
406
+ role: null,
407
+ prefix: '',
408
+ depth: 0,
409
+ controller: null,
410
+ canEdit: false,
411
+ baseClasses: [],
412
+ userMap: {},
413
+ structureMap: {},
414
+ networkNodeMap: {},
415
+ setupMode: false,
416
+ expanded: true,
417
+ expandedClasses: {},
418
+ dropHover: false,
419
+ get trail() {
420
+ const id = this.role?.id || '';
421
+ return this.prefix ? `${this.prefix}/${id}` : id;
422
+ },
423
+ get readonly() {
424
+ return isRoleReadonly(this.role);
425
+ },
426
+ get childRoles() {
427
+ return Array.isArray(this.role?.ROLES) ? this.role.ROLES : [];
428
+ },
429
+ get visibleChildRoles() {
430
+ return this.expanded ? this.childRoles : [];
431
+ },
432
+ get visibleClassRows() {
433
+ return this.expanded ? this.classRows : [];
434
+ },
435
+ get memberEntries() {
436
+ return this.controller ? this.controller.buildMemberEntries(this.role?.USERS) : [];
437
+ },
438
+ get classRows() {
439
+ const links = Array.isArray(this.role?.LINKS) ? this.role.LINKS : [];
440
+ const checkedSet = new Set(links.map(l => l?.id).filter(Boolean));
441
+ const hasBaseTree = Array.isArray(this.baseClasses) && this.baseClasses.length > 0;
442
+ const source = hasBaseTree ? this.baseClasses : buildFallbackClassTree(links);
443
+ const setup = Boolean(this.setupMode);
444
+
445
+ const filterNodes = (nodes) => {
446
+ const res = [];
447
+ for (const n of Array.isArray(nodes) ? nodes : []) {
448
+ if (!n?.path)
449
+ continue;
450
+ const kids = filterNodes(n.children || []);
451
+ const checked = checkedSet.has(n.path);
452
+ if (setup || checked || kids.length > 0) {
453
+ res.push({
454
+ id: n.path,
455
+ label: n.label || n.id,
456
+ icon: n.icon || 'odant:class',
457
+ checked,
458
+ hasCheckedDesc: kids.some(k => k.checked || k.hasCheckedDesc),
459
+ children: kids,
460
+ });
461
+ }
462
+ }
463
+ return res;
464
+ };
465
+
466
+ const out = [];
467
+ const pushRows = (nodes, classDepth) => {
468
+ for (const n of nodes) {
469
+ 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;
473
+ out.push({
474
+ id: n.id,
475
+ label: n.label,
476
+ icon: n.icon,
477
+ checked: n.checked,
478
+ setup: Boolean(this.canEdit && setup),
479
+ hasChildren,
480
+ expanded,
481
+ classDepth,
482
+ });
483
+ if (hasChildren && expanded)
484
+ pushRows(n.children, classDepth + 1);
485
+ }
486
+ };
487
+
488
+ pushRows(filterNodes(source), 0);
489
+ return out;
490
+ },
491
+ get hasChildren() {
492
+ return this.classRows.length > 0 || this.childRoles.length > 0;
493
+ },
494
+ toggleExpand() {
495
+ this.expanded = !this.expanded;
496
+ },
497
+ toggleSetup() {
498
+ this.setupMode = !this.setupMode;
499
+ if (this.setupMode)
500
+ this.expanded = true;
501
+ },
502
+ toggleClassNode(clsPath) {
503
+ const row = (this.classRows || []).find(r => r.id === clsPath);
504
+ const cur = row ? Boolean(row.expanded) : true;
505
+ this.expandedClasses = { ...this.expandedClasses, [clsPath]: !cur };
506
+ },
507
+ onDragOver(e) {
508
+ if (!this.canEdit)
509
+ return;
510
+ e.preventDefault();
511
+ if (e.dataTransfer)
512
+ e.dataTransfer.dropEffect = 'copy';
513
+ this.dropHover = true;
514
+ },
515
+ onDrop(e) {
516
+ this.dropHover = false;
517
+ this.controller?.onRoleDrop(e, this.trail);
518
+ },
519
+ });
68
520
  }
69
521
 
70
522
  export default {
@@ -98,7 +550,7 @@ export default {
98
550
  flex-wrap: wrap;
99
551
  transition: background .15s;
100
552
  }
101
- .root-row.drop-hover, .tree-row.drop-hover {
553
+ .root-row.drop-hover {
102
554
  background: color-mix(in srgb, var(--accent-color, #2563eb) 10%, var(--content-background));
103
555
  outline: 1px dashed var(--accent-color, #2563eb);
104
556
  outline-offset: -2px;
@@ -112,60 +564,6 @@ export default {
112
564
  font-size: 12px;
113
565
  color: var(--muted-color);
114
566
  }
115
- .tree-row {
116
- @apply --horizontal;
117
- align-items: center;
118
- gap: 6px;
119
- padding: 6px 12px;
120
- min-height: 34px;
121
- border-bottom: 1px solid color-mix(in srgb, var(--subtle-border) 55%, transparent);
122
- flex-wrap: wrap;
123
- }
124
- .tree-row:last-child {
125
- border-bottom: none;
126
- }
127
- .tree-row.role-row {
128
- background: var(--content-background);
129
- }
130
- .tree-row.role-row:hover {
131
- background: color-mix(in srgb, var(--subtle-background) 65%, transparent);
132
- }
133
- .tree-row.class-row {
134
- min-height: 30px;
135
- padding-top: 4px;
136
- padding-bottom: 4px;
137
- background: color-mix(in srgb, var(--subtle-background) 35%, var(--content-background));
138
- }
139
- .tree-row.class-row:hover {
140
- background: var(--subtle-background);
141
- }
142
- .expander {
143
- width: 18px;
144
- height: 18px;
145
- display: inline-flex;
146
- align-items: center;
147
- justify-content: center;
148
- cursor: pointer;
149
- color: var(--muted-color);
150
- user-select: none;
151
- border-radius: 4px;
152
- }
153
- .expander:hover {
154
- background: var(--subtle-background);
155
- color: var(--content-color);
156
- }
157
- .role-name {
158
- font-weight: 600;
159
- font-size: 13.5px;
160
- }
161
- .members-wrap {
162
- @apply --horizontal;
163
- align-items: center;
164
- gap: 5px;
165
- flex-wrap: wrap;
166
- flex: 1;
167
- min-width: 140px;
168
- }
169
567
  .chip {
170
568
  @apply --horizontal;
171
569
  align-items: center;
@@ -178,15 +576,7 @@ export default {
178
576
  cursor: pointer;
179
577
  }
180
578
  .chip.inherited {
181
- opacity: .75;
182
- }
183
- .chip.node-chip {
184
- background: color-mix(in srgb, #0284c7 13%, var(--content-background));
185
- border: 1px solid color-mix(in srgb, #0284c7 28%, transparent);
186
- }
187
- .chip.net-chip {
188
- background: color-mix(in srgb, #7c3aed 12%, var(--content-background));
189
- border: 1px solid color-mix(in srgb, #7c3aed 28%, transparent);
579
+ opacity: .8;
190
580
  }
191
581
  .chip:hover {
192
582
  filter: brightness(0.95);
@@ -201,18 +591,6 @@ export default {
201
591
  opacity: 1;
202
592
  color: var(--error-color, #dc2626);
203
593
  }
204
- .badge {
205
- font-size: 11px;
206
- font-weight: 600;
207
- padding: 1px 6px;
208
- border-radius: 8px;
209
- background: var(--accent-soft);
210
- color: var(--accent-color);
211
- }
212
- .badge.ext {
213
- background: light-dark(#fef3c7, #422006);
214
- color: light-dark(#92400e, #fcd34d);
215
- }
216
594
  .icon-btn {
217
595
  border: 1px solid transparent;
218
596
  background: transparent;
@@ -231,79 +609,12 @@ export default {
231
609
  border-color: var(--subtle-border);
232
610
  color: var(--content-color);
233
611
  }
234
- .icon-btn.active {
235
- background: var(--accent-soft);
236
- color: var(--accent-color);
237
- border-color: color-mix(in srgb, var(--accent-color) 35%, transparent);
238
- }
239
- .icon-btn.danger:hover {
240
- color: var(--error-color, #dc2626);
241
- }
242
612
  .row-actions {
243
613
  @apply --horizontal;
244
614
  align-items: center;
245
- gap: 2px;
246
- margin-left: auto;
247
- }
248
- .class-title {
249
- font-weight: 500;
250
- cursor: pointer;
251
- }
252
- .class-title:hover {
253
- color: var(--accent-color);
254
- text-decoration: underline;
255
- }
256
- .class-section {
257
- font-size: 11.5px;
258
- color: var(--muted-color);
259
- }
260
- .write-check {
261
- @apply --horizontal;
262
- align-items: center;
263
- gap: 5px;
264
- font-size: 12.5px;
265
- cursor: pointer;
266
- user-select: none;
615
+ gap: 4px;
267
616
  margin-left: auto;
268
- padding-right: 6px;
269
- }
270
- .inline-panel {
271
- @apply --vertical;
272
- gap: 8px;
273
- padding: 10px 14px;
274
- background: var(--subtle-background);
275
- border-bottom: 1px solid var(--subtle-border);
276
- }
277
- .panel-list {
278
- @apply --vertical;
279
- gap: 2px;
280
- max-height: 220px;
281
- overflow-y: auto;
282
- border: 1px solid var(--subtle-border);
283
- border-radius: 6px;
284
- padding: 4px;
285
- background: var(--content-background);
286
- }
287
- .panel-item {
288
- @apply --horizontal;
289
- align-items: center;
290
- gap: 8px;
291
- padding: 5px 8px;
292
- border-radius: 5px;
293
- cursor: pointer;
294
- font-size: 13px;
295
- }
296
- .panel-item:hover {
297
- background: var(--subtle-background);
298
- }
299
- input[type="text"] {
300
- padding: 5px 8px;
301
- border: 1px solid var(--control-border-color, var(--subtle-border));
302
- border-radius: 6px;
303
- font: inherit;
304
- font-size: 13px;
305
- background: var(--content-background);
306
- color: var(--control-color, inherit);
617
+ flex-wrap: wrap;
307
618
  }
308
619
  .muted {
309
620
  color: var(--muted-color);
@@ -312,196 +623,52 @@ export default {
312
623
  </style>
313
624
 
314
625
  <div class="tree-box">
315
- <!-- Корень дерева: BOSS подразделения -->
626
+ <!-- Корень дерева: Руководитель подразделения (BOSS) -->
316
627
  <div class="root-row" ~class="{ 'drop-hover': bossDropHover }"
317
628
  @dragover="onBossDragOver" @dragleave="bossDropHover = false" @drop="onBossDrop">
318
629
  <oda-icon :icon="$item?.icon || 'odant:structure'" icon-size="20"></oda-icon>
319
630
  <span class="root-title">{{$item?.label || $item?.id}}</span>
320
631
  <span class="boss-label">Руководитель (BOSS):</span>
321
632
 
322
- <div ~if="visibleCurrentBoss" class="chip" title="Открыть профиль" @tap="openUser(visibleCurrentBoss)">
323
- <oda-icon round :icon="userIcon(visibleCurrentBoss)" :icon-color="userColor(visibleCurrentBoss)" icon-size="18"></oda-icon>
324
- <span>{{userLabel(visibleCurrentBoss)}}</span>
633
+ <div ~if="visibleCurrentBoss" class="chip" title="Открыть профиль" @tap="openUser(visibleCurrentBoss.id)">
634
+ <oda-icon round :icon="visibleCurrentBoss.icon" :icon-color="visibleCurrentBoss.iconColor" icon-size="18"></oda-icon>
635
+ <span>{{visibleCurrentBoss.label}}</span>
325
636
  <span ~if="canEdit" class="rm" title="Снять локального руководителя" @tap.stop="clearBoss()">×</span>
326
637
  </div>
327
638
 
328
- <div ~if="!visibleCurrentBoss && visibleInheritedBoss" class="chip inherited" title="Наследуется сверху" @tap="openUser(visibleInheritedBoss)">
329
- <oda-icon round :icon="userIcon(visibleInheritedBoss)" :icon-color="userColor(visibleInheritedBoss)" icon-size="18"></oda-icon>
330
- <span>{{userLabel(visibleInheritedBoss)}}</span>
331
- <span class="muted">({{inheritedBossInfo.fromLabel}})</span>
639
+ <div ~if="!visibleCurrentBoss && visibleInheritedBoss" class="chip inherited" title="Наследуется сверху" @tap="openUser(visibleInheritedBoss.id)">
640
+ <oda-icon round :icon="visibleInheritedBoss.icon" :icon-color="visibleInheritedBoss.iconColor" icon-size="18"></oda-icon>
641
+ <span>{{visibleInheritedBoss.label}}</span>
642
+ <span class="muted">(из «{{inheritedBossInfo.fromLabel}}»)</span>
332
643
  </div>
333
644
 
334
645
  <span ~if="!visibleCurrentBoss && !visibleInheritedBoss" class="muted">не назначен</span>
335
646
 
336
647
  <div ~if="canEdit" class="row-actions">
337
- <button type="button" class="icon-btn" @tap="toggleBossPicker()">
648
+ <button type="button" class="icon-btn" @tap="openBossDropdown($event)">
338
649
  <oda-icon icon="editor:mode-edit" icon-size="14"></oda-icon>
339
650
  <span>{{visibleCurrentBoss ? 'Сменить' : 'Назначить'}}</span>
340
651
  </button>
341
- <button type="button" class="icon-btn" @tap="openAddRole('')">
652
+ <button type="button" class="icon-btn" @tap="promptAddRole('')">
342
653
  <oda-icon icon="icons:add" icon-size="15"></oda-icon>
343
654
  <span>Роль</span>
344
655
  </button>
345
656
  </div>
346
657
  </div>
347
658
 
348
- <!-- Выбор руководителя -->
349
- <div ~if="canEdit && bossPickerOpen" class="inline-panel">
350
- <div class="horizontal" style="gap:8px;align-items:center;">
351
- <input type="text" placeholder="Поиск сотрудника…" ::value="bossSearch" style="flex:1;">
352
- <oda-button ~if="currentBoss" @tap="clearBoss()">Наследовать сверху</oda-button>
353
- <oda-button icon="icons:close" @tap="bossPickerOpen = false">Закрыть</oda-button>
354
- </div>
355
- <div class="panel-list">
356
- <div ~if="!filteredBossUsers.length" class="muted" style="padding:6px;">Пользователи не найдены</div>
357
- <div class="panel-item" ~for="filteredBossUsers" @tap="pickBoss($for.item.id)">
358
- <oda-icon round :icon="userIcon($for.item.id)" :icon-color="userColor($for.item.id)" icon-size="18"></oda-icon>
359
- <span>{{$for.item.label}}</span>
360
- </div>
361
- </div>
362
- </div>
363
-
364
- <!-- Добавление корневой роли -->
365
- <div ~if="canEdit && addingRoleParent === ''" class="inline-panel">
366
- <div class="horizontal" style="gap:8px;align-items:center;">
367
- <input type="text" placeholder="Название новой роли…" ::value="newRoleLabel" style="flex:1;" @keydown="onNewRoleKey($event)">
368
- <oda-button icon="icons:check" info-invert @tap="confirmAddRole()">Добавить</oda-button>
369
- <oda-button icon="icons:close" @tap="cancelAddRole()">Отмена</oda-button>
370
- </div>
371
- </div>
372
-
373
- <div ~if="!treeRows.length" class="muted" style="padding:16px;">Ролей пока нет</div>
374
-
375
- <!-- Единое дерево ролей и классов -->
376
- <div ~for="treeRows" style="display:contents;">
377
- <!-- Строка роли -->
378
- <div ~if="$for.item.kind === 'role'" class="tree-row role-row"
379
- ~class="{ 'drop-hover': dropHoverTrail === $for.item.trail }"
380
- :style="'padding-left:' + (12 + $for.item.depth * 24) + 'px'"
381
- @dragover="onRoleDragOver($event, $for.item.trail)"
382
- @dragleave="onRoleDragLeave($for.item.trail)"
383
- @drop="onRoleDrop($event, $for.item.trail)">
384
-
385
- <span class="expander" @tap="toggleRoleExpand($for.item.trail)">
386
- {{$for.item.hasChildren ? ($for.item.expanded ? '▾' : '▸') : ''}}
387
- </span>
388
- <oda-icon :icon="$for.item.external ? 'icons:public' : 'fontawesome:s-user-tie'" icon-size="16"></oda-icon>
389
- <span class="role-name">{{$for.item.label}}</span>
390
- <span ~if="$for.item.external" class="badge ext">клиент</span>
391
- <span ~if="$for.item.mine" class="badge">ваша роль</span>
392
-
393
- <div class="members-wrap">
394
- <div class="chip" ~for="$for.item.memberEntries"
395
- ~class="{ 'node-chip': $for.$for.item.isNode, 'net-chip': $for.$for.item.isNetworkNode }"
396
- @tap="openMember($for.$for.item)">
397
- <oda-icon :round="!$for.$for.item.isNode && !$for.$for.item.isNetworkNode && !$for.$for.item.isGroup" :icon="$for.$for.item.icon" :icon-color="$for.$for.item.iconColor" icon-size="16"></oda-icon>
398
- <span>{{$for.$for.item.label}}</span>
399
- <span ~if="canEdit" class="rm" title="Убрать из роли" @tap.stop="removeRoleMember($for.item.trail, $for.$for.item.id)">×</span>
400
- </div>
401
- <button ~if="canEdit" type="button" class="icon-btn" title="Добавить участника (человека, подразделение или сервер сети)" @tap="toggleMemberPicker($for.item.trail)">
402
- <oda-icon icon="icons:add" icon-size="14"></oda-icon>
403
- </button>
404
- </div>
405
-
406
- <div ~if="canEdit" class="row-actions">
407
- <button type="button" class="icon-btn" title="Привязать классы" @tap="toggleClassPicker($for.item.trail)">
408
- <oda-icon icon="icons:add" icon-size="14"></oda-icon>
409
- <span>Класс</span>
410
- </button>
411
- <button type="button" class="icon-btn" title="Добавить дочернюю роль" @tap="openAddRole($for.item.trail)">
412
- <oda-icon icon="icons:add" icon-size="14"></oda-icon>
413
- <span>Подроль</span>
414
- </button>
415
- <button type="button" class="icon-btn" ~class="{ active: $for.item.external }" title="Режим внешнего клиента (CLIENT)" @tap="toggleRoleExternal($for.item.trail, !$for.item.external)">
416
- <oda-icon icon="icons:public" icon-size="14"></oda-icon>
417
- </button>
418
- <button type="button" class="icon-btn danger" title="Удалить роль" @tap="removeRole($for.item.trail)">
419
- <oda-icon icon="icons:delete" icon-size="14"></oda-icon>
420
- </button>
421
- </div>
422
- </div>
423
-
424
- <!-- Инлайн-добавление дочерней роли -->
425
- <div ~if="$for.item.kind === 'role' && canEdit && addingRoleParent === $for.item.trail"
426
- class="inline-panel" :style="'padding-left:' + (36 + $for.item.depth * 24) + 'px'">
427
- <div class="horizontal" style="gap:8px;align-items:center;">
428
- <input type="text" placeholder="Название дочерней роли…" ::value="newRoleLabel" style="flex:1;" @keydown="onNewRoleKey($event)">
429
- <oda-button icon="icons:check" info-invert @tap="confirmAddRole()">Добавить</oda-button>
430
- <oda-button icon="icons:close" @tap="cancelAddRole()">Отмена</oda-button>
431
- </div>
432
- </div>
433
-
434
- <!-- Инлайн-выбор участника (сотрудники / подразделения / серверы сети) -->
435
- <div ~if="$for.item.kind === 'role' && canEdit && memberPickerTrail === $for.item.trail"
436
- class="inline-panel" :style="'padding-left:' + (36 + $for.item.depth * 24) + 'px'">
437
- <div class="horizontal" style="gap:8px;align-items:center;">
438
- <input type="text" placeholder="Поиск человека, подразделения или сервера сети…" ::value="memberSearch" style="flex:1;">
439
- <oda-button icon="icons:close" @tap="closeMemberPicker()">Закрыть</oda-button>
440
- </div>
441
- <div class="panel-list">
442
- <div class="panel-item" ~for="filteredUsers" @tap="pickMember($for.item.trail, $for.$for.item.id)">
443
- <oda-icon round :icon="userIcon($for.$for.item.id)" :icon-color="userColor($for.$for.item.id)" icon-size="18"></oda-icon>
444
- <span>{{$for.$for.item.label}}</span>
445
- </div>
446
- <div class="panel-item" ~for="filteredStructures" @tap="pickMember($for.item.trail, $for.$for.item.path)">
447
- <oda-icon :icon="$for.$for.item.icon || 'odant:structure'" icon-size="18"></oda-icon>
448
- <span>{{$for.$for.item.label}}</span>
449
- <span class="muted">подразделение</span>
450
- </div>
451
- <div class="panel-item" ~for="filteredNetworkNodes" @tap="pickMember($for.item.trail, $for.$for.item.principalId || $for.$for.item.id)">
452
- <oda-icon :icon="$for.$for.item.icon || 'icons:dns'" icon-size="18"></oda-icon>
453
- <span>{{$for.$for.item.label}}</span>
454
- <span class="muted">сервер сети</span>
455
- </div>
456
- <div class="panel-item" @tap="pickMember($for.item.trail, 'USERS')">
457
- <oda-icon icon="social:people" icon-size="18"></oda-icon>
458
- <span>Все сотрудники</span>
459
- </div>
460
- <div class="panel-item" @tap="pickMember($for.item.trail, 'GUESTS')">
461
- <oda-icon icon="icons:public" icon-size="18"></oda-icon>
462
- <span>Все гости</span>
463
- </div>
464
- </div>
465
- </div>
466
-
467
- <!-- Инлайн-дерево выбора классов -->
468
- <div ~if="$for.item.kind === 'role' && canEdit && pickerTrail === $for.item.trail"
469
- class="inline-panel" :style="'padding-left:' + (36 + $for.item.depth * 24) + 'px'">
470
- <div class="horizontal" style="gap:8px;align-items:center;">
471
- <input type="text" placeholder="Поиск класса…" ::value="classSearch" style="flex:1;">
472
- <oda-button icon="icons:check" info-invert :disabled="!selectedPickerCount" @tap="applyClassPicker($for.item.trail)">
473
- Добавить ({{selectedPickerCount}})
474
- </oda-button>
475
- <oda-button icon="icons:close" @tap="closeClassPicker()">Закрыть</oda-button>
476
- </div>
477
- <div class="panel-list">
478
- <div ~if="!visibleClassNodes.length" class="muted" style="padding:6px;">Классы не найдены</div>
479
- <div class="panel-item" ~for="visibleClassNodes" :style="'padding-left:' + (6 + $for.$for.item.depth * 18) + 'px'">
480
- <span ~if="$for.$for.item.hasChildren" style="width:14px;text-align:center;font-weight:700;" @tap.stop="toggleClassExpand($for.$for.item.path)">
481
- {{$for.$for.item.expanded ? '▾' : '▸'}}
482
- </span>
483
- <span ~if="!$for.$for.item.hasChildren" style="width:14px;"></span>
484
- <input ~if="$for.$for.item.selectable" type="checkbox" :checked="$for.$for.item.checked" @change="togglePickerCheck($for.$for.item.path, $event.target.checked)">
485
- <oda-icon :icon="$for.$for.item.icon" icon-size="16"></oda-icon>
486
- <span style="flex:1;" @tap="onPickerLabelTap($for.$for.item)">{{$for.$for.item.label}}</span>
487
- </div>
488
- </div>
489
- </div>
659
+ <div ~if="!rootRoles.length" class="muted" style="padding:16px;">Ролей пока нет</div>
490
660
 
491
- <!-- Строка привязанного класса внутри роли -->
492
- <div ~if="$for.item.kind === 'class'" class="tree-row class-row"
493
- :style="'padding-left:' + (28 + $for.item.depth * 24) + 'px'">
494
- <oda-icon :icon="$for.item.icon" icon-size="15"></oda-icon>
495
- <span class="class-title" :title="$for.item.id" @tap="openClass($for.item.id)">{{$for.item.title}}</span>
496
- <span ~if="$for.item.section" class="class-section">{{$for.item.section}}</span>
497
- <label class="write-check" title="Разрешить создание и изменение записей">
498
- <input type="checkbox" :checked="$for.item.isWrite" :disabled="!canEdit"
499
- @change="updateRoleLinkAccess($for.item.trail, $for.item.id, $event.target.checked ? 'write' : 'read')">
500
- <span>Изменение</span>
501
- </label>
502
- <button ~if="canEdit" type="button" class="icon-btn danger" title="Отвязать класс" @tap="removeRoleLink($for.item.trail, $for.item.id)">×</button>
503
- </div>
504
- </div>
661
+ <staff-role-node ~for="rootRoles"
662
+ :role="$for.item"
663
+ :prefix="''"
664
+ :depth="0"
665
+ :controller="selfRef"
666
+ :can-edit="canEdit"
667
+ :base-classes="baseClasses"
668
+ :user-map="userMap"
669
+ :structure-map="structureMap"
670
+ :network-node-map="networkNodeMap">
671
+ </staff-role-node>
505
672
  </div>
506
673
 
507
674
  <div ~if="error" style="color:var(--error-color, #dc2626);font-size:12.5px;">{{error}}</div>
@@ -522,24 +689,20 @@ export default {
522
689
  availableNetworkNodes: [],
523
690
  networkNodeMap: {},
524
691
  inheritedBossInfo: null,
525
- classTreeRoots: [],
526
- classMap: {},
692
+ baseClasses: [],
527
693
  canEdit: false,
528
694
  focusedTrail: '',
529
695
  expandedRoles: {},
530
- bossPickerOpen: false,
531
- bossSearch: '',
532
- addingRoleParent: null,
533
- newRoleLabel: '',
534
- memberPickerTrail: '',
535
- memberSearch: '',
536
- pickerTrail: '',
537
- classSearch: '',
538
- expandedClassPaths: {},
539
- pickerChecked: {},
696
+ setupTrails: {},
697
+ expandedClassNodes: {},
540
698
  bossDropHover: false,
541
- dropHoverTrail: '',
542
699
  error: '',
700
+ get selfRef() {
701
+ return this;
702
+ },
703
+ get rootRoles() {
704
+ return Array.isArray(this.security?.ROLES) ? this.security.ROLES : [];
705
+ },
543
706
  async attached() {
544
707
  if (this.$item)
545
708
  await this.reload();
@@ -556,189 +719,78 @@ export default {
556
719
  get visibleCurrentBoss() {
557
720
  const id = this.currentBoss;
558
721
  if (!id)
559
- return '';
560
- return this.userMap?.[id] ? id : '';
722
+ return null;
723
+ return {
724
+ id,
725
+ label: this.userMap?.[id] || id,
726
+ icon: this.userIcon(id),
727
+ iconColor: this.userColor(id),
728
+ };
561
729
  },
562
730
  get visibleInheritedBoss() {
563
- const id = this.inheritedBossInfo?.users?.[0] || '';
564
- if (!id)
565
- return '';
566
- return this.userMap?.[id] ? id : '';
567
- },
568
- get filteredBossUsers() {
569
- const q = String(this.bossSearch || '').trim().toLowerCase();
570
- return (this.allUsers || []).filter(u =>
571
- !q || u.label.toLowerCase().includes(q)
572
- );
573
- },
574
- get filteredUsers() {
575
- const q = String(this.memberSearch || '').trim().toLowerCase();
576
- if (!q)
577
- return this.allUsers || [];
578
- return (this.allUsers || []).filter(u => u.label.toLowerCase().includes(q));
579
- },
580
- get filteredStructures() {
581
- const q = String(this.memberSearch || '').trim().toLowerCase();
582
- if (!q)
583
- return this.availableStructures || [];
584
- return (this.availableStructures || []).filter(s => String(s.label || '').toLowerCase().includes(q));
585
- },
586
- get filteredNetworkNodes() {
587
- const q = String(this.memberSearch || '').trim().toLowerCase();
588
- if (!q)
589
- return this.availableNetworkNodes || [];
590
- return (this.availableNetworkNodes || []).filter(n =>
591
- String(n.label || '').toLowerCase().includes(q)
592
- || String(n.id || '').toLowerCase().includes(q)
593
- || String(n.origin || '').toLowerCase().includes(q)
594
- );
731
+ const first = this.inheritedBossInfo?.users?.[0];
732
+ if (!first?.id)
733
+ return null;
734
+ return {
735
+ id: first.id,
736
+ label: first.label || this.userMap?.[first.id] || first.id,
737
+ icon: first.icon || this.userIcon(first.id),
738
+ iconColor: first.iconColor || this.userColor(first.id),
739
+ missing: Boolean(first.missing),
740
+ };
595
741
  },
596
- get treeRows() {
597
- const rows = [];
598
- const walk = (roles, prefix = '', depth = 0) => {
599
- for (const r of Array.isArray(roles) ? roles : []) {
600
- if (!r?.id)
601
- continue;
602
- const trail = prefix ? `${prefix}/${r.id}` : r.id;
603
- const links = Array.isArray(r.LINKS) ? r.LINKS : [];
604
- const childRoles = Array.isArray(r.ROLES) ? r.ROLES : [];
605
- const hasChildren = links.length > 0 || childRoles.length > 0;
606
- const expanded = this.expandedRoles?.[trail] !== false;
607
-
608
- const memberEntries = [];
609
- for (const id of Array.isArray(r.USERS) ? r.USERS : []) {
610
- if (typeof id === 'string' && id.startsWith('/')) {
611
- const st = this.structureMap?.[id];
612
- if (!st && !Object.keys(this.structureMap || {}).length) {
613
- memberEntries.push({
614
- id,
615
- isNode: true,
616
- isGroup: false,
617
- label: id.split('/').pop() || id,
618
- icon: 'odant:structure',
619
- iconColor: '',
620
- });
621
- }
622
- else if (st) {
623
- memberEntries.push({
624
- id,
625
- isNode: true,
626
- isGroup: false,
627
- label: st.label || id.split('/').pop() || id,
628
- icon: st.icon || 'odant:structure',
629
- iconColor: '',
630
- });
631
- }
632
- }
633
- else if (id === 'USERS' || id === 'GUESTS' || id === 'GUEST') {
634
- memberEntries.push({
635
- id,
636
- isNode: false,
637
- isNetworkNode: false,
638
- isGroup: true,
639
- label: id === 'USERS' ? 'Все сотрудники' : 'Все гости',
640
- icon: id === 'USERS' ? 'social:people' : 'icons:public',
641
- iconColor: '',
642
- });
643
- }
644
- else if (this.networkNodeMap?.[id] || this.networkNodeMap?.[String(id).toUpperCase()]) {
645
- const nn = this.networkNodeMap[id] || this.networkNodeMap[String(id).toUpperCase()];
646
- memberEntries.push({
647
- id,
648
- isNode: false,
649
- isNetworkNode: true,
650
- isGroup: false,
651
- nodePath: nn.path,
652
- label: nn.label || nn.id || id,
653
- icon: nn.icon || 'icons:dns',
654
- iconColor: '',
655
- });
656
- }
657
- else if (this.userMap?.[id]) {
658
- memberEntries.push({
659
- id,
660
- isNode: false,
661
- isNetworkNode: false,
662
- isGroup: false,
663
- label: this.userLabel(id),
664
- icon: this.userIcon(id),
665
- iconColor: this.userColor(id),
666
- });
667
- }
668
- }
669
-
670
- rows.push({
671
- kind: 'role',
672
- trail,
673
- id: r.id,
674
- label: r.label || r.id,
675
- depth,
676
- hasChildren,
677
- expanded,
678
- external: Boolean(r.external),
679
- mine: Boolean(r.mine),
680
- memberEntries,
742
+ buildMemberEntries(usersList) {
743
+ const memberEntries = [];
744
+ for (const id of Array.isArray(usersList) ? usersList : []) {
745
+ if (typeof id === 'string' && id.startsWith('/')) {
746
+ const st = this.structureMap?.[id];
747
+ memberEntries.push({
748
+ id,
749
+ isNode: true,
750
+ isNetworkNode: false,
751
+ isGroup: false,
752
+ label: st?.label || id.split('/').pop() || id,
753
+ icon: st?.icon || 'odant:structure',
754
+ iconColor: '',
681
755
  });
682
-
683
- if (expanded) {
684
- for (const l of links) {
685
- if (!l?.id)
686
- continue;
687
- const info = splitClassTitle(l.id, this.classMap?.[l.id]);
688
- rows.push({
689
- kind: 'class',
690
- trail,
691
- id: l.id,
692
- depth,
693
- title: info.title,
694
- section: info.section,
695
- icon: info.icon || 'odant:class',
696
- isWrite: l.access === 'write',
697
- });
698
- }
699
- if (childRoles.length)
700
- walk(childRoles, trail, depth + 1);
701
- }
702
756
  }
703
- };
704
- walk(this.security?.ROLES || [], '', 0);
705
- return rows;
706
- },
707
- get selectedPickerCount() {
708
- return Object.keys(this.pickerChecked || {}).filter(k => this.pickerChecked[k]).length;
709
- },
710
- get visibleClassNodes() {
711
- const q = String(this.classSearch || '').trim().toLowerCase();
712
- const out = [];
713
- const matchSubtree = (node) => {
714
- const selfMatch = String(node.label || '').toLowerCase().includes(q);
715
- const kids = Array.isArray(node.children) ? node.children : [];
716
- if (!q)
717
- return { match: true };
718
- return { match: selfMatch || kids.some(k => matchSubtree(k).match) };
719
- };
720
- const walk = (nodes, depth = 0) => {
721
- for (const n of Array.isArray(nodes) ? nodes : []) {
722
- const kids = Array.isArray(n.children) ? n.children : [];
723
- if (!matchSubtree(n).match)
724
- continue;
725
- const expanded = q ? true : Boolean(this.expandedClassPaths?.[n.path] ?? (depth === 0));
726
- out.push({
727
- path: n.path,
728
- label: n.label,
729
- depth,
730
- icon: n.icon || 'odant:class',
731
- selectable: Boolean(n.selectable),
732
- hasChildren: kids.length > 0,
733
- expanded,
734
- checked: Boolean(this.pickerChecked?.[n.path]),
757
+ else if (id === 'USERS' || id === 'GUESTS' || id === 'GUEST') {
758
+ memberEntries.push({
759
+ id,
760
+ isNode: false,
761
+ isNetworkNode: false,
762
+ isGroup: true,
763
+ label: id === 'USERS' ? 'Все сотрудники' : 'Все гости',
764
+ icon: id === 'USERS' ? 'social:people' : 'icons:public',
765
+ iconColor: '',
735
766
  });
736
- if (kids.length && expanded)
737
- walk(kids, depth + 1);
738
767
  }
739
- };
740
- walk(this.classTreeRoots || [], 0);
741
- return out;
768
+ else if (this.networkNodeMap?.[id] || this.networkNodeMap?.[String(id).toUpperCase()]) {
769
+ const nn = this.networkNodeMap[id] || this.networkNodeMap[String(id).toUpperCase()];
770
+ memberEntries.push({
771
+ id,
772
+ isNode: false,
773
+ isNetworkNode: true,
774
+ isGroup: false,
775
+ nodePath: nn.path,
776
+ label: nn.label || nn.id || id,
777
+ icon: nn.icon || 'icons:dns',
778
+ iconColor: '',
779
+ });
780
+ }
781
+ else if (this.userMap?.[id]) {
782
+ memberEntries.push({
783
+ id,
784
+ isNode: false,
785
+ isNetworkNode: false,
786
+ isGroup: false,
787
+ label: this.userLabel(id),
788
+ icon: this.userIcon(id),
789
+ iconColor: this.userColor(id),
790
+ });
791
+ }
792
+ }
793
+ return memberEntries;
742
794
  },
743
795
  userLabel(uid) {
744
796
  return this.userMap?.[uid] || uid;
@@ -765,27 +817,30 @@ export default {
765
817
  try {
766
818
  this.canEdit = !!(WORK?.DEV_MODE || await (this.$item.isBoss ?? this.$item.isAdmin));
767
819
  if (this.canEdit) {
768
- const body = await this.$item.body;
769
- this.security = JSON.parse(JSON.stringify(body?.['#security'] || {}));
770
- await Promise.all([
771
- this.loadUsers(),
772
- this.loadAvailableClasses(),
773
- this.loadAvailableStructures(),
774
- this.loadNetworkNodes(),
820
+ const [body, ctx] = await Promise.all([
821
+ this.$item.body,
822
+ this.$item.fetch?.('agent_staff_context').catch(() => null),
775
823
  ]);
824
+ this.security = JSON.parse(JSON.stringify(body?.['#security'] || {}));
825
+ if (ctx) {
826
+ this._applyStaffContext(ctx);
827
+ }
828
+ else {
829
+ await this.loadUsersFallback();
830
+ }
776
831
  }
777
832
  else {
778
833
  const [bossList, placesRes] = await Promise.all([
779
834
  Promise.resolve(this.$item.bosses).catch(() => []),
780
835
  this.$item.fetch('places').catch(() => ({ places: [] })),
781
- this.loadUsers(),
782
- this.loadNetworkNodes(),
836
+ this.loadUsersFallback(),
783
837
  ]);
784
838
  const toRoles = (list) => (Array.isArray(list) ? list : []).map(p => ({
785
839
  id: p.id,
786
840
  label: p.label || p.id,
787
841
  icon: p.icon || '',
788
842
  ...(p.external ? { external: true } : {}),
843
+ ...(p.readonly ? { readonly: true } : {}),
789
844
  ...(p.mine ? { mine: true } : {}),
790
845
  USERS: Array.isArray(p.users) ? p.users : [],
791
846
  LINKS: Array.isArray(p.links) ? p.links.map(l => ({ id: l.id, access: l.access || 'read', ...(l.scope ? { scope: l.scope } : {}) })) : [],
@@ -795,16 +850,55 @@ export default {
795
850
  BOSS: Array.isArray(bossList) ? bossList.map(u => u?.id || u).filter(Boolean).slice(0, 1) : [],
796
851
  ROLES: toRoles(placesRes?.places),
797
852
  };
798
- this.classTreeRoots = [];
853
+ this.baseClasses = [];
799
854
  this.availableStructures = [];
855
+ this.availableNetworkNodes = [];
800
856
  }
801
- await this.loadInheritedBoss();
802
857
  }
803
858
  catch (e) {
804
859
  this.error = String(e?.message || e);
805
860
  }
806
861
  },
807
- async loadUsers() {
862
+ _applyStaffContext(ctx) {
863
+ const users = Array.isArray(ctx.users) ? ctx.users : [];
864
+ const uMap = {};
865
+ const uMeta = {};
866
+ for (const u of users) {
867
+ if (!u?.id)
868
+ continue;
869
+ uMap[u.id] = u.label || u.id;
870
+ uMeta[u.id] = { icon: u.icon || '', iconColor: u.iconColor || '', label: u.label || u.id };
871
+ }
872
+ this.allUsers = users;
873
+ this.userMap = uMap;
874
+ this.userMetaMap = uMeta;
875
+
876
+ const structs = Array.isArray(ctx.structures) ? ctx.structures : [];
877
+ const sMap = {};
878
+ for (const s of structs) {
879
+ if (s?.path)
880
+ sMap[s.path] = s;
881
+ }
882
+ this.availableStructures = structs;
883
+ this.structureMap = sMap;
884
+
885
+ const netNodes = Array.isArray(ctx.networkNodes) ? ctx.networkNodes : [];
886
+ const nMap = {};
887
+ for (const n of netNodes) {
888
+ if (n?.principalId) {
889
+ nMap[n.principalId] = n;
890
+ nMap[String(n.principalId).toUpperCase()] = n;
891
+ }
892
+ if (n?.id) nMap[n.id] = n;
893
+ if (n?.path) nMap[n.path] = n;
894
+ }
895
+ this.availableNetworkNodes = netNodes;
896
+ this.networkNodeMap = nMap;
897
+
898
+ this.inheritedBossInfo = ctx.inheritedBoss || null;
899
+ this.baseClasses = Array.isArray(ctx.baseClasses) ? ctx.baseClasses : [];
900
+ },
901
+ async loadUsersFallback() {
808
902
  try {
809
903
  const uRoot = (await WORK.get_item('/USERS')) || (await WORK.get_item('/users'));
810
904
  const items = (await uRoot?.items) || [];
@@ -817,11 +911,7 @@ export default {
817
911
  const label = u.label || u.DATA?.label || u.id;
818
912
  list.push({ id: u.id, label });
819
913
  map[u.id] = label;
820
- metaMap[u.id] = {
821
- icon: u.icon || u.DATA?.icon || '',
822
- iconColor: u.iconColor || '',
823
- label,
824
- };
914
+ metaMap[u.id] = { icon: u.icon || u.DATA?.icon || '', iconColor: u.iconColor || '', label };
825
915
  }
826
916
  this.allUsers = list;
827
917
  this.userMap = map;
@@ -829,101 +919,6 @@ export default {
829
919
  }
830
920
  catch { /* ignore */ }
831
921
  },
832
- async loadAvailableStructures() {
833
- if (!this.$item?.fetch)
834
- return;
835
- try {
836
- const res = await this.$item.fetch('agent_structures_list');
837
- const list = Array.isArray(res?.structures) ? res.structures : [];
838
- const map = {};
839
- for (const s of list) {
840
- if (s?.path)
841
- map[s.path] = s;
842
- }
843
- this.availableStructures = list;
844
- this.structureMap = map;
845
- }
846
- catch {
847
- this.availableStructures = [];
848
- }
849
- },
850
- async loadNetworkNodes() {
851
- if (!this.$item?.fetch)
852
- return;
853
- try {
854
- const res = await this.$item.fetch('agent_network_nodes');
855
- const list = Array.isArray(res?.nodes) ? res.nodes : [];
856
- const map = {};
857
- for (const n of list) {
858
- if (n?.principalId) {
859
- map[n.principalId] = n;
860
- map[String(n.principalId).toUpperCase()] = n;
861
- }
862
- if (n?.id) map[n.id] = n;
863
- if (n?.path) map[n.path] = n;
864
- }
865
- this.availableNetworkNodes = list;
866
- this.networkNodeMap = map;
867
- }
868
- catch {
869
- this.availableNetworkNodes = [];
870
- }
871
- },
872
- async loadInheritedBoss() {
873
- if (this.currentBoss || !this.$item?.path) {
874
- this.inheritedBossInfo = null;
875
- return;
876
- }
877
- try {
878
- const segs = String(this.$item.path || '').split('/').filter(Boolean);
879
- for (let i = segs.length - 1; i >= 0; i--) {
880
- const pPath = i === 0 ? '/' : '/' + segs.slice(0, i).join('/');
881
- const anc = CORE?.$item?.ITEMS?.[pPath] || await WORK.get_item(pPath).catch(() => null);
882
- if (!anc)
883
- continue;
884
- let ids = Array.isArray(anc?.DATA?.roleIds?.BOSS) ? anc.DATA.roleIds.BOSS : null;
885
- if (!ids) {
886
- const b = await Promise.resolve(anc.bosses).catch(() => []);
887
- ids = Array.isArray(b) ? b.map(u => u?.id || u).filter(Boolean) : [];
888
- }
889
- if (ids.length) {
890
- this.inheritedBossInfo = {
891
- fromPath: pPath,
892
- fromLabel: anc.label || anc.DATA?.label || anc.id || (pPath === '/' ? 'WORK' : pPath),
893
- users: ids.slice(0, 1),
894
- };
895
- return;
896
- }
897
- }
898
- }
899
- catch { /* ignore */ }
900
- this.inheritedBossInfo = null;
901
- },
902
- async loadAvailableClasses() {
903
- try {
904
- const res = this.$item?.fetch ? await this.$item.fetch('agent_available_classes').catch(() => null) : null;
905
- const roots = Array.isArray(res?.roots) ? res.roots : [];
906
- const map = {};
907
- const indexNodes = (nodes) => {
908
- for (const n of Array.isArray(nodes) ? nodes : []) {
909
- if (n?.path && n.selectable) {
910
- const base = splitClassTitle(n.shortPath || n.path);
911
- map[n.path] = {
912
- title: n.label || base.title,
913
- section: base.section,
914
- icon: n.icon || 'odant:class',
915
- };
916
- }
917
- if (Array.isArray(n?.children))
918
- indexNodes(n.children);
919
- }
920
- };
921
- indexNodes(roots);
922
- this.classTreeRoots = roots;
923
- this.classMap = map;
924
- }
925
- catch { /* ignore */ }
926
- },
927
922
  async persist(nextSec, auditTitle = '', auditSummary = '') {
928
923
  this.error = '';
929
924
  try {
@@ -943,7 +938,6 @@ export default {
943
938
  }
944
939
  this.$item.reset?.();
945
940
  this.$item.fire?.('changed', { value: null });
946
- await this.loadInheritedBoss();
947
941
  try {
948
942
  if (window.top && window.top !== window && window.top.CORE?.$item?.ITEMS) {
949
943
  const topItems = window.top.CORE.$item.ITEMS;
@@ -992,13 +986,81 @@ export default {
992
986
  if (target)
993
987
  window.execute(target);
994
988
  },
995
- toggleBossPicker() {
996
- this.bossPickerOpen = !this.bossPickerOpen;
997
- this.bossSearch = '';
989
+ async openBossDropdown(e) {
990
+ const anchor = e?.currentTarget || e?.target || this;
991
+ const users = (this.allUsers || []).map(u => ({
992
+ id: u.id,
993
+ label: u.label,
994
+ icon: this.userIcon(u.id),
995
+ iconColor: this.userColor(u.id),
996
+ }));
997
+ const el = ODA.createComponent('staff-boss-menu', {
998
+ users,
999
+ currentId: this.currentBoss,
1000
+ hasLocalBoss: Boolean(this.currentBoss),
1001
+ });
1002
+ let picked;
1003
+ try {
1004
+ picked = await WORK.showDropdown(el, { TITLE: { label: 'Руководитель (BOSS)' }, placement: 'bottom' }, anchor);
1005
+ }
1006
+ catch (err) {
1007
+ if (err instanceof WORK.CancelError)
1008
+ return;
1009
+ this.error = String(err?.message || err);
1010
+ return;
1011
+ }
1012
+ if (picked !== undefined)
1013
+ await this.setBoss(picked);
998
1014
  },
999
- async pickBoss(uid) {
1000
- this.bossPickerOpen = false;
1001
- await this.setBoss(uid);
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: 'сотрудник',
1026
+ });
1027
+ }
1028
+ for (const s of this.availableStructures || []) {
1029
+ options.push({
1030
+ value: s.path,
1031
+ label: s.label,
1032
+ icon: s.icon || 'odant:structure',
1033
+ iconColor: '',
1034
+ round: false,
1035
+ tag: 'подразделение',
1036
+ });
1037
+ }
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',
1043
+ iconColor: '',
1044
+ round: false,
1045
+ tag: 'сервер сети',
1046
+ });
1047
+ }
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 });
1052
+ let picked;
1053
+ try {
1054
+ picked = await WORK.showDropdown(el, { TITLE: { label: 'Добавить участника' }, placement: 'bottom' }, anchor);
1055
+ }
1056
+ catch (err) {
1057
+ if (err instanceof WORK.CancelError)
1058
+ return;
1059
+ this.error = String(err?.message || err);
1060
+ return;
1061
+ }
1062
+ if (picked)
1063
+ await this._addMemberToRole(trail, picked);
1002
1064
  },
1003
1065
  async setBoss(uid) {
1004
1066
  const sec = JSON.parse(JSON.stringify(this.security || {}));
@@ -1008,7 +1070,6 @@ export default {
1008
1070
  await this.persist(sec, `Назначен руководитель: ${label}`, `В подразделении ${this.$item?.path || ''} руководитель (BOSS): ${label}.`);
1009
1071
  },
1010
1072
  async clearBoss() {
1011
- this.bossPickerOpen = false;
1012
1073
  await this.setBoss('');
1013
1074
  },
1014
1075
  onBossDragOver(e) {
@@ -1033,20 +1094,7 @@ export default {
1033
1094
  if (uid)
1034
1095
  await this.setBoss(uid);
1035
1096
  },
1036
- onRoleDragOver(e, trail) {
1037
- if (!this.canEdit)
1038
- return;
1039
- e.preventDefault();
1040
- if (e.dataTransfer)
1041
- e.dataTransfer.dropEffect = 'copy';
1042
- this.dropHoverTrail = trail;
1043
- },
1044
- onRoleDragLeave(trail) {
1045
- if (this.dropHoverTrail === trail)
1046
- this.dropHoverTrail = '';
1047
- },
1048
1097
  async onRoleDrop(e, trail) {
1049
- this.dropHoverTrail = '';
1050
1098
  if (!this.canEdit)
1051
1099
  return;
1052
1100
  e.preventDefault();
@@ -1076,13 +1124,23 @@ export default {
1076
1124
  return;
1077
1125
  }
1078
1126
  if (isDroppedClass(dropped) && dropped.path) {
1079
- await this._addLinksToRole(trail, [dropped.path]);
1127
+ await this.toggleClassInRole(trail, dropped.path, true);
1080
1128
  }
1081
1129
  },
1082
1130
  toggleRoleExpand(trail) {
1083
1131
  const cur = this.expandedRoles?.[trail] !== false;
1084
1132
  this.expandedRoles = { ...this.expandedRoles, [trail]: !cur };
1085
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
+ },
1086
1144
  _findRoleMut(sec, trail) {
1087
1145
  const steps = String(trail || '').split('/').filter(Boolean);
1088
1146
  let list = Array.isArray(sec.ROLES) ? sec.ROLES : [];
@@ -1095,25 +1153,11 @@ export default {
1095
1153
  }
1096
1154
  return node;
1097
1155
  },
1098
- openAddRole(parentTrail = '') {
1099
- this.addingRoleParent = this.addingRoleParent === parentTrail ? null : parentTrail;
1100
- this.newRoleLabel = '';
1101
- },
1102
- cancelAddRole() {
1103
- this.addingRoleParent = null;
1104
- this.newRoleLabel = '';
1105
- },
1106
- onNewRoleKey(e) {
1107
- if (e?.key === 'Enter')
1108
- this.confirmAddRole();
1109
- else if (e?.key === 'Escape')
1110
- this.cancelAddRole();
1111
- },
1112
- async confirmAddRole() {
1113
- const label = String(this.newRoleLabel || '').trim();
1114
- if (!label)
1156
+ async promptAddRole(parentTrail = '') {
1157
+ const raw = window.prompt(parentTrail ? 'Добавить подроль' : 'Добавить роль', 'Название');
1158
+ const label = String(raw || '').trim();
1159
+ if (!label || label === 'Название')
1115
1160
  return;
1116
- const parentTrail = this.addingRoleParent || '';
1117
1161
  const id = label.toLowerCase().replace(/[^a-zа-яё0-9_-]+/gi, '_').replace(/^_+|_+$/g, '') || ('role_' + Date.now());
1118
1162
  const sec = JSON.parse(JSON.stringify(this.security || {}));
1119
1163
  const targetList = parentTrail
@@ -1124,9 +1168,35 @@ export default {
1124
1168
  }
1125
1169
  if (parentTrail)
1126
1170
  this.expandedRoles = { ...this.expandedRoles, [parentTrail]: true };
1127
- this.cancelAddRole();
1171
+ const newTrail = parentTrail ? `${parentTrail}/${id}` : id;
1172
+ this.setupTrails = { ...this.setupTrails, [newTrail]: true };
1128
1173
  await this.persist(sec, `Создана роль «${label}»`, `В подразделении ${this.$item?.path || ''} добавлена роль «${label}».`);
1129
1174
  },
1175
+ async promptRenameRole(trail, currentLabel = '') {
1176
+ const raw = window.prompt('Переименовать роль', currentLabel);
1177
+ const label = String(raw || '').trim();
1178
+ if (!label || label === currentLabel)
1179
+ return;
1180
+ const sec = JSON.parse(JSON.stringify(this.security || {}));
1181
+ const node = this._findRoleMut(sec, trail);
1182
+ if (!node)
1183
+ return;
1184
+ node.label = label;
1185
+ await this.persist(sec, `Переименована роль «${label}»`, `Роль ${trail} переименована в «${label}».`);
1186
+ },
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
+ },
1130
1200
  async toggleRoleExternal(trail, checked) {
1131
1201
  const sec = JSON.parse(JSON.stringify(this.security || {}));
1132
1202
  const node = this._findRoleMut(sec, trail);
@@ -1138,7 +1208,20 @@ export default {
1138
1208
  delete node.external;
1139
1209
  await this.persist(sec, `Обновлена роль «${node.label || node.id}»`, `Роль «${node.label || node.id}»: внешний клиент = ${checked ? 'да' : 'нет'}.`);
1140
1210
  },
1141
- async removeRole(trail) {
1211
+ async removeRole(trail, label = '') {
1212
+ const title = label || trail.split('/').pop();
1213
+ let confirmed = false;
1214
+ try {
1215
+ if (typeof WORK?.showConfirm === 'function')
1216
+ confirmed = await WORK.showConfirm(`Удалить роль «${title}» и все вложенные подроли?`);
1217
+ else
1218
+ confirmed = window.confirm(`Удалить роль «${title}» и все вложенные подроли?`);
1219
+ }
1220
+ catch {
1221
+ return;
1222
+ }
1223
+ if (!confirmed)
1224
+ return;
1142
1225
  const steps = String(trail || '').split('/').filter(Boolean);
1143
1226
  if (!steps.length)
1144
1227
  return;
@@ -1152,24 +1235,7 @@ export default {
1152
1235
  if (parent && Array.isArray(parent.ROLES))
1153
1236
  parent.ROLES = parent.ROLES.filter(r => r?.id !== targetId);
1154
1237
  }
1155
- await this.persist(sec, `Удалена роль «${targetId}»`, `Из подразделения ${this.$item?.path || ''} удалена роль «${targetId}».`);
1156
- },
1157
- toggleMemberPicker(trail) {
1158
- this.pickerTrail = '';
1159
- if (this.memberPickerTrail === trail) {
1160
- this.closeMemberPicker();
1161
- return;
1162
- }
1163
- this.memberPickerTrail = trail;
1164
- this.memberSearch = '';
1165
- },
1166
- closeMemberPicker() {
1167
- this.memberPickerTrail = '';
1168
- this.memberSearch = '';
1169
- },
1170
- async pickMember(trail, memberId) {
1171
- this.closeMemberPicker();
1172
- await this._addMemberToRole(trail, memberId);
1238
+ await this.persist(sec, `Удалена роль «${title}»`, `Из подразделения ${this.$item?.path || ''} удалена роль «${title}».`);
1173
1239
  },
1174
1240
  async _addMemberToRole(trail, memberId) {
1175
1241
  const sec = JSON.parse(JSON.stringify(this.security || {}));
@@ -1189,81 +1255,20 @@ export default {
1189
1255
  node.USERS = node.USERS.filter(id => id !== memberId);
1190
1256
  await this.persist(sec, `Из роли «${node.label || node.id}» исключён участник`, `Из роли «${node.label || node.id}» удалён ${memberId}.`);
1191
1257
  },
1192
- toggleClassPicker(trail) {
1193
- this.memberPickerTrail = '';
1194
- if (this.pickerTrail === trail) {
1195
- this.closeClassPicker();
1196
- return;
1197
- }
1198
- this.pickerTrail = trail;
1199
- this.classSearch = '';
1200
- this.pickerChecked = {};
1201
- },
1202
- closeClassPicker() {
1203
- this.pickerTrail = '';
1204
- this.classSearch = '';
1205
- this.pickerChecked = {};
1206
- },
1207
- toggleClassExpand(path) {
1208
- this.expandedClassPaths = {
1209
- ...this.expandedClassPaths,
1210
- [path]: !this.expandedClassPaths?.[path],
1211
- };
1212
- },
1213
- togglePickerCheck(path, checked) {
1214
- this.pickerChecked = {
1215
- ...this.pickerChecked,
1216
- [path]: Boolean(checked),
1217
- };
1218
- },
1219
- onPickerLabelTap(node) {
1220
- if (node.hasChildren && !node.selectable) {
1221
- this.toggleClassExpand(node.path);
1222
- return;
1223
- }
1224
- if (node.selectable)
1225
- this.togglePickerCheck(node.path, !node.checked);
1226
- },
1227
- async applyClassPicker(trail) {
1228
- const paths = Object.keys(this.pickerChecked || {}).filter(k => this.pickerChecked[k]);
1229
- if (!paths.length)
1230
- return;
1231
- await this._addLinksToRole(trail, paths);
1232
- this.closeClassPicker();
1233
- },
1234
- async _addLinksToRole(trail, paths) {
1258
+ async toggleClassInRole(trail, clsPath, checked) {
1235
1259
  const sec = JSON.parse(JSON.stringify(this.security || {}));
1236
1260
  const node = this._findRoleMut(sec, trail);
1237
1261
  if (!node)
1238
1262
  return;
1239
1263
  node.LINKS = Array.isArray(node.LINKS) ? node.LINKS : [];
1240
- let added = 0;
1241
- for (const p of paths) {
1242
- if (p && !node.LINKS.some(l => l?.id === p)) {
1243
- node.LINKS.push({ id: p, access: 'read' });
1244
- added++;
1245
- }
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 });
1246
1268
  }
1247
- if (added) {
1248
- this.expandedRoles = { ...this.expandedRoles, [trail]: true };
1249
- await this.persist(sec, `К роли «${node.label || node.id}» привязаны классы (${added})`, `К роли «${node.label || node.id}» привязаны классы: ${paths.join(', ')}.`);
1269
+ else {
1270
+ node.LINKS = node.LINKS.filter(l => l?.id !== clsPath);
1250
1271
  }
1272
+ await this.persist(sec, `Обновлён доступ к классу в роли «${node.label || node.id}»`, `Роль «${node.label || node.id}»: класс ${clsPath} ${checked ? 'добавлен (' + access + ')' : 'убран'}.`);
1251
1273
  },
1252
- async updateRoleLinkAccess(trail, clsPath, access) {
1253
- const sec = JSON.parse(JSON.stringify(this.security || {}));
1254
- const node = this._findRoleMut(sec, trail);
1255
- const link = node?.LINKS?.find(l => l?.id === clsPath);
1256
- if (!link)
1257
- return;
1258
- link.access = access === 'write' ? 'write' : 'read';
1259
- await this.persist(sec, `Изменён доступ роли к классу`, `Роль «${node.label || node.id}»: для ${clsPath} установлен доступ «${link.access}».`);
1260
- },
1261
- async removeRoleLink(trail, clsPath) {
1262
- const sec = JSON.parse(JSON.stringify(this.security || {}));
1263
- const node = this._findRoleMut(sec, trail);
1264
- if (!node || !Array.isArray(node.LINKS))
1265
- return;
1266
- node.LINKS = node.LINKS.filter(l => l?.id !== clsPath);
1267
- await this.persist(sec, `Отвязан класс от роли`, `От роли «${node.label || node.id}» отвязан класс ${clsPath}.`);
1268
- },
1269
- }
1274
+ };