@openremote/or-survey 1.0.4 → 1.2.0-snapshot.20240512160221

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/package.json CHANGED
@@ -1,32 +1,33 @@
1
1
  {
2
2
  "name": "@openremote/or-survey",
3
- "version": "1.0.4",
3
+ "version": "1.2.0-snapshot.20240512160221",
4
4
  "description": "Displays survey",
5
5
  "main": "dist/umd/index.bundle.js",
6
- "module": "dist/index.js",
7
- "types": "dist/index.d.ts",
6
+ "module": "lib/index.js",
7
+ "exports": {
8
+ ".": "./lib/index.js",
9
+ "./*": "./lib/*.js"
10
+ },
11
+ "types": "lib/index.d.ts",
8
12
  "scripts": {
9
13
  "test": "echo \"No tests\" && exit 0",
10
- "prepublishOnly": "npx tsc -b && npx webpack"
14
+ "prepublishOnly": "npx webpack"
11
15
  },
12
16
  "author": "OpenRemote",
13
17
  "license": "AGPL-3.0-or-later",
14
18
  "dependencies": {
15
- "@openremote/core": "^1.0.3",
16
- "@openremote/model": "^1.0.3",
17
- "@openremote/or-translate": "^1.0.3",
18
- "@types/lodash-es": "^4.17.3",
19
- "lit-element": "^2.4.0",
19
+ "@openremote/core": "1.2.0-snapshot.20240512160221",
20
+ "@openremote/model": "1.2.0-snapshot.20240512160221",
21
+ "@openremote/or-translate": "1.2.0-snapshot.20240512160221",
22
+ "@types/lodash-es": "^4.17.5",
23
+ "lit": "^2.0.2",
20
24
  "lodash-es": "^4.17.15",
21
- "moment": "2.24.0"
25
+ "moment": "2.29.4"
22
26
  },
23
27
  "devDependencies": {
24
- "tslint": ">=5.11.0",
25
- "typescript": ">=3.4.5",
26
- "webpack": "^4.41.2",
27
- "webpack-cli": "^3.3.9"
28
+ "@openremote/util": "1.2.0-snapshot.20240512160221"
28
29
  },
29
30
  "publishConfig": {
30
31
  "access": "public"
31
32
  }
32
- }
33
+ }
package/.project DELETED
@@ -1,17 +0,0 @@
1
- <?xml version="1.0" encoding="UTF-8"?>
2
- <projectDescription>
3
- <name>or-survey</name>
4
- <comment>Project or-survey created by Buildship.</comment>
5
- <projects>
6
- </projects>
7
- <buildSpec>
8
- <buildCommand>
9
- <name>org.eclipse.buildship.core.gradleprojectbuilder</name>
10
- <arguments>
11
- </arguments>
12
- </buildCommand>
13
- </buildSpec>
14
- <natures>
15
- <nature>org.eclipse.buildship.core.gradleprojectnature</nature>
16
- </natures>
17
- </projectDescription>
@@ -1,2 +0,0 @@
1
- connection.project.dir=../../../../manager
2
- eclipse.preferences.version=1
package/dist/index.d.ts DELETED
@@ -1,13 +0,0 @@
1
- import "@openremote/or-translate";
2
- export interface OrComputeGridEventDetail {
3
- }
4
- export declare class OrComputeGridEvent extends CustomEvent<OrComputeGridEventDetail> {
5
- static readonly NAME = "or-asset-viewer-compute-grid-event";
6
- constructor();
7
- }
8
- export interface AnswerOption {
9
- value: string;
10
- }
11
- export interface SurveyAnswers {
12
- [key: string]: string | string[];
13
- }
package/dist/index.js DELETED
@@ -1,434 +0,0 @@
1
- var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
2
- var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3
- if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
4
- else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
5
- return c > 3 && r && Object.defineProperty(target, key, r), r;
6
- };
7
- import { customElement, html, LitElement, property } from "lit-element";
8
- import { surveySectionStyle, surveyLayoutStyle } from "./style";
9
- import get from "lodash-es/get";
10
- import orderBy from "lodash-es/orderBy";
11
- import * as momentImported from 'moment';
12
- const moment = momentImported;
13
- import manager, { OREvent } from "@openremote/core";
14
- import filter from "lodash-es/filter";
15
- import "@openremote/or-translate";
16
- export class OrComputeGridEvent extends CustomEvent {
17
- constructor() {
18
- super(OrComputeGridEvent.NAME, {
19
- bubbles: true,
20
- composed: true
21
- });
22
- }
23
- }
24
- OrComputeGridEvent.NAME = "or-asset-viewer-compute-grid-event";
25
- let OrSurvey = class OrSurvey extends LitElement {
26
- constructor() {
27
- super();
28
- this.resetSurvey();
29
- this.questions = [];
30
- this.completed = false;
31
- }
32
- render() {
33
- if (!this.survey) {
34
- return html ``;
35
- }
36
- const orderedQuestions = orderBy(this.questions, ['attributes.order.value'], ['asc']);
37
- const status = this.checkAssetPeriode(this.survey);
38
- let currentAnswer;
39
- if (this.questions && this.questionIndex && this.questions[this.questionIndex]) {
40
- const currentQuestion = this.questions[this.questionIndex];
41
- if (currentQuestion && currentQuestion.id && this.surveyAnswers) {
42
- currentAnswer = this.surveyAnswers[currentQuestion.id];
43
- }
44
- }
45
- return html `
46
- ${surveySectionStyle}
47
- ${surveyLayoutStyle}
48
- <div id="surveyQuestions">
49
- ${this.completed || this.hasSubmission ? html `
50
- <p>${this.survey.attributes ? this.survey.attributes.thankYouMessage.value : ''}</p>
51
- ${!this.saveanswers ? html `
52
- <button visible="${this.previousButton}" class="previous" @click="${this.resetSurvey}"
53
- aria-label="To survey"><or-translate value="To survey"></or-translate>
54
- <svg viewBox="0 0 32 32" class="icon icon-chevron-left" viewBox="0 0 32 32" aria-hidden="true"><path d="M14.19 16.005l7.869 7.868-2.129 2.129-9.996-9.997L19.937 6.002l2.127 2.129z"/></svg>
55
- </button>
56
- ` : ``}
57
- ` : html `
58
- ${status === 'before' ? html `
59
- <p>${this.survey.attributes ? this.survey.attributes.beforeValidMessage.value : ''}</p>
60
- ` : ``}
61
-
62
- ${status === 'after' ? html `
63
- <p>${this.survey.attributes ? this.survey.attributes.afterValidMessage.value : ''}</p>
64
- ` : ``}
65
-
66
- ${status === 'live' || (status === 'not_published' && !this.saveanswers) ? html `
67
- ${orderedQuestions.map((question, index) => {
68
- return html `
69
- ${get(question, 'attributes.active.value') && index === this.questionIndex ? html `
70
- <div class="${this.questionAnimation}">
71
- <p>${question.name}</p>
72
-
73
- <div id="survey-container" style="flex-wrap: wrap;" class="layout horizontal ${this.questionAnimation}">
74
-
75
- ${this.getType(question.type) === 'text' ? html `
76
- <textarea rows="4" class="text-input" type="${this.getInputType(question.type)}" id="${question.id}" name="${question.id}_${index}">${currentAnswer}</textarea>
77
- ` : html `
78
- ${question.attributes && question.attributes.answerOptions.value.map((answer, index) => {
79
- return html `
80
- <div class="anwser-card ${this.getType(question.type)}">
81
-
82
- ${!currentAnswer ? html `
83
- <input type="${this.getInputType(question.type)}" id="${question.id}_${index}"
84
- name="${question.id}" value="${answer.value}"
85
- autofocus />
86
- ` : html `
87
- ${this.getType(question.type) === 'multiSelect' ? html `
88
- <input type="${this.getInputType(question.type)}" id="${question.id}_${index}"
89
- name="${question.id}" value="${answer.value}"
90
- ?checked="${currentAnswer.includes(answer.value)}"
91
- autofocus />
92
- ` : html `
93
- <input type="${this.getInputType(question.type)}" id="${question.id}_${index}"
94
- name="${question.id}" value="${answer.value}"
95
- ?checked="${currentAnswer === answer.value}"
96
- autofocus />
97
- `}
98
- `}
99
- <label class="flex-grow" @click="${(e) => this.onAnswer(e, answer)}" for="${question.id}_${index}">
100
- ${answer.value}
101
- </label>
102
- </div>
103
- `;
104
- })}
105
- `}
106
-
107
- </div>
108
- </div>
109
-
110
- ` : ``}
111
- `;
112
- })}
113
-
114
- <div style="margin-top:20px;" class="layout horizontal justified center-center">
115
- <button ?visible="${this.previousButton}" class="previous" @click="${this.previousQuestion}"
116
- aria-label="Previous">
117
- <or-translate value="Previous"></or-translate>
118
- <svg viewBox="0 0 32 32" class="icon icon-chevron-left" viewBox="0 0 32 32" aria-hidden="true"><path d="M14.19 16.005l7.869 7.868-2.129 2.129-9.996-9.997L19.937 6.002l2.127 2.129z"/></svg>
119
- </button>
120
- <div style="line-height: 40px;" class="flex-grow t-center">${this.questionIndexLabel} / ${this.questions ? this.questions.length : 0}</div>
121
- <button ?visible="${this.nextButton}" class="next" @click="${this.onAnswer}" data-autoforward="true"
122
- aria-label="${this.nextButtonLabel}">
123
- <or-translate value="${this.nextButtonLabel}"></or-translate>
124
- <svg viewBox="0 0 32 32" class="icon icon-chevron-right" viewBox="0 0 32 32" aria-hidden="true"><path d="M18.629 15.997l-7.083-7.081L13.462 7l8.997 8.997L13.457 25l-1.916-1.916z"/></svg>
125
- </button>
126
- </div>
127
-
128
- ` : ``}
129
- `}
130
- </div>
131
-
132
-
133
- `;
134
- }
135
- firstUpdated(_changedProperties) {
136
- super.firstUpdated(_changedProperties);
137
- if (!manager.ready) {
138
- // Defer until openremote is initialised
139
- this._initCallback = (initEvent) => {
140
- if (initEvent === OREvent.READY) {
141
- this.getSurvey();
142
- manager.removeListener(this._initCallback);
143
- }
144
- };
145
- manager.addListener(this._initCallback);
146
- }
147
- else {
148
- this.getSurvey();
149
- }
150
- }
151
- updated(_changedProperties) {
152
- super.updated(_changedProperties);
153
- if (_changedProperties.has('survey') || _changedProperties.has('surveyId')) {
154
- this.resetSurvey();
155
- }
156
- this.dispatchEvent(new OrComputeGridEvent());
157
- }
158
- checkAssetPeriode(asset) {
159
- const today = moment();
160
- const startDate = get(asset, 'attributes.validity.value.start');
161
- const endDate = get(asset, 'attributes.validity.value.end');
162
- // not published
163
- if (get(asset, 'attributes.published.value') === false) {
164
- return 'not_published';
165
- }
166
- else if (today.diff(startDate) > 0 && today.diff(endDate) < 0) {
167
- // between dates
168
- return 'live';
169
- }
170
- else if (today.diff(startDate) < 0) {
171
- // before start date
172
- return 'before';
173
- }
174
- else if (today.diff(endDate) > 0) {
175
- // after end date
176
- return 'after';
177
- }
178
- else {
179
- return 'not_published';
180
- }
181
- }
182
- getInputType(type) {
183
- if (type) {
184
- if (type.includes('singleSelect') || type.includes('rating')) {
185
- return "radio";
186
- }
187
- else if (type.includes('multiSelect')) {
188
- return "checkbox";
189
- }
190
- else if (type.includes('text')) {
191
- return "text";
192
- }
193
- }
194
- }
195
- getType(type) {
196
- if (type) {
197
- const parts = type.split(':');
198
- const label = parts[parts.length - 1];
199
- return label;
200
- }
201
- }
202
- checkButtons() {
203
- if (!this.survey || !this.questions || typeof this.questionIndex === "undefined") {
204
- return;
205
- }
206
- this.questions.sort((a, b) => a.attributes && b.attributes ? a.attributes.order.value - b.attributes.order.value : 0);
207
- this.questions = [...this.questions];
208
- if (this.questionIndex > 0) {
209
- this.previousButton = true;
210
- this.nextButton = true;
211
- }
212
- else {
213
- if (this.questions[0]) {
214
- if (this.questions[0].attributes && !this.questions[0].attributes.categorizeInResult.value) {
215
- this.nextButton = true;
216
- }
217
- else {
218
- this.nextButton = false;
219
- }
220
- }
221
- this.previousButton = false;
222
- }
223
- if (this.questionIndex + 1 == this.questions.length) {
224
- this.nextButtonLabel = 'Send';
225
- }
226
- else {
227
- this.nextButtonLabel = 'Next';
228
- }
229
- if (this.questionIndex === this.questions.length && this.questions.length !== 0) {
230
- this.completed = true;
231
- if (this.survey.attributes && this.survey.attributes.published.value && this.saveanswers) {
232
- localStorage.setItem('survey' + this.survey.id, "set");
233
- var xhttp = new XMLHttpRequest();
234
- const url = manager.config.managerUrl ? manager.config.managerUrl + "/rest/survey/" : window.location.origin + "/rest/survey/";
235
- xhttp.open("POST", url + this.survey.id, true);
236
- xhttp.setRequestHeader("Content-type", "application/json");
237
- xhttp.send(JSON.stringify(this.surveyAnswers));
238
- }
239
- }
240
- this.requestUpdate();
241
- }
242
- nextQuestion() {
243
- if (typeof this.questionIndex === 'undefined' || typeof this.questionIndexLabel === 'undefined') {
244
- return;
245
- }
246
- this.questionAnimation = 'moveIn';
247
- this.questionIndex = this.questionIndex + 1;
248
- this.questionIndexLabel = this.questionIndexLabel + 1;
249
- this.checkButtons();
250
- }
251
- resetSurvey() {
252
- this.questionIndex = 0;
253
- this.questionIndexLabel = 1;
254
- this.nextButtonLabel = "Next";
255
- this.completed = false;
256
- this.surveyAnswers = {};
257
- this.checkButtons();
258
- }
259
- previousQuestion() {
260
- if (typeof this.questionIndex === 'undefined' || typeof this.questionIndexLabel === 'undefined') {
261
- return;
262
- }
263
- this.questionAnimation = 'moveOut';
264
- this.questionIndex = this.questionIndex - 1;
265
- this.questionIndexLabel = this.questionIndexLabel - 1;
266
- this.checkButtons();
267
- }
268
- onAnswer(e, answer) {
269
- if (!this.questions || typeof this.questionIndex === 'undefined' || typeof this.questionIndexLabel === 'undefined') {
270
- return;
271
- }
272
- const target = e.currentTarget;
273
- let surveyAnswers = this.surveyAnswers;
274
- let currQuestion = this.questions[this.questionIndex];
275
- if (this.getType(currQuestion.type) === "singleSelect" || this.getType(currQuestion.type) === "rating") {
276
- if (!(target instanceof HTMLButtonElement) && !(target instanceof HTMLLabelElement)) {
277
- return;
278
- }
279
- if (target && target.dataset.autoforward == "true") {
280
- this.nextQuestion();
281
- }
282
- else {
283
- if (currQuestion && currQuestion.id && surveyAnswers) {
284
- surveyAnswers[currQuestion.id] = answer.value;
285
- this.surveyAnswers = surveyAnswers;
286
- this.nextQuestion();
287
- }
288
- }
289
- }
290
- else if (this.getType(currQuestion.type) === "text") {
291
- let id = this.questions[this.questionIndex].id;
292
- if (this.shadowRoot && id) {
293
- const element = this.shadowRoot.getElementById(id);
294
- if (element && currQuestion && currQuestion.id && surveyAnswers) {
295
- let value = element.value;
296
- surveyAnswers[currQuestion.id] = value;
297
- }
298
- }
299
- this.nextQuestion();
300
- }
301
- else if (this.getType(currQuestion.type) === "multiSelect") {
302
- if (!(target instanceof HTMLButtonElement) && !(target instanceof HTMLLabelElement)) {
303
- return;
304
- }
305
- if (target.dataset.autoforward == "true") {
306
- this.nextQuestion();
307
- }
308
- else {
309
- if (currQuestion && currQuestion.id && surveyAnswers && target instanceof HTMLLabelElement) {
310
- if (!surveyAnswers[currQuestion.id]) {
311
- surveyAnswers[currQuestion.id] = [];
312
- }
313
- const array = surveyAnswers[currQuestion.id];
314
- if (this.shadowRoot && Array.isArray(array)) {
315
- let input = this.shadowRoot.getElementById(target.htmlFor);
316
- if (!input.checked) {
317
- array.push(answer.value);
318
- }
319
- else {
320
- // Delete answer from array
321
- let index = surveyAnswers[currQuestion.id].indexOf(answer.value);
322
- array.splice(index, 1);
323
- }
324
- this.surveyAnswers = surveyAnswers;
325
- }
326
- }
327
- }
328
- }
329
- }
330
- getSurvey() {
331
- let surveyId;
332
- if (location.hash.indexOf('survey') != -1) {
333
- surveyId = location.hash.split('/')[1];
334
- if (!surveyId) {
335
- this.checkButtons();
336
- return;
337
- }
338
- }
339
- else if (this.surveyId) {
340
- surveyId = this.surveyId;
341
- }
342
- else {
343
- this.checkButtons();
344
- return;
345
- }
346
- const surveyQuery = {
347
- select: {
348
- excludeAttributeMeta: false,
349
- excludeAttributes: false,
350
- excludeAttributeValue: false,
351
- excludeAttributeTimestamp: false,
352
- excludeAttributeType: false
353
- },
354
- ids: [surveyId],
355
- types: [{ predicateType: "string", value: "urn:openremote:asset:" + manager.getRealm() + ":survey" }]
356
- };
357
- manager.rest.api.AssetResource.queryPublicAssets(surveyQuery).then((response) => {
358
- if (response && response.data) {
359
- this.survey = response.data[0];
360
- this.requestUpdate();
361
- }
362
- }).catch((reason) => {
363
- console.error("Error: " + reason);
364
- });
365
- if (localStorage.getItem('survey' + surveyId) && this.saveanswers) {
366
- this.hasSubmission = true;
367
- return;
368
- }
369
- const questionQuery = {
370
- select: {
371
- excludeAttributeMeta: false,
372
- excludeAttributes: false,
373
- excludeAttributeValue: false,
374
- excludeAttributeTimestamp: false,
375
- excludeAttributeType: false
376
- },
377
- types: [{ predicateType: "string", value: "urn:openremote:asset:" + manager.getRealm() + ":survey:question", match: "CONTAINS" /* CONTAINS */ }]
378
- };
379
- manager.rest.api.AssetResource.queryPublicAssets(questionQuery).then((response) => {
380
- if (response && response.data) {
381
- const questions = response.data;
382
- questions.sort((a, b) => a.attributes && b.attributes ? a.attributes.order.value - b.attributes.order.value : 0);
383
- this.questions = [...questions];
384
- if (this.survey) {
385
- this.questions = filter(this.questions, ['parentId', this.survey.id]);
386
- }
387
- this.checkButtons();
388
- this.requestUpdate();
389
- }
390
- }).catch((reason) => {
391
- console.error("Error: " + reason);
392
- });
393
- }
394
- };
395
- __decorate([
396
- property({ type: Object })
397
- ], OrSurvey.prototype, "survey", void 0);
398
- __decorate([
399
- property({ type: String })
400
- ], OrSurvey.prototype, "surveyId", void 0);
401
- __decorate([
402
- property({ type: Boolean })
403
- ], OrSurvey.prototype, "isAddingQuestion", void 0);
404
- __decorate([
405
- property({ type: Boolean })
406
- ], OrSurvey.prototype, "hasIntroQuestion", void 0);
407
- __decorate([
408
- property({ type: Object })
409
- ], OrSurvey.prototype, "question", void 0);
410
- __decorate([
411
- property({ type: Object })
412
- ], OrSurvey.prototype, "surveyAnswers", void 0);
413
- __decorate([
414
- property({ type: Array })
415
- ], OrSurvey.prototype, "questions", void 0);
416
- __decorate([
417
- property({ type: Boolean })
418
- ], OrSurvey.prototype, "saveanswers", void 0);
419
- __decorate([
420
- property({ type: Boolean })
421
- ], OrSurvey.prototype, "completed", void 0);
422
- __decorate([
423
- property({ type: Boolean })
424
- ], OrSurvey.prototype, "hasSubmission", void 0);
425
- __decorate([
426
- property({ type: Boolean })
427
- ], OrSurvey.prototype, "previousButton", void 0);
428
- __decorate([
429
- property({ type: Boolean })
430
- ], OrSurvey.prototype, "nextButton", void 0);
431
- OrSurvey = __decorate([
432
- customElement("or-survey")
433
- ], OrSurvey);
434
- //# sourceMappingURL=index.js.map
package/dist/style.d.ts DELETED
@@ -1,2 +0,0 @@
1
- export declare const surveySectionStyle: import("lit-element").TemplateResult;
2
- export declare const surveyLayoutStyle: import("lit-element").TemplateResult;