From 0b4d3fbc200e646eed48a1a919dde9ee03678688 Mon Sep 17 00:00:00 2001 From: Star Rauchenberger Date: Sat, 10 Dec 2022 11:38:57 -0500 Subject: Bot can submit to scoreboard now Also updated the scoreboard styling refs #13 --- rails/app/assets/stylesheets/lingo/main.css.scss | 37 ++++++++++++++++++++++-- rails/app/controllers/lingo/scores_controller.rb | 10 +++++-- rails/app/views/lingo/scores/index.html.haml | 9 ++++-- 3 files changed, 48 insertions(+), 8 deletions(-) (limited to 'rails') diff --git a/rails/app/assets/stylesheets/lingo/main.css.scss b/rails/app/assets/stylesheets/lingo/main.css.scss index c5bdad0..a65cd94 100644 --- a/rails/app/assets/stylesheets/lingo/main.css.scss +++ b/rails/app/assets/stylesheets/lingo/main.css.scss @@ -1,11 +1,12 @@ body { background-color: black; color: white; + font-family: sans-serif; } #header { width: 100%; - + img { max-width: 80%; margin: 0 auto; @@ -15,10 +16,40 @@ body { h2 { text-align: center; - font-family: sans-serif; } #scores { - width: 50%; margin: 0 auto; + border-spacing: 0px; + tr { + &.even { + background-color: gray; + } + &.odd { + background-color: purple; + } + th { + text-align: left; + padding-left: 0.5em; + padding-bottom: 0.5em; + } + td { + padding-right: 1em; + padding-top: 0.5em; + padding-bottom: 0.5em; + border-collapse: collapse; + &:first-child { + padding-left: 1em; + } + img { + width: 2em; + } + &.score-pfp { + width: 2em; + } + &.score-value { + text-align: center; + } + } + } } \ No newline at end of file diff --git a/rails/app/controllers/lingo/scores_controller.rb b/rails/app/controllers/lingo/scores_controller.rb index 63fd0f9..59bbd9d 100644 --- a/rails/app/controllers/lingo/scores_controller.rb +++ b/rails/app/controllers/lingo/scores_controller.rb @@ -1,5 +1,7 @@ module Lingo class ScoresController < ApplicationController + skip_before_action :verify_authenticity_token, only: [:update] + def index @scores = Score.order(score: :desc) end @@ -8,13 +10,15 @@ module Lingo if params[:secret_code] != Lingo.secret_code then head :unauthorized else - score = Score.find_or_create_by(user_id: params[:user_id]) + score = Score.find_or_create_by(user_id: params[:user_id]) do |score| + score.score = 0 + end score.username = params[:username] - score.avatar_url = params[:avatar_url] + score.avatar_url = CGI.unescape(params[:avatar_url]) score.score += 1 score.save! - render :blank + head :created end end end diff --git a/rails/app/views/lingo/scores/index.html.haml b/rails/app/views/lingo/scores/index.html.haml index f0f681d..afcd0c7 100644 --- a/rails/app/views/lingo/scores/index.html.haml +++ b/rails/app/views/lingo/scores/index.html.haml @@ -1,7 +1,12 @@ %h2 Bot Puzzles Scoreboard %table#scores - - @scores.each do |score| - %tr + %tr.scores-header + %th + %th{colspan: 2} Player + %th Score + - @scores.each_with_index do |score,index| + %tr{class: cycle("even", "odd")} + %td.score-index #{index+1}. %td.score-pfp - if !score.avatar_url.nil? = image_tag score.avatar_url -- cgit 1.4.1