From 1564634177a4e8d9198d829fea41083e3433fd6b Mon Sep 17 00:00:00 2001 From: dartungar Date: Sun, 18 Feb 2024 14:20:27 +0400 Subject: [PATCH] customize mood rating labels --- manifest.json | 2 +- .../EmotionGroupEditComponent.svelte | 0 .../emotionGroupDeleteModal.ts | 2 +- .../emotionGroupEditModal.ts | 0 .../{ => folderSetting}/fileSuggester.ts | 0 .../{ => folderSetting}/moveDataModal.ts | 0 src/settings/{ => folderSetting}/suggest.ts | 0 .../MoodRatingLabelsEditComponent.svelte | 99 +++++++++++++++++++ .../moodRatingLabelsEditModal.ts | 31 ++++++ src/settings/moodTrackerSettings.ts | 2 + src/settings/settingsTab.ts | 56 +++++++---- src/stats/StatsChart.svelte | 8 +- src/stats/statsCodeblockRenderer.ts | 1 + src/statsModal/SelectedDay.svelte | 11 +-- src/statsModal/StatsComponent.svelte | 2 +- src/trackerModal/MoodRating.svelte | 6 +- src/trackerModal/TrackerModal.svelte | 5 + 17 files changed, 185 insertions(+), 40 deletions(-) rename src/settings/{ => emotionGroup}/EmotionGroupEditComponent.svelte (100%) rename src/settings/{ => emotionGroup}/emotionGroupDeleteModal.ts (92%) rename src/settings/{ => emotionGroup}/emotionGroupEditModal.ts (100%) rename src/settings/{ => folderSetting}/fileSuggester.ts (100%) rename src/settings/{ => folderSetting}/moveDataModal.ts (100%) rename src/settings/{ => folderSetting}/suggest.ts (100%) create mode 100644 src/settings/moodRatingLabel/MoodRatingLabelsEditComponent.svelte create mode 100644 src/settings/moodRatingLabel/moodRatingLabelsEditModal.ts diff --git a/manifest.json b/manifest.json index 598f100..12905ae 100644 --- a/manifest.json +++ b/manifest.json @@ -1,7 +1,7 @@ { "id": "mood-tracker", "name": "Mood Tracker", - "version": "1.2.0", + "version": "1.2.1", "minAppVersion": "1.0.0", "description": "Track your moods & emotions easily. Visualize tracked history and browse the past entries.", "author": "dartungar", diff --git a/src/settings/EmotionGroupEditComponent.svelte b/src/settings/emotionGroup/EmotionGroupEditComponent.svelte similarity index 100% rename from src/settings/EmotionGroupEditComponent.svelte rename to src/settings/emotionGroup/EmotionGroupEditComponent.svelte diff --git a/src/settings/emotionGroupDeleteModal.ts b/src/settings/emotionGroup/emotionGroupDeleteModal.ts similarity index 92% rename from src/settings/emotionGroupDeleteModal.ts rename to src/settings/emotionGroup/emotionGroupDeleteModal.ts index 8c79109..527ffbe 100644 --- a/src/settings/emotionGroupDeleteModal.ts +++ b/src/settings/emotionGroup/emotionGroupDeleteModal.ts @@ -1,5 +1,5 @@ import { App } from "obsidian"; -import { MoodTrackerSettingsTab } from "./settingsTab"; +import { MoodTrackerSettingsTab } from "../settingsTab"; import { EmotionGroup } from "src/entities/IEmotionGroup"; import MoodTrackerPlugin from "src/main"; import { ConfirmationModal } from "src/common/confirmationModal"; diff --git a/src/settings/emotionGroupEditModal.ts b/src/settings/emotionGroup/emotionGroupEditModal.ts similarity index 100% rename from src/settings/emotionGroupEditModal.ts rename to src/settings/emotionGroup/emotionGroupEditModal.ts diff --git a/src/settings/fileSuggester.ts b/src/settings/folderSetting/fileSuggester.ts similarity index 100% rename from src/settings/fileSuggester.ts rename to src/settings/folderSetting/fileSuggester.ts diff --git a/src/settings/moveDataModal.ts b/src/settings/folderSetting/moveDataModal.ts similarity index 100% rename from src/settings/moveDataModal.ts rename to src/settings/folderSetting/moveDataModal.ts diff --git a/src/settings/suggest.ts b/src/settings/folderSetting/suggest.ts similarity index 100% rename from src/settings/suggest.ts rename to src/settings/folderSetting/suggest.ts diff --git a/src/settings/moodRatingLabel/MoodRatingLabelsEditComponent.svelte b/src/settings/moodRatingLabel/MoodRatingLabelsEditComponent.svelte new file mode 100644 index 0000000..d78e7d6 --- /dev/null +++ b/src/settings/moodRatingLabel/MoodRatingLabelsEditComponent.svelte @@ -0,0 +1,99 @@ + + +
+
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ +
+
Preview:
+
+ {plugin.settings.moodRatingLabelDict[1]} + {plugin.settings.moodRatingLabelDict[2]} + {plugin.settings.moodRatingLabelDict[3]} + {plugin.settings.moodRatingLabelDict[4]} + {plugin.settings.moodRatingLabelDict[5]} +
+
+ +
+ +
+
+ + diff --git a/src/settings/moodRatingLabel/moodRatingLabelsEditModal.ts b/src/settings/moodRatingLabel/moodRatingLabelsEditModal.ts new file mode 100644 index 0000000..04c10f9 --- /dev/null +++ b/src/settings/moodRatingLabel/moodRatingLabelsEditModal.ts @@ -0,0 +1,31 @@ +import { App, Modal } from "obsidian"; +import MoodRatingLabelsEditComponent from "./MoodRatingLabelsEditComponent.svelte"; +import MoodTrackerPlugin from "src/main"; +import store from "src/store"; + + + +export class MoodRatingLabelsEditModal extends Modal { + component: MoodRatingLabelsEditComponent; + + constructor(private _plugin: MoodTrackerPlugin, app: App) { + super(app); + } + + onOpen(): void { + store.plugin.set(this._plugin); + + this.titleEl.innerText = "Edit mood rating labels"; + + this.component = new MoodRatingLabelsEditComponent({ + target: this.contentEl, + props: { + closeModalFunc: () => this.close() + } + }); + } + + onClose() { + this.component.$destroy(); + } +} \ No newline at end of file diff --git a/src/settings/moodTrackerSettings.ts b/src/settings/moodTrackerSettings.ts index d3d4951..c7379ad 100644 --- a/src/settings/moodTrackerSettings.ts +++ b/src/settings/moodTrackerSettings.ts @@ -6,6 +6,7 @@ export class MoodTrackerSettings { folderPath = ""; emotionGroups: EmotionGroup[] = []; moodRatingLabelDict: { [key: number]: string }; + moodRatingLabelSize: number; template: string; trackerModalTitle: string; useEmotions: boolean; @@ -21,6 +22,7 @@ export const DEFAULT_SETTINGS: MoodTrackerSettings = { 4: "🙂", 5: "😊", }, + moodRatingLabelSize: 3, template: "- {{ICON}} {{NOTE}}", trackerModalTitle: "How are you feeling?", useEmotions: true diff --git a/src/settings/settingsTab.ts b/src/settings/settingsTab.ts index 565cfdb..a6bdb75 100644 --- a/src/settings/settingsTab.ts +++ b/src/settings/settingsTab.ts @@ -7,11 +7,12 @@ import { TFolder, } from "obsidian"; import MoodTrackerPlugin from "src/main"; -import { GenericTextSuggester } from "./fileSuggester"; +import { GenericTextSuggester } from "./folderSetting/fileSuggester"; import { EmotionGroup } from "src/entities/IEmotionGroup"; -import { MoveDataModal } from "./moveDataModal"; -import { EmotionGroupEditModal } from "./emotionGroupEditModal"; -import { EmotionGroupDeleteModal } from "./emotionGroupDeleteModal"; +import { MoveDataModal } from "./folderSetting/moveDataModal"; +import { EmotionGroupEditModal } from "./emotionGroup/emotionGroupEditModal"; +import { EmotionGroupDeleteModal } from "./emotionGroup/emotionGroupDeleteModal"; +import { MoodRatingLabelsEditModal } from "./moodRatingLabel/moodRatingLabelsEditModal"; export class MoodTrackerSettingsTab extends PluginSettingTab { constructor(private _plugin: MoodTrackerPlugin, app: App) { @@ -24,9 +25,10 @@ export class MoodTrackerSettingsTab extends PluginSettingTab { containerEl.empty(); this.addTrackerModalTitleSetting(); - this.addUseEmotionsSetting(); this.addFolderPathSetting(); this.addTemplateSetting(); + this.addMoodRatingLabelsSetting(); + this.addUseEmotionsSetting(); if (this._plugin.settings.useEmotions) { this.addEmotionsSetting(); } @@ -47,21 +49,7 @@ export class MoodTrackerSettingsTab extends PluginSettingTab { }) } - private addUseEmotionsSetting() { - const setting = new Setting(this.containerEl); - setting.setName("Use emotions") - setting.setDesc("Track more nuanced emotions in addition to simple mood rating"); - - setting.addToggle((input) => { - input.setValue(this._plugin.settings.useEmotions) - .onChange(async (value) => { - this._plugin.settings.useEmotions = value; - await this._plugin.saveSettings(); - this.display(); - }); - }) - } // by C.Houmann (https://github.com/chhoumann/quickadd) // TODO: try to implement better one, maybe look outside of obsidian plugins @@ -126,6 +114,36 @@ export class MoodTrackerSettingsTab extends PluginSettingTab { }) } + private addMoodRatingLabelsSetting() { + const setting = new Setting(this.containerEl); + + setting.setName("Mood rating labels") + setting.setDesc("Labels to use for mood rating. Used in tracker modal and stats."); + + setting.addButton((button) => { + button.setButtonText("Edit") + .onClick(async () => { + new MoodRatingLabelsEditModal(this._plugin, app).open(); + }) + }) + } + + private addUseEmotionsSetting() { + const setting = new Setting(this.containerEl); + + setting.setName("Use emotions") + setting.setDesc("Track more nuanced emotions in addition to simple mood rating"); + + setting.addToggle((input) => { + input.setValue(this._plugin.settings.useEmotions) + .onChange(async (value) => { + this._plugin.settings.useEmotions = value; + await this._plugin.saveSettings(); + this.display(); + }); + }) + } + private addEmotionsSetting() { const settingGroupEl = this.containerEl.createEl("div"); settingGroupEl.createEl("h4", { text: "Emotions" }); diff --git a/src/stats/StatsChart.svelte b/src/stats/StatsChart.svelte index b12d20d..b2c9c6f 100644 --- a/src/stats/StatsChart.svelte +++ b/src/stats/StatsChart.svelte @@ -16,10 +16,7 @@ ChartData, } from "chart.js"; import { IDayStats } from "src/entities/IDayStats"; - import { - DEFAULT_SETTINGS, - MoodTrackerSettings, - } from "src/settings/moodTrackerSettings"; + import MoodTrackerPlugin from "src/main"; ChartJS.register( Title, @@ -34,6 +31,7 @@ ); export let data: IDayStats[] = []; + export let plugin: MoodTrackerPlugin; let chartRef: any; @@ -86,7 +84,7 @@ stepSize: 1, callback: function (val: number, _: any) { // TODO: use ones from plugin settings! - return DEFAULT_SETTINGS.moodRatingLabelDict[val]; + return plugin.settings.moodRatingLabelDict[val]; }, }, }, diff --git a/src/stats/statsCodeblockRenderer.ts b/src/stats/statsCodeblockRenderer.ts index 1d4f3a3..1d6b53b 100644 --- a/src/stats/statsCodeblockRenderer.ts +++ b/src/stats/statsCodeblockRenderer.ts @@ -60,6 +60,7 @@ export class StatsCodeblockRenderer { target: containerEl, props: { data: processedData, + plugin: this._plugin }, }); diff --git a/src/statsModal/SelectedDay.svelte b/src/statsModal/SelectedDay.svelte index 013705f..be736fd 100644 --- a/src/statsModal/SelectedDay.svelte +++ b/src/statsModal/SelectedDay.svelte @@ -6,16 +6,7 @@ export let data: IMoodTrackerEntry[]; export let dateString: string; export let plugin: MoodTrackerPlugin; - - - // TODO: get dict from settings - export let moodRatingDict: { [key: number]: string } = { - 1: "😨", - 2: "☚ī¸", - 3: "😐", - 4: "🙂", - 5: "😊", - }; + export let moodRatingDict: { [key: number]: string } = plugin.settings.moodRatingLabelDict; function getTimeFromDate(date: Date) { const hours = date.getHours().toString().padStart(2, '0'); diff --git a/src/statsModal/StatsComponent.svelte b/src/statsModal/StatsComponent.svelte index 4450f6c..6aacac1 100644 --- a/src/statsModal/StatsComponent.svelte +++ b/src/statsModal/StatsComponent.svelte @@ -64,7 +64,7 @@ - +
diff --git a/src/trackerModal/MoodRating.svelte b/src/trackerModal/MoodRating.svelte index c90b773..322cd0d 100644 --- a/src/trackerModal/MoodRating.svelte +++ b/src/trackerModal/MoodRating.svelte @@ -5,6 +5,7 @@ export let title = ''; export let rating; export let activeRating; + export let fontSize; $: isActive = activeRating === Number(rating); @@ -14,16 +15,15 @@ function setRating() { dispatch('setRating', { rating: Number(rating) - }); + });1 } -{emoji} +{emoji}