lesli_dashboard 1.1.3 → 1.1.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/app/assets/stylesheets/lesli_dashboard/application.css +18 -0
- data/app/controllers/lesli_dashboard/components_controller.rb +71 -49
- data/app/controllers/lesli_dashboard/dashboards_controller.rb +88 -3
- data/app/controllers/lesli_dashboard/shared/dashboards_controller.rb +11 -11
- data/app/helpers/lesli_dashboard/components_helper.rb +2 -2
- data/app/models/lesli_dashboard/account.rb +10 -9
- data/app/models/lesli_dashboard/component.rb +15 -2
- data/app/models/lesli_dashboard/dashboard.rb +5 -1
- data/app/models/lesli_dashboard/shared/dashboard.rb +6 -50
- data/app/operators/lesli_dashboard/dashboard_registration_operator.rb +32 -0
- data/app/presenters/lesli_dashboard/dashboard_presenter.rb +31 -0
- data/app/services/lesli_dashboard/component_service.rb +123 -0
- data/app/services/lesli_dashboard/dashboard_service.rb +124 -30
- data/app/views/lesli_dashboard/components/_component.html.erb +48 -2
- data/app/views/lesli_dashboard/components/_form.html.erb +13 -16
- data/app/views/lesli_dashboard/components/_list.html.erb +9 -0
- data/app/views/lesli_dashboard/components/index.html.erb +7 -16
- data/app/views/lesli_dashboard/dashboards/_actions.html.erb +19 -0
- data/app/views/lesli_dashboard/dashboards/_component-calendar.html.erb +1 -1
- data/app/views/lesli_dashboard/dashboards/_form.html.erb +29 -0
- data/app/views/lesli_dashboard/dashboards/edit.html.erb +8 -32
- data/app/views/lesli_dashboard/dashboards/index.html.erb +21 -32
- data/app/views/lesli_dashboard/dashboards/new.html.erb +4 -32
- data/app/views/lesli_dashboard/dashboards/shared/_header.html.erb +13 -2
- data/app/views/lesli_dashboard/dashboards/shared/_navigation.html.erb +20 -0
- data/app/views/lesli_dashboard/dashboards/shared/show.html.erb +24 -31
- data/app/views/lesli_dashboard/dashboards/show.html.erb +7 -2
- data/config/locales/translations.en.yml +55 -3
- data/config/locales/translations.es.yml +59 -3
- data/config/locales/translations.fr.yml +55 -3
- data/config/locales/translations.it.yml +55 -3
- data/config/locales/translations.pt.yml +55 -3
- data/config/routes.rb +6 -0
- data/db/migrate/0306050110_create_lesli_dashboard_dashboards.rb +8 -4
- data/db/migrate/20260118063343_create_lesli_dashboard_components.rb +5 -4
- data/lib/lesli_dashboard/version.rb +2 -2
- data/lib/lesli_dashboard/widget_catalog.rb +43 -0
- data/lib/lesli_dashboard.rb +1 -0
- data/lib/tasks/lesli_dashboard_tasks.rake +11 -11
- data/readme.md +15 -8
- metadata +10 -8
- data/app/controllers/lesli_dashboard/dashboard/components_controller.rb +0 -60
- data/app/models/lesli_dashboard/dashboard/component.rb +0 -50
- data/app/views/lesli_dashboard/components/edit.html.erb +0 -12
- data/app/views/lesli_dashboard/components/new.html.erb +0 -11
- data/app/views/lesli_dashboard/components/show.html.erb +0 -10
- data/app/views/lesli_dashboard/dashboards/shared/edit.html.erb +0 -0
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 6a7249ab6b9d099f3bb760861a6127072d59b7adc30ab00ba04c8091cc605108
|
|
4
|
+
data.tar.gz: 79118f3971712e08b1ceeed57fa008ee48bd1608fe1bc62701c38c59e171b24b
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 40153f4f035f6cfcef77d3317b3caa6102fd0a6e0473462fd0bff9be0c143f4844e802f77f2f5784a9fa2f3df34319318098881371c7b9bf8da06be8861e1331
|
|
7
|
+
data.tar.gz: cc2d24b9cd81d1bdc5c8db6d1fd9c476b36ab2455f3c9dcd11bc7a9b3ee7c5f2ec72f7299ff4fa9cd15648da8a0ce678d50e02beb0fb07a94cc89c95cdc16a03
|
|
@@ -47,6 +47,12 @@ Building a better future, one line of code at a time.
|
|
|
47
47
|
.mt-6 {
|
|
48
48
|
margin-top: calc(var(--spacing) * 6);
|
|
49
49
|
}
|
|
50
|
+
.mb-6 {
|
|
51
|
+
margin-bottom: calc(var(--spacing) * 6);
|
|
52
|
+
}
|
|
53
|
+
.flex {
|
|
54
|
+
display: flex;
|
|
55
|
+
}
|
|
50
56
|
.grid {
|
|
51
57
|
display: grid;
|
|
52
58
|
}
|
|
@@ -62,9 +68,21 @@ Building a better future, one line of code at a time.
|
|
|
62
68
|
.grid-cols-12 {
|
|
63
69
|
grid-template-columns: repeat(12, minmax(0, 1fr));
|
|
64
70
|
}
|
|
71
|
+
.flex-wrap {
|
|
72
|
+
flex-wrap: wrap;
|
|
73
|
+
}
|
|
74
|
+
.items-center {
|
|
75
|
+
align-items: center;
|
|
76
|
+
}
|
|
65
77
|
.items-stretch {
|
|
66
78
|
align-items: stretch;
|
|
67
79
|
}
|
|
80
|
+
.justify-center {
|
|
81
|
+
justify-content: center;
|
|
82
|
+
}
|
|
83
|
+
.gap-3 {
|
|
84
|
+
gap: calc(var(--spacing) * 3);
|
|
85
|
+
}
|
|
68
86
|
.gap-4 {
|
|
69
87
|
gap: calc(var(--spacing) * 4);
|
|
70
88
|
}
|
|
@@ -1,60 +1,82 @@
|
|
|
1
1
|
module LesliDashboard
|
|
2
|
-
|
|
3
|
-
|
|
2
|
+
class ComponentsController < ApplicationController
|
|
3
|
+
before_action :load_dashboard
|
|
4
|
+
before_action :load_component, only: [:update, :destroy, :move]
|
|
5
|
+
rescue_from ActiveRecord::RecordNotFound do
|
|
6
|
+
respond_with_not_found
|
|
7
|
+
end
|
|
4
8
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
+
def index
|
|
10
|
+
prepare_editor
|
|
11
|
+
respond_with_lesli(json: @components)
|
|
12
|
+
end
|
|
9
13
|
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
14
|
+
def create
|
|
15
|
+
@service.create(params.require(:component).permit(:component).to_h.symbolize_keys)
|
|
16
|
+
respond_to_mutation(:created)
|
|
17
|
+
end
|
|
13
18
|
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
19
|
+
def update
|
|
20
|
+
widget = @service.widgets.find { |definition| definition.identifier == @service.result.component }
|
|
21
|
+
keys = widget ? widget.settings.keys : []
|
|
22
|
+
attributes = params.require(:component).permit(:size, config: keys).to_h.symbolize_keys
|
|
23
|
+
@service.update(attributes)
|
|
24
|
+
respond_to_mutation(:updated)
|
|
25
|
+
end
|
|
18
26
|
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
27
|
+
def move
|
|
28
|
+
@service.move(params.require(:direction))
|
|
29
|
+
respond_to_mutation(:moved)
|
|
30
|
+
end
|
|
22
31
|
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
32
|
+
def destroy
|
|
33
|
+
@service.destroy
|
|
34
|
+
respond_to_mutation(:removed)
|
|
35
|
+
end
|
|
26
36
|
|
|
27
|
-
|
|
28
|
-
redirect_to @component, notice: "Component was successfully created."
|
|
29
|
-
else
|
|
30
|
-
render :new, status: :unprocessable_content
|
|
31
|
-
end
|
|
32
|
-
end
|
|
37
|
+
private
|
|
33
38
|
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
else
|
|
39
|
-
render :edit, status: :unprocessable_content
|
|
40
|
-
end
|
|
41
|
-
end
|
|
39
|
+
def load_dashboard
|
|
40
|
+
@service = ComponentService.new(current_user, dashboard_id: params[:dashboard_id])
|
|
41
|
+
@dashboard = @service.dashboard
|
|
42
|
+
end
|
|
42
43
|
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
redirect_to components_path, notice: "Component was successfully destroyed.", status: :see_other
|
|
47
|
-
end
|
|
44
|
+
def load_component
|
|
45
|
+
@service.find(params[:id])
|
|
46
|
+
end
|
|
48
47
|
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
48
|
+
def prepare_editor
|
|
49
|
+
@widgets = @service.widgets.index_by(&:identifier)
|
|
50
|
+
@components = @dashboard.components.order(:position, :id).to_a
|
|
51
|
+
@new_component = @dashboard.components.build
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
def respond_to_mutation(message)
|
|
55
|
+
component = @service.result
|
|
56
|
+
prepare_editor
|
|
57
|
+
if @service.successful?
|
|
58
|
+
streams = if action_name == "update"
|
|
59
|
+
[turbo_stream.replace("dashboard-component-#{component.id}", partial: "lesli_dashboard/components/component", locals: { component: component })]
|
|
60
|
+
else
|
|
61
|
+
[turbo_stream.replace("dashboard-components-list", partial: "lesli_dashboard/components/list")]
|
|
62
|
+
end
|
|
63
|
+
streams << turbo_stream.replace("dashboard-component-form", partial: "lesli_dashboard/components/form") if action_name == "create"
|
|
64
|
+
streams << stream_notification_success(t("lesli_dashboard.components.#{message}"))
|
|
65
|
+
respond_with_lesli(
|
|
66
|
+
turbo: streams, json: { component: component, components: @components },
|
|
67
|
+
redirect: managed_dashboard_components_path(@dashboard), status: action_name == "create" ? :created : :ok
|
|
68
|
+
)
|
|
69
|
+
else
|
|
70
|
+
@new_component = component if action_name == "create"
|
|
71
|
+
@components.map! { |record| record.id == component.id ? component : record }
|
|
72
|
+
target = action_name == "create" ? "dashboard-component-form" : "dashboard-component-#{component.id}"
|
|
73
|
+
partial = action_name == "create" ? "form" : "component"
|
|
74
|
+
respond_with_lesli(
|
|
75
|
+
html: :index, status: :unprocessable_content,
|
|
76
|
+
json: { errors: component.errors.to_hash },
|
|
77
|
+
turbo: turbo_stream.replace(target, partial: "lesli_dashboard/components/#{partial}", locals: { component: component })
|
|
78
|
+
)
|
|
79
|
+
end
|
|
80
|
+
end
|
|
81
|
+
end
|
|
60
82
|
end
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
Lesli
|
|
4
4
|
|
|
5
|
-
Copyright (c)
|
|
5
|
+
Copyright (c) 2026, Lesli Technologies, S. A.
|
|
6
6
|
|
|
7
7
|
This program is free software: you can redistribute it and/or modify
|
|
8
8
|
it under the terms of the GNU General Public License as published by
|
|
@@ -19,7 +19,7 @@ along with this program. If not, see http://www.gnu.org/licenses/.
|
|
|
19
19
|
|
|
20
20
|
Lesli · Ruby on Rails SaaS Development Framework.
|
|
21
21
|
|
|
22
|
-
Made with ♥ by
|
|
22
|
+
Made with ♥ by LesliTech
|
|
23
23
|
Building a better future, one line of code at a time.
|
|
24
24
|
|
|
25
25
|
@contact hello@lesli.tech
|
|
@@ -29,8 +29,93 @@ Building a better future, one line of code at a time.
|
|
|
29
29
|
// · ~·~ ~·~ ~·~ ~·~ ~·~ ~·~ ~·~ ~·~ ~·~
|
|
30
30
|
// ·
|
|
31
31
|
=end
|
|
32
|
-
|
|
33
32
|
module LesliDashboard
|
|
34
33
|
class DashboardsController < Lesli::Shared::DashboardsController
|
|
34
|
+
helper_method :dashboard_action_allowed?
|
|
35
|
+
|
|
36
|
+
before_action :load_dashboard, only: [:edit, :update, :destroy]
|
|
37
|
+
|
|
38
|
+
def index
|
|
39
|
+
@dashboards = DashboardService.new(current_user).index.result
|
|
40
|
+
respond_with_lesli(json: @dashboards)
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
def show
|
|
44
|
+
return super unless params[:id]
|
|
45
|
+
|
|
46
|
+
@service = DashboardService.new(current_user).find(params[:id])
|
|
47
|
+
return respond_with_not_found unless @service.found?
|
|
48
|
+
|
|
49
|
+
@dashboard = @service.result
|
|
50
|
+
@dashboard_engine = @dashboard.engine
|
|
51
|
+
@dashboards = DashboardService.new(current_user).index(engine: @dashboard.engine).result
|
|
52
|
+
@components = @dashboard.components.order(:position, :id)
|
|
53
|
+
@dashboard_presenter = DashboardPresenter.new(@dashboard)
|
|
54
|
+
respond_with_lesli(json: @dashboard)
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
def new
|
|
58
|
+
engine = params[:engine] if WidgetCatalog.engines.include?(params[:engine])
|
|
59
|
+
@dashboard = Dashboard.new(engine: engine)
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
def edit
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
def create
|
|
66
|
+
@service = DashboardService.new(current_user).create(dashboard_params)
|
|
67
|
+
@dashboard = @service.result
|
|
68
|
+
return render_form(:new) unless @service.successful?
|
|
69
|
+
|
|
70
|
+
success(t("lesli_dashboard.dashboards.created"))
|
|
71
|
+
respond_with_lesli(json: @dashboard, status: :created, redirect: managed_dashboard_path(@dashboard))
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
def update
|
|
75
|
+
@service.update(dashboard_params)
|
|
76
|
+
@dashboard = @service.result
|
|
77
|
+
return render_form(:edit) unless @service.successful?
|
|
78
|
+
|
|
79
|
+
success(t("lesli_dashboard.dashboards.updated"))
|
|
80
|
+
respond_with_lesli(json: @dashboard, redirect: managed_dashboard_path(@dashboard))
|
|
81
|
+
end
|
|
82
|
+
|
|
83
|
+
def destroy
|
|
84
|
+
@service.destroy
|
|
85
|
+
success(t("lesli_dashboard.dashboards.deleted"))
|
|
86
|
+
respond_with_lesli(json: { id: @dashboard.id }, redirect: managed_dashboards_path)
|
|
87
|
+
end
|
|
88
|
+
|
|
89
|
+
private
|
|
90
|
+
|
|
91
|
+
def dashboard_action_allowed?(action)
|
|
92
|
+
!defined?(LesliShield) || current_user.has_privileges_for?("lesli_dashboard/dashboards", action)
|
|
93
|
+
end
|
|
94
|
+
|
|
95
|
+
def load_dashboard
|
|
96
|
+
@service = DashboardService.new(current_user)
|
|
97
|
+
# Preserve the existing singular edit URL for the engine's default.
|
|
98
|
+
@service = if params[:id]
|
|
99
|
+
@service.find(params[:id])
|
|
100
|
+
else
|
|
101
|
+
@service.show(engine: "LesliDashboard", id: params[:dashboard_id])
|
|
102
|
+
end
|
|
103
|
+
return respond_with_not_found unless @service.found?
|
|
104
|
+
|
|
105
|
+
@dashboard = @service.result
|
|
106
|
+
end
|
|
107
|
+
|
|
108
|
+
def dashboard_params
|
|
109
|
+
params.require(:dashboard).permit(:name, :engine, :default).to_h.symbolize_keys
|
|
110
|
+
end
|
|
111
|
+
|
|
112
|
+
def render_form(template)
|
|
113
|
+
respond_with_lesli(
|
|
114
|
+
html: template,
|
|
115
|
+
json: { errors: @dashboard.errors.to_hash },
|
|
116
|
+
turbo: turbo_stream.replace("dashboard-form", partial: "lesli_dashboard/dashboards/form"),
|
|
117
|
+
status: :unprocessable_content
|
|
118
|
+
)
|
|
119
|
+
end
|
|
35
120
|
end
|
|
36
121
|
end
|
|
@@ -33,18 +33,18 @@ Building a better future, one line of code at a time.
|
|
|
33
33
|
module LesliDashboard
|
|
34
34
|
module Shared
|
|
35
35
|
class DashboardsController < ApplicationController
|
|
36
|
-
#before_action :set_dashboard, only: [:show, :update, :destroy, :options]
|
|
37
|
-
|
|
38
|
-
def edit
|
|
39
|
-
# renders the edit view for dashboard
|
|
40
|
-
end
|
|
41
|
-
|
|
42
36
|
def show
|
|
43
|
-
|
|
44
|
-
@
|
|
45
|
-
@
|
|
46
|
-
@
|
|
47
|
-
|
|
37
|
+
engine = self.class.module_parent.name
|
|
38
|
+
@dashboard_engine = engine
|
|
39
|
+
@dashboard_entry_path = request.path
|
|
40
|
+
@dashboards = DashboardService.new(current_user).index(engine: engine).result
|
|
41
|
+
@dashboard = DashboardService.new(current_user).show(
|
|
42
|
+
engine: engine,
|
|
43
|
+
id: params[:dashboard_id]
|
|
44
|
+
).result
|
|
45
|
+
|
|
46
|
+
@components = @dashboard ? @dashboard.components.order(:position, :id) : []
|
|
47
|
+
@dashboard_presenter = DashboardPresenter.new(@dashboard)
|
|
48
48
|
render(template:"lesli/shared/dashboards/show")
|
|
49
49
|
end
|
|
50
50
|
end
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
Lesli
|
|
4
4
|
|
|
5
|
-
Copyright (c)
|
|
5
|
+
Copyright (c) 2026, Lesli Technologies, S. A.
|
|
6
6
|
|
|
7
7
|
This program is free software: you can redistribute it and/or modify
|
|
8
8
|
it under the terms of the GNU General Public License as published by
|
|
@@ -19,11 +19,11 @@ along with this program. If not, see http://www.gnu.org/licenses/.
|
|
|
19
19
|
|
|
20
20
|
Lesli · Ruby on Rails SaaS Development Framework.
|
|
21
21
|
|
|
22
|
-
Made with ♥ by
|
|
22
|
+
Made with ♥ by LesliTech
|
|
23
23
|
Building a better future, one line of code at a time.
|
|
24
24
|
|
|
25
25
|
@contact hello@lesli.tech
|
|
26
|
-
@website https://www.lesli.
|
|
26
|
+
@website https://www.lesli.tech
|
|
27
27
|
@license GPLv3 http://www.gnu.org/licenses/gpl-3.0.en.html
|
|
28
28
|
|
|
29
29
|
// · ~·~ ~·~ ~·~ ~·~ ~·~ ~·~ ~·~ ~·~ ~·~
|
|
@@ -32,14 +32,15 @@ Building a better future, one line of code at a time.
|
|
|
32
32
|
|
|
33
33
|
module LesliDashboard
|
|
34
34
|
class Account < ApplicationRecord
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
inverse_of: :dashboard
|
|
35
|
+
self.table_name = "lesli_dashboard_accounts"
|
|
36
|
+
belongs_to :account, class_name: "Lesli::Account", inverse_of: :dashboard
|
|
38
37
|
validates :account_id, uniqueness: true
|
|
39
38
|
|
|
40
|
-
has_many :dashboards
|
|
41
|
-
has_many :users,
|
|
39
|
+
has_many :dashboards, inverse_of: :account
|
|
40
|
+
has_many :users, through: :account
|
|
42
41
|
|
|
42
|
+
# Core account creation provisions this workspace. Initialize dashboards
|
|
43
|
+
# in the same transaction so SaaS signups need no maintenance task.
|
|
43
44
|
after_create :initialize_account
|
|
44
45
|
|
|
45
46
|
def initialize_account
|
|
@@ -47,7 +48,7 @@ module LesliDashboard
|
|
|
47
48
|
end
|
|
48
49
|
|
|
49
50
|
def initialize_dashboards(account)
|
|
50
|
-
|
|
51
|
+
DashboardRegistrationOperator.new(account).operate
|
|
51
52
|
end
|
|
52
53
|
end
|
|
53
54
|
end
|
|
@@ -1,6 +1,19 @@
|
|
|
1
1
|
module LesliDashboard
|
|
2
2
|
class Component < ApplicationRecord
|
|
3
|
-
|
|
4
|
-
|
|
3
|
+
self.table_name = "lesli_dashboard_components"
|
|
4
|
+
|
|
5
|
+
belongs_to :dashboard, inverse_of: :components
|
|
6
|
+
validates :component, presence: true
|
|
7
|
+
validates :size, numericality: { only_integer: true, in: 1..12 }
|
|
8
|
+
validates :position, numericality: { only_integer: true, greater_than: 0 }
|
|
9
|
+
validate :config_is_an_object
|
|
10
|
+
|
|
11
|
+
COMPONENTS_GENERAL = %i[count chart_bar chart_line date weather calendar].freeze
|
|
12
|
+
|
|
13
|
+
private
|
|
14
|
+
|
|
15
|
+
def config_is_an_object
|
|
16
|
+
errors.add(:config, :invalid) unless config.is_a?(Hash)
|
|
17
|
+
end
|
|
5
18
|
end
|
|
6
19
|
end
|
|
@@ -32,11 +32,15 @@ Building a better future, one line of code at a time.
|
|
|
32
32
|
|
|
33
33
|
module LesliDashboard
|
|
34
34
|
class Dashboard < Lesli::Shared::Dashboard
|
|
35
|
+
self.table_name = "lesli_dashboard_dashboards"
|
|
35
36
|
COMPONENTS = [
|
|
36
37
|
:count,
|
|
37
38
|
:chart_bar,
|
|
38
39
|
:chart_line,
|
|
39
|
-
:
|
|
40
|
+
{ calendar: {
|
|
41
|
+
config: { week_starts_on: "sunday" },
|
|
42
|
+
settings: { week_starts_on: { type: :select, choices: %w[sunday monday] } }
|
|
43
|
+
} },
|
|
40
44
|
:date,
|
|
41
45
|
:weather]
|
|
42
46
|
end
|
|
@@ -4,58 +4,14 @@ module LesliDashboard
|
|
|
4
4
|
self.table_name = "lesli_dashboard_dashboards"
|
|
5
5
|
self.abstract_class = true
|
|
6
6
|
|
|
7
|
-
belongs_to :
|
|
8
|
-
|
|
9
|
-
has_many :components, class_name: 'LesliDashboard::Component'
|
|
7
|
+
belongs_to :account, class_name: "LesliDashboard::Account", inverse_of: :dashboards
|
|
8
|
+
has_many :components, class_name: "LesliDashboard::Component", inverse_of: :dashboard
|
|
10
9
|
|
|
11
|
-
|
|
12
|
-
|
|
10
|
+
normalizes :name, with: ->(name) { name.strip }
|
|
11
|
+
validates :name, :engine, presence: true
|
|
12
|
+
attr_readonly :account_id, :engine
|
|
13
13
|
|
|
14
|
-
COMPONENTS = []
|
|
15
|
-
|
|
16
|
-
private
|
|
17
|
-
|
|
18
|
-
# @return [void]
|
|
19
|
-
# @descriptions This is an after_updated and after_create method that validates that at any moment in time, there is only
|
|
20
|
-
# one default dashboard in the engine. If there is another default dashboard, it's *default* field is set to false
|
|
21
|
-
# before committing the changes
|
|
22
|
-
# @example
|
|
23
|
-
# CloudFocus::Dasbhoard.where(default: false).first.update!(default: true)
|
|
24
|
-
# # This will automatically trigger this function and remove the *default* field from the old default dashboard
|
|
25
|
-
def verify_default_dashboard
|
|
26
|
-
if default
|
|
27
|
-
dashboards = self.class.where.not(id: id).where(account: account)
|
|
28
|
-
self.class.where.not(id: id).where(account: account).update_all(default: false)
|
|
29
|
-
end
|
|
30
|
-
|
|
31
|
-
unless self.class.where(account: account).find_by(default: true)
|
|
32
|
-
errors.add(:base, I18n.t("core.dashboards.messages_danger_default_dashboard_must_exist"))
|
|
33
|
-
raise ActiveRecord::Rollback
|
|
34
|
-
end
|
|
35
|
-
end
|
|
36
|
-
|
|
37
|
-
# Build the Rails models and engine information for
|
|
38
|
-
# the current engine implementing the shared dashboards
|
|
39
|
-
# Example: For the LesliAudit engine
|
|
40
|
-
# {
|
|
41
|
-
# :module_name => "audit",
|
|
42
|
-
# :module_name_full => "LesliAudit",
|
|
43
|
-
# :module_model => "LesliAudit::Dashboard",
|
|
44
|
-
# :module_model_component => "LesliAudit::Dashboard::Component"
|
|
45
|
-
# }
|
|
46
|
-
def self.dynamic_info
|
|
47
|
-
|
|
48
|
-
module_info = self.name.split("::")
|
|
49
|
-
|
|
50
|
-
module_name = module_info[0].sub("Lesli", "").downcase
|
|
51
|
-
|
|
52
|
-
{
|
|
53
|
-
module_name: module_name,
|
|
54
|
-
module_name_full: module_info[0],
|
|
55
|
-
module_model: "#{ module_info[0] }::Dashboard".constantize,
|
|
56
|
-
module_model_component: "#{ module_info[0] }::Dashboard::Component".constantize
|
|
57
|
-
}
|
|
58
|
-
end
|
|
14
|
+
COMPONENTS = [].freeze
|
|
59
15
|
end
|
|
60
16
|
end
|
|
61
17
|
end
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
module LesliDashboard
|
|
2
|
+
class DashboardRegistrationOperator
|
|
3
|
+
def initialize(account)
|
|
4
|
+
@account = account
|
|
5
|
+
end
|
|
6
|
+
|
|
7
|
+
def operate
|
|
8
|
+
# Keep the dashboard and all its initial components atomic. The workspace
|
|
9
|
+
# lock also serializes repeated registrations for the same account.
|
|
10
|
+
@account.with_lock do
|
|
11
|
+
WidgetCatalog.engines.each do |engine|
|
|
12
|
+
# A deleted dashboard records a deliberate choice; registration
|
|
13
|
+
# must not resurrect it or restore widgets removed by the user.
|
|
14
|
+
next if @account.dashboards.with_deleted.exists?(engine: engine)
|
|
15
|
+
|
|
16
|
+
dashboard = @account.dashboards.create!(
|
|
17
|
+
engine: engine,
|
|
18
|
+
name: I18n.t("lesli_dashboard.dashboards.initial_name",
|
|
19
|
+
engine: engine.delete_prefix("Lesli")),
|
|
20
|
+
default: true
|
|
21
|
+
)
|
|
22
|
+
WidgetCatalog.widgets(engine).each do |widget|
|
|
23
|
+
dashboard.components.create!(
|
|
24
|
+
widget.options.deep_dup.merge(component: widget.identifier)
|
|
25
|
+
)
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
@account
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
end
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
module LesliDashboard
|
|
2
|
+
class DashboardPresenter
|
|
3
|
+
# Literal classes keep every supported width discoverable by Tailwind.
|
|
4
|
+
WIDTH_CLASSES = {
|
|
5
|
+
1 => "md:col-span-6 lg:col-span-1",
|
|
6
|
+
2 => "md:col-span-6 lg:col-span-2",
|
|
7
|
+
3 => "md:col-span-6 lg:col-span-3",
|
|
8
|
+
4 => "md:col-span-6 lg:col-span-4",
|
|
9
|
+
5 => "md:col-span-6 lg:col-span-5",
|
|
10
|
+
6 => "md:col-span-6 lg:col-span-6",
|
|
11
|
+
7 => "md:col-span-12 lg:col-span-7",
|
|
12
|
+
8 => "md:col-span-12 lg:col-span-8",
|
|
13
|
+
9 => "md:col-span-12 lg:col-span-9",
|
|
14
|
+
10 => "md:col-span-12 lg:col-span-10",
|
|
15
|
+
11 => "md:col-span-12 lg:col-span-11",
|
|
16
|
+
12 => "md:col-span-12 lg:col-span-12",
|
|
17
|
+
}.freeze
|
|
18
|
+
|
|
19
|
+
def initialize(dashboard)
|
|
20
|
+
@widgets = dashboard ? WidgetCatalog.widgets(dashboard.engine).index_by(&:identifier) : {}
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
def width_class(component)
|
|
24
|
+
WIDTH_CLASSES.fetch(component.size, WIDTH_CLASSES.fetch(4))
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
def partial_path(component)
|
|
28
|
+
@widgets.fetch(component.component).partial
|
|
29
|
+
end
|
|
30
|
+
end
|
|
31
|
+
end
|