Skip to content

Commit

Permalink
refactor(Proofs): display the proof action menu to everyone (#1197)
Browse files Browse the repository at this point in the history
  • Loading branch information
raphodn authored Dec 30, 2024
1 parent f3ea4aa commit 3c61f24
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 10 deletions.
21 changes: 15 additions & 6 deletions src/components/ProofActionMenuButton.vue
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,17 @@
{{ $t('Common.Proof') }}
</v-list-subheader>
<v-divider />
<PriceAddLink :proofId="proof.id" display="list-item" :disabled="!userCanAddPrice" />
<PriceAddLink v-if="userIsProofOwner" :proofId="proof.id" display="list-item" :disabled="!userCanAddPrice" />
<v-list-item :slim="true" prepend-icon="mdi-eye-outline" :to="getProofDetailUrl">
{{ $t('Common.Details') }}
</v-list-item>
<v-list-item :slim="true" prepend-icon="mdi-open-in-new" :href="getProofFullUrl" target="_blank">
{{ $t('Common.ImageFull') }}
</v-list-item>
<v-list-item :slim="true" prepend-icon="mdi-pencil" :disabled="!userCanEditProof" @click="openEditDialog">
<v-list-item v-if="userIsProofOwner" :slim="true" prepend-icon="mdi-pencil" :disabled="!userCanEditProof" @click="openEditDialog">
{{ $t('Common.Edit') }}
</v-list-item>
<v-list-item :slim="true" prepend-icon="mdi-delete" :disabled="!userCanDeleteProof" @click="openDeleteConfirmationDialog">
<v-list-item v-if="userIsProofOwner" :slim="true" prepend-icon="mdi-delete" :disabled="!userCanDeleteProof" @click="openDeleteConfirmationDialog">
{{ $t('Common.Delete') }}
</v-list-item>
</v-list>
Expand Down Expand Up @@ -58,6 +58,8 @@

<script>
import { defineAsyncComponent } from 'vue'
import { mapStores } from 'pinia'
import { useAppStore } from '../store'
import constants from '../constants'
export default {
Expand Down Expand Up @@ -87,6 +89,13 @@ export default {
}
},
computed: {
...mapStores(useAppStore),
username() {
return this.appStore.user.username
},
userIsProofOwner() {
return this.username && (this.proof.owner === this.username)
},
getProofFullUrl() {
// return 'https://prices.openfoodfacts.org/img/0002/qU59gK8PQw.webp' // PRICE_TAG
// return 'https://prices.openfoodfacts.net/img/0001/lZGFga9ZOT.webp' // RECEIPT
Expand All @@ -96,17 +105,17 @@ export default {
return `/proofs/${this.proof.id}`
},
userCanAddPrice() {
return this.proof && constants.PROOF_TYPE_USER_EDITABLE_LIST.includes(this.proof.type)
return this.proof && this.userIsProofOwner && constants.PROOF_TYPE_USER_EDITABLE_LIST.includes(this.proof.type)
},
userCanEditProof() {
// user must be proof owner (already checked in parent component)
// only allow edition of certain proof types
return constants.PROOF_TYPE_USER_EDITABLE_LIST.includes(this.proof.type)
return this.userIsProofOwner && constants.PROOF_TYPE_USER_EDITABLE_LIST.includes(this.proof.type)
},
userCanDeleteProof() {
// user must be proof owner (already checked in parent component)
// and proof must not have any prices
return this.proof.price_count === 0
return this.userIsProofOwner && this.proof.price_count === 0
},
},
methods: {
Expand Down
6 changes: 3 additions & 3 deletions src/components/ProofFooterRow.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<template>
<v-row>
<v-col :cols="userIsProofOwner ? '11' : '12'">
<v-col cols="11">
<ProofChip v-if="showProofChip" class="mr-1" :proof="proof" :readonly="true" />
<ProofTypeChip v-if="!hideProofType" class="mr-1" :proofType="proof.type" />
<ProofReceiptPriceCountChip v-if="showReceiptPriceCount" class="mr-1" :totalCount="proof.receipt_price_count" />
Expand All @@ -14,7 +14,7 @@
</v-col>
</v-row>

<ProofActionMenuButton v-if="!hideProofActions && userIsProofOwner" :proof="proof" />
<ProofActionMenuButton v-if="!hideProofActions" :proof="proof" />
</template>

<script>
Expand Down Expand Up @@ -87,7 +87,7 @@ export default {
},
methods: {
goToProof() {
if (this.readonly || !this.userIsProofOwner) {
if (this.readonly) {
return
}
this.$router.push({ path: `/proofs/${this.proof.id}` })
Expand Down
2 changes: 1 addition & 1 deletion src/views/ProofList.vue
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

<v-row class="mt-0">
<v-col v-for="proof in proofList" :key="proof" cols="12" sm="6" md="4" xl="3">
<ProofCard :proof="proof" :hideProofHeader="true" :hideProofActions="true" :showImageThumb="true" elevation="1" height="100%" />
<ProofCard :proof="proof" :hideProofHeader="true" :showImageThumb="true" elevation="1" height="100%" />
</v-col>
</v-row>

Expand Down

0 comments on commit 3c61f24

Please sign in to comment.