c79deb301511fcf0de0ed376c7746e4902804472 chmalee Fri May 5 16:59:33 2023 -0700 Experiment number one, can succesfully upload a file and store it via hgCustom. New userdata library for managing where to store the files Get skeleton structure of new cgi together More work in progress, mostly stubbing out the CGI More work in progress, mostly stubbing out the html page diff --git src/hg/js/utils.js src/hg/js/utils.js index 1b9c28a..bb9753c 100644 --- src/hg/js/utils.js +++ src/hg/js/utils.js @@ -4510,17 +4510,112 @@ searchList.splice(searchList.indexOf(searchTerm), 1); } else { searchObj[db].results[searchTerm] = extra; if (searchList.length >= 5) { let toDelete = searchList.pop(); delete searchObj[db].results[toDelete]; } } searchList.unshift(searchTerm); searchObj.stack = searchList; } else { searchObj[db] = {"stack": [searchTerm], "results": {}}; searchObj[db].results[searchTerm] = extra; } window.localStorage.setItem("searchStack", JSON.stringify(searchObj)); + +// variables to parse url arguments correctly +var digitTest = /^\d+$/, + keyBreaker = /([^\[\]]+)|(\[\])/g, + plus = /\+/g, + paramTest = /([^?#]*)(#.*)?$/; + +function deparam(params) { + /* From https://github.com/jupiterjs/jquerymx/blob/master/lang/string/deparam/deparam.js + * Used by the cell browser */ + if(! params || ! paramTest.test(params) ) { + return {}; + } + + var data = {}, + pairs = params.split('&'), + current; + + for (var i=0; i < pairs.length; i++){ + current = data; + var pair = pairs[i].split('='); + + // if we find foo=1+1=2 + if(pair.length !== 2) { + pair = [pair[0], pair.slice(1).join("=")]; + } + + var key = decodeURIComponent(pair[0].replace(plus, " ")), + value = decodeURIComponent(pair[1].replace(plus, " ")), + parts = key.match(keyBreaker); + + for ( var j = 0; j < parts.length - 1; j++ ) { + var part = parts[j]; + if (!current[part] ) { + //if what we are pointing to looks like an array + current[part] = digitTest.test(parts[j+1]) || parts[j+1] === "[]" ? [] : {}; + } + current = current[part]; + } + var lastPart = parts[parts.length - 1]; + if (lastPart === "[]"){ + current.push(value); + } else{ + current[lastPart] = value; + } + } + return data; +} + +function changeUrl(vars, oldVars) { + /* Save the users search string to the url so web browser can easily + * cache search results into the browser history + * vars: object of new key: val pairs like CGI arguments + * oldVars: arguments we want to keep between calls */ + var myUrl = window.location.href; + myUrl = myUrl.replace('#',''); + var urlParts = myUrl.split("?"); + var baseUrl; + if (urlParts.length > 1) + baseUrl = urlParts[0]; + else + baseUrl = myUrl; + + var urlVars; + if (oldVars === undefined) { + var queryStr = urlParts[1]; + urlVars = deparam(queryStr); + } else { + urlVars = oldVars; + } + + for (var key in vars) { + var val = vars[key]; + if (val === null || val === "") { + if (key in urlVars) { + delete urlVars[key]; + } + } else { + urlVars[key] = val; + } + } + + var argStr = jQuery.param(urlVars); + argStr = argStr.replace(/%20/g, "+"); + + return {"baseUrl": baseUrl, "args": argStr, "urlVars": urlVars}; +} + +function saveHistory(obj, urlParts, replace) { + /* Save an object to the web browser's history stack. When we visit the page for the + * first time, we replace the basic state after we are done making the initial UI */ + if (replace) { + history.replaceState(obj, "", urlParts.baseUrl + (urlParts.args.length !== 0 ? "?" + urlParts.args : "")); + } else { + history.pushState(obj, "", urlParts.baseUrl + (urlParts.args.length !== 0 ? "?" + urlParts.args : "")); } }