c80_map 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (52) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +10 -0
  3. data/.travis.yml +3 -0
  4. data/CODE_OF_CONDUCT.md +13 -0
  5. data/Gemfile +4 -0
  6. data/LICENSE.txt +21 -0
  7. data/README.md +51 -0
  8. data/Rakefile +1 -0
  9. data/app/admin/c80_map/settings.rb +32 -0
  10. data/app/assets/javascripts/buttons/admin_buttons/button_back_to_map.js +48 -0
  11. data/app/assets/javascripts/buttons/admin_buttons/button_cancel_create.js +21 -0
  12. data/app/assets/javascripts/buttons/admin_buttons/button_complete_create.js +22 -0
  13. data/app/assets/javascripts/buttons/admin_buttons/button_edit.js +80 -0
  14. data/app/assets/javascripts/buttons/admin_buttons/button_new.js +46 -0
  15. data/app/assets/javascripts/buttons/admin_buttons/button_save.js +83 -0
  16. data/app/assets/javascripts/buttons/zoom_buttons.js +61 -0
  17. data/app/assets/javascripts/c80_map.js.coffee +11 -0
  18. data/app/assets/javascripts/events/app_event.js +15 -0
  19. data/app/assets/javascripts/map_objects/area.js +221 -0
  20. data/app/assets/javascripts/map_objects/building.js +309 -0
  21. data/app/assets/javascripts/map_objects/dot.js +14 -0
  22. data/app/assets/javascripts/src/main.js +992 -0
  23. data/app/assets/javascripts/src/state_controller.js +220 -0
  24. data/app/assets/javascripts/src/utils.js +127 -0
  25. data/app/assets/javascripts/svg_elements/helper.js +36 -0
  26. data/app/assets/javascripts/svg_elements/polygon.js +192 -0
  27. data/app/assets/javascripts/view/save_preloader.js +30 -0
  28. data/app/assets/stylesheets/c80_map.scss +2 -0
  29. data/app/assets/stylesheets/map.scss +1435 -0
  30. data/app/assets/stylesheets/view/save_preloader.scss +206 -0
  31. data/app/controllers/c80_map/application_controller.rb +6 -0
  32. data/app/controllers/c80_map/map_ajax_controller.rb +54 -0
  33. data/app/helpers/c80_map/application_helper.rb +33 -0
  34. data/app/models/c80_map/area.rb +5 -0
  35. data/app/models/c80_map/building.rb +73 -0
  36. data/app/models/c80_map/setting.rb +30 -0
  37. data/app/uploaders/c80_map/map_image_uploader.rb +31 -0
  38. data/app/views/c80_map/_map_row.html.erb +15 -0
  39. data/app/views/c80_map/_map_row_index.html.erb +39 -0
  40. data/app/views/c80_map/shared/_save_preloader.html.erb +3 -0
  41. data/bin/console +14 -0
  42. data/bin/setup +7 -0
  43. data/c80_map.gemspec +25 -0
  44. data/config/routes.rb +3 -0
  45. data/db/migrate/20160617130000_create_c80_map_settings.rb +8 -0
  46. data/db/migrate/20160620040202_create_c80_map_areas.rb +9 -0
  47. data/db/migrate/20160620040204_create_c80_map_buildings.rb +8 -0
  48. data/db/seeds/801_fill_map_settings.rb +6 -0
  49. data/lib/c80_map/engine.rb +23 -0
  50. data/lib/c80_map/version.rb +3 -0
  51. data/lib/c80_map.rb +8 -0
  52. metadata +136 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: fd89e83da9ff01fcdbab1ebff4e3e4b66279b254
