Skip to content

Commit c6de46d

Browse files
committed
[academic_query] fix building the query from view
SQUASHED: AUTO-COMMIT-src-components-widgets-academic-subquery.js,
1 parent f43f697 commit c6de46d

File tree

1 file changed

+44
-20
lines changed

1 file changed

+44
-20
lines changed

src/components/widgets/academic-subquery.js

Lines changed: 44 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,21 @@ export default class AcademicSubquery extends Morph {
146146
// to use the descriptions in the UI, we need to shorten some
147147
var createShortDescriptions = attr => {
148148
switch(attr.name) {
149+
case "AA.AdId":
150+
attr.shortDesc = "Affiliation ID";
151+
break;
152+
case "AA.AfN":
153+
attr.shortDesc = "Affiliation Name (normalized)";
154+
break;
155+
case "AA.AuN":
156+
attr.shortDesc = "Author Name (normalized)";
157+
break;
158+
case "AA.DAuN":
159+
attr.shortDesc = "Author Name (original)";
160+
break;
161+
case "AA.DAfN":
162+
attr.shortDesc = "Affiliation Name (original)";
163+
break;
149164
case "AW":
150165
attr.shortDesc = "Unique words in abstract";
151166
break;
@@ -158,6 +173,9 @@ export default class AcademicSubquery extends Morph {
158173
case "D":
159174
attr.shortDesc = "Date";
160175
break;
176+
case "DN":
177+
attr.shortDesc = "Paper Title";
178+
break;
161179
case "DOI":
162180
attr.shortDesc = "Digital Object Identifier";
163181
break;
@@ -167,6 +185,12 @@ export default class AcademicSubquery extends Morph {
167185
case "FamId":
168186
attr.shortDesc = "Family Group ID";
169187
break;
188+
case "F.DFN":
189+
attr.shortDesc = "Field of Study Name (original)";
190+
break;
191+
case "F.FN":
192+
attr.shortDesc = "Field of Study Name (normalized)";
193+
break;
170194
case "LP":
171195
attr.shortDesc = "Last Page";
172196
break;
@@ -176,6 +200,9 @@ export default class AcademicSubquery extends Morph {
176200
case "RId":
177201
attr.shortDesc = "Referenced Paper IDs";
178202
break;
203+
case "Ti":
204+
attr.shortDesc = "Title";
205+
break;
179206
case "VFN":
180207
attr.shortDesc = "Journal or Conf. name (full)";
181208
break;
@@ -191,8 +218,8 @@ export default class AcademicSubquery extends Morph {
191218
return attr;
192219
}
193220
this.schemaFiltered = this.schema
194-
.filter(attr => attr.operations != "None")
195-
.map(attr => createShortDescriptions(attr));
221+
.filter(attr => attr.operations != "None")
222+
.map(attr => createShortDescriptions(attr));
196223
// map words for operations to symbols for the query
197224
this.mapOperationToSymbol = op => {switch(op) {
198225
case "Equals":
@@ -365,38 +392,35 @@ export default class AcademicSubquery extends Morph {
365392
} else {
366393
var innerSpan = this.get('#inner');
367394
if (!innerSpan) { return query }
368-
var attr, comp, val;
395+
var attribute, comp, val;
369396
if (this.editing) { // edit mode
370397
var attrElement = innerSpan.querySelector('#attribute');
371-
attr = attrElement.options[attrElement.selectedIndex].value // or .text;
398+
attribute = attrElement.options[attrElement.selectedIndex].value // or .text;
372399
var compElement = innerSpan.querySelector('#comparator');
373400
comp = compElement.options[compElement.selectedIndex].value // or .text;
374401
val = innerSpan.querySelector('#value').value;
375402
} else { // read mode
376403
//lively.notify("INNERSPAN", innerSpan)
377-
[attr, comp, val] = innerSpan
404+
[attribute, comp, val] = innerSpan
378405
.querySelectorAll("span[name='queryPart']")
379406
.map(e => e.textContent);
380-
if (val)
381-
val = val.slice(0, val.length - 1); // remove last whitespace
382407
}
383408

409+
var currentAttribute;
410+
this.schemaFiltered.forEach(attr => {
411+
if (attr.name == attribute) {
412+
currentAttribute = attr;
413+
}})
384414

385-
386-
// TODO check if attribute has string value
387-
var stringAttributes = {
388-
"A": "Author",
389-
"AA.AuN": "Author Name",
390-
}
391-
if (attr.slice(0, attr.length - 1) in stringAttributes) {
415+
if (currentAttribute.type == "String") {
392416
val = "'" + val + "'"
393417
}
394-
// TODO: check if current attribute is composite (has .)
395-
//query = attr + comp + "'" + val + "'";
396-
if (innerSpan.getAttribute("type") == "composite")
397-
query = "Composite(" + attr + comp + val + ")";
418+
419+
if (currentAttribute.name.includes("."))
420+
query = "Composite(" + attribute + comp + val + ")";
421+
// TODO: Set type to Composite?
398422
else
399-
query = attr + comp + val;
423+
query = attribute + comp + val;
400424

401425

402426

@@ -507,7 +531,7 @@ export default class AcademicSubquery extends Morph {
507531
</span>;
508532
var query = <span name="sub" draggable='true'></span>;
509533
[ast.attribute, ast.comparator, ast.value].forEach(value => {
510-
query.appendChild(<span class="queryPart" name="queryPart">{value} </span>)
534+
query.appendChild(<span class="queryPart" name="queryPart">{value}</span>)
511535
query.addEventListener('mouseover', (evt) => this.onMouseOver(evt));
512536
query.addEventListener('mouseout', (evt) => this.onMouseOut(evt));
513537
query.style.cursor = "grab"

0 commit comments

Comments
 (0)