Open source personal finance application
fix (trnFrom): edit trn
ilkomea564e983d3fa
diff --git a/components/trnForm/TrnFormTrns.vue b/components/trnForm/TrnFormTrns.vueindex cd190b70..0449f52c 100644--- a/components/trnForm/TrnFormTrns.vue+++ b/components/trnForm/TrnFormTrns.vue@@ -1,39 +1,10 @@<script lang="ts">-import { useNuxtApp, defineComponent } from '#app'-import useCalculator from '~/components/trnForm/calculator/useCalculator'-export default defineComponent({props: {categoryId: { type: String, default: null },- expenses: { type: Boolean, default: false },- incomes: { type: Boolean, default: false },limit: { type: Number, default: 0 },- onlyList: { type: Boolean, default: false },size: { type: Number, required: false, default: 10 },- slider: { type: Object, required: true },- ui: { type: String, default: 'history' }- },-- setup ({ slider }) {- const { $store } = useNuxtApp()-- const actions = trnItem => ({- onOpenDetails: () => {- event.stopPropagation()- event.stopPropagation()- const { setExpression } = useCalculator()- setExpression($store.state.trns.items[trnItem.id].amount)- $store.commit('trnForm/setTrnFormModalTrnId', trnItem.id)- slider.slideTo(1)- },-- onOpenEdit: () => {},- onSetFilter: () => {}- })-- return {- actions- }+ slider: { type: Object, required: true }},data () {@@ -76,10 +47,6 @@ export default defineComponent({if (this.categoryId)trnsIds = trnsIds.filter(trnId => trns[trnId].categoryId === this.categoryId)- // filter type- if (this.incomes) trnsIds = trnsIds.filter(id => trns[id].type === 1)- if (this.expenses) trnsIds = trnsIds.filter(id => trns[id].type === 0)-// limitif (this.limit > 0) return trnsIds.slice(0, this.limit)return trnsIds@@ -148,11 +115,11 @@ export default defineComponent({TrnsItemHistory.py-3.px-2.rounded-md(v-for="trnId in trnsIds":key="trnId"- :actions="actions"+ :slider="slider":trnId="trnId")- .trnsList__pages(v-if="!isShowedAllTrns")+ .pages(v-if="!isShowedAllTrns").button(@click="showMoreTrns") {{ $t('trns.more') }}.pt-2.pb-5.px-3.justify-center.flex@@ -179,32 +146,9 @@ export default defineComponent({text-align centerfontFamilyNunito()-.trnsList- &__day- overflow hidden- border-bottom 1px solid var(--c-bg-3)- margin-bottom 16px- padding-bottom 16px-- &:first-child- border-top 0-- +media-laptop()- margin 0-- &__header- display flex- align-items center- justify-content space-between- padding 0 $m7- padding-bottom $m7-- &__trns- padding 0 $m7-- &__pages- padding 16px 8px- padding-top 0+.pages+ padding 16px 8px+ padding-top 0.contentWrapposition relative@@ -220,37 +164,4 @@ export default defineComponent({.scrollBlockpadding-top $m6padding-bottom $m8--.switcherList- display flex- justify-content center- width 100%- padding $m6- padding-top $m8- background alpha(#171717, .9)-- /.light-mode &- background var(--c-bg-3)--.menuItem- cursor pointer- margin 0 $m5- padding $m6 $m8- color var(--c-font-5)- font-size 12px- font-weight 500- font-roboto()- text-align center- border 1px solid transparent- anim()-- &._active- cursor default- color var(--c-blue-1)-- +media-hover()- &:not(._active)- color var(--c-font-2)- background var(--c-bg-5)- border-radius 50px</style>diff --git a/components/trnForm/calculator/useCalculator.ts b/components/trnForm/calculator/useCalculator.tsindex d4cccde2..58efd74b 100644--- a/components/trnForm/calculator/useCalculator.ts+++ b/components/trnForm/calculator/useCalculator.ts@@ -1,5 +1,5 @@-import { ref, computed } from '#app'import currency from 'currency.js'+import { ref, computed } from '#app'const baseAmountFormat = (value: string, separator: string, symbol?: string) => currency(value, { symbol, precision: 0, pattern: '#', separator }).format()@@ -77,11 +77,12 @@ export default function useCalculator () {const isLastSimbolAction = checkIsLastSimbolAction(lastSimbol)const prepeatedExpression = isLastSimbolAction ? clearedExpression.slice(0, -1) : clearedExpression+ // eslint-disable-next-line no-new-funcconst math = Function('"use strict";return (' + prepeatedExpression + ')')()- if (math <= Number.MAX_SAFE_INTEGER) {+ if (math <= Number.MAX_SAFE_INTEGER)return String(Math.abs(math))- }+return '0'}catch (error) {@@ -111,20 +112,19 @@ export default function useCalculator () {// Deleteif (clearedExpression !== '0' && isDeleteAction) {const deleteString = clearedExpression.slice(0, -1)- if (deleteString) { return deleteString }+ if (deleteString) return deleteStringreturn '0'}// Start from 0if (clearedExpression === '0') {- if (value === '0') { return expression }- if (!inputIsAction) { return value }+ if (value === '0') return expression+ if (!inputIsAction) return value}// Change math simbol- if (inputIsAction && isLastSimbolAction && !isDotAction && !isSumAction && !isDeleteAction) {+ if (inputIsAction && isLastSimbolAction && !isDotAction && !isSumAction && !isDeleteAction)return clearedExpression.slice(0, -1) + value- }// Calculateif (inputIsAction && isSumAction) {@@ -135,9 +135,9 @@ export default function useCalculator () {// Handle dot valueif (inputIsAction && isDotAction) {if (Array.isArray(clearedExpression.split(/[/*\-+]/)) && (clearedExpression.split(/[/*\-+]/).slice(-1)[0].includes('.') || isLastSimbolAction)) {- if (isLastSimbolAction && lastSimbol !== '.') {+ if (isLastSimbolAction && lastSimbol !== '.')return clearedExpression + '0.'- }+return expression}else {@@ -146,9 +146,8 @@ export default function useCalculator () {}// Add math simbol- if (inputIsAction) {+ if (inputIsAction)return clearedExpression + value- }// Handle numberconst maxIntegerLengthAllowed = 12@@ -162,18 +161,16 @@ export default function useCalculator () {// Check if math will successif (lastSimbol !== '.') {const result = makeCalculation(clearedExpression + value)- if (result === '0') { return clearedExpression }+ if (result === '0') return clearedExpression}// Limit integer- if (isInteger && lastNumber.length < maxIntegerLengthAllowed) {+ if (isInteger && lastNumber.length < maxIntegerLengthAllowed)return clearedExpression + value- }// Limit float- if (!isInteger && lastNumberSplit[1].length < fixed) {+ if (!isInteger && lastNumberSplit[1].length < fixed)return clearedExpression + value- }}return expression@@ -199,19 +196,17 @@ export default function useCalculator () {let clearedValue = removeSpaces(String(item))// Remove ended zero after dot- if (isTrimFloatSpaces) {+ if (isTrimFloatSpaces)clearedValue = String(parseFloat(Number(clearedValue).toFixed(fixed)))- }const splitFloatValue = String(clearedValue).split(/[.]/)const isInteger = splitFloatValue.length === 1- if (isInteger) {+ if (isInteger)formatedItem = baseAmountFormat(item, separator.value)- }- else {++ elseformatedItem = baseAmountFormat(splitFloatValue[0], separator.value) + '.' + splitFloatValue[1]- }}return formatedItem})@@ -229,15 +224,15 @@ export default function useCalculator () {}function keyboardHandler (event: KeyboardEvent): void {- if (!isKeysActive.value) { return }+ if (!isKeysActive.value) returnconst allowValue = (event.key).match(/[0-9%/*\-+=.,]|Backspace|Enter/)let input = allowValue ? allowValue.input : falseif (input) {- if (input === ',') { input = '.' }- if (input === 'Enter') { input = '=' }- if (input === 'Backspace') { input = 'delete' }+ if (input === ',') input = '.'+ if (input === 'Enter') input = '='+ if (input === 'Backspace') input = 'delete'handleTouch(input)}diff --git a/components/trns/item/History.vue b/components/trns/item/History.vueindex af836628..2fa08a6b 100644--- a/components/trns/item/History.vue+++ b/components/trns/item/History.vue@@ -1,24 +1,51 @@<script lang="ts">-import { defineComponent } from '#app'+import { useNuxtApp } from '#app'import useTrn from '~/components/trns/item/useTrn'+import useCalculator from '~/components/trnForm/calculator/useCalculator'+import useFilter from '~/modules/filter/useFilter'export default defineComponent({props: {- actions: { type: Object, required: false, default: () => ({}) },trnId: { type: String, required: true }},- setup ({ trnId, actions }) {+ setup ({ trnId }) {+ const { $store } = useNuxtApp()+ const { setExpression } = useCalculator()+ const { setCategoryFilter } = useFilter()const { formatTrnItem } = useTrn()const trnItem = computed(() => formatTrnItem(trnId))- // @ts-ignore- const { onOpenDetails, onOpenEdit, onSetFilter } = actions(trnItem.value)++ const actions = {+ onOpenDetails: () => {+ if (!$store.state.trns.modal.show) {+ $store.commit('categories/hideCategoryModal')+ $store.commit('trns/showTrnModal')+ $store.commit('trns/setTrnModalId', trnItem.value.id)+ }+ },++ onOpenEdit: (event) => {+ event.stopPropagation()+ setExpression(trnItem.value.amount)+ $store.dispatch('trnForm/openTrnForm', { action: 'edit', trnId: trnItem.value.id })+ $store.commit('stat/setCategoryModal', { id: null, type: null })+ },++ onSetFilter: (event) => {+ event.stopPropagation()+ setCategoryFilter(trnItem.value.categoryId)+ $store.commit('filter/setFilterDateNow')+ $store.commit('trns/hideTrnModal')+ $store.commit('trns/setTrnModalId', null)+ $store.commit('stat/setCategoryModal', { id: null, type: null })+ $store.dispatch('ui/setActiveTabStat', 'details')+ }+ }return {- trnItem,- onOpenDetails,- onOpenEdit,- onSetFilter+ actions,+ trnItem}}})@@ -27,11 +54,11 @@ export default defineComponent({<template lang="pug">.space-x-3.flex.cursor-context-menu(class="hocus:bg-neutral-100 dark:hocus:bg-neutral-800"- @click="onOpenDetails"+ @click="actions.onOpenDetails").cursor-pointer.text-neutral-50.text-xl.leading-none.w-8.h-8.rounded-full.justify-center.items-center.flex(:style="{ background: trnItem.category.color }"- @click="onSetFilter"+ @click="actions.onSetFilter"): div(:class="trnItem.category.icon").grow@@ -67,7 +94,7 @@ export default defineComponent({:currency="trnItem.wallet.currency":type="trnItem.type"colorize="incomes"- @click="onOpenEdit"+ @click="actions.onOpenEdit")//- Descriptiondiff --git a/components/trns/list/TrnsListHistory.vue b/components/trns/list/TrnsListHistory.vueindex 8d84700d..b3529238 100644--- a/components/trns/list/TrnsListHistory.vue+++ b/components/trns/list/TrnsListHistory.vue@@ -1,7 +1,5 @@<script lang="ts">-import { useNuxtApp, defineComponent } from '#app'-import useCalculator from '~/components/trnForm/calculator/useCalculator'-import useFilter from '~/modules/filter/useFilter'+import { defineComponent } from '#app'export default defineComponent({props: {@@ -10,41 +8,6 @@ export default defineComponent({size: { type: Number, required: false, default: 30 }},- setup () {- const { $store } = useNuxtApp()- const { setExpression } = useCalculator()- const { setCategoryFilter } = useFilter()-- const actions = trnItem => ({- onOpenDetails: () => {- if (!$store.state.trns.modal.show) {- $store.commit('categories/hideCategoryModal')- $store.commit('trns/showTrnModal')- $store.commit('trns/setTrnModalId', trnItem.id)- }- },-- onOpenEdit: (event) => {- event.stopPropagation()- setExpression(trnItem.amount)- $store.dispatch('trnForm/openTrnForm', { action: 'edit', trnId: trnItem.id })- $store.commit('stat/setCategoryModal', { id: null, type: null })- },-- onSetFilter: (event) => {- event.stopPropagation()- setCategoryFilter(trnItem.categoryId)- $store.commit('filter/setFilterDateNow')- $store.commit('trns/hideTrnModal')- $store.commit('trns/setTrnModalId', null)- $store.commit('stat/setCategoryModal', { id: null, type: null })- $store.dispatch('ui/setActiveTabStat', 'details')- }- })-- return { actions }- },-data () {return {pageNumber: 1,@@ -144,7 +107,6 @@ divTrnsItemHistory.py-3.px-3.cursor-pointer(v-for="trnId in trnsIds":key="trnId"- :actions="actions":trnId="trnId")