Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ajout de la fonctionnalité permettant de choisir le type de vaccin #143

Open
wants to merge 23 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 8 commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
1198727
Ajout possibilité de choisir le type de vaccin
mccob May 2, 2021
c08569a
Correction bug et commentaire
mccob May 2, 2021
bde62ec
Update README.md
mccob May 2, 2021
7bb403a
Correction pour que le bouton de type de vaccin soit bien sélectioné …
mccob May 2, 2021
053631e
Merge branch 'dev' of github.com:mccob/vitemadose-front into dev
mccob May 2, 2021
1f3997a
modif README
mccob May 2, 2021
60c6051
Nombreuses corrections de bug et d'identation. Merci @hawksttf
mccob May 2, 2021
2dd2e8c
Ajout de la fonctionnalité de choix du type de vaccin sur la recherch…
mccob May 2, 2021
f22280c
Suite aux remarques sur la PR : Simplification des libellés du sélect…
mccob May 2, 2021
4e84f80
Correction
mccob May 2, 2021
e530d61
Modification pour prise en compte du libellé du Janssen retourné par …
mccob May 2, 2021
669e3f1
Update src/views/vmd-rdv.view.ts
mccob May 3, 2021
16e6076
Prises en compte des remarques de @bilelz https://github.com/CovidTra…
mccob May 3, 2021
d692a01
Prises en compte des remarques de @bilelz https://github.com/CovidTra…
mccob May 3, 2021
ebe7ada
Prises en compte des remarques de @bilelz https://github.com/CovidTra…
mccob May 3, 2021
57f5b02
fix compilation errors in State.ts
fcamblor May 3, 2021
fe2e3de
Prises en compte des remarques de @fcamblor. Correction afin que cela…
mccob May 3, 2021
6609d34
Prises en compte des remarques de @fcamblor. Correction afin que cela…
mccob May 3, 2021
dcf84f1
Prises en compte des remarques de @fcamblor. Correction afin que cela…
mccob May 3, 2021
50527d7
Prises en compte des remarques de @fcamblor. Correction afin que cela…
mccob May 3, 2021
1c4441a
Prise en compte de la remarque de @fcamblor sur la compatibilité back…
mccob May 3, 2021
55dadef
Correction bug suite precedent commit
mccob May 3, 2021
77ad7b0
Correction version mobile
mccob May 7, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 10 additions & 9 deletions src/routing/Router.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import page from "page";
import { TemplateResult } from "lit-html";
import {html} from "lit-element";
import {CodeTriCentre, State} from "../state/State";
import {CodeTriCentre, State, CodeTypeVaccin} from "../state/State";
import {Analytics} from "../utils/Analytics";

