Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
user can add budget categories, and select or add categories in line …
…using multiselect
- Loading branch information
1 parent
9ed4b99
commit 7b2f9f3
Showing
6 changed files
with
204 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
<template> | ||
<div id="budget-category-create-edit-view"> | ||
<form class="form" @submit.prevent="processSave"> | ||
<div class="control is-horizontal"> | ||
<div class="control is-grouped"> | ||
<div class="control is-expanded"> | ||
<multiselect | ||
:value="budgetCategory.category" | ||
@input="updateCategorySelection" | ||
:taggable="true" | ||
@tag="handleCreateCategory" | ||
:options="getCategorySelectList" | ||
placeholder="Select or create a category" | ||
label="name" | ||
track-by="id" | ||
></multiselect> | ||
</div> | ||
<div class="control is-expanded"> | ||
$<input type="number" class="input" v-model="budgetCategory.budgeted" /> | ||
</div> | ||
<div class="control is-expanded"> | ||
{{ budgetCategory.spent }} | ||
</div> | ||
<button @click.prevent="processSave">Add</button> | ||
</div> | ||
</div> | ||
</form> | ||
</div> | ||
</template> | ||
|
||
<script> | ||
import { mapActions, mapGetters } from 'vuex'; | ||
import Multiselect from 'vue-multiselect'; | ||
import 'vue-multiselect/dist/vue-multiselect.min.css'; | ||
export default { | ||
name: 'budget-category-create-edit-view', | ||
components: { | ||
Multiselect | ||
}, | ||
data: () => { | ||
return { | ||
budgetCategory: {} | ||
}; | ||
}, | ||
mounted () { | ||
this.loadCategories(); | ||
}, | ||
methods: { | ||
...mapActions([ | ||
'createCategory', | ||
'loadCategories' | ||
]), | ||
processSave () { | ||
this.$emit('add-budget-category', this.budgetCategory); | ||
this.budgetCategory = {}; | ||
}, | ||
handleCreateCategory (category) { | ||
let newCategory = { name: category }; | ||
this.createCategory(newCategory).then((val) => { | ||
this.updateCategorySelection(val); | ||
}); | ||
}, | ||
updateCategorySelection (category) { | ||
// if using v-model and not using Vue.set directly, vue-multiselect seems to struggle to properly | ||
// keep its internal value up to date with the value in our component. So we're skipping v-model | ||
// and handling updates manually. | ||
this.$set(this.budgetCategory, 'category', category); | ||
} | ||
}, | ||
computed: { | ||
...mapGetters([ | ||
'getCategorySelectList' | ||
]) | ||
} | ||
}; | ||
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,13 @@ | ||
export default { | ||
getBudgetById: (state, getters) => (budgetId) => { | ||
return state.budgets && budgetId in state.budgets ? state.budgets[budgetId] : false; | ||
}, | ||
|
||
getCategoryById: (state, getters) => (categoryId) => { | ||
return state.categories && categoryId in state.categories ? state.categories[categoryId] : false; | ||
}, | ||
|
||
getCategorySelectList: (state, getters) => { | ||
return state.categories && Object.keys(state.categories).length > 0 ? Object.values(state.categories) : []; | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters