Skip to content
Snippets Groups Projects
Commit 60cfbee4 authored by Jonathan Foucher's avatar Jonathan Foucher
Browse files

[WIP] evaluation first step front

parent 8512bb4c
No related branches found
No related tags found
No related merge requests found
Pipeline #28504 failed
......@@ -89,9 +89,11 @@ public function save(EvaluationRequest $request, $id = null)
// Evaluer les dangers
if (1 === $data['current_step']) {
$levelsIds = [];
foreach ($data['danger_levels'] as $dangerlevel) {
$evaluation->dangerLevels()->attach($dangerlevel['id']);
$levelsIds[] = $dangerlevel['id'];
}
$evaluation->dangerLevels()->sync($levelsIds);
}
// Evaluer les mesures d'évaluation
......
......@@ -18,7 +18,7 @@ public function definition()
{
return [
'name' => $this->faker->text(50),
'description' => $this->faker->text(500),
'description' => $this->faker->text(),
];
}
}
<template>
<div class="col-md-12">
<div class="card card-default">
<div class="card-body text-center">
<button class="btn btn-default" @click.prevent="cancel">
Annuler l'évaluation
</button>
<button class="btn btn-info" @click.prevent="draft">
<i class="fas fa-spinner fa-spin" v-if="drafting"></i>
Enregistrer un brouillon
</button>
<button class="btn btn-primary" @click.prevent="next">
<i class="fas fa-spinner fa-spin" v-if="saving"></i>
Etape suivante
</button>
</div>
</div>
</div>
</template>
<script>
export default {
name: 'EvaluationButtons',
data() {
return {
drafting: false,
saving: false,
}
},
computed: {
evaluation() {
return this.$store.state.evaluations.all.find(e => e.id === parseInt(this.$route.params.id, 10))
}
},
methods: {
cancel() {
this.$router.push('/evaluations')
},
async draft() {
this.drafting = true
await this.$store.dispatch('saveDraftEvaluation', this.evaluation)
this.drafting = false
},
async next() {
this.saving = true
await this.$store.dispatch('saveEvaluation', this.evaluation)
this.saving = false
},
}
}
</script>
<template>
<div>
Affiche le selecteur de niveau de danger et la description du danger
<div class="col-md-12">
<strong>{{danger.name}}</strong> <i class="text-muted text-sm">(Obligatoire)</i><br>
{{danger.description}}
<select class="form-control" v-model="level">
<option v-for="l in danger.levels" :value="l.id" :key="l.id">
{{l.name}}
</option>
</select>
</div>
</template>
<script>
export default {
name: 'DangerLine',
props: ['danger'],
props: ['danger', 'evaluation'],
data() {
return {
editDanger: this.danger,
}
},
computed: {
level: {
get() {
return this.evaluation.danger_levels ? this.evaluation.danger_levels.find(d => d.danger_id === this.danger.id).id : null
},
set(level) {
const evaluation = {...this.evaluation}
console.log('changing level', level)
console.log('eval before', evaluation.danger_levels)
console.log('this.danger.id', this.danger.id)
evaluation.danger_levels = this.evaluation.danger_levels.map(dl => {
if (dl.danger_id === this.danger.id) {
return {danger_id: dl.danger_id, id: level}
}
return dl
})
console.log('eval after', evaluation.danger_levels)
this.$store.commit('updateEvaluation', evaluation)
}
}
}
}
</script>
<template>
<div>
{{ evaluation.current_step }}
Barre du haut qui montre ou on en est
Etape {{ evaluation.current_step }} sur 5
</div>
</template>
......
<template>
<div>
Step 1
<div class="row">
<div class="col-md-12">
<div class="alert alert-default-light">
<h5>
<i class="fas fa-info-circle"></i>
<strong>Légende</strong>
</h5>
<strong>Négligeable: Lorem ipsum dolor sit amet</strong><br>
<strong>Limité: Lorem ipsum dolor sit amet</strong><br>
<strong>Important: Lorem ipsum dolor sit amet</strong><br>
<strong>Critique: Lorem ipsum dolor sit amet</strong>
</div>
</div>
<div class="col-md-12">
<div class="card card-primary">
<div class="card-header">
<h3 class="card-title">Exposition aux dangers</h3>
</div>
<div class="card-body">
<p>Pour chacun des dangers, veuillez choisir le niveau&nbsp;:</p>
<div class="row">
<DangerLine v-for="danger in dangers" :danger="danger" :evaluation="evaluation" :key="danger.id"></DangerLine>
</div>
</div>
</div>
</div>
<Buttons></Buttons>
</div>
</template>
<script>
import DangerLine from '../Components/Step1/DangerLine'
import Buttons from '../Components/Buttons'
const defaultEvaluation = {
current_step: 1,
};
......@@ -14,8 +42,22 @@ export default {
name: 'EvaluationStep1',
data() {
return {
evaluation: this.$store.state.evaluations.all.find(e => e.id === parseInt(this.$route.params.id, 10)) || defaultEvaluation,
}
},
computed: {
dangers() {
return this.$store.state.dangers.all;
},
evaluation() {
const evaluation = this.$store.state.evaluations.all.find(e => e.id === parseInt(this.$route.params.id, 10))
console.log('levels from parent',evaluation ? evaluation.danger_levels : 'no levels')
if (evaluation) evaluation.current_step = 1;
return evaluation || defaultEvaluation
}
},
components: {
DangerLine,
Buttons,
}
}
</script>
<template>
<div>
<div class="container">
<Steps :evaluation="evaluation"></Steps>
<router-view></router-view>
</div>
......
......@@ -101,13 +101,34 @@ export default [
path: 'evaluations',
name: 'Evaluations',
meta: {
icon: 'fa-search'
icon: 'fa-search',
title: 'Liste des évaluations',
},
component: Evaluations,
children: [
{
path: '',
component: EvaluationsList,
meta: {
icon: 'fa-search',
title: 'Liste des évaluations',
},
},
{
path: 'nouvelle',
component: SingleEvaluation,
children: [
{
path: '',
component: EvaluationStep1,
meta: {
// icon: 'fa-user',
title: 'Créer une évaluation',
type: 'evaluation',
},
},
],
},
{ path: ':id', component: SingleEvaluation, children: [
{ path: '', component: EvaluationStep1 },
......@@ -115,10 +136,13 @@ export default [
{ path: '3', component: EvaluationStep3 },
{ path: '4', component: EvaluationStep4 },
{ path: '5', component: EvaluationStep5 },
]},
{ path: 'nouvelle', component: SingleEvaluation, children: [
{ path: '', component: EvaluationStep1 },
]},
],
meta: {
// icon: 'fa-user',
title: 'Modifier une évaluation',
type: 'evaluation',
},
},
]
},
{
......
import axios from 'axios';
import toaster from '../utils/toaster.js';
export default {
state: { all: []},
mutations: {
setDangers (state, items) {
state.all = items;
},
},
actions: {
getDangers( {commit} ) {
const req = axios.get(`/api/dangers`);
req.then(res => {
commit('setDangers', res.data);
}).catch(err => {
console.log('could not get dangers', err)
})
return req;
},
}
};
......@@ -2,6 +2,7 @@ import user from './user.js'
import users from './users.js';
import organizations from './organizations.js';
import evaluations from './evaluations.js';
import dangers from './dangers.js';
export default {
modules: {
......@@ -9,5 +10,6 @@ export default {
users,
organizations,
evaluations,
dangers,
}
}
......@@ -43,6 +43,7 @@ export default {
dispatch('getUsers');
dispatch('getOrganizations');
dispatch('getEvaluations');
dispatch('getDangers');
return r.data
} catch (e) {
console.log('could not get user', e)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment