Skip to content

Commit

Permalink
Hackathon reviews! (#96)
Browse files Browse the repository at this point in the history
Co-authored-by: Gary Tou <[email protected]>
  • Loading branch information
northeastprince and garyhtou authored Aug 14, 2023
1 parent 32ee248 commit 7fd5295
Show file tree
Hide file tree
Showing 26 changed files with 357 additions and 18 deletions.
23 changes: 23 additions & 0 deletions app/assets/stylesheets/components/button.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
.button-group {
display: flex;
}

.button-group > * {
margin-right: 1.5rem;
}

.button--success {
background-color: limegreen;
}

.button--neutral {
background-color: darkgray;
}

.button--danger {
background-color: crimson;
}

.button {
padding: 0.5rem !important;
}
31 changes: 31 additions & 0 deletions app/assets/stylesheets/components/hackathon.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
.hackathon-snippet {
border: 3px solid;
padding: 0.5rem;
display: flex;
}

.hackathon-snippet__title {
margin: 0 !important;
font-weight: normal;
}

.hackathon-snippet__time {
margin-left: auto;
text-decoration: none !important;
}

.hackathon > * {
margin-top: 1rem;
}

.hackathon--pending {
border-color: darkgray;
}

.hackathon--approved {
border-color: limegreen;
}

.hackathon--rejected {
border-color: red;
}
4 changes: 4 additions & 0 deletions app/assets/stylesheets/components/timeline.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
.timeline__event {
padding: 0.5rem;
margin-bottom: 0.5rem;
}
3 changes: 0 additions & 3 deletions app/assets/stylesheets/spacing.css

This file was deleted.

15 changes: 15 additions & 0 deletions app/assets/stylesheets/spacing.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
$spacing-unit: 1rem;

@each $direction in (top, bottom, left, right) {
.push--#{$direction} {
margin-#{$direction}: $spacing-unit;
}

.push-double--#{$direction} {
margin-#{$direction}: $spacing-unit * 2;
}

.push-half--#{$direction} {
margin-#{$direction}: $spacing-unit / 2;
}
}
4 changes: 4 additions & 0 deletions app/assets/stylesheets/text.scss
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
.heading--small {
font-size: 1.5rem;
}

.heading--medium {
font-size: 2rem;
}
Expand Down
2 changes: 2 additions & 0 deletions app/controllers/admin/base_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
class Admin::BaseController < ApplicationController
end
8 changes: 8 additions & 0 deletions app/controllers/admin/hackathons/approvals_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
class Admin::Hackathons::ApprovalsController < Admin::BaseController
include HackathonScoped

def create
@hackathon.approve
redirect_to admin_hackathon_path(@hackathon)
end
end
8 changes: 8 additions & 0 deletions app/controllers/admin/hackathons/holds_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
class Admin::Hackathons::HoldsController < Admin::BaseController
include HackathonScoped

def create
@hackathon.hold
redirect_to admin_hackathon_path(@hackathon)
end
end
8 changes: 8 additions & 0 deletions app/controllers/admin/hackathons/rejections_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
class Admin::Hackathons::RejectionsController < Admin::BaseController
include HackathonScoped

def create
@hackathon.reject
redirect_to admin_hackathon_path(@hackathon)
end
end
62 changes: 62 additions & 0 deletions app/controllers/admin/hackathons_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
class Admin::HackathonsController < Admin::BaseController
before_action :set_hackathon, only: [:show, :edit, :update, :destroy]

def index
@pagy, @hackathons = pagy(Hackathon.all.order(created_at: :desc))
end

def show
end

def edit
end

def update
if @hackathon.update(hackathon_params)
redirect_to admin_hackathon_path(@hackathon)
else
render :edit, status: :unprocessable_entity, notice: @hackathon.errors.full_messages.to_sentence
end
end

def destroy
if @hackathon.destroy
redirect_to admin_hackathons_path, notice: "#{@hackathon.name} has been deleted."
else
render :show, status: :unprocessable_entity, notice: @hackathon.errors.full_messages.first
end
end

private

def hackathon_params
params.require(:hackathon).permit(
:name,
:website,
:logo,
:banner,
:starts_at,
:ends_at,
:address,
:expected_attendees,
:offers_financial_assistance,
:requested_swag,
swag_mailing_address_attributes: [
:line1,
:line2,
:city,
:province,
:postal_code,
:country_code
],
applicant: [
:name,
:email_address
]
)
end

def set_hackathon
@hackathon = Hackathon.find(params[:id])
end
end
2 changes: 2 additions & 0 deletions app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
class ApplicationController < ActionController::Base
include Pagy::Backend

include SetCurrentRequestDetails
include Authenticate
end
2 changes: 1 addition & 1 deletion app/controllers/concerns/hackathon_scoped.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ module HackathonScoped
extend ActiveSupport::Concern

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

private
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/hackathons_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@ class HackathonsController < ApplicationController
skip_before_action :redirect_if_unauthenticated

def index
redirect_to "https://hackathons.hackclub.com", allow_other_host: true
# redirect_to "https://hackathons.hackclub.com", allow_other_host: true
end
end
2 changes: 2 additions & 0 deletions app/helpers/application_helper.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
module ApplicationHelper
include Pagy::Frontend

