2c925794c53b18f05b37e8f1ff2b0493b440289f
galt
Thu Dec 4 13:12:34 2014 -0800
Fixes #14173. Enables more sophisticated link to table browser from hgGene, hgc, and hgTrackUi, if the table exists and is not a custom track, then hgTables will launch with the table automatically selected. We are really just restoring functionality that we used to have -- and which got nuked when we were simplifying and unifying our menus and adding submenus a few years ago.
diff --git src/hg/lib/web.c src/hg/lib/web.c
index a9d4ae9..f8325c3 100644
--- src/hg/lib/web.c
+++ src/hg/lib/web.c
@@ -209,31 +209,31 @@
puts(""
""
"");
puts("
");
}
else
{
puts("
");
}
puts("" "\n"
"" "\n" );
}
/* Put up the hot links bar. */
-char *menuStr = menuBar(theCart);
+char *menuStr = menuBar(theCart, db);
if(menuStr)
{
puts(menuStr);
}
if (endsWith(scriptName, "hgGateway") && geoMirrorEnabled())
{
// Show an opt-out alert if user is on a host to which user has been automatically redirected (just once, right after they have been redirected)
char *source = cgiOptionalString("source");
char *redirect = cgiOptionalString("redirect");
if (source != NULL && redirect != NULL && sameString(redirect, "auto"))
{
char *domain = cgiServerName();
char *port = cgiServerPort();
// We don't bother maintaining stuff in request URI, because it may contain items like hgsid and other host specific values
@@ -1231,33 +1231,36 @@
}
// overrides for default context specific help link.
char *contextSpecificHelpLink = NULL;
char *contextSpecificHelpLabel = NULL;
void setContextSpecificHelp(char *link, char *label)
// Override default behavior for the context specific help link
{
if(link)
contextSpecificHelpLink = cloneString(link);
if(label)
contextSpecificHelpLabel = cloneString(label);
}
-char *menuBar(struct cart *cart)
+char *menuBar(struct cart *cart, char *db)
// Return HTML for the menu bar (read from a configuration file);
// we fixup internal CGI's to add hgsid's and include the appropriate js and css files.
+//
+// Note this function is also called by hgTracks which extends the menu bar
+// with a View menu defined in hgTracks/menu.c
{
char *docRoot = hDocumentRoot();
char *menuStr, buf[4096], uiVars[128];
FILE *fd;
int len, offset, err;
char *navBarFile = "inc/globalNavBar.inc";
struct stat statBuf;
regex_t re;
regmatch_t match[2];
char *scriptName = cgiScriptName();
if (cart)
safef(uiVars, sizeof(uiVars), "%s=%s", cartSessionVarName(), cartSessionId(cart));
else
uiVars[0] = 0;
@@ -1289,30 +1292,53 @@
struct dyString *dy = newDyString(0);
for(offset = 0; offset < len && !regexec(&re, menuStr + offset, ArraySize(match), match, 0); offset += match[0].rm_eo)
{
dyStringAppendN(dy, menuStr + offset, match[0].rm_eo);
if(match[1].rm_so == match[1].rm_eo)
dyStringAppend(dy, "?");
dyStringAppend(dy, uiVars);
if(match[1].rm_so != match[1].rm_eo)
dyStringAppend(dy, "&");
}
if(offset < len)
dyStringAppend(dy, menuStr + offset);
freez(&menuStr);
menuStr = dyStringCannibalize(&dy);
}
+
+if(scriptName)
+ {
+ // Provide hgTables options for some CGIs.
+ char hgTablesOptions[1024] = "";
+ char *table = (cart == NULL ? NULL :
+ (endsWith(scriptName, "hgGene") ?
+ cartOptionalString(cart, "hgg_type") :
+ cartOptionalString(cart, "g")));
+ if (table && cart && db &&
+ (endsWith(scriptName, "hgc") || endsWith(scriptName, "hgTrackUi") ||
+ endsWith(scriptName, "hgGene")))
+ {
+ struct trackDb *tdb = hTrackDbForTrack(db, table);
+ if (tdb != NULL)
+ safef(hgTablesOptions, sizeof hgTablesOptions,
+ "../cgi-bin/hgTables?hgta_doMainPage=1&hgta_group=%s&hgta_track=%s&hgta_table=%s&",
+ tdb->grp, tdb->track, tdb->table);
+ menuStr = replaceChars(menuStr, "../cgi-bin/hgTables?", hgTablesOptions);
+ trackDbFree(&tdb);
+ }
+ }
+
if(!loginSystemEnabled())
stripRegEx(menuStr, "<\\!-- LOGIN_START -->.*<\\!-- LOGIN_END -->", REG_ICASE);
if(scriptName)
{ // Provide optional official mirror servers menu items
char *geoMenu = geoMirrorMenu();
char *pattern = "";
char *newMenuStr = replaceChars(menuStr, pattern, geoMenu);
freez(&menuStr);
menuStr = newMenuStr;
}
if(scriptName)
{
@@ -1324,30 +1350,34 @@
safef(buf, sizeof(buf), "../cgi-bin/hgGenome?%s&hgGenome_doPsOutput=1", uiVars);
dyStringPrintf(viewItems, "