diff --git a/frontend/src/components/ItemModel.vue b/frontend/src/components/ItemModel.vue
index 3dbed94..2ac4c71 100644
--- a/frontend/src/components/ItemModel.vue
+++ b/frontend/src/components/ItemModel.vue
@@ -35,14 +35,67 @@
+
+
@@ -87,6 +140,8 @@ const Items = {
return {
items: [],
newItem: '',
+ newQuantity: 0,
+ newUnit: '',
editedItem: null,
loading: true,
error: null,
@@ -112,29 +167,29 @@ const Items = {
return this.activeUser ? this.activeUser.email : ''
},
inputPlaceholder: function () {
- return this.activeUser ? this.activeUser.given_name + ', what do you want to add?' : 'What needs to be added'
+ return this.activeUser ? this.activeUser.given_name + ', What do you want to add?' : 'What needs to be added?'
}
},
methods: {
addItem: function () {
- const value = this.newItem && this.newItem.trim();
- if (!value) {
+ const addableItem = this.newItem && this.newItem.trim();
+ const addableQuantity = parseInt(this.newQuantity);
+ const addableUnit = this.newUnit;
+ if (!addableItem) {
return
}
- const components = value.split(' ');
-
- api.createNew(components[0],
- parseInt(components[1].replace(/[^\d.]/g, '')),
- components[1].replace(/[0-9]/g, '') === 'ml' ? 'MILLILETERS' : "GRAMMS"
+ api.createNew(addableItem,
+ addableQuantity,
+ addableUnit
).then((response) => {
this.$log.debug("New item created:", response);
this.items.push({
id: response.data.id,
- name: components[0],
- quantity: parseInt(components[1].replace(/[^\d.]/g, '')),
- unit: components[1].replace(/[0-9]/g, '') === 'MILLILETERS' ? 'ml' : 'g'
+ name: addableItem,
+ quantity: addableQuantity,
+ unit: addableUnit
})
}).catch((error) => {
this.$log.debug(error);
@@ -167,10 +222,6 @@ export default Items
-
-
-
-