diff --git a/.gitignore b/.gitignore index c58b054..d990b41 100755 --- a/.gitignore +++ b/.gitignore @@ -7,4 +7,5 @@ .DS_Store /public/data *.png -coverage \ No newline at end of file +coverage +.tags diff --git a/app/assets/javascripts/application.js b/app/assets/javascripts/application.js index 653be27..283ba09 100755 --- a/app/assets/javascripts/application.js +++ b/app/assets/javascripts/application.js @@ -40,8 +40,36 @@ $("pre.ruby").snippet("ruby",{style:"rand01",transparent:true,showNum:true}); // with a transparent background // without showing line numbers. + + +$("pre.javascript").snippet("javascript",{style:"rand01",transparent:true,showNum:true}); + // Finds
elements with the class "js"
+ // and snippet highlights the JAVASCRIPT code within
+ // using a random style from the selection of 39
+ // with a transparent background
+ // without showing line numbers.
+
};
+var rAmp = /&/g,
+ rLt = //g,
+ rApos = /\'/g,
+ rQuot = /\"/g,
+ hChars = /[&<>\"\']/;
+
+function hoganEscape(str) {
+ str = coerceToString(str);
+ return hChars.test(str) ?
+ str
+ .replace(rAmp, '&')
+ .replace(rLt, '<')
+ .replace(rGt, '>')
+ .replace(rApos, ''')
+ .replace(rQuot, '"') :
+ str;
+ }
+
$(document).ready(function(){
rubyCodeFormat()
});
diff --git a/app/controllers/admin_controller.rb b/app/controllers/admin_controller.rb
index d7efbdb..4cde79f 100755
--- a/app/controllers/admin_controller.rb
+++ b/app/controllers/admin_controller.rb
@@ -5,7 +5,24 @@ class AdminController < ApplicationController
def dashboard
end
-
+
+ def analytics
+ if params[:field].nil?
+ fields = "*"
+ else
+ fields = params[:field].map {|k,v| k }.join(",")
+ # This seems to be a bit safer
+ #fields = params[:field].map {|k,v| Analytics.parse_field(k) }.join(",")
+ end
+
+ if params[:ip]
+ @analytics = Analytics.hits_by_ip(params[:ip], fields)
+ else
+ @analytics = Analytics.all
+ end
+ render "layouts/admin/_analytics"
+ end
+
def get_all_users
@users = User.all
render :partial => "layouts/admin/get_all_users"
diff --git a/app/controllers/api/v1/mobile_controller.rb b/app/controllers/api/v1/mobile_controller.rb
new file mode 100644
index 0000000..63a575d
--- /dev/null
+++ b/app/controllers/api/v1/mobile_controller.rb
@@ -0,0 +1,34 @@
+class Api::V1::MobileController < ApplicationController
+
+ skip_before_filter :authenticated
+ before_filter :mobile_request?
+
+ respond_to :json
+
+ def show
+ if params[:class]
+ model = params[:class].classify.constantize
+ respond_with model.find(params[:id]).to_json
+ end
+ end
+
+ def index
+ if params[:class]
+ model = params[:class].classify.constantize
+ respond_with model.all.to_json
+ else
+ respond_with nil.to_json
+ end
+ end
+
+ private
+
+ def mobile_request?
+ if session[:mobile_param]
+ session[:mobile_param] == "1"
+ else
+ request.user_agent =~ /ios|android/i
+ end
+ end
+
+end
diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb
index 56ad260..3e56186 100755
--- a/app/controllers/application_controller.rb
+++ b/app/controllers/application_controller.rb
@@ -1,7 +1,7 @@
class ApplicationController < ActionController::Base
- before_filter :authenticated, :has_info
- helper_method :current_user, :is_admin?
+ before_filter :authenticated, :has_info, :create_analytic
+ helper_method :current_user, :is_admin?, :sanitize_font
# Our security guy keep talking about sea-surfing, cool story bro.
# protect_from_forgery
@@ -45,4 +45,13 @@ class ApplicationController < ActionController::Base
redirect_to home_dashboard_index_path if redirect
end
+ def create_analytic
+ Analytics.create({ :ip_address => request.remote_ip, :referrer => request.referrer, :user_agent => request.user_agent})
+ end
+
+ def sanitize_font(css)
+ css
+ # css if css.match(/\A[0-9]+([\%]|pt)\z/)
+ end
+
end
diff --git a/app/controllers/benefit_forms_controller.rb b/app/controllers/benefit_forms_controller.rb
index a74befb..64b851e 100644
--- a/app/controllers/benefit_forms_controller.rb
+++ b/app/controllers/benefit_forms_controller.rb
@@ -7,7 +7,7 @@ class BenefitFormsController < ApplicationController
def download
begin
- path = Rails.root.join('public', 'docs', params[:name])
+ path = params[:name]
file = params[:type].constantize.new(path)
send_file file, :disposition => 'attachment'
rescue
diff --git a/app/controllers/dashboard_controller.rb b/app/controllers/dashboard_controller.rb
index 593abe4..41d4236 100755
--- a/app/controllers/dashboard_controller.rb
+++ b/app/controllers/dashboard_controller.rb
@@ -4,6 +4,11 @@ class DashboardController < ApplicationController
def home
@user = current_user
+
+ # See if the user has a font preference
+ if params[:font]
+ cookies[:font] = params[:font]
+ end
end
end
diff --git a/app/models/analytics.rb b/app/models/analytics.rb
new file mode 100644
index 0000000..6690504
--- /dev/null
+++ b/app/models/analytics.rb
@@ -0,0 +1,19 @@
+class Analytics < ActiveRecord::Base
+ attr_accessible :ip_address, :referrer, :user_agent
+
+ scope :hits_by_ip, ->(ip,col="*") { select("#{col}").where(:ip_address => ip).order("id DESC")}
+
+ def self.count_by_col(col)
+ calculate(:count, col)
+ end
+
+ def self.parse_field(field)
+ valid_fields = ["ip_address", "referrer", "user_agent"]
+
+ if valid_fields.include?(field)
+ field
+ else
+ "1"
+ end
+ end
+end
diff --git a/app/models/message.rb b/app/models/message.rb
index 7894ae9..12aaaba 100644
--- a/app/models/message.rb
+++ b/app/models/message.rb
@@ -4,7 +4,10 @@ class Message < ActiveRecord::Base
validates_presence_of :creator_id, :receiver_id, :message
def creator_name
- creator = User.where(:id => self.creator_id).first
- creator.full_name
+ if creator = User.where(:user_id => self.creator_id).first
+ creator.full_name
+ else
+ "Name unavailable".html_safe
+ end
end
-end
\ No newline at end of file
+end
diff --git a/app/views/benefit_forms/index.html.erb b/app/views/benefit_forms/index.html.erb
index 3299355..3c48e5c 100644
--- a/app/views/benefit_forms/index.html.erb
+++ b/app/views/benefit_forms/index.html.erb
@@ -13,7 +13,7 @@