c80_map 0.1.0 → 0.1.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +2 -1
- data/app/admin/c80_map/buildings.rb +37 -0
- data/app/assets/javascripts/map_objects/area.js +5 -0
- data/app/assets/javascripts/map_objects/building.js +5 -0
- data/app/assets/javascripts/src/main.js +3 -2
- data/app/controllers/c80_map/map_ajax_controller.rb +31 -19
- data/app/models/c80_map/area.rb +9 -0
- data/app/models/c80_map/building.rb +3 -60
- data/app/models/c80_map/map_json.rb +85 -0
- data/app/uploaders/c80_map/building_image_uploader.rb +31 -0
- data/db/migrate/{20160620040204_create_c80_map_buildings.rb → 20160620040206_create_c80_map_buildings.rb} +4 -1
- data/lib/c80_map/version.rb +1 -1
- metadata +6 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 45604d02c597521234df05dd9a4e5b6d6f102bad
|
4
|
+
data.tar.gz: 3f5b26bce2ab3ade46ebac5bedd3e7381a0b91e0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6a05585ebb025b8e3ef2f8ceadd2e5dea6adaedd5ff6cdede468d65a41a333bd254573cfc03eebe875f2a93a4c6e93172146c869201109a284dba1a6835d8ef2
|
7
|
+
data.tar.gz: bcaecce4a5783e6eec963d47e8e3cef0ddf577b3f42d542d3028c0dd86f40f65b403375783c76ff282062a215e44040e881ed0c6bbad2559edecc627e06a1b57
|
data/.gitignore
CHANGED
@@ -0,0 +1,37 @@
|
|
1
|
+
ActiveAdmin.register C80Map::Building, as: 'Building' do
|
2
|
+
|
3
|
+
menu :label => "Buildings", :parent => 'Карта'
|
4
|
+
|
5
|
+
before_filter :skip_sidebar!, :only => :index
|
6
|
+
|
7
|
+
permit_params :img_bg, :img_overlay, :coords, :tag
|
8
|
+
|
9
|
+
config.sort_order = 'id_asc'
|
10
|
+
|
11
|
+
index do
|
12
|
+
column :tag
|
13
|
+
# column :coords
|
14
|
+
column 'img_bg' do |sp|
|
15
|
+
"#{ link_to image_tag(sp.img_bg.thumb.url, :style => 'background-color: #cfcfcf;'), sp.img_bg.url, :target => '_blank' }<br>
|
16
|
+
".html_safe
|
17
|
+
end
|
18
|
+
# column 'img_overlay' do |sp|
|
19
|
+
# "#{ link_to image_tag(sp.img_overlay.thumb.url), sp.img_overlay.url, :target => '_blank' }<br>
|
20
|
+
# ".html_safe
|
21
|
+
# end
|
22
|
+
actions
|
23
|
+
end
|
24
|
+
|
25
|
+
form(:html => {:multipart => true}) do |f|
|
26
|
+
|
27
|
+
f.inputs 'Properties' do
|
28
|
+
f.input :tag
|
29
|
+
f.input :coords
|
30
|
+
f.input :img_bg, :hint => "#{image_tag(f.object.img_bg.thumb.url)}".html_safe
|
31
|
+
f.input :img_overlay, :hint => "#{image_tag(f.object.img_overlay.thumb.url)}".html_safe
|
32
|
+
end
|
33
|
+
|
34
|
+
f.actions
|
35
|
+
end
|
36
|
+
|
37
|
+
end
|
@@ -56,6 +56,11 @@ function Area() {
|
|
56
56
|
_this._options["id"] = Math.ceil((Math.random()*100000));
|
57
57
|
}
|
58
58
|
|
59
|
+
// [56dfaw1]
|
60
|
+
for (var i=0; i<_this._options.coords.length; i++) {
|
61
|
+
_this._options.coords[i] = Number(_this._options.coords[i]);
|
62
|
+
}
|
63
|
+
|
59
64
|
_this._options.parent_building_hash = parent_building_hash;
|
60
65
|
//clog(_this._options.parent_building_hash);
|
61
66
|
|
@@ -201,6 +201,11 @@ function Building() {
|
|
201
201
|
_options = options;
|
202
202
|
_this.options = options;
|
203
203
|
|
204
|
+
// [56dfaw1]
|
205
|
+
for (var i=0; i<_this.options.coords.length; i++) {
|
206
|
+
_this.options.coords[i] = Number(_this.options.coords[i]);
|
207
|
+
}
|
208
|
+
|
204
209
|
// [4ddl5df]: в случае, если это только что отрисованное Здание - генерим временный случайный id
|
205
210
|
if (_this.options["id"] == undefined) {
|
206
211
|
_this.options["id"] = Math.ceil((Math.random()*100000));
|
@@ -474,8 +474,9 @@ var clog = function () {
|
|
474
474
|
}
|
475
475
|
}
|
476
476
|
|
477
|
-
/* если находимся в режиме просмотра здания - входим в
|
478
|
-
|
477
|
+
/* если находимся в режиме просмотра здания - входим в площадь */
|
478
|
+
/* если находится в режиме просмотра площади - переключаемся на другую площадь */
|
479
|
+
else if (self.mode == 'view_building' || self.mode == 'view_area') {
|
479
480
|
|
480
481
|
// добираемся до объекта класса Area, который обслуживает полигон
|
481
482
|
p = $(event.target).parent()[0];
|
@@ -2,11 +2,18 @@ module C80Map
|
|
2
2
|
class MapAjaxController < ApplicationController
|
3
3
|
|
4
4
|
def save_map_data
|
5
|
-
|
5
|
+
Rails.logger.debug "<MapAjaxController.save_map_data> params = #{params}"
|
6
6
|
|
7
7
|
#{ "buildings"=>{"0"=>{"coords"=>["2496.5894495412845",...]}} }
|
8
8
|
#{ "areas"=>{"0"=>{"coords"=>["2496.5894495412845",...]}} }
|
9
9
|
|
10
|
+
# ЗДАНИЯ
|
11
|
+
# в случае успеха - вернём id созданного здания,
|
12
|
+
# тогда js обновит id и перенесёт здание из массива "новые здания" (drawn_buildings).
|
13
|
+
# в случае неудачи - вернём описание ошибки
|
14
|
+
# завершаем всё обновленным locations.json, который Map возьмёт
|
15
|
+
# и положит в data
|
16
|
+
|
10
17
|
result = {
|
11
18
|
areas: [],
|
12
19
|
buildings: [],
|
@@ -16,37 +23,42 @@ module C80Map
|
|
16
23
|
if params[:buildings].present?
|
17
24
|
params[:buildings].each_key do |key|
|
18
25
|
new_building_options = params[:buildings][key]
|
19
|
-
puts "<MapAjaxController.save_map_data> new_building_options = #{new_building_options}"
|
20
|
-
puts "<MapAjaxController.save_map_data> new_building_options[:coords] = #{new_building_options[:coords]}"
|
26
|
+
# puts "<MapAjaxController.save_map_data> new_building_options = #{new_building_options}"
|
27
|
+
# puts "<MapAjaxController.save_map_data> new_building_options[:coords] = #{new_building_options[:coords]}"
|
21
28
|
b = Building.new({ coords: new_building_options[:coords].join(',') })
|
22
29
|
|
23
|
-
# в случае успеха - вернём id созданного здания,
|
24
|
-
# тогда js обновит id и перенесёт здание из массива "новые здания" (drawn_buildings).
|
25
|
-
# в случае неудачи - вернём описание ошибки
|
26
|
-
# завершаем всё обновленным locations.json, который Map возьмёт
|
27
|
-
# и положит в data
|
28
|
-
|
29
30
|
if b.valid?
|
30
31
|
b.save
|
31
|
-
result[:buildings] << { id: b.id }
|
32
|
+
result[:buildings] << { id: b.id, old_temp_id: new_building_options["id"] }
|
32
33
|
else
|
33
34
|
result[:buildings] << { id: new_building_options.id, status: 'error' }
|
34
35
|
end
|
35
36
|
end
|
36
37
|
end
|
37
38
|
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
#
|
42
|
-
#
|
43
|
-
|
44
|
-
|
45
|
-
|
39
|
+
if params[:areas].present?
|
40
|
+
params[:areas].each_key do |key|
|
41
|
+
new_area_options = params[:areas][key]
|
42
|
+
# Rails.logger.debug "<MapAjaxController.save_map_data> new_area_options = #{new_area_options}"
|
43
|
+
# puts "<MapAjaxController.save_map_data> new_area_options[:coords] = #{new_area_options[:coords]}"
|
44
|
+
a = Area.new({
|
45
|
+
coords: new_area_options[:coords].join(','),
|
46
|
+
building_id: new_area_options[:parent_building_id]
|
47
|
+
})
|
48
|
+
|
49
|
+
if a.valid?
|
50
|
+
a.save
|
51
|
+
result[:areas] << { id: a.id, old_temp_id: new_area_options["id"] }
|
52
|
+
else
|
53
|
+
result[:areas] << { id: new_area_options.id, status: 'error' }
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
46
58
|
puts "<MapAjaxController.save_map_data> result = #{result.to_json}"
|
47
59
|
|
48
60
|
respond_to do |format|
|
49
|
-
format.json { render json:
|
61
|
+
format.json { render json: result }
|
50
62
|
end
|
51
63
|
end
|
52
64
|
|
data/app/models/c80_map/area.rb
CHANGED
@@ -3,70 +3,13 @@ module C80Map
|
|
3
3
|
has_many :areas, :class_name => 'C80Map::Area', :dependent => :destroy
|
4
4
|
validates :coords, uniqueness: true
|
5
5
|
after_save :update_json
|
6
|
+
mount_uploader :img_bg, C80Map::BuildingImageUploader
|
7
|
+
mount_uploader :img_overlay, C80Map::BuildingImageUploader
|
6
8
|
|
7
9
|
private
|
8
10
|
|
9
11
|
def update_json
|
10
|
-
|
11
|
-
locations_path = Rails.root.join("public", "locations.json")
|
12
|
-
locs = File.read(locations_path)
|
13
|
-
puts "<update_json> #{ Rails.root.join("public", "locations.json") }"
|
14
|
-
|
15
|
-
locs_hash = JSON.parse(locs)
|
16
|
-
|
17
|
-
|
18
|
-
# и заполняем объектами из собранного массива
|
19
|
-
|
20
|
-
# обходим все Building и составляем массив вида
|
21
|
-
# [{id, object_type=object_type, coords, building_hash, img, childs:[<areas>]},..]
|
22
|
-
buildings_to_location_json = []
|
23
|
-
Building.all.each do |b|
|
24
|
-
ob = {
|
25
|
-
id: b.id,
|
26
|
-
object_type: 'building',
|
27
|
-
coords: b.coords,
|
28
|
-
building_hash: {
|
29
|
-
id: 2,
|
30
|
-
title: "Здание 2",
|
31
|
-
props: {
|
32
|
-
square: "1234 кв.м.",
|
33
|
-
square_free: "124 кв. м",
|
34
|
-
floor_height: "6 кв. м",
|
35
|
-
column_step: "2 м",
|
36
|
-
gate_type: "рaспашные",
|
37
|
-
communications: "Интернет, электричество, водоснабжение",
|
38
|
-
price: "от 155 руб/кв.м в месяц"
|
39
|
-
}
|
40
|
-
},
|
41
|
-
img: {
|
42
|
-
bg: {
|
43
|
-
src: "/assets/sample_bg-e36f4b42acde72d4ff05376498e5834423165d43e73650dd24a342ecb20779b9.gif"
|
44
|
-
},
|
45
|
-
overlay: {
|
46
|
-
src: "/assets/sample_overlay-f99419a8904207a6ac74288bccac16c76b388b7162bf2629a2a8dd825746f49b.gif"
|
47
|
-
}
|
48
|
-
},
|
49
|
-
childs: []
|
50
|
-
}
|
51
|
-
buildings_to_location_json << ob
|
52
|
-
end
|
53
|
-
|
54
|
-
# после чего удаляем из locs_hash все object_type=building
|
55
|
-
# locs_hash["childs"].each do |child|
|
56
|
-
# if child["object_type"] == 'building'
|
57
|
-
# delete locs_hash["childs"]
|
58
|
-
# end
|
59
|
-
# end
|
60
|
-
|
61
|
-
# просто заменяем всех детей
|
62
|
-
locs_hash["childs"] = buildings_to_location_json
|
63
|
-
|
64
|
-
puts "<Building.update_json> #{locs_hash}"
|
65
|
-
|
66
|
-
# File.open(locations_path, 'w') do |f|
|
67
|
-
# f.write(locs_hash.to_json)
|
68
|
-
# end
|
69
|
-
|
12
|
+
MapJson.update_json
|
70
13
|
end
|
71
14
|
|
72
15
|
end
|
@@ -0,0 +1,85 @@
|
|
1
|
+
module C80Map
|
2
|
+
|
3
|
+
class MapJson < ActiveRecord::Base
|
4
|
+
|
5
|
+
def self.update_json
|
6
|
+
locations_path = Rails.root.join("public", "locations.json")
|
7
|
+
locs = File.read(locations_path)
|
8
|
+
# puts "<MapJson.update_json> #{ Rails.root.join("public", "locations.json") }"
|
9
|
+
|
10
|
+
locs_hash = JSON.parse(locs)
|
11
|
+
|
12
|
+
# обходим все Building и составляем массив вида
|
13
|
+
# [{id, object_type=object_type, coords, building_hash, img, childs:[<areas>]},..]
|
14
|
+
buildings_to_location_json = []
|
15
|
+
Building.all.each do |b|
|
16
|
+
|
17
|
+
# сначала соберём детей - Area
|
18
|
+
childs = []
|
19
|
+
b.areas.each do |area|
|
20
|
+
Rails.logger.debug "<MapJson.update_json> area #{area}"
|
21
|
+
|
22
|
+
ab = {
|
23
|
+
id: area.id,
|
24
|
+
object_type: 'area',
|
25
|
+
coords: area.coords.split(','),
|
26
|
+
area_hash: {
|
27
|
+
id: 2,
|
28
|
+
title: "Площадь #{area.id}.#{area.id}",
|
29
|
+
is_free: true,
|
30
|
+
props: {
|
31
|
+
square: "124 кв.м.",
|
32
|
+
floor_height: "6 кв. м",
|
33
|
+
column_step: "2 м",
|
34
|
+
gate_type: "распашные",
|
35
|
+
communications: "Интернет, электричество, водоснабжение",
|
36
|
+
price: "от 155 руб/кв.м в месяц"
|
37
|
+
}
|
38
|
+
}
|
39
|
+
}
|
40
|
+
childs << ab
|
41
|
+
end
|
42
|
+
|
43
|
+
ob = {
|
44
|
+
id: b.id,
|
45
|
+
object_type: 'building',
|
46
|
+
coords: b.coords.split(","),
|
47
|
+
building_hash: {
|
48
|
+
id: 2,
|
49
|
+
title: "Здание 2",
|
50
|
+
props: {
|
51
|
+
square: "1234 кв.м.",
|
52
|
+
square_free: "124 кв. м",
|
53
|
+
floor_height: "6 кв. м",
|
54
|
+
column_step: "2 м",
|
55
|
+
gate_type: "рaспашные",
|
56
|
+
communications: "Интернет, электричество, водоснабжение",
|
57
|
+
price: "от 155 руб/кв.м в месяц"
|
58
|
+
}
|
59
|
+
},
|
60
|
+
img: {
|
61
|
+
bg: {
|
62
|
+
src: b.img_bg.url
|
63
|
+
},
|
64
|
+
overlay: {
|
65
|
+
src: b.img_overlay.url
|
66
|
+
}
|
67
|
+
},
|
68
|
+
childs: childs
|
69
|
+
}
|
70
|
+
buildings_to_location_json << ob
|
71
|
+
end
|
72
|
+
|
73
|
+
# просто заменяем всех детей
|
74
|
+
locs_hash["childs"] = buildings_to_location_json
|
75
|
+
|
76
|
+
Rails.logger.debug "<MapJson.update_json> #{locs_hash}"
|
77
|
+
|
78
|
+
File.open(locations_path, 'w') do |f|
|
79
|
+
f.write(locs_hash.to_json)
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
end
|
84
|
+
|
85
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
module C80Map
|
2
|
+
|
3
|
+
class BuildingImageUploader < CarrierWave::Uploader::Base
|
4
|
+
|
5
|
+
include CarrierWave::MiniMagick
|
6
|
+
|
7
|
+
storage :file
|
8
|
+
|
9
|
+
version :thumb do
|
10
|
+
process :resize_to_fit => [500,500]
|
11
|
+
end
|
12
|
+
|
13
|
+
def store_dir
|
14
|
+
"uploads/map/buildings"
|
15
|
+
end
|
16
|
+
|
17
|
+
def filename
|
18
|
+
if original_filename
|
19
|
+
"img_#{secure_token(4)}.#{file.extension}"
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
protected
|
24
|
+
def secure_token(length=16)
|
25
|
+
var = :"@#{mounted_as}_secure_token"
|
26
|
+
model.instance_variable_get(var) or model.instance_variable_set(var, SecureRandom.hex(length/2))
|
27
|
+
end
|
28
|
+
|
29
|
+
end
|
30
|
+
|
31
|
+
end
|
@@ -1,7 +1,10 @@
|
|
1
1
|
class CreateC80MapBuildings < ActiveRecord::Migration
|
2
2
|
def change
|
3
3
|
create_table :c80_map_buildings, :options => 'COLLATE=utf8_unicode_ci' do |t|
|
4
|
-
t.string :
|
4
|
+
t.string :tag
|
5
|
+
t.text :coords
|
6
|
+
t.string :img_bg
|
7
|
+
t.string :img_overlay
|
5
8
|
t.timestamps
|
6
9
|
end
|
7
10
|
end
|
data/lib/c80_map/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: c80_map
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.0
|
4
|
+
version: 0.1.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- C80609A
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-06-
|
11
|
+
date: 2016-06-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -66,6 +66,7 @@ files:
|
|
66
66
|
- LICENSE.txt
|
67
67
|
- README.md
|
68
68
|
- Rakefile
|
69
|
+
- app/admin/c80_map/buildings.rb
|
69
70
|
- app/admin/c80_map/settings.rb
|
70
71
|
- app/assets/javascripts/buttons/admin_buttons/button_back_to_map.js
|
71
72
|
- app/assets/javascripts/buttons/admin_buttons/button_cancel_create.js
|
@@ -93,7 +94,9 @@ files:
|
|
93
94
|
- app/helpers/c80_map/application_helper.rb
|
94
95
|
- app/models/c80_map/area.rb
|
95
96
|
- app/models/c80_map/building.rb
|
97
|
+
- app/models/c80_map/map_json.rb
|
96
98
|
- app/models/c80_map/setting.rb
|
99
|
+
- app/uploaders/c80_map/building_image_uploader.rb
|
97
100
|
- app/uploaders/c80_map/map_image_uploader.rb
|
98
101
|
- app/views/c80_map/_map_row.html.erb
|
99
102
|
- app/views/c80_map/_map_row_index.html.erb
|
@@ -104,7 +107,7 @@ files:
|
|
104
107
|
- config/routes.rb
|
105
108
|
- db/migrate/20160617130000_create_c80_map_settings.rb
|
106
109
|
- db/migrate/20160620040202_create_c80_map_areas.rb
|
107
|
-
- db/migrate/
|
110
|
+
- db/migrate/20160620040206_create_c80_map_buildings.rb
|
108
111
|
- db/seeds/801_fill_map_settings.rb
|
109
112
|
- lib/c80_map.rb
|
110
113
|
- lib/c80_map/engine.rb
|