From 2e9faaa7d3470ed33aa50171ea4fe3cc18b83474 Mon Sep 17 00:00:00 2001 From: JuanCarlos Date: Wed, 16 Jan 2019 16:53:31 +0100 Subject: [PATCH] Some fixes and replacing watchers by events --- .../wz-config-viewer/wz-config-viewer.js | 38 +++++++++---------- public/utils/config-handler.js | 2 + 2 files changed, 19 insertions(+), 21 deletions(-) diff --git a/public/directives/wz-config-viewer/wz-config-viewer.js b/public/directives/wz-config-viewer/wz-config-viewer.js index 2d7e52de4..0da5d0171 100644 --- a/public/directives/wz-config-viewer/wz-config-viewer.js +++ b/public/directives/wz-config-viewer/wz-config-viewer.js @@ -23,46 +23,42 @@ app.directive('wzConfigViewer', function () { scope: { getjson: '&', getxml: '&', - jsoncontent: '=jsoncontent', - xmlcontent: '=xmlcontent' + jsoncontent: '=', + xmlcontent: '=' }, controller($scope, $document) { - this.replace = true; - $scope.callgetjson = () => { $scope.getjson(); - $scope.refreshJsonBox(); }; $scope.callgetxml = () => { $scope.getxml(); - $scope.refreshXmlBox(); }; - - $scope.$watch('jsoncontent', function() { - $scope.refreshJsonBox(); - }); - $scope.$watch('xmlcontent', function() { - $scope.refreshXmlBox(); + $scope.$on('JSONContentReady', (ev, params) => { + $scope.refreshJsonBox(params.data); }); + $scope.$on('XMLContentReady', (ev, params) => { + $scope.refreshXmlBox(params.data); + }); - - $scope.refreshJsonCodeBox = () => { - if($scope.jsoncontent != false){ + $scope.refreshJsonBox = (json) => { + $scope.jsoncontent = json; + if ($scope.jsoncontent != false) { $scope.jsonCodeBox.setValue($scope.jsoncontent); - setTimeout(function() { + setTimeout(function () { $scope.jsonCodeBox.refresh(); - },1); + }, 1); } }; - $scope.refreshXmlCodeBox = () => { - if($scope.xmlcontent != false){ + $scope.refreshXmlBox = (xml) => { + $scope.xmlcontent = xml; + if ($scope.xmlcontent != false) { $scope.xmlCodeBox.setValue($scope.xmlcontent); - setTimeout(function() { + setTimeout(function () { $scope.xmlCodeBox.refresh(); - },1); + }, 1); } }; diff --git a/public/utils/config-handler.js b/public/utils/config-handler.js index 434a90a23..3a697216b 100644 --- a/public/utils/config-handler.js +++ b/public/utils/config-handler.js @@ -210,6 +210,7 @@ export class ConfigurationHandler { $scope.XMLContent = XMLBeautifier( js2xmlparser.parse('configuration', cleaned) ); + $scope.$broadcast('XMLContentReady', { data: $scope.XMLContent }); } catch (error) { $scope.XMLContent = false; } @@ -231,6 +232,7 @@ export class ConfigurationHandler { try { const cleaned = objectWithoutProperties(config); $scope.JSONContent = JSON.stringify(cleaned, null, 2); + $scope.$broadcast('JSONContentReady', { data: $scope.JSONContent }); } catch (error) { $scope.JSONContent = false; }