Class: C80MapFloors::MapAjaxController
- Inherits:
-
ApplicationController
- Object
- ActionController::Base
- ApplicationController
- C80MapFloors::MapAjaxController
- Defined in:
- app/controllers/c80_map_floors/map_ajax_controller.rb
Instance Method Summary collapse
Instance Method Details
#save_map_data ⇒ Object
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 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 |
# File 'app/controllers/c80_map_floors/map_ajax_controller.rb', line 4 def save_map_data # Rails.logger.debug "<MapAjaxController.save_map_data> params = #{params}" #{ "buildings"=>{"0"=>{"coords"=>["2496.5894495412845",...]}} } # ЗДАНИЯ # в случае успеха - вернём id созданного здания, # тогда js обновит id и перенесёт здание из массива "новые здания" (drawn_buildings). # в случае неудачи - вернём описание ошибки # завершаем всё обновленным locations.json, который Map возьмёт # и положит в data # ПЛОЩАДИ # # как было: # {"areas"=>{"0"=>{"id"=>"61319", "coords"=>[..], "parent_building_id"=>"2"}}} # как стало: # {"areas"=>{"0"=>{"id"=>"61319", "coords"=>[..], "parent_floor_id"=>"2"}}} # ... # INSERT INTO `c80_map_floors_areas` (`coords`, `floor_id`, `created_at`, `updated_at`) VALUES ('...', 2, '2016-12-11 05:48:33.629883', '2016-12-11 05:48:33.629883') # # result = { areas: [], buildings: [], updated_locations_json: nil } # сначала создадим здания if params[:buildings].present? params[:buildings].each_key do |key| = params[:buildings][key] # puts "<MapAjaxController.save_map_data> new_building_options = #{new_building_options}" # puts "<MapAjaxController.save_map_data> new_building_options[:coords] = #{new_building_options[:coords]}" b = C80MapFloors::MapBuilding.new({ coords: [:coords].join(',') }) if b.valid? b.save result[:buildings] << { id: b.id, old_temp_id: ["id"] } else result[:buildings] << { id: .id, status: 'error' } end end end # затем создадим площади if params[:areas].present? params[:areas].each_key do |key| = params[:areas][key] # Rails.logger.debug "<MapAjaxController.save_map_data> new_area_options = #{new_area_options}" # puts "<MapAjaxController.save_map_data> new_area_options[:coords] = #{new_area_options[:coords]}" a = C80MapFloors::Area.new({ coords: [:coords].join(','), floor_id: [:parent_floor_id] }) if a.valid? a.save result[:areas] << { id: a.id, old_temp_id: ["id"] } else result[:areas] << { id: .id, status: 'error' } end end end if params[:deleted_areas].present? params[:deleted_areas].each do |area_id| # Rails.logger.debug "[TRACE] <map_ajax_controller.save_map_data> area_id = #{area_id}." # [TRACE] <map_ajax_controller.save_map_data> area_id = 43. area = C80MapFloors::Area.find(area_id) area.destroy end end MapJson.update_json rescue ActiveRecord::RecordNotFound Rails.logger.debug '[TRACE] <MapAjaxController.save_map_data> record not found' MapJson.update_json end |