Skip to content
This repository has been archived by the owner on Dec 26, 2022. It is now read-only.

feat: add max date for appointment #86

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
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
9 changes: 9 additions & 0 deletions browser_action/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,15 @@

<div class="panel-section-separator"></div>

<div class="panel-formElements-item">
<div>
<input type="date" name="dateMaxSearch" id="dateMax" />
<label for="dateMax">Date maximale de recherche (MM/JJ/YYYY)</label>
Copy link
Collaborator

Choose a reason for hiding this comment

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

Ici l'intégration du i18n manque

Suggested change
<label for="dateMax">Date maximale de recherche (MM/JJ/YYYY)</label>
<label for="dateMax" data-i18n="dateMaxLabel>Date maximale de recherche (MM/JJ/YYYY)</label>

dateMaxLabel doit ensuite être défini dans _locales/*/messages.json.

Je suggère comme traduction allemande:

"maxDateLabel": {
    "message": "Termin finden bis zum (DD. MM. YYYY)",
    "description": "Bis zu diesem Datum wird nach einem Termin gesucht"
  },

Copy link
Author

Choose a reason for hiding this comment

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

Rajouté ! Merci pour la trad :)

</div>
</div>

<div class="panel-section-separator"></div>

<div class="panel-formElements-item">
<div>
<input type="radio" name="autoBook" id="disableAutoBook" checked />
Expand Down
10 changes: 10 additions & 0 deletions browser_action/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,12 @@
document.getElementById(injectionVaccine).checked = true;
}

/** @param {Date} dateMaxSearch La date maximale de recherche de rdv */
function displayDateMaxSearch(dateMaxSearch) {
const date = new Date(dateMaxSearch);
document.getElementById('dateMax').value = date.toISOString().split('T')[0]
}

