Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import * as jsPDF from 'jspdf';
- import * as Blob from 'blob';
- // var JsonData = [ [ { publication_id: 14,
- // country: 'Nepal',
- // editor: 'Editor',
- // volume: 123,
- // edition: null,
- // ISBN: '90232131',
- // Page_number: null,
- // Chapter_number: null,
- // Book_author: null,
- // chapter_title: null,
- // author_id: 6,
- // user_email: 'sobit.neupane@gmail.com',
- // title: 'Title',
- // year: 232,
- // publisher: 'Publisher',
- // city: 'Kathmandu',
- // doi: 'doi',
- // impact_factor: null,
- // ranked: null,
- // rank: null,
- // peer_reviewed: null,
- // type_of_publication: 'book',
- // authors: 'Sobit Neupane' } ],
- // [ { publication_id: 15,
- // editor: 'Ram Sharma',
- // volume: 5,
- // journal_name: 'Science',
- // page_number: '10-20',
- // month: '12',
- // day: '10',
- // issue: null,
- // ISSN: null,
- // author_id: 7,
- // user_email: 'sobit.neupane@gmail.com',
- // title: 'Messenger',
- // year: 2019,
- // publisher: 'American Association for the Advancement of Science',
- // city: 'Kathmandu',
- // doi: null,
- // impact_factor: null,
- // ranked: null,
- // rank: null,
- // peer_reviewed: null,
- // type_of_publication: 'journal',
- // authors: 'Prasanga Dhungel, Sobit Neupane' } ],
- // [ { publication_id: 12,
- // country: 'dfds',
- // editor: 'dfd',
- // volume: null,
- // edition: null,
- // ISBN: null,
- // Page_number: '343-55',
- // Chapter_number: 34,
- // Book_author: 'dfa',
- // chapter_title: 'asdfadfdsf',
- // author_id: 5,
- // user_email: 'sobit.neupane@gmail.com',
- // title: 'asdfdffd',
- // year: 234,
- // publisher: 'efedf',
- // city: 'df',
- // doi: null,
- // impact_factor: null,
- // ranked: null,
- // rank: null,
- // peer_reviewed: null,
- // type_of_publication: 'chapter',
- // authors: ' dfasddfd' },
- // { publication_id: 19,
- // country: 'Nepal',
- // editor: 'noone',
- // volume: 5,
- // edition: 3,
- // ISBN: 988-1231-23131,
- // Page_number: '343-55',
- // Chapter_number: 3,
- // Book_author: 'Prasanga Dhungel',
- // chapter_title: 'Somewhere something incredible is waiting to be known',
- // author_id: 5,
- // user_email: 'sobit.neupane@gmail.com',
- // title: 'Universe and Galaxies',
- // year: 2014,
- // publisher: 'MIT Press',
- // city: 'Maschacuttes',
- // doi: '10.12310.121.arXiv.org',
- // impact_factor: 'yes',
- // ranked: 'yes',
- // rank: 5,
- // peer_reviewed: 'yes',
- // type_of_publication: 'chapter',
- // authors: 'Prasanga Dhungel, Albert Einstein' } ] ]
- function downloader(JsonData, bibFormat, fileFormat){
- console.log("JsonData is",JsonData)
- if(bibFormat === 'mla'){
- var mlastr = "<html><body style= 'font-family:Times New Roman font-size: 12px'>";
- for (var k = 0; k<JsonData.length; k++){
- if (JsonData[k].length > 0 && JsonData[k][0].hasOwnProperty("type_of_publication"))
- mlastr += "<p><b>"+ JsonData[k][0].type_of_publication.toUpperCase() +"</b></p>";
- for(var i=0; i<JsonData[k].length; i++){
- mlastr += "<p>";
- mlastr += '['+(i+1).toString()+"] ";
- var authorsList = JsonData[k][i].authors.split(",");
- for(var j= 0; j<authorsList.length; j++){
- var authorstr = authorsList[j];
- var authorstrList = authorstr.split(' ');
- mlastr += authorstrList[authorstrList.length -1].charAt(0).toUpperCase() + authorstrList[authorstrList.length -1].slice(1)+", ";
- for(var abc = 0; abc < authorstrList.length -2 ; abc ++){
- mlastr += authorstrList[abc]+' ';
- }
- if(authorstrList.length >= 2){
- mlastr += authorstrList[authorstrList.length - 2].charAt(0).toUpperCase() + authorstrList[authorstrList.length - 2].slice(1);
- }
- if(j == authorsList.length - 2){
- mlastr += ", and ";
- }
- else if(j < authorsList.length - 2){
- mlastr += ", ";
- }
- }
- if(JsonData[k][i].hasOwnProperty("chapter_title") && JsonData[k][i].chapter_title != null){
- mlastr += `. "`+JsonData[k][i].chapter_title+`" `;
- if(JsonData[k][i].hasOwnProperty("book_title") && JsonData[k][i].book_title != null)
- mlastr += ". <i>"+JsonData[k][i].book_title + '</i>';
- if(JsonData[k][i].hasOwnProperty("title") && JsonData[k][i].title != null)
- mlastr += ". <i>"+JsonData[k][i].title + '</i>';
- }
- else{
- mlastr += ". <i>"+JsonData[k][i].title+"</i>";
- }
- var somethingadded = false;
- if(JsonData[k][i].hasOwnProperty("journal_name") && JsonData[k][i].journal_name != null){
- mlastr += ". In "+ JsonData[k][i].journal_name;
- }
- if(JsonData[k][i].hasOwnProperty("conference_publication_name") && JsonData[k][i].conference_publication_name != null){
- mlastr += ". In Proceedings of "+ JsonData[k][i].conference_publication_name;
- }
- if(JsonData[k][i].hasOwnProperty("chapter_number") && JsonData[k][i].chapter_number != null){
- mlastr += ", chap."+ JsonData[k][i].chapter_number;
- }
- if(JsonData[k][i].hasOwnProperty("issn") && JsonData[k][i].issn != null){
- mlastr += ", ISSN: "+ JsonData[k][i].issn;
- }
- if(JsonData[k][i].hasOwnProperty("isbn") && JsonData[k][i].isbn != null){
- mlastr += ", ISBN: "+ JsonData[k][i].isbn;
- }
- if(JsonData[k][i].hasOwnProperty("doi") && JsonData[k][i].doi != null){
- mlastr += ", DOI: "+ JsonData[k][i].doi;
- }
- if(JsonData[k][i].hasOwnProperty("ISSN") && JsonData[k][i].ISSN != null){
- mlastr += ", ISSN: "+ JsonData[k][i].ISSN;
- }
- if(JsonData[k][i].hasOwnProperty("ISBN") && JsonData[k][i].ISBN != null){
- mlastr += ", ISBN: "+ JsonData[k][i].ISBN;
- }
- if(JsonData[k][i].hasOwnProperty("DOI") && JsonData[k][i].DOI != null){
- mlastr += ", DOI: "+ JsonData[k][i].DOI;
- }
- if(JsonData[k][i].hasOwnProperty("volume") && JsonData[k][i].volume != null){
- mlastr += ", vol. "+ JsonData[k][i].volume;
- }
- if(JsonData[k][i].hasOwnProperty("city") && JsonData[k][i].city != null){
- somethingadded = true;
- mlastr += ", " + JsonData[k][i].city;
- if(JsonData[k][i].hasOwnProperty("country") && JsonData[k][i].country != null)
- mlastr += ", "+JsonData[k][i].country + ": ";
- else
- mlastr += ": " ;
- }
- else{
- if(JsonData[k][i].hasOwnProperty("country") && JsonData[k][i].country != null){
- somethingadded = true;
- mlastr += ", "+JsonData[k][i].country + ": ";
- }
- }
- if(JsonData[k][i].hasOwnProperty("publisher") && JsonData[k][i].publisher != null && !JsonData[k][i].hasOwnProperty("journal_name") && !JsonData[k][i].hasOwnProperty("conference_publication_name")){
- if (!somethingadded)
- mlastr += ". ";
- mlastr += JsonData[k][i].publisher;
- }
- if(JsonData[k][i].hasOwnProperty("page_number") && JsonData[k][i].page_number != null)
- mlastr += ", pp. "+ JsonData[k][i].page_number;
- mlastr += " (";
- if(JsonData[k][i].hasOwnProperty("month") && JsonData[k][i].month != null)
- mlastr += JsonData[k][i].month + " ";
- if(JsonData[k][i].hasOwnProperty("day") && JsonData[k][i].day != null)
- mlastr += JsonData[k][i].day + ", ";
- mlastr += JsonData[k][i].year +")";
- mlastr += "</p>";
- }
- }
- mlastr += "</body></html>";
- if(fileFormat === 'pdf'){
- var doc = new jsPDF('p', 'pt', 'letter');
- doc.fromHTML(mlastr, 45, 30, {width: 517}); //Convert html string into jsPDF instances
- doc.save('MLA.pdf');
- }
- if(fileFormat === 'docx'){
- var blob = new Blob(['\ufeff', mlastr], { //converts html string into blob(Binary Large Object) of type msword
- type: 'application/msword'
- });
- var url = 'data:application/vnd.ms-word;charset=utf-8,' + encodeURIComponent(mlastr);
- var filename = "MLA.docx"; //file is downloaded as MLA.docx, user can change it while downloading
- var downloadLink = document.createElement("a");
- document.body.appendChild(downloadLink);
- if(navigator.msSaveOrOpenBlob ){
- navigator.msSaveOrOpenBlob(blob, filename);
- }else{
- downloadLink.href = url;
- downloadLink.download = filename;
- downloadLink.click();
- }
- document.body.removeChild(downloadLink);
- }
- if(fileFormat === 'html'){
- var element = document.createElement('a');
- element.setAttribute('href', 'data:text/plain;charset=utf-8,' + encodeURIComponent(mlastr));
- element.setAttribute('download', "MLA.html");
- element.style.display = 'none';
- document.body.appendChild(element);
- element.click();
- document.body.removeChild(element);
- }
- }
- if(bibFormat == 'apa'){
- var apastr = "<html><body style= 'font-family:Times New Roman font-size: 12px'>"; //apa formatted html string
- for(var k = 0; k<JsonData.length; k++){
- if (JsonData[k].length > 0 && JsonData[k][0].hasOwnProperty("type_of_publication"))
- apastr += "<p><b>"+ JsonData[k][0].type_of_publication.toUpperCase() +"</b></p>";
- for(var i=0; i<JsonData[k].length; i++){ //This loop prepares required html string
- apastr += "<p>";
- apastr += '['+(i+1).toString()+"] ";
- var authorsList = JsonData[k][i].authors.split(",");
- for(var j= 0; j<authorsList.length; j++){
- var authorstr = authorsList[j];
- var authorstrList = authorstr.split(' ');
- apastr += authorstrList[authorstrList.length -1].charAt(0).toUpperCase() + authorstrList[authorstrList.length -1].slice(1) + ", ";
- for(var abc = 0; abc < authorstrList.length -2 ; abc ++){
- if(authorstr[0] == ' ' && abc == 0)
- continue;
- apastr += authorstrList[abc][0].toUpperCase()+'. ';
- }
- if(authorstrList.length >= 2){
- apastr += authorstrList[authorstrList.length - 2][0]+'.';
- }
- if(j == authorsList.length - 2){
- apastr += ", & ";
- }
- else if(j < authorsList.length - 2){
- apastr += ", ";
- }
- }
- apastr += "(" + JsonData[k][i].year ;
- if(JsonData[k][i].hasOwnProperty("month") && JsonData[k][i].month != null)
- apastr += ", " + JsonData[k][i].month + " ";
- if(JsonData[k][i].hasOwnProperty("day") && JsonData[k][i].day != null)
- apastr += JsonData[k][i].day;
- apastr += ")";
- if(JsonData[k][i].hasOwnProperty("chapter_title") && JsonData[k][i].chapter_title != null){
- apastr += `. "`+JsonData[k][i].chapter_title+`." `;
- if(JsonData[k][i].hasOwnProperty("book_title") && JsonData[k][i].book_title != null)
- apastr += "<i>"+JsonData[k][i].book_title + '.</i>';
- if(JsonData[k][i].hasOwnProperty("title") && JsonData[k][i].title != null)
- apastr += "<i>"+JsonData[k][i].title + '.</i>';
- }
- else{
- apastr += ". <i>"+JsonData[k][i].title+". </i>";
- }
- if(JsonData[k][i].hasOwnProperty("city") && JsonData[k][i].city != null){
- apastr += JsonData[k][i].city;
- if(JsonData[k][i].hasOwnProperty("country") && JsonData[k][i].country != null)
- apastr += ", "+JsonData[k][i].country + ": ";
- else
- apastr += ": " ;
- }
- if(JsonData[k][i].hasOwnProperty("publisher") && JsonData[k][i].publisher != null && !JsonData[k][i].hasOwnProperty("journal_name") && !JsonData[k][i].hasOwnProperty("conference_publication_name"))
- apastr += JsonData[k][i].publisher;
- if(JsonData[k][i].hasOwnProperty("journal_name") && JsonData[k][i].journal_name != null)
- apastr += " In "+ JsonData[k][i].journal_name;
- if(JsonData[k][i].hasOwnProperty("conference_publication_name") && JsonData[k][i].conference_publication_name != null)
- apastr += " In Proceedings of "+ JsonData[k][i].conference_publication_name;
- if(JsonData[k][i].hasOwnProperty("chapter_number") && JsonData[k][i].chapter_number != null)
- apastr += ", chap."+ JsonData[k][i].chapter_number;
- if(JsonData[k][i].hasOwnProperty("issn") && JsonData[k][i].issn != null)
- apastr += ", ISSN: "+ JsonData[k][i].issn ;
- if(JsonData[k][i].hasOwnProperty("isbn") && JsonData[k][i].isbn != null)
- apastr += ", ISBN: "+ JsonData[k][i].isbn;
- if(JsonData[k][i].hasOwnProperty("doi") && JsonData[k][i].doi != null)
- apastr += ", DOI: "+ JsonData[k][i].doi ;
- if(JsonData[k][i].hasOwnProperty("ISSN") && JsonData[k][i].ISSN != null)
- apastr += ", ISSN: "+ JsonData[k][i].ISSN ;
- if(JsonData[k][i].hasOwnProperty("isbn") && JsonData[k][i].ISBN != null)
- apastr += ", ISBN: "+ JsonData[k][i].ISBN ;
- if(JsonData[k][i].hasOwnProperty("DOI") && JsonData[k][i].DOI != null)
- apastr += ", DOI: "+ JsonData[k][i].DOI;
- if(JsonData[k][i].hasOwnProperty("volume") && JsonData[k][i].volume != null)
- apastr += ", vol. "+ JsonData[k][i].volume;
- if(JsonData[k][i].hasOwnProperty("page_number") && JsonData[k][i].page_number != null)
- apastr += ", pp. "+ JsonData[k][i].page_number ;
- apastr += ".</p>";
- }
- }
- apastr += "</body></html>";
- if(fileFormat === 'pdf'){
- var doc = new jsPDF('p', 'pt', 'letter');
- doc.fromHTML(apastr, 45, 30, {width: 517}); //Convert html string into jsPDF instances
- doc.save('APA.pdf');
- }
- if(fileFormat === 'docx'){
- var blob = new Blob(['\ufeff', apastr], { //converts html string into blob(Binary Large Object) of type msword
- type: 'application/msword'
- });
- var url = 'data:application/vnd.ms-word;charset=utf-8,' + encodeURIComponent(apastr);
- var filename = "APA.docx"; //file is downloaded as MLA.docx, user can change it while downloading
- var downloadLink = document.createElement("a");
- document.body.appendChild(downloadLink);
- if(navigator.msSaveOrOpenBlob ){
- navigator.msSaveOrOpenBlob(blob, filename);
- }else{
- downloadLink.href = url;
- downloadLink.download = filename;
- downloadLink.click();
- }
- document.body.removeChild(downloadLink);
- }
- if(fileFormat === 'html'){
- var element = document.createElement('a');
- element.setAttribute('href', 'data:text/plain;charset=utf-8,' + encodeURIComponent(apastr));
- element.setAttribute('download', "APA.html");
- element.style.display = 'none';
- document.body.appendChild(element);
- element.click();
- document.body.removeChild(element);
- }
- }
- if(bibFormat === 'ieee'){
- var ieeestr = "<html><body style= 'font-family:Times New Roman; font-size: 11px'>"; //ieee formatted html string
- for(var k = 0; k < JsonData.length; k++){
- if (JsonData[k].length > 0 && JsonData[k][0].hasOwnProperty("type_of_publication"))
- ieeestr += "<p><b>"+ JsonData[k][0].type_of_publication.toUpperCase() +"</b></p>"; //str is a html string
- for(var i=0; i<JsonData[k].length; i++){
- ieeestr+= "<p>"
- ieeestr += '['+(i+1).toString()+"] ";
- var authorsList = JsonData[k][i].authors.split(",");
- for(var j= 0; j<authorsList.length; j++){
- var authorstr = authorsList[j].charAt(0).toUpperCase() + authorsList[j].slice(1);
- var authorstrList = authorstr.split(' ');
- if(authorstrList.length > 1){
- if(authorstr[0] != ' '){
- ieeestr += authorstrList[0][0].toUpperCase()+". ";
- var star = 1;
- }
- else{
- ieeestr += authorstrList[1][0].toUpperCase()+". ";
- var star = 2;
- }
- }
- else
- ieeestr += authorstrList[0].charAt(0).toUpperCase() + authorstrList[0].slice(1)+". ";
- for(var abc = star; abc <= authorstrList.length -2 ; abc++){
- ieeestr += authorstrList[abc][0].toUpperCase()+'. ';
- }
- ieeestr += authorstrList[authorstrList.length - 1];
- if(j == authorsList.length - 2){
- ieeestr += ", and ";
- }
- else if(j < authorsList.length - 2){
- ieeestr += ", ";
- }
- }
- if(JsonData[k][i].hasOwnProperty("chapter_title") && JsonData[k][i].chapter_title != null){
- ieeestr += `. "`+JsonData[k][i].chapter_title+`." `;
- if(JsonData[k][i].hasOwnProperty("book_title") && JsonData[k][i].book_title != null)
- ieeestr += "<i>"+JsonData[k][i].book_title + '.</i>';
- if(JsonData[k][i].hasOwnProperty("title") && JsonData[k][i].title != null)
- ieeestr += "<i>"+JsonData[k][i].title + '.</i>';
- }
- else{
- ieeestr += ". <i>"+JsonData[k][i].title+". </i>";
- }
- if(JsonData[k][i].hasOwnProperty("city") && JsonData[k][i].city != null){
- ieeestr += JsonData[k][i].city;
- if(JsonData[k][i].hasOwnProperty("country") && JsonData[k][i].country != null)
- ieeestr += ", "+JsonData[k][i].country + ": ";
- else
- ieeestr += ": " ;
- }
- if(JsonData[k][i].hasOwnProperty("publisher") && JsonData[k][i].publisher != null)
- ieeestr += JsonData[k][i].publisher + ", ";
- if(JsonData[k][i].hasOwnProperty("journal_name") && JsonData[k][i].journal_name != null)
- ieeestr += "In Journal of "+ JsonData[k][i].journal_name + ", ";
- if(JsonData[k][i].hasOwnProperty("conference_publication_name") && JsonData[k][i].conference_publication_name != null)
- ieeestr += "In Proceedings of "+ JsonData[k][i].conference_publication_name + ", ";
- ieeestr += "(" + JsonData[k][i].year ;
- if(JsonData[k][i].hasOwnProperty("month") && JsonData[k][i].month != null)
- ieeestr += ", " + JsonData[k][i].month + " ";
- if(JsonData[k][i].hasOwnProperty("day") && JsonData[k][i].day != null)
- ieeestr += JsonData[k][i].day;
- ieeestr += ").";
- ieeestr += "</p>";
- }
- }
- ieeestr += "</body></html>" ;
- if(fileFormat === 'pdf'){
- var doc = new jsPDF('p', 'pt', 'letter');
- doc.fromHTML(ieeestr, 45, 30, {width: 517}); //Convert html string into jsPDF instances
- doc.save('IEEE.pdf');
- }
- if(fileFormat === 'docx'){
- var blob = new Blob(['\ufeff', ieeestr], { //converts html string into blob(Binary Large Object) of type msword
- type: 'application/msword'
- });
- var url = 'data:application/vnd.ms-word;charset=utf-8,' + encodeURIComponent(ieeestr);
- var filename = "IEEE.docx"; //file is downloaded as MLA.docx, user can change it while downloading
- var downloadLink = document.createElement("a");
- document.body.appendChild(downloadLink);
- if(navigator.msSaveOrOpenBlob ){
- navigator.msSaveOrOpenBlob(blob, filename);
- }else{
- downloadLink.href = url;
- downloadLink.download = filename;
- downloadLink.click();
- }
- document.body.removeChild(downloadLink);
- }
- if(fileFormat === 'html'){
- var element = document.createElement('a');
- element.setAttribute('href', 'data:text/plain;charset=utf-8,' + encodeURIComponent(ieeestr));
- element.setAttribute('download', "IEEE.html");
- element.style.display = 'none';
- document.body.appendChild(element);
- element.click();
- document.body.removeChild(element);
- }
- }
- if(bibFormat === 'ugc'){
- var ugcstr = "<html><body style= 'font-family:Times New Roman; font-size: 12px'>"; //ugc table formatted html string
- ugcstr += "<table style='width:100%; table-layout=fixed; border: 1px solid black; border-collapse: collapse'>";
- var nonugc = "";
- ugcstr += "<tr><td style = 'border: 1px solid black; border-collapse: collapse' colspan='3'>Major Research Publication in <strong>Ranked Journals/Proceedings</strong></td></tr>"; //str is a html string
- nonugc += "<tr><td style = 'border: 1px solid black; border-collapse: collapse' colspan='3'>Major Research Publication in <strong>Non-Ranked Peer-Reviewed Journals</strong></td></tr>"; //str is a html string
- ugcstr += "<tr><td></td><td style = 'border: 1px solid black; border-collapse: collapse'>Format: Authors, Title, Journal, Volume(Number), First page-Last page, (Year)</td> <td style = 'border: 1px solid black; border-collapse: collapse'>Rank*/IF</td></tr>";
- nonugc += "<tr><td></td><td style = 'border: 1px solid black; border-collapse: collapse'>Format: Authors, Title, Journal, Volume(Number), First page-Last page, (Year)</td> <td style = 'border: 1px solid black; border-collapse: collapse'>Country</td></tr>";
- for (var k = 0; k< JsonData.length; k++){
- for(var i=0; i<JsonData[k].length; i++){
- if(JsonData.hasOwnProperty("ranked") && JsonData.ranked.toUpperCase === "YES"){
- ugcstr += "<tr><td style = 'border: 1px solid black; border-collapse: collapse'>";
- ugcstr += (i+1).toString();
- ugcstr += "</td><td style = 'border: 1px solid black; border-collapse: collapse'>";
- var authorsList = JsonData[k][i].authors.split(",");
- for(var j= 0; j<authorsList.length; j++){
- var authorstr = authorsList[j];
- var authorstrList = authorstr.split(' ');
- if(authorstrList.length > 1){
- if(authorstr[0] != ' '){
- ugcstr += authorstrList[0][0]+". ";
- var star = 1;
- }
- else{
- ugcstr += authorstrList[1][0]+". ";
- var star = 2;
- }
- }
- else
- ugcstr += authorstrList[0]+". ";
- for(var abc = star; abc <= authorstrList.length -2 ; abc++){
- ugcstr += authorstrList[abc][0]+'. ';
- }
- ugcstr += authorstrList[authorstrList.length - 1] ;
- if(j == authorsList.length - 2){
- ugcstr += ", and ";
- }
- else if(j < authorsList.length - 2){
- ugcstr += ", ";
- }
- }
- if(JsonData[k][i].hasOwnProperty("chapter_title") && JsonData[k][i].chapter_title != null){
- ugcstr += `, "`+JsonData[k][i].chapter_title+`." `;
- if(JsonData[k][i].hasOwnProperty("book_title") && JsonData[k][i].book_title != null)
- ugcstr += "<i>"+JsonData[k][i].book_title + ', </i>';
- if(JsonData[k][i].hasOwnProperty("title") && JsonData[k][i].title != null)
- ugcstr += "<i>"+JsonData[k][i].title + ', </i>';
- }
- else{
- ugcstr += ", <i>"+JsonData[k][i].title+", </i>";
- }
- if(JsonData[k][i].hasOwnProperty("journal_name") && JsonData[k][i].journal_name != null)
- ugcstr += JsonData[k][i].journal_name + ", ";
- else if(JsonData[i].hasOwnProperty("conference_publication_name") && JsonData[k][i].conference_publication_name != null)
- ugcstr += JsonData[i].conference_publication_name + ", ";
- else ugcstr += "- , ";
- if(JsonData[k][i].hasOwnProperty("volume") && JsonData[k][i].volume != null)
- ugcstr += "vol. "+ JsonData[i].volume ;
- else ugcstr += "- , ";
- if(JsonData[k][i].hasOwnProperty("page_number") && JsonData[k][i].page_number != null)
- ugcstr += "pp. "+ JsonData[i].page_number ;
- else ugcstr += "- , ";
- ugcstr += "(" + JsonData[k][i].year + ").";
- ugcstr += "</td><td style = 'border: 1px solid black; border-collapse: collapse'>";
- if(JsonData[k][i].hasOwnProperty("rank") && JsonData[k][i].rank != null){
- ugcstr += JsonData[k][i].rank + "/";
- }
- else ugcstr += "- /";
- if(JsonData[k][i].hasOwnProperty("impact_factor") && JsonData[k][i].impact_factor != null){
- ugcstr += JsonData[k][i].impact_factor + "/";
- }
- else ugcstr += "-";
- ugcstr += "</td>";
- ugcstr +="</tr>";
- }
- else{
- nonugc += "<tr><td style = 'border: 1px solid black; border-collapse: collapse'>";
- nonugc += (i+1).toString();
- nonugc += "</td><td style = 'border: 1px solid black; border-collapse: collapse'>";
- var authorsList = JsonData[k][i].authors.split(",");
- for(var j= 0; j<authorsList.length; j++){
- var authorstr = authorsList[j];
- var authorstrList = authorstr.split(' ');
- if(authorstrList.length > 1){
- if(authorstr[0] != ' '){
- nonugc += authorstrList[0][0]+". ";
- var star = 1;
- }
- else{
- nonugc += authorstrList[1][0]+". ";
- var star = 2;
- }
- }
- else
- nonugc += authorstrList[0]+". ";
- for(var abc = star; abc <= authorstrList.length -2 ; abc++){
- nonugc += authorstrList[abc][0]+'. ';
- }
- nonugc += authorstrList[authorstrList.length - 1] ;
- if(j == authorsList.length - 2){
- nonugc += ", and ";
- }
- else if(j < authorsList.length - 2){
- nonugc += ", ";
- }
- }
- if(JsonData[k][i].hasOwnProperty("chapter_title") && JsonData[k][i].chapter_title != null){
- nonugc += `"`+JsonData[k][i].chapter_title+`." `;
- if(JsonData[k][i].hasOwnProperty("book_title") && JsonData[k][i].book_title != null)
- nonugc += "<i>"+JsonData[k][i].book_title + ', </i>';
- if(JsonData[k][i].hasOwnProperty("title") && JsonData[k][i].title != null)
- nonugc += "<i>"+JsonData[k][i].title + ', </i>';
- }
- else{
- nonugc += ", <i>"+JsonData[k][i].title+", </i>";
- }
- if(JsonData[k][i].hasOwnProperty("journal_name") && JsonData[k][i].journal_name != null)
- nonugc += JsonData[k][i].journal_name + ", ";
- else if(JsonData[k][i].hasOwnProperty("conference_publication_name") && JsonData[k][i].conference_publication_name != null)
- nonugc += JsonData[k][i].conference_publication_name + ", ";
- else nonugc += "- , ";
- if(JsonData[k][i].hasOwnProperty("volume") && JsonData[k][i].volume != null)
- nonugc += "vol. "+ JsonData[k][i].volume ;
- else nonugc += "- , ";
- if(JsonData[k][i].hasOwnProperty("page_number") && JsonData[k][i].page_number != null)
- nonugc += "pp. "+ JsonData[k][i].page_number ;
- else nonugc += "- , ";
- nonugc += "(" + JsonData[k][i].year + ").";
- nonugc += "</td><td style = 'border: 1px solid black; border-collapse: collapse'>";
- if(JsonData[k][i].hasOwnProperty("country") && JsonData[k][i].country != null){
- nonugc += JsonData[k][i].country;
- }
- else{
- nonugc += "-"
- }
- }
- }
- }
- ugcstr += nonugc;
- ugcstr += "</table>";
- ugcstr += "</body></html>" ;
- // if(fileFormat === 'pdf'){
- // // var doc = new jsPDF('p', 'pt', 'letter');
- // // doc.fromHTML(ugcstr, 45, 30, {width: 517}); //Convert html string into jsPDF instances
- // // doc.save('UGC.pdf');
- // var doc = new jsPDF('p', 'pt', 'a4');
- // var source = ugcstr;
- // var margins = {
- // top: 10,
- // bottom: 10,
- // left: 10,
- // width: 595
- // };
- // doc.fromHTML(
- // source, // HTML string or DOM elem ref.
- // margins.left,
- // margins.top, {
- // 'width': margins.width,
- // },
- // function(dispose) {
- // doc.save('Test.pdf');
- // }, margins);
- // }
- if(fileFormat === 'docx' || fileFormat === 'pdf'){
- var blob = new Blob(['\ufeff', ugcstr], { //converts html string into blob(Binary Large Object) of type msword
- type: 'application/msword'
- });
- var url = 'data:application/vnd.ms-word;charset=utf-8,' + encodeURIComponent(ugcstr);
- var filename = "UGC.docx"; //file is downloaded as MLA.docx, user can change it while downloading
- var downloadLink = document.createElement("a");
- document.body.appendChild(downloadLink);
- if(navigator.msSaveOrOpenBlob ){
- navigator.msSaveOrOpenBlob(blob, filename);
- }else{
- downloadLink.href = url;
- downloadLink.download = filename;
- downloadLink.click();
- }
- document.body.removeChild(downloadLink);
- }
- if(fileFormat === 'html'){
- var element = document.createElement('a');
- element.setAttribute('href', 'data:text/plain;charset=utf-8,' + encodeURIComponent(ugcstr));
- element.setAttribute('download', "UGC.html");
- element.style.display = 'none';
- document.body.appendChild(element);
- element.click();
- document.body.removeChild(element);
- }
- }
- }
- export default downloader;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement