@things-factory/auth-ui 8.0.0-beta.9 → 8.0.0
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/auth-style-sign.ts +194 -0
- package/client/bootstrap.ts +51 -0
- package/client/components/abstract-auth-page.ts +301 -0
- package/client/components/abstract-password-reset.ts +168 -0
- package/client/components/abstract-sign.ts +127 -0
- package/client/components/change-password.ts +153 -0
- package/client/components/contact-us.ts +113 -0
- package/client/components/create-domain-popup.ts +141 -0
- package/client/components/create-role.ts +123 -0
- package/client/components/create-user.ts +95 -0
- package/client/components/credential-manager.ts +64 -0
- package/client/components/delete-user-popup.ts +117 -0
- package/client/components/domain-switch.ts +127 -0
- package/client/components/invite-customer.ts +104 -0
- package/client/components/invite-user.ts +96 -0
- package/client/components/my-login-history.ts +101 -0
- package/client/components/ownership-transfer-popup.ts +110 -0
- package/client/components/partner-info-card.ts +89 -0
- package/client/components/partner-role-editor.ts +153 -0
- package/client/components/profile-component.ts +332 -0
- package/client/components/role-edit-form.ts +92 -0
- package/client/components/role-privilege-editor.ts +267 -0
- package/client/components/role-selector.ts +102 -0
- package/client/components/user-role-editor.ts +499 -0
- package/client/constants/application.ts +9 -0
- package/client/constants/index.ts +1 -0
- package/client/entries/auth/activate.ts +272 -0
- package/client/entries/auth/checkin.ts +190 -0
- package/client/entries/auth/forgot-password.ts +103 -0
- package/client/entries/auth/reset-password.ts +22 -0
- package/client/entries/auth/result.ts +193 -0
- package/client/entries/auth/signin.ts +18 -0
- package/client/entries/auth/signup.ts +109 -0
- package/client/entries/auth/unlock-user.ts +22 -0
- package/client/entries/oauth2/oauth2-decision-error-page.ts +50 -0
- package/client/entries/oauth2/oauth2-decision-page.ts +196 -0
- package/client/entries/public/home.ts +246 -0
- package/client/index.ts +124 -0
- package/client/pages/app-binding/app-binding.ts +423 -0
- package/client/pages/app-binding/app-bindings.ts +171 -0
- package/client/pages/appliance/appliance.ts +452 -0
- package/client/pages/appliance/home.ts +177 -0
- package/client/pages/appliance/register.ts +183 -0
- package/client/pages/application/application.ts +428 -0
- package/client/pages/application/applications.ts +182 -0
- package/client/pages/application/register.ts +211 -0
- package/client/pages/attribute/attribute-set-item-list.ts +237 -0
- package/client/pages/attribute/attribute-set-management.ts +282 -0
- package/client/pages/auth-provider/auth-provider-management.ts +381 -0
- package/client/pages/domain/domain-management.ts +410 -0
- package/client/pages/partner/partner-management.ts +112 -0
- package/client/pages/profile.ts +32 -0
- package/client/pages/role/role-management.ts +134 -0
- package/client/pages/user/user-management.ts +224 -0
- package/client/route.ts +67 -0
- package/client/themes/auth-theme.css +65 -0
- package/client/utils/password-rule.ts +37 -0
- package/dist-client/components/abstract-auth-page.js +10 -10
- package/dist-client/components/abstract-auth-page.js.map +1 -1
- package/dist-client/components/abstract-password-reset.d.ts +2 -1
- package/dist-client/components/abstract-password-reset.js +14 -7
- package/dist-client/components/abstract-password-reset.js.map +1 -1
- package/dist-client/components/abstract-sign.js +11 -12
- package/dist-client/components/abstract-sign.js.map +1 -1
- package/dist-client/components/contact-us.d.ts +1 -1
- package/dist-client/components/contact-us.js +7 -10
- package/dist-client/components/contact-us.js.map +1 -1
- package/dist-client/components/create-user.js +5 -28
- package/dist-client/components/create-user.js.map +1 -1
- package/dist-client/components/invite-user.js +11 -19
- package/dist-client/components/invite-user.js.map +1 -1
- package/dist-client/components/ownership-transfer-popup.js +3 -3
- package/dist-client/components/ownership-transfer-popup.js.map +1 -1
- package/dist-client/components/profile-component.d.ts +1 -5
- package/dist-client/components/profile-component.js +4 -64
- package/dist-client/components/profile-component.js.map +1 -1
- package/dist-client/components/role-privilege-editor.js +1 -2
- package/dist-client/components/role-privilege-editor.js.map +1 -1
- package/dist-client/components/user-role-editor.js +18 -18
- package/dist-client/components/user-role-editor.js.map +1 -1
- package/dist-client/entries/auth/checkin.js +1 -1
- package/dist-client/entries/auth/checkin.js.map +1 -1
- package/dist-client/entries/auth/forgot-password.js +2 -11
- package/dist-client/entries/auth/forgot-password.js.map +1 -1
- package/dist-client/entries/auth/signup.js +7 -13
- package/dist-client/entries/auth/signup.js.map +1 -1
- package/dist-client/index.js +1 -1
- package/dist-client/index.js.map +1 -1
- package/dist-client/pages/user/user-management.d.ts +1 -5
- package/dist-client/pages/user/user-management.js +7 -6
- package/dist-client/pages/user/user-management.js.map +1 -1
- package/dist-client/tsconfig.tsbuildinfo +1 -1
- package/dist-server/tsconfig.tsbuildinfo +1 -1
- package/package.json +12 -12
- package/server/index.ts +0 -0
- package/translations/en.json +2 -6
- package/translations/ja.json +2 -6
- package/translations/ko.json +2 -6
- package/translations/ms.json +2 -6
- package/translations/zh.json +2 -6
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import { css, html, LitElement } from 'lit'
|
|
2
|
+
import { customElement, property, query } from 'lit/decorators.js'
|
|
3
|
+
|
|
4
|
+
import { i18next, localize } from '@operato/i18n'
|
|
5
|
+
|
|
6
|
+
@customElement('role-edit-form')
|
|
7
|
+
class RoleEditForm extends localize(i18next)(LitElement) {
|
|
8
|
+
static styles = css`
|
|
9
|
+
[field-2column] {
|
|
10
|
+
border-radius: var(--border-radius);
|
|
11
|
+
display: grid;
|
|
12
|
+
grid-template-columns: 1fr 1fr;
|
|
13
|
+
gap: 5px 15px;
|
|
14
|
+
clear: both;
|
|
15
|
+
max-width: var(--input-container-max-width);
|
|
16
|
+
}
|
|
17
|
+
[field] {
|
|
18
|
+
display: flex;
|
|
19
|
+
flex-direction: column;
|
|
20
|
+
padding-bottom: var(--spacing-medium);
|
|
21
|
+
}
|
|
22
|
+
input {
|
|
23
|
+
border: var(--border-dim-color);
|
|
24
|
+
border-radius: var(--border-radius);
|
|
25
|
+
margin: var(--input-margin);
|
|
26
|
+
padding: var(--input-padding);
|
|
27
|
+
min-width: 250px;
|
|
28
|
+
font: var(--input-font);
|
|
29
|
+
}
|
|
30
|
+
label {
|
|
31
|
+
display: flex;
|
|
32
|
+
flex-direction: column;
|
|
33
|
+
font: var(--label-font);
|
|
34
|
+
color: var(--md-sys-color-on-primary);
|
|
35
|
+
text-transform: var(--label-text-transform);
|
|
36
|
+
}
|
|
37
|
+
@media screen and (max-width: 480px) {
|
|
38
|
+
[field] {
|
|
39
|
+
grid-column: span 2;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
`
|
|
43
|
+
@property({ type: Object }) role: any
|
|
44
|
+
|
|
45
|
+
render() {
|
|
46
|
+
const role = this.role || { name: '', description: '' }
|
|
47
|
+
|
|
48
|
+
return html`
|
|
49
|
+
<form field-2column @input="${this.dispatchRoleChanged.bind(this)}">
|
|
50
|
+
<div field>
|
|
51
|
+
<label
|
|
52
|
+
>role name
|
|
53
|
+
<input name="name" value="${role.name}" @click="${e => e.stopPropagation()}" />
|
|
54
|
+
</label>
|
|
55
|
+
</div>
|
|
56
|
+
|
|
57
|
+
<div field>
|
|
58
|
+
<label
|
|
59
|
+
>role description
|
|
60
|
+
<input name="description" .value="${role.description}" @click="${e => e.stopPropagation()}" />
|
|
61
|
+
</label>
|
|
62
|
+
</div>
|
|
63
|
+
</form>
|
|
64
|
+
`
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
@query('input[name=name]') nameInput!: HTMLInputElement
|
|
68
|
+
@query('input[name=description]') descriptionInput!: HTMLInputElement
|
|
69
|
+
|
|
70
|
+
getRole() {
|
|
71
|
+
const name = this.nameInput.value
|
|
72
|
+
const description = this.descriptionInput.value
|
|
73
|
+
|
|
74
|
+
if (!name) {
|
|
75
|
+
return this.showToast(i18next.t('error.value is empty', { value: i18next.t('field.name') }))
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
return { name, description }
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
dispatchRoleChanged() {
|
|
82
|
+
this.dispatchEvent(
|
|
83
|
+
new CustomEvent('roleChanged', {
|
|
84
|
+
detail: this.getRole()
|
|
85
|
+
})
|
|
86
|
+
)
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
showToast(message) {
|
|
90
|
+
document.dispatchEvent(new CustomEvent('notify', { detail: { message, option: { timer: 1000 } } }))
|
|
91
|
+
}
|
|
92
|
+
}
|
|
@@ -0,0 +1,267 @@
|
|
|
1
|
+
import gql from 'graphql-tag'
|
|
2
|
+
import { css, html, LitElement } from 'lit'
|
|
3
|
+
import { customElement, property, state } from 'lit/decorators.js'
|
|
4
|
+
|
|
5
|
+
import { client, gqlContext } from '@operato/graphql'
|
|
6
|
+
import { i18next, localize } from '@operato/i18n'
|
|
7
|
+
import { OxPrompt } from '@operato/popup/ox-prompt.js'
|
|
8
|
+
import { ButtonContainerStyles } from '@operato/styles'
|
|
9
|
+
|
|
10
|
+
@customElement('role-privilege-editor')
|
|
11
|
+
class RolePrivilegeEditor extends localize(i18next)(LitElement) {
|
|
12
|
+
static styles = [
|
|
13
|
+
ButtonContainerStyles,
|
|
14
|
+
css`
|
|
15
|
+
:host {
|
|
16
|
+
display: flex;
|
|
17
|
+
flex-direction: column;
|
|
18
|
+
|
|
19
|
+
border: 1px solid var(--md-sys-color-primary);
|
|
20
|
+
font: normal 15px var(--theme-font);
|
|
21
|
+
color: var(--md-sys-color-secondary);
|
|
22
|
+
}
|
|
23
|
+
div {
|
|
24
|
+
margin: var(--spacing-medium);
|
|
25
|
+
}
|
|
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
|
+
|
|
38
|
+
ul {
|
|
39
|
+
flex: 1;
|
|
40
|
+
background-color: var(--md-sys-color-surface-variant);
|
|
41
|
+
overflow: auto;
|
|
42
|
+
display: grid;
|
|
43
|
+
grid-template-columns: 1fr 1fr;
|
|
44
|
+
margin-block-start: 0;
|
|
45
|
+
margin-block-end: 0;
|
|
46
|
+
padding: var(--spacing-medium);
|
|
47
|
+
list-style: none;
|
|
48
|
+
border: 1px dashed rgba(0, 0, 0, 0.1);
|
|
49
|
+
border-width: 1px 0;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
input[type='checkbox'] {
|
|
53
|
+
display: inline;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
li {
|
|
57
|
+
padding: var(--spacing-small);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
#checkAll,
|
|
61
|
+
[for='checkAll'] {
|
|
62
|
+
margin-bottom: var(--spacing-medium);
|
|
63
|
+
padding-bottom: var(--spacing-small);
|
|
64
|
+
font-weight: bold;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
md-elevated-button {
|
|
68
|
+
margin: 5px;
|
|
69
|
+
background-color: var(--md-sys-color-surface-variant);
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
md-outlined-button {
|
|
73
|
+
background-color: var(--md-sys-color-surface-variant);
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
@media screen and (max-width: 480px) {
|
|
77
|
+
ul {
|
|
78
|
+
grid-template-columns: 1fr;
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
`
|
|
82
|
+
]
|
|
83
|
+
|
|
84
|
+
@property({ type: Object }) role: any
|
|
85
|
+
@property({ type: Array }) allPrivileges: any[] = []
|
|
86
|
+
@property({ type: Object }) updateRoleObj: any
|
|
87
|
+
|
|
88
|
+
@state() privileges: { id: string; description: string }[] = []
|
|
89
|
+
@state() users: { /* id: string; username: string; */ name: string; email: string }[] = []
|
|
90
|
+
|
|
91
|
+
render() {
|
|
92
|
+
const allPrivileges = this.allPrivileges || []
|
|
93
|
+
const privileges = this.privileges || []
|
|
94
|
+
const users = this.users || []
|
|
95
|
+
|
|
96
|
+
return html`
|
|
97
|
+
<div titler>${String(i18next.t('label.user'))}</div>
|
|
98
|
+
|
|
99
|
+
<div users>${users.map(user => html`<div>${user.name} (${user.email})</div>`)}</div>
|
|
100
|
+
|
|
101
|
+
<div titler>${String(i18next.t('field.privileges'))}</div>
|
|
102
|
+
|
|
103
|
+
<div>
|
|
104
|
+
<input id="checkAll" type="checkbox" @change=${e => this.oncheckAll(e)} />
|
|
105
|
+
<label for="checkAll">Check all</label>
|
|
106
|
+
</div>
|
|
107
|
+
|
|
108
|
+
<ul privileges>
|
|
109
|
+
${allPrivileges.map(
|
|
110
|
+
privilege => html`
|
|
111
|
+
<li>
|
|
112
|
+
<input
|
|
113
|
+
type="checkbox"
|
|
114
|
+
id="${privilege.id}"
|
|
115
|
+
.checked=${privileges.map(p => p.id).indexOf(privilege.id) > -1}
|
|
116
|
+
.data-privilege=${privilege}
|
|
117
|
+
/>
|
|
118
|
+
<label for="${privilege.id}">${privilege.description}</label>
|
|
119
|
+
</li>
|
|
120
|
+
`
|
|
121
|
+
)}
|
|
122
|
+
</ul>
|
|
123
|
+
|
|
124
|
+
<div class="button-container">
|
|
125
|
+
<md-elevated-button @click=${e => this.onSave()}>${String(i18next.t('button.save'))}</md-elevated-button>
|
|
126
|
+
<md-elevated-button @click=${e => this.onDeleteRole()} danger
|
|
127
|
+
>${String(i18next.t('button.delete role'))}</md-elevated-button
|
|
128
|
+
>
|
|
129
|
+
</div>
|
|
130
|
+
`
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
async firstUpdated() {
|
|
134
|
+
this.allPrivileges = await this.fetchPrivileges()
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
async updated(changes) {
|
|
138
|
+
if (changes.has('role')) {
|
|
139
|
+
await this.fetchPrivilegesOnRole(this.role.name)
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
checkAll(checked) {
|
|
144
|
+
Array.from(this.renderRoot.querySelectorAll('ul[privileges] input[type=checkbox]')).forEach(
|
|
145
|
+
checkbox => ((checkbox as HTMLInputElement).checked = checked)
|
|
146
|
+
)
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
oncheckAll(e) {
|
|
150
|
+
this.checkAll(e.target.checked)
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
async onSave() {
|
|
154
|
+
const updateRoleObj = this.updateRoleObj
|
|
155
|
+
const privileges = Array.from(this.renderRoot.querySelectorAll('ul[privileges] input[type=checkbox]:checked')).map(
|
|
156
|
+
e => e['data-privilege']
|
|
157
|
+
)
|
|
158
|
+
|
|
159
|
+
const patch = { ...updateRoleObj, privileges: privileges }
|
|
160
|
+
|
|
161
|
+
if (this.role) {
|
|
162
|
+
const response = await client.mutate({
|
|
163
|
+
mutation: gql`
|
|
164
|
+
mutation ($id: String!, $patch: RolePatch!) {
|
|
165
|
+
updateRole(id: $id, patch: $patch) {
|
|
166
|
+
id
|
|
167
|
+
name
|
|
168
|
+
description
|
|
169
|
+
privileges {
|
|
170
|
+
id
|
|
171
|
+
description
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
`,
|
|
176
|
+
variables: { id: this.role.id, patch },
|
|
177
|
+
context: gqlContext()
|
|
178
|
+
})
|
|
179
|
+
|
|
180
|
+
if (!response.errors) {
|
|
181
|
+
await this.dispatchEvent(new CustomEvent('fetch-roles'))
|
|
182
|
+
this.showToast(i18next.t('text.data_updated_successfully'))
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
async onDeleteRole() {
|
|
188
|
+
if (
|
|
189
|
+
await OxPrompt.open({
|
|
190
|
+
title: i18next.t('text.are_you_sure'),
|
|
191
|
+
text: i18next.t('text.are_you_sure_to_delete_x', { x: i18next.t('label.role') }),
|
|
192
|
+
confirmButton: { text: i18next.t('button.delete') },
|
|
193
|
+
cancelButton: { text: i18next.t('button.cancel') }
|
|
194
|
+
})
|
|
195
|
+
) {
|
|
196
|
+
const response = await client.mutate({
|
|
197
|
+
mutation: gql`
|
|
198
|
+
mutation ($id: String!) {
|
|
199
|
+
deleteRole(id: $id)
|
|
200
|
+
}
|
|
201
|
+
`,
|
|
202
|
+
variables: { id: this.role.id },
|
|
203
|
+
context: gqlContext()
|
|
204
|
+
})
|
|
205
|
+
|
|
206
|
+
if (!response.errors) {
|
|
207
|
+
await this.dispatchEvent(new CustomEvent('fetch-roles'))
|
|
208
|
+
|
|
209
|
+
await OxPrompt.open({
|
|
210
|
+
type: 'success',
|
|
211
|
+
title: i18next.t('text.completed'),
|
|
212
|
+
text: i18next.t('text.x_deleted_successfully', { x: i18next.t('label.role') }),
|
|
213
|
+
confirmButton: { text: i18next.t('button.confirm') }
|
|
214
|
+
})
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
async fetchPrivileges() {
|
|
220
|
+
const response = await client.query({
|
|
221
|
+
query: gql`
|
|
222
|
+
query privileges {
|
|
223
|
+
privileges {
|
|
224
|
+
items {
|
|
225
|
+
id
|
|
226
|
+
name
|
|
227
|
+
description
|
|
228
|
+
}
|
|
229
|
+
total
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
`
|
|
233
|
+
})
|
|
234
|
+
|
|
235
|
+
return response.data.privileges.items
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
async fetchPrivilegesOnRole(name) {
|
|
239
|
+
const response = await client.query({
|
|
240
|
+
query: gql`
|
|
241
|
+
query ($name: String!) {
|
|
242
|
+
role(name: $name) {
|
|
243
|
+
id
|
|
244
|
+
name
|
|
245
|
+
privileges {
|
|
246
|
+
id
|
|
247
|
+
description
|
|
248
|
+
}
|
|
249
|
+
users {
|
|
250
|
+
name
|
|
251
|
+
email
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
`,
|
|
256
|
+
variables: { name },
|
|
257
|
+
context: gqlContext()
|
|
258
|
+
})
|
|
259
|
+
|
|
260
|
+
this.privileges = response.data.role?.privileges
|
|
261
|
+
this.users = response.data.role?.users
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
showToast(message) {
|
|
265
|
+
document.dispatchEvent(new CustomEvent('notify', { detail: { message, option: { timer: 1000 } } }))
|
|
266
|
+
}
|
|
267
|
+
}
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
import { css, html, LitElement, nothing } from 'lit'
|
|
2
|
+
import { customElement, property } from 'lit/decorators.js'
|
|
3
|
+
|
|
4
|
+
@customElement('role-selector')
|
|
5
|
+
export class RoleSelector extends LitElement {
|
|
6
|
+
static styles = [
|
|
7
|
+
css`
|
|
8
|
+
[subtitle] {
|
|
9
|
+
margin: 0;
|
|
10
|
+
padding: var(--subtitle-padding);
|
|
11
|
+
font: var(--subtitle-font);
|
|
12
|
+
color: var(--subtitle-text-color);
|
|
13
|
+
}
|
|
14
|
+
div {
|
|
15
|
+
margin: 0 var(--spacing-medium) var(--spacing-medium) var(--spacing-medium);
|
|
16
|
+
}
|
|
17
|
+
ul {
|
|
18
|
+
flex: 1;
|
|
19
|
+
display: grid;
|
|
20
|
+
grid-template-columns: 1fr 1fr;
|
|
21
|
+
column-gap: 20px;
|
|
22
|
+
overflow: auto;
|
|
23
|
+
margin: 0;
|
|
24
|
+
padding: var(--spacing-medium);
|
|
25
|
+
list-style: none;
|
|
26
|
+
border: 1px dashed rgba(0, 0, 0, 0.1);
|
|
27
|
+
border-width: 1px 0;
|
|
28
|
+
}
|
|
29
|
+
input[type='checkbox'] {
|
|
30
|
+
display: inline;
|
|
31
|
+
}
|
|
32
|
+
label {
|
|
33
|
+
padding-left: var(--spacing-small);
|
|
34
|
+
text-transform: capitalize;
|
|
35
|
+
font: var(--label-font);
|
|
36
|
+
color: var(--label-color, var(--md-sys-color-on-surface));
|
|
37
|
+
}
|
|
38
|
+
li {
|
|
39
|
+
padding: var(--spacing-small);
|
|
40
|
+
}
|
|
41
|
+
#checkAll,
|
|
42
|
+
[for='checkAll'] {
|
|
43
|
+
margin-bottom: var(--spacing-medium);
|
|
44
|
+
padding-bottom: var(--spacing-small);
|
|
45
|
+
font-weight: bold;
|
|
46
|
+
}
|
|
47
|
+
`
|
|
48
|
+
]
|
|
49
|
+
|
|
50
|
+
@property({ type: String }) roleCategory: string = 'Roles'
|
|
51
|
+
@property({ type: Object }) user: any = {}
|
|
52
|
+
@property({ type: Array }) roles: any[] = []
|
|
53
|
+
@property({ type: Array }) userRoles: any[] = []
|
|
54
|
+
|
|
55
|
+
render() {
|
|
56
|
+
const userRoleIds = (this.userRoles || []).map(userRole => userRole.id)
|
|
57
|
+
|
|
58
|
+
return html`
|
|
59
|
+
${this.roles.length
|
|
60
|
+
? html`
|
|
61
|
+
<div>
|
|
62
|
+
${this.roleCategory ? html`<h3 subtitle>${this.roleCategory}</h3>` : nothing}
|
|
63
|
+
<input id="checkAll" type="checkbox" @change=${this.checkAll.bind(this)} />
|
|
64
|
+
<label for="checkAll">Check all</label>
|
|
65
|
+
</div>
|
|
66
|
+
|
|
67
|
+
<ul roles>
|
|
68
|
+
${this.roles.map(
|
|
69
|
+
role => html`
|
|
70
|
+
<li>
|
|
71
|
+
<input
|
|
72
|
+
id="${role.id}"
|
|
73
|
+
type="checkbox"
|
|
74
|
+
.checked=${userRoleIds.indexOf(role.id) >= 0}
|
|
75
|
+
.data-role=${role}
|
|
76
|
+
/>
|
|
77
|
+
<label for="${role.id}">${role.name}</label>
|
|
78
|
+
</li>
|
|
79
|
+
`
|
|
80
|
+
)}
|
|
81
|
+
</ul>
|
|
82
|
+
`
|
|
83
|
+
: ''}
|
|
84
|
+
`
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
checkAll(e) {
|
|
88
|
+
const checked = e.currentTarget.checked
|
|
89
|
+
Array.from(this.renderRoot.querySelectorAll('ul[roles] input[type=checkbox]')).forEach(
|
|
90
|
+
checkbox => ((checkbox as HTMLInputElement).checked = checked)
|
|
91
|
+
)
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
selectedRoles() {
|
|
95
|
+
return Array.from(this.renderRoot.querySelectorAll('ul[roles] input[type=checkbox]'))
|
|
96
|
+
.filter(input => (input as HTMLInputElement).checked)
|
|
97
|
+
.map(input => {
|
|
98
|
+
const { id, name } = input['data-role']
|
|
99
|
+
return { id, name }
|
|
100
|
+
})
|
|
101
|
+
}
|
|
102
|
+
}
|