/* configure - Do configuration page. */ #include "common.h" #include "linefile.h" #include "hash.h" #include "cheapcgi.h" #include "obscure.h" #include "jksql.h" #include "htmshell.h" #include "hdb.h" #include "cart.h" #include "web.h" #include "hgExp.h" #include "hgColors.h" #include "hgNear.h" char *configVarName(struct column *col, char *varName) /* Return variable name for configuration. */ { static char name[64]; safef(name, sizeof(name), "%s%s.%s", colConfigPrefix, col->name, varName); return name; } char *configVarVal(struct column *col, char *varName) /* Return value for configuration variable. Return NULL if it * doesn't exist or if it is "" */ { char *name = configVarName(col, varName); return cartNonemptyString(cart, name); } static void configTable(struct column *colList, struct sqlConnection *conn) /* Write out configuration table */ { struct column *col; char varName[128]; boolean isVis; hPrintf("\n"); /* Write out first row - labels. */ hPrintf(""); hPrintf(""); hPrintf(""); hPrintf(""); hPrintf(""); hPrintf(""); /* Print out configuration controls. */ hPrintf(""); /* Write out other rows. */ for (col = colList; col != NULL; col = col->next) { hPrintf(""); /* Do small label. */ hPrintf("", col->shortLabel); /* Do on/off dropdown. */ hPrintf(""); /* Do left/right button */ hPrintf(""); /* Do long label. */ hPrintf("", col->longLabel); /* Do configuration controls. */ if (col->configControls != NULL) col->configControls(col); else hPrintf(""); hPrintf("\n"); } hPrintf("
NameOnPositionDescriptionConfiguration
%s"); safef(varName, sizeof(varName), "%s%s.vis", colConfigPrefix, col->name); isVis = cartUsualBoolean(cart, varName, col->on); cgiMakeCheckBox(varName, isVis); hPrintf(""); safef(varName, sizeof(varName), "near.do.up.%s", col->name); if (col != colList) { hPrintf(""); } safef(varName, sizeof(varName), "near.do.down.%s", col->name); if (col->next != NULL) { hPrintf(""); } hPrintf("%sn/a
\n"); } static void savePriorities(struct column *colList) /* Save priority list. */ { struct dyString *dy = dyStringNew(4*1024); struct column *col; for (col = colList; col != NULL; col = col->next) dyStringPrintf(dy, "%s %f ", col->name, col->priority); cartSetString(cart, colOrderVar, dy->string); dyStringFree(&dy); } static void bumpColList(char *bumpHow, struct column **pColList) /* Bump a column one way or another */ { char *dupe = cloneString(bumpHow); char *words[4], *upDown, *colName; if (chopString(dupe, ".", words, ArraySize(words)) < 4) { warn("Strange bumpHow value %s in bumpColList", bumpHow); cartRemove(cart, bumpHow); noWarnAbort(); } upDown = words[2]; colName = words[3]; if (sameString(upDown, "up")) { struct column *col, *prev = NULL; for (col = *pColList; col != NULL; col = col->next) { if (sameString(col->name, colName)) { if (prev != NULL) { float swap = prev->priority; prev->priority = col->priority; col->priority = swap; } break; } prev = col; } } else { struct column *col, *next = NULL; for (col = *pColList; col != NULL; col = col->next) { if (sameString(col->name, colName)) { if ((next = col->next) != NULL) { float swap = next->priority; next->priority = col->priority; col->priority = swap; } break; } } } freez(&dupe); slSort(pColList, columnCmpPriority); savePriorities(*pColList); } boolean showOnlyCanonical() /* Return TRUE if we only show canonical splicing variants. */ { return !cartUsualBoolean(cart, showAllSpliceVarName, FALSE); } struct userSettings *colUserSettings() /* Return userSettings object for columns. */ { struct userSettings *us = userSettingsNew(cart, "Current Column Configuration", savedCurrentConfName, colSaveSettingsPrefix); userSettingsCapturePrefix(us, colConfigPrefix); userSettingsCaptureVar(us, colOrderVar); return us; } static void configControlPanel() /* Put up configuration control panel. */ { struct userSettings *us = colUserSettings(); controlPanelStart(); hPrintf("\n"); hPrintf("
"); cgiMakeButton("submit", "submit"); hPrintf(" "); hPrintf(" "); hPrintf(""); hPrintf("Columns:"); hPrintf(" "); cgiMakeButton(hideAllConfName, "hide all"); hPrintf(""); cgiMakeButton(showAllConfName, "show all"); hPrintf(""); cgiMakeButton(defaultConfName, "default"); hPrintf(""); hPrintf("Settings:"); hPrintf(""); cgiMakeButton(saveCurrentConfName, "save"); hPrintf(""); cgiMakeOptionalButton(useSavedConfName, "load", !userSettingsAnySaved(us)); hPrintf("
"); hPrintf("\n"); hPrintf("
"); hPrintf("Expression ratio colors: "); hgExpColorDropDown(cart, expRatioColorVarName); hPrintf(""); hPrintf("Show all splicing variants: "); cgiMakeCheckBox(showAllSpliceVarName, cartUsualBoolean(cart, showAllSpliceVarName, FALSE)); hPrintf(""); cgiMakeButton(customPageDoName, "custom columns"); hPrintf("
"); controlPanelEnd(); } void doConfigure(struct sqlConnection *conn, struct column *colList, char *bumpVar) /* Generate configuration page. */ { if (bumpVar) bumpColList(bumpVar, &colList); makeTitle("Configure Gene Sorter", "hgNearHelp.html#Configure"); hPrintf("
\n"); configControlPanel(); cartSaveSession(cart); configTable(colList, conn); hPrintf("
"); } static void restoreDefaultOrder(struct column **pColList) /* Restore order of columns to default using priority settings. */ { struct column *col; for (col = *pColList; col != NULL; col = col->next) { char *priority = columnSetting(col, "priority", NULL); if (priority != NULL) col->priority = atof(priority); } slSort(pColList, columnCmpPriority); } void doDefaultConfigure(struct sqlConnection *conn, struct column *colList) /* Do configuration starting with defaults. */ { struct column *col; for (col=colList; col != NULL; col = col->next) col->on = col->defaultOn; cartRemovePrefix(cart, colConfigPrefix); cartRemove(cart, colOrderVar); restoreDefaultOrder(&colList); doConfigure(conn, colList, NULL); } static void configAllVis(struct sqlConnection *conn, struct column *colList, boolean how) /* Respond to hide all button in configuration page. */ { char varName[64]; struct column *col; for (col = colList; col != NULL; col = col->next) { safef(varName, sizeof(varName), "%s%s.vis", colConfigPrefix, col->name); cartSetBoolean(cart, varName, how); } doConfigure(conn, colList, NULL); } void doConfigHideAll(struct sqlConnection *conn, struct column *colList) /* Respond to hide all button in configuration page. */ { configAllVis(conn, colList, 0); } void doConfigShowAll(struct sqlConnection *conn, struct column *colList) /* Respond to hide all button in configuration page. */ { configAllVis(conn, colList, 1); } void doConfigUseSaved(struct sqlConnection *conn, struct column *colList) /* Respond to Use Saved Settings button in configuration page. */ { struct userSettings *us = colUserSettings(); userSettingsLoadForm(us); } void doNameCurrentColumns() /* Put up page to save current column configuration. */ { struct userSettings *us = colUserSettings(); userSettingsSaveForm(us); } void doSaveCurrentColumns(struct sqlConnection *conn, struct column *colList) /* Save the current columns, and then go on. */ { struct userSettings *us = colUserSettings(); if (userSettingsProcessForm(us)) { refinePriorities(columnHash); slSort(&colList, columnCmpPriority); doConfigure(conn, colList, NULL); } }