diff --git a/lib/librarix/application.rb b/lib/librarix/application.rb index 0d4faea..cd38207 100644 --- a/lib/librarix/application.rb +++ b/lib/librarix/application.rb @@ -23,7 +23,10 @@ module Librarix helpers Librarix::Menu::Helper get '/' do - slim :index, locals: {movies: Librarix::Filter.new(params).movies} + slim :index, locals: { + compact: params.key?('compact'), + movies: Librarix::Filter.new(params).movies + } end get '/search' do diff --git a/lib/librarix/filter.rb b/lib/librarix/filter.rb index 9f25327..73951d9 100644 --- a/lib/librarix/filter.rb +++ b/lib/librarix/filter.rb @@ -12,6 +12,7 @@ module Librarix def filter @movies = Librarix::Redis::Movie.all by_title if @params.key?('title') + by_view_state if @params.key?('view_state') @movies.sort_by!(&:release_date).reverse! end @@ -19,5 +20,13 @@ module Librarix def by_title movies.select! { |movie| movie.title.downcase.include?(params['title']) } end + + def by_view_state + if params['view_state'] == 'viewed' + movies.keep_if(&:viewed?) + elsif params['view_state'] == 'not_viewed' + movies.delete_if(&:viewed?) + end + end end end diff --git a/lib/librarix/the_movie_db.rb b/lib/librarix/the_movie_db.rb index 2612492..c0b95d3 100644 --- a/lib/librarix/the_movie_db.rb +++ b/lib/librarix/the_movie_db.rb @@ -16,7 +16,7 @@ module Librarix module Movie def release_date - @_release_date ||= Date.parse(super) unless super.nil? + @_release_date ||= Date.parse(super) unless super.nil? || super.empty? end def release_year diff --git a/lib/librarix/views/index.slim b/lib/librarix/views/index.slim index 22fad49..9281a63 100644 --- a/lib/librarix/views/index.slim +++ b/lib/librarix/views/index.slim @@ -2,6 +2,11 @@ form method="get" action="/" id="filter" input type="text" name="title" value="#{params['title']}" autocomplete="off" + select name="view_state" + option value="all" selected=(params['view_state'].nil? || params['view_state'] == '' || params['view_state'] == 'all') All movies + option value="viewed" selected=(params['view_state'] == 'viewed') Only viewed + option value="not_viewed" selected=(params['view_state'] == 'not_viewed') Not viewed input type="submit" value="Filter" -== slim :list, locals: {movies: movies} + +== slim :list, locals: {compact: compact, movies: movies} diff --git a/lib/librarix/views/list.slim b/lib/librarix/views/list.slim index 2062ac1..62a3787 100644 --- a/lib/librarix/views/list.slim +++ b/lib/librarix/views/list.slim @@ -1,4 +1,4 @@ ul#movies - movies.each do |movie| li - == slim :movie, locals: {movie: movie} + == slim :movie, locals: {compact: locals.key?('compact') ? compact : false, movie: movie} diff --git a/lib/librarix/views/movie.slim b/lib/librarix/views/movie.slim index 3422b15..ce6b35e 100644 --- a/lib/librarix/views/movie.slim +++ b/lib/librarix/views/movie.slim @@ -1,12 +1,13 @@ .movie data-id="#{movie.id}" .poster - if movie.poster_path - img src="#{poster_url(movie.poster_path, 'w154')}" + img src="#{poster_url(movie.poster_path, compact ? 'w92' : 'w154')}" .informations h2 a href="https://www.themoviedb.org/movie/#{movie.id}" #{movie.original_title} p = movie.release_date - p = movie.overview + - unless compact + p = movie.overview .actions - if movie.added? - unless movie.viewed?