diff --git a/ui/src/app/common/utils.service.js b/ui/src/app/common/utils.service.js index 97a04bbcf2..d5e4852afd 100644 --- a/ui/src/app/common/utils.service.js +++ b/ui/src/app/common/utils.service.js @@ -150,7 +150,8 @@ function Utils($mdColorPalette, $rootScope, $window, $translate, $q, $timeout, t customTranslation: customTranslation, objToBase64: objToBase64, base64toObj: base64toObj, - loadImageAspect: loadImageAspect + loadImageAspect: loadImageAspect, + sortObjectKeys: sortObjectKeys } return service; @@ -605,4 +606,14 @@ function Utils($mdColorPalette, $rootScope, $window, $translate, $q, $timeout, t return deferred.promise; } + function sortObjectKeys(obj) { + var sortedObj = {}; + var keys = Object.keys(obj).sort(); + for (var i = 0; i < keys.length; i++) { + var key = keys[i]; + sortedObj[key] = obj[key]; + } + return sortedObj; + } + } diff --git a/ui/src/app/event/event-row.directive.js b/ui/src/app/event/event-row.directive.js index eec8a1aff6..ffd5cc4adf 100644 --- a/ui/src/app/event/event-row.directive.js +++ b/ui/src/app/event/event-row.directive.js @@ -25,7 +25,7 @@ import eventRowDebugRuleNodeTemplate from './event-row-debug-rulenode.tpl.html'; /* eslint-enable import/no-unresolved, import/default */ /*@ngInject*/ -export default function EventRowDirective($compile, $templateCache, $mdDialog, $document, types) { +export default function EventRowDirective($compile, $templateCache, $mdDialog, $document, types, utils) { var linker = function (scope, element, attrs) { @@ -71,11 +71,18 @@ export default function EventRowDirective($compile, $templateCache, $mdDialog, $ if (!contentType) { contentType = null; } + var sortedContent; + try { + sortedContent = angular.toJson(utils.sortObjectKeys(angular.fromJson(content))); + } + catch(err) { + sortedContent = content; + } $mdDialog.show({ controller: 'EventContentDialogController', controllerAs: 'vm', templateUrl: eventErrorDialogTemplate, - locals: {content: content, title: title, contentType: contentType, showingCallback: onShowingCallback}, + locals: {content: sortedContent, title: title, contentType: contentType, showingCallback: onShowingCallback}, parent: angular.element($document[0].body), fullscreen: true, targetEvent: $event, diff --git a/ui/src/app/rulechain/script/node-script-test.service.js b/ui/src/app/rulechain/script/node-script-test.service.js index ee6eea8378..ae1f0b0568 100644 --- a/ui/src/app/rulechain/script/node-script-test.service.js +++ b/ui/src/app/rulechain/script/node-script-test.service.js @@ -20,7 +20,7 @@ import nodeScriptTestTemplate from './node-script-test.tpl.html'; /* eslint-enable import/no-unresolved, import/default */ /*@ngInject*/ -export default function NodeScriptTest($q, $mdDialog, $document, ruleChainService) { +export default function NodeScriptTest($q, $mdDialog, $document, ruleChainService, utils) { var service = { testNodeScript: testNodeScript @@ -89,6 +89,8 @@ export default function NodeScriptTest($q, $mdDialog, $document, ruleChainServic deviceName: "Test Device", ts: new Date().getTime() + "" }; + } else { + metadata = utils.sortObjectKeys(metadata); } if (!msgType) { msgType = "POST_TELEMETRY_REQUEST";