API for Locations
This commit is contained in:
parent
6040e63034
commit
c545c6f172
|
@ -23,6 +23,13 @@ class ApplicationController < ActionController::Base
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def check_mobile_api_openness
|
||||||
|
if !Site.first.mobile_api_openness_on
|
||||||
|
redirect_to '/users/sign_in' if not (authenticate_user! and is_member? )
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
def site_restart
|
def site_restart
|
||||||
Resque.enqueue(RestartServer)
|
Resque.enqueue(RestartServer)
|
||||||
end
|
end
|
||||||
|
|
|
@ -14,6 +14,7 @@ class Site
|
||||||
|
|
||||||
field :frontend_open, :type => Boolean, :default => true
|
field :frontend_open, :type => Boolean, :default => true
|
||||||
field :backend_openness_on, :type => Boolean, :default => false
|
field :backend_openness_on, :type => Boolean, :default => false
|
||||||
|
field :mobile_api_openness_on, :type => Boolean, :default => false
|
||||||
field :desktop_closed, :type => Boolean, :default => false
|
field :desktop_closed, :type => Boolean, :default => false
|
||||||
field :sitemap_menu_in_header, :type => Boolean, :default => false
|
field :sitemap_menu_in_header, :type => Boolean, :default => false
|
||||||
field :enable_terms_of_use, :type => Boolean, :default => false
|
field :enable_terms_of_use, :type => Boolean, :default => false
|
||||||
|
|
|
@ -131,6 +131,13 @@
|
||||||
<%= f.check_box :desktop_closed , :class=>"toggle-check", :data=> { disabled: true } %>
|
<%= f.check_box :desktop_closed , :class=>"toggle-check", :data=> { disabled: true } %>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
<div class="control-group">
|
||||||
|
<label class="control-label muted"><%= I18n.t('site.mobile_api_openness_on') %></label>
|
||||||
|
<div class="controls">
|
||||||
|
<%= f.check_box :mobile_api_openness_on , :class=>"toggle-check", :data=> { disabled: true } %>
|
||||||
|
<span class="help-block">API Is available for Mobile Apps</span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
|
@ -386,6 +386,7 @@ en:
|
||||||
thumbnail: Thumbnail
|
thumbnail: Thumbnail
|
||||||
site:
|
site:
|
||||||
backend_openness_on: Backend Openness
|
backend_openness_on: Backend Openness
|
||||||
|
mobile_api_openness_on: Mobile API Openness
|
||||||
default_image: Site default image
|
default_image: Site default image
|
||||||
description: Site description
|
description: Site description
|
||||||
description_help: Description Guide
|
description_help: Description Guide
|
||||||
|
|
|
@ -389,6 +389,7 @@ zh_tw:
|
||||||
frontend_closed: 前台關閉?
|
frontend_closed: 前台關閉?
|
||||||
frontend_open: 開啟前台
|
frontend_open: 開啟前台
|
||||||
backend_openness_on: 開啟開放式後台(訪客可遊覽)
|
backend_openness_on: 開啟開放式後台(訪客可遊覽)
|
||||||
|
mobile_api_openness_on: 開啟手機API
|
||||||
enable_personal_desktop: 開啟個人桌面
|
enable_personal_desktop: 開啟個人桌面
|
||||||
default_image: 預設圖像
|
default_image: 預設圖像
|
||||||
description: 網站描述
|
description: 網站描述
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
class Panel::Location::BackEnd::LocationsController < OrbitBackendController
|
class Panel::Location::BackEnd::LocationsController < OrbitBackendController
|
||||||
include AdminHelper
|
include AdminHelper
|
||||||
|
open_for_visitor :only => [:get_location_categories, :get_categorywise_locations]
|
||||||
|
|
||||||
def index
|
def index
|
||||||
@locations = LocationInfo.all
|
@locations = LocationInfo.all
|
||||||
|
@ -89,4 +90,43 @@ class Panel::Location::BackEnd::LocationsController < OrbitBackendController
|
||||||
|
|
||||||
render :json => JSON.pretty_generate(@data)
|
render :json => JSON.pretty_generate(@data)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def get_location_categories
|
||||||
|
check_mobile_api_openness
|
||||||
|
location_categories = get_categories_for_index
|
||||||
|
@data = Array.new
|
||||||
|
|
||||||
|
location_categories.each do |category|
|
||||||
|
I18n.locale = :en
|
||||||
|
name_en = category.title
|
||||||
|
I18n.locale = :zh_tw
|
||||||
|
name_zh_tw = category.title
|
||||||
|
category_id = category.id.to_s
|
||||||
|
@data << { name_en: name_en, name_zh_tw: name_zh_tw, category_id: category_id, location_link: "http://#{request.host_with_port}"+"/#{panel_location_back_end_locations_get_categorywise_locations_path}"+"?category_id=#{category_id}"}
|
||||||
|
end
|
||||||
|
|
||||||
|
render :json => JSON.pretty_generate(@data)
|
||||||
|
end
|
||||||
|
|
||||||
|
def get_categorywise_locations
|
||||||
|
check_mobile_api_openness
|
||||||
|
location_infos = LocationInfo.where(:category_id => params[:category_id])
|
||||||
|
@data = Array.new
|
||||||
|
|
||||||
|
location_infos.each do |location|
|
||||||
|
|
||||||
|
picurl = location.file.blank? ? '' : "http://#{request.host_with_port + location.file.url}"
|
||||||
|
thumburl = location.file.blank? ? '' : "http://#{request.host_with_port + location.file.thumb.url}"
|
||||||
|
|
||||||
|
@data << { id: location.id.to_s,
|
||||||
|
name: location.name,
|
||||||
|
pic_url: picurl,
|
||||||
|
thumb_url: thumburl,
|
||||||
|
longitude: location.longitude,
|
||||||
|
latitude: location.latitude,
|
||||||
|
description: location.description }
|
||||||
|
end
|
||||||
|
|
||||||
|
render :json => JSON.pretty_generate(@data)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -3,6 +3,9 @@ Rails.application.routes.draw do
|
||||||
namespace :location do
|
namespace :location do
|
||||||
namespace :back_end do
|
namespace :back_end do
|
||||||
match 'location_categories/list' => "location_categories#list"
|
match 'location_categories/list' => "location_categories#list"
|
||||||
|
match "locations/get_locations" => "locations#get_locations"
|
||||||
|
match "locations/get_categorywise_locations" => "locations#get_categorywise_locations"
|
||||||
|
match "locations/get_location_categories" => "locations#get_location_categories"
|
||||||
resources :location_categories
|
resources :location_categories
|
||||||
match "locations/get_locations" => "locations#get_locations"
|
match "locations/get_locations" => "locations#get_locations"
|
||||||
match "locations/get_categories" => "locations#get_categories"
|
match "locations/get_categories" => "locations#get_categories"
|
||||||
|
|
Reference in New Issue