From aadc775ffde41e92de6dacb8a9b59b1515a8d63a Mon Sep 17 00:00:00 2001 From: Andy Zhao Date: Mon, 6 May 2019 18:16:23 -0400 Subject: [PATCH] Add listings to /internal pages (#2725) * Add routes for listings in internal * Add internal listings controller and views --- .../classified_listings_controller.rb | 29 ++++++++++++++++ .../classified_listings/edit.html.erb | 34 +++++++++++++++++++ .../classified_listings/index.html.erb | 32 +++++++++++++++++ app/views/layouts/internal.html.erb | 2 +- config/routes.rb | 2 ++ 5 files changed, 98 insertions(+), 1 deletion(-) create mode 100644 app/controllers/internal/classified_listings_controller.rb create mode 100644 app/views/internal/classified_listings/edit.html.erb create mode 100644 app/views/internal/classified_listings/index.html.erb diff --git a/app/controllers/internal/classified_listings_controller.rb b/app/controllers/internal/classified_listings_controller.rb new file mode 100644 index 000000000..49976ae8f --- /dev/null +++ b/app/controllers/internal/classified_listings_controller.rb @@ -0,0 +1,29 @@ +class Internal::ClassifiedListingsController < Internal::ApplicationController + layout "internal" + + def index + @classified_listings = ClassifiedListing.all + end + + def edit + @classified_listing = ClassifiedListing.find(params[:id]) + end + + def update + @classified_listing = ClassifiedListing.find(params[:id]) + @classified_listing.update!(listing_params) + flash[:success] = "Listing updated successfully" + redirect_to "/internal/listings/#{@classified_listing.id}/edit" + end + + def destroy + @classified_listing = ClassifiedListing.find(params[:id]) + @classified_listing.destroy + flash[:warning] = "'#{@classified_listing.title}' was destroyed successfully" + redirect_to "/internal/listings" + end + + def listing_params + params.require(:classified_listing).permit(:published, :body_markdown, :title, :category, :tag_list) + end +end diff --git a/app/views/internal/classified_listings/edit.html.erb b/app/views/internal/classified_listings/edit.html.erb new file mode 100644 index 000000000..56eedb035 --- /dev/null +++ b/app/views/internal/classified_listings/edit.html.erb @@ -0,0 +1,34 @@ +Back to All Listings + +

Edit <%= @classified_listing.title %>

+ +<%= form_for [:internal, @classified_listing] do |form| %> + <%= form.label :title %> +
+ <%= form.text_field :title, size: 100, maxlength: 128 %> +
+ <%= form.label :body_markdown %> +
+ <%= form.text_area :body_markdown, cols: 40, rows: 15, maxlength: 400 %> +
+ <%= form.label :tag_list %> +
+ Comma separated, one space, 8 tags max +
+ <%= form.text_field :tag_list, value: @classified_listing.cached_tag_list, size: 100 %> +
+ <%= form.label :category %> +
+ <%= form.select :category, options_for_select(ClassifiedListing.select_options_for_categories.map(&:last), @classified_listing.category) %> +
+ <%= form.label :published %> +
+ <%= form.check_box :published %> +
+ <%= form.submit "Update Listing", class: "btn btn-lg btn-primary" %> + +
+<% end %> + +<%= link_to "Destroy Listing", url_for(action: :destroy, id: @classified_listing.id), method: :delete, data: { confirm: "Are you sure?" }, class: "btn btn-danger" %> +


diff --git a/app/views/internal/classified_listings/index.html.erb b/app/views/internal/classified_listings/index.html.erb new file mode 100644 index 000000000..fe86a2a93 --- /dev/null +++ b/app/views/internal/classified_listings/index.html.erb @@ -0,0 +1,32 @@ +Visit /listings + +
+
Title (direct link)
+
Category
+
Tags (cached_tag_list)
+
Published?
+
Last Bumped
+
+<% @classified_listings.each do |listing| %> +
+ +
<%= listing.category %>
+
<%= listing.cached_tag_list %>
+
<%= listing.published ? "Yes" : "No" %>
+
<%= time_ago_in_words(listing.bumped_at) %> ago
+
+ Edit +
+
+<% end %> + + diff --git a/app/views/layouts/internal.html.erb b/app/views/layouts/internal.html.erb index 110daa730..773d05df7 100644 --- a/app/views/layouts/internal.html.erb +++ b/app/views/layouts/internal.html.erb @@ -112,7 +112,7 @@