Skip to content

Commit

Permalink
Hackathon applications
Browse files Browse the repository at this point in the history
  • Loading branch information
northeastprince committed Aug 6, 2023
1 parent 06e5bd2 commit 1c95cbc
Show file tree
Hide file tree
Showing 24 changed files with 220 additions and 23 deletions.
2 changes: 2 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,11 @@ gem "airrecord" # Airtable client

# Assets
gem "sprockets-rails"
gem "sass-rails"
gem "importmap-rails"
gem "turbo-rails"
gem "stimulus-rails"
gem "local_time"

# Active Storage
gem "aws-sdk-s3", require: false
Expand Down
14 changes: 14 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,7 @@ GEM
railties (>= 5.2)
rexml
lint_roller (1.1.0)
local_time (2.1.0)
loofah (2.21.3)
crass (~> 1.0.2)
nokogiri (>= 1.12.0)
Expand Down Expand Up @@ -269,6 +270,16 @@ GEM
ffi (~> 1.12)
ruby2_keywords (0.0.5)
rubyzip (2.3.2)
sass-rails (6.0.0)
sassc-rails (~> 2.1, >= 2.1.1)
sassc (2.4.0)
ffi (~> 1.9)
sassc-rails (2.1.2)
railties (>= 4.0.0)
sassc (>= 2.0)
sprockets (> 3.0)
sprockets-rails
tilt
selenium-webdriver (4.10.0)
rexml (~> 3.2, >= 3.2.5)
rubyzip (>= 1.2.2, < 3.0)
Expand Down Expand Up @@ -301,6 +312,7 @@ GEM
stimulus-rails (1.2.1)
railties (>= 6.0.0)
thor (1.2.2)
tilt (2.2.0)
timeout (0.4.0)
turbo-rails (1.4.0)
actionpack (>= 6.0.0)
Expand Down Expand Up @@ -348,12 +360,14 @@ DEPENDENCIES
importmap-rails
jbuilder
letter_opener_web
local_time
pagy
pg
puma
rack-mini-profiler
rails (~> 7.0.6)
redis
sass-rails
selenium-webdriver
shoulda
spring
Expand Down
9 changes: 9 additions & 0 deletions app/assets/stylesheets/animations.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
@keyframes appear-then-fade {
0%,100% {
opacity: 0
}

6%,66% {
opacity: 1
}
}
15 changes: 0 additions & 15 deletions app/assets/stylesheets/application.css

This file was deleted.

6 changes: 6 additions & 0 deletions app/assets/stylesheets/application.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
@import "*";
@import "components/*";

.field_with_errors {
border: darkred 1px solid;
}
18 changes: 18 additions & 0 deletions app/assets/stylesheets/components/flash.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
.flash-notice {
position: fixed;
top: 5rem;
width: 100%;
display: flex;
justify-content: center;
}

.flash-notice__content {
background-color: rgba(35, 28, 51, 0.75);
animation: appear-then-fade 6s 250ms both;
border-radius: 5rem;
padding: .5rem 1.5rem;
display: flex;
align-items: center;
color: gainsboro;
backdrop-filter: blur(3px) contrast(0.5)
}
7 changes: 7 additions & 0 deletions app/assets/stylesheets/text.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
.heading--medium {
font-size: 2rem;
}

.text--small {
font-size: 1rem;
}
13 changes: 13 additions & 0 deletions app/controllers/concerns/hackathon_scoped.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
module HackathonScoped
extend ActiveSupport::Concern

included do
before_action :set_hackathon, except: [:index, :new, :create]
end

private

def set_hackathon
@hackathon = Hackathon.find(params[:hackathon_id])
end
end
39 changes: 39 additions & 0 deletions app/controllers/hackathons/submissions_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
class Hackathons::SubmissionsController < ApplicationController
def index
@hackathons = Hackathon.not_approved.where applicant: Current.user

redirect_to new_hackathons_request_path if @hackathons.none?
end

def new
@hackathon = Hackathon.new
end

def create
@hackathon = Hackathon.new(hackathon_params)
if @hackathon.save context: :submit
redirect_to hackathons_requests_path, notice: "Your hackathon has been submitted for approval!"
else
render :new, status: :unprocessable_entity
end
end

def show
@hackathon = Hackathon.not_approved.where(applicant: Current.user).find(params[:id])
end

private

def hackathon_params
params.require(:hackathon).permit(
:name,
:website,
:logo,
:banner,
:starts_at,
:ends_at,
:address,
:expected_attendees
)
end
end
1 change: 1 addition & 0 deletions app/controllers/hackathons_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@ class HackathonsController < ApplicationController
skip_before_action :redirect_if_unauthenticated

def index
redirect_to "https://hackathons.hackclub.com", allow_other_host: true
end
end
3 changes: 3 additions & 0 deletions app/javascript/application.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// Configure your import map in config/importmap.rb. Read more: https://github.com/rails/importmap-rails
import "@hotwired/turbo-rails"
import "controllers"

import LocalTime from "local-time"
LocalTime.start()
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Controller } from "@hotwired/stimulus"

export default class extends Controller {
connect() {
this.element.textContent = "Hello World!"
remove() {
this.element.remove()
}
}
2 changes: 2 additions & 0 deletions app/models/hackathon/regional.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ module Hackathon::Regional
extend ActiveSupport::Concern

included do
validates :address, presence: true, on: :submit

geocoded_by :address
reverse_geocoded_by :latitude, :longitude do |hackathon, results| # essentially formats the location
if (result = results.first)
Expand Down
27 changes: 24 additions & 3 deletions app/models/hackathon/scheduled.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,33 @@ module Hackathon::Scheduled
extend ActiveSupport::Concern

included do
scope :upcoming, -> { where("starts_at > ?", Time.now) }

validates :starts_at, presence: true
validates :ends_at, presence: true
validate do
errors.add(:ends_at, :before_start_date) if errors.none? && ends_at < starts_at

validate :dates_are_chronological,
unless: -> { errors.include?(:starts_at) || errors.include?(:ends_at) }

validate :dates_are_in_the_future, on: :submit,
unless: -> { errors.include?(:starts_at) || errors.include?(:ends_at) }
end

private

def dates_are_chronological
if ends_at < starts_at
errors.add(:ends_at, :before_the_start)
end
end

scope :upcoming, -> { where("starts_at > ?", Time.now) }
def dates_are_in_the_future
if starts_at < Time.now
errors.add(:starts_at, :in_the_past)
end

if ends_at < Time.now
errors.add(:ends_at, :in_the_past)
end
end
end
Empty file.
8 changes: 8 additions & 0 deletions app/views/hackathons/submissions/index.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<h3>Your Hackathon Submissions</h3>
<% @hackathons.each do |hackathon| %>
<article>
<%= link_to hackathon.name, hackathons_request_path(hackathon) %>

<small><i><%= hackathon.events.timelined.last %></i></small>
</article>
<% end %>
43 changes: 43 additions & 0 deletions app/views/hackathons/submissions/new.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<%= form_with model: @hackathon, url: hackathons_requests_path do |form| %>
<div>
<%= form.label :name, "Hackathon Name" %>
<%= form.text_field :name, required: true, placeholder: "Epoch" %>
</div>

<div>
<%= form.label :website %>
<%= form.text_field :website, required: true, placeholder: "epoch.hackclub.com" %>
</div>

<div>
<%= form.label :logo %>
<%= form.file_field :logo %>
</div>

<div>
<%= form.label :banner %>
<%= form.file_field :banner %>
</div>

<div>
<%= form.label :start_date %>
<%= form.date_field :starts_at, required: true %>
</div>

<div>
<%= form.label :end_date %>
<%= form.date_field :ends_at, required: true %>
</div>

<div>
<%= form.label :location %>
<%= form.text_field :address, required: true, placeholder: "15 Falls Rd, Shelburne VT" %>
</div>

<div>
<%= form.label :expected_attendees %>
<%= form.number_field :expected_attendees, required: true %>
</div>

<%= form.button "Submit for Review" %>
<% end %>
3 changes: 3 additions & 0 deletions app/views/hackathons/submissions/show.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<h1 class="heading--medium">
<%= @hackathon.name %>
</h1>
1 change: 1 addition & 0 deletions app/views/layouts/application.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
</head>

<body>
<%= render "shared/flash" %>
<%= yield %>
</body>
</html>
7 changes: 7 additions & 0 deletions app/views/shared/_flash.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<% if flash.notice %>
<div class="flash-notice" data-controller="element-removal" data-action="animationend->element-removal#remove">
<div class="flash-notice__content">
<%= flash.notice %>
</div>
</div>
<% end %>
1 change: 1 addition & 0 deletions config/importmap.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@
pin "@hotwired/stimulus", to: "stimulus.min.js", preload: true
pin "@hotwired/stimulus-loading", to: "stimulus-loading.js", preload: true
pin_all_from "app/javascript/controllers", under: "controllers"
pin "local-time", to: "https://ga.jspm.io/npm:[email protected]/app/assets/javascripts/local-time.js"
13 changes: 13 additions & 0 deletions config/initializers/field_with_errors.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
Rails.application.configure do
config.action_view.field_error_proc = proc do |html_tag, instance|
if html_tag !~ /^input/
html_tag
elsif (class_attribute_index = html_tag.index('class="'))
html_tag.insert(class_attribute_index + 7, "field_with_errors ")
elsif html_tag.index("/>")
html_tag.insert(html_tag.index("/>"), " class=field_with_errors ")
else
html_tag.insert(html_tag.index(">"), " class=field_with_errors ")
end
end
end
4 changes: 4 additions & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,9 @@
end
end

namespace :hackathons do
resources :submissions, only: [:index, :new, :create, :show]
end

mount LetterOpenerWeb::Engine, at: "/letter_opener" if Rails.env.development?
end
3 changes: 0 additions & 3 deletions test/fixtures/hackathons.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ zephyr:
high_school_led: true
expected_attendees: 50
modality: <%= Hackathon.modalities[:in_person] %>
financial_assistance: true
applicant: gary
seattle_hacks:
name: SeattleHacks
Expand All @@ -28,7 +27,6 @@ seattle_hacks:
high_school_led: true
expected_attendees: 50
modality: <%= Hackathon.modalities[:in_person] %>
financial_assistance: true
applicant: gary
city: Seattle
province: Washington
Expand All @@ -42,7 +40,6 @@ bellevue_hacks:
high_school_led: true
expected_attendees: 50
modality: <%= Hackathon.modalities[:in_person] %>
financial_assistance: true
applicant: gary
city: Bellevue
province: Washington
Expand Down

0 comments on commit 1c95cbc

Please sign in to comment.