From fda16b2a655d73c53c46c421120966ab9231b086 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89lisson=20Michael?= Date: Wed, 9 Oct 2019 21:06:29 -0300 Subject: [PATCH 01/15] Adiciona Index de Genre --- app/controllers/genres_controller.rb | 5 +++++ app/views/genres/index.html.erb | 7 +++++++ config/routes.rb | 1 + 3 files changed, 13 insertions(+) create mode 100644 app/controllers/genres_controller.rb create mode 100644 app/views/genres/index.html.erb diff --git a/app/controllers/genres_controller.rb b/app/controllers/genres_controller.rb new file mode 100644 index 0000000..f23ef89 --- /dev/null +++ b/app/controllers/genres_controller.rb @@ -0,0 +1,5 @@ +class GenresController < ApplicationController + def index + @genres = Genre.all + end +end diff --git a/app/views/genres/index.html.erb b/app/views/genres/index.html.erb new file mode 100644 index 0000000..a6164b5 --- /dev/null +++ b/app/views/genres/index.html.erb @@ -0,0 +1,7 @@ +

All Genres

+ +
    + <% @genres.each do |genre| %> +
  1. <%= genre.name %>
  2. + <% end %> +
diff --git a/config/routes.rb b/config/routes.rb index 6c4e4ee..fd60f5a 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,4 +1,5 @@ Rails.application.routes.draw do resources :artists + resources :genres root 'artists#index' end From 91e22a7ea3d5885865629b65b13ac63ad1191a9e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89lisson=20Michael?= Date: Wed, 9 Oct 2019 21:25:34 -0300 Subject: [PATCH 02/15] Adiciona Show de Genre --- app/controllers/genres_controller.rb | 4 ++++ app/helpers/application_helper.rb | 3 +++ app/views/genres/index.html.erb | 2 +- app/views/genres/show.html.erb | 8 ++++++++ 4 files changed, 16 insertions(+), 1 deletion(-) create mode 100644 app/views/genres/show.html.erb diff --git a/app/controllers/genres_controller.rb b/app/controllers/genres_controller.rb index f23ef89..4100305 100644 --- a/app/controllers/genres_controller.rb +++ b/app/controllers/genres_controller.rb @@ -2,4 +2,8 @@ class GenresController < ApplicationController def index @genres = Genre.all end + + def show + @genre = Genre.find(params[:id]) + end end diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index de6be79..6ef238a 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -1,2 +1,5 @@ module ApplicationHelper + def format(date) + date.strftime("%d/%m/%y %H:%M") + end end diff --git a/app/views/genres/index.html.erb b/app/views/genres/index.html.erb index a6164b5..8e522f0 100644 --- a/app/views/genres/index.html.erb +++ b/app/views/genres/index.html.erb @@ -2,6 +2,6 @@
    <% @genres.each do |genre| %> -
  1. <%= genre.name %>
  2. +
  3. <%= link_to genre.name, genre %>
  4. <% end %>
diff --git a/app/views/genres/show.html.erb b/app/views/genres/show.html.erb new file mode 100644 index 0000000..3b58d00 --- /dev/null +++ b/app/views/genres/show.html.erb @@ -0,0 +1,8 @@ +

Showing Genre

+ +
+ ID: <%= @genre.id %>
+ Name: <%= @genre.name %>
+ Created at: <%= format(@genre.created_at) %>
+ Updated at: <%= format(@genre.updated_at) %>
+
From 7f6ed89ef8aa23526fe7e4a70be1b242715ca262 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89lisson=20Michael?= Date: Wed, 16 Oct 2019 21:35:13 -0300 Subject: [PATCH 03/15] =?UTF-8?q?Adiciona=20Formul=C3=A1rio=20de=20Cria?= =?UTF-8?q?=C3=A7=C3=A3o=20de=20Genre?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/genres_controller.rb | 19 +++++++++++++++++++ app/views/genres/new.html.erb | 6 ++++++ config/routes.rb | 2 +- 3 files changed, 26 insertions(+), 1 deletion(-) create mode 100644 app/views/genres/new.html.erb diff --git a/app/controllers/genres_controller.rb b/app/controllers/genres_controller.rb index 4100305..04ba375 100644 --- a/app/controllers/genres_controller.rb +++ b/app/controllers/genres_controller.rb @@ -6,4 +6,23 @@ def index def show @genre = Genre.find(params[:id]) end + + def new + @genre = Genre.new + end + + def create + @genre = Genre.new(genre_params) + if @genre.save + redirect_to @genre + else + render :new + end + end + + private + + def genre_params + params.require(:genre).permit(:name) + end end diff --git a/app/views/genres/new.html.erb b/app/views/genres/new.html.erb new file mode 100644 index 0000000..830171c --- /dev/null +++ b/app/views/genres/new.html.erb @@ -0,0 +1,6 @@ +

New Genre

+<%= @genre.errors.first %> +<%= form_for @genre do |f| %> + Nome: <%= f.text_field :name %> + <%= f.submit 'Save' %> +<% end %> diff --git a/config/routes.rb b/config/routes.rb index fd60f5a..260ef24 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,5 +1,5 @@ Rails.application.routes.draw do resources :artists - resources :genres + resources :genres, except: :destroy root 'artists#index' end From c6590046b4fa85cb27e1bd8f1116345bddcb9ed5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89lisson=20Michael?= Date: Wed, 30 Oct 2019 19:35:21 -0300 Subject: [PATCH 04/15] Adiciona Filtro em Genres Index --- app/controllers/genres_controller.rb | 3 +++ app/views/genres/index.html.erb | 6 ++++++ 2 files changed, 9 insertions(+) diff --git a/app/controllers/genres_controller.rb b/app/controllers/genres_controller.rb index 04ba375..cc3d898 100644 --- a/app/controllers/genres_controller.rb +++ b/app/controllers/genres_controller.rb @@ -1,6 +1,9 @@ class GenresController < ApplicationController def index @genres = Genre.all + if params['name'].present? + @genres = @genres.where("name LIKE ?", "%#{params['name']}%") + end end def show diff --git a/app/views/genres/index.html.erb b/app/views/genres/index.html.erb index 8e522f0..0b9a1bc 100644 --- a/app/views/genres/index.html.erb +++ b/app/views/genres/index.html.erb @@ -1,5 +1,11 @@

All Genres

