On 18 Jan 2012, at 21:27, Ross Gardler wrote: > Scott, I love you're style. Don't waste time discussing ideas floated on > the list. Just implement them. Great stuff.
often the only way to know if something is doable is to try to do it... > > And using the template engine too - that makes me really happy. :-D > > Sent from my mobile device, please forgive errors and brevity. > On Jan 18, 2012 8:56 PM, <[email protected]> wrote: > >> Author: scottbw >> Date: Wed Jan 18 20:55:36 2012 >> New Revision: 1233062 >> >> URL: http://svn.apache.org/viewvc?rev=1233062&view=rev >> Log: >> Created a basic JIRA widget that gets version, release and issue counts >> from the ASF JIRA server using its REST JSON API. This is another example >> of using the Browse template (see WOOKIE-295) >> >> Added: >> incubator/wookie/trunk/widgets/templates/widgets/jira/ >> >> incubator/wookie/trunk/widgets/templates/widgets/jira/content_footer.html >> >> incubator/wookie/trunk/widgets/templates/widgets/jira/content_header.html >> >> incubator/wookie/trunk/widgets/templates/widgets/jira/content_primary.html >> >> incubator/wookie/trunk/widgets/templates/widgets/jira/content_secondary.html >> >> incubator/wookie/trunk/widgets/templates/widgets/jira/item_summary_template.html >> incubator/wookie/trunk/widgets/templates/widgets/jira/item_template.html >> incubator/wookie/trunk/widgets/templates/widgets/jira/scripts/ >> >> incubator/wookie/trunk/widgets/templates/widgets/jira/scripts/jira_controller.js >> incubator/wookie/trunk/widgets/templates/widgets/jira/widget.properties >> >> Added: >> incubator/wookie/trunk/widgets/templates/widgets/jira/content_footer.html >> URL: >> http://svn.apache.org/viewvc/incubator/wookie/trunk/widgets/templates/widgets/jira/content_footer.html?rev=1233062&view=auto >> >> ============================================================================== >> --- >> incubator/wookie/trunk/widgets/templates/widgets/jira/content_footer.html >> (added) >> +++ >> incubator/wookie/trunk/widgets/templates/widgets/jira/content_footer.html >> Wed Jan 18 20:55:36 2012 >> @@ -0,0 +1,2 @@ >> +<div style="float:left;"><img src="images/icon.png" height="24" >> style="vertical-align:text-bottom;"><strong>${widget.name}</strong></div> >> +<a class="button" href="#help" data-role="button" data-rel="dialog" >> data-transition="pop" data-icon="info" data-iconpos="notext">Help</a> >> \ No newline at end of file >> >> Added: >> incubator/wookie/trunk/widgets/templates/widgets/jira/content_header.html >> URL: >> http://svn.apache.org/viewvc/incubator/wookie/trunk/widgets/templates/widgets/jira/content_header.html?rev=1233062&view=auto >> >> ============================================================================== >> --- >> incubator/wookie/trunk/widgets/templates/widgets/jira/content_header.html >> (added) >> +++ >> incubator/wookie/trunk/widgets/templates/widgets/jira/content_header.html >> Wed Jan 18 20:55:36 2012 >> @@ -0,0 +1 @@ >> + >> >> Added: >> incubator/wookie/trunk/widgets/templates/widgets/jira/content_primary.html >> URL: >> http://svn.apache.org/viewvc/incubator/wookie/trunk/widgets/templates/widgets/jira/content_primary.html?rev=1233062&view=auto >> >> ============================================================================== >> --- >> incubator/wookie/trunk/widgets/templates/widgets/jira/content_primary.html >> (added) >> +++ >> incubator/wookie/trunk/widgets/templates/widgets/jira/content_primary.html >> Wed Jan 18 20:55:36 2012 >> @@ -0,0 +1,18 @@ >> +<!-- >> + Licensed to the Apache Software Foundation (ASF) under one or more >> + contributor license agreements. See the NOTICE file distributed with >> + this work for additional information regarding copyright ownership. >> + The ASF licenses this file to You under the Apache License, Version 2.0 >> + (the "License"); you may not use this file except in compliance with >> + the License. You may obtain a copy of the License at >> + >> + http://www.apache.org/licenses/LICENSE-2.0 >> + >> + Unless required by applicable law or agreed to in writing, software >> + distributed under the License is distributed on an "AS IS" BASIS, >> + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. >> + See the License for the specific language governing permissions and >> + limitations under the License. >> +--> >> +<div id="results" data-role="collapsible-set"> >> +</div> >> >> Added: >> incubator/wookie/trunk/widgets/templates/widgets/jira/content_secondary.html >> URL: >> http://svn.apache.org/viewvc/incubator/wookie/trunk/widgets/templates/widgets/jira/content_secondary.html?rev=1233062&view=auto >> >> ============================================================================== >> --- >> incubator/wookie/trunk/widgets/templates/widgets/jira/content_secondary.html >> (added) >> +++ >> incubator/wookie/trunk/widgets/templates/widgets/jira/content_secondary.html >> Wed Jan 18 20:55:36 2012 >> @@ -0,0 +1,59 @@ >> +<!-- >> + Licensed to the Apache Software Foundation (ASF) under one or more >> + contributor license agreements. See the NOTICE file distributed with >> + this work for additional information regarding copyright ownership. >> + The ASF licenses this file to You under the Apache License, Version 2.0 >> + (the "License"); you may not use this file except in compliance with >> + the License. You may obtain a copy of the License at >> + >> + http://www.apache.org/licenses/LICENSE-2.0 >> + >> + Unless required by applicable law or agreed to in writing, software >> + distributed under the License is distributed on an "AS IS" BASIS, >> + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. >> + See the License for the specific language governing permissions and >> + limitations under the License. >> +--> >> + >> +<!-- >> + Login panel >> +--> >> +<div id="loginPanel" data-role="collapsible" data-theme="c" >> + data-content-theme="c" data-collapsed="false"> >> + <h2>Login</h2> >> + <span id="loginMessage" style="color:red; font-weight: bold"></span> >> + <form >> + >> action="javascript:${widget.shortname}_browse_controller.submitLoginForm()" >> + method="get"> >> + <div data-role="fieldcontain"> >> + <label for="usernameString">Username:</label> <input >> type="text" >> + >> name="usernameString" id="usernameString" value="" >> + >> placeholder="username" /> >> + <label for="passwordString">Password:</label> <input >> type="password" >> + >> name="passwordString" id="passwordString" value="" >> + >> placeholder="password" /> >> + </div> >> + >> + <input type="submit" value="Login" /> >> + </form> >> + >> +</div> >> + >> +<div id="searchPanel" data-role="collapsible" data-theme="c" >> + data-content-theme="c" data-collapsed="true"> >> + <h2>Select an Apache project</h2> >> + <div data-role="content"> >> + <form >> + >> action="javascript:${widget.shortname}_browse_controller.submitSearchForm()" >> + method="get"> >> + <div data-role="fieldcontain"> >> + <label for="searchString">Search:</label> <input type="text" >> + >> name="searchString" id="searchString" value="" >> + >> placeholder="Project name..." /> >> + </div> >> + >> + <input type="submit" value="Search" /> >> + </form> >> + </div> >> + >> +</div> >> >> Added: >> incubator/wookie/trunk/widgets/templates/widgets/jira/item_summary_template.html >> URL: >> http://svn.apache.org/viewvc/incubator/wookie/trunk/widgets/templates/widgets/jira/item_summary_template.html?rev=1233062&view=auto >> >> ============================================================================== >> --- >> incubator/wookie/trunk/widgets/templates/widgets/jira/item_summary_template.html >> (added) >> +++ >> incubator/wookie/trunk/widgets/templates/widgets/jira/item_summary_template.html >> Wed Jan 18 20:55:36 2012 >> @@ -0,0 +1,10 @@ >> +<div class='result' data-role='collapsible' wid='${ID}'> >> + <h3>${NAME} <span id='${ID}-released'></span> </h3> >> + <p>${DESCRIPTION}</p> >> + <div class='detail'> >> + </div> >> + <script> >> + if (${RELEASED}) >> + $('#${ID}-released').html('<em>Released: >> ${USERRELEASEDATE}</em>'); >> + </script> >> +</div> >> >> Added: >> incubator/wookie/trunk/widgets/templates/widgets/jira/item_template.html >> URL: >> http://svn.apache.org/viewvc/incubator/wookie/trunk/widgets/templates/widgets/jira/item_template.html?rev=1233062&view=auto >> >> ============================================================================== >> --- >> incubator/wookie/trunk/widgets/templates/widgets/jira/item_template.html >> (added) >> +++ >> incubator/wookie/trunk/widgets/templates/widgets/jira/item_template.html >> Wed Jan 18 20:55:36 2012 >> @@ -0,0 +1,4 @@ >> + >> + <p>Issues to resolve: ${ISSUESUNRESOLVEDCOUNT}</p> >> + >> + >> \ No newline at end of file >> >> Added: >> incubator/wookie/trunk/widgets/templates/widgets/jira/scripts/jira_controller.js >> URL: >> http://svn.apache.org/viewvc/incubator/wookie/trunk/widgets/templates/widgets/jira/scripts/jira_controller.js?rev=1233062&view=auto >> >> ============================================================================== >> --- >> incubator/wookie/trunk/widgets/templates/widgets/jira/scripts/jira_controller.js >> (added) >> +++ >> incubator/wookie/trunk/widgets/templates/widgets/jira/scripts/jira_controller.js >> Wed Jan 18 20:55:36 2012 >> @@ -0,0 +1,65 @@ >> +/* >> + * Licensed to the Apache Software Foundation (ASF) under one or more >> + * contributor license agreements. See the NOTICE file distributed with >> + * this work for additional information regarding copyright ownership. >> + * The ASF licenses this file to You under the Apache License, Version 2.0 >> + * (the "License"); you may not use this file except in compliance with >> + * the License. You may obtain a copy of the License at >> + * >> + * http://www.apache.org/licenses/LICENSE-2.0 >> + * >> + * Unless required by applicable law or agreed to in writing, software >> + * distributed under the License is distributed on an "AS IS" BASIS, >> + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or >> implied. >> + * See the License for the specific language governing permissions and >> + * limitations under the License. >> + */ >> +${widget.shortname}_browse_controller.requiresLogin=true; >> + >> +// >> +// Hide the search panel until logged in >> +// >> +$('#home').live( 'pageinit',function(event){ >> + $('#searchPanel').hide(); >> +}); >> + >> +/** >> + * Login action >> + * >> + * Sets the username and password to use during this browser session >> + * and toggles the login panel and search panel >> + */ >> +${widget.shortname}_browse_controller.submitLoginForm = function(){ >> + >> + $.mobile.showPageLoadingMsg(); >> + ${widget.shortname}_browse_controller.username = >> $('#usernameString').val(); >> + ${widget.shortname}_browse_controller.password = >> $('#passwordString').val(); >> + >> + // >> + // Check if the credentials can pull down session info; if so they are >> + // correct and we can use them. Note we don't actually create a >> session, we >> + // use Basic Auth for each request, and this is just to check >> credential >> + // validity >> + // >> + // If the credentials are OK, we hide the login form and show the >> search >> + // form. >> + // >> + $.ajax({ >> + url: window.widget.proxify(' >> https://issues.apache.org/jira/rest/auth/1/session')+"&username="+ >> ${widget.shortname}_browse_controller.username + >> "&password="+${widget.shortname}_browse_controller.password, >> + dataType: 'json', >> + success: function(data){ >> + $.mobile.hidePageLoadingMsg(); >> + ${widget.shortname}_browse_controller.requiresLogin=false; >> + $('#loginPanel').hide(); >> + $('#searchPanel').trigger('expand'); >> + $('#searchPanel').show(); >> + }, >> + >> + error: function(){ >> + $.mobile.hidePageLoadingMsg(); >> + $('#loginMessage').text("login rejected, please try again"); >> + } >> + }); >> + >> + >> +} >> >> Added: >> incubator/wookie/trunk/widgets/templates/widgets/jira/widget.properties >> URL: >> http://svn.apache.org/viewvc/incubator/wookie/trunk/widgets/templates/widgets/jira/widget.properties?rev=1233062&view=auto >> >> ============================================================================== >> --- >> incubator/wookie/trunk/widgets/templates/widgets/jira/widget.properties >> (added) >> +++ >> incubator/wookie/trunk/widgets/templates/widgets/jira/widget.properties Wed >> Jan 18 20:55:36 2012 >> @@ -0,0 +1,45 @@ >> +template.name=browse >> +widget.shortname=jira >> +widget.name=Jira >> +widget.description=Info about Wookie from Jira >> + >> +# >> +# The name of the XML element that represents a single item. In a JIRA >> API call, we ignore this as we're using JSON and >> +# the object we're interested in is the top-level array of "version" >> objects >> +# type: string >> +# >> +browse.item.name="" >> + >> +# The URL from which to retrieve data for the browse index. >> +# >> +# type: string >> +# variables: sort = the sort term for APIs that support it >> +# order = the sort order for APIs that support it >> +browse.index.url=" >> https://issues.apache.org/jira/rest/api/latest/project/WOOKIE/versions&username= >> "+${widget.shortname}_browse_controller.username+"&password="+${widget.shortname}_browse_controller.password >> + >> +# The URL from which to retrieve search data. >> +# We override this here with the version API url, but use the query for >> the project name >> +# >> +# type: string >> +# variables: query = query string entered into the search form >> +# sort = the sort term for APIs that support it >> +# order = the sort order for APIs that support it >> +browse.search.url=" >> https://issues.apache.org/jira/rest/api/latest/project/"+query.toUpperCase() >> +"/versions&username="+${widget.shortname}_browse_controller.username+"&password="+${widget.shortname}_browse_controller.password >> + >> + >> +# The URL from which to retrieve detailed >> +# information about an item >> +# >> +# type: string >> +# variables: itemId is the ID of the item to display >> +browse.get.detail.url=" >> https://issues.apache.org/jira/rest/api/latest/version/" + itemId + >> "/unresolvedIssueCount&username="+${widget.shortname}_browse_controller.username+"&password="+${widget.shortname}_browse_controller.password >> + >> +browse.format="json" >> + >> +# >> +# The names of the elements to map into the template placeholders. E.g. >> if it contains "title", then $TITLE in the template >> +# would be replaced by the content of the <title> element in the XML data. >> +# In our case these are the important elements returned by the Jira API >> +# >> +browse.item.elements = "" >> +browse.item.attributes = >> "id,description,name,userReleaseDate,released,issuesUnresolvedCount" >> >> >>