export type SlottedTemplateResultFactory = (subViewSlot: TemplateResult) => TemplateResult;
Expand Down Expand Up @@ -50,22 +50,23 @@ class Routing {
`/centres-vaccination-covid-dpt:codeDpt-:nomDpt/age-:trancheAge/`,
`/centres-vaccination-covid-dpt:codeDpt-:nomDpt/ville-:codeVille-:nomVille/age-:trancheAge/`,
// Proper URL really used
`/centres-vaccination-covid-dpt:codeDpt-:nomDpt`
`/centres-vaccination-covid-dpt:codeDpt-:nomDpt/type-vaccin-:typeVaccin`,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pas fan de l'URL. Je pense que juste ARNm ou Adenovaccin serait plus clair

], analyticsViewName: 'search_results_by_department',
viewContent: (params) => (subViewSlot) =>
html`<vmd-rdv-par-departement codeDepartementSelectionne="${params[`codeDpt`]}">${subViewSlot}</vmd-rdv-par-departement>`,
html`<vmd-rdv-par-departement codeDepartementSelectionne="${params[`codeDpt`]}" typeVaccin="${params[`typeVaccin`]}">${subViewSlot}</vmd-rdv-par-departement>`,
pageTitleProvider: (params) =>
State.current.chercheDepartementParCode(params[`codeDpt`])
.then(nomDpt => `Vaccination COVID-19 en ${nomDpt.nom_departement} ${params[`codeDpt`]}`)
});
this.declareRoutes({
pathPattern: `/centres-vaccination-covid-dpt:codeDpt-:nomDpt/commune:codeCommune-:codePostal-:nomCommune/en-triant-par-:codeTriCentre`,
pathPattern: `/centres-vaccination-covid-dpt:codeDpt-:nomDpt/commune:codeCommune-:codePostal-:nomCommune/en-triant-par-:codeTriCentre/type-vaccin-:typeVaccin`,
analyticsViewName: 'search_results_by_city',
viewContent: (params) => (subViewSlot) =>
html`<vmd-rdv-par-commune
codeCommuneSelectionne="${params[`codeCommune`]}"
codePostalSelectionne="${params[`codePostal`]}"
critèreDeTri="${params[`codeTriCentre`]}">
critèreDeTri="${params[`codeTriCentre`]}"
typeVaccin="${params[`typeVaccin`]}">
${subViewSlot}
</vmd-rdv-par-commune>`,
pageTitleProvider: (params) =>
Expand Down Expand Up @@ -133,12 +134,12 @@ class Routing {
this.navigateToHome();
}

public navigateToRendezVousAvecDepartement(codeDepartement: string, pathLibelleDepartement: string) {
page(`${this.basePath}centres-vaccination-covid-dpt${codeDepartement}-${pathLibelleDepartement}`);
public navigateToRendezVousAvecDepartement(codeDepartement: string, pathLibelleDepartement: string,typeVaccin: CodeTypeVaccin) {
page(`${this.basePath}centres-vaccination-covid-dpt${codeDepartement}-${pathLibelleDepartement}/type-vaccin-${typeVaccin}`);
}

public navigateToRendezVousAvecCommune(codeTriCentre: CodeTriCentre, codeDepartement: string, pathLibelleDepartement: string, codeCommune: string, codePostal: string, pathLibelleCommune: string) {
page(`${this.basePath}centres-vaccination-covid-dpt${codeDepartement}-${pathLibelleDepartement}/commune${codeCommune}-${codePostal}-${pathLibelleCommune}/en-triant-par-${codeTriCentre}`);
public navigateToRendezVousAvecCommune(codeTriCentre: CodeTriCentre, codeDepartement: string, pathLibelleDepartement: string, codeCommune: string, codePostal: string, pathLibelleCommune: string,typeVaccin: CodeTypeVaccin) {
page(`${this.basePath}centres-vaccination-covid-dpt${codeDepartement}-${pathLibelleDepartement}/commune${codeCommune}-${codePostal}-${pathLibelleCommune}/en-triant-par-${codeTriCentre}/type-vaccin-${typeVaccin}`);
}

navigateToHome() {
Expand Down
16 changes: 16 additions & 0 deletions src/state/State.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,22 @@ export const TRIS_CENTRE: Map<CodeTriCentre, TriCentre> = new Map([
['date', { codeTriCentre: 'date', libelle: "Disponible au plus vite" }],
]);

export type CodeTypeVaccin = 'all' | 'arnm' | 'adenovirus';
export const FILTRE_TYPE_VACCIN: Map<CodeTypeVaccin> = new Map([
['all', {codeTypeVaccin: 'all', libelle: "Tous" }],
['arnm', {codeTypeVaccin: 'arnm', libelle: "ARN messager" }],
['adenovirus', {codeTypeVaccin: 'adenovirus', libelle: "à base d'adénovirus" }],
]);


export type TypeVaccin = 'AstraZeneca'|'Pfizer-BioNTech'|'Moderna'|'Johnson';
export const TYPES_VACCIN: {[k in TypeVaccin]: string} = {
"AstraZeneca": 'adenovirus',
"Pfizer-BioNTech": 'arnm',
"Moderna": 'arnm',
"Johnson": 'adenovirus',
};

const USE_RAW_GITHUB = false
const VMD_BASE_URL = USE_RAW_GITHUB
? "https://raw.githubusercontent.com/CovidTrackerFr/vitemadose/data-auto/data/output"
Expand Down
7 changes: 7 additions & 0 deletions src/utils/Analytics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,4 +81,11 @@ export class Analytics {
});
}

critereTypeVaccinMisAJour(typeVaccin: CodeTypeVaccin) {
window.dataLayer.push({
'event': 'type_change',
'type_changed_to' : typeVaccin,
});
}

}
5 changes: 3 additions & 2 deletions src/views/vmd-home.view.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ export class VmdHomeView extends LitElement {

rechercherRdv() {
if(this.departementSelectione) {
Router.navigateToRendezVousAvecDepartement(this.departementSelectione.code_departement, libelleUrlPathDuDepartement(this.departementSelectione));
Router.navigateToRendezVousAvecDepartement(this.departementSelectione.code_departement, libelleUrlPathDuDepartement(this.departementSelectione),'all');
return;
}

Expand All @@ -57,7 +57,8 @@ export class VmdHomeView extends LitElement {
departement.code_departement,
libelleUrlPathDuDepartement(departement),
this.communeSelectionee!.code, this.communeSelectionee!.codePostal,
libelleUrlPathDeCommune(this.communeSelectionee!)
libelleUrlPathDeCommune(this.communeSelectionee!),
'all'
)
}

Expand Down
83 changes: 77 additions & 6 deletions src/views/vmd-rdv.view.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,10 @@ import {
Lieu, LieuAffichableAvecDistance, LieuxAvecDistanceParDepartement,
LieuxParDepartement,
State, TriCentre,
TRIS_CENTRE
TRIS_CENTRE,
CodeTypeVaccin,
FILTRE_TYPE_VACCIN,
TYPES_VACCIN,
} from "../state/State";
import {Dates} from "../utils/Dates";
import {Strings} from "../utils/Strings";
Expand Down Expand Up @@ -125,7 +128,8 @@ export abstract class AbstractVmdRdvView extends LitElement {
libelleUrlPathDuDepartement(departement!),
commune.code,
commune.codePostal,
libelleUrlPathDeCommune(commune)
libelleUrlPathDeCommune(commune),
'all'
);
return;
}
Expand All @@ -144,7 +148,7 @@ export abstract class AbstractVmdRdvView extends LitElement {

async departementSelected(departement: Departement, triggerNavigation: boolean): Promise<void> {
if(this.communeSelectionnee) {
Router.navigateToRendezVousAvecDepartement(departement.code_departement, libelleUrlPathDuDepartement(departement));
Router.navigateToRendezVousAvecDepartement(departement.code_departement, libelleUrlPathDuDepartement(departement),this.typeVaccin);
return;
}

Expand Down Expand Up @@ -184,6 +188,18 @@ export abstract class AbstractVmdRdvView extends LitElement {
</vmd-commune-or-departement-selector>
</div>
</div>
<div class="rdvForm-fields row align-items-center">
<label class="col-sm-24 col-md-auto mb-md-3">
Je recherche un vaccin de type :
</label>
<div class="col">
<vmd-button-switch class="mb-3"
codeSelectionne="${this.typeVaccin}"
.options="${Array.from(FILTRE_TYPE_VACCIN.values()).map(tc => ({code: tc.codeTypeVaccin, libelle: tc.libelle }))}"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On avait déjà parlé de ARNm et adenovirus avant, ça serait peut être bien de mettre (AZ/Janseen) et (Pfizer/Moderna) pour que ça soit plus clair

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Il y a un sujet sur la taille des libéllés
image

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oui on en avait parlé sur le chat. Il faut que je corrige mais cela va aussi dépendre de où va le filtre au final.

@changed="${(event: ValueStrCustomEvent<CodeTypeVaccin>) => this.critereVaccinUpdated(event.detail.value)}">
</vmd-button-switch>
</div>
</div>
${this.renderAdditionnalSearchCriteria()}
</div>

Expand Down Expand Up @@ -352,7 +368,7 @@ export abstract class AbstractVmdRdvView extends LitElement {
}

if (this.codeDepartementSelectionne) {
Router.navigateToRendezVousAvecDepartement(this.codeDepartementSelectionne, libelleUrlPathDuDepartement(this.departementSelectionne!));
Router.navigateToRendezVousAvecDepartement(this.codeDepartementSelectionne, libelleUrlPathDuDepartement(this.departementSelectionne!),this.typeVaccin);
}
}

Expand Down Expand Up @@ -404,6 +420,40 @@ export abstract class AbstractVmdRdvView extends LitElement {
throw new Error(`Unsupported tri : ${tri}`);
}
}

protected filterTypeVaccin(vaccine_type: Array, typeVaccin: CodeTypeVaccin) {
Copy link
Collaborator

@bilelz bilelz May 3, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Le typage de vaccine_type est vraiment Array?
Plus bas, c'est traité comme un string : vaccine_type.split(',')

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

en effet, je modifie

if(typeVaccin === 'all') {
return true;
} else {
let result = false;

if(vaccine_type && vaccine_type.length)
{
if(vaccine_type.indexOf(',')!==-1)
{
let arrayVaccinne = vaccine_type.split(',');
mccob marked this conversation as resolved.
Show resolved Hide resolved

arrayVaccinne.forEach(function(item){
if(TYPES_VACCIN[item.trim()]==typeVaccin)
{
result = true;
}
});
}else{
if(TYPES_VACCIN[vaccine_type.trim()]==typeVaccin)
{
result = true;
}
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
}else{
if(TYPES_VACCIN[vaccine_type.trim()]==typeVaccin)
{
result = true;
}
}
}else if(TYPES_VACCIN[vaccine_type.trim()]==typeVaccin) {
result = true;
}

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

il ya un problème avec la touche espace ? ^^

return result;
}else{
// Not hidding vaccine center of vaccine type is unknown
result = true;
}

return result;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hello,
Le code n'est pas immutable à cause de cette variable result. Je pense que tu peux t'en passer.
Et faire directement directement un return true ou return false au lieu de mettre à jour la variable.

Copy link
Author

@mccob mccob May 3, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Le problème est qu'elle est nécessaire au moins pour la boucle forEach : la valeur finale du result est nécessaire dans ce cadre.

Copy link
Collaborator

@fcamblor fcamblor May 3, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

J'ai l'impression que tout ça peut se simplifier en :

    protected filterTypeVaccin(vaccine_type: String, typeVaccin: CodeTypeVaccin) {
        if(typeVaccin === 'tous') {
            return true;
        } else {
            if(!vaccine_type || !vaccine_type.length) {
                return false;
            }
            return vaccine_type.split(",")
                .map((typeStr) => TYPES_VACCIN[typeStr.trim() as TypeVaccin])
                .indexOf(typeVaccin) !== -1;
        }
    }

non ?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

La méthode Array.prototype.some() peut faire le job aussi
https://developer.mozilla.org/fr/docs/Web/JavaScript/Reference/Global_Objects/Array/some

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Merci

}
}

abstract libelleLieuSelectionne(): TemplateResult;
abstract afficherLieuxParDepartement(lieuxParDepartement: LieuxParDepartement): LieuxAvecDistanceParDepartement;
Expand All @@ -414,7 +464,8 @@ export class VmdRdvParCommuneView extends AbstractVmdRdvView {
@property({type: String}) codeCommuneSelectionne: string | undefined = undefined;
@property({type: String}) codePostalSelectionne: string | undefined = undefined;

@property({type: String}) critèreDeTri: 'date' | 'distance' = 'distance'
@property({type: String}) critèreDeTri: 'date' | 'distance' = 'distance';
@property({type: String}) typeVaccin: 'all' | 'arnm' | 'adenovirus' = 'all';

preventRafraichissementLieux() {
return !this.communeSelectionnee;
Expand All @@ -436,7 +487,7 @@ export class VmdRdvParCommuneView extends AbstractVmdRdvView {
_onRefreshPageWhenValidParams() {
// To be overriden
if(this.departementSelectionne && this.communeSelectionnee && this.codePostalSelectionne) {
Router.navigateToRendezVousAvecCommune(this.critèreDeTri, this.departementSelectionne.code_departement, libelleUrlPathDuDepartement(this.departementSelectionne), this.communeSelectionnee.code, this.communeSelectionnee.codePostal, libelleUrlPathDeCommune(this.communeSelectionnee));
Router.navigateToRendezVousAvecCommune(this.critèreDeTri, this.departementSelectionne.code_departement, libelleUrlPathDuDepartement(this.departementSelectionne), this.communeSelectionnee.code, this.communeSelectionnee.codePostal, libelleUrlPathDeCommune(this.communeSelectionnee),this.typeVaccin);
return 'return';
}

Expand Down Expand Up @@ -525,6 +576,7 @@ export class VmdRdvParCommuneView extends AbstractVmdRdvView {
.concat([...lieuxIndisponibles].map(l => ({...l, disponible: false})))
.map(l => ({...l, distance: distanceAvec(l) }))
.filter(l => !l.distance || l.distance < MAX_DISTANCE_CENTRE_IN_KM)
.filter(l => this.filterTypeVaccin(l.vaccine_type,this.typeVaccin))
.sortBy(l => this.extraireFormuleDeTri(l, this.critèreDeTri))
.build()
};
Expand All @@ -538,6 +590,14 @@ export class VmdRdvParCommuneView extends AbstractVmdRdvView {
this.refreshPageWhenValidParams();
}

critereVaccinUpdated(typeVaccin: CodeTypeVaccin) {
this.typeVaccin = typeVaccin;

Analytics.INSTANCE.critereTypeVaccinMisAJour(typeVaccin);

this.refreshPageWhenValidParams();
}

renderAdditionnalSearchCriteria(): TemplateResult {
return html`
<div class="rdvForm-fields row align-items-center">
Expand All @@ -559,6 +619,8 @@ export class VmdRdvParCommuneView extends AbstractVmdRdvView {
@customElement('vmd-rdv-par-departement')
export class VmdRdvParDepartementView extends AbstractVmdRdvView {

@property({type: String}) typeVaccin: 'all' | 'arnm' | 'adenovirus' = 'all';

async onceStartupPromiseResolved() {
if(this.codeDepartementSelectionne) {
const departementSelectionne = this.departementsDisponibles.find(d => d.code_departement === this.codeDepartementSelectionne);
Expand Down Expand Up @@ -590,8 +652,17 @@ export class VmdRdvParDepartementView extends AbstractVmdRdvView {
lieuxAffichables: ArrayBuilder.from([...lieuxDisponibles].map(l => ({...l, disponible: true})))
.concat([...lieuxIndisponibles].map(l => ({...l, disponible: false})))
.map(l => ({...l, distance: undefined }))
.filter(l => this.filterTypeVaccin(l.vaccine_type,this.typeVaccin))
.sortBy(l => this.extraireFormuleDeTri(l, 'date'))
.build()
};
}

critereVaccinUpdated(typeVaccin: CodeTypeVaccin) {
this.typeVaccin = typeVaccin;

Analytics.INSTANCE.critereTypeVaccinMisAJour(typeVaccin);

this.refreshPageWhenValidParams();
}
}