From 1ca107e223a31ff0c9240911c224fea70225a2eb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jes=C3=BAs=20=C3=81ngel?= Date: Wed, 9 Jan 2019 19:06:28 +0100 Subject: [PATCH] Added event for refreshing xml content after it's loaded --- public/controllers/management/groups.js | 2 +- .../wz-xml-file-editor/wz-xml-file-editor.js | 20 ++++++++++++------- 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/public/controllers/management/groups.js b/public/controllers/management/groups.js index 2831949bb..5d3f95eaf 100644 --- a/public/controllers/management/groups.js +++ b/public/controllers/management/groups.js @@ -257,7 +257,7 @@ export function GroupsController( $scope.editingFile = true; try { $scope.fetchedXML = await fetchFile(); - $scope.$broadcast('fetchedFile',{data:$scope.fetchedXML}); + $scope.$broadcast('fetchedFile', { data: $scope.fetchedXML }); } catch (error) { $scope.fetchedXML = null; errorHandler.handle(error, 'Fetch file error'); diff --git a/public/directives/wz-xml-file-editor/wz-xml-file-editor.js b/public/directives/wz-xml-file-editor/wz-xml-file-editor.js index fa0b03fe7..f1daf3781 100644 --- a/public/directives/wz-xml-file-editor/wz-xml-file-editor.js +++ b/public/directives/wz-xml-file-editor/wz-xml-file-editor.js @@ -16,7 +16,7 @@ import { uiModules } from 'ui/modules'; const app = uiModules.get('app/wazuh', []); -app.directive('wzXmlFileEditor', function () { +app.directive('wzXmlFileEditor', function() { return { restrict: 'E', scope: { @@ -31,9 +31,15 @@ app.directive('wzXmlFileEditor', function () { try { const parser = new DOMParser(); // eslint-disable-line const xml = $scope.xmlCodeBox.getValue(); - const xmlDoc = parser.parseFromString('' + xml + '', 'text/xml'); + const xmlDoc = parser.parseFromString( + '' + xml + '', + 'text/xml' + ); $scope.validFn({ - valid: !!xmlDoc.getElementsByTagName('parsererror').length || !xml || !xml.length + valid: + !!xmlDoc.getElementsByTagName('parsererror').length || + !xml || + !xml.length }); } catch (error) { errorHandler.handle(error, 'Error validating XML'); @@ -84,16 +90,16 @@ app.directive('wzXmlFileEditor', function () { } catch (error) { errorHandler.handle(error, 'Fetching original file'); } - } + }; init(); // Refresh content if it's not the very first time we are loading data - $scope.$on('fetchedFile',(ev,params) => { - if(!firstTime) { + $scope.$on('fetchedFile', (ev, params) => { + if (!firstTime) { init(params.data); } - }) + }); $scope.xmlCodeBox.on('change', () => { checkXmlParseError();