Skip to content

Commit 4ae6cba

Browse files
committed
[academic_query] remove annoying MutationObserver and ... done_
SQUASHED: AUTO-COMMIT-demos-bibliographie-academic-histogram.md,AUTO-COMMIT-demos-visualizations-academic-histogram.md,AUTO-COMMIT-src-components-widgets-academic-query.js,AUTO-COMMIT-src-components-widgets-academic-subquery.html,AUTO-COMMIT-src-components-widgets-academic-subquery.js,
1 parent 871cf37 commit 4ae6cba

File tree

3 files changed

+17
-133
lines changed

3 files changed

+17
-133
lines changed

demos/bibliographie/leoUIexample.md renamed to demos/bibliographie/academic-histogram.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import AcademicQuery from "src/components/widgets/academic-query.js"
1111

1212
import files from "src/client/files.js"
1313

14-
const default_query="Composite(AA.AuId=2055148755)"
14+
const default_query="Y=2020"
1515
const default_count = 1000
1616
const default_min = 0
1717
const default_attr = "F.FN"
Lines changed: 7 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,13 @@
11
import Morph from 'src/components/widgets/lively-morph.js';
22
import AcademicSubquery from "src/components/widgets/academic-subquery.js";
33

4-
var timeout;
5-
64
export default class AcademicQuery extends Morph {
75
constructor() {
86
super();
97
}
108

119
async initialize() {
1210
this.updateView();
13-
14-
// alternativ immer das AcademicQuery object mitgeben
15-
// und dem Bescheid geben, wenn ein update ist
16-
// (alles kacke)
17-
// idealerweise bemerkt der hier schon, wenn sich
18-
// irgendwo unter ihm Text ändert
19-
var observer = new MutationObserver((mutations) => {
20-
mutations.forEach(async mutation => {
21-
//lively.notify("SUPER observation", mutation.type)
22-
clearTimeout(timeout);
23-
timeout = setTimeout(async () => {
24-
if (mutation.type == "childList") {
25-
if (this.subquery) {
26-
this.textContent = await this.subquery.viewToQuery();
27-
var queryText = this.get('#queryText');
28-
queryText.innerHTML = this.getQuery();
29-
}
30-
}
31-
}, 1000);
32-
})
33-
});
34-
35-
const config = {
36-
attributes: true,
37-
childList: true,
38-
subtree: true,
39-
attributeOldValue: true,
40-
characterDataOldValue: true,
41-
//attributeFilter: true // breaks for some reason
42-
};
43-
44-
observer.observe(this.get('#pane'), config);
4511
}
4612

4713
async setQuery(q) {
@@ -57,12 +23,19 @@ export default class AcademicQuery extends Morph {
5723
getQuery() {
5824
return this.textContent;
5925
}
26+
27+
async update(){
28+
this.textContent = await this.subquery.viewToQuery();
29+
var queryText = this.get('#queryText');
30+
queryText.innerHTML = this.getQuery();
31+
}
6032

6133
async updateView() {
6234
if(!this.subquery) { return }
6335
var pane = this.get("#pane")
6436
var queryView = <academic-subquery></academic-subquery>;
6537
queryView = this.subquery;
38+
queryView.parentQuery = this;
6639

6740
var queryText = <span id="queryText" style="width: 300px; font-style: italic; color: lightgray;">{this.textContent}</span>;
6841
var searchButton = <button click={() => lively.openBrowser("academic://expr:" + this.textContent + "?count=100")}>search</button>;
@@ -81,10 +54,6 @@ export default class AcademicQuery extends Morph {
8154

8255
async livelyExample() {
8356
this.setQuery("Composite(AA.AuId = 2055148755)")
84-
//this.setQuery("And(Composite(AA.AuId = 2154319088),Y = 2020)")
85-
//this.setQuery("And(O='abc', Y='1000')")
86-
//this.setQuery("Y='1000'")
8757
}
8858

89-
9059
}

src/components/widgets/academic-subquery.js

Lines changed: 9 additions & 94 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,6 @@ import ohm from "https://unpkg.com/[email protected]/dist/ohm.js";
33
import {Author, Paper, MicrosoftAcademicEntities} from "src/client/literature.js";
44
import files from "src/client/files.js"
55

6-
/*MD
7-
# Blabla
8-
Strg + Alt + P
9-
oder Alt + P MD*/
10-
11-
/*MD <edit://src/components/widgets/academic-subquery.html>
12-
oder browse://
13-
#TODO MD*/
146
var g = ohm.grammar(
157
`Academic {
168
Exp =
@@ -132,53 +124,14 @@ s.addOperation(
132124
}
133125
)
134126

135-
var observer;
136-
var timeout;
137-
138127
export default class AcademicSubquery extends Morph {
139128
constructor() {
140129
super();
141130
}
142131

143-
/*MD ## Init MD*/
144132
async initialize() {
145133
this.updateView();
146134

147-
observer = new MutationObserver((mutations) => {
148-
clearTimeout(timeout);
149-
timeout = setTimeout(async () => {
150-
mutations.forEach(async mutation => {
151-
if (mutation.type == "characterData") {
152-
//this.textContent = await this.viewToQuery();
153-
}
154-
if (mutation.type == "childList") {
155-
// TODO: better propagation to super elements
156-
var div = <div id="update"></div>;
157-
this.appendChild(div);
158-
this.removeChild(div);
159-
160-
}
161-
})
162-
}, 300);
163-
});
164-
const config = {
165-
attributes: true,
166-
childList: true,
167-
subtree: true,
168-
attributeOldValue: true,
169-
characterDataOldValue: true,
170-
};
171-
observer.observe(this.get('#pane'), config);
172-
173-
// TODO: falls ich das umbaue, sodass eine subquery einfach als
174-
// html Element in updateView erstellt wird, muss das hier auch da rein
175-
/* this.addEventListener('dragstart', (evt) => this.onDragStart(evt))
176-
this.addEventListener('dragend', (evt) => this.onDragEnd(evt))
177-
this.addEventListener('dragover', (evt) => this.onDragOver(evt))
178-
this.addEventListener('dragenter', (evt) => this.onDragEnter(evt))
179-
this.addEventListener('dragleave', (evt) => this.onDragLeave(evt))
180-
this.addEventListener('drop', (evt) => this.onDrop(evt))
181-
*/
182135
this.style.draggable = 'true';
183136
}
184137

@@ -281,38 +234,24 @@ export default class AcademicSubquery extends Morph {
281234
}
282235

283236
onDragStart(event) {
284-
//event.dataTransfer.setData("element", event.target.id);
285237
this.style.opacity = '0.4';
286238
this.style.color = "black";
287239

288-
// var id = lively.ensureID(this)
289-
// this.id = id
290-
291240
event.dataTransfer.effectAllowed = 'move';
292241
event.dataTransfer.setData('text', this.queryElement.getQuery()); // set Query as info
293-
//event.dataTransfer.setData("application/lively4id", id);
294242
}
295243

296244
onDragEnd(event) {
297-
//event.dataTransfer.setData("element", event.target.id);
298245
this.style.opacity = '1.0';
299246
}
300247

301248
onDragOver(event) {
302-
//event.dataTransfer.setData("element", event.target.id);
303-
// the next line should not be neccessary with onDragEnter()...
304249
this.classList.add('over');
305-
//this.style.border = '3px dotted #666';
306250
}
307251

308252
onDrop(event) {
309253
event.preventDefault();
310254
event.stopPropagation();
311-
//if (this.dragStart !== this) {
312-
//var id = event.dataTransfer.getData("application/lively4id")
313-
//var el = lively.query(this, "#"+id);
314-
//lively.notify("ELEMENT", el);
315-
//lively.notify("MATCH", g.match(query));
316255
var query = event.dataTransfer.getData("text");
317256
this.classList.remove('over');
318257
try {
@@ -327,16 +266,12 @@ export default class AcademicSubquery extends Morph {
327266

328267
onDragEnter(event) {
329268
event.preventDefault();
330-
//if (!this.complexQuery) this.style.border = '3px dotted #666';
331-
//lively.notify("ENTERED THIS", this.classList)
332269
this.classList.add('over');
333270
}
334271

335272
onDragLeave(event) {
336273
event.preventDefault();
337274
this.classList.remove('over');
338-
339-
//if (!this.isComplex) this.style.border = '3px dotted #FFF';
340275
}
341276

342277

@@ -357,46 +292,33 @@ export default class AcademicSubquery extends Morph {
357292
this.ui.addEventListener('drop', this.onDrop)
358293
}
359294
this.ui.queryElement = this; // for drag and drop
360-
/*if (!this.isComplex) {
361-
this.addEventListener('dragstart', this.onDragStart)
362-
this.addEventListener('dragend', this.onDragEnd)
363-
this.addEventListener('dragover', this.onDragOver)
364-
this.addEventListener('dragenter', this.onDragEnter)
365-
this.addEventListener('dragleave', this.onDragLeave)
366-
this.addEventListener('drop', this.onDrop)
367-
}*/
295+
368296
pane.appendChild(this.ui)
369297
}
370298

299+
async update(){
300+
if (this.parentQuery) await this.parentQuery.update();
301+
}
302+
371303
async setQuery(q) {
372304
this.textContent = q;
373305

374306
var match = g.match(q);
375307
this.ast = s(match).interpret();
376308
this.ui = await this.queryToView(this.ast);
377309

378-
this.updateView()
310+
this.updateView();
311+
if (this.parentQuery) await this.parentQuery.update();
379312
}
380313

381314
getQuery() {
382315
return this.textContent;
383316
}
384-
385-
async setQueryObject(o) {
386-
this.ast = o
387-
this.ui = await this.queryToView();
388-
389-
this.updateView();
390-
391-
// when only setting the query object, the query might not be set yet
392-
this.textContent = await this.viewToQuery();
393-
}
394317

395318
async viewToQuery() {
396319
var query = this.textContent;
397320

398321
if (this.isComplex) { // conjunction
399-
// TODO: Why is this neccessary?
400322
if (await this.leftSubquery && await this.rightSubquery) {
401323
var left = await this.leftSubquery.viewToQuery();
402324
var right = await this.rightSubquery.viewToQuery();
@@ -420,7 +342,6 @@ export default class AcademicSubquery extends Morph {
420342
comp = compElement.options[compElement.selectedIndex].value; // or .text;
421343
val = innerSpan.querySelector('#value').value;
422344
} else { // read mode
423-
//lively.notify("INNERSPAN", innerSpan)
424345
[attribute, comp, val] = innerSpan
425346
.querySelectorAll("span[name='queryPart']")
426347
.map(e => e.textContent);
@@ -439,7 +360,6 @@ export default class AcademicSubquery extends Morph {
439360

440361
if (currentAttribute.name.match(/\./))
441362
query = "Composite(" + currentAttribute.name + comp + val + ")";
442-
// TODO: Set type to Composite?
443363
else
444364
query = currentAttribute.name + comp + val;
445365
}
@@ -455,7 +375,6 @@ export default class AcademicSubquery extends Morph {
455375
this.editing = !this.editing;
456376
lively.notify("Please enter a value!", e.message)
457377
}
458-
//this.ui = await this.queryToView(); // update ui to read-mode
459378
this.updateView();
460379
}
461380

@@ -562,13 +481,13 @@ export default class AcademicSubquery extends Morph {
562481
var conjunction = <span id="conjunction" contenteditable="false" style="font-size: 150%">{ast.conjunction}</span>;
563482

564483
var left = await (<academic-subquery style="font-size: smaller;"></academic-subquery>);
565-
//await left.setQueryObject(ast.left); // TODO: Remove all traces this ever existed
566484
await left.setQuery(leftQuery);
485+
left.parentQuery = this;
567486
this.leftSubquery = left; // for viewToQuery
568487

569488
var right = await (<academic-subquery style="font-size: smaller;"></academic-subquery>);
570-
//await right.setQueryObject(ast.right);
571489
await right.setQuery(rightQuery);
490+
right.parentQuery = this;
572491
this.rightSubquery = right; // for viewToQuery
573492
inner.appendChild(
574493
<table>
@@ -691,10 +610,6 @@ export default class AcademicSubquery extends Morph {
691610

692611
async livelyExample() {
693612
this.setQuery("Composite(AA.AuN=='susan t dumais')");
694-
//this.setQuery("Composite(AA.AuId=2055148755)")
695-
//this.setQuery("And(Or(Y=1985, Y=2008), Ti='disordered electronic systems')")
696-
//this.setQuery("And(O='abc', Y=1000)")
697-
//this.setQuery("Y='1000'")
698613
}
699614

700615

0 commit comments

Comments
 (0)