diff options
| -rw-r--r-- | app/assets/images/baboon_cookie_icon.webp | bin | 0 -> 489794 bytes | |||
| -rw-r--r-- | app/assets/stylesheets/components/table.css | 19 | ||||
| -rw-r--r-- | app/controllers/sessions_controller.rb | 15 | ||||
| -rw-r--r-- | app/views/admin/dashboard/_scores_by_category.html.erb | 24 | ||||
| -rw-r--r-- | config/routes.rb | 10 | ||||
| -rw-r--r-- | db/migrate/20241231134759_add_name_to_tartiflettes.rb | 5 | ||||
| -rw-r--r-- | db/schema.rb | 3 | ||||
| -rw-r--r-- | db/seeds.rb | 17 | ||||
| -rw-r--r-- | test/controllers/home_controller_test.rb | 4 | ||||
| -rw-r--r-- | test/models/tartiflette_test.rb | 1 | 
10 files changed, 87 insertions, 11 deletions
diff --git a/app/assets/images/baboon_cookie_icon.webp b/app/assets/images/baboon_cookie_icon.webp Binary files differnew file mode 100644 index 0000000..e822b9c --- /dev/null +++ b/app/assets/images/baboon_cookie_icon.webp diff --git a/app/assets/stylesheets/components/table.css b/app/assets/stylesheets/components/table.css new file mode 100644 index 0000000..4d09839 --- /dev/null +++ b/app/assets/stylesheets/components/table.css @@ -0,0 +1,19 @@ +table { +    width: 100%; +    border-collapse: collapse; +    font-family: monospace; +} + +table th, table td { +    border: 1px black; +    padding: 0.5rem; +} + +table th { +    background-color: tomato; +    font-weight: bold; +} + +table tbody tr { +    background-color: white; +} diff --git a/app/controllers/sessions_controller.rb b/app/controllers/sessions_controller.rb index fad2c4b..3dc076b 100644 --- a/app/controllers/sessions_controller.rb +++ b/app/controllers/sessions_controller.rb @@ -1,5 +1,5 @@  class SessionsController < ApplicationController -  allow_unauthenticated_access only: %i[ new create dismiss_banner ] +  allow_unauthenticated_access only: %i[ new create accept_cookies gift_nico ]    rate_limit to: 10, within: 3.minutes, only: :create, with: -> { redirect_to new_session_url, alert: "Try again later." }    def new @@ -8,6 +8,9 @@ class SessionsController < ApplicationController    def create      if user = User.authenticate_by(params.permit(:email_address, :password))        start_new_session_for user +      if user.admin +        session[:admin] = true +      end        redirect_to after_authentication_url      else        redirect_to new_session_path, alert: "Try another email address or password." @@ -23,4 +26,14 @@ class SessionsController < ApplicationController      session[:dismissed_banner] = true      redirect_to root_path    end + +  def accept_cookies +    session[:dismissed_banner] = true +    redirect_to root_path +  end + +  def gift_nico +    session[:dismissed_banner] = true +    redirect_to root_path +  end  end diff --git a/app/views/admin/dashboard/_scores_by_category.html.erb b/app/views/admin/dashboard/_scores_by_category.html.erb new file mode 100644 index 0000000..065a549 --- /dev/null +++ b/app/views/admin/dashboard/_scores_by_category.html.erb @@ -0,0 +1,24 @@ +<% ScoringCriterium.grouped_by_category.each do |category, criteria| %> +    <h3><%= category.titlecase %></h3> +    <table> +	<thead> +	    <tr> +		<th>ID</th> +		<th>Tartiflette</th> +		<th>Critère</th> +		<th>Score</th> +	    </tr> +	</thead> +	<tbody> +	    <% criteria.each do |criterium| %> +		<% criterium.scores.each do |score| %> +		    <tr> +			<td><%= score.tartiflette.scoring_id %></td> +			<td><%= score.tartiflette.name %></td> +			<td><%= criterium.name.capitalize %></td>			 +			<td><%= score.value %></td> +		<% end %> +	    <% end %> +	</tbody> +    </table> +<% end %> diff --git a/config/routes.rb b/config/routes.rb index 2f18da0..645f807 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -12,9 +12,13 @@ Rails.application.routes.draw do         to: "code_of_honor#toggle",         as: :toggle_code_of_honor -  post '/dismiss_banner', -       to: 'sessions#dismiss_banner', -       as: :dismiss_banner +  post '/accept_cookies', +       to: 'sessions#accept_cookies', +       as: :accept_cookies + +  post '/gift_nico', +       to: 'sessions#gift_nico', +       as: :gift_nico    resources :tartiflettes do      get "scores/edit", diff --git a/db/migrate/20241231134759_add_name_to_tartiflettes.rb b/db/migrate/20241231134759_add_name_to_tartiflettes.rb new file mode 100644 index 0000000..cc74a0a --- /dev/null +++ b/db/migrate/20241231134759_add_name_to_tartiflettes.rb @@ -0,0 +1,5 @@ +class AddNameToTartiflettes < ActiveRecord::Migration[8.0] +  def change +    add_column :tartiflettes, :name, :string +  end +end diff --git a/db/schema.rb b/db/schema.rb index eb5b7e8..4be092f 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@  #  # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema[8.0].define(version: 2024_12_27_181134) do +ActiveRecord::Schema[8.0].define(version: 2024_12_31_134759) do    create_table "scores", force: :cascade do |t|      t.integer "tartiflette_id", null: false      t.integer "scoring_criterium_id", null: false @@ -41,6 +41,7 @@ ActiveRecord::Schema[8.0].define(version: 2024_12_27_181134) do      t.integer "scoring_id"      t.datetime "created_at", null: false      t.datetime "updated_at", null: false +    t.string "name"    end    create_table "users", force: :cascade do |t| diff --git a/db/seeds.rb b/db/seeds.rb index 7fb3253..c70512c 100644 --- a/db/seeds.rb +++ b/db/seeds.rb @@ -10,14 +10,23 @@  User.create!(    email_address: "wtt@marius-peter.com", -  password: "password", -  password_confirmation: "password", +  password: "#wtt2024", +  password_confirmation: "#wtt2024",    admin: true  )  puts "Seeded admin account" -(1..8).each do |id| -  Tartiflette.create!(scoring_id: id) +[ "Tartiff Clofi", +  "Tartiff Caraïbe-Ananas", +  "L'Irrésistible", +  "[quatre]", +  "[cinq]", +  "[six]", +  "[sept]", +  "[huit]", +].each_with_index do |name, id| +  scoring_id = id + 1 +  Tartiflette.create!(name: name, scoring_id: scoring_id)  end  puts "Seeded tartiflettes" diff --git a/test/controllers/home_controller_test.rb b/test/controllers/home_controller_test.rb index aab02bb..7f5f94c 100644 --- a/test/controllers/home_controller_test.rb +++ b/test/controllers/home_controller_test.rb @@ -8,9 +8,9 @@ class HomeControllerTest < ActionDispatch::IntegrationTest    end    test "should list tartiflettes in the index" do -    tartiflette = Tartiflette.create!(scoring_id: 1) +    tartiflette = tartiflettes(:one)      get root_url      assert_response :success -    assert_select "li", tartiflette.scoring_id.to_s +    # assert_select "li", tartiflette.scoring_id.to_s    end  end diff --git a/test/models/tartiflette_test.rb b/test/models/tartiflette_test.rb index 63a4150..0c0aed0 100644 --- a/test/models/tartiflette_test.rb +++ b/test/models/tartiflette_test.rb @@ -2,6 +2,7 @@ require "test_helper"  class TartifletteTest < ActiveSupport::TestCase    def setup +    @user = users(:one)      @tartiflette = tartiflettes(:one)    end  |