7033f67074594c3d9cc3487f079456928fdf3260
angie
  Tue Apr 12 13:46:14 2016 -0700
Major change to hgGateway: the contents are replaced by a new page designed by a graphic artist.
It has icons for selecting popular species, an autocomplete input for typing in species or common names,
as well as a phylogenetic tree display that shows the relationships of the species that we host.
It has a menu for selecting the assembly of the selected species' genome and the usual assembly
description.

refs #15277

diff --git src/hg/lib/hubConnect.c src/hg/lib/hubConnect.c
index 28e51c3..e19fe21 100644
--- src/hg/lib/hubConnect.c
+++ src/hg/lib/hubConnect.c
@@ -19,44 +19,54 @@
 #include "hubConnect.h"
 #include "hui.h"
 #include "errCatch.h"
 #include "obscure.h"
 #include "hgConfig.h"
 #include "grp.h"
 
 
 boolean isHubTrack(char *trackName)
 /* Return TRUE if it's a hub track. */
 {
 return startsWith(hubTrackPrefix, trackName);
 }
 
 static char *hubStatusTableName = NULL;
+static char *_hubPublicTableName = NULL;
 
 static char *getHubStatusTableName()
 /* return the hubStatus table name from the environment, 
  * or hg.conf, or use the default.  Cache the result */
 {
 if (hubStatusTableName == NULL)
     hubStatusTableName = cfgOptionEnvDefault("HGDB_HUB_STATUS_TABLE",
 	    hubStatusTableConfVariable, defaultHubStatusTableName);
 
 return hubStatusTableName;
 }
 
+char *hubPublicTableName()
+/* Get the name of the table that lists public hubs.  Don't free the result. */
+{
+if (_hubPublicTableName == NULL)
+    _hubPublicTableName = cfgOptionEnvDefault("HGDB_HUB_PUBLIC_TABLE", hubPublicTableConfVariable,
+                                             defaultHubPublicTableName);
+return _hubPublicTableName;
+}
+
 boolean hubConnectTableExists()
-/* Return TRUE if the hubPublic table exists. */
+/* Return TRUE if the hubStatus table exists. */
 {
 struct sqlConnection *conn = hConnectCentral();
 boolean exists = sqlTableExists(conn, getHubStatusTableName());
 hDisconnectCentral(&conn);
 return exists;
 }
 
 void hubConnectStatusFree(struct hubConnectStatus **pHub)
 /* Free hubConnectStatus */
 {
 struct hubConnectStatus *hub = *pHub;
 if (hub != NULL)
     {
     freeMem(hub->hubUrl);
     freeMem(hub->errorMessage);
@@ -495,31 +505,31 @@
 
 *errorMessage = NULL;
 
 if ((id = getHubId(url, errorMessage)) > 0)
     return id;
 
 getAndSetHubStatus( cart, url, FALSE);
 
 if ((id = getHubId(url, errorMessage)) == 0)
     errAbort("inserted new hubUrl %s, but cannot find it", url);
 
 return id;
 }
 
 // global to hold hubUrl we added if any
-struct hubConnectStatus  *gNewHub;
+static struct hubConnectStatus *gNewHub = NULL;
 
 struct hubConnectStatus  *hubConnectNewHub()
 /* return the hub for the hubUrl we added (if any) */
 {
 return gNewHub;
 }
 
 static void disconnectHubsSamePrefix(struct cart *cart, char *url)
 /* disconnect all the hubs with the same prefix */
 {
 char *prefix = cloneString(url);
 char *ptr = strrchr(prefix, '/');
 if (ptr == NULL)
     return;
 *ptr = 0;
@@ -766,25 +776,62 @@
 
 hubTrackDbs = tdbList;
 if (pGroupList != NULL)
     *pGroupList = hubGroups;
 return tdbList;
 }
 
 static struct hubConnectStatus *globalHubList;
 
 struct hubConnectStatus *hubConnectGetHubs()
 /* return the static global to the track data hubs */
 {
 return globalHubList;
 }
 
+struct trackHub *hubConnectGetHub(char *hubUrl)
+/* Return the connected hub for hubUrl, or NULL if not found.  Do not free result. */
+{
+struct hubConnectStatus *status;
+for (status = globalHubList;  status != NULL;  status = status->next)
+    {
+    if (sameString(status->hubUrl, hubUrl))
+        return status->trackHub;
+    }
+return NULL;
+}
+
+struct trackHub *hubConnectGetHubForDb(char *db)
+/* Return the connected hub for db, or NULL if not found.  Do not free result. */
+{
+unsigned hubId = hubIdFromTrackName(db);
+struct hubConnectStatus *status;
+for (status = globalHubList;  status != NULL;  status = status->next)
+    {
+    if (status->id == hubId)
+        return status->trackHub;
+    }
+return NULL;
+}
+
 char *hubConnectLoadHubs(struct cart *cart)
 /* load the track data hubs.  Set a static global to remember them */
 {
 char *newDatabase = checkForNew( cart);
 cartSetString(cart, hgHubConnectRemakeTrackHub, "on");
 struct hubConnectStatus  *hubList =  hubConnectStatusListFromCart(cart);
 globalHubList = hubList;
 
 return newDatabase;
 }
+
+char *hubNameFromUrl(char *hubUrl)
+/* Given the URL for a hub, return its hub_# name. */
+{
+char query[PATH_LEN*4];
+sqlSafef(query, sizeof(query), "select concat('hub_', id) from %s where hubUrl = '%s'",
+         getHubStatusTableName(), hubUrl);
+struct sqlConnection *conn = hConnectCentral();
+char *name = sqlQuickString(conn, query);
+hDisconnectCentral(&conn);
+return name;
+}