Open source personal finance application
Change id creation method to more elegant
Ilya Komichev2f348ab0ed93
diff --git a/src/components/categories/form/CategoryForm.vue b/src/components/categories/form/CategoryForm.vueindex 71f280fd..696ac524 100644--- a/src/components/categories/form/CategoryForm.vue+++ b/src/components/categories/form/CategoryForm.vue@@ -1,7 +1,7 @@<script>import { focus } from 'vue-focus'import { db } from '@/firebase'-import { createId } from '@/utils/id'+import { generateSimpleId } from '@/utils/id'import colors from '@/components/ui/store/colors'import icons from '@/components/ui/store/icons'@@ -96,7 +96,7 @@ export default {handleSubmit () {if (this.validateForm()) {const uid = this.$store.state.user.user.uid- const id = this.categoryId || createId()+ const id = this.categoryId || generateSimpleId()const categoriesValues = {color: this.category.color,diff --git a/src/components/trnForm/TrnForm.vue b/src/components/trnForm/TrnForm.vueindex b049fd9a..ecb48272 100644--- a/src/components/trnForm/TrnForm.vue+++ b/src/components/trnForm/TrnForm.vue@@ -1,6 +1,6 @@<script>import moment from 'moment'-import { createId } from '@/utils/id'+import { generateDateId } from '@/utils/id'import Amount from '@/components/amount/Amount'import CategoriesView from '@/components/categories/list/CategoriesView'@@ -92,7 +92,7 @@ export default {handleSubmitTrn () {const values = { ...this.$store.state.trnForm.values }- const id = values.trnId || createId()+ const id = values.trnId || generateDateId()this.$store.dispatch('addTrn', {id,@@ -101,7 +101,6 @@ export default {},handleSubmitTrnasfer () {- const newId = createId()const values = {amount: this.$store.state.trnForm.values.amount,categoryId: this.$store.getters.transferCategoryId,@@ -110,7 +109,7 @@ export default {// Incomethis.$store.dispatch('addTrn', {- id: `${newId}-to`,+ id: generateDateId(),values: {...values,walletId: this.$store.state.trnForm.transfer.to,@@ -120,7 +119,7 @@ export default {// Expensethis.$store.dispatch('addTrn', {- id: `${newId}-from`,+ id: generateDateId(),values: {...values,walletId: this.$store.state.trnForm.transfer.from,diff --git a/src/components/wallets/form/WalletForm.vue b/src/components/wallets/form/WalletForm.vueindex c70de521..86dc7bdc 100644--- a/src/components/wallets/form/WalletForm.vue+++ b/src/components/wallets/form/WalletForm.vue@@ -1,6 +1,6 @@<script>import { focus } from 'vue-focus'-import { createId } from '@/utils/id'+import { generateSimpleId } from '@/utils/id'import colors from '@/components/ui/store/colors'import Button from '@/components/shared/button/Button'@@ -73,7 +73,7 @@ export default {handleSubmit () {if (this.validateForm()) {- const id = this.walletId || createId()+ const id = this.walletId || generateSimpleId()const walletsValues = {color: this.wallet.color,diff --git a/src/utils/id.js b/src/utils/id.jsindex 0a24075a..d1650435 100644--- a/src/utils/id.js+++ b/src/utils/id.js@@ -1,7 +1,13 @@import moment from 'moment'-function uuid (a, b) { for (b = a = ''; a++ < 36; b += a * 51 & 52 ? (a ^ 15 ? 8 ^ Math.random() * (a ^ 20 ? 16 : 4) : 4).toString(16) : '-');return b }+export const generateDateId = (date) => {+ const string = Math.random().toString(36).substring(2, 15) + Math.random().toString(36).substring(2, 15)+ if (date) {+ return `${moment(date).format('YYMMDD[-]HH:mm:ss')}-${string.substring(1, 5)}`+ }+ return `${moment().format('YYMMDD[-]HH:mm:ss')}-${string.substring(1, 5)}`+}-export const createId = () => {- return `${moment().format('YY-MM-DD[_]H:mm:ss')}__${uuid()}`+export const generateSimpleId = () => {+ return Math.random().toString(36).substring(2, 15) + Math.random().toString(36).substring(2, 15)}