@things-factory/dataset 8.0.0-beta.9 → 8.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (147) hide show
  1. package/client/activities/activity-data-collect-edit.ts +105 -0
  2. package/client/activities/activity-data-collect-view.ts +91 -0
  3. package/client/activities/activity-data-review-edit.ts +133 -0
  4. package/client/activities/activity-data-review-view.ts +145 -0
  5. package/client/activities/activity-ooc-resolve-edit.ts +195 -0
  6. package/client/activities/activity-ooc-resolve-view.ts +143 -0
  7. package/client/activities/activity-ooc-review-edit.ts +173 -0
  8. package/client/activities/activity-ooc-review-view.ts +129 -0
  9. package/client/bootstrap.ts +35 -0
  10. package/client/components/data-entry-form.ts +109 -0
  11. package/client/index.ts +1 -0
  12. package/client/pages/data-archive/data-archive-list-page.ts +277 -0
  13. package/client/pages/data-archive/data-archive-request-popup.ts +177 -0
  14. package/client/pages/data-entry/data-entry-list-page.ts +464 -0
  15. package/client/pages/data-key-set/data-key-item-list.ts +183 -0
  16. package/client/pages/data-key-set/data-key-set-importer.ts +89 -0
  17. package/client/pages/data-key-set/data-key-set-list-page.ts +413 -0
  18. package/client/pages/data-ooc/data-ooc-list-page.ts +549 -0
  19. package/client/pages/data-ooc/data-ooc-page.ts +164 -0
  20. package/client/pages/data-ooc/data-ooc-view.ts +236 -0
  21. package/client/pages/data-ooc/data-oocs-page.ts +200 -0
  22. package/client/pages/data-report/data-report-embed-page.ts +108 -0
  23. package/client/pages/data-report/data-report-list-page.ts +454 -0
  24. package/client/pages/data-report/data-report-samples-page.ts +174 -0
  25. package/client/pages/data-report/jasper-report-oocs-page.ts +110 -0
  26. package/client/pages/data-report/jasper-report-samples-crosstab-page.ts +110 -0
  27. package/client/pages/data-report/jasper-report-samples-page.ts +110 -0
  28. package/client/pages/data-sample/data-sample-list-page.ts +442 -0
  29. package/client/pages/data-sample/data-sample-page.ts +55 -0
  30. package/client/pages/data-sample/data-sample-search-page.ts +424 -0
  31. package/client/pages/data-sample/data-sample-view.ts +292 -0
  32. package/client/pages/data-sample/data-samples-page.ts +249 -0
  33. package/client/pages/data-sensor/data-sensor-list-page.ts +456 -0
  34. package/client/pages/data-set/data-item-list.ts +304 -0
  35. package/client/pages/data-set/data-set-importer.ts +89 -0
  36. package/client/pages/data-set/data-set-list-page.ts +1078 -0
  37. package/client/pages/data-summary/data-summary-list-page.ts +363 -0
  38. package/client/pages/data-summary/data-summary-period-page.ts +439 -0
  39. package/client/pages/data-summary/data-summary-search-page.ts +426 -0
  40. package/client/pages/data-summary/data-summary-view.ts +133 -0
  41. package/client/route.ts +91 -0
  42. package/client/tsconfig.json +13 -0
  43. package/dist-client/activities/activity-data-review-edit.d.ts +1 -5
  44. package/dist-client/activities/activity-data-review-edit.js +5 -143
  45. package/dist-client/activities/activity-data-review-edit.js.map +1 -1
  46. package/dist-client/pages/data-entry/data-entry-list-page.js +2 -2
  47. package/dist-client/pages/data-entry/data-entry-list-page.js.map +1 -1
  48. package/dist-client/tsconfig.tsbuildinfo +1 -1
  49. package/dist-server/activities/activity-data-review.js +5 -18
  50. package/dist-server/activities/activity-data-review.js.map +1 -1
  51. package/dist-server/activities/activity-ooc-review.js +52 -13
  52. package/dist-server/activities/activity-ooc-review.js.map +1 -1
  53. package/dist-server/controllers/create-data-sample.js +94 -4
  54. package/dist-server/controllers/create-data-sample.js.map +1 -1
  55. package/dist-server/controllers/index.d.ts +0 -3
  56. package/dist-server/controllers/index.js +0 -3
  57. package/dist-server/controllers/index.js.map +1 -1
  58. package/dist-server/service/data-sample/data-sample-query.d.ts +1 -1
  59. package/dist-server/service/data-sample/data-sample-query.js +3 -3
  60. package/dist-server/service/data-sample/data-sample-query.js.map +1 -1
  61. package/dist-server/service/index.d.ts +1 -1
  62. package/dist-server/tsconfig.tsbuildinfo +1 -1
  63. package/package.json +26 -26
  64. package/server/activities/activity-data-collect.ts +100 -0
  65. package/server/activities/activity-data-review.ts +82 -0
  66. package/server/activities/activity-ooc-resolve.ts +123 -0
  67. package/server/activities/activity-ooc-review.ts +144 -0
  68. package/server/activities/index.ts +11 -0
  69. package/server/controllers/create-data-sample.ts +426 -0
  70. package/server/controllers/data-use-case.ts +98 -0
  71. package/server/controllers/finalize-data-collection.ts +388 -0
  72. package/server/controllers/index.ts +3 -0
  73. package/server/controllers/issue-data-collection-task.ts +70 -0
  74. package/server/controllers/jasper-report.ts +186 -0
  75. package/server/controllers/query-data-summary-by-period.ts +178 -0
  76. package/server/controllers/shiny-report.ts +54 -0
  77. package/server/engine/index.ts +1 -0
  78. package/server/engine/task/create-data-sample.ts +100 -0
  79. package/server/engine/task/index.ts +2 -0
  80. package/server/engine/task/issue-collect-data.ts +45 -0
  81. package/server/index.ts +8 -0
  82. package/server/routes.ts +188 -0
  83. package/server/service/data-archive/data-archive-mutation.ts +273 -0
  84. package/server/service/data-archive/data-archive-query.ts +58 -0
  85. package/server/service/data-archive/data-archive-type.ts +48 -0
  86. package/server/service/data-archive/data-archive.ts +69 -0
  87. package/server/service/data-archive/index.ts +6 -0
  88. package/server/service/data-key-set/data-key-item-type.ts +31 -0
  89. package/server/service/data-key-set/data-key-set-mutation.ts +201 -0
  90. package/server/service/data-key-set/data-key-set-query.ts +68 -0
  91. package/server/service/data-key-set/data-key-set-type.ts +70 -0
  92. package/server/service/data-key-set/data-key-set.ts +86 -0
  93. package/server/service/data-key-set/index.ts +6 -0
  94. package/server/service/data-ooc/data-ooc-mutation.ts +154 -0
  95. package/server/service/data-ooc/data-ooc-query.ts +106 -0
  96. package/server/service/data-ooc/data-ooc-subscription.ts +48 -0
  97. package/server/service/data-ooc/data-ooc-type.ts +71 -0
  98. package/server/service/data-ooc/data-ooc.ts +259 -0
  99. package/server/service/data-ooc/index.ts +7 -0
  100. package/server/service/data-sample/data-sample-mutation.ts +18 -0
  101. package/server/service/data-sample/data-sample-query.ts +215 -0
  102. package/server/service/data-sample/data-sample-type.ts +47 -0
  103. package/server/service/data-sample/data-sample.ts +193 -0
  104. package/server/service/data-sample/index.ts +6 -0
  105. package/server/service/data-sensor/data-sensor-mutation.ts +116 -0
  106. package/server/service/data-sensor/data-sensor-query.ts +76 -0
  107. package/server/service/data-sensor/data-sensor-type.ts +104 -0
  108. package/server/service/data-sensor/data-sensor.ts +126 -0
  109. package/server/service/data-sensor/index.ts +6 -0
  110. package/server/service/data-set/data-item-type.ts +155 -0
  111. package/server/service/data-set/data-set-mutation.ts +552 -0
  112. package/server/service/data-set/data-set-query.ts +461 -0
  113. package/server/service/data-set/data-set-type.ts +204 -0
  114. package/server/service/data-set/data-set.ts +326 -0
  115. package/server/service/data-set/index.ts +6 -0
  116. package/server/service/data-set-history/data-set-history-query.ts +126 -0
  117. package/server/service/data-set-history/data-set-history-type.ts +12 -0
  118. package/server/service/data-set-history/data-set-history.ts +217 -0
  119. package/server/service/data-set-history/event-subscriber.ts +17 -0
  120. package/server/service/data-set-history/index.ts +7 -0
  121. package/server/service/data-spec/data-spec-manager.ts +21 -0
  122. package/server/service/data-spec/data-spec-query.ts +21 -0
  123. package/server/service/data-spec/data-spec.ts +45 -0
  124. package/server/service/data-spec/index.ts +5 -0
  125. package/server/service/data-summary/data-summary-mutation.ts +45 -0
  126. package/server/service/data-summary/data-summary-query.ts +179 -0
  127. package/server/service/data-summary/data-summary-type.ts +86 -0
  128. package/server/service/data-summary/data-summary.ts +170 -0
  129. package/server/service/data-summary/index.ts +7 -0
  130. package/server/service/index.ts +57 -0
  131. package/server/tsconfig.json +10 -0
  132. package/server/utils/config-resolver.ts +29 -0
  133. package/server/utils/index.ts +1 -0
  134. package/translations/en.json +0 -3
  135. package/translations/ja.json +0 -3
  136. package/translations/ko.json +0 -3
  137. package/translations/ms.json +0 -3
  138. package/translations/zh.json +0 -3
  139. package/dist-server/controllers/create-data-ooc.d.ts +0 -4
  140. package/dist-server/controllers/create-data-ooc.js +0 -65
  141. package/dist-server/controllers/create-data-ooc.js.map +0 -1
  142. package/dist-server/controllers/issue-ooc-resolve.d.ts +0 -3
  143. package/dist-server/controllers/issue-ooc-resolve.js +0 -49
  144. package/dist-server/controllers/issue-ooc-resolve.js.map +0 -1
  145. package/dist-server/controllers/issue-ooc-review.d.ts +0 -3
  146. package/dist-server/controllers/issue-ooc-review.js +0 -47
  147. package/dist-server/controllers/issue-ooc-review.js.map +0 -1
