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

View File

@ -1,13 +1,15 @@
import SwitchWidget from "./switch.js";
import attributeService from "../services/attributes.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.
*/
export default class TemplateSwitchWidget extends SwitchWidget {
isEnabled() {
return super.isEnabled() && !this.noteId.startsWith("_options");
return super.isEnabled() && !this.noteId?.startsWith("_options");
}
doRender() {
@ -16,29 +18,35 @@ export default class TemplateSwitchWidget extends SwitchWidget {
this.$switchOnName.text(t("template_switch.template"));
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.$helpButton.attr("data-help-page", "template.html").show();
}
async switchOn() {
await attributeService.setLabel(this.noteId, "template");
if (this.noteId) {
await attributeService.setLabel(this.noteId, "template");
}
}
async switchOff() {
if (!this.note || !this.noteId) {
return;
}
for (const templateAttr of this.note.getOwnedLabels("template")) {
await attributeService.removeAttributeById(this.noteId, templateAttr.attributeId);
}
}
async refreshWithNote(note) {
async refreshWithNote(note: FNote) {
const isTemplate = note.hasLabel("template");
this.$switchOn.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)) {
this.refresh();
}

View File

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

View File

@ -250,5 +250,8 @@
"backend_log": {
"log-does-not-exist": "The backend log file '{{ fileName }}' does not exist (yet).",
"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": {
"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."
}
}