@wg-npm/survey-creator 0.5.166 → 0.5.167

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.
@@ -303,328 +303,306 @@ function currentLang() {
303
303
  }
304
304
  var locale = { use, t, i18n, currentLang };
305
305
 
306
- class QuestionFactory {
307
- constructor(locale) {
308
- this.creatorHash = {};
309
- this.locale = locale;
310
- this.registerQuestion("FILL_BLANK", (locale) => {
311
- return new BaseQuestionModel("FILL_BLANK", locale);
312
- });
313
- this.registerQuestion("SHORT_ANSWER", (locale) => {
314
- return new BaseQuestionModel("SHORT_ANSWER", locale);
315
- });
316
- this.registerQuestion("MATRIX", (locale) => {
317
- return new QuestionMatrixModel("MATRIX", locale);
318
- });
319
- this.registerQuestion("SCORING", (locale) => {
320
- return new QuestionScoringModel("SCORING", locale);
321
- });
322
- this.registerQuestion("TEXT_TITLE", (locale) => {
323
- return new QuestionTextTitleModel("TEXT_TITLE", locale);
324
- });
325
- this.registerQuestion("SINGLE_SELECTION", (locale) => {
326
- return new QuestionCheckBoxModel("SINGLE_SELECTION", locale);
327
- });
328
- this.registerQuestion("MULTI_SELECTION", (locale) => {
329
- return new QuestionCheckBoxModel("MULTI_SELECTION", locale);
330
- });
331
- this.registerQuestion("EVALUATION", (locale) => {
332
- return new QuestionEvaluationModel("EVALUATION", locale);
333
- });
334
- }
335
- static getInstance(locale) {
336
- if (!QuestionFactory.instance) {
337
- QuestionFactory.instance = new QuestionFactory(locale);
338
- }
339
- return QuestionFactory.instance;
340
- }
341
- static createDefault(locale) {
342
- return new ChoiceModel(locale);
343
- }
344
- static createSubQuestion(locale) {
345
- return new SubQuestionModel(locale);
346
- }
347
- static createEvaluationItem(locale) {
348
- return new StarEvaluationItemModel(locale);
349
- }
350
- static createSelectionQuestionChoices(locale) {
351
- return _.range(4).map(() => this.createDefault(locale));
352
- }
353
- static createMatrixQuestionChoices(locale) {
354
- return _.range(5).map(() => this.createDefault(locale));
355
- }
356
- static createEvaluationItems(locale) {
357
- return _.range(5).map(() => this.createEvaluationItem(locale));
358
- }
359
- registerQuestion(questionType, questionCreator) {
360
- this.creatorHash[questionType] = questionCreator;
361
- }
362
- createQuestion(questionType) {
363
- const creator = this.creatorHash[questionType];
364
- return creator(this.locale);
365
- }
366
- static createExclusiveChoice(locale) {
367
- return new ExclusiveChoiceModel(locale);
368
- }
306
+ class QuestionFactory {
307
+ constructor(locale) {
308
+ this.creatorHash = {};
309
+ this.locale = locale;
310
+ this.registerQuestion("FILL_BLANK", locale => {
311
+ return new BaseQuestionModel("FILL_BLANK", locale);
312
+ });
313
+ this.registerQuestion("SHORT_ANSWER", locale => {
314
+ return new BaseQuestionModel("SHORT_ANSWER", locale);
315
+ });
316
+ this.registerQuestion("MATRIX", locale => {
317
+ return new QuestionMatrixModel("MATRIX", locale);
318
+ });
319
+ this.registerQuestion("SCORING", locale => {
320
+ return new QuestionScoringModel("SCORING", locale);
321
+ });
322
+ this.registerQuestion("TEXT_TITLE", locale => {
323
+ return new QuestionTextTitleModel("TEXT_TITLE", locale);
324
+ });
325
+ this.registerQuestion("SINGLE_SELECTION", locale => {
326
+ return new QuestionCheckBoxModel("SINGLE_SELECTION", locale);
327
+ });
328
+ this.registerQuestion("MULTI_SELECTION", locale => {
329
+ return new QuestionCheckBoxModel("MULTI_SELECTION", locale);
330
+ });
331
+ this.registerQuestion("EVALUATION", locale => {
332
+ return new QuestionEvaluationModel("EVALUATION", locale);
333
+ });
334
+ }
335
+ static getInstance(locale) {
336
+ if (!QuestionFactory.instance) {
337
+ QuestionFactory.instance = new QuestionFactory(locale);
338
+ }
339
+ return QuestionFactory.instance;
340
+ }
341
+ static createDefault(locale) {
342
+ return new ChoiceModel(locale);
343
+ }
344
+ static createSubQuestion(locale) {
345
+ return new SubQuestionModel(locale);
346
+ }
347
+ static createEvaluationItem(locale) {
348
+ return new StarEvaluationItemModel(locale);
349
+ }
350
+ static createSelectionQuestionChoices(locale) {
351
+ return _.range(4).map(() => this.createDefault(locale));
352
+ }
353
+ static createMatrixQuestionChoices(locale) {
354
+ return _.range(5).map(() => this.createDefault(locale));
355
+ }
356
+ static createEvaluationItems(locale) {
357
+ return _.range(5).map(() => this.createEvaluationItem(locale));
358
+ }
359
+ registerQuestion(questionType, questionCreator) {
360
+ this.creatorHash[questionType] = questionCreator;
361
+ }
362
+ createQuestion(questionType) {
363
+ const creator = this.creatorHash[questionType];
364
+ return creator(this.locale);
365
+ }
366
+ static createExclusiveChoice(locale) {
367
+ return new ExclusiveChoiceModel(locale);
368
+ }
369
369
  }
370
-
371
- const defaultText = function getText(locale) {
372
- return _.set({}, locale, "");
373
- };
374
- class ChoiceOptionModel {
375
- constructor() {
376
- this.score = null;
377
- this.star = false;
378
- this.starCount = null;
379
- this.exclusiveEnabled = false;
380
- }
381
- }
382
- class ChoiceModel {
383
- constructor(locale) {
384
- this.id = ChoiceModel.createChoiceId();
385
- this.text = defaultText(locale);
386
- this.options = new ChoiceOptionModel();
387
- }
388
- static createChoiceId() {
389
- return `Choice-${_.now()}-${_.random(0, 9999999)}`;
390
- }
391
- }
392
- class ExclusiveChoiceModel extends ChoiceModel {
393
- constructor(locale) {
394
- super(locale);
395
- if (!_.isEmpty(this.options)) {
396
- _.set(this.options, "exclusiveEnabled", true);
397
- }
398
- }
399
- }
400
- class EvaluationItemModel {
401
- constructor(locale) {
402
- this.id = EvaluationItemModel.createChoiceId();
403
- this.text = defaultText(locale);
404
- }
405
- static createChoiceId() {
406
- return `Evaluation-Item-${_.now()}-${_.random(0, 9999999)}`;
407
- }
408
- }
409
- class StarEvaluationItemModel extends EvaluationItemModel {
410
- constructor(locale) {
411
- super(locale);
412
- }
413
- }
414
- class QuestionOptionsModel {
415
- constructor(required) {
416
- this.inputMinLength = 10;
417
- this.required = required;
418
- this.visible = true;
419
- }
420
- }
421
- class QuestionHeaderModel {
422
- constructor(locale) {
423
- this.text = defaultText(locale);
424
- this.number = null;
425
- }
426
- }
427
- class SubQuestionModel {
428
- constructor(locale) {
429
- this.id = `SubQ-${_.now()}-${_.random(0, 9999999)}`;
430
- this.text = defaultText(locale);
431
- this.number = null;
432
- }
433
- }
434
- class BaseQuestionModel {
435
- constructor(type, locale) {
436
- this.id = BaseQuestionModel.createQuestionId();
437
- this.type = type;
438
- this.header = new QuestionHeaderModel(locale);
439
- this.options = new QuestionOptionsModel(false);
440
- }
441
- static getMaxScore(question) {
442
- if (question.type == "SINGLE_SELECTION") {
443
- return (_.max(_.map(question.choices, (choice) => parseFloat(_.get(choice, "options.score", 0) || 0))) || 0);
444
- }
445
- else if (question.type == "MULTI_SELECTION") {
446
- return _.sumBy(question.choices, (item) => parseFloat(_.get(item, "options.score") || 0));
447
- }
448
- else if (question.type == "MATRIX") {
449
- const score = _.max(_.map(question.choices, (choice) => parseFloat(_.get(choice, "options.score", 0) || 0))) || 0;
450
- return score * question.subQuestions.length;
451
- }
452
- else if (question.type == "SCORING") {
453
- const score = question.options.maxRange;
454
- return (score *
455
- (_.isEmpty(question.subQuestions) ? 1 : question.subQuestions.length));
456
- }
457
- return 0;
458
- }
459
- static getScoreRange(question) {
460
- if (question.type == "SCORING") {
461
- const minRange = question.options.minRange;
462
- const maxRange = question.options.maxRange;
463
- return minRange + " - " + maxRange;
464
- }
465
- return "";
466
- }
467
- static createQuestionId() {
468
- return `Q-${_.now()}-${_.random(0, 9999999)}`;
469
- }
470
- static getNumber(preNumber, question) {
471
- return preNumber + 1;
472
- }
473
- static refreshSurvey(survey) {
474
- this.rebuildQuestionNumber(survey.questions);
475
- this.deleteUnusedProperties(survey.questions);
476
- survey.statistics.maxScore = this.calculationAllQuestionMaxScore(survey.questions);
477
- survey.statistics.questionCount = this.calculationAllQuestionCount(survey.questions);
478
- }
479
- static calculationAllQuestionCount(questions) {
480
- let count = 0;
481
- const exclude = ["TEXT_TITLE"];
482
- _.forEach(questions, (question) => {
483
- if (!_.includes(exclude, question.type)) {
484
- count++;
485
- }
486
- });
487
- return count;
488
- }
489
- static calculationAllQuestionMaxScore(questions) {
490
- let maxScore = 0;
491
- _.forEach(questions, (question) => {
492
- maxScore += this.getMaxScore(question);
493
- });
494
- return maxScore;
495
- }
496
- static setActiveQuestion(currentQuestion, questions) {
497
- _.forEach(questions, (question) => {
498
- if (question.id == currentQuestion.id) {
499
- question.active = true;
500
- }
501
- else {
502
- question.active = false;
503
- }
504
- });
505
- }
506
- static rebuildQuestionNumber(questions) {
507
- let preNumber = 0;
508
- _.forEach(questions, function (question) {
509
- let number;
510
- if (question.type === "TEXT_TITLE") {
511
- number = QuestionTextTitleModel.getNumber(preNumber, question);
512
- }
513
- else if (question.type === "MATRIX") {
514
- number = QuestionMatrixModel.getNumber(preNumber, question);
515
- }
516
- else if (question.type === "SCORING") {
517
- number = QuestionScoringModel.getNumber(preNumber, question);
518
- }
519
- else {
520
- number = BaseQuestionModel.getNumber(preNumber, question);
521
- }
522
- question.header.number = number;
523
- if (number) {
524
- preNumber = number;
525
- }
526
- });
527
- }
528
- static deleteUnusedProperties(questions) {
529
- _.forEach(questions, function (question) {
530
- if (question.type === "SCORING") {
531
- QuestionScoringModel.removeUnusedProperty(question);
532
- }
533
- });
534
- }
535
- }
536
- class QuestionCheckBoxModel extends BaseQuestionModel {
537
- constructor(type, locale) {
538
- super(type, locale);
539
- this.choices = QuestionFactory.createSelectionQuestionChoices(locale);
540
- }
541
- }
542
- class QuestionEvaluationModel extends BaseQuestionModel {
543
- constructor(type, locale) {
544
- super(type, locale);
545
- this.evaluationItems = QuestionFactory.createEvaluationItems(locale);
546
- }
547
- }
548
- class QuestionTextTitleModel extends BaseQuestionModel {
549
- constructor(type, locale) {
550
- super(type, locale);
551
- }
552
- static getNumber(preNumber, question) {
553
- return null;
554
- }
555
- }
556
- class QuestionMatrixModel extends BaseQuestionModel {
557
- constructor(type, locale) {
558
- super(type, locale);
559
- this.choices = QuestionFactory.createMatrixQuestionChoices(locale);
560
- this.subQuestions = [QuestionFactory.createSubQuestion(locale)];
561
- }
562
- static getNumber(preNumber, question) {
563
- const number = preNumber + 1;
564
- _.forEach(question.subQuestions, (sq, index) => {
565
- sq.number = index + 1;
566
- });
567
- return number;
568
- }
569
- }
570
- class QuestionScoringModel extends BaseQuestionModel {
571
- constructor(type, locale) {
572
- super(type, locale);
573
- this.subQuestions = [];
574
- }
575
- static getNumber(preNumber, question) {
576
- const number = preNumber + 1;
577
- _.forEach(question.subQuestions, (sq, index) => {
578
- sq.number = index + 1;
579
- });
580
- return number;
581
- }
582
- static removeUnusedProperty(question) {
583
- const options = question.options;
584
- delete options.sliderValue;
585
- _.forEach(question.subQuestions, (subQuestion) => {
586
- delete subQuestion.sliderValue;
587
- });
588
- }
589
- }
590
-
591
- const ZH_CN = _.camelCase("zh-CN");
592
- const EN_US = _.camelCase("en-US");
593
- const ZH_TW = _.camelCase("zh-TW");
594
- function getValue(obj, locale) {
595
- const value = _.get(obj, _.camelCase(locale), "");
596
- if (!_.isEmpty(value)) {
597
- return value;
598
- }
599
- return _.get(obj, locale, "");
600
- }
601
- function translate(obj, locale, prettyMath = false) {
602
- const value = getValue(obj, locale);
603
- if (!_.isEmpty(value) || !prettyMath) {
604
- return value;
605
- }
606
- return (obj[ZH_CN] ||
607
- obj["zh-CN"] ||
608
- obj[EN_US] ||
609
- obj["en-US"] ||
610
- obj[ZH_TW] ||
611
- obj["zh-TW"]);
370
+ const defaultText = function getText(locale) {
371
+ return _.set({}, locale, "");
372
+ };
373
+ class ChoiceOptionModel {
374
+ constructor() {
375
+ this.score = null;
376
+ this.star = false;
377
+ this.starCount = null;
378
+ this.exclusiveEnabled = false;
379
+ }
612
380
  }
613
-
614
- const CUSTOM_INPUT_REG = /(_{5,})/g;
615
- function formatTitle(question, locale) {
616
- const title = translate(question.header.text, locale, true);
617
- if (!_.get(question, "options.richTextEnabled", false)) {
618
- return [title];
619
- }
620
- const trimmedTitles = title.split(CUSTOM_INPUT_REG);
621
- if (trimmedTitles[0] === "") {
622
- trimmedTitles.splice(0, 1);
623
- }
624
- if (trimmedTitles[trimmedTitles.length - 1] === "") {
625
- trimmedTitles.splice(trimmedTitles.length - 1, 1);
626
- }
627
- return trimmedTitles;
381
+ class ChoiceModel {
382
+ constructor(locale) {
383
+ this.id = ChoiceModel.createChoiceId();
384
+ this.text = defaultText(locale);
385
+ this.options = new ChoiceOptionModel();
386
+ }
387
+ static createChoiceId() {
388
+ return `Choice-${_.now()}-${_.random(0, 9999999)}`;
389
+ }
390
+ }
391
+ class ExclusiveChoiceModel extends ChoiceModel {
392
+ constructor(locale) {
393
+ super(locale);
394
+ if (!_.isEmpty(this.options)) {
395
+ _.set(this.options, "exclusiveEnabled", true);
396
+ }
397
+ }
398
+ }
399
+ class EvaluationItemModel {
400
+ constructor(locale) {
401
+ this.id = EvaluationItemModel.createChoiceId();
402
+ this.text = defaultText(locale);
403
+ }
404
+ static createChoiceId() {
405
+ return `Evaluation-Item-${_.now()}-${_.random(0, 9999999)}`;
406
+ }
407
+ }
408
+ class StarEvaluationItemModel extends EvaluationItemModel {
409
+ constructor(locale) {
410
+ super(locale);
411
+ }
412
+ }
413
+ class QuestionOptionsModel {
414
+ constructor(required) {
415
+ this.inputMinLength = 10;
416
+ this.required = required;
417
+ this.visible = true;
418
+ }
419
+ }
420
+ class QuestionHeaderModel {
421
+ constructor(locale) {
422
+ this.text = defaultText(locale);
423
+ this.number = null;
424
+ }
425
+ }
426
+ class SubQuestionModel {
427
+ constructor(locale) {
428
+ this.id = `SubQ-${_.now()}-${_.random(0, 9999999)}`;
429
+ this.text = defaultText(locale);
430
+ this.number = null;
431
+ }
432
+ }
433
+ class BaseQuestionModel {
434
+ constructor(type, locale) {
435
+ this.id = BaseQuestionModel.createQuestionId();
436
+ this.type = type;
437
+ this.header = new QuestionHeaderModel(locale);
438
+ this.options = new QuestionOptionsModel(false);
439
+ }
440
+ static getMaxScore(question) {
441
+ if (question.type == "SINGLE_SELECTION") {
442
+ return _.max(_.map(question.choices, choice => parseFloat(_.get(choice, "options.score", 0) || 0))) || 0;
443
+ } else if (question.type == "MULTI_SELECTION") {
444
+ return _.sumBy(question.choices, item => parseFloat(_.get(item, "options.score") || 0));
445
+ } else if (question.type == "MATRIX") {
446
+ const score = _.max(_.map(question.choices, choice => parseFloat(_.get(choice, "options.score", 0) || 0))) || 0;
447
+ return score * question.subQuestions.length;
448
+ } else if (question.type == "SCORING") {
449
+ const score = question.options.maxRange;
450
+ return score * (_.isEmpty(question.subQuestions) ? 1 : question.subQuestions.length);
451
+ }
452
+ return 0;
453
+ }
454
+ static getScoreRange(question) {
455
+ if (question.type == "SCORING") {
456
+ const minRange = question.options.minRange;
457
+ const maxRange = question.options.maxRange;
458
+ return minRange + " - " + maxRange;
459
+ }
460
+ return "";
461
+ }
462
+ static createQuestionId() {
463
+ return `Q-${_.now()}-${_.random(0, 9999999)}`;
464
+ }
465
+ static getNumber(preNumber, question) {
466
+ return preNumber + 1;
467
+ }
468
+ static refreshSurvey(survey) {
469
+ this.rebuildQuestionNumber(survey.questions);
470
+ this.deleteUnusedProperties(survey.questions);
471
+ survey.statistics.maxScore = this.calculationAllQuestionMaxScore(survey.questions);
472
+ survey.statistics.questionCount = this.calculationAllQuestionCount(survey.questions);
473
+ }
474
+ static calculationAllQuestionCount(questions) {
475
+ let count = 0;
476
+ const exclude = ["TEXT_TITLE"];
477
+ _.forEach(questions, question => {
478
+ if (!_.includes(exclude, question.type)) {
479
+ count++;
480
+ }
481
+ });
482
+ return count;
483
+ }
484
+ static calculationAllQuestionMaxScore(questions) {
485
+ let maxScore = 0;
486
+ _.forEach(questions, question => {
487
+ maxScore += this.getMaxScore(question);
488
+ });
489
+ return maxScore;
490
+ }
491
+ static setActiveQuestion(currentQuestion, questions) {
492
+ _.forEach(questions, question => {
493
+ if (question.id == currentQuestion.id) {
494
+ question.active = true;
495
+ } else {
496
+ question.active = false;
497
+ }
498
+ });
499
+ }
500
+ static rebuildQuestionNumber(questions) {
501
+ let preNumber = 0;
502
+ _.forEach(questions, function (question) {
503
+ let number;
504
+ if (question.type === "TEXT_TITLE") {
505
+ number = QuestionTextTitleModel.getNumber(preNumber, question);
506
+ } else if (question.type === "MATRIX") {
507
+ number = QuestionMatrixModel.getNumber(preNumber, question);
508
+ } else if (question.type === "SCORING") {
509
+ number = QuestionScoringModel.getNumber(preNumber, question);
510
+ } else {
511
+ number = BaseQuestionModel.getNumber(preNumber, question);
512
+ }
513
+ question.header.number = number;
514
+ if (number) {
515
+ preNumber = number;
516
+ }
517
+ });
518
+ }
519
+ static deleteUnusedProperties(questions) {
520
+ _.forEach(questions, function (question) {
521
+ if (question.type === "SCORING") {
522
+ QuestionScoringModel.removeUnusedProperty(question);
523
+ }
524
+ });
525
+ }
526
+ }
527
+ class QuestionCheckBoxModel extends BaseQuestionModel {
528
+ constructor(type, locale) {
529
+ super(type, locale);
530
+ this.choices = QuestionFactory.createSelectionQuestionChoices(locale);
531
+ }
532
+ }
533
+ class QuestionEvaluationModel extends BaseQuestionModel {
534
+ constructor(type, locale) {
535
+ super(type, locale);
536
+ this.evaluationItems = QuestionFactory.createEvaluationItems(locale);
537
+ }
538
+ }
539
+ class QuestionTextTitleModel extends BaseQuestionModel {
540
+ constructor(type, locale) {
541
+ super(type, locale);
542
+ }
543
+ static getNumber(preNumber, question) {
544
+ return null;
545
+ }
546
+ }
547
+ class QuestionMatrixModel extends BaseQuestionModel {
548
+ constructor(type, locale) {
549
+ super(type, locale);
550
+ this.choices = QuestionFactory.createMatrixQuestionChoices(locale);
551
+ this.subQuestions = [QuestionFactory.createSubQuestion(locale)];
552
+ }
553
+ static getNumber(preNumber, question) {
554
+ const number = preNumber + 1;
555
+ _.forEach(question.subQuestions, (sq, index) => {
556
+ sq.number = index + 1;
557
+ });
558
+ return number;
559
+ }
560
+ }
561
+ class QuestionScoringModel extends BaseQuestionModel {
562
+ constructor(type, locale) {
563
+ super(type, locale);
564
+ this.subQuestions = [];
565
+ }
566
+ static getNumber(preNumber, question) {
567
+ const number = preNumber + 1;
568
+ _.forEach(question.subQuestions, (sq, index) => {
569
+ sq.number = index + 1;
570
+ });
571
+ return number;
572
+ }
573
+ static removeUnusedProperty(question) {
574
+ const options = question.options;
575
+ delete options.sliderValue;
576
+ _.forEach(question.subQuestions, subQuestion => {
577
+ delete subQuestion.sliderValue;
578
+ });
579
+ }
580
+ }
581
+ const ZH_CN = _.camelCase("zh-CN");
582
+ const EN_US = _.camelCase("en-US");
583
+ const ZH_TW = _.camelCase("zh-TW");
584
+ function getValue(obj, locale) {
585
+ const value = _.get(obj, _.camelCase(locale), "");
586
+ if (!_.isEmpty(value)) {
587
+ return value;
588
+ }
589
+ return _.get(obj, locale, "");
590
+ }
591
+ function translate(obj, locale, prettyMath = false) {
592
+ const value = getValue(obj, locale);
593
+ if (!_.isEmpty(value) || !prettyMath) {
594
+ return value;
595
+ }
596
+ return obj[ZH_CN] || obj["zh-CN"] || obj[EN_US] || obj["en-US"] || obj[ZH_TW] || obj["zh-TW"];
597
+ }
598
+ const CUSTOM_INPUT_REG = /(_{5,})/g;
599
+ function formatTitle(question, locale) {
600
+ const title = translate(question.header.text, locale, true);
601
+ if (!_.get(question, "options.richTextEnabled", false)) {
602
+ return [title];
603
+ }
604
+ const trimmedTitles = title.split(CUSTOM_INPUT_REG);
605
+ return trimmedTitles;
628
606
  }
629
607
 
630
608
  var LocaleMixin = Vue.extend({
@@ -2039,96 +2017,113 @@ var __vue_staticRenderFns__$z = [];
2039
2017
 
2040
2018
  var Star$1 = __vue_component__$z;
2041
2019
 
2042
- class ExprEvaluationQuestion {
2043
- constructor(questions, scope) {
2044
- this.questions = questions;
2045
- this.scope = _.sortBy(scope);
2046
- this.questionMap = this.buildQuestionMap();
2047
- }
2048
- calculateNumbers() {
2049
- const checkedQuestions = this.checkedQuestion();
2050
- const checkedNumberElements = new Array();
2051
- this.recurs(checkedQuestions, checkedNumberElements);
2052
- return checkedNumberElements;
2053
- }
2054
- buildQuestionMap() {
2055
- const questionMap = {};
2056
- _.forEach(this.questions, (question) => {
2057
- questionMap[question.id] = question;
2058
- if (question.type == "MATRIX") {
2059
- _.forEach(_.get(question, "subQuestions", []), (subQuestion) => {
2060
- questionMap[subQuestion.id] = subQuestion;
2061
- });
2062
- }
2063
- });
2064
- return questionMap;
2065
- }
2066
- checkedQuestion() {
2067
- const questions = new Array();
2068
- _.forEach(this.questions, (question) => {
2069
- if (_.get(question, "type") == "MATRIX") {
2070
- const markedQuestions = new Array();
2071
- _.forEach(_.get(question, "subQuestions", []), (subQuestion) => {
2072
- if (_.includes(this.scope, subQuestion.id)) {
2073
- const newSubQuestion = _.cloneDeep(subQuestion);
2074
- _.set(newSubQuestion, "type", "MATRIX");
2075
- _.set(newSubQuestion, "parentId", _.get(question, "id"));
2076
- markedQuestions.push(newSubQuestion);
2077
- }
2078
- });
2079
- if (!_.isEmpty(markedQuestions)) {
2080
- questions.push(markedQuestions);
2081
- }
2082
- }
2083
- else if (_.includes(this.scope, question.id)) {
2084
- questions.push(question);
2085
- }
2086
- });
2087
- return questions;
2088
- }
2089
- recurs(elements, numbers) {
2090
- for (let i = 0; i < elements.length; i++) {
2091
- const element = elements[i];
2092
- if (_.isArray(element)) {
2093
- numbers.push(new Array());
2094
- this.recurs(element, numbers[numbers.length - 1]);
2095
- }
2096
- else {
2097
- const temp = new Array();
2098
- temp.push(this.getFullNumber(element));
2099
- if (i == elements.length - 1) {
2100
- numbers.push(temp);
2101
- continue;
2102
- }
2103
- for (let j = i + 1;; j++) {
2104
- if (j == elements.length ||
2105
- !this.isContinuous(elements[j - 1], elements[j])) {
2106
- numbers.push(temp);
2107
- i = j - 1;
2108
- break;
2109
- }
2110
- if (_.size(temp) > 1) {
2111
- temp.pop();
2112
- }
2113
- temp.push(this.getFullNumber(elements[j]));
2114
- }
2115
- }
2116
- }
2117
- }
2118
- isContinuous(front, hind) {
2119
- return (!_.isArray(hind) && this.getNumber(hind) - this.getNumber(front) == 1);
2120
- }
2121
- getFullNumber(question) {
2122
- if (question.type == "MATRIX") {
2123
- return (this.questionMap[question.parentId].header.number +
2124
- "." +
2125
- this.getNumber(question));
2126
- }
2127
- return this.getNumber(question).toString();
2128
- }
2129
- getNumber(question) {
2130
- return question.type == "MATRIX" ? question.number : question.header.number;
2131
- }
2020
+ class ExprEvaluationQuestion {
2021
+ questions;
2022
+ scope;
2023
+ questionMap;
2024
+
2025
+ constructor(questions, scope) {
2026
+ this.questions = questions;
2027
+ this.scope = _.sortBy(scope);
2028
+
2029
+ this.questionMap = this.buildQuestionMap();
2030
+ }
2031
+
2032
+ calculateNumbers() {
2033
+ const checkedQuestions = this.checkedQuestion();
2034
+ const checkedNumberElements = new Array();
2035
+ this.recurs(checkedQuestions, checkedNumberElements);
2036
+
2037
+ return checkedNumberElements;
2038
+ }
2039
+
2040
+ buildQuestionMap() {
2041
+ const questionMap = {};
2042
+ _.forEach(this.questions, (question) => {
2043
+ questionMap[question.id] = question;
2044
+ if (question.type == "MATRIX") {
2045
+ _.forEach(_.get(question, "subQuestions", []), (subQuestion) => {
2046
+ questionMap[subQuestion.id] = subQuestion;
2047
+ });
2048
+ }
2049
+ });
2050
+ return questionMap;
2051
+ }
2052
+
2053
+ checkedQuestion() {
2054
+ const questions = new Array();
2055
+ _.forEach(this.questions, (question) => {
2056
+ if (_.get(question, "type") == "MATRIX") {
2057
+ const markedQuestions = new Array();
2058
+ _.forEach(_.get(question, "subQuestions", []), (subQuestion) => {
2059
+ if (_.includes(this.scope, subQuestion.id)) {
2060
+ const newSubQuestion = _.cloneDeep(subQuestion);
2061
+ _.set(newSubQuestion, "type", "MATRIX");
2062
+ _.set(newSubQuestion, "parentId", _.get(question, "id"));
2063
+ markedQuestions.push(newSubQuestion);
2064
+ }
2065
+ });
2066
+ if (!_.isEmpty(markedQuestions)) {
2067
+ questions.push(markedQuestions);
2068
+ }
2069
+ } else if (_.includes(this.scope, question.id)) {
2070
+ questions.push(question);
2071
+ }
2072
+ });
2073
+ return questions;
2074
+ }
2075
+
2076
+ recurs(elements, numbers) {
2077
+ for (let i = 0; i < elements.length; i++) {
2078
+ const element = elements[i];
2079
+ if (_.isArray(element)) {
2080
+ numbers.push(new Array());
2081
+ this.recurs(element, numbers[numbers.length - 1]);
2082
+ } else {
2083
+ const temp = new Array();
2084
+ temp.push(this.getFullNumber(element));
2085
+ if (i == elements.length - 1) {
2086
+ numbers.push(temp);
2087
+ continue;
2088
+ }
2089
+ for (let j = i + 1; ; j++) {
2090
+ if (
2091
+ j == elements.length ||
2092
+ !this.isContinuous(elements[j - 1], elements[j])
2093
+ ) {
2094
+ numbers.push(temp);
2095
+ i = j - 1;
2096
+ break;
2097
+ }
2098
+ if (_.size(temp) > 1) {
2099
+ temp.pop();
2100
+ }
2101
+ temp.push(this.getFullNumber(elements[j]));
2102
+ }
2103
+ }
2104
+ }
2105
+ }
2106
+
2107
+ isContinuous(front, hind) {
2108
+ return (
2109
+ !_.isArray(hind) && this.getNumber(hind) - this.getNumber(front) == 1
2110
+ );
2111
+ }
2112
+
2113
+ getFullNumber(question) {
2114
+ if (question.type == "MATRIX") {
2115
+ return (
2116
+ this.questionMap[question.parentId].header.number +
2117
+ "." +
2118
+ this.getNumber(question)
2119
+ );
2120
+ }
2121
+ return this.getNumber(question).toString();
2122
+ }
2123
+
2124
+ getNumber(question) {
2125
+ return question.type == "MATRIX" ? question.number : question.header.number;
2126
+ }
2132
2127
  }
2133
2128
 
2134
2129
  const SPLIT_LENGTH = 60;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wg-npm/survey-creator",
3
- "version": "0.5.166",
3
+ "version": "0.5.167",
4
4
  "description": "",
5
5
  "license": "MIT",
6
6
  "scripts": {
@@ -12,8 +12,8 @@
12
12
  "lint-fix": "eslint \"**/*.ts\" \"**/*.vue\" --fix --no-error-on-unmatched-pattern"
13
13
  },
14
14
  "peerDependencies": {
15
- "@wg-npm/survey-core": "0.5.166",
16
- "@wg-npm/survey-service-api": "0.5.166",
15
+ "@wg-npm/survey-core": "0.5.167",
16
+ "@wg-npm/survey-service-api": "0.5.167",
17
17
  "axios": "^0.19.2",
18
18
  "camelcase": "^6.0.0",
19
19
  "deepmerge": "^4.2.2",
@@ -38,8 +38,8 @@
38
38
  "@typescript-eslint/eslint-plugin": "^3.6.0",
39
39
  "@typescript-eslint/parser": "^3.6.0",
40
40
  "@vue/eslint-config-prettier": "^6.0.0",
41
- "@wg-npm/survey-core": "0.5.166",
42
- "@wg-npm/survey-service-api": "0.5.166",
41
+ "@wg-npm/survey-core": "0.5.167",
42
+ "@wg-npm/survey-service-api": "0.5.167",
43
43
  "acorn": "^7.3.1",
44
44
  "axios": "^0.19.2",
45
45
  "babelrc-rollup": "^3.0.0",