Class: Platform::AppsController
- Inherits:
-
BaseController
- Object
- ApplicationController
- BaseController
- Platform::AppsController
- Defined in:
- app/controllers/platform/apps_controller.rb
Overview
– Copyright © 2011 Michael Berkovich
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ++
Instance Method Summary collapse
- #featured_applications_module_content ⇒ Object
- #index ⇒ Object
- #paginate_module ⇒ Object
- #remove ⇒ Object
- #run ⇒ Object
- #settings ⇒ Object
- #view ⇒ Object
- #xd ⇒ Object
Methods inherited from BaseController
#mobile_device?, #platform_current_developer, #platform_current_user, #platform_current_user_is_admin?, #platform_current_user_is_developer?, #platform_current_user_is_guest?
Instance Method Details
#featured_applications_module_content ⇒ Object
87 88 89 90 |
# File 'app/controllers/platform/apps_controller.rb', line 87 def featured_applications_module_content @apps = Platform::Application.all render :layout => false end |
#index ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'app/controllers/platform/apps_controller.rb', line 26 def index unless Platform::Config.enable_app_directory? return redirect_to(:controller=>"/platform/developer/apps", :action=>"index") end @categories = Platform::Category.root.children @category = Platform::Category.find(params[:cat_id]) if params[:cat_id] @category = @categories.first unless @category @featured_apps = [] @apps = [] @search_apps = [] if params[:search].blank? @featured_apps = Platform::Application.featured_for_category(@category, page, Platform::Config.featured_apps_per_page) @apps = Platform::Application.regular_for_category(@category, page, Platform::Config.suggested_apps_per_page) else @category = nil conditions = [] @search_apps = Platform::Application.where("name like ? or description like ?", "%#{params[:search]}%", "%#{params[:search]}%").page(page).per(Platform::Config.searched_apps_per_page).order("name asc") end end |
#paginate_module ⇒ Object
71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 |
# File 'app/controllers/platform/apps_controller.rb', line 71 def paginate_module if params[:module] == 'featured_apps' category = Platform::Category.find(params[:cat_id]) apps = Platform::Application.featured_for_category(category, page, Platform::Config.featured_apps_per_page) render(:partial => 'featured_apps_module', :locals => {:apps => apps, :per_row => Platform::Config.featured_apps_per_row}) elsif params[:module] == 'suggested_apps' category = Platform::Category.find(params[:cat_id]) apps = Platform::Application.regular_for_category(category, page, Platform::Config.suggested_apps_per_page) render(:partial => 'apps_module', :locals => {:apps => apps, :per_row => Platform::Config.suggested_apps_per_row}) else conditions = ["name like ? or description like ?", "%#{params[:search]}%", "%#{params[:search]}%"] apps = Platform::Application.where(conditions).page(page).per(Platform::Config.searched_apps_per_page).order("name asc") render(:partial => 'search_apps_module', :locals => {:apps => apps}) end end |
#remove ⇒ Object
100 101 102 103 104 105 106 107 108 109 110 |
# File 'app/controllers/platform/apps_controller.rb', line 100 def remove if request.post? app_user = Platform::ApplicationUser.find_by_id(params[:app_user_id]) if app_user app_user.destroy trfn("{app} has been removed from your account and will no longer have access to your account information.", "", :app => app_user.application.name) end end redirect_to :action => :settings end |
#run ⇒ Object
112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 |
# File 'app/controllers/platform/apps_controller.rb', line 112 def run @app = Platform::Application.find_by_canvas_name(params[:canvas_name]) return render(:action => :canvas_app) unless @app @page_title = @app.name if @app.auto_signin? app_user = Platform::ApplicationUser.for(@app) unless app_user @canvas_url = "http://#{Platform::Config.site_base_url}/platform/oauth/authorize?response_type=token&client_id=#{@app.key}&display=iframe&redirect_url=#{CGI.escape(@app.canvas_url)}" return render(:action => :canvas_app) end tokens = @app.valid_tokens_for_user(Platform::Config.current_user) if tokens access_token = tokens.first else access_token = client_application.create_access_token(:user=>Platform::Config.current_user) end @access_token = access_token end @canvas_url = @app.canvas_url canvas_uri = URI.parse(@app.canvas_url) [:controller, :action].each do |key| params.delete(key) end # add all desired params here params[:access_token] = @access_token.token if @access_token params[:t] = Time.now.to_s query_params = [] params.each do |key, val| query_params << "#{key}=#{CGI.escape(val)}" end @canvas_url << "/" if canvas_uri.path.blank? @canvas_url << (canvas_uri.query.blank? ? "?" : "&") @canvas_url << query_params.join('&') render :action => :canvas_app end |
#settings ⇒ Object
96 97 98 |
# File 'app/controllers/platform/apps_controller.rb', line 96 def settings @app_users = Platform::ApplicationUser.where("user_id = ?", current_user.id).order("updated_at desc") end |
#view ⇒ Object
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'app/controllers/platform/apps_controller.rb', line 49 def view @app = Platform::Application.find(params[:id]) @sections = ["Info", "Reviews", "Discussions"] @section = params[:sec] || "Info" @ratings = Platform::Rating.where("object_type = ? and object_id = ?", @app.class.name, @app.id).order("updated_at desc").page(page).per(per_page) params[:sec] ||= 'Info' if params[:sec] == 'Discussions' if params[:topic_id] @topic = Platform::ForumTopic.find_by_id(params[:topic_id]) if params[:last_page] params[:page] = (@topic.post_count / per_page.to_i) params[:page] += 1 unless (@topic.post_count % per_page.to_i == 0) params[:page] = 1 if params[:page] == 0 end @messages = Platform::ForumMessage.where("forum_topic_id = ?", @topic.id).order("created_at asc").page(page).per(per_page) else @topics = Platform::ForumTopic.where("subject_type = ? and subject_id = ?", @app.class.name, @app.id).order("created_at asc").page(page).per(per_page) end end end |
#xd ⇒ Object
92 93 94 |
# File 'app/controllers/platform/apps_controller.rb', line 92 def xd render :layout => false end |