Skip to content

Commit 5ad3d16

Browse files
Merge pull request #264 from tobiasKaminsky/toggleCategories
[WIP] toggle categories
2 parents 77f539e + a2b922b commit 5ad3d16

File tree

5 files changed

+204
-165
lines changed

5 files changed

+204
-165
lines changed

src/components/ListCategoryNew.vue

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99
@trailing-button-click="newCategoryName = ''" />
1010

1111
<NcButton type="tertiary"
12-
:aria-label="t('grocerylist', 'Add category {category}', { category: newCategoryName })"
13-
@click="addCategory">
12+
:aria-label="t('grocerylist', 'Add category {category}', { category: newCategoryName })"
13+
@click="addCategory">
1414
<template #icon>
1515
<IconPlus :size="20" />
1616
</template>

src/components/ListItem.vue

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
<template>
2+
<li :class="{'snoozed': isSnoozed}">
3+
<NcButton aria-label="Snooze"
4+
type="tertiary"
5+
style="display:inline-block;"
6+
@click="hideItem(item)">
7+
<template #icon>
8+
<AlarmSnooze :size="20" />
9+
</template>
10+
</NcButton>
11+
<NcCheckboxRadioSwitch :checked="item.checked === true"
12+
style="display:inline-block;"
13+
@update:checked="checkItem(item)" />
14+
<span @click="$emit('edit')">
15+
<span v-if="item.quantity !== ''">
16+
{{ item.quantity }}
17+
</span>
18+
{{ item.name }}
19+
</span>
20+
</li>
21+
</template>
22+
<script>
23+
import axios from '@nextcloud/axios'
24+
import { generateUrl } from '@nextcloud/router'
25+
import { showError } from '@nextcloud/dialogs'
26+
import AlarmSnooze from 'vue-material-design-icons/AlarmSnooze.vue'
27+
28+
import {
29+
NcCheckboxRadioSwitch,
30+
NcButton,
31+
} from '@nextcloud/vue'
32+
export default {
33+
name: 'ListItem',
34+
components: {
35+
AlarmSnooze,
36+
NcCheckboxRadioSwitch,
37+
NcButton,
38+
},
39+
props: {
40+
item: {
41+
type: Object,
42+
required: true,
43+
},
44+
},
45+
computed: {
46+
isSnoozed() {
47+
return this.item?.hidden > (Math.floor(Date.now() / 1000) - (15 * 60))
48+
},
49+
},
50+
methods: {
51+
async checkItem(item) {
52+
if (item.checked === true) {
53+
item.checked = false
54+
} else {
55+
item.checked = true
56+
}
57+
try {
58+
await axios.post(generateUrl('/apps/grocerylist/api/item/check'),
59+
{ id: item.id, checked: item.checked },
60+
)
61+
} catch (e) {
62+
console.error(e)
63+
showError(t('grocerylist', 'Could not check item'))
64+
}
65+
},
66+
async hideItem(item) {
67+
try {
68+
await axios.post(generateUrl('/apps/grocerylist/api/item/hide'),
69+
{ id: item.id },
70+
)
71+
72+
this.$emit('update')
73+
} catch (e) {
74+
console.error(e)
75+
showError(t('grocerylist', 'Could not add item'))
76+
}
77+
},
78+
},
79+
}
80+
</script>
81+
<style scoped lang="scss">
82+
83+
</style>

src/components/NavigationGroceryListItem.vue

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -16,19 +16,19 @@
1616
{{ t('grocerylist', 'Delete list') }}
1717
</NcActionButton>
1818
</template>
19-
<template #counter v-if="groceryList.uncheckedCount > 0">
20-
<NcCounterBubble>
21-
{{ groceryList.uncheckedCount }}
22-
</NcCounterBubble>
23-
</template>
19+
<template v-if="groceryList.uncheckedCount > 0" #counter>
20+
<NcCounterBubble>
21+
{{ groceryList.uncheckedCount }}
22+
</NcCounterBubble>
23+
</template>
2424
</NcAppNavigationItem>
2525
</template>
2626
<script>
2727
import { showError, showInfo, showSuccess } from '@nextcloud/dialogs'
2828
import {
2929
NcActionButton,
3030
NcAppNavigationItem,
31-
NcCounterBubble,
31+
NcCounterBubble,
3232
} from '@nextcloud/vue'
3333
import axios from '@nextcloud/axios'
3434
import { generateUrl } from '@nextcloud/router'
@@ -38,7 +38,7 @@ export default {
3838
components: {
3939
NcActionButton,
4040
NcAppNavigationItem,
41-
NcCounterBubble
41+
NcCounterBubble,
4242
},
4343
props: {
4444
groceryList: {
@@ -63,14 +63,14 @@ export default {
6363
},
6464
title() {
6565
return this.groceryList.title
66-
},
67-
titleWithCount() {
68-
if (this.groceryList.uncheckedCount > 0) {
69-
return this.groceryList.title + ' (' + this.groceryList.uncheckedCount + ')'
70-
} else {
71-
return this.groceryList.title
72-
}
73-
},
66+
},
67+
titleWithCount() {
68+
if (this.groceryList.uncheckedCount > 0) {
69+
return this.groceryList.title + ' (' + this.groceryList.uncheckedCount + ')'
70+
} else {
71+
return this.groceryList.title
72+
}
73+
},
7474
},
7575
methods: {
7676
async onRename(newTitle) {

0 commit comments

Comments
 (0)