4d2eb49f84199890ac7e679ba67f094cb49bd124
braney
  Thu Apr 6 14:29:02 2023 -0700
Change recommended track sets to merge with the current session.  refs #28525

diff --git src/hg/hgTracks/hgTracks.c src/hg/hgTracks/hgTracks.c
index d3fea01..ab74a65 100644
--- src/hg/hgTracks/hgTracks.c
+++ src/hg/hgTracks/hgTracks.c
@@ -244,45 +244,50 @@
 {
 const struct group *a = *((struct group **)va);
 const struct group *b = *((struct group **)vb);
 float dif = a->priority - b->priority;
 
 if (dif == 0)
     return 0;
 if (dif < 0)
    return -1;
 else if (dif == 0.0)
    return 0;
 else
    return 1;
 }
 
-void changeTrackVis(struct group *groupList, char *groupTarget, int changeVis)
+void changeTrackVisExclude(struct group *groupList, char *groupTarget, int changeVis, struct hash *excludeHash)
 /* Change track visibilities. 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.
  * If we are going back to default visibility, then reset the track
- * ordering also. */
+ * ordering also. 
+ * If excludeHash is not NULL then don't change the visibility of the group names in that hash.
+ */
 {
 struct group *group;
 if (changeVis == -2)
     return;
 for (group = groupList; group != NULL; group = group->next)
     {
     struct trackRef *tr;
+    if (excludeHash && hashLookup(excludeHash, group->name))
+        continue;
+
     if (groupTarget == NULL || sameString(group->name,groupTarget))
         {
         static char pname[512];
         /* if default vis then reset group priority */
         if (changeVis == -1)
             group->priority = group->defaultPriority;
         for (tr = group->trackList; tr != NULL; tr = tr->next)
             {
             struct track *track = tr->track;
             struct trackDb *tdb = track->tdb;
             if (changeVis == -1) // to default
                 {
                 if (tdbIsComposite(tdb))
                     {
                     safef(pname, sizeof(pname),"%s.*",track->track); //to remove all settings associated with this composite!
@@ -354,30 +359,42 @@
                         {
                         if (changeVis == tvHide)               // Since subtrack level vis is an
                             cartRemove(cart, subtrack->track); // override, simply remove to hide
                         else
                             cartSetString(cart, subtrack->track, hStringFromTv(changeVis));
                         subtrack->visibility = changeVis;
                         }
                     }
                 }
             }
         }
     }
 slSort(&groupList, gCmpPriority);
 }
 
+void changeTrackVis(struct group *groupList, char *groupTarget, int changeVis)
+/* Change track visibilities. 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.
+ * If we are going back to default visibility, then reset the track
+ * ordering also. */
+{
+changeTrackVisExclude(groupList, groupTarget, changeVis, NULL);
+}
+
 int trackOffsetX()
 /* Return x offset where track display proper begins. */
 {
 int x = gfxBorder;
 if (withLeftLabels)
     x += tl.leftLabelWidth + gfxBorder;
 return x;
 }
 
 
 static void mapBoxTrackUi(struct hvGfx *hvg, int x, int y, int width,
                           int height, char *name, char *shortLabel, char *id)
 /* Print out image map rectangle that invokes hgTrackUi. */
 {
 x = hvGfxAdjXW(hvg, x, width);
@@ -7150,30 +7167,66 @@
     struct sqlConnection *conn = wikiConnect();
     if (sqlTableExists(conn, "variome"))
         addVariomeWikiTrack(&trackList);
     wikiDisconnect(&conn);
     }
 
 struct grp *grpList = NULL;
 if (cartOptionalString(cart, "hgt.trackNameFilter") == NULL)
     { // If a single track was asked for and it is from a hub, then it is already in trackList
     loadTrackHubs(&trackList, &grpList);
     }
 loadCustomTracks(&trackList);
 makeDupeTracks(&trackList);
 groupTracks( &trackList, pGroupList, grpList, vis);
 setSearchedTrackToPackOrFull(trackList);
+char *rtsLoad = cgiOptionalString( "rtsLoad");
+if (rtsLoad)  // load a recommended track set
+    {
+    // store session name and user
+    char *otherUserName = cartOptionalString(cart, hgsOtherUserName);
+    char *otherUserSessionName = rtsLoad;
+
+    // Hide all tracks except custom tracks
+    struct hash *excludeHash = newHash(2);
+    hashStore(excludeHash, "user");
+    changeTrackVisExclude(groupList, NULL, tvHide, excludeHash);
+
+    // delete any ordering we have
+    char wildCard[32];
+    safef(wildCard,sizeof(wildCard),"*_%s",IMG_ORDER_VAR);
+    cartRemoveLike(cart, wildCard);
+
+    // now we have to restart to load the session since that happens at cart initialization
+    
+    char newUrl[4096];
+    safef(newUrl, sizeof newUrl,
+        "./hgTracks?"
+        hgsOtherUserSessionName "=%s"
+        "&" hgsOtherUserName "=%s"
+        "&" hgsMergeCart "=on"
+        "&" hgsDoOtherUser "=submit"
+	"& hgsid=%s"
+        , otherUserSessionName, otherUserName,cartSessionId(cart));
+
+    cartCheckout(&cart);   // make sure cart records all our changes above
+
+    // output the redirect and exit
+    printf("<META HTTP-EQUIV=\"REFRESH\" CONTENT=\"0;URL=%s\">", newUrl);
+    exit(0);
+    }
+
 boolean hideTracks = cgiOptionalString( "hideTracks") != NULL;
 if (hideTracks)
     changeTrackVis(groupList, NULL, tvHide);    // set all top-level tracks to hide
 
 /* Get visibility values if any from ui. */
 struct hash *superTrackHash = newHash(5);  // cache whether supertrack is hiding tracks or not
 char buffer[4096];
 
 // Check to see if we have a versioned default gene track and let the knownGene 
 // cart variable determine its visibility
 char *defaultGeneTrack = NULL;
 char *knownDb = hdbDefaultKnownDb(database);
 if (differentString(knownDb, database))
     defaultGeneTrack = hdbGetMasterGeneTrack(knownDb);