Show a message when no matching projects are found
Show a message when no matching projects are found

--- a/js/projectsearch.js
+++ b/js/projectsearch.js
@@ -25,9 +25,12 @@
 
 	var visibleCats = [];
 
+	var hasmatch = false;
+
 	$('table.projectList tr.projectRow').each(function() {
 		if (search.length < 1) {
 			$(this).show();
+			hasmatch = true;
 			return;
 		}
 
@@ -37,6 +40,7 @@
 		if (projectName.length > 0) {
 			if (projectName.indexOf(search) != -1) {
 				$(this).show();
+				hasmatch = true;
 				category = $(this).data('category');
 				if (category) {
 					if (jQuery.inArray(category, visibleCats) == -1) {
@@ -50,6 +54,7 @@
 		if (projectDesc.length > 0) {
 			if (projectDesc.indexOf(search) != -1) {
 				$(this).show();
+				hasmatch = true;
 				category = $(this).data('category');
 				if (category) {
 					if (jQuery.inArray(category, visibleCats) == -1) {
@@ -63,6 +68,7 @@
 		if (projectOwner.length > 0) {
 			if (projectOwner.indexOf(search) != -1) {
 				$(this).show();
+				hasmatch = true;
 				category = $(this).data('category');
 				if (category) {
 					if (jQuery.inArray(category, visibleCats) == -1) {
@@ -91,6 +97,24 @@
 		}
 	});
 
+	var msgDiv = $('div.message');
+	if (hasmatch) {
+		msgDiv.hide();
+		$('tr.projectHeader').show();
+	} else {
+		if (msgDiv.length == 0) {
+			msgDiv = jQuery(document.createElement('div'));
+			msgDiv.addClass('message');
+			msgDiv.appendTo($('table.projectList'));
+		}
+
+		var msg = GITPHP_RES_NO_MATCHES_FOUND.replace(new RegExp('%1'), search);
+		msgDiv.text(msg);
+
+		msgDiv.show();
+		$('tr.projectHeader').hide();
+	}
+
 	$('img.searchSpinner').hide();
 }
 
@@ -101,9 +125,16 @@
 		}
 	});
 
+	var rows = $('table.projectList tr');
+
+	if (rows.length == 0) {
+		// No projects, just stop
+		return;
+	}
+
 	// Store project categories
 	var category = '';
-	$('table.projectList tr').each(function() {
+	rows.each(function() {
 		if ($(this).hasClass('categoryRow')) {
 			category = $(this).children('th.categoryName').text();
 		} else if ($(this).hasClass('projectRow')) {

--- a/templates/header.tpl
+++ b/templates/header.tpl
@@ -29,6 +29,7 @@
       var GITPHP_RES_LOADING="{t escape='js'}Loading…{/t}";
       var GITPHP_RES_LOADING_BLAME_DATA="{t escape='js'}Loading blame data…{/t}";
       var GITPHP_RES_SNAPSHOT="{t escape='js'}snapshot{/t}";
+      var GITPHP_RES_NO_MATCHES_FOUND='{t escape=no}No matches found for "%1"{/t}';
       var GITPHP_SNAPSHOT_FORMATS = {ldelim}
       {foreach from=$snapshotformats key=format item=extension name=formats}
         "{$format}": "{$extension}"{if !$smarty.foreach.formats.last},{/if}

--- a/templates/projectlist.tpl
+++ b/templates/projectlist.tpl
@@ -28,7 +28,7 @@
   {foreach name=projects from=$projectlist item=proj}
     {if $smarty.foreach.projects.first}
       {* Header *}
-      <tr>
+      <tr class="projectHeader">
         {if $order == "project"}
           <th>{t}Project{/t}</th>
         {else}
@@ -96,7 +96,11 @@
       </td>
     </tr>
   {foreachelse}
+    {if $search}
+    <div class="message">{t 1=$search}No matches found for "%1"{/t}</div>
+    {else}
     <div class="message">{t}No projects found{/t}</div>
+    {/if}
   {/foreach}
 
 </table>

comments