Skip to content

Commit

Permalink
refactored util methods
Browse files Browse the repository at this point in the history
  • Loading branch information
fabian-beck committed Jul 27, 2020
1 parent 5adc5ad commit 002e8e1
Show file tree
Hide file tree
Showing 11 changed files with 304 additions and 290 deletions.
1 change: 1 addition & 0 deletions electron/index-electron.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
</script>
<script type="text/javascript" src="properties.js"></script>
<script type="text/javascript" src="../src/js/survis.js"></script>
<script type="text/javascript" src="../src/js/util.js"></script>
<script data-main="../src/js/app.js" src="../src/js/require.js"></script>
<meta http-equiv="Content-Security-Policy" content="script-src 'self' 'unsafe-inline';" />
</head>
Expand Down
1 change: 1 addition & 0 deletions src/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<script type="text/javascript" src="properties.js"></script>
<script type="text/javascript" src="js/survis.js"></script>
<script type="text/javascript" src="js/util.js"></script>
<script data-main="js/app.js" src="js/require.js"></script>
</head>
<body>
Expand Down
39 changes: 26 additions & 13 deletions src/js/app/bib.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
define(['jquery', 'bibtex_js', 'FileSaver', 'codemirror', 'app/util', 'data/generated/bib', 'data/generated/available_pdf', 'data/generated/available_img', 'data/search_stopwords', 'data/tag_categories', 'data/authorized_tags'],
function ($, bibtexJS, fileSaver, CodeMirror, util, generatedBib, availaiblePdf, availableImg, stopwords, tagCategories, authorizedTags) {
define(['jquery', 'bibtex_js', 'FileSaver', 'codemirror', 'data/generated/bib', 'data/generated/available_pdf', 'data/generated/available_img', 'data/search_stopwords', 'data/tag_categories', 'data/authorized_tags'],
function ($, bibtexJS, fileSaver, CodeMirror, generatedBib, availaiblePdf, availableImg, stopwords, tagCategories, authorizedTags) {

var entries = readBibtex();
if (!entries && !electron) {
Expand All @@ -25,7 +25,7 @@ define(['jquery', 'bibtex_js', 'FileSaver', 'codemirror', 'app/util', 'data/gene
createBibtex: function (id, entry) {
var bibtex = '@' + entry['type'] + '{' + id;
for (var fieldName in entry) {
if (fieldName == 'type' || util.isFieldForbidden(fieldName)) {
if (fieldName == 'type' || isFieldForbidden(fieldName)) {
continue;
}
if (entry.hasOwnProperty(fieldName)) {
Expand Down Expand Up @@ -54,7 +54,7 @@ define(['jquery', 'bibtex_js', 'FileSaver', 'codemirror', 'app/util', 'data/gene
if (i == bib.parsedEntries[id]['author'].length - 1 && i > 0) {
citation += 'and ';
}
citation += util.latexToHtml(author);
citation += latexUtil.latexToHtml(author);
if (bib.parsedEntries[id]['author'].length > 2 || i > 0) {
citation += ', ';
} else {
Expand All @@ -67,31 +67,31 @@ define(['jquery', 'bibtex_js', 'FileSaver', 'codemirror', 'app/util', 'data/gene
citation += year + '. ';
}
if (title = bib.entries[id]['title']) {
citation += util.latexToHtml(title) + '. ';
citation += latexUtil.latexToHtml(title) + '. ';
}
var journal = bib.entries[id]['journal'];
var pages = bib.entries[id]['pages'];
if (journal) {
citation += 'In <i>' + util.latexToHtml(journal) + '</i>';
citation += 'In <i>' + latexUtil.latexToHtml(journal) + '</i>';
var volume = bib.entries[id]['volume'];
if (volume) {
citation += ' (Vol. ' + util.latexToHtml(volume);
citation += ' (Vol. ' + latexUtil.latexToHtml(volume);
var number = bib.entries[id]['number'];
if (number) {
citation += ', No. ' + util.latexToHtml(number);
citation += ', No. ' + latexUtil.latexToHtml(number);
}
if (pages) {
citation += ', pp. ' + util.latexToHtml(pages);
citation += ', pp. ' + latexUtil.latexToHtml(pages);
}
citation += ')';
}
citation += '. ';
}
var booktitle = bib.entries[id]['booktitle'];
if (booktitle) {
citation += 'In <i>' + util.latexToHtml(booktitle) + '</i>';
citation += 'In <i>' + latexUtil.latexToHtml(booktitle) + '</i>';
if (pages) {
citation += ' (pp. ' + util.latexToHtml(pages) + ')';
citation += ' (pp. ' + latexUtil.latexToHtml(pages) + ')';
}
citation += '. ';
}
Expand Down Expand Up @@ -307,7 +307,7 @@ define(['jquery', 'bibtex_js', 'FileSaver', 'codemirror', 'app/util', 'data/gene
}
return null;
} else {
var loadFromLocalStorage = util.getUrlParameter('loadFromLocalStorage') === 'true';
var loadFromLocalStorage = browserUtil.getUrlParameter('loadFromLocalStorage') === 'true';
if (editable && loadFromLocalStorage && localStorage.bibtexString) {
try {
bibParser.setInput(localStorage.bibtexString);
Expand All @@ -326,7 +326,7 @@ define(['jquery', 'bibtex_js', 'FileSaver', 'codemirror', 'app/util', 'data/gene
function generateTagCategoriesFromKeywords(entries) {
const tagCategories = {};
Object.keys(entries).forEach(id => {
util.parseField(entries[id].keywords, 'keywords', tagCategories).forEach(keyword => {
bibUtil.parseField(entries[id].keywords, 'keywords', tagCategories).forEach(keyword => {
if (keyword.indexOf(':') > 0) {
const category = keyword.split(':')[0];
if (!tagCategories[category]) {
Expand All @@ -338,4 +338,17 @@ define(['jquery', 'bibtex_js', 'FileSaver', 'codemirror', 'app/util', 'data/gene
return tagCategories;
}

function isFieldForbidden(fieldName) {
const forbiddenFields = []; //['referencedby', 'titlesafe', 'references'];
if (typeof forbiddenFields === 'undefined' || !forbiddenFields) {
return false;
}
for (var i in forbiddenFields) {
if (fieldName.indexOf(forbiddenFields[i]) == 0) {
return true;
}
}
return false;
}

});
8 changes: 4 additions & 4 deletions src/js/app/cluster.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
define(['jquery', 'app/util', 'figue', 'app/selectors', 'app/bib'], function ($, util, figue, selectors, bib) {
define(['jquery', 'figue', 'app/selectors', 'app/bib'], function ($, figue, selectors, bib) {

var clusteringCount = 0;

Expand Down Expand Up @@ -229,7 +229,7 @@ define(['jquery', 'app/util', 'figue', 'app/selectors', 'app/bib'], function ($,
});

var clusterDiv = $('<div>', {
class: 'tooltip tag authorized ' + util.getFrequencyClass(clusterSizes[clusterName])
class: 'tooltip tag authorized ' + tagUtil.getFrequencyClass(clusterSizes[clusterName])
}).appendTo(clusteringDiv);
var sparklineDiv = $('<div>', {
class: 'vis sparkline'
Expand All @@ -249,7 +249,7 @@ define(['jquery', 'app/util', 'figue', 'app/selectors', 'app/bib'], function ($,
for (i = 0; i < Math.min(3, tfidf.length); i++) {
$('<div>', {
class: 'term',
html: util.latexToHtml(tfidf[i].name)
html: latexUtil.latexToHtml(tfidf[i].name)
}).appendTo(termsDiv);
}
clusterDiv.click(function (event) {
Expand All @@ -265,7 +265,7 @@ define(['jquery', 'app/util', 'figue', 'app/selectors', 'app/bib'], function ($,
for (i = 0; i < Math.min(10, tfidf.length); i++) {
$('<div>', {
class: 'term',
html: util.latexToHtml(tfidf[i].name)//+'('+tfidf[i].value.toFixed(3)+')'
html: latexUtil.latexToHtml(tfidf[i].name)//+'('+tfidf[i].value.toFixed(3)+')'
}).appendTo(termDetailsDiv);
}
var totalSimilarity = selectors.computeTotalSimilarity(clusterSelectorSimilarities[clusterName]);
Expand Down
Loading

0 comments on commit 002e8e1

Please sign in to comment.