Skip to content

Commit

Permalink
Merge pull request #1409 Ajoute la page de sondage
Browse files Browse the repository at this point in the history
  • Loading branch information
guillett authored Nov 30, 2019
2 parents 07f2dc0 + b7861d6 commit c177254
Show file tree
Hide file tree
Showing 6 changed files with 237 additions and 70 deletions.
14 changes: 13 additions & 1 deletion backend/lib/survey.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,14 @@ send.addArgument(
help: 'Followup Id'
}
);
send.addArgument(
[ '--mock' ],
{
action: 'storeTrue',
help: 'Do not send emails'
}
);

send.addArgument(
[ '--multiple' ],
{
Expand Down Expand Up @@ -52,7 +60,11 @@ function main() {
Followup.findOne({
'_id': args.id
}).then(f => {
return f.sendSurvey();
if (args.mock) {
return f.mock();
} else {
return f.sendSurvey();
}
}).then(e => {
console.log('log', e);
}).catch(e => {
Expand Down
10 changes: 10 additions & 0 deletions backend/models/followup.js
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,16 @@ FollowupSchema.methods.sendSurvey = function() {
});
};

FollowupSchema.methods.mock = function() {
var followup = this;
return this.createSurvey('initial').then((survey) => {
var surveys = Array.from(followup.surveys);
surveys.push(survey);
followup.surveys = surveys;
return followup.save();
});
};

FollowupSchema.methods.updateSurvey = function(id, answers) {
var surveys = Array.from(this.surveys);
var survey = _.find(surveys, function(s) { return s._id === id; });
Expand Down
69 changes: 0 additions & 69 deletions src/components/DroitsDetails.vue
Original file line number Diff line number Diff line change
Expand Up @@ -126,72 +126,3 @@ export default {
},
}
</script>

<style scoped lang="scss">
@import '@/styles/main.scss';
.droit-detail {
margin-bottom: 30px;
&-heading {
align-items: center;
display: flex;
flex-direction: row;
justify-content: space-between;
padding: 15px 0;
position: relative;
h2 {
font-weight: 600;
margin: 0;
}
}
&-description {
margin-bottom: 15px;
}
&-buttons {
align-items: center;
display: flex;
flex-direction: row;
justify-content: space-between;
margin-bottom: 15px;
&-cta {
display: flex;
align-items: stretch;
justify-content: space-between;
}
@media (max-width: $screen-sm-max) {
&, > * {
flex-direction: column;
width: 100%;
}
.btn-secondary {
order: 3;
}
}
}
.alert-warning {
align-items: center;
display: flex;
font-weight: 400;
justify-content: space-between;
}
}
.montant i {
position: relative;
top: 0.4em;
}
@media print {
.droit-detail {
page-break-inside: avoid;
}
}
</style>
5 changes: 5 additions & 0 deletions src/router.js
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,11 @@ const router = new Router({
name: 'sos',
component: () => import(/* webpackChunkName: "sos" */ './views/SOS.vue')
},
{
path: '/suivi',
name: 'suivi',
component: () => import(/* webpackChunkName: "suivi" */ './views/Suivi.vue')
},
],
scrollBehavior (to/*, from, savedPosition*/) {
if (to.hash) {
Expand Down
64 changes: 64 additions & 0 deletions src/styles/main.scss
Original file line number Diff line number Diff line change
Expand Up @@ -56,3 +56,67 @@ form {
}

}

.droit-detail {
margin-bottom: 30px;

&-heading {
align-items: center;
display: flex;
flex-direction: row;
justify-content: space-between;
padding: 15px 0;
position: relative;

h2 {
font-weight: 600;
margin: 0;
}
}

&-description {
margin-bottom: 15px;
}

&-buttons {
align-items: center;
display: flex;
flex-direction: row;
justify-content: space-between;
margin-bottom: 15px;

&-cta {
display: flex;
align-items: stretch;
justify-content: space-between;
}

@media (max-width: $screen-sm-max) {
&, > * {
flex-direction: column;
width: 100%;
}
.btn-secondary {
order: 3;
}
}
}

.alert-warning {
align-items: center;
display: flex;
font-weight: 400;
justify-content: space-between;
}
}

.montant i {
position: relative;
top: 0.4em;
}

@media print {
.droit-detail {
page-break-inside: avoid;
}
}
145 changes: 145 additions & 0 deletions src/views/Suivi.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,145 @@
<template>
<form>
<h1>Suivi Mes Aides</h1>
<p v-show="!this.droits"><i class="fa fa-spinner fa-spin" aria-hidden="true"></i> Récupération de la situation en cours…</p>


<div class="alert alert-success" v-if="submitted">
Merci d'avoir rempli ce questionnaire !
</div>

<div v-if="this.droits && ! submitted">
<p>
Vous avez effectué une simulation le <strong>{{createdAt}}</strong>.
</p>
<p>
Répondez à ce questionnaire afin de nous aider à améliorer la pertinence des résultats que nous affichons. Ça ne prend pas plus de 2 minutes !
</p>

<div class="droit-details">
<div v-for="droit in droits" v-bind:key="droit.id" class="droit-detail"
itemscope itemtype="http://schema.org/GovernmentService">

<div class="droit-detail-heading">
<h3 itemprop="name">{{ droit.label }}</h3>
<div class="dotted-line"></div>
<droit-montant v-bind:droit="droit" v-if="droit.montant && (isString(droit.montant) || isNumber(droit.montant))"></droit-montant>
</div>

<div v-for="choice in droit.choices" v-bind:key="choice.value">
<label>
<input type="radio" v-bind:name="`choices_${ droit.id }_${ choice.value }`" v-bind:value="choice.value"
v-model="droit.choiceValue">
{{ choice.label }}
</label>
</div>
<textarea v-show="isNegative(droit.choiceValue)" v-model="droit.choiceComments" placeholder="Pour quelle raison ?"></textarea>
</div>
</div>

<button type="submit" v-bind:class="`button large ${!isComplete ? 'secondary ' : ''}`" v-bind:disabled="! isComplete" v-on:click.prevent="submit">Envoyer</button>
</div>
</form>
</template>

<script>
import axios from 'axios'
import _ from 'lodash'
import moment from 'moment'
import DroitMontant from '@/components/DroitMontant'
import { forEach } from '../../backend/lib/mes-aides'
const choices = [
{ value: 'already', label: "J'en bénéficiais déjà" },
{ value: 'asked', label: "J'ai fait une demande" },
{ value: 'failed', label: "Je n'ai pas réussi à faire une demande" },
{ value: 'nothing', label: "Je n'ai rien fait" },
]
function isNegative(value) {
return value === 'failed' || value === 'nothing'
}
export default {
name: 'Suivi',
data: function() {
return {
submitted: false,
droits: null,
followup: null
}
},
components: {
DroitMontant
},
computed: {
createdAt: function() {
return this.followup && moment(this.followup.createdAt).format('ll')
},
isComplete: function() {
var choiceValues = _.map(this.droits, droit => droit.choiceValue)
return _.filter(choiceValues).length === this.droits.length
}
},
methods: {
isString: _.isString,
isNumber: _.isNumber,
isNegative,
submit: function() {
var answers = this.droits.map(droit => ({
id: droit.id,
value: droit.choiceValue,
comments: droit.choiceComments
}))
let that = this
axios.post(`/api/followups/surveys/${this.$route.query.token}/answers`, answers)
.then(function(response) {
if (response.status === 201) {
that.submitted = true
}
})
}
},
mounted: function() {
axios.get(`/api/followups/surveys/${this.$route.query.token}`)
.then((response) => {
this.followup = response.data
var benefitsIds = this.followup.benefits.map(benefit => benefit.id)
var benefitsNormalized = []
forEach((benefit, benefitId, provider, providerId) => {
if (! benefitsIds.includes(benefitId)) {
return
}
var montant = _.find(this.followup.benefits, benefit => benefit.id === benefitId).amount
benefitsNormalized.push(_.assign({},
benefit,
{
id: benefitId,
montant: montant,
provider: provider,
providerId: providerId,
choices: choices,
choiceValue: null,
choiceComments: ''
}
))
})
this.droits = benefitsNormalized
})
}
}
</script>

<style scoped lang="scss">
form {
flex-grow: 1;
padding: 1em;
}
</style>

0 comments on commit c177254

Please sign in to comment.