lesli_dashboard 1.1.2 → 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 (52) hide show
  1. checksums.yaml +4 -4
  2. data/Rakefile +6 -1
  3. data/app/assets/stylesheets/lesli_dashboard/application.css +190 -0
  4. data/app/controllers/lesli_dashboard/components_controller.rb +71 -49
  5. data/app/controllers/lesli_dashboard/dashboards_controller.rb +88 -3
  6. data/app/controllers/lesli_dashboard/shared/dashboards_controller.rb +11 -11
  7. data/app/helpers/lesli_dashboard/components_helper.rb +2 -2
  8. data/app/models/lesli_dashboard/account.rb +11 -7
  9. data/app/models/lesli_dashboard/component.rb +15 -2
  10. data/app/models/lesli_dashboard/dashboard.rb +5 -1
  11. data/app/models/lesli_dashboard/shared/dashboard.rb +6 -50
  12. data/app/operators/lesli_dashboard/dashboard_registration_operator.rb +32 -0
  13. data/app/presenters/lesli_dashboard/dashboard_presenter.rb +31 -0
  14. data/app/services/lesli_dashboard/component_service.rb +123 -0
  15. data/app/services/lesli_dashboard/dashboard_service.rb +124 -30
  16. data/app/views/lesli_dashboard/components/_component.html.erb +48 -2
  17. data/app/views/lesli_dashboard/components/_form.html.erb +13 -16
  18. data/app/views/lesli_dashboard/components/_list.html.erb +9 -0
  19. data/app/views/lesli_dashboard/components/index.html.erb +7 -16
  20. data/app/views/lesli_dashboard/dashboards/_actions.html.erb +19 -0
  21. data/app/views/lesli_dashboard/dashboards/_component-calendar.html.erb +1 -1
  22. data/app/views/lesli_dashboard/dashboards/_form.html.erb +29 -0
  23. data/app/views/lesli_dashboard/dashboards/edit.html.erb +8 -32
  24. data/app/views/lesli_dashboard/dashboards/index.html.erb +21 -32
  25. data/app/views/lesli_dashboard/dashboards/new.html.erb +4 -32
  26. data/app/views/lesli_dashboard/dashboards/shared/_header.html.erb +13 -2
  27. data/app/views/lesli_dashboard/dashboards/shared/_navigation.html.erb +20 -0
  28. data/app/views/lesli_dashboard/dashboards/shared/show.html.erb +24 -31
  29. data/app/views/lesli_dashboard/dashboards/show.html.erb +7 -2
  30. data/config/locales/translations.en.yml +55 -3
  31. data/config/locales/translations.es.yml +59 -3
  32. data/config/locales/translations.fr.yml +55 -3
  33. data/config/locales/translations.it.yml +55 -3
  34. data/config/locales/translations.pt.yml +55 -3
  35. data/config/routes.rb +6 -0
  36. data/db/migrate/0306050110_create_lesli_dashboard_dashboards.rb +8 -4
  37. data/db/migrate/20260118063343_create_lesli_dashboard_components.rb +5 -4
  38. data/lib/lesli_dashboard/engine.rb +1 -5
  39. data/lib/lesli_dashboard/version.rb +2 -2
  40. data/lib/lesli_dashboard/widget_catalog.rb +43 -0
  41. data/lib/lesli_dashboard.rb +1 -0
  42. data/lib/tasks/lesli_dashboard_tasks.rake +11 -11
  43. data/readme.md +17 -10
  44. metadata +14 -11
  45. data/app/assets/config/lesli_dashboard_manifest.js +0 -38
  46. data/app/assets/stylesheets/lesli_dashboard/application.tailwind.css +0 -33
  47. data/app/controllers/lesli_dashboard/dashboard/components_controller.rb +0 -60
  48. data/app/models/lesli_dashboard/dashboard/component.rb +0 -50
  49. data/app/views/lesli_dashboard/components/edit.html.erb +0 -12
  50. data/app/views/lesli_dashboard/components/new.html.erb +0 -11
  51. data/app/views/lesli_dashboard/components/show.html.erb +0 -10
  52. data/app/views/lesli_dashboard/dashboards/shared/edit.html.erb +0 -0
