Commit f02ab9c5 authored by Joe TS Dell's avatar Joe TS Dell
Browse files

update excel function as callback

parent 3dd6bb83
Pipeline #3349 passed with stage
in 24 seconds
...@@ -4,171 +4,181 @@ ...@@ -4,171 +4,181 @@
var jsonContent = []; var jsonContent = [];
var bibAuthors = ""; var bibAuthors = "";
var bit1stAuthorLN =""; var bit1stAuthorLN = "";
/* set up XMLHttpRequest */
var url = "./content/CitationSheet3.xlsx"; var url = "./content/CitationSheet3.xlsx";
var xmlHttpRequest = new XMLHttpRequest(); var xmlHttpRequest = new XMLHttpRequest();
xmlHttpRequest.open("GET", url, true);
xmlHttpRequest.responseType = "arraybuffer";
xmlHttpRequest.onload = function (e) {
var arraybuffer = xmlHttpRequest.response;
// convert data to binary string //
var data = new Uint8Array(arraybuffer);
var arr = new Array();
for (var i = 0; i != data.length; ++i) arr[i] = String.fromCharCode(data[i]);
var bstr = arr.join("");
// Call XLSX //
var workbook = XLSX.read(bstr, {
type: "binary"
});
// DO SOMETHING WITH workbook HERE //
var first_sheet_name = workbook.SheetNames[0];
// Get worksheet //
var worksheet = workbook.Sheets[first_sheet_name];
var jsonOutput = XLSX.utils.sheet_to_json(worksheet);
// console.log(jsonOutput);
for (i = 0; i < jsonOutput.length; i++) { var load_excel_citation = function (cb) {
var authors; xmlHttpRequest.open("GET", url, true);
if (jsonOutput[i].Authors != undefined){ xmlHttpRequest.responseType = "arraybuffer";
authors = jsonOutput[i].Authors.replace("and ", "").trim().split(","); xmlHttpRequest.onload = function (e) {
} var arraybuffer = xmlHttpRequest.response;
var bibAuthors;
var item = { // convert data to binary string //
"item": { var data = new Uint8Array(arraybuffer);
"title": "", var arr = new Array();
"project": "", for (var i = 0; i != data.length; ++i) arr[i] = String.fromCharCode(data[i]);
"authors": [], var bstr = arr.join("");
"imageLink": "",
"keywords": "", // Call XLSX //
"journal": { var workbook = XLSX.read(bstr, {
"name": "journal", type: "binary"
"volume": "", });
"year": "",
"pages": "" // DO SOMETHING WITH workbook HERE //
var first_sheet_name = workbook.SheetNames[0];
// Get worksheet //
var worksheet = workbook.Sheets[first_sheet_name];
var jsonOutput = XLSX.utils.sheet_to_json(worksheet);
// console.log(jsonOutput);
for (i = 0; i < jsonOutput.length; i++) {
var authors;
if (jsonOutput[i].Authors != undefined) {
authors = jsonOutput[i].Authors.replace("and ", "").trim().split(",");
}
var bibAuthors;
var item = {
"item": {
"title": "",
"project": "",
"authors": [],
"imageLink": "",
"keywords": "",
"journal": {
"name": "journal",
"volume": "",
"year": "",
"pages": ""
},
"conference": {
"name": "",
"place": "",
"date": ""
},
"DOI": "",
"publisher": "",
"type": "",
"project": "",
"reviewed": "",
"open": ""
}, },
"conference":{ "links": {
"name":"", "pdf": "",
"place":"", "url": "",
"date":"" "demo": ""
}, },
"DOI": "", "bibtex": ""
"publisher":"",
"type":"",
"project":"",
"reviewed":"",
"open":""
},
"links": {
"pdf": "",
"url": "",
"demo": ""
},
"bibtex" : ""
}
bibAuthors = "";
bit1stAuthorLN ="";
for (j = 0; j < authors.length; j++) {
var author = {
"firstName": "",
"lastName": ""
} }
if (authors[j].trim().split(" ").length == 1) {
author["firstName"] = authors[j].trim().split(".")[0];
author["lastName"] = authors[j].trim().split(".")[1]; bibAuthors = "";
item["item"].authors.push(author); bit1stAuthorLN = "";
bibAuthors+=authors[j].trim().split(".")[1] + ", "+ authors[j].trim().split(".")[0]+ " and "; for (j = 0; j < authors.length; j++) {
} else if (authors[j].trim().split(" ").length == 2) { var author = {
author["firstName"] = authors[j].trim().split(" ")[0]; "firstName": "",
author["lastName"] = authors[j].trim().split(" ")[1]; "lastName": ""
item["item"].authors.push(author); }
bibAuthors+=authors[j].trim().split(" ")[1] + ", "+ authors[j].trim().split(" ")[0]+ " and "; if (authors[j].trim().split(" ").length == 1) {
} else if (authors[j].trim().split(" ").length == 3) { author["firstName"] = authors[j].trim().split(".")[0];
author["firstName"] = authors[j].trim().split(" ")[0]; author["lastName"] = authors[j].trim().split(".")[1];
author["lastName"] = authors[j].trim().split(" ")[2]; item["item"].authors.push(author);
item["item"].authors.push(author); bibAuthors += authors[j].trim().split(".")[1] + ", " + authors[j].trim().split(".")[0] + " and ";
bibAuthors+=authors[j].trim().split(" ")[2] + ", "+ authors[j].trim().split(" ")[0]+ " and "; } else if (authors[j].trim().split(" ").length == 2) {
author["firstName"] = authors[j].trim().split(" ")[0];
author["lastName"] = authors[j].trim().split(" ")[1];
item["item"].authors.push(author);
bibAuthors += authors[j].trim().split(" ")[1] + ", " + authors[j].trim().split(" ")[0] + " and ";
} else if (authors[j].trim().split(" ").length == 3) {
author["firstName"] = authors[j].trim().split(" ")[0];
author["lastName"] = authors[j].trim().split(" ")[2];
item["item"].authors.push(author);
bibAuthors += authors[j].trim().split(" ")[2] + ", " + authors[j].trim().split(" ")[0] + " and ";
}
} }
} if (jsonOutput[i].Keywords != undefined) {
item["item"].keywords = jsonOutput[i].Keywords.split(",");
if (jsonOutput[i].Keywords != undefined) { } else {
item["item"].keywords = jsonOutput[i].Keywords.split(","); item["item"].keywords = jsonOutput[i].Keywords;
} else { }
item["item"].keywords = jsonOutput[i].Keywords;
} if (authors[0].split(" ").length == 3) {
bit1stAuthorLN = authors[0].split(" ")[2];
if (authors[0].split(" ").length == 3 ){ } else if (authors[0].split(" ").length == 2) {
bit1stAuthorLN = authors[0].split(" ")[2]; bit1stAuthorLN = authors[0].split(" ")[1];
} else if (authors[0].split(" ").length == 2 ){ } else if (authors[0].split(" ").length == 1) {
bit1stAuthorLN = authors[0].split(" ")[1]; bit1stAuthorLN = authors[0].split(" ")[0];
} else if (authors[0].split(" ").length == 1 ){ }
bit1stAuthorLN = authors[0].split(" ")[0];
} item["item"].title = jsonOutput[i].Titel;
item["item"].project = jsonOutput[i].Project;
item["item"].title = jsonOutput[i].Titel; item["item"].imageLink = jsonOutput[i]["Path to demo image"]
item["item"].project = jsonOutput[i].Project; item["item"].journal.name = jsonOutput[i].Journal;
item["item"].imageLink = jsonOutput[i]["Path to demo image"] item["item"].journal.volume = jsonOutput[i].Volume;
item["item"].journal.name = jsonOutput[i].Journal; item["item"].journal.year = jsonOutput[i].Year;
item["item"].journal.volume = jsonOutput[i].Volume;
item["item"].journal.year = jsonOutput[i].Year; item["item"].journal.pages = jsonOutput[i].Pages;
item["item"].conference.name = jsonOutput[i].Conference;
item["item"].journal.pages = jsonOutput[i].Pages; item["item"].conference.place = jsonOutput[i]["City and Country"]
item["item"].conference.name = jsonOutput[i].Conference; item["item"].conference.date = jsonOutput[i].Date;
item["item"].conference.place = jsonOutput[i]["City and Country"] item["item"].publisher = jsonOutput[i].Publisher;
item["item"].conference.date = jsonOutput[i].Date; item["item"].type = jsonOutput[i]["Type of Work"];
item["item"].publisher = jsonOutput[i].Publisher; item["item"].project = jsonOutput[i].Project;
item["item"].type = jsonOutput[i]["Type of Work"]; item["item"].reviewed = jsonOutput[i]["Peer-Reviewed"];
item["item"].project = jsonOutput[i].Project; item["item"].open = jsonOutput[i]["Open Access"];
item["item"].reviewed = jsonOutput[i]["Peer-Reviewed"]; item["item"].DOI = jsonOutput[i].DOI;
item["item"].open = jsonOutput[i]["Open Access"]; item["links"].pdf = jsonOutput[i].PDF_Link;
item["item"].DOI = jsonOutput[i].DOI; item["links"].url = jsonOutput[i].URL;
item["links"].pdf = jsonOutput[i].PDF_Link; item["links"].demo = jsonOutput[i].Demo;
item["links"].url = jsonOutput[i].URL;
item["links"].demo = jsonOutput[i].Demo;
var month = "";
if (jsonOutput[i].Date != undefined) {
var month = ""; month = jsonOutput[i].Date.split(",")[0].trim();
if (jsonOutput[i].Date != undefined){ }
month = jsonOutput[i].Date.split(",")[0].trim();
//// BibTex /////////////////////
item["bibtex"] = "@article{" + bit1stAuthorLN + jsonOutput[i].Year + "," +
"title={" + jsonOutput[i].Titel +
"},author={" + bibAuthors.trim().substring(0, bibAuthors.trim().lastIndexOf(" ")) +
"},journal={" + jsonOutput[i].Journal +
"},volume={" + jsonOutput[i].Volume +
"},month={" + month +
"},pages={" + jsonOutput[i].Pages +
"},year={" + jsonOutput[i].Year +
"},DOI ={" + jsonOutput[i].DOI +
"},url ={" + jsonOutput[i].URL +
"}}"
jsonContent.push(item);
} }
// console.log(jsonContent);
//// BibTex /////////////////////
item["bibtex"] = "@article{"+ bit1stAuthorLN + jsonOutput[i].Year +","+
"title={"+ jsonOutput[i].Titel +
"},author={"+ bibAuthors.trim().substring(0, bibAuthors.trim().lastIndexOf(" ")) +
"},journal={"+ jsonOutput[i].Journal +
"},volume={"+ jsonOutput[i].Volume +
"},month={"+ month +
"},pages={"+ jsonOutput[i].Pages +
"},year={"+ jsonOutput[i].Year +
"},DOI ={"+ jsonOutput[i].DOI+
"},url ={"+ jsonOutput[i].URL+
"}}"
jsonContent.push(item);
} }
console.log(jsonContent); xmlHttpRequest.send();
cb() // callback
} }
xmlHttpRequest.send();
// str = str.substring(0, lastIndex);
// // get paper from the Sabo result
// ending of xlsx to json coversion load_excel_citation(function () {
// stuff_paper = jsonContent;
var new_row = document.getElementById("cont_paper")
new_row.innerHTML = "";
var arrayLength = stuff_paper.length;
for (var i = 0; i < arrayLength; i++) {
if (Math.abs(arrayLength - i) <= max_paper_list) {
console.log("close to " + i)
addpaper(stuff_paper[i]);
}
//Do something
}
})
\ No newline at end of file
var json_to_bib = function (json_content) {
// Sabo Add Script here
}
\ No newline at end of file
...@@ -94,21 +94,8 @@ $(document).ready(function () { ...@@ -94,21 +94,8 @@ $(document).ready(function () {
// } // }
// }); // });
// get paper from the Sabo result
stuff_paper = jsonContent;
var new_row = document.getElementById("cont_paper")
new_row.innerHTML = "";
var arrayLength = stuff_paper.length;
for (var i = 0; i < arrayLength; i++) {
if (Math.abs(arrayLength - i) <= max_paper_list) {
console.log("close to " + i)
addpaper(stuff_paper[i]);
}
//Do something
}
json_to_bib(stuff_paper)
var userLang = navigator.language || navigator.userLanguage; var userLang = navigator.language || navigator.userLanguage;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment