cm-admin 1.5.49 → 1.5.50

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: e8b93ddf37f6e38e2941258922c9717f51376d2950759b4822aed030c6b90d20
4
- data.tar.gz: 45da70fe84a3cbdbf3edac26d7d55d276fb93057cbaa6a408f91d5e960e8090e
3
+ metadata.gz: d1c927758f152c126931344ac38ad2b7cfdf454b5a70d2c4508e67bfaece250b
4
+ data.tar.gz: f7a78226339aa88ae1bc5cfe59ad0947431e065b9ef66fbfd3fc5d2baac3ccac
5
5
  SHA512:
6
- metadata.gz: 3e9f9eb33d0109f203fecef632fe6d42599cc2932a1a6dda8b1671742009c21faf69cdd9037c8406ca62582b6ad69dae95561aee88326d8051a61e348d6e0e37
7
- data.tar.gz: 7c00620c3ff14846ab2371bab8c9a3873d558f01925ea0d22074cd2ce4259389f88e8a23fc0b02fd32174c0e3f9213ad0d1418a31b6cd03515f4a028e8f49bff
6
+ metadata.gz: 26666e659ad3fa593545112f5fdf5f61c8bf124b7d8c9a7fc4d9a01d3280550e6b86bce8db84c6fa4abdd6b7cd69d964b774bca36d868965ad731bce29c1354b
7
+ data.tar.gz: eac4324c8a183c0d8bb5ad952bf7302f563b07f0685efa7e05f34a589689086e6fa8fe19501dd7a0551df6dbd7c8f84580e2625bb2f083fec4731448eb702542
data/.yardopts CHANGED
@@ -2,4 +2,5 @@ lib/cm_admin/models/dsl_method.rb
2
2
  -
3
3
  docs/ShowHideContent.md
4
4
  docs/ListingSelectTwoItems.md
5
- docs/ListingSelectTwoAjax.md
5
+ docs/ListingSelectTwoAjax.md
6
+ docs/AddingAlert.md
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- cm-admin (1.5.49)
4
+ cm-admin (1.5.50)
5
5
  caxlsx_rails
6
6
  cocoon (~> 1.2.15)
7
7
  csv-importer (~> 0.8.2)
@@ -0,0 +1,36 @@
1
+ .alert {
2
+ .alert-banner-body {
3
+ display: flex;
4
+ justify-content: space-between;
5
+ align-items: flex-start;
6
+
7
+ .alert-banner-icon {
8
+ margin: 1px;
9
+
10
+ svg {
11
+ width: 16px;
12
+ height: 16px;
13
+ }
14
+ }
15
+
16
+ .alert-banner-content {
17
+ margin-left: 10px;
18
+ display: flex;
19
+ flex-direction: column;
20
+
21
+ .alert-banner-header {
22
+ p {
23
+ font-size: 1.1rem;
24
+ font-weight: bold;
25
+ margin-bottom: 0;
26
+ }
27
+ }
28
+
29
+ .alert-banner-text {
30
+ p.mb-0 {
31
+ margin-bottom: 0;
32
+ }
33
+ }
34
+ }
35
+ }
36
+ }
@@ -17,6 +17,7 @@
17
17
  @import "./base/common";
18
18
  @import "./base/cardView";
19
19
  @import "./base/kanban";
20
+ @import "./base/alertbanner";
20
21
  @import "./components/index";
21
22
  @import "./dependency/flatpickr.min";
22
23
  @import "./dependency/fontawesome.all";
@@ -32,6 +32,7 @@ module CmAdmin
32
32
  @current_action = CmAdmin::Models::Action.find_by(@model, name: 'show')
33
33
  scoped_model = "CmAdmin::#{@model.name}Policy::Scope".constantize.new(Current.user, @model.name.constantize).resolve
34
34
  @ar_object = fetch_ar_object(scoped_model, params[:id])
35
+ @alerts = @model.alerts
35
36
  resource_identifier
36
37
  respond_to do |format|
37
38
  if request.xhr?
