Add view_state filter and compact view

master
Guillaume Dott 2015-11-06 12:51:08 +01:00
parent 6e0eab0c74
commit 50694cc25a
6 changed files with 24 additions and 6 deletions

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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}

View File

@ -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}

View File

@ -1,11 +1,12 @@
.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
- unless compact
p = movie.overview p = movie.overview
.actions .actions
- if movie.added? - if movie.added?