Skip to content

Instantly share code, notes, and snippets.

@nimezhu
Last active September 25, 2015 15:58
Show Gist options
  • Save nimezhu/88c105424d2ca645946e to your computer and use it in GitHub Desktop.
Save nimezhu/88c105424d2ca645946e to your computer and use it in GitHub Desktop.
get source into data table , template
<!DOCTYPE html>
<html>
<head lang="en">
<meta charset="UTF-8">
<title>ClsViz Data Browser</title>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<script src="http://d3js.org/d3.v3.min.js"></script>
<script src="../../lib/snowflake.js"></script>
</head>
<body>
<div id="main" class="main">
<div id="left" >
<h2>Open...</h2>
<table id="svg_options" class="ctrl_table">
<tr>
<td><b>Source</b></td>
<td><select id="source_option">
<option value="input">Input GSheet or URL</option>
<option value="local_file">Upload your local file</option>
</select>
</td>
</tr>
<tr id="input_row">
<td id="source_input"><b>Source</b> <span style="font-size:8px">URL or Google Sheet ID</span></td>
<td>
<textarea id="source" rows="5" cols="20" placeholder="http://garberwiki.umassmed.edu:8000/data/Jul2015/MDDC_Ifnb.resp.cls.tsv">
</textarea>
</td>
</tr>
<tr id="local_file_row" hidden>
<td id="local_tsv_file">Local TSV File</td><td><input style="width:150px" id="file" type="file" size="10" name="file"></td>
</tr>
</table>
</div>
<div id="canvas">
</div>
</div>
</body>
<script>
(function (S,$) {
var cb=function(data) {
window.data=data;
console.log(data);
}
$("#source_option").on("change",
function(d){
if (this.value=="input") {
$("#input_row").prop("hidden",false)
$("#results_row").prop("hidden",true)
$("#local_file_row").prop("hidden",true)
getSrc(cb)
}
else if(this.value=="local_file") {
$("#input_row").prop("hidden",true)
$("#local_file_row").prop("hidden",false)
getSrc(cb)
//$("#body").removeClass("body_loading")
}
}
)
$("#source").on("change",function(d){getSrc(cb)})
var getSrc=function(callback){
_googleSheetHandler=callback;
var src;
if($("#source_option").val()=="input"){
var url = S.tools.getUrlParam("q");
if (url) {
$("#source").val(url);
}
src= $("#source").val() ||document.getElementById("source").placeholder;
var re=/^http/;
var OK=re.exec(src);
if(OK){
S.tools.parseUrlToTsvUmass(src,callback);
}
else{
S.gsheet.query("select *", src, "_googleSheetHandler")
}
}
else if($("#source_option").val()=="local_file"){
//$("body").removeClass("body_loading")
$("#file").on("change",function(d) {
var ft=$("#file")[0].files[0]
var myfdata ={ "file":ft}
var fdata = new FormData()
for (var key in myfdata) {
fdata.append(key,myfdata[key])
}
var xhr = new XMLHttpRequest;
xhr.open('POST', '../../cgi-bin/parse_tsv.py', true);
xhr.send(fdata);
xhr.onreadystatechange = function() {
if (xhr.readyState == 4) {
var data=JSON.parse(xhr.responseText);
callback(data);
}
}
})
}
}
getSrc(cb);
}
(snowflake,jQuery))
</script>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment