Skip to content

Commit 98e300a

Browse files
committed
Merge branch 'dev' into interface-changes-cite
2 parents 619636a + 36aaf37 commit 98e300a

8 files changed

Lines changed: 119 additions & 47 deletions

File tree

CHANGELOG.md

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,30 @@
11
# Changelog
22

3+
## 2022-01-20
4+
5+
### New features
6+
7+
- backend data sanitization
8+
- pdfs searchable by the searchbox
9+
10+
### Changes
11+
12+
- data preprocessing refactoring
13+
14+
### Bug fixes
15+
16+
- footer size on narrow screens
17+
18+
### Internal
19+
20+
- test database update
21+
22+
## 2021-12-22
23+
24+
### Changes
25+
26+
- unified HTML & CSS of various paper tags (access tags, dataset tag, custom tags)
27+
328
## 2021-12-09
429

530
### New features

server/storage/test.sqlite

1.43 MB
Binary file not shown.

vis/js/dataschemes/defaultScheme.js

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,24 @@ import {
77
stringArrayValidator,
88
} from "../utils/data";
99

10-
// name; required?; type?; protected?; validator?; sanitizer?; fallback?;
10+
/**
11+
* Scheme object based on the metadata spreadsheet.
12+
*
13+
* https://docs.google.com/spreadsheets/d/112Anbf-sJYkehyFvjuxr1DuMih-fPB9nt3E8ll19Iyc/edit#gid=0
14+
*
15+
* It's an array of objects, each object describes a paper property.
16+
*
17+
* It has the following properties:
18+
*
19+
* - name: string - the paper property's name
20+
* - required?: boolean - true for mandatory properties
21+
* - type?: string[] - list of allowed js types
22+
* - protected?: boolean - true for properties that shouldn't be escaped
23+
* - validator?: (value: any) => boolean - validator function that receives the property value and returns true if the value is valid
24+
* - sanitizer?: (value: any) => any - sanitizer function that sanitizes the property value
25+
* - fallback?: (localization?: object, paper?: object) => any - fallback function that returns a fallback value
26+
*
27+
*/
1128
const DEFAULT_SCHEME = [
1229
{
1330
name: "id",
@@ -57,6 +74,7 @@ const DEFAULT_SCHEME = [
5774
name: "subject_orig",
5875
required: true,
5976
type: ["string"],
77+
validator: (val) => val !== "",
6078
fallback: (loc) => loc.no_keywords,
6179
},
6280
{ name: "subject_cleaned", required: true, type: ["string"] },

vis/js/templates/listentry/PaperButtons.jsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { connect } from "react-redux";
44
import useMatomo from "../../utils/useMatomo";
55
import { getPaperPDFClickHandler } from "../../utils/data";
66
import { mapDispatchToListEntriesProps } from "../../utils/eventhandlers";
7+
import Highlight from "../../components/Highlight";
78

89
const PaperButtons = ({
910
paper,
@@ -30,7 +31,7 @@ const PaperButtons = ({
3031
<div className="paper_buttons_row">
3132
{!!onPDFClick && (
3233
<button className="paper_button main" onClick={handlePDFButtonClick}>
33-
<i className="fa fa-eye"></i>&nbsp;&nbsp;PDF
34+
<i className="fa fa-eye"></i>&nbsp;&nbsp;<Highlight>PDF</Highlight>
3435
</button>
3536
)}
3637
{showCiteButton && (

vis/js/utils/data.js

Lines changed: 30 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -83,54 +83,48 @@ const getParamFilterFunction = (param, field) => {
8383
};
8484
};
8585

86+
const SEARCHED_PROPS = [
87+
"title",
88+
"authors_string",
89+
"published_in",
90+
"year",
91+
"subject_orig",
92+
"tags",
93+
"comments_for_filtering",
94+
"resulttype",
95+
"paper_abstract",
96+
];
97+
8698
/**
8799
* Creates a paper filtering function from the search words.
88100
*
89-
* Function taken from legacy list.js
90-
* @param {Array} search_words array of search words (plaintext strings)
101+
* @param {Array} searchedKeywords array of search keywords (plaintext strings)
91102
*
92-
* @returns {Function} filtering function
103+
* @returns {Function} filtering function that returns true if paper contains all the searched keywords
93104
*/
94-
const getWordFilterFunction = (search_words) => {
95-
return (d) => {
96-
const abstract = getPropertyOrEmptyString(d, "paper_abstract");
97-
const title = getPropertyOrEmptyString(d, "title");
98-
const authors = getPropertyOrEmptyString(d, "authors_string");
99-
const journals = getPropertyOrEmptyString(d, "published_in");
100-
const year = getPropertyOrEmptyString(d, "year");
101-
const keywords = getPropertyOrEmptyString(d, "subject_orig");
102-
const tags = getPropertyOrEmptyString(d, "tags");
103-
const comments = getPropertyOrEmptyString(d, "comments_for_filtering");
104-
const resulttype = getPropertyOrEmptyString(d, "resulttype");
105-
// TODO: make these two properties language-aware
106-
const open_access = d.oa ? "open access" : "";
107-
const free_access = d.free_access ? "free access" : "";
108-
109-
let i = 0;
110-
let word_found = true;
111-
while (word_found && i < search_words.length) {
112-
word_found =
113-
abstract.indexOf(search_words[i]) !== -1 ||
114-
title.indexOf(search_words[i]) !== -1 ||
115-
authors.indexOf(search_words[i]) !== -1 ||
116-
journals.indexOf(search_words[i]) !== -1 ||
117-
year.indexOf(search_words[i]) !== -1 ||
118-
keywords.indexOf(search_words[i]) !== -1 ||
119-
tags.indexOf(search_words[i]) !== -1 ||
120-
comments.indexOf(search_words[i]) !== -1 ||
121-
resulttype.indexOf(search_words[i]) !== -1 ||
122-
open_access.indexOf(search_words[i]) !== -1 ||
123-
free_access.indexOf(search_words[i]) !== -1;
124-
i++;
105+
const getWordFilterFunction = (searchedKeywords) => {
106+
return (paper) => {
107+
const paperKeywords = SEARCHED_PROPS.map((prop) =>
108+
getPropertyOrEmptyString(paper, prop)
109+
);
110+
111+
if (paper.oa) {
112+
paperKeywords.push("open access");
113+
paperKeywords.push("pdf");
125114
}
115+
if (paper.free_access) {
116+
paperKeywords.push("free access");
117+
}
118+
119+
const paperString = paperKeywords.join(" ");
126120

127-
return word_found;
121+
return !searchedKeywords.some((keyword) => !paperString.includes(keyword));
128122
};
129123
};
130124

131125
const getPropertyOrEmptyString = (object, property) => {
132126
if (Object.prototype.hasOwnProperty.call(object, property)) {
133-
return object[property].toString().toLowerCase();
127+
return object[property].toString().toLowerCase().trim();
134128
}
135129

136130
return "";

vis/stylesheets/components/_buttons.scss

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,10 @@ img#close-button {
180180
-moz-border-radius: 14px;
181181
-webkit-border-radius: 14px;
182182

183+
.highlighted {
184+
color: $okm-red;
185+
}
186+
183187
&:hover {
184188
color: $okm-modal-btn;
185189
background-color: white;

vis/stylesheets/modules/_footer.scss

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
.builtwith {
22
margin: 15px 10px 15px 50px;
33
font-size: 12px;
4-
// TODO this doesn't work on mobile (footer is unreadable)
54
height: 20px;
65
}
76

@@ -15,7 +14,31 @@
1514
}
1615
}
1716

18-
@media screen and (max-width: 640px) {
17+
@media screen and (max-width: 1210px) {
18+
.builtwith {
19+
font-size: 11px;
20+
}
21+
}
22+
23+
@media screen and (max-width: 1120px) {
24+
.builtwith {
25+
font-size: 10px;
26+
}
27+
}
28+
29+
@media screen and (max-width: 1030px) {
30+
.builtwith {
31+
font-size: 9px;
32+
}
33+
}
34+
35+
@media screen and (max-width: 1000px) {
36+
.builtwith {
37+
font-size: 10px;
38+
}
39+
}
40+
41+
@media screen and (max-width: 900px) {
1942
.builtwith {
2043
margin: 10px 0px 10px 20px;
2144
font-size: 11px;

vis/test/snapshot/__snapshots__/list-base.test.js.snap

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -430,7 +430,8 @@ exports[`List entries component snapshot (BASE) matches a snapshot (zoomed-in, p
430430
<i
431431
className="fa fa-eye"
432432
/>
433-
  PDF
433+
  
434+
PDF
434435
</button>
435436
<button
436437
className="paper_button"
@@ -864,7 +865,8 @@ exports[`List entries component snapshot (BASE) matches a snapshot (zoomed-out)
864865
<i
865866
className="fa fa-eye"
866867
/>
867-
  PDF
868+
  
869+
PDF
868870
</button>
869871
<button
870872
className="paper_button"
@@ -1158,7 +1160,8 @@ exports[`List entries component snapshot (BASE) matches a snapshot (zoomed-out)
11581160
<i
11591161
className="fa fa-eye"
11601162
/>
1161-
  PDF
1163+
  
1164+
PDF
11621165
</button>
11631166
<button
11641167
className="paper_button"
@@ -1589,7 +1592,8 @@ exports[`List entries component snapshot (BASE) matches a snapshot (zoomed-out)
15891592
<i
15901593
className="fa fa-eye"
15911594
/>
1592-
  PDF
1595+
  
1596+
PDF
15931597
</button>
15941598
<button
15951599
className="paper_button"
@@ -2842,7 +2846,8 @@ exports[`List entries component snapshot (BASE) matches a snapshot (zoomed-out)
28422846
<i
28432847
className="fa fa-eye"
28442848
/>
2845-
  PDF
2849+
  
2850+
PDF
28462851
</button>
28472852
<button
28482853
className="paper_button"
@@ -3121,7 +3126,8 @@ exports[`List entries component snapshot (BASE) matches a snapshot (zoomed-out)
31213126
<i
31223127
className="fa fa-eye"
31233128
/>
3124-
  PDF
3129+
  
3130+
PDF
31253131
</button>
31263132
<button
31273133
className="paper_button"
@@ -3411,7 +3417,8 @@ exports[`List entries component snapshot (BASE) matches a snapshot (zoomed-out)
34113417
<i
34123418
className="fa fa-eye"
34133419
/>
3414-
  PDF
3420+
  
3421+
PDF
34153422
</button>
34163423
<button
34173424
className="paper_button"

0 commit comments

Comments
 (0)