Skip to content

Commit

Permalink
Refactor black powder revolver path
Browse files Browse the repository at this point in the history
  • Loading branch information
thomashbrnrd committed Jun 7, 2024
1 parent 32e1272 commit ed7e07b
Show file tree
Hide file tree
Showing 9 changed files with 39 additions and 49 deletions.
2 changes: 1 addition & 1 deletion frontend/cypress/e2e/typology-revolver-securing.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ describe('Typology Revolver Securing', () => {
cy.contains('h1', 'mise en sécurité')
cy.contains('p', 'les manipulations sont complexes')
cy.getByDataTestid('go-to-identification').click()
cy.url().should('contain', '/guide-identification/resultat-typologie')
cy.url().should('contain', '/guide-identification/resultat-final')
cy.getByDataTestid('arm-category').should('contain', 'Catégorie D')
})

Expand Down
18 changes: 7 additions & 11 deletions frontend/src/components/ResultPage.vue
Original file line number Diff line number Diff line change
Expand Up @@ -27,17 +27,7 @@ const isFeedbackDone = ref(false)
const label = computed(() => typology?.displayLabel)
const category = computed(() => {
if (store.selectedAlarmGun && store.selectedAlarmGun !== '') {
return 'D'
} else if (isDummy.value) {
return 'Non Classée'
} else if (typology.displayLabel === 'Revolver') {
return typology?.categoryWithoutSecuring
} else {
return typology?.getCategory(store.gunLength, store.gunBarrelLength)
}
})
const category = computed(() => isDummy.value ? 'Non Classée' : typology?.getCategory(store.gunLength, store.gunBarrelLength))
const disclaimer = computed(() => typology && Object.hasOwn(typology, 'getDisclaimer') ? typology.getDisclaimer(category.value, isCardDetected.value) : null)
Expand Down Expand Up @@ -135,6 +125,12 @@ function sendFeedback (isCorrect: boolean) {
>
Arme d'alarme de type {{ label }}
</h2>
<h2
v-else-if="store.selectedOptions[0] === 'revolver_black_powder'"
class="fr-alert__title"
>
Revolver à poudre noire
</h2>
<h2
v-else
class="fr-alert__title"
Expand Down
13 changes: 10 additions & 3 deletions frontend/src/utils/firearms-utils/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { revolver, revolver_black_powder } from './revolver'
import { revolver } from './revolver'
import { pistolet_semi_auto_moderne } from './pistolet-semi-auto-moderne'
import { epaule_a_un_coup_par_canon } from './epaule-a-un-coup-par-canon'
import { epaule_a_verrou } from './epaule-a-verrou'
Expand All @@ -11,6 +11,8 @@ import { epaule_mecanisme_ancien } from './epaule_mecanisme_ancien'
import { pistolet_mecanisme_ancien } from './pistolet-mecanisme-ancien'
import { autre_pistolet } from './autre-pistolet'
import { arme_alarme } from './arme-alarme'
import { useStore } from '@/stores/result'
const store = useStore()

export const TYPOLOGIES = {
autre_pistolet,
Expand All @@ -24,7 +26,6 @@ export const TYPOLOGIES = {
pistolet_mecanisme_ancien,
pistolet_semi_auto_moderne,
revolver,
revolver_black_powder,
semi_auto_style_militaire_autre,
arme_alarme,
} as const
Expand Down Expand Up @@ -72,7 +73,13 @@ export const identificationRoutePathsWithArmeAlarme = [
'resultat-final',
] as const

export const ALARM_GUNS_TYPOLOGIES = ['pistolet_semi_auto_moderne', 'revolver']
export function isAlarmGun () {
if (store.selectedOptions[0] === 'revolver_black_powder' || !['pistolet_semi_auto_moderne', 'revolver'].includes(store.typology) || store.selectedAmmo === 'billes') {
return false
}
return store.selectedAlarmGun ? true : undefined
}

export const MEASURED_GUNS_TYPOLOGIES = [
'epaule_a_levier_sous_garde',
'epaule_a_pompe',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,16 @@ import pistoletSemiAutoTalonImg from '@/assets/guide-mise-en-securite/photos/pis
import pistoletSemiAutoTalonVideo from '@/assets/guide-mise-en-securite/videos/pistolet_semi_auto_moderne/pistolet_talon.mp4'
import pistoletSemiAutoModerneCartridges from '@/assets/guide-identification/photos/pistolet_semi_auto_moderne/pistolet_sa_moderne_chargeur_cartouche.jpg'
import pistoletSemiAutoModerneBalls from '@/assets/guide-identification/photos/pistolet_semi_auto_moderne/pistolet_sa_moderne_chargeur_bille.jpg'

import { isAlarmGun } from '@/utils/firearms-utils/index'
/*
Pistolets semi-auto modernes
Bouton pontet
Poussoir talon
*/
export const pistolet_semi_auto_moderne = {
displayLabel: 'Pistolet semi-automatique',
getCategory: () => 'B',
getCategory: () => isAlarmGun() ? 'D' : 'B',
pistolet_semi_auto_moderne_text_option: 'Sélectionner ce que vous voyez sur votre arme : <span class="font-bold">bouton à proximité du pontet du côté gauche de la poignée</span>, OU <span class="font-bold">bouton sur le talon</span> de la crosse.',
textOptions: '',
securingSteps: [
Expand Down
17 changes: 8 additions & 9 deletions frontend/src/utils/firearms-utils/revolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@ import revolver31892Img from '@/assets/guide-mise-en-securite/photos/revolver/re
import revolver31892Video from '@/assets/guide-mise-en-securite/videos/revolver/revolver_1892.mp4'
import revolverCartridges from '@/assets/guide-identification/photos/revolver/revolver_cartouche_pleine.jpg'
import revolverBalls from '@/assets/guide-identification/photos/revolver/revolver_cartouche_bille.jpg'

import { isAlarmGun } from '@/utils/firearms-utils/index'
import { useStore } from '@/stores/result'
const store = useStore()

/*
Revolvers
Revolver Enfield - Webley - brisure
Expand All @@ -30,8 +35,7 @@ Revolvers
*/
export const revolver = {
displayLabel: 'Revolver',
getCategory: () => 'B',
categoryWithoutSecuring: 'B ou D',
getCategory: () => isAlarmGun() || store.selectedOptions[0] === 'revolver_black_powder' ? 'D' : 'B ou D',
securingSteps: [
{
text: 'En maintenant l’arme dans une <span class="font-bold">direction sécurisée</span> , sélectionnez ce que vous voyez.',
Expand Down Expand Up @@ -175,14 +179,9 @@ export const revolver = {
img_ammo: revolverBalls,
},
],
getDisclaimer: (category: string) => {
if (category === 'D') {
getDisclaimer: () => {
if (isAlarmGun()) {
return 'Les <strong>armes d’alarmes</strong> sont susceptibles d’être <strong>modifiées pour tirer des munitions létales</strong>. Pour des raisons de sécurité, <strong>faites si possible expertiser l’arme.</strong>'
}
},
} as const

export const revolver_black_powder = {
displayLabel: 'Revolver à poudre noire',
getCategory: () => 'D',
} as const
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
identificationGuideSteps,
identificationGuideStepsWithArmeAlarme,
TYPOLOGIES,
ALARM_GUNS_TYPOLOGIES,
isAlarmGun,
} from '@/utils/firearms-utils/index'
import { useStore } from '@/stores/result'
Expand All @@ -22,7 +22,7 @@ const isLowConfidence = confidenceLevel.value === 'low'
const steps = computed(() => {
if (TYPOLOGIES[typology]?.dummyOptions || !isLowConfidence) {
if (ALARM_GUNS_TYPOLOGIES.includes(store.typology) && store.selectedAmmo === 'cartouches') {
if (isAlarmGun() !== false) {
return ['Typologie de l\'arme', 'Compléments', 'Typologie de munitions', 'Identification d\'une arme d\'alarme', 'Résultat final']
} else {
return ['Typologie de l\'arme', 'Compléments', 'Typologie de munitions', 'Résultat final']
Expand Down Expand Up @@ -80,7 +80,7 @@ const nextStepButtonAction = () => {
function handlePreviousButtonClick () {
currentStep.value--
if (ALARM_GUNS_TYPOLOGIES.includes(typology.value)) {
if (isAlarmGun() !== false) {
goToNewRouteWithArmeAlarme()
} else {
goToNewRoute()
Expand All @@ -95,7 +95,7 @@ const showDiv = ref(false)
<div class="mt-5 fr-container">
<div class="result fr-col-11 fr-col-lg-6 mx-auto">
<StepsGuide
v-if="TYPOLOGIES[typology]?.dummyOptions"
v-if="TYPOLOGIES[typology]?.dummyOptions && store.selectedOptions[0] !== 'revolver_black_powder'"
class="!fr-container my-auto"
:steps="steps"
:current-step="currentStep"
Expand All @@ -117,6 +117,7 @@ const showDiv = ref(false)
@click="$router.push({name: 'StartPage'})"
/>
<DsfrButton
v-if="store.selectedOptions[0] !== 'revolver_black_powder'"
class="mt-3 flex justify-center !w-full"
label="Retourner à l'étape précédente"
icon="ri-arrow-go-back-fill"
Expand All @@ -127,7 +128,7 @@ const showDiv = ref(false)
</div>
</div>
<div
v-else-if="ALARM_GUNS_TYPOLOGIES.includes(typology) && route.path === '/guide-identification/munition-type'"
v-else-if="isAlarmGun() !== false && route.path === '/guide-identification/munition-type'"
class="footer content z-1"
>
<div
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@ function goToMissingCardPageIfMissing () {
if (isCardDetected.value === false && MEASURED_GUNS_TYPOLOGIES.includes(typology.value)) {
return 'MissingCard'
}
return 'IdentificationTypologyResult'
return store.selectedOptions[0] !== 'revolver_black_powder' ? 'IdentificationTypologyResult' : 'IdentificationFinalResult'
}
</script>

<template>
<div class="fr-container">
<div class="result fr-col-11 fr-col-lg-6 m-auto">
<div v-if="TYPOLOGIES[typology]?.securingSteps">
<div v-if="TYPOLOGIES[typology]?.securingSteps && store.selectedOptions[0] !== 'revolver_black_powder'">
<h1 class="mt-5 text-center">
Fin de la mise en sécurité de l’arme
</h1>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
<script lang="ts" setup>
import { computed, ref } from 'vue'
import { useRouter } from 'vue-router'
import { useStore } from '@/stores/result'
import { TYPOLOGIES } from '@/utils/firearms-utils/index'
import AskingExpert from '@/components/AskingExpert.vue'
import SecuringFooter from './SecuringFooter.vue'
const router = useRouter()
const props = defineProps<{
step: 1 | 2 | 3
}>()
Expand All @@ -35,13 +32,6 @@ const zoomOn = (imgValue: string) => {
zoom.value = imgValue
}
function updateTypology () {
if (props.step === 1 && selectedOptionValue.value === 'revolver_black_powder') {
// Remember if it is a revolver with black powder
store.typology = selectedOptionValue.value
}
}
const nextTo = computed(() => {
if (typology.displayLabel === 'Revolver') {
if (props.step === 1) {
Expand Down Expand Up @@ -72,11 +62,6 @@ const nextTo = computed(() => {
}
})
function nextClick () {
updateTypology()
router.push(nextTo.value)
}
</script>

<template>
Expand Down Expand Up @@ -162,7 +147,7 @@ function nextClick () {
<SecuringFooter
:next-disabled="disabledValidation"
@back-click="$router.back()"
@next-click="nextClick"
@next-click="$router.push(nextTo)"
/>
</div>
</template>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ const typology = TYPOLOGIES[store.typology]
// Tutorial object from last selected option
const selectedOption = computed(() => {
if (typology.securingSteps[0].text) {
return typology.securingSteps.at(store.selectedOptions.length - 1).options.find((option) => option.value === store.selectedOptions.at(-1))
return typology.securingSteps[store.selectedOptions.length - 1].options.find((option) => option.value === store.selectedOptions.at(-1))
}
return typology.securingSteps[0].options[0]
})
Expand Down

0 comments on commit ed7e07b

Please sign in to comment.