From cfce7443388f6bf08dcfa0a5d1e97a009d02884d Mon Sep 17 00:00:00 2001
From: azivner
Date: Wed, 14 Nov 2018 17:26:07 +0100
Subject: [PATCH] method name refactoring
---
db/main_notes.sql | 2 +-
docs/backend_api/Note.html | 6 +++---
docs/backend_api/entities_note.js.html | 6 +++---
src/entities/note.js | 8 ++++----
.../javascripts/services/note_detail_relation_map.js | 2 +-
5 files changed, 12 insertions(+), 12 deletions(-)
diff --git a/db/main_notes.sql b/db/main_notes.sql
index 6735503ac..fbd3e4d4f 100644
--- a/db/main_notes.sql
+++ b/db/main_notes.sql
@@ -79,7 +79,7 @@ INSERT INTO notes VALUES('7H3OrcgB8Io6','Meeting minutes','bla bla bla ...
Miscellaneous notes done on monday ...
Interesting video: https://www.youtube.com/watch?v=_eSAF_qT_FY&feature=youtu.be
',0,0,'2018-08-29T17:29:24.548Z','2018-08-29T21:28:50.683Z','text','text/html','3ZuNMUCKI6');
INSERT INTO notes VALUES('qEi5St9PBPCP','Button',replace('api.addButtonToToolbar({\n title: ''Weight Tracker'',\n icon: ''star'',\n action: () => api.activateNote(''8LOr7xUMuWD4'')\n});','\n',char(10)),0,0,'2018-08-28T20:50:36.150Z','2018-08-28T21:01:26.563Z','code','application/javascript;env=frontend','N9f0m+DlQA');
INSERT INTO notes VALUES('kV2NwNNvepGF','JS code',replace('async function getChartData() {\n const days = await api.runOnServer(async () => {\n const notes = await api.getNotesWithLabel(''weight'');\n const days = [];\n\n for (const note of notes) {\n const date = await note.getLabelValue(''dateNote'');\n const weight = parseFloat(await note.getLabelValue(''weight''));\n\n if (date && weight) {\n days.push({ date, weight });\n }\n }\n\n days.sort((a, b) => a.date > b.date ? 1 : -1);\n\n return days;\n });\n\n const datasets = [\n {\n label: "Weight (kg)",\n backgroundColor: ''red'',\n borderColor: ''red'',\n data: days.map(day => day.weight),\n fill: false,\n spanGaps: true,\n datalabels: {\n display: false\n }\n }\n ];\n\n return {\n datasets: datasets,\n labels: days.map(day => day.date)\n };\n}\n\nconst ctx = $("#canvas")[0].getContext("2d");\n\nnew chartjs.Chart(ctx, {\n type: ''line'',\n data: await getChartData()\n});','\n',char(10)),0,0,'2018-08-28T20:50:36.092Z','2018-08-29T22:14:00.701Z','code','application/javascript;env=frontend','w+OzbwCEwQ');
-INSERT INTO notes VALUES('Dk5RGYzufXg3','JS code',replace('const persons = await api.runOnServer(async () => {\n const relationMapping = {\n isPartnerOf: "isPartnerOf",\n isChildOf: "hasChild",\n hasChild: "isChildOf"\n };\n \n const familyContainer = await api.originEntity.getRelationTarget(''familyContainer'');\n \n const persons = await familyContainer.findNotesWithLabel(''person'');\n const map = {};\n \n for (const person of persons) {\n const src = map[person.noteId] = map[person.noteId] || {};\n src.title = person.title;\n src.dateOfBirth = await person.getLabelValue(''dateOfBirth'') || '''';\n src.dateOfDeath = await person.getLabelValue(''dateOfDeath'') || '''';\n \n for (const relation of await person.getRelations()) {\n src[relation.name] = src[relation.name] || [];\n src[relation.name].push(relation.value);\n \n const trg = persons[relation.value] = persons[relation.value] || {};\n const inverseRelation = relationMapping[relation.name];\n \n trg[inverseRelation] = trg[inverseRelation] || [];\n trg[inverseRelation].push(person.noteId);\n }\n }\n \n return map;\n});\n\n// Create the input graph\nvar g = new dagreD3.graphlib.Graph()\n .setGraph({\n rankdir: "TB",\n ranksep: 100\n })\n .setDefaultEdgeLabel(function() { return {}; });\n\nfor (const noteId in persons) {\n const person = persons[noteId];\n \n const noteLink = await api.createNoteLink(noteId);\n \n g.setNode(noteId, { labelType: ''html'', label: noteLink[0].outerHTML \n + `${person.dateOfBirth.substr(0, 4)} - ${person.dateOfDeath.substr(0, 4)}
` });\n \n for (const childNoteId of (person.hasChild || [])) {\n g.setEdge(noteId, childNoteId);\n }\n}\n\ng.nodes().forEach(function(v) {\n var node = g.node(v);\n // Round the corners of the nodes\n node.rx = node.ry = 5;\n});\n\n// Create the renderer\nvar render = new dagreD3.render();\n\n// Set up an SVG group so that we can translate the final graph.\nvar svg = d3.select("svg"),\n svgGroup = svg.append("g");\n\n// Run the renderer. This is what draws the final graph.\nrender(d3.select("svg g"), g);\n\n// Center the graph\nvar xCenterOffset = (svg.attr("width") - g.graph().width) / 2;\nsvgGroup.attr("transform", "translate(" + xCenterOffset + ", 20)");\nsvg.attr("height", g.graph().height + 40);','\n',char(10)),0,0,'2018-08-28T20:50:21.939Z','2018-08-29T22:14:10.701Z','code','application/javascript;env=frontend','4CRzHnTsUv');
+INSERT INTO notes VALUES('Dk5RGYzufXg3','JS code',replace('const persons = await api.runOnServer(async () => {\n const relationMapping = {\n isPartnerOf: "isPartnerOf",\n isChildOf: "hasChild",\n hasChild: "isChildOf"\n };\n \n const familyContainer = await api.originEntity.getRelationTarget(''familyContainer'');\n \n const persons = await familyContainer.findChildNotesWithLabel(''person'');\n const map = {};\n \n for (const person of persons) {\n const src = map[person.noteId] = map[person.noteId] || {};\n src.title = person.title;\n src.dateOfBirth = await person.getLabelValue(''dateOfBirth'') || '''';\n src.dateOfDeath = await person.getLabelValue(''dateOfDeath'') || '''';\n \n for (const relation of await person.getRelations()) {\n src[relation.name] = src[relation.name] || [];\n src[relation.name].push(relation.value);\n \n const trg = persons[relation.value] = persons[relation.value] || {};\n const inverseRelation = relationMapping[relation.name];\n \n trg[inverseRelation] = trg[inverseRelation] || [];\n trg[inverseRelation].push(person.noteId);\n }\n }\n \n return map;\n});\n\n// Create the input graph\nvar g = new dagreD3.graphlib.Graph()\n .setGraph({\n rankdir: "TB",\n ranksep: 100\n })\n .setDefaultEdgeLabel(function() { return {}; });\n\nfor (const noteId in persons) {\n const person = persons[noteId];\n \n const noteLink = await api.createNoteLink(noteId);\n \n g.setNode(noteId, { labelType: ''html'', label: noteLink[0].outerHTML \n + `${person.dateOfBirth.substr(0, 4)} - ${person.dateOfDeath.substr(0, 4)}
` });\n \n for (const childNoteId of (person.hasChild || [])) {\n g.setEdge(noteId, childNoteId);\n }\n}\n\ng.nodes().forEach(function(v) {\n var node = g.node(v);\n // Round the corners of the nodes\n node.rx = node.ry = 5;\n});\n\n// Create the renderer\nvar render = new dagreD3.render();\n\n// Set up an SVG group so that we can translate the final graph.\nvar svg = d3.select("svg"),\n svgGroup = svg.append("g");\n\n// Run the renderer. This is what draws the final graph.\nrender(d3.select("svg g"), g);\n\n// Center the graph\nvar xCenterOffset = (svg.attr("width") - g.graph().width) / 2;\nsvgGroup.attr("transform", "translate(" + xCenterOffset + ", 20)");\nsvg.attr("height", g.graph().height + 40);','\n',char(10)),0,0,'2018-08-28T20:50:21.939Z','2018-08-29T22:14:10.701Z','code','application/javascript;env=frontend','4CRzHnTsUv');
INSERT INTO notes VALUES('ucC6Zabv3Uml','CS',replace('/* This sets the color for "TK" nodes to a light blue green. */\ng.type-TK > rect {\n fill: #00ffd0;\n}\n\ntext {\n font-weight: 300;\n font-family: "Helvetica Neue", Helvetica, Arial, sans-serf;\n font-size: 14px;\n}\n\n.node rect {\n stroke: #999;\n fill: #fff;\n stroke-width: 1.5px;\n}\n\n.edgePath path {\n stroke: #333;\n stroke-width: 1.5px;\n}','\n',char(10)),0,0,'2018-08-28T20:50:22.120Z','2018-08-29T22:14:15.695Z','code','text/css','i19l+E0YSl');
INSERT INTO notes VALUES('gYNJtGEPGW95','CSS',replace('span.fancytree-node.todo .fancytree-title {\n color: red !important;\n}\n\nspan.fancytree-node.done .fancytree-title {\n color: green !important;\n}','\n',char(10)),0,0,'2018-08-28T20:50:48.581Z','2018-08-29T22:14:28.006Z','code','text/css','gz0KCewmIx');
INSERT INTO notes VALUES('s0Hhsl0nb1bg','Queen Elizabeth II.','
Elizabeth II (Elizabeth Alexandra Mary; born 21 April 1926)[a] is Queen of the United Kingdom and the other Commonwealth realms.
Elizabeth was born in London as the first child of the Duke and Duchess of York, later King George VI and Queen Elizabeth, and she was educated privately at home. Her father acceded to the throne on the abdication of his brother King Edward VIII in 1936, from which time she was the heir presumptive. She began to undertake public duties during the Second World War, serving in the Auxiliary Territorial Service. In 1947, she married Philip, Duke of Edinburgh, a former prince of Greece and Denmark, with whom she has four children: Charles, Prince of Wales; Anne, Princess Royal; Andrew, Duke of York; and Edward, Earl of Wessex.
When her father died in February 1952, she became Head of the Commonwealth and queen regnant of seven independent Commonwealth countries: the United Kingdom, Canada, Australia, New Zealand, South Africa, Pakistan, and Ceylon.
',0,0,'2018-08-28T20:50:22.196Z','2018-08-29T22:32:40.728Z','text','text/html','Fno0n5c24z');
diff --git a/docs/backend_api/Note.html b/docs/backend_api/Note.html
index 04446ec7e..448585529 100644
--- a/docs/backend_api/Note.html
+++ b/docs/backend_api/Note.html
@@ -438,7 +438,7 @@
- (async) findNotesWithAttribute(type, name, valueopt) → {Promise.<Array.<Note>>}
+ (async) findChildNotesWithAttribute(type, name, valueopt) → {Promise.<Array.<Note>>}
@@ -665,7 +665,7 @@
- (async) findNotesWithLabel(name, valueopt) → {Promise.<Array.<Note>>}
+ (async) findChildNotesWithLabel(name, valueopt) → {Promise.<Array.<Note>>}
@@ -861,7 +861,7 @@
- (async) findNotesWithRelation(name, valueopt) → {Promise.<Array.<Note>>}
+ (async) findChildNotesWithRelation(name, valueopt) → {Promise.<Array.<Note>>}
diff --git a/docs/backend_api/entities_note.js.html b/docs/backend_api/entities_note.js.html
index dedb6c6f9..b2ff9f0de 100644
--- a/docs/backend_api/entities_note.js.html
+++ b/docs/backend_api/entities_note.js.html
@@ -468,7 +468,7 @@ class Note extends Entity {
* @param {string} [value] - attribute value
* @returns {Promise<Note[]>}
*/
- async findNotesWithAttribute(type, name, value) {
+ async findChildNotesWithAttribute(type, name, value) {
const params = [this.noteId, name];
let valueCondition = "";
@@ -506,7 +506,7 @@ class Note extends Entity {
* @param {string} [value] - label value
* @returns {Promise<Note[]>}
*/
- async findNotesWithLabel(name, value) { return await this.findNotesWithAttribute(LABEL, name, value); }
+ async findChildNotesWithLabel(name, value) { return await this.findChildNotesWithAttribute(LABEL, name, value); }
/**
* Finds notes with given relation name and value. Only own relations are considered, not inherited ones
@@ -515,7 +515,7 @@ class Note extends Entity {
* @param {string} [value] - relation value
* @returns {Promise<Note[]>}
*/
- async findNotesWithRelation(name, value) { return await this.findNotesWithAttribute(RELATION, name, value); }
+ async findChildNotesWithRelation(name, value) { return await this.findChildNotesWithAttribute(RELATION, name, value); }
/**
* Returns note revisions of this note.
diff --git a/src/entities/note.js b/src/entities/note.js
index efeade002..4c9aaa6a5 100644
--- a/src/entities/note.js
+++ b/src/entities/note.js
@@ -433,14 +433,14 @@ class Note extends Entity {
}
/**
- * Finds notes with given attribute name and value. Only own attributes are considered, not inherited ones
+ * Finds child notes with given attribute name and value. Only own attributes are considered, not inherited ones
*
* @param {string} type - attribute type (label, relation, etc.)
* @param {string} name - attribute name
* @param {string} [value] - attribute value
* @returns {Promise}
*/
- async findNotesWithAttribute(type, name, value) {
+ async findChildNotesWithAttribute(type, name, value) {
const params = [this.noteId, name];
let valueCondition = "";
@@ -478,7 +478,7 @@ class Note extends Entity {
* @param {string} [value] - label value
* @returns {Promise}
*/
- async findNotesWithLabel(name, value) { return await this.findNotesWithAttribute(LABEL, name, value); }
+ async findChildNotesWithLabel(name, value) { return await this.findChildNotesWithAttribute(LABEL, name, value); }
/**
* Finds notes with given relation name and value. Only own relations are considered, not inherited ones
@@ -487,7 +487,7 @@ class Note extends Entity {
* @param {string} [value] - relation value
* @returns {Promise}
*/
- async findNotesWithRelation(name, value) { return await this.findNotesWithAttribute(RELATION, name, value); }
+ async findChildNotesWithRelation(name, value) { return await this.findChildNotesWithAttribute(RELATION, name, value); }
/**
* Returns note revisions of this note.
diff --git a/src/public/javascripts/services/note_detail_relation_map.js b/src/public/javascripts/services/note_detail_relation_map.js
index 0d3edd552..101959a91 100644
--- a/src/public/javascripts/services/note_detail_relation_map.js
+++ b/src/public/javascripts/services/note_detail_relation_map.js
@@ -420,7 +420,7 @@ async function createNoteBox(noteId, title, x, y) {
const $noteBox = $("")
.addClass("note-box")
.prop("id", noteIdToId(noteId))
- .append($("
").addClass("title").html(await linkService.createNoteLink(noteId, title)).append(`[${Math.floor(x)}, ${Math.floor(y)}]`))
+ .append($("").addClass("title").html(await linkService.createNoteLink(noteId, title)))
.append($("").addClass("endpoint").attr("title", "Start dragging relations from here and drop them on another note."))
.css("left", x + "px")
.css("top", y + "px");