introduced NoteFull entity, fixes

This commit is contained in:
azivner 2018-03-25 23:25:17 -04:00
parent cdf94181d2
commit 35998058ce
15 changed files with 184 additions and 165 deletions

View File

@ -10,10 +10,10 @@
<collation id="4" parent="1" name="NOCASE"/> <collation id="4" parent="1" name="NOCASE"/>
<collation id="5" parent="1" name="RTRIM"/> <collation id="5" parent="1" name="RTRIM"/>
<table id="6" parent="2" name="api_tokens"/> <table id="6" parent="2" name="api_tokens"/>
<table id="7" parent="2" name="attributes"/> <table id="7" parent="2" name="branches"/>
<table id="8" parent="2" name="branches"/> <table id="8" parent="2" name="event_log"/>
<table id="9" parent="2" name="event_log"/> <table id="9" parent="2" name="images"/>
<table id="10" parent="2" name="images"/> <table id="10" parent="2" name="labels"/>
<table id="11" parent="2" name="note_images"/> <table id="11" parent="2" name="note_images"/>
<table id="12" parent="2" name="note_revisions"/> <table id="12" parent="2" name="note_revisions"/>
<table id="13" parent="2" name="notes"/> <table id="13" parent="2" name="notes"/>
@ -59,7 +59,7 @@
<Primary>1</Primary> <Primary>1</Primary>
<UnderlyingIndexName>sqlite_autoindex_api_tokens_1</UnderlyingIndexName> <UnderlyingIndexName>sqlite_autoindex_api_tokens_1</UnderlyingIndexName>
</key> </key>
<column id="26" parent="7" name="attributeId"> <column id="26" parent="7" name="branchId">
<Position>1</Position> <Position>1</Position>
<DataType>TEXT|0s</DataType> <DataType>TEXT|0s</DataType>
<NotNull>1</NotNull> <NotNull>1</NotNull>
@ -69,198 +69,198 @@
<DataType>TEXT|0s</DataType> <DataType>TEXT|0s</DataType>
<NotNull>1</NotNull> <NotNull>1</NotNull>
</column> </column>
<column id="28" parent="7" name="name"> <column id="28" parent="7" name="parentNoteId">
<Position>3</Position> <Position>3</Position>
<DataType>TEXT|0s</DataType> <DataType>TEXT|0s</DataType>
<NotNull>1</NotNull> <NotNull>1</NotNull>
</column> </column>
<column id="29" parent="7" name="value"> <column id="29" parent="7" name="notePosition">
<Position>4</Position>
<DataType>TEXT|0s</DataType>
<NotNull>1</NotNull>
<DefaultExpression>&apos;&apos;</DefaultExpression>
</column>
<column id="30" parent="7" name="position">
<Position>5</Position>
<DataType>INT|0s</DataType>
<NotNull>1</NotNull>
<DefaultExpression>0</DefaultExpression>
</column>
<column id="31" parent="7" name="dateCreated">
<Position>6</Position>
<DataType>TEXT|0s</DataType>
<NotNull>1</NotNull>
</column>
<column id="32" parent="7" name="dateModified">
<Position>7</Position>
<DataType>TEXT|0s</DataType>
<NotNull>1</NotNull>
</column>
<column id="33" parent="7" name="isDeleted">
<Position>8</Position>
<DataType>INT|0s</DataType>
<NotNull>1</NotNull>
</column>
<index id="34" parent="7" name="sqlite_autoindex_attributes_1">
<NameSurrogate>1</NameSurrogate>
<ColNames>attributeId</ColNames>
<ColumnCollations></ColumnCollations>
<Unique>1</Unique>
</index>
<index id="35" parent="7" name="IDX_attributes_noteId">
<ColNames>noteId</ColNames>
<ColumnCollations></ColumnCollations>
</index>
<index id="36" parent="7" name="IDX_attributes_name_value">
<ColNames>name
value</ColNames>
<ColumnCollations>
</ColumnCollations>
</index>
<key id="37" parent="7">
<ColNames>attributeId</ColNames>
<Primary>1</Primary>
<UnderlyingIndexName>sqlite_autoindex_attributes_1</UnderlyingIndexName>
</key>
<column id="38" parent="8" name="branchId">
<Position>1</Position>
<DataType>TEXT|0s</DataType>
<NotNull>1</NotNull>
</column>
<column id="39" parent="8" name="noteId">
<Position>2</Position>
<DataType>TEXT|0s</DataType>
<NotNull>1</NotNull>
</column>
<column id="40" parent="8" name="parentNoteId">
<Position>3</Position>
<DataType>TEXT|0s</DataType>
<NotNull>1</NotNull>
</column>
<column id="41" parent="8" name="notePosition">
<Position>4</Position> <Position>4</Position>
<DataType>INTEGER|0s</DataType> <DataType>INTEGER|0s</DataType>
<NotNull>1</NotNull> <NotNull>1</NotNull>
</column> </column>
<column id="42" parent="8" name="prefix"> <column id="30" parent="7" name="prefix">
<Position>5</Position> <Position>5</Position>
<DataType>TEXT|0s</DataType> <DataType>TEXT|0s</DataType>
</column> </column>
<column id="43" parent="8" name="isExpanded"> <column id="31" parent="7" name="isExpanded">
<Position>6</Position> <Position>6</Position>
<DataType>BOOLEAN|0s</DataType> <DataType>BOOLEAN|0s</DataType>
</column> </column>
<column id="44" parent="8" name="isDeleted"> <column id="32" parent="7" name="isDeleted">
<Position>7</Position> <Position>7</Position>
<DataType>INTEGER|0s</DataType> <DataType>INTEGER|0s</DataType>
<NotNull>1</NotNull> <NotNull>1</NotNull>
<DefaultExpression>0</DefaultExpression> <DefaultExpression>0</DefaultExpression>
</column> </column>
<column id="45" parent="8" name="dateModified"> <column id="33" parent="7" name="dateModified">
<Position>8</Position> <Position>8</Position>
<DataType>TEXT|0s</DataType> <DataType>TEXT|0s</DataType>
<NotNull>1</NotNull> <NotNull>1</NotNull>
</column> </column>
<index id="46" parent="8" name="sqlite_autoindex_branches_1"> <index id="34" parent="7" name="sqlite_autoindex_branches_1">
<NameSurrogate>1</NameSurrogate> <NameSurrogate>1</NameSurrogate>
<ColNames>branchId</ColNames> <ColNames>branchId</ColNames>
<ColumnCollations></ColumnCollations> <ColumnCollations></ColumnCollations>
<Unique>1</Unique> <Unique>1</Unique>
</index> </index>
<index id="47" parent="8" name="IDX_branches_noteId_parentNoteId"> <index id="35" parent="7" name="IDX_branches_noteId_parentNoteId">
<ColNames>noteId <ColNames>noteId
parentNoteId</ColNames> parentNoteId</ColNames>
<ColumnCollations> <ColumnCollations>
</ColumnCollations> </ColumnCollations>
</index> </index>
<index id="48" parent="8" name="IDX_branches_noteId"> <index id="36" parent="7" name="IDX_branches_noteId">
<ColNames>noteId</ColNames> <ColNames>noteId</ColNames>
<ColumnCollations></ColumnCollations> <ColumnCollations></ColumnCollations>
</index> </index>
<key id="49" parent="8"> <key id="37" parent="7">
<ColNames>branchId</ColNames> <ColNames>branchId</ColNames>
<Primary>1</Primary> <Primary>1</Primary>
<UnderlyingIndexName>sqlite_autoindex_branches_1</UnderlyingIndexName> <UnderlyingIndexName>sqlite_autoindex_branches_1</UnderlyingIndexName>
</key> </key>
<column id="50" parent="9" name="id"> <column id="38" parent="8" name="id">
<Position>1</Position> <Position>1</Position>
<DataType>INTEGER|0s</DataType> <DataType>INTEGER|0s</DataType>
<NotNull>1</NotNull> <NotNull>1</NotNull>
<SequenceIdentity>1</SequenceIdentity> <SequenceIdentity>1</SequenceIdentity>
</column> </column>
<column id="51" parent="9" name="noteId"> <column id="39" parent="8" name="noteId">
<Position>2</Position> <Position>2</Position>
<DataType>TEXT|0s</DataType> <DataType>TEXT|0s</DataType>
</column> </column>
<column id="52" parent="9" name="comment"> <column id="40" parent="8" name="comment">
<Position>3</Position> <Position>3</Position>
<DataType>TEXT|0s</DataType> <DataType>TEXT|0s</DataType>
</column> </column>
<column id="53" parent="9" name="dateAdded"> <column id="41" parent="8" name="dateAdded">
<Position>4</Position> <Position>4</Position>
<DataType>TEXT|0s</DataType> <DataType>TEXT|0s</DataType>
<NotNull>1</NotNull> <NotNull>1</NotNull>
</column> </column>
<key id="54" parent="9"> <key id="42" parent="8">
<ColNames>id</ColNames> <ColNames>id</ColNames>
<Primary>1</Primary> <Primary>1</Primary>
</key> </key>
<foreign-key id="55" parent="9"> <foreign-key id="43" parent="8">
<ColNames>noteId</ColNames> <ColNames>noteId</ColNames>
<RefTableName>notes</RefTableName> <RefTableName>notes</RefTableName>
<RefColNames>noteId</RefColNames> <RefColNames>noteId</RefColNames>
</foreign-key> </foreign-key>
<column id="56" parent="10" name="imageId"> <column id="44" parent="9" name="imageId">
<Position>1</Position> <Position>1</Position>
<DataType>TEXT|0s</DataType> <DataType>TEXT|0s</DataType>
<NotNull>1</NotNull> <NotNull>1</NotNull>
</column> </column>
<column id="57" parent="10" name="format"> <column id="45" parent="9" name="format">
<Position>2</Position> <Position>2</Position>
<DataType>TEXT|0s</DataType> <DataType>TEXT|0s</DataType>
<NotNull>1</NotNull> <NotNull>1</NotNull>
</column> </column>
<column id="58" parent="10" name="checksum"> <column id="46" parent="9" name="checksum">
<Position>3</Position> <Position>3</Position>
<DataType>TEXT|0s</DataType> <DataType>TEXT|0s</DataType>
<NotNull>1</NotNull> <NotNull>1</NotNull>
</column> </column>
<column id="59" parent="10" name="name"> <column id="47" parent="9" name="name">
<Position>4</Position> <Position>4</Position>
<DataType>TEXT|0s</DataType> <DataType>TEXT|0s</DataType>
<NotNull>1</NotNull> <NotNull>1</NotNull>
</column> </column>
<column id="60" parent="10" name="data"> <column id="48" parent="9" name="data">
<Position>5</Position> <Position>5</Position>
<DataType>BLOB|0s</DataType> <DataType>BLOB|0s</DataType>
</column> </column>
<column id="61" parent="10" name="isDeleted"> <column id="49" parent="9" name="isDeleted">
<Position>6</Position> <Position>6</Position>
<DataType>INT|0s</DataType> <DataType>INT|0s</DataType>
<NotNull>1</NotNull> <NotNull>1</NotNull>
<DefaultExpression>0</DefaultExpression> <DefaultExpression>0</DefaultExpression>
</column> </column>
<column id="62" parent="10" name="dateModified"> <column id="50" parent="9" name="dateModified">
<Position>7</Position> <Position>7</Position>
<DataType>TEXT|0s</DataType> <DataType>TEXT|0s</DataType>
<NotNull>1</NotNull> <NotNull>1</NotNull>
</column> </column>
<column id="63" parent="10" name="dateCreated"> <column id="51" parent="9" name="dateCreated">
<Position>8</Position> <Position>8</Position>
<DataType>TEXT|0s</DataType> <DataType>TEXT|0s</DataType>
<NotNull>1</NotNull> <NotNull>1</NotNull>
</column> </column>
<index id="64" parent="10" name="sqlite_autoindex_images_1"> <index id="52" parent="9" name="sqlite_autoindex_images_1">
<NameSurrogate>1</NameSurrogate> <NameSurrogate>1</NameSurrogate>
<ColNames>imageId</ColNames> <ColNames>imageId</ColNames>
<ColumnCollations></ColumnCollations> <ColumnCollations></ColumnCollations>
<Unique>1</Unique> <Unique>1</Unique>
</index> </index>
<key id="65" parent="10"> <key id="53" parent="9">
<ColNames>imageId</ColNames> <ColNames>imageId</ColNames>
<Primary>1</Primary> <Primary>1</Primary>
<UnderlyingIndexName>sqlite_autoindex_images_1</UnderlyingIndexName> <UnderlyingIndexName>sqlite_autoindex_images_1</UnderlyingIndexName>
</key> </key>
<column id="54" parent="10" name="labelId">
<Position>1</Position>
<DataType>TEXT|0s</DataType>
<NotNull>1</NotNull>
</column>
<column id="55" parent="10" name="noteId">
<Position>2</Position>
<DataType>TEXT|0s</DataType>
<NotNull>1</NotNull>
</column>
<column id="56" parent="10" name="name">
<Position>3</Position>
<DataType>TEXT|0s</DataType>
<NotNull>1</NotNull>
</column>
<column id="57" parent="10" name="value">
<Position>4</Position>
<DataType>TEXT|0s</DataType>
<NotNull>1</NotNull>
<DefaultExpression>&apos;&apos;</DefaultExpression>
</column>
<column id="58" parent="10" name="position">
<Position>5</Position>
<DataType>INT|0s</DataType>
<NotNull>1</NotNull>
<DefaultExpression>0</DefaultExpression>
</column>
<column id="59" parent="10" name="dateCreated">
<Position>6</Position>
<DataType>TEXT|0s</DataType>
<NotNull>1</NotNull>
</column>
<column id="60" parent="10" name="dateModified">
<Position>7</Position>
<DataType>TEXT|0s</DataType>
<NotNull>1</NotNull>
</column>
<column id="61" parent="10" name="isDeleted">
<Position>8</Position>
<DataType>INT|0s</DataType>
<NotNull>1</NotNull>
</column>
<index id="62" parent="10" name="sqlite_autoindex_labels_1">
<NameSurrogate>1</NameSurrogate>
<ColNames>labelId</ColNames>
<ColumnCollations></ColumnCollations>
<Unique>1</Unique>
</index>
<index id="63" parent="10" name="IDX_labels_noteId">
<ColNames>noteId</ColNames>
<ColumnCollations></ColumnCollations>
</index>
<index id="64" parent="10" name="IDX_labels_name_value">
<ColNames>name
value</ColNames>
<ColumnCollations>
</ColumnCollations>
</index>
<key id="65" parent="10">
<ColNames>labelId</ColNames>
<Primary>1</Primary>
<UnderlyingIndexName>sqlite_autoindex_labels_1</UnderlyingIndexName>
</key>
<column id="66" parent="11" name="noteImageId"> <column id="66" parent="11" name="noteImageId">
<Position>1</Position> <Position>1</Position>
<DataType>TEXT|0s</DataType> <DataType>TEXT|0s</DataType>

