layers_of_london-booth-map_tool 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/LICENSE +621 -0
  3. data/README.md +28 -0
  4. data/Rakefile +32 -0
  5. data/app/assets/config/layers_of_london_booth_map_tool_manifest.js +2 -0
  6. data/app/assets/javascripts/layers_of_london/booth/map_tool/application.js +15 -0
  7. data/app/assets/javascripts/layers_of_london/booth/map_tool/maptools.js +2 -0
  8. data/app/assets/javascripts/layers_of_london/booth/map_tool/polygons.js +2 -0
  9. data/app/assets/javascripts/layers_of_london/booth/map_tool/squares.js +2 -0
  10. data/app/assets/stylesheets/layers_of_london/booth/map_tool/application.css +15 -0
  11. data/app/assets/stylesheets/layers_of_london/booth/map_tool/maptools.css +4 -0
  12. data/app/assets/stylesheets/layers_of_london/booth/map_tool/polygons.css +4 -0
  13. data/app/assets/stylesheets/layers_of_london/booth/map_tool/squares.css +4 -0
  14. data/app/controllers/layers_of_london/booth/map_tool/application_controller.rb +35 -0
  15. data/app/controllers/layers_of_london/booth/map_tool/maptools_controller.rb +8 -0
  16. data/app/controllers/layers_of_london/booth/map_tool/polygons_controller.rb +68 -0
  17. data/app/controllers/layers_of_london/booth/map_tool/squares_controller.rb +79 -0
  18. data/app/helpers/layers_of_london/booth/map_tool/application_helper.rb +8 -0
  19. data/app/helpers/layers_of_london/booth/map_tool/maptools_helper.rb +4 -0
  20. data/app/helpers/layers_of_london/booth/map_tool/polygons_helper.rb +4 -0
  21. data/app/helpers/layers_of_london/booth/map_tool/squares_helper.rb +4 -0
  22. data/app/jobs/layers_of_london/booth/map_tool/application_job.rb +8 -0
  23. data/app/mailers/layers_of_london/booth/map_tool/application_mailer.rb +10 -0
  24. data/app/models/layers_of_london/booth/map_tool/application_record.rb +9 -0
  25. data/app/models/layers_of_london/booth/map_tool/polygon.rb +20 -0
  26. data/app/models/layers_of_london/booth/map_tool/square.rb +146 -0
  27. data/app/policies/layers_of_london/booth/map_tool/polygon_policy.rb +25 -0
  28. data/app/views/layers_of_london/booth/map_tool/maptools/show.html.erb +2 -0
  29. data/app/views/layers_of_london/booth/map_tool/polygons/create.html.erb +2 -0
  30. data/app/views/layers_of_london/booth/map_tool/polygons/destroy.html.erb +2 -0
  31. data/app/views/layers_of_london/booth/map_tool/polygons/index.html.erb +2 -0
  32. data/app/views/layers_of_london/booth/map_tool/polygons/update.html.erb +2 -0
  33. data/app/views/layers_of_london/booth/map_tool/squares/create.html.erb +2 -0
  34. data/app/views/layers_of_london/booth/map_tool/squares/edit.html.erb +2 -0
  35. data/app/views/layers_of_london/booth/map_tool/squares/index.html.erb +2 -0
  36. data/app/views/layers_of_london/booth/map_tool/squares/show.html.erb +2 -0
  37. data/app/views/layers_of_london/booth/map_tool/squares/update.html.erb +2 -0
  38. data/app/views/layouts/layers_of_london/booth/map_tool/application.html.erb +16 -0
  39. data/config/routes.rb +17 -0
  40. data/db/migrate/20190724120049_create_layers_of_london_booth_map_tool_squares.rb +7 -0
  41. data/db/migrate/20190724120136_create_layers_of_london_booth_map_tool_polygons.rb +10 -0
  42. data/db/migrate/20190731111508_add_aasm_state_to_squares.rb +5 -0
  43. data/db/migrate/20190802100700_add_locations_to_squares.rb +10 -0
  44. data/db/migrate/20190802120000_add_north_west_south_east_to_squares.rb +12 -0
  45. data/db/migrate/20190806161900_add_row_col_to_squares.rb +9 -0
  46. data/db/migrate/20190809151958_add_user_tracking_to_square.rb +5 -0
  47. data/lib/generators/map_tool/grid_generator.rb +28 -0
  48. data/lib/layers_of_london/booth/map_tool.rb +46 -0
  49. data/lib/layers_of_london/booth/map_tool/engine.rb +27 -0
  50. data/lib/layers_of_london/booth/map_tool/version.rb +7 -0
  51. data/lib/tasks/layers_of_london/booth/map_tool_tasks.rake +4 -0
  52. metadata +164 -0
