Add basic deadline to sections index

This commit is contained in:
Charlotte Van Petegem 2025-05-25 21:54:34 +02:00
parent 782355322e
commit f4106b9fb6
Signed by: chvp
SSH key fingerprint: SHA256:s9rb8jBVfdahqWHuBAcHCBP1wmj4eYQXZfqgz4H3E9E
15 changed files with 175 additions and 1 deletions

View file

@ -44,6 +44,30 @@ header {
text-decoration-line: underline;
}
.deadline-info-container {
padding: 2rem 0;
display: flex;
flex-direction: column;
gap: 2rem;
}
.extension-grid {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 3rem;
}
.extension {
align-self: stretch;
color: black;
background-color: white;
padding: 1rem;
display: flex;
flex-direction: row;
align-items: center;
justify-content: space-between;
}
.title-card-grid {
display: grid;
grid-template-columns: 1fr 1fr 1fr;

View file

@ -0,0 +1,7 @@
class ExtensionsController < ApplicationController
def confirm
Extension.find(params[:id]).confirm!
redirect_to sections_url
end
end

View file

@ -1,6 +1,11 @@
class SectionsController < ApplicationController
def index
@sections = Section.all.order(id: :asc)
@extensions = Extension.all.order(id: :asc)
@deadline = Time.zone.local(2025, 7, 8, 0, 0, 0)
@extensions.each do |e|
@deadline = e.affect_deadline(@deadline)
end
end
def show

View file

@ -0,0 +1,2 @@
module ExtensionsHelper
end

View file

@ -5,6 +5,7 @@ import initPoliticianQuestions from './politicians_answer.js'
import initAcrosticQuestions from './acrostic_answer.js'
import initConnectionsQuestions from './connections_answer.js'
import initLyricsQuestions from './lyrics_answer.js'
import initDeadlineDisplay from './deadline_display.js'
import { Sortable, Swap } from 'sortablejs'
@ -17,4 +18,5 @@ addEventListener("DOMContentLoaded", () => {
initAcrosticQuestions()
initConnectionsQuestions()
initLyricsQuestions()
initDeadlineDisplay()
})

View file

@ -0,0 +1,27 @@
export default function initDeadlineDisplay() {
document.querySelectorAll('[data-behaviour="deadline_display"]').forEach((span) => {
const deadline = new Date(span.dataset.deadline)
function update() {
const remaining = Math.floor((deadline - new Date()) / 1000)
const days = Math.floor(remaining / (60 * 60 * 24))
const hours = Math.floor((remaining % (60 * 60 * 24)) / (60 * 60))
const minutes = Math.floor((remaining % (60 * 60)) / 60)
const seconds = remaining % 60
let remainingText = ""
if (days > 0) {
remainingText += `${days} dagen, `
}
if (days > 0 || hours > 0) {
remainingText += `${hours} uren, `
}
if (days > 0 || hours > 0 || minutes > 0) {
remainingText += `${minutes} minuten en `
}
remainingText += `${seconds} seconden`
span.innerText = remainingText
}
setInterval(update, 200)
})
}

21
app/models/extension.rb Normal file
View file

@ -0,0 +1,21 @@
# == Schema Information
#
# Table name: extensions
#
# id :integer not null, primary key
# confirmed :boolean
# reason :text
# created_at :datetime not null
# updated_at :datetime not null
#
class Extension < ApplicationRecord
def affect_deadline(deadline)
return deadline unless confirmed
deadline + 6.weeks
end
def confirm!
update!(confirmed: true)
end
end

View file

@ -1,3 +1,21 @@
<div class="deadline-info-container">
<div>
Je hebt nog
<span class="deadline-display" data-behaviour="deadline_display" data-deadline="<%= @deadline.httpdate %>">tijd tot <%= @deadline.to_fs(:short) %>.</span>
</div>
Je kan extra tijd krijgen door volgende dingen te organiseren. Je krijgt dan 6 weken extra.
<div class="extension-grid">
<% @extensions.each do |extension| %>
<div class="extension">
<span><%= extension.reason %></span>
<%= form_with url: confirm_extension_path(extension), method: :put do |form| %>
<%= form.submit "Bevestig", disabled: extension.confirmed %>
<% end %>
</div>
<% end %>
</div>
</div>
<div class="title-card-grid">
<% @sections.each do |section| %>
<%= link_to(section_url(section), html_options = { class: 'title-card-container' }) do %>

View file

@ -28,6 +28,8 @@ module EntranceExam
# Common ones are `templates`, `generators`, or `middleware`, for example.
config.autoload_lib(ignore: %w[assets tasks])
config.time_zone = 'Europe/Brussels'
# Configuration for the application, engines, and railties goes here.
#
# These settings can be overridden in specific environments using the files

View file

@ -21,4 +21,10 @@ Rails.application.routes.draw do
put :answer
end
end
resources "extensions", only: [] do
member do
put :confirm
end
end
end

View file

@ -0,0 +1,10 @@
class CreateExtensions < ActiveRecord::Migration[8.0]
def change
create_table :extensions do |t|
t.text :reason
t.boolean :confirmed
t.timestamps
end
end
end

9
db/schema.rb generated
View file

@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema[8.0].define(version: 2025_05_15_124656) do
ActiveRecord::Schema[8.0].define(version: 2025_05_25_115606) do
create_table "active_storage_attachments", force: :cascade do |t|
t.string "name", null: false
t.string "record_type", null: false
@ -47,6 +47,13 @@ ActiveRecord::Schema[8.0].define(version: 2025_05_15_124656) do
t.index ["question_id"], name: "index_answers_on_question_id"
end
create_table "extensions", force: :cascade do |t|
t.text "reason"
t.boolean "confirmed"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
end
create_table "questions", force: :cascade do |t|
t.integer "section_id", null: false
t.text "text", null: false

View file

@ -0,0 +1,7 @@
require "test_helper"
class ExtensionsControllerTest < ActionDispatch::IntegrationTest
# test "the truth" do
# assert true
# end
end

19
test/fixtures/extensions.yml vendored Normal file
View file

@ -0,0 +1,19 @@
# == Schema Information
#
# Table name: extensions
#
# id :integer not null, primary key
# confirmed :boolean
# reason :text
# created_at :datetime not null
# updated_at :datetime not null
#
extension_housewarming:
id: 2
reason: Housewarming
confirmed: false
extension_dinner:
id: 1
reason: Diner
confirmed: false

View file

@ -0,0 +1,17 @@
# == Schema Information
#
# Table name: extensions
#
# id :integer not null, primary key
# confirmed :boolean
# reason :text
# created_at :datetime not null
# updated_at :datetime not null
#
require "test_helper"
class ExtensionTest < ActiveSupport::TestCase
# test "the truth" do
# assert true
# end
end