+<%= form_tag("/genres", method: "get") do %> + <%= label_tag(:name, "Filter:") %> + <%= text_field_tag(:name, params['name']) %> + <%= submit_tag("Submit") %> +<% end %> +
    <% @genres.each do |genre| %>
  1. <%= link_to genre.name, genre %>
  2. From 42c1ec07f6919b2c4429051d364c58048df6bab4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89lisson=20Michael?= Date: Wed, 30 Oct 2019 19:54:48 -0300 Subject: [PATCH 05/15] Refatora Filtro em Genres p/ Usar Scope --- app/controllers/genres_controller.rb | 5 +---- app/models/genre.rb | 2 +- 2 files changed, 2 insertions(+), 5 deletions(-) diff --git a/app/controllers/genres_controller.rb b/app/controllers/genres_controller.rb index cc3d898..9af3ef3 100644 --- a/app/controllers/genres_controller.rb +++ b/app/controllers/genres_controller.rb @@ -1,9 +1,6 @@ class GenresController < ApplicationController def index - @genres = Genre.all - if params['name'].present? - @genres = @genres.where("name LIKE ?", "%#{params['name']}%") - end + @genres = Genre.filtrar(params['name']) end def show diff --git a/app/models/genre.rb b/app/models/genre.rb index 3fc7d25..a032523 100644 --- a/app/models/genre.rb +++ b/app/models/genre.rb @@ -1,5 +1,5 @@ class Genre < ApplicationRecord has_many :tracks - + scope :filtrar, ->(name) { where("name LIKE ?", "%#{name}%") if name.present? } validates_presence_of :name end From c1f36206ff7481ed4e89d3d620801f00f7fa44e1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89lisson=20Michael?= Date: Wed, 30 Oct 2019 21:11:48 -0300 Subject: [PATCH 06/15] Add Boostrap to Genres Filter --- app/views/genres/index.html.erb | 14 ++++++++++---- app/views/layouts/application.html.erb | 23 ++++++++++++++--------- 2 files changed, 24 insertions(+), 13 deletions(-) diff --git a/app/views/genres/index.html.erb b/app/views/genres/index.html.erb index 0b9a1bc..8bc773c 100644 --- a/app/views/genres/index.html.erb +++ b/app/views/genres/index.html.erb @@ -1,13 +1,19 @@

    All Genres

    <%= form_tag("/genres", method: "get") do %> - <%= label_tag(:name, "Filter:") %> - <%= text_field_tag(:name, params['name']) %> - <%= submit_tag("Submit") %> +
    +
    + +
    + <%= text_field_tag(:name, params['name'], class: "form-control") %> +
    + <%= submit_tag("Submit", class: 'btn btn-outline-primary') %> +
    +
    <% end %>
      <% @genres.each do |genre| %> -
    1. <%= link_to genre.name, genre %>
    2. +
    3. <%= link_to genre.name, genre %>
    4. <% end %>
    diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb index 49e0033..810495e 100644 --- a/app/views/layouts/application.html.erb +++ b/app/views/layouts/application.html.erb @@ -1,14 +1,19 @@ - - RailsWindows - <%= csrf_meta_tags %> + + RailsWindows + <%= csrf_meta_tags %> + + <%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track': 'reload' %> + <%= javascript_include_tag 'application', 'data-turbolinks-track': 'reload' %> + - <%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track': 'reload' %> - <%= javascript_include_tag 'application', 'data-turbolinks-track': 'reload' %> - - - + +
    <%= yield %> - +
    + + + + From bb42d0369b6a9d0ffbc12cc651340692e35695d6 Mon Sep 17 00:00:00 2001 From: Rodolpho Lopes Date: Thu, 31 Oct 2019 04:21:54 +0000 Subject: [PATCH 07/15] Controller do artist --- app/controllers/artists_controller.rb | 29 ++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/app/controllers/artists_controller.rb b/app/controllers/artists_controller.rb index c4dccc0..9d92fd3 100644 --- a/app/controllers/artists_controller.rb +++ b/app/controllers/artists_controller.rb @@ -1,5 +1,32 @@ class ArtistsController < ApplicationController def index - @consulta = Artist.all + @artist = Artist.all + if params['name'].present? + @artist = @artist.where("name LIKE ?", "%#{params['name']}%") + end end + + def show + @artist = Artist.find(params[:id]).albums + end + + def new + @artist = Artist.new + end + + def create + @artist = Artist.new(artist_params) + if @artist.save + redirect_to @artist + else + render :new + end + end + + private + + def artist_params + params.require(:artist).permit(:name) + end + end From 4a570430273975a9330cf839f4f2afdc86f6e806 Mon Sep 17 00:00:00 2001 From: Rodolpho Lopes Date: Thu, 31 Oct 2019 04:22:13 +0000 Subject: [PATCH 08/15] Controller de genres --- app/controllers/genres_controller.rb | 39 ++++++++++++++++++++++++++-- 1 file changed, 37 insertions(+), 2 deletions(-) diff --git a/app/controllers/genres_controller.rb b/app/controllers/genres_controller.rb index 9af3ef3..9f305de 100644 --- a/app/controllers/genres_controller.rb +++ b/app/controllers/genres_controller.rb @@ -1,6 +1,9 @@ class GenresController < ApplicationController def index - @genres = Genre.filtrar(params['name']) + @genre = Genre.all + if params['name'].present? + @genre = @genre.where("name LIKE ?", "%#{params['name']}%") + end end def show @@ -25,4 +28,36 @@ def create def genre_params params.require(:genre).permit(:name) end -end + +endclass GenresController < ApplicationController + def index + @genre = Genre.all + if params['name'].present? + @genre = @genre.where("name LIKE ?", "%#{params['name']}%") + end + end + + def show + @genre = Genre.find(params[:id]) + end + + def new + @genre = Genre.new + end + + def create + @genre = Genre.new(genre_params) + if @genre.save + redirect_to @genre + else + render :new + end + end + + private + + def genre_params + params.require(:genre).permit(:name) + end + +end \ No newline at end of file From 8d5b037fd51f3e498a254a58d4aff338168af577 Mon Sep 17 00:00:00 2001 From: Rodolpho Lopes Date: Thu, 31 Oct 2019 04:22:27 +0000 Subject: [PATCH 09/15] Controller de albums --- app/controllers/albums_controller.rb | 32 ++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 app/controllers/albums_controller.rb diff --git a/app/controllers/albums_controller.rb b/app/controllers/albums_controller.rb new file mode 100644 index 0000000..733485b --- /dev/null +++ b/app/controllers/albums_controller.rb @@ -0,0 +1,32 @@ +class AlbumsController < ApplicationController + def index + @album = Album.all + if params['title'].present? + @album = @album.where("title LIKE ?", "%#{params['title']}%") + end + end + + def show + @album = Album.find(params[:id]) + end + + def new + @album = Album.new + end + + def create + @album = Album.new(album_params) + if @album.save + redirect_to @album + else + render :new + end + end + + private + + def album_params + params.require(:album).permit(:title) + end + +end From b676550b767306fd6f86047cdd74fa0f85fa91d9 Mon Sep 17 00:00:00 2001 From: Rodolpho Lopes Date: Thu, 31 Oct 2019 04:22:38 +0000 Subject: [PATCH 10/15] Controller de tracks --- app/controllers/tracks_controller.rb | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 app/controllers/tracks_controller.rb diff --git a/app/controllers/tracks_controller.rb b/app/controllers/tracks_controller.rb new file mode 100644 index 0000000..2344a69 --- /dev/null +++ b/app/controllers/tracks_controller.rb @@ -0,0 +1,13 @@ +class TracksController < ApplicationController + def index + @tracks = Track.all + if params['name'].present? + @tracks = @tracks.where("name LIKE ?", "%#{params['name']}%") + end + end + + def show + @tracks = Track.find(params[:id]) + end + +end \ No newline at end of file From 31488f5781fe604a17d3530f9a08de2914954958 Mon Sep 17 00:00:00 2001 From: Rodolpho Lopes Date: Thu, 31 Oct 2019 04:23:07 +0000 Subject: [PATCH 11/15] index de artists --- app/views/artists/index.html.erb | 28 +++++++++++++++++++++++++--- 1 file changed, 25 insertions(+), 3 deletions(-) diff --git a/app/views/artists/index.html.erb b/app/views/artists/index.html.erb index 3d26cfd..b6f865d 100644 --- a/app/views/artists/index.html.erb +++ b/app/views/artists/index.html.erb @@ -1,5 +1,27 @@ -

    Desenvolvimento Web 2

    +
    +

    +
    +
    +

    Artist List <%= @artists.count %>

    +
    -

    O Conteúdo da Variável Consulta Será Exibido Abaixo:

    + <%= form_tag("/artists", method: "get") do %> +
    +
    + +
    + <%= text_field_tag(:name, params['name'], class: "form-control") %> +
    + <%= submit_tag("Search", class: 'btn btn-outline-primary') %> +
    +
    +<% end %> -<%= @consulta.try(:inspect) %> +
    +
      + <% @artists.each do |artist| %> +
    • <%= link_to artist.name, artist %>
    • + <% end %> +
    +
    +
    \ No newline at end of file From 10dd75ab3175d097803146815c603c78c75e377e Mon Sep 17 00:00:00 2001 From: Rodolpho Lopes Date: Thu, 31 Oct 2019 04:23:19 +0000 Subject: [PATCH 12/15] Index de genres --- app/views/genres/index.html.erb | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/app/views/genres/index.html.erb b/app/views/genres/index.html.erb index 8bc773c..630ccb4 100644 --- a/app/views/genres/index.html.erb +++ b/app/views/genres/index.html.erb @@ -1,19 +1,28 @@ -

    All Genres

    +
    +

    + +
    +

    Genres List <%= @genres.count %>

    +
    + <%= form_tag("/genres", method: "get") do %>
    - +
    <%= text_field_tag(:name, params['name'], class: "form-control") %>
    - <%= submit_tag("Submit", class: 'btn btn-outline-primary') %> + <%= submit_tag("Search", class: 'btn btn-outline-primary') %>
    <% end %> -
      +
      +
        <% @genres.each do |genre| %> -
      • <%= link_to genre.name, genre %>
      • +
      • <%= link_to genre.name, genre %>
      • <% end %> -
    + +
    + \ No newline at end of file From 53117f2ad4beba31442c7935e4e6a090f4c38d16 Mon Sep 17 00:00:00 2001 From: Rodolpho Lopes Date: Thu, 31 Oct 2019 04:23:41 +0000 Subject: [PATCH 13/15] Index de aplication --- app/views/layouts/application.html.erb | 73 +++++++++++++++++++++----- 1 file changed, 59 insertions(+), 14 deletions(-) diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb index 810495e..a986aaa 100644 --- a/app/views/layouts/application.html.erb +++ b/app/views/layouts/application.html.erb @@ -1,19 +1,64 @@ - - RailsWindows - <%= csrf_meta_tags %> - - <%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track': 'reload' %> - <%= javascript_include_tag 'application', 'data-turbolinks-track': 'reload' %> - + + RailsWindows + <%= csrf_meta_tags %> + + + + + <%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track': 'reload' %> + <%= javascript_include_tag 'application', 'data-turbolinks-track': 'reload' %> + - -
    - <%= yield %> + + + + <%= yield %> + From 01b3ea6200f4380e25f9b71be50dc3059e8c82ba Mon Sep 17 00:00:00 2001 From: Rodolpho Lopes Date: Thu, 31 Oct 2019 04:23:51 +0000 Subject: [PATCH 14/15] Index de albums --- app/views/albums/index.html.erb | 36 +++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 app/views/albums/index.html.erb diff --git a/app/views/albums/index.html.erb b/app/views/albums/index.html.erb new file mode 100644 index 0000000..550bbcb --- /dev/null +++ b/app/views/albums/index.html.erb @@ -0,0 +1,36 @@ + +
    +

    +
    +
    +

    Albums List <%= @albums.count %>

    +
    + <%= form_tag("/albums", method: "get") do %> +
    +
    + +
    + <%= text_field_tag(:title, params['title'], class: "form-control") %> +
    + <%= submit_tag("Search", class: 'btn btn-outline-primary') %> +
    +
    +<% end %> + +
    +
      +
    • Album
    • + <% @albums.each do |album| %> +
    • <%= link_to album.title, album %>
    • + + <% end %> +
    +
      +
    • Artist
    • + <% @albums.each do |album| %> +
    • <%= link_to album.artist_id, album %>
    • + + <% end %> +
    +
    +
    \ No newline at end of file From 3458af0e08e1ac82039eee6ddfd7f74f9d00513e Mon Sep 17 00:00:00 2001 From: Rodolpho Lopes Date: Thu, 31 Oct 2019 04:24:00 +0000 Subject: [PATCH 15/15] Index de tracks --- app/views/tracks/index.html.erb | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 app/views/tracks/index.html.erb diff --git a/app/views/tracks/index.html.erb b/app/views/tracks/index.html.erb new file mode 100644 index 0000000..48d227f --- /dev/null +++ b/app/views/tracks/index.html.erb @@ -0,0 +1,29 @@ + + +
    +

    +
    +
    +

    Track List <%= @tracks.count %>

    +
    + + <%= form_tag("/tracks", method: "get") do %> +
    +
    + +
    + <%= text_field_tag(:name, params['name'], class: "form-control") %> +
    + <%= submit_tag("Search", class: 'btn btn-outline-primary') %> +
    +
    +<% end %> + +
    +
      + <% @tracks.each do |track| %> +
    • <%= link_to track.name, track %>
    • + <% end %> +
    +
    +