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.
Files changed (48) hide show
  1. checksums.yaml +4 -4
  2. data/app/assets/stylesheets/lesli_dashboard/application.css +18 -0
  3. data/app/controllers/lesli_dashboard/components_controller.rb +71 -49
  4. data/app/controllers/lesli_dashboard/dashboards_controller.rb +88 -3
  5. data/app/controllers/lesli_dashboard/shared/dashboards_controller.rb +11 -11
  6. data/app/helpers/lesli_dashboard/components_helper.rb +2 -2
  7. data/app/models/lesli_dashboard/account.rb +10 -9
  8. data/app/models/lesli_dashboard/component.rb +15 -2
  9. data/app/models/lesli_dashboard/dashboard.rb +5 -1
  10. data/app/models/lesli_dashboard/shared/dashboard.rb +6 -50
  11. data/app/operators/lesli_dashboard/dashboard_registration_operator.rb +32 -0
  12. data/app/presenters/lesli_dashboard/dashboard_presenter.rb +31 -0
  13. data/app/services/lesli_dashboard/component_service.rb +123 -0
  14. data/app/services/lesli_dashboard/dashboard_service.rb +124 -30
  15. data/app/views/lesli_dashboard/components/_component.html.erb +48 -2
  16. data/app/views/lesli_dashboard/components/_form.html.erb +13 -16
  17. data/app/views/lesli_dashboard/components/_list.html.erb +9 -0
  18. data/app/views/lesli_dashboard/components/index.html.erb +7 -16
  19. data/app/views/lesli_dashboard/dashboards/_actions.html.erb +19 -0
  20. data/app/views/lesli_dashboard/dashboards/_component-calendar.html.erb +1 -1
  21. data/app/views/lesli_dashboard/dashboards/_form.html.erb +29 -0
  22. data/app/views/lesli_dashboard/dashboards/edit.html.erb +8 -32
  23. data/app/views/lesli_dashboard/dashboards/index.html.erb +21 -32
  24. data/app/views/lesli_dashboard/dashboards/new.html.erb +4 -32
  25. data/app/views/lesli_dashboard/dashboards/shared/_header.html.erb +13 -2
  26. data/app/views/lesli_dashboard/dashboards/shared/_navigation.html.erb +20 -0
  27. data/app/views/lesli_dashboard/dashboards/shared/show.html.erb +24 -31
  28. data/app/views/lesli_dashboard/dashboards/show.html.erb +7 -2
  29. data/config/locales/translations.en.yml +55 -3
  30. data/config/locales/translations.es.yml +59 -3
  31. data/config/locales/translations.fr.yml +55 -3
  32. data/config/locales/translations.it.yml +55 -3
  33. data/config/locales/translations.pt.yml +55 -3
  34. data/config/routes.rb +6 -0
  35. data/db/migrate/0306050110_create_lesli_dashboard_dashboards.rb +8 -4
  36. data/db/migrate/20260118063343_create_lesli_dashboard_components.rb +5 -4
  37. data/lib/lesli_dashboard/version.rb +2 -2
  38. data/lib/lesli_dashboard/widget_catalog.rb +43 -0
  39. data/lib/lesli_dashboard.rb +1 -0
  40. data/lib/tasks/lesli_dashboard_tasks.rake +11 -11
  41. data/readme.md +15 -8
  42. metadata +10 -8
  43. data/app/controllers/lesli_dashboard/dashboard/components_controller.rb +0 -60
  44. data/app/models/lesli_dashboard/dashboard/component.rb +0 -50
  45. data/app/views/lesli_dashboard/components/edit.html.erb +0 -12
  46. data/app/views/lesli_dashboard/components/new.html.erb +0 -11
  47. data/app/views/lesli_dashboard/components/show.html.erb +0 -10
  48. data/app/views/lesli_dashboard/dashboards/shared/edit.html.erb +0 -0
