added "auto book" displayed on the empty text pages as a replacement for children overview

This commit is contained in:
zadam 2019-10-05 20:27:30 +02:00
parent cbc7710d81
commit 516277a478
6 changed files with 55 additions and 21 deletions

View File

@ -1,6 +1,6 @@
'use strict'; 'use strict';
const electron = require('electron'); const {app, globalShortcut, BrowserWindow} = require('electron');
const path = require('path'); const path = require('path');
const log = require('./src/services/log'); const log = require('./src/services/log');
const sqlInit = require('./src/services/sql_init'); const sqlInit = require('./src/services/sql_init');
@ -12,9 +12,6 @@ const appIconService = require('./src/services/app_icon');
const windowStateKeeper = require('electron-window-state'); const windowStateKeeper = require('electron-window-state');
const contextMenu = require('electron-context-menu'); const contextMenu = require('electron-context-menu');
const app = electron.app;
const globalShortcut = electron.globalShortcut;
// Adds debug features like hotkeys for triggering dev tools and reload // Adds debug features like hotkeys for triggering dev tools and reload
require('electron-debug')(); require('electron-debug')();
@ -66,7 +63,7 @@ async function createMainWindow() {
defaultHeight: 800 defaultHeight: 800
}); });
const win = new electron.BrowserWindow({ const win = new BrowserWindow({
x: mainWindowState.x, x: mainWindowState.x,
y: mainWindowState.y, y: mainWindowState.y,
width: mainWindowState.width, width: mainWindowState.width,

View File

@ -94,7 +94,7 @@ class NoteDetailBook {
setZoom(zoomLevel) { setZoom(zoomLevel) {
if (!(zoomLevel in ZOOMS)) { if (!(zoomLevel in ZOOMS)) {
zoomLevel = 1; zoomLevel = this.getDefaultZoomLevel();
} }
this.zoomLevel = zoomLevel; this.zoomLevel = zoomLevel;
@ -109,7 +109,18 @@ class NoteDetailBook {
async render() { async render() {
this.$content.empty(); this.$content.empty();
const zoomLevel = parseInt(await this.ctx.note.getLabelValue('bookZoomLevel')) || 1; if (this.isAutoBook()) {
const $addTextLink = $('<a href="javascript:">here</a>').click(() => {
this.ctx.renderComponent(true);
});
this.$content.append($('<div class="note-book-auto-message"></div>')
.append(`This note doesn't have any content so we display it's children. Click `)
.append($addTextLink)
.append(' if you want to add some text.'))
}
const zoomLevel = parseInt(await this.ctx.note.getLabelValue('bookZoomLevel')) || this.getDefaultZoomLevel();
this.setZoom(zoomLevel); this.setZoom(zoomLevel);
await this.renderIntoElement(this.ctx.note, this.$content); await this.renderIntoElement(this.ctx.note, this.$content);
@ -148,7 +159,7 @@ class NoteDetailBook {
const $content = $("<div>").html(fullNote.content); const $content = $("<div>").html(fullNote.content);
if (!fullNote.content.toLowerCase().includes("<img") && $content.text().trim() === "") { if (utils.isHtmlEmpty(fullNote.content)) {
return ""; return "";
} }
else { else {
@ -208,6 +219,15 @@ class NoteDetailBook {
} }
} }
/** @return {boolean} true if this is "auto book" activated (empty text note) and not explicit book note */
isAutoBook() {
return this.ctx.note.type !== 'book';
}
getDefaultZoomLevel() {
return this.isAutoBook() ? 3 : 1;
}
getContent() {} getContent() {}
show() { show() {

View File

@ -115,13 +115,13 @@ class TabContext {
await this.initComponent(); await this.initComponent();
} }
async initComponent() { async initComponent(disableAutoBook = false) {
const type = this.getComponentType(); this.type = this.getComponentType(disableAutoBook);
if (!(type in this.components)) { if (!(this.type in this.components)) {
const clazz = await import(componentClasses[type]); const clazz = await import(componentClasses[this.type]);
this.components[type] = new clazz.default(this); this.components[this.type] = new clazz.default(this);
} }
} }
@ -208,11 +208,11 @@ class TabContext {
this.setTitleBar(); this.setTitleBar();
} }
async renderComponent() { async renderComponent(disableAutoBook = false) {
await this.initComponent(); await this.initComponent(disableAutoBook);
for (const componentType in this.components) { for (const componentType in this.components) {
if (componentType !== this.getComponentType()) { if (componentType !== this.type) {
this.components[componentType].cleanup(); this.components[componentType].cleanup();
} }
} }
@ -281,18 +281,20 @@ class TabContext {
} }
getComponent() { getComponent() {
const type = this.getComponentType(); return this.components[this.type];
return this.components[type];
} }
getComponentType() { getComponentType(disableAutoBook) {
if (!this.note) { if (!this.note) {
return "empty"; return "empty";
} }
let type = this.note.type; let type = this.note.type;
if (type === 'text' && !disableAutoBook && utils.isHtmlEmpty(this.note.content) && this.note.hasChildren()) {
type = 'book';
}
if (this.note.isProtected) { if (this.note.isProtected) {
if (protectedSessionHolder.isProtectedSessionAvailable()) { if (protectedSessionHolder.isProtectedSessionAvailable()) {
protectedSessionHolder.touchProtectedSession(); protectedSessionHolder.touchProtectedSession();

View File

@ -201,6 +201,10 @@ function closeActiveDialog() {
} }
} }
function isHtmlEmpty(html) {
return $(html).text().trim().length === 0 && !html.toLowerCase().includes('<img');
}
export default { export default {
reloadApp, reloadApp,
parseDate, parseDate,
@ -231,5 +235,6 @@ export default {
getCookie, getCookie,
getNoteTypeClass, getNoteTypeClass,
getMimeTypeClass, getMimeTypeClass,
closeActiveDialog closeActiveDialog,
isHtmlEmpty
}; };

View File

@ -838,3 +838,12 @@ a.external:not(.no-arrow):after, a[href^="http://"]:not(.no-arrow):after, a[href
.note-book-content { .note-book-content {
flex-grow: 1; flex-grow: 1;
} }
.note-book-auto-message {
background-color: var(--more-accented-background-color);
text-align: center;
width: 100%;
border-radius: 10px;
padding: 5px;
margin-top: 5px;
}

View File

@ -22,6 +22,7 @@ const BUILTIN_ATTRIBUTES = [
{ type: 'label', name: 'run', isDangerous: true }, { type: 'label', name: 'run', isDangerous: true },
{ type: 'label', name: 'customRequestHandler', isDangerous: true }, { type: 'label', name: 'customRequestHandler', isDangerous: true },
{ type: 'label', name: 'customResourceProvider', isDangerous: true }, { type: 'label', name: 'customResourceProvider', isDangerous: true },
{ type: 'label', name: 'bookZoomLevel', isDangerous: false },
// relation names // relation names
{ type: 'relation', name: 'runOnNoteView', isDangerous: true }, { type: 'relation', name: 'runOnNoteView', isDangerous: true },