b274662adfb195dd49ab8de8bb3d5d92f2fb7ca9
braney
  Sat Aug 6 11:27:33 2011 -0700
add soft-reset button to hgHubConnect (#4815)
diff --git src/hg/hgHubConnect/hgHubConnect.c src/hg/hgHubConnect/hgHubConnect.c
index 839775c..563095d 100644
--- src/hg/hgHubConnect/hgHubConnect.c
+++ src/hg/hgHubConnect/hgHubConnect.c
@@ -14,30 +14,31 @@
 #include "hui.h"
 #include "cart.h"
 #include "dbDb.h"
 #include "web.h"
 #include "trackHub.h"
 #include "hubConnect.h"
 #include "dystring.h"
 #include "hPrint.h"
 #include "jsHelper.h"
 #include "obscure.h"
 
 #define hgHub             "hgHub_"  /* prefix for all control variables */
 #define hgHubDo            hgHub   "do_"    /* prefix for all commands */
 #define hgHubDoClear       hgHubDo "clear"
 #define hgHubDoDisconnect  hgHubDo "disconnect"
+#define hgHubDoReset       hgHubDo "reset"
 
 struct cart *cart;	/* The user's ui state. */
 struct hash *oldVars = NULL;
 
 static char *destUrl = "../cgi-bin/hgTracks";
 static char *pageTitle = "Import Tracks from Data Hubs";
 char *database = NULL;
 char *organism = NULL;
 
 static void ourCellStart()
 {
 puts("<TD>");
 }
 
 static void ourCellEnd()
@@ -101,46 +102,56 @@
 // start first row
 printf("<tbody><tr>");
 
 count = 0;
 for(hub = hubList; hub; hub = hub->next)
     {
     /* if the hub is public, then don't list it here */
     if (!isHubUnlisted(hub))
 	continue;
 
     if (count)
 	webPrintLinkTableNewRow();  // ends last row and starts a new one
     count++;
 
     // if there's an error message, we don't let people select it
-    // these error messages are cleared by the hubDaemon
     if (isEmpty(hub->errorMessage))
 	{
 	ourCellStart();
 	char hubName[32];
 	safef(hubName, sizeof(hubName), "%s%u", hgHubConnectHubVarPrefix, hub->id);
 	cartMakeCheckBox(cart, hubName, FALSE);
 	ourCellEnd();
 	}
     else
-	ourPrintCell("error");
+	{
+	// give people a chance to clear the error 
+	ourCellStart();
+	printf(
+	"<input name=\"hubClearButton\""
+	    "onClick=\"document.resetHubForm.elements['hubUrl'].value='%s';"
+		"document.resetHubForm.submit();return true;\" "
+		"class=\"hubField\" type=\"button\" value=\"clear error\">"
+		, hub->hubUrl);
+	ourCellEnd();
+	}
     ourPrintCell(hub->shortLabel);
     if (isEmpty(hub->errorMessage))
 	ourPrintCell(hub->longLabel);
     else
-	ourPrintCell(hub->errorMessage);
+	printf("<TD>ERROR: %s</TD>", hub->errorMessage);
+
     ourPrintCell(hub->hubUrl);
 
     ourCellStart();
     printf(
     "<input name=\"hubDisconnectButton\""
 	"onClick=\"document.disconnectHubForm.elements['hubId'].value='%d';"
 	    "document.disconnectHubForm.submit();return true;\" "
 	    "class=\"hubField\" type=\"button\" value=\"X\">"
 	    , hub->id);
     ourCellEnd();
     }
 
 printf("</TR></tbody></TABLE>\n");
 printf("</div>");
 }
@@ -194,63 +205,80 @@
 
 	char *errorMessage = NULL;
 	// get an id for this hub
 	unsigned id = hubFindOrAddUrlInStatusTable(database, cart, 
 	    url, &errorMessage);
 
 	if ((id != 0) && isEmpty(errorMessage)) 
 	    {
 	    ourCellStart();
 	    char hubName[32];
 	    safef(hubName, sizeof(hubName), "%s%u", hgHubConnectHubVarPrefix, id);
 	    cartMakeCheckBox(cart, hubName, FALSE);
 	    ourCellEnd();
 	    }
 	else if (!isEmpty(errorMessage))
-	    ourPrintCell("error");
+	    {
+	    // give user a chance to clear the error
+	    ourCellStart();
+	    printf(
+	    "<input name=\"hubClearButton\""
+		"onClick=\"document.resetHubForm.elements['hubUrl'].value='%s';"
+		    "document.resetHubForm.submit();return true;\" "
+		    "class=\"hubField\" type=\"button\" value=\"clear error\">"
+		    , url);
+	    ourCellEnd();
+	    }
 	else
 	    errAbort("cannot get id for hub with url %s\n", url);
 
 	ourPrintCell(shortLabel);
 	if (isEmpty(errorMessage))
 	    ourPrintCell(longLabel);
 	else
-	    {
-	    char errorBuf[4*1024];
-	    safef(errorBuf, sizeof errorBuf, "Error: %s", errorMessage);
-	    ourPrintCell(errorBuf);
-	    }
+	    printf("<TD>ERROR: %s</TD>", errorMessage);
+
 	ourPrintCell(url);
 	}
     }
 sqlFreeResult(&sr);
 
 if (gotAnyRows)
     {
     printf("</TR></tbody></TABLE>\n");
     }
 else
     {
     printf("<div id=\"publicHubs\" class=\"hubList\"> \n");
     printf("No Public Track Hubs for this genome assembly<BR>");
     }
 
 printf("</div>");
 
 hDisconnectCentral(&conn);
 }
 
