Skip to content

Commit

Permalink
Merge pull request #635 from KatrinIhler/MH-13295-json-parse-error-no…
Browse files Browse the repository at this point in the history
…-license

MH-13295 Handle null for presentable value extraction
  • Loading branch information
staubesv committed Jan 9, 2019
2 parents 10ecbdd + 1a22878 commit 3507376
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 40 deletions.
Expand Up @@ -86,29 +86,32 @@ angular.module('adminNg.services')
this.extractPresentableValue = function (field) {
var actualValue = field.value;
var presentableValue = '';
if (field.collection) {
if (angular.isArray(actualValue)) {
angular.forEach(actualValue, function (item, index) {
presentableValue += item;
if ((index + 1) < actualValue.length) {
presentableValue += ', ';
}
});
field.presentableValue = presentableValue;
} else {
if (field.collection.hasOwnProperty(actualValue)) {
presentableValue = field.collection[actualValue];

if (actualValue !== undefined && actualValue !== '' && actualValue !== null) {
if (field.collection) {
if (angular.isArray(actualValue)) {
angular.forEach(actualValue, function (item, index) {
presentableValue += item;
if ((index + 1) < actualValue.length) {
presentableValue += ', ';
}
});
field.presentableValue = presentableValue;
} else {
// this should work in older browsers, albeit looking clumsy
var matchingKey = Object.keys(field.collection)
.filter(function(key) {return field.collection[key] === actualValue;})[0];
presentableValue = field.type === 'ordered_text'
? JSON.parse(matchingKey)['label']
: matchingKey;
if (field.collection.hasOwnProperty(actualValue)) {
presentableValue = field.collection[actualValue];
} else {
// this should work in older browsers, albeit looking clumsy
var matchingKey = Object.keys(field.collection)
.filter(function(key) {return field.collection[key] === actualValue;})[0];
presentableValue = field.type === 'ordered_text'
? JSON.parse(matchingKey)['label']
: matchingKey;
}
}
} else {
presentableValue = actualValue;
}
} else {
presentableValue = actualValue;
}
return presentableValue;
};
Expand Down
Expand Up @@ -81,29 +81,32 @@ angular.module('adminNg.services')
this.extractPresentableValue = function (field) {
var actualValue = field.value;
var presentableValue = '';
if (field.collection) {
if (angular.isArray(actualValue)) {
angular.forEach(actualValue, function (item, index) {
presentableValue += item;
if ((index + 1) < actualValue.length) {
presentableValue += ', ';
}
});
field.presentableValue = presentableValue;
} else {
if (field.collection.hasOwnProperty(actualValue)) {
presentableValue = field.collection[actualValue];

if (actualValue !== undefined && actualValue !== '' && actualValue !== null) {
if (field.collection) {
if (angular.isArray(actualValue)) {
angular.forEach(actualValue, function (item, index) {
presentableValue += item;
if ((index + 1) < actualValue.length) {
presentableValue += ', ';
}
});
field.presentableValue = presentableValue;
} else {
// this should work in older browsers, albeit looking clumsy
var matchingKey = Object.keys(field.collection)
.filter(function(key) {return field.collection[key] === actualValue;})[0];
presentableValue = field.type === 'ordered_text'
? JSON.parse(matchingKey)['label']
: matchingKey;
if (field.collection.hasOwnProperty(actualValue)) {
presentableValue = field.collection[actualValue];
} else {
// this should work in older browsers, albeit looking clumsy
var matchingKey = Object.keys(field.collection)
.filter(function(key) {return field.collection[key] === actualValue;})[0];
presentableValue = field.type === 'ordered_text'
? JSON.parse(matchingKey)['label']
: matchingKey;
}
}
} else {
presentableValue = actualValue;
}
} else {
presentableValue = actualValue;
}
return presentableValue;
};
Expand Down

0 comments on commit 3507376

Please sign in to comment.