# This method makes it easier to yield content with a default value.
#
# USAGE:
Expand Down
2 changes: 1 addition & 1 deletion app/models/event.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ def description
if creator && !target
"#{action.humanize(capitalize: false)} by #{creator.name}" # e.g. (hackathon) "approved by Matt" vs "Matt removed X" ∨∨∨
else
[creator.name, action.humanize(capitalize: false), target.name].compact.join(" ")
[creator&.name, action.humanize(capitalize: false), target&.name].compact.join(" ")
end
end
end
4 changes: 3 additions & 1 deletion app/models/hackathon.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@ class Hackathon < ApplicationRecord
include Eventable
include Taggable

include Status

include Applicant
include Brand
include FinanciallyAssisting # depends on Taggable
include Gathering
include Named
include Regional
include Reviewable # depends on Eventable and Status
include Scheduled
include Status
include Swag
end
37 changes: 37 additions & 0 deletions app/models/hackathon/reviewable.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
module Hackathon::Reviewable
extend ActiveSupport::Concern

included do
scope :reviewed_by, ->(user) {
joins(:events)
.where(events:
{action: [:approved, :rejected, :held],
creator: user})
}
end

def reviewers
events.where(action: [:approved, :rejected, :held]).collect(&:creator)
end

def approve
transaction do
record :approved
update! status: :approved
end
end

def reject
transaction do
record :rejected
update! status: :rejected
end
end

def hold
transaction do
record :held_for_review
update! status: :pending
end
end
end
8 changes: 8 additions & 0 deletions app/models/mailing_address.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@
class MailingAddress < ApplicationRecord
validates :line1, :city, :country_code, presence: true
validates :country_code, inclusion: {in: ISO3166::Country.codes}

def full
components = []
components << [line1, line2].compact.join(" ")
components << city << province << postal_code << country_code

components.compact.join(", ")
end
end
6 changes: 6 additions & 0 deletions app/views/admin/hackathons/_snippet.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<%= link_to admin_hackathon_path(hackathon) do %>
<article id="<%= dom_id(hackathon) %>" class="hackathon-snippet hackathon--<%= hackathon.status %>">
<h2 class="heading--small hackathon-snippet__title"><%= hackathon.name %></h2>
<span class="hackathon-snippet__time">created <%= local_time_ago(hackathon.created_at) %></span>
</article>
<% end %>
7 changes: 7 additions & 0 deletions app/views/admin/hackathons/index.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<h1>Hackathons</h1>

<% @hackathons.each do |hackathon| %>
<%= render "snippet", hackathon: %>
<% end %>

<%== pagy_nav(@pagy) %>
92 changes: 92 additions & 0 deletions app/views/admin/hackathons/show.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
<% content_for :title, @hackathon.name %>

<% content_for :nav do %>
<%= link_to "◀ Back to Hackathons", admin_hackathons_path, class: "button" %>
<% end %>

<div id="<%= dom_id(@hackathon) %>" class="hackathon">
<h1 class="heading--medium">
<%= @hackathon.name %>
</h1>

<% if @hackathon.logo.present? || @hackathon.banner.present? %>
<section style="display: flex;">
<% if @hackathon.logo.present? %>
<div>
<h2 class="heading--small">Logo</h2>
<%= image_tag @hackathon.logo, size: 128 %>
</div>
<% end %>

<% if @hackathon.banner.present? %>
<div>
<h2 class="heading--small">Banner</h2>
<%= image_tag @hackathon.banner, height: 128 %>
</div>
<% end %>
</section>
<% end %>

<div>
Status:
<%= @hackathon.status %>
</div>

<div>
High School Led:
<%= @hackathon.high_school_led? ? "Yes" : "No" %>
</div>

<div>
Applicant:
<%= "#{@hackathon.applicant.name}, " if @hackathon.applicant.name.present? %>
<%= @hackathon.applicant.email_address %>
</div>

<div>
Website:
<%= @hackathon.website %>
</div>

<div>
Starts <%= local_time_ago(@hackathon.starts_at) %>,
ends <%= local_time_ago(@hackathon.ends_at) %>
</div>

<div>
Expected Attendees:
<%= @hackathon.expected_attendees %> <%= @hackathon.modality.humanize(capitalize: false) %>
</div>

<div>
Location:

<%= @hackathon.address %>

<% if @hackathon.latitude %>
<span title="latitude, longitude">- <%= @hackathon.latitude %>, <%= @hackathon.longitude %></span>
<% end %>
</div>

<div>
<% if @hackathon.requested_swag? %>
Swag requested for: <%= @hackathon.swag_mailing_address.full %>
<% else %>
No swag requested.
<% end %>
</div>

<div class="button-group">
<% if @hackathon.pending? %>
<%= button_to "Approve", admin_hackathon_approval_path(@hackathon), class: "button--success" %>
<%= button_to "Reject", admin_hackathon_rejection_path(@hackathon), class: "button--danger" %>
<% end %>
<% unless @hackathon.pending? %>
<%= button_to "Hold for review", admin_hackathon_hold_path(@hackathon), class: "button--neutral" %>
<% end %>
</div>

<section>
<%= render "events/timeline", {eventable: @hackathon} %>
</section>
</div>
Loading

0 comments on commit 7fd5295

Please sign in to comment.