Skip to content

Commit

Permalink
Hackathon reviews!
Browse files Browse the repository at this point in the history
  • Loading branch information
northeastprince committed Aug 12, 2023
1 parent af17b78 commit 34492fa
Show file tree
Hide file tree
Showing 23 changed files with 287 additions and 14 deletions.
7 changes: 7 additions & 0 deletions app/assets/stylesheets/components/button.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
.button-group {
display: flex;
}

.button-group > * {
margin-right: 1.5rem;
}
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--pending {
border-color: darkgray;
}

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

.hackathon--rejected {
border-color: red;
}

.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;
}
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;
}
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
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
2 changes: 1 addition & 1 deletion app/models/user/named.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@ module User::Named
end

def first_name
name.split(" ").first
name&.split(" ")&.first
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) %>
61 changes: 61 additions & 0 deletions app/views/admin/hackathons/show.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
<% content_for :title, @hackathon.name %>

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

<div>
Status:
<%= @hackathon.status %>
</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">
<%= button_to "Approve", admin_hackathon_approval_path(@hackathon) %>
<%= button_to "Reject", admin_hackathon_rejection_path(@hackathon) %>
<%= button_to "Hold", admin_hackathon_hold_path(@hackathon) %>
</div>

<section>
<%= render "events/timeline", {eventable: @hackathon} %>
</section>
</div>
6 changes: 6 additions & 0 deletions app/views/events/_timeline.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<% eventable.events.includes(:creator, :target).each do |event| %>
<article id="<%= dom_id(event) %>" class="timeline__event">
<%= event.description %>
<i><%= local_time_ago(event.created_at) %></i>
</article>
<% end %>
Empty file.
28 changes: 18 additions & 10 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,7 @@
get "unsubscribe_all", on: :collection
end
namespace :subscriptions do
resource :bulk, controller: :bulk, only: [:update, :destroy]
end
end
end

namespace :api, defaults: {format: :json} do
scope "/v:api_version" do
resources :hackathons, only: [:index, :show]
scope module: :hackathon do
resources :subscriptions, only: :create
resource :bulk, only: [:update, :destroy]
end
end
end
Expand All @@ -37,7 +28,24 @@

constraints Constraints::Admin do
mount Sidekiq::Web => "/sidekiq"

namespace :admin do
resources :hackathons, except: [:new, :create] do
scope module: :hackathons do
resource :approval, :rejection, :hold, only: [:create]
end
end
end
end

mount LetterOpenerWeb::Engine, at: "/letter_opener" if Rails.env.development?

namespace :api, defaults: {format: :json} do
scope "/v:api_version" do
resources :hackathons, only: [:index, :show]
scope module: :hackathon do
resources :subscriptions, only: :create
end
end
end
end

0 comments on commit 34492fa

Please sign in to comment.