Fix erblint errors on the app/views/listings folder (#8374)

* Fix erblint errors on the `app/views/listings` folder

* Move `to_json()` methods to the controller
This commit is contained in:
Alberto Pérez de Rada Fiol 2020-06-10 16:38:21 +02:00 committed by GitHub
parent 87c258bdec
commit df759bd310
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 26 additions and 23 deletions

View file

@ -2,7 +2,7 @@ class ListingsController < ApplicationController
include ListingsToolkit
before_action :check_limit, only: [:create]
JSON_OPTIONS = {
INDEX_JSON_OPTIONS = {
only: %i[
title processed_html tag_list category id user_id slug contact_via_connect location
],
@ -11,6 +11,15 @@ class ListingsController < ApplicationController
}
}.freeze
DASHBOARD_JSON_OPTIONS = {
only: %i[
title tag_list created_at expires_at bumped_at updated_at category id user_id slug organization_id location published
],
include: {
author: { only: %i[username name], methods: %i[username profile_image_90] }
}
}.freeze
before_action :set_listing, only: %i[edit update destroy]
before_action :set_cache_control_headers, only: %i[index]
before_action :raise_suspended, only: %i[new create update]
@ -36,8 +45,8 @@ class ListingsController < ApplicationController
Listing.none
end
@listings_json = @listings.to_json(JSON_OPTIONS)
@displayed_listing_json = @displayed_listing.to_json(JSON_OPTIONS)
@listings_json = @listings.to_json(INDEX_JSON_OPTIONS)
@displayed_listing_json = @displayed_listing.to_json(INDEX_JSON_OPTIONS)
# TODO: [mkohl] Can we change this to listings-#{params[:category]}?
set_surrogate_key_header "classified-listings-#{params[:category]}"
@ -64,14 +73,17 @@ class ListingsController < ApplicationController
end
def dashboard
@listings = current_user.listings.
listings = current_user.listings.
includes(:organization, :taggings)
@listings_json = listings.to_json(DASHBOARD_JSON_OPTIONS)
organizations_ids = current_user.organization_memberships.
where(type_of_user: "admin").
pluck(:organization_id)
@orgs = Organization.where(id: organizations_ids)
@org_listings = Listing.where(organization_id: organizations_ids)
orgs = Organization.where(id: organizations_ids)
@orgs_json = orgs.to_json(only: %i[id name slug unspent_credits_count])
org_listings = Listing.where(organization_id: organizations_ids)
@org_listings_json = org_listings.to_json(DASHBOARD_JSON_OPTIONS)
@user_credits = current_user.unspent_credits_count
end

View file

@ -1,18 +1,9 @@
<% title "Listings Dashboard" %>
<div id="listings-dashboard" data-listings="<%= @listings.to_json(
only: %i[title tag_list created_at expires_at bumped_at updated_at category id user_id slug organization_id location published],
include: {
author: { only: %i[username name], methods: %i[username profile_image_90] },
},
)%>" data-usercredits="<%= @user_credits %>"
data-orglistings="<%= @org_listings.to_json(
only: %i[title tag_list created_at expires_at bumped_at updated_at category id user_id slug organization_id location published],
include: {
author: { only: %i[username name], methods: %i[username profile_image_90] },
},
) %>" data-orgs="<%= @orgs.to_json(
only: %i[id name slug unspent_credits_count]
) %>" >
<div id="listings-dashboard"
data-listings="<%= @listings_json %>"
data-usercredits="<%= @user_credits %>"
data-orglistings="<%= @org_listings_json %>"
data-orgs="<%= @orgs_json %>">
</div>
<%= javascript_packs_with_chunks_tag "listingDashboard", defer: true %>

View file

@ -38,7 +38,7 @@
<div class="listing-filters-categories">
<a href="<%= listings_path %>" class="<%= "selected" if params[:category].blank? %> data-no-instant=" true ">all</a>
<% categories_for_display.each do |cat| %>
<a href="<%= listing_category_path(category: cat[:slug]) %>" class="<%= "selected" if params[:category] == cat[:slug] %> data-no-instant="true"><%= cat[:name] %></a>
<a href="<%= listing_category_path(category: cat[:slug]) %> " class="<%= "selected" if params[:category] == cat[:slug] %> data-no-instant="true"><%= cat[:name] %></a>
<% end %>
<a href="<%= new_listing_path %>" class='listing-create-link'>Create a Listing</a>
<% if @displayed_listing %>

View file

@ -1,4 +1,4 @@
<p id="notice"><%= notice %></p>
<%= link_to 'Edit', edit_listing_path(@listing) %> |
<%= link_to 'Back', listings_path %>
<%= link_to "Edit", edit_listing_path(@listing) %> |
<%= link_to "Back", listings_path %>