Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Importing from Published Google Sheet #32

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion examples/upload_file.html
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,10 @@ <h6 class="or"><span>OR</span></h6>
<div class="container_csv_string">
<textarea class="csv_string text_field" placeholder="Paste a CSV string here" ></textarea>
</div>

<h6 class="or"><span>OR</span></h6>
<div class="container_google_sheet">
<input type="text" class="google_sheet text_field" placeholder="Link of published Google Sheet" >
</div>
<div class="upload_button">
<button type="button" class="btn btn-primary" id="upload" >Upload CSV</button>
</div>
Expand Down
53 changes: 53 additions & 0 deletions src/parsing.js
Original file line number Diff line number Diff line change
Expand Up @@ -421,6 +421,54 @@ function handleFileSelectstring(val){
$('.carousel').carousel(1);
determineHeaders(mat);
}
}
function handleFileSelectGoogleSheet(val){

document.getElementById("upload").onclick = function(e){
var sheet_link=val;
$.getJSON(sheet_link, function(data) {
//first row "title" column
var hashSheet=data.feed.entry;
var headers_sheet=[];
for (var key in hashSheet){
var h=hashSheet[key];
for (var headKey in h){
if (headKey.slice(0,4)=="gsx$"){
headers_sheet.push(headKey);
}
}
break;
}
console.log(headers_sheet,"headers_sheet");
var matrixComplete=[];
for (var i=0;i<headers_sheet.length;i++){
matrixComplete[i]=[];
}
console.log(headers_sheet.length);
for (var i=0;i<headers_sheet.length;i++){
for (var key in hashSheet){
var valueCell=hashSheet[key][headers_sheet[i]]["$t"];
if (!isNaN(valueCell)){
matrixComplete[i].push(+valueCell);}
else{
matrixComplete[i].push(valueCell);
}
}
}
console.log(matrixComplete,"matrixComplete");
for (var i=0;i<headers_sheet.length;i++){
headers_sheet[i]=headers_sheet[i].slice(4,headers_sheet[i].length);
}

console.log(headers_sheet,"hh");
extractSampleData(matrixComplete,headers_sheet);
$('.carousel').carousel(1);
});

}

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It might be just Github, but could you please eliminate extra blank lines here, if any? Thanks!



}
//this triggers handleFileSelectLocal function whenever a file is uploaded in the field
$(document).ready(function(){
Expand All @@ -432,6 +480,11 @@ $(document).ready(function(){
$(".csv_string").on('change',function(){
handleFileSelectstring(this.value);
});
$(".google_sheet").on('change',function(){
var sheetLink=this.value;
var sheetURL="https://spreadsheets.google.com/feeds/list/"+sheetLink.split("/")[5]+"/od6/public/values?alt=json";
handleFileSelectGoogleSheet(sheetURL);
});

});
document.getElementById("update_graph").onclick = function(e){
Expand Down