4
+ data.tar.gz: 9130f925242ae7cf4dafc4d0f59e27d639c3ba53
5
+ SHA512:
6
+ metadata.gz: 12ce4d2c50b665134b914ba23ca51ff30976b117325a06d1887f24706ce6e0f51ce1d995589484675d08b8cf6267415268fbc7b4c7503f323e35d7ae86c07e86
7
+ data.tar.gz: 5ca2a0b5ccc59e366e1628f03ed8ce12b4181024fa2301e614c63289b2fcccab09d8d8e637375e81dc4f7e01713f5716c1fa38cf52e03b9da2426cfa6bd83641
data/.gitignore ADDED
@@ -0,0 +1,10 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ .idea
data/.travis.yml ADDED
@@ -0,0 +1,3 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.1.4
@@ -0,0 +1,13 @@
1
+ # Contributor Code of Conduct
2
+
3
+ As contributors and maintainers of this project, we pledge to respect all people who contribute through reporting issues, posting feature requests, updating documentation, submitting pull requests or patches, and other activities.
4
+
5
+ We are committed to making participation in this project a harassment-free experience for everyone, regardless of level of experience, gender, gender identity and expression, sexual orientation, disability, personal appearance, body size, race, age, or religion.
6
+
7
+ Examples of unacceptable behavior by participants include the use of sexual language or imagery, derogatory comments or personal attacks, trolling, public or private harassment, insults, or other unprofessional conduct.
8
+
9
+ Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct. Project maintainers who do not follow the Code of Conduct may be removed from the project team.
10
+
11
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by opening an issue or contacting one or more of the project maintainers.
12
+
13
+ This Code of Conduct is adapted from the [Contributor Covenant](http:contributor-covenant.org), version 1.0.0, available at [http://contributor-covenant.org/version/1/0/0/](http://contributor-covenant.org/version/1/0/0/)
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in c80_map.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 C80609A
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,51 @@
1
+ # C80Map
2
+
3
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/c80_map`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+
5
+ TODO: Delete this and the text above, and describe your gem
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'c80_map'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install c80_map
22
+
23
+ ## Usage
24
+
25
+ 1. Host application:
26
+
27
+ ```
28
+ $(document).ready(function() {
29
+ InitMap();
30
+ });
31
+ ```
32
+
33
+ 2. Seeds:
34
+
35
+ ```
36
+ $ rake db:seed:801_fill_map_settings
37
+ ```
38
+
39
+ ## Development
40
+
41
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `bin/console` for an interactive prompt that will allow you to experiment.
42
+
43
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release` to create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
44
+
45
+ ## Contributing
46
+
47
+ 1. Fork it ( https://github.com/[my-github-username]/c80_map/fork )
48
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
49
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
50
+ 4. Push to the branch (`git push origin my-new-feature`)
51
+ 5. Create a new Pull Request
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,32 @@
1
+ ActiveAdmin.register C80Map::Setting, as: 'Setting' do
2
+
3
+ menu :label => "Свойства", :parent => 'Карта'
4
+
5
+ before_filter :skip_sidebar!, :only => :index
6
+
7
+ permit_params :map_image
8
+
9
+ config.sort_order = 'id_asc'
10
+
11
+ # controller do
12
+ # cache_sweeper :suit_sweeper, :only => [:update,:create,:destroy]
13
+ # end
14
+
15
+ index do
16
+ column '' do |sp|
17
+ "#{ link_to image_tag(sp.map_image.thumb.url), sp.map_image.url, :target => '_blank' }<br>
18
+ ".html_safe
19
+ end
20
+ actions
21
+ end
22
+
23
+ form(:html => {:multipart => true}) do |f|
24
+
25
+ f.inputs 'Свойства карты' do
26
+ f.input :map_image, :hint => "#{image_tag(f.object.map_image.thumb.url)}".html_safe
27
+ end
28
+
29
+ f.actions
30
+ end
31
+
32
+ end
@@ -0,0 +1,48 @@
1
+ "use strict";
2
+
3
+ function BackToMapButton() {
4
+
5
+ var _map = null;
6
+ var _this = this;
7
+
8
+ var _cnt = null;
9
+ var _btn = null;
10
+
11
+ var _onClick = function () {
12
+ _map.setMode('viewing');
13
+
14
+ _map.current_area = null;
15
+
16
+ if (_map.current_building) {
17
+ _map.current_building.exit();
18
+ }
19
+
20
+ if (_map.current_area) {
21
+ _map.current_area.exit();
22
+ }
23
+
24
+ _map.svgRemoveAllNodes();
25
+
26
+
27
+ _map.draw_childs(_map.data["childs"]);
28
+
29
+ };
30
+
31
+ _this.init = function (parent_div_selector, link_to_map) {
32
+ _map = link_to_map;
33
+ _cnt = $('<div></div>').addClass('back_to_map_button');
34
+ _cnt.appendTo($(parent_div_selector));
35
+ _btn = $('<a href="#" id="BackToMapButton">Обратно на карту</a>');
36
+ _btn.on('click', _onClick);
37
+ _cnt.append(_btn);
38
+ };
39
+
40
+ _this.show = function () {
41
+ _cnt.css('display', 'block');
42
+ };
43
+
44
+ _this.hide = function () {
45
+ _cnt.css('display', 'none');
46
+ }
47
+
48
+ }
@@ -0,0 +1,21 @@
1
+ "use strict";
2
+
3
+ function CancelCreatingButton() {
4
+
5
+ var _map = null;
6
+ var _this = this;
7
+ _this.el = null;
8
+
9
+ this.onClick = function (e) {
10
+ console.log("<CancelCreatingButton.onClick>");
11
+ e.preventDefault();
12
+ _map.setMode("editing");
13
+ };
14
+
15
+ this.init = function (button_css_selector, link_to_map) {
16
+ _map = link_to_map;
17
+ _this.el = $(button_css_selector);
18
+ _this.el.on('click', this.onClick);
19
+ };
20
+
21
+ }
@@ -0,0 +1,22 @@
1
+ "use strict";
2
+
3
+ function CompleteCreatingButton() {
4
+
5
+ var _map = null;
6
+ var _this = this;
7
+ _this.el = null;
8
+
9
+ _this.onClick = function (e) {
10
+ console.log("<CompleteCreatingButton.onClick>");
11
+ if (e != null) e.preventDefault();
12
+ _map.onDrawStop();
13
+ };
14
+
15
+ _this.init = function (button_css_selector, link_to_map) {
16
+ _map = link_to_map;
17
+ _this.el = $(button_css_selector);
18
+ _this.el.on('click', _this.onClick);
19
+ _map.complete_creating_button_klass = _this;
20
+ };
21
+
22
+ }
@@ -0,0 +1,80 @@
1
+ "use strict";
2
+
3
+ // именно эта кнопка контролирует переходы между состояниями:
4
+ // - viewing, editing;
5
+ // - view_building, edit_building;
6
+ // - view_area, edit_area;
7
+ function EditButton() {
8
+
9
+ var _map = null;
10
+ var _this = this;
11
+ _this.state = 'init'; // editing / viewing
12
+ _this.el = null;
13
+
14
+ // состояние этой кнопки извне меняет приложение,
15
+ // когда входим в здание\площадь (вот тут [a1x7]),
16
+ // и чтобы не происходило бесконечного зацикленного вызова,
17
+ // вводится флаг mark_change_only_inner_state
18
+ this.setState = function (state,mark_change_only_inner_state) {
19
+ if (mark_change_only_inner_state == undefined) {
20
+ mark_change_only_inner_state = false;
21
+ }
22
+ console.log("<EditButton.setState> state = " + state);
23
+
24
+ // этот код коррелирует с [x9cs7]
25
+ _this.state = state;
26
+ _this.el.removeClass('editing');
27
+ _this.el.removeClass('viewing');
28
+ _this.el.removeClass('view_building');
29
+ _this.el.removeClass('edit_building');
30
+ _this.el.removeClass('view_area');
31
+ _this.el.removeClass('edit_area');
32
+ _this.el.addClass(state);
33
+
34
+ if (!mark_change_only_inner_state) {
35
+ _map.setMode(state);
36
+ }
37
+
38
+ };
39
+
40
+ this.onClick = function (e) {
41
+ e.preventDefault();
42
+
43
+ switch (_this.state) {
44
+ case 'editing':
45
+ _this.setState('viewing');
46
+ break;
47
+
48
+ case 'viewing':
49
+ _this.setState('editing');
50
+ break;
51
+
52
+ case 'view_building':
53
+ _this.setState('edit_building');
54
+ break;
55
+
56
+ case 'edit_building':
57
+ _this.setState('view_building');
58
+ break;
59
+
60
+ case 'view_area':
61
+ _this.setState('edit_area');
62
+ break;
63
+
64
+ case 'edit_area':
65
+ _this.setState('view_area');
66
+ break;
67
+
68
+ }
69
+
70
+ };
71
+
72
+ this.init = function (button_css_selector, link_to_map) {
73
+ _map = link_to_map;
74
+ _this.el = $(button_css_selector);
75
+ _this.state = _map.mode;
76
+ _this.el.addClass(_map.mode);
77
+ _this.el.on('click', this.onClick);
78
+ };
79
+
80
+ }
@@ -0,0 +1,46 @@
1
+ "use strict";
2
+
3
+ function NewButton() {
4
+
5
+ var _map = null;
6
+ var _this = this;
7
+ _this.state = 'init'; // creating / editing
8
+ _this.el = null;
9
+
10
+ _this.setState = function (state) {
11
+
12
+ _this.state = state;
13
+ _this.el.removeClass('creating');
14
+ _this.el.removeClass('editing');
15
+ _this.el.addClass(state);
16
+
17
+ _map.setMode(state);
18
+
19
+ };
20
+
21
+ _this.resetState = function () {
22
+ _this.state = 'editing';
23
+ _this.el.removeClass('creating');
24
+ _this.el.removeClass('editing');
25
+ _this.el.addClass('editing');
26
+ };
27
+
28
+ _this.onClick = function (e) {
29
+ if (_this.el.hasClass('disabled')) return;
30
+ e.preventDefault();
31
+
32
+ if (_this.state == 'creating') {
33
+ _this.setState('editing');
34
+ } else {
35
+ console.log("<NewButton.onClick> Переходим в режим создания полигона.");
36
+ _this.setState('creating');
37
+ }
38
+ };
39
+
40
+ _this.init = function (button_css_selector, link_to_map) {
41
+ _map = link_to_map;
42
+ _this.el = $(button_css_selector);
43
+ _this.setState(_map.mode);
44
+ _this.el.on('click', _this.onClick);
45
+ };
46
+ }
@@ -0,0 +1,83 @@
1
+ "use strict";
2
+
3
+ function SaveChangesButton() {
4
+
5
+ var _map = null;
6
+ var _this = this;
7
+ _this.el = null;
8
+
9
+ var sendDataToServer = function () {
10
+
11
+ var areas;
12
+ var buildings;
13
+ var i, len;
14
+
15
+ len = _map.drawn_areas.length;
16
+ if (len > 0) {
17
+ areas = [];
18
+ for (i = 0; i < len; i++) {
19
+ areas.push(_map.drawn_areas[i].to_json());
20
+ }
21
+ }
22
+
23
+ len = _map.drawn_buildings.length;
24
+ if (len > 0) {
25
+ buildings = [];
26
+ for (i = 0; i < len; i++) {
27
+ buildings.push(_map.drawn_buildings[i].to_json());
28
+ }
29
+ }
30
+
31
+ $.ajax({
32
+ url: '/save_map_data',
33
+ type: 'POST',
34
+ data: {
35
+ areas: areas,
36
+ buildings: buildings
37
+ },
38
+ dataType: 'json'
39
+ }).done(sendDataToServerDone);
40
+ };
41
+
42
+ var sendDataToServerDone = function (data, result) {
43
+ console.log("<ButtonSave.sendDataToServerDone> data,result:");
44
+ console.log(data);
45
+ console.log(result);
46
+ console.log("<ButtonSave.sendDataToServerDone> ------------");
47
+ };
48
+
49
+ _this.onClick = function (e) {
50
+ if (_this.el.hasClass('disabled')) return;
51
+ e.preventDefault();
52
+ _map.save_preloader_klass.show();
53
+ sendDataToServer();
54
+ };
55
+
56
+ _this.init = function (button_css_selector, link_to_map) {
57
+ _map = link_to_map;
58
+ _this.el = $(button_css_selector);
59
+ _this.el.on('click', _this.onClick);
60
+ };
61
+
62
+ _this.check_and_enable = function () {
63
+
64
+ //check
65
+ var mark_dirty = _map.drawn_areas.length || _map.drawn_buildings.length;
66
+
67
+ // enable
68
+ if (mark_dirty) {
69
+ _this.el.removeClass('mapplic-disabled');
70
+ } else {
71
+ _this.el.addClass('mapplic-disabled');
72
+ }
73
+
74
+ };
75
+
76
+ _this.hide = function () {
77
+ _this.el.css('display','none');
78
+ };
79
+
80
+ _this.show = function () {
81
+ _this.el.css('display','block');
82
+ };
83
+ }
@@ -0,0 +1,61 @@
1
+ "use strict";
2
+
3
+ // Zoom Buttons
4
+ function ZoomButtons() {
5
+
6
+ var _map = null;
7
+ this.el = null;
8
+
9
+ this.init = function (options, link_to_map) {
10
+ var mt = options["height"] - 10;
11
+ _map = link_to_map;
12
+
13
+ //var div_container = $('<div></div>')
14
+ // .addClass("container")
15
+ // .attr("id",'container_buttons')
16
+ // .appendTo(_map.container)
17
+ // .css('margin-top',mt+"px");
18
+ var div_container = $("#container_buttons");
19
+ div_container.css('margin-top', mt + "px");
20
+
21
+ //this.el = $('<div></div>').addClass('mzoom_buttons').appendTo(div_container);
22
+ this.el = $('.mzoom_buttons');
23
+
24
+ this.zoomin = $('<a></ha>').attr('href', '#').addClass('mapplic-zoomin-button').appendTo(this.el);
25
+
26
+ this.zoomin.on('click touchstart', function (e) {
27
+ e.preventDefault();
28
+
29
+ var scale = _map.scale;
30
+ _map.scale = _map.normalizeScale(scale + .2);
31
+
32
+ _map.x = _map.normalizeX(_map.x - (_map.container.width() / 2 - _map.x) * (_map.scale / scale - 1));
33
+ _map.y = _map.normalizeY(_map.y - (_map.container.height() / 2 - _map.y) * (_map.scale / scale - 1));
34
+
35
+ _map.moveTo(_map.x, _map.y, _map.scale, 400, 'easeInOutCubic');
36
+ _map.mark_virgin = false;
37
+ });
38
+
39
+ this.zoomout = $('<a></ha>').attr('href', '#').addClass('mapplic-zoomout-button').appendTo(this.el);
40
+
41
+ this.zoomout.on('click touchstart', function (e) {
42
+ e.preventDefault();
43
+
44
+ var scale = _map.scale;
45
+ _map.scale = _map.normalizeScale(scale - .2);
46
+
47
+ _map.x = _map.normalizeX(_map.x - (_map.container.width() / 2 - _map.x) * (_map.scale / scale - 1));
48
+ _map.y = _map.normalizeY(_map.y - (_map.container.height() / 2 - _map.y) * (_map.scale / scale - 1));
49
+
50
+ _map.moveTo(_map.x, _map.y, _map.scale, 400, 'easeInOutCubic');
51
+ _map.mark_virgin = false;
52
+ });
53
+ };
54
+
55
+ this.update = function (scale) {
56
+ this.zoomin.removeClass('mapplic-disabled');
57
+ this.zoomout.removeClass('mapplic-disabled');
58
+ if (scale == _map.o.fitscale) this.zoomout.addClass('mapplic-disabled');
59
+ else if (scale == _map.o.maxscale) this.zoomin.addClass('mapplic-disabled');
60
+ };
61
+ }
@@ -0,0 +1,11 @@
1
+ #= require ./svg_elements/helper.js
2
+ #= require ./svg_elements/polygon.js
3
+
4
+ #= require_directory ./events
5
+ #= require_directory ./map_objects
6
+ #= require_directory ./view
7
+ #= require_tree ./buttons
8
+
9
+ #= require ./src/utils.js
10
+ #= require ./src/state_controller.js
11
+ #= require ./src/main.js
@@ -0,0 +1,15 @@
1
+
2
+ /* AppEvent constructor */
3
+ function AppEvent(target, eventType, func) {
4
+ console.log("<AppEvent.new> target = " + target);
5
+
6
+ this.target = target;
7
+ this.eventType = eventType;
8
+ this.func = func;
9
+
10
+ target.addEventListener(eventType, func, false);
11
+ }
12
+
13
+ AppEvent.prototype.remove = function () {
14
+ this.target.removeEventListener(this.eventType, this.func, false);
15
+ };