@@ -0,0 +1,123 @@
1
+ module LesliDashboard
2
+ class ComponentService < Lesli::ApplicationLesliService
3
+ attr_reader :dashboard
4
+
5
+ def initialize(current_user, dashboard_id:)
6
+ super(current_user)
7
+ @dashboard = DashboardService.new(current_user).find(dashboard_id).result
8
+ raise ActiveRecord::RecordNotFound unless @dashboard
9
+ end
10
+
11
+ def index
12
+ response(dashboard.components.order(:position, :id))
13
+ end
14
+
15
+ def find(id)
16
+ response(dashboard.components.find(id))
17
+ end
18
+
19
+ def create(attributes)
20
+ component = dashboard.components.build(component: attributes[:component])
21
+ widget = widgets.find { |definition| definition.identifier == component.component }
22
+ unless widget
23
+ component.errors.add(:component, :invalid)
24
+ return failure(component)
25
+ end
26
+
27
+ # Appending and reordering use the same parent lock and transaction.
28
+ dashboard.with_lock do
29
+ component.assign_attributes(widget.options.deep_dup.except(:position))
30
+ component.position = (dashboard.components.maximum(:position) || 0) + 1
31
+ component.save!
32
+ end
33
+ response(component)
34
+ rescue ActiveRecord::RecordInvalid => exception
35
+ failure(exception.record)
36
+ end
37
+
38
+ def update(attributes)
39
+ component = resource
40
+ dashboard.with_lock do
41
+ component.reload
42
+ component.size = attributes[:size] if attributes.key?(:size)
43
+ assign_settings(component, attributes.fetch(:config, {}))
44
+ raise ActiveRecord::RecordInvalid.new(component) if component.errors.any?
45
+ component.save!
46
+ end
47
+ response(component)
48
+ rescue ActiveRecord::RecordInvalid => exception
49
+ failure(exception.record)
50
+ end
51
+
52
+ def move(direction)
53
+ unless %w[up down].include?(direction)
54
+ resource.errors.add(:position, :invalid)
55
+ return failure(resource)
56
+ end
57
+
58
+ dashboard.with_lock do
59
+ components = dashboard.components.order(:position, :id).to_a
60
+ index = components.index { |component| component.id == resource.id }
61
+ target = index + (direction == "up" ? -1 : 1)
62
+ if target.between?(0, components.length - 1)
63
+ components[index], components[target] = components[target], components[index]
64
+ # Normalize positions as well as swapping: older layouts may
65
+ # contain ties, which would otherwise make arrows unpredictable.
66
+ components.each_with_index { |component, position| component.update!(position: position + 1) }
67
+ end
68
+ end
69
+ response(resource.reload)
70
+ rescue ActiveRecord::RecordInvalid => exception
71
+ resource.errors.add(:base, exception.record.errors.full_messages.to_sentence)
72
+ failure(resource)
73
+ end
74
+
75
+ def destroy
76
+ dashboard.with_lock { resource.destroy! }
77
+ response(resource)
78
+ end
79
+
80
+ def widgets
81
+ WidgetCatalog.widgets(dashboard.engine)
82
+ end
83
+
84
+ private
85
+
86
+ def failure(component)
87
+ error(component.errors.full_messages.to_sentence)
88
+ response(component)
89
+ end
90
+
91
+ def assign_settings(component, attributes)
92
+ widget = widgets.find { |definition| definition.identifier == component.component }
93
+ # Retired widgets can still be resized or removed, but have no editable options.
94
+ settings = widget ? widget.settings : {}
95
+ config = component.config.deep_dup
96
+ attributes.stringify_keys.slice(*settings.keys.map(&:to_s)).each do |key, value|
97
+ definition = settings.fetch(key.to_sym)
98
+ config[key] = value
99
+ case definition.fetch(:type).to_sym
100
+ when :text
101
+ config[key] = value.to_s
102
+ when :integer
103
+ begin
104
+ config[key] = Integer(value.to_s, 10)
105
+ rescue ArgumentError
106
+ component.errors.add(:config, :invalid)
107
+ end
108
+ when :boolean
109
+ if [true, false, "true", "false", "1", "0"].include?(value)
110
+ config[key] = ActiveModel::Type::Boolean.new.cast(value)
111
+ else
112
+ component.errors.add(:config, :invalid)
113
+ end
114
+ when :select
115
+ component.errors.add(:config, :invalid) unless definition.fetch(:choices).include?(value)
116
+ else
117
+ raise ArgumentError, "Unsupported widget setting type: #{definition[:type]}"
118
+ end
119
+ end
120
+ component.config = config
121
+ end
122
+ end
123
+ end
@@ -1,46 +1,140 @@
1
1
  module LesliDashboard
2
2
  class DashboardService < Lesli::ApplicationLesliService
3
+ # Controller operations return this service: result holds the record or
4
+ # collection, while successful? and errors describe validation failures.
5
+ # Methods ending in ! return records directly and let exceptions propagate.
3
6
 
4
- DEFAULT_COMPONENT_OPTIONS = {
5
- size: 4,
6
- config: {},
7
- position: 1
8
- }.freeze
7
+ # List active dashboards for the current account in a stable display order.
8
+ def index(engine: nil)
9
+ records = engine ? dashboards.where(engine: engine) : dashboards
10
+ response(records.order(:engine, :name, :id))
11
+ end
9
12
 
10
- def register account
13
+ # Store an account-scoped lookup for subsequent update/destroy operations.
14
+ # A missing or inaccessible ID leaves result nil, so found? returns false.
15
+ def find(id)
16
+ response(dashboards.find_by(id: id))
17
+ end
11
18
 
12
- # Get all the installed and loaded engines
13
- # to register a base dashboard for every engine
14
- LesliSystem.engines.each do |engine, data|
19
+ # Create from submitted attributes using the authenticated user's workspace.
20
+ # Account ownership is never taken from the submitted form.
21
+ def create(attributes)
22
+ dashboard = current_user.account.dashboard.dashboards.build(attributes.slice(:name, :engine, :default))
23
+ dashboard.account.with_lock do
24
+ # Only engines declared by server-side code may own new dashboards.
25
+ unless WidgetCatalog.engines.include?(dashboard.engine)
26
+ dashboard.errors.add(:engine, :invalid)
27
+ raise ActiveRecord::RecordInvalid.new(dashboard)
28
+ end
29
+ siblings = dashboards.where(engine: dashboard.engine)
30
+ # The first active dashboard is always the default. Clear an existing
31
+ # default before saving its replacement to satisfy the unique index.
32
+ dashboard.default = true unless siblings.exists?
33
+ siblings.update_all(default: false) if dashboard.default?
34
+ dashboard.save!
35
+ end
36
+ response(dashboard)
37
+ rescue ActiveRecord::RecordInvalid => exception
38
+ # The transaction restores the previous default; keep the invalid record
39
+ # and its submitted values so the controller can render the form again.
40
+ error(exception.record.errors.full_messages.to_sentence)
41
+ response(exception.record)
42
+ end
15
43
 
16
- # Skip not work module engine
17
- next if ['Lesli', 'LesliBabel', 'Root'].include?(engine)
44
+ # Update the record previously loaded with find. Restrict editable fields
45
+ # so a dashboard cannot move to another account or engine.
46
+ def update(attributes)
47
+ dashboard = resource
48
+ dashboard.account.with_lock do
49
+ # Read the persisted default state after acquiring the workspace lock.
50
+ dashboard.reload
51
+ was_default = dashboard.default?
52
+ dashboard.assign_attributes(attributes.slice(:name, :default))
53
+ # Changing the default requires promoting another dashboard, rather
54
+ # than leaving an engine with active dashboards but no default.
55
+ if was_default && !dashboard.default?
56
+ dashboard.errors.add(:default, I18n.t("lesli_dashboard.dashboards.default_required"))
57
+ raise ActiveRecord::RecordInvalid.new(dashboard)
58
+ end
59
+ # Promotion and saving the edits must succeed or roll back together.
60
+ if dashboard.default?
61
+ dashboards.where(engine: dashboard.engine).where.not(id: dashboard.id).update_all(default: false)
62
+ end
63
+ dashboard.save!
64
+ end
65
+ response(dashboard)
66
+ rescue ActiveRecord::RecordInvalid => exception
67
+ error(exception.record.errors.full_messages.to_sentence)
68
+ response(exception.record)
69
+ end
18
70
 
19
- # Create a dashboard for the current engine
20
- dashboard = account.dashboards
21
- .create_with(:default => true)
22
- .find_or_create_by(engine: engine)
71
+ # Delete the scoped record loaded with find, preserving the service contract.
72
+ def destroy
73
+ response(destroy!(resource))
74
+ end
23
75
 
