Skip to content

Commit

Permalink
Added the subjects (SAB) tree
Browse files Browse the repository at this point in the history
  • Loading branch information
peterhellberg committed May 10, 2010
1 parent 0b7d647 commit b45cf7c
Show file tree
Hide file tree
Showing 5 changed files with 92 additions and 28 deletions.
18 changes: 18 additions & 0 deletions app.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ class Search
require 'enumerator'
require 'lib/ur_helpers'
require 'ur-product'
require 'ur-sab'

# Application

Expand All @@ -20,13 +21,29 @@ class Search
if !product.nil?
haml :show, :locals => {
:page_title => "UR Produktsök — #{product.title}",
:body_class => 'product',
:product => product
}
else
redirect '/'
end
end

get '/subjects' do
sab_search = UR::SabSearch.new(params[:sab_code])

if sab_search.subjects.count == 1
redirect facet_link('sab_subjects', sab_search.subjects.first.code)
end

haml :subjects, :locals => {
:page_title => 'Navigera i trädstrukturen – UR Produktsök',
:body_class => 'subjects',
:selected_sab => sab_search.sab,
:subjects => sab_search.subjects
}
end

get '/' do
current_page = 1
search_params = { :per_page => 10 }
Expand All @@ -53,6 +70,7 @@ class Search
:current_page => current_page,
:search => search_result,
:tag_cloud => tag_cloud,
:body_class => 'search',
:facet_order => [
['search_product_type', 'Typ'],
['typicalagerange', 'Målgrupp'],
Expand Down
5 changes: 3 additions & 2 deletions lib/ur_helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,15 @@ def facet_filter(name, facet)

def facet_link(name, facet)
link = base_link
value = (facet.respond_to?('value')) ? facet.value : facet

if link.match(/fq=/)
link = link.gsub(/ao:\"[^\"]+?\"/, '') if name == 'ao'
link = link.gsub('fq=', "fq=#{name}:\"#{facet.value}\" ").
link = link.gsub('fq=', "fq=#{name}:\"#{value}\" ").
gsub(/page\=\d+/, "page=1").sub(' &', '&').gsub(' ', ' ')
else
link += '&' if link != '/?'
link = "#{link}fq=#{name}:\"#{facet.value}\"".gsub(/page\=\d+/, "page=1")
link = "#{link}fq=#{name}:\"#{value}\"".gsub(/page\=\d+/, "page=1").gsub(/sab_code\=.+?&/, '')
end

link
Expand Down
33 changes: 17 additions & 16 deletions views/index.haml
Original file line number Diff line number Diff line change
@@ -1,19 +1,24 @@
%div.container-12.clearfix
%div.grid-6
%div.grid-8
%h1
%a{ :href => '/' }='UR Produktsök'
%div.grid-6
%form#search{ :action => '/', :method => 'get' }
- if !search.nil? && search.ok? && should_show_results?
%div.num_found
= "Antal träffar"
%strong=search.num_found
%input{ :type => 'text', :name => 'q', :autofocus => 'true', :value => params[:q] }
%input.button{ :type => 'submit', :value => 'Sök' }
%div.grid-4
%ul.nav
%li
%a.active{ :href => '/' }="Sök"
%li
%a{ :href => '/subjects' }="Bläddra ämnesvis"
- if !search.nil? && search.ok? && search.num_found > 0
%div.grid-8
- if should_show_results?
%div.products.clearfix
%div.products.clearfix
%form#search{ :action => '/', :method => 'get' }
%input{ :type => 'text', :name => 'q', :autofocus => 'true', :value => params[:q] }
%input.button{ :type => 'submit', :value => 'Sök' }
- if !search.nil? && search.ok? && should_show_results?
%div.num_found
= "Antal träffar"
%strong=search.num_found
- if should_show_results?
- search.products.each do |product|
%div.product.clearfix
%div.grid-2.alpha
Expand All @@ -28,11 +33,7 @@
- if search.next_page > current_page
%div.next_page
%a{ :href => next_page_link(search.next_page) }
="Nästa sida →"
- else
%div.products
%div.no_products
%h2= "Välkommen till produktsöket"
="Nästa sida →"
%div.grid-4
%div.sidebar
%h3
Expand Down
2 changes: 1 addition & 1 deletion views/layout.haml
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@
%script{ :src => "/javascripts/jquery.auto-complete.min.js" }
%script{ :src => "/javascripts/application.js" }
%title= page_title
%body
%body{ :class => body_class }
%div.content= yield
62 changes: 53 additions & 9 deletions views/style.sass
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ a

h1
font-size: 3em
margin-top: 0
margin: 0 0 0.2em 0
+shadowed-text(0, 2px, 3px, #fff)

a
Expand All @@ -68,8 +68,10 @@ h2, h3
padding-top: 0

ul
list-style: none
margin: 0

li
list-style: none

body
background-color: #ddd
Expand Down Expand Up @@ -98,7 +100,7 @@ body

div.main_content, div.sidebar
background-color: #fff
+round-corners(10px)
+round-corners(8px)
padding: 1.5em

div.main_content
Expand All @@ -116,7 +118,7 @@ body

div.products
background-color: #fff
+round-corners(10px)
+round-corners(8px)
&:first-child
padding-top: 1em
&:last-child
Expand Down Expand Up @@ -152,8 +154,7 @@ body
padding: 1em 0.2em 0
/* Search form */
#search
margin-top: 0.8em
text-align: right
margin: 0 0 1.5em 1em

input
vertical-align: middle
Expand All @@ -170,14 +171,18 @@ body

div.num_found
vertical-align: middle
display: inline
padding: 0.8em 1em
color= !ur_gray
margin: 0.4em 0 1em 0

strong
color= !ur_dark_gray

.dimmed
color= !ur_gray

.small
font-size: x-small

.hidden
display: none

Expand Down Expand Up @@ -224,4 +229,43 @@ ul.auto-complete-list
background-color= !ur_pink
color: #fff
.auto-complete-striped
background-color: #D7EEF9
background-color: #D7EEF9

/* Navigation */
ul.nav
float: right
margin-top: 1em
margin-bottom: 0

ul.nav li
float: left
padding-left: 2em

ul.nav a
color= !ur_dark_gray
font-size: 1.8em

ul.nav a.active
border-bottom= 5px "solid" !ur_pink

/* Subjects (SAB codes) */
ul.sab_codes
margin-top: 1em

li
strong
display: block
float: left
margin-right: 10px
padding: 0 5px
width: 40px

span
a
color= !ur_dark_gray

li.selected
font-size: 1.5em
margin-bottom: 0


0 comments on commit b45cf7c

Please sign in to comment.