@@ -0,0 +1,143 @@
1
+ import '@operato/dataset/ox-data-ooc-brief-view.js'
2
+
3
+ import gql from 'graphql-tag'
4
+ import { css, html, LitElement } from 'lit'
5
+ import { customElement, property, query, state } from 'lit/decorators.js'
6
+
7
+ import { client } from '@operato/graphql'
8
+ import { i18next, localize } from '@operato/i18n'
9
+ import { ScrollbarStyles } from '@operato/styles'
10
+
11
+ @customElement('activity-ooc-resolve-view')
12
+ export class OocResolveActivityView extends localize(i18next)(LitElement) {
13
+ static styles = [
14
+ ScrollbarStyles,
15
+ css`
16
+ :host {
17
+ display: flex;
18
+ flex-direction: column;
19
+
20
+ background-color: var(--md-sys-color-surface);
21
+ }
22
+
23
+ div[content] {
24
+ flex: 1;
25
+ flex-direction: column;
26
+
27
+ display: flex;
28
+ overflow: auto;
29
+ }
30
+
31
+ ox-data-ooc-brief-view {
32
+ flex: 1;
33
+ padding: var(--spacing-large);
34
+ overflow: auto;
35
+ }
36
+
37
+ @media print {
38
+ :host {
39
+ display: block;
40
+ overflow: visible;
41
+ }
42
+
43
+ div[content] {
44
+ display: block;
45
+ overflow: visible;
46
+ }
47
+ }
48
+ `
49
+ ]
50
+
51
+ @property({ type: Object }) input?: any
52
+ @property({ type: Object }) output?: any
53
+ @property({ type: Object }) activityApproval?: any
54
+
55
+ @state() dataOoc?: any
56
+
57
+ render() {
58
+ return html`
59
+ <div content>
60
+ <ox-data-ooc-brief-view .dataOoc=${this.dataOoc}></ox-data-ooc-brief-view>
61
+ </div>
62
+ `
63
+ }
64
+
65
+ updated(changes) {
66
+ if (changes.has('input')) {
67
+ this.fetchDataOoc()
68
+ }
69
+ }
70
+
71
+ async fetchDataOoc() {
72
+ const id = this.input.dataOocId
73
+
74
+ if (id) {
75
+ const response = await client.query({
76
+ query: gql`
77
+ query ($id: String!) {
78
+ dataOoc(id: $id) {
79
+ id
80
+ name
81
+ description
82
+ ooc
83
+ oos
84
+ state
85
+ type
86
+ useCase
87
+ data
88
+ judgment
89
+ history
90
+ correctiveAction
91
+ correctiveInstruction
92
+ dataItems {
93
+ name
94
+ description
95
+ active
96
+ hidden
97
+ tag
98
+ group
99
+ type
100
+ unit
101
+ options
102
+ quota
103
+ spec
104
+ stat
105
+ }
106
+ workDate
107
+ workShift
108
+ reviewer {
109
+ id
110
+ name
111
+ }
112
+ corrector {
113
+ id
114
+ name
115
+ }
116
+ collectedAt
117
+ reviewedAt
118
+ correctedAt
119
+ }
120
+ }
121
+ `,
122
+ variables: {
123
+ id
124
+ }
125
+ })
126
+
127
+ const dataOoc = {
128
+ ...response.data.dataOoc
129
+ }
130
+
131
+ const activityThread = this.activityApproval?.activityThread
132
+
133
+ if (activityThread?.output) {
134
+ /* approval 에서 사용되는 경우 corrective 관련정보를 보완한다. - approval과정에서는 아직 dataOoc.correctiveAction 정보는 채워지지 않았기 때문. */
135
+ dataOoc.correctiveAction = activityThread.output.action
136
+ dataOoc.correctedAt = activityThread.updatedAt
137
+ dataOoc.corrector = activityThread.assignee
138
+ }
139
+
140
+ this.dataOoc = dataOoc
141
+ }
142
+ }
143
+ }
@@ -0,0 +1,173 @@
1
+ import '@material/web/icon/icon.js'
2
+ import '@operato/dataset/ox-data-sample-view.js'
3
+
4
+ import gql from 'graphql-tag'
5
+ import { css, html, LitElement } from 'lit'
6
+ import { customElement, property, query, state } from 'lit/decorators.js'
7
+
8
+ import { client } from '@operato/graphql'
9
+ import { i18next, localize } from '@operato/i18n'
10
+ import { ScrollbarStyles } from '@operato/styles'
11
+
12
+ @customElement('activity-ooc-review-edit')
13
+ class OocReviewActivityEdit extends localize(i18next)(LitElement) {
14
+ static styles = [
15
+ ScrollbarStyles,
16
+ css`
17
+ :host {
18
+ display: flex;
19
+ flex-direction: column;
20
+
21
+ background-color: var(--md-sys-color-surface);
22
+ }
23
+
24
+ div[content] {
25
+ flex: 1;
26
+ flex-direction: column;
27
+
28
+ display: flex;
29
+ overflow: auto;
30
+ }
31
+
32
+ ox-data-sample-view {
33
+ flex: 1;
34
+ padding: var(--spacing-large);
35
+ overflow: auto;
36
+ }
37
+
38
+ label[instruction] {
39
+ display: flex;
40
+ flex-direction: column;
41
+
42
+ padding: var(--spacing-large);
43
+
44
+ h2 {
45
+ display: flex;
46
+
47
+ color: var(--title-text-color);
48
+ text-transform: capitalize;
49
+ margin: var(--title-margin);
50
+ align-items: center;
51
+ }
52
+
53
+ div {
54
+ padding: var(--spacing-large);
55
+ font: var(--input-field-font);
56
+ }
57
+
58
+ md-icon {
59
+ color: var(--status-danger-color);
60
+ }
61
+
62
+ textarea {
63
+ border: var(--input-field-border);
64
+ border-radius: var(--spacing-small);
65
+ margin: var(--spacing-medium);
66
+ padding: var(--spacing-medium);
67
+ font: var(--input-field-font);
68
+ color: var(--md-sys-color-on-surface);
69
+ background: var(--md-sys-color-surface-variant);
70
+
71
+ resize: none;
72
+ outline: none;
73
+ min-height: 200px;
74
+ }
75
+ }
76
+ `
77
+ ]
78
+
79
+ @property({ type: Object }) input?: any
80
+ @property({ type: Object }) output?: any
81
+ @property({ type: Object }) activityThread?: any
82
+
83
+ @state() dataOoc?: any
84
+
85
+ render() {
86
+ const instruction = this.output?.instruction
87
+ const { state } = this.activityThread || {}
88
+ const editable = state == 'unassigned' || state == 'assigned' || state == 'started' || state == 'submitted'
89
+
90
+ return html`
91
+ <div content>
92
+ <ox-data-sample-view .dataSample=${this.dataOoc}></ox-data-sample-view>
93
+ </div>
94
+
95
+ <label instruction>
96
+ <h2><md-icon>build_circle</md-icon>&nbsp;<span>${i18next.t('label.corrective instruction')}</span></h2>
97
+ ${editable
98
+ ? html`
99
+ <textarea
100
+ placeholder=${String(i18next.t('text.corrective instruction placeholder'))}
101
+ .value=${instruction || ''}
102
+ @change=${this.onChangeInstruction}
103
+ ></textarea>
104
+ `
105
+ : html`<div>${instruction}</div>`}
106
+ </label>
107
+ `
108
+ }
109
+
110
+ onChangeInstruction(e: Event) {
111
+ this.output ||= {}
112
+ this.output.instruction = (e.target as HTMLTextAreaElement).value
113
+
114
+ this.dispatchEvent(
115
+ new CustomEvent('change', {
116
+ detail: this.output
117
+ })
118
+ )
119
+ }
120
+
121
+ updated(changes) {
122
+ if (changes.has('input')) {
123
+ this.fetchDataOoc()
124
+ }
125
+ }
126
+
127
+ async fetchDataOoc() {
128
+ const id = this.input?.dataOocId
129
+
130
+ if (id) {
131
+ const response = await client.query({
132
+ query: gql`
133
+ query ($id: String!) {
134
+ dataOoc(id: $id) {
135
+ id
136
+ name
137
+ description
138
+ ooc
139
+ oos
140
+ state
141
+ type
142
+ useCase
143
+ data
144
+ judgment
145
+ dataItems {
146
+ name
147
+ description
148
+ active
149
+ hidden
150
+ tag
151
+ group
152
+ type
153
+ unit
154
+ options
155
+ quota
156
+ spec
157
+ stat
158
+ }
159
+ workDate
160
+ workShift
161
+ collectedAt
162
+ }
163
+ }
164
+ `,
165
+ variables: {
166
+ id
167
+ }
168
+ })
169
+
170
+ this.dataOoc = response.data.dataOoc
171
+ }
172
+ }
173
+ }
@@ -0,0 +1,129 @@
1
+ import '@operato/dataset/ox-data-ooc-brief-view.js'
2
+
3
+ import gql from 'graphql-tag'
4
+ import { css, html, LitElement } from 'lit'
5
+ import { customElement, property, query, state } from 'lit/decorators.js'
6
+
7
+ import { client } from '@operato/graphql'
8
+ import { i18next, localize } from '@operato/i18n'
9
+ import { ScrollbarStyles } from '@operato/styles'
10
+
11
+ @customElement('activity-ooc-review-view')
12
+ class OocReviewActivityView extends localize(i18next)(LitElement) {
13
+ static styles = [
14
+ ScrollbarStyles,
15
+ css`
16
+ :host {
17
+ display: flex;
18
+ flex-direction: column;
19
+
20
+ background-color: var(--md-sys-color-surface);
21
+ }
22
+
23
+ div[content] {
24
+ flex: 1;
25
+ flex-direction: column;
26
+
27
+ display: flex;
28
+ overflow: auto;
29
+ }
30
+
31
+ ox-data-ooc-brief-view {
32
+ flex: 1;
33
+ padding: var(--spacing-large);
34
+ overflow: auto;
35
+ }
36
+
37
+ @media print {
38
+ :host {
39
+ display: block;
40
+ overflow: visible;
41
+ }
42
+
43
+ div[content] {
44
+ display: block;
45
+ overflow: visible;
46
+ }
47
+ }
48
+ `
49
+ ]
50
+
51
+ @property({ type: Object }) input?: any
52
+ @property({ type: Object }) output?: any
53
+
54
+ @state() dataOoc?: any
55
+
56
+ render() {
57
+ return html`
58
+ <div content>
59
+ <ox-data-ooc-brief-view .dataOoc=${this.dataOoc}></ox-data-ooc-brief-view>
60
+ </div>
61
+ `
62
+ }
63
+
64
+ updated(changes) {
65
+ if (changes.has('input')) {
66
+ this.fetchDataOoc()
67
+ }
68
+ }
69
+
70
+ async fetchDataOoc() {
71
+ const id = this.input?.dataOocId
72
+
73
+ if (id) {
74
+ const response = await client.query({
75
+ query: gql`
76
+ query ($id: String!) {
77
+ dataOoc(id: $id) {
78
+ id
79
+ name
80
+ description
81
+ ooc
82
+ oos
83
+ state
84
+ type
85
+ useCase
86
+ data
87
+ judgment
88
+ history
89
+ correctiveAction
90
+ correctiveInstruction
91
+ dataItems {
92
+ name
93
+ description
94
+ active
95
+ hidden
96
+ tag
97
+ group
98
+ type
99
+ unit
100
+ options
101
+ quota
102
+ spec
103
+ stat
104
+ }
105
+ workDate
106
+ workShift
107
+ reviewer {
108
+ id
109
+ name
110
+ }
111
+ corrector {
112
+ id
113
+ name
114
+ }
115
+ collectedAt
116
+ reviewedAt
117
+ correctedAt
118
+ }
119
+ }
120
+ `,
121
+ variables: {
122
+ id
123
+ }
124
+ })
125
+
126
+ this.dataOoc = response.data.dataOoc
127
+ }
128
+ }
129
+ }
@@ -0,0 +1,35 @@
1
+ import './activities/activity-data-collect-edit' /* refered by the activity template (activity-data-collect) on server */
2
+ import './activities/activity-data-collect-view' /* refered by the activity template (activity-data-collect) on server */
3
+ import './activities/activity-data-review-edit' /* refered by the activity template (activity-data-review) on server */
4
+ import './activities/activity-data-review-view' /* refered by the activity template (activity-data-review) on server */
5
+ import './activities/activity-ooc-review-edit' /* refered by the activity template (activity-ooc-review) on server */
6
+ import './activities/activity-ooc-review-view' /* refered by the activity template (activity-ooc-review) on server */
7
+ import './activities/activity-ooc-resolve-edit' /* refered by the activity template (activity-ooc-resolve) on server */
8
+ import './activities/activity-ooc-resolve-view' /* refered by the activity template (activity-ooc-resolve) on server */
9
+ import '@operato/app/filter-renderer.js' /* register resource-object filter renderer */
10
+
11
+ import { OxGristEditorCode } from '@operato/app/grist-editor/ox-grist-editor-code.js'
12
+ import {
13
+ OxGristRendererJson5,
14
+ registerEditor as registerGristEditor,
15
+ registerRenderer as registerGristRenderer
16
+ } from '@operato/data-grist'
17
+ import { OxGristEditorDataItemSpec } from '@operato/dataset/grist-editor/ox-grist-editor-data-item-spec.js'
18
+ import { OxGristEditorPartitionKeys } from '@operato/grist-editor/ox-grist-editor-partition-keys.js'
19
+ import { OxGristRendererPartitionKeys } from '@operato/grist-editor/ox-grist-renderer-partition-keys.js'
20
+
21
+ import { OxGristEditorSignature } from '@operato/grist-editor/ox-grist-editor-signature.js'
22
+ import { OxGristRendererSignature } from '@operato/grist-editor/ox-grist-renderer-signature.js'
23
+
24
+ export default function bootstrap() {
25
+ registerGristEditor('data-item-spec', OxGristEditorDataItemSpec)
26
+ registerGristRenderer('data-item-spec', OxGristRendererJson5)
27
+
28
+ registerGristEditor('script', OxGristEditorCode)
29
+
30
+ registerGristEditor('partition-keys', OxGristEditorPartitionKeys)
31
+ registerGristRenderer('partition-keys', OxGristRendererPartitionKeys)
32
+
33
+ registerGristRenderer('signature', OxGristRendererSignature)
34
+ registerGristEditor('signature', OxGristEditorSignature)
35
+ }
@@ -0,0 +1,109 @@
1
+ import '@material/web/icon/icon.js'
2
+ import '@operato/dataset/ox-data-entry-form.js'
3
+
4
+ import gql from 'graphql-tag'
5
+ import { css, html, LitElement } from 'lit'
6
+ import { customElement, property, query, state } from 'lit/decorators.js'
7
+
8
+ import { client } from '@operato/graphql'
9
+ import { i18next, localize } from '@operato/i18n'
10
+ import { CommonHeaderStyles, ScrollbarStyles } from '@operato/styles'
11
+ import { OxDataEntryForm } from '@operato/dataset/ox-data-entry-form.js'
12
+ import { DataSet } from '@operato/dataset'
13
+
14
+ @customElement('data-entry-form')
15
+ export class DataEntryForm extends localize(i18next)(LitElement) {
16
+ static styles = [
17
+ CommonHeaderStyles,
18
+ ScrollbarStyles,
19
+ css`
20
+ :host {
21
+ display: flex;
22
+ flex-direction: column;
23
+
24
+ background-color: var(--md-sys-color-surface);
25
+ }
26
+
27
+ ox-data-entry-form {
28
+ flex: 1;
29
+ padding: 10px;
30
+ overflow: auto;
31
+ }
32
+
33
+ .footer span {
34
+ font-size: 0.8em;
35
+ color: var(--md-sys-color-on-surface);
36
+ line-height: 1.5;
37
+ padding: 10px;
38
+ }
39
+ `
40
+ ]
41
+
42
+ @property({ type: Object }) dataSet?: DataSet & { id: string }
43
+
44
+ @state() dataSample?: { id: string; collectedAt: Date }
45
+
46
+ @query('ox-data-entry-form') entryForm!: OxDataEntryForm
47
+
48
+ render() {
49
+ return html`
50
+ <ox-data-entry-form .dataSet=${this.dataSet}></ox-data-entry-form>
51
+
52
+ <div class="footer">
53
+ <div filler></div>
54
+ ${!this.dataSample
55
+ ? html`
56
+ <button @click=${this.updateDataItems.bind(this)} done>
57
+ <md-icon>save</md-icon>${i18next.t('button.save')}
58
+ </button>
59
+ `
60
+ : html` <span>${i18next.t('field.collected-at')}: ${this.dataSample.collectedAt.toLocaleString()}</span> `}
61
+ </div>
62
+ `
63
+ }
64
+
65
+ private async updateDataItems() {
66
+ //@ts-ignore TODO replace with following line and confirm
67
+ const data = this.entryForm.buildValue()
68
+
69
+ const dataSample = {
70
+ dataSet: {
71
+ id: this.dataSet?.id
72
+ },
73
+ data
74
+ } as any
75
+
76
+ if (this.dataSample?.collectedAt) {
77
+ dataSample.collectedAt = this.dataSample.collectedAt
78
+ }
79
+
80
+ const response = await client.mutate({
81
+ mutation: gql`
82
+ mutation ($dataSample: NewDataSample!) {
83
+ createDataSample(dataSample: $dataSample) {
84
+ id
85
+ collectedAt
86
+ }
87
+ }
88
+ `,
89
+ variables: {
90
+ dataSample
91
+ },
92
+ context: {
93
+ hasUpload: true
94
+ }
95
+ })
96
+
97
+ if (!response.errors) {
98
+ const { id, collectedAt } = response.data.createDataSample
99
+ this.dataSample = {
100
+ id,
101
+ collectedAt: new Date(collectedAt)
102
+ }
103
+
104
+ document.dispatchEvent(
105
+ new CustomEvent('notify', { detail: { message: i18next.t('text.data sample created successfully') } })
106
+ )
107
+ }
108
+ }
109
+ }
@@ -0,0 +1 @@
1
+ export * from './components/data-entry-form.js'