-
-
Notifications
You must be signed in to change notification settings - Fork 277
/
Copy pathcity.rb
111 lines (103 loc) · 3.3 KB
/
city.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
# frozen_string_literal: true
class Avo::Resources::City < Avo::BaseResource
self.search = {
query: -> { query.ransack(id_eq: params[:q], m: "or").result(distinct: false) }
}
self.extra_params = [city: [:name, :metadata, :coordinates, :city_center_area, :description, :population, :is_capital, :image_url, :tiny_description, :status, features: {}, metadata: {}]]
self.default_view_type = :map
self.map_view = {
mapkick_options: {
controls: true
},
record_marker: -> {
{
latitude: record.latitude,
longitude: record.longitude,
tooltip: record.name
}
},
extra_markers: -> do
[
{
latitude: params[:lat] || 37.780411,
longitude: params[:long] || -25.497047,
label: "Açores",
tooltip: "São Miguel",
color: "#0F0"
}
]
end,
table: {
visible: true,
layout: :bottom
}
}
def base_fields
field :preview, as: :preview
field :id, as: :id
field :coordinates,
as: :location,
show_on: :preview,
stored_as: [:latitude, :longitude],
mapkick_options: {
style: "mapbox://styles/mapbox/satellite-v9",
markers: {color: "#FFC0CB"}
}
field :city_center_area,
as: :area,
geometry: :polygon,
mapkick_options: {
style: "mapbox://styles/mapbox/satellite-v9",
controls: true
},
datapoint_options: {
label: "Paris City Center",
tooltip: "Bonjour mes amis!",
color: "#009099"
}
field :description,
as: :trix,
attachment_key: :description_file,
visible: -> { resource.params[:show_native_fields].blank? }
field :metadata, as: :code, pretty_generated: true
field :created_at, as: :date_time, filterable: true
end
# Notice that even if those fields are hidden on the form, we still include them on `form_fields`.
# This is because we want to be able to edit them using the tool.
# When submitting the form, we need this fields declared on the resource in order to know how to process them and fill the record.
def tool_fields
field :name, as: :text, hide_on: [:index, :forms], copyable: true
with_options hide_on: :forms do
field :name, as: :text, filterable: true, name: "name (click to edit)", only_on: :index do
path, data = Avo::Actions::City::Update.link_arguments(
resource: resource,
arguments: {
cities: [resource.record.to_param],
render_name: true
}
)
link_to resource.record.name, path, data: data
end
field :population, as: :number, filterable: true, decorate: -> { number_with_delimiter(value, delimiter: ".") }
field :is_capital, as: :boolean, filterable: true
field :features, as: :key_value
field :image_url, as: :external_image
field :tiny_description, as: :easy_mde
field :status, as: :badge, enum: ::City.statuses
end
end
def display_fields
base_fields
tool_fields
end
def form_fields
base_fields
tool_fields
tool Avo::ResourceTools::CityEditor, only_on: :forms
end
def actions
action Avo::Actions::City::PreUpdate
action Avo::Actions::City::Update
action Avo::Actions::Sub::DummyAction, arguments: {test_action_name: " city resource"}
end
end