@@ -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 %>
@@ -30,51 +30,44 @@ Building a better future, one line of code at a time.
30
30
  // ·
31
31
  %>
32
32
 
33
- <% @components ||= [] %>
34
- <%
35
- # Dashboard component sizes use the same 12-column scale stored in the database.
36
- # Components stack on small screens and retain their configured width on desktops.
37
- component_width_classes = {
38
- 1 => "md:col-span-6 lg:col-span-1",
39
- 2 => "md:col-span-6 lg:col-span-2",
40
- 3 => "md:col-span-6 lg:col-span-3",
41
- 4 => "md:col-span-6 lg:col-span-4",
42
- 5 => "md:col-span-6 lg:col-span-5",
43
- 6 => "md:col-span-6 lg:col-span-6",
44
- 7 => "md:col-span-12 lg:col-span-7",
45
- 8 => "md:col-span-12 lg:col-span-8",
46
- 9 => "md:col-span-12 lg:col-span-9",
47
- 10 => "md:col-span-12 lg:col-span-10",
48
- 11 => "md:col-span-12 lg:col-span-11",
49
- 12 => "md:col-span-12 lg:col-span-12"
50
- }.freeze
51
- %>
33
+ <% content_for :head do %>
34
+ <%= stylesheet_link_tag "lesli_dashboard/application", media: "all" %>
35
+ <% end %>
52
36
 
53
37
  <%= render(LesliView::Layout::Container.new("dashboards-show", :dashboard => false)) do %>
54
38
 
55
39
  <%= render("lesli_dashboard/dashboards/shared/header") %>
56
40
 
41
+ <%= render("lesli_dashboard/dashboards/shared/navigation") %>
42
+
57
43
  <% if @components.empty? %>
58
44
  <section
59
45
  class="mt-6 rounded-2xl border border-dashed border-slate-300 bg-slate-50/70 px-6 py-12 sm:py-16"
60
- aria-label="Empty dashboard">
61
- <%= render(LesliView::Elements::Empty.new(text: "Empty dashboard")) %>
46
+ aria-label="<%= t("lesli_dashboard.dashboards.empty") %>">
47
+ <%= render(LesliView::Elements::Empty.new(text: t("lesli_dashboard.dashboards.empty"))) %>
48
+ <div class="mt-6 flex justify-center">
49
+ <% if @dashboard&.persisted? %>
50
+ <%= render LesliView::Elements::Button.new(
51
+ t("lesli_dashboard.components.add"),
52
+ url: lesli_dashboard.managed_dashboard_components_path(@dashboard), icon: "add"
53
+ ) %>
54
+ <% else %>
55
+ <%= render LesliView::Elements::Button.new(
56
+ t("lesli_dashboard.dashboards.new"),
57
+ url: lesli_dashboard.new_managed_dashboard_path(engine: @dashboard_engine), icon: "add"
58
+ ) %>
59
+ <% end %>
60
+ </div>
62
61
  </section>
63
62
  <% else %>
64
- <section class="mt-6 w-full" aria-label="Dashboard widgets">
63
+ <section class="mt-6 w-full" aria-label="<%= t("lesli_dashboard.dashboards.widgets") %>">
65
64
  <div class="grid grid-cols-12 items-stretch gap-4 sm:gap-5 lg:gap-6">
66
65
  <% @components.each do |component| %>
67
- <%
68
- component_size = component["size"].to_i
69
- component_size = 4 unless component_width_classes.key?(component_size)
70
- component_name = component["component"].to_s
71
- component_path = "#{controller.controller_path}/component-#{component_name.dasherize}"
72
- %>
73
66
  <article
74
- class="col-span-12 min-w-0 <%= component_width_classes.fetch(component_size) %>"
75
- data-dashboard-component="<%= component_name %>">
67
+ class="col-span-12 min-w-0 <%= @dashboard_presenter.width_class(component) %>"
68
+ data-dashboard-component="<%= component.component %>">
76
69
  <div class="h-full min-w-0 [&>*]:h-full [&_.box]:h-full">
77
- <%= render(component_path, { :component => component }) %>
70
+ <%= render(@dashboard_presenter.partial_path(component), { :component => component }) %>
78
71
  </div>
79
72
  </article>
80
73
  <% end %>
@@ -1,2 +1,7 @@
1
-
2
- <%= render("/lesli/shared/dashboards/show") %>
1
+ <% content_for :dashboard_actions do %>
2
+ <%= render LesliView::Elements::Button.new(
3
+ t("lesli_dashboard.dashboards.back"), url: managed_dashboards_path, icon: "arrow_back", solid: false
4
+ ) %>
5
+ <%= render "actions", dashboard: @dashboard %>
6
+ <% end %>
7
+ <%= render(template: "lesli/shared/dashboards/show") %>
@@ -1,7 +1,59 @@
1
1
  ---
2
2
  en:
3
3
  lesli_dashboard:
4
+ widgets:
5
+ calendar_week_starts_on: "Week starts on"
6
+ calendar_week_starts_on_sunday: "Sunday"
7
+ calendar_week_starts_on_monday: "Monday"
8
+ components:
9
+ title: "Edit widgets"
10
+ add: "Add widget"
11
+ widget: "Widget"
12
+ choose: "Select a widget"
13
+ size: "Width (columns)"
14
+ empty: "No widgets added"
15
+ up: "Move up"
16
+ down: "Move down"
17
+ remove: "Remove"
18
+ confirm_remove: "Remove this widget?"
19
+ created: "Widget added."
20
+ updated: "Widget updated."
21
+ moved: "Widget moved."
22
+ removed: "Widget removed."
23
+ dashboards:
24
+ navigation: "Dashboards for this engine"
25
+ "title": "Dashboards"
26
+ "new": "Create dashboard"
27
+ "edit": "Edit dashboard"
28
+ "delete": "Delete"
29
+ "confirm_delete": "Delete this dashboard?"
30
+ "name": "Name"
31
+ "engine": "Engine"
32
+ "default": "Default"
33
+ "actions": "Actions"
34
+ "yes": "Yes"
35
+ "no": "No"
36
+ "save": "Save"
37
+ "back": "All dashboards"
38
+ "choose_engine": "Select an engine"
39
+ "created": "Dashboard created."
40
+ "updated": "Dashboard updated."
41
+ "deleted": "Dashboard deleted."
42
+ "default_required": "must be replaced by another default dashboard"
43
+ "manage": "Manage dashboards"
44
+ initial_name: "%{engine} dashboard"
45
+ empty: "Empty dashboard"
46
+ widgets: "Dashboard widgets"
4
47
  greetings:
5
- morning: Good morning
6
- afternoon: Good afternoon
7
- evening: Good evening
48
+ afternoon: "Good afternoon"
49
+ evening: "Good evening"
50
+ morning: "Good morning"
51
+ activerecord:
52
+ attributes:
53
+ lesli_dashboard/dashboard:
54
+ name: "Name"
55
+ engine: "Engine"
56
+ default: "Default"
57
+ lesli_dashboard/component:
58
+ component: "Widget"
59
+ size: "Width (columns)"
@@ -1,7 +1,63 @@
1
1
  ---
2
2
  es:
3
3
  lesli_dashboard:
4
+ widgets:
5
+ calendar_week_starts_on: "Inicio de semana"
6
+ calendar_week_starts_on_sunday: "Domingo"
7
+ calendar_week_starts_on_monday: "Lunes"
8
+ components:
9
+ title: "Editar widgets"
10
+ add: "Agregar widget"
11
+ widget: "Widget"
12
+ choose: "Selecciona un widget"
13
+ size: "Ancho (columnas)"
14
+ empty: "No hay widgets agregados"
15
+ up: "Subir"
16
+ down: "Bajar"
17
+ remove: "Quitar"
18
+ confirm_remove: "¿Quitar este widget?"
19
+ created: "Widget agregado."
20
+ updated: "Widget actualizado."
21
+ moved: "Widget movido."
22
+ removed: "Widget eliminado."
23
+ dashboards:
24
+ navigation: "Paneles de este módulo"
25
+ "title": "Paneles"
26
+ "new": "Crear panel"
27
+ "edit": "Editar panel"
28
+ "delete": "Eliminar"
29
+ "confirm_delete": "¿Eliminar este panel?"
30
+ "name": "Nombre"
31
+ "engine": "Módulo"
32
+ "default": "Predeterminado"
33
+ "actions": "Acciones"
34
+ "yes": "Sí"
35
+ "no": "No"
36
+ "save": "Guardar"
37
+ "back": "Todos los paneles"
38
+ "choose_engine": "Selecciona un módulo"
39
+ "created": "Panel creado."
40
+ "updated": "Panel actualizado."
41
+ "deleted": "Panel eliminado."
42
+ "default_required": "debe reemplazarse por otro panel predeterminado"
43
+ "manage": "Administrar paneles"
44
+ initial_name: "Panel de %{engine}"
45
+ empty: "Panel vacío"
46
+ widgets: "Widgets del panel"
4
47
  greetings:
5
- morning: Buenos días
6
- afternoon: Buenas tardes
7
- evening: Buenas noches
48
+ afternoon: "Buenas tardes"
49
+ evening: "Buenas noches"
50
+ morning: "Buenos días"
51
+ items/attachments: {}
52
+ items/discussions: {}
53
+ items/tasks: {}
54
+ shared: {}
55
+ activerecord:
56
+ attributes:
57
+ lesli_dashboard/dashboard:
58
+ name: "Nombre"
59
+ engine: "Módulo"
60
+ default: "Predeterminado"
61
+ lesli_dashboard/component:
62
+ component: "Widget"
63
+ size: "Ancho (columnas)"
@@ -1,7 +1,59 @@
1
1
  ---
2
2
  fr:
3
3
  lesli_dashboard:
4
+ widgets:
5
+ calendar_week_starts_on: "Début de semaine"
6
+ calendar_week_starts_on_sunday: "Dimanche"
7
+ calendar_week_starts_on_monday: "Lundi"
8
+ components:
9
+ title: "Modifier les widgets"
10
+ add: "Ajouter un widget"
11
+ widget: "Widget"
12
+ choose: "Sélectionner un widget"
13
+ size: "Largeur (colonnes)"
14
+ empty: "Aucun widget ajouté"
15
+ up: "Monter"
16
+ down: "Descendre"
17
+ remove: "Retirer"
18
+ confirm_remove: "Retirer ce widget ?"
19
+ created: "Widget ajouté."
20
+ updated: "Widget modifié."
21
+ moved: "Widget déplacé."
22
+ removed: "Widget retiré."
23
+ dashboards:
24
+ navigation: "Tableaux de bord de ce module"
25
+ "title": "Tableaux de bord"
26
+ "new": "Créer un tableau de bord"
27
+ "edit": "Modifier le tableau de bord"
28
+ "delete": "Supprimer"
29
+ "confirm_delete": "Supprimer ce tableau de bord ?"
30
+ "name": "Nom"
31
+ "engine": "Module"
32
+ "default": "Par défaut"
33
+ "actions": "Actions"
34
+ "yes": "Oui"
35
+ "no": "Non"
36
+ "save": "Enregistrer"
37
+ "back": "Tous les tableaux de bord"
38
+ "choose_engine": "Sélectionner un module"
39
+ "created": "Tableau de bord créé."
40
+ "updated": "Tableau de bord modifié."
41
+ "deleted": "Tableau de bord supprimé."
42
+ "default_required": "doit être remplacé par un autre tableau de bord par défaut"
43
+ "manage": "Gérer les tableaux de bord"
44
+ initial_name: "Tableau de bord %{engine}"
45
+ empty: "Tableau de bord vide"
46
+ widgets: "Widgets du tableau de bord"
4
47
  greetings:
