4288d963377a85706ba950b7cfb68689c25d8b7b
max
Tue Jul 9 10:11:03 2013 -0700
adding iframeUrl and iframeOptions trackDb options to hgc. They allow to show an external webpage directly on the hgc page
diff --git src/hg/hgc/hgc.c src/hg/hgc/hgc.c
index 88d6cf4..77dae99 100644
--- src/hg/hgc/hgc.c
+++ src/hg/hgc/hgc.c
@@ -920,31 +920,31 @@
printf("
\n%s\n", html->html);
itemDetailsHtmlFreeList(&htmls);
hFreeConn(&conn);
}
}
char *getIdInUrl(struct trackDb *tdb, char *itemName)
/* If we have an idInUrlSql tag, look up itemName in that, else just
* return itemName. */
{
char *sql = trackDbSetting(tdb, "idInUrlSql");
char *id = itemName;
if (sql != NULL)
{
char buf[256];
- safef(buf, sizeof(buf), sql, itemName);
+ sqlSafef(buf, sizeof(buf), sql, itemName);
struct sqlConnection *conn = hAllocConn(database);
id = sqlQuickString(conn, buf);
hFreeConn(&conn);
}
return id;
}
char* replaceInUrl(struct trackDb *tdb, char *url, char *idInUrl, boolean encode)
/* replace $$ in url with idInUrl. Supports many other wildchards */
{
struct dyString *uUrl = NULL;
struct dyString *eUrl = NULL;
char startString[64], endString[64];
char *ins[9], *outs[9];
char *eItem = (encode ? cgiEncode(idInUrl) : cloneString(idInUrl));
@@ -998,59 +998,90 @@
// check the url setting prefix and get the correct url setting from trackDb
char *url;
if (sameWord(urlSetting, "url"))
url = tdb->url;
else
url = trackDbSetting(tdb, urlSetting);
if (url == NULL || url[0] == 0)
return NULL;
char* eUrl = replaceInUrl(tdb, url, idInUrl, encode);
return eUrl;
}
+void printIframe(struct trackDb *tdb, char *itemName)
+/* print an iframe with the URL specified in trackDb (iframeUrl), can have
+ * the standard codes in it (like $$ for itemName, etc)
+ */
+{
+char* eUrl = constructUrl(tdb, "iframeUrl", itemName, FALSE);
+if (eUrl==NULL)
+ return;
+
+char *iframeOptions = trackDbSettingOrDefault(tdb, "iframeOptions", "width='100%%' height='1024'");
+// Resizing requires the hgcDetails pages to include a bit of javascript.
+//
+// Explanation how this works and why the javascript is needed:
+// http://stackoverflow.com/questions/153152/resizing-an-iframe-based-on-content
+// In short:
+// - iframes have a fixed size in html, resizing can only be done in javascript
+// - the iframed page cannot call the resize() function in the hgc html directly, as they have
+// been loaded from different webservers
+// - one way around it is that the iframed page includes a helper page on our server and
+// send their size to the helper page (pages can call functions of included pages)
+// - the helper page then sends the size back to hgc (pages on the same server can
+// call each others' functions)
+// width='%s' height='%s' src='%s' seamless scrolling='%s' frameborder='%s'
+
+printf(" \
+ \
+ \
+ \
+
", eUrl, iframeOptions);
+}
+
void printCustomUrlWithLabel(struct trackDb *tdb, char *itemName, char *itemLabel, char *urlSetting, boolean encode)
/* Print custom URL specified in trackDb settings. */
{
char urlLabelSetting[32];
-// first try to resolve itemName via an optional sql statement to something else
-char *idInUrl = getIdInUrl(tdb, itemName);
-if (idInUrl == NULL)
- return;
-
// replace the $$ and other wildchards with the url given in tdb
-char* eUrl = constructUrl(tdb, urlSetting, idInUrl, encode);
+char* eUrl = constructUrl(tdb, urlSetting, itemName, encode);
if (eUrl==NULL)
return;
/* create the url label setting for trackDb from the url
setting prefix */
safef(urlLabelSetting, sizeof(urlLabelSetting), "%sLabel", urlSetting);
printf("%s ",
trackDbSettingOrDefault(tdb, urlLabelSetting, "Outside Link:"));
printf("", eUrl);
if (sameWord(tdb->table, "npredGene"))
{
- printf("%s (%s)
\n", idInUrl, "NCBI MapView");
+ printf("%s (%s)
\n", itemName, "NCBI MapView");
}
else
{
- char *label = idInUrl;
+ char *label = itemName;
if (isNotEmpty(itemLabel) && !sameString(itemName, itemLabel))
label = itemLabel;
printf("%s
\n", label);
}
//freeMem(&eUrl); small memory leak
}
void printCustomUrl(struct trackDb *tdb, char *itemName, boolean encode)
/* Wrapper to call printCustomUrlWithLabel using the url setting in trackDb */
{
char urlSetting[10];
safef(urlSetting, sizeof(urlSetting), "url");
printCustomUrlWithLabel(tdb, itemName, itemName, urlSetting, encode);
}
@@ -3834,31 +3865,35 @@
{
type = words[0];
if (sameString(type, "maf") || sameString(type, "wigMaf") || sameString(type, "netAlign")
|| sameString(type, "encodePeak"))
headerItem = NULL;
else if (( sameString(type, "narrowPeak")
|| sameString(type, "broadPeak")
|| sameString(type, "gappedPeak") )
&& headerItem
&& sameString(headerItem, ".") )
headerItem = NULL;
}
/* Print header. */
genericHeader(tdb, headerItem);
+
+itemForUrl = getIdInUrl(tdb, item);
printCustomUrl(tdb, itemForUrl, item == itemForUrl);
+printIframe(tdb, itemForUrl);
+
if (plus != NULL)
{
fputs(plus, stdout);
}
if (container != NULL)
{
genericContainerClick(conn, container, tdb, item, itemForUrl);
}
else if (wordCount > 0)
{
type = words[0];
if (sameString(type, "bed"))
{
int num = 0;