diff --git a/app/controllers/listings_controller.rb b/app/controllers/listings_controller.rb index fa7dc1095..889aaa428 100644 --- a/app/controllers/listings_controller.rb +++ b/app/controllers/listings_controller.rb @@ -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 diff --git a/app/views/listings/dashboard.html.erb b/app/views/listings/dashboard.html.erb index 61b4155b7..264d3df7d 100644 --- a/app/views/listings/dashboard.html.erb +++ b/app/views/listings/dashboard.html.erb @@ -1,18 +1,9 @@ <% title "Listings Dashboard" %> -
<%= notice %>
-<%= link_to 'Edit', edit_listing_path(@listing) %> | -<%= link_to 'Back', listings_path %> +<%= link_to "Edit", edit_listing_path(@listing) %> | +<%= link_to "Back", listings_path %>