2ba572dc8bbe18b3398dcf17205dafdd52ab396a
braney
  Sat May 24 10:01:21 2014 -0700
updates to hgHubConnect to interface to make it less confusing.   Nowconnection and disconnection put you on the gateway page.

diff --git src/hg/hgHubConnect/hgHubConnect.c src/hg/hgHubConnect/hgHubConnect.c
index 2b54555..8f9e737 100644
--- src/hg/hgHubConnect/hgHubConnect.c
+++ src/hg/hgHubConnect/hgHubConnect.c
@@ -12,42 +12,34 @@
 #include "htmshell.h"
 #include "hdb.h"
 #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"
 #include "hgConfig.h"
 #include "trix.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"
-#define hgHubDoSearch      hgHubDo "search"
-#define hgHubDoDeleteSearch      hgHubDo "deleteSearch"
 
 struct cart *cart;	/* The user's ui state. */
 struct hash *oldVars = NULL;
 
-static char *destUrl = "../cgi-bin/hgTracks";
 static char *pageTitle = "Track Data Hubs";
 char *database = NULL;
 char *organism = NULL;
 
 static void ourCellStart()
 {
 fputs("<TD>", stdout);  // do not add a newline
 }
 
 static void ourCellEnd()
 {
 puts("</TD>");
 }
 
 static void ourPrintCellLink(char *str, char *url)
@@ -188,51 +180,55 @@
     {
     // nothing to see here
     printf("<tr><td>No Unlisted Track Hubs</td></tr>");
     printf("</thead></table></div>");
     return;
     }
 
 // time to output the big table.  First the header
 printf(
     "<tr> "
 	"<th>Display</th> "
 	"<th>Hub Name</th> "
 	"<th>Description</th> "
 	"<th>Assemblies</th> "
 	"<th>URL</th> "
-	"<th>Disconnect</th> "
     "</tr>\n"
     "</thead>\n");
 
 // start first row
 printf("<tbody><tr>");
 
 int count = 0;
 for(hub = unlistedHubList; hub; hub = hub->next)
     {
     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
     if (isEmpty(hub->errorMessage))
 	{
 	ourCellStart();
 	char hubName[32];
 	safef(hubName, sizeof(hubName), "%s%u", hgHubConnectHubVarPrefix, hub->id);
-	cartMakeCheckBox(cart, hubName, FALSE);
+	if (cartUsualBoolean(cart, hubName, FALSE))
+	    printf("<input name=\"hubDisconnectButton\""
+		"onClick="
+		"\" document.disconnectHubForm.elements['hubId'].value= '%d';"
+		"document.disconnectHubForm.submit();return true;\" "
+		"class=\"hubField\" type=\"button\" value=\"Disconnect\">\n", hub->id);
 	ourCellEnd();
 	}
     else
 	{
 	// 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=\"check hub\">\n"
 		, hub->hubUrl);
 	ourCellEnd();
 	}
     if (hub->trackHub != NULL)
@@ -247,39 +243,30 @@
 
     if (!isEmpty(hub->errorMessage))
 	printf("<TD><span class=\"hubError\">ERROR: %s </span>"
 	    "<a href=\"../goldenPath/help/hgTrackHubHelp.html#Debug\">Debug</a></TD>\n", 
 	    hub->errorMessage);
     else if (hub->trackHub != NULL)
 	ourPrintCell(hub->trackHub->longLabel);
     else
 	ourPrintCell("");
 
     if (hub->trackHub != NULL)
 	printGenomes(hub->trackHub, count);
     else
 	ourPrintCell("");
     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\">\n"
