Internal Listings View Enhancement (#2931)
* wip * add username to listings list view * add pagination * small style adjustment on edit page * add has_many relationship to users and orgs * add search by username or listing title
This commit is contained in:
parent
1678489a2b
commit
65e3cf605c
6 changed files with 24 additions and 15 deletions
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
<a href="/internal/listings">Back to All Listings</a>
|
||||
|
||||
<h1>Edit <a href="/listings/<%= @classified_listing.category %>/<%= @classified_listing.slug %>" target="_blank"><%= @classified_listing.title %></a></h1>
|
||||
<h1>Edit <a href="/listings/<%= @classified_listing.category %>/<%= @classified_listing.slug %>" target="_blank">"<%= @classified_listing.title %>"</a></h1>
|
||||
|
||||
<%= 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) %>
|
||||
<hr>
|
||||
<%= form.label :published %>
|
||||
<br>
|
||||
<%= form.check_box :published %>
|
||||
<hr>
|
||||
<%= form.submit "Update Listing", class: "btn btn-lg btn-primary" %>
|
||||
|
|
|
|||
|
|
@ -1,29 +1,36 @@
|
|||
<a href="/listings">Visit /listings</a>
|
||||
|
||||
<h1>Classified Listings</h1>
|
||||
<%= 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 %>
|
||||
<div class="wrapper">
|
||||
<div class="grid-item">Title (direct link)</div>
|
||||
<div class="grid-item">Title Link</div>
|
||||
<div class="grid-item">User/Org</div>
|
||||
<div class="grid-item">Category</div>
|
||||
<div class="grid-item">Tags (cached_tag_list)</div>
|
||||
<div class="grid-item">Cached Tags</div>
|
||||
<div class="grid-item">Published?</div>
|
||||
<div class="grid-item">Last Bumped</div>
|
||||
</div>
|
||||
<% @classified_listings.each do |listing| %>
|
||||
<div class="wrapper">
|
||||
<div class="grid-item">
|
||||
<a href="/listings/<%= listing.category %>/<%= listing.slug %>" target="_blank">
|
||||
<a href="/internal/listings/<%= listing.id %>/edit" target="_blank">
|
||||
<%= listing.title %>
|
||||
</a>
|
||||
</div>
|
||||
<div class="grid-item"><a href="/internal/users/<%= listing.user_id %>"><%= User.find(listing.user_id).username %></a><%= " / " + Organization.find(listing.organization_id).name if listing.organization_id.present? %></div>
|
||||
<div class="grid-item"><%= listing.category %></div>
|
||||
<div class="grid-item"><%= listing.cached_tag_list %></div>
|
||||
<div class="grid-item"><%= listing.published ? "Yes" : "No" %></div>
|
||||
<div class="grid-item"><%= "#{time_ago_in_words(listing.bumped_at)} ago" if listing.bumped_at %></div>
|
||||
<div class="grid-item">
|
||||
<a class="btn btn-success" href="/internal/listings/<%= listing.id %>/edit">Edit</a>
|
||||
</div>
|
||||
<div class="grid-item"><%= time_ago_in_words(listing.bumped_at) %> ago</div>
|
||||
</div>
|
||||
<% end %>
|
||||
|
||||
<%= paginate @classified_listings %>
|
||||
<style>
|
||||
.wrapper {
|
||||
border-bottom: 1px solid grey;
|
||||
|
|
|
|||
|
|
@ -38,7 +38,7 @@
|
|||
|
||||
.wrapper {
|
||||
display: grid;
|
||||
grid-template-columns: 20% 20% 20% 20% 20%;
|
||||
grid-template-columns: 25% 15% 15% 15% 15% 15%;
|
||||
padding: 2px;
|
||||
}
|
||||
|
||||
|
|
@ -112,7 +112,7 @@
|
|||
</div>
|
||||
<div id="navbar" class="collapse navbar-collapse">
|
||||
<ul class="nav navbar-nav">
|
||||
<% controller_names = %w(comments articles users members dogfood tags welcome broadcasts reports pages classified_listings) %>
|
||||
<% controller_names = %w[comments articles users members dogfood tags welcome broadcasts reports pages classified_listings] %>
|
||||
<% controller_names.each do |name| %>
|
||||
<li class="<%= "active" if controller_name == name %>"><a href="/internal/<%= name %>"><%= name %></a></li>
|
||||
<% end %>
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue