You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@bloodhound.apache.org by da...@apache.org on 2014/07/01 06:05:50 UTC

svn commit: r1606979 - in /bloodhound/branches/bep_0011_batch_create_tickets/bloodhound_theme/bhtheme: htdocs/js/batchcreate.js theme.py

Author: dammina
Date: Tue Jul  1 04:05:49 2014
New Revision: 1606979

URL: http://svn.apache.org/r1606979
Log:
Details of the created tickets appear in a ticket table

Modified:
    bloodhound/branches/bep_0011_batch_create_tickets/bloodhound_theme/bhtheme/htdocs/js/batchcreate.js
    bloodhound/branches/bep_0011_batch_create_tickets/bloodhound_theme/bhtheme/theme.py

Modified: bloodhound/branches/bep_0011_batch_create_tickets/bloodhound_theme/bhtheme/htdocs/js/batchcreate.js
URL: http://svn.apache.org/viewvc/bloodhound/branches/bep_0011_batch_create_tickets/bloodhound_theme/bhtheme/htdocs/js/batchcreate.js?rev=1606979&r1=1606978&r2=1606979&view=diff
==============================================================================
--- bloodhound/branches/bep_0011_batch_create_tickets/bloodhound_theme/bhtheme/htdocs/js/batchcreate.js (original)
+++ bloodhound/branches/bep_0011_batch_create_tickets/bloodhound_theme/bhtheme/htdocs/js/batchcreate.js Tue Jul  1 04:05:49 2014
@@ -4,7 +4,7 @@ function emptyTable(products,href,token)
 	if(numOfRows != "" && document.getElementById("empty-table") == null){
 	var contentDiv = document.getElementById("content");
 	//var headers = {"summary":"Summary","description":"Description","product":"Product","status":"Status","priority":"Priority","type":"Types","owner":"Owner","cc":"Cc","milestone":"Milestone","keywords":"Keywords"}
-        var headers = {"summary":"Summary","description":"Description","product":"Product","status":"Status","priority":"Priority"}
+    var headers = {"summary":"Summary","description":"Description","product":"Product","status":"Status","priority":"Priority"}
 	statuses = ["accepted", "assigned", "closed", "new", "reopened"];
 	priorities = ["blocker", "critical", "major", "minor", "trivial"];
 	types = ["defect", "enhancement", "task"];
@@ -20,7 +20,6 @@ function emptyTable(products,href,token)
 	form.setAttribute("id","bct-form");
 	form.setAttribute("name","bct");
 	form.setAttribute("method","post");
-	form.setAttribute("action",href);
 	
 	var div_token = document.createElement("div");
 	var form_token_val = document.createElement("input");
@@ -180,25 +179,107 @@ function emptyTable(products,href,token)
     submit_button = document.createElement("button");
 	submit_button.setAttribute("class","btn pull-right");
 	submit_button.setAttribute("type","button");
-	submit_button.setAttribute("onclick","submitForm()");
+	submit_button.setAttribute("onclick","submit_btn_action()");
+	submit_button.setAttribute("id","bct-create");
+	submit_button.setAttribute("data-target",href);
 	submit_button.appendChild(document.createTextNode("save"));
-	form.appendChild(submit_button);
+	form.appendChild(submit_button);	
+	
+	cancle_button = document.createElement("button");
+	cancle_button.setAttribute("class","btn pull-right");
+	cancle_button.setAttribute("type","button");
+	cancle_button.setAttribute("onclick","deleteForm()");
+	cancle_button.appendChild(document.createTextNode("cancel"));
+	form.appendChild(cancle_button);
+	
 	div.appendChild(form);
 	contentDiv.appendChild(div);
 	}
 
-    //var rowCount = table.rows.length;
-    //var row = table.insertRow(rowCount);
 }
 
 function submitForm(){
 	document.getElementById("bct-form").submit();
 }
- 
-//function deleteRow(obj) {
-      
-//    var index = obj.parentNode.parentNode.rowIndex;
-//    var table = document.getElementById("myTableData");
-//    table.deleteRow(index);
-    
-//}
+
+function removeBatchCreate(){
+	document.getElementById("bct-button").remove();
+	document.getElementById("numOfRows").remove();
+}
+
+function deleteForm(){
+	document.getElementById("empty-table").remove();
+}
+
+//$('#bct-create').click(
+function submit_btn_action() {
+        // data-target is the base url for the product in current scope
+	var product_base_url = $('#bct-create').attr('data-target');
+    if (product_base_url === '/')
+        product_base_url = '';
+        $.post(product_base_url , $('#bct-form').serialize(),
+        function(ticket) {
+			deleteForm();
+			removeBatchCreate();
+			
+			var headers = {"id":"Ticket","summary":"Summary","product":"Product","status":"Status"}
+			var contentDiv = document.getElementById("content");
+			var div = document.createElement("div");
+			div.setAttribute("class","span12");
+			var h2 = document.createElement("h2");
+			h2.appendChild(document.createTextNode("Created Tickets"));
+			div.appendChild(h2);
+			var table = document.createElement("table");
+			table.setAttribute("class","listing tickets table table-bordered table-condensed query");
+			table.setAttribute("style","border-radius: 0px 0px 4px 4px");
+			tr = document.createElement("tr");
+			tr.setAttribute("class","trac-columns");
+			
+			for (header in headers){
+				th = document.createElement("th");
+				font = document.createElement("font");
+				font.setAttribute("color","#1975D1");
+				font.appendChild(document.createTextNode(headers[header]))
+				th = document.createElement("th");
+				th.appendChild(font);
+				tr.appendChild(th);
+			}
+			table.appendChild(tr);
+			
+			for ( i=0 ; i<Object.keys(ticket.tickets).length ; i++ ){
+				tr = document.createElement("tr");
+				for (j=0;j<4;j++){
+					if(j==0){
+						td = document.createElement("td");
+						a = document.createElement("a");
+						tkt = JSON.parse(ticket.tickets[i]);
+						a.setAttribute("href",tkt.url);
+						a.appendChild(document.createTextNode("#"+tkt.id));
+						td.appendChild(a);
+					}
+					else if(j==1){
+						td = document.createElement("td");
+						a = document.createElement("a");
+						tkt = JSON.parse(ticket.tickets[i]);
+						a.setAttribute("href",tkt.url);
+						a.appendChild(document.createTextNode(tkt.summary));
+						td.appendChild(a);
+					}
+					else if(j==2){
+						td = document.createElement("td");
+						tkt = JSON.parse(ticket.tickets[i]);
+						td.appendChild(document.createTextNode(tkt.product));
+					}
+					else if(j==3){
+						td = document.createElement("td");
+						tkt = JSON.parse(ticket.tickets[i]);
+						td.appendChild(document.createTextNode(tkt.status));
+					}
+					tr.appendChild(td);
+				}
+				table.appendChild(tr);
+			}
+			div.appendChild(table);
+			contentDiv.appendChild(div);     
+        });
+}

Modified: bloodhound/branches/bep_0011_batch_create_tickets/bloodhound_theme/bhtheme/theme.py
URL: http://svn.apache.org/viewvc/bloodhound/branches/bep_0011_batch_create_tickets/bloodhound_theme/bhtheme/theme.py?rev=1606979&r1=1606978&r2=1606979&view=diff
==============================================================================
--- bloodhound/branches/bep_0011_batch_create_tickets/bloodhound_theme/bhtheme/theme.py (original)
+++ bloodhound/branches/bep_0011_batch_create_tickets/bloodhound_theme/bhtheme/theme.py Tue Jul  1 04:05:49 2014
@@ -789,17 +789,20 @@ class BatchCreateTicketDialog(Component)
                          if k.startswith('field_'))
             #new_tkts variable will contain the tickets that have been created as a batch
             #that information will be used to load the resultant query table
-            product, tid, new_tkts = self.batch_create(req, attrs, True)
+            product, tid, new_tkts,num_of_tkts = self.batch_create(req, attrs, True)
+            # product, tid = self.batch_create(req, attrs, True)
         except Exception, exc:
             self.log.exception("BH: Batch create tickets failed %s" % (exc,))
             req.send(str(exc), 'plain/text', 500)
         else:
-            tres = Neighborhood('product', product)('ticket', tid)
-            href = req.href
-            req.send(to_json({'product': product, 'id': tid,
-                              'url': get_resource_url(self.env, tres, href)}),
-                     'application/json')
-
+            tkt_list=[]
+            tkt_dict={}
+            for i in range(0,num_of_tkts):
+                tres = Neighborhood('product', new_tkts[i].values['product'])('ticket', tid-num_of_tkts+i+1)
+                href = req.href
+                tkt_list.append(to_json({'product': new_tkts[i].values['product'], 'id': tid-num_of_tkts+i+1, 'url': get_resource_url(self.env, tres, href), 'summary': new_tkts[i].values['summary'] ,'status': new_tkts[i].values['status'],'priority': new_tkts[i].values['priority'],'description': new_tkts[i].values['description']}))
+            tkt_dict["tickets"]=tkt_list
+            req.send(to_json(tkt_dict), 'application/json')
 
     def _get_ticket_module(self):
         ptm = None
@@ -821,7 +824,7 @@ class BatchCreateTicketDialog(Component)
             form = tag.form(method="get", style="display:inline", id="batchcreate")
             div = tag.div(class_="btn-group")
             span = tag.span(class_="input-group-btn")
-            button = tag.button(class_="btn btn-default", type="button", onclick="Javascript:emptyTable("+to_json(products)+","+to_json(req.href()+"/bct")+","+to_json(str(req.environ["HTTP_COOKIE"]))+")")
+            button = tag.button(id="bct-button", class_="btn btn-default", type="button", onclick="Javascript:emptyTable("+to_json(products)+","+to_json(req.href()+"/bct")+","+to_json(str(req.environ["HTTP_COOKIE"]))+")")
             input = tag.input(id="numOfRows",type="text", style="width:110px;", class_="form-control", placeholder="How many tickets?")
             text = tag.text("Batch Create")
             button.append(text)
@@ -837,7 +840,9 @@ class BatchCreateTicketDialog(Component)
         """ Create batch of tickets, returning created tickets.
         """
         num_of_tkts = attributes.__len__()/5
+        created_tickets = []
         for i in range(0,num_of_tkts):
+
             if 'product'+str(i) in attributes:
                 env = self.env.parent or self.env
                 if attributes['product'+str(i)]:
@@ -859,6 +864,7 @@ class BatchCreateTicketDialog(Component)
             t['product'] = product
             t['priority'] = priority
             t.insert()
+            created_tickets.append(t)
 
             if notify:
                 try:
@@ -867,7 +873,8 @@ class BatchCreateTicketDialog(Component)
                 except Exception, e:
                     self.log.exception("Failure sending notification on creation "
                                    "of ticket #%s: %s" % (t.id, e))
-        start_id = self.env.db_query("SELECT MAX(uid) FROM ticket")[0][0] - num_of_tkts
-        created_tickets = self.env.db_query("SELECT * FROM ticket WHERE uid>%s"%start_id)
-        return t['product'], t.id, created_tickets
+        # start_id = self.env.db_query("SELECT MAX(uid) FROM ticket")[0][0] - num_of_tkts
+        # created_tickets = self.env.db_query("SELECT * FROM ticket WHERE uid>%s"%start_id)
+        # return t['product'], t.id, created_tickets
+        return t['product'], t.id, created_tickets, num_of_tkts
 



Re: svn commit: r1606979 - in /bloodhound/branches/bep_0011_batch_create_tickets/bloodhound_theme/bhtheme: htdocs/js/batchcreate.js theme.py

Posted by Dammina Sahabandu <dm...@gmail.com>.
Now the component will generate a ticket table after creating the
tickets. And that ticket table will contain the details of the tickets
that have being created by the user.

