Add basic deadline to sections index
This commit is contained in:
parent
782355322e
commit
f4106b9fb6
15 changed files with 175 additions and 1 deletions
|
@ -44,6 +44,30 @@ header {
|
||||||
text-decoration-line: underline;
|
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 {
|
.title-card-grid {
|
||||||
display: grid;
|
display: grid;
|
||||||
grid-template-columns: 1fr 1fr 1fr;
|
grid-template-columns: 1fr 1fr 1fr;
|
||||||
|
|
7
app/controllers/extensions_controller.rb
Normal file
7
app/controllers/extensions_controller.rb
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
class ExtensionsController < ApplicationController
|
||||||
|
def confirm
|
||||||
|
Extension.find(params[:id]).confirm!
|
||||||
|
|
||||||
|
redirect_to sections_url
|
||||||
|
end
|
||||||
|
end
|
|
@ -1,6 +1,11 @@
|
||||||
class SectionsController < ApplicationController
|
class SectionsController < ApplicationController
|
||||||
def index
|
def index
|
||||||
@sections = Section.all.order(id: :asc)
|
@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
|
end
|
||||||
|
|
||||||
def show
|
def show
|
||||||
|
|
2
app/helpers/extensions_helper.rb
Normal file
2
app/helpers/extensions_helper.rb
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
module ExtensionsHelper
|
||||||
|
end
|
|
@ -5,6 +5,7 @@ import initPoliticianQuestions from './politicians_answer.js'
|
||||||
import initAcrosticQuestions from './acrostic_answer.js'
|
import initAcrosticQuestions from './acrostic_answer.js'
|
||||||
import initConnectionsQuestions from './connections_answer.js'
|
import initConnectionsQuestions from './connections_answer.js'
|
||||||
import initLyricsQuestions from './lyrics_answer.js'
|
import initLyricsQuestions from './lyrics_answer.js'
|
||||||
|
import initDeadlineDisplay from './deadline_display.js'
|
||||||
|
|
||||||
import { Sortable, Swap } from 'sortablejs'
|
import { Sortable, Swap } from 'sortablejs'
|
||||||
|
|
||||||
|
@ -17,4 +18,5 @@ addEventListener("DOMContentLoaded", () => {
|
||||||
initAcrosticQuestions()
|
initAcrosticQuestions()
|
||||||
initConnectionsQuestions()
|
initConnectionsQuestions()
|
||||||
initLyricsQuestions()
|
initLyricsQuestions()
|
||||||
|
initDeadlineDisplay()
|
||||||
})
|
})
|
||||||
|
|
27
app/javascript/deadline_display.js
Normal file
27
app/javascript/deadline_display.js
Normal 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
21
app/models/extension.rb
Normal 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
|
|
@ -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">
|
<div class="title-card-grid">
|
||||||
<% @sections.each do |section| %>
|
<% @sections.each do |section| %>
|
||||||
<%= link_to(section_url(section), html_options = { class: 'title-card-container' }) do %>
|
<%= link_to(section_url(section), html_options = { class: 'title-card-container' }) do %>
|
||||||
|
|
|
@ -28,6 +28,8 @@ module EntranceExam
|
||||||
# Common ones are `templates`, `generators`, or `middleware`, for example.
|
# Common ones are `templates`, `generators`, or `middleware`, for example.
|
||||||
config.autoload_lib(ignore: %w[assets tasks])
|
config.autoload_lib(ignore: %w[assets tasks])
|
||||||
|
|
||||||
|
config.time_zone = 'Europe/Brussels'
|
||||||
|
|
||||||
# Configuration for the application, engines, and railties goes here.
|
# Configuration for the application, engines, and railties goes here.
|
||||||
#
|
#
|
||||||
# These settings can be overridden in specific environments using the files
|
# These settings can be overridden in specific environments using the files
|
||||||
|
|
|
@ -21,4 +21,10 @@ Rails.application.routes.draw do
|
||||||
put :answer
|
put :answer
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
resources "extensions", only: [] do
|
||||||
|
member do
|
||||||
|
put :confirm
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
10
db/migrate/20250525115606_create_extensions.rb
Normal file
10
db/migrate/20250525115606_create_extensions.rb
Normal 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
9
db/schema.rb
generated
|
@ -10,7 +10,7 @@
|
||||||
#
|
#
|
||||||
# It's strongly recommended that you check this file into your version control system.
|
# 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|
|
create_table "active_storage_attachments", force: :cascade do |t|
|
||||||
t.string "name", null: false
|
t.string "name", null: false
|
||||||
t.string "record_type", 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"
|
t.index ["question_id"], name: "index_answers_on_question_id"
|
||||||
end
|
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|
|
create_table "questions", force: :cascade do |t|
|
||||||
t.integer "section_id", null: false
|
t.integer "section_id", null: false
|
||||||
t.text "text", null: false
|
t.text "text", null: false
|
||||||
|
|
7
test/controllers/extensions_controller_test.rb
Normal file
7
test/controllers/extensions_controller_test.rb
Normal 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
19
test/fixtures/extensions.yml
vendored
Normal 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
|
17
test/models/extension_test.rb
Normal file
17
test/models/extension_test.rb
Normal 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
|
Loading…
Add table
Add a link
Reference in a new issue