thecore_ui_commons 3.3.4 → 3.3.6

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b139db37d97713ea9f025376e438e9bca180afc0be792219089cdf53e94a9a16
4
- data.tar.gz: 37e112968a59444921342aac4b3a20dc895319097fc690d967f28c0baf9dfe49
3
+ metadata.gz: 7d1091f859ef05f14096826e8d5cd82712958819de284543dfc26120e90c0dc4
4
+ data.tar.gz: aea72ad38d7f5ac1f53af37faef3fc7f3f5b8d7f0000f918bb568093950433f8
5
5
  SHA512:
6
- metadata.gz: a1eab6f1db0ddcd41569c1044088e3a70755b9156746273eb552d98c25d19edb0990fbe9c2d7196287f2aa4a89d04c2662dcc7c61ad82e1fbf6a2710ed7f5e67
7
- data.tar.gz: 3ca02b2607961e1cb9e1ecfca1f0399593ec01d947a13f4d9fd750902c07dec1525d72bcdbf26734f549fa03b242263e3ccfc3f9ef24721d687a28c40744ddc3
6
+ metadata.gz: 2a7096802f754f1f38d48adaf8491798e61f1cf725d850e53f5f7d40e209ecab3470371e04dc2d4bad5716fa5dcf27f1accfd0cab7c03693d30d54e8e244c9da
7
+ data.tar.gz: acc0f1101c996dab5ccce5673f0e415265fa3e49437c6f7cecba832d96909756e5927ecd2bc39bf3e7b62b00e7e42ed3966881625955974c989ee0b5b08b5b4d
data/README.md CHANGED
@@ -1 +1,27 @@
1
- This is part of Thecore framework: https://github.com/gabrieletassoni/thecore/tree/release/3
1
+ # thecore_ui_commons
2
+
3
+ A Rails engine providing shared UI artifacts for [Thecore](https://github.com/gabrieletassoni/thecore/tree/release/3)-based host applications.
4
+
5
+ ## What it provides
6
+
7
+ - **Layouts** — Devise session page, Swagger UI, mailer (HTML + text)
8
+ - **Partials** — Bootstrap flash alerts, Kaminari pagination, drag-drop file uploader, logos
9
+ - **ECharts helpers** — Ruby classes for building Apache ECharts config server-side (`Vector`, `MultipleVectors`, `Binary`, `BinarySeries`, `Speedometer`, `Map`)
10
+ - **Swagger versioning** — `/info/swagger/:version` with automatic version discovery from mounted routes
11
+ - **Assets** — shared CSS/JS manifests, Active Job monitor, Devise i18n injection
12
+
13
+ ## Installation
14
+
15
+ Add to your host app's `Gemfile`:
16
+
17
+ ```ruby
18
+ gem 'thecore_ui_commons', '~> 3.0'
19
+ ```
20
+
21
+ The engine mounts automatically. No configuration required.
22
+
23
+ ## Swagger UI
24
+
25
+ The Swagger UI is available at `/info/swagger` (redirects to `/info/swagger/v2`).
26
+
27
+ If your app mounts `model_driven_api`, the engine discovers all available API versions at startup by scanning `Rails.application.routes` for paths matching `api/vN/info/swagger`. A version nav banner appears automatically above the Swagger UI — no configuration needed.
@@ -1,8 +1,10 @@
1
1
  class InfoController < ApplicationController
2
- # This is a model-less controller just to render che swagger page using a custom layout
3
2
  layout 'swagger'
4
3
  def swagger
4
+ @version = params[:version].to_s.gsub(/[^a-zA-Z0-9]/, '')
5
+ @versions = ThecoreUiCommons.swagger_api_versions
5
6
  uri = URI(request.url)
6
- @swagger_json_url = "#{uri.scheme}://#{uri.host}#{":#{uri.port}" if uri.port.present?}#{ENV.fetch("RAILS_RELATIVE_URL_ROOT", "")}/api/v2/info/swagger.json"
7
+ @base_url = "#{uri.scheme}://#{uri.host}#{":#{uri.port}" if uri.port.present?}#{ENV.fetch("RAILS_RELATIVE_URL_ROOT", "")}"
8
+ @swagger_json_url = "#{@base_url}/api/#{@version}/info/swagger.json"
7
9
  end
8
- end
10
+ end
@@ -1,28 +1,55 @@
1
- <script src="https://cdnjs.cloudflare.com/ajax/libs/swagger-ui/3.19.5/swagger-ui-bundle.js"> </script>
2
- <script src="https://cdnjs.cloudflare.com/ajax/libs/swagger-ui/3.19.5/swagger-ui-standalone-preset.js"> </script>
3
- <script>
4
- function get(yourUrl){
5
- var Httpreq = new XMLHttpRequest(); // a new request
6
- Httpreq.open("GET",yourUrl,false);
7
- Httpreq.send(null);
8
- var json_obj = JSON.parse(Httpreq.responseText);
9
- return json_obj;
10
- }
11
- window.onload = function() {
12
- const ui = SwaggerUIBundle({
13
- spec: get('<%= @swagger_json_url %>'),
14
- dom_id: '#swagger-ui',
15
- deepLinking: true,
16
- presets: [
17
- SwaggerUIBundle.presets.apis,
18
- SwaggerUIStandalonePreset
19
- ],
20
- plugins: [
21
- SwaggerUIBundle.plugins.DownloadUrl
22
- ],
23
- layout: "StandaloneLayout"
24
- })
25
-
26
- window.ui = ui
27
- }
28
- </script>
1
+ <% if @versions.length > 1 %>
2
+ <% content_for :version_nav do %>
3
+ <style>
4
+ #version-nav {
5
+ display: flex;
6
+ align-items: center;
7
+ gap: 0.4rem;
8
+ padding: 0.55rem 1rem;
9
+ background: #f1f5f9;
10
+ border-bottom: 1px solid #e2e8f0;
11
+ font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
12
+ font-size: 0.82rem;
13
+ color: #64748b;
14
+ }
15
+ #version-nav .vn-label { margin-right: 0.2rem; }
16
+ #version-nav a {
17
+ display: inline-block;
18
+ padding: 0.22rem 0.7rem;
19
+ border-radius: 999px;
20
+ text-decoration: none;
21
+ border: 1px solid #3b82f6;
22
+ color: #3b82f6;
23
+ font-weight: 500;
24
+ transition: background 0.15s, color 0.15s;
25
+ }
26
+ #version-nav a:hover { background: #3b82f6; color: #fff; }
27
+ #version-nav a.current { background: #3b82f6; color: #fff; pointer-events: none; }
28
+ </style>
29
+ <div id="version-nav">
30
+ <span class="vn-label">API version:</span>
31
+ <% @versions.each do |v| %>
32
+ <% if v == @version %>
33
+ <a href="#" class="current"><%= v %></a>
34
+ <% else %>
35
+ <a href="<%= request.path.sub(/[^\/]+$/, v) %>"><%= v %></a>
36
+ <% end %>
37
+ <% end %>
38
+ </div>
39
+ <% end %>
40
+ <% end %>
41
+
42
+ <script src="https://cdnjs.cloudflare.com/ajax/libs/swagger-ui/3.19.5/swagger-ui-bundle.js"></script>
43
+ <script src="https://cdnjs.cloudflare.com/ajax/libs/swagger-ui/3.19.5/swagger-ui-standalone-preset.js"></script>
44
+ <script>
45
+ window.addEventListener('load', function () {
46
+ SwaggerUIBundle({
47
+ url: '<%= j @swagger_json_url %>',
48
+ dom_id: '#swagger-ui',
49
+ deepLinking: true,
50
+ presets: [SwaggerUIBundle.presets.apis, SwaggerUIStandalonePreset],
51
+ plugins: [SwaggerUIBundle.plugins.DownloadUrl],
52
+ layout: 'StandaloneLayout'
53
+ });
54
+ });
55
+ </script>
@@ -2,14 +2,10 @@
2
2
  <head>
