guess moods according to user pref
This commit is contained in:
parent
c5c70c91ba
commit
939668c4fb
6 changed files with 17 additions and 14 deletions
|
|
@ -2,11 +2,9 @@ class HomeController < ApplicationController
|
|||
allow_unauthenticated_access
|
||||
|
||||
def index
|
||||
user = User.find_by(username: request.subdomain)
|
||||
if user&.public?
|
||||
@mode = user.current_mood
|
||||
@history = user.history
|
||||
render template: "moods/index"
|
||||
@user = User.find_by(username: request.subdomain)
|
||||
if @user&.public?
|
||||
render "moods/index"
|
||||
else
|
||||
redirect_to dashboard_path
|
||||
end
|
||||
|
|
|
|||
|
|
@ -1,6 +1,5 @@
|
|||
class MoodsController < ApplicationController
|
||||
def index
|
||||
@mode = Current.user.current_mood
|
||||
@history = Current.user.history
|
||||
@user = Current.user
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
module MoodsHelper
|
||||
def mode_for(mood)
|
||||
if params[:guess] == "active"
|
||||
def mode_for(mood, user)
|
||||
if user.guess?
|
||||
mood[:mode] || mood[:guess] || "unknown"
|
||||
else
|
||||
mood[:mode] || "unknown"
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
<div class="current-day column is-hidden-mobile">
|
||||
<section class="m-4">
|
||||
<figure class="image has-ratio">
|
||||
<%= image_tag(@mode + ".jpg", "data-mood-target": "image") %>
|
||||
<%= image_tag(@user.current_mood + ".jpg", "data-mood-target": "image") %>
|
||||
</figure>
|
||||
</section>
|
||||
</div>
|
||||
|
|
@ -36,19 +36,19 @@
|
|||
<div class="container mb-4 p-3 has-background-white day-info">
|
||||
<div class="title is-4">
|
||||
<span class="icon"><i class="fa-regular fa-calendar"></i></span>
|
||||
<span data-mood-target="modeDay">Aujourd'hui : <%= @mode %></span>
|
||||
<span data-mood-target="modeDay">Aujourd'hui : <%= @user.current_mood %></span>
|
||||
</div>
|
||||
</div>
|
||||
<div class="logs">
|
||||
<div class="is-flex is-flex-direction-row is-flex-wrap-wrap mb-3">
|
||||
<% @history.each do |month| %>
|
||||
<% @user.history.each do |month| %>
|
||||
<div class="mr-3">
|
||||
<div> <%= I18n.l(month[:month], format: "%b %y").capitalize %></div>
|
||||
<div class="is-flex is-flex-wrap-wrap">
|
||||
<% month[:weeks].each do |week| %>
|
||||
<div class="is-flex is-flex-direction-column is-flex-wrap-wrap mb-3">
|
||||
<% week.each do |mood| %>
|
||||
<% mode = mode_for(mood) %>
|
||||
<% mode = mode_for(mood, @user) %>
|
||||
<div data-image="<%= asset_path(mode + ".jpg") %>" data-mode="<%= mode %>" data-day="<%= l mood[:recorded_at].to_date %>" data-action="click->mood#updateDayInfo" title="<%= l(mood[:recorded_at].to_date) %> : <%= mode %>" class="day <%= mode %>"></div>
|
||||
<% end %>
|
||||
</div>
|
||||
|
|
|
|||
5
db/migrate/20260226101258_add_guess_to_users.rb
Normal file
5
db/migrate/20260226101258_add_guess_to_users.rb
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
class AddGuessToUsers < ActiveRecord::Migration[8.0]
|
||||
def change
|
||||
add_column :users, :guess, :boolean, default: false
|
||||
end
|
||||
end
|
||||
3
db/schema.rb
generated
3
db/schema.rb
generated
|
|
@ -10,7 +10,7 @@
|
|||
#
|
||||
# It's strongly recommended that you check this file into your version control system.
|
||||
|
||||
ActiveRecord::Schema[8.0].define(version: 2026_02_19_114040) do
|
||||
ActiveRecord::Schema[8.0].define(version: 2026_02_26_101258) do
|
||||
create_table "moods", force: :cascade do |t|
|
||||
t.string "mode"
|
||||
t.datetime "recorded_at"
|
||||
|
|
@ -48,6 +48,7 @@ ActiveRecord::Schema[8.0].define(version: 2026_02_19_114040) do
|
|||
t.datetime "invitation_accepted_at"
|
||||
t.string "username", null: false
|
||||
t.boolean "public", default: false
|
||||
t.boolean "guess", default: false
|
||||
t.index ["email_address"], name: "index_users_on_email_address", unique: true
|
||||
end
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue