aboutsummaryrefslogtreecommitdiff
path: root/app/models
diff options
context:
space:
mode:
authorhellekin <hellekin@cepheide.org>2021-01-22 05:32:15 +0100
committerhellekin <hellekin@cepheide.org>2021-01-22 05:32:15 +0100
commitb54a8458d5029b3494165b7430e21b3ae34ecc0c (patch)
tree32ea6fc6b8774f672325fec52f0ffc97229a9568 /app/models
parent1c1aead78192982e221179de6688b944e5b01bf6 (diff)
downloadincommon-map-b54a8458d5029b3494165b7430e21b3ae34ecc0c.tar.gz
Upgrade Rails and add StimulusJS support
Diffstat (limited to 'app/models')
-rw-r--r--app/models/agency.rb28
-rw-r--r--app/models/resource.rb20
2 files changed, 16 insertions, 32 deletions
diff --git a/app/models/agency.rb b/app/models/agency.rb
index 7ffe489..842e8bd 100644
--- a/app/models/agency.rb
+++ b/app/models/agency.rb
@@ -3,34 +3,6 @@
# SPDX-License-Identifier: AGPL-3.0-or-later
class Agency < ApplicationRecord
- include Bitfields
-
belongs_to :agent
belongs_to :user
-
- bitfield :roles, :observer, :editor, :maintainer, :leader
-
- class << self
- # Grant role in agent to user
- def grant(agent, user, role)
- r = find_or_create_by(agent: agent, user: user)
- r&.public_send("#{role}=", true) && r&.save
- end
-
- # Revoke role in agent from user
- def revoke(agent, user, role)
- r = find_by(agent: agent, user: user)
- r&.public_send("#{role}=", false) && r&.save
- end
- end
-
- # Grant role to current user in current agent
- def grant(role)
- self.class.grant(agent, user, role)
- end
-
- # Revoke role from current user in current agent
- def revoke(role)
- self.class.revoke(agent, user, role)
- end
end
diff --git a/app/models/resource.rb b/app/models/resource.rb
index 8df106c..bde0c56 100644
--- a/app/models/resource.rb
+++ b/app/models/resource.rb
@@ -44,17 +44,17 @@ class Resource < ApplicationRecord
# You can use, e.g.: res.longitude = 0.123
def longitude
- feature['geometry']['coordinates'][0]
+ format('%<lon>3.7f', lon: feature['geometry']['coordinates'][0]).to_f
end
def longitude=(value)
- feature['geometry']['coordinates'][0] = value
+ feature['geometry']['coordinates'][0] = format('%<lon>3.7f', lon: value).to_f
end
# You can use, e.g.: res.latitude = 0.123
def latitude
- feature['geometry']['coordinates'][1]
+ format('%<lat>2.7f', lat: feature['geometry']['coordinates'][1]).to_f
end
def latitude=(value)
- feature['geometry']['coordinates'][1] = value
+ feature['geometry']['coordinates'][1] = format('%<lat>2.7f', lat: value).to_f
end
# Properties
@@ -68,4 +68,16 @@ class Resource < ApplicationRecord
feature['properties'][prop.to_s] = v
end
end
+
+ # Poor man's GeoJSON output
+ def to_geojson
+ out = feature.dup
+ # Convert original Dewey IDs with local Section IDs
+ out['properties']['categories'] = Section.where(dewey_id: out['properties']['categories']).pluck(:id)
+ # Add IN COMMON Resource UUID property
+ out['properties']['uuid'] = uuid
+ # Add IN COMMON Agent UUID property
+ out['properties']['agent_uuid'] = agent.uuid
+ out
+ end
end