24
- # Get the components registered in every engine dashboard model
25
- "#{engine}::Dashboard".constantize::COMPONENTS.each do |component|
76
+ # Resolve an engine's entry point within the current account. With no ID,
77
+ # return its default or nil for the empty state. An explicit ID must match
78
+ # both scopes; missing, deleted or inaccessible records raise RecordNotFound.
79
+ def show(engine:, id: nil)
80
+ workspace = current_user.account.dashboard
81
+ dashboards = workspace ? workspace.dashboards.where(engine: engine) : Dashboard.none
82
+ response(id.nil? ? dashboards.find_by(default: true) : dashboards.find(id))
83
+ end
26
84
 
27
- name, options =
28
- case component
29
- when Symbol
30
- [component, {}]
31
- when Hash
32
- component.first
33
- else
34
- raise ArgumentError, "Invalid dashboard component: #{component.inspect}"
35
- end
85
+ # Explicit creation for trusted application code. The caller supplies the
86
+ # workspace and engine; this method does not use the authenticated context
87
+ # or validate catalog membership. Pass default as a boolean.
88
+ # Workspace locking keeps creation and default changes in one transaction.
89
+ # The unique index also prevents duplicate active defaults from other writers.
90
+ def create!(account:, engine:, name:, default: false)
91
+ account.with_lock do
92
+ dashboards = account.dashboards.where(engine: engine)
93
+ make_default = default || !dashboards.exists?
94
+ dashboards.update_all(default: false) if make_default
95
+ dashboards.create!(name: name, default: make_default)
96
+ end
97
+ end
36
98
 
37
- final_options = DEFAULT_COMPONENT_OPTIONS.merge(options || {})
99
+ # Promote a trusted dashboard record within its own account and engine.
100
+ # Callers must resolve access before passing a record to this operation.
101
+ def make_default!(dashboard)
102
+ dashboard.account.with_lock do
103
+ dashboard.reload
104
+ dashboard.account.dashboards.where(engine: dashboard.engine)
105
+ .where.not(id: dashboard.id).update_all(default: false)
106
+ dashboard.update!(default: true)
107
+ dashboard
108
+ end
109
+ end
38
110
 
39
- dashboard.components
40
- .create_with(final_options)
41
- .find_or_create_by(component: name)
111
+ # Soft-delete a trusted dashboard record and replace its default atomically.
112
+ # Callers must resolve access first, as this method uses the record's account.
113
+ def destroy!(dashboard)
114
+ dashboard.account.with_lock do
115
+ dashboard.reload
116
+ was_default = dashboard.default?
117
+ dashboard.update!(default: false)
118
+ # Keep component records with their soft-deleted parent.
119
+ dashboard.destroy!
120
+ if was_default
121
+ # Prefer the oldest remaining dashboard, with ID as a stable
122
+ # tie-breaker. Deleting the last dashboard leaves no replacement.
123
+ replacement = dashboard.account.dashboards.where(engine: dashboard.engine)
124
+ .order(:created_at, :id).first
125
+ replacement&.update!(default: true)
42
126
  end
127
+ dashboard
43
128
  end
44
129
  end
130
+
131
+ private
132
+
133
+ # Shared account boundary for controller operations. The model's soft-delete
134
+ # scope excludes deleted dashboards; a missing workspace is an empty relation.
135
+ def dashboards
136
+ workspace = current_user.account.dashboard
137
+ workspace ? workspace.dashboards : Dashboard.none
138
+ end
45
139
  end
46
140
  end