5
- morning: Bonjour
6
- afternoon: Bon après-midi
7
- evening: Bonsoir
48
+ afternoon: "Bon après-midi"
49
+ evening: "Bonsoir"
50
+ morning: "Bonjour"
51
+ activerecord:
52
+ attributes:
53
+ lesli_dashboard/dashboard:
54
+ name: "Nom"
55
+ engine: "Module"
56
+ default: "Par défaut"
57
+ lesli_dashboard/component:
58
+ component: "Widget"
59
+ size: "Largeur (colonnes)"
@@ -1,7 +1,59 @@
1
1
  ---
2
2
  it:
3
3
  lesli_dashboard:
4
+ widgets:
5
+ calendar_week_starts_on: "Inizio della settimana"
6
+ calendar_week_starts_on_sunday: "Domenica"
7
+ calendar_week_starts_on_monday: "Lunedì"
8
+ components:
9
+ title: "Modifica widget"
10
+ add: "Aggiungi widget"
11
+ widget: "Widget"
12
+ choose: "Seleziona un widget"
13
+ size: "Larghezza (colonne)"
14
+ empty: "Nessun widget aggiunto"
15
+ up: "Sposta su"
16
+ down: "Sposta giù"
17
+ remove: "Rimuovi"
18
+ confirm_remove: "Rimuovere questo widget?"
19
+ created: "Widget aggiunto."
20
+ updated: "Widget aggiornato."
21
+ moved: "Widget spostato."
22
+ removed: "Widget rimosso."
23
+ dashboards:
24
+ navigation: "Dashboard di questo modulo"
25
+ "title": "Dashboard"
26
+ "new": "Crea dashboard"
27
+ "edit": "Modifica dashboard"
28
+ "delete": "Elimina"
29
+ "confirm_delete": "Eliminare questa dashboard?"
30
+ "name": "Nome"
31
+ "engine": "Modulo"
32
+ "default": "Predefinita"
33
+ "actions": "Azioni"
34
+ "yes": "Sì"
35
+ "no": "No"
36
+ "save": "Salva"
37
+ "back": "Tutte le dashboard"
38
+ "choose_engine": "Seleziona un modulo"
39
+ "created": "Dashboard creata."
40
+ "updated": "Dashboard aggiornata."
41
+ "deleted": "Dashboard eliminata."
42
+ "default_required": "deve essere sostituita da un’altra dashboard predefinita"
43
+ "manage": "Gestisci dashboard"
44
+ initial_name: "Dashboard %{engine}"
45
+ empty: "Dashboard vuota"
46
+ widgets: "Widget della dashboard"
4
47
  greetings:
5
- morning: Buongiorno
6
- afternoon: Buon pomeriggio
7
- evening: Buonasera
48
+ afternoon: "Buon pomeriggio"
49
+ evening: "Buonasera"
50
+ morning: "Buongiorno"
51
+ activerecord:
52
+ attributes:
53
+ lesli_dashboard/dashboard:
54
+ name: "Nome"
55
+ engine: "Modulo"
56
+ default: "Predefinita"
57
+ lesli_dashboard/component:
58
+ component: "Widget"
59
+ size: "Larghezza (colonne)"
@@ -1,7 +1,59 @@
1
1
  ---
2
2
  pt:
3
3
  lesli_dashboard:
4
+ widgets:
5
+ calendar_week_starts_on: "Início da semana"
6
+ calendar_week_starts_on_sunday: "Domingo"
7
+ calendar_week_starts_on_monday: "Segunda-feira"
8
+ components:
9
+ title: "Editar widgets"
10
+ add: "Adicionar widget"
11
+ widget: "Widget"
12
+ choose: "Selecione um widget"
13
+ size: "Largura (colunas)"
14
+ empty: "Nenhum widget adicionado"
15
+ up: "Mover para cima"
16
+ down: "Mover para baixo"
17
+ remove: "Remover"
18
+ confirm_remove: "Remover este widget?"
19
+ created: "Widget adicionado."
20
+ updated: "Widget atualizado."
21
+ moved: "Widget movido."
22
+ removed: "Widget removido."
23
+ dashboards:
24
+ navigation: "Painéis deste módulo"
25
+ "title": "Painéis"
26
+ "new": "Criar painel"
27
+ "edit": "Editar painel"
28
+ "delete": "Excluir"
29
+ "confirm_delete": "Excluir este painel?"
30
+ "name": "Nome"
31
+ "engine": "Módulo"
32
+ "default": "Padrão"
33
+ "actions": "Ações"
34
+ "yes": "Sim"
35
+ "no": "Não"
36
+ "save": "Salvar"
37
+ "back": "Todos os painéis"
38
+ "choose_engine": "Selecione um módulo"
39
+ "created": "Painel criado."
40
+ "updated": "Painel atualizado."
41
+ "deleted": "Painel excluído."
42
+ "default_required": "deve ser substituído por outro painel padrão"
43
+ "manage": "Gerenciar painéis"
44
+ initial_name: "Painel de %{engine}"
45
+ empty: "Painel vazio"
46
+ widgets: "Widgets do painel"
4
47
  greetings:
5
- morning: Bom dia
6
- afternoon: Boa tarde
7
- evening: Boa noite
48
+ afternoon: "Boa tarde"
49
+ evening: "Boa noite"
50
+ morning: "Bom dia"
51
+ activerecord:
52
+ attributes:
53
+ lesli_dashboard/dashboard:
54
+ name: "Nome"
55
+ engine: "Módulo"
56
+ default: "Padrão"
57
+ lesli_dashboard/component:
58
+ component: "Widget"
59
+ size: "Largura (colunas)"
data/config/routes.rb CHANGED
@@ -31,5 +31,11 @@ Building a better future, one line of code at a time.
31
31
  =end
32
32
 
33
33
  LesliDashboard::Engine.routes.draw do
34
+ resources :dashboards, as: :managed_dashboards
35
+ scope "dashboards/:dashboard_id", as: :managed_dashboard do
36
+ resources :components, only: [:index, :create, :update, :destroy] do
37
+ patch :move, on: :member
38
+ end
39
+ end
34
40
  Lesli::Router.mount_lesli_engine_routes(self)
35
41
  end
@@ -33,14 +33,18 @@ Building a better future, one line of code at a time.
33
33
  class CreateLesliDashboardDashboards < ActiveRecord::Migration[6.1]
34
34
  def change
35
35
  create_table :lesli_dashboard_dashboards do |t|
36
- t.string :engine
37
- t.boolean :default
36
+ t.string :name, null: false
37
+ t.string :engine, null: false
38
+ t.boolean :default, null: false, default: false
38
39
  t.datetime :deleted_at, index: true
39
40
  t.timestamps
40
41
  end
41
42
 
42
- add_reference(:lesli_dashboard_dashboards, :user, foreign_key: { to_table: :lesli_users }, index: true)
43
- add_reference(:lesli_dashboard_dashboards, :role, foreign_key: { to_table: :lesli_roles }, index: true)
44
43
  add_reference(:lesli_dashboard_dashboards, :account, foreign_key: { to_table: :lesli_dashboard_accounts }, null: false)
44
+ add_index :lesli_dashboard_dashboards, [:account_id, :engine]
45
+ # Deleted dashboards do not reserve the default for their account and engine.
46
+ add_index :lesli_dashboard_dashboards, [:account_id, :engine],
47
+ unique: true, where: '"default" = true AND deleted_at IS NULL',
48
+ name: "index_dashboard_active_default"
45
49
  end
46
50
  end
@@ -33,13 +33,14 @@ Building a better future, one line of code at a time.
33
33
  class CreateLesliDashboardComponents < ActiveRecord::Migration[8.0]
34
34
  def change
35
35
  create_table :lesli_dashboard_components do |t|
36
- t.string :component
37
- t.integer :position
38
- t.integer :size
39
- t.json :config
36
+ t.string :component, null: false
37
+ t.integer :position, null: false, default: 1
38
+ t.integer :size, null: false, default: 4
39
+ t.json :config, null: false, default: {}
40
40
  t.timestamps
41
41
  end
42
42
 
43
43
  add_reference(:lesli_dashboard_components, :dashboard, foreign_key: { to_table: :lesli_dashboard_dashboards }, null: false)
