Class: MusicMetadataEnrichment::TracksController

Inherits:
ApplicationController show all
Includes:
Applicat::Mvc::Controller::Resource, ArtistConfirmation, BaseController, TrackConfirmation
Defined in:
app/controllers/music_metadata_enrichment/tracks_controller.rb

Instance Method Summary collapse

Methods included from ArtistConfirmation

#artist_selection, #build_artist, #confirm_artist, #create_artist, #redirect_after_artist_available, #render_modal_javascript_response, #set_template_name_for_xhr_or_render

Methods included from BaseController

#application_navigation, #navigation_product_name, #navigation_product_path

Instance Method Details

#artist_confirmationObject



27
28
29
30
31
32
# File 'app/controllers/music_metadata_enrichment/tracks_controller.rb', line 27

def artist_confirmation
  confirm_artist('new_track')
  set_template_name_for_xhr_or_render
  
  render_modal_javascript_response if request.xhr?
end

#autocompleteObject



13
14
15
16
17
18
# File 'app/controllers/music_metadata_enrichment/tracks_controller.rb', line 13

def autocomplete
  artist = MusicArtist.find(params[:artist_id])
  render json: (
    artist.tracks.without_slaves.select('id, name').where("LOWER(name) LIKE ?", "#{params[:term].to_s.strip.downcase}%").order(:name).limit(10).map{|r| { id: r.id, value: r.name } }
  ), root: false
end

#by_nameObject



76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
# File 'app/controllers/music_metadata_enrichment/tracks_controller.rb', line 76

def by_name
  if params[:artist_name].blank? || params[:name].blank?
    flash[:alert] = I18n.t('music_tracks.by_name.artist_name_or_name_blank')
    redirect_to music_tracks_path(artist_name: params[:artist_name], name: params[:name]) and return
  end
  
  @tracks = MusicTrack.by_artist_and_name([[params[:artist_name], params[:name]]])
  @track = @tracks.first if params[:page].blank? && @tracks.count == 1
 
  if @track
    get_variables_for_show
    render :show
  else
    @tracks = MusicTrack.without_slaves.artist_and_name_like(params[:artist_name], params[:name]) if @tracks.nil? || @tracks.count == 0
    @tracks = @tracks.paginate(per_page: 10, page: params[:page] || 1)
  end
end

#createObject



62
63
64
65
66
67
68
69
# File 'app/controllers/music_metadata_enrichment/tracks_controller.rb', line 62

def create
  build_track
  track_creation('new_track')
  
  add_to_year_in_review_music_top_tracks if @track.persisted? && params[:year_in_review_music_id].present?
  
  render_modal_javascript_response if request.xhr?
end

#indexObject



10
11
# File 'app/controllers/music_metadata_enrichment/tracks_controller.rb', line 10

def index
end

#nameObject



41
42
43
44
45
46
# File 'app/controllers/music_metadata_enrichment/tracks_controller.rb', line 41

def name
  build_track
  set_template_name_for_xhr_or_render
  
  render_modal_javascript_response if request.xhr?
end

#name_confirmationObject



48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'app/controllers/music_metadata_enrichment/tracks_controller.rb', line 48

def name_confirmation
  build_track
  @tracks = MusicTrack.search_on_musicbrainz(@track.artist.mbid, @track.name)
  
  if @tracks.none?
    track_creation('new_track', @track.name) 
    add_to_year_in_review_music_top_tracks if @track.persisted? && params[:year_in_review_music_id].present?
  else
    set_template_name_for_xhr_or_render
  end
  
  render_modal_javascript_response if request.xhr?
end

#newObject



20
21
22
23
24
25
# File 'app/controllers/music_metadata_enrichment/tracks_controller.rb', line 20

def new
  build_artist
  set_template_name_for_xhr_or_render
  
  render_modal_javascript_response if request.xhr?
end

#resourceObject



94
95
96
# File 'app/controllers/music_metadata_enrichment/tracks_controller.rb', line 94

def resource
  @track
end

#select_artistObject



34
35
36
37
38
39
# File 'app/controllers/music_metadata_enrichment/tracks_controller.rb', line 34

def select_artist
  artist_selection('new_track')
  set_template_name_for_xhr_or_render
  
  render_modal_javascript_response if request.xhr?
end

#showObject



71
72
73
74
# File 'app/controllers/music_metadata_enrichment/tracks_controller.rb', line 71

def show
  @track = MusicTrack.find(params[:id])
  get_variables_for_show
end