7545a188d43c6e1ea33f692b0d833ec96a7f76c5 chmalee Wed Aug 14 09:21:15 2024 -0700 refactor some methods into userdata.c for writing hub.txt files. Finish trackHubWizard.c back end for writing hub.txt and clean up the html. Start of adding a modal dialog for creating hub.txt diff --git src/hg/hgHubConnect/trackHubWizard.c src/hg/hgHubConnect/trackHubWizard.c index 5b27de0..f7ea546 100644 --- src/hg/hgHubConnect/trackHubWizard.c +++ src/hg/hgHubConnect/trackHubWizard.c @@ -58,65 +58,76 @@ /* Move a file to a new hub */ { } static void writeHubText(char *path, char *userName, char *hubName, char *db) /* Create a hub.txt file, optionally creating the directory holding it */ { int oldUmask = 00; oldUmask = umask(0); makeDirsOnPath(path); // restore umask umask(oldUmask); // now make the hub.txt with some basic information char *hubFile = catTwoStrings(path, "/hub.txt"); FILE *f = mustOpen(hubFile, "w"); -fprintf(stderr, "would write \"hub %s\nemail %s\nshortLabel %s\nlongLabel %s\nuseOneFile on\n\ngenome %s\n\n\" to %s", hubName, emailForUserName(userName), hubName, hubName, db, hubFile); -//fprintf(f, "hub %s\nemail %s\nshortLabel %s\nlongLabel %s\nuseOneFile on\n\ngenome %s\n\n", hubName, emailForUserName(userName), hubName, hubName, db); +//fprintf(stderr, "would write \"hub %s\nemail %s\nshortLabel %s\nlongLabel %s\nuseOneFile on\n\ngenome %s\n\n\" to %s", hubName, emailForUserName(userName), hubName, hubName, db, hubFile); +fprintf(f, "hub %s\n" + "email %s\n" + "shortLabel %s\n" + "longLabel %s\n" + "useOneFile on\n\n" + "genome %s\n\n", + hubName, emailForUserName(userName), hubName, hubName, db); carefulClose(&f); } void doCreateHub(struct cartJson *cj, struct hash *paramHash) /* Make a new hub.txt with the parameters from the JSON request */ { char *userName = getUserName(); if (userName) { struct jsonWrite *errors = jsonWriteNew(); // verify the arguments: (void)cartJsonRequiredParam(paramHash, "createHub", errors, "doCreateHub"); // paramHash is an object with everything necessary to create a hub: name and assembly char *db = jsonStringVal(hashFindVal(paramHash, "db"), "db"); char *name = jsonStringVal(hashFindVal(paramHash, "name"), "name"); fprintf(stderr, "creating hub '%s' for db '%s'\n", name, db); fflush(stderr); // check if this hub already exists, must have a directory and hub.txt already: char *path = prefixUserFile(userName, name); if (isDirectory(path)) { // can't make a hub that already exists! + fprintf(stdout, "Status: 400 Bad Request\n\n"); + fprintf(stdout, "Hub already exists, select hub from dropdown or try a different name"); + fflush(stdout); + exit(1); } else { // good we can make a new directory and stuff a hub.txt in it // the directory needs to be 777, so ignore umask for now writeHubText(path, userName, name, db); + // TODO: add a row to the hubspace table for the hub.txt + // return json to fill out the table + jsonWriteString(cj->jw, "hubName", name); + jsonWriteString(cj->jw, "db", db); } } -fprintf(stderr, "Status: 204 No Content\n\n"); -fflush(stdout); -exit(0); } static void outFilesForUser() /* List out the currently stored files for the user and their sizes */ { char *userName = getUserName(); struct jsonWrite *jw = jsonWriteNew(); // the JSON to return for the client javascript jsonWriteObjectStart(jw, NULL); if (userName) { // the url for this user: jsonWriteString(jw, "userUrl", webDataDir(userName)); jsonWriteListStart(jw, "fileList"); struct hubSpace *file, *fileList = listFilesForUser(userName); for (file = fileList; file != NULL; file = file->next) @@ -134,65 +145,33 @@ } jsonWriteObjectEnd(jw); jsInlineF("var userFiles = %s;\n", dyStringCannibalize(&jw->dy)); jsonWriteFree(&jw); } void doTrackHubWizard() /* Offer an upload form so users can upload all their hub files */ { jsIncludeFile("utils.js", NULL); jsIncludeFile("ajax.js", NULL); jsIncludeFile("lodash.3.10.0.compat.min.js", NULL); jsIncludeFile("cart.js", NULL); jsIncludeFile("tus.js", NULL); jsIncludeFile("hgMyData.js", NULL); -webIncludeResourceFile("../style/bootstrap.min.css"); -webIncludeResourceFile("../style/gb.css"); puts("<link rel=\"stylesheet\" href=\"https://maxcdn.bootstrapcdn.com/font-awesome/4.5.0/css/font-awesome.min.css\">\n"); puts("<link rel=\"stylesheet\" type=\"text/css\" " - "href=\"https://cdn.datatables.net/1.10.12/css/jquery.dataTables.min.css\">\n"); + "href=\"https://cdn.datatables.net/2.1.3/css/dataTables.dataTables.min.css\">\n"); puts("<script type=\"text/javascript\" " - "src=\"https://cdn.datatables.net/1.10.12/js/jquery.dataTables.min.js\"></script>"); -puts("<div id='hubUpload' class='hubList'>\n"); - -puts("<div class='row'>\n"); -puts("<div class='col-md-6'>\n"); -puts("<div class='row'>\n"); -puts("<div class='tabSection'>\n"); -puts("<h4>Create your own hub</h4>\n"); -puts("<p>After choosing files, click \"Create Hub\" to begin uploading the files to our server</p>\n"); -puts("<div class='buttonDiv' id='chooseAndSendFilesRow'>\n"); -puts("<button id='btnForInput' class='button' for=\"chosenFiles\">Choose files</button>\n"); -puts("</div>\n"); // .buttonDiv -puts("<div id='fileList' style=\"clear: right\"></div>\n"); -puts("</div>"); // .tabSection -puts("</div>\n"); // row - -puts("<div class='row'>\n"); -puts("<div class='tabSection'>"); -puts("For information on making track hubs, see the following pages: \n " - "<ul>\n" - "<li><a href='../goldenPath/help/hubQuickStart.html' style='color:#121E9A' target=_blank>Quick Start Guide</a></li>\n" - "<li><a href=\"../goldenPath/help/hgTrackHubHelp.html\" style='color:#121E9A' TARGET=_blank>Track Hub User's Guide</a></li>\n" - "<li><a href=\"../goldenPath/help/hgTrackHubHelp#Hosting\" style='color:#121E9A' target=_blank>Where to Host Your Track Hub</a></li>\n" - "<li><a href=\"../goldenPath/help/trackDb/trackDbHub.html\" style='color:#121E9A' target=_blank>Track Hub Settings Reference</a></li>\n" - "<li><a href=\"../goldenPath/help/publicHubGuidelines.html\" style='color:#121E9A' target=_blank>Guidelines for Submitting a Public Hub</a></li>\n" - "</ul>\n" - "<BR>You may also <a href='../contacts.html' style='color:#121E9A'>contact us</a> if you have any " - "issues or questions on hub development."); -puts("</div>"); // .tabSection -puts("</div>\n"); // col-md-6 -puts("</div>\n"); // row + "src=\"https://cdn.datatables.net/2.1.3/js/dataTables.min.js\"></script>"); +puts("<link rel=\"stylesheet\" type=\"text/css\" " + "href=\"https://cdn.datatables.net/buttons/3.1.1/css/buttons.dataTables.min.css\">\n"); +puts("<script type=\"text/javascript\" " + "src=\"https://cdn.datatables.net/buttons/3.1.1/js/dataTables.buttons.min.js\"></script>"); -puts("<div id='chosenFilesSection' style=\"display: none\" class='col-md-6 tabSection'>"); -puts("<h4>Your uploaded hubs</h4>"); +// the skeleton HTML: webIncludeFile("inc/hgMyData.html"); -puts("</div>\n"); -puts("</div>\n"); // row -puts("</div>\n"); // row // get the current files stored for this user outFilesForUser(); jsInline("$(document).ready(function() {\nhubCreate.init();\n})"); puts("</div>"); }