Merge commit 'ef5f5b35db25bd532c1f22424a7f17576cc219a4' into develop

This commit is contained in:
Elian Doran 2025-01-30 18:04:49 +02:00
commit 047b226426
No known key found for this signature in database
5 changed files with 45 additions and 21 deletions

View File

@ -3,12 +3,12 @@ import NoteContextAwareWidget from "./note_context_aware_widget.js";
const TPL = ` const TPL = `
<div class="switch-widget"> <div class="switch-widget">
<style> <style>
.switch-widget { .switch-widget {
display: flex; display: flex;
align-items: center; align-items: center;
} }
/* The switch - the box around the slider */ /* The switch - the box around the slider */
.switch-widget .switch { .switch-widget .switch {
position: relative; position: relative;
@ -17,11 +17,11 @@ const TPL = `
height: 24px; height: 24px;
margin: 0; margin: 0;
} }
.switch-on, .switch-off { .switch-on, .switch-off {
display: flex; display: flex;
} }
/* The slider */ /* The slider */
.switch-widget .slider { .switch-widget .slider {
border-radius: 24px; border-radius: 24px;
@ -34,7 +34,7 @@ const TPL = `
background-color: var(--more-accented-background-color); background-color: var(--more-accented-background-color);
transition: .4s; transition: .4s;
} }
.switch-widget .slider:before { .switch-widget .slider:before {
border-radius: 50%; border-radius: 50%;
position: absolute; position: absolute;
@ -47,20 +47,20 @@ const TPL = `
-webkit-transition: .4s; -webkit-transition: .4s;
transition: .4s; transition: .4s;
} }
.switch-widget .slider.checked { .switch-widget .slider.checked {
background-color: var(--main-text-color); background-color: var(--main-text-color);
} }
.switch-widget .slider.checked:before { .switch-widget .slider.checked:before {
transform: translateX(26px); transform: translateX(26px);
} }
.switch-widget .switch-disabled { .switch-widget .switch-disabled {
opacity: 70%; opacity: 70%;
pointer-events: none; pointer-events: none;
} }
.switch-widget .switch-help-button { .switch-widget .switch-help-button {
font-weight: 900; font-weight: 900;
border: 0; border: 0;
@ -72,9 +72,9 @@ const TPL = `
<div class="switch-on"> <div class="switch-on">
<span class="switch-on-name"></span> <span class="switch-on-name"></span>
&nbsp; &nbsp;
<span class="switch-on-button"> <span class="switch-on-button">
<label class="switch"> <label class="switch">
<span class="slider"></span> <span class="slider"></span>
@ -82,19 +82,28 @@ const TPL = `
</div> </div>
<div class="switch-off"> <div class="switch-off">
<span class="switch-off-name"></span> <span class="switch-off-name"></span>
&nbsp; &nbsp;
<span class="switch-off-button"> <span class="switch-off-button">
<label class="switch"> <label class="switch">
<span class="slider checked"></span> <span class="slider checked"></span>
</span> </span>
</div> </div>
<button class="switch-help-button" type="button" data-help-page="" title="${t("open-help-page")}" style="display: none;">?</button> <button class="switch-help-button" type="button" data-help-page="" title="${t("open-help-page")}" style="display: none;">?</button>
</div>`; </div>`;
export default class SwitchWidget extends NoteContextAwareWidget { export default class SwitchWidget extends NoteContextAwareWidget {
protected $switchOn!: JQuery<HTMLElement>;
protected $switchOnName!: JQuery<HTMLElement>;
protected $switchOnButton!: JQuery<HTMLElement>;
protected $switchOff!: JQuery<HTMLElement>;
protected $switchOffName!: JQuery<HTMLElement>;
protected $switchOffButton!: JQuery<HTMLElement>;
protected $helpButton!: JQuery<HTMLElement>;
doRender() { doRender() {
this.$widget = $(TPL); this.$widget = $(TPL);
@ -113,7 +122,7 @@ export default class SwitchWidget extends NoteContextAwareWidget {
this.$helpButton = this.$widget.find(".switch-help-button"); this.$helpButton = this.$widget.find(".switch-help-button");
} }
toggle(state) { toggle(state: boolean) {
if (state) { if (state) {
this.switchOn(); this.switchOn();
} else { } else {

View File

@ -1,13 +1,15 @@
import SwitchWidget from "./switch.js"; import SwitchWidget from "./switch.js";
import attributeService from "../services/attributes.js"; import attributeService from "../services/attributes.js";
import { t } from "../services/i18n.js"; import { t } from "../services/i18n.js";
import type FNote from "../entities/fnote.js";
import type { EventData } from "../components/app_context.js";
/** /**
* Switch for the basic properties widget which allows the user to select whether the note is a template or not, which toggles the `#template` attribute. * Switch for the basic properties widget which allows the user to select whether the note is a template or not, which toggles the `#template` attribute.
*/ */
export default class TemplateSwitchWidget extends SwitchWidget { export default class TemplateSwitchWidget extends SwitchWidget {
isEnabled() { isEnabled() {
return super.isEnabled() && !this.noteId.startsWith("_options"); return super.isEnabled() && !this.noteId?.startsWith("_options");
} }
doRender() { doRender() {
@ -16,29 +18,35 @@ export default class TemplateSwitchWidget extends SwitchWidget {
this.$switchOnName.text(t("template_switch.template")); this.$switchOnName.text(t("template_switch.template"));
this.$switchOnButton.attr("title", t("template_switch.toggle-on-hint")); this.$switchOnButton.attr("title", t("template_switch.toggle-on-hint"));
this.$switchOffName.text("Template"); this.$switchOffName.text(t("template_switch.template"));
this.$switchOffButton.attr("title", t("template_switch.toggle-off-hint")); this.$switchOffButton.attr("title", t("template_switch.toggle-off-hint"));
this.$helpButton.attr("data-help-page", "template.html").show(); this.$helpButton.attr("data-help-page", "template.html").show();
} }
async switchOn() { async switchOn() {
await attributeService.setLabel(this.noteId, "template"); if (this.noteId) {
await attributeService.setLabel(this.noteId, "template");
}
} }
async switchOff() { async switchOff() {
if (!this.note || !this.noteId) {
return;
}
for (const templateAttr of this.note.getOwnedLabels("template")) { for (const templateAttr of this.note.getOwnedLabels("template")) {
await attributeService.removeAttributeById(this.noteId, templateAttr.attributeId); await attributeService.removeAttributeById(this.noteId, templateAttr.attributeId);
} }
} }
async refreshWithNote(note) { async refreshWithNote(note: FNote) {
const isTemplate = note.hasLabel("template"); const isTemplate = note.hasLabel("template");
this.$switchOn.toggle(!isTemplate); this.$switchOn.toggle(!isTemplate);
this.$switchOff.toggle(!!isTemplate); this.$switchOff.toggle(!!isTemplate);
} }
entitiesReloadedEvent({ loadResults }) { entitiesReloadedEvent({ loadResults }: EventData<"entitiesReloaded">) {
if (loadResults.getAttributeRows().find((attr) => attr.type === "label" && attr.name === "template" && attr.noteId === this.noteId)) { if (loadResults.getAttributeRows().find((attr) => attr.type === "label" && attr.name === "template" && attr.noteId === this.noteId)) {
this.refresh(); this.refresh();
} }

View File

@ -4,6 +4,7 @@ import assetPath from "../services/asset_path.js";
import shareRoot from "./share_root.js"; import shareRoot from "./share_root.js";
import escapeHtml from "escape-html"; import escapeHtml from "escape-html";
import type SNote from "./shaca/entities/snote.js"; import type SNote from "./shaca/entities/snote.js";
import { t } from "i18next";
/** /**
* Represents the output of the content renderer. * Represents the output of the content renderer.
@ -43,7 +44,7 @@ function getContent(note: SNote) {
} else if (note.type === "book") { } else if (note.type === "book") {
result.isEmpty = true; result.isEmpty = true;
} else { } else {
result.content = "<p>This note type cannot be displayed.</p>"; result.content = `<p>${t("content_renderer.note-cannot-be-displayed")}</p>`;
} }
return result; return result;

View File

@ -250,5 +250,8 @@
"backend_log": { "backend_log": {
"log-does-not-exist": "The backend log file '{{ fileName }}' does not exist (yet).", "log-does-not-exist": "The backend log file '{{ fileName }}' does not exist (yet).",
"reading-log-failed": "Reading the backend log file '{{ fileName }}' failed." "reading-log-failed": "Reading the backend log file '{{ fileName }}' failed."
},
"content_renderer": {
"note-cannot-be-displayed": "This note type cannot be displayed."
} }
} }

View File

@ -251,5 +251,8 @@
}, },
"geo-map": { "geo-map": {
"create-child-note-instruction": "Clic pe hartă pentru a crea o nouă notiță la acea poziție sau apăsați Escape pentru a renunța." "create-child-note-instruction": "Clic pe hartă pentru a crea o nouă notiță la acea poziție sau apăsați Escape pentru a renunța."
},
"content_renderer": {
"note-cannot-be-displayed": "Acest tip de notiță nu poate fi afișat."
} }
} }