Add view_state filter and compact view
parent
6e0eab0c74
commit
50694cc25a
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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}
|
||||
|
|
|
@ -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}
|
||||
|
|
|
@ -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?
|
||||
|
|
Loading…
Reference in New Issue