Skip to content

Commit

Permalink
Merge pull request #6154 from pmattmann/feature/delete-checklist-item
Browse files Browse the repository at this point in the history
Delete ChecklistItem
  • Loading branch information
usu authored Oct 17, 2024
2 parents 30b451d + 4c6d66e commit 7c21c49
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 2 deletions.
68 changes: 66 additions & 2 deletions frontend/src/components/checklist/ChecklistItemEdit.vue
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,30 @@
submit-color="success"
:cancel-action="close"
>
<template #moreActions>
<PromptEntityDelete
:entity="checklistItem"
:submit-enabled="activitiesWithChecklistItem.length === 0"
align="left"
position="top"
:btn-attrs="{
class: 'v-btn--has-bg',
}"
>
<template v-if="activitiesWithChecklistItem.length > 0" #error>
<ErrorExistingActivitiesList
:camp="camp"
:existing-activities="activitiesWithChecklistItem"
/>
</template>
{{
$tc('components.checklist.checklistItemEdit.delete', 0, {
text: checklistItem.text,
})
}}
</PromptEntityDelete>
</template>

<template #activator="{ on }">
<slot name="activator" v-bind="{ on }" />
</template>
Expand All @@ -26,12 +50,19 @@
</template>

<script>
import { sortBy } from 'lodash'
import DetailPane from '@/components/generic/DetailPane.vue'
import DialogBase from '@/components/dialog/DialogBase.vue'
import PromptEntityDelete from '@/components/prompt/PromptEntityDelete.vue'
import ErrorExistingActivitiesList from '@/components/campAdmin/ErrorExistingActivitiesList.vue'
export default {
name: 'ChecklistItemEdit',
components: { DetailPane },
components: {
DetailPane,
PromptEntityDelete,
ErrorExistingActivitiesList,
},
extends: DialogBase,
provide() {
return {
Expand All @@ -48,6 +79,36 @@ export default {
entityUri: '',
}
},
computed: {
camp() {
return this.checklist.camp()
},
activitiesWithChecklistItem() {
const activities = this.camp.activities().items
const allChecklistNodes = this.api
.get()
.checklistNodes({ camp: this.camp._meta.self }).items
const checklistNodes = allChecklistNodes.filter((cn) =>
cn.checklistItems().items.some((ci) => ci.id === this.checklistItem.id)
)
return sortBy(
activities.filter((a) =>
checklistNodes.some((cn) => cn.root().id === a.rootContentNode().id)
),
(activity) =>
activity
.scheduleEntries()
.items.map(
(s) =>
`${s.dayNumber}`.padStart(3, '0') +
`${s.scheduleEntryNumber}`.padStart(3, '0')
)
.reduce((p, v) => (p < v ? p : v))
)
},
},
watch: {
showDialog: function (showDialog) {
if (showDialog) {
Expand All @@ -61,8 +122,11 @@ export default {
}
},
},
mounted() {
async mounted() {
this.api.href(this.api.get(), 'checklistItems').then((uri) => (this.entityUri = uri))
await this.api.get().checklistNodes({ camp: this.camp._meta.self })
await this.api.get().checklistItems({ 'checklist.camp': this.camp._meta.self })
},
}
</script>
Expand Down
1 change: 1 addition & 0 deletions frontend/src/locales/de.json
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,7 @@
"title": "Checklisteneintrag hinzufügen"
},
"checklistItemEdit": {
"delete": "Möchtest du diesen Eintrag wirklich löschen?",
"title": "Checklisteneintrag bearbeiten"
},
"sortableChecklist": {
Expand Down
1 change: 1 addition & 0 deletions frontend/src/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,7 @@
"title": "Add checklist entry"
},
"checklistItemEdit": {
"delete": "Do you really want to remove this item?",
"title": "Edit checklist entry"
},
"sortableChecklist": {
Expand Down

0 comments on commit 7c21c49

Please sign in to comment.