Skip to content

Commit

Permalink
#786: Quartz plugin. Work in progress.
Browse files Browse the repository at this point in the history
  • Loading branch information
davsclaus committed Dec 24, 2013
1 parent 5f9f8cb commit 34cbcb7
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 90 deletions.
64 changes: 13 additions & 51 deletions hawtio-web/src/main/webapp/app/camel/js/tree.ts
Expand Up @@ -123,62 +123,24 @@ module Camel {
}

function updateSelectionFromURL() {
camelUpdateTreeSelectionFromURL($location, $("#cameltree"), true);
}
}

// TODO: Jmx.updateTreeSelectionFromURL should likely support to auto expand and select a node in the tree
// based on a function or an option if there is only 1 element in the tree
export function camelUpdateTreeSelectionFromURL($location, treeElement, activateIfNoneSelected = false) {
var dtree = treeElement.dynatree("getTree");
if (dtree) {
var node = null;
var key = $location.search()['nid'];
if (key) {
try {
node = dtree.activateKey(key);
} catch (e) {
// tree not visible we suspect!
}
}
if (node) {
node.expand(true);
} else {
if (!treeElement.dynatree("getActiveNode")) {
// lets expand the first node
var root = treeElement.dynatree("getRoot");
var children = root ? root.getChildren() : null;
Jmx.updateTreeSelectionFromURLAndAutoSelect($location, $("#cameltree"), (first) => {
// use function to auto select first Camel context routes if there is only one Camel context
var contexts = first.getChildren();
if (contexts && contexts.length === 1) {
first = contexts[0];
first.expand(true);
var children = first.getChildren();
if (children && children.length) {
// if only 1 camel context then auto select it, and expand its routes (if it has any routes)
if (children.length === 1) {
var first = children[0];
first.expand(true);
var contexts = first.getChildren();
if (contexts && contexts.length === 1) {
first = contexts[0];
first.expand(true);
children = first.getChildren();
if (children && children.length) {
var routes = children[0];
if (routes.data.typeName === 'routes') {
first = routes;
first.expand(true);
}
}
}
if (activateIfNoneSelected) {
first.activate();
}
} else {
var first = children[0];
var routes = children[0];
if (routes.data.typeName === 'routes') {
first = routes;
first.expand(true);
if (activateIfNoneSelected) {
first.activate();
}
return first;
}
}
}
}
return null;
}, true);
}
}

Expand Down
17 changes: 17 additions & 0 deletions hawtio-web/src/main/webapp/app/jmx/js/jmxHelpers.ts
Expand Up @@ -86,6 +86,10 @@ module Jmx {


export function updateTreeSelectionFromURL($location, treeElement, activateIfNoneSelected = false) {
updateTreeSelectionFromURLAndAutoSelect($location, treeElement, null, activateIfNoneSelected);
}

export function updateTreeSelectionFromURLAndAutoSelect($location, treeElement, autoSelect, activateIfNoneSelected = false) {
var dtree = treeElement.dynatree("getTree");
if (dtree) {
var node = null;
Expand All @@ -105,6 +109,19 @@ module Jmx {
var root = treeElement.dynatree("getRoot");
var children = root ? root.getChildren() : null;
if (children && children.length) {
var first = children[0];
first.expand(true);
// invoke any auto select function, and use its result as new first, if any returned
if (autoSelect) {
var result = autoSelect(first);
if (result) {
first = result;
}
}
if (activateIfNoneSelected) {
first.activate();
}
} else {
var first = children[0];
first.expand(true);
if (activateIfNoneSelected) {
Expand Down
47 changes: 8 additions & 39 deletions hawtio-web/src/main/webapp/app/quartz/js/quartz.ts
Expand Up @@ -177,47 +177,16 @@ module Quartz {
}
}

// TODO: Jmx.updateTreeSelectionFromURL should likely support to auto expand and select a node in the tree
// based on a function or an option if there is only 1 element in the tree
function updateSelectionFromURL() {
quartzUpdateTreeSelectionFromURL($location, $("#quartztree"), true)
}

function quartzUpdateTreeSelectionFromURL($location, treeElement, activateIfNoneSelected = false) {
var dtree = treeElement.dynatree("getTree");
if (dtree) {
var node = null;
var key = $location.search()['nid'];
if (key) {
try {
node = dtree.activateKey(key);
} catch (e) {
// tree not visible we suspect!
Jmx.updateTreeSelectionFromURLAndAutoSelect($location, $("#quartztree"), (first) => {
// use function to auto select first scheduler if there is only one scheduler
var schedulers = first.getChildren();
if (schedulers && schedulers.length === 1) {
first = schedulers[0];
first.expand(true);
return first;
}
}
if (node) {
node.expand(true);
} else {
if (!treeElement.dynatree("getActiveNode")) {
// lets expand the first node
var root = treeElement.dynatree("getRoot");
var children = root ? root.getChildren() : null;
if (children && children.length) {
// if only 1 quartz scheduler then auto select it, and expand its routes (if it has any routes)
var first = children[0];
first.expand(true);
var schedulers = first.getChildren();
if (schedulers && schedulers.length === 1) {
first = schedulers[0];
first.expand(true);
}
if (activateIfNoneSelected) {
first.activate();
}
}
}
}
}
}, true);
}

function selectionChanged(data) {
Expand Down

0 comments on commit 34cbcb7

Please sign in to comment.