Class: MusicMetadataEnrichment::ArtistsController
Instance Method Summary
collapse
#artist_selection, #build_artist, #confirm_artist, #create_artist, #redirect_after_artist_available, #render_modal_javascript_response, #set_template_name_for_xhr_or_render
#application_navigation, #navigation_product_name, #navigation_product_path
Instance Method Details
#autocomplete ⇒ Object
38
39
40
41
42
|
# File 'app/controllers/music_metadata_enrichment/artists_controller.rb', line 38
def autocomplete
render json: (
MusicArtist.select('id, name, disambiguation').where("LOWER(name) LIKE ?", "#{params[:term].to_s.strip.downcase}%").order(:name).limit(10).map{|a| { id: a.id, value: a.name + (a.disambiguation.present? ? " (#{a.disambiguation})" : '') } }
), root: false
end
|
#by_name ⇒ Object
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
|
# File 'app/controllers/music_metadata_enrichment/artists_controller.rb', line 64
def by_name
if params[:name].blank?
flash[:alert] = I18n.t('music_artists.by_name.name_blank')
redirect_to music_artists_path and return
end
@artists = MusicArtist.where("LOWER(name) = ?", params[:name].downcase.strip)
@artist = @artists.first if params[:page].blank? && @artists.count == 1
if @artist
get_variables_for_show
render :show
else
@artists = MusicArtist.name_like(params[:name]) if @artists.nil? || @artists.count == 0
@artists = @artists.paginate(per_page: 10, page: params[:page] || 1)
end
end
|
#create ⇒ Object
52
53
54
55
56
57
|
# File 'app/controllers/music_metadata_enrichment/artists_controller.rb', line 52
def create
params[:music_artist] ||= {}
name_and_mbid = params[:music_artist].delete(:name_and_mbid)
create_artist('new_artist', name_and_mbid)
redirect_after_artist_available(from)
end
|
#index ⇒ Object
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
|
# File 'app/controllers/music_metadata_enrichment/artists_controller.rb', line 10
def index
if request.xhr?
if params[:group_id].present? || request.original_url.match('/groups/') && params[:id]
@group = MusicMetadataEnrichment::Group.find(params[:group_id] || params[:id])
@artists = @group.artists
@pagination_params = { group_id: (params[:group_id] || params[:id]) }
elsif params[:user_id].present?
@artists = User.by_slug_or_id(params[:user_id]).music_artists
end
@artists = @artists.order('name ASC').paginate(per_page: 10, page: params[:page] || 1)
if @group && @artists.any?
@group_artist_connections = @group.artist_connections.where('music_metadata_enrichment_group_artist_connections.artist_id IN(?)', @artists.map(&:id))
if user_signed_in?
@group_artist_connection_likes = MusicMetadataEnrichment::GroupArtistConnection.likes_or_dislikes_for(current_user, @group_artist_connections.map(&:id))
end
@group_artist_connections = @group_artist_connections.index_by(&:artist_id)
elsif params[:user_id].present? && current_user.try(:id) == params[:user_id].to_i && @artists.any?
@music_library_artists = current_user.music_library_artists.where('music_library_artists.artist_id IN(?)', @artists.map(&:id)).index_by(&:artist_id)
end
render partial: 'music_metadata_enrichment/artists/collection', layout: false, locals: { title: I18n.t("music_metadata_enrichment_group_artist_connections.index.empty_collection"), paginate: true }
end
end
|
#name_confirmation ⇒ Object
48
49
50
|
# File 'app/controllers/music_metadata_enrichment/artists_controller.rb', line 48
def name_confirmation
confirm_artist('new_artist')
end
|
#new ⇒ Object
44
45
46
|
# File 'app/controllers/music_metadata_enrichment/artists_controller.rb', line 44
def new
build_artist
end
|
#resource ⇒ Object
82
83
84
|
# File 'app/controllers/music_metadata_enrichment/artists_controller.rb', line 82
def resource
@artist
end
|
#show ⇒ Object
59
60
61
62
|
# File 'app/controllers/music_metadata_enrichment/artists_controller.rb', line 59
def show
@artist = MusicArtist.find(params[:id])
get_variables_for_show
end
|