Permalink
Browse files

Fixes contextmenu settings

  • Loading branch information...
1 parent 00db8f9 commit 2b6c76ef9903e0821e53fd99220e681174cea2d3 @kawasima committed Aug 21, 2012
@@ -83,78 +83,8 @@ def destroy
end
def get_list
- sql = <<-'END_OF_SQL'
-SELECT T.*, LENGTH(T.path) - LENGTH(REPLACE(T.path,'.','')) AS level, E.expected_date, E.status, users.firstname, users.lastname
-FROM (
- SELECT distinct parent.*, tpc.test_plan_id
- FROM impasse_nodes AS parent
- JOIN impasse_nodes AS child
- ON parent.path = SUBSTR(child.path, 1, LENGTH(parent.path))
- LEFT JOIN impasse_test_cases AS tc
- ON child.id = tc.id
- LEFT JOIN impasse_test_plan_cases AS tpc
- ON tc.id=tpc.test_case_id
- LEFT JOIN impasse_executions AS exec
- ON tpc.id = exec.test_plan_case_id
- WHERE tpc.test_plan_id=:test_plan_id
-<%- if conditions.include? :path -%>
- AND parent.path LIKE :path
-<%- end -%>
-<%- if [:user_id, :execution_status, :expected_date].any? {|key| conditions.include? key} -%>
- <%- if conditions.include? :user_id -%>
- AND tester_id = :user_id
- <%- end -%>
- <%- if conditions.include? :execution_status -%>
- AND (exec.status IN (:execution_status) <%- if conditions[:execution_status].include? "0" %>OR exec.status IS NULL<% end %> )
- <%- end -%>
- <%- if conditions.include? :expected_date -%>
- AND exec.expected_date <%= conditions[:expected_date_op] %> :expected_date
- <%- end -%>
-<%- end -%>
-) AS T
-LEFT JOIN impasse_test_plan_cases
- ON T.id = impasse_test_plan_cases.test_case_id
- AND T.test_plan_id = impasse_test_plan_cases.test_plan_id
-LEFT JOIN impasse_executions AS E
- ON E.test_plan_case_id = impasse_test_plan_cases.id
-LEFT OUTER JOIN users
- ON users.id = tester_id
-ORDER BY level, T.node_order
-END_OF_SQL
-
- conditions = { :test_plan_id => params[:test_plan_id] }
-
- if params.include? :id and params[:id] != "-1" # TODO
- node = Impasse::Node.find(params[:id])
- conditions[:path] = "#{node.path}_%"
- end
-
- if params[:myself]
- conditions[:user_id] = User.current.id
- end
-
- if params.include? :execution_status
- conditions[:execution_status] = []
- if params[:execution_status].is_a? Array
- params[:execution_status].each {|param|
- conditions[:execution_status] << param.to_s
- }
- else
- conditions[:execution_status] << params[:execution_status].to_s
- end
- end
-
- if params.include? :expected_date
- conditions[:expected_date] = params[:expected_date]
- conditions[:expected_date_op] = params[:expected_date_op] || '='
- end
- @nodes = Impasse::Node.find_by_sql([ERB.new(sql, nil, '-').result(binding), conditions])
- if @nodes.size > 0 and @nodes[0].node_type_id == 1
- test_plan = Impasse::TestPlan.find(params[:test_plan_id])
- @nodes[0].name = test_plan.name
- end
-
- jstree_nodes = convert(@nodes, params[:prefix])
+ nodes = Impasse::Node.find_planned(params[:id], params[:test_plan_id], params[:filters] || {})
+ jstree_nodes = convert(nodes, params[:prefix])
respond_to do |format|
format.json { render :json => jstree_nodes }
@@ -203,8 +133,8 @@ def convert(nodes, prefix='node')
'data' => {},
'children'=>[]}
jstree_node['data']['title'] = node.name
- if node.node_type_id != 3
- jstree_node['state'] = 'open'
+ if node.node_type_id == 2
+ jstree_node['state'] = 'closed'
end
assign_text = []
if node.firstname or node.lastname
@@ -225,6 +155,7 @@ def convert(nodes, prefix='node')
if node_map.include? node.parent_id
# non-root node
node_map[node.parent_id]['children'] << jstree_node
+ node_map[node.parent_id]['state'] = 'open'
else
#root node
jstree_nodes << jstree_node
@@ -81,21 +81,23 @@ def add_test_case
if params.include? :test_case_ids
new_cases = 0
nodes = Impasse::Node.find(:all, :conditions => ["id in (?)", params[:test_case_ids]])
- for node in nodes
- test_case_ids = []
- if node.is_test_suite?
- test_case_ids.concat node.all_decendant_cases.collect{|n| n.id}
- else
- test_case_ids << node.id
- end
-
- for test_case_id in test_case_ids
- test_plan_case =
- Impasse::TestPlanCase.find_or_create_by_test_case_id_and_test_plan_id(
- :test_case_id => test_case_id,
- :test_plan_id => params[:test_plan_id],
- :node_order => 0)
- new_cases += 1
+ ActiveRecord::Base.transaction do
+ for node in nodes
+ test_case_ids = []
+ if node.is_test_suite?
+ test_case_ids.concat node.all_decendant_cases.collect{|n| n.id}
+ else
+ test_case_ids << node.id
+ end
+
+ for test_case_id in test_case_ids
+ test_plan_case =
+ Impasse::TestPlanCase.find_or_create_by_test_case_id_and_test_plan_id(
+ :test_case_id => test_case_id,
+ :test_plan_id => params[:test_plan_id],
+ :node_order => 0)
+ new_cases += 1
+ end
end
end
end
View
@@ -124,6 +124,93 @@ def self.find_children(node_id, test_plan_id=nil, filters=nil, limit=300)
find_by_sql([ERB.new(sql, nil, '-').result(binding), conditions])
end
+ def self.find_planned(node_id, test_plan_id=nil, filters={}, limit=300)
+ sql = <<-'END_OF_SQL'
+ SELECT T.*, LENGTH(T.path) - LENGTH(REPLACE(T.path,'.','')) AS level, E.expected_date, E.status, users.firstname, users.lastname
+ FROM (
+ SELECT distinct parent.*, tpc.test_plan_id
+ FROM impasse_nodes AS parent
+ JOIN impasse_nodes AS child
+ ON parent.path = SUBSTR(child.path, 1, LENGTH(parent.path))
+ LEFT JOIN impasse_test_cases AS tc
+ ON child.id = tc.id
+ LEFT JOIN impasse_test_plan_cases AS tpc
+ ON tc.id=tpc.test_case_id
+ LEFT JOIN impasse_executions AS exec
+ ON tpc.id = exec.test_plan_case_id
+ WHERE tpc.test_plan_id=:test_plan_id
+ <%- if conditions.include? :level -%>
+ AND LENGTH(parent.path) - LENGTH(REPLACE(parent.path,'.','')) <= :level
+ <%- end -%>
+ <%- if conditions.include? :path -%>
+ AND parent.path LIKE :path
+ <%- end -%>
+ <%- if [:user_id, :execution_status, :expected_date].any? {|key| conditions.include? key} -%>
+ <%- if conditions.include? :user_id -%>
+ AND tester_id = :user_id
+ <%- end -%>
+ <%- if conditions.include? :execution_status -%>
+ AND (exec.status IN (:execution_status) <%- if conditions[:execution_status].include? "0" %>OR exec.status IS NULL<% end %> )
+ <%- end -%>
+ <%- if conditions.include? :expected_date -%>
+ AND exec.expected_date <%= conditions[:expected_date_op] %> :expected_date
+ <%- end -%>
+ <%- end -%>
+ ) AS T
+LEFT JOIN impasse_test_plan_cases
+ ON T.id = impasse_test_plan_cases.test_case_id AND
+ T.test_plan_id = impasse_test_plan_cases.test_plan_id
+LEFT JOIN impasse_executions AS E
+ ON E.test_plan_case_id = impasse_test_plan_cases.id
+LEFT OUTER JOIN users
+ ON users.id = tester_id
+ORDER BY level, T.node_order
+ END_OF_SQL
+
+ conditions = { :test_plan_id => test_plan_id }
+
+ unless node_id.to_i == -1
+ node = self.find(node_id)
+ child_counts = self.count(:conditions => [ "path like ?", "#{node.path}_%"])
+ if child_counts > limit
+ conditions[:level] = node.path.count('.') + 1
+ end
+ conditions[:path] = "#{node.path}_%"
+ else
+ child_counts = Impasse::TestPlanCase.count(:conditions => [ "test_plan_id=?", test_plan_id])
+ if child_counts > limit
+ conditions[:level] = 3
+ end
+ end
+
+ if filters[:myself]
+ conditions[:user_id] = User.current.id
+ end
+
+ if filters[:execution_status]
+ conditions[:execution_status] = []
+ if filters[:execution_status].is_a? Array
+ filters[:execution_status].each {|param|
+ conditions[:execution_status] << param.to_s
+ }
+ else
+ conditions[:execution_status] << filters[:execution_status].to_s
+ end
+ end
+
+ if filters[:expected_date]
+ conditions[:expected_date] = filters[:expected_date]
+ conditions[:expected_date_op] = filters[:expected_date_op] || '='
+ end
+
+ nodes = self.find_by_sql([ERB.new(sql, nil, '-').result(binding), conditions])
+ if nodes.size > 0 and nodes[0].node_type_id == 1
+ test_plan = Impasse::TestPlan.find(test_plan_id)
+ nodes[0].name = test_plan.name
+ end
+ nodes
+ end
+
def all_decendant_cases
sql = <<-'END_OF_SQL'
SELECT distinct parent.*
@@ -34,7 +34,7 @@ def self.summary_default(test_plan_id, test_suite_id=nil)
ON tc.id = n.id
<%- if conditions[:path] -%>
INNER JOIN impasse_nodes AS head
- ON head.path = SUBSTR(n.path, 1, LENGTH(:path) + LENGTH(CAST(head.id AS CHAR)) + 1)
+ ON head.path = SUBSTR(n.path, 1, LENGTH(:path || head.id || '.'))
<%- end -%>
LEFT OUTER JOIN impasse_executions AS exe
ON exe.test_plan_case_id = tpc.id
@@ -51,7 +51,7 @@ def self.summary_default(test_plan_id, test_suite_id=nil)
WHERE tp.id = :test_plan_id
<%- if conditions[:path] -%>
AND n.path LIKE :path_starts_with
- GROUP BY head.id, head.name, head.node_type_id, SUBSTR(n.path, 1, LENGTH(:path) + LENGTH(CAST(head.id AS CHAR)) + 1)
+ GROUP BY head.id, head.name, head.node_type_id, SUBSTR(n.path, 1, LENGTH(:path || head.id || '.'))
<%- else -%>
GROUP BY tp.id, tp.name, node_type_id
<%- end -%>
@@ -15,14 +15,10 @@ def self.delete_cascade!(test_plan_id, test_case_id)
DELETE FROM impasse_test_plan_cases
WHERE test_plan_id=#{test_plan_id}
AND test_case_id in (
- SELECT distinct parent.id
- FROM impasse_nodes AS parent
- JOIN impasse_nodes AS child
- ON parent.path = SUBSTR(child.path, 1, LENGTH(parent.path))
- LEFT JOIN impasse_test_cases AS tc
- ON child.id = tc.id
- WHERE parent.path LIKE '#{node.path}%'
- AND parent.node_type_id=3
+ SELECT id
+ FROM impasse_nodes
+ WHERE path LIKE '#{node.path}%'
+ AND node_type_id=3
)
END_OF_SQL
@@ -44,14 +44,14 @@ jQuery(document).ready(function ($) {
id : n.attr ? n.attr("id").replace("exec_","") : -1
};
if ($("#filters #cb_myself").is(":checked")) {
- params["myself"] = true;
+ params["filters[myself]"] = true;
}
- params["execution_status"] = $("#filters :checkbox[name=execution_status]:checked").map(function() {
+ params["filters[execution_status]"] = $("#filters :checkbox[name=execution_status]:checked").map(function() {
return $(this).val();
}).get();
$.each(["expected_date", "expected_date_op"], function(i, key) {
var val = $("#filters :input[name=" + key + "]").val();
- if (val) params[key] = val;
+ if (val) params["filters[" + key + "]"] = val;
});
return params;
},
@@ -2,12 +2,10 @@ jQuery.noConflict();
jQuery(document).ready(function ($) {
var PLAN_CASE_MENU = {
- contextmenu: {
- remove: {
- label: IMPASSE.label.buttonDelete,
- icon: IMPASSE.url.iconDelete,
- action: function(node) { this.remove(node) }
- }
+ remove: {
+ label: IMPASSE.label.buttonDelete,
+ icon: IMPASSE.url.iconDelete,
+ action: function(node) { this.remove(node) }
}
};
@@ -95,8 +93,6 @@ jQuery(document).ready(function ($) {
$("li[rel=test_case],li[rel=test_suite]", this).data("jstree", PLAN_CASE_MENU);
$("li[rel=test_project]", this).data("jstree", {contextmenu:{}});
})
- .bind("contextmenu.jstree", function(e,data) {
- })
.bind("remove.jstree", function (e, data) {
data.rslt.obj.each(function () {
$.ajax({
@@ -133,6 +129,12 @@ jQuery(document).ready(function ($) {
}
}
},
+ contextmenu: {
+ items: function (node) {
+ if (node.attr("rel") == 'test_case' || node.attr("rel") == 'test_suite')
+ return PLAN_CASE_MENU;
+ }
+ },
types: {
max_depth: -2,
max_children: -2,
@@ -213,7 +213,15 @@ jQuery(document).ready(function ($) {
animation: 0
},
contextmenu: {
- select_node: true
+ select_node: true,
+ items: function(node) {
+ if (node.attr('rel') == 'test_project')
+ return ROOT_MENU.contextmenu;
+ else if (node.attr('rel') == 'test_suite')
+ return FOLDER_MENU.contextmenu;
+ else if (node.attr('rel') == 'test_case')
+ return LEAF_MENU.contextmenu;
+ }
},
json_data: {
ajax: {
@@ -270,9 +278,6 @@ jQuery(document).ready(function ($) {
testcaseTree.jstree('hide_checkboxes');
prepared_checkbox = true;
}
- $("li[rel=test_project]", this).data("jstree", ROOT_MENU);
- $("li[rel=test_suite]", this).data("jstree", FOLDER_MENU);
- $("li[rel=test_case]", this).data("jstree", LEAF_MENU);
})
.bind("create.jstree", function (e, data) {
dialog[$(data.rslt.obj).attr("rel")].bind('dialogbeforeclose', function(e) {
Oops, something went wrong.

0 comments on commit 2b6c76e

Please sign in to comment.