From c6b125080c902c33b51610270421a381464fd671 Mon Sep 17 00:00:00 2001 From: pymuzard Date: Sun, 8 Sep 2024 15:19:53 +0200 Subject: [PATCH 01/13] =?UTF-8?q?ajout=20m=C3=A9thode=20getString?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/lua/src/lua_file.cpp | 1 + lib/lua/src/lua_json.cpp | 5 +++++ lib/lua/src/lua_json.hpp | 1 + 3 files changed, 7 insertions(+) diff --git a/lib/lua/src/lua_file.cpp b/lib/lua/src/lua_file.cpp index 60fb065d..ad1466a6 100755 --- a/lib/lua/src/lua_file.cpp +++ b/lib/lua/src/lua_file.cpp @@ -372,6 +372,7 @@ void LuaFile::load() "get_int", &LuaJson::get_int, "get_double", &LuaJson::get_double, "get_bool", &LuaJson::get_bool, + "get_string", &LuaJson::get_string, "set_int", &LuaJson::set_int, "set_double", &LuaJson::set_double, "set_bool", &LuaJson::set_bool, diff --git a/lib/lua/src/lua_json.cpp b/lib/lua/src/lua_json.cpp index e5452619..210c09ab 100644 --- a/lib/lua/src/lua_json.cpp +++ b/lib/lua/src/lua_json.cpp @@ -66,6 +66,11 @@ bool LuaJson::get_bool(std::string key) return json[key].get(); } +std::string LuaJson::get_string(std::string key) +{ + return json[key].get(); +} + void LuaJson::set_int(std::string key, int value) { json[key] = value; diff --git a/lib/lua/src/lua_json.hpp b/lib/lua/src/lua_json.hpp index e77b9448..9cee015e 100644 --- a/lib/lua/src/lua_json.hpp +++ b/lib/lua/src/lua_json.hpp @@ -22,6 +22,7 @@ class LuaJson int get_int(std::string key); double get_double(std::string key); bool get_bool(std::string key); + std::string get_string(std::string key); void set_int(std::string key, int value); void set_double(std::string key, double value); From 967a199daa95034007bd319933bdcc44f039d9ab Mon Sep 17 00:00:00 2001 From: pymuzard Date: Sun, 8 Sep 2024 15:28:23 +0200 Subject: [PATCH 02/13] =?UTF-8?q?ajout=20m=C3=A9thode=20getWindow?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/lua/src/lua_file.cpp | 1 + lib/lua/src/lua_gui.cpp | 5 + lib/lua/src/lua_gui.hpp | 1 + storage/apps/calendrier/app.lua | 2007 +++++++++++++++++++++ storage/apps/calendrier/back.png | Bin 0 -> 305 bytes storage/apps/calendrier/config.json | 1 + storage/apps/calendrier/day.png | Bin 0 -> 1442 bytes storage/apps/calendrier/fleche_droite.png | Bin 0 -> 1540 bytes storage/apps/calendrier/fleche_gauche.png | Bin 0 -> 1137 bytes storage/apps/calendrier/gestionDate.lua | 117 ++ storage/apps/calendrier/icon.png | Bin 0 -> 4084 bytes storage/apps/calendrier/manifest.json | 4 + storage/apps/calendrier/menu.png | Bin 0 -> 1119 bytes storage/apps/calendrier/month.png | Bin 0 -> 1594 bytes storage/apps/calendrier/parameter.png | Bin 0 -> 1484 bytes storage/apps/calendrier/plus.png | Bin 0 -> 180 bytes storage/apps/calendrier/today.png | Bin 0 -> 1557 bytes storage/apps/calendrier/week.png | Bin 0 -> 1433 bytes storage/system/auth.list | 3 +- storage/system/calendrier.json | 3 + 20 files changed, 2141 insertions(+), 1 deletion(-) create mode 100644 storage/apps/calendrier/app.lua create mode 100644 storage/apps/calendrier/back.png create mode 100644 storage/apps/calendrier/config.json create mode 100644 storage/apps/calendrier/day.png create mode 100644 storage/apps/calendrier/fleche_droite.png create mode 100644 storage/apps/calendrier/fleche_gauche.png create mode 100644 storage/apps/calendrier/gestionDate.lua create mode 100644 storage/apps/calendrier/icon.png create mode 100644 storage/apps/calendrier/manifest.json create mode 100644 storage/apps/calendrier/menu.png create mode 100644 storage/apps/calendrier/month.png create mode 100644 storage/apps/calendrier/parameter.png create mode 100644 storage/apps/calendrier/plus.png create mode 100644 storage/apps/calendrier/today.png create mode 100644 storage/apps/calendrier/week.png create mode 100644 storage/system/calendrier.json diff --git a/lib/lua/src/lua_file.cpp b/lib/lua/src/lua_file.cpp index ad1466a6..0d874b83 100755 --- a/lib/lua/src/lua_file.cpp +++ b/lib/lua/src/lua_file.cpp @@ -417,6 +417,7 @@ void LuaFile::load() "checkbox", &LuaGui::checkbox, "del", &LuaGui::del, "setWindow", &LuaGui::setMainWindow, + "getWindow", &LuaGui::getMainWindow, "keyboard", &LuaGui::keyboard, "showInfoMessage", &LuaGui::showInfoMessage, "showWarningMessage", &LuaGui::showWarningMessage, diff --git a/lib/lua/src/lua_gui.cpp b/lib/lua/src/lua_gui.cpp index a72ef80b..bfe6d6ee 100644 --- a/lib/lua/src/lua_gui.cpp +++ b/lib/lua/src/lua_gui.cpp @@ -181,6 +181,11 @@ void LuaGui::setMainWindow(LuaWindow* window) { AppManager::askGui(this->lua); } + +LuaWindow* LuaGui::getMainWindow() { + return this->mainWindow; +} + void LuaGui::showErrorMessage(const std::string& msg ){ GuiManager &guiManager = GuiManager::getInstance(); diff --git a/lib/lua/src/lua_gui.hpp b/lib/lua/src/lua_gui.hpp index a913acf2..db371ee2 100644 --- a/lib/lua/src/lua_gui.hpp +++ b/lib/lua/src/lua_gui.hpp @@ -41,6 +41,7 @@ class LuaGui void update(); void setMainWindow(LuaWindow* window); + LuaWindow* getMainWindow(); void showInfoMessage(const std::string& msg ); void showWarningMessage(const std::string& msg ); void showErrorMessage(const std::string& msg ); diff --git a/storage/apps/calendrier/app.lua b/storage/apps/calendrier/app.lua new file mode 100644 index 00000000..c75d171f --- /dev/null +++ b/storage/apps/calendrier/app.lua @@ -0,0 +1,2007 @@ + + +local boxImgDay, boxImgWeek, boxImgMonth, boxImgParametre, boxImgAdd +local menu +local currentMode +local winDay, winNewEvent + + +-- variable newEvent +local vListeDateNewEvent +local selectedDateHeure = {} + +local monthsName = {"Janvier", "Fevrier", "Mars", "Avril", "Mai", "Juin", "Juillet", "Août", "Septembre", "Octobre", "Novembre", "Decembre"} +local monthsShortName = {"Jan", "Fev", "Mars", "Avr", "Mai", "Juin", "Juil", "Août", "Sep", "Oct", "Nov", "Dec"} + +local daysOfWeek = { "Lundi", "Mardi", "Mercredi", "Jeudi", "Vendredi", "Samedi", "Dimanche" } +local daysOfWeekShort = { "lun", "mar", "mer", "jeu", "ven", "sam", "dim" } + +local affichageTop = 60 + + +-- Parametrage du calendrier +local config = {} + +-- liste d'event du calendrier +local PATH_DATA = "/data" +local data = {} + + +-- --------------------------------------- +-- FONCTIONS DU CALENDRIER +-- --------------------------------------- + +-- Lancement de l'appication +function run() + + -- récupération de la date courante + local today = getToday() + year = today[1] + month = today[2] + day = today[3] + + -- chargement de la config de l'application + loadConfig() + + -- lancement de la vue par défaut de l'application + if (config.defaultView == "day") then + displayDay (year, month, day) + elseif config.defaultView == "week" then + displayWeek(year, month, day) + else + displayMonth(year, month) + end + +end -- run + + + +-- chargement du fichier de configuration de l'application +function loadConfig() + + -- A remplacer par une lecture du fichier JSON + -- Gererles erreurs Json et les valeurs par défaut + local strFilename ="config.json" + local fileConfig = storage:file (strFilename, READ) + local configStr + + if fileConfig and storage:isFile(strFilename) then + fileConfig:open() + configStr = fileConfig:readAll() + fileConfig:close() + fileConfig = nil + else + configStr = '{"defaultView":"day","displayBusinessWeek":false,"displayWeekNum":false,"day":{"heureDebut":8, "heureFin":17}}' + end + local json_obj = Json:new(configStr) + + if json_obj:has_key("defaultView") then + config.defaultView = json_obj:get_string("defaultView") + else + config.defaultView = "day" + end + + if json_obj:has_key("displayBusinessWeek") then + config.displayBusinessWeek = json_obj:get_bool("displayBusinessWeek") + else + config.displayBusinessWeek = false + end + + if json_obj:has_key("displayWeekNum") then + config.displayWeekNum = json_obj:get_bool("displayWeekNum") + else + config.displayWeekNum = true + end + + config.day = {} + if (json_obj:has_key("day") and json_obj["day"]:has_key("heureDebut")) then + config.day.heureDebut = json_obj["day"]:get_int("heureDebut") + else + config.day.heureDebut = 8 + end + + if (json_obj:has_key("day") and json_obj["day"]:has_key("heureFin")) then + config.day.heureFin = json_obj["day"]:get_int("heureFin") + else + config.day.heureFin = 17 + end + + --debugPrint(config) + +end + +-- --------------------------------------- +-- AFFICHAGE ECRAN CONFIG +-- ---------------------- + +function displayConfig() + + winConfig = gui:window() + gui:setWindow (winConfig) + + local title=gui:label(winConfig, 50, 28, 144, 28) + title:setFontSize(24) + title:setText("Préférences") + + -- récupération de la date courante + local today = getToday() + + local imgBack = gui:image(winConfig, "back.png", 20, 30, 18, 18) + imgBack:onClick(function () switchScreen(today[1], today[2], today[3]) end) + + + local lblWeekNum = gui:label(winConfig, 20, 100, 300, 30) + lblWeekNum:setText("Afficher le n° des semaines") + + local chkWeekNum = gui:checkbox(lblWeekNum, 200, 0) + chkWeekNum:setState(config.displayWeekNum) + + local lblWeekEnd = gui:label(winConfig, 20, 150, 300, 30) + lblWeekEnd:setText("Masquer les week-ends") + + local chkWeekEnd = gui:checkbox(lblWeekEnd, 200, 0) + chkWeekEnd:setState(config.displayBusinessWeek) + + local lblDefaultView = gui:label(winConfig, 20, 200, 300, 60) + + lblDefaultView:setText("Vue par défaut") + local radioDefaultViewDay = gui:radio(lblDefaultView, 15, 30) + local lblDefaultViewDay = gui:label(lblDefaultView, 40, 30, 60, 30) + lblDefaultViewDay:setText("Journée") + + local radioDefaultViewWeek = gui:radio(lblDefaultView, 110, 30) + local lblDefaultViewWeek = gui:label(lblDefaultView, 135, 30, 60, 30) + lblDefaultViewWeek:setText("Semaine") + + local radioDefaultViewMonth = gui:radio(lblDefaultView, 210, 30) + local lblDefaultViewMonth = gui:label(lblDefaultView, 235, 30, 60, 30) + lblDefaultViewMonth:setText("Mois") + + local groupRadio ={radioDefaultViewDay, radioDefaultViewWeek, radioDefaultViewMonth} + radioDefaultViewDay:onClick(function() selectGroupRadio(radioDefaultViewDay, groupRadio) end) + radioDefaultViewWeek:onClick(function() selectGroupRadio(radioDefaultViewWeek, groupRadio) end) + radioDefaultViewMonth:onClick(function() selectGroupRadio(radioDefaultViewMonth, groupRadio) end) + + + local lblDebutJour = gui:label(winConfig, 20, 280, 150, 20) + lblDebutJour:setText("Début de journée") + + local lblFinJour = gui:label(winConfig, 160, 280, 150, 20) + lblFinJour:setText("Fin de journée") + + local vLstHeureDebut = gui:vlist(winConfig, 20, 305, 150, 100) + vLstHeureDebut:setSpaceLine(0) + local vLstHeureFin = gui:vlist(winConfig, 160, 305, 150, 100) + vLstHeureFin:setSpaceLine(0) + + local heureDebut, heureFin + local oldHeureDebut, oldHeureFin + + + for i=0,23 do + local lblHeureDebut = gui:label(vLstHeureDebut, 50, 0, 40, 18) + local lblHeureFin = gui:label(vLstHeureFin, 30, 0, 40, 18) + lblHeureDebut:setText(tostring(i)..":00") + lblHeureFin:setText(tostring(i)..":00") + lblHeureDebut:setHorizontalAlignment(RIGHT_ALIGNMENT) + lblHeureFin:setHorizontalAlignment(RIGHT_ALIGNMENT) + + lblHeureDebut:onClick(function () + oldHeureDebut:setBackgroundColor(COLOR_WHITE) + lblHeureDebut:setBackgroundColor(COLOR_LIGHT_GREY) + oldHeureDebut = lblHeureDebut + heureDebut = i + end) + + lblHeureFin:onClick(function () + oldHeureFin:setBackgroundColor(COLOR_WHITE) + lblHeureFin:setBackgroundColor(COLOR_LIGHT_GREY) + oldHeureFin = lblHeureFin + heureFin = i + end) + + -- sélection initiale des listes + if config.day.heureDebut == i then + lblHeureDebut:setBackgroundColor(COLOR_LIGHT_GREY) + oldHeureDebut = lblHeureDebut + heureDebut = i + vLstHeureDebut:setIndex(i) + end + if config.day.heureFin == i then + lblHeureFin:setBackgroundColor(COLOR_LIGHT_GREY) + oldHeureFin = lblHeureFin + heureFin = i + vLstHeureFin:setIndex(i) + end + end + + -- selection initiale des boutons radio + if config.defaultView =="day" then + selectGroupRadio(radioDefaultViewDay, groupRadio) + elseif config.defaultView =="week" then + selectGroupRadio(radioDefaultViewWeek, groupRadio) + else + selectGroupRadio(radioDefaultViewMonth, groupRadio) + end + + local btnEnregistrer = gui:label(winConfig, 60, 420, 200, 30) + btnEnregistrer:setRadius(10) + btnEnregistrer:setBorderSize(1) + btnEnregistrer:setBackgroundColor(COLOR_LIGHT_GREY) + btnEnregistrer:setHorizontalAlignment(CENTER_ALIGNMENT) + btnEnregistrer:setVerticalAlignment (CENTER_ALIGNMENT) + btnEnregistrer:setText("Enregistrer") + btnEnregistrer:onClick(function() + + config.displayWeekNum = chkWeekNum:getState() + config.displayBusinessWeek = chkWeekEnd:getState() + + if radioDefaultViewDay:getState() then + config.defaultView = "day" + elseif radioDefaultViewWeek:getState() then + config.defaultView = "week" + else + config.defaultView = "month" + end + config.day={} + config.day.heureFin = heureFin + config.day.heureDebut = heureDebut + + -- sauvegarde de la config en fichier + saveConfig() + + --retour à l'écran précédent + switchScreen(year, month, day) + end) + + +end -- displayConfig + + +-- Gère la sélection unique d'un groupe de bouton radio +function selectGroupRadio(selected, groupRadio) + + if type(groupRadio) ~= "table" then + return + end + + for _, radio in ipairs(groupRadio) do + radio:setState(radio == selected) + end + +end + +-- sauvegarde la config en fichier json +function saveConfig() + + + local fileConfig = storage:file ("config.json", WRITE) + + if (fileConfig == nil) then + print("[saveConfig] error saving config file") + return + end + + local str_Json = array_to_json(config) + fileConfig:open() + fileConfig:write(str_Json) + + fileConfig:close() + fileConfig = nil + + +end + + +-- --------------------------------------- +-- AFFICHAGE D'UN MOIS +-- --------------------------------------- + + +function displayWeek(year, month, day) + + winWeek = gui:window() + gui:setWindow(winWeek) + + currentMode = "week" + + displayTopBarre() + -- sélection du menu actif + selectMenu(boxImgWeek) + + -- chargement des données du mois + loadDataMonth(year, month) + + -- récupération de la date du jour + local today = getToday() + + local numWeek = getWeekNum(year, month, day) + local numFirstDay = getDayOfWeek (year, month, day) -- jour de la semaine du jour à afficher + + local dateDebutSemaine = addDaysToDate({year, month, day}, 1 - numFirstDay) + local dateFinSemaine = addDaysToDate({year, month, day}, 7 - numFirstDay) + + -- Affichage de la semaine courante + local lblWeek = gui:label(winWeek, 20, affichageTop, 280, 35) + lblWeek:setHorizontalAlignment(CENTER_ALIGNMENT) + + local strTitre = "Semaine "..tostring(numWeek).." du "..tostring(dateDebutSemaine[3]) + if dateDebutSemaine[2] ~= dateFinSemaine[2] then + strTitre = strTitre .. " "..monthsShortName[dateDebutSemaine[2]] + end + strTitre = strTitre .." au "..tostring(dateFinSemaine[3]).." "..monthsShortName[dateFinSemaine[2]] + + lblWeek:setText(strTitre) + + -- Affichage des fleches avant et aprés pour naviguer sur le mois précédent / suivant + + local datePreviousWeek = addDaysToDate({year ,month, day}, -7) + local imgPreviousWeek = gui:image(winWeek, "fleche_gauche.png", 0, affichageTop, 20, 35) + imgPreviousWeek:onClick(function() displayWeek(datePreviousWeek[1], datePreviousWeek[2], datePreviousWeek[3]) end) + + + local dateNextWeek = addDaysToDate({year ,month, day}, 7) + local imgNextWeek = gui:image(winWeek, "fleche_droite.png", 300, affichageTop, 20, 35) + imgNextWeek:onClick(function() displayWeek(dateNextWeek[1], dateNextWeek[2], dateNextWeek[3]) end) + + local sizeListeHeures = 350 + local NbHeureToDisplay = config.day.heureFin - config.day.heureDebut +1 + + -- récupération de l'heure actuelle + local currentTime = time:get("h") + local currentHour = currentTime[1] + + local sizeBoxHeure = int(sizeListeHeures / NbHeureToDisplay) + local widthBox = 300 + + -- Gestion du header + local espacementBox = 1 -- espacement entre les cellules + local heigthHeader = 30 -- hauteur fixe pour le header + local topHeader = affichageTop+ heigthHeader -- décalage en haut pour l'affichage du header + + -- Définition de la taille du calendrier + local heightDisplayMonth = 480 - topHeader - heigthHeader- espacementBox - 10--360 -- hauteur de la partie calendrier + + --local nbDaysInMonth = getDaysInMonth(year, month) -- nombre de jour dans le mois + --local nbWeeksInMonths = int((6+numFirstDay + nbDaysInMonth -1 )/7) -- nombre de semaine à afficher pour le mois + local widthBoxJour -- largeur de la cellule jour + local widthWeekNum = 30 -- largeur fixe de la partie num de semaine + local leftMonth = 40 -- décalage à gauche pour l'affichage du lundi + local decalageHeure = 10 + local widthDisplayMonth = 310 - leftMonth -- largeur de la partie calendrier + + local NbJourstoDisplay = 7 -- Nombre de jours à afficher (dépend de la config avec l'affichagfe ou non des week)end + -- si config.displayBusinessWeek = true alors on n'affiche pas les week-end + if config.displayBusinessWeek then NbJourstoDisplay = 5 end + + widthBoxJour = int((widthDisplayMonth- NbJourstoDisplay *espacementBox)/ NbJourstoDisplay) + + -- liste déroulante des heures + vListeHeure = gui:vlist(winWeek, decalageHeure, topHeader+heigthHeader+espacementBox, widthBox, sizeListeHeures) + vListeHeure:setSpaceLine(0) + vListeHeure:setBackgroundColor(COLOR_LIGHT_GREY) + + local lstBoxHeure = {} + + -- Affichage du header + for j=1, NbJourstoDisplay do + + -- calcul de la date + local decalageDays = j - numFirstDay + local dateCellule = addDaysToDate({year, month, day}, decalageDays) + + -- récupération de la liste des événements + local lstEvent = getDayEvents(dateCellule[1], dateCellule[2], dateCellule[3]) + + local lblHeader = gui:label(winWeek, leftMonth + (j-1)*(widthBoxJour+espacementBox) , topHeader, widthBoxJour, heigthHeader) + local colorHeader = COLOR_LIGHT_GREY + if dateCellule[1] == today[1] and dateCellule[2] == today[2] and dateCellule[3] == today[3] then + colorHeader = COLOR_LIGHT_ORANGE + end + lblHeader:setBackgroundColor(colorHeader) + + local headerJour = gui:label(lblHeader, 0, 0, widthBoxJour, 12) + headerJour:setFontSize(12) + headerJour:setBackgroundColor(colorHeader) + headerJour:setHorizontalAlignment(CENTER_ALIGNMENT) + headerJour:setText(daysOfWeekShort[j]) + + local headerJourNum = gui:label(lblHeader, 0, 12, widthBoxJour, 18) + headerJourNum:setFontSize(18) + headerJourNum:setBackgroundColor(colorHeader) + headerJourNum:setHorizontalAlignment(CENTER_ALIGNMENT) + headerJour:setVerticalAlignment(CENTER_ALIGNMENT) + headerJourNum:setText(tostring(dateCellule[3])) + + -- Affichage des heures + for i=0,23 do + local boxHour + if not lstBoxHeure[i] then + boxHour = gui:box(vListeHeure, 0, 0, widthBox+1, sizeBoxHeure) + lstBoxHeure[i] = boxHour + + boxHour:setBorderColor(COLOR_LIGHT_GREY) + boxHour:setBorderSize(1) + boxHour:setRadius(1) + + -- affichage des heures + local boxLabelHeure = gui:box(boxHour, 0, 0, leftMonth-decalageHeure, sizeBoxHeure) + boxLabelHeure:setBorderColor(COLOR_LIGHT_GREY) + boxLabelHeure:setBorderSize(1) + boxLabelHeure:setRadius(1) + + local lblHeure = gui:label(boxLabelHeure, 0 , 1, 20, sizeBoxHeure-2) + --lblHeure:setBackgroundColor(COLOR) + --lblHeure:setTextColor(COLOR_) + lblHeure:setHorizontalAlignment(RIGHT_ALIGNMENT) + lblHeure:setFontSize(14) + lblHeure:setText(tostring(i)..":") + + local lblMin = gui:label(boxLabelHeure, 20,1, 18, sizeBoxHeure-2) + lblMin:setHorizontalAlignment(LEFT_ALIGNMENT) + lblMin:setTextColor(COLOR_GREY) + --lblMin:setBackgroundColor(colorBackGround) + lblMin:setFontSize(10) + lblMin:setText("00") + else + boxHour = lstBoxHeure[i] + end + + local lblCase = gui:label(boxHour, leftMonth-decalageHeure+(j-1)*(widthBoxJour+espacementBox) , 0, widthBoxJour+espacementBox, sizeBoxHeure) + lblCase:setBorderColor(COLOR_LIGHT_GREY) + lblCase:setBorderSize(1) + lblCase:setRadius(1) + if config.day.heureDebut >i or config.day.heureFin < i then + lblCase:setBackgroundColor(COLOR_LIGHT_BLUE) + end + -- ------------------------ + -- Affichage des evenements + -- ------------------------ + + if lstEvent ~= nil then + for _, ev in pairs(lstEvent) do + + -- il y a un un event ou troncon d'event sur cette plage horaire + if i>= ev.debut.heure and (i < ev.fin.heure or ( ev.fin.heure==i and ev.fin.minute >0 )) then + local nomEvent = "" + -- gestion du positionnement du haut de l'event dans la case horaire + local positionHaut = 0 + if ev.debut.heure == i then + positionHaut = int(ev.debut.minute * sizeBoxHeure / 60)+1 + -- on met le nom de l'event sur le 1er "troncon" + nomEvent = ev.name + elseif i > ev.debut.heure then + positionHaut = 0 + end + + -- gestion du positionnement du bas de l'event dans la case horaire + local positionBas = sizeBoxHeure-1 + if ev.fin.heure == i then + positionBas = int((ev.fin.minute) * sizeBoxHeure / 60)-1 + elseif ev.fin.heure > i then + positionBas = sizeBoxHeure + end + --local lblEvent = gui:label(winWeek, leftMonth + (j-1)*(widthBoxJour+espacementBox) , topHeader, widthBoxJour, heigthHeader) + -- local lblEvent = gui:label(boxHour, 41, positionHaut, widthBox - 50, positionBas - positionHaut) + + local lblEvent = gui:label(boxHour, leftMonth-decalageHeure+(j-1)*(widthBoxJour+espacementBox) , positionHaut, widthBoxJour, positionBas - positionHaut) + -- local lblEvent = gui:label(winWeek, leftMonth + (j-1)*(widthBoxJour+espacementBox) , topHeader, widthBoxJour, heigthHeader) + + lblEvent:setBackgroundColor(COLOR_LIGHT_ORANGE) + lblEvent:setFontSize(14) + lblEvent:setText(" "..nomEvent) + lblEvent:onClick( + function() + local ev = getEventByID(ev.UID, dateCellule[1], dateCellule[2], dateCellule[3]) + if not ev then ev = createEventObject (dateCellule[1], dateCellule[2], dateCellule[3]) end + displayEvent(ev) + end + ) + end + end + + end -- if lstEvent + + end + + -- on positionne la vliste sur la 1ere heure du jour + vListeHeure:setIndex(config.day.heureDebut) + +end + + + +end -- displayWeek + +-- --------------------------------------- +-- AFFICHAGE D'UN MOIS +-- --------------------------------------- + + +function displayMonth (year, month) + + winMonth = gui:window() + gui:setWindow(winMonth) + + currentMode = "month" + + displayTopBarre() + -- sélection du menu actif + selectMenu(boxImgMonth) + + + -- chargement des données du mois + loadDataMonth(year, month) + + -- récupération de la date du jour + local today = getToday() + + -- Affichage du mois courant + local lblMois = gui:label(winMonth, 20, affichageTop, 280, 35) + lblMois:setHorizontalAlignment(CENTER_ALIGNMENT) + lblMois:setText(formatDate({year, month, 1}, "MM yyyy")) + + -- Affichage des fleches avant et aprés pour naviguer sur le mois précédent / suivant + local previousMonth, previousYear + if month == 1 then + previousMonth = 12 + previousYear = year -1 + else + previousMonth = month-1 + previousYear = year + end + + local imgPreviousMonth = gui:image(winMonth, "fleche_gauche.png", 0, affichageTop, 20, 35) + imgPreviousMonth:onClick(function() displayMonth(previousYear, previousMonth) end) + + local nextMonth, nextYear + if month == 12 then + nextMonth = 1 + nextYear = year +1 + else + nextMonth = month+1 + nextYear = year + end + + local imgNextMonth = gui:image(winMonth, "fleche_droite.png", 300, affichageTop, 20, 35) + imgNextMonth:onClick(function() displayMonth(nextYear, nextMonth) end) + + local espacementBox = 3 -- espacement entre les cellules + local heigthHeader = 30 -- hauteur fixe pour le header + local topHeader = affichageTop+ heigthHeader -- décalage en haut pour l'affichage du header + + -- Définition de la taille du calendrier + local heightDisplayMonth = 480 - topHeader - heigthHeader- espacementBox - 10--360 -- hauteur de la partie calendrier + local widthDisplayMonth = 300 -- largeur de la partie calendrier + + local numFirstDay = getDayOfWeek (year, month, 1) -- jour de la semaine du premier jour du mois + local nbDaysInMonth = getDaysInMonth(year, month) -- nombre de jour dans le mois + local nbWeeksInMonths = int((6+numFirstDay + nbDaysInMonth -1 )/7) -- nombre de semaine à afficher pour le mois + local NbJourstoDisplay = 7 -- Nombre de jours à afficher (dépend de la config avec l'affichagfe ou non des week)end + local widthBoxJour -- largeur de la cellule jour + local widthWeekNum = 30 -- largeur fixe de la partie num de semaine + local leftMonth -- décalage à gauche pour l'affichage du lundi + + -- si config.displayBusinessWeek = true alors on n'affiche pas les week-end + if config.displayBusinessWeek then NbJourstoDisplay = 5 end + + -- Affichage du header avec les jours + if config.displayWeekNum then + widthBoxJour = int((widthDisplayMonth-widthWeekNum - NbJourstoDisplay*espacementBox) / NbJourstoDisplay) + leftMonth = widthWeekNum + else + widthBoxJour = int((widthDisplayMonth- NbJourstoDisplay*espacementBox )/ NbJourstoDisplay) + leftMonth = 0 + end + + -- hauteur des cellules jour + local heightSemaine = int((heightDisplayMonth - nbWeeksInMonths * espacementBox)/nbWeeksInMonths) + local heightEvent = 10 + + -- AMELIORATION POSSIBLE - Calculer le nombre d'event affichable possible + -- local nbMaxEventDisplay = int((heightSemaine - 16) / heightEvent) + + -- Affichage du header + for i=1, NbJourstoDisplay do + local lblHearder = gui:label(winMonth, 10+leftMonth + espacementBox+ (i-1)*(widthBoxJour + espacementBox) , topHeader, widthBoxJour, heigthHeader) + lblHearder:setBackgroundColor(COLOR_LIGHT_GREY) + lblHearder:setHorizontalAlignment(CENTER_ALIGNMENT) + lblHearder:setVerticalAlignment(CENTER_ALIGNMENT) + lblHearder:setText(daysOfWeekShort[i]) + end + + local weekNum = getWeekNum(year, month, 1) + + -- Affichage des cellules + for i=1, nbWeeksInMonths do + + -- si config.displayWeekNum, on affiche le numéro de semaine + if config.displayWeekNum then + local lblNumSemaine = gui:label (winMonth, 10, topHeader+ heigthHeader + espacementBox+ (heightSemaine+ espacementBox) * (i-1),widthWeekNum, heightSemaine) + lblNumSemaine:setBackgroundColor(COLOR_LIGHT_GREY) + lblNumSemaine:setHorizontalAlignment(CENTER_ALIGNMENT) + lblNumSemaine:setVerticalAlignment(CENTER_ALIGNMENT) + lblNumSemaine:setFontSize(14) + lblNumSemaine:setText(tostring(weekNum +i -1)) + end + + -- Affichage des cellules + for j=1, NbJourstoDisplay do + -- calcul de la date + local decalageDays = (i-1) * 7 + j - numFirstDay + local dateCellule = addDaysToDate({year, month, 1}, decalageDays) + + -- Affichage de la cellule + local lblJourMonth = gui:label (winMonth, 10+leftMonth + espacementBox+ (j-1)*(widthBoxJour + espacementBox), topHeader+ heigthHeader + espacementBox+ (heightSemaine+ espacementBox) * (i-1),widthBoxJour, heightSemaine) + lblJourMonth:setBorderSize(1) + lblJourMonth:setBorderColor(COLOR_LIGHT_GREY) + lblJourMonth:setHorizontalAlignment(RIGHT_ALIGNMENT) + lblJourMonth:setFontSize(14) + lblJourMonth:setRadius(1) + + -- Affichage des events (s'il y en a) + local lstEvent = getDayEvents(dateCellule[1], dateCellule[2], dateCellule[3]) + if lstEvent then + local nbEvents = #lstEvent + local idx = 0 + + for id, ev in pairs(lstEvent) do + local lblEvent = gui:label(lblJourMonth, 2, 16 +idx *(heightEvent+1), widthBoxJour-4, heightEvent) + lblEvent:setBackgroundColor(COLOR_LIGHT_ORANGE) + lblEvent:setText(ev.name) + lblEvent:setFontSize(10) + idx = idx +1 + end + end + + -- affichage des jours du mois précédent / suivant en une autre couleur + if dateCellule[2] ~= month then + lblJourMonth:setTextColor(COLOR_LIGHT_GREY) + end + lblJourMonth:setText(tostring(dateCellule[3])) + + -- highligth de la cellule du jour courant + if (today[1] == dateCellule[1] and today[2] == dateCellule[2] and today[3] == dateCellule[3]) then + lblJourMonth:setBorderColor(COLOR_BLUE) + --lblJourMonth:setBackgroundColor(COLOR_LIGHT_BLUE) + end + + lblJourMonth:onClick( + function() + displayDay(dateCellule[1], dateCellule[2], dateCellule[3]) + end + ) + + + end + + end + +end --displayMonth + + + +-- --------------------------------------- +-- GESTION DES DATA +-- --------------------------------------- + + + +-- Enregistrement d'un event dans la structure Data +function saveEvent(event) + + if not data[event.debut.year] then data[event.debut.year] = {} end + if not data[event.debut.year][event.debut.month] then data[event.debut.year][event.debut.month] = {} end + if not data[event.debut.year][event.debut.month][event.debut.day] then data[event.debut.year][event.debut.month][event.debut.day] = {} end + if not data[event.debut.year][event.debut.month][event.debut.day][event.UID] then + data[event.debut.year][event.debut.month][event.debut.day][event.UID] = {} + end + --table.insert(data[event.debut.year][event.debut.month][event.debut.day][event.UID], event) + data[event.debut.year][event.debut.month][event.debut.day][event.UID] = event + + saveDataFile(event.debut.year,event.debut.month) + +end + + +-- create an array based on its json representation +function json_to_array(jsonString) + + local function parse(jsonStr) + local array = {} + jsonStr = jsonStr:match("^%s*%.+") + + jsonStr = json:sub(2, -2) -- Remove brackets + local current = array + local stack = {} + + for value in jsonStr:gmatch("{[^,%[%]]+}") do + value = value:gsub('^%s*(.-)%s*$', '%1') -- Trim whitespace + + if value == "{" then + local newArray = {} + table.insert(current, newArray) + table.insert(stack, current) + current = newArray + elseif value == "}" then + current = table.remove(stack) + else + table.insert(current, value:match('^%s*"(.*)"%s*$') or value) + end + end + + return array + end + return parse(jsonString) +end + + +-- create a json string representing the given array +function array_to_json(array) + + + local result = "{" + local first = true + + if type(array) == "table" then + for k, v in pairs(array) do + + if not first then + result = result .. ", " + end + first = false + + if type(v) == "table" then + result = result..'"'..tostring(k) ..'":'..array_to_json(v) + elseif type(v) == "string" then + result = result..'"'..tostring(k) ..'":'.. '"' .. v:gsub('"', '\\"') .. '"' + elseif type(v) == "number" then + result = result..'"'..tostring(k) ..'":' .. tostring(v) + elseif type(v) == "boolean" then + result = result..'"'..tostring(k) ..'":' .. tostring(v) + else + result = result..'"'..tostring(k) ..'":'.. "null" + end + end + elseif type(array) == "string" then + result = result..'"'..tostring(k) ..'":'.. '"' .. array:gsub('"', '\\"') .. '"' + elseif type(array) == "number" then + result = result..'"'..tostring(k) ..'":'.. tostring(array) + elseif type(array) == "boolean" then + result = result..'"'..tostring(k) ..'":'.. tostring(array) + else + result = result..'"'..tostring(k) ..'":'.. "null" + end + + result = result .. "}" + return result +end + +-- Sauvegarde la structure data pour un mois donné dans un fichier au format json +-- si le fichier existe déjà, les données sont écrasées itégralement +function saveDataFile(year, month) + + if data[year] then + if data[year][month] then + local strData = serialize (data[year][month]) + local filename = PATH_DATA.."/"..tostring(year)..tostring(month)..".dat" + fileData = storage:file (filename, WRITE) + fileData:open() + fileData:write(strData) + fileData:close() + fileData = nil + + return + end + end + + print("saveDataFile - aucune donnée à sauvegarder pour le mois "..tostring(month).." de "..tostring(year)) + + +end + +-- Chargement des fichiers event dans la structure data +-- les fichiers event sont stockés dans PATH_DATA +-- on compte un fichier event par mois, au format json, avec le nom {year}{month}.dat +-- pour un mois donné, on charge les données du mois, du mois précédent et du mois suivant si 'noLoadingAdjacent' n'est pas indiqué + +function loadDataMonth(year, month, noLoadingAdjacent) + + local filename = PATH_DATA.."/"..tostring(year)..tostring(month)..".dat" + local fileData + local strData + + if data[year] and data[year][month] then + print("données déjà chargées pour le mois "..tostring(month).. " de "..tostring(year)) + return + end + + -- par défaut, on charge les mois précédent et suivants + if noLoadingAdjacent == nil then noLoadingAdjacent = false end + + -- check if a data file exists + if storage:isFile(filename) then + + -- lecture du fichier + fileData = storage:file (filename, READ) + fileData:open() + strData = fileData:readAll() + fileData:close() + fileData = nil + +-- dataLoad = json_to_array(strData) + local dataLoad = unserialize(strData) + + if not dataLoad or not dataLoad[1] then return end + + -- ajout du json dans la structure data + if not data[year] then data[year] = {} end + if not data[year][month] then data[year][month] = {} end + + data[year][month]=dataLoad[1] + --debugPrint(data) + + if (not noLoadingAdjacent) then + -- chargement des données du mois précédent + + local previousMonth, previousYear + if month == 1 then + previousMonth = 12 + previousYear = year - 1 + else + previousMonth = month -1 + previousYear = year + end + + loadDataMonth(previousYear, previousMonth, true) + + -- chargement des données du mois suivant + local nextMonth, nextYear + if month == 12 then + nextMonth = 1 + nextYear = year + 1 + else + nextMonth = month + 1 + nextYear = year + end + loadDataMonth(nextYear, nextMonth, true) + end + else + return + end + +end --loadDataMonth + +-- retourne la liste d'événements existant pour un jour donné +-- retourne nil si aucun évenment n'existe +function getDayEvents(year, month, day) + local result = nil + if data[year] then + if data[year][month] then + if data[year][month][day] then +-- print("des données existent pour "..tostring(day).."/"..tostring(month).."/"..tostring(year)) + result = data[year][month][day] + end + end + end + --debugPrint(result) + return result +end + +-- récupére l'objet event sur un jour donné avec son UID +function getEventByID(UID, year, month, day) + local result = nil + if data[year] then + if data[year][month] then + if data[year][month][day] then + if data[year][month][day][UID] then + result = data[year][month][day][UID] + end + end + end + end + return result + +end + +-- Suppression d'un event de la table data et retourne cet élément +function deleteEvent(UID, year, month, day) + + local element = data[year][month][day][UID] + if element then + data[year][month][day][UID] = nil + end + return element +end + +-- Créer un nouvel événement +function createEventObject(name, description, yearDebut, monthDebut, dayDebut, heureDebut, minuteDebut, yearFin, monthFin, dayFin, heureFin, minuteFin) + + event = {} + event.debut = {} + event.fin = {} + event.UID = createUID() + + --{"s","mi","h","d","mo","y"}; + local date= time:get("y,mo,d,h,mi") + year = date[1] + month = date[2] + day = date[3] + heure = date[4] + minute = date[5] + + -- TODO: gestion de la cohérence des dates & heures entre début et fin + + if not name then event.name = "" else event.name = name end + if not description then event.description = "" else event.description = description end + + if not yearDebut then event.debut.year = year else event.debut.year = yearDebut end + if not monthDebut then event.debut.month = month else event.debut.month = monthDebut end + if not dayDebut then event.debut.day = day else event.debut.day = dayDebut end + if not heureDebut then event.debut.heure = heure else event.debut.day = heureDebut end + if not minuteDebut then event.debut.minute = 0 else event.debut.day = minuteDebut end + + if not yearFin then event.fin.year = year else event.fin.year = yearFin end + if not monthFin then event.fin.month = month else event.fin.month = monthDFin end + if not dayFin then event.fin.day = day else event.fin.day = dayFin end + if not heureFin then event.fin.heure = heure+1 else event.fin.day = heureFin end + if not minuteFin then event.fin.minute = 0 else event.fin.day = minuteFin end + + return event +end + +-- --------------------------------------- +-- AFFICHAGE D'UN JOUR +-- --------------------------------------- +function displayDay(year, month, day) + + currentMode = "day" + + -- création d'une nouvelle fenetre pour le jour + -- if not winDay then + winDay = gui:window() + --end + gui:setWindow(winDay) + + -- cration de la top barre + displayTopBarre() + + -- sélection du menu actif + selectMenu(boxImgDay) + + -- chargement des données du mois + loadDataMonth(year, month) + + -- -------------------- + -- création de l'écran + -- -------------------- + + -- Label du jour sélectionné + local lblJour = gui:label(winDay, 10, affichageTop, 200, 25) + lblJour:setHorizontalAlignment(LEFT_ALIGNMENT) + + str = formatDate({year, month, day}, "DD dd MM") + lblJour:setText(str) + + local sizeListeHeures = 350 + local NbHeureToDisplay = config.day.heureFin - config.day.heureDebut +1 + + -- récupération de l'heure actuelle + local currentTime = time:get("h") + local currentHour = currentTime[1] + + local today = getToday() + + local sizeBoxHeure = int(sizeListeHeures / NbHeureToDisplay) + local widthBox = 300 + + -- liste déroulante des heures + vListeHeure = gui:vlist(winDay, 10, 85, widthBox, sizeListeHeures) + vListeHeure:setSpaceLine(0) + vListeHeure:setBackgroundColor(COLOR_LIGHT_GREY) + + -- récupération de la liste des événements + local lstEvent = getDayEvents(year, month, day) + + -- Affichage des heures + for i=0,23 do + local boxHour = gui:box(vListeHeure, 0, 0, widthBox, sizeBoxHeure) + if (i==currentHour) then + boxHour:setBackgroundColor(COLOR_RED) + else + boxHour:setBackgroundColor(COLOR_GREY) + end + + local lblDummy = gui:label(boxHour, 0 , 1, widthBox, sizeBoxHeure-1) + if (i < config.day.heureDebut or i>config.day.heureFin) then + lblDummy:setBackgroundColor(COLOR_LIGHT_BLUE) + else + lblDummy:setBackgroundColor(COLOR_WHITE) + end + + local colorBackGround = COLOR_WHITE + local colorTextHeure = COLOR_BLACK + local colorTextMin = COLOR_GREY + + if (i==currentHour) then + colorBackGround = COLOR_RED + colorTextHeure = COLOR_WHITE + colorTextMin = COLOR_WHITE + end + + local lblHeure = gui:label(boxHour, 0 , 1, 20, sizeBoxHeure-2) + lblHeure:setBackgroundColor(colorBackGround) + lblHeure:setTextColor(colorTextHeure) + lblHeure:setHorizontalAlignment(RIGHT_ALIGNMENT) + lblHeure:setFontSize(14) + lblHeure:setText(tostring(i)..":") + + local lblMin = gui:label(boxHour, 20,1, 18, sizeBoxHeure-2) + lblMin:setHorizontalAlignment(LEFT_ALIGNMENT) + lblMin:setTextColor(colorTextMin) + lblMin:setBackgroundColor(colorBackGround) + lblMin:setFontSize(10) + lblMin:setText("00") + + -- ------------------------ + -- Affichage des evenements + -- ------------------------ + + if lstEvent ~= nil then + for _, ev in pairs(lstEvent) do + + -- il y a un un event ou troncon d'event sur cette plage horaire + if i>= ev.debut.heure and (i < ev.fin.heure or ( ev.fin.heure==i and ev.fin.minute >0 )) then + local nomEvent = "" + -- gestion du positionnement du haut de l'event dans la case horaire + local positionHaut = 0 + if ev.debut.heure == i then + positionHaut = int(ev.debut.minute * sizeBoxHeure / 60)+1 + -- on met le nom de l'event sur le 1er "troncon" + nomEvent = ev.name + elseif i > ev.debut.heure then + positionHaut = 0 + end + + -- gestion du positionnement du bas de l'event dans la case horaire + local positionBas = sizeBoxHeure-1 + if ev.fin.heure == i then + positionBas = int((ev.fin.minute) * sizeBoxHeure / 60)-1 + elseif ev.fin.heure > i then + positionBas = sizeBoxHeure + end + + local lblEvent = gui:label(boxHour, 41, positionHaut, widthBox - 50, positionBas - positionHaut) + --local lblEvent = gui:label(boxHour, 41, 0, widthBox - 50, sizeBoxHeure) + lblEvent:setBackgroundColor(COLOR_LIGHT_ORANGE) + lblEvent:setFontSize(14) + lblEvent:setText(" "..nomEvent) + + lblEvent:onClick( + function() + local ev = getEventByID(ev.UID, year, month, day) + if not ev then ev = createEventObject (year, month, day) end + displayEvent(ev) + end + ) + end + end + + end -- if lstEvent + + end + + -- on positionne la vliste sur la 1ere heure du jour + vListeHeure:setIndex(config.day.heureDebut) + + -- ------------------------------------------ + -- Affichage des jours de la semaine en cours + + local currentDayWeek = getDayOfWeek(year, month, day) + local nbDaysWeekToDisplay = 7 + if (config.displayBusinessWeek) then + nbDaysWeekToDisplay = 5 + end + + local widthBoxDay = int((winDay:getWidth()-40)/nbDaysWeekToDisplay) + vListDays = gui:hlist(winDay, 20, 435, widthBox, 40) + vListDays:setSpaceLine(0) + + -- ajout des fleches de navigation d'une semaine en + ou en - + local datePreviousWeek = addDaysToDate({year, month, day}, -nbDaysWeekToDisplay) + local imgPreviousWeek = gui:image(winDay, "fleche_gauche.png", 0, 440, 20, 35) + imgPreviousWeek:onClick(function() displayDay(datePreviousWeek[1], datePreviousWeek[2], datePreviousWeek[3]) end) + + local dateNextWeek = addDaysToDate({year, month, day}, nbDaysWeekToDisplay) + local imgNextWeek = gui:image(winDay, "fleche_droite.png", 300, 440, 20, 35) + imgNextWeek:onClick(function() displayDay(dateNextWeek[1], dateNextWeek[2], dateNextWeek[3]) end) + + + for i=1, nbDaysWeekToDisplay do + local date = addDaysToDate({year, month, day}, i-currentDayWeek) + + local boxDayWeek = gui:box(vListDays, 0, 5, widthBoxDay, 35) + + local lblDayOfWeek = gui:label(boxDayWeek, 2, 2, widthBoxDay-4, 12, COLOR_WHITE) + lblDayOfWeek:setFontSize(9) + lblDayOfWeek:setHorizontalAlignment(CENTER_ALIGNMENT) + lblDayOfWeek:setText(daysOfWeek[i]) + + local lblDay = gui:label(boxDayWeek, 4, 11, widthBoxDay-8, 20, COLOR_WHITE) + lblDay:setHorizontalAlignment(CENTER_ALIGNMENT) + lblDay:setFontSize(15) + lblDay:setText(tostring(date[3])) + + if (currentDayWeek == i) then + boxDayWeek:setRadius(5) + boxDayWeek:setBackgroundColor(COLOR_LIGHT_ORANGE) + lblDayOfWeek:setBackgroundColor(COLOR_LIGHT_ORANGE) + lblDay:setBackgroundColor(COLOR_LIGHT_ORANGE) + --lblDayOfWeek + else + boxDayWeek:onClick(function() displayDay(date[1], date[2], date[3]) end) + end + end + + +end --displayDay + + + +function printEvent(event) + + print("event: ".. event.name) + print("date debut: ".. tostring(event.debut.day).."/".. tostring(event.debut.month).."/".. tostring(event.debut.year)) + print( " debut: "..tostring(event.debut.heure)..":"..tostring(event.debut.minute) ) + print( " fin: "..tostring(event.fin.heure)..":"..tostring(event.fin.minute) ) + +end + +-- --------------------------------------- +-- ECRAN DETAIL / NOUVEL EVENEMENT +-- --------------------------------------- + +function displayEvent(event) + + winNewEvent = gui:window() + gui:setWindow(winNewEvent) + + local isNew = false + + local titre="" + if not event then + event = createEventObject() + isNew = true + end + + if event.name == nil or event.name == "" then + titre = "Nouvel évènement" + event.name = "" + isNew = true + end + + local lblMsgError = gui:label(winNewEvent, 30, 380, 260, 40) + lblMsgError:setFontSize(14) + lblMsgError:setHorizontalAlignment(CENTER_ALIGNMENT) + lblMsgError:setTextColor(COLOR_RED) + + imgBack = gui:image(winNewEvent, "back.png", 20, 30, 18, 18) + imgBack:onClick(function () switchScreen(year, month, day) end) + + local inputName = gui:input(winNewEvent, 60, 10, 250, 40) + inputName:setTitle(titre) + inputName:setText(event.name) + inputName:onClick( + function () + local keyboard = gui:keyboard("Nom de l'évènement", event.name) + inputName:setText(keyboard) + event.name = keyboard + lblMsgError:setText("") + end + ) + -- ----------------------------------- + -- Gestion de la date & heure de début + + local lblDebut = gui:label(winNewEvent, 20, 80, 100, 20) + lblDebut:setText("Début") + + local lblDateHeureDebut = gui:label(winNewEvent, 120, 80, 180, 20) + lblDateHeureDebut:setHorizontalAlignment(RIGHT_ALIGNMENT) + lblDateHeureDebut:setText(formatDate({event.debut.year, event.debut.month, event.debut.day, event.debut.heure, event.debut.minute},"DD dd sh hh:mi")) + + local lblTraitDebut = gui:label(winNewEvent, 20, 101, 280, 1) + lblTraitDebut:setBackgroundColor(COLOR_GREY) + + local vListeDateDebutNewEvent = gui:vlist(winNewEvent, 20, 110, 140, 100) + vListeDateDebutNewEvent:setSpaceLine(0) + + local oldSelectionDateDebut + local nbJourToDisplay = 30 + + -- Affichage des dates + for i=0, 2*nbJourToDisplay do + local date = addDaysToDate({event.debut.year, event.debut.month, event.debut.day}, i-nbJourToDisplay) + local lblDateDebut = gui:label(vListeDateDebutNewEvent, 0, 0, 140, 13) + lblDateDebut:setFontSize(12) + lblDateDebut:setHorizontalAlignment(RIGHT_ALIGNMENT) + lblDateDebut:setText(formatDate(date, "DD dd sh").." ") + lblDateDebut:onClick( + function() + + if oldSelectionDateDebut == lblDateDebut then return end + + event.debut.year = date[1] + event.debut.month = date[2] + event.debut.day = date[3] + lblDateHeureDebut:setText(formatDate(event.debut,"DD dd sh hh:mi")) + + oldSelectionDateDebut:setBackgroundColor(COLOR_WHITE) + lblDateDebut:setBackgroundColor(COLOR_LIGHT_GREY) + oldSelectionDateDebut = lblDateDebut + + lblMsgError:setText("") + end + ) + + if i == nbJourToDisplay then + lblDateDebut:setBackgroundColor(COLOR_LIGHT_GREY) + vListeDateDebutNewEvent:setIndex(i) + oldSelectionDateDebut = lblDateDebut + end + end + + local vListeHeureDebutNewEvent = gui:vlist(winNewEvent, 200, 110, 40, 100) + vListeHeureDebutNewEvent:setSpaceLine(0) + local oldLblHeureDebutNewEvent + -- Affichage des Heures + for i=0, 23 do + + local lblHeureDebutNewEvent = gui:label(vListeHeureDebutNewEvent, 0, 0, 40, 13) + lblHeureDebutNewEvent:setFontSize(12) + lblHeureDebutNewEvent:setHorizontalAlignment(CENTER_ALIGNMENT) + lblHeureDebutNewEvent:setText(tostring(i)) + lblHeureDebutNewEvent:onClick( + function() + + if lblHeureDebutNewEvent == oldLblHeureDebutNewEvent then return end + + -- set de l'heure sélectionnée et affichage sur le label Debut + event.debut.heure = i + lblDateHeureDebut:setText(formatDate(event.debut,"DD dd sh hh:mi")) + + lblHeureDebutNewEvent:setBackgroundColor(COLOR_LIGHT_GREY) + oldLblHeureDebutNewEvent:setBackgroundColor(COLOR_WHITE) + oldLblHeureDebutNewEvent = lblHeureDebutNewEvent + + lblMsgError:setText("") + end + ) + + if i == event.debut.heure then + lblHeureDebutNewEvent:setBackgroundColor(COLOR_LIGHT_GREY) + vListeHeureDebutNewEvent:setIndex(i) + oldLblHeureDebutNewEvent = lblHeureDebutNewEvent + end + + end + + local vListeMinDebutNewEvent = gui:vlist(winNewEvent, 260, 110, 40, 100) + vListeMinDebutNewEvent:setSpaceLine(0) + local oldLblMinDebutNewEvent + + -- Affichage des Minutes + for i=0, 55, 5 do + local lblMinuteDebutNewEvent = gui:label(vListeMinDebutNewEvent, 0, 0, 40, 13) + lblMinuteDebutNewEvent:setFontSize(12) + lblMinuteDebutNewEvent:setHorizontalAlignment(CENTER_ALIGNMENT) + lblMinuteDebutNewEvent:setText(tostring(i)) + + lblMinuteDebutNewEvent:onClick( + function() + -- set de la minute de début et affichage sur le label Debut + if lblMinuteDebutNewEvent == oldLblMinDebutNewEvent then return end + + event.debut.minute = i + lblDateHeureDebut:setText(formatDate(event.debut,"DD dd sh hh:mi")) + + lblMinuteDebutNewEvent:setBackgroundColor(COLOR_LIGHT_GREY) + oldLblMinDebutNewEvent:setBackgroundColor(COLOR_WHITE) + oldLblMinDebutNewEvent = lblMinuteDebutNewEvent + + lblMsgError:setText("") + end + ) + + if i == event.debut.minute then + lblMinuteDebutNewEvent:setBackgroundColor(COLOR_LIGHT_GREY) + vListeMinDebutNewEvent:setIndex(int(i/5)) + oldLblMinDebutNewEvent = lblMinuteDebutNewEvent + end + end + + -- ----------------------------------- + -- Gestion de la date & heure de fin + + local lblFin = gui:label(winNewEvent, 20, 230, 100, 20) + lblFin:setText("Fin") + + local lblDateHeureFin = gui:label(winNewEvent, 120, 230, 180, 20) + lblDateHeureFin:setHorizontalAlignment(RIGHT_ALIGNMENT) + lblDateHeureFin:setText(formatDate({event.fin.year, event.fin.month, event.fin.day, event.fin.heure, event.fin.minute},"DD dd sh hh:mi")) + + local lblTraitFin = gui:label(winNewEvent, 20, 251, 280, 1) + lblTraitFin:setBackgroundColor(COLOR_GREY) + + + local vListeDateFinNewEvent = gui:vlist(winNewEvent, 20, 260, 140, 100) + vListeDateFinNewEvent:setSpaceLine(0) + local oldSelectionDateFin + + -- Affichage des dates + for i=0, 2*nbJourToDisplay do + local date = addDaysToDate({event.fin.year, event.fin.month, event.fin.day}, i-nbJourToDisplay) + local lblDateFin = gui:label(vListeDateFinNewEvent, 0, 0, 140, 13) + lblDateFin:setFontSize(12) + lblDateFin:setHorizontalAlignment(RIGHT_ALIGNMENT) + lblDateFin:setText(formatDate(date, "DD dd sh").." ") + lblDateFin:onClick( + function() + + if oldSelectionDateFin == lblDateFin then return end + + event.fin.year = date[1] + event.fin.month = date[2] + event.fin.day = date[3] + lblDateHeureFin:setText(formatDate(event.fin,"DD dd sh hh:mi")) + + oldSelectionDateFin:setBackgroundColor(COLOR_WHITE) + lblDateFin:setBackgroundColor(COLOR_LIGHT_GREY) + oldSelectionDateFin = lblDateFin + + lblMsgError:setText("") + end + ) + + if i == nbJourToDisplay then + lblDateFin:setBackgroundColor(COLOR_LIGHT_GREY) + vListeDateFinNewEvent:setIndex(i) + oldSelectionDateFin = lblDateFin + end + end + + -- Affichage des Heures + local vListeHeureFinNewEvent = gui:vlist(winNewEvent, 200, 260, 40, 100) + vListeHeureFinNewEvent:setSpaceLine(0) + local oldLblHeureFinNewEvent + + for i=0, 23 do + + local lblHeureFintNewEvent = gui:label(vListeHeureFinNewEvent, 0, 0, 40, 13) + lblHeureFintNewEvent:setFontSize(12) + lblHeureFintNewEvent:setHorizontalAlignment(CENTER_ALIGNMENT) + lblHeureFintNewEvent:setText(tostring(i)) + lblHeureFintNewEvent:onClick( + function() + -- set de l'heure de fin + if lblHeureFintNewEvent == oldLblHeureFinNewEvent then return end + + event.fin.heure = i + lblHeureFintNewEvent:setBackgroundColor(COLOR_LIGHT_GREY) + + oldLblHeureFinNewEvent:setBackgroundColor(COLOR_WHITE) + lblDateHeureFin:setText(formatDate(event.fin,"DD dd sh hh:mi")) + oldLblHeureFinNewEvent = lblHeureFintNewEvent + + lblMsgError:setText("") + + end + ) + + if i == event.fin.heure then + lblHeureFintNewEvent:setBackgroundColor(COLOR_LIGHT_GREY) + vListeHeureFinNewEvent:setIndex(i) + oldLblHeureFinNewEvent = lblHeureFintNewEvent + end + + end + + -- Affichage des Minutes + local vListeMinFinNewEvent = gui:vlist(winNewEvent, 260, 260, 40, 100) + vListeMinFinNewEvent:setSpaceLine(0) + local oldLblMinFinNewEvent + + for i=0, 55, 5 do + local lblMinuteFinNewEvent = gui:label(vListeMinFinNewEvent, 0, 0, 40, 13) + lblMinuteFinNewEvent:setFontSize(12) + lblMinuteFinNewEvent:setHorizontalAlignment(CENTER_ALIGNMENT) + lblMinuteFinNewEvent:setText(tostring(i)) + + lblMinuteFinNewEvent:onClick( + function() + + if oldLblMinFinNewEvent == lblMinuteFinNewEvent then return end + + event.fin.minute = i + lblDateHeureFin:setText(formatDate(event.debut,"DD dd sh hh:mi")) + + lblMinuteFinNewEvent:setBackgroundColor(COLOR_LIGHT_GREY) + oldLblMinFinNewEvent:setBackgroundColor(COLOR_WHITE) + oldLblMinFinNewEvent = lblMinuteFinNewEvent + + lblMsgError:setText("") + end + ) + + if i == event.fin.minute then + lblMinuteFinNewEvent:setBackgroundColor(COLOR_LIGHT_GREY) + vListeMinFinNewEvent:setIndex(int(i/5)) + oldLblMinFinNewEvent = lblMinuteFinNewEvent + end + end + + if not isNew then + local btnSupprimer = gui:label(winNewEvent, 60, 425, 200, 22) + btnSupprimer:setRadius(10) + btnSupprimer:setBorderSize(1) + btnSupprimer:setBackgroundColor(COLOR_LIGHT_GREY) + btnSupprimer:setHorizontalAlignment(CENTER_ALIGNMENT) + btnSupprimer:setVerticalAlignment (CENTER_ALIGNMENT) + btnSupprimer:setText("Supprimer") + btnSupprimer:onClick(function () + local oldEvent = deleteEvent(event.UID, event.debut.year, event.debut.month, event.debut.day) + + -- sauvegarde les modifs en fichier + saveDataFile(oldEvent.debut.year, oldEvent.debut.month, oldEvent.debut.day) + switchScreen(oldEvent.debut.year, oldEvent.debut.month, oldEvent.debut.day) + end + ) + end + + local btnEnregistrer = gui:label(winNewEvent, 60, 450, 200, 22) + btnEnregistrer:setRadius(10) + btnEnregistrer:setBorderSize(1) + btnEnregistrer:setBackgroundColor(COLOR_LIGHT_GREY) + btnEnregistrer:setHorizontalAlignment(CENTER_ALIGNMENT) + btnEnregistrer:setVerticalAlignment (CENTER_ALIGNMENT) + btnEnregistrer:setText("Enregistrer") + btnEnregistrer:onClick( + function() + local compare = compareEventDates(event.debut, event.fin) + + if event.name == "" then + lblMsgError:setText("Renseigner le nom de l'évènement") + elseif compare < 1 then + lblMsgError:setText("la date de fin doit être supérieure à la date de début") + else + saveEvent(event) + switchScreen(event.debut.year, event.debut.month, event.debut.day) + end + + end + ) +end --newEvent + + +-- --------------------------------------- +-- HELPER DE L'AFFICHAGE +-- --------------------------------------- + +function switchScreen(year, month, day) + + if (currentMode == "day") then + displayDay(year, month, day) + + elseif (currentMode == "week") then + displayWeek(year, month, day) + else + displayMonth(year, month) + end + +end --switchScreen + + +-- Création de la barre de menu en haut sur la fenetre active +function displayTopBarre() + + activeWin = gui:getWindow() + + local today = getToday() + + boxImgParametre = gui:box(activeWin, 10, 15, 25, 25) + imgParametre = gui:image(boxImgParametre, "menu.png", 0, 0, 25, 25) + imgParametre:setTransparentColor(COLOR_WHITE) + imgParametre:onClick(displayConfig) + + boxImgDay = gui:box(activeWin, 80, 15, 25, 25) + imgDay = gui:image(boxImgDay, "day.png", 0, 0, 25, 25) + imgDay:setTransparentColor(COLOR_WHITE) + imgDay:onClick(function() displayDay(today[1], today[2], today[3]) end) + + boxImgWeek = gui:box(activeWin, 130, 15, 25, 25) + imgWeek = gui:image(boxImgWeek, "week.png", 0, 0, 25, 25) + imgWeek:setTransparentColor(COLOR_WHITE) + imgWeek:onClick(function() displayWeek(today[1], today[2], today[3]) end) + + boxImgMonth = gui:box(activeWin, 180, 15, 25, 25) + imgMonth = gui:image(boxImgMonth, "month.png", 0, 0, 25, 25) + imgMonth:setTransparentColor(COLOR_WHITE) + imgMonth:onClick(function() displayMonth(today[1], today[2]) end) + + boxImgAdd = gui:box(activeWin, 280, 15, 25, 25) + boxImgAdd:setBackgroundColor(COLOR_DARK) + boxImgAdd:setRadius(20) + + local imgAdd = gui:image(boxImgAdd, "plus.png", 6, 6, 12, 12, COLOR_DARK) + boxImgAdd:onClick( + function() + local event = createEventObject(nil, nil, today[1], today[2], today[3]) + displayEvent(event) + end + ) + + menu = {boxImgParametre, boxImgDay, boxImgWeek, boxImgMonth} + +end --displayTopBarre + + +-- highlight de la box sélectionnée +function selectMenu(selectedBox) + + for _, box in ipairs(menu) do + if box == selectedBox then + box:setBackgroundColor(COLOR_LIGHT_ORANGE) + else + box:setBackgroundColor(COLOR_WHITE) + end + end + +end + + + +-- ------------------ +-- FONCTION DE DEBUG +-- ------------------ + + +function debugPrint(t, indent) + + + local debugType = true + + if not indent then print("[DEBUG] "..getVariableName(t))end + indent = indent or 0 + local spacing = string.rep(" ", indent) + + if type(t) == "table" then + for k, v in pairs(t) do + if type(v) == "table" then + if debugType then + print(spacing .."("..type(k)..") "..tostring(k) .. ":") + else + print(spacing ..tostring(k)) + end + debugPrint(v, indent + 1) + else + if debugType then + print(spacing .."("..type(k)..") "..tostring(k) .. ": " .. tostring(v) .." ("..type(v)..")") + else + print(spacing ..tostring(k) .. ": " .. tostring(v)) + end + end + end + else + if debugType then + print(spacing .. "("..type(t)..") "..tostring(t)) + else + print(spacing ..tostring(t)) + end + end +end + + +function getVariableName(var) + local name +-- for k, v in pairs(_G) do + for k, v in pairs(_G) do + if v == var then + name = k + break + end + end + if name then + return name + else + return "Variable not found" + end +end + + + +-- --------------------------------------- +-- FONCTIONS HELPER +-- --------------------------------------- + +-- Create a unique identifier for the event +function createUID() + + math.randomseed(time:monotonic()) + return time:monotonic()..math.random(999999) +end + + + +--renvoi x tronqué +function int(x) + return math.floor(x) +end + + +-- compare two date ate the event format +-- returns : +-- -1 if eventDebut > eventFin +-- 1 if eventFin > eventDebut +-- 0 if eventFin = eventDebut +function compareEventDates(eventDebut, eventFin) + + if eventFin.year ~= eventDebut.year then + return eventFin.year < eventDebut.year and -1 or 1 + elseif eventFin.month ~= eventDebut.month then + return eventFin.month < eventDebut.month and -1 or 1 + elseif eventFin.day ~= eventDebut.day then + return eventFin.day < eventDebut.day and -1 or 1 + elseif eventFin.heure ~= eventDebut.heure then + return eventFin.heure < eventDebut.heure and -1 or 1 + elseif eventFin.minute ~= eventDebut.minute then + return eventFin.minute < eventDebut.minute and -1 or 1 + else + return 0 + end + +end + + +-- Format a date given a specific pattern +-- yyyy year +-- mm month +-- MM month Full Name +-- sh month Short Name +-- dd day +-- DD day Of Week +-- hh heure +-- mi minute + +function formatDate (date, pattern) + + if (date.year) then m_year = date.year else m_year = date[1] end + if (date.month) then m_month = date.month else m_month = date[2] end + if (date.day) then m_day = date.day else m_day = date[3] end + if (date.heure) then m_heure = date.heure elseif date[4] then m_heure = date[4] else m_heure = 0 end + if (date.minute) then m_minute = date.minute elseif date[5] then m_minute = date[5] else m_minute = 0 end + + local year = m_year + local month = string.format("%02d", m_month) + local day = string.format("%02d", m_day) + local heure = string.format("%02d", m_heure) + local minute = string.format("%02d", m_minute) + local dayOfWeek = daysOfWeek[getDayOfWeek(m_year, m_month, m_day)] + local monthName = monthsName[m_month] + local monthShortName = monthsShortName[m_month] + + local result = pattern:gsub("yyyy", year) + :gsub("mm", month) + :gsub("MM", monthName) + :gsub("sh", monthShortName) + :gsub("dd", day) + :gsub("DD", dayOfWeek) + :gsub("hh", heure) + :gsub("mi", minute) + return result + +end --formatDate + +-- Retourne le numero de la semaine d'une date donnée +function getWeekNum(year, month, day) + local daysInMonth = {31, isLeapYear(year) and 29 or 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31} + local totalDays = 0 + + for m = 1, month - 1 do + totalDays = totalDays + daysInMonth[m] + end + + totalDays = totalDays + day + + return int((totalDays - 1) / 7) + 1 +end + +-- Add days "dayToAdd" to the "originalDate" +-- return new date to and array year, month, day +function addDaysToDate(originalDate, daysToAdd) + + local year = originalDate[1] + local month = originalDate[2] + local day = originalDate[3] + + -- Ensure input date is valid + if year < 1 or month < 1 or month > 12 or day < 1 or day > getDaysInMonth(year, month) then + return nil, "Invalid input date" + end + + local newYear, newMonth, newDay = year, month, day + + while daysToAdd ~= 0 do + if daysToAdd > 0 then + -- Adding days + local daysInCurrentMonth = getDaysInMonth(newYear, newMonth) + if newDay + daysToAdd <= daysInCurrentMonth then + newDay = newDay + daysToAdd + break + else + daysToAdd = daysToAdd - (daysInCurrentMonth - newDay + 1) + newDay = 1 + newMonth = newMonth + 1 + if newMonth > 12 then + newMonth = 1 + newYear = newYear + 1 + end + end + else + -- Subtracting days + if newDay + daysToAdd >= 1 then + newDay = newDay + daysToAdd + break + else + daysToAdd = daysToAdd + newDay + newMonth = newMonth - 1 + if newMonth < 1 then + newMonth = 12 + newYear = newYear - 1 + end + newDay = getDaysInMonth(newYear, newMonth) + end + end + end + + return {newYear, newMonth, newDay} +end -- addDaysToDate + + +-- return an array with the current year, month and day +function getToday() + + local today = time:get("y,mo,d") + return {today[1], today[2], today[3]} + +end + +-- récupère le jour de la semaine en fonction de la date +-- format européen : le 1er jours est le lundi +function getDayOfWeek(yy, mm, dd) + local mmx = mm + + if (mm == 1) then mmx = 13; yy = yy-1 end + if (mm == 2) then mmx = 14; yy = yy-1 end + + local val8 = dd -1 + (mmx*2) + math.floor(((mmx+1)*3)/5) + yy + math.floor(yy/4) - math.floor(yy/100) + math.floor(yy/400) + 2 + local val9 = math.floor(val8/7) + local dw = val8-(val9*7) + + if (dw == 0) then + dw = 7 + end + + return dw +end + + + -- Détermine si year est une année bixestile ou non +function isLeapYear(year) + return year % 4 == 0 and (year % 100 ~= 0 or year % 400 == 0) +end + + +-- renvoi le nombre de jours d'un mois et année donnée +function getDaysInMonth(year, month) + local days_in_month = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 } + local d = days_in_month[month] + + if month == 2 and isLeapYear(year) then d=29 end + return d +end + + + + +-- ------------------------------------- +-- LUA SERIALIZER +-- From Rochet2 w&)X2{W?w8N#(kLQUKTTsDO{MO7)zL4ve24*O_ZqtM5~sRCAYek=7ESBFCNy z+Cf}b9lL6J_OCtf9eB{_OWnlh&#P~|Tt6kC^PSeqHrqSvruQ0$h${yl6g75Q7oqy3 wDN;9gR-SQHMX>E*pZB*I_P13EJ-lDZ^!sOe$j;dlKtaLa>FVdQ&MBb@08@%_LI3~& literal 0 HcmV?d00001 diff --git a/storage/apps/calendrier/config.json b/storage/apps/calendrier/config.json new file mode 100644 index 00000000..5bd96ab9 --- /dev/null +++ b/storage/apps/calendrier/config.json @@ -0,0 +1 @@ +{"day":{"heureDebut":8, "heureFin":17}, "defaultView":"month", "displayBusinessWeek":true, "displayWeekNum":true} \ No newline at end of file diff --git a/storage/apps/calendrier/day.png b/storage/apps/calendrier/day.png new file mode 100644 index 0000000000000000000000000000000000000000..12986ba3c677bb938503440dec361f0ded038beb GIT binary patch literal 1442 zcmeAS@N?(olHy`uVBq!ia0vp^k|4~%1|*NXY)uAIjKx9jP7LeL$-D$|rlm%Bruq6Z zXaU(A46KYo49p-UK*+!-#lQ+?Gcb5DO2gSfjD`$MKyg7Jj%v?jV1cU10n#841;jwz z5W2j)TrV>(yEr+qAXP8FC>2(s|s5s zunH?68zii+qySb@l5MLL;TxdfoL`ixV5VoFXP{)qrJ$f-QG?WUP)qwZeFo6#1NP{E~&-IMVSR9nfZAN zAafIw@=Hr>m6Sjh!2#5rxdm{G@`|Cp0{TzCBC$Z?{pz^f3g{HTV~0 zrUC;8ticef9$5@seFQcOkOiR{Z1h0^iWI<**aM3KqtA{D=oeU0u;WVK%&`ZUaB@6d z978;Kw@$P54{;P}3upZq;1aN5i{hoko)WXD2{(Q-zsShQQBi!z|6^jn<&W|l2af~@ zEHzxHutg}N*D1u|L-*6lHrv_Wo8Fw;_0V_T-s0!y<`_ReGqZYoh}Bh&>8=({MXisW ztbY})-#=ru?b~U3p;Fl~w;!;-aWKEb$X?HO{OO6p{}0r@9Ez{tIJsE6hL^c)!SRIq z>^pe;b}-uVb{O{6Gv6{;G-c8In8S^=iyt(I=1L9d{g_E=gNz`!;ND1n1=h5h*#QQgO9|M(3wi zKe`vk{C3%@OVMk!HrcnnJ|I>ibM-5)^7;i5CyU>iCyFTvbsx0+8q$-})wu6?R@n7| zrS&%%bzcY(#3zxgwUElK2n&l_+tVvf*cc*QWaG@*-DLrHY?E zcl=pY!x_6#ecFra4^NjJuB%|Nie?qRtRWQdJntQE1!Gu5=<`~}(q#|R46B0I$HdIG zcYAzLlD#-Hgg=4rS|U?SqMu6GLot_Em$U7^rOapd7PvIiC{{jr_0IWaZL`-^zG!}< zzc{&Ag#E_nM3q$kUFiq&H?yZRT={z0+v;QA$DKa}SG6bmtmR8{Xy<-+oMTPn%H134 xwQuRlCa?_Wh;oX0rDk3n(yiPxI;OM5`YlBcVm%Q~loCIFuy1MdI; literal 0 HcmV?d00001 diff --git a/storage/apps/calendrier/fleche_droite.png b/storage/apps/calendrier/fleche_droite.png new file mode 100644 index 0000000000000000000000000000000000000000..30af1f5ad9bf7eb0538937565e75ec5db2ec14c9 GIT binary patch literal 1540 zcmeAS@N?(olHy`uVBq!ia0vp^B0#Ln!3HF!eAAKuQY`6?zK#qG8~eHcB(ehe3dtTp zz6=aiY77hwEes65fIz8sVAd>&u`8WOFdE zG72#;16hnf$iOJY05T28V(?;=hO>hhHK1yk7#P|!8CaldqJT6AcmOd-4}@l3z=$w$ z0TW!c$O2|KTN$J+=-JNO75STeGsl~}fnFS@8`FRQ;a}$&DOG|8(lt3220mPjpnP~`{ z@`|C}0(wv%B%^PrXP}QwTWUon4s9SAh&HglAlBJ{46}+1N-fUMDFr#p&fLfbYy*lQ z!hH}82=$?PnI(2GEoj2%x*`zr2y2i9(KYxNWu^iH66`KRsI!p8kko^GXBCiHk(v|X zl9`*DR}AutsUgs1SY^<4I_Kx)7X=q2Ca2l~Edpyn5<*uEwkHy&JxDT8oi_TQ*hY$d zNYVm}0@IcqmyJF=o!W6l?bJU4Ow}TuE{-7{yl+D{W-&PmoUL@zJ>s0BqT%7OP~fPZ zL`%dI{v%4UtF+eytCV&v5o5ZjwUUY5>ED54OFUF(SWWO~n!C1Z*UarZs&?LHE>c_1@J!@mYqs|KS-COd&6eA5xoh5h|9zstv23Dk%<>+k1B$cH$_X+bSQDa^ zx-fX_M6IV+RX8q0=#=qa$T0c!fIDGffCYns=u2lArPaUQyJ;wWe9AZd<%hZ@TK0;u zStWLDr{k{7aXk`u)hx$ChRxJ>_G13!mtQJ=eHgwqYOj;yr=Nf3NX)N%Q$OL2$fcjw znn_+YGgI%!O9w_CHpqLKcj1KCJC3TOU)QubL`}JvaU{LOXyzN{6%jh~nz?PC_#TlD zp2=v-Xa4x(kBztA?o-?qwbpF%&7CD(CKXc?_q<#=>E|k?lt=H~_cMK&lm6)LyPLO~ j7iI<7>^SB7PvL=i*YSG6%PF6uL1mk#tDnm{r-UW|v$P7N literal 0 HcmV?d00001 diff --git a/storage/apps/calendrier/fleche_gauche.png b/storage/apps/calendrier/fleche_gauche.png new file mode 100644 index 0000000000000000000000000000000000000000..ea88662183dc132007321e59f298066deaa44ece GIT binary patch literal 1137 zcmeAS@N?(olHy`uVBq!ia0vp^B0#Ln!3HF!eAAKuQjEnx?oJHr&dIz4a#~U&JkxxA z8MJ_G4hB|6AqHlU5+Gz?lwx27vl$q?7^UItAVv+S8YTvY_DlvAsG2As4FVoO4Ac#! znHMl3OkBVOS1q!D8O~M)X$yMxGXqF*7I;J!Gca%qgD@k*tT{jzGe%~HM3hAM`dB6B z=jtV<VstT4fPE4;bsH1+JHo@{EISEfi{E8w==W>t3(ll+GC>+vK+}V z5TAlYfnK%aveAbJn;n;A+(UK-1|~&M7sn6}-nUZ?y`2I@j@Rz1I{$ECM|Vq;OS4l~ zw1g91Ewf`rc2R-eqMZw)=3ZL4?9d0}9U;z>6N)2}cI;fXWc%m(k|$sHJTtx@Ca(AV z?ql2i#qVsN%ZVzsTz~wiK(uYgzsAp-gV%mo0fA@Fq*MBWpw2=1RVmuYU=v zy#8n_`EA16Y`ZL_i8oZ09Y5PnKb_0aV7>MI{OS~@S&~;x-U=QF&?sSw*co%}t-+dl zmO~uJCVDLKa9XkISCH0Jo);%7HtH02igX`sxc>TWlVGpgcgEjceiL0Sv^5u9&6?@H z_WJANk3UxQ_Wil=vP4f%a_Twu!m}<14{lfdd?J*gcz|`z0m=C-PuDC-_@DCScdaqw%aUIl zrw%4;;5=DX^VwnBGrm_A%CF8vEexnwcC5gop7CzkZr$yV1Lk_ 12 or day < 1 or day > getDaysInMonth(month, year) then + return nil, "Invalid input date" + end + + local newYear, newMonth, newDay = year, month, day + + while daysToAdd ~= 0 do + if daysToAdd > 0 then + -- Adding days + local daysInCurrentMonth = getDaysInMonth(newMonth, newYear) + if newDay + daysToAdd <= daysInCurrentMonth then + newDay = newDay + daysToAdd + break + else + daysToAdd = daysToAdd - (daysInCurrentMonth - newDay + 1) + newDay = 1 + newMonth = newMonth + 1 + if newMonth > 12 then + newMonth = 1 + newYear = newYear + 1 + end + end + else + -- Subtracting days + if newDay + daysToAdd >= 1 then + newDay = newDay + daysToAdd + break + else + daysToAdd = daysToAdd + newDay + newMonth = newMonth - 1 + if newMonth < 1 then + newMonth = 12 + newYear = newYear - 1 + end + newDay = getDaysInMonth(newMonth, newYear) + end + end + end + + return {newYear, newMonth, newDay} +end + + +-- return an array with the current year, month and day +function getToday() + + local today = time:get("y,mo,d") + return {today[1], today[2], today[3]} + +end + +-- récupère le jour de la semaine en fonction de la date +-- format européen : le 1er jours est le lundi +function getDayOfWeek(yy, mm, dd) + local mmx = mm + + if (mm == 1) then mmx = 13; yy = yy-1 end + if (mm == 2) then mmx = 14; yy = yy-1 end + + local val8 = dd -1 + (mmx*2) + math.floor(((mmx+1)*3)/5) + yy + math.floor(yy/4) - math.floor(yy/100) + math.floor(yy/400) + 2 + local val9 = math.floor(val8/7) + local dw = val8-(val9*7) + + if (dw == 0) then + dw = 7 + end + + return dw +end + + + -- Détermine si year est une année bixestile ou non +function isLeapYear(year) + return year % 4 == 0 and (year % 100 ~= 0 or year % 400 == 0) +end + + +-- renvoi le nombre de jours d'un mois et année donnée +function getDaysInMonth(month, year) + local days_in_month = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 } + local d = days_in_month[month] + + -- check for leap year + if (month == 2) then + if (math.mod(year,4) == 0) then + if (math.mod(year,100) == 0)then + if (math.mod(year,400) == 0) then + d = 29 + end + else + d = 29 + end + end + end + + return d +end + + +-- Renvoi la date au format +function formatLongDate(year, month, day) + + numDay = getDayOfWeek(year, month, day) + str = daysOfWeek[numDay].." "..tostring(day).." "..monthsName[month] + return str +end \ No newline at end of file diff --git a/storage/apps/calendrier/icon.png b/storage/apps/calendrier/icon.png new file mode 100644 index 0000000000000000000000000000000000000000..94084937e7db84e5496e4d685be105d1fbca873f GIT binary patch literal 4084 zcmZu!c|6qX_aA$f$dWZ{vNwZ4ng-nrE?LGhj4g&4*~SbrvR*|ZAxpL_W!E74GS(O= zS-VB{y%1&JD)AlF_ul)vzwh&TozFSX`MlrfJm;L}pHCFrSnni@APWEhIH~_T%#5mK zj^zX+^&N9a#!?jx!A$Q8psfGQN9ra8gVc91G6Kj^?Gpe78ZH3cF@*X6XaoTaKWqTN zfJW#q+l)pDKuh&=QpG0H4M6`3<4M)W%aJNn_D}8S=LdB2@*p^)@E9P@=Q`C-mre6` zj%?b$_%hjaf7?_X0MqE?MpexC->nG%0Q>V}p-Gl!7Xkoi&%0S5iAWK|BVB~5S)G7@I*J9m)LP!loQUEs39S7oanFh>zr8pUx~a3zpA3v2l7YZ zK}tYH(ElP4-CX`Y-v418fB8xKQPt06P-<%++CCT*5$9up!+C1{dq7aozY%|*6nY#I zVr_;Y;5>bgE7H8E1_k{;=f4RiK5iIlbAAw%e&PS=`!^o>zY_e@`HKJr9XIqJ4gNX3 zA71MCG+C&%{P!wovTUm476Slmt@^OvERf7CNM<}@NZ@cPCH46yp(tkNAXqq{{njmo z<;y*}bL7DS8y=lY7`P43gzZzLH_4nnLWji+?GSc~Cn-#phAqrBKOUezQjL?uHSO(w z8~6kCzQEgN$#9^VFx{}|Fz_sk06aCJ5L{awxnE@dy{M-%5!U`-kRK5xmO(|lWke8t`e&~J;Mu8#Uu>Q(m~45=iT z4umj$fQaltHdaxkY;t2`>qprLo=EI95l?qDwG@s9p8O<6`uD~8td zauM>9bRAy{aymcX?sKQP*?l3usn`Wsigz_4`Bc_)faltBHawOXccRUrxsqiT3_k z;}SRNQoU4DY|LUkf>5Dr>|`(5%iWj{b@9;l%HL_3Hr{S`s*FnHWo;3MKINUZ&x^~S zKBA;|qBX-ND>ieEmRApz4%P@BH!c+3>dO&mJQ?A&=U$=G5PZc|n%lZES-wt4(R29C zt2Qrw&6STfpiU)mg^Kvc#HK=XDNNic;V01!()K(s3?dd8?r(R$Fk``6(&>5IVcJDM zuw|JRpk$IU3;$a~ikFgWum?{gaW$$xR?D$lC}Y+qAUP=6&NRI0yK_hR0|O5leek5N zxwV_Oh9r#!lM!t69VdPzhTgrCA^K8T4rxcb{?2S;3<}wh4Kk2#sQ|C?ICNSBPj)x@ zN-B+v-OWu$cF|_JM~G{j4Fko9$A!n}SeGZy6f+41M2JB&nXUET>pYq}oltnF&a!mM zQ8+&vP0A;slXYG^R}0p><56kQ_4=O0?pVgOB7_j8W5BCmuOQ7SR+Y?-rKgu&+Te<| zKRlfyYD%oNU3Ps7-zScqI^;Vy{yVNi&uPF-6;s~{zv?s;`!uoujgR2uTfS8Ww#A^# z!k0lb7tlqhQA%7wMm_7EQ4o{!H@d!9r_j36gTVU7+&m8-s4~18qPb5_i+Ftw$DU;E zo{QRcM3f_*bVPE*^$iSwULAc~B_}2EOn&yUeOOMhaTDU=3X1_w!fkD1(~ISh*k0F0 z61E!obnvX$L#2}Ffie~O*}}rX2V?x*MapV?ay9+%qL5h%!^*m8p2rh&j%AAyyEDS) zFY&#u4!R&&P(UNXQSWtKUfa5H&F3uFd~QM}53c_b{Z!$X3A@;7n4HvDdrNq<+8da4 z&00{Yj%LOqijz(p^>anKu*fP4_=@s;D*%23f%PtC+Tng5^5N_}ZFNA^d&YMaEZO z=;}CLw$y^bU=?cVD)$uE`L#lV6tVxP{^TGS4FG|eyNE>4&Rss=C zIy=ITu?RvrRF&e7S^iyhstTnoZ};K~NU=S^Tf~ian{ss_yuK^GvWsUlmu|Y`JA~o1 zd;ity?5aW$oRR45(SakIr{tj2elpzpdf3O-s|erynJ-cPH@@7pzD+s&ylXjN7HTbUJMwqHYT?) zn>S?%wXpbbYja&$Ap4~os;j}s&q$ClcA!eARI|-TQbiZnL*ZKX(`rL7k1Qc6PM ziNyiCh*!}O>D$E1>a*afvGBnpWB1kDR+^okPHW*lfVK(h(kTyigXVyCTdX!cFlLU* z*}Q25ZGLB4Wg9ehbU&QgbI+oO_a<(YpjL;iPdL| zKuO82hg?reN;#L*kqSer?iELP|=v zy#!hO4mWi#qDKUAKao36$!*U6xwO>s_3rM{j~anP@FI~xk|ig7;``oLP91nvk4J@! zKttB$)&;4KA^3H&(8|fR4==>hW*BF}&d%>{U*U$82i%=gZ5qhiSB_HoGt|I0Q?i>* zfzAv)kO}Ebx{jS|y1kKuAJsiHDf~8%dE4O7GVqsWB~DUIlZE?pqet-Keq`T{KxSml*vJ^W~b;sHHNO zp}oa51R;;9K(Kxh{bXaf>6z!99^?{(l)5snV9u}&P>6E$wckGWQzlCHacM?u`$g>- zXT7+J?){poMDDO@_x9{T&J%BWrHxaZcHet`viW{JxYdV!p@qoT`mGXa-9-UURB{(> zL|%_@UM%)wz9~ew9@EZo1SJ_?_F+k^>}58@(_6WQTRK6G+Qgw6n#=)PBAr&zh3iYT zqI#`by0~?*fqb`dNUu{nR}EkH~%W-SCU4 zS5C-bJ0shaz6IBk=6kkY%5LvV#m^nIj1?!vQxejYeV!PINGU`tpwHr7c7(540h@r^ zG%;t?(hSlg$2rg3tlXk8JnH#PhdcE^F(N_N`OV$vNVerj@d2Zb+=;gndqUo%DnWCX zo%dPK4Iu>as%pj1UcN07d+0TgnYno-x*e*VssJ`=p^PkAiJjFD?nzY;n-Hz-^%|9> zwH|G;y-@mf#c9<&M7;yX3)`*iF^8Hj;VKMiZYy zL;$96vr(@d9JFI*XTrnh{H~{*Qt;4PpgUu`i7*AbV3U&SsPkAOn7&c+g@mSf!cHAS zLV{`Oot%*>=c3{$R$c{ob66rQe2X@Qa#oMivRdS-Lo;2pOYDn2Qo%?T?nOqdPQcAs zl%$7k1#$N?61t)`ajJpCfsbc1zfYNx);C_ul;GRI(u&^2veeJa)Nf~NTkk$?AZ)Cz zfKbzqCXw~a+@9k#G#T$oDOuc7G6iOdTt-_P0_gU((&WncWDS}uaFZEI-fJ1mDI9g#Pb$sC zqJ5-01{!DM!Fmhs~BPxYPm=maYw|LKoye>;~5{D>aiF$oyZ} zhU;WmcR!EwL4$H?O3%m&*mD}(NzBW=EB)zvte3~QnZyU7MU##PZ^2{P=2%ir>515( zp#xZ<^HgpDvLW!~`TF0m1wPiw92M9ubqf}+$wq{vfVSR!3gwHacodU)`7;@&*9CB< zK~8xAvqjp=hey(6|10;gO?#hoR;j}*kaX@TK3#|*WwsUc>c<$ob?>{>WEQ{k3SnW9 ze^Y(&q(zqOP&5mNjj)2WoTSl#yh&}6eEHGNU830w39@sriXS`U&VbplVFRVx7tx;< zqd)n1<8EASWk*B<%e{L^rf6J(2DZIM`mulDn{e+$j7mHTD3u+56Qf0fw`B^?GWTkg zx2msC_R!rKDEf1AA@%&B5LC?e9rjh{=Fkdn;+(*Z+BMlXwI0LWJ;66Zd`+hw{9%YZ l(h9ts()DO<_>MO6kU@^$6MkGm0fWR`wt=CKDz(_ literal 0 HcmV?d00001 diff --git a/storage/apps/calendrier/manifest.json b/storage/apps/calendrier/manifest.json new file mode 100644 index 00000000..a497aa5d --- /dev/null +++ b/storage/apps/calendrier/manifest.json @@ -0,0 +1,4 @@ +{ + "access": ["files", "files_root", "gsm", "gui", "hardware", "time", "web", "web_paxo"], + "name": "Calendrier" +} diff --git a/storage/apps/calendrier/menu.png b/storage/apps/calendrier/menu.png new file mode 100644 index 0000000000000000000000000000000000000000..89f28d8c4376dca6b428b21633cbdf547f4d4d40 GIT binary patch literal 1119 zcmeAS@N?(olHy`uVBq!ia0vp^k|4~%1|*NXY)uAIjKx9jP7LeL$-D$|rlm%Bruq6Z zXaU(A46KYo49p-UK*+!-#lQ+?Gcb5DO2gSfjD`$MKyg7Jj%v?jV1cU10n#9l0K`Du z5W2j)TrV>(yEr+qAXP8FC>XQ2>tmIipR1RclAn~SSCLx)(#2p?VFhI7rj{fsROII56h?X&sHg; zq@=(~UmxV1a$}H3^bIX7E%gnI^o@*kfhu&1EAvVcD|GXUl_7?}%yCIAPA7W}}ZGh_1oE zC^HopIA9HiQ1!@S=;|Y|S%54E)nKC!3Q(i~hQuCN6c~MWTtL6Tl7b!ACzD01fC*F6 z)5S5wgZJ)KYraDU0xryq2YGk!ipsJ-^b*k%I#_1GvWI~ zn}f@w9w_M_c7B=ma!ty528$0m3l{q6#Xo7ZnY7nLti#~PvMoz29$cBW!&klFh>D!& zjMRmFcc#g|nk|1%;Hqor+QTx@zBOsiymC)-Klr`f-B z&kavoss2+Y>eu>Nq6NDB8A|$3|Kz`SNn94fTlnDgwj-OlehB@_*;QzHr2JC&{p#cA zneOK`Y?%MId}ATUf|8Xi{s)_*l^Ybwc6|SyqNjFW^oQD^I>pCg4^@_hw7bmXTQ}j| X^6#^Lui8}S1j(yEr+qAXP8FC>2(s|s5s zunH?68zii+qySb@l5MLL;TxdfoL`ixV5VoFXP{)qrJ$f-QG?WUP)qwZeFo6#1NP{E~&-IMVSR9nfZAN zAafIw@=Hr>m6Sjh!2#5rxdm{G@`|Cp0{TzCBC$Z?{pz^f3g{HTV~0 zrUC;8ticef9$5@seFQcOkOiR{Z1h0^iWI<**aM3KqtA{D=oeU0u;WVK%&`ZU_*gt$ z978;Kw@%%iJ=Iab-M)9$kDgga{3dGLVD0Hzps`&|hJTEHuw1^tm}eGme4l4cd)^Q3-3o6r4y}G5f9=q&H?rs3f6T2slOC5J z@|Pw5!gH3-ZvT@%R)3y({ZHohLiX;2XSv7Lt)5|WpswVQj!XQSja$FH@;3e#tMu;H zi}viCJ++4Uznpc-_DNjpnY`n(@P{jxm`}Y|wrLjqAid4WzUMHD%bl%zKgcXQF#BZQ z2BVcc>p#XB=kPP1E>>r{Isar~ZRYivJN5;#oK3%%rgAO%@Y4mFuDWxX_N$#O>Xlr7 zuK4NN(yMwW?=Gx7GyRkMW8I7F9J9|cdoQV78~auF_l)|JpH+g7d4>IEerBBi+PC7; z(_gq$&-5<)!bx$*qRzbS6kEle?{D&YeeRmrS-)rd zo?HCvTk0u?ZQE~Zv*?Bhugd;@|8?rs-EW*7!e^Ab`mcGNyPvwBbRg@@kt3|^mPc1#rOPM-W_ zLC5ryvEm;imJ67Cp2I%>SnO{@2Cbv5^AG;}akg;b-@tQv^BAiib57l`sc%R2-2-+% zzP@1OUss`1Yh*6Px;{=z<=E2l%|&vLgO)xsoL{-RJ~Zv+*YozQmq5j(r>mdKI;Vst E04LgF=Kufz literal 0 HcmV?d00001 diff --git a/storage/apps/calendrier/parameter.png b/storage/apps/calendrier/parameter.png new file mode 100644 index 0000000000000000000000000000000000000000..ecb71d14d16ebb75ed9b0ae41e8098c24d10b19f GIT binary patch literal 1484 zcmeAS@N?(olHy`uVBq!ia0vp^k|4~%1|*NXY)uAIjKx9jP7LeL$-D$|rlm%Bruq6Z zXaU(A46KYo49p-UK*+!-#lQ+?Gcb5DO2gSfjD`$MKyg7Jj%v?jV1cU10n#9l0K`Du z5W2j)TrV>(yEr+qAXP8FC>XQ2>tmIipR1RclAn~SSCLx)(#2p?VFhI7rj{fsROII56h?X&sHg; zq@=(~UmxV1a$}H3^bIX7E%gnI^o@*kfhu&1EAvVcD|GXUl_7?}%yCIAPA7W}}ZGh_1oE zC^HopIA9HiQ1!@S=;|Y|S%54E)nKC!3Q(i~hQuCN6c~MWTtL6Tl7b!ACzD01fC*=s zr;B5V2k+Kv)>)x}B5V&HYe(JC=(v$3RqdFZsP>3uo%03FBThb(13CO2hDkOo>0%LK z)m_6PYP#-$cG-}+K@ebJNuf~y%X zicd{#dVbX1_tH(p!pUVZ{k42C`lri2dVX~Jyie!n!d~SUZxsCY*!`dRgxok6j#hq+Fs_lBh^1{uZPjkhdo?O0~ zJ-L>hZQ7}semB?sd|9xpSNZX)$4^!-mRmD-?vo$C_w~Lvtz7x!_@WsiQ`cw;-S~O5 zvwinuiF>A&T&K6Iv`^pbn?C(`N8*mCPmv#UKNe3eDf5_P!@FYfyj?f%N%<9Ye3RI8 z%G&f_;FLd$c3f4NJ6B#vKYp&V!R19Sth`EQBxskcy5RV+Y9ssK1t;|NqP5~>zh03I zpEUi=J^k*TuBI~EJ)G1ER%~lzDXWVXKN0S3Yxnhd(yEr+qAXP8FC>2(s|s5s zunH?68zii+qySb@l5MLL;TxdfoL`ixV5VoFXP{)qrJ$f-QG?WUP)qwZeFo6#1NP{E~&-IMVSR9nfZAN zAafIw@=Hr>m6Sjh!2#5rxdm{G@`|Cp0{TzCBC$Z?{pz^f3g{HTV~0 zrUC;8ticef9$5@seFQcOkOiR{Z1h0^iWI<**aM3KqtA{D=oeU0u;WVK%&`ZUaPE7$ zIEHxeuAREO-#1XCef>wN{KugRi6R*Sf=NxM>=%5oUvZ_)O-ZWv*6P3&>Rg=~DpH+J zDo%~FB{@HGI5j`~wXgQuu4{943JKSpe7|PzwYdJh-|W)o`z=4{bR|p=jQK$T&_z%&#_RFPzcxV1xywp0q=if0)v;LoFZf{f#ua0M}X|UQM6#juv%7(>v z-=LH4zEPTNyux15OH!PMtac;L8h#_H#x2bg{cW!>gETA*z8e8MgN5ZgDmSKoar zq<5<3*R1^^+nb+iiHc7!cXqtB(Sl3<@Lny2H)TcA^R7lD+I_wiyYiarx**1NO3rsv z>a)waTYv7_Al~SAV;0Bkjk0$HgdO_BtIkMf(wJ*|*xY@4M z9&UMDwyy5$qlt1>Y0phe7dw<}VP@Zb^6t0fMMw7~@--j*v1`KP3)^3ri2Pl@C$Ro~ z@{7n_ry?1z9?bo=Sh{uks<(ktnadp>t9)@5mJ6HHx$E(r!g;$7&-oZpf@heh@CnsuMUOV$|tkTm&`vemUGOXOo&9V@%o#-}%C+4kHIKmOXIP*lod zA(PGG8oy)gHInyMNKDwS9VWE;_Q^l5Ux|Mb{>7$oX#d4o=^|g7?k;)h?>gsmw7~5L zwkzIqS4ebOd~lon^Nj4&1Del1YtOlx{CZ2Iju8JVg-44fFLGz9_h>BJ5Z)^5d-(ZP z%`e;5Uk-HmpIyK*P5-+6-2B7;TYlcC_1s&p5w!J9m9lnUH+8=9Bl=yw5-R@AY}cc{Z#447=ENGs(W! Q?*NsAp00i_>zopr0K)r0TmS$7 literal 0 HcmV?d00001 diff --git a/storage/apps/calendrier/week.png b/storage/apps/calendrier/week.png new file mode 100644 index 0000000000000000000000000000000000000000..6fe9ae89e4420a4986aa1a26c3ff97145a919491 GIT binary patch literal 1433 zcmeAS@N?(olHy`uVBq!ia0vp^k|4~%1|*NXY)uAIjKx9jP7LeL$-D$|rlm%Bruq6Z zXaU(A46KYo49p-UK*+!-#lQ+?Gcb5DO2gSfjD`$MKyg7Jj%v?jV1cU10n#841;jwz z5W2j)TrV>(yEr+qAXP8FC>2(s|s5s zunH?68zii+qySb@l5MLL;TxdfoL`ixV5VoFXP{)qrJ$f-QG?WUP)qwZeFo6#1NP{E~&-IMVSR9nfZAN zAafIw@=Hr>m6Sjh!2#5rxdm{G@`|Cp0{TzCBC$Z?{pz^f3g{HTV~0 zrUC;8ticef9$5@seFQcOkOiR{Z1h0^iWI<**aM3KqtA{D=oeU0u;WVK%&`ZUaFRV; z978;Kw@%yLCE_U3RxMk&cXwPcv#U>ti(#0Vk=a+?8YahhhxkKBF1XBe_#hZ#U|=fX zQxbaZ_uY@bSN)F9iejs}@bls9;L>MbR%VBnUfyEWD|tA4M#-Obr#@!ZpZ#$C<1@qg zm9v+w+t7BG>-|ICH*JSMu*Mza@Y%;7mcV?^@z1e$E!RIV@*Rr%!TEf_mJI&<=7X<{ zUQ}nW%4Yc%%dU=JEmYsX>7TaM#JbNfrSl)Ai^?3-jbQ(}(sZf1*xz_dUaf0!+SP09 zwl8~PIRE_GTPKVxTr(SzW~!|XUb1idGyU1e>Pr4w@16Mb%;I*vGVMP5O{(ZTC3j(!(exW@Zhm|8w#s$q7rxz#Kdb9~U0IWPB%)d=Yg+Dq*>AID zf`hlbl$o~J#l#8Ft)88_0-OqV4VzJjMF82Pg(ka3p!>s Date: Sun, 8 Sep 2024 15:52:40 +0200 Subject: [PATCH 03/13] ajout methode setTransparentColor --- lib/gui/src/elements/Image.cpp | 9 +++++++++ lib/gui/src/elements/Image.hpp | 1 + lib/lua/src/lua_file.cpp | 2 ++ lib/lua/src/lua_image.cpp | 6 +++++- lib/lua/src/lua_image.hpp | 2 +- 5 files changed, 18 insertions(+), 2 deletions(-) diff --git a/lib/gui/src/elements/Image.cpp b/lib/gui/src/elements/Image.cpp index de5ce499..4a0a0db7 100644 --- a/lib/gui/src/elements/Image.cpp +++ b/lib/gui/src/elements/Image.cpp @@ -98,4 +98,13 @@ namespace gui::elements m_surface = gui::ImagesList::loadImage(this->m_path, this->m_width, this->m_height, background); localGraphicalUpdate(); } + + void Image::setTransparentColor(color_t color){ + if ( ! m_surface) { + //std::cout << "[Image] m_surface is null"; + load(color); + } + m_surface->setTransparentColor(color); + m_surface->setTransparency(true); + } } \ No newline at end of file diff --git a/lib/gui/src/elements/Image.hpp b/lib/gui/src/elements/Image.hpp index bb103c0d..eef41a52 100644 --- a/lib/gui/src/elements/Image.hpp +++ b/lib/gui/src/elements/Image.hpp @@ -15,6 +15,7 @@ namespace gui::elements void render() override; void load(color_t background = COLOR_WHITE); + void setTransparentColor(color_t color); private: storage::Path m_path; diff --git a/lib/lua/src/lua_file.cpp b/lib/lua/src/lua_file.cpp index 0d874b83..e2e4888b 100755 --- a/lib/lua/src/lua_file.cpp +++ b/lib/lua/src/lua_file.cpp @@ -478,6 +478,8 @@ void LuaFile::load() sol::base_classes, sol::bases()); lua.new_usertype("LuaImage", + "setTransparentColor", &LuaImage::setTransparentColor, + sol::base_classes, sol::bases()); lua.new_usertype("LuaLabel", diff --git a/lib/lua/src/lua_image.cpp b/lib/lua/src/lua_image.cpp index f1c8f0c0..46546717 100644 --- a/lib/lua/src/lua_image.cpp +++ b/lib/lua/src/lua_image.cpp @@ -4,4 +4,8 @@ LuaImage::LuaImage(LuaWidget* parent, storage::Path path, int x, int y, int widt { widget = new Image(path, x, y, width, height, background); init(widget, parent); -} \ No newline at end of file +} + +void LuaImage::setTransparentColor(color_t color){ + widget->setTransparentColor(color); +} diff --git a/lib/lua/src/lua_image.hpp b/lib/lua/src/lua_image.hpp index 47df663f..19b26400 100644 --- a/lib/lua/src/lua_image.hpp +++ b/lib/lua/src/lua_image.hpp @@ -7,7 +7,7 @@ class LuaImage : public LuaWidget { public: LuaImage(LuaWidget* parent, storage::Path path, int x, int y, int width, int height, color_t background = COLOR_WHITE); - + void setTransparentColor(color_t color); Image* widget = nullptr; }; From a8f11e2bd50a09cb9b4c0994fba0b6906715d6c4 Mon Sep 17 00:00:00 2001 From: pymuzard Date: Mon, 9 Sep 2024 00:05:17 +0200 Subject: [PATCH 04/13] gestion autoSelection sur les listes --- lib/gui/src/ElementBase.cpp | 9 ++++++ lib/gui/src/ElementBase.hpp | 2 ++ lib/gui/src/elements/List.cpp | 58 ++++++++++++++++++++++++++++++----- lib/gui/src/elements/List.hpp | 9 ++++++ lib/lua/src/lua_file.cpp | 7 +++++ lib/lua/src/lua_list.hpp | 3 ++ 6 files changed, 81 insertions(+), 7 deletions(-) diff --git a/lib/gui/src/ElementBase.cpp b/lib/gui/src/ElementBase.cpp index beb3de45..9aee92df 100644 --- a/lib/gui/src/ElementBase.cpp +++ b/lib/gui/src/ElementBase.cpp @@ -634,3 +634,12 @@ std::shared_ptr gui::ElementBase::getSurface() { void gui::ElementBase::forceUpdate() { localGraphicalUpdate(); } + + +gui::ElementBase *gui::ElementBase::getElementAt(int index) { + + if (index >=0 && index < m_children.size()) { + return m_children[index]; + } + +} diff --git a/lib/gui/src/ElementBase.hpp b/lib/gui/src/ElementBase.hpp index 82047fa3..b9e068b2 100644 --- a/lib/gui/src/ElementBase.hpp +++ b/lib/gui/src/ElementBase.hpp @@ -87,6 +87,8 @@ namespace gui ElementBase *getParent() const; void addChild(ElementBase *child); + ElementBase *getElementAt(int index); + ElementBase *m_parent; std::vector m_children; static int16_t touchX, touchY; diff --git a/lib/gui/src/elements/List.cpp b/lib/gui/src/elements/List.cpp index e22bb2de..9fd7d355 100644 --- a/lib/gui/src/elements/List.cpp +++ b/lib/gui/src/elements/List.cpp @@ -13,7 +13,9 @@ namespace gui::elements m_lineSpace = 25; m_verticalScrollEnabled = true; m_hasEvents = true; - m_selectionFocus == SelectionFocus::UP; + m_selectionFocus = SelectionFocus::UP; + m_selectionColor = COLOR_LIGHT_GREY; + m_autoSelect = false; } VerticalList::~VerticalList() = default; @@ -41,21 +43,53 @@ namespace gui::elements void VerticalList::setIndex(int index) { if(m_focusedIndex >= 0 && m_focusedIndex < m_children.size()) + { + if (m_autoSelect) { + select(index); + } + else { + m_focusedIndex = index; + updateFocusedIndex(); + } + } + + } + + void VerticalList::select(int index) + { + if(index >= 0 && index < m_children.size()) { m_focusedIndex = index; + ElementBase *oldSelection = this->getElementAt(m_oldFocusedIndex); + oldSelection->setBackgroundColor(m_backgroundColor); + + ElementBase *selection = this->getElementAt(index); + selection->setBackgroundColor(m_selectionColor); + + m_oldFocusedIndex = index; + updateFocusedIndex(); } } + + void VerticalList::setSelectionColor(color_t color){ + m_selectionColor = color; + } void VerticalList::setSpaceLine(uint16_t y) { m_lineSpace = y; } + void VerticalList::setAutoSelect(bool autoSelect) { + m_autoSelect = autoSelect; + } + + void VerticalList::updateFocusedIndex() { eventHandlerApp.setTimeout(new Callback<>([&](){ - std::cout << "updateFocusedIndex" << std::endl; + //std::cout << "updateFocusedIndex" << std::endl; if(m_children.size() == 0) { m_focusedIndex = 0; @@ -67,7 +101,7 @@ namespace gui::elements m_verticalScroll = m_verticalScroll - getHeight() / 2 + m_children[m_focusedIndex]->getHeight() / 2; localGraphicalUpdate(); - std::cout << "updateFocusedIndex end: " << m_selectionFocus << std::endl; + //std::cout << "updateFocusedIndex end: " << m_selectionFocus << std::endl; // for (int i = 0; i < m_children.size(); i++) // { @@ -83,8 +117,13 @@ namespace gui::elements { if(m_focusedIndex != 0) { - m_focusedIndex--; - updateFocusedIndex(); + if (m_autoSelect) { + select(m_focusedIndex - 1); + } + else { + m_focusedIndex--; + updateFocusedIndex(); + } } } @@ -92,8 +131,13 @@ namespace gui::elements { if(m_focusedIndex+1 != m_children.size()) { - m_focusedIndex++; - updateFocusedIndex(); + if (m_autoSelect) { + select(m_focusedIndex + 1); + } + else { + m_focusedIndex++; + updateFocusedIndex(); + } } } diff --git a/lib/gui/src/elements/List.hpp b/lib/gui/src/elements/List.hpp index 664e3ccc..aaec6e06 100644 --- a/lib/gui/src/elements/List.hpp +++ b/lib/gui/src/elements/List.hpp @@ -31,11 +31,20 @@ namespace gui::elements void setSelectionFocus(SelectionFocus focus); int getFocusedElement(); + void select(int index); + void setSelectionColor(color_t color); + void setAutoSelect(bool autoSelect); + private: int16_t m_focusedIndex = 0; + int16_t m_oldFocusedIndex = 0; + uint16_t m_lineSpace = 0; SelectionFocus m_selectionFocus = SelectionFocus::UP; + color_t m_selectionColor; + bool m_autoSelect; + }; class HorizontalList final : public ElementBase diff --git a/lib/lua/src/lua_file.cpp b/lib/lua/src/lua_file.cpp index e2e4888b..0ab75529 100755 --- a/lib/lua/src/lua_file.cpp +++ b/lib/lua/src/lua_file.cpp @@ -528,12 +528,19 @@ void LuaFile::load() "setSpaceLine", &LuaVerticalList::setSpaceLine, "setSelectionFocus", &LuaVerticalList::setFocus, "getSelected", &LuaVerticalList::getSelected, + "select", &LuaVerticalList::select, + "setSelectionColor", &LuaVerticalList::setSelectionColor, + "setAutoSelect", &LuaVerticalList::setAutoSelect, sol::base_classes, sol::bases()); lua.new_usertype("LuaHList", //"add", &LuaHorizontalList::add, + "setSpaceLine", &LuaHorizontalList::setSpaceLine, sol::base_classes, sol::bases()); + lua.set("SELECTION_UP", VerticalList::SelectionFocus::UP); + lua.set("SELECTION_CENTER", VerticalList::SelectionFocus::CENTER); + lua.set("LEFT_ALIGNMENT", Label::Alignement::LEFT); lua.set("RIGHT_ALIGNMENT", Label::Alignement::RIGHT); lua.set("CENTER_ALIGNMENT", Label::Alignement::CENTER); diff --git a/lib/lua/src/lua_list.hpp b/lib/lua/src/lua_list.hpp index a0f888df..80626836 100644 --- a/lib/lua/src/lua_list.hpp +++ b/lib/lua/src/lua_list.hpp @@ -13,6 +13,9 @@ class LuaVerticalList : public LuaWidget void setIndex(int i = 0) { this->widget->setIndex(i); }; void setFocus(VerticalList::SelectionFocus focus) { std::cout << "setFocus: " << focus << std::endl; this->widget->setSelectionFocus(focus); }; int getSelected() { return this->widget->getFocusedElement(); }; + void select(int index) { this->widget->select(index); }; + void setSelectionColor(color_t color) { this->widget->setSelectionColor( color); }; + void setAutoSelect(bool autoSelect) { this->widget->setAutoSelect(autoSelect); }; VerticalList* widget = nullptr; }; From 6a67245b129588ce40d8d24a7a1e2cd6a846ea10 Mon Sep 17 00:00:00 2001 From: pymuzard Date: Mon, 9 Sep 2024 07:55:48 +0200 Subject: [PATCH 05/13] correction ElementBase::getElementAt --- lib/gui/src/ElementBase.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/gui/src/ElementBase.cpp b/lib/gui/src/ElementBase.cpp index 9aee92df..0fc609ba 100644 --- a/lib/gui/src/ElementBase.cpp +++ b/lib/gui/src/ElementBase.cpp @@ -641,5 +641,6 @@ gui::ElementBase *gui::ElementBase::getElementAt(int index) { if (index >=0 && index < m_children.size()) { return m_children[index]; } + return nullptr; } From 242c81efe54d54e28818053941c082257e868a61 Mon Sep 17 00:00:00 2001 From: pymuzard Date: Mon, 9 Sep 2024 07:57:56 +0200 Subject: [PATCH 06/13] robistesse VerticalList::select --- lib/gui/src/elements/List.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/lib/gui/src/elements/List.cpp b/lib/gui/src/elements/List.cpp index 9fd7d355..8437655d 100644 --- a/lib/gui/src/elements/List.cpp +++ b/lib/gui/src/elements/List.cpp @@ -61,10 +61,12 @@ namespace gui::elements { m_focusedIndex = index; ElementBase *oldSelection = this->getElementAt(m_oldFocusedIndex); - oldSelection->setBackgroundColor(m_backgroundColor); + if (oldSelection != nullptr) + oldSelection->setBackgroundColor(m_backgroundColor); ElementBase *selection = this->getElementAt(index); - selection->setBackgroundColor(m_selectionColor); + if (selection != nullptr) + selection->setBackgroundColor(m_selectionColor); m_oldFocusedIndex = index; From 15d614191f091118d694e979f1bbec9eaf243a0d Mon Sep 17 00:00:00 2001 From: pymuzard Date: Mon, 9 Sep 2024 13:04:19 +0200 Subject: [PATCH 07/13] ajout event onSelect sur vList --- lib/applications/src/launcher.cpp | 10 +- lib/gsm/src/gsm.cpp | 4 +- lib/gui/src/elements/List.cpp | 12 +- lib/gui/src/elements/List.hpp | 5 + lib/lua/src/lua_file.cpp | 1 + lib/lua/src/lua_list.cpp | 87 +++- lib/lua/src/lua_list.hpp | 37 +- lib/lua/src/lua_widget.cpp | 10 +- lib/lua/src/lua_widget.hpp | 94 ++--- storage/apps/calendrier/app.lua | 492 ++++------------------- storage/apps/calendrier/config.json | 2 +- storage/apps/calendrier/data/20249.dat | Bin 0 -> 381 bytes storage/apps/calendrier/gestionDate.lua | 77 ++-- storage/apps/calendrier/gestionDebug.lua | 56 +++ 14 files changed, 361 insertions(+), 526 deletions(-) create mode 100644 storage/apps/calendrier/data/20249.dat create mode 100644 storage/apps/calendrier/gestionDebug.lua diff --git a/lib/applications/src/launcher.cpp b/lib/applications/src/launcher.cpp index 25fc4081..8b667f80 100644 --- a/lib/applications/src/launcher.cpp +++ b/lib/applications/src/launcher.cpp @@ -91,7 +91,7 @@ void applications::launcher::init() { } void applications::launcher::update() { - std::cout << "Launcher update" << std::endl; + // std::cout << "Launcher update" << std::endl; if (dirty) { // If dirty, free to force redraw it @@ -102,7 +102,7 @@ void applications::launcher::update() { if (!allocated) { // If launcher has been freed, redraw it draw(); - std::cout << "Launcher redraw" << std::endl; + //std::cout << "Launcher redraw" << std::endl; } // Update dynamic elements @@ -225,7 +225,7 @@ void applications::launcher::draw() { launcherWindow = std::make_shared(); } - std::cout << "launcher::update 1.1" << std::endl; + //std::cout << "launcher::update 1.1" << std::endl; StandbyMode::triggerPower(); @@ -238,7 +238,7 @@ void applications::launcher::draw() { launcherWindow->addChild(clockLabel); - std::cout << "launcher::update 1.2" << std::endl; + //std::cout << "launcher::update 1.2" << std::endl; // Date dateLabel = new Label(55, 89, 210, 18); @@ -249,7 +249,7 @@ void applications::launcher::draw() { launcherWindow->addChild(dateLabel); - std::cout << "launcher::update 1.3" << std::endl; +// std::cout << "launcher::update 1.3" << std::endl; // Battery icon const auto batteryIconDarkPath = storage::Path("system/icons/dark/" + getBatteryIconFilename() + "_64px.png"); diff --git a/lib/gsm/src/gsm.cpp b/lib/gsm/src/gsm.cpp index 3185070f..2e8508dc 100644 --- a/lib/gsm/src/gsm.cpp +++ b/lib/gsm/src/gsm.cpp @@ -1113,7 +1113,7 @@ namespace GSM int getNetworkStatus() { - std::cout << "networkQuality: " << networkQuality << std::endl; + // std::cout << "networkQuality: " << networkQuality << std::endl; return networkQuality; } @@ -1124,7 +1124,7 @@ namespace GSM { networkQuality = atoi(o.substr(o.find("+CSQ: ") + 5, o.find(",") - o.find("+CSQ: ") - 5).c_str()); } - std::cout << "networkQuality: " << networkQuality << std::endl; + //std::cout << "networkQuality: " << networkQuality << std::endl; } void getNetworkQuality() diff --git a/lib/gui/src/elements/List.cpp b/lib/gui/src/elements/List.cpp index 8437655d..025114d5 100644 --- a/lib/gui/src/elements/List.cpp +++ b/lib/gui/src/elements/List.cpp @@ -55,6 +55,15 @@ namespace gui::elements } + void VerticalList::setIsSelected(bool selected) { + isSelected = selected; + } + + bool VerticalList::getIsSelected() { + return isSelected; + } + + void VerticalList::select(int index) { if(index >= 0 && index < m_children.size()) @@ -68,7 +77,8 @@ namespace gui::elements if (selection != nullptr) selection->setBackgroundColor(m_selectionColor); - m_oldFocusedIndex = index; + m_oldFocusedIndex = m_focusedIndex; + setIsSelected(true); updateFocusedIndex(); } diff --git a/lib/gui/src/elements/List.hpp b/lib/gui/src/elements/List.hpp index aaec6e06..6e8bc59f 100644 --- a/lib/gui/src/elements/List.hpp +++ b/lib/gui/src/elements/List.hpp @@ -34,6 +34,10 @@ namespace gui::elements void select(int index); void setSelectionColor(color_t color); void setAutoSelect(bool autoSelect); + void setIsSelected(bool autoSelect); + bool getIsSelected(); + + //virtual void onSelect() {} private: @@ -44,6 +48,7 @@ namespace gui::elements SelectionFocus m_selectionFocus = SelectionFocus::UP; color_t m_selectionColor; bool m_autoSelect; + bool isSelected = false; }; diff --git a/lib/lua/src/lua_file.cpp b/lib/lua/src/lua_file.cpp index 0ab75529..045804d3 100755 --- a/lib/lua/src/lua_file.cpp +++ b/lib/lua/src/lua_file.cpp @@ -531,6 +531,7 @@ void LuaFile::load() "select", &LuaVerticalList::select, "setSelectionColor", &LuaVerticalList::setSelectionColor, "setAutoSelect", &LuaVerticalList::setAutoSelect, + "onSelect", &LuaVerticalList::onSelect, sol::base_classes, sol::bases()); lua.new_usertype("LuaHList", diff --git a/lib/lua/src/lua_list.cpp b/lib/lua/src/lua_list.cpp index c76f151a..a30fda84 100644 --- a/lib/lua/src/lua_list.cpp +++ b/lib/lua/src/lua_list.cpp @@ -1,13 +1,98 @@ #include "lua_list.hpp" +/** + * LuaVerticalList + */ LuaVerticalList::LuaVerticalList(LuaWidget* parent, int x, int y, int width, int height) { widget = new VerticalList(x, y, width, height); init(widget, parent); } +void LuaVerticalList::addChild(LuaWidget* widget) +{ + this->children.push_back(widget); + widget->parent = this; + this->widget->add(widget->widget); +} + +void LuaVerticalList::setSpaceLine(int line) +{ + this->widget->setSpaceLine(line); +} + +void LuaVerticalList::setIndex(int i) +{ + this->widget->setIndex(i); +} + +void LuaVerticalList::setFocus(VerticalList::SelectionFocus focus) +{ + this->widget->setSelectionFocus(focus); +} + +int LuaVerticalList::getSelected() +{ + return this->widget->getFocusedElement(); +} + + +void LuaVerticalList::onSelect(sol::protected_function func) +{ + onSelectFunc = func; +} + +void LuaVerticalList::select(int index) +{ + this->widget->select(index); + if (onSelectFunc) { + onSelectFunc(); + } +} + +void LuaVerticalList::setSelectionColor(color_t color) +{ + this->widget->setSelectionColor( color); +} + +void LuaVerticalList::setAutoSelect(bool autoSelect) +{ + this->widget->setAutoSelect(autoSelect); +} + + +void LuaVerticalList::specificUpdate() +{ + +// LuaWidget:update(); + + if(onSelectFunc && this->widget->getIsSelected()){ + onSelectFunc(); + this->widget->setIsSelected(false); + } + +} + +/** + * LuaHorizontalList + */ + LuaHorizontalList::LuaHorizontalList(LuaWidget* parent, int x, int y, int width, int height) { widget = new HorizontalList(x, y, width, height); init(widget, parent); -} \ No newline at end of file +} + +void LuaHorizontalList::addChild(LuaWidget* widget) +{ + this->children.push_back(widget); + widget->parent = this; + this->widget->add(widget->widget); +} + +void LuaHorizontalList::setSpaceLine(int line) +{ + this->widget->setSpaceLine(line); +} + + diff --git a/lib/lua/src/lua_list.hpp b/lib/lua/src/lua_list.hpp index 80626836..6a857812 100644 --- a/lib/lua/src/lua_list.hpp +++ b/lib/lua/src/lua_list.hpp @@ -3,30 +3,43 @@ #include "lua_widget.hpp" + +/** + * Liste Verticale + */ class LuaVerticalList : public LuaWidget { public: LuaVerticalList(LuaWidget* parent, int x, int y, int width, int height); - void addChild(LuaWidget* widget){ this->children.push_back(widget); widget->parent = this; this->widget->add(widget->widget); } - void setSpaceLine(int line){ this->widget->setSpaceLine(line); } - void setIndex(int i = 0) { this->widget->setIndex(i); }; - void setFocus(VerticalList::SelectionFocus focus) { std::cout << "setFocus: " << focus << std::endl; this->widget->setSelectionFocus(focus); }; - int getSelected() { return this->widget->getFocusedElement(); }; - void select(int index) { this->widget->select(index); }; - void setSelectionColor(color_t color) { this->widget->setSelectionColor( color); }; - void setAutoSelect(bool autoSelect) { this->widget->setAutoSelect(autoSelect); }; - - VerticalList* widget = nullptr; + void addChild(LuaWidget* widget); + void setSpaceLine(int line); + void setIndex(int i = 0); + void setFocus(VerticalList::SelectionFocus focus); + int getSelected(); + void select(int index); + void setSelectionColor(color_t color); + void setAutoSelect(bool autoSelect); + void specificUpdate(); + + + void onSelect(sol::protected_function func); + + protected: + VerticalList* widget = nullptr; + sol::protected_function onSelectFunc; }; +/** + * Liste Horizontale + */ class LuaHorizontalList : public LuaWidget { public: LuaHorizontalList(LuaWidget* parent, int x, int y, int width, int height); - void addChild(LuaWidget* widget){ this->children.push_back(widget); widget->parent = this; this->widget->add(widget->widget); } - void setSpaceLine(int line){ this->widget->setSpaceLine(line); } + void addChild(LuaWidget* widget); + void setSpaceLine(int line); HorizontalList* widget = nullptr; }; diff --git a/lib/lua/src/lua_widget.cpp b/lib/lua/src/lua_widget.cpp index c107733f..8b17bce8 100644 --- a/lib/lua/src/lua_widget.cpp +++ b/lib/lua/src/lua_widget.cpp @@ -161,4 +161,12 @@ void LuaWidget::update() { children[i]->update(); } -} \ No newline at end of file +} + + + void LuaWidget::addChild(LuaWidget* child) + { + this->children.push_back(child); + child->parent = this; + this->widget->addChild(child->widget); + } diff --git a/lib/lua/src/lua_widget.hpp b/lib/lua/src/lua_widget.hpp index a90e5630..85a8f3fc 100644 --- a/lib/lua/src/lua_widget.hpp +++ b/lib/lua/src/lua_widget.hpp @@ -10,56 +10,50 @@ class LuaGui; class LuaWidget { public: - void init(gui::ElementBase* obj, LuaWidget* parent); - void init(gui::ElementBase* obj) {widget = obj;} - ~LuaWidget(); - - void setX(int x){this->widget->setX(x);} - void setY(int y){this->widget->setY(y);} - void setWidth(int width){this->widget->setWidth(width);} - void setHeight(int height){this->widget->setHeight(height);} - int getX(){return this->widget->getX();} - int getY(){return this->widget->getY();} - int getWidth(){return this->widget->getWidth();} - int getHeight(){return this->widget->getHeight();} - void setBackgroundColor(color_t color){this->widget->setBackgroundColor(color);} - void setBorderColor(color_t color){this->widget->setBorderColor(color);} - void setBorderSize(uint16_t size){this->widget->setBorderSize(size);} - void setRadius(uint16_t r){this->widget->setRadius(r);} - void enable(){this->widget->enable();} - void disable(){this->widget->disable();} - bool isEnabled(){return this->widget->isEnabled();} - bool isTouched(){return this->widget->isFocused();} - void onClick(sol::protected_function func){onClickFunc = func;} - void onScrollUp(sol::protected_function func){onScrollUpFunc = func;} - void onScrollDown(sol::protected_function func){onScrollDownFunc = func;} - void onScrollRight(sol::protected_function func){onScrollRightFunc = func;} - void onScrollLeft(sol::protected_function func){onScrollLeftFunc = func;} - LuaWidget* getChildAtIndex(int index){return children[index];} - - void update(); - virtual void specificUpdate(){}; - - gui::ElementBase* widget = nullptr; - LuaWidget* parent = nullptr; - std::vector children; - - LuaGui* gui = nullptr; - - private: - virtual void addChild(LuaWidget* child) - { - this->children.push_back(child); child->parent = this; - this->widget->addChild(child->widget); - } - - static LuaWidget* rootOfDelete; - - sol::protected_function onClickFunc; - sol::protected_function onScrollUpFunc; - sol::protected_function onScrollDownFunc; - sol::protected_function onScrollRightFunc; - sol::protected_function onScrollLeftFunc; + void init(gui::ElementBase* obj, LuaWidget* parent); + void init(gui::ElementBase* obj) {widget = obj;} + ~LuaWidget(); + + void setX(int x){this->widget->setX(x);} + void setY(int y){this->widget->setY(y);} + void setWidth(int width){this->widget->setWidth(width);} + void setHeight(int height){this->widget->setHeight(height);} + int getX(){return this->widget->getX();} + int getY(){return this->widget->getY();} + int getWidth(){return this->widget->getWidth();} + int getHeight(){return this->widget->getHeight();} + void setBackgroundColor(color_t color){this->widget->setBackgroundColor(color);} + void setBorderColor(color_t color){this->widget->setBorderColor(color);} + void setBorderSize(uint16_t size){this->widget->setBorderSize(size);} + void setRadius(uint16_t r){this->widget->setRadius(r);} + void enable(){this->widget->enable();} + void disable(){this->widget->disable();} + bool isEnabled(){return this->widget->isEnabled();} + bool isTouched(){return this->widget->isFocused();} + void onClick(sol::protected_function func){onClickFunc = func;} + void onScrollUp(sol::protected_function func){onScrollUpFunc = func;} + void onScrollDown(sol::protected_function func){onScrollDownFunc = func;} + void onScrollRight(sol::protected_function func){onScrollRightFunc = func;} + void onScrollLeft(sol::protected_function func){onScrollLeftFunc = func;} + LuaWidget* getChildAtIndex(int index){return children[index];} + + void update(); + virtual void specificUpdate(){}; + + gui::ElementBase* widget = nullptr; + LuaWidget* parent = nullptr; + std::vector children; + + LuaGui* gui = nullptr; + + protected: + virtual void addChild(LuaWidget* child); + static LuaWidget* rootOfDelete; + sol::protected_function onClickFunc; + sol::protected_function onScrollUpFunc; + sol::protected_function onScrollDownFunc; + sol::protected_function onScrollRightFunc; + sol::protected_function onScrollLeftFunc; }; #endif \ No newline at end of file diff --git a/storage/apps/calendrier/app.lua b/storage/apps/calendrier/app.lua index c75d171f..ee62bc94 100644 --- a/storage/apps/calendrier/app.lua +++ b/storage/apps/calendrier/app.lua @@ -1,4 +1,5 @@ - +require "gestionDate.lua" +require "gestionDebug.lua" local boxImgDay, boxImgWeek, boxImgMonth, boxImgParametre, boxImgAdd local menu @@ -10,9 +11,6 @@ local winDay, winNewEvent local vListeDateNewEvent local selectedDateHeure = {} -local monthsName = {"Janvier", "Fevrier", "Mars", "Avril", "Mai", "Juin", "Juillet", "Août", "Septembre", "Octobre", "Novembre", "Decembre"} -local monthsShortName = {"Jan", "Fev", "Mars", "Avr", "Mai", "Juin", "Juil", "Août", "Sep", "Oct", "Nov", "Dec"} - local daysOfWeek = { "Lundi", "Mardi", "Mercredi", "Jeudi", "Vendredi", "Samedi", "Dimanche" } local daysOfWeekShort = { "lun", "mar", "mer", "jeu", "ven", "sam", "dim" } @@ -171,49 +169,35 @@ function displayConfig() local vLstHeureDebut = gui:vlist(winConfig, 20, 305, 150, 100) vLstHeureDebut:setSpaceLine(0) - local vLstHeureFin = gui:vlist(winConfig, 160, 305, 150, 100) - vLstHeureFin:setSpaceLine(0) + vLstHeureDebut:setSelectionFocus(SELECTION_CENTER) + vLstHeureDebut:setSelectionColor(COLOR_LIGHT_ORANGE) + vLstHeureDebut:setAutoSelect(true) - local heureDebut, heureFin - local oldHeureDebut, oldHeureFin + vLstHeureDebut:onSelect(function() print("onSelect OK") end) + local vLstHeureFin = gui:vlist(winConfig, 160, 305, 150, 100) + vLstHeureFin:setSpaceLine(0) + vLstHeureFin:setSelectionFocus(SELECTION_CENTER) + vLstHeureFin:setSelectionColor(COLOR_LIGHT_ORANGE) + vLstHeureFin:setAutoSelect(true) + for i=0,23 do - local lblHeureDebut = gui:label(vLstHeureDebut, 50, 0, 40, 18) - local lblHeureFin = gui:label(vLstHeureFin, 30, 0, 40, 18) - lblHeureDebut:setText(tostring(i)..":00") - lblHeureFin:setText(tostring(i)..":00") - lblHeureDebut:setHorizontalAlignment(RIGHT_ALIGNMENT) - lblHeureFin:setHorizontalAlignment(RIGHT_ALIGNMENT) - - lblHeureDebut:onClick(function () - oldHeureDebut:setBackgroundColor(COLOR_WHITE) - lblHeureDebut:setBackgroundColor(COLOR_LIGHT_GREY) - oldHeureDebut = lblHeureDebut - heureDebut = i - end) - - lblHeureFin:onClick(function () - oldHeureFin:setBackgroundColor(COLOR_WHITE) - lblHeureFin:setBackgroundColor(COLOR_LIGHT_GREY) - oldHeureFin = lblHeureFin - heureFin = i - end) - - -- sélection initiale des listes - if config.day.heureDebut == i then - lblHeureDebut:setBackgroundColor(COLOR_LIGHT_GREY) - oldHeureDebut = lblHeureDebut - heureDebut = i - vLstHeureDebut:setIndex(i) - end - if config.day.heureFin == i then - lblHeureFin:setBackgroundColor(COLOR_LIGHT_GREY) - oldHeureFin = lblHeureFin - heureFin = i - vLstHeureFin:setIndex(i) + local lblHeureDebut = gui:label(vLstHeureDebut, 30, 0, 80, 18) + local lblHeureFin = gui:label(vLstHeureFin, 30, 0, 80, 18) + + if i<10 then + lblHeureDebut:setText(" "..tostring(i)..":00") + lblHeureFin:setText(" "..tostring(i)..":00") + else + lblHeureDebut:setText(tostring(i)..":00") + lblHeureFin:setText(tostring(i)..":00") end + lblHeureDebut:setHorizontalAlignment(CENTER_ALIGNMENT) + lblHeureFin:setHorizontalAlignment(CENTER_ALIGNMENT) end + vLstHeureDebut:select(config.day.heureDebut) + vLstHeureFin:select(config.day.heureFin) -- selection initiale des boutons radio if config.defaultView =="day" then @@ -231,6 +215,7 @@ function displayConfig() btnEnregistrer:setHorizontalAlignment(CENTER_ALIGNMENT) btnEnregistrer:setVerticalAlignment (CENTER_ALIGNMENT) btnEnregistrer:setText("Enregistrer") + btnEnregistrer:onClick(function() config.displayWeekNum = chkWeekNum:getState() @@ -243,9 +228,9 @@ function displayConfig() else config.defaultView = "month" end - config.day={} - config.day.heureFin = heureFin - config.day.heureDebut = heureDebut + --config.day={} + config.day.heureFin = vLstHeureFin:getSelected() + config.day.heureDebut = vLstHeureDebut:getSelected() -- sauvegarde de la config en fichier saveConfig() @@ -327,9 +312,9 @@ function displayWeek(year, month, day) local strTitre = "Semaine "..tostring(numWeek).." du "..tostring(dateDebutSemaine[3]) if dateDebutSemaine[2] ~= dateFinSemaine[2] then - strTitre = strTitre .. " "..monthsShortName[dateDebutSemaine[2]] + strTitre = strTitre .. " "..getMonthShortName(dateDebutSemaine[2]) end - strTitre = strTitre .." au "..tostring(dateFinSemaine[3]).." "..monthsShortName[dateFinSemaine[2]] + strTitre = strTitre .." au "..tostring(dateFinSemaine[3]).." "..getMonthShortName(dateFinSemaine[2]) lblWeek:setText(strTitre) @@ -404,7 +389,7 @@ function displayWeek(year, month, day) headerJour:setFontSize(12) headerJour:setBackgroundColor(colorHeader) headerJour:setHorizontalAlignment(CENTER_ALIGNMENT) - headerJour:setText(daysOfWeekShort[j]) + headerJour:setText(getDayOfWeekShortName(j)) local headerJourNum = gui:label(lblHeader, 0, 12, widthBoxJour, 18) headerJourNum:setFontSize(18) @@ -493,7 +478,7 @@ function displayWeek(year, month, day) lblEvent:onClick( function() local ev = getEventByID(ev.UID, dateCellule[1], dateCellule[2], dateCellule[3]) - if not ev then ev = createEventObject (dateCellule[1], dateCellule[2], dateCellule[3]) end + if not ev then ev = createEventObject (nil, dateCellule[1], dateCellule[2], dateCellule[3]) end displayEvent(ev) end ) @@ -607,7 +592,7 @@ function displayMonth (year, month) lblHearder:setBackgroundColor(COLOR_LIGHT_GREY) lblHearder:setHorizontalAlignment(CENTER_ALIGNMENT) lblHearder:setVerticalAlignment(CENTER_ALIGNMENT) - lblHearder:setText(daysOfWeekShort[i]) + lblHearder:setText(getDayOfWeekShortName(i)) end local weekNum = getWeekNum(year, month, 1) @@ -782,6 +767,14 @@ end function saveDataFile(year, month) if data[year] then + if data[year][month] then + local filename = PATH_DATA.."/"..tostring(year)..tostring(month)..".dat" + debugPrint(data[year][month]) + saveTable(filename, data[year][month]) + end + end + +--[[ if data[year] then if data[year][month] then local strData = serialize (data[year][month]) local filename = PATH_DATA.."/"..tostring(year)..tostring(month)..".dat" @@ -796,7 +789,7 @@ function saveDataFile(year, month) end print("saveDataFile - aucune donnée à sauvegarder pour le mois "..tostring(month).." de "..tostring(year)) - +]]-- end @@ -821,7 +814,7 @@ function loadDataMonth(year, month, noLoadingAdjacent) -- check if a data file exists if storage:isFile(filename) then - +--[[ -- lecture du fichier fileData = storage:file (filename, READ) fileData:open() @@ -837,9 +830,23 @@ function loadDataMonth(year, month, noLoadingAdjacent) -- ajout du json dans la structure data if not data[year] then data[year] = {} end if not data[year][month] then data[year][month] = {} end +]]-- + + -- data[year][month]=dataLoad[1] + -- ********************** + + -- dataLoad = {} + local dataLoad = loadTable(filename) + + if not data[year] then data[year] = {} end + if not data[year][month] then data[year][month] = {} end + + --debugPrint(dataLoad) + --print(#dataLoad) + data[year][month]=dataLoad - data[year][month]=dataLoad[1] - --debugPrint(data) + -- data[year][month]=dataLoad[1] + --debugPrint(data) if (not noLoadingAdjacent) then -- chargement des données du mois précédent @@ -915,7 +922,7 @@ function deleteEvent(UID, year, month, day) end -- Créer un nouvel événement -function createEventObject(name, description, yearDebut, monthDebut, dayDebut, heureDebut, minuteDebut, yearFin, monthFin, dayFin, heureFin, minuteFin) +function createEventObject(name, yearDebut, monthDebut, dayDebut, heureDebut, minuteDebut, yearFin, monthFin, dayFin, heureFin, minuteFin) event = {} event.debut = {} @@ -933,7 +940,7 @@ function createEventObject(name, description, yearDebut, monthDebut, dayDebut, h -- TODO: gestion de la cohérence des dates & heures entre début et fin if not name then event.name = "" else event.name = name end - if not description then event.description = "" else event.description = description end +-- if not description then event.description = "" else event.description = description end if not yearDebut then event.debut.year = year else event.debut.year = yearDebut end if not monthDebut then event.debut.month = month else event.debut.month = monthDebut end @@ -1080,7 +1087,7 @@ function displayDay(year, month, day) lblEvent:onClick( function() local ev = getEventByID(ev.UID, year, month, day) - if not ev then ev = createEventObject (year, month, day) end + if not ev then ev = createEventObject (nil, year, month, day) end displayEvent(ev) end ) @@ -1125,7 +1132,7 @@ function displayDay(year, month, day) local lblDayOfWeek = gui:label(boxDayWeek, 2, 2, widthBoxDay-4, 12, COLOR_WHITE) lblDayOfWeek:setFontSize(9) lblDayOfWeek:setHorizontalAlignment(CENTER_ALIGNMENT) - lblDayOfWeek:setText(daysOfWeek[i]) + lblDayOfWeek:setText(getDayOfWeekName(i)) local lblDay = gui:label(boxDayWeek, 4, 11, widthBoxDay-8, 20, COLOR_WHITE) lblDay:setHorizontalAlignment(CENTER_ALIGNMENT) @@ -1214,6 +1221,7 @@ function displayEvent(event) local vListeDateDebutNewEvent = gui:vlist(winNewEvent, 20, 110, 140, 100) vListeDateDebutNewEvent:setSpaceLine(0) + vListeDateDebutNewEvent:setAutoSelect(true) local oldSelectionDateDebut local nbJourToDisplay = 30 @@ -1451,7 +1459,7 @@ function displayEvent(event) local oldEvent = deleteEvent(event.UID, event.debut.year, event.debut.month, event.debut.day) -- sauvegarde les modifs en fichier - saveDataFile(oldEvent.debut.year, oldEvent.debut.month, oldEvent.debut.day) + saveDataFile(oldEvent.debut.year, oldEvent.debut.month) switchScreen(oldEvent.debut.year, oldEvent.debut.month, oldEvent.debut.day) end ) @@ -1534,7 +1542,7 @@ function displayTopBarre() local imgAdd = gui:image(boxImgAdd, "plus.png", 6, 6, 12, 12, COLOR_DARK) boxImgAdd:onClick( function() - local event = createEventObject(nil, nil, today[1], today[2], today[3]) + local event = createEventObject(nil, today[1], today[2], today[3]) displayEvent(event) end ) @@ -1559,62 +1567,6 @@ end --- ------------------ --- FONCTION DE DEBUG --- ------------------ - - -function debugPrint(t, indent) - - - local debugType = true - - if not indent then print("[DEBUG] "..getVariableName(t))end - indent = indent or 0 - local spacing = string.rep(" ", indent) - - if type(t) == "table" then - for k, v in pairs(t) do - if type(v) == "table" then - if debugType then - print(spacing .."("..type(k)..") "..tostring(k) .. ":") - else - print(spacing ..tostring(k)) - end - debugPrint(v, indent + 1) - else - if debugType then - print(spacing .."("..type(k)..") "..tostring(k) .. ": " .. tostring(v) .." ("..type(v)..")") - else - print(spacing ..tostring(k) .. ": " .. tostring(v)) - end - end - end - else - if debugType then - print(spacing .. "("..type(t)..") "..tostring(t)) - else - print(spacing ..tostring(t)) - end - end -end - - -function getVariableName(var) - local name --- for k, v in pairs(_G) do - for k, v in pairs(_G) do - if v == var then - name = k - break - end - end - if name then - return name - else - return "Variable not found" - end -end @@ -1684,9 +1636,9 @@ function formatDate (date, pattern) local day = string.format("%02d", m_day) local heure = string.format("%02d", m_heure) local minute = string.format("%02d", m_minute) - local dayOfWeek = daysOfWeek[getDayOfWeek(m_year, m_month, m_day)] - local monthName = monthsName[m_month] - local monthShortName = monthsShortName[m_month] + local dayOfWeek = getDayOfWeekName(getDayOfWeek(m_year, m_month, m_day)) -- PYM + local monthName = getMonthName(m_month) + local monthShortName = getMonthShortName(m_month) local result = pattern:gsub("yyyy", year) :gsub("mm", month) @@ -1700,308 +1652,4 @@ function formatDate (date, pattern) end --formatDate --- Retourne le numero de la semaine d'une date donnée -function getWeekNum(year, month, day) - local daysInMonth = {31, isLeapYear(year) and 29 or 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31} - local totalDays = 0 - - for m = 1, month - 1 do - totalDays = totalDays + daysInMonth[m] - end - - totalDays = totalDays + day - - return int((totalDays - 1) / 7) + 1 -end - --- Add days "dayToAdd" to the "originalDate" --- return new date to and array year, month, day -function addDaysToDate(originalDate, daysToAdd) - - local year = originalDate[1] - local month = originalDate[2] - local day = originalDate[3] - - -- Ensure input date is valid - if year < 1 or month < 1 or month > 12 or day < 1 or day > getDaysInMonth(year, month) then - return nil, "Invalid input date" - end - - local newYear, newMonth, newDay = year, month, day - - while daysToAdd ~= 0 do - if daysToAdd > 0 then - -- Adding days - local daysInCurrentMonth = getDaysInMonth(newYear, newMonth) - if newDay + daysToAdd <= daysInCurrentMonth then - newDay = newDay + daysToAdd - break - else - daysToAdd = daysToAdd - (daysInCurrentMonth - newDay + 1) - newDay = 1 - newMonth = newMonth + 1 - if newMonth > 12 then - newMonth = 1 - newYear = newYear + 1 - end - end - else - -- Subtracting days - if newDay + daysToAdd >= 1 then - newDay = newDay + daysToAdd - break - else - daysToAdd = daysToAdd + newDay - newMonth = newMonth - 1 - if newMonth < 1 then - newMonth = 12 - newYear = newYear - 1 - end - newDay = getDaysInMonth(newYear, newMonth) - end - end - end - - return {newYear, newMonth, newDay} -end -- addDaysToDate - - --- return an array with the current year, month and day -function getToday() - - local today = time:get("y,mo,d") - return {today[1], today[2], today[3]} - -end - --- récupère le jour de la semaine en fonction de la date --- format européen : le 1er jours est le lundi -function getDayOfWeek(yy, mm, dd) - local mmx = mm - - if (mm == 1) then mmx = 13; yy = yy-1 end - if (mm == 2) then mmx = 14; yy = yy-1 end - - local val8 = dd -1 + (mmx*2) + math.floor(((mmx+1)*3)/5) + yy + math.floor(yy/4) - math.floor(yy/100) + math.floor(yy/400) + 2 - local val9 = math.floor(val8/7) - local dw = val8-(val9*7) - - if (dw == 0) then - dw = 7 - end - - return dw -end - - - -- Détermine si year est une année bixestile ou non -function isLeapYear(year) - return year % 4 == 0 and (year % 100 ~= 0 or year % 400 == 0) -end - - --- renvoi le nombre de jours d'un mois et année donnée -function getDaysInMonth(year, month) - local days_in_month = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 } - local d = days_in_month[month] - - if month == 2 and isLeapYear(year) then d=29 end - return d -end - - - - --- ------------------------------------- --- LUA SERIALIZER --- From Rochet2 z3sk%^HL(aHx?sKoBTQdLYH1Nnv9SXq%;c2BO1PWgYIF1RN;06rN(i-~o-SBi3)hvB hnp9c>vyOq0a%UPLtR}{pF#qQz=BB~}qa?p19{|dIC5!+7 literal 0 HcmV?d00001 diff --git a/storage/apps/calendrier/gestionDate.lua b/storage/apps/calendrier/gestionDate.lua index a875adaf..427e3a56 100644 --- a/storage/apps/calendrier/gestionDate.lua +++ b/storage/apps/calendrier/gestionDate.lua @@ -1,15 +1,51 @@ +local monthsName = {"Janvier", "Fevrier", "Mars", "Avril", "Mai", "Juin", "Juillet", "Août", "Septembre", "Octobre", "Novembre", "Decembre"} +local monthsShortName = {"Jan", "Fev", "Mars", "Avr", "Mai", "Juin", "Juil", "Août", "Sep", "Oct", "Nov", "Dec"} +local daysOfWeek = { "Lundi", "Mardi", "Mercredi", "Jeudi", "Vendredi", "Samedi", "Dimanche" } +local daysOfWeekShort = { "lun", "mar", "mer", "jeu", "ven", "sam", "dim" } + + +function getDayOfWeekName (m_day) + return daysOfWeek[m_day] +end + +function getDayOfWeekShortName (m_day) + return daysOfWeekShort[m_day] +end + +function getMonthName(m_month) + return monthsName[m_month] +end + + +function getMonthShortName(m_month) + return monthsShortName[m_month] +end + +-- Retourne le numero de la semaine d'une date donnée +function getWeekNum(year, month, day) + local daysInMonth = {31, isLeapYear(year) and 29 or 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31} + local totalDays = 0 + + for m = 1, month - 1 do + totalDays = totalDays + daysInMonth[m] + end + + totalDays = totalDays + day + + return int((totalDays - 1) / 7) + 1 +end -- Add days "dayToAdd" to the "originalDate" -- return new date to and array year, month, day function addDaysToDate(originalDate, daysToAdd) - year = originalDate[1] - month = originalDate[2] - day = originalDate[3] + local year = originalDate[1] + local month = originalDate[2] + local day = originalDate[3] -- Ensure input date is valid - if year < 1 or month < 1 or month > 12 or day < 1 or day > getDaysInMonth(month, year) then + if year < 1 or month < 1 or month > 12 or day < 1 or day > getDaysInMonth(year, month) then return nil, "Invalid input date" end @@ -18,7 +54,7 @@ function addDaysToDate(originalDate, daysToAdd) while daysToAdd ~= 0 do if daysToAdd > 0 then -- Adding days - local daysInCurrentMonth = getDaysInMonth(newMonth, newYear) + local daysInCurrentMonth = getDaysInMonth(newYear, newMonth) if newDay + daysToAdd <= daysInCurrentMonth then newDay = newDay + daysToAdd break @@ -43,13 +79,13 @@ function addDaysToDate(originalDate, daysToAdd) newMonth = 12 newYear = newYear - 1 end - newDay = getDaysInMonth(newMonth, newYear) + newDay = getDaysInMonth(newYear, newMonth) end end end return {newYear, newMonth, newDay} -end +end -- addDaysToDate -- return an array with the current year, month and day @@ -87,31 +123,10 @@ end -- renvoi le nombre de jours d'un mois et année donnée -function getDaysInMonth(month, year) +function getDaysInMonth(year, month) local days_in_month = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 } local d = days_in_month[month] - - -- check for leap year - if (month == 2) then - if (math.mod(year,4) == 0) then - if (math.mod(year,100) == 0)then - if (math.mod(year,400) == 0) then - d = 29 - end - else - d = 29 - end - end - end - + + if month == 2 and isLeapYear(year) then d=29 end return d -end - - --- Renvoi la date au format -function formatLongDate(year, month, day) - - numDay = getDayOfWeek(year, month, day) - str = daysOfWeek[numDay].." "..tostring(day).." "..monthsName[month] - return str end \ No newline at end of file diff --git a/storage/apps/calendrier/gestionDebug.lua b/storage/apps/calendrier/gestionDebug.lua new file mode 100644 index 00000000..2b1929fc --- /dev/null +++ b/storage/apps/calendrier/gestionDebug.lua @@ -0,0 +1,56 @@ +-- ------------------ +-- FONCTION DE DEBUG +-- ------------------ + + +function debugPrint(t, indent) + + + local debugType = true + + if not indent then print("[DEBUG] "..getVariableName(t))end + indent = indent or 0 + local spacing = string.rep(" ", indent) + + if type(t) == "table" then + for k, v in pairs(t) do + if type(v) == "table" then + if debugType then + print(spacing .."("..type(k)..") "..tostring(k) .. ":") + else + print(spacing ..tostring(k)) + end + debugPrint(v, indent + 1) + else + if debugType then + print(spacing .."("..type(k)..") "..tostring(k) .. ": " .. tostring(v) .." ("..type(v)..")") + else + print(spacing ..tostring(k) .. ": " .. tostring(v)) + end + end + end + else + if debugType then + print(spacing .. "("..type(t)..") "..tostring(t)) + else + print(spacing ..tostring(t)) + end + end +end + + +function getVariableName(var) + local name +-- for k, v in pairs(_G) do + for k, v in pairs(_G) do + if v == var then + name = k + break + end + end + if name then + return name + else + return "Variable not found" + end +end From 03dc831a37170bc7858feb5273600c34337d4b80 Mon Sep 17 00:00:00 2001 From: pymuzard Date: Mon, 9 Sep 2024 20:54:26 +0200 Subject: [PATCH 08/13] remplacement composant Liste --- storage/apps/calendrier/app.lua | 475 +++++++---------------- storage/apps/calendrier/config.json | 2 +- storage/apps/calendrier/data/20249.dat | Bin 381 -> 0 bytes storage/apps/calendrier/gestionDebug.lua | 13 +- 4 files changed, 161 insertions(+), 329 deletions(-) delete mode 100644 storage/apps/calendrier/data/20249.dat diff --git a/storage/apps/calendrier/app.lua b/storage/apps/calendrier/app.lua index ee62bc94..8270f89d 100644 --- a/storage/apps/calendrier/app.lua +++ b/storage/apps/calendrier/app.lua @@ -6,17 +6,8 @@ local menu local currentMode local winDay, winNewEvent - --- variable newEvent -local vListeDateNewEvent -local selectedDateHeure = {} - -local daysOfWeek = { "Lundi", "Mardi", "Mercredi", "Jeudi", "Vendredi", "Samedi", "Dimanche" } -local daysOfWeekShort = { "lun", "mar", "mer", "jeu", "ven", "sam", "dim" } - local affichageTop = 60 - -- Parametrage du calendrier local config = {} @@ -49,11 +40,8 @@ function run() else displayMonth(year, month) end - end -- run - - -- chargement du fichier de configuration de l'application function loadConfig() @@ -160,7 +148,6 @@ function displayConfig() radioDefaultViewWeek:onClick(function() selectGroupRadio(radioDefaultViewWeek, groupRadio) end) radioDefaultViewMonth:onClick(function() selectGroupRadio(radioDefaultViewMonth, groupRadio) end) - local lblDebutJour = gui:label(winConfig, 20, 280, 150, 20) lblDebutJour:setText("Début de journée") @@ -173,9 +160,6 @@ function displayConfig() vLstHeureDebut:setSelectionColor(COLOR_LIGHT_ORANGE) vLstHeureDebut:setAutoSelect(true) - vLstHeureDebut:onSelect(function() print("onSelect OK") end) - - local vLstHeureFin = gui:vlist(winConfig, 160, 305, 150, 100) vLstHeureFin:setSpaceLine(0) vLstHeureFin:setSelectionFocus(SELECTION_CENTER) @@ -196,6 +180,7 @@ function displayConfig() lblHeureDebut:setHorizontalAlignment(CENTER_ALIGNMENT) lblHeureFin:setHorizontalAlignment(CENTER_ALIGNMENT) end + print("config.day.heureFin = ") vLstHeureDebut:select(config.day.heureDebut) vLstHeureFin:select(config.day.heureFin) @@ -238,28 +223,21 @@ function displayConfig() --retour à l'écran précédent switchScreen(year, month, day) end) - - end -- displayConfig - -- Gère la sélection unique d'un groupe de bouton radio function selectGroupRadio(selected, groupRadio) - if type(groupRadio) ~= "table" then return end - for _, radio in ipairs(groupRadio) do radio:setState(radio == selected) end - end -- sauvegarde la config en fichier json function saveConfig() - local fileConfig = storage:file ("config.json", WRITE) if (fileConfig == nil) then @@ -273,16 +251,12 @@ function saveConfig() fileConfig:close() fileConfig = nil - - end - -- --------------------------------------- -- AFFICHAGE D'UN MOIS -- --------------------------------------- - function displayWeek(year, month, day) winWeek = gui:window() @@ -409,15 +383,12 @@ function displayWeek(year, month, day) boxHour:setBorderSize(1) boxHour:setRadius(1) - -- affichage des heures local boxLabelHeure = gui:box(boxHour, 0, 0, leftMonth-decalageHeure, sizeBoxHeure) boxLabelHeure:setBorderColor(COLOR_LIGHT_GREY) boxLabelHeure:setBorderSize(1) boxLabelHeure:setRadius(1) local lblHeure = gui:label(boxLabelHeure, 0 , 1, 20, sizeBoxHeure-2) - --lblHeure:setBackgroundColor(COLOR) - --lblHeure:setTextColor(COLOR_) lblHeure:setHorizontalAlignment(RIGHT_ALIGNMENT) lblHeure:setFontSize(14) lblHeure:setText(tostring(i)..":") @@ -425,7 +396,6 @@ function displayWeek(year, month, day) local lblMin = gui:label(boxLabelHeure, 20,1, 18, sizeBoxHeure-2) lblMin:setHorizontalAlignment(LEFT_ALIGNMENT) lblMin:setTextColor(COLOR_GREY) - --lblMin:setBackgroundColor(colorBackGround) lblMin:setFontSize(10) lblMin:setText("00") else @@ -439,7 +409,7 @@ function displayWeek(year, month, day) if config.day.heureDebut >i or config.day.heureFin < i then lblCase:setBackgroundColor(COLOR_LIGHT_BLUE) end - -- ------------------------ + -- ------------------------ -- Affichage des evenements -- ------------------------ @@ -466,11 +436,7 @@ function displayWeek(year, month, day) elseif ev.fin.heure > i then positionBas = sizeBoxHeure end - --local lblEvent = gui:label(winWeek, leftMonth + (j-1)*(widthBoxJour+espacementBox) , topHeader, widthBoxJour, heigthHeader) - -- local lblEvent = gui:label(boxHour, 41, positionHaut, widthBox - 50, positionBas - positionHaut) - local lblEvent = gui:label(boxHour, leftMonth-decalageHeure+(j-1)*(widthBoxJour+espacementBox) , positionHaut, widthBoxJour, positionBas - positionHaut) - -- local lblEvent = gui:label(winWeek, leftMonth + (j-1)*(widthBoxJour+espacementBox) , topHeader, widthBoxJour, heigthHeader) lblEvent:setBackgroundColor(COLOR_LIGHT_ORANGE) lblEvent:setFontSize(14) @@ -486,15 +452,10 @@ function displayWeek(year, month, day) end end -- if lstEvent - end - -- on positionne la vliste sur la 1ere heure du jour vListeHeure:setIndex(config.day.heureDebut) - -end - - + end end -- displayWeek @@ -514,7 +475,6 @@ function displayMonth (year, month) -- sélection du menu actif selectMenu(boxImgMonth) - -- chargement des données du mois loadDataMonth(year, month) @@ -584,7 +544,6 @@ function displayMonth (year, month) local heightEvent = 10 -- AMELIORATION POSSIBLE - Calculer le nombre d'event affichable possible - -- local nbMaxEventDisplay = int((heightSemaine - 16) / heightEvent) -- Affichage du header for i=1, NbJourstoDisplay do @@ -594,7 +553,6 @@ function displayMonth (year, month) lblHearder:setVerticalAlignment(CENTER_ALIGNMENT) lblHearder:setText(getDayOfWeekShortName(i)) end - local weekNum = getWeekNum(year, month, 1) -- Affichage des cellules @@ -651,27 +609,16 @@ function displayMonth (year, month) --lblJourMonth:setBackgroundColor(COLOR_LIGHT_BLUE) end - lblJourMonth:onClick( - function() - displayDay(dateCellule[1], dateCellule[2], dateCellule[3]) - end - ) - - + lblJourMonth:onClick( function() displayDay(dateCellule[1], dateCellule[2], dateCellule[3]) end) end - end - end --displayMonth - -- --------------------------------------- -- GESTION DES DATA -- --------------------------------------- - - -- Enregistrement d'un event dans la structure Data function saveEvent(event) @@ -685,7 +632,6 @@ function saveEvent(event) data[event.debut.year][event.debut.month][event.debut.day][event.UID] = event saveDataFile(event.debut.year,event.debut.month) - end @@ -814,43 +760,16 @@ function loadDataMonth(year, month, noLoadingAdjacent) -- check if a data file exists if storage:isFile(filename) then ---[[ - -- lecture du fichier - fileData = storage:file (filename, READ) - fileData:open() - strData = fileData:readAll() - fileData:close() - fileData = nil - --- dataLoad = json_to_array(strData) - local dataLoad = unserialize(strData) - - if not dataLoad or not dataLoad[1] then return end - - -- ajout du json dans la structure data - if not data[year] then data[year] = {} end - if not data[year][month] then data[year][month] = {} end -]]-- - - -- data[year][month]=dataLoad[1] - -- ********************** - -- dataLoad = {} local dataLoad = loadTable(filename) if not data[year] then data[year] = {} end if not data[year][month] then data[year][month] = {} end - --debugPrint(dataLoad) - --print(#dataLoad) data[year][month]=dataLoad - -- data[year][month]=dataLoad[1] - --debugPrint(data) - if (not noLoadingAdjacent) then -- chargement des données du mois précédent - local previousMonth, previousYear if month == 1 then previousMonth = 12 @@ -861,7 +780,6 @@ function loadDataMonth(year, month, noLoadingAdjacent) end loadDataMonth(previousYear, previousMonth, true) - -- chargement des données du mois suivant local nextMonth, nextYear if month == 12 then @@ -949,7 +867,7 @@ function createEventObject(name, yearDebut, monthDebut, dayDebut, heureDebut, mi if not minuteDebut then event.debut.minute = 0 else event.debut.day = minuteDebut end if not yearFin then event.fin.year = year else event.fin.year = yearFin end - if not monthFin then event.fin.month = month else event.fin.month = monthDFin end + if not monthFin then event.fin.month = month else event.fin.month = monthFin end if not dayFin then event.fin.day = day else event.fin.day = dayFin end if not heureFin then event.fin.heure = heure+1 else event.fin.day = heureFin end if not minuteFin then event.fin.minute = 0 else event.fin.day = minuteFin end @@ -965,9 +883,7 @@ function displayDay(year, month, day) currentMode = "day" -- création d'une nouvelle fenetre pour le jour - -- if not winDay then - winDay = gui:window() - --end + winDay = gui:window() gui:setWindow(winDay) -- cration de la top barre @@ -1013,12 +929,21 @@ function displayDay(year, month, day) -- Affichage des heures for i=0,23 do local boxHour = gui:box(vListeHeure, 0, 0, widthBox, sizeBoxHeure) - if (i==currentHour) then - boxHour:setBackgroundColor(COLOR_RED) - else - boxHour:setBackgroundColor(COLOR_GREY) + + local colorBackGround = COLOR_WHITE + local colorTextHeure = COLOR_BLACK + local colorTextMin = COLOR_GREY + local colorLine = COLOR_GREY + + if (i==currentHour and today[1] == year and today[2] == month and today[3] == day ) then + colorLine = COLOR_RED + colorBackGround = COLOR_RED + colorTextHeure = COLOR_WHITE + colorTextMin = COLOR_WHITE end + boxHour:setBackgroundColor(colorLine) + local lblDummy = gui:label(boxHour, 0 , 1, widthBox, sizeBoxHeure-1) if (i < config.day.heureDebut or i>config.day.heureFin) then lblDummy:setBackgroundColor(COLOR_LIGHT_BLUE) @@ -1026,16 +951,6 @@ function displayDay(year, month, day) lblDummy:setBackgroundColor(COLOR_WHITE) end - local colorBackGround = COLOR_WHITE - local colorTextHeure = COLOR_BLACK - local colorTextMin = COLOR_GREY - - if (i==currentHour) then - colorBackGround = COLOR_RED - colorTextHeure = COLOR_WHITE - colorTextMin = COLOR_WHITE - end - local lblHeure = gui:label(boxHour, 0 , 1, 20, sizeBoxHeure-2) lblHeure:setBackgroundColor(colorBackGround) lblHeure:setTextColor(colorTextHeure) @@ -1056,7 +971,6 @@ function displayDay(year, month, day) if lstEvent ~= nil then for _, ev in pairs(lstEvent) do - -- il y a un un event ou troncon d'event sur cette plage horaire if i>= ev.debut.heure and (i < ev.fin.heure or ( ev.fin.heure==i and ev.fin.minute >0 )) then local nomEvent = "" @@ -1093,9 +1007,7 @@ function displayDay(year, month, day) ) end end - end -- if lstEvent - end -- on positionne la vliste sur la 1ere heure du jour @@ -1123,12 +1035,9 @@ function displayDay(year, month, day) local imgNextWeek = gui:image(winDay, "fleche_droite.png", 300, 440, 20, 35) imgNextWeek:onClick(function() displayDay(dateNextWeek[1], dateNextWeek[2], dateNextWeek[3]) end) - for i=1, nbDaysWeekToDisplay do local date = addDaysToDate({year, month, day}, i-currentDayWeek) - local boxDayWeek = gui:box(vListDays, 0, 5, widthBoxDay, 35) - local lblDayOfWeek = gui:label(boxDayWeek, 2, 2, widthBoxDay-4, 12, COLOR_WHITE) lblDayOfWeek:setFontSize(9) lblDayOfWeek:setHorizontalAlignment(CENTER_ALIGNMENT) @@ -1149,21 +1058,8 @@ function displayDay(year, month, day) boxDayWeek:onClick(function() displayDay(date[1], date[2], date[3]) end) end end - - end --displayDay - - -function printEvent(event) - - print("event: ".. event.name) - print("date debut: ".. tostring(event.debut.day).."/".. tostring(event.debut.month).."/".. tostring(event.debut.year)) - print( " debut: "..tostring(event.debut.heure)..":"..tostring(event.debut.minute) ) - print( " fin: "..tostring(event.fin.heure)..":"..tostring(event.fin.minute) ) - -end - -- --------------------------------------- -- ECRAN DETAIL / NOUVEL EVENEMENT -- --------------------------------------- @@ -1187,14 +1083,17 @@ function displayEvent(event) isNew = true end + -- Message d'erreur local lblMsgError = gui:label(winNewEvent, 30, 380, 260, 40) lblMsgError:setFontSize(14) lblMsgError:setHorizontalAlignment(CENTER_ALIGNMENT) lblMsgError:setTextColor(COLOR_RED) + -- Bouton retour arrière imgBack = gui:image(winNewEvent, "back.png", 20, 30, 18, 18) imgBack:onClick(function () switchScreen(year, month, day) end) + -- input Nom de l'event local inputName = gui:input(winNewEvent, 60, 10, 250, 40) inputName:setTitle(titre) inputName:setText(event.name) @@ -1219,117 +1118,6 @@ function displayEvent(event) local lblTraitDebut = gui:label(winNewEvent, 20, 101, 280, 1) lblTraitDebut:setBackgroundColor(COLOR_GREY) - local vListeDateDebutNewEvent = gui:vlist(winNewEvent, 20, 110, 140, 100) - vListeDateDebutNewEvent:setSpaceLine(0) - vListeDateDebutNewEvent:setAutoSelect(true) - - local oldSelectionDateDebut - local nbJourToDisplay = 30 - - -- Affichage des dates - for i=0, 2*nbJourToDisplay do - local date = addDaysToDate({event.debut.year, event.debut.month, event.debut.day}, i-nbJourToDisplay) - local lblDateDebut = gui:label(vListeDateDebutNewEvent, 0, 0, 140, 13) - lblDateDebut:setFontSize(12) - lblDateDebut:setHorizontalAlignment(RIGHT_ALIGNMENT) - lblDateDebut:setText(formatDate(date, "DD dd sh").." ") - lblDateDebut:onClick( - function() - - if oldSelectionDateDebut == lblDateDebut then return end - - event.debut.year = date[1] - event.debut.month = date[2] - event.debut.day = date[3] - lblDateHeureDebut:setText(formatDate(event.debut,"DD dd sh hh:mi")) - - oldSelectionDateDebut:setBackgroundColor(COLOR_WHITE) - lblDateDebut:setBackgroundColor(COLOR_LIGHT_GREY) - oldSelectionDateDebut = lblDateDebut - - lblMsgError:setText("") - end - ) - - if i == nbJourToDisplay then - lblDateDebut:setBackgroundColor(COLOR_LIGHT_GREY) - vListeDateDebutNewEvent:setIndex(i) - oldSelectionDateDebut = lblDateDebut - end - end - - local vListeHeureDebutNewEvent = gui:vlist(winNewEvent, 200, 110, 40, 100) - vListeHeureDebutNewEvent:setSpaceLine(0) - local oldLblHeureDebutNewEvent - -- Affichage des Heures - for i=0, 23 do - - local lblHeureDebutNewEvent = gui:label(vListeHeureDebutNewEvent, 0, 0, 40, 13) - lblHeureDebutNewEvent:setFontSize(12) - lblHeureDebutNewEvent:setHorizontalAlignment(CENTER_ALIGNMENT) - lblHeureDebutNewEvent:setText(tostring(i)) - lblHeureDebutNewEvent:onClick( - function() - - if lblHeureDebutNewEvent == oldLblHeureDebutNewEvent then return end - - -- set de l'heure sélectionnée et affichage sur le label Debut - event.debut.heure = i - lblDateHeureDebut:setText(formatDate(event.debut,"DD dd sh hh:mi")) - - lblHeureDebutNewEvent:setBackgroundColor(COLOR_LIGHT_GREY) - oldLblHeureDebutNewEvent:setBackgroundColor(COLOR_WHITE) - oldLblHeureDebutNewEvent = lblHeureDebutNewEvent - - lblMsgError:setText("") - end - ) - - if i == event.debut.heure then - lblHeureDebutNewEvent:setBackgroundColor(COLOR_LIGHT_GREY) - vListeHeureDebutNewEvent:setIndex(i) - oldLblHeureDebutNewEvent = lblHeureDebutNewEvent - end - - end - - local vListeMinDebutNewEvent = gui:vlist(winNewEvent, 260, 110, 40, 100) - vListeMinDebutNewEvent:setSpaceLine(0) - local oldLblMinDebutNewEvent - - -- Affichage des Minutes - for i=0, 55, 5 do - local lblMinuteDebutNewEvent = gui:label(vListeMinDebutNewEvent, 0, 0, 40, 13) - lblMinuteDebutNewEvent:setFontSize(12) - lblMinuteDebutNewEvent:setHorizontalAlignment(CENTER_ALIGNMENT) - lblMinuteDebutNewEvent:setText(tostring(i)) - - lblMinuteDebutNewEvent:onClick( - function() - -- set de la minute de début et affichage sur le label Debut - if lblMinuteDebutNewEvent == oldLblMinDebutNewEvent then return end - - event.debut.minute = i - lblDateHeureDebut:setText(formatDate(event.debut,"DD dd sh hh:mi")) - - lblMinuteDebutNewEvent:setBackgroundColor(COLOR_LIGHT_GREY) - oldLblMinDebutNewEvent:setBackgroundColor(COLOR_WHITE) - oldLblMinDebutNewEvent = lblMinuteDebutNewEvent - - lblMsgError:setText("") - end - ) - - if i == event.debut.minute then - lblMinuteDebutNewEvent:setBackgroundColor(COLOR_LIGHT_GREY) - vListeMinDebutNewEvent:setIndex(int(i/5)) - oldLblMinDebutNewEvent = lblMinuteDebutNewEvent - end - end - - -- ----------------------------------- - -- Gestion de la date & heure de fin - local lblFin = gui:label(winNewEvent, 20, 230, 100, 20) lblFin:setText("Fin") @@ -1340,113 +1128,148 @@ function displayEvent(event) local lblTraitFin = gui:label(winNewEvent, 20, 251, 280, 1) lblTraitFin:setBackgroundColor(COLOR_GREY) + -- Liste des dates de début + local vListeDateDebutNewEvent = gui:vlist(winNewEvent, 20, 110, 140, 100) + vListeDateDebutNewEvent:setSpaceLine(0) + vListeDateDebutNewEvent:setAutoSelect(true) + vListeDateDebutNewEvent:setSelectionFocus(SELECTION_CENTER) + vListeDateDebutNewEvent:setSelectionColor(COLOR_LIGHT_ORANGE) + -- Liste des dates de Fin local vListeDateFinNewEvent = gui:vlist(winNewEvent, 20, 260, 140, 100) vListeDateFinNewEvent:setSpaceLine(0) - local oldSelectionDateFin + vListeDateFinNewEvent:setAutoSelect(true) + vListeDateFinNewEvent:setSelectionFocus(SELECTION_CENTER) + vListeDateFinNewEvent:setSelectionColor(COLOR_LIGHT_ORANGE) - -- Affichage des dates - for i=0, 2*nbJourToDisplay do - local date = addDaysToDate({event.fin.year, event.fin.month, event.fin.day}, i-nbJourToDisplay) - local lblDateFin = gui:label(vListeDateFinNewEvent, 0, 0, 140, 13) - lblDateFin:setFontSize(12) - lblDateFin:setHorizontalAlignment(RIGHT_ALIGNMENT) - lblDateFin:setText(formatDate(date, "DD dd sh").." ") - lblDateFin:onClick( - function() + local nbJourToDisplay = 30 + local lstDates ={} + + vListeDateDebutNewEvent:onSelect(function () + local date = lstDates[vListeDateDebutNewEvent:getSelected()] + event.debut.year = date[1] + event.debut.month = date[2] + event.debut.day = date[3] + + lblDateHeureDebut:setText(formatDate(event.debut,"DD dd sh hh:mi")) + lblMsgError:setText("") + end) - if oldSelectionDateFin == lblDateFin then return end + vListeDateFinNewEvent:onSelect(function () + local date = lstDates[vListeDateFinNewEvent:getSelected()] + event.fin.year = date[1] + event.fin.month = date[2] + event.fin.day = date[3] + + lblDateHeureFin:setText(formatDate(event.fin,"DD dd sh hh:mi")) + lblMsgError:setText("") + end) - event.fin.year = date[1] - event.fin.month = date[2] - event.fin.day = date[3] - lblDateHeureFin:setText(formatDate(event.fin,"DD dd sh hh:mi")) - oldSelectionDateFin:setBackgroundColor(COLOR_WHITE) - lblDateFin:setBackgroundColor(COLOR_LIGHT_GREY) - oldSelectionDateFin = lblDateFin + -- Affichage des dates Debut et Fin + for i=0, 2*nbJourToDisplay do + local date = addDaysToDate({event.debut.year, event.debut.month, event.debut.day}, i-nbJourToDisplay) + lstDates[i] = date + local strDate = formatDate(date, "DD dd sh").." " + + local lblDateDebut = gui:label(vListeDateDebutNewEvent, 0, 0, 140, 17) + lblDateDebut:setFontSize(16) + lblDateDebut:setHorizontalAlignment(RIGHT_ALIGNMENT) + lblDateDebut:setText(strDate) + + local lblDateFin = gui:label(vListeDateFinNewEvent, 0, 0, 140, 17) + lblDateFin:setFontSize(16) + lblDateFin:setHorizontalAlignment(RIGHT_ALIGNMENT) + lblDateFin:setText(strDate) - lblMsgError:setText("") - end - ) - - if i == nbJourToDisplay then - lblDateFin:setBackgroundColor(COLOR_LIGHT_GREY) - vListeDateFinNewEvent:setIndex(i) - oldSelectionDateFin = lblDateFin - end end + + -- selection de la date du jour de début + vListeDateDebutNewEvent:select(nbJourToDisplay) + vListeDateFinNewEvent:select(nbJourToDisplay) - -- Affichage des Heures + -- Liste des heures de Début et Fin de l'event + local vListeHeureDebutNewEvent = gui:vlist(winNewEvent, 200, 110, 40, 100) + vListeHeureDebutNewEvent:setSpaceLine(0) + vListeHeureDebutNewEvent:setAutoSelect(true) + vListeHeureDebutNewEvent:setSelectionFocus(SELECTION_CENTER) + vListeHeureDebutNewEvent:setSelectionColor(COLOR_LIGHT_ORANGE) + vListeHeureDebutNewEvent:onSelect(function () + event.debut.heure = vListeHeureDebutNewEvent:getSelected() + lblDateHeureDebut:setText(formatDate(event.debut,"DD dd sh hh:mi")) + lblMsgError:setText("") + end +) local vListeHeureFinNewEvent = gui:vlist(winNewEvent, 200, 260, 40, 100) vListeHeureFinNewEvent:setSpaceLine(0) - local oldLblHeureFinNewEvent - + vListeHeureFinNewEvent:setAutoSelect(true) + vListeHeureFinNewEvent:setSelectionFocus(SELECTION_CENTER) + vListeHeureFinNewEvent:setSelectionColor(COLOR_LIGHT_ORANGE) + vListeHeureFinNewEvent:onSelect( + function () + event.fin.heure = vListeHeureFinNewEvent:getSelected() + lblDateHeureFin:setText(formatDate(event.fin,"DD dd sh hh:mi")) + lblMsgError:setText("") + end + ) + -- Affichage des Heures for i=0, 23 do + local lblHeureDebutNewEvent = gui:label(vListeHeureDebutNewEvent, 0, 0, 40, 16) + lblHeureDebutNewEvent:setFontSize(16) + lblHeureDebutNewEvent:setHorizontalAlignment(CENTER_ALIGNMENT) + lblHeureDebutNewEvent:setText(tostring(i)) - local lblHeureFintNewEvent = gui:label(vListeHeureFinNewEvent, 0, 0, 40, 13) - lblHeureFintNewEvent:setFontSize(12) - lblHeureFintNewEvent:setHorizontalAlignment(CENTER_ALIGNMENT) - lblHeureFintNewEvent:setText(tostring(i)) - lblHeureFintNewEvent:onClick( - function() - -- set de l'heure de fin - if lblHeureFintNewEvent == oldLblHeureFinNewEvent then return end - - event.fin.heure = i - lblHeureFintNewEvent:setBackgroundColor(COLOR_LIGHT_GREY) - - oldLblHeureFinNewEvent:setBackgroundColor(COLOR_WHITE) - lblDateHeureFin:setText(formatDate(event.fin,"DD dd sh hh:mi")) - oldLblHeureFinNewEvent = lblHeureFintNewEvent + local lblHeureFinNewEvent = gui:label(vListeHeureFinNewEvent, 0, 0, 40, 16) + lblHeureFinNewEvent:setFontSize(16) + lblHeureFinNewEvent:setHorizontalAlignment(CENTER_ALIGNMENT) + lblHeureFinNewEvent:setText(tostring(i)) + end - lblMsgError:setText("") - - end - ) + vListeHeureDebutNewEvent:select(event.debut.heure) + vListeHeureFinNewEvent:select(event.fin.heure) - if i == event.fin.heure then - lblHeureFintNewEvent:setBackgroundColor(COLOR_LIGHT_GREY) - vListeHeureFinNewEvent:setIndex(i) - oldLblHeureFinNewEvent = lblHeureFintNewEvent + -- gestion des heures du début de l'évent + local vListeMinDebutNewEvent = gui:vlist(winNewEvent, 260, 110, 40, 100) + vListeMinDebutNewEvent:setSpaceLine(0) + vListeMinDebutNewEvent:setAutoSelect(true) + vListeMinDebutNewEvent:setSelectionFocus(SELECTION_CENTER) + vListeMinDebutNewEvent:setSelectionColor(COLOR_LIGHT_ORANGE) + vListeMinDebutNewEvent:onSelect( + function () + event.debut.minute = vListeMinDebutNewEvent:getSelected()*5 + lblDateHeureDebut:setText(formatDate(event.debut,"DD dd sh hh:mi")) + lblMsgError:setText("") end - - end - - -- Affichage des Minutes + ) local vListeMinFinNewEvent = gui:vlist(winNewEvent, 260, 260, 40, 100) vListeMinFinNewEvent:setSpaceLine(0) - local oldLblMinFinNewEvent + vListeMinFinNewEvent:setAutoSelect(true) + vListeMinFinNewEvent:setSelectionFocus(SELECTION_CENTER) + vListeMinFinNewEvent:setSelectionColor(COLOR_LIGHT_ORANGE) + vListeMinFinNewEvent:onSelect( + function () + event.fin.minute = vListeMinFinNewEvent:getSelected()*5 + lblDateHeureFin:setText(formatDate(event.fin,"DD dd sh hh:mi")) + lblMsgError:setText("") + end + ) + -- Affichage des Minutes for i=0, 55, 5 do - local lblMinuteFinNewEvent = gui:label(vListeMinFinNewEvent, 0, 0, 40, 13) - lblMinuteFinNewEvent:setFontSize(12) - lblMinuteFinNewEvent:setHorizontalAlignment(CENTER_ALIGNMENT) - lblMinuteFinNewEvent:setText(tostring(i)) - - lblMinuteFinNewEvent:onClick( - function() - - if oldLblMinFinNewEvent == lblMinuteFinNewEvent then return end - - event.fin.minute = i - lblDateHeureFin:setText(formatDate(event.debut,"DD dd sh hh:mi")) - - lblMinuteFinNewEvent:setBackgroundColor(COLOR_LIGHT_GREY) - oldLblMinFinNewEvent:setBackgroundColor(COLOR_WHITE) - oldLblMinFinNewEvent = lblMinuteFinNewEvent - - lblMsgError:setText("") - end - ) + local lblMinuteDebutNewEvent = gui:label(vListeMinDebutNewEvent, 0, 0, 40, 13) + lblMinuteDebutNewEvent:setFontSize(16) + lblMinuteDebutNewEvent:setHorizontalAlignment(CENTER_ALIGNMENT) + lblMinuteDebutNewEvent:setText(tostring(i)) - if i == event.fin.minute then - lblMinuteFinNewEvent:setBackgroundColor(COLOR_LIGHT_GREY) - vListeMinFinNewEvent:setIndex(int(i/5)) - oldLblMinFinNewEvent = lblMinuteFinNewEvent - end + local lblMinuteDebutFinEvent = gui:label(vListeMinFinNewEvent, 0, 0, 40, 13) + lblMinuteDebutFinEvent:setFontSize(16) + lblMinuteDebutFinEvent:setHorizontalAlignment(CENTER_ALIGNMENT) + lblMinuteDebutFinEvent:setText(tostring(i)) end + vListeMinDebutNewEvent:select(int(event.debut.minute / 5)) + vListeMinFinNewEvent:select(int(event.fin.minute / 5)) + if not isNew then local btnSupprimer = gui:label(winNewEvent, 60, 425, 200, 22) btnSupprimer:setRadius(10) @@ -1455,13 +1278,12 @@ function displayEvent(event) btnSupprimer:setHorizontalAlignment(CENTER_ALIGNMENT) btnSupprimer:setVerticalAlignment (CENTER_ALIGNMENT) btnSupprimer:setText("Supprimer") - btnSupprimer:onClick(function () - local oldEvent = deleteEvent(event.UID, event.debut.year, event.debut.month, event.debut.day) - - -- sauvegarde les modifs en fichier - saveDataFile(oldEvent.debut.year, oldEvent.debut.month) - switchScreen(oldEvent.debut.year, oldEvent.debut.month, oldEvent.debut.day) - end + btnSupprimer:onClick( + function () + local oldEvent = deleteEvent(event.UID, event.debut.year, event.debut.month, event.debut.day) + saveDataFile(oldEvent.debut.year, oldEvent.debut.month) + switchScreen(oldEvent.debut.year, oldEvent.debut.month, oldEvent.debut.day) + end ) end @@ -1487,6 +1309,7 @@ function displayEvent(event) end ) + end --newEvent @@ -1650,6 +1473,4 @@ function formatDate (date, pattern) :gsub("mi", minute) return result -end --formatDate - - +end --formatDate \ No newline at end of file diff --git a/storage/apps/calendrier/config.json b/storage/apps/calendrier/config.json index 64531421..7a0f99a6 100644 --- a/storage/apps/calendrier/config.json +++ b/storage/apps/calendrier/config.json @@ -1 +1 @@ -{"day":{"heureDebut":9, "heureFin":15}, "displayWeekNum":true, "defaultView":"week", "displayBusinessWeek":false} \ No newline at end of file +{"day":{"heureFin":15, "heureDebut":9}, "defaultView":"week", "displayWeekNum":true, "displayBusinessWeek":false} \ No newline at end of file diff --git a/storage/apps/calendrier/data/20249.dat b/storage/apps/calendrier/data/20249.dat deleted file mode 100644 index 26c8298d0abeda610076bc8330bec8a3dd0c557f..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 381 zcmZQzfB+^4rQpB{6<}cGg0c)PjZDmp3@yye5OT~=xwOnYgdiJKFgG)=v?LX3A_D^> z3sk%^HL(aHx?sKoBTQdLYH1Nnv9SXq%;c2BO1PWgYIF1RN;06rN(i-~o-SBi3)hvB hnp9c>vyOq0a%UPLtR}{pF#qQz=BB~}qa?p19{|dIC5!+7 diff --git a/storage/apps/calendrier/gestionDebug.lua b/storage/apps/calendrier/gestionDebug.lua index 2b1929fc..41764e1d 100644 --- a/storage/apps/calendrier/gestionDebug.lua +++ b/storage/apps/calendrier/gestionDebug.lua @@ -5,7 +5,6 @@ function debugPrint(t, indent) - local debugType = true if not indent then print("[DEBUG] "..getVariableName(t))end @@ -54,3 +53,15 @@ function getVariableName(var) return "Variable not found" end end + + + +function printEvent(event) + + print("event: ".. event.name) + print("date debut: ".. tostring(event.debut.day).."/".. tostring(event.debut.month).."/".. tostring(event.debut.year)) + print( " debut: "..tostring(event.debut.heure)..":"..tostring(event.debut.minute) ) + print( " fin: "..tostring(event.fin.heure)..":"..tostring(event.fin.minute) ) + +end + From 5d655b57a63e9e67321f4d8919a623a089123ffc Mon Sep 17 00:00:00 2001 From: pymuzard Date: Tue, 10 Sep 2024 08:29:14 +0200 Subject: [PATCH 09/13] correction serialiser --- lib/lua/src/lua_file.cpp | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/lib/lua/src/lua_file.cpp b/lib/lua/src/lua_file.cpp index a5899b2b..ba2eb205 100755 --- a/lib/lua/src/lua_file.cpp +++ b/lib/lua/src/lua_file.cpp @@ -118,15 +118,21 @@ int custom_panic_handler(lua_State* L) { std::string tableToString(const sol::table& table) { std::stringstream ss; ss << "{"; - bool first = true; + int size = 0; + for (const auto& pair : table) { size++;} + + int i=0; for (const auto& pair : table) { if (pair.first.is()) { ss << "[\"" << pair.first.as() << "\"]"; - } else { // Assuming it's an identifier - ss << pair.first.as(); + } else if(pair.first.is()) { + ss << "[" <()<< "]"; } - + else { // Assuming it's an identifier + ss << "[\"" << pair.first.as() << "\"]"; + } + i++; ss << "="; // Handle different value types carefully @@ -143,7 +149,8 @@ std::string tableToString(const sol::table& table) { //std::cout << std::endl; - ss << ", "; +// if (size != i) + ss << ", "; } ss << "}"; From 1048f698df6cc640c89065dacf095cfa1d7949e3 Mon Sep 17 00:00:00 2001 From: pymuzard Date: Tue, 10 Sep 2024 08:45:51 +0200 Subject: [PATCH 10/13] =?UTF-8?q?Mise=20=C3=A0=20jour=20app=20calendar?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- storage/apps/calendrier/app.lua | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/storage/apps/calendrier/app.lua b/storage/apps/calendrier/app.lua index 8270f89d..3ab8b1e3 100644 --- a/storage/apps/calendrier/app.lua +++ b/storage/apps/calendrier/app.lua @@ -715,6 +715,7 @@ function saveDataFile(year, month) if data[year] then if data[year][month] then local filename = PATH_DATA.."/"..tostring(year)..tostring(month)..".dat" + debugPrint(data) debugPrint(data[year][month]) saveTable(filename, data[year][month]) end @@ -760,9 +761,13 @@ function loadDataMonth(year, month, noLoadingAdjacent) -- check if a data file exists if storage:isFile(filename) then - local dataLoad = loadTable(filename) + if not dataLoad then + print("Error loading data File") + return + end + if not data[year] then data[year] = {} end if not data[year][month] then data[year][month] = {} end From 9cb706f9f063ce942cb4c210f2d2fd5dda15bd02 Mon Sep 17 00:00:00 2001 From: pymuzard Date: Tue, 10 Sep 2024 08:46:16 +0200 Subject: [PATCH 11/13] MaJ app --- storage/apps/calendrier/app.lua | 21 +-------------------- 1 file changed, 1 insertion(+), 20 deletions(-) diff --git a/storage/apps/calendrier/app.lua b/storage/apps/calendrier/app.lua index 3ab8b1e3..3d2afa11 100644 --- a/storage/apps/calendrier/app.lua +++ b/storage/apps/calendrier/app.lua @@ -715,29 +715,10 @@ function saveDataFile(year, month) if data[year] then if data[year][month] then local filename = PATH_DATA.."/"..tostring(year)..tostring(month)..".dat" - debugPrint(data) - debugPrint(data[year][month]) saveTable(filename, data[year][month]) end end ---[[ if data[year] then - if data[year][month] then - local strData = serialize (data[year][month]) - local filename = PATH_DATA.."/"..tostring(year)..tostring(month)..".dat" - fileData = storage:file (filename, WRITE) - fileData:open() - fileData:write(strData) - fileData:close() - fileData = nil - - return - end - end - - print("saveDataFile - aucune donnée à sauvegarder pour le mois "..tostring(month).." de "..tostring(year)) -]]-- - end -- Chargement des fichiers event dans la structure data @@ -764,7 +745,7 @@ function loadDataMonth(year, month, noLoadingAdjacent) local dataLoad = loadTable(filename) if not dataLoad then - print("Error loading data File") + print("Error loading data from "..filename) return end From fe2498d29cb24af9f36486024e54491d10905d50 Mon Sep 17 00:00:00 2001 From: pymuzard Date: Tue, 10 Sep 2024 11:49:54 +0200 Subject: [PATCH 12/13] correction uint en uint32_t --- src/main.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main.cpp b/src/main.cpp index 51c1bbe7..f099ba8b 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -126,7 +126,7 @@ void mainLoop(void* data) { applications::launcher::free(); launcher = false; } - for (uint i = 0; i < 10 && AppManager::isAnyVisibleApp(); i++) // define a limit on how many apps can be stopped (prevent from a loop) + for (uint32_t i = 0; i < 10 && AppManager::isAnyVisibleApp(); i++) // define a limit on how many apps can be stopped (prevent from a loop) { AppManager::quitApp(); } From 540c611e0a9478ed807998b44b92ad311eddd3f9 Mon Sep 17 00:00:00 2001 From: pymuzard Date: Tue, 10 Sep 2024 19:38:27 +0200 Subject: [PATCH 13/13] ajout gestion erreur sur load / save Table Lua --- lib/lua/src/lua_file.cpp | 37 +++++++++++++++++++++----- storage/apps/calendrier/config.json | 2 +- storage/apps/calendrier/data/20249.dat | 1 + 3 files changed, 32 insertions(+), 8 deletions(-) create mode 100644 storage/apps/calendrier/data/20249.dat diff --git a/lib/lua/src/lua_file.cpp b/lib/lua/src/lua_file.cpp index ba2eb205..f47b112e 100755 --- a/lib/lua/src/lua_file.cpp +++ b/lib/lua/src/lua_file.cpp @@ -170,8 +170,19 @@ void save_lua_table(sol::state& lua, const std::string& path, sol::table table) } std::cout << tableToString(table) << std::endl; - - file << tableToString(table); + try{ + file << tableToString(table); + } + catch (const sol::error& e) { + // Handle Solidity specific errors + std::cerr << "Sol error: " << e.what() << std::endl; + } catch (const std::exception& e) { + // Handle other standard exceptions + std::cerr << "Standard error: " << e.what() << std::endl; + } catch (...) { + // Handle any other unknown exceptions + std::cerr << "Unknown error" << std::endl; + } file.close(); } @@ -186,13 +197,25 @@ sol::table load_lua_table(sol::state& lua, const std::string& path) { std::stringstream content; content << file.rdbuf(); - lua.script("returntable=" + content.str()); + sol::table resultTable; + try { + lua.script("returntable=" + content.str()); + std::string tableName = "returntable"; // Adjust if your table has a different name + // Retrieve the created table from the Lua state + resultTable= lua[tableName]; + } + catch (const sol::error& e) { + // Handle Solidity specific errors + std::cerr << "Sol error on table serialisation" << e.what() << std::endl; + } catch (const std::exception& e) { + // Handle other standard exceptions + std::cerr << "Error: " << e.what() << std::endl; + } catch (...) { + // Handle any other unknown exceptions + std::cerr << "Unknown error" << std::endl; + } // Get the global table name (assuming the string defines a table named 'resultTable') - std::string tableName = "returntable"; // Adjust if your table has a different name - - // Retrieve the created table from the Lua state - sol::table resultTable = lua[tableName]; return resultTable; } diff --git a/storage/apps/calendrier/config.json b/storage/apps/calendrier/config.json index 7a0f99a6..ddfd665d 100644 --- a/storage/apps/calendrier/config.json +++ b/storage/apps/calendrier/config.json @@ -1 +1 @@ -{"day":{"heureFin":15, "heureDebut":9}, "defaultView":"week", "displayWeekNum":true, "displayBusinessWeek":false} \ No newline at end of file +{"day":{"heureFin":18, "heureDebut":9}, "displayBusinessWeek":false, "defaultView":"week", "displayWeekNum":true} \ No newline at end of file diff --git a/storage/apps/calendrier/data/20249.dat b/storage/apps/calendrier/data/20249.dat new file mode 100644 index 00000000..769fe527 --- /dev/null +++ b/storage/apps/calendrier/data/20249.dat @@ -0,0 +1 @@ +{[10]={["18084540232"]={["UID"]="18084540232", ["fin"]={["minute"]=0, ["year"]=2024, ["heure"]=17, ["day"]=10, ["month"]=9, }, ["name"]="chi", ["debut"]={["minute"]=0, ["year"]=2024, ["heure"]=16, ["day"]=10, ["month"]=9, }, }, }, } \ No newline at end of file