From 4739c45da0520630e8ea49aaa37cc17107efe3d7 Mon Sep 17 00:00:00 2001 From: r888888888 Date: Sat, 26 May 2018 13:13:07 -0700 Subject: [PATCH] fixes #3729 --- app/controllers/moderator/ip_addrs_controller.rb | 2 ++ .../ip_addrs/{_ip_listing.erb => _ip_listing.html.erb} | 0 app/views/moderator/ip_addrs/_ip_listing.json.erb | 1 + app/views/moderator/ip_addrs/_user_listing.json.erb | 1 + app/views/moderator/ip_addrs/index.json.erb | 5 +++++ 5 files changed, 9 insertions(+) rename app/views/moderator/ip_addrs/{_ip_listing.erb => _ip_listing.html.erb} (100%) create mode 100644 app/views/moderator/ip_addrs/_ip_listing.json.erb create mode 100644 app/views/moderator/ip_addrs/_user_listing.json.erb create mode 100644 app/views/moderator/ip_addrs/index.json.erb diff --git a/app/controllers/moderator/ip_addrs_controller.rb b/app/controllers/moderator/ip_addrs_controller.rb index 2add8f756..26f36d1ef 100644 --- a/app/controllers/moderator/ip_addrs_controller.rb +++ b/app/controllers/moderator/ip_addrs_controller.rb @@ -1,10 +1,12 @@ module Moderator class IpAddrsController < ApplicationController before_action :moderator_only + respond_to :html, :json def index @search = IpAddrSearch.new(params[:search]) @results = @search.execute + respond_with(@results) end def search diff --git a/app/views/moderator/ip_addrs/_ip_listing.erb b/app/views/moderator/ip_addrs/_ip_listing.html.erb similarity index 100% rename from app/views/moderator/ip_addrs/_ip_listing.erb rename to app/views/moderator/ip_addrs/_ip_listing.html.erb diff --git a/app/views/moderator/ip_addrs/_ip_listing.json.erb b/app/views/moderator/ip_addrs/_ip_listing.json.erb new file mode 100644 index 000000000..bb9f4c563 --- /dev/null +++ b/app/views/moderator/ip_addrs/_ip_listing.json.erb @@ -0,0 +1 @@ +<%= raw @results.map {|ip_addr, count| {ip_addr: ip_addr.to_s, count: count}}.to_json %> \ No newline at end of file diff --git a/app/views/moderator/ip_addrs/_user_listing.json.erb b/app/views/moderator/ip_addrs/_user_listing.json.erb new file mode 100644 index 000000000..e08079c16 --- /dev/null +++ b/app/views/moderator/ip_addrs/_user_listing.json.erb @@ -0,0 +1 @@ +<%= raw @results.map {|user, count| {user_id: user.id, count: count}}.to_json %> \ No newline at end of file diff --git a/app/views/moderator/ip_addrs/index.json.erb b/app/views/moderator/ip_addrs/index.json.erb new file mode 100644 index 000000000..75017df8c --- /dev/null +++ b/app/views/moderator/ip_addrs/index.json.erb @@ -0,0 +1,5 @@ +<% if params[:search][:user_id].present? || params[:search][:user_name].present? %> + <%= render "ip_listing.json" %> +<% else %> + <%= render "user_listing.json" %> +<% end %>