@things-factory/auth-ui 10.1.4 → 10.1.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (59) hide show
  1. package/dist-client/components/change-password.d.ts +11 -0
  2. package/dist-client/components/change-password.js +103 -6
  3. package/dist-client/components/change-password.js.map +1 -1
  4. package/dist-client/components/role-privilege-picker.d.ts +37 -0
  5. package/dist-client/components/role-privilege-picker.js +58 -0
  6. package/dist-client/components/role-privilege-picker.js.map +1 -0
  7. package/dist-client/components/role-template-picker.d.ts +83 -0
  8. package/dist-client/components/role-template-picker.js +487 -0
  9. package/dist-client/components/role-template-picker.js.map +1 -0
  10. package/dist-client/components/user-detail.d.ts +151 -0
  11. package/dist-client/components/user-detail.js +631 -0
  12. package/dist-client/components/user-detail.js.map +1 -0
  13. package/dist-client/components/user-invite.d.ts +80 -0
  14. package/dist-client/components/user-invite.js +422 -0
  15. package/dist-client/components/user-invite.js.map +1 -0
  16. package/dist-client/entries/auth/activate.d.ts +0 -1
  17. package/dist-client/entries/auth/activate.js +0 -8
  18. package/dist-client/entries/auth/activate.js.map +1 -1
  19. package/dist-client/pages/role/role-list-page.d.ts +203 -0
  20. package/dist-client/pages/role/role-list-page.js +838 -0
  21. package/dist-client/pages/role/role-list-page.js.map +1 -0
  22. package/dist-client/pages/role/role-privilege-page.d.ts +181 -0
  23. package/dist-client/pages/role/role-privilege-page.js +980 -0
  24. package/dist-client/pages/role/role-privilege-page.js.map +1 -0
  25. package/dist-client/pages/user/user-list-page.d.ts +88 -0
  26. package/dist-client/pages/user/user-list-page.js +474 -0
  27. package/dist-client/pages/user/user-list-page.js.map +1 -0
  28. package/dist-client/route.js +5 -2
  29. package/dist-client/route.js.map +1 -1
  30. package/dist-client/tsconfig.tsbuildinfo +1 -1
  31. package/dist-server/tsconfig.tsbuildinfo +1 -1
  32. package/package.json +4 -4
  33. package/things-factory.config.js +3 -2
  34. package/translations/en.json +72 -3
  35. package/translations/ja.json +14 -3
  36. package/translations/ko.json +73 -4
  37. package/translations/ms.json +15 -4
  38. package/translations/zh.json +14 -3
  39. package/dist-client/components/contact-us.d.ts +0 -20
  40. package/dist-client/components/contact-us.js +0 -121
  41. package/dist-client/components/contact-us.js.map +0 -1
  42. package/dist-client/components/create-role.d.ts +0 -1
  43. package/dist-client/components/create-role.js +0 -117
  44. package/dist-client/components/create-role.js.map +0 -1
  45. package/dist-client/components/credential-manager.d.ts +0 -11
  46. package/dist-client/components/credential-manager.js +0 -64
  47. package/dist-client/components/credential-manager.js.map +0 -1
  48. package/dist-client/components/role-edit-form.d.ts +0 -1
  49. package/dist-client/components/role-edit-form.js +0 -95
  50. package/dist-client/components/role-edit-form.js.map +0 -1
  51. package/dist-client/components/role-privilege-editor.d.ts +0 -1
  52. package/dist-client/components/role-privilege-editor.js +0 -368
  53. package/dist-client/components/role-privilege-editor.js.map +0 -1
  54. package/dist-client/pages/role/role-management.d.ts +0 -4
  55. package/dist-client/pages/role/role-management.js +0 -137
  56. package/dist-client/pages/role/role-management.js.map +0 -1
  57. package/dist-client/pages/user/user-management.d.ts +0 -35
  58. package/dist-client/pages/user/user-management.js +0 -223
  59. package/dist-client/pages/user/user-management.js.map +0 -1
