static void trackConfig(struct track *trackList, struct group *groupList, char *groupTarget, int changeVis) /* Put up track configurations. If groupTarget is * NULL then set visibility for tracks in all groups. Otherwise, * just set it for the given group. If vis is -2, then visibility is * unchanged. If -1 then set visibility to default, otherwise it should * be tvHide, tvDense, etc. */ { struct group *group; boolean showedRuler = FALSE; setRulerMode(); changeTrackVis(groupList, groupTarget, changeVis); /* Set up ruler mode according to changeVis. */ #ifdef BOB_DOESNT_LIKE if (changeVis != -2) { if (groupTarget == NULL || (groupList != NULL && sameString(groupTarget, groupList->name))) { if (changeVis == -1) rulerMode = tvFull; else rulerMode = changeVis; } } #endif /* BOB_DOESNT_LIKE */ jsInit(); cgiMakeHiddenVar(configGroupTarget, "none"); // Now all groups are in a single table, divided by an empty borderless row hPrintf("<TABLE BORDER='0' CELLSPACING='0' class='groupLists'>\n"); for (group = groupList; group != NULL; group = group->next) { struct trackRef *tr; if (group->trackList == NULL) continue; /* check if group section should be displayed */ char *otherState; char *indicator; char *indicatorImg; boolean isOpen = !isCollapsedGroup(group); collapseGroupGoodies(isOpen, FALSE, &indicatorImg, &indicator, &otherState); hPrintf("<TR NOWRAP class='blueToggleBar'>"); hPrintf("<TH NOWRAP align='left' colspan=3>"); hPrintf("<table style='width:100%%;'><tr class='noData'><td style='text-align:left;'>"); hPrintf("\n<A NAME='%sGroup'></A>",group->name); hPrintf("<input type=hidden name='%s' id='%s' value=%d>", collapseGroupVar(group->name),collapseGroupVar(group->name), (isOpen?0:1)); char idText[256]; safef(idText, sizeof idText, "%s_button", group->name); hPrintf("<IMG class='toggleButton' " "id='%s' src='%s' alt='%s' title='%s this group'> ", idText, indicatorImg, indicator,isOpen?"Collapse":"Expand"); // TODO XSS filter group->name jsOnEventByIdF("click", idText, "return vis.toggleForGroup(this,'%s');", group->name); hPrintf("<B> %s</B> ", group->label); hPrintf(" "); hPrintf("</td><td style='text-align:right;'>\n"); safef(idText, sizeof idText, "%s_hideAllBut", group->name); hPrintf("<INPUT TYPE=SUBMIT NAME=\"%s\" id='%s' VALUE=\"%s\" " "title='Hide all tracks in this groups'>", configHideAll, idText, "hide all"); // TODO XSS filter configGroupTarget char jsText[256]; // used several times safef(jsText, sizeof jsText, "document.mainForm.%s.value='%s'; %s", configGroupTarget, group->name, jsSetVerticalPosition("mainForm")); jsOnEventById("click", idText, jsText); hPrintf(" "); safef(idText, sizeof idText, "%s_showAllBut", group->name); hPrintf("<INPUT TYPE=SUBMIT NAME=\"%s\" id='%s' VALUE=\"%s\" " "title='Show all tracks in this groups'>", configShowAll, idText, "show all"); jsOnEventById("click", idText, jsText); hPrintf(" "); safef(idText, sizeof idText, "%s_defaultBut", group->name); hPrintf("<INPUT TYPE=SUBMIT NAME=\"%s\" id='%s' VALUE=\"%s\" " "title='Show default tracks in this group'>", configDefaultAll, idText, "default"); jsOnEventById("click", idText, jsText); hPrintf(" "); /* do not want all the submit buttons named the same. It is * confusing to the javascript submit() function. */ char submitName[256]; safef(submitName, sizeof(submitName), "%sSubmit", group->name); cgiMakeButtonWithMsg(submitName, "submit","Submit your selections and view them in the browser"); hPrintf("</td></tr></table>\n"); hPrintf("</TH></TR>\n"); /* First non-CT, non-hub group gets ruler. */ if (!showedRuler && !isHubTrack(group->name) && differentString(group->name, "user")) { showedRuler = TRUE; hPrintf("<TR %sid='%s-0'>",(isOpen ? "" : "style='display: none'"), group->name); hPrintf("<TD>"); hPrintf("<A HREF=\"%s?%s=%s&c=%s&g=%s&hgTracksConfigPage=configure\">", hgTrackUiName(), cartSessionVarName(), cartSessionId(cart), chromName, RULER_TRACK_NAME); hPrintf("%s</A>", RULER_TRACK_LABEL); hPrintf("</TD><TD>"); hTvDropDownClass("ruler", rulerMode, FALSE, rulerMode ? "normalText" : "hiddenText"); hPrintf("</TD><TD>"); hPrintf("Chromosome position in bases. (Clicks here zoom in 3x)"); hPrintf("</TD></TR>\n"); } /* Scan track list to determine which supertracks have visible member * tracks, and to insert a track in the list for the supertrack. * Sort tracks and supertracks together by priority */ makeGlobalTrackHash(trackList); groupTrackListAddSuper(cart, group); if (!withPriorityOverride) { /* sort hierarchically by priority, considering supertracks */ struct trackRef *refList = NULL, *ref; for (tr = group->trackList; tr != NULL; tr = tr->next) { struct track *track = tr->track; if (tdbIsSuperTrackChild(track->tdb)) /* ignore supertrack member tracks till supertrack is found */ continue; AllocVar(ref); ref->track = track; slAddTail(&refList, ref); if (tdbIsSuper(track->tdb)) { struct slRef *child = track->tdb->children; for (; child != NULL; child=child->next) { struct trackDb *childTdb = child->val; struct track *childTrack = hashFindVal(trackHash, childTdb->track); // Try adding downloadsOnly track if (childTrack == NULL && tdbIsDownloadsOnly(childTdb)) { AllocVar(childTrack); // Fake a track! childTrack->tdb = childTdb; childTrack->hasUi = FALSE; } if (childTrack != NULL) { AllocVar(ref); ref->track = childTrack; slAddTail(&refList, ref); } } } } group->trackList = refList; } /* Loop through this group and display */ int rowCount=1; for (tr = group->trackList; tr != NULL; tr = tr->next) { struct track *track = tr->track; struct trackDb *tdb = track->tdb; hPrintf("<TR %sid='%s-%d'>",(isOpen ? "" : "style='display: none;'"), group->name, rowCount++); hPrintf("<TD NOWRAP>"); if (tdbIsSuperTrackChild(tdb)) /* indent members of a supertrack */ hPrintf(" "); // Print an icon before the title when one is defined hPrintPennantIcon(tdb); if (track->hasUi) hPrintf("<A TITLE='%s%s...' HREF='%s?%s=%s&g=%s&hgTracksConfigPage=configure'>", tdb->parent ? "Part of super track: " : "Configure ", tdb->parent ? tdb->parent->shortLabel : tdb->shortLabel, hTrackUiForTrack(tdb->track), cartSessionVarName(), cartSessionId(cart), track->track); hPrintf(" %s", tdb->shortLabel); if (tdbIsSuper(tdb)) hPrintf("..."); if (track->hasUi) hPrintf("</A>"); hPrintf("</TD><TD NOWRAP>"); if (tdbIsSuperTrackChild(tdb)) /* indent members of a supertrack */ hPrintf(" "); /* If track is not on this chrom print an informational message for the user. */ if (tdbIsDownloadsOnly(tdb)) // No vis display for downloadsOnly hPrintf("<A TITLE='Downloadable files...' HREF='%s?%s=%s&g=%s'>Downloads</A>", hgFileUiName(),cartSessionVarName(), cartSessionId(cart), tdb->track); else if (hTrackOnChrom(track->tdb, chromName)) { if (tdbIsSuper(track->tdb)) { /* supertrack dropdown is hide/show */ superTrackDropDown(cart, track->tdb, 1); } else { /* check for option of limiting visibility to one mode */ hTvDropDownClassVisOnly(track->track, track->visibility, rTdbTreeCanPack(track->tdb), (track->visibility == tvHide) ? "hiddenText" : "normalText", trackDbSetting(track->tdb, "onlyVisibility")); } } else hPrintf("[No data-%s]", chromName); hPrintf("</TD><TD NOWRAP>"); hPrintf("%s", tdb->longLabel); hPrintf("</TD></TR>\n"); } hPrintf("<tr class='noData'><td colspan=3>"); cgiDown(0.9); hPrintf("</td></tr>\n"); } hPrintf("</TABLE>\n"); }
static struct jsonWrite *rTdbToJw(struct trackDb *tdb, struct hash *fieldHash, struct hash *excludeTypesHash, int depth, int maxDepth) /* Recursively build and return a new jsonWrite object with JSON for tdb and its children, * or NULL if tdb or all children have been filtered out by excludeTypesHash. * If excludeTypesHash is non-NULL, omit any tracks/views/subtracks with type in excludeTypesHash. * If fieldHash is non-NULL, include only the field names indexed in fieldHash. */ { if (maxDepth >= 0 && depth > maxDepth) return NULL; boolean doSubtracks = (tdb->subtracks && fieldOk("subtracks", fieldHash)); // If excludeTypesHash is given and tdb is a leaf track/subtrack, look up the first word // of tdb->type in excludeTypesHash; if found, return NULL. if (excludeTypesHash && !doSubtracks) { char typeCopy[PATH_LEN]; safecpy(typeCopy, sizeof(typeCopy), tdb->type); if (hashLookup(excludeTypesHash, firstWordInLine(typeCopy))) return NULL; } boolean gotSomething = !doSubtracks; struct jsonWrite *jwNew = jsonWriteNew(); jsonWriteObjectStart(jwNew, NULL); writeTdbSimple(jwNew, tdb, fieldHash); if (tdb->parent && fieldOk("parent", fieldHash)) { // We can't link to an object in JSON and better not recurse here or else infinite loop. if (tdbIsSuperTrackChild(tdb)) { // Supertracks have been omitted from fullTrackList, so add the supertrack object's // non-parent/child info here. jsonWriteObjectStart(jwNew, "parent"); writeTdbSimple(jwNew, tdb->parent, fieldHash); jsonWriteObjectEnd(jwNew); } else // Just the name so we don't have infinite loops. jsonWriteString(jwNew, "parent", tdb->parent->track); } if (doSubtracks) { jsonWriteListStart(jwNew, "subtracks"); slSort(&tdb->subtracks, trackDbViewCmp); struct trackDb *subTdb; for (subTdb = tdb->subtracks; subTdb != NULL; subTdb = subTdb->next) { struct jsonWrite *jwSub = rTdbToJw(subTdb, fieldHash, excludeTypesHash, depth+1, maxDepth); if (jwSub) { gotSomething = TRUE; jsonWriteAppend(jwNew, NULL, jwSub); jsonWriteFree(&jwSub); } } jsonWriteListEnd(jwNew); } jsonWriteObjectEnd(jwNew); if (! gotSomething) // All children were excluded; clean up and null out jwNew. jsonWriteFree(&jwNew); return jwNew; }
static void hgPositionsJson(struct jsonWrite *jw, char *db, struct hgPositions *hgp, struct cart *cart) /* Write out JSON description of multiple position matches. */ { struct hgPosTable *table; jsonWriteListStart(jw, "positionMatches"); struct trackDb *tdbList = NULL; for (table = hgp->tableList; table != NULL; table = table->next) { if (table->posList != NULL) { char *tableName = table->name; // clear the tdb cache if this track is a hub track if (isHubTrack(tableName)) tdbList = NULL; struct trackDb *tdb = tdbForTrack(db, tableName, &tdbList); if (!tdb && startsWith("all_", tableName)) tdb = tdbForTrack(db, tableName+strlen("all_"), &tdbList); if (!tdb) errAbort("no track for table \"%s\" found via a findSpec", tableName); char *trackName = tdb->track; jsonWriteObjectStart(jw, NULL); jsonWriteString(jw, "name", table->name); jsonWriteString(jw, "trackName", trackName); jsonWriteString(jw, "description", table->description); jsonWriteString(jw, "vis", hCarefulTrackOpenVis(db, trackName)); jsonWriteListStart(jw, "matches"); struct hgPos *pos; for (pos = table->posList; pos != NULL; pos = pos->next) { char *encMatches = cgiEncode(pos->browserName); jsonWriteObjectStart(jw, NULL); // begin one match if (pos->chrom != NULL) jsonWriteStringf(jw, "position", "%s:%d-%d", pos->chrom, pos->chromStart+1, pos->chromEnd); else // GenBank results set position to GB accession instead of chr:s-e position. jsonWriteString(jw, "position", pos->name); // this is magic to tell the browser to make the // composite and this subTrack visible if (tdb->parent) { if (tdbIsSuperTrackChild(tdb)) jsonWriteStringf(jw, "extraSel", "%s=show&", tdb->parent->track); else { // tdb is a subtrack of a composite or a view jsonWriteStringf(jw, "extraSel", "%s_sel=1&%s_sel=1&", trackName, tdb->parent->track); } } jsonWriteString(jw, "hgFindMatches", encMatches); jsonWriteString(jw, "posName", htmlEncodeText(pos->name, FALSE)); if (pos->description) { stripString(pos->description, "\n"); jsonWriteString(jw, "description", stripAnchor(pos->description)); } jsonWriteObjectEnd(jw); // end one match } jsonWriteListEnd(jw); // end matches jsonWriteObjectEnd(jw); // end one table } } jsonWriteListEnd(jw); // end positionMatches }
static void trackConfig(struct track *trackList, struct group *groupList, char *groupTarget, int changeVis) /* Put up track configurations. If groupTarget is * NULL then set visibility for tracks in all groups. Otherwise, * just set it for the given group. If vis is -2, then visibility is * unchanged. If -1 then set visibility to default, otherwise it should * be tvHide, tvDense, etc. */ { #ifdef PRIORITY_CHANGES_IN_CONFIG_UI char pname[512]; char gname[512]; #endif///def PRIORITY_CHANGES_IN_CONFIG_UI struct group *group; boolean showedRuler = FALSE; setRulerMode(); changeTrackVis(groupList, groupTarget, changeVis); /* Set up ruler mode according to changeVis. */ #ifdef BOB_DOESNT_LIKE if (changeVis != -2) { if (groupTarget == NULL || (groupList != NULL && sameString(groupTarget, groupList->name))) { if (changeVis == -1) rulerMode = tvFull; else rulerMode = changeVis; } } #endif /* BOB_DOESNT_LIKE */ jsInit(); cgiMakeHiddenVar(configGroupTarget, "none"); boolean isFirstNotCtGroup = TRUE; for (group = groupList; group != NULL; group = group->next) { struct trackRef *tr; if (group->trackList == NULL) continue; /* check if group section should be displayed */ char *otherState; char *indicator; char *indicatorImg; boolean isOpen = !isCollapsedGroup(group); collapseGroupGoodies(isOpen, FALSE, &indicatorImg, &indicator, &otherState); hTableStart(); hPrintf("<TR NOWRAP>"); hPrintf("<TH NOWRAP align=\"left\" colspan=3 BGCOLOR=#536ED3>"); hPrintf("\n<A NAME='%sGroup'></A>",group->name); hPrintf("<input type=hidden name='%s' id='%s' value=%d>", collapseGroupVar(group->name),collapseGroupVar(group->name), (isOpen?0:1)); hPrintf("<A HREF='%s?%s&%s=%s#%sGroup' class='bigBlue'><IMG height=22 width=22 onclick=\"return toggleTrackGroupVisibility(this,'%s');\" id='%s_button' src='%s' alt='%s' class='bigBlue' title='%s this group'></A> ", hgTracksName(), cartSidUrlString(cart),collapseGroupVar(group->name), otherState, group->name, group->name, group->name, indicatorImg, indicator,isOpen?"Collapse":"Expand"); hPrintf("<B> %s</B> ", wrapWhiteFont(group->label)); hPrintf(" "); hPrintf("<INPUT TYPE=SUBMIT NAME=\"%s\" VALUE=\"%s\" " "onClick=\"document.mainForm.%s.value='%s'; %s\" title='Hide all tracks in this groups'>", configHideAll, "hide all", configGroupTarget, group->name, jsSetVerticalPosition("mainForm")); hPrintf(" "); hPrintf("<INPUT TYPE=SUBMIT NAME=\"%s\" VALUE=\"%s\" " "onClick=\"document.mainForm.%s.value='%s'; %s\" title='Show all tracks in this groups'>", configShowAll, "show all", configGroupTarget, group->name, jsSetVerticalPosition("mainForm")); hPrintf(" "); hPrintf("<INPUT TYPE=SUBMIT NAME=\"%s\" VALUE=\"%s\" " "onClick=\"document.mainForm.%s.value='%s'; %s\" title='Show default tracks in this group'>", configDefaultAll, "default", configGroupTarget, group->name, jsSetVerticalPosition("mainForm")); hPrintf(" "); /* do not want all the submit buttons named the same. It is * confusing to the javascript submit() function. */ char submitName[256]; safef(submitName, sizeof(submitName), "%sSubmit", group->name); cgiMakeButtonWithMsg(submitName, "submit","Submit your selections and view them in the browser"); #ifdef PRIORITY_CHANGES_IN_CONFIG_UI if (withPriorityOverride) { hPrintf(" "); hPrintf(" "); hPrintf(" "); hPrintf("%s", wrapWhiteFont("Group Order: ")); } #endif///def PRIORITY_CHANGES_IN_CONFIG_UI hPrintf("</TH>\n"); #ifdef PRIORITY_CHANGES_IN_CONFIG_UI if (withPriorityOverride) { hPrintf("<TH>\n"); safef(pname, sizeof(pname), "%s.priority",group->name); hDoubleVar(pname, (double)group->priority, 4); hPrintf("</TH>\n"); if (isOpen) hPrintf("<TH align=CENTER BGCOLOR=#536ED3><B> %s</B></TH> ", wrapWhiteFont("Group")); hPrintf("\n"); } #endif///def PRIORITY_CHANGES_IN_CONFIG_UI hPrintf("</TR>\n"); /* First non-CT group gets ruler. */ if (!showedRuler && isFirstNotCtGroup && differentString(group->name, "user")) { showedRuler = TRUE; hPrintf("<TR %sid='%s-0'>",(isOpen ? "" : "style='display: none'"), group->name); hPrintf("<TD>"); hPrintf("<A HREF=\"%s?%s=%u&c=%s&g=%s&hgTracksConfigPage=configure\">", hgTrackUiName(), cartSessionVarName(), cartSessionId(cart), chromName, RULER_TRACK_NAME); hPrintf("%s</A>", RULER_TRACK_LABEL); hPrintf("</TD>"); hPrintf("<TD>"); hTvDropDownClass("ruler", rulerMode, FALSE, rulerMode ? "normalText" : "hiddenText"); hPrintf("</TD>"); hPrintf("<TD>"); hPrintf("Chromosome position in bases. (Clicks here zoom in 3x)"); hPrintf("</TD>"); #ifdef PRIORITY_CHANGES_IN_CONFIG_UI if (withPriorityOverride) { hPrintf("<TD>"); hPrintf("</TD>"); hPrintf("<TD>"); hPrintf("</TD>"); } #endif///def PRIORITY_CHANGES_IN_CONFIG_UI hPrintf("</TR>\n"); } if (differentString(group->name, "user")) isFirstNotCtGroup = FALSE; /* Scan track list to determine which supertracks have visible member * tracks, and to insert a track in the list for the supertrack. * Sort tracks and supertracks together by priority */ groupTrackListAddSuper(cart, group); if (!withPriorityOverride) { /* sort hierarchically by priority, considering supertracks */ struct trackRef *refList = NULL, *ref; for (tr = group->trackList; tr != NULL; tr = tr->next) { struct track *track = tr->track; if (tdbIsSuperTrackChild(track->tdb)) /* ignore supertrack member tracks till supertrack is found */ continue; AllocVar(ref); ref->track = track; slAddTail(&refList, ref); if (tdbIsSuper(track->tdb)) { struct trackRef *tr2; for (tr2 = group->trackList; tr2 != NULL; tr2 = tr2->next) { char *parent = tr2->track->tdb->parentName; if (parent && sameString(parent, track->track)) { AllocVar(ref); ref->track = tr2->track; slAddTail(&refList, ref); } } } } group->trackList = refList; } /* Loop through this group and display */ int rowCount=1; for (tr = group->trackList; tr != NULL; tr = tr->next) { struct track *track = tr->track; struct trackDb *tdb = track->tdb; hPrintf("<TR %sid='%s-%d'>",(isOpen ? "" : "style='display: none'"),group->name, rowCount++); hPrintf("<TD NOWRAP>"); if (tdbIsSuperTrackChild(tdb)) /* indent members of a supertrack */ hPrintf(" "); // Print an icon before the title when one is defined hPrintPennantIcon(track->tdb); if (track->hasUi) hPrintf("<A %s%s%s HREF=\"%s?%s=%u&g=%s&hgTracksConfigPage=configure\">", tdb->parent ? "TITLE=\"Part of super track: " : "", tdb->parent ? tdb->parent->shortLabel : "", tdb->parent ? "...\"" : "", hgTrackUiName(), cartSessionVarName(), cartSessionId(cart), track->track); hPrintf(" %s", track->shortLabel); if (tdbIsSuper(track->tdb)) hPrintf("..."); if (track->hasUi) hPrintf("</A>"); hPrintf("</TD>"); hPrintf("<TD NOWRAP>"); if (tdbIsSuperTrackChild(tdb)) /* indent members of a supertrack */ hPrintf(" "); /* If track is not on this chrom print an informational message for the user. */ if (hTrackOnChrom(track->tdb, chromName)) { if (tdbIsSuper(track->tdb)) { /* supertrack dropdown is hide/show */ superTrackDropDown(cart, track->tdb, 1); } else { /* check for option of limiting visibility to one mode */ hTvDropDownClassVisOnly(track->track, track->visibility, track->canPack, (track->visibility == tvHide) ? "hiddenText" : "normalText", trackDbSetting(track->tdb, "onlyVisibility")); } } else hPrintf("[No data-%s]", chromName); hPrintf("</TD>"); hPrintf("<TD NOWRAP>"); hPrintf("%s", track->longLabel); hPrintf("</TD>"); #ifdef PRIORITY_CHANGES_IN_CONFIG_UI if (withPriorityOverride) { hPrintf("<TD>"); safef(pname, sizeof(pname), "%s.priority",track->track); hDoubleVar(pname, (double)track->priority, 4); hPrintf("</TD>"); hPrintf("<TD>\n"); /* suppress group pull-down for supertrack members */ if (tdbIsSuperTrackChild(track->tdb)) hPrintf(" "); else { safef(gname, sizeof(gname), "%s.group",track->track); printGroupListHtml(gname, groupList, track->groupName); } hPrintf("</TD>"); } #endif///def PRIORITY_CHANGES_IN_CONFIG_UI hPrintf("</TR>\n"); } hTableEnd(); hPrintf("<BR>"); } }