View File

@ -20,7 +20,7 @@ class Note extends Entity {
} }
isJson() { isJson() {
return this.type === "code" && this.mime === "application/json"; return this.mime === "application/json";
} }
isJavaScript() { isJavaScript() {

View File

@ -12,7 +12,7 @@ function showDialog() {
height: 500 height: 500
}); });
const noteText = noteDetailService.getCurrentNote().detail.content; const noteText = noteDetailService.getCurrentNote().content;
$noteSource.text(formatHtml(noteText)); $noteSource.text(formatHtml(noteText));
} }

View File

@ -0,0 +1,15 @@
import NoteShort from './note_short.js';
class NoteFull extends NoteShort {
constructor(treeCache, row) {
super(treeCache, row);
this.content = row.content;
if (this.isJson()) {
this.jsonContent = JSON.parse(this.content);
}
}
}
export default NoteFull;

View File

@ -9,6 +9,10 @@ class NoteShort {
this.hideInAutocomplete = row.hideInAutocomplete; this.hideInAutocomplete = row.hideInAutocomplete;
} }
isJson() {
return this.mime === "application/json";
}
async getBranches() { async getBranches() {
const branches = []; const branches = [];

View File

@ -164,7 +164,7 @@ $(document).tooltip({
if (notePath !== null) { if (notePath !== null) {
const noteId = treeUtils.getNoteIdFromNotePath(notePath); const noteId = treeUtils.getNoteIdFromNotePath(notePath);
noteDetailService.loadNote(noteId).then(note => callback(note.detail.content)); noteDetailService.loadNote(noteId).then(note => callback(note.content));
} }
}, },
close: function(event, ui) close: function(event, ui)

View File

@ -7,6 +7,8 @@ import server from './server.js';
import messagingService from "./messaging.js"; import messagingService from "./messaging.js";
import bundleService from "./bundle.js"; import bundleService from "./bundle.js";
import infoService from "./info.js"; import infoService from "./info.js";
import treeCache from "./tree_cache.js";
import NoteFull from "../entities/note_full.js";
const $noteTitle = $("#note-title"); const $noteTitle = $("#note-title");
@ -45,7 +47,7 @@ function getCurrentNote() {
} }
function getCurrentNoteId() { function getCurrentNoteId() {
return currentNote ? currentNote.detail.noteId : null; return currentNote ? currentNote.noteId : null;
} }
function noteChanged() { function noteChanged() {
@ -81,13 +83,13 @@ async function saveNoteIfChanged() {
await saveNoteToServer(note); await saveNoteToServer(note);
if (note.detail.isProtected) { if (note.isProtected) {
protectedSessionHolder.touchProtectedSession(); protectedSessionHolder.touchProtectedSession();
} }
} }
function updateNoteFromInputs(note) { function updateNoteFromInputs(note) {
if (note.detail.type === 'text') { if (note.type === 'text') {
let content = editor.getData(); let content = editor.getData();
// if content is only tags/whitespace (typically <p>&nbsp;</p>), then just make it empty // if content is only tags/whitespace (typically <p>&nbsp;</p>), then just make it empty
@ -96,32 +98,32 @@ function updateNoteFromInputs(note) {
content = ''; content = '';
} }
note.detail.content = content; note.content = content;
} }
else if (note.detail.type === 'code') { else if (note.type === 'code') {
note.detail.content = codeEditor.getValue(); note.content = codeEditor.getValue();
} }
else if (note.detail.type === 'search') { else if (note.type === 'search') {
note.detail.content = JSON.stringify({ note.content = JSON.stringify({
searchString: $searchString.val() searchString: $searchString.val()
}); });
} }
else if (note.detail.type === 'render' || note.detail.type === 'file') { else if (note.type === 'render' || note.type === 'file') {
// nothing // nothing
} }
else { else {
infoService.throwError("Unrecognized type: " + note.detail.type); infoService.throwError("Unrecognized type: " + note.type);
} }
const title = $noteTitle.val(); const title = $noteTitle.val();
note.detail.title = title; note.title = title;
treeService.setNoteTitle(note.detail.noteId, title); treeService.setNoteTitle(note.noteId, title);
} }
async function saveNoteToServer(note) { async function saveNoteToServer(note) {
await server.put('notes/' + note.detail.noteId, note); await server.put('notes/' + note.noteId, note);
isNoteChanged = false; isNoteChanged = false;
@ -129,7 +131,7 @@ async function saveNoteToServer(note) {
} }
function setNoteBackgroundIfProtected(note) { function setNoteBackgroundIfProtected(note) {
const isProtected = !!note.detail.isProtected; const isProtected = !!note.isProtected;
$noteDetailWrapper.toggleClass("protected", isProtected); $noteDetailWrapper.toggleClass("protected", isProtected);
$protectButton.toggle(!isProtected); $protectButton.toggle(!isProtected);
@ -143,7 +145,7 @@ function newNoteCreated() {
} }
async function setContent(content) { async function setContent(content) {
if (currentNote.detail.type === 'text') { if (currentNote.type === 'text') {
if (!editor) { if (!editor) {
await utils.requireLibrary(utils.CKEDITOR); await utils.requireLibrary(utils.CKEDITOR);
@ -157,7 +159,7 @@ async function setContent(content) {
$noteDetail.show(); $noteDetail.show();
} }
else if (currentNote.detail.type === 'code') { else if (currentNote.type === 'code') {
if (!codeEditor) { if (!codeEditor) {
await utils.requireLibrary(utils.CODE_MIRROR); await utils.requireLibrary(utils.CODE_MIRROR);
@ -186,7 +188,7 @@ async function setContent(content) {
// this needs to happen after the element is shown, otherwise the editor won't be refresheds // this needs to happen after the element is shown, otherwise the editor won't be refresheds
codeEditor.setValue(content); codeEditor.setValue(content);
const info = CodeMirror.findModeByMIME(currentNote.detail.mime); const info = CodeMirror.findModeByMIME(currentNote.mime);
if (info) { if (info) {
codeEditor.setOption("mode", info.mime); codeEditor.setOption("mode", info.mime);
@ -195,7 +197,7 @@ async function setContent(content) {
codeEditor.refresh(); codeEditor.refresh();
} }
else if (currentNote.detail.type === 'search') { else if (currentNote.type === 'search') {
$noteDetailSearch.show(); $noteDetailSearch.show();
try { try {
@ -223,9 +225,9 @@ async function loadNoteToEditor(noteId) {
$noteIdDisplay.html(noteId); $noteIdDisplay.html(noteId);
await protectedSessionService.ensureProtectedSession(currentNote.detail.isProtected, false); await protectedSessionService.ensureProtectedSession(currentNote.isProtected, false);
if (currentNote.detail.isProtected) { if (currentNote.isProtected) {
protectedSessionHolder.touchProtectedSession(); protectedSessionHolder.touchProtectedSession();
} }
@ -237,10 +239,10 @@ async function loadNoteToEditor(noteId) {
noteChangeDisabled = true; noteChangeDisabled = true;
$noteTitle.val(currentNote.detail.title); $noteTitle.val(currentNote.title);
noteTypeService.setNoteType(currentNote.detail.type); noteTypeService.setNoteType(currentNote.type);
noteTypeService.setNoteMime(currentNote.detail.mime); noteTypeService.setNoteMime(currentNote.mime);
$noteDetail.hide(); $noteDetail.hide();
$noteDetailSearch.hide(); $noteDetailSearch.hide();
@ -248,7 +250,7 @@ async function loadNoteToEditor(noteId) {
$noteDetailRender.html('').hide(); $noteDetailRender.html('').hide();
$noteDetailAttachment.hide(); $noteDetailAttachment.hide();
if (currentNote.detail.type === 'render') { if (currentNote.type === 'render') {
$noteDetailRender.show(); $noteDetailRender.show();
const bundle = await server.get('script/bundle/' + getCurrentNoteId()); const bundle = await server.get('script/bundle/' + getCurrentNoteId());
@ -257,15 +259,18 @@ async function loadNoteToEditor(noteId) {
bundleService.executeBundle(bundle); bundleService.executeBundle(bundle);
} }
else if (currentNote.detail.type === 'file') { else if (currentNote.type === 'file') {
const labels = await server.get('notes/' + currentNote.noteId + '/labels');
const labelMap = utils.toObject(labels, l => [l.name, l.value]);
$noteDetailAttachment.show(); $noteDetailAttachment.show();
$attachmentFileName.text(currentNote.labels.original_file_name); $attachmentFileName.text(labelMap.original_file_name);
$attachmentFileSize.text(currentNote.labels.file_size + " bytes"); $attachmentFileSize.text(labelMap.file_size + " bytes");
$attachmentFileType.text(currentNote.detail.mime); $attachmentFileType.text(currentNote.mime);
} }
else { else {
await setContent(currentNote.detail.content); await setContent(currentNote.content);
} }
noteChangeDisabled = false; noteChangeDisabled = false;
@ -299,7 +304,9 @@ async function loadLabelList() {
} }
async function loadNote(noteId) { async function loadNote(noteId) {
return await server.get('notes/' + noteId); const row = await server.get('notes/' + noteId);
return new NoteFull(treeCache, row);
} }
function getEditor() { function getEditor() {
@ -309,24 +316,24 @@ function getEditor() {
function focus() { function focus() {
const note = getCurrentNote(); const note = getCurrentNote();
if (note.detail.type === 'text') { if (note.type === 'text') {
$noteDetail.focus(); $noteDetail.focus();
} }
else if (note.detail.type === 'code') { else if (note.type === 'code') {
codeEditor.focus(); codeEditor.focus();
} }
else if (note.detail.type === 'render' || note.detail.type === 'file' || note.detail.type === 'search') { else if (note.type === 'render' || note.type === 'file' || note.type === 'search') {
// do nothing // do nothing
} }
else { else {
infoService.throwError('Unrecognized type: ' + note.detail.type); infoService.throwError('Unrecognized type: ' + note.type);
} }
} }
function getCurrentNoteType() { function getCurrentNoteType() {
const currentNote = getCurrentNote(); const currentNote = getCurrentNote();
return currentNote ? currentNote.detail.type : null; return currentNote ? currentNote.type : null;
} }
async function executeCurrentNote() { async function executeCurrentNote() {
@ -334,13 +341,13 @@ async function executeCurrentNote() {
// make sure note is saved so we load latest changes // make sure note is saved so we load latest changes
await saveNoteIfChanged(); await saveNoteIfChanged();
if (currentNote.detail.mime.endsWith("env=frontend")) { if (currentNote.mime.endsWith("env=frontend")) {
const bundle = await server.get('script/bundle/' + getCurrentNoteId()); const bundle = await server.get('script/bundle/' + getCurrentNoteId());
bundleService.executeBundle(bundle); bundleService.executeBundle(bundle);
} }
if (currentNote.detail.mime.endsWith("env=backend")) { if (currentNote.mime.endsWith("env=backend")) {
await server.post('script/run/' + getCurrentNoteId()); await server.post('script/run/' + getCurrentNoteId());
} }

View File

@ -1,6 +1,6 @@
import treeService from './tree.js'; import treeService from './tree.js';
import noteDetail from './note_detail.js'; import noteDetail from './note_detail.js';
import utils from './utils.js'; import server from './server.js';
import infoService from "./info.js"; import infoService from "./info.js";
const $executeScriptButton = $("#execute-script-button"); const $executeScriptButton = $("#execute-script-button");
@ -86,7 +86,7 @@ function NoteTypeModel() {
async function save() { async function save() {
const note = noteDetail.getCurrentNote(); const note = noteDetail.getCurrentNote();
await server.put('notes/' + note.detail.noteId await server.put('notes/' + note.noteId
+ '/type/' + encodeURIComponent(self.type()) + '/type/' + encodeURIComponent(self.type())
+ '/mime/' + encodeURIComponent(self.mime())); + '/mime/' + encodeURIComponent(self.mime()));

View File

@ -94,11 +94,11 @@ async function protectNoteAndSendToServer() {
noteDetail.updateNoteFromInputs(note); noteDetail.updateNoteFromInputs(note);
note.detail.isProtected = true; note.isProtected = true;
await noteDetail.saveNoteToServer(note); await noteDetail.saveNoteToServer(note);
treeService.setProtected(note.detail.noteId, note.detail.isProtected); treeService.setProtected(note.noteId, note.isProtected);
noteDetail.setNoteBackgroundIfProtected(note); noteDetail.setNoteBackgroundIfProtected(note);
} }
@ -110,11 +110,11 @@ async function unprotectNoteAndSendToServer() {
noteDetail.updateNoteFromInputs(note); noteDetail.updateNoteFromInputs(note);
note.detail.isProtected = false; note.isProtected = false;
await noteDetail.saveNoteToServer(note); await noteDetail.saveNoteToServer(note);
treeService.setProtected(note.detail.noteId, note.detail.isProtected); treeService.setProtected(note.noteId, note.isProtected);
noteDetail.setNoteBackgroundIfProtected(note); noteDetail.setNoteBackgroundIfProtected(note);
} }

View File

@ -1,4 +1,5 @@
import treeService from './tree.js'; import treeService from './tree.js';
import server from './server.js';
const $tree = $("#tree"); const $tree = $("#tree");
const $searchInput = $("input[name='search-text']"); const $searchInput = $("input[name='search-text']");
@ -45,6 +46,8 @@ async function doSearch() {
async function saveSearch() { async function saveSearch() {
const {noteId} = await server.post('search/' + encodeURIComponent($searchInput.val())); const {noteId} = await server.post('search/' + encodeURIComponent($searchInput.val()));
resetSearch();
await treeService.reload(); await treeService.reload();
await treeService.activateNode(noteId); await treeService.activateNode(noteId);

View File

@ -12,6 +12,7 @@ import recentNotesDialog from '../dialogs/recent_notes.js';
import editTreePrefixDialog from '../dialogs/edit_tree_prefix.js'; import editTreePrefixDialog from '../dialogs/edit_tree_prefix.js';
import treeCache from './tree_cache.js'; import treeCache from './tree_cache.js';
import infoService from "./info.js"; import infoService from "./info.js";
import Branch from '../entities/branch.js';
const $tree = $("#tree"); const $tree = $("#tree");
const $parentList = $("#parent-list"); const $parentList = $("#parent-list");
@ -615,25 +616,22 @@ function initFancyTree(branch) {
} }
async function loadSearchNote(searchNoteId) { async function loadSearchNote(searchNoteId) {
const note = await server.get('notes/' + searchNoteId); const searchNote = await noteDetailService.loadNote(searchNoteId);
const noteIds = await server.get('search/' + encodeURIComponent(searchNote.jsonContent.searchString));
const json = JSON.parse(note.detail.content);
const noteIds = await server.get('search/' + encodeURIComponent(json.searchString));
for (const noteId of noteIds) { for (const noteId of noteIds) {
const branchId = "virt" + utils.randomString(10); const branch = new Branch(treeCache, {
branchId: "virt" + utils.randomString(10),
treeCache.addBranch({
branchId: branchId,
noteId: noteId, noteId: noteId,
parentNoteId: searchNoteId, parentNoteId: searchNoteId,
prefix: '', prefix: '',
virtual: true virtual: true
}); });
treeCache.addBranch(branch);
} }
return await prepareBranchInner(await treeCache.getNote(searchNoteId)); return await prepareBranchInner(searchNote);
} }
function getTree() { function getTree() {

View File

@ -167,9 +167,9 @@ function toObject(array, fn) {
const obj = {}; const obj = {};
for (const item of array) { for (const item of array) {
const ret = fn(item); const [key, value] = fn(item);
obj[ret[0]] = ret[1]; obj[key] = value;
} }
return obj; return obj;

View File

@ -28,7 +28,7 @@
} }
async function validatorJavaScript(text, options) { async function validatorJavaScript(text, options) {
if (glob.getCurrentNote().detail.mime === 'application/json') { if (glob.getCurrentNote().mime === 'application/json') {
// eslint doesn't seem to validate pure JSON well // eslint doesn't seem to validate pure JSON well
return []; return [];
} }

View File

@ -5,7 +5,6 @@ const router = express.Router();
const auth = require('../../services/auth'); const auth = require('../../services/auth');
const sql = require('../../services/sql'); const sql = require('../../services/sql');
const notes = require('../../services/notes'); const notes = require('../../services/notes');
const labels = require('../../services/labels');
const log = require('../../services/log'); const log = require('../../services/log');
const utils = require('../../services/utils'); const utils = require('../../services/utils');
const protected_session = require('../../services/protected_session'); const protected_session = require('../../services/protected_session');
@ -26,20 +25,12 @@ router.get('/:noteId', auth.checkApiAuth, wrap(async (req, res, next) => {
protected_session.decryptNote(req, detail); protected_session.decryptNote(req, detail);
let labelMap = null;
if (detail.type === 'file') { if (detail.type === 'file') {
// no need to transfer attachment payload for this request // no need to transfer (potentially large) attachment payload for this request
detail.content = null; detail.content = null;
// labels contain important attachment metadata - filename and size
labelMap = await labels.getNoteLabelMap(noteId);
} }
res.send({ res.send(detail);
detail: detail,
labels: labelMap
});
})); }));
router.post('/:parentNoteId/children', auth.checkApiAuth, wrap(async (req, res, next) => { router.post('/:parentNoteId/children', auth.checkApiAuth, wrap(async (req, res, next) => {

View File

@ -26,7 +26,8 @@ router.post('/:searchString', auth.checkApiAuth, wrap(async (req, res, next) =>
const noteId = await notes.createNote('root', 'Search note', noteContent, { const noteId = await notes.createNote('root', 'Search note', noteContent, {
json: true, json: true,
type: 'search' type: 'search',
mime: "application/json"
}); });
res.send({ noteId }); res.send({ noteId });