| 1 | ActiveAdmin.register Album do |
| 2 | menu priority: 4, parent: 'Music Database' |
| 3 | permit_params :name, :description, :user_id, :locale, album_artists_attributes: %i[id artist_id primary _destroy] |
| 4 | |
| 5 | index do |
| 6 | selectable_column |
| 7 | column :name |
| 8 | column :description do |album| |
| 9 | strip_tags album.description.truncate 150 |
| 10 | end |
| 11 | column 'Artists' do |album| |
| 12 | if album.artists.count.positive? |
| 13 | album.artists.each_with_index do |artist, _index| |
| 14 | a artist.name, href: admin_artist_url(artist) |
| 15 | text_node ' | '.html_safe |
| 16 | a 'edit', href: edit_admin_artist_url(artist) |
| 17 | text_node '</br>'.html_safe |
| 18 | end |
| 19 | nil |
| 20 | end |
| 21 | end |
| 22 | column 'Songs' do |album| |
| 23 | if album.songs.count.positive? |
| 24 | album.songs.each_with_index do |song, _index| |
| 25 | a song.name, href: admin_song_url(song) |
| 26 | text_node ' | '.html_safe |
| 27 | a 'edit', href: edit_admin_song_url(song) |
| 28 | text_node '</br>'.html_safe |
| 29 | end |
| 30 | text_node '</br>'.html_safe |
| 31 | end |
| 32 | link_to 'Tambah', "#{new_admin_song_path}?album_id=#{album.id.to_s}" |
| 33 | end |
| 34 | column :user |
| 35 | column :views_count |
| 36 | actions |
| 37 | end |
| 38 | |
| 39 | filter :artists |
| 40 | filter :songs |
| 41 | filter :views_count |
| 42 | filter :name |
| 43 | filter :description |
| 44 | filter :created_at |
| 45 | filter :updated_at |
| 46 | |
| 47 | show do |
| 48 | attributes_table do |
| 49 | row :name |
| 50 | row :description do |album| |
| 51 | raw album.description |
| 52 | end |
| 53 | row :user |
| 54 | row :created_at |
| 55 | row :updated_at |
| 56 | end |
| 57 | end |
| 58 | |
| 59 | form do |f| |
| 60 | f.inputs do |
| 61 | f.has_many :album_artists, allow_destroy: true, new_record: 'Tambah Artis' do |a| |
| 62 | a.input :artist, include_blank: false |
| 63 | a.input :primary |
| 64 | end |
| 65 | end |
| 66 | f.inputs do |
| 67 | f.input :name |
| 68 | f.input :user |
| 69 | f.input :description, as: :quill_editor |
| 70 | end |
| 71 | f.actions |
| 72 | end |
| 73 | end |