Skip to content
Snippets Groups Projects
Commit 1c8670be authored by Martin Claesson's avatar Martin Claesson
Browse files

Merge branch '14-journal-backend-crash' into 'master'

#14 - BUG - Backend crashes if you save a new journal entry without log text

Closes #14

See merge request !21
parents 8c176fbe e927eedb
Branches
Tags
1 merge request!21#14 - BUG - Backend crashes if you save a new journal entry without log text
<template>
<VForm @submit.prevent="save" ref="form">
<VForm @submit.prevent="save" ref="form" lazy-validation>
<VRow dense v-if="!!getMessage">
<VCol>
<VAlert :type="!!error ? 'error' : 'success'" dense tile>{{ getMessage }}</VAlert>
......@@ -12,6 +12,8 @@
v-model.lazy="value.writtenBy"
:success="updated"
:error="!!error"
:rules="[rules.required]"
required
@change="update"
@input="input"/>
<VTextarea outlined
......@@ -19,6 +21,8 @@
v-model.lazy="value.text"
:success="updated"
:error="!!error"
:rules="[rules.required]"
required
@change="update"
@input="input"/>
</VCol>
......@@ -29,7 +33,10 @@
label="XP"
type="number"
v-model.lazy="value.xp"
:rules="[rules.required,rules.decimal]"
:success="updated"
:error="!!error"
required
@change="update"
@input="input"></VTextField>
</VCol>
......@@ -53,7 +60,10 @@
readonly
v-bind="attrs"
v-on="on"
required
:rules="[rules.required]"
:success="updated"
:error="!!error"
@change="update"
@input="input"
></VTextField>
......@@ -84,6 +94,7 @@ import Vue from "vue";
import {Interfaces} from "@alboneon/library/types/Interfaces";
import JournalEntry = Interfaces.JournalEntry;
const decimalPattern = /^\d+?\.?\d*$/
export default Vue.extend({
name: "PartyJournalNewEntry",
props: {
......@@ -110,6 +121,9 @@ export default Vue.extend({
methods: {
save(): void {
this.resetState()
if (!(this.$refs.form as HTMLFormElement).validate()) {
return
}
if (this.newEntry) {
JournalClient.Add(this.value as Interfaces.JournalEntry, this.handleError, () => {
(this.$refs.form as HTMLFormElement).reset()
......@@ -141,6 +155,9 @@ export default Vue.extend({
update() {
this.resetState()
this.$emit('change', this.value)
if (!(this.$refs.form as HTMLFormElement).validate()) {
return
}
if (!this.newEntry) {
JournalClient.Update(this.value as Interfaces.JournalEntry, this.handleError, () => {
this.updated = true
......@@ -156,6 +173,11 @@ export default Vue.extend({
loading: false,
message: '',
datePicker: false,
rules: {
positive: (value: number) => value >= 0 || "Must be positive",
decimal: (value: number | string) => decimalPattern.test(value + '') || "Not a valid number",
required: (value: string | number) => !!value || value + '' === '0' || "Required"
},
}
}
})
......
......@@ -18,8 +18,8 @@ export async function AddJournalEntry(partyUUID: string, values: Interfaces.Jour
party.save().then(prty => {
resolve(prty.toObject().journal[i-1])
})
})
}).catch(reject)
}).catch(reject)
})
}
......@@ -45,8 +45,8 @@ export async function RemoveJournalEntry(partyUUID:string, journalEntryID:string
party.save().then(() => {
resolve()
})
})
}).catch(reject)
}).catch(reject)
})
}
......@@ -70,7 +70,7 @@ export async function UpdateJournalEntry(partyUUID:string, journalEntry: Interfa
party.save().then(p => {
resolve(p.journal[index])
})
})
}).catch(reject)
}).catch(reject)
})
}
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment