decidim-decidim_geo 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (146) hide show
  1. checksums.yaml +7 -0
  2. data/LICENSE-AGPLv3.txt +661 -0
  3. data/README.md +172 -0
  4. data/Rakefile +119 -0
  5. data/app/cells/decidim/geo/content_blocks/geo_maps/show.erb +15 -0
  6. data/app/cells/decidim/geo/content_blocks/geo_maps_cell.rb +114 -0
  7. data/app/cells/decidim/geo/content_blocks/geo_maps_settings_form_cell.rb +14 -0
  8. data/app/cells/decidim/geo/geo_collection_map/show.erb +4 -0
  9. data/app/cells/decidim/geo/geo_collection_map_cell.rb +102 -0
  10. data/app/commands/decidim/admin/create_scope.rb +56 -0
  11. data/app/commands/decidim/admin/create_scope_type.rb +47 -0
  12. data/app/commands/decidim/admin/update_scope.rb +60 -0
  13. data/app/commands/decidim/admin/update_scope_type.rb +62 -0
  14. data/app/commands/decidim/geo/admin/create_shapefile.rb +51 -0
  15. data/app/commands/decidim/geo/admin/update_geo_config.rb +54 -0
  16. data/app/commands/decidim/geo/command.rb +14 -0
  17. data/app/controllers/decidim/admin/scopes_controller.rb +115 -0
  18. data/app/controllers/decidim/geo/admin/application_controller.rb +21 -0
  19. data/app/controllers/decidim/geo/admin/geo_configs_controller.rb +44 -0
  20. data/app/controllers/decidim/geo/admin/shapefiles_controller.rb +41 -0
  21. data/app/controllers/decidim/geo/application_controller.rb +13 -0
  22. data/app/controllers/decidim/geo/shapefile_controller.rb +11 -0
  23. data/app/forms/decidim/admin/scope_form.rb +43 -0
  24. data/app/forms/decidim/admin/scope_type_form.rb +27 -0
  25. data/app/forms/decidim/geo/admin/geo_config_form.rb +20 -0
  26. data/app/forms/decidim/geo/admin/shapefile_form.rb +23 -0
  27. data/app/helpers/decidim/admin/scopes_helper.rb +72 -0
  28. data/app/jobs/decidim/geo/shp2pgsql_job.rb +14 -0
  29. data/app/models/decidim/debates/debate.rb +226 -0
  30. data/app/models/decidim/geo/application_record.rb +10 -0
  31. data/app/models/decidim/geo/geo_config.rb +28 -0
  32. data/app/models/decidim/geo/shapedata.rb +23 -0
  33. data/app/models/decidim/geo/shapefile.rb +27 -0
  34. data/app/models/decidim/geo/space_location.rb +16 -0
  35. data/app/models/decidim/scope.rb +111 -0
  36. data/app/models/decidim/scope_type.rb +26 -0
  37. data/app/overrides/decidim/assemblies/admin/assemblies/_form/insert_location_form.html.erb.deface +13 -0
  38. data/app/overrides/decidim/assemblies/assemblies/show/insert_location.html.erb.deface +7 -0
  39. data/app/overrides/decidim/participatory_processes/admin/participatory_processes/_form/insert_location_form.html.erb.deface +13 -0
  40. data/app/overrides/decidim/participatory_processes/participatory_process_groups/show/insert_map.html.erb.deface +6 -0
  41. data/app/overrides/layouts/decidim/_assembly_header/insert_map.html.erb.deface +25 -0
  42. data/app/overrides/layouts/decidim/_process_header/insert_map.html.erb.deface +22 -0
  43. data/app/overrides/layouts/decidim/_wrapper/insert_map.html.erb.deface +5 -0
  44. data/app/overrides/remove_default_meetings_map.rb +4 -0
  45. data/app/overrides/remove_default_proposals_map.rb +4 -0
  46. data/app/packs/entrypoints/decidim_geo.js +3 -0
  47. data/app/packs/images/decidim/geo/not-geolocated.svg +3 -0
  48. data/app/packs/src/decidim/geo/actions/index.js +25 -0
  49. data/app/packs/src/decidim/geo/api/index.js +53 -0
  50. data/app/packs/src/decidim/geo/api/queries.js +77 -0
  51. data/app/packs/src/decidim/geo/bootstrap.js +6 -0
  52. data/app/packs/src/decidim/geo/index.js +101 -0
  53. data/app/packs/src/decidim/geo/models/configStore.js +44 -0
  54. data/app/packs/src/decidim/geo/models/dropdownFilterStore.js +65 -0
  55. data/app/packs/src/decidim/geo/models/filterStore.js +121 -0
  56. data/app/packs/src/decidim/geo/models/geoDatasourceNode/GeoDatasourceNode.js +124 -0
  57. data/app/packs/src/decidim/geo/models/geoDatasourceNode/index.js +1 -0
  58. data/app/packs/src/decidim/geo/models/geoScope/GeoScope.js +128 -0
  59. data/app/packs/src/decidim/geo/models/geoScope/index.js +1 -0
  60. data/app/packs/src/decidim/geo/models/geoStore.js +118 -0
  61. data/app/packs/src/decidim/geo/models/pointStore.js +134 -0
  62. data/app/packs/src/decidim/geo/models/scopeDropdownStore.js +20 -0
  63. data/app/packs/src/decidim/geo/ui/DrawerDetail/fallback.js +42 -0
  64. data/app/packs/src/decidim/geo/ui/DrawerDetail/index.js +2 -0
  65. data/app/packs/src/decidim/geo/ui/DrawerDetail/meetings.js +75 -0
  66. data/app/packs/src/decidim/geo/ui/DrawerMenuItem/fallback.js +45 -0
  67. data/app/packs/src/decidim/geo/ui/DrawerMenuItem/index.js +2 -0
  68. data/app/packs/src/decidim/geo/ui/DrawerMenuItem/meetings.js +62 -0
  69. data/app/packs/src/decidim/geo/ui/createClasses.js +7 -0
  70. data/app/packs/src/decidim/geo/ui/createCustomMarker.js +14 -0
  71. data/app/packs/src/decidim/geo/ui/createDomElement.js +2 -0
  72. data/app/packs/src/decidim/geo/ui/createDrawer.js +170 -0
  73. data/app/packs/src/decidim/geo/ui/createDrawerActions.js +197 -0
  74. data/app/packs/src/decidim/geo/ui/createFilterDropdown.js +320 -0
  75. data/app/packs/src/decidim/geo/ui/createGeoScopeLayer.js +20 -0
  76. data/app/packs/src/decidim/geo/ui/createGeoScopeMenuItem.js +8 -0
  77. data/app/packs/src/decidim/geo/ui/createNodeMarker.js +9 -0
  78. data/app/packs/src/decidim/geo/ui/createNodeMenuItem.js +13 -0
  79. data/app/packs/src/decidim/geo/ui/index.js +8 -0
  80. data/app/packs/src/decidim/geo/ui/initMap.js +22 -0
  81. data/app/packs/src/decidim/geo/utils/index.js +30 -0
  82. data/app/packs/src/decidim/geo/utils/saveConfig.js +15 -0
  83. data/app/packs/stylesheets/decidim/geo/_geo.scss +2 -0
  84. data/app/packs/stylesheets/decidim/geo/geo/_decidim_geo_decidimGeo.scss +476 -0
  85. data/app/packs/stylesheets/decidim/geo/geo/_decidim_geo_override.scss +65 -0
  86. data/app/permissions/decidim/geo/admin/permissions.rb +24 -0
  87. data/app/permissions/decidim/geo/permissions.rb +15 -0
  88. data/app/uploaders/decidim/geo/shapefile_uploader.rb +14 -0
  89. data/app/validators/geocoding_validator.rb +30 -0
  90. data/app/views/decidim/admin/scope_types/_form.html.erb +10 -0
  91. data/app/views/decidim/admin/scope_types/index.html.erb +46 -0
  92. data/app/views/decidim/admin/scopes/_form.html.erb +20 -0
  93. data/app/views/decidim/admin/scopes/index.html.erb +55 -0
  94. data/app/views/decidim/geo/admin/geo_configs/_form.html.erb +47 -0
  95. data/app/views/decidim/geo/admin/geo_configs/index.html.erb +8 -0
  96. data/app/views/decidim/geo/admin/shapefiles/_form.html.erb +29 -0
  97. data/app/views/decidim/geo/admin/shapefiles/index.html.erb +38 -0
  98. data/app/views/decidim/geo/admin/shapefiles/new.html.erb +8 -0
  99. data/app/views/layouts/decidim/decidim_geo/admin/application.html.erb +19 -0
  100. data/config/assets.rb +9 -0
  101. data/config/i18n-tasks.yml +10 -0
  102. data/config/locales/de.yml +102 -0
  103. data/config/locales/en.yml +108 -0
  104. data/config/locales/fr.yml +102 -0
  105. data/db/migrate/20221019184712_add_postgis_extension_to_database.rb +5 -0
  106. data/db/migrate/20221025195520_create_decidim_geo.rb +22 -0
  107. data/db/migrate/20231013082325_create_decidim_geo_config.rb +11 -0
  108. data/db/migrate/20231206115531_add_spaces_config_to_decidim_geo_configs.rb +6 -0
  109. data/db/migrate/20240309004347_add_organization_to_shapefiles.rb +6 -0
  110. data/db/migrate/20240326052727_create_space_locations.rb +18 -0
  111. data/lib/decidim/api/geo_config_type.rb +15 -0
  112. data/lib/decidim/api/geo_coordinates_type.rb +22 -0
  113. data/lib/decidim/api/geo_datasource_type.rb +147 -0
  114. data/lib/decidim/api/geo_dates_type.rb +15 -0
  115. data/lib/decidim/api/geo_query_extension.rb +25 -0
  116. data/lib/decidim/api/geo_scope_api_type.rb +26 -0
  117. data/lib/decidim/api/geo_shapedata_type.rb +18 -0
  118. data/lib/decidim/api/geo_shapefile_type.rb +22 -0
  119. data/lib/decidim/api/input_filters/assembly_input_filter.rb +13 -0
  120. data/lib/decidim/api/input_filters/geo_datasource_input_filter.rb +18 -0
  121. data/lib/decidim/api/input_filters/geoencoded_input_filter.rb +13 -0
  122. data/lib/decidim/api/input_filters/has_scopeable_input_filter.rb +17 -0
  123. data/lib/decidim/api/input_filters/process_input_filter.rb +13 -0
  124. data/lib/decidim/api/input_filters/resource_type_input_filter.rb +13 -0
  125. data/lib/decidim/api/input_filters/scope_input_filter.rb +13 -0
  126. data/lib/decidim/api/input_filters/time_input_filter.rb +13 -0
  127. data/lib/decidim/api/meetings_input_filter.rb +14 -0
  128. data/lib/decidim/api/query_extension.rb +320 -0
  129. data/lib/decidim/api/shapefile_query_extention.rb +18 -0
  130. data/lib/decidim/api/shapefile_type.rb +18 -0
  131. data/lib/decidim/decidim_geo/admin.rb +10 -0
  132. data/lib/decidim/decidim_geo/admin_engine.rb +69 -0
  133. data/lib/decidim/decidim_geo/api.rb +23 -0
  134. data/lib/decidim/decidim_geo/engine.rb +58 -0
  135. data/lib/decidim/decidim_geo/load_shp/app_load_shp.rb +85 -0
  136. data/lib/decidim/decidim_geo/space_location/assembly_create_command_override.rb +26 -0
  137. data/lib/decidim/decidim_geo/space_location/assembly_form_override.rb +33 -0
  138. data/lib/decidim/decidim_geo/space_location/assembly_update_command_override.rb +21 -0
  139. data/lib/decidim/decidim_geo/space_location/participatory_process_command_override.rb +21 -0
  140. data/lib/decidim/decidim_geo/space_location/participatory_process_form_override.rb +33 -0
  141. data/lib/decidim/decidim_geo/space_location/space_override.rb +15 -0
  142. data/lib/decidim/decidim_geo/test/factories.rb +13 -0
  143. data/lib/decidim/decidim_geo/version.rb +14 -0
  144. data/lib/decidim/decidim_geo.rb +25 -0
  145. data/lib/tasks/decidim_geo_webpacker_tasks.rake +61 -0
  146. metadata +335 -0
@@ -0,0 +1,60 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Decidim
4
+ module Admin
5
+ # A command with all the business logic when updating a scope.
6
+ class UpdateScope < Decidim::Geo::Command
7
+ # Public: Initializes the command.
8
+ #
9
+ # scope - The Scope to update
10
+ # form - A form object with the params.
11
+ def initialize(scope, form)
12
+ @scope = scope
13
+ @form = form
14
+ end
15
+
16
+ # Executes the command. Broadcasts these events:
17
+ #
18
+ # - :ok when everything is valid.
19
+ # - :invalid if the form wasn't valid and we couldn't proceed.
20
+ #
21
+ # Returns nothing.
22
+ def call
23
+ return broadcast(:invalid) if form.invalid?
24
+
25
+ update_scope
26
+ broadcast(:ok)
27
+ end
28
+
29
+ private
30
+
31
+ attr_reader :form
32
+
33
+ def update_scope
34
+ Decidim.traceability.update!(
35
+ @scope,
36
+ form.current_user,
37
+ attributes,
38
+ extra: {
39
+ parent_name: @scope.parent.try(:name),
40
+ scope_type_name: form.scope_type.try(:name)
41
+ }
42
+ )
43
+ @scope.shapedata = shapedata
44
+ @scope.save!
45
+ end
46
+
47
+ def shapedata
48
+ Decidim::Geo::Shapedata.find_by_id(form.shapedata)
49
+ end
50
+
51
+ def attributes
52
+ {
53
+ name: form.name,
54
+ code: form.code,
55
+ scope_type: form.scope_type
56
+ }
57
+ end
58
+ end
59
+ end
60
+ end
@@ -0,0 +1,62 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Decidim
4
+ module Admin
5
+ # A command with all the business logic when updating a scope type.
6
+ class UpdateScopeType < Decidim::Geo::Command
7
+ # Public: Initializes the command.
8
+ #
9
+ # scope_type - The ScopeType to update
10
+ # form - A form object with the params.
11
+ # current_user - nil for compatibility with 0.26
12
+ def initialize(scope_type, form, user = nil)
13
+ @scope_type = scope_type
14
+ @form = form
15
+ @user = user
16
+ end
17
+
18
+ # Executes the command. Broadcasts these events:
19
+ #
20
+ # - :ok when everything is valid.
21
+ # - :invalid if the form wasn't valid and we couldn't proceed.
22
+ #
23
+ # Returns nothing.
24
+ def call
25
+ return broadcast(:invalid) if form.invalid?
26
+
27
+ update_scope_type
28
+ broadcast(:ok)
29
+ end
30
+
31
+ private
32
+
33
+ attr_reader :form
34
+
35
+ def update_scope_type
36
+ @scope_type.shapefile = shapefile
37
+ @scope_type.save!
38
+ @scope_type.update!(attributes)
39
+ traceability_update
40
+ end
41
+
42
+ def traceability_update
43
+ Decidim.traceability.update!(
44
+ @scope_type,
45
+ @user,
46
+ attributes
47
+ )
48
+ end
49
+
50
+ def shapefile
51
+ Decidim::Geo::Shapefile.find_by_id(form.shapefile)
52
+ end
53
+
54
+ def attributes
55
+ {
56
+ name: form.name,
57
+ plural: form.plural
58
+ }
59
+ end
60
+ end
61
+ end
62
+ end
@@ -0,0 +1,51 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Decidim
4
+ module Geo
5
+ module Admin
6
+ # A command with all the business logic when a user creates a new proposal.
7
+ class CreateShapefile < Decidim::Geo::Command
8
+ # Public: Initializes the command.
9
+ #
10
+ # form - A form object with the params.
11
+ def initialize(form)
12
+ @form = form
13
+ end
14
+
15
+ # Executes the command. Broadcasts these events:
16
+ #
17
+ # - :ok when everything is valid, together with the shapefile.
18
+ # - :invalid if the form wasn't valid and we couldn't proceed.
19
+ #
20
+ # Returns nothing.
21
+ def call
22
+ return broadcast(:invalid) if form.invalid?
23
+
24
+ create_shapefile
25
+ load_shapefile = LoadShp::AppLoadShp.new(@shapefile)
26
+ load_shapefile.run!
27
+ broadcast(:ok, @shapefile)
28
+
29
+ rescue Exception => e
30
+ @shapefile.destroy
31
+ broadcast(:invalid, "#{e}")
32
+ end
33
+
34
+ private
35
+
36
+ attr_reader :form
37
+
38
+ def create_shapefile
39
+ @shapefile = Decidim::Geo::Shapefile.create!(
40
+ title: form.title,
41
+ description: form.description,
42
+ shapefile: form.shapefile,
43
+ organization: form.organization
44
+ )
45
+ end
46
+
47
+
48
+ end
49
+ end
50
+ end
51
+ end
@@ -0,0 +1,54 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Decidim
4
+ module Geo
5
+ module Admin
6
+ # A command with all the business logic when updating a geo_config.
7
+ class UpdateGeoConfig < Decidim::Geo::Command
8
+ # Public: Initializes the command.
9
+ #
10
+ # geo_config - The geo_config to update
11
+ # form - A form object with the params.
12
+ def initialize(geo_config, form)
13
+ @geo_config = geo_config
14
+ @form = form
15
+ end
16
+
17
+ # Executes the command. Broadcasts these events:
18
+ #
19
+ # - :ok when everything is valid.
20
+ # - :invalid if the form wasn't valid and we couldn't proceed.
21
+ #
22
+ # Returns nothing.
23
+ def call
24
+ return broadcast(:invalid) if form.invalid?
25
+ @geo_config.nil? ? create_geo_config : update_geo_config
26
+ broadcast(:ok)
27
+ end
28
+
29
+ private
30
+
31
+ attr_reader :form
32
+
33
+ def update_geo_config
34
+ @geo_config.update(attributes)
35
+ end
36
+
37
+ def create_geo_config
38
+ @geo_config = Decidim::Geo::GeoConfig.create!(attributes)
39
+ end
40
+
41
+ def attributes
42
+ {
43
+ longitude: form.longitude,
44
+ latitude: form.latitude,
45
+ zoom: form.zoom,
46
+ tile: form.tile,
47
+ only_assemblies: form.only_assemblies,
48
+ only_processes: form.only_processes
49
+ }
50
+ end
51
+ end
52
+ end
53
+ end
54
+ end
@@ -0,0 +1,14 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Decidim
4
+ module Geo
5
+ # maintains compatibility with v0.26 which uses Rectify
6
+ if defined? ::Decidim::Command
7
+ class Command < ::Decidim::Command
8
+ end
9
+ else
10
+ class Command < ::Rectify::Command
11
+ end
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,115 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Decidim
4
+ module Admin
5
+ # Controller that allows managing all scopes at the admin panel.
6
+ #
7
+ class ScopesController < Decidim::Admin::ApplicationController
8
+ helper_method :scope, :parent_scope, :add_scope_path, :current_scopes_path
9
+ layout "decidim/admin/settings"
10
+
11
+ def index
12
+ enforce_permission_to :read, :scope
13
+ field = Arel::Nodes::InfixOperation.new("->", Decidim::Scope.arel_table[:name], Arel::Nodes.build_quoted(I18n.locale))
14
+ @scopes = children_scopes.order(Arel::Nodes::InfixOperation.new("", field, Arel.sql("ASC")))
15
+ end
16
+
17
+ def new
18
+ enforce_permission_to :create, :scope
19
+ @form = form(ScopeForm).instance
20
+ end
21
+
22
+ def create
23
+ enforce_permission_to :create, :scope
24
+ @form = form(ScopeForm).from_params(params)
25
+ CreateScope.call(@form, parent_scope) do
26
+ on(:ok) do |scope|
27
+ flash[:notice] = I18n.t("scopes.create.success", scope: "decidim.admin")
28
+ if has_geo_scope_type? && !has_shapedata?
29
+ redirect_to Decidim::Admin::Engine.routes.url_helpers.edit_scope_path(scope[:scope])
30
+ else
31
+ redirect_to current_scopes_path
32
+ end
33
+ end
34
+
35
+ on(:invalid) do
36
+ flash.now[:alert] = I18n.t("scopes.create.error", scope: "decidim.admin")
37
+ render :new
38
+ end
39
+ end
40
+ end
41
+
42
+ def edit
43
+ enforce_permission_to :update, :scope, scope: scope
44
+ @form = form(ScopeForm).from_model(scope)
45
+ end
46
+
47
+ def update
48
+ enforce_permission_to :update, :scope, scope: scope
49
+ @form = form(ScopeForm).from_params(params)
50
+
51
+ UpdateScope.call(scope, @form) do
52
+ on(:ok) do
53
+ flash[:notice] = I18n.t("scopes.update.success", scope: "decidim.admin")
54
+ redirect_to current_scopes_path
55
+ end
56
+
57
+ on(:invalid) do
58
+ flash.now[:alert] = I18n.t("scopes.update.error", scope: "decidim.admin")
59
+ render :edit
60
+ end
61
+ end
62
+ end
63
+
64
+ def destroy
65
+ enforce_permission_to :destroy, :scope, scope: scope
66
+
67
+ DestroyScope.call(scope, current_user) do
68
+ on(:ok) do
69
+ flash[:notice] = I18n.t("scopes.destroy.success", scope: "decidim.admin")
70
+ redirect_to current_scopes_path
71
+ end
72
+ end
73
+ end
74
+
75
+ private
76
+
77
+ def organization_scopes
78
+ current_organization.scopes
79
+ end
80
+
81
+ def parent_scope
82
+ return @parent_scope if defined?(@parent_scope)
83
+
84
+ @parent_scope = scope ? scope.parent : organization_scopes.find_by(id: params[:scope_id])
85
+ end
86
+
87
+ def scope
88
+ return @scope if defined?(@scope)
89
+
90
+ @scope = organization_scopes.find_by(id: params[:id])
91
+ end
92
+
93
+ def children_scopes
94
+ @children_scopes ||= parent_scope ? parent_scope.children : organization_scopes.top_level
95
+ end
96
+
97
+ def current_scopes_path
98
+ if parent_scope
99
+ scope_scopes_path(parent_scope)
100
+ else
101
+ scopes_path
102
+ end
103
+ end
104
+
105
+ def has_geo_scope_type?
106
+ @form.scope_type.present?
107
+ end
108
+
109
+ def has_shapedata?
110
+ @form.shapedata.present?
111
+ end
112
+ end
113
+ end
114
+ end
115
+
@@ -0,0 +1,21 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Decidim
4
+ module Geo
5
+ module Admin
6
+
7
+ # This controller is the abstract class from which all other controllers of
8
+ # this engine inherit.
9
+ #
10
+ # Note that it inherits from `Decidim::Components::BaseController`, which
11
+ # override its layout and provide all kinds of useful methods.
12
+ class ApplicationController < Decidim::Admin::ApplicationController
13
+ def permission_class_chain
14
+ [::Decidim::Geo::Admin::Permissions] + super
15
+ end
16
+
17
+
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,44 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Decidim
4
+ module Geo
5
+ module Admin
6
+ class GeoConfigsController < Decidim::Geo::Admin::ApplicationController
7
+ layout "decidim/decidim_geo/admin/application"
8
+
9
+ before_action :authenticate_user!
10
+
11
+ def index
12
+ @form = form(Decidim::Geo::Admin::GeoConfigForm).from_model(geo_config_default)
13
+ end
14
+
15
+ def create
16
+ update
17
+ end
18
+
19
+ def update
20
+ @form = form(Decidim::Geo::Admin::GeoConfigForm).from_params(params)
21
+
22
+ Admin::UpdateGeoConfig.call(geo_config_default, @form) do
23
+ on(:ok) do
24
+ flash[:notice] = I18n.t("geo_configs.actions.update.success", scope: "decidim.geo.admin")
25
+ end
26
+
27
+ on(:invalid) do
28
+ flash.now[:alert] = @form.errors.full_messages_for(:base).join(',')
29
+ end
30
+
31
+ render action: "index"
32
+ end
33
+ end
34
+
35
+ private
36
+
37
+ def geo_config_default
38
+ Decidim::Geo::GeoConfig.geo_config_default
39
+ end
40
+
41
+ end
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,41 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Decidim
4
+ module Geo
5
+ module Admin
6
+ class ShapefilesController < ApplicationController
7
+ layout "decidim/decidim_geo/admin/application"
8
+ before_action :authenticate_user!
9
+
10
+ def index
11
+ #enforce_permission_to :list
12
+ @shapefiles = Decidim::Geo::Shapefile.all
13
+ end
14
+
15
+ def new
16
+ enforce_permission_to :new, :shapefile
17
+ @form = Decidim::Geo::Admin::ShapefileForm.new
18
+ end
19
+
20
+ def create
21
+ enforce_permission_to :create, :shapefile
22
+ @form = form(Decidim::Geo::Admin::ShapefileForm).from_params(params)
23
+
24
+ return Admin::CreateShapefile.call(@form) do
25
+ on(:invalid) do |message|
26
+ flash.now[:alert] = message || @form.errors.full_messages.join(',') || "Can not upload this shapefile"
27
+ render action: "new"
28
+ end
29
+
30
+ on(:ok) do
31
+ flash[:notice] = I18n.t("shapefiles.actions.create.success", scope: "decidim.geo.admin")
32
+ redirect_to shapefiles_path
33
+ end
34
+
35
+
36
+ end
37
+ end
38
+ end
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Decidim
4
+ module Geo
5
+ # This controller is the abstract class from which all other controllers of
6
+ # this engine inherit.
7
+ #
8
+ # Note that it inherits from `Decidim::Components::BaseController`, which
9
+ # override its layout and provide all kinds of useful methods.
10
+ class ApplicationController < Decidim::Components::BaseController
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Decidim
4
+ module Geo
5
+ class ShapefileController < Decidim::Geo::ApplicationController
6
+ def index
7
+
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,43 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Decidim
4
+ module Admin
5
+ # A form object to create or update scopes.
6
+ class ScopeForm < Form
7
+ include TranslatableAttributes
8
+
9
+ translatable_attribute :name, String
10
+ attribute :organization, Decidim::Organization
11
+ attribute :code, String
12
+ attribute :parent_id, Integer
13
+ attribute :scope_type_id, Integer
14
+
15
+ attribute :shapedata, Decidim::Geo::Shapedata
16
+
17
+ mimic :scope
18
+
19
+ validates :name, translatable_presence: true
20
+ validates :organization, :code, presence: true
21
+ validate :code, :code_uniqueness
22
+
23
+ alias organization current_organization
24
+
25
+ def scope_type
26
+ Decidim::ScopeType.find_by(id: scope_type_id) if scope_type_id
27
+ end
28
+
29
+ def map_model(model)
30
+ self.shapedata = model.shapedata.id unless model.shapedata.nil?
31
+ end
32
+
33
+ private
34
+
35
+ def code_uniqueness
36
+ return unless organization
37
+ return unless organization.scopes.where(code: code).where.not(id: id).any?
38
+
39
+ errors.add(:code, :taken)
40
+ end
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,27 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Decidim
4
+ module Admin
5
+ # A form object to create or update scopes.
6
+ class ScopeTypeForm < Form
7
+ include TranslatableAttributes
8
+
9
+ translatable_attribute :name, String
10
+ translatable_attribute :plural, String
11
+ attribute :organization, Decidim::Organization
12
+
13
+ attribute :shapefile, Decidim::Geo::Shapefile
14
+
15
+ mimic :scope_type
16
+
17
+ validates :name, :plural, translatable_presence: true
18
+ validates :organization, presence: true
19
+
20
+ alias organization current_organization
21
+
22
+ def map_model(model)
23
+ self.shapefile = model.shapefile.id unless model.shapefile.nil?
24
+ end
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,20 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Decidim
4
+ module Geo
5
+ module Admin
6
+ # A form object to be used when admin configure default .
7
+ class GeoConfigForm < Form
8
+
9
+ attribute :longitude, Float
10
+ attribute :latitude, Float
11
+ attribute :zoom, Integer
12
+ attribute :tile, String
13
+ attribute :only_assemblies, Boolean
14
+ attribute :only_processes, Boolean
15
+
16
+ alias organization current_organization
17
+ end
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,23 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Decidim
4
+ module Geo
5
+ module Admin
6
+ # A form object to be used when admin users want to upload a shapefile.
7
+ class ShapefileForm < Form
8
+ include Decidim::HasUploadValidations
9
+
10
+ attribute :title, String
11
+ attribute :description, String
12
+ attribute :shapefile
13
+
14
+ validates :title, :description, :presence => true
15
+ validates :shapefile, passthru: { to: Decidim::Geo::Shapefile }, if: ->(form) { form.shapefile.present? }
16
+
17
+ validates_upload :shapefile, uploader: Decidim::Geo::ShapefileUploader
18
+
19
+ alias organization current_organization
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,72 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Decidim
4
+ module Admin
5
+ # This module includes helpers to show scopes in admin
6
+ module ScopesHelper
7
+ Option = Struct.new(:id, :name)
8
+
9
+ # Public: This helper shows the path to the given scope, linking each ancestor.
10
+ #
11
+ # current_scope - Scope object to show
12
+ #
13
+ def scope_breadcrumbs(current_scope)
14
+ current_scope.part_of_scopes.map do |scope|
15
+ if scope == current_scope
16
+ translated_attribute(scope.name)
17
+ else
18
+ link_to translated_attribute(scope.name), scope_scopes_path(scope)
19
+ end
20
+ end
21
+ end
22
+
23
+ # Public: A formatted collection of scopes for a given organization to be used
24
+ # in forms.
25
+ #
26
+ # organization - Organization object
27
+ #
28
+ # Returns an Array.
29
+ def organization_scope_types(organization = current_organization)
30
+ [Option.new("", "-")] +
31
+ organization.scope_types.map do |scope_type|
32
+ Option.new(scope_type.id, translated_attribute(scope_type.name))
33
+ end
34
+ end
35
+
36
+ def organization_scope_depths(organization = current_organization)
37
+ organization.scope_types.map do |scope_type|
38
+ Option.new(scope_type.id, translated_attribute(scope_type.name))
39
+ end.reverse
40
+ end
41
+
42
+ def shapedata_scope(scope)
43
+ return nil if scope.scope_type.shapefile.nil?
44
+
45
+ shapefile = scope.scope_type.shapefile
46
+ shapedata = shapedata_version_compat(shapefile)
47
+
48
+ shapedata.map do |shp|
49
+ Option.new(shp.id, shp.data)
50
+ end
51
+ end
52
+
53
+ def shapedata_name(scope)
54
+ Decidim::Geo::Shapedata
55
+ .select("data['NAME']")
56
+ .find_by_id(scope.shapedata.id).data
57
+ end
58
+
59
+ private
60
+
61
+ def shapedata_version_compat(shapefile)
62
+ return Decidim::Geo::Shapedata
63
+ .select("id", "data['NAME']")
64
+ .where(decidim_geo_shapefiles_id: shapefile.id).order(:data.name) if Decidim.version.to_f >= 0.27
65
+
66
+ Decidim::Geo::Shapedata
67
+ .select("id", "data['NAME']")
68
+ .where(decidim_geo_shapefiles_id: shapefile.id).order("data['NAME'] ASC")
69
+ end
70
+ end
71
+ end
72
+ end
@@ -0,0 +1,14 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Decidim
4
+ module Geo
5
+ class Shp2pgsqlJob < ApplicationJob
6
+ queue_as :shapefile_loader
7
+
8
+ def perform(shapefile)
9
+ load_shapefile = LoadShp::AppLoadShp.new(shapefile)
10
+ load_shapefile.run!
11
+ end
12
+ end
13
+ end
14
+ end