-	    , hub->id);
-    ourCellEnd();
     }
 
 printf("</TR></tbody></TABLE>\n");
 printf("</div>");
 }
 
 static void addPublicHubsToHubStatus(struct sqlConnection *conn, char *publicTable, char  *statusTable)
 /* add url's in the hubPublic table to the hubStatus table if they aren't there already */
 {
 char query[1024];
 sqlSafef(query, sizeof(query), "select hubUrl from %s where hubUrl not in (select hubUrl from %s)\n", publicTable, statusTable); 
 struct sqlResult *sr = sqlGetResult(conn, query);
 char **row;
 while ((row = sqlNextRow(sr)) != NULL)
     {
@@ -357,90 +344,117 @@
 
 struct sqlResult *sr = sqlGetResult(conn, query);
 char **row;
 int count = 0;
 boolean gotAnyRows = FALSE;
 while ((row = sqlNextRow(sr)) != NULL)
     {
     ++count;
     char *url = row[0], *shortLabel = row[1], *longLabel = row[2], 
     	  *dbList = row[3], *errorMessage = row[4], *descriptionUrl = row[6];
     int id = atoi(row[5]);
 
     if ((urlSearchHash != NULL) && (hashLookup(urlSearchHash, url) == NULL))
 	continue;
 
+    struct slName *dbListNames = slNameListFromComma(dbList);
+
     if (gotAnyRows)
 	webPrintLinkTableNewRow();
     else
 	{
 	/* output header */
 	printf("<div id=\"publicHubs\" class=\"hubList\"> \n");
 
 	printf("<table id=\"publicHubsTable\"> "
 	    "<thead><tr> "
 		"<th>Display</th> "
 		"<th>Hub Name</th> "
 		"<th>Description</th> "
 		"<th>Assemblies</th> "
-		"<th>URL</th> "
 	    "</tr></thead>\n");
 
 	// start first row
 	printf("<tbody> <tr>");
 	gotAnyRows = TRUE;
 
 	// allocate the hash to store hubUrl's
 	publicHash = newHash(5);
 	}
 
     if ((id != 0) && isEmpty(errorMessage)) 
 	{
 	ourCellStart();
 	char hubName[32];
 	safef(hubName, sizeof(hubName), "%s%u", hgHubConnectHubVarPrefix, id);
-	cartMakeCheckBox(cart, hubName, FALSE);
+	if (cartUsualBoolean(cart, hubName, FALSE))
+	    printf("<input name=\"hubDisconnectButton\""
+		"onClick="
+		"\" document.disconnectHubForm.elements['hubId'].value= '%d';"
+		"document.disconnectHubForm.submit();return true;\" "
+		"class=\"hubField\" type=\"button\" value=\"Disconnect\">\n", id);
+	else
+	    {
+	    // get first name off of list of supported databases
+	    char * name = dbListNames->name;
+
+	    // if the name isn't currently loaded, we assume it's a hub
+	    if (!hDbExists(name))
+		{
+		char buffer[512];
+
+		safef(buffer, sizeof buffer, "hub_%d_%s",  id, name);
+		name = cloneString(buffer);
+		}
+
+	    printf("<input name=\"hubConnectButton\""
+	    "onClick="
+		"\" document.connectHubForm.elements['hubUrl'].value= '%s';"
+		"document.connectHubForm.elements['db'].value= '%s';"
+		"document.connectHubForm.submit();return true;\" "
+		"class=\"hubField\" type=\"button\" value=\"Connect\">\n", url,name);
+	    }
+
 	ourCellEnd();
 	}
     else if (!isEmpty(errorMessage))
 	{
 	// 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=\"check hub\">"
 		, url);
 	ourCellEnd();
 	}
     else
 	errAbort("cannot get id for hub with url %s\n", url);
 
     if (hasDescription && !isEmpty(descriptionUrl))
 	ourPrintCellLink(shortLabel, descriptionUrl);
     else
 	ourPrintCell(shortLabel);
     if (isEmpty(errorMessage))
 	ourPrintCell(longLabel);
     else
 	printf("<TD><span class=\"hubError\">ERROR: %s </span>"
 	    "<a href=\"../goldenPath/help/hgTrackHubHelp.html#Debug\">Debug</a></TD>", 
 	    errorMessage);
 
-    printGenomeList(slNameListFromComma(dbList), count); // Leaking a bit of memory
-    ourPrintCell(url);
+    printGenomeList(dbListNames, count); 
 
     hashStore(publicHash, url);
     }
 sqlFreeResult(&sr);
 
 if (gotAnyRows)
     {
     printf("</TR></tbody></TABLE>\n");
     printf("</div>");
     }
 return publicHash;
 }
 
 
 struct hash *hgHubConnectPublic()
@@ -497,90 +511,65 @@
     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");
