Skip to content

Commit

Permalink
Get Searchy
Browse files Browse the repository at this point in the history
  • Loading branch information
evenwestvang committed Mar 20, 2011
1 parent 4974e57 commit 4962fb3
Show file tree
Hide file tree
Showing 26 changed files with 583 additions and 68 deletions.
23 changes: 22 additions & 1 deletion app.rb
Expand Up @@ -19,6 +19,15 @@
haml :index
end

get '/search' do
reg = ""
q_regexp = Unicode.downcase(params["term"]).gsub(/([^a-z])/, '').each_char { |c| reg << "#{c}+.?" }
schools = School.find(:all, :limit => 100, :conditions => {:name => Regexp.new(reg, Regexp::IGNORECASE)})
schools = schools.map do |s|
{ :id => school_url(s), :text => s.name, :value => "#{s.name} - #{s.municipality.name}" }
end.to_json
end


get '/marker_info/:marker_id' do |marker_id|
content_type 'text/json', :charset => 'utf-8'
Expand Down Expand Up @@ -106,7 +115,7 @@
@page_title = "for #{@school.name}"

@has_position = false
if @school.location.length == 2
if @school.location and @school.location.length == 2
@map_options = {
:map_id => "school_map_canvas",
:ll => [@school.location[0].to_f, @school.location[1].to_f],
Expand All @@ -121,10 +130,22 @@
haml :about
end

get '/test' do
haml :test, :layout => false
end

helpers do
def id_for_object(obj)
obj.class.to_s << "_" << obj.id.to_s
end

def county_url(county)
"/skolene/#{county.link_name}"
end

def municipality_url(muni)
"/skolene/#{muni.county.link_name}/#{muni.link_name}"
end

def school_url(school)
"/skolene/#{school.county.link_name}/#{school.municipality.link_name}/#{school.link_name}"
Expand Down
6 changes: 2 additions & 4 deletions environment.rb
Expand Up @@ -5,6 +5,7 @@
require 'mongoid'
require 'haml'
require 'sass'
require 'unicode'
require './models'
require 'rack/cache'
require 'yajl/json_gem'
Expand All @@ -24,9 +25,6 @@
]
config.persist_in_safe_mode = false




# use Rack::Cache,
# :verbose => true,
# :metastore => 'memcached://localhost:11211/meta',
Expand All @@ -47,7 +45,7 @@
end

before do
cache_control :public, :max_age => 36000
cache_control :public, :max_age => 172800
end

