diff --git a/app/assets/stylesheets/kluk.css b/app/assets/stylesheets/kluk.css index fb807ba..659dea5 100644 --- a/app/assets/stylesheets/kluk.css +++ b/app/assets/stylesheets/kluk.css @@ -86,31 +86,6 @@ main { height: 15px; } -.creatif { - background-color: red; -} - -.unknown { - border: 2px double grey; - background-color: white; -} - -.en-charge { - background-color: orange; -} - -.frigo-vide { - background-color: grey; -} - -.croisiere { - background-color: green; -} - -.afond { - background-color: black; -} - .info { margin: 30px; } diff --git a/app/helpers/moods_helper.rb b/app/helpers/moods_helper.rb index 0c04021..6a49c77 100644 --- a/app/helpers/moods_helper.rb +++ b/app/helpers/moods_helper.rb @@ -1,9 +1,15 @@ module MoodsHelper def mode_for(mood, user) if user.guess? - mood[:mode] || mood[:guess] || "unknown" + mood[:mode] || mood[:guess] || { label: "unknown", color: "white" } else - mood[:mode] || "unknown" + mood[:mode] || { label: "unknown", color: "white" } end end + + def style_for_mode(mode) + style = "background-color: #{mode[:color]};" + style += " border: 2px double grey;" if mode[:label] == "unknown" + style + end end diff --git a/app/models/mood.rb b/app/models/mood.rb index 2b6a392..c065440 100644 --- a/app/models/mood.rb +++ b/app/models/mood.rb @@ -1,3 +1,4 @@ class Mood < ApplicationRecord belongs_to :user + belongs_to :mode end diff --git a/app/services/mood_calendar_service.rb b/app/services/mood_calendar_service.rb index 04553bb..bb54b97 100644 --- a/app/services/mood_calendar_service.rb +++ b/app/services/mood_calendar_service.rb @@ -2,10 +2,10 @@ class MoodCalendarService def self.generate_calendar(moods, start_date: nil, end_date: Date.current) # Convertir la relation ActiveRecord en tableau de hash - data = moods.order(:recorded_at) - .pluck(:mode, :recorded_at) - .map { |mode, recorded_at| { mode: mode, recorded_at: recorded_at } } - + data = moods.joins(:mode) + .order(:recorded_at) + .pluck(:recorded_at, "modes.label", "modes.color") + .map { |recorded_at, label, color| { mode: { label: label, color: color }, recorded_at: recorded_at } } if data.empty? start_date = Date.current @@ -43,28 +43,21 @@ class MoodCalendarService # Regrouper par mois avec semaines commençant au premier lundi complete_data.group_by { |d| d[:recorded_at].to_date.beginning_of_month } .map do |month_start, month_data| - # Trouver le premier lundi du mois (à partir du 1er du mois) first_monday = month_start first_monday = first_monday.next_occurring(:monday) unless first_monday.monday? - # Trouver le premier lundi du mois SUIVANT next_month_start = month_start.next_month.beginning_of_month next_first_monday = next_month_start next_first_monday = next_first_monday.next_occurring(:monday) unless next_first_monday.monday? - # Le dernier jour du mois est le dimanche précédant le premier lundi du mois suivant month_end = next_first_monday - 1.day - # Créer un hash pour accès rapide aux données de complete_data (qui contient déjà les guess) data_hash = complete_data.index_by { |d| d[:recorded_at].to_date } - # Générer tous les jours du premier lundi jusqu'au dimanche avant le prochain lundi all_days = (first_monday..month_end).map do |date| - # Utiliser directement les données de complete_data qui ont déjà le bon guess data_hash[date] || { mode: nil, recorded_at: date.to_datetime, guess: nil } end - # Grouper par semaines weeks = all_days.group_by { |d| d[:recorded_at].to_date.beginning_of_week(:monday) } .sort_by { |week_start, _| week_start } .map { |_, week_moods| week_moods } @@ -75,4 +68,4 @@ class MoodCalendarService } end end -end +end# diff --git a/app/views/moods/index.html.erb b/app/views/moods/index.html.erb index 1d5cf5e..5e0bc10 100644 --- a/app/views/moods/index.html.erb +++ b/app/views/moods/index.html.erb @@ -2,7 +2,7 @@