This commit is contained in:
Matthieu Bessat 2020-07-16 17:42:49 +02:00
commit b8d7b53308
7 changed files with 316 additions and 87 deletions

View file

@ -4,12 +4,14 @@
<v-data-table
:headers="headers"
:items="organizations"
sort-by="calories"
sort-by="validationState"
class="elevation-1"
>
<template v-slot:top>
<v-toolbar flat color="white">
<v-toolbar-title>Gestion des associations</v-toolbar-title>
<v-toolbar-title v-if="!$vuetify.breakpoint.mobile">
Gestion des associations
</v-toolbar-title>
<v-spacer></v-spacer>
<v-btn
outlined
@ -29,7 +31,7 @@
v-bind="attrs"
v-on="on"
>
Nouvelle association
<v-icon left>add</v-icon> Association
</v-btn>
</template>
<v-card>
@ -84,21 +86,28 @@
<!-- <template v-slot:item.description="{ item }">
{{ item.description|less }}
</template> -->
<template v-slot:item.validationState="{ item }">
<v-chip
:color="getValidationColor(item.validationState)"
dark>
{{ getValidationText(item.validationState) }}
</v-chip>
</template>
<template v-slot:item.actions="{ item }">
<v-tooltip top>
<template v-slot:activator="{ on, attrs }">
<v-btn icon small color="success">
<v-icon
small
@click="openApproveModal(item)"
@click="openExternal(item)"
v-bind="attrs"
v-on="on"
>
done
launch
</v-icon>
</v-btn>
</template>
<span>Valider les changements</span>
<span>Ouvrir la page publique (version non publié)</span>
</v-tooltip>
<v-tooltip top>
<template v-slot:activator="{ on, attrs }">
@ -145,20 +154,20 @@
</template>
<span>Voir plus</span>
</v-tooltip>
<v-tooltip top>
<v-tooltip top v-if="item.validationState === 'pending'">
<template v-slot:activator="{ on, attrs }">
<v-btn icon small color="success">
<v-btn small icon color="success">
<v-icon
small
@click="openExternal(item)"
@click="openApproveModal(item)"
v-bind="attrs"
v-on="on"
>
launch
done
</v-icon>
</v-btn>
</template>
<span>Ouvrir la page publique</span>
<span>Valider les changements</span>
</v-tooltip>
</template>
<template v-slot:no-data>
@ -266,32 +275,38 @@
</v-card-text>
<v-card-actions>
<v-spacer />
<v-btn color="blue darken-1" text @click="detailsModal = false">Fermer</v-btn>
<v-btn color="primary" text @click="detailsModal = false">Fermer</v-btn>
</v-card-actions>
</v-card>
</v-dialog>
<v-dialog v-model="approveModal" max-width="700">
<Preview
:enabled="approveModal"
:slug="toApproveItem.slug"
:dialogTitle="approveModalTitle"
@close="approveModal = false"
>
<v-btn outlined dark text @click="rejectionModal = true">
<v-icon>clear</v-icon>
</v-btn>
<v-btn outlined dark text @click="approve()">
<v-icon>done</v-icon>
</v-btn>
</Preview>
<v-dialog max-width="500px" v-model="rejectionModal">
<v-card>
<v-card-title>
Vérification et publication des changements de l'association {{ toSeeItem.adminName }}
</v-card-title>
<v-card-title>Indiquez la raison de ce refus</v-card-title>
<v-card-text>
<v-switch label="Les modifications sont acceptées" v-model="approved" />
<v-textarea
:disabled="approved"
label="Raisons du rejet"
v-model="rejectionDescription">
</v-textarea>
label="Description"
v-model="rejectionDescription" />
</v-card-text>
<v-card-actions>
<v-btn text @click="rejectionModal = false">Fermer</v-btn>
<v-spacer />
<v-btn color="grey darken-3" text @click="approveModal = false">Fermer</v-btn>
<v-btn
color="primary"
text
@click="approveOrReject()"
:disabled="approved && rejectionDescription.length === 0"
>Valider</v-btn>
<v-btn color="primary" text @click="reject()" :disabled="rejectionDescription.length === 0">
Valider
</v-btn>
</v-card-actions>
</v-card>
</v-dialog>
@ -299,14 +314,20 @@
</template>
<script>
import Preview from '../../components/Preview'
export default {
components: {
Preview
},
data: () => {
const item = {
adminName: '',
email: '',
validationState: 'none',
rejectionDescription: ''
rejectionDescription: '',
slug: ''
}
return {
dialog: false,
@ -315,6 +336,10 @@ export default {
text: 'Nom interne',
value: 'adminName'
},
{
text: 'État',
value: 'validationState'
},
{
text: 'E-mail',
value: 'email'
@ -329,19 +354,23 @@ export default {
editedItem: item,
defaultItem: item,
deleteModal: false,
validationState: ['none', 'pending', 'rejected', 'published'],
validationState: ['unaware', 'pending', 'rejected', 'published'],
detailsModal: false,
toSeeItem: item,
approveModal: false,
toApproveItem: item,
rejectionDescription: '',
approved: false
approved: false,
rejectionModal: false
}
},
computed: {
formTitle () {
return this.editedIndex === -1 ? 'Nouvelle association' : "Modification de l'association"
},
approveModalTitle () {
return 'Vérification des changements apporté par "' + this.toApproveItem.adminName + '"'
}
},
@ -360,6 +389,14 @@ export default {
fetchData () {
this.$apitator.get('/admin/organizations', { withAuth: true }).then(res => {
this.organizations = res.data.data
if (this.$route.query.approval !== undefined) {
const organizations = this.organizations.filter(o => o._id === this.$route.query.approval)
if (organizations.length > 0) {
this.$router.push({ query: {} })
this.openApproveModal(organizations[0])
}
}
})
},
@ -479,7 +516,7 @@ export default {
},
openExternal (item) {
window.open('https://forum.espacecondorcet.org/association/slug' + item.slug, '_blank').focus()
window.open(process.env.VUE_APP_BASE_URL + '/association/' + item.slug + '?version=proposed', '_blank').focus()
},
openApproveModal (item) {
@ -488,35 +525,74 @@ export default {
this.approved = false
},
approveOrReject (item) {
if (this.approved) {
this.$apitator.post('/admin/organizations/' + item._id + '/approve', {}, { withAuth: true }).then(() => {
this.approveModal = false
this.$store.commit('ADD_ALERT', {
color: 'success',
text: 'La publication est cours de réalisation et un email va être envoyé à cette association afin de notifier de cette publication'
})
}).catch(() => {
this.$store.commit('ADD_ALERT', {
color: 'error',
text: "Impossible d'approuver les changements"
})
approve () {
this.$apitator.post('/admin/organizations/' + this.toApproveItem._id + '/approve', {}, { withAuth: true }).then(() => {
this.approveModal = false
this.organizations = this.organizations.map(o => {
if (o._id === this.toApproveItem._id) {
o.validationState = 'published'
}
return o
})
} else {
this.$apitator.post('/admin/organizations/' + item._id + '/reject', {
rejectionDescription: this.rejectionDescription
}, { withAuth: true }).then(() => {
this.approveModal = false
this.$store.commit('ADD_ALERT', {
color: 'success',
text: "Un email va être envoyé à cette association afin d'informer du problème"
})
}).catch(() => {
this.$store.commit('ADD_ALERT', {
color: 'error',
text: 'Impossible de rejeter les changements'
})
this.$store.commit('ADD_ALERT', {
color: 'success',
text: 'La publication est cours de réalisation et un email va être envoyé à cette association afin de notifier de cette publication'
})
}).catch(() => {
this.$store.commit('ADD_ALERT', {
color: 'error',
text: "Impossible d'approuver les changements"
})
})
},
reject () {
this.$apitator.post('/admin/organizations/' + this.toApproveItem._id + '/reject', {
rejectionDescription: this.rejectionDescription
}, { withAuth: true }).then(() => {
this.rejectionModal = false
this.approveModal = false
this.organizations = this.organizations.map(o => {
if (o._id === this.toApproveItem._id) {
o.validationState = 'rejected'
}
return o
})
this.$store.commit('ADD_ALERT', {
color: 'success',
text: "Un email va être envoyé à cette association afin d'informer du problème"
})
}).catch(() => {
this.$store.commit('ADD_ALERT', {
color: 'error',
text: 'Impossible de rejeter les changements'
})
})
},
getValidationColor (state) {
switch (state) {
case 'unaware':
return 'accent'
case 'published':
return 'success'
case 'rejected':
return 'error'
case 'pending':
return 'secondary'
}
},
getValidationText (state) {
switch (state) {
case 'unaware':
return 'Début'
case 'published':
return 'Publié'
case 'rejected':
return 'Refusé'
case 'pending':
return 'En attente'
}
}
}

View file

@ -9,12 +9,9 @@
>
<template v-slot:top>
<v-toolbar flat color="white">
<v-toolbar-title>Gestion des catégories</v-toolbar-title>
<!-- <v-divider
class="mx-4"
inset
vertical
></v-divider> -->
<v-toolbar-title v-if="!$vuetify.breakpoint.mobile">
Gestion des catégories
</v-toolbar-title>
<v-spacer></v-spacer>
<v-btn
outlined
@ -34,7 +31,7 @@
v-bind="attrs"
v-on="on"
>
Nouvelle catégorie
<v-icon left>add</v-icon> Catégorie
</v-btn>
</template>
<v-card>