@things-factory/board-ui 4.3.111 → 4.3.114

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/index.js CHANGED
@@ -5,3 +5,5 @@ export * from './viewparts/board-creation-card'
5
5
  export * from './pages/board-viewer-page'
6
6
  export * from './pages/board-player-page'
7
7
  export * from './pages/board-modeller-page'
8
+
9
+ export * from './setting-let/board-view-setting-let'
@@ -5,7 +5,7 @@ import gql from 'graphql-tag'
5
5
  import { css, html } from 'lit'
6
6
  import { connect } from 'pwa-helpers/connect-mixin.js'
7
7
 
8
- import { client, PageView, store } from '@things-factory/shell'
8
+ import { client, clientSettingStore, PageView, store } from '@things-factory/shell'
9
9
 
10
10
  import { createBoardProvider } from '../board-provider'
11
11
 
@@ -77,6 +77,7 @@ export class BoardPlayerPage extends connect(store)(PageView) {
77
77
 
78
78
  async refresh() {
79
79
  if (!this._playGroupId) {
80
+ this.stopCheckingForAutoRefresh()
80
81
  return
81
82
  }
82
83
 
@@ -84,6 +85,9 @@ export class BoardPlayerPage extends connect(store)(PageView) {
84
85
  this._showSpinner = true
85
86
  this.updateContext()
86
87
 
88
+ const { autoRefresh, interval } = (await clientSettingStore.get('board-view'))?.value
89
+ autoRefresh && this.startCheckingForAutoRefresh(interval)
90
+
87
91
  this._playGroup = (
88
92
  await client.query({
89
93
  query: gql`
@@ -109,6 +113,7 @@ export class BoardPlayerPage extends connect(store)(PageView) {
109
113
  name
110
114
  }
111
115
  }
116
+ updatedAt
112
117
  }
113
118
  }
114
119
  `,
@@ -192,10 +197,65 @@ export class BoardPlayerPage extends connect(store)(PageView) {
192
197
 
193
198
  this.refresh()
194
199
  } else {
200
+ this.stopCheckingForAutoRefresh()
201
+
195
202
  this._playGroupId = null
196
203
  this.shadowRoot.querySelector('ox-board-player').stop()
197
204
  }
198
205
  }
206
+
207
+ async startCheckingForAutoRefresh(interval) {
208
+ await this.stopCheckingForAutoRefresh()
209
+
210
+ if (!this._playGroupId) {
211
+ return
212
+ }
213
+
214
+ this._interval = setInterval(async () => {
215
+ const response = await client.query({
216
+ query: gql`
217
+ query FetchPlayGroup($id: String!) {
218
+ playGroup(id: $id) {
219
+ id
220
+ boards {
221
+ id
222
+ updatedAt
223
+ }
224
+ updatedAt
225
+ }
226
+ }
227
+ `,
228
+ variables: {
229
+ id: this._playGroupId
230
+ }
231
+ })
232
+
233
+ const playGroup = response.data.playGroup
234
+
235
+ if (playGroup)
236
+ if (this._playGroup.updatedAt !== playGroup.updatedAt) {
237
+ console.log('== playgroup changed (refreshed automatically) ==')
238
+ this.refresh()
239
+ } else {
240
+ const boards = playGroup.boards || []
241
+ const currentBoards = this._playGroup.boards
242
+
243
+ if (
244
+ boards.find(({ id, updatedAt }) => {
245
+ const currentBoard = currentBoards.find(b => b.id === id)
246
+ return !currentBoard || currentBoard.updatedAt !== updatedAt
247
+ })
248
+ ) {
249
+ console.log('== some board in playgroup changed (refreshed automatically) ==')
250
+ this.refresh()
251
+ }
252
+ }
253
+ }, (interval || 60) * 60 * 1000)
254
+ }
255
+
256
+ async stopCheckingForAutoRefresh() {
257
+ clearInterval(this._interval)
258
+ }
199
259
  }
200
260
 
201
261
  customElements.define('board-player-page', BoardPlayerPage)
@@ -6,7 +6,7 @@ import { css, html } from 'lit'
6
6
  import { connect } from 'pwa-helpers/connect-mixin.js'
7
7
 
8
8
  import { buildLabelPrintCommand } from '@things-factory/barcode-base'
9
- import { client, gqlContext, PageView, store } from '@things-factory/shell'
9
+ import { client, clientSettingStore, gqlContext, PageView, store } from '@things-factory/shell'
10
10
 
11
11
  import { provider } from '../board-provider'
12
12
 
@@ -120,6 +120,8 @@ export class BoardViewerPage extends connect(store)(PageView) {
120
120
  * 화면이 inactive 될 때, 굳이 scene을 close하는 이유는,
121
121
  * 새로운 board가 선택되어 뷰어가 열릴 때, 기존 보드 잔상이 보이지 않도록 하기위해서이다.
122
122
  */
123
+ this.stopCheckingForAutoRefresh()
124
+
123
125
  if (this._boardId) {
124
126
  let boardViewer = this.shadowRoot.querySelector('ox-board-viewer')
125
127
  boardViewer && boardViewer.closeScene()
@@ -135,6 +137,7 @@ export class BoardViewerPage extends connect(store)(PageView) {
135
137
 
136
138
  async refresh() {
137
139
  if (!this._boardId) {
140
+ this.stopCheckingForAutoRefresh()
138
141
  this._board = null
139
142
  return
140
143
  }
@@ -150,6 +153,7 @@ export class BoardViewerPage extends connect(store)(PageView) {
150
153
  id
151
154
  name
152
155
  model
156
+ updatedAt
153
157
  }
154
158
  }
155
159
  `,
@@ -181,6 +185,9 @@ export class BoardViewerPage extends connect(store)(PageView) {
181
185
  } finally {
182
186
  this._showSpinner = false
183
187
  this.updateContext()
188
+
189
+ const { autoRefresh, interval } = (await clientSettingStore.get('board-view'))?.value
190
+ autoRefresh && this.startCheckingForAutoRefresh(interval)
184
191
  }
185
192
  }
186
193
 
@@ -198,6 +205,40 @@ export class BoardViewerPage extends connect(store)(PageView) {
198
205
  async printTrick(image) {
199
206
  await this.renderRoot.querySelector('ox-board-viewer').printTrick(image)
200
207
  }
208
+
209
+ async startCheckingForAutoRefresh(interval) {
210
+ await this.stopCheckingForAutoRefresh()
211
+
212
+ if (!this._boardId) {
213
+ return
214
+ }
215
+
216
+ this._interval = setInterval(async () => {
217
+ const response = await client.query({
218
+ query: gql`
219
+ query FetchBoardById($id: String!) {
220
+ board(id: $id) {
221
+ id
222
+ updatedAt
223
+ }
224
+ }
225
+ `,
226
+ variables: { id: this._boardId },
227
+ context: gqlContext()
228
+ })
229
+
230
+ const board = response.data.board
231
+
232
+ if (board && this._board.updatedAt !== board.updatedAt) {
233
+ console.log('== board changed (refreshed automatically) ==')
234
+ this.refresh()
235
+ }
236
+ }, (interval || 60) * 60 * 1000)
237
+ }
238
+
239
+ async stopCheckingForAutoRefresh() {
240
+ clearInterval(this._interval)
241
+ }
201
242
  }
202
243
 
203
244
  customElements.define('board-viewer-page', BoardViewerPage)
@@ -0,0 +1,114 @@
1
+ import '@things-factory/setting-base'
2
+ import '@material/mwc-formfield'
3
+ import '@material/mwc-checkbox'
4
+
5
+ import { css, html, LitElement } from 'lit'
6
+
7
+ import { i18next, localize } from '@operato/i18n'
8
+ import { clientSettingStore } from '@things-factory/shell'
9
+
10
+ export class BoardViewSettingLet extends localize(i18next)(LitElement) {
11
+ static get styles() {
12
+ return [
13
+ css`
14
+ label {
15
+ font: var(--label-font);
16
+ color: var(--label-color);
17
+ text-transform: var(--label-text-transform);
18
+ }
19
+
20
+ mwc-formfield {
21
+ display: block;
22
+ }
23
+ `
24
+ ]
25
+ }
26
+
27
+ static get properties() {
28
+ return {
29
+ autoRefresh: Boolean,
30
+ interval: Number
31
+ }
32
+ }
33
+
34
+ render() {
35
+ return html`
36
+ <setting-let>
37
+ <i18n-msg slot="title" msgid="title.board view setting"></i18n-msg>
38
+
39
+ <div slot="content">
40
+ <mwc-formfield label=${i18next.t('label.auto refresh board view')}>
41
+ <mwc-checkbox
42
+ id="auto-refresh"
43
+ @change=${e => this.onchangeAutoRefresh(e)}
44
+ ?checked=${this.autoRefresh}
45
+ ></mwc-checkbox>
46
+ </mwc-formfield>
47
+
48
+ ${this.autoRefresh
49
+ ? html`
50
+ <mwc-textfield
51
+ name="interval"
52
+ type="number"
53
+ helper=${i18next.t('label.auto refresh checking interval (minutes)')}
54
+ @change=${e => this.onchangeInterval(e)}
55
+ helperpersistent
56
+ .value=${this.interval || 60}
57
+ ></mwc-textfield>
58
+ `
59
+ : html``}
60
+ </div>
61
+ </setting-let>
62
+ `
63
+ }
64
+
65
+ async firstUpdated() {
66
+ const { autoRefresh = false, interval = 60 } = (await clientSettingStore.get('board-view'))?.value || {}
67
+ this.autoRefresh = autoRefresh
68
+ this.interval = interval
69
+ }
70
+
71
+ async onchangeAutoRefresh(e) {
72
+ this.autoRefresh = e.target.checked
73
+
74
+ const { autoRefresh: valueFromStore } = (await clientSettingStore.get('board-view'))?.value || {}
75
+ if (this.autoRefresh === valueFromStore) {
76
+ return
77
+ }
78
+
79
+ try {
80
+ await clientSettingStore.put({
81
+ key: 'board-view',
82
+ value: {
83
+ autoRefresh: this.autoRefresh,
84
+ interval: this.interval || 60
85
+ }
86
+ })
87
+ } catch (e) {
88
+ console.error(e)
89
+ }
90
+ }
91
+
92
+ async onchangeInterval(e) {
93
+ this.interval = e.target.value
94
+
95
+ const { interval: valueFromStore } = (await clientSettingStore.get('board-view'))?.value || {}
96
+ if (this.interval === valueFromStore) {
97
+ return
98
+ }
99
+
100
+ try {
101
+ await clientSettingStore.put({
102
+ key: 'board-view',
103
+ value: {
104
+ autoRefresh: this.autoRefresh,
105
+ interval: this.interval
106
+ }
107
+ })
108
+ } catch (e) {
109
+ console.error(e)
110
+ }
111
+ }
112
+ }
113
+
114
+ customElements.define('board-view-setting-let', BoardViewSettingLet)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@things-factory/board-ui",
3
- "version": "4.3.111",
3
+ "version": "4.3.114",
4
4
  "main": "dist-server/index.js",
5
5
  "browser": "client/index.js",
6
6
  "things-factory": true,
@@ -40,11 +40,11 @@
40
40
  "@polymer/paper-listbox": "^3.0.1",
41
41
  "@polymer/paper-menu-button": "^3.0.1",
42
42
  "@polymer/paper-slider": "^3.0.1",
43
- "@things-factory/barcode-base": "^4.3.111",
44
- "@things-factory/grist-ui": "^4.3.111",
45
- "@things-factory/modeller-ui": "^4.3.111",
43
+ "@things-factory/barcode-base": "^4.3.114",
44
+ "@things-factory/grist-ui": "^4.3.114",
45
+ "@things-factory/modeller-ui": "^4.3.114",
46
46
  "file-saver": "^2.0.2",
47
47
  "sortablejs": "^1.10.2"
48
48
  },
49
- "gitHead": "71a701731b643b32dd78334647dbcc287519aa1d"
49
+ "gitHead": "6f16bd9dfb3210e848e5118d894424972ed83773"
50
50
  }
@@ -113,6 +113,8 @@
113
113
  "label.auth": "authority",
114
114
  "label.authorization": "authorization",
115
115
  "label.auto-rotate": "auto rotate",
116
+ "label.auto refresh board view": "auto refresh board view",
117
+ "label.auto refresh checking interval (minutes)": "label.auto refresh checking interval (minutes)",
116
118
  "label.axes": "axes",
117
119
  "label.axis-max-auto": "Max Auto",
118
120
  "label.axis-max": "Max",
@@ -610,6 +612,7 @@
610
612
  "text.want-to-confirm": "Do you want to release this version?",
611
613
  "text.want-to-request-confirm": "Do you want to change this to finished version?",
612
614
  "text.want-to-version-up": "Do you want to version up?",
615
+ "title.board view setting": "Board UI setting",
613
616
  "title.copy": "Copy",
614
617
  "title.create-board": "create board",
615
618
  "title.create-group": "create group",
@@ -627,4 +630,4 @@
627
630
  "title.update-user": "Update User",
628
631
  "title.update-variable": "Update Variable",
629
632
  "title.warn": "Warning"
630
- }
633
+ }
@@ -112,6 +112,8 @@
112
112
  "label.auth-domain": "auth domain",
113
113
  "label.auth": "권한",
114
114
  "label.authorization": "authorization",
115
+ "label.auto refresh board view": "보드 뷰 자동 리프레시",
116
+ "label.auto refresh checking interval (minutes)": "보드 뷰 자동 리프레시 체크 주기 (분)",
115
117
  "label.auto-rotate": "자동 회전",
116
118
  "label.axes": "축",
117
119
  "label.axis-max-auto": "최대값 자동",
@@ -611,6 +613,7 @@
611
613
  "text.want-to-confirm": "Board를 배포 하시겠습니까?",
612
614
  "text.want-to-request-confirm": "Board를 작업 완료 상태로 바꾸시겠습니까?",
613
615
  "text.want-to-version-up": "새 버전을 생성하시겠습니까?",
616
+ "title.board view setting": "보드 뷰 설정",
614
617
  "title.copy": "복사",
615
618
  "title.create-board": "보드 생성",
616
619
  "title.create-group": "그룹 생성",
@@ -628,4 +631,4 @@
628
631
  "title.update-user": "사용자 수정",
629
632
  "title.update-variable": "변수 수정",
630
633
  "title.warn": "경고"
631
- }
634
+ }
@@ -111,6 +111,8 @@
111
111
  "label.auth-domain": "auth domain",
112
112
  "label.auth": "kuasa",
113
113
  "label.authorization": "kebenaran",
114
+ "label.auto refresh board view": "auto refresh board view",
115
+ "label.auto refresh checking interval (minutes)": "label.auto refresh checking interval (minutes)",
114
116
  "label.auto-rotate": "auto putar",
115
117
  "label.axes": "paksi",
116
118
  "label.axis-max-auto": "max auto",
@@ -610,6 +612,7 @@
610
612
  "text.want-to-confirm": "adakah anda mahu keluarkan versi ini?",
611
613
  "text.want-to-request-confirm": "adakah anda mahu ubah ini ke versi yang telah siap?",
612
614
  "text.want-to-version-up": "adakah anda mahu tambah versi?",
615
+ "title.board view setting": "Board UI setting",
613
616
  "title.copy": "salin",
614
617
  "title.create-board": "cipta peristiwa",
615
618
  "title.create-group": "cipta kumpulan",
@@ -627,4 +630,4 @@
627
630
  "title.update-user": "kemaskini pengguna",
628
631
  "title.update-variable": "kemaskini pemboleh ubah",
629
632
  "title.warn": "amaran"
630
- }
633
+ }
@@ -111,6 +111,8 @@
111
111
  "label.auth-domain": "验证域",
112
112
  "label.auth": "权限",
113
113
  "label.authorization": "授权",
114
+ "label.auto refresh board view": "auto refresh board view",
115
+ "label.auto refresh checking interval (minutes)": "label.auto refresh checking interval (minutes)",
114
116
  "label.auto-rotate": "自动旋转",
115
117
  "label.axes": "轴",
116
118
  "label.axis-max-auto": "自动计算最大值",
@@ -612,6 +614,7 @@
612
614
  "text.want-to-request-confirm": "是否执行审批申请?",
613
615
  "text.want-to-self-confirm": "是否希望自我审批?",
614
616
  "text.want-to-version-up": "是否希望升级创建新版本?",
617
+ "title.board view setting": "Board UI setting",
615
618
  "title.copy": "复制",
616
619
  "title.create-board": "创建标签",
617
620
  "title.create-group": "创建组",
@@ -629,4 +632,4 @@
629
632
  "title.update-user": "更新用户",
630
633
  "title.update-variable": "更新变量",
631
634
  "title.warn": "警告"
632
- }
635
+ }