Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
added cpg/hg19 import page
  • Loading branch information
yuj12001 committed Sep 25, 2015
1 parent 727ad02 commit e845f71
Show file tree
Hide file tree
Showing 2 changed files with 123 additions and 2 deletions.
106 changes: 106 additions & 0 deletions ImportFiles.html
@@ -0,0 +1,106 @@
<html>
<head>
<script src="http://code.jquery.com/jquery-1.10.2.min.js"></script>
</head>
<body>
<div id="uploadFile">
table name: <input type="text" id="fname"><br>
</div>
</body>
</html>

<script>
this.makeUploadForm = function() {
var fileInput = document.createElement('input');
fileInput.type = 'file';


fileInput.addEventListener('change', function (e) {
var file = fileInput.files[0];
var textType = /text.*/;
if (file.type.match(textType)) {
var reader = new FileReader();

reader.onload = function (e) {
var Data = reader.result;
var name = document.getElementById("fname").value;
uploadFile(Data,name);
}

reader.readAsText(file);

} else {
alert("File not supported!");

}

});

var f = document.createElement("form");
fileInput.style.display="inline";
f.innerHTML = "upload file:";
f.appendChild(fileInput);
document.getElementById("uploadFile").appendChild(f);

}
this.makeUploadForm();


var uploadFile = function(data,name){

var fileArray = data.split("\n");
headerArray = fileArray[0].split("\t");

dataToSend = '';
counter = 3000;

for(i = 0; i < fileArray.length; i++){


dataToSend += "\n"+ fileArray[i];

counter--;
if(counter == 0){
dataToSend = dataToSend.trim();
dataToSend = "\n"+dataToSend;
$.ajax({
url: "dynamic_loading.php",
type: 'POST',
dataType: "json",
data: {
"header": headerArray,
"upload": dataToSend,
"tableName": name
}

}).success(function (data) {

}).error(function (req, status, error) {
$("body").append(status + ": " + error);
});
dataToSend = '';
counter = 3000;

}
}

dataToSend = dataToSend.trim();
dataToSend = "\n"+dataToSend;
$.ajax({
url: "dynamic_loading.php",
type: 'POST',
dataType: "json",
data: {
"header": headerArray,
"upload": dataToSend,
"tableName": name
}

}).success(function (data) {

}).error(function (req, status, error) {
$("body").append(status + ": " + error);
});

}
</script>
19 changes: 17 additions & 2 deletions dynamic_loading.php
Expand Up @@ -19,8 +19,15 @@
if (isset($_POST["upload"])){
$timestamp = (new DateTime())->getTimestamp();
$data = parseData($_POST["upload"]);
$result = insertToDb($timestamp, $_POST["header"],$data);
ajaxReturn($result);
if(isset($_POST["tableName"])){
$result = insertToDb($_POST["tableName"], $_POST["header"],$data);
ajaxReturn($result);
}
else{
$result = insertToDb($timestamp, $_POST["header"],$data);
ajaxReturn($result);
}

}
else if (isset($_POST["processData"])){
$serviceUrl = $_POST["processData"];
Expand Down Expand Up @@ -853,6 +860,14 @@
// echo $result;
mysqli_query ($link,$result);
}


$sql = "SELECT @n:=0";
mysqli_query ($link,$sql);

$sql = "UPDATE ".$tableName." SET ID = @n := @n + 1";
mysqli_query ($link,$sql);

return $tableName;
//echo json_encode($tableName);
}
Expand Down

0 comments on commit e845f71

Please sign in to comment.