|
1 | 1 | <template> |
2 | 2 | <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> |
3 | 12 | <h1>{{ groceryList?.title ?? t('grocerylist', 'Grocery list') }}</h1> |
4 | 13 | <div> |
5 | 14 | <NcCheckboxRadioSwitch :checked="!!groceryList?.showOnlyUnchecked" type="switch" @update:checked="toggleVisibility"> |
6 | 15 | {{ t('grocerylist', 'Show only unchecked') }} |
7 | 16 | </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')" |
11 | 21 | @close="closeModal"> |
12 | 22 | <form class="modal__content" |
13 | 23 | @submit.prevent="onSaveItem()"> |
14 | | - <p> |
| 24 | + <p class="quantityRow"> |
15 | 25 | <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> |
18 | 47 | <p> |
19 | 48 | <NcTextField :value.sync="newItemName" |
20 | 49 | label="Item…" |
@@ -105,22 +134,24 @@ import { |
105 | 134 | } from '@nextcloud/vue' |
106 | 135 | import AlarmSnooze from 'vue-material-design-icons/AlarmSnooze.vue' |
107 | 136 | import Plus from 'vue-material-design-icons/Plus.vue' |
| 137 | +import Minus from 'vue-material-design-icons/Minus.vue' |
108 | 138 | import Delete from 'vue-material-design-icons/Delete.vue' |
109 | 139 | import { ref } from 'vue' |
110 | 140 |
|
111 | 141 | export default { |
112 | 142 | name: 'GroceryList', |
113 | 143 |
|
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 | + }, |
124 | 155 |
|
125 | 156 | props: { |
126 | 157 | listId: { |
@@ -350,9 +381,37 @@ export default { |
350 | 381 | this.newItemCategory = this.allCategories.find(i => i.id === item.category) |
351 | 382 | this.modal = true |
352 | 383 | }, |
| 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 | + }, |
353 | 412 | async onSaveItem() { |
354 | | - if (this.newItemName === '') { |
355 | | - showInfo('Cannot add empty item!') |
| 413 | + if (this.newItemName === "") { |
| 414 | + showInfo("Cannot add empty item!") |
356 | 415 | return |
357 | 416 | } |
358 | 417 |
|
@@ -451,9 +510,17 @@ h1 { |
451 | 510 | .modal__content { |
452 | 511 | margin: 50px; |
453 | 512 |
|
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 | + } |
457 | 524 | } |
458 | 525 |
|
459 | 526 | .button-list { |
|
0 commit comments