avo 0.5.0.beta9 → 0.5.0.beta14
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of avo might be problematic. Click here for more details.
- checksums.yaml +4 -4
- data/Gemfile +46 -50
- data/Gemfile.lock +1 -6
- data/Rakefile +14 -14
- data/app/components/avo/common/multiple_file_viewer_component.rb +1 -1
- data/app/components/avo/common/single_file_viewer_component.rb +1 -1
- data/app/components/avo/edit/field_wrapper_component.rb +3 -3
- data/app/components/avo/index/field_wrapper_component.rb +1 -1
- data/app/components/avo/index/grid_item_component.rb +10 -9
- data/app/components/avo/index/resource_controls_component.rb +2 -2
- data/app/components/avo/panel_component.rb +7 -6
- data/app/components/avo/resource_component.rb +4 -3
- data/app/components/avo/show/field_wrapper_component.rb +3 -3
- data/app/components/avo/views/resource_edit_component.rb +4 -3
- data/app/components/avo/views/resource_index_component.rb +8 -7
- data/app/components/avo/views/resource_new_component.rb +4 -3
- data/app/components/avo/views/resource_show_component.rb +21 -21
- data/app/controllers/avo/actions_controller.rb +30 -29
- data/app/controllers/avo/application_controller.rb +113 -126
- data/app/controllers/avo/attachments_controller.rb +3 -3
- data/app/controllers/avo/base_controller.rb +81 -80
- data/app/controllers/avo/home_controller.rb +2 -2
- data/app/controllers/avo/relations_controller.rb +29 -28
- data/app/controllers/avo/resources_controller.rb +1 -1
- data/app/controllers/avo/search_controller.rb +20 -19
- data/app/helpers/avo/application_helper.rb +48 -42
- data/app/helpers/avo/resources_helper.rb +11 -11
- data/app/mailers/avo/application_mailer.rb +2 -2
- data/app/packs/entrypoints/application.js +9 -7
- data/app/packs/images/logo.png +0 -0
- data/app/packs/js/controllers/fields/code_field_controller.js +14 -14
- data/app/packs/js/controllers/filter_controller.js +9 -8
- data/app/packs/js/toastr.js +1 -0
- data/avo.gemspec +30 -31
- data/config/initializers/pagy.rb +1 -1
- data/config/routes.rb +12 -12
- data/config/spring.rb +5 -5
- data/config/webpack/base.js +2 -2
- data/config/webpacker.yml +32 -0
- data/db/factories.rb +3 -5
- data/lib/avo.rb +6 -6
- data/lib/avo/app.rb +18 -18
- data/lib/avo/base_action.rb +20 -20
- data/lib/avo/base_resource.rb +41 -45
- data/lib/avo/configuration.rb +16 -18
- data/lib/avo/engine.rb +18 -18
- data/lib/avo/fields/badge_field.rb +2 -2
- data/lib/avo/fields/base_field.rb +25 -26
- data/lib/avo/fields/belongs_to_field.rb +13 -12
- data/lib/avo/fields/boolean_field.rb +4 -4
- data/lib/avo/fields/boolean_group_field.rb +3 -3
- data/lib/avo/fields/code_field.rb +4 -4
- data/lib/avo/fields/country_field.rb +2 -2
- data/lib/avo/fields/currency_field.rb +3 -3
- data/lib/avo/fields/date_field.rb +3 -3
- data/lib/avo/fields/date_time_field.rb +2 -2
- data/lib/avo/fields/external_image_field.rb +2 -2
- data/lib/avo/fields/field_extensions/has_field_name.rb +2 -2
- data/lib/avo/fields/field_extensions/visible_in_different_views.rb +34 -33
- data/lib/avo/fields/file_field.rb +1 -1
- data/lib/avo/fields/files_field.rb +2 -2
- data/lib/avo/fields/gravatar_field.rb +9 -9
- data/lib/avo/fields/has_and_belongs_to_many_field.rb +1 -1
- data/lib/avo/fields/has_many_field.rb +1 -1
- data/lib/avo/fields/has_one_field.rb +2 -2
- data/lib/avo/fields/heading_field.rb +2 -2
- data/lib/avo/fields/hidden_field.rb +1 -1
- data/lib/avo/fields/id_field.rb +3 -3
- data/lib/avo/fields/key_value_field.rb +12 -12
- data/lib/avo/fields/markdown_field.rb +2 -2
- data/lib/avo/fields/number_field.rb +3 -3
- data/lib/avo/fields/password_field.rb +1 -1
- data/lib/avo/fields/select_field.rb +8 -12
- data/lib/avo/fields/status_field.rb +4 -4
- data/lib/avo/fields/text_field.rb +2 -2
- data/lib/avo/fields/textarea_field.rb +2 -2
- data/lib/avo/fields/trix_field.rb +1 -1
- data/lib/avo/fields_collector.rb +4 -5
- data/lib/avo/filters/base_filter.rb +6 -6
- data/lib/avo/filters/boolean_filter.rb +1 -1
- data/lib/avo/filters/select_filter.rb +1 -1
- data/lib/avo/licensing/h_q.rb +56 -55
- data/lib/avo/licensing/license.rb +5 -5
- data/lib/avo/licensing/license_manager.rb +4 -4
- data/lib/avo/licensing/null_license.rb +2 -2
- data/lib/avo/licensing/pro_license.rb +1 -1
- data/lib/avo/loaders/fields_loader.rb +4 -4
- data/lib/avo/services/authorization_service.rb +2 -2
- data/lib/avo/services/panel_service.rb +4 -4
- data/lib/avo/version.rb +1 -1
- data/lib/generators/avo/action_generator.rb +4 -4
- data/lib/generators/avo/controller_generator.rb +4 -4
- data/lib/generators/avo/filter_generator.rb +5 -5
- data/lib/generators/avo/install_generator.rb +8 -8
- data/lib/generators/avo/locales_generator.rb +5 -5
- data/lib/generators/avo/partials_generator.rb +4 -4
- data/lib/generators/avo/resource_generator.rb +5 -5
- data/lib/generators/avo/templates/action.tt +0 -4
- data/lib/generators/avo/templates/resource/resource.tt +3 -13
- data/lib/tasks/avo_tasks.rake +0 -60
- data/public/avo-packs/css/{application-38e7e91b.css → application-9d115b7e.css} +44 -147
- data/public/avo-packs/css/application-9d115b7e.css.br +0 -0
- data/public/avo-packs/css/application-9d115b7e.css.gz +0 -0
- data/public/avo-packs/css/application-9d115b7e.css.map +1 -0
- data/public/avo-packs/css/application-9d115b7e.css.map.br +0 -0
- data/public/avo-packs/css/application-9d115b7e.css.map.gz +0 -0
- data/public/avo-packs/js/{application-2b90fe889f7d6df1ad92.js → application-4751feac1bb0404b9c47.js} +4 -4
- data/public/avo-packs/js/{application-2b90fe889f7d6df1ad92.js.LICENSE.txt → application-4751feac1bb0404b9c47.js.LICENSE.txt} +0 -0
- data/public/avo-packs/js/application-4751feac1bb0404b9c47.js.br +0 -0
- data/public/avo-packs/js/application-4751feac1bb0404b9c47.js.gz +0 -0
- data/public/avo-packs/js/application-4751feac1bb0404b9c47.js.map +1 -0
- data/public/avo-packs/js/application-4751feac1bb0404b9c47.js.map.br +0 -0
- data/public/avo-packs/js/application-4751feac1bb0404b9c47.js.map.gz +0 -0
- data/public/avo-packs/manifest.json +16 -16
- data/public/avo-packs/media/images/dadf2db36589607d107d.png +0 -0
- metadata +16 -31
- data/config/initializers/inline_svg.rb +0 -33
- data/public/avo-packs/css/application-38e7e91b.css.br +0 -0
- data/public/avo-packs/css/application-38e7e91b.css.gz +0 -0
- data/public/avo-packs/css/application-38e7e91b.css.map +0 -1
- data/public/avo-packs/css/application-38e7e91b.css.map.br +0 -0
- data/public/avo-packs/css/application-38e7e91b.css.map.gz +0 -0
- data/public/avo-packs/js/application-2b90fe889f7d6df1ad92.js.br +0 -0
- data/public/avo-packs/js/application-2b90fe889f7d6df1ad92.js.gz +0 -0
- data/public/avo-packs/js/application-2b90fe889f7d6df1ad92.js.map +0 -1
- data/public/avo-packs/js/application-2b90fe889f7d6df1ad92.js.map.br +0 -0
- data/public/avo-packs/js/application-2b90fe889f7d6df1ad92.js.map.gz +0 -0
- data/public/avo-packs/media/images/f1b4befac91a3336db9a.png +0 -0
@@ -1,4 +1,4 @@
|
|
1
|
-
require_dependency
|
1
|
+
require_dependency "avo/application_controller"
|
2
2
|
|
3
3
|
module Avo
|
4
4
|
class AttachmentsController < ApplicationController
|
@@ -16,9 +16,9 @@ module Avo
|
|
16
16
|
if attachment.present?
|
17
17
|
attachment.destroy
|
18
18
|
|
19
|
-
redirect_to params[:referrer] || resource_path(@model), notice: t(
|
19
|
+
redirect_to params[:referrer] || resource_path(@model), notice: t("avo.attachment_destroyed")
|
20
20
|
else
|
21
|
-
redirect_back fallback_location: resource_path(@model), notice: t(
|
21
|
+
redirect_back fallback_location: resource_path(@model), notice: t("avo.failed_to_find_attachment")
|
22
22
|
end
|
23
23
|
end
|
24
24
|
end
|
@@ -1,4 +1,4 @@
|
|
1
|
-
require_dependency
|
1
|
+
require_dependency "avo/application_controller"
|
2
2
|
|
3
3
|
module Avo
|
4
4
|
class BaseController < ApplicationController
|
@@ -66,16 +66,16 @@ module Avo
|
|
66
66
|
|
67
67
|
respond_to do |format|
|
68
68
|
if saved
|
69
|
-
if params[:via_relation_class].present? && params[:via_resource_id].present?
|
70
|
-
|
69
|
+
redirect_path = if params[:via_relation_class].present? && params[:via_resource_id].present?
|
70
|
+
resource_path(params[:via_relation_class].safe_constantize, resource_id: params[:via_resource_id])
|
71
71
|
else
|
72
|
-
|
72
|
+
resource_path(@model)
|
73
73
|
end
|
74
74
|
|
75
75
|
format.html { redirect_to redirect_path, notice: "#{@model.class.name} was successfully created." }
|
76
76
|
format.json { render :show, status: :created, location: @model }
|
77
77
|
else
|
78
|
-
flash[:error] = t
|
78
|
+
flash[:error] = t "avo.you_missed_something_check_form"
|
79
79
|
format.html { render :new, status: :unprocessable_entity }
|
80
80
|
format.json { render json: @model.errors, status: :unprocessable_entity }
|
81
81
|
end
|
@@ -92,7 +92,7 @@ module Avo
|
|
92
92
|
format.html { redirect_to params[:referrer] || resource_path(@model), notice: "#{@model.class.name} was successfully updated." }
|
93
93
|
format.json { render :show, status: :ok, location: @model }
|
94
94
|
else
|
95
|
-
flash[:error] = t
|
95
|
+
flash[:error] = t "avo.you_missed_something_check_form"
|
96
96
|
format.html { render :edit, status: :unprocessable_entity }
|
97
97
|
format.json { render json: @model.errors, status: :unprocessable_entity }
|
98
98
|
end
|
@@ -103,116 +103,117 @@ module Avo
|
|
103
103
|
@model.destroy!
|
104
104
|
|
105
105
|
respond_to do |format|
|
106
|
-
format.html { redirect_to params[:referrer] || resources_path(@model, turbo_frame: params[:turbo_frame], view_type: params[:view_type]), notice: t(
|
106
|
+
format.html { redirect_to params[:referrer] || resources_path(@model, turbo_frame: params[:turbo_frame], view_type: params[:view_type]), notice: t("avo.resource_destroyed", attachment_class: @attachment_class) }
|
107
107
|
format.json { head :no_content }
|
108
108
|
end
|
109
109
|
end
|
110
110
|
|
111
111
|
private
|
112
|
-
def model_route_key
|
113
|
-
@resource.model_class.model_name.route_key.singularize
|
114
|
-
end
|
115
112
|
|
116
|
-
|
117
|
-
|
113
|
+
def model_route_key
|
114
|
+
@resource.model_class.model_name.route_key.singularize
|
115
|
+
end
|
118
116
|
|
119
|
-
|
120
|
-
|
121
|
-
request_params.delete(:password)
|
122
|
-
end
|
117
|
+
def model_params
|
118
|
+
request_params = params.require(model_route_key).permit(permitted_params)
|
123
119
|
|
124
|
-
|
120
|
+
if @resource.devise_password_optional && request_params[:password].blank? && request_params[:password_confirmation].blank?
|
121
|
+
request_params.delete(:password_confirmation)
|
122
|
+
request_params.delete(:password)
|
125
123
|
end
|
126
124
|
|
127
|
-
|
128
|
-
|
129
|
-
end
|
125
|
+
request_params
|
126
|
+
end
|
130
127
|
|
131
|
-
|
132
|
-
|
128
|
+
def permitted_params
|
129
|
+
@resource.get_field_definitions.select(&:updatable).map(&:to_permitted_param)
|
130
|
+
end
|
133
131
|
|
134
|
-
|
135
|
-
|
136
|
-
|
132
|
+
def cast_nullable(params)
|
133
|
+
fields = @resource.get_field_definitions
|
134
|
+
|
135
|
+
nullable_fields = fields.filter do |field|
|
136
|
+
field.nullable
|
137
|
+
end
|
137
138
|
.map do |field|
|
138
|
-
|
139
|
-
|
139
|
+
[field.id, field.null_values]
|
140
|
+
end
|
140
141
|
.to_h
|
141
142
|
|
142
|
-
|
143
|
-
|
143
|
+
params.each do |key, value|
|
144
|
+
nullable = nullable_fields[key.to_sym]
|
144
145
|
|
145
|
-
|
146
|
-
|
147
|
-
end
|
146
|
+
if nullable.present? && value.in?(nullable)
|
147
|
+
params[key] = nil
|
148
148
|
end
|
149
|
-
|
150
|
-
params
|
151
149
|
end
|
152
150
|
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
# Pagination
|
157
|
-
@index_params[:page] = params[:page] || 1
|
158
|
-
@index_params[:per_page] = Avo.configuration.per_page
|
151
|
+
params
|
152
|
+
end
|
159
153
|
|
160
|
-
|
161
|
-
|
162
|
-
end
|
154
|
+
def set_index_params
|
155
|
+
@index_params = {}
|
163
156
|
|
164
|
-
|
165
|
-
|
166
|
-
|
157
|
+
# Pagination
|
158
|
+
@index_params[:page] = params[:page] || 1
|
159
|
+
@index_params[:per_page] = Avo.configuration.per_page
|
167
160
|
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
end
|
161
|
+
if cookies[:per_page].present?
|
162
|
+
@index_params[:per_page] = cookies[:per_page]
|
163
|
+
end
|
172
164
|
|
173
|
-
|
174
|
-
@index_params[:
|
175
|
-
|
165
|
+
if @parent_model.present?
|
166
|
+
@index_params[:per_page] = Avo.configuration.via_per_page
|
167
|
+
end
|
176
168
|
|
177
|
-
|
178
|
-
@index_params[:
|
179
|
-
|
169
|
+
if params[:per_page].present?
|
170
|
+
@index_params[:per_page] = params[:per_page]
|
171
|
+
cookies[:per_page] = params[:per_page]
|
180
172
|
end
|
181
173
|
|
182
|
-
|
183
|
-
|
184
|
-
|
174
|
+
# Sorting
|
175
|
+
@index_params[:sort_by] = params[:sort_by] || :created_at
|
176
|
+
@index_params[:sort_direction] = params[:sort_direction] || :desc
|
185
177
|
|
186
|
-
|
187
|
-
|
178
|
+
# View types
|
179
|
+
@index_params[:view_type] = params[:view_type] || @resource.default_view_type || Avo.configuration.default_view_type
|
180
|
+
@index_params[:available_view_types] = @resource.available_view_types
|
181
|
+
end
|
182
|
+
|
183
|
+
def set_filters
|
184
|
+
@filters = @resource.get_filters.map do |filter_class|
|
185
|
+
filter = filter_class.new
|
186
|
+
|
187
|
+
filter
|
188
188
|
end
|
189
|
+
end
|
189
190
|
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
191
|
+
def set_actions
|
192
|
+
if params[:resource_id].present?
|
193
|
+
model = @resource.model_class.find params[:resource_id]
|
194
|
+
end
|
194
195
|
|
195
|
-
|
196
|
-
|
197
|
-
end
|
196
|
+
@actions = @resource.get_actions.map do |action|
|
197
|
+
action.new(model: model, resource: @resource)
|
198
198
|
end
|
199
|
+
end
|
199
200
|
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
201
|
+
def applied_filters
|
202
|
+
if params[:filters].present?
|
203
|
+
return JSON.parse(Base64.decode64(params[:filters]))
|
204
|
+
end
|
204
205
|
|
205
|
-
|
206
|
+
filter_defaults = {}
|
206
207
|
|
207
|
-
|
208
|
-
|
208
|
+
@resource.get_filters.each do |filter_class|
|
209
|
+
filter = filter_class.new
|
209
210
|
|
210
|
-
|
211
|
-
|
212
|
-
end
|
211
|
+
if filter.default.present?
|
212
|
+
filter_defaults[filter_class.to_s] = filter.default
|
213
213
|
end
|
214
|
-
|
215
|
-
filter_defaults
|
216
214
|
end
|
215
|
+
|
216
|
+
filter_defaults
|
217
|
+
end
|
217
218
|
end
|
218
219
|
end
|
@@ -1,10 +1,10 @@
|
|
1
|
-
require_dependency
|
1
|
+
require_dependency "avo/application_controller"
|
2
2
|
|
3
3
|
module Avo
|
4
4
|
class HomeController < ApplicationController
|
5
5
|
def index
|
6
6
|
unless Rails.env.development?
|
7
|
-
redirect_to resources_path Avo::App.get_resources.
|
7
|
+
redirect_to resources_path Avo::App.get_resources.min_by { |resource| resource.route_key }.model_class
|
8
8
|
end
|
9
9
|
end
|
10
10
|
end
|
@@ -1,4 +1,4 @@
|
|
1
|
-
require_dependency
|
1
|
+
require_dependency "avo/base_controller"
|
2
2
|
|
3
3
|
module Avo
|
4
4
|
class RelationsController < BaseController
|
@@ -41,15 +41,15 @@ module Avo
|
|
41
41
|
end
|
42
42
|
|
43
43
|
def create
|
44
|
-
if reflection_class ==
|
45
|
-
@model.send(
|
44
|
+
if reflection_class == "HasManyReflection"
|
45
|
+
@model.send(params[:related_name].to_s) << @attachment_model
|
46
46
|
else
|
47
47
|
@model.send("#{params[:related_name]}=", @attachment_model)
|
48
48
|
end
|
49
49
|
|
50
50
|
respond_to do |format|
|
51
51
|
if @model.save
|
52
|
-
format.html { redirect_to resource_path(@model), notice: t(
|
52
|
+
format.html { redirect_to resource_path(@model), notice: t("avo.attachment_class_attached", attachment_class: @attachment_class) }
|
53
53
|
format.json { render :show, status: :created, location: resource_path(@model) }
|
54
54
|
else
|
55
55
|
format.html { render :new }
|
@@ -59,45 +59,46 @@ module Avo
|
|
59
59
|
end
|
60
60
|
|
61
61
|
def destroy
|
62
|
-
if reflection_class ==
|
63
|
-
@model.send(
|
62
|
+
if reflection_class == "HasManyReflection"
|
63
|
+
@model.send(params[:related_name].to_s).delete @attachment_model
|
64
64
|
else
|
65
65
|
@model.send("#{params[:related_name]}=", nil)
|
66
66
|
end
|
67
67
|
|
68
68
|
respond_to do |format|
|
69
|
-
format.html { redirect_to params[:referrer] || resource_path(@model), notice: t(
|
69
|
+
format.html { redirect_to params[:referrer] || resource_path(@model), notice: t("avo.attachment_class_detached", attachment_class: @attachment_class) }
|
70
70
|
end
|
71
71
|
end
|
72
72
|
|
73
73
|
private
|
74
|
-
def set_attachment_class
|
75
|
-
@attachment_class = @model._reflections[params[:related_name].to_s].klass
|
76
|
-
end
|
77
74
|
|
78
|
-
|
79
|
-
|
80
|
-
|
75
|
+
def set_attachment_class
|
76
|
+
@attachment_class = @model._reflections[params[:related_name].to_s].klass
|
77
|
+
end
|
81
78
|
|
82
|
-
|
83
|
-
|
84
|
-
|
79
|
+
def set_attachment_resource
|
80
|
+
@attachment_resource = App.get_resource_by_model_name @attachment_class
|
81
|
+
end
|
85
82
|
|
86
|
-
|
87
|
-
|
88
|
-
|
83
|
+
def set_attachment_model
|
84
|
+
@attachment_model = @model._reflections[params[:related_name].to_s].klass.find attachment_id
|
85
|
+
end
|
89
86
|
|
90
|
-
|
91
|
-
|
92
|
-
|
87
|
+
def set_reflection
|
88
|
+
@reflection = @model._reflections[params[:related_name].to_s]
|
89
|
+
end
|
90
|
+
|
91
|
+
def attachment_id
|
92
|
+
params[:related_id] || params.require(:fields).permit(:related_id)[:related_id]
|
93
|
+
end
|
93
94
|
|
94
|
-
|
95
|
-
|
95
|
+
def reflection_class
|
96
|
+
reflection = @model._reflections[params[:related_name]]
|
96
97
|
|
97
|
-
|
98
|
-
|
98
|
+
klass = reflection.class.name.demodulize.to_s
|
99
|
+
klass = reflection.through_reflection.class.name.demodulize.to_s if klass == "ThroughReflection"
|
99
100
|
|
100
|
-
|
101
|
-
|
101
|
+
klass
|
102
|
+
end
|
102
103
|
end
|
103
104
|
end
|
@@ -1,4 +1,4 @@
|
|
1
|
-
require_dependency
|
1
|
+
require_dependency "avo/application_controller"
|
2
2
|
|
3
3
|
module Avo
|
4
4
|
class SearchController < ApplicationController
|
@@ -8,9 +8,9 @@ module Avo
|
|
8
8
|
@authorization.set_record(resource_model).authorize_action :index
|
9
9
|
resources = []
|
10
10
|
|
11
|
-
|
11
|
+
App.get_resources
|
12
12
|
.select { |resource| resource.search.present? }
|
13
|
-
.select { |resource| AuthorizationService.authorize_action _current_user, resource.model,
|
13
|
+
.select { |resource| AuthorizationService.authorize_action _current_user, resource.model, "index" }
|
14
14
|
.each do |resource_model|
|
15
15
|
found_resources = add_link_to_search_results(search_resource(resource_model), resource_model)
|
16
16
|
resources.push({
|
@@ -31,26 +31,27 @@ module Avo
|
|
31
31
|
end
|
32
32
|
|
33
33
|
private
|
34
|
-
def add_link_to_search_results(resources, avo_resource)
|
35
|
-
resources.map do |model|
|
36
|
-
{
|
37
|
-
id: model.id,
|
38
|
-
search_label: model.send(avo_resource.class.title),
|
39
|
-
link: "/resources/#{model.class.to_s.singularize.underscore}/#{model.id}",
|
40
|
-
}
|
41
|
-
end
|
42
|
-
end
|
43
34
|
|
44
|
-
|
45
|
-
|
35
|
+
def add_link_to_search_results(resources, avo_resource)
|
36
|
+
resources.map do |model|
|
37
|
+
{
|
38
|
+
id: model.id,
|
39
|
+
search_label: model.send(avo_resource.class.title),
|
40
|
+
link: "/resources/#{model.class.to_s.singularize.underscore}/#{model.id}"
|
41
|
+
}
|
46
42
|
end
|
43
|
+
end
|
44
|
+
|
45
|
+
def search_resource(avo_resource)
|
46
|
+
avo_resource.query_search(query: params[:q], via_resource_name: params[:via_resource_name], via_resource_id: params[:via_resource_id], user: _current_user)
|
47
|
+
end
|
47
48
|
|
48
|
-
|
49
|
-
|
49
|
+
# def authorize_user
|
50
|
+
# return if params[:action] == 'index'
|
50
51
|
|
51
|
-
|
52
|
+
# action = params[:action] == 'resource' ? :index : params[:action]
|
52
53
|
|
53
|
-
|
54
|
-
|
54
|
+
# return render_unauthorized unless AuthorizationService::authorize_action _current_user, avo_resource.model, action
|
55
|
+
# end
|
55
56
|
end
|
56
57
|
end
|
@@ -8,32 +8,40 @@ module Avo
|
|
8
8
|
end
|
9
9
|
|
10
10
|
def render_logo
|
11
|
-
render partial:
|
11
|
+
render partial: "vendor/avo/partials/logo"
|
12
|
+
rescue
|
13
|
+
render partial: "avo/partials/logo"
|
12
14
|
end
|
13
15
|
|
14
16
|
def render_header
|
15
|
-
render partial:
|
17
|
+
render partial: "vendor/avo/partials/header"
|
18
|
+
rescue
|
19
|
+
render partial: "avo/partials/header"
|
16
20
|
end
|
17
21
|
|
18
22
|
def render_footer
|
19
|
-
render partial:
|
23
|
+
render partial: "vendor/avo/partials/footer"
|
24
|
+
rescue
|
25
|
+
render partial: "avo/partials/footer"
|
20
26
|
end
|
21
27
|
|
22
28
|
def render_scripts
|
23
|
-
render partial:
|
29
|
+
render partial: "vendor/avo/partials/scripts"
|
30
|
+
rescue
|
31
|
+
""
|
24
32
|
end
|
25
33
|
|
26
34
|
def render_license_warnings
|
27
|
-
render partial:
|
28
|
-
license: Avo::App.license.properties
|
35
|
+
render partial: "avo/sidebar/license_warnings", locals: {
|
36
|
+
license: Avo::App.license.properties
|
29
37
|
}
|
30
38
|
end
|
31
39
|
|
32
|
-
def render_license_warning(title:
|
33
|
-
render partial:
|
40
|
+
def render_license_warning(title: "", message: "", icon: "exclamation")
|
41
|
+
render partial: "avo/sidebar/license_warning", locals: {
|
34
42
|
title: title,
|
35
43
|
message: message,
|
36
|
-
icon: icon
|
44
|
+
icon: icon
|
37
45
|
}
|
38
46
|
end
|
39
47
|
|
@@ -44,7 +52,7 @@ module Avo
|
|
44
52
|
end
|
45
53
|
|
46
54
|
def empty_state(resource_name)
|
47
|
-
render partial:
|
55
|
+
render partial: "avo/partials/empty_state", locals: {resource_name: resource_name}
|
48
56
|
end
|
49
57
|
|
50
58
|
def turbo_frame_start(name)
|
@@ -52,7 +60,7 @@ module Avo
|
|
52
60
|
end
|
53
61
|
|
54
62
|
def turbo_frame_end(name)
|
55
|
-
|
63
|
+
"</turbo-frame>".html_safe if name.present?
|
56
64
|
end
|
57
65
|
|
58
66
|
def a_button(label = nil, **args, &block)
|
@@ -60,37 +68,37 @@ module Avo
|
|
60
68
|
|
61
69
|
locals = {
|
62
70
|
label: label,
|
63
|
-
args: args
|
71
|
+
args: args
|
64
72
|
}
|
65
73
|
|
66
|
-
if
|
67
|
-
render layout:
|
74
|
+
if block
|
75
|
+
render layout: "avo/partials/a_button", locals: locals do
|
68
76
|
capture(&block)
|
69
77
|
end
|
70
78
|
else
|
71
|
-
render partial:
|
79
|
+
render partial: "avo/partials/a_button", locals: locals
|
72
80
|
end
|
73
81
|
end
|
74
82
|
|
75
83
|
def a_link(label, url = nil, **args, &block)
|
76
84
|
args[:class] = button_classes(args[:class], color: args[:color], variant: args[:variant], size: args[:size])
|
77
85
|
|
78
|
-
if
|
86
|
+
if block
|
79
87
|
url = label
|
80
88
|
end
|
81
89
|
|
82
90
|
locals = {
|
83
91
|
label: label,
|
84
92
|
url: url,
|
85
|
-
args: args
|
93
|
+
args: args
|
86
94
|
}
|
87
95
|
|
88
|
-
if
|
89
|
-
render layout:
|
96
|
+
if block
|
97
|
+
render layout: "avo/partials/a_link", locals: locals do
|
90
98
|
capture(&block)
|
91
99
|
end
|
92
100
|
else
|
93
|
-
render partial:
|
101
|
+
render partial: "avo/partials/a_link", locals: locals
|
94
102
|
end
|
95
103
|
end
|
96
104
|
|
@@ -98,27 +106,27 @@ module Avo
|
|
98
106
|
classes = "inline-flex flex-grow-0 items-center text-sm font-bold leading-none fill-current whitespace-nowrap transition duration-100 rounded-lg shadow-xl transform transition duration-100 active:translate-x-px active:translate-y-px cursor-pointer disabled:cursor-not-allowed #{extra_classes}"
|
99
107
|
|
100
108
|
if color.present?
|
101
|
-
if variant.present?
|
102
|
-
classes +=
|
109
|
+
if variant.present? && (variant.to_sym == :outlined)
|
110
|
+
classes += " bg-white border"
|
103
111
|
|
104
112
|
classes += " hover:border-#{color}-700 border-#{color}-600 text-#{color}-600 hover:text-#{color}-700 disabled:border-gray-300 disabled:text-gray-600"
|
105
113
|
else
|
106
114
|
classes += " text-white bg-#{color}-500 hover:bg-#{color}-600 disabled:bg-#{color}-300"
|
107
115
|
end
|
108
116
|
else
|
109
|
-
classes +=
|
117
|
+
classes += " text-gray-700 bg-white hover:bg-gray-100 disabled:bg-gray-300"
|
110
118
|
end
|
111
119
|
|
112
120
|
size = size.present? ? size.to_sym : :md
|
113
|
-
case size
|
121
|
+
classes += case size
|
114
122
|
when :xs
|
115
|
-
|
123
|
+
" p-2 py-1"
|
116
124
|
when :sm
|
117
|
-
|
125
|
+
" p-3"
|
118
126
|
when :md
|
119
|
-
|
127
|
+
" p-4"
|
120
128
|
else
|
121
|
-
|
129
|
+
" p-4"
|
122
130
|
end
|
123
131
|
|
124
132
|
classes
|
@@ -126,23 +134,23 @@ module Avo
|
|
126
134
|
|
127
135
|
def svg(file_name, **args)
|
128
136
|
options = {}
|
129
|
-
options[:class]
|
130
|
-
options[:class] += args[:extra_class].present? ? " #{args[:extra_class]}" :
|
137
|
+
options[:class] = args[:class].present? ? args[:class] : "h-4 mr-1"
|
138
|
+
options[:class] += args[:extra_class].present? ? " #{args[:extra_class]}" : ""
|
131
139
|
|
132
140
|
# Create the path to the svgs directory
|
133
141
|
file_path = "#{Avo::Engine.root}/app/packs/svgs/#{file_name}"
|
134
|
-
file_path = "#{file_path}.svg" unless file_path.end_with?
|
142
|
+
file_path = "#{file_path}.svg" unless file_path.end_with? ".svg"
|
135
143
|
|
136
144
|
# Create a cache hash
|
137
|
-
hash = Digest::MD5.hexdigest "#{file_path.underscore}_#{options
|
145
|
+
hash = Digest::MD5.hexdigest "#{file_path.underscore}_#{options}"
|
138
146
|
|
139
147
|
svg_content = Avo::App.cache_store.fetch "svg_file_#{hash}", expires_in: 1.year, cache_nils: false do
|
140
|
-
if File.
|
148
|
+
if File.exist?(file_path)
|
141
149
|
file = File.read(file_path)
|
142
150
|
|
143
151
|
# parse svg
|
144
152
|
doc = Nokogiri::HTML::DocumentFragment.parse file
|
145
|
-
svg = doc.at_css
|
153
|
+
svg = doc.at_css "svg"
|
146
154
|
|
147
155
|
# attach options
|
148
156
|
options.each do |attr, value|
|
@@ -151,23 +159,21 @@ module Avo
|
|
151
159
|
|
152
160
|
# cast to html
|
153
161
|
doc.to_html.html_safe
|
154
|
-
else
|
155
|
-
nil
|
156
162
|
end
|
157
163
|
end
|
158
164
|
|
159
|
-
return
|
165
|
+
return "(not found)" if svg_content.to_s.blank?
|
160
166
|
|
161
167
|
svg_content
|
162
168
|
end
|
163
169
|
|
164
|
-
def input_classes(extra_classes =
|
165
|
-
classes =
|
170
|
+
def input_classes(extra_classes = "", has_error: false)
|
171
|
+
classes = "appearance-none inline-flex bg-blue-gray-100 disabled:bg-blue-gray-300 disabled:cursor-not-allowed focus:bg-white text-blue-gray-700 disabled:text-blue-gray-700 rounded-md py-2 px-3 leading-tight border outline-none outline"
|
166
172
|
|
167
|
-
if has_error
|
168
|
-
|
173
|
+
classes += if has_error
|
174
|
+
" border-red-600"
|
169
175
|
else
|
170
|
-
|
176
|
+
" border-blue-gray-300"
|
171
177
|
end
|
172
178
|
|
173
179
|
classes += " #{extra_classes}"
|