@wg-npm/survey-core 0.3.377-8.develop → 0.3.3791
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/dist/survey-core.esm.js +14 -10
- package/package.json +1 -1
- package/src/array-utils.ts +6 -2
- package/src/index.ts +29 -31
- package/src/locale-utils.ts +18 -8
- package/src/models.ts +3 -3
- package/src/quetion-factory.ts +70 -70
package/dist/survey-core.esm.js
CHANGED
|
@@ -54,7 +54,7 @@ class QuestionFactory {
|
|
|
54
54
|
this.creatorHash[questionType] = questionCreator;
|
|
55
55
|
}
|
|
56
56
|
createQuestion(questionType) {
|
|
57
|
-
|
|
57
|
+
const creator = this.creatorHash[questionType];
|
|
58
58
|
return creator(this.locale);
|
|
59
59
|
}
|
|
60
60
|
}
|
|
@@ -135,7 +135,7 @@ class BaseQuestionModel {
|
|
|
135
135
|
return _.sumBy(question.choices, (item) => parseFloat(_.get(item, "options.score") || 0));
|
|
136
136
|
}
|
|
137
137
|
else if (question.type == "MATRIX") {
|
|
138
|
-
|
|
138
|
+
const score = _.max(_.map(question.choices, (choice) => parseFloat(_.get(choice, "options.score", 0) || 0)));
|
|
139
139
|
return score * question.subQuestions.length;
|
|
140
140
|
}
|
|
141
141
|
return 0;
|
|
@@ -153,7 +153,7 @@ class BaseQuestionModel {
|
|
|
153
153
|
}
|
|
154
154
|
static calculationAllQuestionCount(questions) {
|
|
155
155
|
let count = 0;
|
|
156
|
-
|
|
156
|
+
const exclude = ["TEXT_TITLE"];
|
|
157
157
|
_.forEach(questions, (question) => {
|
|
158
158
|
if (!_.includes(exclude, question.type)) {
|
|
159
159
|
count++;
|
|
@@ -251,7 +251,7 @@ class QuestionMatrixModel extends BaseQuestionModel {
|
|
|
251
251
|
this.subQuestions = [QuestionFactory.createSubQuestion(locale)];
|
|
252
252
|
}
|
|
253
253
|
static getNumber(preNumber, question) {
|
|
254
|
-
|
|
254
|
+
const number = preNumber + 1;
|
|
255
255
|
_.forEach(question.subQuestions, (sq, index) => {
|
|
256
256
|
sq.number = index + 1;
|
|
257
257
|
});
|
|
@@ -271,23 +271,27 @@ const ZH_CN = _.camelCase("zh-CN");
|
|
|
271
271
|
const EN_US = _.camelCase("en-US");
|
|
272
272
|
const ZH_TW = _.camelCase("zh-TW");
|
|
273
273
|
function getValue(obj, locale) {
|
|
274
|
-
|
|
274
|
+
const value = _.get(obj, _.camelCase(locale), "");
|
|
275
275
|
if (!_.isEmpty(value)) {
|
|
276
276
|
return value;
|
|
277
277
|
}
|
|
278
|
-
return _.get(obj, locale,
|
|
278
|
+
return _.get(obj, locale, "");
|
|
279
279
|
}
|
|
280
280
|
function translate(obj, locale, prettyMath = false) {
|
|
281
|
-
|
|
281
|
+
const value = getValue(obj, locale);
|
|
282
282
|
if (!_.isEmpty(value) || !prettyMath) {
|
|
283
283
|
return value;
|
|
284
284
|
}
|
|
285
|
-
return obj[ZH_CN] ||
|
|
286
|
-
|
|
285
|
+
return (obj[ZH_CN] ||
|
|
286
|
+
obj["zh-CN"] ||
|
|
287
|
+
obj[EN_US] ||
|
|
288
|
+
obj["en-US"] ||
|
|
289
|
+
obj[ZH_TW] ||
|
|
290
|
+
obj["zh-TW"]);
|
|
287
291
|
}
|
|
288
292
|
|
|
289
293
|
function move(array, fromIndex, toIndex) {
|
|
290
|
-
|
|
294
|
+
const moveValue = array[fromIndex];
|
|
291
295
|
array[fromIndex] = array[toIndex];
|
|
292
296
|
array[toIndex] = moveValue;
|
|
293
297
|
}
|
package/package.json
CHANGED
package/src/array-utils.ts
CHANGED
|
@@ -1,5 +1,9 @@
|
|
|
1
|
-
export function move(
|
|
2
|
-
|
|
1
|
+
export function move(
|
|
2
|
+
array: Array<any>,
|
|
3
|
+
fromIndex: number,
|
|
4
|
+
toIndex: number
|
|
5
|
+
): void {
|
|
6
|
+
const moveValue: any = array[fromIndex];
|
|
3
7
|
array[fromIndex] = array[toIndex];
|
|
4
8
|
array[toIndex] = moveValue;
|
|
5
9
|
}
|
package/src/index.ts
CHANGED
|
@@ -1,35 +1,33 @@
|
|
|
1
1
|
export {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
2
|
+
SurveyLocales,
|
|
3
|
+
SurveyLayout,
|
|
4
|
+
QuestionType,
|
|
5
|
+
ResponseStatisticsModel,
|
|
6
|
+
PlanStatisticsModel,
|
|
7
|
+
QuestionOptionsModel,
|
|
8
|
+
QuestionHeaderModel,
|
|
9
|
+
BaseQuestionModel,
|
|
10
|
+
QuestionCheckBoxModel,
|
|
11
|
+
QuestionTextTitleModel,
|
|
12
|
+
QuestionMatrixModel,
|
|
13
|
+
QuestionFillBlankModel,
|
|
14
|
+
QuestionMulitSelectionModel,
|
|
15
|
+
QuestionShortAnswerModel,
|
|
16
|
+
QuestionSingleSelectionModel,
|
|
17
|
+
QuestionEvaluationModel,
|
|
18
|
+
SubQuestionModel,
|
|
19
|
+
SurveyOptionsModel,
|
|
20
|
+
SurveyModel,
|
|
21
|
+
ChoiceModel,
|
|
22
|
+
ResponseModel,
|
|
23
|
+
PlanModel,
|
|
24
|
+
EvaluationType,
|
|
25
|
+
EvaluationItemModel,
|
|
26
|
+
StarEvaluationItemModel,
|
|
27
|
+
ExprEvaluationItemModel,
|
|
28
|
+
ExprConditionModel,
|
|
29
|
+
ExprConditionType,
|
|
30
30
|
} from "./models";
|
|
31
|
-
export {
|
|
32
|
-
QuestionFactory
|
|
33
|
-
} from "./quetion-factory"
|
|
31
|
+
export { QuestionFactory } from "./quetion-factory";
|
|
34
32
|
export { translate } from "./locale-utils";
|
|
35
33
|
export { move } from "./array-utils";
|
package/src/locale-utils.ts
CHANGED
|
@@ -1,23 +1,33 @@
|
|
|
1
|
-
import _ from
|
|
2
|
-
import { SurveyLocales } from
|
|
1
|
+
import _ from "lodash";
|
|
2
|
+
import { SurveyLocales } from "./models";
|
|
3
3
|
|
|
4
4
|
const ZH_CN: string = _.camelCase(SurveyLocales.ZH_CN);
|
|
5
5
|
const EN_US: string = _.camelCase(SurveyLocales.EN_US);
|
|
6
6
|
const ZH_TW: string = _.camelCase(SurveyLocales.ZH_TW);
|
|
7
7
|
|
|
8
8
|
function getValue(obj: any, locale: string) {
|
|
9
|
-
|
|
9
|
+
const value: any = _.get(obj, _.camelCase(locale), "");
|
|
10
10
|
if (!_.isEmpty(value)) {
|
|
11
11
|
return value;
|
|
12
12
|
}
|
|
13
|
-
return _.get(obj, locale,
|
|
13
|
+
return _.get(obj, locale, "");
|
|
14
14
|
}
|
|
15
15
|
|
|
16
|
-
export function translate(
|
|
17
|
-
|
|
16
|
+
export function translate(
|
|
17
|
+
obj: any,
|
|
18
|
+
locale: string,
|
|
19
|
+
prettyMath: boolean = false
|
|
20
|
+
): any {
|
|
21
|
+
const value: any = getValue(obj, locale);
|
|
18
22
|
if (!_.isEmpty(value) || !prettyMath) {
|
|
19
23
|
return value;
|
|
20
24
|
}
|
|
21
|
-
return
|
|
22
|
-
|
|
25
|
+
return (
|
|
26
|
+
obj[ZH_CN] ||
|
|
27
|
+
obj[SurveyLocales.ZH_CN] ||
|
|
28
|
+
obj[EN_US] ||
|
|
29
|
+
obj[SurveyLocales.EN_US] ||
|
|
30
|
+
obj[ZH_TW] ||
|
|
31
|
+
obj[SurveyLocales.ZH_TW]
|
|
32
|
+
);
|
|
23
33
|
}
|
package/src/models.ts
CHANGED
|
@@ -184,7 +184,7 @@ export class BaseQuestionModel {
|
|
|
184
184
|
parseFloat(_.get(item, "options.score") || 0)
|
|
185
185
|
);
|
|
186
186
|
} else if (question.type == QuestionType.MATRIX) {
|
|
187
|
-
|
|
187
|
+
const score = _.max(
|
|
188
188
|
_.map(question.choices, (choice) =>
|
|
189
189
|
parseFloat(_.get(choice, "options.score", 0) || 0)
|
|
190
190
|
)
|
|
@@ -217,7 +217,7 @@ export class BaseQuestionModel {
|
|
|
217
217
|
|
|
218
218
|
static calculationAllQuestionCount(questions): number {
|
|
219
219
|
let count = 0;
|
|
220
|
-
|
|
220
|
+
const exclude = [QuestionType.TEXT_TITLE];
|
|
221
221
|
_.forEach(questions, (question) => {
|
|
222
222
|
if (!_.includes(exclude, question.type)) {
|
|
223
223
|
count++;
|
|
@@ -346,7 +346,7 @@ export class QuestionMatrixModel extends BaseQuestionModel {
|
|
|
346
346
|
preNumber: number,
|
|
347
347
|
question: QuestionMatrixModel
|
|
348
348
|
): null | number {
|
|
349
|
-
|
|
349
|
+
const number = preNumber + 1;
|
|
350
350
|
_.forEach(question.subQuestions, (sq, index) => {
|
|
351
351
|
sq.number = index + 1;
|
|
352
352
|
});
|
package/src/quetion-factory.ts
CHANGED
|
@@ -1,90 +1,90 @@
|
|
|
1
1
|
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
2
|
+
BaseQuestionModel,
|
|
3
|
+
ChoiceModel,
|
|
4
|
+
QuestionType,
|
|
5
|
+
QuestionMatrixModel,
|
|
6
|
+
QuestionTextTitleModel,
|
|
7
|
+
QuestionCheckBoxModel,
|
|
8
|
+
SubQuestionModel,
|
|
9
|
+
QuestionEvaluationModel,
|
|
10
|
+
StarEvaluationItemModel,
|
|
11
11
|
} from "./models";
|
|
12
12
|
import _ from "lodash";
|
|
13
13
|
|
|
14
14
|
interface HashTable<T> {
|
|
15
|
-
|
|
15
|
+
[key: string]: T;
|
|
16
16
|
}
|
|
17
17
|
|
|
18
18
|
export class QuestionFactory {
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
19
|
+
private creatorHash: HashTable<(locale: string) => BaseQuestionModel> = {};
|
|
20
|
+
private static instance: QuestionFactory;
|
|
21
|
+
private locale: string;
|
|
22
22
|
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
}
|
|
27
|
-
return QuestionFactory.instance;
|
|
23
|
+
public static getInstance(locale: string): QuestionFactory {
|
|
24
|
+
if (!QuestionFactory.instance) {
|
|
25
|
+
QuestionFactory.instance = new QuestionFactory(locale);
|
|
28
26
|
}
|
|
27
|
+
return QuestionFactory.instance;
|
|
28
|
+
}
|
|
29
29
|
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
30
|
+
private constructor(locale: string) {
|
|
31
|
+
this.locale = locale;
|
|
32
|
+
this.registerQuestion(QuestionType.FILL_BLANK, (locale: string) => {
|
|
33
|
+
return new BaseQuestionModel(QuestionType.FILL_BLANK, locale);
|
|
34
|
+
});
|
|
35
|
+
this.registerQuestion(QuestionType.SHORT_ANSWER, (locale: string) => {
|
|
36
|
+
return new BaseQuestionModel(QuestionType.SHORT_ANSWER, locale);
|
|
37
|
+
});
|
|
38
|
+
this.registerQuestion(QuestionType.MATRIX, (locale: string) => {
|
|
39
|
+
return new QuestionMatrixModel(QuestionType.MATRIX, locale);
|
|
40
|
+
});
|
|
41
|
+
this.registerQuestion(QuestionType.TEXT_TITLE, (locale: string) => {
|
|
42
|
+
return new QuestionTextTitleModel(QuestionType.TEXT_TITLE, locale);
|
|
43
|
+
});
|
|
44
|
+
this.registerQuestion(QuestionType.SINGLE_SELECTION, (locale: string) => {
|
|
45
|
+
return new QuestionCheckBoxModel(QuestionType.SINGLE_SELECTION, locale);
|
|
46
|
+
});
|
|
47
|
+
this.registerQuestion(QuestionType.MULTI_SELECTION, (locale: string) => {
|
|
48
|
+
return new QuestionCheckBoxModel(QuestionType.MULTI_SELECTION, locale);
|
|
49
|
+
});
|
|
50
|
+
this.registerQuestion(QuestionType.EVALUATION, (locale: string) => {
|
|
51
|
+
return new QuestionEvaluationModel(QuestionType.EVALUATION, locale);
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
54
|
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
55
|
+
public static createDefault(locale: string): ChoiceModel {
|
|
56
|
+
return new ChoiceModel(locale);
|
|
57
|
+
}
|
|
58
58
|
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
59
|
+
public static createSubQuestion(locale: string): SubQuestionModel {
|
|
60
|
+
return new SubQuestionModel(locale);
|
|
61
|
+
}
|
|
62
62
|
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
63
|
+
public static createEvaluationItem(locale: string): ChoiceModel {
|
|
64
|
+
return new StarEvaluationItemModel(locale);
|
|
65
|
+
}
|
|
66
66
|
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
67
|
+
public static createSelectionQuestionChoices(locale: string) {
|
|
68
|
+
return _.range(4).map(() => this.createDefault(locale));
|
|
69
|
+
}
|
|
70
70
|
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
71
|
+
public static createMatrixQuestionChoices(locale: string) {
|
|
72
|
+
return _.range(5).map(() => this.createDefault(locale));
|
|
73
|
+
}
|
|
74
74
|
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
75
|
+
public static createEvaluationItems(locale: string) {
|
|
76
|
+
return _.range(5).map(() => this.createEvaluationItem(locale));
|
|
77
|
+
}
|
|
78
78
|
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
79
|
+
public registerQuestion(
|
|
80
|
+
questionType: string,
|
|
81
|
+
questionCreator: (locale: string) => BaseQuestionModel
|
|
82
|
+
) {
|
|
83
|
+
this.creatorHash[questionType] = questionCreator;
|
|
84
|
+
}
|
|
85
85
|
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
86
|
+
public createQuestion(questionType: string): BaseQuestionModel {
|
|
87
|
+
const creator = this.creatorHash[questionType];
|
|
88
|
+
return creator(this.locale);
|
|
89
|
+
}
|
|
90
90
|
}
|