diff --git a/app/controllers/admin/events_controller.rb b/app/controllers/admin/events_controller.rb
index c52925991..5f6602ad7 100644
--- a/app/controllers/admin/events_controller.rb
+++ b/app/controllers/admin/events_controller.rb
@@ -4,35 +4,40 @@ module Admin
include ApplicationHelper
def index
+ @events = Event.order(starts_at: :desc).page(params[:page]).per(20)
+ end
+
+ def new
@event = Event.new(
location_name: "#{URL.domain}/live",
location_url: app_url,
description_markdown: "*Description* *Pre-requisites:* *Bio*",
)
- @events = Event.order(starts_at: :desc)
+ end
+
+ def edit
+ @event = Event.find(params[:id])
end
def create
@event = Event.new(event_params)
- @events = Event.order(starts_at: :desc)
if @event.save
flash[:success] = "Successfully created event: #{@event.title}"
- redirect_to(action: :index)
+ redirect_to admin_events_path
else
flash[:danger] = @event.errors.full_messages
- render "index.html.erb"
+ render new_admin_event_path
end
end
def update
@event = Event.find(params[:id])
- @events = Event.order(starts_at: :desc)
if @event.update(event_params)
flash[:success] = "#{@event.title} was successfully updated"
- redirect_to "/admin/events"
+ redirect_to admin_events_path
else
flash[:danger] = @event.errors.full_messages
- render "index.html.erb"
+ render :edit
end
end
diff --git a/app/views/admin/events/_event_form.html.erb b/app/views/admin/events/_event_form.html.erb
index a72f39ea7..fe1b7869b 100644
--- a/app/views/admin/events/_event_form.html.erb
+++ b/app/views/admin/events/_event_form.html.erb
@@ -1,50 +1,54 @@
-
- <%= f.label :cover_image %>:
- <%= f.file_field :cover_image, class: "form-control" %>
+
+ <%= form_for [:admin, @event] do |f| %>
+
+ <%= f.label :cover_image, class: "crayons-field__label" %>
+ <%= f.file_field :cover_image, class: "crayons-field" %>
+
+
+ <%= f.label :profile_image, class: "crayons-field__label" %> (for live notification):
+ <%= f.file_field :profile_image, class: "crayons-field" %>
+

+
+
+ <%= f.label :title, class: "crayons-field__label" %>
+ <%= f.text_field :title, maxlength: 90, size: 40, required: true, class: "crayons-textfield" %>
+
+
+ <%= f.label :host_name, class: "crayons-field__label" %>
+ <%= f.text_field :host_name, size: 40, required: true, class: "crayons-textfield" %>
+
+
+ <%= f.label :category, class: "crayons-field__label" %>
+ <%= f.select :category, ["AMA", "Workshop", "Talk", "Town Hall"], required: true, class: "crayons-select" %>
+
+
+ <%= f.label :starts_at, class: "crayons-field__label" %>
+ <%= f.datetime_select :starts_at, required: true, include_blank: true, start_year: Time.current.year, end_year: Time.current.year + 2, class: "crayons-select" %> UTC Time Only (4 hours ahead of eastern time)
+
+
+ <%= f.label :ends_at, class: "crayons-field__label" %>
+ <%= f.datetime_select :ends_at, required: true, include_blank: true, start_year: Time.current.year, end_year: Time.current.year + 2, class: "crayons-select" %> UTC Time Only (4 hours ahead of eastern time)
+
+
+ <%= f.label :location_name, class: "crayons-field__label" %>
+ <%= f.text_field :location_name, required: true, class: "crayons-textfield" %>
+
+
+ <%= f.label :location_url, class: "crayons-field__label" %>
+ <%= f.text_field :location_url, required: true, class: "crayons-textfield" %>
+
+
+ <%= f.label :description_markdown, class: "crayons-field__label" %>
+ <%= f.text_area :description_markdown, size: "45x10", required: true, class: "crayons-textfield" %>
+
+
+ <%= f.label :published, class: "crayons-field__label" %>
+ <%= f.check_box :published, class: "crayons-checkbox" %>
+
+
+ <%= f.label :live_now, class: "crayons-field__label" %>
+ <%= f.check_box :live_now, class: "crayons-checkbox" %>
+
+ <%= f.submit class: "crayons-btn" %>
+ <% end %>
-
-
- <%= f.label :title %>
- <%= f.text_field :title, maxlength: 90, size: 40, required: true, class: "form-control" %>
-
-
- <%= f.label :host_name %>
- <%= f.text_field :host_name, size: 40, required: true, class: "form-control" %>
-
-
- <%= f.label :category %>
- <%= f.select :category, ["AMA", "Workshop", "Talk", "Town Hall"], required: true %>
-
-
- <%= f.label :starts_at %>
- <%= f.datetime_select :starts_at, required: true, include_blank: true, start_year: Time.current.year, end_year: Time.current.year + 2, class: "form-control" %> UTC Time Only (4 hours ahead of eastern time)
-
-
- <%= f.label :ends_at %>
- <%= f.datetime_select :ends_at, required: true, include_blank: true, start_year: Time.current.year, end_year: Time.current.year + 2, class: "form-control" %> UTC Time Only (4 hours ahead of eastern time)
-
-
- <%= f.label :location_name %>
- <%= f.text_field :location_name, required: true, class: "form-control" %>
-
-
- <%= f.label :location_url %>
- <%= f.text_field :location_url, required: true, class: "form-control" %>
-
-
- <%= f.label :description_markdown %>
- <%= f.text_area :description_markdown, size: "45x10", required: true, class: "form-control" %>
-
-
- <%= f.label :published %>
- <%= f.check_box :published %>
-
-
- <%= f.label :live_now %>
- <%= f.check_box :live_now %>
-
-<%= f.submit class: "btn btn-primary" %>
diff --git a/app/views/admin/events/edit.html.erb b/app/views/admin/events/edit.html.erb
new file mode 100644
index 000000000..b4b11e963
--- /dev/null
+++ b/app/views/admin/events/edit.html.erb
@@ -0,0 +1,4 @@
+
+
Edit Event: <%= @event.title.to_s %>
+ <%= render "event_form" %>
+
diff --git a/app/views/admin/events/index.html.erb b/app/views/admin/events/index.html.erb
index d76033047..9ea789110 100644
--- a/app/views/admin/events/index.html.erb
+++ b/app/views/admin/events/index.html.erb
@@ -1,31 +1,38 @@
-
-
Create New Event
+
+ Events
+ <%= link_to "New Event", new_admin_event_path, class: "ml-auto crayons-btn crayons-btn--s" %>
+
+
- <%= form_for @event, url: { controller: "events", action: "create" } do |f| %>
- <%= render "event_form", f: f, event: @event %>
- <% end %>
-
-
-
-
Upcoming Events
+
+
Upcoming Events
<% @events.each do |event| %>
<% if event.starts_at.future? %>
-

