avo 2.11.3.pre.1 → 2.11.3.pre.2
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.lock +1 -1
- data/app/components/avo/actions_component.html.erb +3 -3
- data/app/components/avo/actions_component.rb +3 -12
- data/app/components/avo/button_component.rb +3 -1
- data/app/components/avo/card_component.html.erb +8 -8
- data/app/components/avo/cards_list_component.html.erb +16 -0
- data/app/components/avo/cards_list_component.rb +13 -0
- data/app/components/avo/panel_component.html.erb +1 -1
- data/app/components/avo/resource_component.rb +4 -6
- data/app/components/avo/sidebar_component.html.erb +1 -1
- data/app/components/avo/views/resource_edit_component.rb +20 -0
- data/app/components/avo/views/resource_index_component.html.erb +90 -42
- data/app/components/avo/views/resource_show_component.html.erb +50 -137
- data/app/components/avo/views/resource_show_component.rb +0 -1
- data/app/controllers/avo/application_controller.rb +2 -2
- data/app/controllers/avo/associations_controller.rb +1 -1
- data/app/controllers/avo/base_controller.rb +7 -3
- data/app/controllers/avo/cards_controller.rb +18 -5
- data/app/controllers/avo/dashboards_controller.rb +4 -2
- data/app/javascript/js/controllers/{dashboard_card_controller.js → card_controller.js} +0 -0
- data/app/javascript/js/controllers.js +2 -2
- data/app/views/avo/cards/_metric_card.html.erb +2 -2
- data/app/views/avo/dashboards/show.html.erb +2 -19
- data/app/views/avo/debug/report.html.erb +0 -1
- data/app/views/avo/private/design.html.erb +1 -1
- data/app/views/layouts/avo/application.html.erb +1 -1
- data/config/routes.rb +3 -0
- data/lib/avo/base_card.rb +40 -20
- data/lib/avo/base_resource.rb +2 -5
- data/lib/avo/concerns/has_cards.rb +88 -0
- data/lib/avo/concerns/has_model.rb +11 -0
- data/lib/avo/concerns/styles_cards.rb +48 -0
- data/lib/avo/dashboards/base_dashboard.rb +15 -50
- data/lib/avo/dashboards/base_divider.rb +5 -1
- data/lib/avo/dashboards/chartkick_card.rb +3 -3
- data/lib/avo/fields/base_field.rb +2 -6
- data/lib/avo/fields/field_extensions/visible_in_different_views.rb +12 -1
- data/lib/avo/hosts/dashboard_card.rb +1 -1
- data/lib/avo/licensing/pro_license.rb +0 -1
- data/lib/avo/tab.rb +3 -1
- data/lib/avo/version.rb +1 -1
- data/lib/generators/avo/templates/action.tt +1 -1
- data/lib/generators/avo/templates/cards/partial_card_partial.tt +1 -1
- data/lib/generators/avo/templates/resource_tools/partial.tt +1 -1
- data/lib/generators/avo/templates/standalone_action.tt +1 -1
- data/public/avo-assets/avo.css +150 -594
- data/public/avo-assets/avo.js +6 -6
- data/public/avo-assets/avo.js.map +3 -3
- metadata +7 -13
- data/lib/avo/concerns/has_editable_controls.rb +0 -34
- data/lib/avo/resources/controls/action.rb +0 -32
- data/lib/avo/resources/controls/actions_list.rb +0 -19
- data/lib/avo/resources/controls/back_button.rb +0 -13
- data/lib/avo/resources/controls/base_control.rb +0 -59
- data/lib/avo/resources/controls/delete_button.rb +0 -13
- data/lib/avo/resources/controls/detach_button.rb +0 -13
- data/lib/avo/resources/controls/edit_button.rb +0 -13
- data/lib/avo/resources/controls/execution_context.rb +0 -59
- data/lib/avo/resources/controls/items_holder.rb +0 -19
- data/lib/avo/resources/controls/link_to.rb +0 -27
@@ -7,6 +7,7 @@ module Avo
|
|
7
7
|
before_action :hydrate_resource
|
8
8
|
before_action :set_applied_filters, only: :index
|
9
9
|
before_action :set_model, only: [:show, :edit, :destroy, :update, :order]
|
10
|
+
before_action :hydrate_resource
|
10
11
|
before_action :set_model_to_fill
|
11
12
|
before_action :set_edit_title_and_breadcrumbs, only: [:edit, :update]
|
12
13
|
before_action :fill_model, only: [:create, :update]
|
@@ -100,7 +101,7 @@ module Avo
|
|
100
101
|
|
101
102
|
def new
|
102
103
|
@model = @resource.model_class.new
|
103
|
-
@resource = @resource.hydrate(model: @model, view: :new
|
104
|
+
@resource = @resource.hydrate(model: @model, view: :new)
|
104
105
|
|
105
106
|
set_actions
|
106
107
|
|
@@ -170,7 +171,7 @@ module Avo
|
|
170
171
|
def update
|
171
172
|
# model gets instantiated and filled in the fill_model method
|
172
173
|
saved = save_model
|
173
|
-
@resource = @resource.hydrate(model: @model, view: :edit
|
174
|
+
@resource = @resource.hydrate(model: @model, view: :edit)
|
174
175
|
|
175
176
|
respond_to do |format|
|
176
177
|
if saved
|
@@ -209,6 +210,9 @@ module Avo
|
|
209
210
|
end
|
210
211
|
end
|
211
212
|
|
213
|
+
def cards
|
214
|
+
end
|
215
|
+
|
212
216
|
private
|
213
217
|
|
214
218
|
def save_model
|
@@ -376,7 +380,7 @@ module Avo
|
|
376
380
|
end
|
377
381
|
|
378
382
|
def set_edit_title_and_breadcrumbs
|
379
|
-
@resource = @resource.hydrate(model: @model, view: :edit
|
383
|
+
@resource = @resource.hydrate(model: @model, view: :edit)
|
380
384
|
@page_title = @resource.default_panel_name.to_s
|
381
385
|
|
382
386
|
last_crumb_args = {}
|
@@ -2,7 +2,12 @@ require_dependency "avo/application_controller"
|
|
2
2
|
|
3
3
|
module Avo
|
4
4
|
class CardsController < ApplicationController
|
5
|
-
before_action :set_dashboard
|
5
|
+
before_action :set_dashboard
|
6
|
+
before_action :set_resource_name
|
7
|
+
before_action :set_resource, if: -> { @dashboard.blank? }
|
8
|
+
before_action :set_model, only: :show, if: -> { @resource.present? }
|
9
|
+
before_action :hydrate_resource, if: -> { @resource.present? }
|
10
|
+
before_action :set_parent, only: :show
|
6
11
|
before_action :set_card, only: :show
|
7
12
|
|
8
13
|
def show
|
@@ -10,15 +15,23 @@ module Avo
|
|
10
15
|
|
11
16
|
private
|
12
17
|
|
18
|
+
def set_parent
|
19
|
+
@parent = @dashboard || @resource
|
20
|
+
end
|
21
|
+
|
13
22
|
def set_dashboard
|
14
|
-
|
23
|
+
return if params[:dashboard_id].blank?
|
24
|
+
|
25
|
+
@dashboard_class = Avo::App.get_dashboard_by_id params[:dashboard_id]
|
26
|
+
|
27
|
+
raise ActionController::RoutingError.new("Not Found") if @dashboard_class.nil? || @dashboard_class.is_hidden?
|
15
28
|
|
16
|
-
|
29
|
+
@dashboard = @dashboard_class.new
|
17
30
|
end
|
18
31
|
|
19
32
|
def set_card
|
20
|
-
@card = @
|
21
|
-
card.hydrate(
|
33
|
+
@card = @parent.item_at_index(params[:index].to_i).tap do |card|
|
34
|
+
card.hydrate(parent: @parent, params: params)
|
22
35
|
end
|
23
36
|
end
|
24
37
|
end
|
@@ -10,9 +10,11 @@ module Avo
|
|
10
10
|
private
|
11
11
|
|
12
12
|
def set_dashboard
|
13
|
-
@
|
13
|
+
@dashboard_class = Avo::App.get_dashboard_by_id params[:id]
|
14
14
|
|
15
|
-
raise ActionController::RoutingError.new("Not Found") if @
|
15
|
+
raise ActionController::RoutingError.new("Not Found") if @dashboard_class.nil? || @dashboard_class.is_hidden?
|
16
|
+
|
17
|
+
@dashboard = @dashboard_class.new.hydrate(params: params) if @dashboard_class.present?
|
16
18
|
end
|
17
19
|
end
|
18
20
|
end
|
File without changes
|
@@ -5,9 +5,9 @@ import ActionsPickerController from './controllers/actions_picker_controller'
|
|
5
5
|
import AttachmentsController from './controllers/attachments_controller'
|
6
6
|
import BelongsToFieldController from './controllers/fields/belongs_to_field_controller'
|
7
7
|
import BooleanFilterController from './controllers/boolean_filter_controller'
|
8
|
+
import CardController from './controllers/card_controller'
|
8
9
|
import CodeFieldController from './controllers/fields/code_field_controller'
|
9
10
|
import CopyToClipboardController from './controllers/copy_to_clipboard_controller'
|
10
|
-
import DashboardCardController from './controllers/dashboard_card_controller'
|
11
11
|
import DateFieldController from './controllers/fields/date_field_controller'
|
12
12
|
import FilterController from './controllers/filter_controller'
|
13
13
|
import HiddenInputController from './controllers/hidden_input_controller'
|
@@ -38,8 +38,8 @@ application.register('action', ActionController)
|
|
38
38
|
application.register('actions-picker', ActionsPickerController)
|
39
39
|
application.register('attachments', AttachmentsController)
|
40
40
|
application.register('boolean-filter', BooleanFilterController)
|
41
|
+
application.register('card', CardController)
|
41
42
|
application.register('copy-to-clipboard', CopyToClipboardController)
|
42
|
-
application.register('dashboard-card', DashboardCardController)
|
43
43
|
application.register('filter', FilterController)
|
44
44
|
application.register('hidden-input', HiddenInputController)
|
45
45
|
application.register('item-select-all', ItemSelectAllController)
|
@@ -1,5 +1,5 @@
|
|
1
|
-
<div class="flex
|
1
|
+
<div class="flex items-end text-gray-800">
|
2
2
|
<span class="text-3xl"><%= @card.prefix %></span>
|
3
|
-
<span class="text-5xl"><%= @card.result_data %></span>
|
3
|
+
<span class="text-5xl font-semibold"><%= @card.result_data %></span>
|
4
4
|
<span class="text-3xl"><%= @card.suffix %></span>
|
5
5
|
</div>
|
@@ -1,24 +1,7 @@
|
|
1
1
|
<%= render Avo::PanelComponent.new(title: @dashboard.name, description: @dashboard.description) do |c| %>
|
2
2
|
<% c.bare_content do %>
|
3
|
-
<% if @dashboard.
|
4
|
-
|
5
|
-
<%= content_tag(:div, class: "grid gap-4 grid-cols-1 #{@dashboard.classes}") do %>
|
6
|
-
<% @dashboard.items.each do |item| %>
|
7
|
-
<% if item.is_divider? %>
|
8
|
-
<%= render Avo::Dashboards::DividerComponent.new(divider: item) %>
|
9
|
-
<% elsif item.is_card? %>
|
10
|
-
<%= content_tag(:div, class: "relative bg-white rounded shadow-panel space-y-2 #{item.card_classes} overflow-hidden") do %>
|
11
|
-
<turbo-frame id="<%= item.turbo_frame %>"
|
12
|
-
src="<%= item.frame_url(enforced_range: @range, params: params) %>"
|
13
|
-
data-card-index="<%= item.index %>"
|
14
|
-
>
|
15
|
-
<%= render(Avo::LoadingComponent.new(title: item.label)) %>
|
16
|
-
</turbo-frame>
|
17
|
-
<% end %>
|
18
|
-
<% end %>
|
19
|
-
<% end %>
|
20
|
-
<% end %>
|
21
|
-
</div>
|
3
|
+
<% if @dashboard.cards.present? %>
|
4
|
+
<%= render Avo::CardsListComponent.new parent: @dashboard %>
|
22
5
|
<% else %>
|
23
6
|
<div class="w-full h-full">
|
24
7
|
<% if Rails.env.development? %>
|
@@ -1,7 +1,7 @@
|
|
1
1
|
<div class="flex flex-col">
|
2
2
|
<%= render Avo::PanelComponent.new(title: 'Welcome to Avo', description: 'This page is visible only in development. It will be hidden in other environments.') do |c| %>
|
3
3
|
<% c.tools do %>
|
4
|
-
<%= a_link('/admin', icon: 'arrow-left',
|
4
|
+
<%= a_link('/admin', icon: 'arrow-left', style: :primary, is_link: true) do %>
|
5
5
|
Primary
|
6
6
|
<% end %>
|
7
7
|
|
@@ -18,7 +18,7 @@
|
|
18
18
|
<% end %>
|
19
19
|
<% end %>
|
20
20
|
</head>
|
21
|
-
<body class="bg-
|
21
|
+
<body class="bg-application os-mac">
|
22
22
|
<div class="relative flex flex-1 w-full min-h-full" data-controller="sidebar" data-sidebar-open-value="<%= @sidebar_open %>">
|
23
23
|
<div class="flex-1 flex flex-col max-w-full">
|
24
24
|
<%= render partial: "avo/partials/navbar" %>
|
data/config/routes.rb
CHANGED
@@ -35,6 +35,9 @@ Avo::Engine.routes.draw do
|
|
35
35
|
# resources :posts
|
36
36
|
Avo::DynamicRouter.routes(self)
|
37
37
|
|
38
|
+
# Cards
|
39
|
+
get "/:resource_name/:id/cards/:card_id", to: "cards#show"
|
40
|
+
|
38
41
|
# Associations
|
39
42
|
get "/:resource_name/:id/:related_name/new", to: "associations#new", as: "associations_new"
|
40
43
|
get "/:resource_name/:id/:related_name/", to: "associations#index", as: "associations_index"
|
data/lib/avo/base_card.rb
CHANGED
@@ -1,10 +1,11 @@
|
|
1
1
|
module Avo
|
2
2
|
class BaseCard
|
3
|
+
include Avo::Concerns::StylesCards
|
4
|
+
include Avo::Fields::FieldExtensions::VisibleInDifferentViews
|
5
|
+
|
3
6
|
class_attribute :id
|
4
7
|
class_attribute :label
|
5
8
|
class_attribute :description
|
6
|
-
class_attribute :cols, default: 1
|
7
|
-
class_attribute :rows, default: 1
|
8
9
|
class_attribute :initial_range
|
9
10
|
class_attribute :ranges, default: []
|
10
11
|
class_attribute :refresh_every
|
@@ -13,7 +14,7 @@ module Avo
|
|
13
14
|
class_attribute :result_data
|
14
15
|
class_attribute :query_block
|
15
16
|
|
16
|
-
attr_accessor :
|
17
|
+
attr_accessor :parent
|
17
18
|
attr_accessor :options
|
18
19
|
attr_accessor :index
|
19
20
|
attr_accessor :params
|
@@ -26,8 +27,8 @@ module Avo
|
|
26
27
|
end
|
27
28
|
end
|
28
29
|
|
29
|
-
def initialize(
|
30
|
-
@
|
30
|
+
def initialize(parent:, options: {}, index: 0, cols: nil, rows: nil, label: nil, description: nil, refresh_every: nil, **args)
|
31
|
+
@parent = parent
|
31
32
|
@options = options
|
32
33
|
@index = index
|
33
34
|
@cols = cols
|
@@ -35,6 +36,8 @@ module Avo
|
|
35
36
|
@label = label
|
36
37
|
@refresh_every = refresh_every
|
37
38
|
@description = description
|
39
|
+
|
40
|
+
initialize_visibility args
|
38
41
|
end
|
39
42
|
|
40
43
|
def label
|
@@ -53,13 +56,21 @@ module Avo
|
|
53
56
|
end
|
54
57
|
|
55
58
|
def turbo_frame
|
56
|
-
|
59
|
+
if parent_is_dashboard?
|
60
|
+
"#{parent.id}_#{id}"
|
61
|
+
elsif parent_is_resource?
|
62
|
+
"#{parent.id}_#{parent.model.id}_#{id}"
|
63
|
+
end
|
57
64
|
end
|
58
65
|
|
59
66
|
def frame_url(enforced_range: nil, params: {})
|
60
67
|
enforced_range ||= initial_range || ranges.first
|
61
68
|
|
62
|
-
|
69
|
+
if parent_is_dashboard?
|
70
|
+
Avo::App.view_context.avo.dashboard_card_path(dashboard.id, id, turbo_frame: turbo_frame, index: index, range: enforced_range, **params.permit!.to_h)
|
71
|
+
elsif parent_is_resource?
|
72
|
+
Avo::App.root_path(paths: ["resources", parent.route_key, parent.model.id, "cards", id], query: {turbo_frame: turbo_frame, index: index, range: enforced_range, **params.permit!.to_h})
|
73
|
+
end
|
63
74
|
end
|
64
75
|
|
65
76
|
def card_classes
|
@@ -76,12 +87,12 @@ module Avo
|
|
76
87
|
}
|
77
88
|
|
78
89
|
classes_for_rows = {
|
79
|
-
1 => " h-
|
80
|
-
2 => " h-
|
81
|
-
3 => " h-[27rem]",
|
82
|
-
4 => " h-[36rem]",
|
83
|
-
5 => " h-[45rem]",
|
84
|
-
6 => " h-[54rem]"
|
90
|
+
1 => " min-h-[9rem] row-span-1",
|
91
|
+
2 => " min-h-[18rem] row-span-2",
|
92
|
+
3 => " min-h-[27rem] row-span-3",
|
93
|
+
4 => " min-h-[36rem] row-span-4",
|
94
|
+
5 => " min-h-[45rem] row-span-5",
|
95
|
+
6 => " min-h-[54rem] row-span-6"
|
85
96
|
}
|
86
97
|
# puts ["cols->", cols, classes_for_cols, classes_for_rows, classes_for_cols[cols.to_i]].inspect
|
87
98
|
|
@@ -98,15 +109,16 @@ module Avo
|
|
98
109
|
end
|
99
110
|
|
100
111
|
def compute_result
|
101
|
-
Avo::Hosts::DashboardCard.new(card: self,
|
112
|
+
Avo::Hosts::DashboardCard.new(card: self, parent: parent, params: params, context: context, range: range, options: options)
|
102
113
|
.compute_result
|
103
114
|
|
104
115
|
self
|
105
116
|
end
|
106
117
|
|
107
|
-
def hydrate(
|
108
|
-
@
|
118
|
+
def hydrate(parent: nil, params: nil, view: nil)
|
119
|
+
@parent = parent if parent.present?
|
109
120
|
@params = params if params.present?
|
121
|
+
@view = view if view.present?
|
110
122
|
|
111
123
|
self
|
112
124
|
end
|
@@ -135,12 +147,20 @@ module Avo
|
|
135
147
|
|
136
148
|
private
|
137
149
|
|
138
|
-
def
|
139
|
-
|
150
|
+
def parent_is_dashboard?
|
151
|
+
parent.class.superclass == Avo::Dashboards::BaseDashboard
|
152
|
+
end
|
153
|
+
|
154
|
+
def parent_is_resource?
|
155
|
+
parent.class.superclass == Avo::BaseResource
|
156
|
+
end
|
157
|
+
|
158
|
+
def resource
|
159
|
+
parent if parent_is_resource?
|
140
160
|
end
|
141
161
|
|
142
|
-
def
|
143
|
-
|
162
|
+
def dashboard
|
163
|
+
parent if parent_is_dashboard?
|
144
164
|
end
|
145
165
|
end
|
146
166
|
end
|
data/lib/avo/base_resource.rb
CHANGED
@@ -3,8 +3,9 @@ module Avo
|
|
3
3
|
extend ActiveSupport::DescendantsTracker
|
4
4
|
|
5
5
|
include ActionView::Helpers::UrlHelper
|
6
|
+
include Avo::Concerns::HasCards
|
7
|
+
include Avo::Concerns::HasModel
|
6
8
|
include Avo::Concerns::HasFields
|
7
|
-
include Avo::Concerns::HasEditableControls
|
8
9
|
include Avo::Concerns::HasStimulusControllers
|
9
10
|
include Avo::Concerns::ModelClassConstantized
|
10
11
|
|
@@ -439,9 +440,5 @@ module Avo
|
|
439
440
|
def ordering_host(**args)
|
440
441
|
Avo::Hosts::Ordering.new resource: self, options: self.class.ordering, **args
|
441
442
|
end
|
442
|
-
|
443
|
-
def has_model_id?
|
444
|
-
model.present? && model.id.present?
|
445
|
-
end
|
446
443
|
end
|
447
444
|
end
|
@@ -0,0 +1,88 @@
|
|
1
|
+
module Avo
|
2
|
+
module Concerns
|
3
|
+
module HasCards
|
4
|
+
extend ActiveSupport::Concern
|
5
|
+
|
6
|
+
included do
|
7
|
+
class_attribute :cards_holder
|
8
|
+
class_attribute :cards_index, default: 0
|
9
|
+
class_attribute :grid_cols, default: 3
|
10
|
+
|
11
|
+
delegate :item_at_index, to: :class
|
12
|
+
|
13
|
+
def cards
|
14
|
+
return [] if self.class.cards.blank?
|
15
|
+
|
16
|
+
view = self&.view
|
17
|
+
|
18
|
+
self.class.cards
|
19
|
+
.map do |card|
|
20
|
+
# Try to hydrate the card
|
21
|
+
card.hydrate(parent: self, params: params, view: view) if card.is_card?
|
22
|
+
|
23
|
+
card
|
24
|
+
end
|
25
|
+
.select do |card|
|
26
|
+
# If we don't get a view return all cards
|
27
|
+
return true if view.nil?
|
28
|
+
|
29
|
+
card.send("show_on_#{view}")
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
class_methods do
|
35
|
+
def card(klass, label: nil, description: nil, cols: nil, rows: nil, refresh_every: nil, options: {}, visible_on: nil, **args)
|
36
|
+
self.cards_holder ||= []
|
37
|
+
|
38
|
+
self.cards_holder << klass.new(
|
39
|
+
parent: self,
|
40
|
+
options: options,
|
41
|
+
index: cards_index,
|
42
|
+
label: label,
|
43
|
+
description: description,
|
44
|
+
cols: cols,
|
45
|
+
rows: rows,
|
46
|
+
refresh_every: refresh_every,
|
47
|
+
**args
|
48
|
+
)
|
49
|
+
self.cards_index += 1
|
50
|
+
end
|
51
|
+
|
52
|
+
def item_at_index(index)
|
53
|
+
cards.find do |item|
|
54
|
+
next if item.index.blank?
|
55
|
+
|
56
|
+
item.index == index
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
def divider(**args)
|
61
|
+
self.cards_holder ||= []
|
62
|
+
|
63
|
+
self.cards_holder << Avo::Dashboards::BaseDivider.new(**args)
|
64
|
+
self.cards_index += 1
|
65
|
+
end
|
66
|
+
|
67
|
+
def cards
|
68
|
+
self.cards_holder
|
69
|
+
end
|
70
|
+
|
71
|
+
def cards_classes
|
72
|
+
case grid_cols
|
73
|
+
when 3
|
74
|
+
"sm:grid-cols-3"
|
75
|
+
when 4
|
76
|
+
"sm:grid-cols-4"
|
77
|
+
when 5
|
78
|
+
"sm:grid-cols-5"
|
79
|
+
when 6
|
80
|
+
"sm:grid-cols-6"
|
81
|
+
else
|
82
|
+
"sm:grid-cols-3"
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
88
|
+
end
|
@@ -0,0 +1,48 @@
|
|
1
|
+
module Avo
|
2
|
+
module Concerns
|
3
|
+
module StylesCards
|
4
|
+
extend ActiveSupport::Concern
|
5
|
+
|
6
|
+
included do
|
7
|
+
class_attribute :cols, default: 1
|
8
|
+
class_attribute :rows, default: 1
|
9
|
+
|
10
|
+
def card_classes
|
11
|
+
result = ""
|
12
|
+
|
13
|
+
# Writing down the classes so TailwindCSS knows not to purge them
|
14
|
+
classes_for_cols = {
|
15
|
+
1 => " sm:col-span-1",
|
16
|
+
2 => " sm:col-span-2",
|
17
|
+
3 => " sm:col-span-3",
|
18
|
+
4 => " sm:col-span-4",
|
19
|
+
5 => " sm:col-span-5",
|
20
|
+
6 => " sm:col-span-6"
|
21
|
+
}
|
22
|
+
|
23
|
+
classes_for_rows = {
|
24
|
+
1 => " sm:row-span-1 min-h-[8rem]",
|
25
|
+
2 => " sm:row-span-2 min-h-[16rem]",
|
26
|
+
3 => " sm:row-span-3 min-h-[24rem]",
|
27
|
+
4 => " sm:row-span-4 min-h-[32rem]",
|
28
|
+
5 => " sm:row-span-5 min-h-[40rem]",
|
29
|
+
6 => " sm:row-span-6 min-h-[48rem]",
|
30
|
+
}
|
31
|
+
|
32
|
+
result += classes_for_cols[cols.to_i] if classes_for_cols[cols.to_i].present?
|
33
|
+
result += classes_for_rows[rows.to_i] if classes_for_rows[rows.to_i].present?
|
34
|
+
|
35
|
+
result
|
36
|
+
end
|
37
|
+
|
38
|
+
def cols
|
39
|
+
@cols || self.class.cols
|
40
|
+
end
|
41
|
+
|
42
|
+
def rows
|
43
|
+
@rows || self.class.rows
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
@@ -3,63 +3,18 @@ module Avo
|
|
3
3
|
class BaseDashboard
|
4
4
|
extend ActiveSupport::DescendantsTracker
|
5
5
|
|
6
|
+
include Avo::Concerns::HasCards
|
7
|
+
|
6
8
|
class_attribute :id
|
7
9
|
class_attribute :name
|
8
10
|
class_attribute :description
|
9
|
-
class_attribute :items_holder
|
10
|
-
class_attribute :grid_cols, default: 3
|
11
11
|
class_attribute :visible, default: true
|
12
12
|
class_attribute :index, default: 0
|
13
13
|
|
14
|
-
|
15
|
-
|
16
|
-
self.items_holder ||= []
|
17
|
-
|
18
|
-
self.items_holder << klass.new(dashboard: self,
|
19
|
-
label: label,
|
20
|
-
description: description,
|
21
|
-
cols: cols,
|
22
|
-
rows: rows,
|
23
|
-
refresh_every: refresh_every,
|
24
|
-
options: options,
|
25
|
-
index: index
|
26
|
-
)
|
27
|
-
self.index += 1
|
28
|
-
end
|
29
|
-
|
30
|
-
def item_at_index(index)
|
31
|
-
items.find do |item|
|
32
|
-
next if item.index.blank?
|
33
|
-
|
34
|
-
item.index == index
|
35
|
-
end
|
36
|
-
end
|
37
|
-
|
38
|
-
def divider(**args)
|
39
|
-
self.items_holder ||= []
|
40
|
-
|
41
|
-
self.items_holder << BaseDivider.new(**args)
|
42
|
-
end
|
43
|
-
|
44
|
-
def items
|
45
|
-
self.items_holder
|
46
|
-
end
|
47
|
-
|
48
|
-
def classes
|
49
|
-
case grid_cols
|
50
|
-
when 3
|
51
|
-
"sm:grid-cols-3"
|
52
|
-
when 4
|
53
|
-
"sm:grid-cols-4"
|
54
|
-
when 5
|
55
|
-
"sm:grid-cols-5"
|
56
|
-
when 6
|
57
|
-
"sm:grid-cols-6"
|
58
|
-
else
|
59
|
-
"sm:grid-cols-3"
|
60
|
-
end
|
61
|
-
end
|
14
|
+
attr_reader :view
|
15
|
+
attr_reader :params
|
62
16
|
|
17
|
+
class << self
|
63
18
|
def navigation_label
|
64
19
|
name
|
65
20
|
end
|
@@ -84,6 +39,16 @@ module Avo
|
|
84
39
|
!is_visible?
|
85
40
|
end
|
86
41
|
end
|
42
|
+
|
43
|
+
def initialize
|
44
|
+
@view = :dashboard
|
45
|
+
end
|
46
|
+
|
47
|
+
def hydrate(params:)
|
48
|
+
@params = params
|
49
|
+
|
50
|
+
self
|
51
|
+
end
|
87
52
|
end
|
88
53
|
end
|
89
54
|
end
|
@@ -5,12 +5,16 @@ module Avo
|
|
5
5
|
attr_reader :invisible
|
6
6
|
attr_reader :index
|
7
7
|
|
8
|
+
include Avo::Fields::FieldExtensions::VisibleInDifferentViews
|
9
|
+
|
8
10
|
class_attribute :id
|
9
11
|
|
10
|
-
def initialize(label: nil, invisible: false, index: nil)
|
12
|
+
def initialize(label: nil, invisible: false, index: nil, **args)
|
11
13
|
@label = label
|
12
14
|
@invisible = invisible
|
13
15
|
@index = index
|
16
|
+
|
17
|
+
initialize_visibility args
|
14
18
|
end
|
15
19
|
|
16
20
|
def is_divider?
|
@@ -23,8 +23,8 @@ module Avo
|
|
23
23
|
end
|
24
24
|
|
25
25
|
def chartkick_options
|
26
|
-
card_height =
|
27
|
-
card_heading =
|
26
|
+
card_height = 128
|
27
|
+
card_heading = 30
|
28
28
|
|
29
29
|
default = {
|
30
30
|
# figure our the available height for the chart
|
@@ -35,7 +35,7 @@ module Avo
|
|
35
35
|
points: false,
|
36
36
|
animation: true
|
37
37
|
},
|
38
|
-
id: "#{
|
38
|
+
id: "#{parent.id}-#{rand(10_000..99_999)}"
|
39
39
|
}
|
40
40
|
|
41
41
|
no_scale_options = {display: false}
|
@@ -54,7 +54,7 @@ module Avo
|
|
54
54
|
class_attribute :item_type, default: :field
|
55
55
|
|
56
56
|
def initialize(id, **args, &block)
|
57
|
-
super(id, **args, &block)
|
57
|
+
# super(id, **args, &block)
|
58
58
|
|
59
59
|
@id = id
|
60
60
|
@name = args[:name]
|
@@ -83,11 +83,7 @@ module Avo
|
|
83
83
|
@computed = block.present?
|
84
84
|
@computed_value = nil
|
85
85
|
|
86
|
-
|
87
|
-
show_on args[:show_on] if args[:show_on].present?
|
88
|
-
hide_on args[:hide_on] if args[:hide_on].present?
|
89
|
-
only_on args[:only_on] if args[:only_on].present?
|
90
|
-
except_on args[:except_on] if args[:except_on].present?
|
86
|
+
initialize_visibility args
|
91
87
|
end
|
92
88
|
|
93
89
|
def hydrate(model: nil, resource: nil, action: nil, view: nil, panel_name: nil, user: nil)
|