@@ -1,2 +1,48 @@
1
- <div id="<%= dom_id component %>">
2
- </div>
1
+ <% widget = @widgets[component.component] %>
2
+ <section id="dashboard-component-<%= component.id %>" class="mb-6">
3
+ <%= form_with model: component, scope: :component, builder: LesliView::Forms::Builder,
4
+ url: managed_dashboard_component_path(@dashboard, component), data: { turbo_frame: "_top" } do |form| %>
5
+ <%= form.fieldset(widget ? widget.name : component.component.humanize) do %>
6
+ <% if component.errors.any? %>
7
+ <div role="alert"><%= form.field_control_builder(message_text: component.errors.full_messages.to_sentence, category: :danger) %></div>
8
+ <% end %>
9
+ <%= form.field_control_select(:size, ((1..12).to_a + [component.size_before_type_cast]).compact.uniq.map { |size| [size, size] },
10
+ label: t("lesli_dashboard.components.size"), humanize: false,
11
+ options: { selected: component.size_before_type_cast }) %>
12
+ <% if widget %>
13
+ <%= form.fields_for :config do |settings_form| %>
14
+ <% widget.settings.each do |key, definition| %>
15
+ <%
16
+ value = component.config[key.to_s]
17
+ label = t(definition.fetch(:label_key, "#{@dashboard.engine.underscore}.widgets.#{widget.identifier}_#{key}"), default: key.to_s.humanize)
18
+ %>
19
+ <% if definition.fetch(:type).to_sym == :select %>
20
+ <% choices = (definition.fetch(:choices) + [value]).compact.uniq.map do |choice|
21
+ [t("#{@dashboard.engine.underscore}.widgets.#{widget.identifier}_#{key}_#{choice}", default: choice.to_s.humanize), choice]
22
+ end %>
23
+ <%= settings_form.field_control_select(key, choices, label: label, humanize: false,
24
+ options: { selected: value }) %>
25
+ <% elsif definition[:type].to_sym == :boolean %>
26
+ <%= settings_form.field_control_checkbox(key, label: label, checked: ActiveModel::Type::Boolean.new.cast(value)) %>
27
+ <% elsif [:integer, :text].include?(definition[:type].to_sym) %>
28
+ <%= settings_form.field_control(key, label: label, value: value,
29
+ type: definition[:type].to_sym == :integer ? "number" : "text") %>
30
+ <% end %>
31
+ <% end %>
32
+ <% end %>
33
+ <% end %>
34
+ <%= form.field_control_submit(t("lesli_dashboard.dashboards.save")) %>
35
+ <% end %>
36
+ <% end %>
37
+ <div class="flex flex-wrap gap-3">
38
+ <% %w[up down].each do |direction| %>
39
+ <%= render LesliView::Elements::Button.new(t("lesli_dashboard.components.#{direction}"),
40
+ url: move_managed_dashboard_component_path(@dashboard, component), method: :patch,
41
+ params: { direction: direction }, icon: "arrow_#{direction}ward", solid: false, small: true) %>
42
+ <% end %>
43
+ <%= render LesliView::Elements::Button.new(t("lesli_dashboard.components.remove"),
44
+ url: managed_dashboard_component_path(@dashboard, component), method: :delete,
45
+ data: { turbo_confirm: t("lesli_dashboard.components.confirm_remove") },
46
+ icon: "delete", danger: true, solid: false, small: true) %>
47
+ </div>
48
+ </section>
@@ -1,17 +1,14 @@
1
- <%= form_with(model: component) do |form| %>
2
- <% if component.errors.any? %>
3
- <div style="color: red">
4
- <h2><%= pluralize(component.errors.count, "error") %> prohibited this component from being saved:</h2>
5
-
6
- <ul>
7
- <% component.errors.each do |error| %>
8
- <li><%= error.full_message %></li>
1
+ <div id="dashboard-component-form">
2
+ <%= form_with model: @new_component, scope: :component, builder: LesliView::Forms::Builder,
3
+ url: managed_dashboard_components_path(@dashboard), data: { turbo_frame: "_top" } do |form| %>
4
+ <%= form.fieldset(t("lesli_dashboard.components.add")) do %>
5
+ <% if @new_component.errors.any? %>
6
+ <div role="alert"><%= form.field_control_builder(message_text: @new_component.errors.full_messages.to_sentence, category: :danger) %></div>
7
+ <% end %>
8
+ <%= form.field_control_select(:component, @widgets.values.map { |widget| [widget.name, widget.identifier] },
9
+ label: t("lesli_dashboard.components.widget"), humanize: false,
10
+ options: { prompt: t("lesli_dashboard.components.choose") }, html_options: { required: true }) %>
11
+ <%= form.field_control_submit(t("lesli_dashboard.components.add")) %>
9
12
  <% end %>
