@things-factory/auth-ui 8.0.0-alpha.36 → 8.0.0-alpha.37
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.
- package/client/components/role-privilege-editor.ts +31 -5
- package/dist-client/components/role-privilege-editor.js +38 -9
- package/dist-client/components/role-privilege-editor.js.map +1 -1
- package/dist-client/tsconfig.tsbuildinfo +1 -1
- package/dist-server/tsconfig.tsbuildinfo +1 -1
- package/package.json +2 -2
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import gql from 'graphql-tag'
|
|
2
2
|
import { css, html, LitElement } from 'lit'
|
|
3
|
-
import { customElement, property } from 'lit/decorators.js'
|
|
3
|
+
import { customElement, property, state } from 'lit/decorators.js'
|
|
4
4
|
|
|
5
5
|
import { client, gqlContext } from '@operato/graphql'
|
|
6
6
|
import { i18next, localize } from '@operato/i18n'
|
|
@@ -24,6 +24,17 @@ class RolePrivilegeEditor extends localize(i18next)(LitElement) {
|
|
|
24
24
|
margin: var(--spacing-medium);
|
|
25
25
|
}
|
|
26
26
|
|
|
27
|
+
div[users] {
|
|
28
|
+
margin: 0;
|
|
29
|
+
background-color: var(--md-sys-color-surface-variant);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
div[titler] {
|
|
33
|
+
color: var(--md-sys-color-secondary);
|
|
34
|
+
font: bold 1.2em var(--theme-font);
|
|
35
|
+
text-transform: capitalize;
|
|
36
|
+
}
|
|
37
|
+
|
|
27
38
|
ul {
|
|
28
39
|
flex: 1;
|
|
29
40
|
color: var(--md-sys-color-secondary);
|
|
@@ -31,7 +42,8 @@ class RolePrivilegeEditor extends localize(i18next)(LitElement) {
|
|
|
31
42
|
overflow: auto;
|
|
32
43
|
display: grid;
|
|
33
44
|
grid-template-columns: 1fr 1fr;
|
|
34
|
-
margin: 0;
|
|
45
|
+
margin-block-start: 0;
|
|
46
|
+
margin-block-end: 0;
|
|
35
47
|
padding: var(--spacing-medium);
|
|
36
48
|
list-style: none;
|
|
37
49
|
border: 1px dashed rgba(0, 0, 0, 0.1);
|
|
@@ -72,14 +84,23 @@ class RolePrivilegeEditor extends localize(i18next)(LitElement) {
|
|
|
72
84
|
|
|
73
85
|
@property({ type: Object }) role: any
|
|
74
86
|
@property({ type: Array }) allPrivileges: any[] = []
|
|
75
|
-
@property({ type: Array }) privileges: any[] = []
|
|
76
87
|
@property({ type: Object }) updateRoleObj: any
|
|
77
88
|
|
|
89
|
+
@state() privileges: { id: string; description: string }[] = []
|
|
90
|
+
@state() users: { /* id: string; username: string; */ name: string; email: string }[] = []
|
|
91
|
+
|
|
78
92
|
render() {
|
|
79
93
|
const allPrivileges = this.allPrivileges || []
|
|
80
94
|
const privileges = this.privileges || []
|
|
95
|
+
const users = this.users || []
|
|
81
96
|
|
|
82
97
|
return html`
|
|
98
|
+
<div titler>${String(i18next.t('label.user'))}</div>
|
|
99
|
+
|
|
100
|
+
<div users>${users.map(user => html`<div>${user.name} (${user.email})</div>`)}</div>
|
|
101
|
+
|
|
102
|
+
<div titler>${String(i18next.t('field.privileges'))}</div>
|
|
103
|
+
|
|
83
104
|
<div>
|
|
84
105
|
<input id="checkAll" type="checkbox" @change=${e => this.oncheckAll(e)} />
|
|
85
106
|
<label for="checkAll">Check all</label>
|
|
@@ -116,7 +137,7 @@ class RolePrivilegeEditor extends localize(i18next)(LitElement) {
|
|
|
116
137
|
|
|
117
138
|
async updated(changes) {
|
|
118
139
|
if (changes.has('role')) {
|
|
119
|
-
|
|
140
|
+
await this.fetchPrivilegesOnRole(this.role.name)
|
|
120
141
|
}
|
|
121
142
|
}
|
|
122
143
|
|
|
@@ -226,6 +247,10 @@ class RolePrivilegeEditor extends localize(i18next)(LitElement) {
|
|
|
226
247
|
id
|
|
227
248
|
description
|
|
228
249
|
}
|
|
250
|
+
users {
|
|
251
|
+
name
|
|
252
|
+
email
|
|
253
|
+
}
|
|
229
254
|
}
|
|
230
255
|
}
|
|
231
256
|
`,
|
|
@@ -233,7 +258,8 @@ class RolePrivilegeEditor extends localize(i18next)(LitElement) {
|
|
|
233
258
|
context: gqlContext()
|
|
234
259
|
})
|
|
235
260
|
|
|
236
|
-
|
|
261
|
+
this.privileges = response.data.role?.privileges
|
|
262
|
+
this.users = response.data.role?.users
|
|
237
263
|
}
|
|
238
264
|
|
|
239
265
|
showToast(message) {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { __decorate, __metadata } from "tslib";
|
|
2
2
|
import gql from 'graphql-tag';
|
|
3
3
|
import { css, html, LitElement } from 'lit';
|
|
4
|
-
import { customElement, property } from 'lit/decorators.js';
|
|
4
|
+
import { customElement, property, state } from 'lit/decorators.js';
|
|
5
5
|
import { client, gqlContext } from '@operato/graphql';
|
|
6
6
|
import { i18next, localize } from '@operato/i18n';
|
|
7
7
|
import { OxPrompt } from '@operato/popup/ox-prompt.js';
|
|
@@ -11,11 +11,19 @@ let RolePrivilegeEditor = class RolePrivilegeEditor extends localize(i18next)(Li
|
|
|
11
11
|
super(...arguments);
|
|
12
12
|
this.allPrivileges = [];
|
|
13
13
|
this.privileges = [];
|
|
14
|
+
this.users = [];
|
|
14
15
|
}
|
|
15
16
|
render() {
|
|
16
17
|
const allPrivileges = this.allPrivileges || [];
|
|
17
18
|
const privileges = this.privileges || [];
|
|
19
|
+
const users = this.users || [];
|
|
18
20
|
return html `
|
|
21
|
+
<div titler>${String(i18next.t('label.user'))}</div>
|
|
22
|
+
|
|
23
|
+
<div users>${users.map(user => html `<div>${user.name} (${user.email})</div>`)}</div>
|
|
24
|
+
|
|
25
|
+
<div titler>${String(i18next.t('field.privileges'))}</div>
|
|
26
|
+
|
|
19
27
|
<div>
|
|
20
28
|
<input id="checkAll" type="checkbox" @change=${e => this.oncheckAll(e)} />
|
|
21
29
|
<label for="checkAll">Check all</label>
|
|
@@ -48,7 +56,7 @@ let RolePrivilegeEditor = class RolePrivilegeEditor extends localize(i18next)(Li
|
|
|
48
56
|
}
|
|
49
57
|
async updated(changes) {
|
|
50
58
|
if (changes.has('role')) {
|
|
51
|
-
|
|
59
|
+
await this.fetchPrivilegesOnRole(this.role.name);
|
|
52
60
|
}
|
|
53
61
|
}
|
|
54
62
|
checkAll(checked) {
|
|
@@ -130,7 +138,7 @@ let RolePrivilegeEditor = class RolePrivilegeEditor extends localize(i18next)(Li
|
|
|
130
138
|
return response.data.privileges.items;
|
|
131
139
|
}
|
|
132
140
|
async fetchPrivilegesOnRole(name) {
|
|
133
|
-
var _a;
|
|
141
|
+
var _a, _b;
|
|
134
142
|
const response = await client.query({
|
|
135
143
|
query: gql `
|
|
136
144
|
query ($name: String!) {
|
|
@@ -141,13 +149,18 @@ let RolePrivilegeEditor = class RolePrivilegeEditor extends localize(i18next)(Li
|
|
|
141
149
|
id
|
|
142
150
|
description
|
|
143
151
|
}
|
|
152
|
+
users {
|
|
153
|
+
name
|
|
154
|
+
email
|
|
155
|
+
}
|
|
144
156
|
}
|
|
145
157
|
}
|
|
146
158
|
`,
|
|
147
159
|
variables: { name },
|
|
148
160
|
context: gqlContext()
|
|
149
161
|
});
|
|
150
|
-
|
|
162
|
+
this.privileges = (_a = response.data.role) === null || _a === void 0 ? void 0 : _a.privileges;
|
|
163
|
+
this.users = (_b = response.data.role) === null || _b === void 0 ? void 0 : _b.users;
|
|
151
164
|
}
|
|
152
165
|
showToast(message) {
|
|
153
166
|
document.dispatchEvent(new CustomEvent('notify', { detail: { message, option: { timer: 1000 } } }));
|
|
@@ -168,6 +181,17 @@ RolePrivilegeEditor.styles = [
|
|
|
168
181
|
margin: var(--spacing-medium);
|
|
169
182
|
}
|
|
170
183
|
|
|
184
|
+
div[users] {
|
|
185
|
+
margin: 0;
|
|
186
|
+
background-color: var(--md-sys-color-surface-variant);
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
div[titler] {
|
|
190
|
+
color: var(--md-sys-color-secondary);
|
|
191
|
+
font: bold 1.2em var(--theme-font);
|
|
192
|
+
text-transform: capitalize;
|
|
193
|
+
}
|
|
194
|
+
|
|
171
195
|
ul {
|
|
172
196
|
flex: 1;
|
|
173
197
|
color: var(--md-sys-color-secondary);
|
|
@@ -175,7 +199,8 @@ RolePrivilegeEditor.styles = [
|
|
|
175
199
|
overflow: auto;
|
|
176
200
|
display: grid;
|
|
177
201
|
grid-template-columns: 1fr 1fr;
|
|
178
|
-
margin: 0;
|
|
202
|
+
margin-block-start: 0;
|
|
203
|
+
margin-block-end: 0;
|
|
179
204
|
padding: var(--spacing-medium);
|
|
180
205
|
list-style: none;
|
|
181
206
|
border: 1px dashed rgba(0, 0, 0, 0.1);
|
|
@@ -221,14 +246,18 @@ __decorate([
|
|
|
221
246
|
property({ type: Array }),
|
|
222
247
|
__metadata("design:type", Array)
|
|
223
248
|
], RolePrivilegeEditor.prototype, "allPrivileges", void 0);
|
|
224
|
-
__decorate([
|
|
225
|
-
property({ type: Array }),
|
|
226
|
-
__metadata("design:type", Array)
|
|
227
|
-
], RolePrivilegeEditor.prototype, "privileges", void 0);
|
|
228
249
|
__decorate([
|
|
229
250
|
property({ type: Object }),
|
|
230
251
|
__metadata("design:type", Object)
|
|
231
252
|
], RolePrivilegeEditor.prototype, "updateRoleObj", void 0);
|
|
253
|
+
__decorate([
|
|
254
|
+
state(),
|
|
255
|
+
__metadata("design:type", Array)
|
|
256
|
+
], RolePrivilegeEditor.prototype, "privileges", void 0);
|
|
257
|
+
__decorate([
|
|
258
|
+
state(),
|
|
259
|
+
__metadata("design:type", Array)
|
|
260
|
+
], RolePrivilegeEditor.prototype, "users", void 0);
|
|
232
261
|
RolePrivilegeEditor = __decorate([
|
|
233
262
|
customElement('role-privilege-editor')
|
|
234
263
|
], RolePrivilegeEditor);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"role-privilege-editor.js","sourceRoot":"","sources":["../../client/components/role-privilege-editor.ts"],"names":[],"mappings":";AAAA,OAAO,GAAG,MAAM,aAAa,CAAA;AAC7B,OAAO,EAAE,GAAG,EAAE,IAAI,EAAE,UAAU,EAAE,MAAM,K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AAE,IAAI,EAAE,KAAK,EAAE,CAAC;;0DAA0B;AACzB;IAA1B,QAAQ,CAAC,EAAE,IAAI,EAAE,KAAK,EAAE,CAAC;;uDAAuB;AACrB;IAA3B,QAAQ,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;;0DAAmB;AAjE1C,mBAAmB;IADxB,aAAa,CAAC,uBAAuB,CAAC;GACjC,mBAAmB,CAuOxB","sourcesContent":["import gql from 'graphql-tag'\nimport { css, html, LitElement } from 'lit'\nimport { customElement, property } from 'lit/decorators.js'\n\nimport { client, gqlContext } from '@operato/graphql'\nimport { i18next, localize } from '@operato/i18n'\nimport { OxPrompt } from '@operato/popup/ox-prompt.js'\nimport { ButtonContainerStyles } from '@operato/styles'\n\n@customElement('role-privilege-editor')\nclass RolePrivilegeEditor extends localize(i18next)(LitElement) {\n static styles = [\n ButtonContainerStyles,\n css`\n :host {\n display: flex;\n flex-direction: column;\n\n border: 1px solid var(--md-sys-color-primary);\n font: normal 15px var(--theme-font);\n }\n\n div {\n margin: var(--spacing-medium);\n }\n\n ul {\n flex: 1;\n color: var(--md-sys-color-secondary);\n background-color: var(--md-sys-color-surface-variant);\n overflow: auto;\n display: grid;\n grid-template-columns: 1fr 1fr;\n margin: 0;\n padding: var(--spacing-medium);\n list-style: none;\n border: 1px dashed rgba(0, 0, 0, 0.1);\n border-width: 1px 0;\n }\n\n input[type='checkbox'] {\n display: inline;\n }\n\n li {\n padding: var(--spacing-small);\n }\n\n #checkAll,\n [for='checkAll'] {\n margin-bottom: var(--spacing-medium);\n padding-bottom: var(--spacing-small);\n font-weight: bold;\n }\n\n md-elevated-button {\n margin: 5px;\n background-color: var(--md-sys-color-surface-variant);\n }\n\n md-outlined-button {\n background-color: var(--md-sys-color-surface-variant);\n }\n\n @media screen and (max-width: 480px) {\n ul {\n grid-template-columns: 1fr;\n }\n }\n `\n ]\n\n @property({ type: Object }) role: any\n @property({ type: Array }) allPrivileges: any[] = []\n @property({ type: Array }) privileges: any[] = []\n @property({ type: Object }) updateRoleObj: any\n\n render() {\n const allPrivileges = this.allPrivileges || []\n const privileges = this.privileges || []\n\n return html`\n <div>\n <input id=\"checkAll\" type=\"checkbox\" @change=${e => this.oncheckAll(e)} />\n <label for=\"checkAll\">Check all</label>\n </div>\n\n <ul privileges>\n ${allPrivileges.map(\n privilege => html`\n <li>\n <input\n type=\"checkbox\"\n id=\"${privilege.id}\"\n .checked=${privileges.map(p => p.id).indexOf(privilege.id) > -1}\n .data-privilege=${privilege}\n />\n <label for=\"${privilege.id}\">${privilege.description}</label>\n </li>\n `\n )}\n </ul>\n\n <div class=\"button-container\">\n <md-elevated-button @click=${e => this.onSave()}>${String(i18next.t('button.save'))}</md-elevated-button>\n <md-elevated-button @click=${e => this.onDeleteRole()} danger\n >${String(i18next.t('button.delete role'))}</md-elevated-button\n >\n </div>\n `\n }\n\n async firstUpdated() {\n this.allPrivileges = await this.fetchPrivileges()\n }\n\n async updated(changes) {\n if (changes.has('role')) {\n this.privileges = await this.fetchPrivilegesOnRole(this.role.name)\n }\n }\n\n checkAll(checked) {\n Array.from(this.renderRoot.querySelectorAll('ul[privileges] input[type=checkbox]')).forEach(\n checkbox => ((checkbox as HTMLInputElement).checked = checked)\n )\n }\n\n oncheckAll(e) {\n this.checkAll(e.target.checked)\n }\n\n async onSave() {\n const updateRoleObj = this.updateRoleObj\n const privileges = Array.from(this.renderRoot.querySelectorAll('ul[privileges] input[type=checkbox]:checked')).map(\n e => e['data-privilege']\n )\n\n const patch = { ...updateRoleObj, privileges: privileges }\n\n if (this.role) {\n const response = await client.mutate({\n mutation: gql`\n mutation ($id: String!, $patch: RolePatch!) {\n updateRole(id: $id, patch: $patch) {\n id\n name\n description\n privileges {\n id\n description\n }\n }\n }\n `,\n variables: { id: this.role.id, patch },\n context: gqlContext()\n })\n\n if (!response.errors) {\n await this.dispatchEvent(new CustomEvent('fetch-roles'))\n this.showToast(i18next.t('text.data_updated_successfully'))\n }\n }\n }\n\n async onDeleteRole() {\n if (\n await OxPrompt.open({\n title: i18next.t('text.are_you_sure'),\n text: i18next.t('text.are_you_sure_to_delete_x', { x: i18next.t('label.role') }),\n confirmButton: { text: i18next.t('button.delete') },\n cancelButton: { text: i18next.t('button.cancel') }\n })\n ) {\n const response = await client.mutate({\n mutation: gql`\n mutation ($id: String!) {\n deleteRole(id: $id)\n }\n `,\n variables: { id: this.role.id },\n context: gqlContext()\n })\n\n if (!response.errors) {\n await this.dispatchEvent(new CustomEvent('fetch-roles'))\n\n await OxPrompt.open({\n type: 'success',\n title: i18next.t('text.completed'),\n text: i18next.t('text.x_deleted_successfully', { x: i18next.t('label.role') }),\n confirmButton: { text: i18next.t('button.confirm') }\n })\n }\n }\n }\n\n async fetchPrivileges() {\n const response = await client.query({\n query: gql`\n query privileges {\n privileges {\n items {\n id\n name\n description\n }\n total\n }\n }\n `\n })\n\n return response.data.privileges.items\n }\n\n async fetchPrivilegesOnRole(name) {\n const response = await client.query({\n query: gql`\n query ($name: String!) {\n role(name: $name) {\n id\n name\n privileges {\n id\n description\n }\n }\n }\n `,\n variables: { name },\n context: gqlContext()\n })\n\n return response.data.role?.privileges\n }\n\n showToast(message) {\n document.dispatchEvent(new CustomEvent('notify', { detail: { message, option: { timer: 1000 } } }))\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"role-privilege-editor.js","sourceRoot":"","sources":["../../client/components/role-privilege-editor.ts"],"names":[],"mappings":";AAAA,OAAO,GAAG,MAAM,aAAa,CAAA;AAC7B,OAAO,EAAE,GAAG,EAAE,IAAI,EAAE,UAAU,EAAE,MAAM,KAAK,CAAA;AAC3C,OAAO,EAAE,aAAa,EAAE,QAAQ,EAAE,KAAK,EAAE,MAAM,mBAAmB,CAAA;AAElE,OAAO,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAA;AACrD,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAA;AACjD,OAAO,EAAE,QAAQ,EAAE,MAAM,6BAA6B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A;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;KAoEF;CACF,AAvEY,CAuEZ;AAE2B;IAA3B,QAAQ,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;;iDAAU;AACV;IAA1B,QAAQ,CAAC,EAAE,IAAI,EAAE,KAAK,EAAE,CAAC;;0DAA0B;AACxB;IAA3B,QAAQ,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;;0DAAmB;AAErC;IAAR,KAAK,EAAE;;uDAAuD;AACtD;IAAR,KAAK,EAAE;;kDAAkF;AA/EtF,mBAAmB;IADxB,aAAa,CAAC,uBAAuB,CAAC;GACjC,mBAAmB,CAiQxB","sourcesContent":["import gql from 'graphql-tag'\nimport { css, html, LitElement } from 'lit'\nimport { customElement, property, state } from 'lit/decorators.js'\n\nimport { client, gqlContext } from '@operato/graphql'\nimport { i18next, localize } from '@operato/i18n'\nimport { OxPrompt } from '@operato/popup/ox-prompt.js'\nimport { ButtonContainerStyles } from '@operato/styles'\n\n@customElement('role-privilege-editor')\nclass RolePrivilegeEditor extends localize(i18next)(LitElement) {\n static styles = [\n ButtonContainerStyles,\n css`\n :host {\n display: flex;\n flex-direction: column;\n\n border: 1px solid var(--md-sys-color-primary);\n font: normal 15px var(--theme-font);\n }\n\n div {\n margin: var(--spacing-medium);\n }\n\n div[users] {\n margin: 0;\n background-color: var(--md-sys-color-surface-variant);\n }\n\n div[titler] {\n color: var(--md-sys-color-secondary);\n font: bold 1.2em var(--theme-font);\n text-transform: capitalize;\n }\n\n ul {\n flex: 1;\n color: var(--md-sys-color-secondary);\n background-color: var(--md-sys-color-surface-variant);\n overflow: auto;\n display: grid;\n grid-template-columns: 1fr 1fr;\n margin-block-start: 0;\n margin-block-end: 0;\n padding: var(--spacing-medium);\n list-style: none;\n border: 1px dashed rgba(0, 0, 0, 0.1);\n border-width: 1px 0;\n }\n\n input[type='checkbox'] {\n display: inline;\n }\n\n li {\n padding: var(--spacing-small);\n }\n\n #checkAll,\n [for='checkAll'] {\n margin-bottom: var(--spacing-medium);\n padding-bottom: var(--spacing-small);\n font-weight: bold;\n }\n\n md-elevated-button {\n margin: 5px;\n background-color: var(--md-sys-color-surface-variant);\n }\n\n md-outlined-button {\n background-color: var(--md-sys-color-surface-variant);\n }\n\n @media screen and (max-width: 480px) {\n ul {\n grid-template-columns: 1fr;\n }\n }\n `\n ]\n\n @property({ type: Object }) role: any\n @property({ type: Array }) allPrivileges: any[] = []\n @property({ type: Object }) updateRoleObj: any\n\n @state() privileges: { id: string; description: string }[] = []\n @state() users: { /* id: string; username: string; */ name: string; email: string }[] = []\n\n render() {\n const allPrivileges = this.allPrivileges || []\n const privileges = this.privileges || []\n const users = this.users || []\n\n return html`\n <div titler>${String(i18next.t('label.user'))}</div>\n\n <div users>${users.map(user => html`<div>${user.name} (${user.email})</div>`)}</div>\n\n <div titler>${String(i18next.t('field.privileges'))}</div>\n\n <div>\n <input id=\"checkAll\" type=\"checkbox\" @change=${e => this.oncheckAll(e)} />\n <label for=\"checkAll\">Check all</label>\n </div>\n\n <ul privileges>\n ${allPrivileges.map(\n privilege => html`\n <li>\n <input\n type=\"checkbox\"\n id=\"${privilege.id}\"\n .checked=${privileges.map(p => p.id).indexOf(privilege.id) > -1}\n .data-privilege=${privilege}\n />\n <label for=\"${privilege.id}\">${privilege.description}</label>\n </li>\n `\n )}\n </ul>\n\n <div class=\"button-container\">\n <md-elevated-button @click=${e => this.onSave()}>${String(i18next.t('button.save'))}</md-elevated-button>\n <md-elevated-button @click=${e => this.onDeleteRole()} danger\n >${String(i18next.t('button.delete role'))}</md-elevated-button\n >\n </div>\n `\n }\n\n async firstUpdated() {\n this.allPrivileges = await this.fetchPrivileges()\n }\n\n async updated(changes) {\n if (changes.has('role')) {\n await this.fetchPrivilegesOnRole(this.role.name)\n }\n }\n\n checkAll(checked) {\n Array.from(this.renderRoot.querySelectorAll('ul[privileges] input[type=checkbox]')).forEach(\n checkbox => ((checkbox as HTMLInputElement).checked = checked)\n )\n }\n\n oncheckAll(e) {\n this.checkAll(e.target.checked)\n }\n\n async onSave() {\n const updateRoleObj = this.updateRoleObj\n const privileges = Array.from(this.renderRoot.querySelectorAll('ul[privileges] input[type=checkbox]:checked')).map(\n e => e['data-privilege']\n )\n\n const patch = { ...updateRoleObj, privileges: privileges }\n\n if (this.role) {\n const response = await client.mutate({\n mutation: gql`\n mutation ($id: String!, $patch: RolePatch!) {\n updateRole(id: $id, patch: $patch) {\n id\n name\n description\n privileges {\n id\n description\n }\n }\n }\n `,\n variables: { id: this.role.id, patch },\n context: gqlContext()\n })\n\n if (!response.errors) {\n await this.dispatchEvent(new CustomEvent('fetch-roles'))\n this.showToast(i18next.t('text.data_updated_successfully'))\n }\n }\n }\n\n async onDeleteRole() {\n if (\n await OxPrompt.open({\n title: i18next.t('text.are_you_sure'),\n text: i18next.t('text.are_you_sure_to_delete_x', { x: i18next.t('label.role') }),\n confirmButton: { text: i18next.t('button.delete') },\n cancelButton: { text: i18next.t('button.cancel') }\n })\n ) {\n const response = await client.mutate({\n mutation: gql`\n mutation ($id: String!) {\n deleteRole(id: $id)\n }\n `,\n variables: { id: this.role.id },\n context: gqlContext()\n })\n\n if (!response.errors) {\n await this.dispatchEvent(new CustomEvent('fetch-roles'))\n\n await OxPrompt.open({\n type: 'success',\n title: i18next.t('text.completed'),\n text: i18next.t('text.x_deleted_successfully', { x: i18next.t('label.role') }),\n confirmButton: { text: i18next.t('button.confirm') }\n })\n }\n }\n }\n\n async fetchPrivileges() {\n const response = await client.query({\n query: gql`\n query privileges {\n privileges {\n items {\n id\n name\n description\n }\n total\n }\n }\n `\n })\n\n return response.data.privileges.items\n }\n\n async fetchPrivilegesOnRole(name) {\n const response = await client.query({\n query: gql`\n query ($name: String!) {\n role(name: $name) {\n id\n name\n privileges {\n id\n description\n }\n users {\n name\n email\n }\n }\n }\n `,\n variables: { name },\n context: gqlContext()\n })\n\n this.privileges = response.data.role?.privileges\n this.users = response.data.role?.users\n }\n\n showToast(message) {\n document.dispatchEvent(new CustomEvent('notify', { detail: { message, option: { timer: 1000 } } }))\n }\n}\n"]}
|