3
3
  <meta charset="UTF-8">
4
4
  <link rel="stylesheet" type="text/css" href="https://cdnjs.cloudflare.com/ajax/libs/swagger-ui/3.19.5/swagger-ui.css" >
5
- <style>
6
- .swagger-ui .topbar {
7
- display: none;
8
- }
9
- </style>
10
5
  </head>
11
6
 
12
7
  <body>
8
+ <%= yield :version_nav %>
13
9
  <div id="swagger-ui"></div>
14
10
  <%=yield%>
15
11
  </body>
@@ -1,4 +1,6 @@
1
1
  en:
2
- activerecord:
3
- models:
4
- thecore_settings/setting: Configurations
2
+ settings: Settings
3
+ master_data: Registries
4
+ activerecord:
5
+ models:
6
+ thecore_settings/setting: Configurations
@@ -4,45 +4,45 @@ it:
4
4
  charts:
5
5
  menu: Analisi
6
6
  title: Grafici
7
- breadcrumb: Grafici
7
+ breadcrumb: Grafici
8
8
  links:
9
9
  label: Collegamenti
10
10
  settings:
11
11
  label: Impostazioni
12
12
  advanced: Avanzate
13
13
  registries: Anagrafiche
14
- operations: Operatività
14
+ operations: Operatività
15
15
  tools:
16
16
  label: "Strumenti"
17
- advanced: Impostazioni
18
- contact: "Aiutaci a Migliorare"
19
- current_user: Utente corrente
20
- dashboard: "Pagina Iniziale"
17
+ advanced: Impostazioni
18
+ contact: "Aiutaci a Migliorare"
19
+ current_user: Utente corrente
20
+ dashboard: "Pagina Iniziale"
21
21
  devise:
22
22
  omniauth:
23
23
  labels:
24
- entra_id:
24
+ entra_id:
25
25
  html: Sign in con Microsoft <i class="fa fa-microsoft"></i>
26
- google_oauth2:
26
+ google_oauth2:
27
27
  html: Sign in con Google <i class="fa fa-google"></i>
28
28
  sessions:
29
29
  new:
30
30
  login: Login
31
- password: Password
32
- dont_leve_or_drag_here: Upload in corso, si prega di non lasciare la pagina o trascinare qui altri file.
31
+ password: Password
32
+ dont_leve_or_drag_here: Upload in corso, si prega di non lasciare la pagina o trascinare qui altri file.
33
33
  errors:
34
34
  messages:
35
- invalid: contiene caratteri invalidi
36
- file_upload: Descrizione della procedura, prego aggiungere una traduzione per file_upload al tuo file delle traduzioni.
37
- file_upload_subtitle: Descrizione aggiuntiva, prego aggiungere una traduzione per file_upload_subtitle al tuo file delle traduzioni.
38
- hello: "Ciao Mondo"
35
+ invalid: contiene caratteri non validi
36
+ file_upload: Descrizione della procedura, prego aggiungere una traduzione per file_upload al file delle traduzioni.
37
+ file_upload_subtitle: Descrizione aggiuntiva, prego aggiungere una traduzione per file_upload_subtitle al file delle traduzioni.
38
+ hello: "Ciao Mondo"
39
39
  import_success: Importazione completata con successo
40
40
  loading: Caricamento
41
- main_records: Anagrafiche
42
- manage: "Gestione"
43
- please_drag_and_drop_here: Trascinare qui i file da importare
41
+ main_records: Anagrafiche
42
+ manage: "Gestione"
43
+ please_drag_and_drop_here: Trascinare qui i file da importare
44
44
  run_import: Forza l'importazione
45
- sign_out: "Uscita"
45
+ sign_out: "Esci"
46
46
  tiered_times:
47
47
  dd:
48
48
  zero: "0 Giorni"
@@ -59,4 +59,4 @@ it:
59
59
  ss:
60
60
  zero: "0 Secondi"
61
61
  one: "%{count} Secondo"
62
- other: "%{count} Secondi"
62
+ other: "%{count} Secondi"
data/config/routes.rb CHANGED
@@ -3,7 +3,7 @@ Rails.application.routes.draw do
3
3
  controllers = {
4
4
  sessions: "users/sessions"
5
5
  }
6
- controllers[:omniauth_callbacks] = 'users/omniauth_callbacks' if ThecoreAuthCommons.oauth_vars?
6
+ controllers[:omniauth_callbacks] = 'users/omniauth_callbacks' if ThecoreAuthCommons.respond_to?(:oauth_vars?) && ThecoreAuthCommons.oauth_vars?
7
7
  devise_for :users, controllers: controllers
8
8
  end
9
9
 
@@ -14,6 +14,7 @@ Rails.application.routes.draw do
14
14
  end
15
15
 
16
16
  scope ENV.fetch("RAILS_RELATIVE_URL_ROOT", "/") do
17
- get '/info/swagger', to: 'info#swagger'
17
+ get '/info/swagger', to: redirect { |_params, req| "#{req.path}/v2" }
18
+ get '/info/swagger/:version', to: 'info#swagger'
18
19
  end
19
20
  end
@@ -1,3 +1,3 @@
1
1
  module ThecoreUiCommons
2
- VERSION = "3.3.4".freeze
2
+ VERSION = "3.3.6".freeze
3
3
  end
@@ -16,6 +16,25 @@ require "omniauth/rails_csrf_protection"
16
16
  require "thecore_ui_commons/engine"
17
17
 
18
18
  module ThecoreUiCommons
19
+ @swagger_api_versions = nil
20
+
21
+ class << self
22
+ attr_writer :swagger_api_versions
23
+
24
+ def swagger_api_versions
25
+ @swagger_api_versions.nil? ? scan_swagger_routes(Rails.application.routes.routes) : @swagger_api_versions
26
+ end
27
+ end
28
+
29
+ def self.scan_swagger_routes(routes)
30
+ routes
31
+ .map { |r| r.path.spec.to_s }
32
+ .grep(/\/api\/(v\d+)\/info\/swagger/)
33
+ .map { |p| p.match(/\/api\/(v\d+)\/info\/swagger/)[1] }
34
+ .uniq
35
+ .sort_by { |v| v[1..].to_i }
36
+ end
37
+
19
38
  def self.save_files files
20
39
  files.each do |pic|
21
40
  upload_dir = Rails.root.join(Settings.ns(:importer).import_from_folder, 'uploads')
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: thecore_ui_commons
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.3.4
4
+ version: 3.3.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Gabriele Tassoni