10
- </ul>
11
- </div>
12
- <% end %>
13
-
14
- <div>
15
- <%= form.submit %>
16
- </div>
17
- <% end %>
13
+ <% end %>
14
+ </div>
@@ -0,0 +1,9 @@
1
+ <div id="dashboard-components-list">
2
+ <% if @components.empty? %>
3
+ <%= render LesliView::Elements::Empty.new(text: t("lesli_dashboard.components.empty")) %>
4
+ <% else %>
5
+ <% @components.each do |component| %>
6
+ <%= render "lesli_dashboard/components/component", component: component %>
7
+ <% end %>
8
+ <% end %>
9
+ </div>
@@ -1,16 +1,7 @@
1
- <p style="color: green"><%= notice %></p>
2
-
3
- <% content_for :title, "Components" %>
4
-
5
- <h1>Components</h1>
6
-
7
- <div id="components">
8
- <% @components.each do |component| %>
9
- <%= render component %>
10
- <p>
11
- <%= link_to "Show this component", component %>
12
- </p>
13
- <% end %>
14
- </div>
15
-
16
- <%= link_to "New component", new_component_path %>
1
+ <%= render LesliView::Layout::Container.new("dashboard-components") do %>
2
+ <%= render LesliView::Components::Header.new(t("lesli_dashboard.components.title"), @dashboard.name) do %>
3
+ <%= render LesliView::Elements::Button.new(t("lesli_dashboard.dashboards.back"), url: managed_dashboard_path(@dashboard), icon: "arrow_back", solid: false) %>
4
+ <% end %>
5
+ <%= render "form" %>
6
+ <%= render "list" %>
7
+ <% end %>
@@ -0,0 +1,19 @@
1
+ <div class="flex flex-wrap items-center gap-4">
2
+ <%= render LesliView::Elements::Button.new(
3
+ t("lesli_dashboard.components.title"), url: managed_dashboard_components_path(dashboard),
4
+ icon: "widgets", solid: false, small: true
5
+ ) %>
6
+ <% if dashboard_action_allowed?(:edit) %>
7
+ <%= render LesliView::Elements::Button.new(
8
+ t("lesli_dashboard.dashboards.edit"), url: edit_managed_dashboard_path(dashboard),
9
+ icon: "edit", solid: false
10
+ ) %>
11
+ <% end %>
12
+ <% if dashboard_action_allowed?(:destroy) %>
13
+ <%= render LesliView::Elements::Button.new(
14
+ t("lesli_dashboard.dashboards.delete"), url: managed_dashboard_path(dashboard), method: :delete,
15
+ icon: "delete", danger: true, solid: false,
16
+ data: { turbo_confirm: t("lesli_dashboard.dashboards.confirm_delete") }
17
+ ) %>
18
+ <% end %>
19
+ </div>
@@ -10,6 +10,6 @@ calendar_events = [8, 10, 27].map { |day| calendar_date.change(day: day) }
10
10
  date: calendar_date,
11
11
  events: calendar_events,
12
12
  selected_date: calendar_date,
13
- week_starts_on: :sunday
13
+ week_starts_on: component.config.fetch("week_starts_on", "sunday").to_sym
14
14
  )
15
15
  ) %>