@@ -0,0 +1,9 @@
1
+ .alert class="alert-#{alert.type}" *alert.html_attrs
2
+ .alert-banner-body
3
+ .alert-banner-icon
4
+ i.fas class="fa-#{icon_class} fs-5 ms-2"
5
+ .alert-banner-content
6
+ .alert-banner-header
7
+ p== alert.header
8
+ .alert-banner-text
9
+ p.mb-0== alert.body
@@ -2,6 +2,8 @@
2
2
  == render 'cm_admin/main/top_navbar'
3
3
  == render 'cm_admin/main/tabs', via_xhr: defined?(via_xhr) ? via_xhr : false
4
4
  .show-page__inner
5
+ - unless @alerts.empty?
6
+ == create_alerts(@alerts,@ar_object)
5
7
  - if @action.partial
6
8
  == render @action.partial
7
9
  - else
@@ -0,0 +1,84 @@
1
+ # Adding Alert Feature ⚠️
2
+
3
+ ## Overview
4
+
5
+ The Alert feature has been added to CmAdmin to provide a standardized method for displaying alerts and notifications to users. This documentation outlines how to use the Alert, including its configuration, types, and examples.
6
+
7
+ ## Features
8
+
9
+ - **Customizable Alerts:** Display alerts with headers, bodies, and specific types.
10
+ - **Conditional Display:** Control when alerts should be shown based on dynamic conditions.
11
+ - **Type Support:** Supports four predefined types of alerts: `info`, `success`, `danger`, and `warning`.
12
+
13
+ ## Usage
14
+
15
+ The Alert Banner is implemented using the `alert_box` helper. Below are the key elements and their usage:
16
+
17
+ ### Syntax
18
+
19
+ **1. Using Parameters:**
20
+
21
+ ```ruby
22
+ alert_box header:"Title", body:"Body1", type: :info, display_if:->(arg){arg.present?}, html_attrs:{}
23
+ ```
24
+
25
+ **2. Using a Partial:**
26
+
27
+ ```ruby
28
+ alert_box partial:"/users/sessions/alert", display_if:->(arg){arg.present?}, html_attrs:{}
29
+ ```
30
+
31
+ ### Parameters
32
+
33
+ - **`header:`** (optional) - The title text for the alert.
34
+ - **`body:`** (optional) - A string to display as the body of the alert.
35
+ - **`type:`** (optional) - The type of alert. Accepts one of the following symbols: `:info`, `:success`, `:danger`, `:warning`.
36
+ - **`partial:`** (optional) - The path to a custom partial or HTML for the alert.
37
+ - **`display_if:`** (optional) - A lambda function that determines whether the alert should be shown. Should return a boolean.
38
+ - **`html_attrs:`** (optional) - Additional HTML attributes to apply to the alert. Note: This has no effect on partials.
39
+
40
+ ## Types of Alerts
41
+
42
+ The following types are supported:
43
+
44
+ - **`info`** - Blue alert for informational messages.
45
+ - **`success`** - Green alert for successful actions or positive feedback.
46
+ - **`danger`** - Red alert for errors or critical warnings.
47
+ - **`warning`** - Yellow alert for cautionary messages.
48
+
49
+ ### Examples
50
+
51
+ #### Example 1: Basic Info Alert
52
+
53
+ ```ruby
54
+ alert_box header:"Information", body:"This is an informational message.", type: :info, display_if:->(arg){arg.present?}
55
+ ```
56
+
57
+ - **Screenshot:** ![image](https://github.com/user-attachments/assets/cb0c9a09-5084-4204-ae83-64ac06065cf9)
58
+ - **Screenshot:** ![image](https://github.com/user-attachments/assets/8bc1c066-03c0-4e34-8e38-217062db4579)
59
+ - **Description:** Displays an alert with a title and body text.
60
+
61
+ #### Example 2: Using Custom Body
62
+
63
+ ```ruby
64
+ alert_box header:"Information", body:"This is an informational message. <br>This is a break text.", type: :info, display_if:->(arg){arg.present?}
65
+ ```
66
+ - **Screenshot:** ![image](https://github.com/user-attachments/assets/5614e104-4675-49e8-a2db-034a890fd581)
67
+ - **Screenshot:** ![image](https://github.com/user-attachments/assets/41c22856-4647-4c47-ba48-d144833c2074)
68
+ - **Description:** Displays a custom body for the alert, allowing for more customized content.
69
+
70
+
71
+ #### Example 3: Using Partial
72
+
73
+ ```ruby
74
+ alert_box partial:"/check/alert", display_if:->(arg){arg.present?}
75
+ ```
76
+ - **Screenshot:** ![image](https://github.com/user-attachments/assets/5614e104-4675-49e8-a2db-034a890fd581)
77
+ - **Screenshot:** ![image](https://github.com/user-attachments/assets/41c22856-4647-4c47-ba48-d144833c2074)
78
+ - **Description:** Displays a custom partial for the alert, allowing for more customized HTML or content.
79
+
80
+
81
+ ### Important Notes
82
+
83
+ - **Nested Sections:** Alerts cannot be placed inside nested sections. If added within a nested section, the alert will appear on the wrapped `cm_show_section`.
84
+ - **Unsupported Types:** Only the specified types (`info`, `success`, `danger`, `warning`) are supported. Any other type will default to a standard div.
@@ -14,6 +14,7 @@ require_relative 'models/section'
14
14
  require_relative 'models/row'
15
15
  require_relative 'models/tab'
16
16
  require_relative 'models/dsl_method'
17
+ require_relative 'models/alert'
17
18
  require 'pagy'
18
19
  require 'axlsx'
19
20
  require 'cocoon'
@@ -29,7 +30,7 @@ module CmAdmin
29
30
  include CmAdmin::Engine.routes.url_helpers
30
31
 
31
32
  attr_accessor :available_actions, :actions_set, :available_fields, :additional_permitted_fields,
32
- :current_action, :params, :filters, :available_tabs, :icon_name, :bulk_actions, :display_name
33
+ :current_action, :params, :filters, :available_tabs, :icon_name, :bulk_actions, :display_name, :alerts
33
34
  attr_reader :name, :ar_model, :is_visible_on_sidebar, :importer
34
35
 
35
36
  def initialize(entity, &block)
@@ -42,9 +43,10 @@ module CmAdmin
42
43
  @additional_permitted_fields ||= []
43
44
  @current_action = nil
44
45
  @available_tabs ||= []
45
- @available_fields ||= {index: [], show: [], edit: [], new: []}
46
+ @available_fields ||= { index: [], show: [], edit: [], new: [] }
46
47
  @params = nil
47
48
  @filters ||= []
49
+ @alerts = []
48
50
  instance_eval(&block) if block_given?
49
51
  actions unless @actions_set
50
52
  $available_actions = @available_actions.dup
@@ -112,6 +114,10 @@ module CmAdmin
112
114
  @display_name.present? ? @display_name : @ar_model.table_name
113
115
  end
114
116
 
117
+ def alert_box(options = {})
118
+ @alerts << CmAdmin::Models::Alert.new(options)
119
+ end
120
+
115
121
  def model_name
116
122
  @display_name.present? ? @display_name : @name
117
123
  end
@@ -0,0 +1,23 @@
1
+ module CmAdmin
2
+ module Models
3
+ class Alert
4
+ attr_accessor :header, :body, :type, :partial, :display_if, :html_attrs
5
+
6
+ def initialize(attributes = {})
7
+ set_default_values
8
+ attributes.each do |key, value|
9
+ send("#{key}=", value)
10
+ end
11
+ end
12
+
13
+ def set_default_values
14
+ self.header = nil
15
+ self.body = nil
16
+ self.type = :info
17
+ self.partial = nil
18
+ self.display_if = ->(_args) { true }
19
+ self.html_attrs = {}
20
+ end
21
+ end
22
+ end
23
+ end
@@ -335,6 +335,44 @@ module CmAdmin
335
335
  def sort_column(column = :created_at)
336
336
  @current_action.sort_column = column.to_sym if @current_action
337
337
  end
338
+
339
+ # Adds a new alert to the current section.
340
+ #
341
+ # @param [String, nil] header The title text for the alert.
342
+ # @param [String, nil] body A string to display as the body of the alert.
343
+ # @param [Symbol, nil] type The type of alert. Accepts one of the following symbols: :info, :success, :danger, :warning.
344
+ # @param [String, nil] partial The path to a custom partial or HTML for the alert.
345
+ # @param [Proc, nil] display_if A lambda function that determines whether the alert should be shown. Should return a boolean.
346
+ # @param [Hash] html_attrs Additional HTML attributes to apply to the alert. Has no effect on partials.
347
+ #
348
+ # @example Basic info alert
349
+ # alert_box(header: "Information", body: "This is an informational message.", type: :info)
350
+ #
351
+ # @example Basic info alert with custom body
352
+ # alert_box(header: "Information", body: "This is an informational message. <br>This is a break text", type: :info)
353
+ #
354
+ # @example Alert with custom partial
355
+ # alert_box(partial: "/users/sessions/alert", display_if: ->(arg) { arg.present? })
356
+ #
357
+ # @example Alert with conditional display and custom HTML attributes
358
+ # alert_box(
359
+ # header: "Warning",
360
+ # body: "Please review your submission.",
361
+ # type: :warning,
362
+ # display_if: ->(user) { user.submissions.any?(&:incomplete?) },
363
+ # html_attrs: { id: "submission-warning", data: { turbo_frame: "warnings" } }
364
+ # )
365
+ #
366
+ # @note Alerts cannot be placed inside nested sections. If added within a nested section,
367
+ # the alert will appear on the wrapped cm_show_section.
368
+ # @note Only the specified types (info, success, danger, warning) are supported.
369
+ # Any other type will default to a standard div.
370
+ #
371
+ # @see file:docs/AddingAlert.md For more information on how to add alerts to your model.
372
+ #
373
+ def alert_box(header: nil, body: nil, type: nil, partial: nil, display_if: nil, html_attrs: {})
374
+ @section_fields << CmAdmin::Models::Alert.new(header, body, type, partial: partial, display_if: display_if, html_attrs: html_attrs)
375
+ end
338
376
  end
339
377
  end
340
378
  end
@@ -33,6 +33,10 @@ module CmAdmin
33
33
  end
34
34
  end
35
35
 
36
+ def alert_box(options = {})
37
+ @section_fields << CmAdmin::Models::Alert.new(options)
38
+ end
39
+
36
40
  def form_field(field_name, options = {}, arg = nil)
37
41
  if @current_nested_field
38
42
  @current_nested_field.fields << CmAdmin::Models::FormField.new(field_name, options[:input_type], options)
@@ -1,3 +1,3 @@
1
1
  module CmAdmin
2
- VERSION = '1.5.49'
2
+ VERSION = '1.5.50'
3
3
  end
@@ -1,9 +1,17 @@
1
1
  module CmAdmin
2
2
  module ViewHelpers
3
3
  module FieldDisplayHelper
4
+ ALERT_ICON_CLASSES = {
5
+ warning: 'triangle-exclamation',
6
+ danger: 'triangle-exclamation',
7
+ success: 'circle-check'
8
+ }.freeze
9
+
4
10
  def show_field(ar_object, field)
11
+ return create_alert(field, ar_object) if field.is_a?(CmAdmin::Models::Alert)
5
12
  return unless field.display_if.call(ar_object)
6
- content_tag(:div, class: "card-info") do
13
+
14
+ content_tag(:div, class: 'card-info') do
7
15
  concat show_field_label(ar_object, field) if field.label
8
16
  concat value_with_prefix_and_suffix(ar_object, field)
9
17
  end
@@ -16,7 +24,7 @@ module CmAdmin
16
24
  next unless field.display_if.call(ar_object)
17
25
 
18
26
  content_tag(:div, class: "col-#{col_size}") do
19
- content_tag(:div, class: "card-info") do
27
+ content_tag(:div, class: 'card-info') do
20
28
  concat show_field_label(ar_object, field) if field.label
21
29
  concat value_with_prefix_and_suffix(ar_object, field)
22
30
  end
@@ -26,6 +34,21 @@ module CmAdmin
26
34
  end.join.html_safe
27
35
  end
28
36
 
37
+ def create_alerts(alerts, ar_object)
38
+ alerts.map do |alert|
39
+ create_alert(alert, ar_object)
40
+ end.join.html_safe
41
+ end
42
+
43
+ def create_alert(alert, ar_object)
44
+ return unless alert.display_if.call(ar_object)
45
+
46
+ return render partial: alert.partial if alert.partial
47
+
48
+ icon_class = ALERT_ICON_CLASSES.fetch(alert.type, 'circle-info')
49
+ render partial: 'cm_admin/main/alert_banner', locals: { alert: alert, icon_class: icon_class }
50
+ end
51
+
29
52
  def show_field_label(ar_object, field)
30
53
  content_tag(:div, class: "card-info__label") do
31
54
  field_label = if field.label.present?
@@ -106,6 +106,7 @@ module CmAdmin
106
106
 
107
107
  def set_form_field(resource, form_obj, field)
108
108
  return unless field.display_if.call(form_obj.object)
109
+ return create_alert(field, form_obj.object) if field.is_a?(CmAdmin::Models::Alert)
109
110
 
110
111
  is_required = is_field_presence_validated?(form_obj, field)
111
112
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cm-admin
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.5.49
4
+ version: 1.5.50
5
5
  platform: ruby
6
6
  authors:
7
7
  - Michael
@@ -14,7 +14,7 @@ authors:
14
14
  autorequire:
15
15
  bindir: exe
16
16
  cert_chain: []
17
- date: 2024-09-06 00:00:00.000000000 Z
17
+ date: 2024-09-09 00:00:00.000000000 Z
18
18
  dependencies:
19
19
  - !ruby/object:Gem::Dependency
20
20
  name: caxlsx_rails
@@ -218,6 +218,7 @@ files:
218
218
  - app/assets/javascripts/cm_admin/scaffolds.js
219
219
  - app/assets/javascripts/cm_admin/shared_scaffolds.js
220
220
  - app/assets/stylesheets/cm_admin/actiontext.scss
221
+ - app/assets/stylesheets/cm_admin/base/alertbanner.scss
221
222
  - app/assets/stylesheets/cm_admin/base/auth.scss
222
223
  - app/assets/stylesheets/cm_admin/base/cardView.scss
223
224
  - app/assets/stylesheets/cm_admin/base/comments.scss
@@ -367,6 +368,7 @@ files:
367
368
  - app/models/file_import.rb
368
369
  - app/policies/cm_admin/file_import_policy.rb
369
370
  - app/views/cm_admin/main/_actions_dropdown.html.slim
371
+ - app/views/cm_admin/main/_alert_banner.html.slim
370
372
  - app/views/cm_admin/main/_associated_table.html.slim
371
373
  - app/views/cm_admin/main/_card.html.slim
372
374
  - app/views/cm_admin/main/_cm_pagy_nav.html.slim
@@ -419,6 +421,7 @@ files:
419
421
  - config/webpack/production.js
420
422
  - config/webpack/test.js
421
423
  - config/webpacker.yml
424
+ - docs/AddingAlert.md
422
425
  - docs/ListingSelectTwoAjax.md
423
426
  - docs/ListingSelectTwoItems.md
424
427
  - docs/ShowHideContent.md
@@ -431,6 +434,7 @@ files:
431
434
  - lib/cm_admin/model.rb
432
435
  - lib/cm_admin/models/action.rb
433
436
  - lib/cm_admin/models/actions/blocks.rb
437
+ - lib/cm_admin/models/alert.rb
434
438
  - lib/cm_admin/models/blocks.rb
435
439
  - lib/cm_admin/models/bulk_action.rb
436
440
  - lib/cm_admin/models/column.rb