Add better support for compact view

master
Guillaume Dott 2015-11-12 12:33:22 +01:00
parent f803a6adfb
commit 0535253c91
5 changed files with 24 additions and 14 deletions

View File

@ -1,6 +1,7 @@
require 'librarix/filter' require 'librarix/filter'
require 'librarix/menu' require 'librarix/menu'
require 'librarix/the_movie_db' require 'librarix/the_movie_db'
require 'librarix/helpers'
require 'sinatra/base' require 'sinatra/base'
require 'sinatra/content_for' require 'sinatra/content_for'
@ -21,12 +22,10 @@ module Librarix
helpers Librarix::TheMovieDB helpers Librarix::TheMovieDB
helpers Librarix::Menu::Helper helpers Librarix::Menu::Helper
helpers Librarix::Helpers
get '/' do get '/' do
slim :index, locals: { slim :index, locals: {movies: Librarix::Filter.new(params).movies}
compact: params.key?('compact'),
movies: Librarix::Filter.new(params).movies
}
end end
get '/search' do get '/search' do

View File

@ -0,0 +1,7 @@
module Librarix
module Helpers
def compact?
params.key?('compact')
end
end
end

View File

@ -1,12 +1,16 @@
- content_for(:title) { 'Index' } - content_for(:title) { 'Index' }
form method="get" action="/" id="filter" form method="get" action="/" id="filter"
input type="text" name="title" value="#{params['title']}" autocomplete="off" div id="search-main"
select name="view_state" input type="text" name="title" value="#{params['title']}" autocomplete="off"
option value="all" selected=(params['view_state'].nil? || params['view_state'] == '' || params['view_state'] == 'all') All movies input type="submit" value="Filter"
option value="viewed" selected=(params['view_state'] == 'viewed') Only viewed div id="search-more"
option value="not_viewed" selected=(params['view_state'] == 'not_viewed') Not viewed select name="view_state"
input type="submit" value="Filter" 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="checkbox" name="compact" id="compact" checked=(params['compact'])
label for="compact" Compact view
== slim :list, locals: {compact: compact, movies: movies} == slim :list, locals: {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: {compact: locals.key?('compact') ? compact : false, movie: movie} == slim :movie, locals: {movie: movie}

View File

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