@@ -0,0 +1,29 @@
1
+ <div id="dashboard-form">
2
+ <%= form_with model: @dashboard, scope: :dashboard, builder: LesliView::Forms::Builder,
3
+ data: { turbo_frame: "_top" },
4
+ url: @dashboard.persisted? ? managed_dashboard_path(@dashboard) : managed_dashboards_path do |form| %>
5
+ <%= form.fieldset do %>
6
+ <% if @dashboard.errors.any? %>
7
+ <div role="alert">
8
+ <%= form.field_control_builder(message_text: @dashboard.errors.full_messages.to_sentence, category: :danger) %>
9
+ </div>
10
+ <% end %>
11
+
12
+ <%= form.field_control(:name, label: t("lesli_dashboard.dashboards.name"), required: true) %>
13
+ <% if @dashboard.persisted? %>
14
+ <%= form.field_control(:engine, label: t("lesli_dashboard.dashboards.engine"), disabled: true) %>
15
+ <% else %>
16
+ <%= form.field_control_select(:engine, LesliDashboard::WidgetCatalog.engines,
17
+ label: t("lesli_dashboard.dashboards.engine"), humanize: false,
18
+ options: { prompt: t("lesli_dashboard.dashboards.choose_engine") },
19
+ html_options: { required: true }) %>
20
+ <% end %>
21
+ <%= form.field_control_checkbox(:default, label: t("lesli_dashboard.dashboards.default")) %>
22
+
23
+ <%= form.field_control_submit(t("lesli_dashboard.dashboards.save")) %>
24
+ <%= render LesliView::Elements::Button.new(
25
+ t("lesli_dashboard.dashboards.back"), url: managed_dashboards_path, icon: "arrow_back", solid: false
26
+ ) %>
27
+ <% end %>
28
+ <% end %>
29
+ </div>
@@ -1,32 +1,8 @@
1
- <%#
2
-
3
- Lesli
4
-
5
- Copyright (c) 2023, Lesli Technologies, S. A.
6
-
7
- This program is free software: you can redistribute it and/or modify
8
- it under the terms of the GNU General Public License as published by
9
- the Free Software Foundation, either version 3 of the License, or
10
- (at your option) any later version.
11
-
12
- This program is distributed in the hope that it will be useful,
13
- but WITHOUT ANY WARRANTY; without even the implied warranty of
14
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
- GNU General Public License for more details.
16
-
17
- You should have received a copy of the GNU General Public License
18
- along with this program. If not, see http://www.gnu.org/licenses/.
19
-
20
- Lesli · Ruby on Rails SaaS Development Framework.
21
-
22
- Made with ♥ by https://www.lesli.tech
23
- Building a better future, one line of code at a time.
24
-
25
- @contact hello@lesli.tech
26
- @website https://www.lesli.tech
27
- @license GPLv3 http://www.gnu.org/licenses/gpl-3.0.en.html
28
-
29
- // · ~·~ ~·~ ~·~ ~·~ ~·~ ~·~ ~·~ ~·~ ~·~
30
- // ·
31
- %>
32
- <router-view></router-view>
1
+ <%= render LesliView::Layout::Container.new("dashboards-edit") do %>
2
+ <%= render LesliView::Components::Header.new(t("lesli_dashboard.dashboards.edit")) do %>
3
+ <%= render LesliView::Elements::Button.new(
4
+ t("lesli_dashboard.components.title"), url: managed_dashboard_components_path(@dashboard), icon: "widgets"
5
+ ) %>
6
+ <% end %>
7
+ <%= render "form" %>
8
+ <% end %>
@@ -1,32 +1,21 @@
1
- <%#
2
-
3
- Lesli
4
-
5
- Copyright (c) 2023, Lesli Technologies, S. A.
6
-
7
- This program is free software: you can redistribute it and/or modify
8
- it under the terms of the GNU General Public License as published by
9
- the Free Software Foundation, either version 3 of the License, or
10
- (at your option) any later version.
11
-
12
- This program is distributed in the hope that it will be useful,
13
- but WITHOUT ANY WARRANTY; without even the implied warranty of
14
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
- GNU General Public License for more details.
16
-
17
- You should have received a copy of the GNU General Public License
18
- along with this program. If not, see http://www.gnu.org/licenses/.
19
-
20
- Lesli · Ruby on Rails SaaS Development Framework.
21
-
22
- Made with ♥ by https://www.lesli.tech
23
- Building a better future, one line of code at a time.
24
-
25
- @contact hello@lesli.tech
26
- @website https://www.lesli.tech
27
- @license GPLv3 http://www.gnu.org/licenses/gpl-3.0.en.html
28
-
29
- // · ~·~ ~·~ ~·~ ~·~ ~·~ ~·~ ~·~ ~·~ ~·~
30
- // ·
31
- %>
32
- <router-view></router-view>
1
+ <%= render LesliView::Layout::Container.new("dashboards-index") do %>
2
+ <%= render LesliView::Components::Header.new(t("lesli_dashboard.dashboards.title")) do %>
3
+ <% if dashboard_action_allowed?(:new) %>
4
+ <%= render LesliView::Elements::Button.new(
5
+ t("lesli_dashboard.dashboards.new"), url: new_managed_dashboard_path, icon: "add"
6
+ ) %>
7
+ <% end %>
8
+ <% end %>
9
+
10
+ <%= render LesliView::Elements::Table.new(
11
+ columns: %w[name engine default].map { |field| { field: field, label: t("lesli_dashboard.dashboards.#{field}") } },
12
+ records: @dashboards.map { |dashboard| {
13
+ id: dashboard.id,
14
+ name: dashboard.name,
15
+ engine: dashboard.engine,
16
+ default: t("lesli_dashboard.dashboards.#{dashboard.default? ? 'yes' : 'no'}")
17
+ } },
18
+ link: ->(dashboard) { managed_dashboard_path(dashboard.fetch(:id)) },
19
+ empty: t("lesli_dashboard.dashboards.empty")
20
+ ) %>
21
+ <% end %>
@@ -1,32 +1,4 @@
1
- <%#
2
-
3
- Lesli
4
-
5
- Copyright (c) 2023, Lesli Technologies, S. A.
6
-
7
- This program is free software: you can redistribute it and/or modify
8
- it under the terms of the GNU General Public License as published by
9
- the Free Software Foundation, either version 3 of the License, or
10
- (at your option) any later version.
11
-
12
- This program is distributed in the hope that it will be useful,
13
- but WITHOUT ANY WARRANTY; without even the implied warranty of
14
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
- GNU General Public License for more details.
16
-
17
- You should have received a copy of the GNU General Public License
18
- along with this program. If not, see http://www.gnu.org/licenses/.
19
-
20
- Lesli · Ruby on Rails SaaS Development Framework.
21
-
22
- Made with ♥ by https://www.lesli.tech
23
- Building a better future, one line of code at a time.
24
-
25
- @contact hello@lesli.tech
26
- @website https://www.lesli.tech
27
- @license GPLv3 http://www.gnu.org/licenses/gpl-3.0.en.html
28
-
29
- // · ~·~ ~·~ ~·~ ~·~ ~·~ ~·~ ~·~ ~·~ ~·~
30
- // ·
31
- %>
32
- <router-view></router-view>
1
+ <%= render LesliView::Layout::Container.new("dashboards-new") do %>
2
+ <%= render LesliView::Components::Header.new(t("lesli_dashboard.dashboards.new")) %>
3
+ <%= render "form" %>
4
+ <% end %>
@@ -27,6 +27,17 @@ title = [greeting, current_user&.full_name.presence].compact.join(", ")
27
27
  %>
