@things-factory/menu-ui 8.0.0-beta.0 → 8.0.0-beta.2

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,216 +0,0 @@
1
- import '@material/web/icon/icon.js'
2
- import '@operato/oops'
3
-
4
- import { css, html, LitElement } from 'lit'
5
- import { customElement, property } from 'lit/decorators.js'
6
-
7
- @customElement('menu-tile-list')
8
- export default class MenuTileList extends LitElement {
9
- static styles = [
10
- css`
11
- :host {
12
- display: block;
13
- box-sizing: border-box;
14
-
15
- position: relative;
16
- }
17
-
18
- ul {
19
- display: grid;
20
- grid-template-columns: 1fr 1fr;
21
- grid-auto-rows: 110px;
22
- list-style: none;
23
- padding: 0;
24
- margin: 0;
25
- }
26
-
27
- ul > li {
28
- margin: var(--menu-tile-list-item-margin);
29
- padding: 10px;
30
-
31
- position: relative;
32
- }
33
-
34
- md-icon {
35
- cursor: pointer;
36
- position: absolute;
37
- right: 8px;
38
- top: 8px;
39
-
40
- color: var(--menu-tile-list-favorite-color);
41
- font-size: 1em;
42
- }
43
-
44
- md-icon[selected] {
45
- color: white;
46
- text-shadow: 1px 1px 1px var(--menu-tile-list-favorite-color);
47
- }
48
-
49
- li.text a {
50
- color: #fff;
51
- text-decoration: none;
52
-
53
- font-size: 1.4em;
54
- line-height: 1.3;
55
- word-wrap: break-word;
56
- word-break: keep-all;
57
-
58
- margin: 0px;
59
- display: block;
60
- width: 100%;
61
- height: 100%;
62
- }
63
-
64
- li.text:nth-child(7n + 1) {
65
- background-color: #4397de;
66
- }
67
-
68
- li.text:nth-child(7n + 2) {
69
- background-color: #33b8d0;
70
- }
71
-
72
- li.text:nth-child(7n + 3) {
73
- background-color: #4ab75f;
74
- }
75
-
76
- li.text:nth-child(7n + 4) {
77
- background-color: #93796f;
78
- }
79
-
80
- li.text:nth-child(7n + 5) {
81
- background-color: #f1ac42;
82
- }
83
-
84
- li.text:nth-child(7n + 6) {
85
- background-color: #ea6361;
86
- }
87
-
88
- li.text:nth-child(7n + 7) {
89
- background-color: #7386c3;
90
- }
91
-
92
- ox-oops-note {
93
- display: block;
94
- position: absolute;
95
- left: 50%;
96
- top: 50%;
97
- transform: translate(-50%, -50%);
98
- }
99
-
100
- ox-oops-spinner {
101
- display: none;
102
- position: absolute;
103
- left: 50%;
104
- top: 50%;
105
- transform: translate(-50%, -50%);
106
- }
107
-
108
- ox-oops-spinner[show] {
109
- display: block;
110
- }
111
-
112
- @media (min-width: 600px) {
113
- ul {
114
- grid-template-columns: 1fr 1fr 1fr;
115
- grid-auto-rows: 120px;
116
- }
117
- }
118
- @media (min-width: 1200px) {
119
- ul {
120
- grid-template-columns: 1fr 1fr 1fr 1fr;
121
- grid-auto-rows: 130px;
122
- }
123
- }
124
- @media (min-width: 1800px) {
125
- ul {
126
- grid-template-columns: 1fr 1fr 1fr 1fr 1fr;
127
- grid-auto-rows: 140px;
128
- }
129
- }
130
- @media (min-width: 2400px) {
131
- ul {
132
- grid-template-columns: 1fr 1fr 1fr 1fr 1fr 1fr;
133
- grid-auto-rows: 150px;
134
- }
135
- }
136
- `
137
- ]
138
-
139
- @property({ type: String }) menuId?: string
140
- @property({ type: Array }) menus: any[] = []
141
- @property({ type: Object }) routingTypes: any
142
- @property({ type: Array }) favorites: any[] = []
143
- @property({ type: Boolean }) showSpinner: boolean = false
144
-
145
- render() {
146
- var topmenus = this.menus || []
147
- var menuId = this.menuId
148
-
149
- if (!menuId) {
150
- /* favorite menus */
151
- var submenus = topmenus.reduce((allmenu, topmenu) => {
152
- let menus = (topmenu && topmenu.children) || []
153
- menus.forEach(menu => {
154
- if (this.favorites.includes(this._getFullRouting(menu))) {
155
- allmenu.push(menu)
156
- }
157
- })
158
- return allmenu
159
- }, [])
160
- } else {
161
- var menu = topmenus[menuId]
162
- var submenus = (menu && menu.children) || []
163
- }
164
-
165
- return html`
166
- <ul>
167
- ${submenus.map(subMenu => {
168
- const routing = this._getFullRouting(subMenu)
169
-
170
- return html`
171
- <li
172
- class="${subMenu.class} text"
173
- style="grid-row: span ${subMenu.routingType.toUpperCase() === 'STATIC' ? 1 : 2}"
174
- >
175
- <a href=${routing}>${subMenu.name}</a>
176
-
177
- <md-icon ?selected=${(this.favorites || []).includes(routing)}
178
- >${(this.favorites || ([] as any[])).includes(routing) ? 'star' : 'star_border'}</md-icon
179
- >
180
- </li>
181
- `
182
- })}
183
- </ul>
184
-
185
- ${submenus.length == 0 && !this.showSpinner
186
- ? typeof menuId == 'number'
187
- ? html`
188
- <ox-oops-note
189
- icon="apps"
190
- title="No Menu Found"
191
- description="Seems like you are not authorised to view this menu"
192
- ></ox-oops-note>
193
- `
194
- : html`
195
- <ox-oops-note
196
- icon="star_border"
197
- title="No Favourite Found"
198
- description="Click ☆ icon to add new favourite menu"
199
- ></ox-oops-note>
200
- `
201
- : html``}
202
-
203
- <ox-oops-spinner ?show=${this.showSpinner}></ox-oops-spinner>
204
- `
205
- }
206
-
207
- _getFullRouting(menu): string {
208
- var { routingType, titleField, name, resourceUrl } = menu
209
- if (routingType.toUpperCase() === 'STATIC') {
210
- return resourceUrl
211
- }
212
-
213
- var { page } = this.routingTypes[routingType]
214
- return titleField ? `${page}/${menu[titleField]}` : `${page}/${name}`
215
- }
216
- }
@@ -1,289 +0,0 @@
1
- import '@material/web/icon/icon.js'
2
-
3
- import gql from 'graphql-tag'
4
- import { css, html, LitElement } from 'lit'
5
- import { customElement, property } from 'lit/decorators.js'
6
- import { connect } from 'pwa-helpers/connect-mixin.js'
7
-
8
- import { client, store } from '@things-factory/shell/client'
9
- import { ScrollbarStyles } from '@operato/styles'
10
-
11
- @customElement('menu-tree-bar')
12
- export default class MenuTreeBar extends connect(store)(LitElement) {
13
- static styles = [
14
- ScrollbarStyles,
15
- css`
16
- :host {
17
- display: flex;
18
- flex-direction: column;
19
- min-width: 200px;
20
- }
21
- [domain] {
22
- background: var(--menu-domain-background-color);
23
- background: linear-gradient(180deg, var(--md-sys-color-secondary) 0%, var(--md-sys-color-primary) 120%);
24
- padding: var(--menu-domain-padding);
25
- border-bottom: 1px solid var(--md-sys-color-primary);
26
- }
27
- [domain] md-icon {
28
- margin-right: -8px;
29
- font-size: 12px;
30
- color: var(--menu-domain-icon-color);
31
- }
32
- [domain] * {
33
- vertical-align: middle;
34
- }
35
- [domain] span {
36
- padding-left: 7px;
37
- font: var(--menu-domain-font);
38
- color: var(--menu-domain-color);
39
- }
40
- [domain] select {
41
- background-color: transparent;
42
- width: -webkit-fill-available;
43
- max-width: 175px;
44
- border: none;
45
-
46
- font: var(--menu-domain-font);
47
- color: var(--menu-domain-color);
48
- }
49
- select:focus {
50
- outline: 0;
51
- }
52
-
53
- ul {
54
- list-style: none;
55
- margin: 0;
56
- padding: 0;
57
- }
58
-
59
- ul[toplevel] {
60
- overflow: auto;
61
- }
62
-
63
- li {
64
- border-bottom: var(--menu-tree-toplevel-border-bottom);
65
- }
66
-
67
- [grouplevel] li {
68
- border-bottom: var(--menu-tree-grouplevel-border-bottom);
69
- }
70
-
71
- li span,
72
- li a {
73
- display: block;
74
- text-decoration: none;
75
- position: relative;
76
- }
77
-
78
- [menutype] {
79
- position: absolute;
80
- font-size: 1.2em;
81
- right: 0;
82
- bottom: 50%;
83
- transform: translate(-5px, 50%);
84
- }
85
-
86
- [favorite] {
87
- color: var(--menu-tree-favorite-color, tomato);
88
- }
89
-
90
- [groupmenu] > span {
91
- padding: 9px 9px 7px 10px;
92
- font: var(--menu-tree-toplevel-font);
93
- color: var(--menu-tree-toplevel-color);
94
- }
95
-
96
- a {
97
- background-color: rgba(0, 0, 0, 0.4);
98
- padding: 7px 7px 6px 15px;
99
- font: var(--menu-tree-grouplevel-font);
100
- color: var(--menu-tree-grouplevel-color);
101
- }
102
-
103
- [groupmenu] > span::before {
104
- content: '';
105
- display: inline-block;
106
- width: var(--menu-tree-toplevel-icon-size);
107
- height: var(--menu-tree-toplevel-icon-size);
108
- border: var(--menu-tree-toplevel-icon-border);
109
- border-radius: 50%;
110
- margin-right: 5px;
111
- }
112
-
113
- a span::before {
114
- content: '-';
115
- margin-right: 4px;
116
- }
117
-
118
- [expanded] > span {
119
- font-weight: bold;
120
- color: var(--menu-tree-focus-color);
121
- }
122
-
123
- [grouplevel] {
124
- overflow-y: hidden;
125
- max-height: 0;
126
-
127
- transition-property: all;
128
- transition-duration: 0.7s;
129
- }
130
-
131
- [expanded] > [grouplevel] {
132
- overflow-y: auto;
133
- max-height: 500px;
134
- }
135
-
136
- li[active] a {
137
- color: var(--menu-tree-focus-color);
138
- font-weight: bold;
139
- border-left: var(--menu-tree-grouplevel-active-border-left);
140
- background-color: rgba(0, 0, 0, 0.6);
141
- padding-left: 12px;
142
- }
143
- `
144
- ]
145
-
146
- @property({ type: String }) menuId?: string
147
- @property({ type: Array }) menus: any[] = []
148
- @property({ type: Array }) favorites: string[] = []
149
- @property({ type: Array }) routingTypes: string[] = []
150
- @property({ type: String }) page?: string
151
- @property({ type: Object }) user?: any
152
- @property({ type: String }) contextPath?: string
153
- @property({ type: Array }) domains: any[] = []
154
- @property({ type: Object }) domain?: any
155
-
156
- render() {
157
- var domains = this.domains || []
158
- var domain = this.domain || {}
159
- const currentRouting = decodeURIComponent(
160
- location.pathname.substr(this.contextPath ? this.contextPath.length + 1 : 1)
161
- )
162
-
163
- return html`
164
- <div domain>
165
- <md-icon>beenhere</md-icon>
166
- ${domains.length <= 1
167
- ? html` <span>${domain.name}</span> `
168
- : html`
169
- <select
170
- .value=${domain.subdomain}
171
- @change=${e => (window.location.pathname = `/auth/checkin/${e.target.value}`)}
172
- >
173
- ${domains.map(
174
- d => html`
175
- <option .value=${d.subdomain} ?selected=${d.subdomain == domain.subdomain}>${d.name}</option>
176
- `
177
- )}
178
- </select>
179
- `}
180
- </div>
181
-
182
- <ul toplevel>
183
- ${(this.menus || []).map(
184
- menu => html`
185
- <li groupmenu>
186
- <span
187
- @click=${e => {
188
- e.target.parentElement.toggleAttribute('expanded')
189
- this.renderRoot
190
- .querySelectorAll('[expanded]')
191
- .forEach(element => element !== e.target.parentElement && element.removeAttribute('expanded'))
192
- }}
193
- >${menu.name}</span
194
- >
195
-
196
- <ul grouplevel>
197
- ${menu.children.map(subMenu => {
198
- const routing = this._getFullRouting(subMenu)
199
- const favorite = this.favorites.includes(routing)
200
- const { icon } = this.routingTypes[subMenu.routingType] || ({} as any)
201
- const typeIcon = icon ? icon : favorite ? 'star' : null
202
-
203
- return html`
204
- <li ?active=${routing === currentRouting}>
205
- <a href=${routing}>
206
- <span>${subMenu.name}</span>
207
- ${typeIcon ? html` <md-icon menutype ?favorite=${favorite}>${typeIcon}</md-icon> ` : html``}</a
208
- >
209
- </li>
210
- `
211
- })}
212
- </ul>
213
- </li>
214
- `
215
- )}
216
- </ul>
217
- `
218
- }
219
-
220
- async updated(changes) {
221
- if (changes.has('user')) {
222
- this.menus = await this.getMenus()
223
- }
224
-
225
- await this.updateComplete
226
-
227
- var active = this.renderRoot.querySelector('[active]')
228
- if (active) {
229
- active.parentElement?.parentElement?.setAttribute('expanded', '')
230
- }
231
- }
232
-
233
- stateChanged(state) {
234
- this.contextPath = state.app.contextPath
235
- this.routingTypes = state.menu.routingTypes
236
- this.menuId = state.route.resourceId
237
- this.page = state.route.page
238
- this.user = state.auth.user
239
- this.domains = state.app.domains
240
- this.domain = state.app.domain
241
- this.getMenus =
242
- state.menu.provider && typeof state.menu.provider === 'function' ? state.menu.provider : this.getMenus
243
- this.favorites = state.favorite.favorites
244
- }
245
-
246
- _getFullRouting(menu) {
247
- var { routingType, resourceUrl, titleField, name, resourceType, resourceId } = menu
248
- if (routingType.toUpperCase() === 'STATIC') {
249
- if (resourceType?.toUpperCase() === 'BOARD') {
250
- return `${resourceUrl || 'board-viewer'}/${resourceId}?title=${name}`
251
- }
252
- return resourceUrl
253
- }
254
-
255
- var { page } = this.routingTypes[routingType] as any
256
- return titleField ? `${page}/${menu[titleField]}` : `${page}/${name}`
257
- }
258
-
259
- _onClickRefresh(e) {
260
- this.dispatchEvent(new CustomEvent('refresh'))
261
- }
262
-
263
- async getMenus() {
264
- const response = await client.query({
265
- query: gql`
266
- query {
267
- userMenus {
268
- id
269
- name
270
- children {
271
- id
272
- name
273
- routingType
274
- idField
275
- titleField
276
- resourceType
277
- resourceId
278
- resourceName
279
- resourceUrl
280
- template
281
- }
282
- }
283
- }
284
- `
285
- })
286
-
287
- return response.data.userMenus
288
- }
289
- }
package/server/index.ts DELETED
File without changes