Skip to content

Commit

Permalink
- add user defined substring, which when present in assistant automat…
Browse files Browse the repository at this point in the history
…ically adds your todo tag (ex. "electricit 22 !!")

- created new settings page for assistant configs
  • Loading branch information
cioraneanu committed Dec 17, 2024
1 parent 3e532cc commit f56a3fa
Show file tree
Hide file tree
Showing 11 changed files with 87 additions and 12 deletions.
4 changes: 4 additions & 0 deletions front/assets/styles/theme-dark.css
Original file line number Diff line number Diff line change
Expand Up @@ -366,4 +366,8 @@

.van-theme-dark .split-transaction-badge {
background: #B71C1C;
}

.van-theme-dark .assistant-tag {
box-shadow: 0 2px 6px 0px rgba(0, 0, 0, 0.65);
}
2 changes: 1 addition & 1 deletion front/assets/styles/theme.css
Original file line number Diff line number Diff line change
Expand Up @@ -725,7 +725,7 @@ body {

.assistant-tag {
padding: 10px;
box-shadow: 0 4px 15px 0 rgba(45, 54, 65, 0.75);
box-shadow: 0 2px 6px 0px rgba(45, 54, 65, 0.45);
display: flex;
align-items: center;
gap: 5px;
Expand Down
22 changes: 15 additions & 7 deletions front/components/transaction/transaction-assistant.vue
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@

<template v-if="foundTag">
<van-tag round class="assistant-tag" size="medium" type="primary">
<!-- <app-icon :icon="TablerIconConstants.tag" color="#fff" class="" :size="15"/>-->
<span>Tag</span>
<span>|</span>
{{ Tag.getDisplayNameEllipsized(foundTag) }}
Expand All @@ -51,7 +50,6 @@

<template v-if="foundCategory">
<van-tag round class="assistant-tag" size="medium" type="primary">
<!-- <app-icon :icon="TablerIconConstants.category" color="#fff" class="mr-5" :size="15"/>-->
<span>Category:</span>
<span>|</span>
{{ Category.getDisplayName(foundCategory) }}
Expand All @@ -74,7 +72,12 @@
</van-tag>
</template>

<!-- <div class="flex-1" />-->
<template v-if="isTodo">
<div class="assistant-tag tag-todo">
<span>Todo</span>
</div>
</template>

</div>
</template>
</div>
Expand Down Expand Up @@ -112,6 +115,7 @@ const foundTag = ref(null)
const foundTemplate = ref(null)
const foundAmount = ref(null)
const foundDescription = ref(null)
const isTodo = ref(false)
const hasAmount = computed(() => {
return foundAmount.value && foundAmount.value > 0
Expand Down Expand Up @@ -179,20 +183,23 @@ const processAssistantText = () => {
text = RomanianLanguageUtils.fixBadWordNumbers(text)
text = text.replace(',', '.')
// let words = text.split(' ')
isTodo.value = profileStore.assistantTodoTagMatcher && text.endsWith(profileStore.assistantTodoTagMatcher)
text = isTodo.value ? text.slice(0, text.length - profileStore.assistantTodoTagMatcher.length) : text
// 3 groups: <template> <amount> <description>
const regex = /^(\D+)?(?:\s*(\d[\.\d\s\+\-\*\/]*))?(?:\s+(.*))?$/
const match = text.match(regex)
console.log('text', { text, match })
let searchWords = match[1] || ''
searchWords = LanguageUtils.removeAccents(searchWords).trim()
let numerical = match[2]
let { wasSuccessful, value } = evalMath(numerical)
foundAmount.value = numerical && wasSuccessful ? value : null
foundDescription.value = match[3] || ''
const fuseTemplateResults = fuseTransactionTemplate.search(searchWords)
Expand Down Expand Up @@ -265,13 +272,14 @@ const onShow = () => {
show.value = true
}
watch([foundTemplate, foundTag, foundCategory, foundAmount, foundDescription], ([newTemplate, newTag, newCategory, newAmount, foundDescription]) => {
watch([foundTemplate, foundTag, foundCategory, foundAmount, foundDescription, isTodo], ([newTemplate, newTag, newCategory, newAmount, newDescription, newIsTodo]) => {
emit('change', {
transactionTemplate: newTemplate,
amount: newAmount,
tag: newTag,
category: newCategory,
description: foundDescription,
description: newDescription,
isTodo: newIsTodo,
})
// If you selected a template and didn't write anything => write the text
Expand Down
1 change: 1 addition & 0 deletions front/constants/RouteConstants.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ export default {
ROUTE_SETTINGS: '/settings',
ROUTE_SETTINGS_SETUP: '/settings/setup',
ROUTE_SETTINGS_UI: '/settings/ui',
ROUTE_SETTINGS_ASSISTANT: '/settings/assistant',
ROUTE_SETTINGS_FORMATTING: '/settings/formatting',
ROUTE_SETTINGS_DASHBOARD: '/settings/dashboard',
ROUTE_SETTINGS_DASHBOARD_CARDS_ORDER: '/settings/dashboard/cards',
Expand Down
2 changes: 2 additions & 0 deletions front/constants/TablerIconConstants.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ export const icons = {
transactionTemplate: 'IconTemplate',
dashboard: 'IconDeviceDesktopAnalytics',
exchangeRates: 'IconReplace',
assistant: 'IconMessageChatbot',


settingsAppConfig: 'IconTool',
settingsUserPreferences: 'IconMoodCog',
Expand Down
52 changes: 52 additions & 0 deletions front/pages/settings/assistant.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
<template>
<div class="app-form">
<app-top-toolbar />

<van-form @submit="onSave" class="">
<van-cell-group inset>
<div class="van-cell-group-title">General:</div>

<app-field left-icon="link-o" v-model="assistantTodoTagMatcher" label="Trailing substring to auto add the todo tag" :rules="[{ required: true, message: 'This field is required' }]" required />
</van-cell-group>

<app-button-form-save />
</van-form>
</div>
</template>

<script setup>
import { onMounted, ref } from 'vue'
import { useProfileStore } from '~/stores/profileStore'
import { useDataStore } from '~/stores/dataStore'
import UIUtils from '~/utils/UIUtils'
import { useToolbar } from '~/composables/useToolbar'
import RouteConstants from '~/constants/RouteConstants'
import { NUMBER_FORMAT } from '~/utils/MathUtils.js'
import TablerIconConstants from '~/constants/TablerIconConstants.js'
import { saveSettingsToStore, watchSettingsStore } from '~/utils/SettingUtils.js'
const profileStore = useProfileStore()
const dataStore = useDataStore()
const assistantTodoTagMatcher = ref('')
const syncedSettings = [{ store: profileStore, path: 'assistantTodoTagMatcher', ref: assistantTodoTagMatcher }]
watchSettingsStore(syncedSettings)
const onSave = async () => {
saveSettingsToStore(syncedSettings)
await profileStore.writeProfile()
UIUtils.showToastSuccess('Settings saved')
}
const toolbar = useToolbar()
toolbar.init({
title: 'Assistant settings',
backRoute: RouteConstants.ROUTE_SETTINGS,
})
onMounted(() => {
animateSettings()
})
</script>
2 changes: 1 addition & 1 deletion front/pages/settings/formatting.vue
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ watchSettingsStore(syncedSettings)
const onSave = async () => {
saveSettingsToStore(syncedSettings)
await profileStore.writeProfile()
UIUtils.showToastSuccess('Formatting')
UIUtils.showToastSuccess('Settings saved')
}
const toolbar = useToolbar()
Expand Down
1 change: 1 addition & 0 deletions front/pages/settings/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
<van-cell-group inset style="overflow: auto">
<app-field-link label="Setup" :icon="TablerIconConstants.settings" @click="navigateTo(RouteConstants.ROUTE_SETTINGS_SETUP)" />
<app-field-link label="User interface" :icon="TablerIconConstants.settingsUI" @click="navigateTo(RouteConstants.ROUTE_SETTINGS_UI)" />
<app-field-link label="Assistant" :icon="TablerIconConstants.assistant" @click="navigateTo(RouteConstants.ROUTE_SETTINGS_ASSISTANT)" />
<app-field-link label="Formatting" :icon="TablerIconConstants.settingsUserPreferences" @click="navigateTo(RouteConstants.ROUTE_SETTINGS_FORMATTING)" />
<app-field-link label="Dashboard" :icon="TablerIconConstants.dashboard" @click="navigateTo(RouteConstants.ROUTE_SETTINGS_DASHBOARD)" />
<app-field-link label="Transactions" :icon="TablerIconConstants.transaction" @click="navigateTo(RouteConstants.ROUTE_SETTINGS_TRANSACTION)" />
Expand Down
7 changes: 5 additions & 2 deletions front/pages/transactions/[[id]].vue
Original file line number Diff line number Diff line change
Expand Up @@ -294,12 +294,15 @@ const resetFormFields = () => {
description.value = ''
}
const onAssistant = async ({ tag: newTag, category: newCategory, transactionTemplate: transactionTemplate, amount: newAmount, description: newDescription }) => {
const onAssistant = async ({ tag: newTag, category: newCategory, transactionTemplate: transactionTemplate, amount: newAmount, description: newDescription, isTodo: newIsTodo }) => {
resetFormFields()
if (newTag) {
tags.value = Tag.getTagWithParents(newTag)
// tags.value = [newTag]
}
if (newIsTodo && dataStore.tagTodo) {
tags.value = [...tags.value, dataStore.tagTodo]
}
if (newCategory) {
Expand Down
4 changes: 3 additions & 1 deletion front/plugins/register-tabler-icons.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@ import {
IconMoneybag,
IconBasket,
IconCopy,
IconLock
IconLock,
IconMessageChatbot
} from '@tabler/icons-vue'

export default defineNuxtPlugin((nuxtApp) => {
Expand Down Expand Up @@ -111,6 +112,7 @@ export default defineNuxtPlugin((nuxtApp) => {
nuxtApp.vueApp.component('IconBasket', IconBasket)
nuxtApp.vueApp.component('IconCopy', IconCopy)
nuxtApp.vueApp.component('IconLock', IconLock)
nuxtApp.vueApp.component('IconMessageChatbot', IconMessageChatbot)

// for (let iconName in tablerIcons) {
// nuxtApp.vueApp.component(iconName, tablerIcons[iconName])
Expand Down
2 changes: 2 additions & 0 deletions front/stores/profileStore.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ export const useProfileStore = defineStore('profile', {
darkTheme: useLocalStorage('darkTheme', false),
startingPage: useLocalStorage('startingPage', Page.types.transactionNew),

assistantTodoTagMatcher: useLocalStorage('assistantTodoTagMatcher', '!!'),

defaultAccountSource: useLocalStorage('defaultAccountSource', null, { serializer: StorageSerializers.object }),
defaultAccountDestination: useLocalStorage('defaultAccountDestination', null, { serializer: StorageSerializers.object }),
defaultCategory: useLocalStorage('defaultCategory', null, { serializer: StorageSerializers.object }),
Expand Down

0 comments on commit f56a3fa

Please sign in to comment.