Skip to content

Commit

Permalink
Add Bootstrap 2 framework; ReAdd simple_form and convert search form …
Browse files Browse the repository at this point in the history
…to use it; Refactor Items search into query object; Fix Book#page_urls URL generation; Add preferences model and UI
  • Loading branch information
bloopletech committed Jun 12, 2015
1 parent 3f92137 commit 2590057
Show file tree
Hide file tree
Showing 27 changed files with 551 additions and 208 deletions.
5 changes: 3 additions & 2 deletions Gemfile
Expand Up @@ -15,18 +15,19 @@ gem 'acts-as-taggable-on', '2.3.3'
gem 'carrierwave', '0.10.0'
gem 'rubyzip', '0.9.4'
gem 'sendfile', '1.2.2'
gem 'formtastic', :git => 'git://github.com/justinfrench/formtastic.git', :ref => '038357cae3fbe4ce9d64'
gem 'naturally', '>= 1.0.3', '<= 1.3.1'
gem 'haml'
gem 'simple_form'

gem 'test-unit', '~> 3.0'

group :assets do
#gem 'sass-rails', "~> 3.1.0"
#gem 'coffee-rails', "~> 3.1.0"
gem 'uglifier'
gem 'jquery-rails'
gem 'turbo-sprockets-rails3'
gem 'bootstrap-sass', '2.3.2'
gem 'sass-rails'
end

group :development, :test do
Expand Down
24 changes: 13 additions & 11 deletions Gemfile.lock
@@ -1,13 +1,3 @@
GIT
remote: git://github.com/justinfrench/formtastic.git
revision: 038357cae3fbe4ce9d648249a4c6d0b1f520a1f4
ref: 038357cae3fbe4ce9d64
specs:
formtastic (1.0.0.beta)
actionpack (>= 2.3.0)
activesupport (>= 2.3.0)
i18n (>= 0.4.0)

GIT
remote: git://github.com/rails/rails.git
revision: b344986bc3d94ca7821fc5e0eef1874882ac6cbb
Expand Down Expand Up @@ -62,6 +52,8 @@ GEM
acts-as-taggable-on (2.3.3)
rails (~> 3.0)
arel (3.0.3)
bootstrap-sass (2.3.2.0)
sass (~> 3.2)
builder (3.0.4)
byebug (5.0.0)
columnize (= 0.9.0)
Expand Down Expand Up @@ -134,6 +126,11 @@ GEM
rspec-support (~> 3.2.0)
rspec-support (3.2.2)
rubyzip (0.9.4)
sass (3.4.14)
sass-rails (3.2.6)
railties (~> 3.2.0)
sass (>= 3.1.10)
tilt (~> 1.3)
sendfile (1.2.2)
sidekiq (3.3.4)
celluloid (>= 0.16.0)
Expand All @@ -143,6 +140,9 @@ GEM
redis-namespace (>= 1.3.1)
sidekiq-failures (0.4.4)
sidekiq (>= 2.16.0)
simple_form (2.1.2)
actionpack (~> 3.0)
activemodel (~> 3.0)
sinatra (1.4.6)
rack (~> 1.4)
rack-protection (~> 1.4)
Expand Down Expand Up @@ -175,10 +175,10 @@ PLATFORMS

DEPENDENCIES
acts-as-taggable-on (= 2.3.3)
bootstrap-sass (= 2.3.2)
byebug
carrierwave (= 0.10.0)
foreman
formtastic!
haml
jquery-rails
naturally (>= 1.0.3, <= 1.3.1)
Expand All @@ -189,9 +189,11 @@ DEPENDENCIES
rmagick (= 2.15.0)
rspec-rails (~> 3.0)
rubyzip (= 0.9.4)
sass-rails
sendfile (= 1.2.2)
sidekiq
sidekiq-failures
simple_form
sinatra
test-unit (~> 3.0)
turbo-sprockets-rails3
Expand Down
1 change: 1 addition & 0 deletions app/assets/javascripts/application.js
@@ -1,5 +1,6 @@
//= require jquery
//= require jquery_ujs
//= require bootstrap
//= require utils
//= require lib/URI.js
//= require lib/featherlight.min.js
6 changes: 1 addition & 5 deletions app/assets/javascripts/index.js
Expand Up @@ -17,11 +17,7 @@ $(update_items);

$(function()
{
$(".selector li a").click(function(event) {
event.preventDefault();
});
$(".selector li").click(function(event) {
$("#" + $(this).parent().data("name")).val($(this).data("value"));
$("#search_form select").change(function(event) {
$('#search_form').submit();
});

Expand Down
8 changes: 0 additions & 8 deletions app/assets/stylesheets/application.css

This file was deleted.

10 changes: 10 additions & 0 deletions app/assets/stylesheets/application.scss
@@ -0,0 +1,10 @@
$baseFontSize: 16px;
$baseLineHeight: 22px;
$textColor: #000000;

@import "bootstrap";
@import "style";
@import "lib/featherlight.min";
@import "index";
@import "show";
@import "thumbnail_sizes";
103 changes: 103 additions & 0 deletions app/assets/stylesheets/index.scss
@@ -0,0 +1,103 @@
#items-index {
ul { margin: 0; }

#header { padding: 10px; }
#search_form {
margin-bottom: 0;
}
#actions { float: right; }

#wrapper { position: relative; background-color: #000000; }

#tag_cloud, #header { background-color: #ffffff; }
#tag_cloud { position: absolute; top: 0; right: 0; z-index: 1000; width: 500px; background-color: #ffffff; padding: 15px; }
#tag_cloud .size_1 { font-size: 1.0em; }
#tag_cloud .size_2 { font-size: 1.2em; }
#tag_cloud .size_3 { font-size: 1.4em; }
#tag_cloud .size_4 { font-size: 1.6em; }

.title { }
#items {
padding: 2px 0 0 2px;

li {
margin: 0 2px 2px 0;
float: left;
list-style-type: none;
position: relative;
overflow: hidden;

.emblems, .actions {
display: block;
position: absolute;
top: 0;
right: 0;
padding: 1px;
line-height: 0;
background-color: #ffffff;
}

.actions {
display: none;
right: auto;
left: 0;
width: 32px;
}

.wrapper {
position: relative;
}

.info-wrapper {
position: absolute;
bottom: 0;
left: 0;
right: 0;
background-color: #ffffff;
}

.info {
padding: 2px;
img {
vertical-align: middle;
}
}

&.no_results {
color: #ffffff;
width: auto;
float: none;
text-align: center;
padding: 40px 0;
}

&:hover {
.actions {
display: block;
}
}
}

.tag_list {
min-height: 1.2em;

&:hover {
background-color: #ffffaa;
}
}

input {
width: 100%;
}

.title_image {
float: left;
margin-right: 15px;
}

#info {
float: left;
width: 315px;
}
}
}
71 changes: 6 additions & 65 deletions app/assets/stylesheets/style.css
@@ -1,73 +1,14 @@
* { margin: 0; padding: 0; font: 16px/1.3em 'Open Sans', Helvetica, Arial, sans-serif; }
body { color: #000000; padding: 2px; }
* { font-family: 'Open Sans', Helvetica, Arial, sans-serif; }
body { color: #000000; }
img { border: none; vertical-align: middle; }
li { margin-left: 30px; }
p, ul { margin-bottom: 1.3em; }

.clear { clear: both; }

#header { padding: 10px; }
#search { width: 300px; border: 1px solid #a0a0a0; }
#actions { float: right; }

input[type="text"], select { padding: 1px; }
.selector { display: inline; margin-right: 20px; }
.selector li { display: inline; margin-left: 0; margin-right: 5px; }
.selector li:last-child { margin-right: 0; }
.selector li.selected a { font-weight: bold; text-decoration: none; color: #000000; }

#wrapper { position: relative; background-color: #000000; }

#tag_cloud, #header { background-color: #ffffff; }
#tag_cloud { position: absolute; top: 0; right: 0; z-index: 1000; width: 500px; background-color: #ffffff; padding: 15px; }
#tag_cloud .size_1 { font-size: 1.0em; }
#tag_cloud .size_2 { font-size: 1.2em; }
#tag_cloud .size_3 { font-size: 1.4em; }
#tag_cloud .size_4 { font-size: 1.6em; }

.title { }
#items { padding: 2px 0 0 2px; }
#items li { margin: 0 2px 2px 0; float: left; list-style-type: none; position: relative; overflow: hidden; }
#items li .emblems, #items li .actions { display: block; position: absolute; top: 0; right: 0; padding: 1px; line-height: 0; background-color: #ffffff; }
#items li .actions { display: none; right: auto; left: 0; width: 32px; }
#items li .wrapper { position: relative; }
#items li .info-wrapper {
position: absolute;
bottom: 0;
left: 0;
right: 0;
background-color: #ffffff;
}
#items li .info { padding: 2px; }
#items li .info img { vertical-align: middle; }
#items .tag_list { min-height: 1.2em; }
#items .tag_list:hover { background-color: #ffffaa; }
#items input { width: 100%; }

#items li.no_results { color: #ffffff; width: auto; float: none; text-align: center; padding: 40px 0; }
/*#items .tags form { display: none; }*/

#items li:hover .actions { display: block; }

#item .title_image { float: left; margin-right: 15px; }
#item #info { float: left; width: 315px; }

/*
#items-index body {
background-image: -webkit-gradient(
linear,
left top,
right bottom,
color-stop(0.39, rgb(0,0,0)),
color-stop(0.73, rgb(46,46,46))
);
background-image: -moz-linear-gradient(
left top,
rgb(0,0,0) 39%,
rgb(46,46,46) 73%
);
}*/

@media screen and (max-width: 844px) {
.desktop-only { display: none; }
}

.table {
width: auto;
}
58 changes: 3 additions & 55 deletions app/controllers/items_controller.rb
Expand Up @@ -2,16 +2,15 @@
raise "Wrong ActsAsTaggableOn version!" unless ActsAsTaggableOn::VERSION == "2.3.3" #Needed to ensure our joins_values hack doesn't fail silently in new versions of AATO

class ItemsController < ApplicationController
SORT_OPTIONS = [['Published', 'published_on'], ['A-Z', 'sort_key'], ['Last opened at', 'last_opened_at'], ['Date added', 'created_at'], ['Pages', 'pages'], ['Popularity', 'opens']]

def index
@items = _search_results.order(params[:sort_direction] == "RAND" ? "RANDOM()" : "#{params[:sort]} #{params[:sort_direction]}").paginate(:page => params[:page], :per_page => 100)
@query = ItemsQuery.new(params[:query])
@items = @query.results.paginate(page: params[:page], per_page: 100)

@tags = Item.tag_counts_on(:tags).order("name ASC")
end

def bulk_export
_search_results.each { |i| i.export }
ItemsQuery.new(params[:query]).results.each { |i| i.export }
end

def more_info
Expand Down Expand Up @@ -73,55 +72,4 @@ def quit
def dynamic_stylesheet
self.formats = [:css]
end

private
def _search_results
params[:sort] ||= 'published_on'
params[:sort_direction] ||= 'DESC'
if !params[:search].blank?
included_terms, excluded_terms = ActsAsTaggableOn::TagList.from(params[:search]).partition { |t| t.gsub!(/^-/, ''); $& != '-' }
included_tags = included_terms.empty? ? [] : ActsAsTaggableOn::Tag.named_any(included_terms)
excluded_tags = excluded_terms.empty? ? [] : ActsAsTaggableOn::Tag.named_any(excluded_terms)

results = Item

results = results.where("opens > 0") if included_terms.delete 's:read'
results = results.where("opens = 0") if excluded_terms.delete 's:read'
results = results.where("opens <= 3") if included_terms.delete 's:readish'
results = results.where("opens > 3") if excluded_terms.delete 's:readish'
results = results.where("opens = 0") if included_terms.delete 's:unread'
results = results.where("opens > 0") if excluded_terms.delete 's:unread'
results = results.where("page_count >= 150") if included_terms.delete 's:tank'
results = results.where("page_count < 150") if excluded_terms.delete 's:tank'
results = results.where("page_count >= 80") if included_terms.delete 's:long'
results = results.where("page_count < 80") if excluded_terms.delete 's:long'
results = results.where("page_count <= 30") if included_terms.delete 's:short'
results = results.where("page_count > 30") if excluded_terms.delete 's:short'
#results = results.where("COUNT(taggings.id) > 0") if included_tags.delete 's:tagged'

unless excluded_terms.empty?
results = results.tagged_with(excluded_tags, :exclude => true) unless excluded_tags.empty?
results = results.where(excluded_terms.map { |t| "NOT items.title LIKE #{qt t}" }.join(" AND "))
end

unless included_terms.empty?
included_terms_sql = included_terms.map { |t| "items.title LIKE #{qt t}" }.join(" AND ")
if included_tags.empty?
results = results.where(included_terms_sql)
else
results = results.tagged_with(included_tags)
results.joins_values.first.insert(0, "LEFT ")
results = results.where("tag_id NOTNULL OR (#{included_terms_sql})")
end
end

results
else
Item
end
end

def qt(term)
Item.connection.quote("%#{term}%")
end
end

0 comments on commit 2590057

Please sign in to comment.