Skip to content

Commit

Permalink
extract data from the XML to populate the form re #223
Browse files Browse the repository at this point in the history
  • Loading branch information
jstrachan committed Apr 4, 2013
1 parent c30b6ff commit a680799
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 5 deletions.
2 changes: 1 addition & 1 deletion hawtio-web/src/main/webapp/app/camel/js/camel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ module Camel {
}
} else {
// ignore non EIP nodes, though we should add expressions...
var langSettings = _apacheCamelModel.languages[nodeId];
var langSettings = Camel.camelLanguageSettings(nodeId);
if (langSettings && parentNode) {
// lets add the language kind
var name = langSettings["name"] || nodeId;
Expand Down
38 changes: 37 additions & 1 deletion hawtio-web/src/main/webapp/app/camel/js/helpers.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@

module Camel {

/**
Expand Down Expand Up @@ -51,6 +52,34 @@ module Camel {
return uri;
}

export function getRouteNodeJSON(routeXmlNode, answer = {}) {
if (routeXmlNode) {
angular.forEach(routeXmlNode.attributes, (attr) => {
answer[attr.name] = attr.value;
});

// lets look for nested elements and convert those
// explicitly looking for expressions
$(routeXmlNode).children("*").each((idx, element) => {
var nodeName = element.nodeName;
var langSettings = Camel.camelLanguageSettings(nodeName);
if (langSettings) {
// TODO the expression key could be anything really; how should we know?
answer["expression"] = {
language: nodeName,
expression: element.textContent
};
} else {
var nested = getRouteNodeJSON(element);
if (nested) {
answer[nodeName] = nested;
}
}
});
}
return answer;
}

export function getRouteNodeIcon(nodeSettings) {
var imageName = nodeSettings["icon"] || "generic24.png";
return url("/app/camel/img/" + imageName);
Expand All @@ -68,6 +97,13 @@ module Camel {
return Forms.lookupDefinition(nodeId, _apacheCamelModel);
}

/**
* Looks up the Camel language settings for the given language name
*/
export function camelLanguageSettings(nodeName) {
return _apacheCamelModel.languages[nodeName];
}

/**
* Adds the route children to the given folder for each step in the route
*/
Expand Down Expand Up @@ -101,7 +137,7 @@ module Camel {
addRouteChildren(child, n);
} else {
// ignore non EIP nodes, though we should add expressions...
var langSettings = _apacheCamelModel.languages[nodeName];
var langSettings = Camel.camelLanguageSettings(nodeName);
if (langSettings && folder) {
// lets add the language kind
var name = langSettings["name"] || nodeName;
Expand Down
6 changes: 3 additions & 3 deletions hawtio-web/src/main/webapp/app/camel/js/properties.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,15 @@ module Camel {
});

function updateData() {
$scope.nodeData = {};

var routeXmlNode = getSelectedRouteNode(workspace);
$scope.nodeData = getRouteNodeJSON(routeXmlNode);

if (routeXmlNode) {
var nodeName = routeXmlNode.nodeName;
$scope.schema = getCamelSchema(nodeName);

if ($scope.schema) {
// TODO now lets create the data from the XML
console.log("data is: " + JSON.stringify($scope.nodeData, null, " "));
console.log("schema is: " + JSON.stringify($scope.schema, null, " "));

// TODO as a little hack for now lets use the edit form
Expand Down

0 comments on commit a680799

Please sign in to comment.