diff --git a/app/controllers/internal/classified_listings_controller.rb b/app/controllers/internal/classified_listings_controller.rb index 5606a4e6a..cd9390be7 100644 --- a/app/controllers/internal/classified_listings_controller.rb +++ b/app/controllers/internal/classified_listings_controller.rb @@ -2,7 +2,8 @@ class Internal::ClassifiedListingsController < Internal::ApplicationController layout "internal" def index - @classified_listings = ClassifiedListing.all + @classified_listings = ClassifiedListing.page(params[:page]).per(50) + @classified_listings = @classified_listings.joins(:user).where("classified_listings.title ILIKE :search OR users.username ILIKE :search", search: "%#{params[:search]}%") if params[:search].present? end def edit diff --git a/app/models/organization.rb b/app/models/organization.rb index af1aceb48..de4f70be6 100644 --- a/app/models/organization.rb +++ b/app/models/organization.rb @@ -11,6 +11,7 @@ class Organization < ApplicationRecord has_many :display_ads has_many :notifications has_many :credits + has_many :classified_listings validates :name, :summary, :url, :profile_image, presence: true validates :name, diff --git a/app/models/user.rb b/app/models/user.rb index 8df744f7c..5cd285f6d 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -35,6 +35,7 @@ class User < ApplicationRecord has_many :html_variants, dependent: :destroy has_many :page_views has_many :credits + has_many :classified_listings has_many :mentor_relationships_as_mentee, class_name: "MentorRelationship", foreign_key: "mentee_id", inverse_of: :mentee has_many :mentor_relationships_as_mentor, diff --git a/app/views/internal/classified_listings/edit.html.erb b/app/views/internal/classified_listings/edit.html.erb index 56eedb035..55d09e7c3 100644 --- a/app/views/internal/classified_listings/edit.html.erb +++ b/app/views/internal/classified_listings/edit.html.erb @@ -1,6 +1,6 @@ Back to All Listings -

Edit <%= @classified_listing.title %>

+

Edit "<%= @classified_listing.title %>"

<%= form_for [:internal, @classified_listing] do |form| %> <%= form.label :title %> @@ -22,7 +22,6 @@ <%= 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" %> diff --git a/app/views/internal/classified_listings/index.html.erb b/app/views/internal/classified_listings/index.html.erb index f5ba9806f..de3a25054 100644 --- a/app/views/internal/classified_listings/index.html.erb +++ b/app/views/internal/classified_listings/index.html.erb @@ -1,29 +1,36 @@ -Visit /listings - +

Classified Listings

+<%= form_tag("/internal/listings", method: "get") do %> + <%= label_tag(:search, "Find by listing title or username:") %> + <%= text_field_tag(:search, params[:search]) %> + <% if params[:state].present? %> + <%= hidden_field_tag(:state, params[:state]) %> + <% end %> + <%= submit_tag("Search") %> +<% end %> +<%= paginate @classified_listings %>
-
Title (direct link)
+
Title Link
+
User/Org
Category
-
Tags (cached_tag_list)
+
Cached Tags
Published?
Last Bumped
<% @classified_listings.each do |listing| %>
- + <%= listing.title %>
+
<%= User.find(listing.user_id).username %><%= " / " + Organization.find(listing.organization_id).name if listing.organization_id.present? %>
<%= listing.category %>
<%= listing.cached_tag_list %>
<%= listing.published ? "Yes" : "No" %>
-
<%= "#{time_ago_in_words(listing.bumped_at)} ago" if listing.bumped_at %>
-
- Edit -
+
<%= time_ago_in_words(listing.bumped_at) %> ago
<% end %> - +<%= paginate @classified_listings %>