Skip to content

Commit 6eef24e

Browse files
add plus minus for quantity
1 parent 5a8d516 commit 6eef24e

File tree

1 file changed

+88
-21
lines changed

1 file changed

+88
-21
lines changed

src/views/GroceryList.vue

Lines changed: 88 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,49 @@
11
<template>
22
<div class="page-wrapper">
3+
<div>
4+
<NcButton aria-label="Show add/edit modal"
5+
@click="showAddModal">
6+
<template #icon>
7+
<Plus :size="20"/>
8+
</template>
9+
<template>Add</template>
10+
</NcButton>
11+
</div>
312
<h1>{{ groceryList?.title ?? t('grocerylist', 'Grocery list') }}</h1>
413
<div>
514
<NcCheckboxRadioSwitch :checked="!!groceryList?.showOnlyUnchecked" type="switch" @update:checked="toggleVisibility">
615
{{ t('grocerylist', 'Show only unchecked') }}
716
</NcCheckboxRadioSwitch>
8-
<NcModal v-if="modal"
9-
ref="modalRef"
10-
:name="t('grocerylist', 'Add item')"
17+
<NcModal
18+
v-if="modal"
19+
ref="modalRef"
20+
:name="t('grocerylist', 'Add item')"
1121
@close="closeModal">
1222
<form class="modal__content"
1323
@submit.prevent="onSaveItem()">
14-
<p>
24+
<p class="quantityRow">
1525
<NcTextField :value.sync="newItemQuantity"
16-
label="Quantity…" />
17-
</p>
26+
label="Quantity…"
27+
@keyup.up="increaseQuantity()"
28+
@keyup.down="decreaseQuantity()"
29+
/>
30+
<NcButton aria-label="Increase quantity"
31+
style="display:inline-block;"
32+
type="tertiary"
33+
@click="increaseQuantity()">
34+
<template #icon>
35+
<Plus :size="20"/>
36+
</template>
37+
</NcButton>
38+
<NcButton aria-label="Decrease quantity"
39+
style="display:inline-block;"
40+
type="tertiary"
41+
@click="decreaseQuantity()">
42+
<template #icon>
43+
<Minus :size="20"/>
44+
</template>
45+
</NcButton>
46+
</p>
1847
<p>
1948
<NcTextField :value.sync="newItemName"
2049
label="Item…"
@@ -105,22 +134,24 @@ import {
105134
} from '@nextcloud/vue'
106135
import AlarmSnooze from 'vue-material-design-icons/AlarmSnooze.vue'
107136
import Plus from 'vue-material-design-icons/Plus.vue'
137+
import Minus from 'vue-material-design-icons/Minus.vue'
108138
import Delete from 'vue-material-design-icons/Delete.vue'
109139
import { ref } from 'vue'
110140
111141
export default {
112142
name: 'GroceryList',
113143
114-
components: {
115-
NcCheckboxRadioSwitch,
116-
NcSelect,
117-
NcButton,
118-
NcTextField,
119-
AlarmSnooze,
120-
Plus,
121-
Delete,
122-
NcModal,
123-
},
144+
components: {
145+
NcCheckboxRadioSwitch,
146+
NcSelect,
147+
NcButton,
148+
AlarmSnooze,
149+
NcTextField,
150+
Plus,
151+
Minus,
152+
Delete,
153+
NcModal,
154+
},
124155
125156
props: {
126157
listId: {
@@ -350,9 +381,37 @@ export default {
350381
this.newItemCategory = this.allCategories.find(i => i.id === item.category)
351382
this.modal = true
352383
},
384+
increaseQuantity() {
385+
if (this.newItemQuantity === '') {
386+
this.newItemQuantity = 0
387+
}
388+
389+
if (this.newItemQuantity >= 1000) {
390+
this.newItemQuantity = this.newItemQuantity + 1000
391+
} else if (this.newItemQuantity >= 100) {
392+
this.newItemQuantity = this.newItemQuantity + 100
393+
} else if (this.newItemQuantity >= 10) {
394+
this.newItemQuantity = this.newItemQuantity + 10
395+
} else {
396+
this.newItemQuantity = this.newItemQuantity + 1
397+
}
398+
},
399+
decreaseQuantity() {
400+
if (this.newItemQuantity > 1000) {
401+
this.newItemQuantity = this.newItemQuantity - 1000
402+
} else if (this.newItemQuantity > 100) {
403+
this.newItemQuantity = this.newItemQuantity - 100
404+
} else if (this.newItemQuantity > 10) {
405+
this.newItemQuantity = this.newItemQuantity - 10
406+
} else if (this.newItemQuantity > 1) {
407+
this.newItemQuantity = this.newItemQuantity - 1
408+
} else {
409+
this.newItemQuantity = ''
410+
}
411+
},
353412
async onSaveItem() {
354-
if (this.newItemName === '') {
355-
showInfo('Cannot add empty item!')
413+
if (this.newItemName === "") {
414+
showInfo("Cannot add empty item!")
356415
return
357416
}
358417
@@ -451,9 +510,17 @@ h1 {
451510
.modal__content {
452511
margin: 50px;
453512
454-
p {
455-
margin-bottom: calc(var(--default-grid-baseline) * 4);
456-
}
513+
p {
514+
margin-bottom: calc(var(--default-grid-baseline) * 4);
515+
516+
&.quantityRow {
517+
display: flex;
518+
519+
input {
520+
flex-grow: 1;
521+
}
522+
}
523+
}
457524
}
458525
459526
.button-list {

0 commit comments

Comments
 (0)