Symbian.org/Bugzilla.js
changeset 0 54498df70f5d
child 1 609a552a42fa
equal deleted inserted replaced
-1:000000000000 0:54498df70f5d
       
     1 
       
     2 
       
     3 var bugzillaTableStyle = "bugzilla";
       
     4 
       
     5 // Bugzilla access 
       
     6 
       
     7 function BugzillaSearchPanel(parent) {
       
     8 	this.previousView = parent;
       
     9 	ListView.prototype.init.call(this, null, null);	
       
    10 
       
    11 	// add the banner and 'title bar' - avoids the caption bug
       
    12 	var titleBar = new NavigationButton(null, "titlebar.png", "Bugzilla");
       
    13 	titleBar.setEnabled(false);
       
    14 	this.addControl(titleBar);
       
    15 	
       
    16 	// search term control
       
    17     this.searchTerm = new TextField('bugzillaSearchTerm', "Bugzilla search term:", "test");
       
    18     this.addControl(this.searchTerm);
       
    19 
       
    20 	// add the search box
       
    21 	this.searchButton = new FormButton(null, "Search");
       
    22 	var self = this;
       
    23     this.searchButton.addEventListener("ActionPerformed", function(){
       
    24 		self.bugzillaSearchClicked();
       
    25 	});
       
    26 	this.addControl(this.searchButton);
       
    27 }
       
    28 
       
    29 
       
    30 BugzillaSearchPanel.prototype = new ListView(null,null);
       
    31 
       
    32 
       
    33 BugzillaSearchPanel.prototype.bugzillaSearchClicked = function() {
       
    34 	// create the RssReader for bugzilla
       
    35 	var searchString = this.searchTerm.getText();
       
    36 	var title = "Bugzilla: " + searchString;
       
    37 	var url = symbianOrgBaseUrl + "/bugs/buglist.cgi?"
       
    38 		+ "bug_status=NEW&bug_status=ASSIGNED&bug_status=UNCONFIRMED"
       
    39 		+ "&field-1-0-0=bug_status&field0-0-0=product&field0-0-1=component&field0-0-2=short_desc"
       
    40 		+ "&field0-0-3=status_whiteboard&field0-0-4=longdesc"
       
    41 		+ "&query_format=advanced&remaction=&type-1-0-0=anyexact"
       
    42 		+ "&type0-0-0=substring&type0-0-1=substring&type0-0-2=substring&type0-0-3=substring"
       
    43 		+ "&type0-0-4=substring&value-1-0-0=NEW%2CASSIGNED%2CUNCONFIRMED"
       
    44 		+ "&value0-0-0=" + searchString
       
    45 		+ "&value0-0-1=" + searchString
       
    46 		+ "&value0-0-2=" + searchString
       
    47 		+ "&value0-0-3=" + searchString
       
    48 		+ "&value0-0-4=" + searchString
       
    49 		+ "&title=Bug List&ctype=atom";
       
    50 	var reader = new RssReader(title, url, new BugzillaFeedPresenter(null), this, parseBugzillaFeed);
       
    51 	reader.show();
       
    52 }
       
    53 
       
    54 
       
    55 function parseBugzillaFeed(broker, responseStatus, xmlDoc) {
       
    56     if (responseStatus == 200 && xmlDoc != null) {
       
    57         // node ref for iterating
       
    58         var node;
       
    59 
       
    60 		// for compatibility with rss
       
    61 		var lastModified = new Date();
       
    62 		
       
    63         // init result items array
       
    64         var items = [];
       
    65 
       
    66 		var itemElements = xmlDoc.getElementsByTagName("entry");
       
    67 		
       
    68 		for (var i = 0; i < itemElements.length; i++) {
       
    69             // iterate through child nodes of this item and gather
       
    70             // all the data we need for a feed item
       
    71             var title = null;
       
    72             var date = null;
       
    73             var description = null;
       
    74             var url = null;
       
    75             var author = null;
       
    76 			var bugid;
       
    77             node = itemElements[i].firstChild;
       
    78             while (node != null) {
       
    79                 if (node.nodeType == Node.ELEMENT_NODE) {
       
    80                     if (node.nodeName == "title") {
       
    81                         // item title
       
    82                         title = getTextOfNode(node);
       
    83 						if ( title.length > 48) {
       
    84 							title = title.substring(0,45) + "...";
       
    85 						}
       
    86                     } else if (node.nodeName == "updated" ) {
       
    87                         // item publishing date
       
    88                         date = getTextOfNode(node);
       
    89                     } else if (node.nodeName == "summary" && !this.ignoreContent ) {
       
    90                         // item description
       
    91                         description = getTextOfNode(node);
       
    92                     } else if (node.nodeName == "link") {
       
    93                         // link URL
       
    94                         url = node.getAttribute("href");
       
    95 						// extract bug id
       
    96 						var ind = url.indexOf("?id=");
       
    97 						if ( ind != -1 ) {
       
    98 							bugid = url.substring(ind + 4);
       
    99 							url = symbianOrgBaseUrl + "/bugtracker/show_bug.cgi?ctype=xml&id="+bugid;
       
   100 						}
       
   101                     } else if (node.nodeName == "author" ) {
       
   102 						author = getTextOfNode(node);
       
   103 					}
       
   104                 }
       
   105                 node = node.nextSibling;
       
   106             }
       
   107             items.push({ title: title, date: date, description: description, url: url, author: author });
       
   108 		}
       
   109 
       
   110         // update was completed successfully
       
   111         return { status: "ok", lastModified: lastModified, items: items };
       
   112     } else {
       
   113         // update failed
       
   114         return { status: "error" };
       
   115     }
       
   116 }
       
   117 
       
   118 
       
   119 // Implementation of FeedPresenter that shows feed as a clickable
       
   120 // button and shows feed entry title as label
       
   121 function BugzillaFeedPresenter(rssreader) {
       
   122 	ButtonFeedPresenter.prototype.init.call(this, rssreader);
       
   123 }
       
   124 
       
   125 // BugzillaFeedPresenter is a subclass of ButtonFeedPresenter
       
   126 BugzillaFeedPresenter.prototype = new ButtonFeedPresenter(null);
       
   127 
       
   128 // Handle the button-press
       
   129 BugzillaFeedPresenter.prototype.feedClicked = function(event){
       
   130 	var clickedButton = event.source;
       
   131 	var id = clickedButton.id;
       
   132 	var url = this.items[id].url;
       
   133 	var presenter = new HtmlFeedPresenter(null);
       
   134 	presenter.expanded = true;
       
   135 	var reader = new RssReader(this.items[id].title, url, 
       
   136 		presenter, uiManager.currentView, parseBugzillaBugFeed);
       
   137 	reader.show();
       
   138 }
       
   139 
       
   140 
       
   141 function parseBugzillaBugFeed(broker, responseStatus, xmlDoc) {
       
   142     if (responseStatus == 200 && xmlDoc != null) {
       
   143         // node ref for iterating
       
   144         var node;
       
   145 
       
   146 		// for compatibility with rss
       
   147 		var lastModified = new Date();
       
   148 		
       
   149         // init result items array
       
   150         var items = [];
       
   151 
       
   152 		var itemElements = xmlDoc.getElementsByTagName("bug");
       
   153 		
       
   154 		for (var i = 0; i < itemElements.length; i++) {
       
   155             // iterate through child nodes of this item and gather
       
   156             // all the data we need for a feed item
       
   157             var title = null;
       
   158             var date = null;
       
   159             var url = null;
       
   160             var author = null;
       
   161 			var bugid = null;
       
   162 			var creationTime = "Not specified";
       
   163 			var product = "Not specified";
       
   164 			var component = "Not specified";
       
   165 			var classification = "Not specified";
       
   166 			var op_sys = "Not specified";
       
   167 			var bug_status = "Not specified";
       
   168 			var bug_file_loc = "Not specified";
       
   169 			var priority = "Not specified";
       
   170 			var severity = "Not specified";
       
   171 			var target_milestone = "Not specified";
       
   172 			var version = "Not specified";
       
   173 			var platform = "Not specified";
       
   174 			var assignedToName = "Not specified";
       
   175 			var solutionDetails = "Not specified";
       
   176 			var longdesc = "";
       
   177 			var shortDesc = "";
       
   178 			var bugid = "";
       
   179 			
       
   180             node = itemElements[i].firstChild;
       
   181             while (node != null) {
       
   182                 if (node.nodeType == Node.ELEMENT_NODE) {
       
   183                     if (node.nodeName == "bug_id") {
       
   184                         // item title
       
   185                         bugid = "Bug " + getTextOfNode(node);
       
   186                     } else if (node.nodeName == "updated" ) {
       
   187                         // item publishing date
       
   188                         date = getTextOfNode(node);
       
   189                     } else if (node.nodeName == "creation_ts" ) {
       
   190                         // item publishing date
       
   191                         creationTime = getTextOfNode(node);
       
   192                     } else if (node.nodeName == "short_desc" && !this.ignoreContent ) {
       
   193                         // item description
       
   194                         title = getTextOfNode(node);
       
   195                     } else if (node.nodeName == "reporter" ) {
       
   196 						author = getTextOfNode(node);
       
   197 					} else if (node.nodeName == "product" ) {
       
   198                         product = getTextOfNode(node);
       
   199 					} else if (node.nodeName == "component" ) {
       
   200                         component = getTextOfNode(node);
       
   201 					} else if (node.nodeName == "classification" ) {
       
   202                         classification = getTextOfNode(node);
       
   203 					} else if (node.nodeName == "version" ) {
       
   204                         version = getTextOfNode(node);
       
   205 					} else if (node.nodeName == "op_sys" ) {
       
   206                         op_sys = getTextOfNode(node);
       
   207 					} else if (node.nodeName == "bug_status" ) {
       
   208                         bug_status = getTextOfNode(node);
       
   209 					} else if (node.nodeName == "bug_file_loc" ) {
       
   210                         bug_file_loc = getTextOfNode(node);
       
   211 					} else if (node.nodeName == "priority" ) {
       
   212                         priority = getTextOfNode(node);
       
   213 					} else if (node.nodeName == "severity" ) {
       
   214                         severity = getTextOfNode(node);
       
   215 					} else if (node.nodeName == "target_milestone" ) {
       
   216                         target_milestone = getTextOfNode(node);
       
   217 					} else if (node.nodeName == "platform" ) {
       
   218                         platform = getTextOfNode(node);
       
   219 					} else if (node.nodeName == "cf_solutiondetails" ) {
       
   220                         solutionDetails = getTextOfNode(node);
       
   221 					} else if (node.nodeName == "long_desc" ) {
       
   222                         longdesc += "<br><table style="+bugzillaTableStyle+">";
       
   223 						var ld_nodes = node.childNodes;
       
   224 						for ( var tmp = 0 ; tmp < ld_nodes.length ; tmp++ ) {
       
   225 	                        longdesc += "<tr><td>" 
       
   226 								+ getTextOfNode(ld_nodes[tmp]) + "</td></tr>";
       
   227 						}
       
   228                         longdesc += "</table>";
       
   229 					} else if (node.nodeName == "assigned_to" ) {
       
   230                         assignedToName = getTextOfNode(node);
       
   231 					} 
       
   232                 }
       
   233                 node = node.nextSibling;
       
   234             }
       
   235 			// format the description
       
   236 			var description = "<table style="+bugzillaTableStyle+">";
       
   237 			description += "<tr><td>Reported:" + "</td><td>" + creationTime + "</td></tr>";
       
   238 			description += "<tr><td>Product:" + "</td><td>" + product + "</td></tr>";
       
   239 			description += "<tr><td>Component:" + "</td><td>" + component + "</td></tr>";
       
   240 			description += "<tr><td>Classification:" + "</td><td>" + classification + "</td></tr>";
       
   241 			description += "<tr><td>Operating system:" + "</td><td>" + op_sys + "</td></tr>";
       
   242 			description += "<tr><td>Status:" + "</td><td>" + bug_status + "</td></tr>";
       
   243 			description += "<tr><td>Priority:" + "</td><td>" + priority + "</td></tr>";
       
   244 			description += "<tr><td>Severity:" + "</td><td>" + severity + "</td></tr>";
       
   245 			description += "<tr><td>Version:" + "</td><td>" + version + "</td></tr>";
       
   246 			description += "<tr><td>Platform:" + "</td><td>" + platform + "</td></tr>";
       
   247 			description += "<tr><td>Reported by:" + "</td><td>" + author + "</td></tr>";
       
   248 			description += "<tr><td>Assigned to:" + "</td><td>" + assignedToName + "</td></tr>";
       
   249 			description += "<tr><td>Target milestone:" + "</td><td>" + target_milestone + "</td></tr>";
       
   250 			description += "<tr><td>File location:" + "</td><td>" + bug_file_loc + "</td></tr>";
       
   251 			description += "</table>";
       
   252 			
       
   253 			description += "<table style="+bugzillaTableStyle+">";
       
   254 			description += "<tr><td>Description:" + "</td></tr>";
       
   255 			description += "<tr><td>" + longdesc + "</td></tr>";
       
   256 			description += "</table>";
       
   257 			
       
   258 			description += "<table style="+bugzillaTableStyle+">";
       
   259 			description += "<tr><td>Solution details:" + "</td></tr>";
       
   260 			description += "<tr><td>" + solutionDetails + "</td></tr>";
       
   261 			description += "</table>";			
       
   262 			
       
   263             items.push({ title: title, date: date, description: description, url: url, author: author });
       
   264 		}
       
   265 
       
   266         // update was completed successfully
       
   267         return { status: "ok", lastModified: lastModified, items: items };
       
   268     } else {
       
   269         // update failed
       
   270         return { status: "error" };
       
   271     }
       
   272 }
       
   273