diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 733bbac5..18f33a2c 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -23,6 +23,13 @@ class ApplicationController < ActionController::Base 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 Resque.enqueue(RestartServer) end diff --git a/app/models/site.rb b/app/models/site.rb index c6da53c3..e93e9a87 100644 --- a/app/models/site.rb +++ b/app/models/site.rb @@ -14,6 +14,7 @@ class Site field :frontend_open, :type => Boolean, :default => true 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 :sitemap_menu_in_header, :type => Boolean, :default => false field :enable_terms_of_use, :type => Boolean, :default => false diff --git a/app/views/admin/sites/preference.html.erb b/app/views/admin/sites/preference.html.erb index 5ad98a4b..6cd1f289 100644 --- a/app/views/admin/sites/preference.html.erb +++ b/app/views/admin/sites/preference.html.erb @@ -131,6 +131,13 @@ <%= f.check_box :desktop_closed , :class=>"toggle-check", :data=> { disabled: true } %> +
+ +
+ <%= f.check_box :mobile_api_openness_on , :class=>"toggle-check", :data=> { disabled: true } %> + API Is available for Mobile Apps +
+
diff --git a/config/locales/en.yml b/config/locales/en.yml index 3715ebef..ca2d3dcb 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -386,6 +386,7 @@ en: thumbnail: Thumbnail site: backend_openness_on: Backend Openness + mobile_api_openness_on: Mobile API Openness default_image: Site default image description: Site description description_help: Description Guide diff --git a/config/locales/zh_tw.yml b/config/locales/zh_tw.yml index 5cfbec91..5df73458 100644 --- a/config/locales/zh_tw.yml +++ b/config/locales/zh_tw.yml @@ -389,6 +389,7 @@ zh_tw: frontend_closed: 前台關閉? frontend_open: 開啟前台 backend_openness_on: 開啟開放式後台(訪客可遊覽) + mobile_api_openness_on: 開啟手機API enable_personal_desktop: 開啟個人桌面 default_image: 預設圖像 description: 網站描述 diff --git a/vendor/built_in_modules/location/app/controllers/panel/location/back_end/locations_controller.rb b/vendor/built_in_modules/location/app/controllers/panel/location/back_end/locations_controller.rb index b2a13516..e3baf793 100644 --- a/vendor/built_in_modules/location/app/controllers/panel/location/back_end/locations_controller.rb +++ b/vendor/built_in_modules/location/app/controllers/panel/location/back_end/locations_controller.rb @@ -1,5 +1,6 @@ class Panel::Location::BackEnd::LocationsController < OrbitBackendController include AdminHelper + open_for_visitor :only => [:get_location_categories, :get_categorywise_locations] def index @locations = LocationInfo.all @@ -89,4 +90,43 @@ class Panel::Location::BackEnd::LocationsController < OrbitBackendController render :json => JSON.pretty_generate(@data) 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 diff --git a/vendor/built_in_modules/location/config/routes.rb b/vendor/built_in_modules/location/config/routes.rb index e4df6eaa..bc9389bd 100644 --- a/vendor/built_in_modules/location/config/routes.rb +++ b/vendor/built_in_modules/location/config/routes.rb @@ -3,6 +3,9 @@ Rails.application.routes.draw do namespace :location do namespace :back_end do 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 match "locations/get_locations" => "locations#get_locations" match "locations/get_categories" => "locations#get_categories"