@things-factory/auth-ui 7.1.33 → 7.1.42

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,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'
@@ -23,13 +23,26 @@ class RolePrivilegeEditor extends localize(i18next)(LitElement) {
23
23
  div {
24
24
  margin: var(--spacing-medium);
25
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
+
26
38
  ul {
27
39
  flex: 1;
28
40
  background-color: var(--md-sys-color-surface-variant);
29
41
  overflow: auto;
30
42
  display: grid;
31
43
  grid-template-columns: 1fr 1fr;
32
- margin: 0;
44
+ margin-block-start: 0;
45
+ margin-block-end: 0;
33
46
  padding: var(--spacing-medium);
34
47
  list-style: none;
35
48
  border: 1px dashed rgba(0, 0, 0, 0.1);
@@ -70,14 +83,23 @@ class RolePrivilegeEditor extends localize(i18next)(LitElement) {
70
83
 
71
84
  @property({ type: Object }) role: any
72
85
  @property({ type: Array }) allPrivileges: any[] = []
73
- @property({ type: Array }) privileges: any[] = []
74
86
  @property({ type: Object }) updateRoleObj: any
75
87
 
88
+ @state() privileges: { id: string; description: string }[] = []
89
+ @state() users: { /* id: string; username: string; */ name: string; email: string }[] = []
90
+
76
91
  render() {
77
92
  const allPrivileges = this.allPrivileges || []
78
93
  const privileges = this.privileges || []
94
+ const users = this.users || []
79
95
 
80
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
+
81
103
  <div>
82
104
  <input id="checkAll" type="checkbox" @change=${e => this.oncheckAll(e)} />
83
105
  <label for="checkAll">Check all</label>
@@ -114,7 +136,7 @@ class RolePrivilegeEditor extends localize(i18next)(LitElement) {
114
136
 
115
137
  async updated(changes) {
116
138
  if (changes.has('role')) {
117
- this.privileges = await this.fetchPrivilegesOnRole(this.role.name)
139
+ await this.fetchPrivilegesOnRole(this.role.name)
118
140
  }
119
141
  }
120
142
 
@@ -224,6 +246,10 @@ class RolePrivilegeEditor extends localize(i18next)(LitElement) {
224
246
  id
225
247
  description
226
248
  }
249
+ users {
250
+ name
251
+ email
252
+ }
227
253
  }
228
254
  }
229
255
  `,
@@ -231,7 +257,8 @@ class RolePrivilegeEditor extends localize(i18next)(LitElement) {
231
257
  context: gqlContext()
232
258
  })
233
259
 
234
- return response.data.role?.privileges
260
+ this.privileges = response.data.role?.privileges
261
+ this.users = response.data.role?.users
235
262
  }
236
263
 
237
264
  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
- this.privileges = await this.fetchPrivilegesOnRole(this.role.name);
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
- return (_a = response.data.role) === null || _a === void 0 ? void 0 : _a.privileges;
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 } } }));
@@ -167,13 +180,26 @@ RolePrivilegeEditor.styles = [
167
180
  div {
168
181
  margin: var(--spacing-medium);
169
182
  }
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
+
170
195
  ul {
171
196
  flex: 1;
172
197
  background-color: var(--md-sys-color-surface-variant);
173
198
  overflow: auto;
174
199
  display: grid;
175
200
  grid-template-columns: 1fr 1fr;
176
- margin: 0;
201
+ margin-block-start: 0;
202
+ margin-block-end: 0;
177
203
  padding: var(--spacing-medium);
178
204
  list-style: none;
179
205
  border: 1px dashed rgba(0, 0, 0, 0.1);
@@ -219,14 +245,18 @@ __decorate([
219
245
  property({ type: Array }),
220
246
  __metadata("design:type", Array)
221
247
  ], RolePrivilegeEditor.prototype, "allPrivileges", void 0);
222
- __decorate([
223
- property({ type: Array }),
224
- __metadata("design:type", Array)
225
- ], RolePrivilegeEditor.prototype, "privileges", void 0);
226
248
  __decorate([
227
249
  property({ type: Object }),
228
250
  __metadata("design:type", Object)
229
251
  ], RolePrivilegeEditor.prototype, "updateRoleObj", void 0);
252
+ __decorate([
253
+ state(),
254
+ __metadata("design:type", Array)
255
+ ], RolePrivilegeEditor.prototype, "privileges", void 0);
256
+ __decorate([
257
+ state(),
258
+ __metadata("design:type", Array)
259
+ ], RolePrivilegeEditor.prototype, "users", void 0);
230
260
  RolePrivilegeEditor = __decorate([
231
261
  customElement('role-privilege-editor')
232
262
  ], 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,KAAK,CAAA;AAC3C,OAAO,EAAE,aAAa,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAA;AAE3D,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,CAAA;AACtD,OAAO,EAAE,qBAAqB,EAAE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'\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 color: var(--md-sys-color-secondary);\n }\n div {\n margin: var(--spacing-medium);\n }\n ul {\n flex: 1;\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,CAAA;AACtD,OAAO,EAAE,qBAAqB,EAAE,MAAM,iBAAiB,CAAA;AAGvD,IAAM,mBAAmB,GAAzB,MAAM,mBAAoB,SAAQ,QAAQ,CAAC,OAAO,CAAC,CAAC,UAAU,CAAC;IAA/D;;QA0E6B,kBAAa,GAAU,EAAE,CAAA;QAG3C,eAAU,GAA0C,EAAE,CAAA;QACtD,UAAK,GAA0E,EAAE,CAAA;IAkL5F,CAAC;IAhLC,MAAM;QACJ,MAA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MAAM,EAAE,CAAC;;0DAAmB;AAErC;IAAR,KAAK,EAAE;;uDAAuD;AACtD;IAAR,KAAK,EAAE;;kDAAkF;AA9EtF,mBAAmB;IADxB,aAAa,CAAC,uBAAuB,CAAC;GACjC,mBAAmB,CAgQxB","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 color: var(--md-sys-color-secondary);\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 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"]}