@glowgreen/gg-questionnaire-v2 0.0.110 → 0.0.112

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.
@@ -731,6 +731,8 @@
731
731
  * @author Will Poulson
732
732
  */
733
733
  FormConstructorService.prototype.generateFormsForQuestionnaire = function (questionnaire, currentQuestionnaire, currentQuestionnaireForm, additionalData, skipFilter) {
734
+ console.log('zero');
735
+ console.log(additionalData);
734
736
  var sections = skipFilter ?
735
737
  questionnaire.sections :
736
738
  this.filterService.filterSections(questionnaire.sections, currentQuestionnaireForm, additionalData);
@@ -738,16 +740,18 @@
738
740
  if (noChange && !skipFilter) {
739
741
  return null;
740
742
  }
741
- var questionnaireForms = this.generateFormsForSections(sections, currentQuestionnaireForm);
743
+ var questionnaireForms = this.generateFormsForSections(sections, currentQuestionnaireForm, additionalData);
742
744
  return { sections: sections, forms: questionnaireForms };
743
745
  };
744
- FormConstructorService.prototype.generateFormsForSections = function (sections, currentQuestionnaireForm) {
746
+ FormConstructorService.prototype.generateFormsForSections = function (sections, currentQuestionnaireForm, additionalData) {
745
747
  var e_1, _a;
748
+ console.log('one');
749
+ console.log(additionalData);
746
750
  var questionnaireForms = this.fb.group({});
747
751
  try {
748
752
  for (var sections_1 = __values(sections), sections_1_1 = sections_1.next(); !sections_1_1.done; sections_1_1 = sections_1.next()) {
749
753
  var section = sections_1_1.value;
750
- var sectionForms = this.generateFormsForSection(section, currentQuestionnaireForm);
754
+ var sectionForms = this.generateFormsForSection(section, currentQuestionnaireForm, additionalData);
751
755
  questionnaireForms.addControl(section.name, sectionForms);
752
756
  }
753
757
  }
@@ -767,8 +771,10 @@
767
771
  * @returns A filtered form group.
768
772
  * @author Will Poulson
769
773
  */
770
- FormConstructorService.prototype.generateFormsForSection = function (section, currentQuestionnaireForm) {
774
+ FormConstructorService.prototype.generateFormsForSection = function (section, currentQuestionnaireForm, additionalData) {
771
775
  var e_2, _a;
776
+ console.log('two');
777
+ console.log(additionalData);
772
778
  var sectionForms = this.fb.group({});
773
779
  try {
774
780
  for (var _b = __values(section.questions), _c = _b.next(); !_c.done; _c = _b.next()) {
@@ -776,7 +782,7 @@
776
782
  if (question.type === exports.QuestionType.Info) {
777
783
  continue;
778
784
  }
779
- var questionControl = this.generateControlForQuestion(question, section, currentQuestionnaireForm);
785
+ var questionControl = this.generateControlForQuestion(question, section, currentQuestionnaireForm, additionalData);
780
786
  sectionForms.addControl(question.name, questionControl);
781
787
  }
782
788
  }
@@ -795,10 +801,44 @@
795
801
  * @returns An abstract control.
796
802
  * @author Will Poulson
797
803
  */
798
- FormConstructorService.prototype.generateControlForQuestion = function (question, section, currentQuestionnaireForm) {
804
+ FormConstructorService.prototype.generateControlForQuestion = function (question, section, currentQuestionnaireForm, additionalData) {
799
805
  var e_3, _a;
800
806
  var convertedValidators = this.convertValidators(question.validators);
801
807
  var defaultValue = question.defaultValue ? question.defaultValue : null;
808
+ console.log('three');
809
+ console.log(additionalData);
810
+ if (defaultValue !== null) {
811
+ defaultValue = this.filterService.getValueForString(defaultValue, currentQuestionnaireForm, additionalData);
812
+ }
813
+ console.log('default');
814
+ console.log(defaultValue);
815
+ var titleRegEx = /(\{\{([^\}]+)\}\})/gi;
816
+ var titlePlaceholdersFound = null;
817
+ console.log('default');
818
+ console.log(question);
819
+ while ((titlePlaceholdersFound = titleRegEx.exec(question.title)) !== null) {
820
+ var titleReplacementValue = this.filterService.getValueForString(titlePlaceholdersFound[2], currentQuestionnaireForm, additionalData);
821
+ console.log('m1');
822
+ var titleReplaceRe = new RegExp('\{\{' + titlePlaceholdersFound[2] + '\}\}', 'g');
823
+ titleReplacementValue = titleReplacementValue.replace(/\w\S*/g, function (txt) {
824
+ return txt.charAt(0).toUpperCase() + txt.substr(1).toLowerCase();
825
+ });
826
+ question.title = question.title.replace(titleReplaceRe, titleReplacementValue);
827
+ }
828
+ var subTitleRegEx = /(\{\{([^\}]+)\}\})/gi;
829
+ var subTitlePlaceholdersFound = null;
830
+ while ((subTitlePlaceholdersFound = subTitleRegEx.exec(question.subtitle)) !== null) {
831
+ var subTitleReplacementValue = this.filterService.getValueForString(subTitlePlaceholdersFound[2], currentQuestionnaireForm, additionalData);
832
+ console.log('m2');
833
+ var subTitleReplaceRe = new RegExp('\{\{' + subTitlePlaceholdersFound[2] + '\}\}', 'g');
834
+ subTitleReplacementValue = subTitleReplacementValue.replace(/\w\S*/g, function (txt) {
835
+ return txt.charAt(0).toUpperCase() + txt.substr(1).toLowerCase();
836
+ });
837
+ question.subtitle = question.subtitle.replace(subTitleReplaceRe, subTitleReplacementValue);
838
+ }
839
+ console.log('final');
840
+ console.log(question);
841
+ console.log('====');
802
842
  switch (question.type) {
803
843
  case exports.QuestionType.Repeater:
804
844
  var newArray = this.fb.array([], convertedValidators);
@@ -1333,34 +1373,21 @@
1333
1373
  if (!data) {
1334
1374
  return null;
1335
1375
  }
1336
- var regexp = /(\{\{([^\}]+)\}\})/gi;
1337
- var placeholdersFound = null;
1338
- while ((placeholdersFound = regexp.exec(data.title)) !== null) {
1339
- var replacementValue = this.filterService.getValueForString(placeholdersFound[2], this.currentQuestionnaireForm, this.additionalData);
1340
- var replace_re = new RegExp('\{\{' + placeholdersFound[2] + '\}\}', 'g');
1341
- replacementValue = replacementValue.replace(/\w\S*/g, function (txt) {
1342
- return txt.charAt(0).toUpperCase() + txt.substr(1).toLowerCase();
1343
- });
1344
- data.title = data.title.replace(replace_re, replacementValue);
1345
- }
1346
- var regexp2 = /(\{\{([^\}]+)\}\})/gi;
1347
- var subTitlePlaceholdersFound = null;
1348
- while ((subTitlePlaceholdersFound = regexp2.exec(data.subtitle)) !== null) {
1349
- var replacementValue2 = this.filterService.getValueForString(subTitlePlaceholdersFound[2], this.currentQuestionnaireForm, this.additionalData);
1350
- var replace_re2 = new RegExp('\{\{' + subTitlePlaceholdersFound[2] + '\}\}', 'g');
1351
- replacementValue2 = replacementValue2.replace(/\w\S*/g, function (txt) {
1352
- return txt.charAt(0).toUpperCase() + txt.substr(1).toLowerCase();
1353
- });
1354
- data.subtitle = data.subtitle.replace(replace_re2, replacementValue2);
1355
- }
1356
1376
  var formControl = this.currentSection.formGroup.get(data.name);
1357
- if (data.defaultValue !== null && data.defaultValue !== '') {
1358
- var oriDefaultValue = data.defaultValue;
1359
- data.defaultValue = this.filterService.getValueForString(data.defaultValue, this.currentQuestionnaireForm, this.additionalData);
1360
- if (oriDefaultValue !== data.defaultValue) {
1377
+ /*
1378
+ if (data.defaultValue !== null && data.defaultValue !== '') {
1379
+ const oriDefaultValue = data.defaultValue;
1380
+ data.defaultValue = this.filterService.getValueForString(
1381
+ data.defaultValue,
1382
+ this.currentQuestionnaireForm,
1383
+ this.additionalData);
1384
+
1385
+ if (oriDefaultValue !== data.defaultValue) {
1361
1386
  formControl.patchValue(data.defaultValue);
1387
+ }
1388
+
1362
1389
  }
1363
- }
1390
+ */
1364
1391
  return {
1365
1392
  data: data,
1366
1393
  formControl: formControl