+static void doResetHub(struct cart *theCart)
+{
+char *url = cartOptionalString(cart, hgHubDataText);
+
+if (url != NULL)
+    hubResetError(url);
+else
+    errAbort("must specify url in %s\n", hgHubDataText);
+}
+
 static void doClearHub(struct cart *theCart)
 {
 char *url = cartOptionalString(cart, hgHubDataText);
 
 printf("<pre>clearing hub %s\n",url);
 if (url != NULL)
     hubClearStatus(url);
 else
     errAbort("must specify url in %s\n", hgHubDataText);
 printf("<pre>Completed\n");
 }
 
 static void doDisconnectHub(struct cart *theCart)
 {
 char *id = cartOptionalString(cart, "hubId");
@@ -260,43 +288,49 @@
     char buffer[1024];
     safef(buffer, sizeof buffer, "hgHubConnect.hub.%s", id);
     cartRemove(cart, buffer);
     }
 
 cartRemove(theCart, "hubId");
 }
 
 void doMiddle(struct cart *theCart)
 /* Write header and body of html page. */
 {
 boolean gotDisconnect = FALSE;
 
 cart = theCart;
 setUdcCacheDir();
+
 if (cartVarExists(cart, hgHubDoClear))
     {
     doClearHub(cart);
     cartWebEnd();
     return;
     }
 
 if (cartVarExists(cart, hgHubDoDisconnect))
     {
     gotDisconnect = TRUE;
     doDisconnectHub(cart);
     }
 
+if (cartVarExists(cart, hgHubDoReset))
+    {
+    doResetHub(cart);
+    }
+
 cartWebStart(cart, NULL, "%s", pageTitle);
 jsIncludeFile("jquery.js", NULL);
 jsIncludeFile("utils.js", NULL);
 jsIncludeFile("jquery-ui.js", NULL);
 
 webIncludeResourceFile("jquery-ui.css");
 
 jsIncludeFile("ajax.js", NULL);
 jsIncludeFile("hgHubConnect.js", NULL);
 webIncludeResourceFile("hgHubConnect.css");
 
 printf("<div id=\"hgHubConnectUI\"> <div id=\"description\"> \n");
 printf(
    "<P>Track data hubs are collections of tracks from outside of UCSC that "
    "can be imported into the Genome Browser.  To import a public hub check "
@@ -316,30 +350,38 @@
 boolean gotNew = hubCheckForNew(database, cart);
 
 // here's a little form for the add new hub button
 printf("<FORM ACTION=\"%s\" NAME=\"addHubForm\">\n",  "../cgi-bin/hgHubConnect");
 cgiMakeHiddenVar("hubUrl", "");
 cgiMakeHiddenVar(hgHubConnectRemakeTrackHub, "on");
 puts("</FORM>");
 
 // this the form for the disconnect hub button
 printf("<FORM ACTION=\"%s\" NAME=\"disconnectHubForm\">\n",  "../cgi-bin/hgHubConnect");
 cgiMakeHiddenVar("hubId", "");
 cgiMakeHiddenVar(hgHubDoDisconnect, "on");
 cgiMakeHiddenVar(hgHubConnectRemakeTrackHub, "on");
 puts("</FORM>");
 
+// this the form for the reset hub button
+printf("<FORM ACTION=\"%s\" NAME=\"resetHubForm\">\n",  "../cgi-bin/hgHubConnect");
+cgiMakeHiddenVar("hubUrl", "");
+cgiMakeHiddenVar(hgHubDoReset, "on");
+cgiMakeHiddenVar(hgHubConnectRemakeTrackHub, "on");
+puts("</FORM>");
+
+
 // ... and now the main form
 if (cartVarExists(cart, hgHubConnectCgiDestUrl))
     destUrl = cartOptionalString(cart, hgHubConnectCgiDestUrl);
 printf("<FORM ACTION=\"%s\" METHOD=\"POST\" NAME=\"mainForm\">\n", destUrl);
 cartSaveSession(cart);
 
 // we have two tabs for the public and unlisted hubs
 printf("<div id=\"tabs\">"
        "<ul> <li><a href=\"#publicHubs\">Public Hubs</a></li>"
        "<li><a href=\"#unlistedHubs\">My Hubs</a></li> "
        "</ul> ");
 
 hgHubConnectPublic();
 hgHubConnectUnlisted();
 printf("</div>");
@@ -353,27 +395,27 @@
     {
     printf("<script type='text/javascript'>\n ");
     printf("var $tabs = $('#tabs').tabs();\n");
     printf(" $tabs.tabs('select',1);\n");
     printf("</script>\n");
     }
 
 cgiMakeHiddenVar(hgHubConnectRemakeTrackHub, "on");
 
 printf("</div>\n");
 puts("</FORM>");
 cartWebEnd();
 }
 
 char *excludeVars[] = {"Submit", "submit", "hc_one_url", 
-    hgHubDoClear, hgHubDoDisconnect, hgHubDataText, 
+    hgHubDoReset, hgHubDoClear, hgHubDoDisconnect, hgHubDataText, 
     hgHubConnectRemakeTrackHub, NULL};
 
 int main(int argc, char *argv[])
 /* Process command line. */
 {
 oldVars = hashNew(10);
 cgiSpoof(&argc, argv);
 cartEmptyShell(doMiddle, hUserCookie(), excludeVars, oldVars);
 return 0;
 }