diff --git a/app/controllers/artist_urls_controller.rb b/app/controllers/artist_urls_controller.rb index 1c75ece3b..cd3c97e54 100644 --- a/app/controllers/artist_urls_controller.rb +++ b/app/controllers/artist_urls_controller.rb @@ -1,6 +1,14 @@ class ArtistUrlsController < ApplicationController - respond_to :json - before_action :member_only + respond_to :json, :xml, :html + before_action :member_only, except: [:index] + + def index + @artist_urls = ArtistUrl.includes(:artist).search(search_params).paginate(params[:page], :limit => params[:limit], :search_count => params[:search]) + respond_with(@artist_urls) do |format| + format.json { render json: @artist_urls.to_json(include: "artist",) } + format.xml { render xml: @artist_urls.to_xml(include: "artist", root: "artist-urls") } + end + end def update @artist_url = ArtistUrl.find(params[:id]) diff --git a/app/models/artist_url.rb b/app/models/artist_url.rb index 8612ed3fb..68625c9dc 100644 --- a/app/models/artist_url.rb +++ b/app/models/artist_url.rb @@ -45,6 +45,24 @@ class ArtistUrl < ApplicationRecord end end + def self.search(params = {}) + q = super + + q = q.attribute_matches(:artist_id, params[:artist_id]) + q = q.attribute_matches(:is_active, params[:is_active]) + + case params[:order] + when /\A(id|artist_id|url|normalized_url|is_active|created_at|updated_at)(?:_(asc|desc))?\z/i + dir = $2 || :desc + q = q.order($1 => dir).order(id: :desc) + else + q = q.apply_default_order(params) + end + + q + end + + def parse_prefix case url when /^-/ diff --git a/app/views/artist_urls/index.html.erb b/app/views/artist_urls/index.html.erb new file mode 100644 index 000000000..fd4d498e7 --- /dev/null +++ b/app/views/artist_urls/index.html.erb @@ -0,0 +1,44 @@ +
| ID | +Artist Name | +URL | +Normalized URL | +Active? | +Created | +Updated | +
|---|---|---|---|---|---|---|