// Preparation des données
const appStatus = new AppStatus();
const vCLStorage = new VCLocalStorage({
Expand All @@ -118,6 +124,7 @@
appStatus.onAutoBookChange(displayAutoBook);
appStatus.onInjectionTypeChange(displayInjectionType);
appStatus.onInjectionVaccineChange(displayInjectionVaccine);
appStatus.onDateMaxSearchChange(displayDateMaxSearch);

// Initialisation donnée
appStatus.init();
Expand Down Expand Up @@ -150,6 +157,8 @@
appStatus.setInjectionVaccine.bind(appStatus, "modernaInjection");
document.getElementById("pfizerInjection").onclick =
appStatus.setInjectionVaccine.bind(appStatus, "pfizerInjection");
document.getElementById("dateMax").onblur =
appStatus.setDateMaxSearch.bind(appStatus, document.getElementById('dateMax'));

document.getElementById("reset").onclick = () => {
if (
Expand All @@ -169,5 +178,6 @@
displayAutoBook(appStatus.getAutoBook());
displayInjectionType(appStatus.getInjectionType());
displayInjectionVaccine(appStatus.getInjectionVaccine());
displayDateMaxSearch(appStatus.getDateMaxSearch());
displayLocations();
})();
36 changes: 36 additions & 0 deletions commons/AppStatus.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ class AppStatus {
this.injectionType = "fullServiceInjection";
/** @type {'modernaInjection' | 'pfizerInjection'} vaccin d'injection souhaité par le user */
this.injectionVaccine = "pfizerInjection";
/** @type {Date} Date max de recherche de rdv (par défaut aujd + 1 mois) */
this.dateMaxSearch = new Date((new Date()).getFullYear()+1, (new Date()).getMonth(), (new Date()).getDate());
/** @type {(string) => void} callback quand une {@link VaccineLocation} a été ajouté */
this.onLocationAddedCb = (job) => {};
/** @type {(string) => void} callback quand une {@link VaccineLocation} a été supprimée */
Expand All @@ -34,6 +36,8 @@ class AppStatus {
this.onInjectionTypeCb = (newValue) => {};
/** @type {'modernaInjection' | 'pfizerInjection'} callback quand injectionVaccine change de valeur */
this.onInjectionVaccineCb = (newValue) => {};
/** @type {Date} callback quand maxDateSearch change de valeur */
this.onDateMaxSearchCb = (newValue) => {};

this.onStorageChange = this.onStorageChange.bind(this);
browser.storage.onChanged.addListener(this.onStorageChange);
Expand All @@ -49,6 +53,7 @@ class AppStatus {
autoBook: false,
injectionType: "fullServiceInjection",
injectionVaccine: "pfizerInjection",
dateMaxSearch: new Date((new Date()).getFullYear()+1, (new Date()).getMonth(), (new Date()).getDate()),
});

Object.keys(result.locations).forEach((url) => {
Expand All @@ -67,6 +72,9 @@ class AppStatus {

this.injectionVaccine = result.injectionVaccine;
this.onInjectionVaccineCb(this.injectionVaccine);

this.dateMaxSearch = result.dateMaxSearch;
this.onDateMaxSearchCb(this.dateMaxSearch);
}

getLocations() {
Expand Down Expand Up @@ -105,6 +113,10 @@ class AppStatus {
return this.injectionVaccine;
}

getDateMaxSearch() {
return this.dateMaxSearch;
}

/**
* @param {(string) => void} cbAdd callback quand une {@link VaccineLocation} a été ajouté
* @param {(string) => void} cbDelete callback quand une {@link VaccineLocation} a été supprimée
Expand Down Expand Up @@ -142,6 +154,13 @@ class AppStatus {
this.onInjectionVaccineCb = callback;
}

/**
* @param {(Date) => void} callback quand dateMaxSearch change de valeur
*/
onDateMaxSearchChange(callback) {
this.onDateMaxSearchCb = callback;
}

start() {
this.stopped = false;
browser.storage.sync.set({ stopped: this.stopped });
Expand All @@ -168,6 +187,15 @@ class AppStatus {
browser.storage.sync.set({ injectionType: this.injectionType });
}


/**
* @param {Date} value The new dateMaxSearch value
*/
setDateMaxSearch(value) {
this.dateMaxSearch = new Date(value.value);
browser.storage.sync.set({ dateMaxSearch: this.dateMaxSearch });
}

/**
* @param {'modernaInjection' | 'pfizerInjection'} value The new injectionVaccine value
*/
Expand All @@ -193,6 +221,8 @@ class AppStatus {
this.onInjectionTypeCb(this.injectionType);
this.injectionVaccine = "pfizerInjection";
this.onInjectionTypeCb(this.injectionVaccine);
this.dateMaxSearch = new Date((new Date()).getFullYear(), (new Date()).getMonth()+1, (new Date()).getDate());
Copy link
Collaborator

Choose a reason for hiding this comment

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

Ici on rajoute encore +1 au mois au lieu de l'ajouter à l'année.

this.onDateMaxSearchCb(this.dateMaxSearch);
}

/**
Expand All @@ -209,6 +239,7 @@ class AppStatus {
this.onAutoBookChangeCb = null;
this.onInjectionTypeCb = null;
this.onInjectionVaccineCb = null;
this.onDateMaxSearchCb = null;
}

/**
Expand Down Expand Up @@ -262,5 +293,10 @@ class AppStatus {

this.onInjectionVaccineCb(this.injectionVaccine);
}
if (change.dateMaxSearch) {
this.dateMaxSearch = change.dateMaxSearch.newValue;

this.onDateMaxSearchCb(this.dateMaxSearch);
}
}
}
35 changes: 25 additions & 10 deletions content_scripts/doctolib/book.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,20 @@
if (currentMonth > selectedMonth) return new Date().getFullYear() + 1;
return new Date().getFullYear();
}
const MONTHS = {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Ce code n'est plus utilisé il me semble :)

'janv.': 1,
'févr.': 2,
'mars': 3,
'avr.': 4,
'mai': 5,
'juin': 6,
'juil.': 7,
'aout': 8,
'sept.': 9,
'oct.': 10,
'nov.': 11,
'déc.': 12,
};

async function waitTimeout(timeout) {
await new Promise((r) => setTimeout(r, timeout));
Expand Down Expand Up @@ -295,15 +309,18 @@

let running = false;
async function checkAvailability() {
const { locations, stopped, autoBook, injectionType, injectionVaccine } =
const { locations, stopped, autoBook, injectionType, injectionVaccine, dateMaxSearch } =
await browser.storage.sync.get({
locations: {},
stopped: false,
autoBook: false,
injectionType: "fullServiceInjection",
injectionVaccine: "pfizerInjection",
dateMaxSearch: new Date((new Date()).getFullYear()+1, (new Date()).getMonth(), (new Date()).getDate()),
});

const dateMaxSearchDate = typeof(dateMaxSearch) === 'string' ? new Date(dateMaxSearch) : dateMaxSearch;

if (stopped || !locations[url]) {
running = false;
return;
Expand Down Expand Up @@ -421,6 +438,8 @@
const parts = slot.title.match(
/([0-9]+)\.? ([\p{Letter}]+)\.? ([0-9]+:[0-9]+)/u
);
// /([0-9]+) [\p{Letter}]+\.? ([0-9]+:[0-9]+)/gu
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 t'il une raison pour laisser ce code commenté dans le source ou c'est juste un petit oubli? :)

Copy link
Author

Choose a reason for hiding this comment

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

Juste un oubli :)

// )[0].split(' ');
if (!parts) {
throw new Error(
browser.i18n.getMessage("slotDateFormatNotFound", slot.title)
Expand All @@ -434,18 +453,14 @@
const selectedTime = parts[3];

const date = new Date(
`${selectedMonth} ${selectedDay} ${selectedYear} ${selectedTime}`
);
`${selectedMonth} ${selectedDay} ${selectedYear} ${selectedTime}`);

const tomorrow = new Date();
tomorrow.setHours(23);
tomorrow.setMinutes(59);
tomorrow.setDate(tomorrow.getDate() + 1);

if (date > tomorrow && date < new Date("2021-05-31T00:20:00"))
if (date > dateMaxSearchDate) {
const formatedDate = dateMaxSearchDate.toLocaleDateString();
throw new Error(
"Pas de créneau dispo d'ici demain soir ou après le 31 mai"
`Pas de créneau dispo d'ici demain soir ou avant le ${formatedDate}`
);
}

if (!autoBook) {
browser.runtime.sendMessage({
Expand Down