-
-if (id != NULL)
-    {
-    char buffer[1024];
-    safef(buffer, sizeof buffer, "hgHubConnect.hub.%s", id);
-    cartRemove(cart, buffer);
-    }
-
-cartRemove(theCart, "hubId");
-}
 
 static void checkTrackDbs(struct hubConnectStatus *hubList)
 {
 struct hubConnectStatus *hub = hubList;
 
 for(; hub; hub = hub->next)
     {
     struct errCatch *errCatch = errCatchNew();
     if (errCatchStart(errCatch))
 	{
 	hubAddTracks(hub, database);
 	}
     errCatchEnd(errCatch);
     if (errCatch->gotError)
 	{
 	hub->errorMessage = cloneString(errCatch->message->string);
 	hubUpdateStatus( errCatch->message->string, hub);
 	}
     else
 	hubUpdateStatus(NULL, hub);
     }
 }
 
 void doMiddle(struct cart *theCart)
 /* Write header and body of html page. */
 {
-boolean gotDisconnect = FALSE;
-
 cart = theCart;
 
 if (cartVarExists(cart, hgHubDoClear))
     {
     doClearHub(cart);
     cartWebEnd();
     return;
     }
 
-if (cartVarExists(cart, hgHubDoDisconnect))
-    {
-    gotDisconnect = TRUE;
-    doDisconnectHub(cart);
-
-    // now rebuild the cart variable ("trackHubs") that has which lists which
-    // hubs are on.
-    hubConnectHubsInCart(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);
 jsIncludeFile("jquery.cookie.js", NULL);
@@ -606,88 +595,94 @@
 char *surveyLabel = cfgOptionEnv("HGDB_HUB_SURVEY_LABEL", "hubSurveyLabel");
 
 if (survey && differentWord(survey, "off"))
     hPrintf("<span style='background-color:yellow;'><A HREF='%s' TARGET=_BLANK><EM><B>%s</EM></B></A></span>\n", survey, surveyLabel ? surveyLabel : "Take survey");
 hPutc('\n');
 
 // check to see if we have any new hubs
 hubCheckForNew(cart);
 
 // grab all the hubs that are listed in the cart
 struct hubConnectStatus *hubList =  hubConnectStatusListFromCartAll(cart);
 
 checkTrackDbs(hubList);
 
 // here's a little form for the add new hub button
-printf("<FORM ACTION=\"%s\" NAME=\"addHubForm\">\n",  "../cgi-bin/hgHubConnect");
+printf("<FORM ACTION=\"%s\" NAME=\"addHubForm\">\n",  "../cgi-bin/hgGateway");
+cgiMakeHiddenVar("hubUrl", "");
+cgiMakeHiddenVar(hgHubConnectRemakeTrackHub, "on");
+puts("</FORM>");
+
+// this is the form for the connect hub button
+printf("<FORM ACTION=\"%s\" NAME=\"connectHubForm\">\n",  "../cgi-bin/hgGateway");
 cgiMakeHiddenVar("hubUrl", "");
+cgiMakeHiddenVar("db", "");
+cgiMakeHiddenVar(hgHubDoConnect, "on");
 cgiMakeHiddenVar(hgHubConnectRemakeTrackHub, "on");
 puts("</FORM>");
 
 // this is the form for the disconnect hub button
-printf("<FORM ACTION=\"%s\" NAME=\"disconnectHubForm\">\n",  "../cgi-bin/hgHubConnect");
+printf("<FORM ACTION=\"%s\" NAME=\"disconnectHubForm\">\n",  "../cgi-bin/hgGateway");
+cgiMakeHiddenVar("db", "hg19");
 cgiMakeHiddenVar("hubId", "");
 cgiMakeHiddenVar(hgHubDoDisconnect, "on");
 cgiMakeHiddenVar(hgHubConnectRemakeTrackHub, "on");
 puts("</FORM>");
 
 // this is 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>");
 
 // this is the form for the search hub button
 printf("<FORM ACTION=\"%s\" NAME=\"searchHubForm\">\n",  "../cgi-bin/hgHubConnect");
 cgiMakeHiddenVar(hgHubSearchTerms, "");
 cgiMakeHiddenVar(hgHubDoSearch, "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);
+printf("<FORM ACTION=\"%s\" METHOD=\"POST\" NAME=\"mainForm\">\n", "../cgi-bin/hgGateway");
 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> ");
 
 struct hash *publicHash = hgHubConnectPublic();
 hgHubConnectUnlisted(hubList, publicHash);
 printf("</div>");
 
 printf("<div class=\"tabFooter\">");
-cgiMakeButton("Submit", "Use Selected Hubs");
 
 char *emailAddress = cfgOptionDefault("hub.emailAddress","genome@soe.ucsc.edu");
 printf("<span class=\"small\">"
     "Contact <A HREF=\"mailto:%s\">%s</A> to add a public hub."
     "</span>\n", emailAddress,emailAddress);
 printf("</div>");
 
 cgiMakeHiddenVar(hgHubConnectRemakeTrackHub, "on");
 
 printf("</div>\n");
 puts("</FORM>");
 cartWebEnd();
 }
 
 char *excludeVars[] = {"Submit", "submit", "hc_one_url", 
-    hgHubDoReset, hgHubDoClear, hgHubDoDisconnect, hgHubDataText, 
+    hgHubDoReset, hgHubDoClear, hgHubDoDisconnect,hgHubDoConnect, hgHubDataText, 
     hgHubConnectRemakeTrackHub, NULL};
 
 int main(int argc, char *argv[])
 /* Process command line. */
 {
 long enteredMainTime = clock1000();
 oldVars = hashNew(10);
 setUdcCacheDir();
 cgiSpoof(&argc, argv);
 cartEmptyShell(doMiddle, hUserCookie(), excludeVars, oldVars);
 cgiExitTime("hgHubConnect", enteredMainTime);
 return 0;
 }