@wg-npm/survey-core 0.3.377-8.develop → 0.3.479-2.release

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.
@@ -69,7 +69,7 @@ class ChoiceModel {
69
69
  this.options = {
70
70
  score: null,
71
71
  star: false,
72
- starCount: null,
72
+ starCount: null
73
73
  };
74
74
  }
75
75
  static createChoiceId() {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wg-npm/survey-core",
3
- "version": "0.3.3778.develop",
3
+ "version": "0.3.4792.release",
4
4
  "description": "",
5
5
  "license": "MIT",
6
6
  "scripts": {
package/src/models.ts CHANGED
@@ -1,388 +1,390 @@
1
1
  import _ from "lodash";
2
- import { QuestionFactory } from "./quetion-factory";
2
+ import {QuestionFactory} from "./quetion-factory";
3
3
 
4
4
  const defaultText = function getText(locale: string): object {
5
- return _.set({}, locale, "");
5
+ return _.set({}, locale, "");
6
6
  };
7
7
 
8
8
  export const enum SurveyLocales {
9
- ZH_CN = "zh-CN",
10
- ZH_TW = "zh-TW",
11
- EN_US = "en-US",
9
+ ZH_CN = "zh-CN",
10
+ ZH_TW = "zh-TW",
11
+ EN_US = "en-US",
12
12
  }
13
13
 
14
14
  export const enum SurveyLayout {
15
- HORIZONTAL = "HORIZONTAL",
16
- VERTICAL = "VERTICAL",
15
+ HORIZONTAL = "HORIZONTAL",
16
+ VERTICAL = "VERTICAL",
17
17
  }
18
18
 
19
19
  export const enum QuestionType {
20
- SINGLE_SELECTION = "SINGLE_SELECTION",
21
- MULTI_SELECTION = "MULTI_SELECTION",
22
- FILL_BLANK = "FILL_BLANK",
23
- SHORT_ANSWER = "SHORT_ANSWER",
24
- MATRIX = "MATRIX",
25
- TEXT_TITLE = "TEXT_TITLE",
26
- EVALUATION = "EVALUATION",
20
+ SINGLE_SELECTION = "SINGLE_SELECTION",
21
+ MULTI_SELECTION = "MULTI_SELECTION",
22
+ FILL_BLANK = "FILL_BLANK",
23
+ SHORT_ANSWER = "SHORT_ANSWER",
24
+ MATRIX = "MATRIX",
25
+ TEXT_TITLE = "TEXT_TITLE",
26
+ EVALUATION = "EVALUATION",
27
27
  }
28
28
 
29
29
  export const enum EvaluationType {
30
- STAR = "STAR",
31
- EXPR = "EXPR",
30
+ STAR = "STAR",
31
+ EXPR = "EXPR"
32
32
  }
33
33
 
34
34
  export const enum ExprConditionType {
35
- ASSIGN = "ASSIGN",
36
- AUTO = "AUTO",
37
- SCORE = "SCORE",
35
+ ASSIGN = "ASSIGN",
36
+ AUTO = "AUTO"
38
37
  }
39
38
 
40
39
  export const enum ExprEvaluationItemType {
41
- IF = "IF",
42
- ELSE = "ELSE",
40
+ IF = "IF",
41
+ ELSE = "ELSE"
43
42
  }
44
43
 
45
44
  export class ChoiceModel {
46
- id: string;
47
- options?: Object;
48
- text: object;
49
-
50
- constructor(locale: string) {
51
- this.id = ChoiceModel.createChoiceId();
52
- this.text = defaultText(locale);
53
- this.options = {
54
- score: null,
55
- star: false,
56
- starCount: null,
57
- };
58
- }
45
+ id: string;
46
+ options?: Object;
47
+ text: object;
48
+
49
+ constructor(locale: string) {
50
+ this.id = ChoiceModel.createChoiceId();
51
+ this.text = defaultText(locale);
52
+ this.options = {
53
+ score: null,
54
+ star: false,
55
+ starCount: null
56
+ };
57
+ }
59
58
 
60
- static createChoiceId(): string {
61
- return `Choice-${_.now()}-${_.random(0, 9999999)}`;
62
- }
59
+ static createChoiceId(): string {
60
+ return `Choice-${_.now()}-${_.random(0, 9999999)}`;
61
+ }
63
62
  }
64
63
 
65
64
  export class LevelRange {
66
- min?: Number;
67
- max?: Number;
65
+ min?: Number;
66
+ max?: Number;
68
67
  }
69
68
 
70
69
  export class EvaluationItemModel {
71
- id: string;
72
- options?: Object;
73
- text: object;
70
+ id: string;
71
+ options?: Object;
72
+ text: object;
74
73
 
75
- constructor(locale: string) {
76
- this.id = EvaluationItemModel.createChoiceId();
77
- this.text = defaultText(locale);
78
- }
74
+ constructor(locale: string) {
75
+ this.id = EvaluationItemModel.createChoiceId();
76
+ this.text = defaultText(locale);
77
+ }
79
78
 
80
- static createChoiceId(): string {
81
- return `Evaluation-Item-${_.now()}-${_.random(0, 9999999)}`;
82
- }
79
+ static createChoiceId(): string {
80
+ return `Evaluation-Item-${_.now()}-${_.random(0, 9999999)}`;
81
+ }
83
82
  }
84
83
 
85
84
  export class StarEvaluationItemModel extends EvaluationItemModel {
86
- level?: Number;
87
- range?: LevelRange;
85
+ level?: Number;
86
+ range?: LevelRange;
88
87
 
89
- constructor(locale: string) {
90
- super(locale);
91
- }
88
+ constructor(locale: string) {
89
+ super(locale);
90
+ }
92
91
  }
93
92
 
94
93
  export class ExprEvaluationItemModel extends EvaluationItemModel {
95
- type: ExprEvaluationItemType;
96
- conditions?: Array<ExprConditionModel>;
94
+ type: ExprEvaluationItemType;
95
+ conditions?: Array<ExprConditionModel>;
97
96
 
98
- constructor(locale: string, type: ExprEvaluationItemType) {
99
- super(locale);
100
- this.type = type;
101
- }
97
+ constructor(locale: string, type: ExprEvaluationItemType) {
98
+ super(locale);
99
+ this.type = type;
100
+ }
102
101
  }
103
102
 
104
103
  export class ExprConditionModel {
105
- type: ExprConditionType;
106
- expr?: string;
107
- desc?: string;
108
- payload?: any;
104
+ type: ExprConditionType;
105
+ expr?: string;
106
+ desc?: string;
107
+ payload?: any;
109
108
 
110
- constructor(type: ExprConditionType) {
111
- this.type = type;
112
- }
109
+ constructor(type: ExprConditionType) {
110
+ this.type = type;
111
+ }
113
112
  }
114
113
 
115
114
  export class QuestionOptionsModel {
116
- required: Boolean;
117
- visible: Boolean;
118
- layout?: SurveyLayout;
119
- wordLimit?: Number;
120
- scoringEnabled?: Boolean;
121
- starEnabled?: Boolean;
122
- starMinCount?: Number;
123
-
124
- constructor(required: Boolean) {
125
- this.required = required;
126
- this.visible = true;
127
- }
115
+ required: Boolean;
116
+ visible: Boolean;
117
+ layout?: SurveyLayout;
118
+ wordLimit?: Number;
119
+ scoringEnabled?: Boolean;
120
+ starEnabled?: Boolean;
121
+ starMinCount?: Number;
122
+
123
+ constructor(required: Boolean) {
124
+ this.required = required;
125
+ this.visible = true;
126
+ }
128
127
  }
129
128
 
130
129
  export class QuestionHeaderModel {
131
- number?: Number | null;
132
- text: Object;
130
+ number?: Number | null;
131
+ text: Object;
133
132
 
134
- constructor(locale: string) {
135
- this.text = defaultText(locale);
136
- this.number = null;
137
- }
133
+ constructor(locale: string) {
134
+ this.text = defaultText(locale);
135
+ this.number = null;
136
+ }
138
137
  }
139
138
 
140
139
  export class SubQuestionModel {
141
- id: string;
142
- number?: Number | null;
143
- text?: Object;
144
-
145
- constructor(locale: string) {
146
- this.id = `SubQ-${_.now()}-${_.random(0, 9999999)}`;
147
- this.text = defaultText(locale);
148
- this.number = null;
149
- }
140
+ id: string;
141
+ number?: Number | null;
142
+ text?: Object;
143
+
144
+ constructor(locale: string) {
145
+ this.id = `SubQ-${_.now()}-${_.random(0, 9999999)}`;
146
+ this.text = defaultText(locale);
147
+ this.number = null;
148
+ }
150
149
  }
151
150
 
152
151
  export class QuestionExprModel {
153
- id: string;
154
- answer: any;
152
+ id: string;
153
+ answer: any;
155
154
 
156
- constructor(id: string, answer: any) {
157
- this.id = id;
158
- this.answer = answer;
159
- }
155
+ constructor(id: string, answer: any) {
156
+ this.id = id;
157
+ this.answer = answer;
158
+ }
160
159
  }
161
160
 
162
161
  export class BaseQuestionModel {
163
- id: string;
164
- type: string;
165
- options: QuestionOptionsModel;
166
- header: QuestionHeaderModel;
167
-
168
- constructor(type: string, locale: string) {
169
- this.id = BaseQuestionModel.createQuestionId();
170
- this.type = type;
171
- this.header = new QuestionHeaderModel(locale);
172
- this.options = new QuestionOptionsModel(false);
173
- }
174
-
175
- static getMaxScore(question): number {
176
- if (question.type == QuestionType.SINGLE_SELECTION) {
177
- return _.max(
178
- _.map(question.choices, (choice) =>
179
- parseFloat(_.get(choice, "options.score", 0) || 0)
180
- )
181
- );
182
- } else if (question.type == QuestionType.MULTI_SELECTION) {
183
- return _.sumBy(question.choices, (item) =>
184
- parseFloat(_.get(item, "options.score") || 0)
185
- );
186
- } else if (question.type == QuestionType.MATRIX) {
187
- let score = _.max(
188
- _.map(question.choices, (choice) =>
189
- parseFloat(_.get(choice, "options.score", 0) || 0)
190
- )
191
- );
192
- return score * question.subQuestions.length;
193
- }
194
- return 0;
195
- }
196
-
197
- static createQuestionId(): string {
198
- return `Q-${_.now()}-${_.random(0, 9999999)}`;
199
- }
200
-
201
- static getNumber(
202
- preNumber: number,
203
- question: BaseQuestionModel
204
- ): null | number {
205
- return preNumber + 1;
206
- }
207
-
208
- static refreshSurvey(survey): void {
209
- this.rebuildQuestionNumber(survey.questions);
210
- survey.statistics.maxScore = this.calculationAllQuestionMaxScore(
211
- survey.questions
212
- );
213
- survey.statistics.questionCount = this.calculationAllQuestionCount(
214
- survey.questions
215
- );
216
- }
217
-
218
- static calculationAllQuestionCount(questions): number {
219
- let count = 0;
220
- let exclude = [QuestionType.TEXT_TITLE];
221
- _.forEach(questions, (question) => {
222
- if (!_.includes(exclude, question.type)) {
223
- count++;
224
- }
225
- });
226
- return count;
227
- }
228
-
229
- static calculationAllQuestionMaxScore(questions): number {
230
- let maxScore = 0;
231
- _.forEach(questions, (question) => {
232
- maxScore += this.getMaxScore(question);
233
- });
234
- return maxScore;
235
- }
236
-
237
- static setActiveQuestion(currentQuestion, questions): void {
238
- _.forEach(questions, (question) => {
239
- if (question.id == currentQuestion.id) {
240
- question.active = true;
241
- } else {
242
- question.active = false;
243
- }
244
- });
245
- }
246
-
247
- static rebuildQuestionNumber(questions): void {
248
- let preNumber = 0;
249
- _.forEach(questions, function (question: BaseQuestionModel) {
250
- let number;
251
- if (question.type === QuestionType.TEXT_TITLE) {
252
- number = QuestionTextTitleModel.getNumber(preNumber, question);
253
- } else if (question.type === QuestionType.MATRIX) {
254
- number = QuestionMatrixModel.getNumber(
255
- preNumber,
256
- question as QuestionMatrixModel
162
+ id: string;
163
+ type: string;
164
+ options: QuestionOptionsModel;
165
+ header: QuestionHeaderModel;
166
+
167
+ constructor(type: string, locale: string) {
168
+ this.id = BaseQuestionModel.createQuestionId();
169
+ this.type = type;
170
+ this.header = new QuestionHeaderModel(locale);
171
+ this.options = new QuestionOptionsModel(false);
172
+ }
173
+
174
+ static getMaxScore(question): number {
175
+ if (question.type == QuestionType.SINGLE_SELECTION) {
176
+ return _.max(
177
+ _.map(question.choices, (choice) =>
178
+ parseFloat(_.get(choice, "options.score", 0) || 0)
179
+ )
180
+ );
181
+ } else if (question.type == QuestionType.MULTI_SELECTION) {
182
+ return _.sumBy(
183
+ question.choices,
184
+ (item) => parseFloat(_.get(item, "options.score") || 0)
185
+ );
186
+ } else if (question.type == QuestionType.MATRIX) {
187
+ let score = _.max(
188
+ _.map(question.choices, (choice) =>
189
+ parseFloat(_.get(choice, "options.score", 0) || 0)
190
+ )
191
+ );
192
+ return score * question.subQuestions.length;
193
+ }
194
+ return 0;
195
+ }
196
+
197
+ static createQuestionId(): string {
198
+ return `Q-${_.now()}-${_.random(0, 9999999)}`;
199
+ }
200
+
201
+ static getNumber(
202
+ preNumber: number,
203
+ question: BaseQuestionModel
204
+ ): null | number {
205
+ return preNumber + 1;
206
+ }
207
+
208
+ static refreshSurvey(survey): void {
209
+ this.rebuildQuestionNumber(survey.questions);
210
+ survey.statistics.maxScore = this.calculationAllQuestionMaxScore(
211
+ survey.questions
212
+ );
213
+ survey.statistics.questionCount = this.calculationAllQuestionCount(
214
+ survey.questions
257
215
  );
258
- } else {
259
- number = BaseQuestionModel.getNumber(preNumber, question);
260
- }
261
- question.header.number = number;
262
- if (number) {
263
- preNumber = number;
264
- }
265
- });
266
- }
216
+ }
217
+
218
+ static calculationAllQuestionCount(questions): number {
219
+ let count = 0;
220
+ let exclude = [QuestionType.TEXT_TITLE];
221
+ _.forEach(questions, (question) => {
222
+ if (!_.includes(exclude, question.type)) {
223
+ count++;
224
+ }
225
+ });
226
+ return count;
227
+ }
228
+
229
+ static calculationAllQuestionMaxScore(questions): number {
230
+ let maxScore = 0;
231
+ _.forEach(questions, (question) => {
232
+ maxScore += this.getMaxScore(question);
233
+ });
234
+ return maxScore;
235
+ }
236
+
237
+ static setActiveQuestion(currentQuestion, questions): void {
238
+ _.forEach(questions, (question) => {
239
+ if (question.id == currentQuestion.id) {
240
+ question.active = true;
241
+ } else {
242
+ question.active = false;
243
+ }
244
+ });
245
+ }
246
+
247
+ static rebuildQuestionNumber(questions): void {
248
+ let preNumber = 0;
249
+ _.forEach(questions, function (question: BaseQuestionModel) {
250
+ let number;
251
+ if (question.type === QuestionType.TEXT_TITLE) {
252
+ number = QuestionTextTitleModel.getNumber(preNumber, question);
253
+ } else if (question.type === QuestionType.MATRIX) {
254
+ number = QuestionMatrixModel.getNumber(
255
+ preNumber,
256
+ question as QuestionMatrixModel
257
+ );
258
+ } else {
259
+ number = BaseQuestionModel.getNumber(preNumber, question);
260
+ }
261
+ question.header.number = number;
262
+ if (number) {
263
+ preNumber = number;
264
+ }
265
+ });
266
+ }
267
267
  }
268
268
 
269
269
  export class QuestionCheckBoxModel extends BaseQuestionModel {
270
- choices: Array<any>;
270
+ choices: Array<any>;
271
271
 
272
- constructor(type: QuestionType, locale: string) {
273
- super(type, locale);
274
- this.choices = QuestionFactory.createSelectionQuestionChoices(locale);
275
- }
272
+ constructor(type: QuestionType, locale: string) {
273
+ super(type, locale);
274
+ this.choices = QuestionFactory.createSelectionQuestionChoices(locale);
275
+ }
276
276
  }
277
277
 
278
278
  export class QuestionEvaluationModel extends BaseQuestionModel {
279
- evaluationItems: Array<EvaluationItemModel>;
279
+ evaluationItems: Array<EvaluationItemModel>;
280
280
 
281
- constructor(type: QuestionType, locale: string) {
282
- super(type, locale);
283
- this.evaluationItems = QuestionFactory.createEvaluationItems(locale);
284
- }
281
+ constructor(type: QuestionType, locale: string) {
282
+ super(type, locale);
283
+ this.evaluationItems = QuestionFactory.createEvaluationItems(locale);
284
+ }
285
285
  }
286
286
 
287
287
  export class QuestionTextTitleModel extends BaseQuestionModel {
288
- constructor(type: QuestionType, locale: string) {
289
- super(type, locale);
290
- }
288
+ constructor(type: QuestionType, locale: string) {
289
+ super(type, locale);
290
+ }
291
291
 
292
- static getNumber(
293
- preNumber: number,
294
- question: BaseQuestionModel
295
- ): null | number {
296
- return null;
297
- }
292
+ static getNumber(
293
+ preNumber: number,
294
+ question: BaseQuestionModel
295
+ ): null | number {
296
+ return null;
297
+ }
298
298
  }
299
299
 
300
300
  export class QuestionFillBlankModel extends BaseQuestionModel {
301
- constructor(type: QuestionType, locale: string) {
302
- super(type, locale);
303
- }
301
+ constructor(type: QuestionType, locale: string) {
302
+ super(type, locale);
303
+ }
304
304
 
305
- static getNumber(
306
- preNumber: number,
307
- question: BaseQuestionModel
308
- ): null | number {
309
- return null;
310
- }
305
+ static getNumber(
306
+ preNumber: number,
307
+ question: BaseQuestionModel
308
+ ): null | number {
309
+ return null;
310
+ }
311
311
  }
312
312
 
313
313
  export class QuestionShortAnswerModel extends BaseQuestionModel {
314
- constructor(type: QuestionType, locale: string) {
315
- super(type, locale);
316
- }
314
+ constructor(type: QuestionType, locale: string) {
315
+ super(type, locale);
316
+ }
317
317
 
318
- getNumber(preNumber: number): null | number {
319
- return null;
320
- }
318
+ getNumber(preNumber: number): null | number {
319
+ return null;
320
+ }
321
321
  }
322
322
 
323
323
  export class QuestionSingleSelectionModel extends QuestionCheckBoxModel {
324
- constructor(type: QuestionType, locale: string) {
325
- super(type, locale);
326
- }
324
+ constructor(type: QuestionType, locale: string) {
325
+ super(type, locale);
326
+ }
327
327
  }
328
328
 
329
329
  export class QuestionMulitSelectionModel extends QuestionCheckBoxModel {
330
- constructor(type: QuestionType, locale: string) {
331
- super(type, locale);
332
- }
330
+ constructor(type: QuestionType, locale: string) {
331
+ super(type, locale);
332
+ }
333
333
  }
334
334
 
335
335
  export class QuestionMatrixModel extends BaseQuestionModel {
336
- choices: Array<any>;
337
- subQuestions: Array<SubQuestionModel>;
338
-
339
- constructor(type: QuestionType, locale: string) {
340
- super(type, locale);
341
- this.choices = QuestionFactory.createMatrixQuestionChoices(locale);
342
- this.subQuestions = [QuestionFactory.createSubQuestion(locale)];
343
- }
344
-
345
- static getNumber(
346
- preNumber: number,
347
- question: QuestionMatrixModel
348
- ): null | number {
349
- let number = preNumber + 1;
350
- _.forEach(question.subQuestions, (sq, index) => {
351
- sq.number = index + 1;
352
- });
353
- return number;
354
- }
336
+ choices: Array<any>;
337
+ subQuestions: Array<SubQuestionModel>;
338
+
339
+ constructor(type: QuestionType, locale: string) {
340
+ super(type, locale);
341
+ this.choices = QuestionFactory.createMatrixQuestionChoices(locale);
342
+ this.subQuestions = [QuestionFactory.createSubQuestion(locale)];
343
+ }
344
+
345
+ static getNumber(
346
+ preNumber: number,
347
+ question: QuestionMatrixModel
348
+ ): null | number {
349
+ let number = preNumber + 1;
350
+ _.forEach(question.subQuestions, (sq, index) => {
351
+ sq.number = index + 1;
352
+ });
353
+ return number;
354
+ }
355
355
  }
356
356
 
357
357
  export interface SurveyOptionsModel {
358
- primaryLanguage: SurveyLocales;
359
- languages: SurveyLocales[];
360
- layout: SurveyLayout;
358
+ primaryLanguage: SurveyLocales;
359
+ languages: SurveyLocales[];
360
+ layout: SurveyLayout;
361
361
  }
362
362
 
363
363
  export interface SurveyStatisticsModel {
364
- maxScore: Number;
365
- questionCount: Number;
364
+ maxScore: Number;
365
+ questionCount: Number;
366
366
  }
367
367
 
368
368
  export interface SurveyModel {
369
- id: string;
370
- name: any;
371
- options: SurveyOptionsModel;
372
- statistics: SurveyStatisticsModel;
373
- questions: BaseQuestionModel[];
369
+ id: string;
370
+ name: any;
371
+ options: SurveyOptionsModel;
372
+ statistics: SurveyStatisticsModel;
373
+ questions: BaseQuestionModel[];
374
374
  }
375
375
 
376
376
  export class ResponseModel {
377
- id?: string;
377
+ id?: string;
378
378
  }
379
379
 
380
380
  export class PlanModel {
381
- id?: string;
381
+ id?: string;
382
382
  }
383
383
 
384
384
  //todo remove
385
- export class PlanStatisticsModel {}
385
+ export class PlanStatisticsModel {
386
+ }
386
387
 
387
388
  //todo remove
388
- export class ResponseStatisticsModel {}
389
+ export class ResponseStatisticsModel {
390
+ }