44
+ add_index :lesli_dashboard_components, [:dashboard_id, :position]
44
45
  end
45
46
  end
@@ -34,11 +34,7 @@ module LesliDashboard
34
34
  class Engine < ::Rails::Engine
35
35
  isolate_namespace LesliDashboard
36
36
 
37
- initializer :lesli_admin do |app|
38
-
39
- # register assets manifest
40
- config.assets.precompile += %w[lesli_dashboard_manifest.js]
41
-
37
+ initializer :lesli_dashboard do |app|
42
38
  # register engine migrations path
43
39
  unless app.root.to_s.match root.to_s
44
40
  config.paths["db/migrate"].expanded.each do |expanded_path|
@@ -1,4 +1,4 @@
1
1
  module LesliDashboard
2
- VERSION = "1.1.2"
3
- BUILD = "1790534691"
2
+ VERSION = "1.1.4"
3
+ BUILD = "1794795981"
4
4
  end
@@ -0,0 +1,43 @@
1
+ module LesliDashboard
2
+ module WidgetCatalog
3
+ Widget = Struct.new(:identifier, :name_key, :partial, :options, :settings, keyword_init: true) do
4
+ def name
5
+ I18n.t(name_key, default: identifier.humanize)
6
+ end
7
+ end
8
+
9
+ @providers = {}
10
+
11
+ # Use a block so Rails reloads resolve the current model and its COMPONENTS.
12
+ def self.register(engine, &provider)
13
+ @providers[engine] = provider
14
+ end
15
+
16
+ def self.engines
17
+ (LesliSystem.engines.keys - %w[Lesli LesliBabel Root] + @providers.keys).uniq
18
+ end
19
+
20
+ def self.widgets(engine)
21
+ return [] unless engines.include?(engine)
22
+
23
+ declarations = if @providers.key?(engine)
24
+ @providers.fetch(engine).call
25
+ else
26
+ "#{engine}::Dashboard".constantize::COMPONENTS
27
+ end
28
+
29
+ declarations.each_with_index.map do |declaration, index|
30
+ identifier, options = declaration.is_a?(Hash) ? declaration.first : [declaration, {}]
31
+ identifier = identifier.to_s
32
+ options = options.deep_symbolize_keys
33
+ Widget.new(
34
+ identifier: identifier,
35
+ name_key: options.fetch(:name_key, "#{engine.underscore}.widgets.#{identifier}"),
36
+ partial: options.fetch(:partial, "#{engine.underscore}/dashboards/component-#{identifier.dasherize}"),
37
+ settings: options.fetch(:settings, {}),
38
+ options: { size: 4, position: index + 1, config: {} }.merge(options.slice(:size, :position, :config))
39
+ )
40
+ end
41
+ end
42
+ end
43
+ end
@@ -1,4 +1,5 @@
1
1
  require "lesli_dashboard/version"
2
+ require "lesli_dashboard/widget_catalog"
2
3
  require "lesli_dashboard/engine"
3
4
 
4
5
  module LesliDashboard
@@ -1,15 +1,15 @@
1
1
  namespace :lesli_dashboard do
2
-
3
- desc ""
4
- task :register => :environment do |task, args|
5
- dashboard_initialize()
6
- end
7
-
8
- # Drop, build, migrate & seed database (development only)
9
- def dashboard_initialize
10
- Lesli::Account.all.each do |account|
11
- LesliDashboard::DashboardService.new(nil).register(account.dashboard)
2
+ desc "Initialize missing dashboards without changing existing layouts"
3
+ task register: :environment do
4
+ Lesli::Account.find_each do |core_account|
5
+ account = LesliDashboard::Account.find_or_initialize_by(account: core_account)
6
+ if account.persisted?
7
+ LesliDashboard::DashboardRegistrationOperator.new(account).operate
8
+ else
9
+ # Creating the workspace initializes its dashboards through after_create.
10
+ account.save!
11
+ end
12
12
  end
13
- L2.msg("LesliDashboard: Dashboards initialized!")
13
+ Termline.info("LesliDashboard: Dashboard registration completed.")
14
14
  end
15
15
  end