- <%= form_for [:admin, event] do |f| %>
- <%= render "event_form", f: f, event: event %>
- <% end %>
+
+ <%= event.title %>
+ <% if event.cover_image_url.present? %>
+

+ <% end %>
+ <%= link_to "Edit", edit_admin_event_path(event.id), class: "ml-auto crayons-btn crayons-btn--s crayons-btn--secondary" %>
+
+
<% end %>
<% end %>
+
-
-
Past Events
+
+
Past Events
<% @events.each do |event| %>
<% if !event.starts_at.future? %>
-

- <%= form_for [:admin, event] do |f| %>
- <%= render "event_form", f: f, event: event %>
- <% end %>
+
+ <%= event.title %>
+ <% if event.cover_image_url.present? %>
+

+ <% end %>
+ <%= link_to "Edit", edit_admin_event_path(event.id), class: "ml-auto crayons-btn crayons-btn--s crayons-btn--secondary" %>
+
+
<% end %>
<% end %>
diff --git a/app/views/admin/events/new.html.erb b/app/views/admin/events/new.html.erb
index cca524004..e05acfd43 100644
--- a/app/views/admin/events/new.html.erb
+++ b/app/views/admin/events/new.html.erb
@@ -1,55 +1,4 @@
-
Create Event
-
-
- <%# form_with url: admin_ %>
+
+
Create New Event
+ <%= render "event_form" %>
-
- <%= f.label :cover_image %>:
- <%= f.file_field :cover_image, class: "form-control" %>
-
-
-
- <%= f.label :title %>
- <%= f.text_field :title, maxlength: 90, size: 40, required: true, class: "form-control" %>
-
-
- <%= f.label :host_name %>
- <%= f.text_field :host_name, size: 40, required: true, class: "form-control" %>
-
-
- <%= f.label :category %>
- <%= f.select :category, ["AMA", "Workshop", "Talk", "Town Hall"], required: true %>
-
-
- <%= f.label :starts_at %>
- <%= f.datetime_select :starts_at, required: true, include_blank: true, start_year: Time.current.year, end_year: Time.current.year + 2, class: "form-control" %> UTC Time Only (4 hours ahead of eastern time)
-
-
- <%= f.label :ends_at %>
- <%= f.datetime_select :ends_at, required: true, include_blank: true, start_year: Time.current.year, end_year: Time.current.year + 2, class: "form-control" %> UTC Time Only (4 hours ahead of eastern time)
-
-
- <%= f.label :location_name %>
- <%= f.text_field :location_name, required: true, class: "form-control" %>
-
-
- <%= f.label :location_url %>
- <%= f.text_field :location_url, required: true, class: "form-control" %>
-
-
- <%= f.label :description_markdown %>
- <%= f.text_area :description_markdown, size: "45x10", required: true, class: "form-control" %>
-
-
- <%= f.label :published %>
- <%= f.check_box :published %>
-
-
- <%= f.label :live_now %>
- <%= f.check_box :live_now %>
-
-<%= f.submit class: "btn btn-primary" %>
\ No newline at end of file
diff --git a/app/views/admin/pages/index.html.erb b/app/views/admin/pages/index.html.erb
index 2c81364ca..d4ad1b9cf 100644
--- a/app/views/admin/pages/index.html.erb
+++ b/app/views/admin/pages/index.html.erb
@@ -16,7 +16,7 @@
- <% if !@code_of_conduct || !@privacy || !@terms%>
+ <% if !@code_of_conduct || !@privacy || !@terms %>
Override defaults
Note: Proceed with caution. When you edit any of the following pages, it will diverge from the original Forem version and you will no longer receive updates. You will see your updated version in the section above.
@@ -31,7 +31,7 @@
<% if !@privacy %>
<%= link_to "Privacy Policy", privacy_path %>
- <%= link_to "Override", new_admin_page_path(slug: "privacy"), class: "ml-auto crayons-btn crayons-btn--s crayons-btn--danger" %>
+ <%= link_to "Override", new_admin_page_path(slug: "privacy"), class: "ml-auto crayons-btn crayons-btn--s crayons-btn--danger" %>
<% end %>
<% if !@terms %>
@@ -47,6 +47,4 @@
<% end %>
-
-
diff --git a/app/views/events/_event.html.erb b/app/views/events/_event.html.erb
index 656dc0a4c..fd5326a39 100644
--- a/app/views/events/_event.html.erb
+++ b/app/views/events/_event.html.erb
@@ -80,14 +80,14 @@
<%= event.location_url %>
15
- <%= event.description_html.html_safe %>
+ <%= event.description_html&.html_safe %>
------
Link to attend - <%= event.location_url %>
- <%= event.description_html.html_safe %>
+ <%= event.description_html&.html_safe %>
diff --git a/config/routes.rb b/config/routes.rb
index b76cdb175..acdab644c 100644
--- a/config/routes.rb
+++ b/config/routes.rb
@@ -66,7 +66,7 @@ Rails.application.routes.draw do
destroy], path: "listings/categories"
resources :comments, only: [:index]
- resources :events, only: %i[index create update]
+ resources :events, only: %i[index create update new edit]
resources :feedback_messages, only: %i[index show]
resources :invitations, only: %i[index new create destroy]
resources :pages, only: %i[index new create edit update destroy]
diff --git a/spec/requests/admin/events_spec.rb b/spec/requests/admin/events_spec.rb
index 7ded70ece..96da54d48 100644
--- a/spec/requests/admin/events_spec.rb
+++ b/spec/requests/admin/events_spec.rb
@@ -1,8 +1,19 @@
require "rails_helper"
RSpec.describe "/admin/events", type: :request do
- let(:event) { create(:event) }
+ let(:event) { create(:event, title: "Hey") }
let(:admin) { create(:user, :super_admin) }
+ let(:params) do
+ {
+ event: {
+ title: "Hello, world!",
+ description_markdown: "This is an event",
+ starts_at: Time.current,
+ ends_at: 3660.seconds.from_now,
+ category: "Talk"
+ }
+ }
+ end
describe "PUT admin/events" do
before do
@@ -19,5 +30,23 @@ RSpec.describe "/admin/events", type: :request do
patch "/admin/events/#{event.id}", params: { event: { live_now: "1" } }
expect(event.reload.live_now).to eq true
end
+
+ it "successfully updates the event title" do
+ expect do
+ patch "/admin/events/#{event.id}", params: params
+ end.to change { event.reload.title }.to("Hello, world!")
+ end
+ end
+
+ describe "POST /admin/events" do
+ let(:post_resource) { post "/admin/events", params: params }
+
+ before { sign_in admin }
+
+ it "successfully creates an event" do
+ expect do
+ post_resource
+ end.to change { Event.all.count }.by(1)
+ end
end
end
diff --git a/spec/system/admin/admin_creates_new_event_spec.rb b/spec/system/admin/admin_creates_new_event_spec.rb
index 2c83e1471..d2bfeee36 100644
--- a/spec/system/admin/admin_creates_new_event_spec.rb
+++ b/spec/system/admin/admin_creates_new_event_spec.rb
@@ -6,7 +6,7 @@ RSpec.describe "Admin creates new event", type: :system do
before do
sign_in admin
- visit "/admin/events"
+ visit "/admin/events/new"
end
def select_date_and_time(year, month, date, hour, min, field_name)
@@ -26,7 +26,7 @@ RSpec.describe "Admin creates new event", type: :system do
end
it "loads /admin/events" do
- expect(page).to have_content("Create New Event")
+ expect(page).to have_content("New Event")
end
it "loads published events on /events" do