From 426d3191e81dc5abff9b36c8dab2eb08b069eeb5 Mon Sep 17 00:00:00 2001 From: Julianna Tetreault <32834804+juliannatetreault@users.noreply.github.com> Date: Thu, 18 Jun 2020 15:51:45 -0600 Subject: [PATCH] Add a Broadcast Show View (#8769) [deploy] * Add #show to the Broadcasts::Controller and to routes.rb - Adds a show method to the Broadcasts Controller - Adds a show route to routes.rb * Add a show view for Broadcasts - Adds show.html.erb to /internal/broadcasts - Repurposes code from index.html.erb for show view - Repurposes code from edit.html.erb for show view * Rewrite /internal/broadcasts index to use a table - Formats /internal/broadcasts with a table - Removes on-hover functionality from show.html.erb * Refactor Broadcast resources in routes.rb * Redirect to #show on create and update for Broadcasts * Add the Destroy Broadcast button to the Broadcast show view * Remove style preventing Broadcast preview * Add Broadcast styling back and add display: block to stylesheet * Add display: flex to .broadcast-wrapper in layout.scss * Remove superfluous slashes from opening tags --- app/assets/stylesheets/internal/layout.scss | 1 + .../internal/broadcasts_controller.rb | 8 +++- app/views/internal/broadcasts/_form.html.erb | 13 ----- app/views/internal/broadcasts/edit.html.erb | 1 - app/views/internal/broadcasts/index.html.erb | 47 +++++++++---------- app/views/internal/broadcasts/show.html.erb | 39 +++++++++++++++ config/routes.rb | 2 +- 7 files changed, 70 insertions(+), 41 deletions(-) create mode 100644 app/views/internal/broadcasts/show.html.erb diff --git a/app/assets/stylesheets/internal/layout.scss b/app/assets/stylesheets/internal/layout.scss index 16a08dc9d..5b607cbad 100644 --- a/app/assets/stylesheets/internal/layout.scss +++ b/app/assets/stylesheets/internal/layout.scss @@ -52,6 +52,7 @@ } .broadcast-wrapper { + display: flex; position: relative; z-index: auto; } diff --git a/app/controllers/internal/broadcasts_controller.rb b/app/controllers/internal/broadcasts_controller.rb index d5adcf5a5..600217ac6 100644 --- a/app/controllers/internal/broadcasts_controller.rb +++ b/app/controllers/internal/broadcasts_controller.rb @@ -9,6 +9,10 @@ class Internal::BroadcastsController < Internal::ApplicationController end.order(title: :asc) end + def show + @broadcast = Broadcast.find(params[:id]) + end + def new @broadcast = Broadcast.new end @@ -22,7 +26,7 @@ class Internal::BroadcastsController < Internal::ApplicationController if @broadcast.save flash[:success] = "Broadcast has been created!" - redirect_to internal_broadcasts_path + redirect_to internal_broadcast_path(@broadcast) else flash[:danger] = @broadcast.errors.full_messages.to_sentence render new_internal_broadcast_path @@ -34,7 +38,7 @@ class Internal::BroadcastsController < Internal::ApplicationController if @broadcast.update(broadcast_params) flash[:success] = "Broadcast has been updated!" - redirect_to internal_broadcasts_path + redirect_to internal_broadcast_path(@broadcast) else flash[:danger] = @broadcast.errors.full_messages.to_sentence render :edit diff --git a/app/views/internal/broadcasts/_form.html.erb b/app/views/internal/broadcasts/_form.html.erb index 3816ade84..98888bd3d 100644 --- a/app/views/internal/broadcasts/_form.html.erb +++ b/app/views/internal/broadcasts/_form.html.erb @@ -17,17 +17,4 @@ <%= label_tag :active, "Active:" %> <%= select_tag :active, options_for_select([false, true], selected: @broadcast.active) %> -
- -<% if @broadcast.processed_html %> -
-

Preview

- -

Please note: announcement broadcasts will render directly below the nav bar once activated.

-
-<% end %>
diff --git a/app/views/internal/broadcasts/edit.html.erb b/app/views/internal/broadcasts/edit.html.erb index 5158e09a5..9cda44ba6 100644 --- a/app/views/internal/broadcasts/edit.html.erb +++ b/app/views/internal/broadcasts/edit.html.erb @@ -5,6 +5,5 @@ <%= render "form" %> <%= submit_tag "Update Broadcast", class: "btn btn-primary float-right" %> <% end %> - <%= link_to "Destroy Broadcast", url_for(action: :destroy, id: @broadcast.id), method: :delete, data: { confirm: "Are you sure?" }, class: "btn btn-danger" %>
diff --git a/app/views/internal/broadcasts/index.html.erb b/app/views/internal/broadcasts/index.html.erb index 3b3ab014a..773d07e72 100644 --- a/app/views/internal/broadcasts/index.html.erb +++ b/app/views/internal/broadcasts/index.html.erb @@ -19,30 +19,29 @@ -
-
-
Note: You must ensure that your Broadcast is active in order for it to be sent to users!
-
- <% @broadcasts.each do |broadcast| %> - -

Title: <%= broadcast.title %>

-

Broadcast Type: <%= broadcast.type_of %>

-

Content:

-

- <%= broadcast.processed_html %> -

-

Last Active On: <%= broadcast.active_status_updated_at&.strftime("%b %d, %Y %H:%M UTC") %>

-

Status:

-

- "> +
Note: You must ensure that your Broadcast is active in order for it to be sent to users!
+ + + + + + + + + + <% @broadcasts.each do |broadcast| %> + + + + + <% end %> + +
TitleStatus
<%= link_to broadcast.title, internal_broadcast_path(broadcast.id) %> +
+
"> <%= broadcast.active? ? "Active" : "Inactive" %> - - Broadcast Status -
- - <% end %> - - - + + +
<%= csrf_meta_tags %> diff --git a/app/views/internal/broadcasts/show.html.erb b/app/views/internal/broadcasts/show.html.erb new file mode 100644 index 000000000..7b2ecb7f3 --- /dev/null +++ b/app/views/internal/broadcasts/show.html.erb @@ -0,0 +1,39 @@ +
+
+
+ +

Title: <%= @broadcast.title %>

+

Broadcast Type: <%= @broadcast.type_of %>

+

Content:

+

+ <%= @broadcast.processed_html %> +

+

Last Active On: <%= @broadcast.active_status_updated_at&.strftime("%b %d, %Y %H:%M UTC") %>

+

Status:

+

+ "> + <%= @broadcast.active? ? "Active" : "Inactive" %> + + Broadcast Status +

+
+
+ <% if @broadcast.processed_html %> +
+

Preview

+ +

Please note: announcement broadcasts will render directly below the nav bar once activated.

+
+ <% end %> +
+ <%= link_to "Destroy Broadcast", url_for(action: :destroy, id: @broadcast.id), method: :delete, data: { confirm: "Are you sure?" }, class: "btn btn-danger" %> + <%= link_to "Edit Broadcast", edit_internal_broadcast_path, class: "btn btn-primary float-right" %> +
+
+
+ +<%= csrf_meta_tags %> diff --git a/config/routes.rb b/config/routes.rb index cf0e455fa..6d49c5be9 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -46,7 +46,7 @@ Rails.application.routes.draw do end resources :articles, only: %i[index show update] - resources :broadcasts, only: %i[index new create edit update destroy] + resources :broadcasts resources :buffer_updates, only: %i[create update] resources :listings, only: %i[index edit update destroy] resources :comments, only: [:index]