28
28
 
29
29
  <%= render(LesliView::Components::Header.new(
30
- title,
30
+ @dashboard&.name.presence || title,
31
31
  date.date_words_day
32
- )) %>
32
+ )) do %>
33
+ <% if content_for?(:dashboard_actions) %>
34
+ <%= content_for(:dashboard_actions) %>
35
+ <% elsif current_user && (!defined?(LesliShield) || current_user.has_privileges_for?("lesli_dashboard/dashboards", "index")) %>
36
+ <%= render LesliView::Elements::Button.new(
37
+ t("lesli_dashboard.dashboards.manage"),
38
+ url: lesli_dashboard.managed_dashboards_path,
39
+ icon: "dashboard",
40
+ solid: false
41
+ ) %>
42
+ <% end %>
43
+ <% end %>
@@ -0,0 +1,20 @@
1
+ <% if @dashboards && @dashboards.size > 1 %>
2
+ <nav class="flex flex-wrap gap-3" aria-label="<%= t("lesli_dashboard.dashboards.navigation") %>">
3
+ <% @dashboards.each do |dashboard| %>
4
+ <%# Keep engine entry points such as /support while changing the selection. %>
5
+ <%
6
+ destination = if @dashboard_entry_path
7
+ "#{@dashboard_entry_path}?dashboard_id=#{dashboard.id}"
8
+ else
9
+ lesli_dashboard.managed_dashboard_path(dashboard)
10
+ end
11
+ %>
12
+ <span aria-current="<%= "page" if dashboard.id == @dashboard&.id %>">
13
+ <%= render LesliView::Elements::Button.new(
14
+ dashboard.name, url: destination, small: true,
15
+ solid: dashboard.id == @dashboard&.id
16
+ ) %>
17
+ </span>
18
+ <% end %>
19
+ </nav>
20
+ <% end %>