@@ -0,0 +1,838 @@
1
+ import { __decorate, __metadata } from "tslib";
2
+ import '@material/web/icon/icon.js';
3
+ import '@operato/data-grist';
4
+ import '@operato/oops/ox-oops-note.js';
5
+ import gql from 'graphql-tag';
6
+ import { css, html, nothing } from 'lit';
7
+ import { customElement, property, query, state } from 'lit/decorators.js';
8
+ import { client, gqlContext } from '@operato/graphql';
9
+ import { openPopup } from '@operato/layout';
10
+ import { OxPrompt } from '@operato/popup/ox-prompt.js';
11
+ import { i18next, localize } from '@operato/i18n';
12
+ import { p13n } from '@operato/p13n';
13
+ import { InheritedValueType, navigate, PageView } from '@operato/shell';
14
+ import { CommonGristStyles, CommonHeaderStyles, ScrollbarStyles } from '@operato/styles';
15
+ import { isMobileDevice } from '@operato/utils';
16
+ import { getDomain } from '@things-factory/auth-base/dist-client';
17
+ /**
18
+ * 역할 목록 — **보이는 것과 고칠 수 있는 것을 가른다.**
19
+ *
20
+ * ── 옛 화면이 하던 것 (`pages/role/role-management.ts`) ──────────────────────
21
+ * `quick-find-list` 안에 역할을 늘어놓고, 펼치면 그 안에 이름 입력칸과 84줄의 권한 체크박스가
22
+ * 함께 있었다. 그 구조에서 셋이 났다.
23
+ *
24
+ * ① 이름 입력이 매 글자마다 페이지로 올라가 **모든** 편집기에 공유됐다 — A 를 고치고 B 를
25
+ * 저장하면 B 의 이름이 A 가 됐다. 지금은 이름·설명을 격자에서 고친다.
26
+ * ② 목록에 권한이 하나도 안 보였다. 「이 역할이 무엇을 여나」를 알려면 펼쳐야 했다.
27
+ * ③ 한도도 쪽 나누기도 없었다.
28
+ *
29
+ * ── 상속이 이 화면의 중심이다 ───────────────────────────────────────────────
30
+ * 목록은 부모 도메인의 역할까지 보여 준다 — **부여할 수 있는 범위가 그것**이기 때문이다.
31
+ * 그런데 그 행은 여기서 못 고친다(`updateRole` 이 `domain.id` 하나로 좁혀 찾는다).
32
+ *
33
+ * 전에는 `Include` 로 열어서 **못 고치는 9행이 고칠 수 있는 2행 앞에 깔렸다**(UX 실측).
34
+ * 지금은 「우리 역할」로 열고, 세 묶음의 수를 함께 적어 **상속이 있다는 사실 자체는 남긴다.**
35
+ * 편집도 `editable` 함수로 상속 행에서 닫고, 삭제도 상속 행을 안 보낸다.
36
+ *
37
+ * ── 권한은 수만 낸다 ────────────────────────────────────────────────────────
38
+ * 전에는 `activity 쓰기 · activity-instance 쓰기·읽기` 식으로 잘린 코드 용어를 그렸고, 그것을
39
+ * 그리려고 권한 **행**을 받았다(UX 실측 5,731 bytes · 69ms 대 518 bytes · 7ms). 지금은
40
+ * `privilegeCount` 하나를 받는다. 권한 편집으로 가는 문은 **버튼 gutter 칸**이 진다 —
41
+ * 눌리는 숫자는 손잡이로 보이지 않는다.
42
+ */
43
+ const RoleListPageBase = p13n(localize(i18next)(PageView));
44
+ let RoleListPage = class RoleListPage extends RoleListPageBase {
45
+ constructor() {
46
+ super(...arguments);
47
+ this.mode = isMobileDevice() ? 'LIST' : 'GRID';
48
+ /* 읽는 중 · 못 읽었다 · 읽었는데 없다 를 가른다. */
49
+ this.fetchState = 'loading';
50
+ this.total = 0;
51
+ this.filtered = false;
52
+ /*
53
+ * 지금 어느 도메인에 있나.
54
+ *
55
+ * 목록은 상속으로 부모 도메인의 역할까지 보여 준다 — 실제로 부여할 수 있는 범위가 그것이기
56
+ * 때문이다. 그런데 **그 행은 여기서 못 고친다**(`updateRole`·`updateMultipleRole` 이
57
+ * `domain.id` 하나로 좁혀 찾는다). 그래서 편집을 열어 두면 안 된다.
58
+ *
59
+ * 프로필의 `domain` 에는 `id` 가 없어서(`auth-private-process-router.ts`) `subdomain` 으로
60
+ * 견준다 — 두 도메인이 같은 subdomain 을 가질 수 없으므로 id 와 같은 답이다.
61
+ */
62
+ this.mySubdomain = '';
63
+ /*
64
+ * **어느 묶음을 보고 있나 — 기본값은 「우리 역할」이다.**
65
+ *
66
+ * 전에는 `Include` 로 열었다. 그러면 처음 화면에 **못 고치는 행 9개가 앞에 깔린다**
67
+ * (UX 실측: miratek 2 · system 9). `None` 으로 열면 처음 화면이 2행이고 **그 2행이 전부
68
+ * 고칠 수 있는 행**이다.
69
+ *
70
+ * 세 묶음은 서버에 이미 있다(`InheritedValueType`). 새로 만들 것이 없다.
71
+ */
72
+ this.scope = InheritedValueType.None;
73
+ /**
74
+ * 묶음마다 몇 건인가.
75
+ *
76
+ * 수를 함께 적는 이유는 **상속이 있다는 사실 자체가 보이게** 하는 것이다. 기본값을 「우리
77
+ * 역할」로 좁혀 놓으면, 수가 없으면 상속 9건이 존재하는지조차 모른다.
78
+ *
79
+ * `undefined` 는 「아직 못 셌다」다 — 0 으로 메우면 「없다」와 같아 보인다.
80
+ */
81
+ this.counts = {};
82
+ }
83
+ static { this.styles = [
84
+ ScrollbarStyles,
85
+ CommonGristStyles,
86
+ CommonHeaderStyles,
87
+ css `
88
+ :host {
89
+ display: flex;
90
+ flex-direction: column;
91
+ width: 100%;
92
+ background-color: var(--md-sys-color-surface);
93
+ color: var(--md-sys-color-on-surface);
94
+ position: relative;
95
+ }
96
+
97
+ ox-grist {
98
+ flex: 1;
99
+ min-height: 0;
100
+ }
101
+
102
+ /* 요약 배지 — 색은 짝으로, 그리고 「무엇이 나를 기다리나」에만 쓴다. */
103
+ .badge {
104
+ display: inline-block;
105
+ padding: 2px 8px;
106
+ border-radius: var(--md-sys-shape-corner-small, 6px);
107
+ font-size: 0.78rem;
108
+ white-space: nowrap;
109
+ background-color: var(--md-sys-color-surface-variant);
110
+ color: var(--md-sys-color-on-surface-variant);
111
+ }
112
+ .badge[attention] {
113
+ background-color: var(--md-sys-color-error-container);
114
+ color: var(--md-sys-color-on-error-container);
115
+ }
116
+ /* 「우리」는 기본 상태다 — 색을 쓰면 색이 아무것도 말하지 않게 된다. */
117
+ .badge[quiet] {
118
+ background-color: transparent;
119
+ color: var(--md-sys-color-outline);
120
+ }
121
+
122
+ /*
123
+ ── 세 묶음 ────────────────────────────────────────────────────────────
124
+ 고른 것은 면으로 말한다. 글자색만 바꾸면 야간에 안 보인다.
125
+ */
126
+ [scopes] {
127
+ display: flex;
128
+ align-items: center;
129
+ gap: 4px;
130
+ }
131
+
132
+ button[scope] {
133
+ display: inline-flex;
134
+ align-items: baseline;
135
+ gap: 5px;
136
+ padding: 5px 12px;
137
+ font: var(--label-font, inherit);
138
+ font-size: 0.82rem;
139
+ color: var(--md-sys-color-on-surface-variant);
140
+ background-color: transparent;
141
+ border: 1px solid var(--md-sys-color-outline-variant);
142
+ border-radius: var(--md-sys-shape-corner-full, 999px);
143
+ cursor: pointer;
144
+ white-space: nowrap;
145
+ }
146
+
147
+ button[scope]:hover {
148
+ background-color: var(--md-sys-color-surface-variant);
149
+ }
150
+
151
+ button[scope][active] {
152
+ color: var(--md-sys-color-on-secondary-container);
153
+ background-color: var(--md-sys-color-secondary-container);
154
+ border-color: var(--md-sys-color-secondary-container);
155
+ }
156
+
157
+ button[scope] [count] {
158
+ font-size: 0.78rem;
159
+ color: var(--md-sys-color-outline);
160
+ }
161
+
162
+ button[scope][active] [count] {
163
+ color: var(--md-sys-color-on-secondary-container);
164
+ }
165
+
166
+ /*
167
+ * 새 역할 단추 — **옆에 선 것들을 따라간다.**
168
+ *
169
+ * 이 줄에는 알약 범위 단추 셋과 검색이 서 있다. 그 사이에서 이것만 네모난 기본 단추면
170
+ * 같은 줄의 문법이 깨진다. 범위 단추와 같은 모서리·같은 테두리를 쓰되, **여는 일**이므로
171
+ * 채워서 한 단 앞으로 낸다 — 나머지는 거르는 일이고 이것만 만드는 일이다.
172
+ */
173
+ button[add] {
174
+ display: inline-flex;
175
+ align-items: center;
176
+ justify-content: center;
177
+ padding: 5px 10px;
178
+ color: var(--md-sys-color-on-secondary-container);
179
+ background-color: var(--md-sys-color-secondary-container);
180
+ border: 1px solid transparent;
181
+ border-radius: var(--md-sys-shape-corner-full, 999px);
182
+ cursor: pointer;
183
+ margin-left: auto;
184
+ }
185
+
186
+ button[add]:hover {
187
+ background-color: var(--md-sys-color-secondary);
188
+ color: var(--md-sys-color-on-secondary);
189
+ }
190
+
191
+ button[add] md-icon {
192
+ --md-icon-size: 18px;
193
+ }
194
+
195
+ ox-oops-note[note] {
196
+ position: absolute;
197
+ inset: 0;
198
+ z-index: 5;
199
+ background-color: var(--md-sys-color-surface);
200
+ }
201
+ `
202
+ ]; }
203
+ /**
204
+ * 저장과 삭제를 **툴바**에 둔다.
205
+ *
206
+ * 격자에서 고치는 화면들의 관례다(`fiscal-quarter-list-page` 외). 격자 안 편집은 여러 줄을
207
+ * 한꺼번에 고치므로, 줄마다 저장 단추를 두면 어디를 눌러야 하는지가 사라진다.
208
+ */
209
+ /**
210
+ * 찾기는 **제목 줄**에 선다 — 셸이 그 자리를 모든 화면에 같은 모양으로 둔다.
211
+ *
212
+ * 이 페이지는 한동안 `ox-filters-form` 을 헤드룸의 칩 줄에 **직접** 끼워 넣고 있었다. 그래서
213
+ * 돋보기가 범위 칩과 만들기 단추 사이에 끼어, 같은 앱의 다른 목록과 찾기 자리가 달랐다
214
+ * (`env-var-list-page` 외 auth-ui 목록 다섯이 전부 아래 모양이다).
215
+ *
216
+ * 둘은 대안이 아니라 **다른 것**이다 — `search` 는 목록 전체를 훑는 글자 찾기이고,
217
+ * `filter` 는 칸별 조건 폼을 접었다 펴는 것이다. 표준 화면은 둘 다 선언한다.
218
+ */
219
+ get context() {
220
+ return {
221
+ title: i18next.t('text.role_management'),
222
+ help: 'auth/roles',
223
+ search: {
224
+ handler: (search) => {
225
+ this.grist.searchText = search;
226
+ },
227
+ value: this.grist?.searchText || ''
228
+ },
229
+ filter: {
230
+ handler: () => {
231
+ this.grist.toggleHeadroom();
232
+ }
233
+ },
234
+ actions: [
235
+ { title: i18next.t('button.save'), action: this.onSaveGrid.bind(this) },
236
+ { title: i18next.t('button.delete'), action: this.onDeleteGrid.bind(this) }
237
+ ]
238
+ };
239
+ }
240
+ render() {
241
+ return html `
242
+ <ox-grist
243
+ .mode=${this.mode}
244
+ .config=${this.config}
245
+ .fetchHandler=${this.fetchHandler.bind(this)}
246
+ .personalConfigProvider=${this.getPagePreferenceProvider('ox-grist')}
247
+ >
248
+ <div slot="headroom" class="header">
249
+ <div class="filters">
250
+ ${this.renderScopes()}
251
+
252
+ <!-- 찾기는 제목 줄이 갖는다(context.search). 폼이 자기 검색칸을 또 그리면 둘이 된다. -->
253
+ <ox-filters-form without-search></ox-filters-form>
254
+
255
+ <!--
256
+ 여기 ox-record-creator 가 있었다 — 목록에 빈 줄을 만들고 이름을 치게 하는
257
+ 관례(24 파일)다. 걷어낸 이유는 openCreate 의 머리말에 있다.
258
+ -->
259
+ <button add @click=${() => this.openCreate()} title=${i18next.t('button.create')}>
260
+ <md-icon>add</md-icon>
261
+ </button>
262
+ </div>
263
+ <ox-context-page-toolbar class="actions" .context=${this.context}></ox-context-page-toolbar>
264
+ </div>
265
+
266
+ <ox-grist-personalizer slot="setting"></ox-grist-personalizer>
267
+ </ox-grist>
268
+
269
+ ${this.renderNote()}
270
+ `;
271
+ }
272
+ /**
273
+ * 세 묶음.
274
+ *
275
+ * **수를 함께 적는 것이 이 부품의 이유다.** 기본값을 「우리 역할」로 좁혀 두면 처음 화면이
276
+ * 깨끗한 대신 **상속 9건이 있다는 사실이 사라진다.** 수가 그것을 되돌려 놓는다.
277
+ *
278
+ * 아직 못 센 묶음은 수를 **안 그린다** — 0 으로 메우면 「없다」와 같아 보인다.
279
+ */
280
+ renderScopes() {
281
+ const scopes = [
282
+ [InheritedValueType.None, 'label.ours'],
283
+ [InheritedValueType.Only, 'label.inherited'],
284
+ [InheritedValueType.Include, 'label.all']
285
+ ];
286
+ return html `
287
+ <div scopes>
288
+ ${scopes.map(([scope, key]) => html `
289
+ <button scope ?active=${this.scope === scope} @click=${() => this.onScope(scope)}>
290
+ ${i18next.t(key)}
291
+ ${this.counts[scope] === undefined ? nothing : html `<span count>${this.counts[scope]}</span>`}
292
+ </button>
293
+ `)}
294
+ </div>
295
+ `;
296
+ }
297
+ onScope(scope) {
298
+ if (this.scope === scope) {
299
+ return;
300
+ }
301
+ this.scope = scope;
302
+ this.grist.fetch();
303
+ }
304
+ /**
305
+ * 세 묶음의 건수.
306
+ *
307
+ * 세 번 묻는다. 한 번에 셋을 세는 질의가 서버에 없고, 각각 `total` 만 받으므로 가볍다
308
+ * (UX 실측 158·566·684 bytes). 실패하면 **수를 안 그린다** — 틀린 수를 그리는 것보다
309
+ * 없는 것이 낫다.
310
+ */
311
+ async countScopes() {
312
+ const scopes = [InheritedValueType.None, InheritedValueType.Only, InheritedValueType.Include];
313
+ const counted = await Promise.all(scopes.map(async (scope) => {
314
+ const response = await client.query({
315
+ query: gql `
316
+ query ($inherited: InheritedValueType) {
317
+ roles(inherited: $inherited, pagination: { page: 1, limit: 1 }) {
318
+ total
319
+ }
320
+ }
321
+ `,
322
+ variables: { inherited: scope }
323
+ });
324
+ return [scope, response.errors?.length ? undefined : response.data?.roles?.total];
325
+ }));
326
+ this.counts = counted.reduce((counts, [scope, total]) => {
327
+ if (total !== undefined) {
328
+ counts[scope] = total;
329
+ }
330
+ return counts;
331
+ }, {});
332
+ }
333
+ /**
334
+ * 목록 위에 겹쳐 그린다 — 격자를 떼면 다시 읽을 길이 없어진다.
335
+ *
336
+ * **아무 역할도 없는 것이 이 화면의 가장 중요한 자리다.** 새 도메인은 여기서 시작하고,
337
+ * 역할이 없으면 초대한 사람은 로그인해도 볼 화면이 하나도 없다. 그래서 그 사실을 말한다.
338
+ */
339
+ renderNote() {
340
+ if (this.fetchState === 'loading') {
341
+ return nothing;
342
+ }
343
+ if (this.fetchState === 'failed') {
344
+ return html `<ox-oops-note
345
+ note
346
+ icon="error_outline"
347
+ title=${i18next.t('text.failed to fetch')}
348
+ description=${i18next.t('text.please try again')}
349
+ ></ox-oops-note>`;
350
+ }
351
+ if (this.total === 0 && !this.filtered) {
352
+ return html `<ox-oops-note
353
+ note
354
+ icon="badge"
355
+ title=${i18next.t('text.no role yet')}
356
+ description=${i18next.t('text.without a role they see nothing')}
357
+ ></ox-oops-note>`;
358
+ }
359
+ return nothing;
360
+ }
361
+ /**
362
+ * 상속된 역할인가 — **격자의 편집 가드가 이것을 본다.**
363
+ *
364
+ * `mySubdomain` 을 아직 못 읽었으면 **거짓을 돌려주지 않고 상속으로 본다.** 「모른다」를
365
+ * 「내 것이다」로 바꾸면 그 순간 못 고치는 행이 열리고, 사람이 타이핑해 저장한 뒤에 서버가
366
+ * 거절한다. 모를 때는 잠가 두는 쪽이 안전하다.
367
+ */
368
+ isInherited(record) {
369
+ if (!this.mySubdomain) {
370
+ return true;
371
+ }
372
+ const subdomain = record?.domain?.subdomain;
373
+ return Boolean(subdomain) && subdomain !== this.mySubdomain;
374
+ }
375
+ /**
376
+ * 출처 한 칸.
377
+ *
378
+ * 「우리」는 조용히 둔다 — 기본 상태에 색을 쓰면 색이 아무것도 말하지 않게 된다.
379
+ * 상속은 **어느 도메인에서 왔는지 함께 적는다.** 「상속」만 적으면 관리자가 어디로 가야
380
+ * 하는지 모른다.
381
+ */
382
+ sourceCell(record) {
383
+ if (!this.isInherited(record)) {
384
+ return html `<span class="badge" quiet>${i18next.t('label.ours')}</span>`;
385
+ }
386
+ const from = record?.domain?.name || record?.domain?.subdomain || '';
387
+ return html `<span class="badge" title=${i18next.t('text.role belongs to x domain and is edited there', { x: from })}
388
+ >${i18next.t('label.inherited')}${from ? ` · ${from}` : ''}</span
389
+ >`;
390
+ }
391
+ async pageInitialized() {
392
+ this.mySubdomain = (await getDomain())?.subdomain || '';
393
+ this.countScopes();
394
+ this.config = {
395
+ /*
396
+ * **두 모드가 다른 말을 하지 않게 한다.**
397
+ *
398
+ * ⚠ 여기가 `summary`·`domain` 을 가리킨 채로 남아 있었다 — 컬럼을 `privilegeCount`·
399
+ * `source` 로 갈았는데 이 설정을 안 고쳤다. 그래서 **LIST 모드에서는 권한 수도 출처도
400
+ * 아예 안 그려졌다.** 이름이 틀려도 격자가 조용히 넘어가므로 빌드도 시험도 못 잡는다.
401
+ *
402
+ * 그리고 이 앱이 실제로 LIST 로 연다(`isMobileDevice()` 또는 사람마다 기억된 개인 설정).
403
+ * GRID 만 보고 만들면 그 사람들은 내가 만든 칸을 한 번도 못 본다.
404
+ */
405
+ list: {
406
+ fields: ['name', 'description'],
407
+ details: ['privilegeCount', 'source']
408
+ },
409
+ columns: [
410
+ { type: 'gutter', gutterName: 'sequence', fixed: true },
411
+ {
412
+ /*
413
+ * **권한 편집으로 가는 문.**
414
+ *
415
+ * `gutterName: 'button'` 이 이 저장소의 관례다 — 68 파일 · 104 자리
416
+ * (`employee-list-page.ts:110-124` 가 같은 모양). `header` 에 이름이 붙은 아이콘 칸은
417
+ * **손잡이로 보인다.** 그것이 「권한 편집 방법을 모르겠다」를 고치는 자리다.
418
+ *
419
+ * 행 전체에 클릭을 두지 않는 이유는 그대로다 — 이름을 고치려 누른 것이 화면을
420
+ * 떠나면 안 된다.
421
+ *
422
+ * ── 상속 행에서도 버튼은 남긴다 ─────────────────────────────────────
423
+ * **읽는 것은 정당하다.** 상속 역할이 무엇을 여는지 보는 것은 막을 이유가 없고,
424
+ * 오히려 「우리 역할로 복사」를 하려면 먼저 봐야 한다. `icon`·`title` 이 record 를
425
+ * 받으므로 그 구분이 여기 실린다 — 글자만 「보기만」으로 바뀐다.
426
+ */
427
+ type: 'gutter',
428
+ gutterName: 'button',
429
+ header: i18next.t('field.privileges'),
430
+ /*
431
+ * ⚠ **아직 저장 안 된 빈 줄에는 내주지 않는다.** 격자가 데이터 2행 아래에 추가용 빈
432
+ * 줄을 하나 더 그리는데, 거기에도 버튼이 나왔다. 눌러도 `record.id` 가 없어 아무 일이
433
+ * 없다 — **조용한 무동작 단추**다.
434
+ *
435
+ * `employee-list-page` 가 `icon` 에서 `''` 를 돌려주는 이유가 이것이었다. 모양만
436
+ * 베끼고 그 가드를 안 가져왔다.
437
+ */
438
+ icon: (record) => (record?.id ? 'key' : ''),
439
+ iconOnly: false,
440
+ title: (record) => !record?.id
441
+ ? ''
442
+ : this.isInherited(record)
443
+ ? i18next.t('text.view only')
444
+ : i18next.t('button.edit privileges'),
445
+ width: 92,
446
+ handlers: {
447
+ click: (_columns, _data, _column, record) => {
448
+ if (record?.id) {
449
+ navigate(`role-privileges/${record.id}`);
450
+ }
451
+ }
452
+ }
453
+ },
454
+ {
455
+ type: 'string',
456
+ name: 'name',
457
+ header: i18next.t('field.name'),
458
+ /*
459
+ * **격자 안에서 고친다.** 이 저장소의 관례가 그렇고(`editable` 139 파일 대
460
+ * `openPopup` 96 파일), 옛 화면이 이름을 팝업에 두었다가 A 의 이름을 B 에 저장했다.
461
+ *
462
+ * ⚠ **상속된 행은 열지 않는다.** `editable` 이 함수를 받는다
463
+ * (`data-grist` types.ts:458, data-grid-body.js:530·861 이 그렇게 부른다). 이것이
464
+ * 없으면 부모 도메인 역할에 타이핑해 저장할 수 있고, 서버가 그때 거절한다.
465
+ */
466
+ record: { align: 'left', editable: (_v, _c, record) => !this.isInherited(record) },
467
+ filter: 'search',
468
+ sortable: true,
469
+ width: 160
470
+ },
471
+ {
472
+ type: 'string',
473
+ name: 'description',
474
+ header: i18next.t('field.description'),
475
+ record: { align: 'left', editable: (_v, _c, record) => !this.isInherited(record) },
476
+ filter: 'search',
477
+ sortable: true,
478
+ width: 220
479
+ },
480
+ {
481
+ /*
482
+ * **이 역할이 여는 것이 몇 개인가.** 읽는 값이고, 누르는 자리가 아니다.
483
+ *
484
+ * 전에는 여기에 `activity 쓰기 · activity-instance 쓰기·읽기 · 3개 더` 식으로 잘린
485
+ * 코드 용어를 그렸다. 그것을 그리려고 목록이 권한 **행**을 받았다.
486
+ *
487
+ * ```
488
+ * [UX 실측] roles(limit:20) 권한 포함 5,731 bytes · 69ms
489
+ * [UX 실측] 권한 없이 518 bytes · 7ms → 11.1배 · 10배
490
+ * ```
491
+ *
492
+ * 수는 잘린 문자열이 못 하던 것을 한다 — 「더 있다」가 아니라 **얼마인지** 말하고,
493
+ * `0` 이면 아직 아무것도 안 열린 역할이라는 것이 한눈에 보인다.
494
+ *
495
+ * ⚠ **여기에 클릭을 얹지 않는다.** 한때 그렇게 뒀는데, 읽는 값과 누르는 자리가 한 칸에
496
+ * 들어간다. 그리고 사용자 평가의 첫 줄이 「권한 편집 방법을 모르겠다」였는데 —
497
+ * **눌리는 숫자는 보이는 손잡이가 아니다.** 문은 아래 버튼 칸이 진다.
498
+ */
499
+ type: 'string',
500
+ name: 'privilegeCount',
501
+ header: i18next.t('field.privileges'),
502
+ record: { align: 'center', renderer: privilegeCountCell },
503
+ width: 110
504
+ },
505
+ {
506
+ /*
507
+ * **출처 — 여기가 「보이는 것과 고칠 수 있는 것」을 가른다.**
508
+ *
509
+ * 전에는 도메인 이름을 날값으로 냈다(`SYSTEM` · `MIRATEK`). 그건 구분이 아니다 —
510
+ * 읽는 사람이 자기 도메인 이름을 외우고 있어야 한다. 지금은 「우리」와
511
+ * 「상속 · SYSTEM」 으로 말한다.
512
+ *
513
+ * ⚠ `classifier` 로 행 전체를 물들이지 않는다. 선례들이 색을 `'#8B0000'` 처럼 박아
514
+ * 두었고(dataset 5곳), 그 규약(`emphasized: [배경, 글자]`)이 `var(...)` 를 받는지도
515
+ * 확인되지 않았다. 그리고 `emphasized` 는 **강조**하는 장치인데 여기서 필요한 것은
516
+ * 그 반대다 — 11행 중 9행을 강조하면 강조가 아니다. 그래서 이 칸이 진다.
517
+ */
518
+ type: 'string',
519
+ name: 'source',
520
+ header: i18next.t('field.source'),
521
+ record: { align: 'center', renderer: (_v, _c, record) => this.sourceCell(record) },
522
+ width: 150
523
+ },
524
+ {
525
+ type: 'datetime',
526
+ name: 'updatedAt',
527
+ header: i18next.t('field.updated_at'),
528
+ record: { align: 'center' },
529
+ sortable: true,
530
+ width: 160
531
+ }
532
+ ],
533
+ rows: {
534
+ selectable: { multiple: true }
535
+ },
536
+ sorters: [{ name: 'name' }]
537
+ };
538
+ }
539
+ async pageUpdated(_changes, _lifecycle) {
540
+ if (this.active) {
541
+ await this.updateComplete;
542
+ this.grist.fetch();
543
+ }
544
+ }
545
+ /**
546
+ * 역할을 가져온다 — **권한 행은 받지 않는다.**
547
+ *
548
+ * 전에는 `privileges { id name category }` 를 함께 물었다. 그것으로 그린 것은 잘린 코드 용어
549
+ * 셋이었고, 값은 이랬다.
550
+ *
551
+ * ```
552
+ * [UX 실측] 권한 포함 5,731 bytes · 69ms
553
+ * [UX 실측] 권한 없이 518 bytes · 7ms
554
+ * ```
555
+ *
556
+ * 바이트보다 큰 것은 **`Role.privileges` 필드 리졸버가 역할마다 한 번씩 도는 것**이 함께
557
+ * 없어지는 쪽이다. 지금은 `privilegeCount` 를 받는다 — DB 가 센다(`role-query.ts`).
558
+ *
559
+ * `inherited` 는 화면이 고른 묶음을 그대로 넘긴다. 기본값이 「우리 역할」이라 처음 화면에
560
+ * 못 고치는 행이 안 깔린다.
561
+ */
562
+ async fetchHandler({ filters = [], page, limit, sortings = [] }) {
563
+ this.fetchState = 'loading';
564
+ this.filtered = filters.length > 0;
565
+ try {
566
+ const response = (await client.query({
567
+ query: gql `
568
+ query (
569
+ $filters: [Filter!]
570
+ $pagination: Pagination
571
+ $sortings: [Sorting!]
572
+ $inherited: InheritedValueType
573
+ ) {
574
+ responses: roles(
575
+ filters: $filters
576
+ pagination: $pagination
577
+ sortings: $sortings
578
+ inherited: $inherited
579
+ ) {
580
+ items {
581
+ id
582
+ name
583
+ description
584
+ domain {
585
+ id
586
+ name
587
+ subdomain
588
+ }
589
+ privilegeCount
590
+ updatedAt
591
+ }
592
+ total
593
+ }
594
+ }
595
+ `,
596
+ variables: {
597
+ filters,
598
+ pagination: { page, limit },
599
+ sortings: sortings.length ? sortings : [{ name: 'name' }],
600
+ inherited: this.scope
601
+ }
602
+ })).data.responses;
603
+ this.total = response.total;
604
+ this.fetchState = 'loaded';
605
+ return {
606
+ records: response.items,
607
+ total: response.total
608
+ };
609
+ }
610
+ catch (e) {
611
+ /* 못 읽은 것을 「없다」로 그리지 않는다. */
612
+ this.fetchState = 'failed';
613
+ throw e;
614
+ }
615
+ }
616
+ /**
617
+ * 격자에서 고친 줄들을 저장한다.
618
+ *
619
+ * 이 저장소의 목록 관례를 그대로 쓴다 — `dirtyRecords` 를 `__dirtyfields__[key].after` 로 펴서
620
+ * `cuFlag` 와 함께 보낸다(`fiscal-quarter-list-page` 가 같은 모양). 서버가
621
+ * `updateMultipleRole` 로 받는다.
622
+ *
623
+ * **`privileges` 는 안 보낸다.** 여기서 고치는 것은 이름과 설명이고, 권한은 전용 화면이
624
+ * 소유한다. 안 보낸 것을 「비우라」로 읽으면 이름만 고친 순간 그 역할이 아무것도 안 여는
625
+ * 역할이 된다 — 서버 쪽에도 같은 말을 주석으로 적어 뒀다.
626
+ */
627
+ async onSaveGrid() {
628
+ const dirty = this.grist.dirtyRecords;
629
+ if (!dirty?.length) {
630
+ return;
631
+ }
632
+ const patches = dirty.map((record) => {
633
+ const patch = record.id ? { id: record.id } : {};
634
+ for (const key in record.__dirtyfields__) {
635
+ patch[key] = record.__dirtyfields__[key].after;
636
+ }
637
+ patch.cuFlag = record.__dirty__;
638
+ return patch;
639
+ });
640
+ const response = await client.mutate({
641
+ mutation: gql `
642
+ mutation ($patches: [RolePatch!]!) {
643
+ updateMultipleRole(patches: $patches) {
644
+ id
645
+ }
646
+ }
647
+ `,
648
+ variables: { patches },
649
+ context: gqlContext()
650
+ });
651
+ if (response.errors?.length) {
652
+ /* 실패를 조용히 넘기지 않는다 — 격자는 고친 채로 남아 있어야 다시 저장할 수 있다. */
653
+ document.dispatchEvent(new CustomEvent('notify', { detail: { level: 'error', message: response.errors[0]?.message } }));
654
+ return;
655
+ }
656
+ this.grist.fetch();
657
+ }
658
+ /**
659
+ * 고른 역할을 지운다.
660
+ *
661
+ * 서버는 **가진 사람이 있는 역할을 남긴다**(`deleteRoles`). 그래서 여기서 「지웠다」고 말하지
662
+ * 않고 목록을 다시 읽는다 — 무엇이 남았는지가 화면에서 보이는 것이 맞다.
663
+ */
664
+ async onDeleteGrid() {
665
+ const selected = this.grist.selected;
666
+ if (!selected?.length) {
667
+ return;
668
+ }
669
+ /*
670
+ * **상속된 행은 여기서 못 지운다** — `deleteRoles` 가 `domain.id` 로 좁혀 찾으므로 그 행은
671
+ * 조용히 남는다. 「지웠다」로 보이고 목록에 그대로 있으면 사람이 두 번 세 번 누른다.
672
+ */
673
+ const mine = selected.filter((record) => !this.isInherited(record));
674
+ if (!mine.length) {
675
+ await OxPrompt.open({
676
+ type: 'warning',
677
+ title: i18next.t('button.delete'),
678
+ text: i18next.t('text.inherited roles are edited in their own domain'),
679
+ confirmButton: { text: i18next.t('button.confirm') }
680
+ });
681
+ return;
682
+ }
683
+ if (!(await OxPrompt.open({
684
+ type: 'warning',
685
+ title: i18next.t('button.delete'),
686
+ text: i18next.t('text.roles in use are kept'),
687
+ confirmButton: { text: i18next.t('button.confirm') },
688
+ cancelButton: { text: i18next.t('button.cancel') }
689
+ }))) {
690
+ return;
691
+ }
692
+ const response = await client.mutate({
693
+ mutation: gql `
694
+ mutation ($ids: [String!]!) {
695
+ deleteRoles(ids: $ids)
696
+ }
697
+ `,
698
+ variables: { ids: mine.map((record) => record.id) },
699
+ context: gqlContext()
700
+ });
701
+ if (response.errors?.length) {
702
+ document.dispatchEvent(new CustomEvent('notify', { detail: { level: 'error', message: response.errors[0]?.message } }));
703
+ return;
704
+ }
705
+ this.grist.fetch();
706
+ }
707
+ /**
708
+ * 역할을 만드는 두 문을 **한 자리에** 연다.
709
+ *
710
+ * ── 왜 `ox-record-creator`(빈 줄)를 걷어냈나 ────────────────────────────────
711
+ * 이름을 짓는 것은 쉬운 쪽이고 「품질검사원에게 84개 중 무엇을 주나」가 어려운 쪽인데, 빈
712
+ * 줄은 그 판단을 통째로 사람에게 넘긴다. 미라텍이 그래서 역할 둘뿐이다.
713
+ *
714
+ * 그리고 그 단추는 `.filters` 안에 있었는데 `CommonHeaderStyles` 는 `.actions button` 만
715
+ * 꾸민다. `.filters` 에 button 규칙이 없어서 **브라우저 기본 단추**가 그대로 나왔다 — 옆의
716
+ * 알약 범위 단추·검색과 같은 줄에서 혼자 네모난 회색 상자였다. 이 관례를 쓰는 다른 목록
717
+ * 화면(24 파일)도 전부 같은 상태다.
718
+ *
719
+ * ── 순서가 가르친다 ────────────────────────────────────────────────────────
720
+ * 템플릿이 먼저고 백지가 나중이다. 「품질검사원, 권한 7」을 본 사람은 자리가 어떻게 생긴
721
+ * 것인지 알고 나서 자기 것을 짓는다. 그렇다고 백지를 감추면 안 된다 — 「야간반장」·「외주
722
+ * 검사」 같은 자리는 그 공장이 아는 것이지 제품이 아는 게 아니다.
723
+ */
724
+ async openCreate() {
725
+ await import('../../components/role-template-picker.js');
726
+ const popup = openPopup(html `<role-template-picker .page=${this} @close=${() => popup.close()}></role-template-picker>`, {
727
+ backdrop: true,
728
+ size: 'large',
729
+ title: i18next.t('button.create role')
730
+ });
731
+ }
732
+ /** 템플릿에서 — 이름은 이 공장이 정한 것을 그대로 보낸다. */
733
+ async createFromTemplate(templateId, name) {
734
+ const response = await client.mutate({
735
+ mutation: gql `
736
+ mutation ($templateId: String!, $name: String) {
737
+ createRoleFromTemplate(templateId: $templateId, name: $name) {
738
+ id
739
+ }
740
+ }
741
+ `,
742
+ variables: { templateId, name },
743
+ context: gqlContext()
744
+ });
745
+ if (response.errors?.length) {
746
+ document.dispatchEvent(new CustomEvent('notify', { detail: { level: 'error', message: response.errors[0]?.message } }));
747
+ return false;
748
+ }
749
+ this.grist.fetch();
750
+ return true;
751
+ }
752
+ /** 백지에서 — 권한 없이 선다. 목록의 권한 수 칸이 0 을 빨갛게 말하므로 다음 걸음이 보인다. */
753
+ async createBlankRole(name, description) {
754
+ return await this.onCreateRole({ name, description });
755
+ }
756
+ /**
757
+ * 새 역할.
758
+ *
759
+ * **권한 없이 만들어진다.** 그것이 맞다 — 이름을 정하는 것과 무엇을 열지 정하는 것은 다른
760
+ * 판단이고, 목록의 요약 칸이 「여는 것이 없음」을 빨갛게 말하므로 다음 걸음이 보인다.
761
+ */
762
+ async onCreateRole(record) {
763
+ const response = await client.mutate({
764
+ mutation: gql `
765
+ mutation ($role: NewRole!) {
766
+ createRole(role: $role) {
767
+ id
768
+ }
769
+ }
770
+ `,
771
+ variables: { role: { name: record.name, description: record.description } },
772
+ context: gqlContext()
773
+ });
774
+ if (response.errors?.length) {
775
+ document.dispatchEvent(new CustomEvent('notify', { detail: { level: 'error', message: response.errors[0]?.message } }));
776
+ return false;
777
+ }
778
+ this.grist.fetch();
779
+ return true;
780
+ }
781
+ };
782
+ __decorate([
783
+ property({ type: Object }),
784
+ __metadata("design:type", Object)
785
+ ], RoleListPage.prototype, "config", void 0);
786
+ __decorate([
787
+ property({ type: String }),
788
+ __metadata("design:type", String)
789
+ ], RoleListPage.prototype, "mode", void 0);
790
+ __decorate([
791
+ state(),
792
+ __metadata("design:type", String)
793
+ ], RoleListPage.prototype, "fetchState", void 0);
794
+ __decorate([
795
+ state(),
796
+ __metadata("design:type", Number)
797
+ ], RoleListPage.prototype, "total", void 0);
798
+ __decorate([
799
+ state(),
800
+ __metadata("design:type", Boolean)
801
+ ], RoleListPage.prototype, "filtered", void 0);
802
+ __decorate([
803
+ state(),
804
+ __metadata("design:type", String)
805
+ ], RoleListPage.prototype, "mySubdomain", void 0);
806
+ __decorate([
807
+ state(),
808
+ __metadata("design:type", String)
809
+ ], RoleListPage.prototype, "scope", void 0);
810
+ __decorate([
811
+ state(),
812
+ __metadata("design:type", Object)
813
+ ], RoleListPage.prototype, "counts", void 0);
814
+ __decorate([
815
+ query('ox-grist'),
816
+ __metadata("design:type", Function)
817
+ ], RoleListPage.prototype, "grist", void 0);
818
+ RoleListPage = __decorate([
819
+ customElement('role-list-page')
820
+ ], RoleListPage);
821
+ export { RoleListPage };
822
+ /**
823
+ * 권한 수 한 칸 — **0 이 가장 할 말이 많은 값이다.**
824
+ *
825
+ * 권한이 하나도 없는 역할은 붙여도 아무 일이 없다. 그것이 이 화면에서 **조치가 필요한 유일한
826
+ * 상태**이므로 색을 그때만 쓴다. 나머지는 수만 낸다.
827
+ */
828
+ function privilegeCountCell(_value, _column, record) {
829
+ const count = record?.privilegeCount;
830
+ /* 「모른다」와 「0」은 다르다 — 아직 안 온 값에 색을 쓰지 않는다. */
831
+ if (count === undefined || count === null) {
832
+ return html ``;
833
+ }
834
+ return count === 0
835
+ ? html `<span class="badge" attention>${i18next.t('text.no privilege granted')}</span>`
836
+ : html `<span class="badge">${count}</span>`;
837
+ }
838
+ //# sourceMappingURL=role-list-page.js.map