[Ovirt-devel] [PATCH server] JS Tree testing files.
Jason Guiditta
jguiditt at redhat.com
Wed Nov 19 21:28:36 UTC 2008
This patch:
* Adds the standard_tree (actual widget vs nav) test harness
* Cleans up the tree.rhtml to account for some previous restructuring
* Moves sample json data into a 'test' subfolder.
I am looking into some more proper javascript testing systems, so this
will undoubtedly be changing again in the near future.
Signed-off-by: Jason Guiditta <jguiditt at redhat.com>
---
.../views/layouts/components/standard_tree.rhtml | 105 ++++++++++++++
src/app/views/layouts/components/tree.rhtml | 11 +-
src/public/javascripts/smart_nav_test_data.js | 151 --------------------
.../javascripts/test/smart_nav_sample_data.js | 151 ++++++++++++++++++++
.../javascripts/test/storage_tree_sample_data.js | 58 ++++++++
5 files changed, 320 insertions(+), 156 deletions(-)
create mode 100644 src/app/views/layouts/components/standard_tree.rhtml
delete mode 100644 src/public/javascripts/smart_nav_test_data.js
create mode 100644 src/public/javascripts/test/smart_nav_sample_data.js
create mode 100644 src/public/javascripts/test/storage_tree_sample_data.js
diff --git a/src/app/views/layouts/components/standard_tree.rhtml b/src/app/views/layouts/components/standard_tree.rhtml
new file mode 100644
index 0000000..d4390c3
--- /dev/null
+++ b/src/app/views/layouts/components/standard_tree.rhtml
@@ -0,0 +1,105 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+
+<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
+
+<head>
+ <meta http-equiv="content-type" content="text/html;charset=UTF-8" />
+ <title><%= yield :title -%></title>
+ <%= stylesheet_link_tag 'ovirt-tree/tree' %>
+
+ <%= javascript_include_tag "jquery-1.2.6.min.js" -%>
+ <%= javascript_include_tag "jquery.ui-1.5.2/ui/packed/ui.core.packed.js" -%>
+ <%= javascript_include_tag "test/storage_tree_sample_data.js" -%>
+ <%= javascript_include_tag "test/smart_nav_sample_data.js" -%>
+ <%= javascript_include_tag "jquery.form.js" -%>
+ <%= javascript_include_tag "trimpath-template-1.0.38.js" %>
+ <%= javascript_include_tag "ovirt.tree.js" %>
+ <script type="text/javascript">
+ $(document).ready(function(){
+ //initialize tree widget
+ $('#nav_tree').tree({
+ content: {"pools" : pools3.pools},
+ clickHandler: myClickHandler
+ });
+ $('#some_tree').tree({
+ content: {"pools" : pools3.pools}
+ });
+ $('#storage_tree').tree({
+ content: {"pools" : storage_pools.pools },
+ template : 'storage_tree_template'
+ });
+ });
+
+ function myClickHandler(e, elem) {
+ $(elem)
+ .toggleClass('current');
+ }
+ </script>
+ </head>
+
+ <body>
+
+ <form id="nav_tree_form">
+ <ul id="nav_tree" class="ovirt-tree"></ul>
+ </form>
+ <br/><br/><br/><br/>
+ <form id="some_tree_form">
+ <ul id="some_tree" class="ovirt-tree"></ul>
+ </form>
+ <textarea id="tree_template" style="display:none;">
+ {macro htmlList(list, optionalListType)}
+ {var listType = optionalListType != null ? optionalListType : "ul"}
+ <${listType} style="display:none;">
+ {for item in list}
+ <li>
+ <input type="checkbox" name="item[]" value="${item.id}-${item.name}" style="display:none" checked="checked"/>
+ <span class="hitarea {if item.children} expandable{/if}"> </span><div id="${item.id}" class="${item.type}">${item.name}</div>
+ {if item.children}
+ ${htmlList(item.children)}
+ {/if}
+ </li>
+ {/for}
+ </${listType}>
+ {/macro}
+
+ {for item in pools}
+ <li>
+ <input type="checkbox" name="item[]" value="${item.id}-${item.name}" style="display:none" checked="checked"/>
+ <span class="hitarea {if item.children} expandable{/if}"> </span><div id="${item.id}" class="${item.type}">${item.name}</div>
+ {if item.children}
+ ${htmlList(item.children)}
+ {/if}
+ </li>
+ {/for}
+ </textarea>
+
+ <form>
+ <ul id="storage_tree" class="ovirt-tree"></ul>
+ </form>
+ <textarea id="storage_tree_template" style="display:none;">
+ {macro htmlList(list, isFullList)}
+ {if isFullList}
+ <ul style="display:none;">
+ {/if}
+ {for item in list}
+ <li>
+ <span class="hitarea {if item.children.length > 0} expandable{/if}"> </span>
+ <div id="move-${item.id}" class="{if !item.available} unclickable{/if}">
+ <input type="checkbox" name="vm[storage_volume_ids][]" value="${item.id}"
+ {if !item.available}disabled="disabled" style="display:none"{/if}
+ {if item.selected}checked="checked"{/if}/> ${item.name} {if item.size}(${item.size} GB){/if}
+ </div>
+ {if item.children.length > 0}
+ ${htmlList(item.children, true)}
+ {/if}
+ </li>
+ {/for}
+ {if isFullList}
+ </ul>
+ {/if}
+ {/macro}
+ ${htmlList(pools)}
+ </textarea>
+ </body>
+</html>
diff --git a/src/app/views/layouts/components/tree.rhtml b/src/app/views/layouts/components/tree.rhtml
index 063a6df..402c6e3 100644
--- a/src/app/views/layouts/components/tree.rhtml
+++ b/src/app/views/layouts/components/tree.rhtml
@@ -6,10 +6,15 @@
<head>
<meta http-equiv="content-type" content="text/html;charset=UTF-8" />
<title><%= yield :title -%></title>
+ <%= stylesheet_link_tag 'ovirt-tree/tree' %>
+
<%= javascript_include_tag "jquery-1.2.6.min.js" -%>
<%= javascript_include_tag "jquery.livequery.min.js" -%>
- <%= javascript_include_tag "smart_nav_test_data.js" -%>
+ <%= javascript_include_tag "jquery.ui-1.5.2/ui/packed/ui.core.packed.js" -%>
+ <%= javascript_include_tag "test/smart_nav_sample_data.js" -%>
<%= javascript_include_tag "jquery.form.js" -%>
+ <%= javascript_include_tag "trimpath-template-1.0.38.js" %>
+ <%= javascript_include_tag "ovirt.tree.js" %>
<%= javascript_include_tag "ovirt.js" -%>
<script type="text/javascript">
@@ -43,12 +48,8 @@
<body>
<div id="side">
- <button id="stop">Stop!</button>
<%= render :partial => '/layouts/tree' %>
</div>
- <div id="side-toolbar" class="header_menu_wrapper">
- <%= render :partial => '/layouts/side_toolbar' %>
- </div>
<div id="tabs-and-content-container">
<div id="main">
diff --git a/src/public/javascripts/smart_nav_test_data.js b/src/public/javascripts/smart_nav_test_data.js
deleted file mode 100644
index 43e7dbc..0000000
--- a/src/public/javascripts/smart_nav_test_data.js
+++ /dev/null
@@ -1,151 +0,0 @@
-var pools3 = {
- "deleted" : {},
- "pools" :[
- { "name": "default",
- "text": "default",
- "children":
- [{ "name": "Engineering",
- "text": "Engineering",
- "children":
- [{ "name": "Development",
- "text": "Development",
- "children":
- [{ "name": "Project X",
- "text": "Project X",
- "id": 19,
- "type": "VmResourcePool"},
- { "name": "Project Y",
- "text": "Project Y",
- "id": 20,
- "type": "VmResourcePool"}],
- "id": 9,
- "type": "HardwarePool"},
- { "name": "QA",
- "text": "QA",
- "children":
- [{ "name": "Bob's Team",
- "text": "Bob's Team",
- "children":
- [{ "name": "Bob's VMs",
- "text": "Bob's VMs",
- "id": 21,
- "type": "VmResourcePool"}],
- "id": 17,
- "type": "HardwarePool"},
- { "name": "Jim's Team",
- "text": "Jim's Team",
- "children":
- [{ "name": "Jim's VMs",
- "text": "Jim's VMs",
- "id": 22,
- "type": "VmResourcePool"}],
- "id": 18,
- "type": "HardwarePool"},
- { "name": "Sally's Team",
- "text": "Sally's Team",
- "children":
- [{ "name": "Sally's VMs",
- "text": "Sally's VMs",
- "id": 33,
- "type": "VmResourcePool"}],
- "id": 32,
- "type": "HardwarePool"}],
- "id": 10,
- "type": "HardwarePool"},
- { "name": "Stage",
- "text": "Stage",
- "children":
- [{ "name": "stage1",
- "text": "stage1",
- "id": 45,
- "type": "HardwarePool"},
- { "name": "stage2",
- "text": "stage2",
- "id": 46,
- "type": "HardwarePool"}],
- "id": 44,
- "type": "HardwarePool"}],
- "id": 5,
- "type": "HardwarePool"},
- { "name": "Finance",
- "text": "Finance",
- "children":
- [{ "name": "Payroll",
- "text": "Payroll",
- "children":
- [{ "name": "Payroll VMs",
- "text": "Payroll VMs",
- "id": 23,
- "type": "VmResourcePool"}],
- "id": 11,
- "type": "HardwarePool"},
- { "name": "Accts. Receivable",
- "text": "Accts. Receivable",
- "children":
- [{ "name": "our VMs",
- "text": "our VMs",
- "id": 24,
- "type": "VmResourcePool"}],
- "id": 12,
- "type": "HardwarePool"}],
- "id": 6,
- "type": "HardwarePool"},
- { "name": "HR",
- "text": "HR",
- "children":
- [{ "name": "Hiring Team",
- "text": "Hiring Team",
- "id": 13,
- "type": "HardwarePool"},
- { "name": "Benefits",
- "text": "Benefits",
- "id": 14,
- "type": "HardwarePool"}],
- "id": 7,
- "type": "HardwarePool"},
- { "name": "External (DMZ)",
- "text": "External (DMZ)",
- "children":
- [{ "name": "VMs",
- "text": "VMs",
- "id": 25,
- "type": "VmResourcePool"},
- { "name": "DB Cluster",
- "text": "DB Cluster",
- "children":
- [{ "name": "VMs",
- "text": "VMs",
- "id": 27,
- "type": "VmResourcePool"}],
- "id": 26,
- "type": "HardwarePool"}],
- "id": 8,
- "type": "HardwarePool"}],
- "id": 1,
- "type": "HardwarePool"}],
-"smart_pools":[{ "name": "ovirtadmin",
- "text": "ovirtadmin",
- "children":
- [{ "name": "not so smart",
- "text": "not so smart",
- "id": 39,
- "type": "SmartPool"},
- { "name": "a little smarter",
- "text": "a little smarter",
- "id": 40,
- "type": "SmartPool"},
- { "name": "arrrrr",
- "text": "arrrrr",
- "id": 41,
- "type": "SmartPool"},
- { "name": "huh?",
- "text": "huh?",
- "id": 42,
- "type": "SmartPool"},
- { "name": "booya",
- "text": "booya",
- "id": 43,
- "type": "SmartPool"}],
- "id": 37,
- "type": "DirectoryPool"}]
-}
\ No newline at end of file
diff --git a/src/public/javascripts/test/smart_nav_sample_data.js b/src/public/javascripts/test/smart_nav_sample_data.js
new file mode 100644
index 0000000..43e7dbc
--- /dev/null
+++ b/src/public/javascripts/test/smart_nav_sample_data.js
@@ -0,0 +1,151 @@
+var pools3 = {
+ "deleted" : {},
+ "pools" :[
+ { "name": "default",
+ "text": "default",
+ "children":
+ [{ "name": "Engineering",
+ "text": "Engineering",
+ "children":
+ [{ "name": "Development",
+ "text": "Development",
+ "children":
+ [{ "name": "Project X",
+ "text": "Project X",
+ "id": 19,
+ "type": "VmResourcePool"},
+ { "name": "Project Y",
+ "text": "Project Y",
+ "id": 20,
+ "type": "VmResourcePool"}],
+ "id": 9,
+ "type": "HardwarePool"},
+ { "name": "QA",
+ "text": "QA",
+ "children":
+ [{ "name": "Bob's Team",
+ "text": "Bob's Team",
+ "children":
+ [{ "name": "Bob's VMs",
+ "text": "Bob's VMs",
+ "id": 21,
+ "type": "VmResourcePool"}],
+ "id": 17,
+ "type": "HardwarePool"},
+ { "name": "Jim's Team",
+ "text": "Jim's Team",
+ "children":
+ [{ "name": "Jim's VMs",
+ "text": "Jim's VMs",
+ "id": 22,
+ "type": "VmResourcePool"}],
+ "id": 18,
+ "type": "HardwarePool"},
+ { "name": "Sally's Team",
+ "text": "Sally's Team",
+ "children":
+ [{ "name": "Sally's VMs",
+ "text": "Sally's VMs",
+ "id": 33,
+ "type": "VmResourcePool"}],
+ "id": 32,
+ "type": "HardwarePool"}],
+ "id": 10,
+ "type": "HardwarePool"},
+ { "name": "Stage",
+ "text": "Stage",
+ "children":
+ [{ "name": "stage1",
+ "text": "stage1",
+ "id": 45,
+ "type": "HardwarePool"},
+ { "name": "stage2",
+ "text": "stage2",
+ "id": 46,
+ "type": "HardwarePool"}],
+ "id": 44,
+ "type": "HardwarePool"}],
+ "id": 5,
+ "type": "HardwarePool"},
+ { "name": "Finance",
+ "text": "Finance",
+ "children":
+ [{ "name": "Payroll",
+ "text": "Payroll",
+ "children":
+ [{ "name": "Payroll VMs",
+ "text": "Payroll VMs",
+ "id": 23,
+ "type": "VmResourcePool"}],
+ "id": 11,
+ "type": "HardwarePool"},
+ { "name": "Accts. Receivable",
+ "text": "Accts. Receivable",
+ "children":
+ [{ "name": "our VMs",
+ "text": "our VMs",
+ "id": 24,
+ "type": "VmResourcePool"}],
+ "id": 12,
+ "type": "HardwarePool"}],
+ "id": 6,
+ "type": "HardwarePool"},
+ { "name": "HR",
+ "text": "HR",
+ "children":
+ [{ "name": "Hiring Team",
+ "text": "Hiring Team",
+ "id": 13,
+ "type": "HardwarePool"},
+ { "name": "Benefits",
+ "text": "Benefits",
+ "id": 14,
+ "type": "HardwarePool"}],
+ "id": 7,
+ "type": "HardwarePool"},
+ { "name": "External (DMZ)",
+ "text": "External (DMZ)",
+ "children":
+ [{ "name": "VMs",
+ "text": "VMs",
+ "id": 25,
+ "type": "VmResourcePool"},
+ { "name": "DB Cluster",
+ "text": "DB Cluster",
+ "children":
+ [{ "name": "VMs",
+ "text": "VMs",
+ "id": 27,
+ "type": "VmResourcePool"}],
+ "id": 26,
+ "type": "HardwarePool"}],
+ "id": 8,
+ "type": "HardwarePool"}],
+ "id": 1,
+ "type": "HardwarePool"}],
+"smart_pools":[{ "name": "ovirtadmin",
+ "text": "ovirtadmin",
+ "children":
+ [{ "name": "not so smart",
+ "text": "not so smart",
+ "id": 39,
+ "type": "SmartPool"},
+ { "name": "a little smarter",
+ "text": "a little smarter",
+ "id": 40,
+ "type": "SmartPool"},
+ { "name": "arrrrr",
+ "text": "arrrrr",
+ "id": 41,
+ "type": "SmartPool"},
+ { "name": "huh?",
+ "text": "huh?",
+ "id": 42,
+ "type": "SmartPool"},
+ { "name": "booya",
+ "text": "booya",
+ "id": 43,
+ "type": "SmartPool"}],
+ "id": 37,
+ "type": "DirectoryPool"}]
+}
\ No newline at end of file
diff --git a/src/public/javascripts/test/storage_tree_sample_data.js b/src/public/javascripts/test/storage_tree_sample_data.js
new file mode 100644
index 0000000..44850e5
--- /dev/null
+++ b/src/public/javascripts/test/storage_tree_sample_data.js
@@ -0,0 +1,58 @@
+var storage_pools = {"pools":
+[
+ {
+ "selected":false,
+ "name":"iSCSI: 192.168.50.2:ovirtpriv:storage",
+ "available":false,
+ "children":
+ [
+ {
+ "selected":false,
+ "name":"iSCSI: 192.168.50.2:ovirtpriv:storage:lun-2",
+ "available":true,
+ "children":[],
+ "create_volume":true,
+ "text":"iSCSI: 192.168.50.2:ovirtpriv:storage:lun-2",
+ "id":5,
+ "type":"IscsiStorageVolume"
+ },
+
+ {
+ "selected":false,
+ "name":"iSCSI: 192.168.50.2:ovirtpriv:storage:lun-3",
+ "available":true,
+ "children":[],
+ "create_volume":true,
+ "text":"iSCSI: 192.168.50.2:ovirtpriv:storage:lun-3",
+ "id":4,
+ "type":"IscsiStorageVolume"
+ }
+ ],
+ "create_volume":false,
+ "text":"iSCSI: 192.168.50.2:ovirtpriv:storage",
+ "id":2,
+ "type":"IscsiStoragePool"
+ },
+
+ {
+ "selected":false,
+ "name":"iSCSI: 192.68.60.2:/fred",
+ "available":false,
+ "children":[],
+ "create_volume":false,
+ "text":"iSCSI: 192.68.60.2:/fred",
+ "id":4,
+ "type":"IscsiStoragePool"
+ },
+
+ {
+ "selected":false,
+ "name":"iSCSI: 192.168.60.4:/mo",
+ "available":false,
+ "children":[],
+ "create_volume":false,
+ "text":"iSCSI: 192.168.60.4:/mo",
+ "id":6,
+ "type":"IscsiStoragePool"
+ }
+]}
\ No newline at end of file
--
1.5.6.5
More information about the ovirt-devel
mailing list