use Rack::Cache,
Expand Down
58 changes: 30 additions & 28 deletions public/app.js
Expand Up @@ -181,14 +181,13 @@ function MarkerKeeper(map, options) {

this.updateMarkers = function(data) {
var self = this;

newDetailLevel = data.detailLevel;
if (self.detailLevel != newDetailLevel) {
this.cullAllMarkers();
if (newDetailLevel == "schools") {
$('.header_search_ui').removeClass('less_details');
$('#view_stats_container').removeClass('less_details');
} else {
$('.header_search_ui').addClass('less_details');
$('#view_stats_container').addClass('less_details');
}
self.detailLevel = newDetailLevel;
}
Expand All @@ -200,7 +199,7 @@ function MarkerKeeper(map, options) {
size = (size / 15) + 10;
}
var latlng = new google.maps.LatLng(item.lat, item.lon);
var icon_url = ButtonFactory.create(item.avg, size, self.useContrast);
var icon_url = MarkerFactory.create(item.avg, size, self.useContrast);
var image = new google.maps.MarkerImage(icon_url,
new google.maps.Size(size, size),
new google.maps.Point(0, 0),
Expand All @@ -224,7 +223,7 @@ function MarkerKeeper(map, options) {
this.markerClicked = function(map, marker) {
var self = this;
boxContent = document.createElement("div");
boxContent.style.cssText = "border: 1px solid black;margin-top: 0px; background: rgba(0,0,0,0.80); padding: 5px 10px 5px 10px; border-radius:3px; -moz-border-radius:3px; webkit-border-radius:3px; -moz-box-shadow #000 5px 5px 10px; -webkit-box-shadow #000 5px 5px 10px; box-shadow #000 5px 5px 10px;";
boxContent.style.cssText = "border: 1px solid black;margin-top: 0px; background: rgba(0,0,0,0.80); padding: 5px 10px 8px 10px; border-radius:3px; -moz-border-radius:3px; webkit-border-radius:3px; -moz-box-shadow #000 5px 5px 10px; -webkit-box-shadow #000 5px 5px 10px; box-shadow #000 5px 5px 10px;";

$.getJSON('/marker_info/' + marker.ident, function(data, textStatus) {
data.school_url = encodeURI(data.school_url);
Expand All @@ -239,7 +238,7 @@ function MarkerKeeper(map, options) {
averageDataPoint = {
x: annual_result.year,
y: annual_result.result_average,
color: ButtonFactory.getColor(annual_result.result_average, self.useContrast)
color: MarkerFactory.getColor(annual_result.result_average, self.useContrast, 10)
}
averageSerie.data.push(averageDataPoint);

Expand Down Expand Up @@ -273,17 +272,16 @@ function MarkerKeeper(map, options) {
chart = new Highcharts.Chart(resultChartOptions);

if (data.school_url !== undefined) {
var like = '<fb:like href="'+data.school_url+'" width="400" height="20" show_faces="false" layout="standard" action="recommend" colorscheme="light"/>'
var insert = infoBox.children().last()
insert.append(like);
FB.XFBML.parse(insert[0]);
}
setTimeout(function() {
var like = '<fb:like href="'+data.school_url+'" width="400" height="20" show_faces="false" layout="standard" action="recommend" colorscheme="dark"/>'
var insert = infoBox.children().last()
insert.append(like);
FB.XFBML.parse(insert[0]);
}, 1500)};
}

var schoolPosition = new google.maps.LatLng(data.location[0],data.location[1]);

self.map.panTo(schoolPosition);

if (self.options.fullscreen) {
self.map.panBy(320, 150);
} else {
Expand Down Expand Up @@ -355,35 +353,38 @@ function MarkerKeeper(map, options) {
}



var ButtonFactory = (function() {
var MarkerFactory = (function() {
return new function() {

var h = 1;
var s = 100;
var l = 45;
var a = 0.75;

this.getColor = function(val, useContrast) {
this.getColor = function(val, useContrast, gamma) {
if (!useContrast) {
return "hsla(" + this.sCurveColor(val) +"," + s + "%," + l +"%," + a +")";
return "hsla(" + this.sCurveColor(val, gamma) +"," + s + "%," + l +"%," + a +")";
} else {
return "hsla(" + 0 +"," + 0 + "%," + this.sBrightness(val) +"%," + 1 +")";
}
};

this.getColor1 = function(val, useContrast) {
this.getColor1 = function(val, useContrast, gamma) {
if (!useContrast) {
return "hsla(" + this.sCurveColor(val) +"," + s + "%," + (l*0.75) +"%," + a +")";
return "hsla(" + this.sCurveColor(val, gamma) +"," + s + "%," + (l*0.75) +"%," + a +")";
} else {
return "hsla(" + 0 +"," + 0 + "%," + this.sBrightness(val)*0.25 +"%," + 1 +")";
}
};

this.sCurveColor = function(t) {
t = t - 0.5;
var log_curve = (1 / (1 + Math.pow(Math.E,-t))) - 0.5;
var color_val = 40 + (log_curve * 700);
this.sCurveColor = function(val, gamma) {
val -= 0.5;
// var log_curve = (1 / (1 + Math.pow(Math.E,-(t*3))));
// var color_val = -30 + (log_curve * 180);

var log_curve = (1 / (1 + Math.pow(Math.E,-(val*gamma))));
var color_val = -00 + (log_curve * 90);

return color_val;
};

Expand Down Expand Up @@ -412,7 +413,7 @@ var ButtonFactory = (function() {
context.closePath();
};

this.createCanvas = function(t, size, useContrast) {
this.createCanvas = function(t, size, useContrast, gamma) {
var canvas = document.createElement("canvas");
canvas.width = size;
canvas.height = size;
Expand All @@ -421,8 +422,8 @@ var ButtonFactory = (function() {
var boxStroke;
var colorVal;
if(t !== 0 && t !== undefined && t != null) {
color0 = this.getColor(t, useContrast);
boxStroke = this.getColor1(t, useContrast);
color0 = this.getColor(t, useContrast, gamma);
boxStroke = this.getColor1(t, useContrast, gamma);
} else {
color0 = "Silver";
boxStroke = "rgba(100,100,100,1)";
Expand All @@ -436,8 +437,9 @@ var ButtonFactory = (function() {
return canvas;
};

this.create = function(label, range, useContrast) {
var canvas = this.createCanvas(label, range, useContrast);
this.create = function(label, size, useContrast, gamma) {
gamma = gamma || 10
var canvas = this.createCanvas(label, size, useContrast, gamma);
return canvas.toDataURL();
};
}();
Expand Down
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/images/ui-bg_flat_10_000000_40x100.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/images/ui-bg_glass_100_f6f6f6_1x400.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/images/ui-bg_glass_100_fdf5ce_1x400.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/images/ui-bg_glass_65_ffffff_1x400.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/images/ui-icons_222222_256x240.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/images/ui-icons_228ef1_256x240.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/images/ui-icons_ef8c08_256x240.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/images/ui-icons_ffd27a_256x240.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/images/ui-icons_ffffff_256x240.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 4962fb3

Please sign in to comment.