Skip to content

Commit

Permalink
Reorganize TreeView component initialization on explorer listnavs
Browse files Browse the repository at this point in the history
  • Loading branch information
skateman committed Sep 6, 2017
1 parent fc2ca27 commit b8cfd2e
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 20 deletions.
41 changes: 23 additions & 18 deletions app/assets/javascripts/controllers/tree_view_controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,28 +6,33 @@
var vm = this;
vm.$http = $http;
vm.selectedNodes = {};
};
vm.data = {};

TreeViewController.prototype.initSelected = function(tree, node) {
this.selectedNodes[tree] = this.selectedNodes[tree] || { key: node };
};
vm.initSelected = function(tree, node) {
vm.selectedNodes[tree] = vm.selectedNodes[tree] || { key: node };
};

TreeViewController.prototype.lazyLoad = function(node, name, url) {
var vm = this;
return new Promise(function(resolve) {
vm.$http.post(url, {
id: node.key,
tree: name,
mode: 'all',
}).then(function(response) {
resolve(response.data);
vm.initData = function(tree, data, selected) {
vm.data[tree] = vm.data[tree] || data;
vm.selectedNodes[tree] = vm.selectedNodes[tree] || { key: selected };
};

vm.lazyLoad = function(node, name, url) {
return new Promise(function(resolve) {
vm.$http.post(url, {
id: node.key,
tree: name,
mode: 'all',
}).then(function(response) {
resolve(response.data);
});
});
});
};
};

TreeViewController.prototype.nodeSelect = function(node, path) {
var url = path + '?id=' + encodeURIComponent(node.key.split('__')[0]);
miqJqueryRequest(url, {beforeSend: true});
vm.nodeSelect = function(node, path) {
var url = path + '?id=' + encodeURIComponent(node.key.split('__')[0]);
miqJqueryRequest(url, {beforeSend: true});
};
};

TreeViewController.$inject = ['$http'];
Expand Down
4 changes: 2 additions & 2 deletions app/views/layouts/listnav/_explorer.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
-# Set the first tree to be rendered if there is a mismatch with the name/type
- tree = @trees.find(-> { @trees.first }) { |t| t.type == accord[:name].to_sym }
%miq-tree-view{:name => tree.name,
:data => tree.locals_for_render[:bs_tree],
:data => "vm.data['#{tree.name}']",
:reselect => tree.locals_for_render[:allow_reselect],
"ng-init" => "vm.initSelected('#{tree.name}', '#{tree.locals_for_render[:select_node]}')",
"ng-init" => "vm.initData('#{tree.name}', '#{tree.locals_for_render[:bs_tree]}', '#{tree.locals_for_render[:select_node]}')",
'on-select' => "vm.nodeSelect(node, '/#{request.parameters[:controller]}/tree_select')",
'selected' => "vm.selectedNodes['#{tree.name}']",
'lazy-load' => "(vm.lazyLoad(node, '#{tree.name}', '/#{request.parameters[:controller]}/tree_autoload'))"}
Expand Down

0 comments on commit b8cfd2e

Please sign in to comment.