class Admin::RulingBusesController < OrbitAdminController include Admin::RulingBusesHelper before_action ->(module_app = @app_title) { set_variables module_app } def initialize super @app_title = "ruling_bus" end def index @categories = current_user.approved_categories.select{|c| c.module_app_id == @module_app.id} rescue [] @filter_fields = filter_fields(@categories,[]) @ruling_buses = RulingBusInfo.all.order_by(sort).with_categories(filters("category")) @ruling_buses = search_data(@ruling_buses,[:cache_data]).page(params[:page]).per(10) if request.xhr? render :partial => "index" end end def setting @ruling_bus_setting = RulingBusSetting.first end def update_setting @ruling_bus_setting = RulingBusSetting.find(params[:id]) @ruling_bus_setting.update_attributes(ruling_bus_setting_params) Thread.new do content = "UNICORN_PID=\"`fuser tmp/pids/unicorn.sock tmp/sockets/unicorn.sock tmp/unicorn.sock` `cat tmp/pids/unicorn.pid `\" && kill -s USR2 $UNICORN_PID ; n=20; while (kill -0 $UNICORN_PID > /dev/null 2>&1) && test $n -ge 0; do printf '.' && sleep 1 && n=$(( $n - 1 )); done ; if test $n -lt 0; then kill -s TERM $UNICORN_PID; sleep 3; bundle exec unicorn_rails -c config/unicorn.rb -D -E #{Rails.env}; else kill -s QUIT $UNICORN_PID; fi" system(content) end redirect_to (params[:referer_url].blank? ? "/#{I18n.locale}/admin/ruling_buses": params[:referer_url]) end def destroy RulingBusInfo.where(:id=>params[:id]).destroy redirect_to :back end def edit_bus @ruling_bus = RulingBusInfo.find(params[:id]) end def new_bus @ruling_bus = RulingBusInfo.new(id: true) end def update_bus @ruling_bus = RulingBusInfo.find(params[:id]) @ruling_bus.update_attributes(ruling_bus_info_params) RulingBusCache.where(bus_info_id: params[:id]).destroy redirect_to (params[:referer_url].blank? ? "/#{I18n.locale}/admin/ruling_buses": params[:referer_url]) end def create_bus @ruling_bus = RulingBusInfo.create(ruling_bus_info_params) redirect_to (params[:referer_url].blank? ? "/#{I18n.locale}/admin/ruling_buses": params[:referer_url]) end def ruling_bus_info_params tmp = params.require(:ruling_bus_info).permit! tmp['route_names'] = tmp['route_names'].split(',') tmp['cache_data'] = eval(tmp['cache_data']) tmp end def ruling_bus_setting_params params.require(:ruling_bus_setting).permit! end def get_stops_and_code_for_city code = RulingBusesHelper.get_location_code(params[:city]) stops = RulingBusesHelper.get_stops_for_city(params[:city],code,params[:default_locale]) render :json => {stops: stops, code: code} end def route_name_for_targets data = RulingBusesHelper.get_bus_with_direction_from_a_to_b(params[:city],params[:location_code], params[:monitor_point],params[:destination], params[:default_locale],params[:direction]) render :json => {show: data.map{|k,v| v}.flatten(1).map{|k,v| v}.flatten,org: data.to_s} end end