Module: MusicMetadataEnrichment::ArtistConfirmation
- Extended by:
- ActiveSupport::Concern
- Included in:
- ArtistsController, GroupArtistConnectionsController, ReleasesController, TracksController, VideosController
- Defined in:
- app/controllers/concerns/music_metadata_enrichment/artist_confirmation.rb
Instance Method Summary collapse
- #artist_selection(from) ⇒ Object
- #build_artist ⇒ Object
- #confirm_artist(from) ⇒ Object
- #create_artist(from, name_and_mbid, artist_not_found = false) ⇒ Object
- #redirect_after_artist_available(from) ⇒ Object
- #render_modal_javascript_response ⇒ Object
- #set_template_name_for_xhr_or_render ⇒ Object
Instance Method Details
#artist_selection(from) ⇒ Object
92 93 94 95 96 97 98 |
# File 'app/controllers/concerns/music_metadata_enrichment/artist_confirmation.rb', line 92 def artist_selection(from) params[:music_artist] ||= {} name_and_mbid = params[:music_artist].delete(:name_and_mbid) @artist = MusicArtist.where(mbid: name_and_mbid.split(';').last).first create_artist(from, name_and_mbid, true) unless @artist redirect_after_artist_available(from) end |
#build_artist ⇒ Object
100 101 102 103 104 105 |
# File 'app/controllers/concerns/music_metadata_enrichment/artist_confirmation.rb', line 100 def build_artist params[:music_artist] ||= {} @artist = MusicArtist.new @artist.name = params[:music_artist][:name] @artist.mbid = params[:music_artist][:mbid] end |
#confirm_artist(from) ⇒ Object
9 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 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'app/controllers/concerns/music_metadata_enrichment/artist_confirmation.rb', line 9 def confirm_artist(from) build_artist if @artist.mbid.present? musicbrainz_artist = MusicBrainz::Artist.find(@artist.mbid) if musicbrainz_artist @artist.mbid = musicbrainz_artist.id @artist.name = musicbrainz_artist.name artist = MusicArtist.where(mbid: @artist.mbid).first if artist @artist = artist else @artist.save if from == 'new_artist' flash[:notice] = I18n.t('music_artists.name_confirmation.scheduled_metadata_import') elsif ['new_release', 'new_track', 'new_video'].include?(from) flash[:notice] = I18n.t('music_releases.artist_confirmation.artist_import_scheduled') end end redirect_after_artist_available(from) else flash[:alert] = I18n.t('music_artists.new.mbid_invalid') if from == 'new_artist' if params[:user_id].present? @path = new_user_music_library_artist_path(params[:user_id]) else @path = new_music_artist_path end elsif from == 'new_release' if params[:group_id].present? @path = new_music_group_release_path(params[:group_id]) else @path = new_music_release_path end elsif from == 'new_track' @path = new_music_track_path elsif from == 'new_video' if params[:group_id].present? new_music_group_video_path(params[:group_id]) else @path = new_music_video_path end elsif from == 'new_group_artist_connection' @path = new_music_group_artist_path(params[:group_id]) end end elsif @artist.name.present? @artists = MusicBrainz::Artist.search(@artist.name) else @template = :new end if @template.present? && !request.xhr? render @template elsif @path.present? && !request.xhr? redirect_to @path end end |
#create_artist(from, name_and_mbid, artist_not_found = false) ⇒ Object
73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 |
# File 'app/controllers/concerns/music_metadata_enrichment/artist_confirmation.rb', line 73 def create_artist(from, name_and_mbid, artist_not_found = false) @artist = MusicArtist.where(mbid: name_and_mbid.split(';').last).first unless artist_not_found unless @artist @artist = MusicArtist.create(name: name_and_mbid.split(';').first, mbid: name_and_mbid.split(';').last) if @artist.persisted? if from == 'new_artist' flash[:notice] = I18n.t('music_artists.create.scheduled_artist_for_import') elsif ['new_release', 'new_track', 'new_video'].include? from flash[:notice] = I18n.t('music_releases.select_artist.scheduled_artist_for_import') end else params[:music_artist][:name] = @artist.name params[:music_artist][:mbid] = @artist.mbid end end end |
#redirect_after_artist_available(from) ⇒ Object
107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 |
# File 'app/controllers/concerns/music_metadata_enrichment/artist_confirmation.rb', line 107 def redirect_after_artist_available(from) if !@artist.persisted? render :new elsif ['new_release', 'new_track', 'new_video'].include?(from) # && @artist.active? working_params = {} if params[:group_id].present? MusicMetadataEnrichment::GroupArtistConnection.create(group_id: params[:group_id], artist_id: @artist.id) working_params[:group_id] = params[:group_id] elsif params[:user_id].present? MusicLibraryArtist.create(user_id: params[:user_id], artist_id: @artist.id) end case from when 'new_release' if @artist.is_classical? flash[:alert] = I18n.t('music_releases.artist_confirmation.classical_releases_not_supported') @path = params[:group_id].present? ? music_group_path(params[:group_id]) : music_path else @path = name_music_releases_path(working_params.merge(music_release: { artist_id: @artist.id })) end when 'new_track' then @path = name_music_tracks_path(music_track: { artist_id: @artist.id }) when 'new_video' @path = track_name_music_videos_path(working_params.merge(music_track: { artist_id: @artist.id })) else if params[:group_id].present? @path = music_group_path(params[:group_id]) elsif params[:user_id].present? @path = user_music_library_path(params[:user_id]) else @path = music_path end end elsif from == 'new_group_artist_connection' @path = creation_music_group_artists_path( group_artist_connection: { group_id: params[:group_id], artist_id: @artist.id } ) end redirect_to @path unless @path.blank? || request.xhr? end |
#render_modal_javascript_response ⇒ Object
159 160 161 162 163 164 165 166 167 168 169 170 171 |
# File 'app/controllers/concerns/music_metadata_enrichment/artist_confirmation.rb', line 159 def render_modal_javascript_response @data ||= { year_in_review_music_id: params[:year_in_review_music_id] } @method ||= :get render( partial: 'shared/modal_javascript_response.js', locals: { title: t("year_in_review_music_#{controller_name}.new.new_#{controller_name.singularize}"), namespace: "music_metadata_enrichment/#{controller_name}/", ajax_data: @data, ajax_method: @method }, layout: false ) end |
#set_template_name_for_xhr_or_render ⇒ Object
151 152 153 154 155 156 157 |
# File 'app/controllers/concerns/music_metadata_enrichment/artist_confirmation.rb', line 151 def set_template_name_for_xhr_or_render if @template.present? && !request.xhr? render @template elsif @template.blank? && @path.blank? @template = action_name end end |