Some fixes and replacing watchers by events

This commit is contained in:
JuanCarlos 2019-01-16 16:53:31 +01:00
parent 0da0498f03
commit 2e9faaa7d3
2 changed files with 19 additions and 21 deletions

View File

@ -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);
}
};

View File

@ -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;
}