Skip to content

Commit

Permalink
[fix] is-relevant-if not showing subquestions
Browse files Browse the repository at this point in the history
  • Loading branch information
blcham committed Aug 31, 2016
1 parent f0d36ae commit 7794d58
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 8 deletions.
2 changes: 1 addition & 1 deletion src/components/Question.js
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ export default class Question extends React.Component {

static _getAnswerClass(isTextarea) {
return isTextarea ? 'col-xs-12' : (
Constants.GENERATED_ROW_SIZE === 1 ? 'col-xs-3' : 'col-xs-' + (Constants.COLUMN_COUNT / Constants.GENERATED_ROW_SIZE));
Constants.GENERATED_ROW_SIZE === 1 ? 'col-xs-5' : 'col-xs-' + (Constants.COLUMN_COUNT / Constants.GENERATED_ROW_SIZE));
}

_renderQuestionHelp() {
Expand Down
27 changes: 20 additions & 7 deletions src/util/FormUtils.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
'use strict';

import JsonLdUtils from "jsonld-utils";
import jsonld from "jsonld";

import Constants from "../constants/Constants";
import Utils from "./Utils";
import JsonObjectMap from "./JsonObjectMap";
import JsonLdObjectUtils from "./JsonLdObjectUtils"

export default class FormUtils {

Expand Down Expand Up @@ -80,6 +82,19 @@ export default class FormUtils {
}
}

static resolveValueObject(answer) {
if (!answer) {
return null;
}
if (answer[Constants.HAS_OBJECT_VALUE]) {
return Utils.asArray(answer[Constants.HAS_OBJECT_VALUE])[0];
}
if (answer[Constants.HAS_DATA_VALUE]) {
return Utils.asArray(answer[Constants.HAS_DATA_VALUE])[0];
}
return null;
}

static isRelevant(question) {

if (!question[Constants.IS_RELEVANT_IF]) {
Expand Down Expand Up @@ -111,17 +126,15 @@ export default class FormUtils {
// concrete values
if (acceptedAnswerValues && testedQuestion) {
var question = JsonObjectMap.getObject(testedQuestion["@id"]);
for (var expValueObj of Utils.asArray(acceptedAnswerValues)) {
var expValue = expValueObj['@id'];
var answer = question[Constants.HAS_ANSWER];
for (var expValue of Utils.asArray(acceptedAnswerValues)) {
var answers = jsonld.getValues(question, Constants.HAS_ANSWER);

if (!answer) {
if (answers.length === 0) {
return false;
}
var qValue = FormUtils.resolveValueObject(answers[0]);

var qValue = FormUtils.resolveValue(answer);

if (qValue === expValue) {
if (JsonLdObjectUtils.compareValues(qValue, expValue)) {
return true;
}
}
Expand Down
24 changes: 24 additions & 0 deletions src/util/JsonLdObjectUtils.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
'use strict';

import jsonld from "jsonld";

export default class JsonLdObjectUtils {

static getFirstObject(subject, predicate) {
var values = jsonld.getValues(subject, predicate);

if (values.length === 0) {
//throw "Subject " + subject[@id] + " does not have any value of property " + predicate;
return null;
}
return values[0];
}

static compareValues(jsonLdValue1, jsonLdValue2) {
jsonLdValue1 = (typeof(jsonLdValue1) === 'object') ? jsonLdValue1 : { '@value': jsonLdValue1};
jsonLdValue2 = (typeof(jsonLdValue2) === 'object') ? jsonLdValue2 : { '@value': jsonLdValue2};

return jsonld.compareValues(jsonLdValue1, jsonLdValue2);
}

}

0 comments on commit 7794d58

Please sign in to comment.