Class: Atreides::AdminHomeController
- Inherits:
-
ApplicationController
- Object
- ApplicationController
- ApplicationController
- Atreides::AdminHomeController
- Includes:
- Extendable
- Defined in:
- app/controllers/atreides/admin_home_controller.rb
Instance Method Summary collapse
- #analytics_data ⇒ Object
- #collection ⇒ Object
- #index ⇒ Object
- #search ⇒ Object
- #setup ⇒ Object
- #setup! ⇒ Object
- #switch_site ⇒ Object
Instance Method Details
#analytics_data ⇒ Object
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 |
# File 'app/controllers/atreides/admin_home_controller.rb', line 58 def analytics_data # TODO: parameterize the dates if params[:since] @since = Date.parse(params[:since]).beginning_of_day.to_date else @since = 1.month.ago.beginning_of_day.to_date end @until = Time.now.end_of_month.beginning_of_day.to_date @until = Date.today - 1.day if @until > Date.today puts "From #{@since.to_s} to #{@until.to_s}" @report_name = report_name = params[:report].to_sym case @report_name when *google_analytics_reports.keys @report = google_analytics_reports[@report_name].update({ :start_date => @since.to_s, :end_date => @until.to_s}) @report[:results] = fetch_with_caching(30.minutes) do gs = Gattica.new({:email => Settings.ganalytics.email, :password => Settings.ganalytics.password, :profile_id => Settings.ganalytics.profile_id}) gs.get(@report) end when :tweets @tweets = Atreides::Tweet.analytics(@since) when :fb_page_views # Facebook insights API if Settings.facebook && fb_page_token && Settings.facebook.page_id # @fb_page_views = fb.get(Settings.facebook.page_id, :type => 'insights/page_views/day', :params => {:since => @since}) @fb_page_views = fetch_with_caching(5.minutes) do fb.get(Settings.facebook.page_id, :type => 'insights/page_impressions/day', :params => {:since => @since}) end end when :fb_page_likes # Facebook insights API if Settings.facebook && fb_page_token && Settings.facebook.page_id # @fb_page_likes = fb.get(Settings.facebook.page_id, :type => 'insights/page_like_adds/day', :params => {:since => @since}) @fb_page_likes = fetch_with_caching(5.minutes) do fb.get(Settings.facebook.page_id, :type => 'insights/page_fan_adds/day', :params => {:since => @since}) end end else raise RuntimeError.new "UnknownReport: #{@report_name.inspect}" end render "_#{@report_name}_analytics_tbody", :layout => nil end |
#collection ⇒ Object
25 26 27 |
# File 'app/controllers/atreides/admin_home_controller.rb', line 25 def collection nil end |
#index ⇒ Object
44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'app/controllers/atreides/admin_home_controller.rb', line 44 def index if cannot? :read, Atreides::Tweet raise CanCan::AccessDenied end @show_as_dash = true @reports = google_analytics_reports # Twitter mentions # Group by the date of the tweet @since = 1.month.ago.to_date @tweet_exposure = Atreides::Tweet.exposure(@since) @tweet_reach = Atreides::Tweet.reach(@since) end |
#search ⇒ Object
105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 |
# File 'app/controllers/atreides/admin_home_controller.rb', line 105 def search raise CanCan::AccessDenied if cannot?(:read, Atreides::Post) || cannot?(:read, Atreides::Page) @query = params[:search].to_s.strip like_q = "%#{@query}%".downcase conds = ["LOWER(state) like ? or LOWER(title) like ?", like_q, like_q] tag = Atreides::Tag.find_by_name(@query) content_part_ids = Atreides::ContentPart.where("contentable_type = 'Atreides::Post' and LOWER(body) like ?", like_q).all.map(&:contentable_id) @results = { :posts => current_site.posts. where("LOWER(state) like ? or LOWER(title) like ? or id in (?)", like_q, like_q, content_part_ids). paginate(:page => 1), :pages => current_site.pages. where("LOWER(state) like ? or LOWER(body) like ? or LOWER(title) like ?", like_q, like_q, like_q). paginate(:page => 1) } respond_to do |wants| wants.html { render :template => "atreides/admin_home/search" } end end |
#setup ⇒ Object
29 30 31 |
# File 'app/controllers/atreides/admin_home_controller.rb', line 29 def setup @user = Atreides::User.new end |
#setup! ⇒ Object
32 33 34 35 36 37 38 39 40 41 |
# File 'app/controllers/atreides/admin_home_controller.rb', line 32 def setup! @user = Atreides::User.new params[:user] @user.role = :admin if @user.save sign_in @user redirect_to :admin else render "setup" end end |
#switch_site ⇒ Object
130 131 132 133 134 135 136 137 138 |
# File 'app/controllers/atreides/admin_home_controller.rb', line 130 def switch_site # Set current-site if param matches an existing one if s = Atreides::Site.find_by_name(params[:site]) @current_site = s session[:site_name] = s.name end flash[:notice] = t('atreides.atreides.admin_home.switch_site.site_changed', :current_site => current_site.name) redirect_to request.env["HTTP_REFERER"] || admin_path end |