@@ -0,0 +1,25 @@
1
+ module LayersOfLondon::Booth::MapTool
2
+ class PolygonPolicy < ApplicationPolicy
3
+ def show?
4
+ true
5
+ end
6
+
7
+ def update?
8
+ record.user.id === user.try(:id) && record.square.editable?
9
+ end
10
+
11
+ def destroy?
12
+ update?
13
+ end
14
+
15
+ def create?
16
+ user.present?
17
+ end
18
+
19
+ class Scope < Scope
20
+ def resolve
21
+ scope.all
22
+ end
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,2 @@
1
+ <h1>Maptools#show</h1>
2
+ <p>Find me in app/views/layers_of_london/booth/map_tool/maptools/show.html.erb</p>
@@ -0,0 +1,2 @@
1
+ <h1>Polygons#create</h1>
2
+ <p>Find me in app/views/layers_of_london/booth/map_tool/polygons/create.html.erb</p>
@@ -0,0 +1,2 @@
1
+ <h1>Polygons#destroy</h1>
2
+ <p>Find me in app/views/layers_of_london/booth/map_tool/polygons/destroy.html.erb</p>
@@ -0,0 +1,2 @@
1
+ <h1>Polygons#index</h1>
2
+ <p>Find me in app/views/layers_of_london/booth/map_tool/polygons/index.html.erb</p>
@@ -0,0 +1,2 @@
1
+ <h1>Polygons#update</h1>
2
+ <p>Find me in app/views/layers_of_london/booth/map_tool/polygons/update.html.erb</p>
@@ -0,0 +1,2 @@
1
+ <h1>Squares#create</h1>
2
+ <p>Find me in app/views/layers_of_london/booth/map_tool/squares/create.html.erb</p>
@@ -0,0 +1,2 @@
1
+ <h1>Squares#edit</h1>
2
+ <p>Find me in app/views/layers_of_london/booth/map_tool/squares/edit.html.erb</p>
@@ -0,0 +1,2 @@
1
+ <h1>Squares#index</h1>
2
+ <p>Find me in app/views/layers_of_london/booth/map_tool/squares/index.html.erb</p>
@@ -0,0 +1,2 @@
1
+ <h1>Squares#show</h1>
2
+ <p>Find me in app/views/layers_of_london/booth/map_tool/squares/show.html.erb</p>
@@ -0,0 +1,2 @@
1
+ <h1>Squares#update</h1>
2
+ <p>Find me in app/views/layers_of_london/booth/map_tool/squares/update.html.erb</p>
@@ -0,0 +1,16 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>Layers of london booth map tool</title>
5
+ <%= csrf_meta_tags %>
6
+ <%= csp_meta_tag %>
7
+
8
+ <%= stylesheet_link_tag "layers_of_london/booth/map_tool/application", media: "all" %>
9
+ <%= javascript_include_tag "layers_of_london/booth/map_tool/application" %>
10
+ </head>
11
+ <body>
12
+
13
+ <%= yield %>
14
+
15
+ </body>
16
+ </html>
data/config/routes.rb ADDED
@@ -0,0 +1,17 @@
1
+ LayersOfLondon::Booth::MapTool::Engine.routes.draw do
2
+ scope '/booth' do
3
+ get 'session', to: '/layers_of_london/booth/map_tool/application#session'
4
+ resource :maptools, only: [:show] do
5
+
6
+ resources :squares, only: [:index, :show, :update] do
7
+ collection do
8
+ get :polygons
9
+ get :grid
10
+ get :coordinates
11
+ end
12
+
13
+ resources :polygons, except: [:new]
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,7 @@
1
+ class CreateLayersOfLondonBoothMapToolSquares < ActiveRecord::Migration[5.2]
2
+ def change
3
+ create_table :layers_of_london_booth_map_tool_squares do |t|
4
+ t.timestamps
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,10 @@
1
+ class CreateLayersOfLondonBoothMapToolPolygons < ActiveRecord::Migration[5.2]
2
+ def change
3
+ create_table :layers_of_london_booth_map_tool_polygons do |t|
4
+ t.references :square
5
+ t.belongs_to :user
6
+ t.text :feature
7
+ t.timestamps
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,5 @@
1
+ class AddAasmStateToSquares < ActiveRecord::Migration[5.2]
2
+ def change
3
+ add_column :layers_of_london_booth_map_tool_squares, :aasm_state, :string
4
+ end
5
+ end
@@ -0,0 +1,10 @@
1
+ class AddLocationsToSquares < ActiveRecord::Migration[5.2]
2
+ def change
3
+ add_column :layers_of_london_booth_map_tool_squares, :north_west, :string
4
+ add_column :layers_of_london_booth_map_tool_squares, :geojson, :text
5
+ add_column :layers_of_london_booth_map_tool_squares, :square_size, :integer
6
+
7
+
8
+ end
9
+ end
10
+
@@ -0,0 +1,12 @@
1
+ class AddNorthWestSouthEastToSquares < ActiveRecord::Migration[5.2]
2
+ def change
3
+ remove_column :layers_of_london_booth_map_tool_squares, :north_west, :string
4
+ add_column :layers_of_london_booth_map_tool_squares, :north_west_lat, :float
5
+ add_column :layers_of_london_booth_map_tool_squares, :north_west_lng, :float
6
+ add_column :layers_of_london_booth_map_tool_squares, :south_east_lat, :float
7
+ add_column :layers_of_london_booth_map_tool_squares, :south_east_lng, :float
8
+
9
+
10
+ end
11
+ end
12
+
@@ -0,0 +1,9 @@
1
+ class AddRowColToSquares < ActiveRecord::Migration[5.2]
2
+ def change
3
+ add_column :layers_of_london_booth_map_tool_squares, :row, :int
4
+ add_column :layers_of_london_booth_map_tool_squares, :col, :int
5
+
6
+
7
+ end
8
+ end
9
+
@@ -0,0 +1,5 @@
1
+ class AddUserTrackingToSquare < ActiveRecord::Migration[5.2]
2
+ def change
3
+ add_column :layers_of_london_booth_map_tool_squares, :user_id, :integer
4
+ end
5
+ end
@@ -0,0 +1,28 @@
1
+ module MapTool
2
+ class GridGenerator < ::Rails::Generators::Base
3
+ desc "Generate grid squares in a pattern from the configured north_west_extent to the south_east_extent, of size square_size"
4
+ def create_squares
5
+ config = LayersOfLondon::Booth::MapTool.configuration
6
+
7
+ squares_y = config.squares_y
8
+ squares_x = config.squares_x
9
+ north_west = config.north_west
10
+ row_north_west = north_west
11
+
12
+ squares_y.times do |row|
13
+ puts "Creating row #{row}"
14
+ square_north_west = row_north_west
15
+ square = nil
16
+ squares_x.times do |col|
17
+ puts "\tCreating column #{col}"
18
+ square = LayersOfLondon::Booth::MapTool::Square.create(north_west_lat: square_north_west.lat, north_west_lng: square_north_west.lng, row: row, col: col)
19
+ # get the next square's northwest corner by moving east (90º) by the number of columns from the row's northwest
20
+ square_north_west = square.north_east
21
+ end
22
+ # increment row_north_west by square_size, southwards, ready for the next iteration
23
+ row_north_west = LayersOfLondon::Booth::MapTool::Square.find_by(row: row, col: 0).south_west
24
+ end
25
+
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,46 @@
1
+ require 'geokit'
2
+
3
+ require "layers_of_london/booth/map_tool/engine"
4
+
5
+ module LayersOfLondon
6
+ module Booth
7
+ module MapTool
8
+ class << self
9
+ attr_accessor :configuration
10
+ end
11
+
12
+ def self.configure
13
+ self.configuration ||= Configuration.new
14
+ yield(configuration)
15
+ end
16
+
17
+ class Configuration
18
+ attr_accessor :square_size, :north_west_extent, :south_east_extent
19
+
20
+ def north_west
21
+ @north_west ||= Geokit::LatLng.new(*@north_west_extent)
22
+ end
23
+
24
+ def south_east
25
+ @south_east ||= Geokit::LatLng.new(*@south_east_extent)
26
+ end
27
+
28
+ def north_east
29
+ @north_east ||= Geokit::LatLng.new(north_west.lat, south_east.lng)
30
+ end
31
+
32
+ def south_west
33
+ @south_west ||= Geokit::LatLng.new(south_east.lat, north_west.lng)
34
+ end
35
+
36
+ def squares_x
37
+ @squares_x ||= (north_west.distance_to(north_east, units: :meters) / @square_size).ceil
38
+ end
39
+
40
+ def squares_y
41
+ @squares_y ||= (north_west.distance_to(south_west, units: :meters) / @square_size).ceil
42
+ end
43
+ end
44
+ end
45
+ end
46
+ end
@@ -0,0 +1,27 @@
1
+ module LayersOfLondon
2
+ module Booth
3
+ module MapTool
4
+ class Engine < ::Rails::Engine
5
+ isolate_namespace LayersOfLondon::Booth::MapTool
6
+
7
+ config.before_initialize do
8
+ LayersOfLondon::Booth::MapTool.configure {} if LayersOfLondon::Booth::MapTool.configuration.nil?
9
+ end
10
+
11
+ initializer :append_migrations do |app|
12
+ unless app.root.to_s.match root.to_s
13
+ config.paths["db/migrate"].expanded.each do |path|
14
+ app.config.paths["db/migrate"] << path
15
+ end
16
+ end
17
+ end
18
+
19
+ initializer "configure_booth_maptool" do
20
+ LayersOfLondon::Booth::MapTool.configure do |config|
21
+ config.square_size = LayersOfLondon::Booth::MapTool.configuration.square_size
22
+ end
23
+ end
24
+ end
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,7 @@
1
+ module LayersOfLondon
2
+ module Booth
3
+ module MapTool
4
+ VERSION = '0.1.0'
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,4 @@
1
+ # desc "Explaining what the task does"
2
+ # task :layers_of_london_booth_map_tool do
3
+ # # Task goes here
4
+ # end
metadata ADDED
@@ -0,0 +1,164 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: layers_of_london-booth-map_tool
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Paul Hendrick
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2019-08-13 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rails
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '5.2'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '5.2'
27
+ - !ruby/object:Gem::Dependency
28
+ name: pundit
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '2.0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '2.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: aasm
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '5.0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '5.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: geokit
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: sqlite3
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '1.0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '1.0'
83
+ description: Booth poverty map tool API for Layers Of London
84
+ email:
85
+ - paul@error.agency
86
+ executables: []
87
+ extensions: []
88
+ extra_rdoc_files: []
89
+ files:
90
+ - LICENSE
91
+ - README.md
92
+ - Rakefile
93
+ - app/assets/config/layers_of_london_booth_map_tool_manifest.js
94
+ - app/assets/javascripts/layers_of_london/booth/map_tool/application.js
95
+ - app/assets/javascripts/layers_of_london/booth/map_tool/maptools.js
96
+ - app/assets/javascripts/layers_of_london/booth/map_tool/polygons.js
97
+ - app/assets/javascripts/layers_of_london/booth/map_tool/squares.js
98
+ - app/assets/stylesheets/layers_of_london/booth/map_tool/application.css
99
+ - app/assets/stylesheets/layers_of_london/booth/map_tool/maptools.css
100
+ - app/assets/stylesheets/layers_of_london/booth/map_tool/polygons.css
101
+ - app/assets/stylesheets/layers_of_london/booth/map_tool/squares.css
102
+ - app/controllers/layers_of_london/booth/map_tool/application_controller.rb
103
+ - app/controllers/layers_of_london/booth/map_tool/maptools_controller.rb
104
+ - app/controllers/layers_of_london/booth/map_tool/polygons_controller.rb
105
+ - app/controllers/layers_of_london/booth/map_tool/squares_controller.rb
106
+ - app/helpers/layers_of_london/booth/map_tool/application_helper.rb
107
+ - app/helpers/layers_of_london/booth/map_tool/maptools_helper.rb
108
+ - app/helpers/layers_of_london/booth/map_tool/polygons_helper.rb
109
+ - app/helpers/layers_of_london/booth/map_tool/squares_helper.rb
110
+ - app/jobs/layers_of_london/booth/map_tool/application_job.rb
111
+ - app/mailers/layers_of_london/booth/map_tool/application_mailer.rb
112
+ - app/models/layers_of_london/booth/map_tool/application_record.rb
113
+ - app/models/layers_of_london/booth/map_tool/polygon.rb
114
+ - app/models/layers_of_london/booth/map_tool/square.rb
115
+ - app/policies/layers_of_london/booth/map_tool/polygon_policy.rb
116
+ - app/views/layers_of_london/booth/map_tool/maptools/show.html.erb
117
+ - app/views/layers_of_london/booth/map_tool/polygons/create.html.erb
118
+ - app/views/layers_of_london/booth/map_tool/polygons/destroy.html.erb
119
+ - app/views/layers_of_london/booth/map_tool/polygons/index.html.erb
120
+ - app/views/layers_of_london/booth/map_tool/polygons/update.html.erb
121
+ - app/views/layers_of_london/booth/map_tool/squares/create.html.erb
122
+ - app/views/layers_of_london/booth/map_tool/squares/edit.html.erb
123
+ - app/views/layers_of_london/booth/map_tool/squares/index.html.erb
124
+ - app/views/layers_of_london/booth/map_tool/squares/show.html.erb
125
+ - app/views/layers_of_london/booth/map_tool/squares/update.html.erb
126
+ - app/views/layouts/layers_of_london/booth/map_tool/application.html.erb
127
+ - config/routes.rb
128
+ - db/migrate/20190724120049_create_layers_of_london_booth_map_tool_squares.rb
129
+ - db/migrate/20190724120136_create_layers_of_london_booth_map_tool_polygons.rb
130
+ - db/migrate/20190731111508_add_aasm_state_to_squares.rb
131
+ - db/migrate/20190802100700_add_locations_to_squares.rb
132
+ - db/migrate/20190802120000_add_north_west_south_east_to_squares.rb
133
+ - db/migrate/20190806161900_add_row_col_to_squares.rb
134
+ - db/migrate/20190809151958_add_user_tracking_to_square.rb
135
+ - lib/generators/map_tool/grid_generator.rb
136
+ - lib/layers_of_london/booth/map_tool.rb
137
+ - lib/layers_of_london/booth/map_tool/engine.rb
138
+ - lib/layers_of_london/booth/map_tool/version.rb
139
+ - lib/tasks/layers_of_london/booth/map_tool_tasks.rake
140
+ homepage: https://layersoflondon.org
141
+ licenses:
142
+ - GPL-3.0
143
+ metadata: {}
144
+ post_install_message:
145
+ rdoc_options: []
146
+ require_paths:
147
+ - lib
148
+ required_ruby_version: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - ">="
151
+ - !ruby/object:Gem::Version
152
+ version: '0'
153
+ required_rubygems_version: !ruby/object:Gem::Requirement
154
+ requirements:
155
+ - - ">="
156
+ - !ruby/object:Gem::Version
157
+ version: '0'
158
+ requirements: []
159
+ rubyforge_project:
160
+ rubygems_version: 2.7.6
161
+ signing_key:
162
+ specification_version: 4
163
+ summary: Booth poverty map tool API for Layers Of London
164
+ test_files: []