Add view_state filter and compact view
parent
6e0eab0c74
commit
50694cc25a
|
@ -23,7 +23,10 @@ module Librarix
|
||||||
helpers Librarix::Menu::Helper
|
helpers Librarix::Menu::Helper
|
||||||
|
|
||||||
get '/' do
|
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
|
end
|
||||||
|
|
||||||
get '/search' do
|
get '/search' do
|
||||||
|
|
|
@ -12,6 +12,7 @@ module Librarix
|
||||||
def filter
|
def filter
|
||||||
@movies = Librarix::Redis::Movie.all
|
@movies = Librarix::Redis::Movie.all
|
||||||
by_title if @params.key?('title')
|
by_title if @params.key?('title')
|
||||||
|
by_view_state if @params.key?('view_state')
|
||||||
|
|
||||||
@movies.sort_by!(&:release_date).reverse!
|
@movies.sort_by!(&:release_date).reverse!
|
||||||
end
|
end
|
||||||
|
@ -19,5 +20,13 @@ module Librarix
|
||||||
def by_title
|
def by_title
|
||||||
movies.select! { |movie| movie.title.downcase.include?(params['title']) }
|
movies.select! { |movie| movie.title.downcase.include?(params['title']) }
|
||||||
end
|
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
|
||||||
end
|
end
|
||||||
|
|
|
@ -16,7 +16,7 @@ module Librarix
|
||||||
|
|
||||||
module Movie
|
module Movie
|
||||||
def release_date
|
def release_date
|
||||||
@_release_date ||= Date.parse(super) unless super.nil?
|
@_release_date ||= Date.parse(super) unless super.nil? || super.empty?
|
||||||
end
|
end
|
||||||
|
|
||||||
def release_year
|
def release_year
|
||||||
|
|
|
@ -2,6 +2,11 @@
|
||||||
|
|
||||||
form method="get" action="/" id="filter"
|
form method="get" action="/" id="filter"
|
||||||
input type="text" name="title" value="#{params['title']}" autocomplete="off"
|
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"
|
input type="submit" value="Filter"
|
||||||
|
|
||||||
== slim :list, locals: {movies: movies}
|
|
||||||
|
== slim :list, locals: {compact: compact, movies: movies}
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
ul#movies
|
ul#movies
|
||||||
- movies.each do |movie|
|
- movies.each do |movie|
|
||||||
li
|
li
|
||||||
== slim :movie, locals: {movie: movie}
|
== slim :movie, locals: {compact: locals.key?('compact') ? compact : false, movie: movie}
|
||||||
|
|
|
@ -1,12 +1,13 @@
|
||||||
.movie data-id="#{movie.id}"
|
.movie data-id="#{movie.id}"
|
||||||
.poster
|
.poster
|
||||||
- if movie.poster_path
|
- if movie.poster_path
|
||||||
img src="#{poster_url(movie.poster_path, 'w154')}"
|
img src="#{poster_url(movie.poster_path, compact ? 'w92' : 'w154')}"
|
||||||
.informations
|
.informations
|
||||||
h2
|
h2
|
||||||
a href="https://www.themoviedb.org/movie/#{movie.id}" #{movie.original_title}
|
a href="https://www.themoviedb.org/movie/#{movie.id}" #{movie.original_title}
|
||||||
p = movie.release_date
|
p = movie.release_date
|
||||||
p = movie.overview
|
- unless compact
|
||||||
|
p = movie.overview
|
||||||
.actions
|
.actions
|
||||||
- if movie.added?
|
- if movie.added?
|
||||||
- unless movie.viewed?
|
- unless movie.viewed?
|
||||||
|
|
Loading…
Reference in New Issue