import linkService from "./link.js";
import noteContentRenderer from "./note_content_renderer.js";
import treeCache from "./tree_cache.js";
const ZOOMS = {
1: {
width: "100%",
height: "100%"
},
2: {
width: "49%",
height: "350px"
},
3: {
width: "32%",
height: "250px"
},
4: {
width: "24%",
height: "200px"
},
5: {
width: "19%",
height: "175px"
},
6: {
width: "16%",
height: "150px"
}
};
const zoomLevel = 2;
const TPL = `
')
.css("max-height", ZOOMS[zoomLevel].height);
const $card = $('
')
.attr('data-note-id', note.noteId)
.css("flex-basis", ZOOMS[zoomLevel].width)
.append($('
').append(await linkService.createNoteLink(notePath, {showTooltip: false})))
.append($content);
try {
const {type, renderedContent} = await noteContentRenderer.getRenderedContent(note);
$card.addClass("type-" + type);
$content.append(renderedContent);
} catch (e) {
console.log(`Caught error while rendering note ${note.noteId} of type ${note.type}: ${e.message}, stack: ${e.stack}`);
$content.append("rendering error");
}
const imageLinks = note.getRelations('imageLink');
const childCount = note.getChildNoteIds()
.filter(childNoteId => !imageLinks.find(rel => rel.value === childNoteId))
.length;
if (childCount > 0) {
const label = `${childCount} child${childCount > 1 ? 'ren' : ''}`;
$card.append($('')
.append($(`
+ Show ${label}`))
.append($(`
- Hide ${label}`).hide())
.append($('
'))
);
}
return $card;
}
async function expandCard($card) {
const noteId = $card.attr('data-note-id');
const note = await treeCache.getNote(noteId);
$card.find('.note-book-open-children-button').hide();
$card.find('.note-book-hide-children-button').show();
$card.find('.note-book-children-content').append(await renderList(await note.getChildNotes(), note));
}
function setZoom(zoomLevel) {
if (!(zoomLevel in ZOOMS)) {
zoomLevel = this.getDefaultZoomLevel();
}
this.zoomLevel = zoomLevel;
this.$zoomInButton.prop("disabled", zoomLevel === MIN_ZOOM_LEVEL);
this.$zoomOutButton.prop("disabled", zoomLevel === MAX_ZOOM_LEVEL);
this.$content.find('.note-book-card').css("flex-basis", ZOOMS[zoomLevel].width);
this.$content.find('.note-book-content').css("max-height", ZOOMS[zoomLevel].height);
}
export default {
renderList
};