On Tue, Jul 1, 2014 at 9:35 AM,  <da...@apache.org> wrote:
> Author: dammina
> Date: Tue Jul  1 04:05:49 2014
> New Revision: 1606979
>
> URL: http://svn.apache.org/r1606979
> Log:
> Details of the created tickets appear in a ticket table
>
> Modified:
>     bloodhound/branches/bep_0011_batch_create_tickets/bloodhound_theme/bhtheme/htdocs/js/batchcreate.js
>     bloodhound/branches/bep_0011_batch_create_tickets/bloodhound_theme/bhtheme/theme.py
>
> Modified: bloodhound/branches/bep_0011_batch_create_tickets/bloodhound_theme/bhtheme/htdocs/js/batchcreate.js
> URL: http://svn.apache.org/viewvc/bloodhound/branches/bep_0011_batch_create_tickets/bloodhound_theme/bhtheme/htdocs/js/batchcreate.js?rev=1606979&r1=1606978&r2=1606979&view=diff
> ==============================================================================
> --- bloodhound/branches/bep_0011_batch_create_tickets/bloodhound_theme/bhtheme/htdocs/js/batchcreate.js (original)
> +++ bloodhound/branches/bep_0011_batch_create_tickets/bloodhound_theme/bhtheme/htdocs/js/batchcreate.js Tue Jul  1 04:05:49 2014
> @@ -4,7 +4,7 @@ function emptyTable(products,href,token)
>         if(numOfRows != "" && document.getElementById("empty-table") == null){
>         var contentDiv = document.getElementById("content");
>         //var headers = {"summary":"Summary","description":"Description","product":"Product","status":"Status","priority":"Priority","type":"Types","owner":"Owner","cc":"Cc","milestone":"Milestone","keywords":"Keywords"}
> -        var headers = {"summary":"Summary","description":"Description","product":"Product","status":"Status","priority":"Priority"}
> +    var headers = {"summary":"Summary","description":"Description","product":"Product","status":"Status","priority":"Priority"}
>         statuses = ["accepted", "assigned", "closed", "new", "reopened"];
>         priorities = ["blocker", "critical", "major", "minor", "trivial"];
>         types = ["defect", "enhancement", "task"];
> @@ -20,7 +20,6 @@ function emptyTable(products,href,token)
>         form.setAttribute("id","bct-form");
>         form.setAttribute("name","bct");
>         form.setAttribute("method","post");
> -       form.setAttribute("action",href);
>
>         var div_token = document.createElement("div");
>         var form_token_val = document.createElement("input");
> @@ -180,25 +179,107 @@ function emptyTable(products,href,token)
>      submit_button = document.createElement("button");
>         submit_button.setAttribute("class","btn pull-right");
>         submit_button.setAttribute("type","button");
> -       submit_button.setAttribute("onclick","submitForm()");
> +       submit_button.setAttribute("onclick","submit_btn_action()");
> +       submit_button.setAttribute("id","bct-create");
> +       submit_button.setAttribute("data-target",href);
>         submit_button.appendChild(document.createTextNode("save"));
> -       form.appendChild(submit_button);
> +       form.appendChild(submit_button);
> +
> +       cancle_button = document.createElement("button");
> +       cancle_button.setAttribute("class","btn pull-right");
> +       cancle_button.setAttribute("type","button");
> +       cancle_button.setAttribute("onclick","deleteForm()");
> +       cancle_button.appendChild(document.createTextNode("cancel"));
> +       form.appendChild(cancle_button);
> +
>         div.appendChild(form);
>         contentDiv.appendChild(div);
>         }
>
> -    //var rowCount = table.rows.length;
> -    //var row = table.insertRow(rowCount);
>  }
>
>  function submitForm(){
>         document.getElementById("bct-form").submit();
>  }
> -
> -//function deleteRow(obj) {
> -
> -//    var index = obj.parentNode.parentNode.rowIndex;
> -//    var table = document.getElementById("myTableData");
> -//    table.deleteRow(index);
> -
> -//}
> +
> +function removeBatchCreate(){
> +       document.getElementById("bct-button").remove();
> +       document.getElementById("numOfRows").remove();
> +}
> +
> +function deleteForm(){
> +       document.getElementById("empty-table").remove();
> +}
> +
> +//$('#bct-create').click(
> +function submit_btn_action() {
> +        // data-target is the base url for the product in current scope
> +       var product_base_url = $('#bct-create').attr('data-target');
> +    if (product_base_url === '/')
> +        product_base_url = '';
> +        $.post(product_base_url , $('#bct-form').serialize(),
> +        function(ticket) {
> +                       deleteForm();
> +                       removeBatchCreate();
> +
> +                       var headers = {"id":"Ticket","summary":"Summary","product":"Product","status":"Status"}
> +                       var contentDiv = document.getElementById("content");
> +                       var div = document.createElement("div");
> +                       div.setAttribute("class","span12");
> +                       var h2 = document.createElement("h2");
> +                       h2.appendChild(document.createTextNode("Created Tickets"));
> +                       div.appendChild(h2);
> +                       var table = document.createElement("table");
> +                       table.setAttribute("class","listing tickets table table-bordered table-condensed query");
> +                       table.setAttribute("style","border-radius: 0px 0px 4px 4px");
> +                       tr = document.createElement("tr");
> +                       tr.setAttribute("class","trac-columns");
> +
> +                       for (header in headers){
> +                               th = document.createElement("th");
> +                               font = document.createElement("font");
> +                               font.setAttribute("color","#1975D1");
> +                               font.appendChild(document.createTextNode(headers[header]))
> +                               th = document.createElement("th");
> +                               th.appendChild(font);
> +                               tr.appendChild(th);
> +                       }
> +                       table.appendChild(tr);
> +
> +                       for ( i=0 ; i<Object.keys(ticket.tickets).length ; i++ ){
> +                               tr = document.createElement("tr");
> +                               for (j=0;j<4;j++){
> +                                       if(j==0){
> +                                               td = document.createElement("td");
> +                                               a = document.createElement("a");
> +                                               tkt = JSON.parse(ticket.tickets[i]);
> +                                               a.setAttribute("href",tkt.url);
> +                                               a.appendChild(document.createTextNode("#"+tkt.id));
> +                                               td.appendChild(a);
> +                                       }
> +                                       else if(j==1){
> +                                               td = document.createElement("td");
> +                                               a = document.createElement("a");
> +                                               tkt = JSON.parse(ticket.tickets[i]);
> +                                               a.setAttribute("href",tkt.url);
> +                                               a.appendChild(document.createTextNode(tkt.summary));
> +                                               td.appendChild(a);
> +                                       }
> +                                       else if(j==2){
> +                                               td = document.createElement("td");
> +                                               tkt = JSON.parse(ticket.tickets[i]);
> +                                               td.appendChild(document.createTextNode(tkt.product));
> +                                       }
> +                                       else if(j==3){
> +                                               td = document.createElement("td");
> +                                               tkt = JSON.parse(ticket.tickets[i]);
> +                                               td.appendChild(document.createTextNode(tkt.status));
> +                                       }
> +                                       tr.appendChild(td);
> +                               }
> +                               table.appendChild(tr);
> +                       }
> +                       div.appendChild(table);
> +                       contentDiv.appendChild(div);
> +        });
> +}
>
> Modified: bloodhound/branches/bep_0011_batch_create_tickets/bloodhound_theme/bhtheme/theme.py
> URL: http://svn.apache.org/viewvc/bloodhound/branches/bep_0011_batch_create_tickets/bloodhound_theme/bhtheme/theme.py?rev=1606979&r1=1606978&r2=1606979&view=diff
> ==============================================================================
> --- bloodhound/branches/bep_0011_batch_create_tickets/bloodhound_theme/bhtheme/theme.py (original)
> +++ bloodhound/branches/bep_0011_batch_create_tickets/bloodhound_theme/bhtheme/theme.py Tue Jul  1 04:05:49 2014
> @@ -789,17 +789,20 @@ class BatchCreateTicketDialog(Component)
>                           if k.startswith('field_'))
>              #new_tkts variable will contain the tickets that have been created as a batch
>              #that information will be used to load the resultant query table
> -            product, tid, new_tkts = self.batch_create(req, attrs, True)
> +            product, tid, new_tkts,num_of_tkts = self.batch_create(req, attrs, True)
> +            # product, tid = self.batch_create(req, attrs, True)
>          except Exception, exc:
>              self.log.exception("BH: Batch create tickets failed %s" % (exc,))
>              req.send(str(exc), 'plain/text', 500)
>          else:
> -            tres = Neighborhood('product', product)('ticket', tid)
> -            href = req.href
> -            req.send(to_json({'product': product, 'id': tid,
> -                              'url': get_resource_url(self.env, tres, href)}),
> -                     'application/json')
> -
> +            tkt_list=[]
> +            tkt_dict={}
> +            for i in range(0,num_of_tkts):
> +                tres = Neighborhood('product', new_tkts[i].values['product'])('ticket', tid-num_of_tkts+i+1)
> +                href = req.href
> +                tkt_list.append(to_json({'product': new_tkts[i].values['product'], 'id': tid-num_of_tkts+i+1, 'url': get_resource_url(self.env, tres, href), 'summary': new_tkts[i].values['summary'] ,'status': new_tkts[i].values['status'],'priority': new_tkts[i].values['priority'],'description': new_tkts[i].values['description']}))
> +            tkt_dict["tickets"]=tkt_list
> +            req.send(to_json(tkt_dict), 'application/json')
>
>      def _get_ticket_module(self):
>          ptm = None
> @@ -821,7 +824,7 @@ class BatchCreateTicketDialog(Component)
>              form = tag.form(method="get", style="display:inline", id="batchcreate")
>              div = tag.div(class_="btn-group")
>              span = tag.span(class_="input-group-btn")
> -            button = tag.button(class_="btn btn-default", type="button", onclick="Javascript:emptyTable("+to_json(products)+","+to_json(req.href()+"/bct")+","+to_json(str(req.environ["HTTP_COOKIE"]))+")")
> +            button = tag.button(id="bct-button", class_="btn btn-default", type="button", onclick="Javascript:emptyTable("+to_json(products)+","+to_json(req.href()+"/bct")+","+to_json(str(req.environ["HTTP_COOKIE"]))+")")
>              input = tag.input(id="numOfRows",type="text", style="width:110px;", class_="form-control", placeholder="How many tickets?")
>              text = tag.text("Batch Create")
>              button.append(text)
> @@ -837,7 +840,9 @@ class BatchCreateTicketDialog(Component)
>          """ Create batch of tickets, returning created tickets.
>          """
>          num_of_tkts = attributes.__len__()/5
> +        created_tickets = []
>          for i in range(0,num_of_tkts):
> +
>              if 'product'+str(i) in attributes:
>                  env = self.env.parent or self.env
>                  if attributes['product'+str(i)]:
> @@ -859,6 +864,7 @@ class BatchCreateTicketDialog(Component)
>              t['product'] = product
>              t['priority'] = priority
>              t.insert()
> +            created_tickets.append(t)
>
>              if notify:
>                  try:
> @@ -867,7 +873,8 @@ class BatchCreateTicketDialog(Component)
>                  except Exception, e:
>                      self.log.exception("Failure sending notification on creation "
>                                     "of ticket #%s: %s" % (t.id, e))
> -        start_id = self.env.db_query("SELECT MAX(uid) FROM ticket")[0][0] - num_of_tkts
> -        created_tickets = self.env.db_query("SELECT * FROM ticket WHERE uid>%s"%start_id)
> -        return t['product'], t.id, created_tickets
> +        # start_id = self.env.db_query("SELECT MAX(uid) FROM ticket")[0][0] - num_of_tkts
> +        # created_tickets = self.env.db_query("SELECT * FROM ticket WHERE uid>%s"%start_id)
> +        # return t['product'], t.id, created_tickets
> +        return t['product'], t.id, created_tickets, num_of_tkts
>
>
>



-- 
Dammina Sahabandu.
Committer for ASF (Apache Bloodhound)
Undergraduate Department of Computer Science and Engineering
University of Moratuwa
Sri Lanka.