- // TODO: render nothing if answers is empty
- let domTree = (this.questions || [ ]).map( (q,i) => {
- let questionContent = [ ];
- questionContent.push(
- h(
- "div",
- {
- "class": {
- wording: true,
- },
- domProps: {
- innerHTML: q.wording,
- },
- }
- )
- );
- let optionsOrder = _.range(q.options.length);
- if (!q.fixed)
- optionsOrder = _.shuffle(optionsOrder);
- let optionList = [ ];
- optionsOrder.forEach( idx => {
- let option = [ ];
- option.push(
+ // Prepare questions groups, ordered
+ let questions = this.questions || [ ]
+ let questionGroups = _.groupBy(questions, q => {
+ const dotPos = q.index.indexOf(".");
+ return dotPos === -1 ? q.index : q.index.substring(0,dotPos);
+ });
+ let domTree = Object.keys(questionGroups).map( idx => {
+ let qg = questionGroups[idx];
+ const i = parseInt(idx);
+ // Re-order questions 1.1.1 then 1.1.2 then...
+ const orderedQg = qg.sort( (a,b) => {
+ let aParts = a.split('.').map(Number);
+ let bParts = b.split('.').map(Number);
+ const La = aParts.length, Lb = bParts.length;
+ for (let i=0; i<Math.min(La,Lb); i++)
+ {
+ if (aParts[i] != bParts[i])
+ return aParts[i] - bParts[i];
+ }
+ return La - Lb; //the longer should appear after
+ });
+ let qgDom = orderedQg.map( q => {
+ let questionContent = [ ];
+ questionContent.push(