Add config option to change automatic readonly size (#2174)

This commit is contained in:
Abitofevrything 2021-09-20 21:08:41 +02:00 committed by GitHub
parent bdde52f004
commit b85cf07a28
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 46 additions and 2 deletions

View file

@ -80,6 +80,22 @@ const TPL = `
<label for="note-revision-snapshot-time-interval-in-seconds">Note revision snapshot time interval (in seconds)</label>
<input class="form-control" id="note-revision-snapshot-time-interval-in-seconds" type="number">
</div>
</div>
<div>
<h4>Automatic readonly size</h4>
<p>Automatic readonly note size is the size after which notes will be readonly if automatic readonly is enabled.</p>
<div class="form-group">
<label for="automatic-readonly-size">Automatic readonly size (text notes)</label>
<input class="form-control" id="automatic-readonly-size-text" type="number">
</div>
<div class="form-group">
<label for="automatic-readonly-size">Automatic readonly size (code notes)</label>
<input class="form-control" id="automatic-readonly-size-code" type="number">
</div>
</div>`;
export default class ProtectedSessionOptions {
@ -167,6 +183,24 @@ export default class ProtectedSessionOptions {
return false;
});
this.$autoReadonlySize = $("#automatic-readonly-size-text");
this.$autoReadonlySize.on('change', () => {
const opts = { 'autoReadonlySize': this.$autoReadonlySize.val() };
server.put('options', opts).then(() => toastService.showMessage("Options change have been saved."));
return false;
});
this.$autoCodeReadonlySize = $("#automatic-readonly-size-code");
this.$autoCodeReadonlySize.on('change', () => {
const opts = { 'autoCodeReadonlySize': this.$autoReadonlySize.val() };
server.put('options', opts).then(() => toastService.showMessage("Options change have been saved."));
return false;
});
}
optionsLoaded(options) {
@ -179,5 +213,8 @@ export default class ProtectedSessionOptions {
this.$imageMaxWidthHeight.val(options['imageMaxWidthHeight']);
this.$imageJpegQuality.val(options['imageJpegQuality']);
this.$autoReadonlySize.val(options['autoReadonlySize']);
this.$autoCodeReadonlySize.val(options['autoCodeReadonlySize']);
}
}

View file

@ -6,6 +6,7 @@ import treeService from "./tree.js";
import Component from "../widgets/component.js";
import froca from "./froca.js";
import hoistedNoteService from "./hoisted_note.js";
import options from "./options.js";
class NoteContext extends Component {
/**
@ -192,7 +193,9 @@ class NoteContext extends Component {
const noteComplement = await this.getNoteComplement();
const SIZE_LIMIT = this.note.type === 'text' ? 10000 : 30000;
const SIZE_LIMIT = this.note.type === 'text' ?
options.getInt('autoReadonlySize')
: options.getInt('autoCodeReadonlySize');
return noteComplement.content
&& noteComplement.content.length > SIZE_LIMIT

View file

@ -42,7 +42,9 @@ const ALLOWED_OPTIONS = new Set([
'promotedAttributesExpanded',
'similarNotesExpanded',
'headingStyle',
'autoCollapseNoteTree'
'autoCollapseNoteTree',
'autoReadonlySize',
'autoCodeReadonlySize'
]);
function getOptions() {

View file

@ -87,6 +87,8 @@ const defaultOptions = [
{ name: 'debugModeEnabled', value: 'false', isSynced: false },
{ name: 'headingStyle', value: 'underline', isSynced: true },
{ name: 'autoCollapseNoteTree', value: 'true', isSynced: true },
{ name: 'autoReadonlySize', value: '10000', isSynced: false },
{ name: 'autoCodeReadonlySize', value: '30000', isSynced: false },
];
function initStartupOptions() {