Skip to content

Commit

Permalink
Merge pull request #263 from tobiasKaminsky/plusMinus
Browse files Browse the repository at this point in the history
add plus minus for quantity
  • Loading branch information
tobiasKaminsky authored Sep 19, 2024
2 parents 5a8d516 + 6eef24e commit 77f539e
Showing 1 changed file with 88 additions and 21 deletions.
109 changes: 88 additions & 21 deletions src/views/GroceryList.vue
Original file line number Diff line number Diff line change
@@ -1,20 +1,49 @@
<template>
<div class="page-wrapper">
<div>
<NcButton aria-label="Show add/edit modal"
@click="showAddModal">
<template #icon>
<Plus :size="20"/>
</template>
<template>Add</template>
</NcButton>
</div>
<h1>{{ groceryList?.title ?? t('grocerylist', 'Grocery list') }}</h1>
<div>
<NcCheckboxRadioSwitch :checked="!!groceryList?.showOnlyUnchecked" type="switch" @update:checked="toggleVisibility">
{{ t('grocerylist', 'Show only unchecked') }}
</NcCheckboxRadioSwitch>
<NcModal v-if="modal"
ref="modalRef"
:name="t('grocerylist', 'Add item')"
<NcModal
v-if="modal"
ref="modalRef"
:name="t('grocerylist', 'Add item')"
@close="closeModal">
<form class="modal__content"
@submit.prevent="onSaveItem()">
<p>
<p class="quantityRow">
<NcTextField :value.sync="newItemQuantity"
label="Quantity…" />
</p>
label="Quantity…"
@keyup.up="increaseQuantity()"
@keyup.down="decreaseQuantity()"
/>
<NcButton aria-label="Increase quantity"
style="display:inline-block;"
type="tertiary"
@click="increaseQuantity()">
<template #icon>
<Plus :size="20"/>
</template>
</NcButton>
<NcButton aria-label="Decrease quantity"
style="display:inline-block;"
type="tertiary"
@click="decreaseQuantity()">
<template #icon>
<Minus :size="20"/>
</template>
</NcButton>
</p>
<p>
<NcTextField :value.sync="newItemName"
label="Item…"
Expand Down Expand Up @@ -105,22 +134,24 @@ import {
} from '@nextcloud/vue'
import AlarmSnooze from 'vue-material-design-icons/AlarmSnooze.vue'
import Plus from 'vue-material-design-icons/Plus.vue'
import Minus from 'vue-material-design-icons/Minus.vue'
import Delete from 'vue-material-design-icons/Delete.vue'
import { ref } from 'vue'

export default {
name: 'GroceryList',

components: {
NcCheckboxRadioSwitch,
NcSelect,
NcButton,
NcTextField,
AlarmSnooze,
Plus,
Delete,
NcModal,
},
components: {
NcCheckboxRadioSwitch,
NcSelect,
NcButton,
AlarmSnooze,
NcTextField,
Plus,
Minus,
Delete,
NcModal,
},

props: {
listId: {
Expand Down Expand Up @@ -350,9 +381,37 @@ export default {
this.newItemCategory = this.allCategories.find(i => i.id === item.category)
this.modal = true
},
increaseQuantity() {
if (this.newItemQuantity === '') {
this.newItemQuantity = 0
}

if (this.newItemQuantity >= 1000) {
this.newItemQuantity = this.newItemQuantity + 1000
} else if (this.newItemQuantity >= 100) {
this.newItemQuantity = this.newItemQuantity + 100
} else if (this.newItemQuantity >= 10) {
this.newItemQuantity = this.newItemQuantity + 10
} else {
this.newItemQuantity = this.newItemQuantity + 1
}
},
decreaseQuantity() {
if (this.newItemQuantity > 1000) {
this.newItemQuantity = this.newItemQuantity - 1000
} else if (this.newItemQuantity > 100) {
this.newItemQuantity = this.newItemQuantity - 100
} else if (this.newItemQuantity > 10) {
this.newItemQuantity = this.newItemQuantity - 10
} else if (this.newItemQuantity > 1) {
this.newItemQuantity = this.newItemQuantity - 1
} else {
this.newItemQuantity = ''
}
},
async onSaveItem() {
if (this.newItemName === '') {
showInfo('Cannot add empty item!')
if (this.newItemName === "") {
showInfo("Cannot add empty item!")
return
}

Expand Down Expand Up @@ -451,9 +510,17 @@ h1 {
.modal__content {
margin: 50px;

p {
margin-bottom: calc(var(--default-grid-baseline) * 4);
}
p {
margin-bottom: calc(var(--default-grid-baseline) * 4);

&.quantityRow {
display: flex;

input {
flex-grow: 1;
}
}
}
}

.button-list {
Expand Down

0 comments on commit 77f539e

Please sign in to comment.