headmin 0.1.1 → 0.2.2

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 (210) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +0 -1
  3. data/Gemfile.lock +24 -2
  4. data/README.md +8 -43
  5. data/app/controllers/concerns/headmin/authentication.rb +0 -8
  6. data/app/controllers/concerns/headmin/pagination.rb +1 -1
  7. data/app/helpers/headmin/admin_helper.rb +4 -4
  8. data/app/models/concerns/headmin/block.rb +11 -0
  9. data/app/models/concerns/headmin/blockable.rb +10 -0
  10. data/app/models/concerns/headmin/field.rb +17 -0
  11. data/app/models/concerns/headmin/fieldable.rb +44 -0
  12. data/app/services/block_service.rb +68 -0
  13. data/app/views/{layouts → examples}/admin.html.erb +0 -0
  14. data/app/views/{layouts/admin → examples}/auth.html.erb +0 -0
  15. data/app/views/headmin/_blocks.html.erb +24 -0
  16. data/app/views/headmin/_breadcrumbs.html.erb +9 -5
  17. data/app/views/headmin/_card.html.erb +48 -0
  18. data/app/views/headmin/_dropdown.html.erb +18 -0
  19. data/app/views/headmin/_filters.html.erb +56 -34
  20. data/app/views/headmin/_form.html.erb +60 -6
  21. data/app/views/headmin/_heading.html.erb +8 -4
  22. data/app/views/headmin/_index.html.erb +9 -8
  23. data/app/views/headmin/_notifications.html.erb +8 -0
  24. data/app/views/headmin/_pagination.html.erb +11 -7
  25. data/app/views/headmin/_popup.html.erb +26 -0
  26. data/app/views/headmin/_table.html.erb +11 -4
  27. data/app/views/headmin/dropdown/_button.html.erb +13 -0
  28. data/app/views/headmin/dropdown/_devise.html.erb +21 -0
  29. data/app/views/headmin/{layout/dropdown → dropdown}/_divider.html.erb +1 -1
  30. data/app/views/headmin/dropdown/_item.html.erb +18 -0
  31. data/app/views/headmin/dropdown/_list.html.erb +11 -0
  32. data/app/views/headmin/dropdown/_locale.html.erb +17 -0
  33. data/app/views/headmin/filters/_date.html.erb +21 -16
  34. data/app/views/headmin/filters/_search.html.erb +18 -18
  35. data/app/views/headmin/filters/_select.html.erb +28 -23
  36. data/app/views/headmin/filters/filter/_button.html.erb +15 -6
  37. data/app/views/headmin/filters/filter/_menu_item.html.erb +2 -2
  38. data/app/views/headmin/filters/filter/_template.html.erb +2 -2
  39. data/app/views/headmin/forms/_actions.html.erb +4 -8
  40. data/app/views/headmin/forms/_base.html.erb +60 -0
  41. data/app/views/headmin/forms/_blocks.html.erb +32 -0
  42. data/app/views/headmin/forms/_checkbox.html.erb +39 -0
  43. data/app/views/headmin/forms/_ckeditor.html.erb +42 -0
  44. data/app/views/headmin/forms/_date.html.erb +45 -0
  45. data/app/views/headmin/forms/_email.html.erb +39 -0
  46. data/app/views/headmin/forms/_file.html.erb +40 -0
  47. data/app/views/headmin/forms/_image.html.erb +55 -0
  48. data/app/views/headmin/forms/_label.html.erb +24 -0
  49. data/app/views/headmin/forms/_number.html.erb +50 -0
  50. data/app/views/headmin/forms/_password.html.erb +69 -0
  51. data/app/views/headmin/forms/_redactorx.html.erb +49 -0
  52. data/app/views/headmin/forms/_repeater.html.erb +133 -0
  53. data/app/views/headmin/forms/_select.html.erb +70 -0
  54. data/app/views/headmin/forms/_text.html.erb +62 -0
  55. data/app/views/headmin/forms/_textarea.html.erb +39 -0
  56. data/app/views/headmin/forms/_url.html.erb +39 -0
  57. data/app/views/headmin/forms/_validation.html.erb +21 -0
  58. data/app/views/headmin/forms/actions/_destroy.html.erb +13 -0
  59. data/app/views/headmin/forms/actions/_save.html.erb +12 -0
  60. data/app/views/headmin/forms/actions/_view.html.erb +15 -0
  61. data/app/views/headmin/forms/fields/_base.html.erb +25 -0
  62. data/app/views/headmin/forms/fields/_file.html.erb +15 -22
  63. data/app/views/headmin/forms/fields/_group.html.erb +38 -0
  64. data/app/views/headmin/forms/fields/_image.html.erb +15 -35
  65. data/app/views/headmin/forms/fields/_list.html.erb +26 -0
  66. data/app/views/headmin/forms/fields/_text.html.erb +15 -37
  67. data/app/views/headmin/forms/repeater/_row.html.erb +51 -0
  68. data/app/views/headmin/heading/_title.html.erb +1 -1
  69. data/app/views/headmin/layout/_body.html.erb +1 -1
  70. data/app/views/headmin/layout/_content.html.erb +1 -1
  71. data/app/views/headmin/layout/_footer.html.erb +1 -1
  72. data/app/views/headmin/layout/_header.html.erb +1 -1
  73. data/app/views/headmin/layout/_main.html.erb +2 -2
  74. data/app/views/headmin/layout/_sidebar.html.erb +1 -1
  75. data/app/views/headmin/layout/sidebar/{_menu.html.erb → _nav.html.erb} +1 -1
  76. data/app/views/headmin/nav/_item.html.erb +21 -0
  77. data/app/views/headmin/nav/item/_devise.html.erb +21 -0
  78. data/app/views/headmin/nav/item/_locale.html.erb +17 -0
  79. data/app/views/headmin/pagination/_per_page.html.erb +18 -0
  80. data/app/views/headmin/{kaminari → pagination/kaminari}/_first_page.html.erb +0 -0
  81. data/app/views/headmin/{kaminari → pagination/kaminari}/_gap.html.erb +0 -0
  82. data/app/views/headmin/{kaminari → pagination/kaminari}/_last_page.html.erb +0 -0
  83. data/app/views/headmin/{kaminari → pagination/kaminari}/_next_page.html.erb +0 -0
  84. data/app/views/headmin/{kaminari → pagination/kaminari}/_page.html.erb +1 -1
  85. data/app/views/headmin/{kaminari → pagination/kaminari}/_paginator.html.erb +0 -0
  86. data/app/views/headmin/{kaminari → pagination/kaminari}/_prev_page.html.erb +0 -0
  87. data/app/views/headmin/table/_actions.html.erb +24 -17
  88. data/app/views/headmin/table/_body.html.erb +12 -10
  89. data/app/views/headmin/table/_foot.html.erb +8 -4
  90. data/app/views/headmin/table/_footer.html.erb +3 -7
  91. data/app/views/headmin/table/_head.html.erb +3 -1
  92. data/app/views/headmin/table/_header.html.erb +3 -7
  93. data/app/views/headmin/table/actions/_action.html.erb +26 -9
  94. data/app/views/headmin/table/actions/_delete.html.erb +11 -7
  95. data/app/views/headmin/table/actions/_export.html.erb +11 -7
  96. data/app/views/headmin/table/body/_association.html.erb +1 -1
  97. data/app/views/headmin/table/body/_boolean.erb +1 -1
  98. data/app/views/headmin/table/body/_currency.html.erb +1 -1
  99. data/app/views/headmin/table/body/_date.html.erb +1 -1
  100. data/app/views/headmin/table/body/_id.html.erb +2 -2
  101. data/app/views/headmin/table/body/_row.html.erb +1 -1
  102. data/app/views/headmin/table/body/_string.html.erb +1 -1
  103. data/app/views/headmin/table/body/_text.html.erb +1 -1
  104. data/app/views/headmin/table/foot/_cell.html.erb +1 -1
  105. data/app/views/headmin/table/foot/_id.html.erb +2 -2
  106. data/app/views/headmin/table/head/_cell.html.erb +1 -1
  107. data/app/views/headmin/table/head/_id.html.erb +3 -3
  108. data/app/views/headmin/views/devise/confirmations/_new.html.erb +9 -0
  109. data/app/views/headmin/views/devise/passwords/_edit.html.erb +12 -0
  110. data/app/views/headmin/views/devise/passwords/_new.html.erb +9 -0
  111. data/app/views/{admin/users/registrations/edit.html.erb → headmin/views/devise/registrations/_edit.html.erb} +5 -5
  112. data/app/views/headmin/views/devise/registrations/_new.html.erb +11 -0
  113. data/app/views/headmin/views/devise/sessions/_new.html.erb +13 -0
  114. data/app/views/{admin/users → headmin/views/devise}/shared/_error_messages.html.erb +0 -0
  115. data/app/views/{admin/users → headmin/views/devise}/shared/_links.html.erb +0 -0
  116. data/app/views/headmin/views/devise/unlocks/_new.html.erb +10 -0
  117. data/config/initializers/customize_input_error.rb +9 -0
  118. data/config/locales/devise/en.yml +65 -0
  119. data/config/locales/en.yml +2 -134
  120. data/config/locales/headmin/filters/en.yml +13 -0
  121. data/config/locales/headmin/filters/nl.yml +13 -0
  122. data/config/locales/headmin/forms/en.yml +34 -0
  123. data/config/locales/headmin/forms/nl.yml +33 -0
  124. data/config/locales/headmin/heading/en.yml +5 -0
  125. data/config/locales/headmin/heading/nl.yml +5 -0
  126. data/config/locales/headmin/layout/en.yml +14 -0
  127. data/config/locales/headmin/layout/nl.yml +14 -0
  128. data/config/locales/headmin/pagination/en.yml +21 -0
  129. data/config/locales/headmin/pagination/nl.yml +21 -0
  130. data/config/locales/headmin/table/en.yml +23 -0
  131. data/config/locales/headmin/table/nl.yml +23 -0
  132. data/config/locales/headmin/views/en.yml +58 -0
  133. data/config/locales/headmin/views/nl.yml +58 -0
  134. data/config/locales/nl.yml +2 -135
  135. data/dist/css/headmin.css +3182 -743
  136. data/dist/js/headmin.js +729 -33
  137. data/docs/README.md +2 -1
  138. data/docs/blocks.md +70 -85
  139. data/docs/devise.md +1 -60
  140. data/docs/fields.md +57 -0
  141. data/headmin.gemspec +1 -0
  142. data/lib/generators/headmin/blocks_generator.rb +19 -0
  143. data/lib/generators/headmin/fields_generator.rb +19 -0
  144. data/lib/generators/templates/migrations/create_blocks.rb +10 -0
  145. data/lib/generators/templates/migrations/create_fields.rb +13 -0
  146. data/lib/generators/templates/models/block.rb +3 -0
  147. data/lib/generators/templates/models/field.rb +3 -0
  148. data/lib/headmin/version.rb +1 -1
  149. data/package.json +6 -6
  150. data/src/js/headmin/controllers/blocks_controller.js +103 -0
  151. data/src/js/headmin/controllers/filters_controller.js +23 -12
  152. data/src/js/headmin/controllers/popup_controller.js +68 -0
  153. data/src/js/headmin/controllers/repeater_controller.js +117 -11
  154. data/src/js/headmin/controllers/table_actions_controller.js +16 -5
  155. data/src/js/headmin/controllers/table_controller.js +84 -1
  156. data/src/js/headmin/headmin.js +29 -56
  157. data/src/scss/headmin/filters.scss +0 -14
  158. data/src/scss/headmin/form.scss +43 -3
  159. data/src/scss/headmin/popup.scss +17 -0
  160. data/src/scss/headmin/table.scss +9 -6
  161. data/src/scss/headmin.scss +7 -4
  162. data/src/scss/vendor/redactorx/override.css +3 -0
  163. data/src/scss/vendor/redactorx/redactorx.css +1460 -0
  164. data/yarn.lock +105 -2210
  165. metadata +108 -62
  166. data/app/controllers/admin/users/confirmations_controller.rb +0 -31
  167. data/app/controllers/admin/users/omniauth_callbacks_controller.rb +0 -31
  168. data/app/controllers/admin/users/passwords_controller.rb +0 -35
  169. data/app/controllers/admin/users/registrations_controller.rb +0 -63
  170. data/app/controllers/admin/users/sessions_controller.rb +0 -28
  171. data/app/controllers/admin/users/unlocks_controller.rb +0 -31
  172. data/app/views/admin/users/confirmations/new.html.erb +0 -9
  173. data/app/views/admin/users/mailer/confirmation_instructions.html.erb +0 -5
  174. data/app/views/admin/users/mailer/email_changed.html.erb +0 -7
  175. data/app/views/admin/users/mailer/password_change.html.erb +0 -3
  176. data/app/views/admin/users/mailer/reset_password_instructions.html.erb +0 -8
  177. data/app/views/admin/users/mailer/unlock_instructions.html.erb +0 -7
  178. data/app/views/admin/users/passwords/edit.html.erb +0 -12
  179. data/app/views/admin/users/passwords/new.html.erb +0 -9
  180. data/app/views/admin/users/registrations/new.html.erb +0 -11
  181. data/app/views/admin/users/sessions/new.html.erb +0 -13
  182. data/app/views/admin/users/unlocks/new.html.erb +0 -10
  183. data/app/views/headmin/forms/_group.html.erb +0 -36
  184. data/app/views/headmin/forms/fields/_checkbox.html.erb +0 -23
  185. data/app/views/headmin/forms/fields/_ckeditor.html.erb +0 -28
  186. data/app/views/headmin/forms/fields/_currency.html.erb +0 -24
  187. data/app/views/headmin/forms/fields/_date.html.erb +0 -36
  188. data/app/views/headmin/forms/fields/_email.html.erb +0 -39
  189. data/app/views/headmin/forms/fields/_label.html.erb +0 -9
  190. data/app/views/headmin/forms/fields/_multiple_select.html.erb +0 -37
  191. data/app/views/headmin/forms/fields/_password.html.erb +0 -39
  192. data/app/views/headmin/forms/fields/_repeater.html.erb +0 -48
  193. data/app/views/headmin/forms/fields/_select.html.erb +0 -36
  194. data/app/views/headmin/forms/fields/_select_tags.html.erb +0 -32
  195. data/app/views/headmin/forms/fields/_textarea.html.erb +0 -29
  196. data/app/views/headmin/forms/fields/_url.html.erb +0 -38
  197. data/app/views/headmin/forms/fields/_validation.html.erb +0 -12
  198. data/app/views/headmin/forms/fields/repeater/_row.html.erb +0 -16
  199. data/app/views/headmin/layout/dropdown/_item.html.erb +0 -17
  200. data/app/views/headmin/layout/header/_account.html.erb +0 -25
  201. data/app/views/headmin/layout/header/_locale.html.erb +0 -19
  202. data/app/views/headmin/layout/sidebar/menu/_account.html.erb +0 -25
  203. data/app/views/headmin/layout/sidebar/menu/_item.html.erb +0 -16
  204. data/app/views/headmin/layout/sidebar/menu/_locale.html.erb +0 -18
  205. data/src/js/headmin/controllers/index_controller.js +0 -79
  206. data/src/js/headmin/controllers/repeater_row_controller.js +0 -54
  207. data/src/scss/vendor/choices/cross-inverse.svg +0 -6
  208. data/src/scss/vendor/choices/cross.svg +0 -6
  209. data/src/scss/vendor/choices/custom.scss +0 -28
  210. data/src/scss/vendor/choices/variables.scss +0 -16
@@ -1,12 +1,13 @@
1
- <%#
2
- name: headmin/index
3
- accepts block: yes (required)
4
- parameters:
5
- search:
6
- url: base url to send search query to
7
- placeholder: placeholder for search field
1
+ <%
2
+ # headmin/index
3
+ #
4
+ # === Examples
5
+ # Basic version
6
+ # <%= render 'headmin/index' do %#>
7
+ # Index content
8
+ # <% end %#>
8
9
  %>
9
10
 
10
- <div class="headmin-index container-fluid" data-controller="index">
11
+ <div class="container-fluid">
11
12
  <%= yield %>
12
13
  </div>
@@ -1,3 +1,11 @@
1
+ <%
2
+ # headmin/notifications
3
+ #
4
+ # ==== Examples
5
+ # Basic version
6
+ # <%= render "headmin/notifications" %#>
7
+ %>
8
+
1
9
  <div class="toast-container position-absolute top-0 end-0 p-3">
2
10
  <% flash.each do |name, message| %>
3
11
  <div class="toast align-items-center text-white show <%= notification_color(name.to_sym)[:background] %>" role="alert" aria-live="assertive" aria-atomic="true">
@@ -1,13 +1,17 @@
1
- <%#
2
- name: headmin/pagination
3
- accepts block: no
4
- parameters:
5
- collection: Kaminari collection that accepts a method .total_count
1
+ <%
2
+ # headmin/notifications
3
+ #
4
+ # ==== Options
5
+ # * <tt>collection</tt> - Kaminari collection that accepts a method .total_count
6
+ #
7
+ # ==== Examples
8
+ # Basic version
9
+ # <%= render "headmin/pagination, collection: @pages" %#>
6
10
  %>
7
11
 
8
- <div class="d-flex flex-row-reverse flex-md-row align-items-center w-100 justify-content-between justify-content-md-end">
12
+ <div class="d-flex flex-row-reverse flex-md-row align-items-center justify-content-between justify-content-md-end my-1">
9
13
  <div class="ms-2 me-md-2 text-secondary">
10
14
  <%= t('.items', count: collection.total_count) %>
11
15
  </div>
12
- <%= paginate collection, views_prefix: 'headmin' %>
16
+ <%= paginate collection, views_prefix: 'headmin/pagination' %>
13
17
  </div>
@@ -0,0 +1,26 @@
1
+ <%
2
+ # headmin/popup
3
+ #
4
+ # ==== Options
5
+ # * <tt>id</tt> - Identifier for this popup
6
+ #
7
+ # ==== Examples
8
+ # To trigger this popup create an element with a data attribute like this
9
+ #
10
+ # <button data-popup-id="popupId">open Popup</button>
11
+ # <%= render 'headmin/popup', id: 'popupId' do %#>
12
+ # popup Content
13
+ # <% end %#>
14
+ #
15
+ # If you want to pass a click event to an element inside the popup without opening the popup you can use the
16
+ # "data-popup-pass-thru" attribute.
17
+ #
18
+ # <button data-popup-id="popupId" data-popup-pass-thru="#link">open Popup</button>
19
+ # <%= render 'headmin/popup', id: 'popupId' do %#>
20
+ # <a href="https://example.com" id="link">
21
+ # <% end %#>
22
+ %>
23
+
24
+ <div class="h-popup closed" data-popup-target="popup" data-popup-id="<%= id %>">
25
+ <%= yield if block_given? %>
26
+ </div>
@@ -1,8 +1,15 @@
1
- <%#
2
- name: headmin/table
3
- accepts block: yes
4
- parameters: none
1
+ <%
2
+ # headmin/table
3
+ #
4
+ # ==== Options
5
+ # * <tt>sort_url</tt> - U
6
+ #
7
+ # ==== Examples
8
+ # <%= render 'headmin/table', sort_url: positions_admin_categories_path do %#>
9
+ # table content here
10
+ # <% end %#>
5
11
  %>
12
+
6
13
  <% sort_url = local_assigns.has_key?(:sort_url) ? sort_url : nil %>
7
14
  <div class="h-table card my-2 shadow-sm <%= 'table-drag-sort' if sort_url %>" data-sort-url="<%= sort_url %>">
8
15
  <div class="table-responsive">
@@ -0,0 +1,13 @@
1
+ <%#
2
+ headmin/dropdown/button
3
+ accepts block: yes
4
+ parameters:
5
+ id: unique identifier for the dropdown
6
+ class: css class names as string
7
+ %>
8
+ <% id = local_assigns.has_key?(:id) ? id : 'dropdown-1' %>
9
+ <% class_names = local_assigns.has_key?(:class) ? local_assigns[:class] : 'btn' %>
10
+
11
+ <a class="dropdown-toggle d-flex align-items-center <%= class_names %>" type="button" id="<%= id %>" data-bs-toggle="dropdown" aria-expanded="false">
12
+ <%= yield %>
13
+ </a>
@@ -0,0 +1,21 @@
1
+ <%#
2
+ headmin/dropdown/locale
3
+ accepts block: yes
4
+ parameters:
5
+ scope: (symbol) devise scope, i.e. ':users' => current_user
6
+ %>
7
+
8
+ <% scope = local_assigns.has_key?(:scope) ? scope : :users %>
9
+ <% singular = scope.to_s.singularize.to_sym %>
10
+ <% user = send("current_#{singular}") %>
11
+
12
+ <%= render 'headmin/dropdown' do %>
13
+ <%= render 'headmin/dropdown/button' do %>
14
+ <%= user.to_s %>
15
+ <% end %>
16
+ <%= render 'headmin/dropdown/list' do %>
17
+ <%= render 'headmin/dropdown/item', name: t('.edit_profile'), url: polymorphic_path([:edit, singular, :registration]) %>
18
+ <%= render 'headmin/dropdown/divider' %>
19
+ <%= render 'headmin/dropdown/item', name: t('.log_out'), url: polymorphic_path([:destroy, singular, :session]), method: :delete %>
20
+ <% end %>
21
+ <% end %>
@@ -1,5 +1,5 @@
1
1
  <%#
2
- name: headmin/dropdown/item
2
+ headmin/dropdown/item
3
3
  accepts block: no
4
4
  parameters: none
5
5
  %>
@@ -0,0 +1,18 @@
1
+ <%#
2
+ headmin/dropdown/item
3
+ accepts block: no
4
+ parameters:
5
+ name: Name of the link in the dropdown menu
6
+ url: Url of the link in the dropdown menu
7
+ method: Sets data-method of url
8
+ %>
9
+
10
+ <% method = local_assigns.has_key?(:method) ? method : nil %>
11
+ <% url = local_assigns.has_key?(:url) ? url : '' %>
12
+ <% name = local_assigns.has_key?(:name) ? name : '' %>
13
+
14
+ <li>
15
+ <a class="dropdown-item" href="<%= url %>" <%= "data-method=#{method}" if method %>>
16
+ <%= name %>
17
+ </a>
18
+ </li>
@@ -0,0 +1,11 @@
1
+ <%#
2
+ headmin/dropdown/list
3
+ accepts block: yes
4
+ parameters:
5
+ id: unique identifier for the dropdown
6
+ %>
7
+ <% id = local_assigns.has_key?(:id) ? id : 'dropdown-1' %>
8
+
9
+ <ul class="dropdown-menu" aria-labelledby="<%= id %>">
10
+ <%= yield %>
11
+ </ul>
@@ -0,0 +1,17 @@
1
+ <%#
2
+ headmin/dropdown/locale
3
+ accepts block: no
4
+ parameters: none
5
+ %>
6
+
7
+ <%= render 'headmin/dropdown' do %>
8
+ <%= render 'headmin/dropdown/button', id: 'locale-dropdown' do %>
9
+ <%= bootstrap_icon('globe', class: 'me-2') %>
10
+ <%= t('language_name', locale: ::I18n.locale) %>
11
+ <% end %>
12
+ <%= render 'headmin/dropdown/list', id: 'locale-dropdown' do %>
13
+ <% I18n.available_locales.each do |locale| %>
14
+ <%= render 'headmin/dropdown/item', name: t('language_name', locale: locale), url: url_for({locale: locale.to_s}) %>
15
+ <% end %>
16
+ <% end %>
17
+ <% end %>
@@ -1,20 +1,25 @@
1
- <%#
2
- name: headmin/filters/date_range
3
- accepts block: no
4
- parameters:
5
- name: (string) Name of the parameter
6
- label: (string) Display name
7
- %>
8
- <% label = local_assigns.has_key?(:label) ? label : nil %>
9
- <% name = local_assigns.has_key?(:name) ? name : nil %>
1
+ <%
2
+ # headmin/filters/date
3
+ #
4
+ # ==== Options
5
+ # * <tt>name</tt> - Name of the filter parameter
6
+ # * <tt>label</tt> - Display name
7
+ #
8
+ # ==== Examples
9
+ # Basic version
10
+ # <%= render "headmin/filters/date", name: :created_at, label: 'Created at' %#>
11
+
12
+ label = local_assigns.has_key?(:label) ? label : nil
13
+ name = local_assigns.has_key?(:name) ? name : nil
10
14
 
11
- <% input_options = {
12
- placeholder: 'dd/mm/yyyy',
13
- class: "form-control flatpickr",
14
- required: true,
15
- 'data-filters-target': 'input',
16
- 'data-action': "change->filters#update"
17
- } %>
15
+ input_options = {
16
+ placeholder: 'dd/mm/yyyy',
17
+ class: "form-control flatpickr",
18
+ required: true,
19
+ 'data-filters-target': 'input',
20
+ 'data-action': "change->filters#update"
21
+ }
22
+ %>
18
23
 
19
24
  <%= content_for :filters_menu do %>
20
25
  <%= render 'headmin/filters/filter/menu_item', name: name, label: label %>
@@ -1,22 +1,22 @@
1
- <%#
2
- name: headmin/filters/search
3
- accepts block: no
4
- parameters:
5
- name: (string) Name of the parameter
6
- model: (Object) model to create a placeholder for
7
- placeholder: (string) placeholder for search field. Defaults to model name
8
- %>
9
- <% name = local_assigns.has_key?(:name) ? name : :search %>
10
- <% label = local_assigns.has_key?(:label) ? label : nil %>
11
- <% placeholder = local_assigns.has_key?(:placeholder) ? placeholder : t('.placeholder', resource: label) %>
1
+ <%
2
+ # headmin/filters/search
3
+ #
4
+ # ==== Options
5
+ # * <tt>name</tt> - Name of the filter parameter
6
+ # * <tt>label</tt> - Name of the resource to be used in the placeholder (search in ...)
7
+ # * <tt>placeholder</tt> - Placeholder in the search field
8
+ #
9
+ # ==== Examples
10
+ # Basic version.
11
+ # <%= render 'headmin/filters/search', name: :search, label: Poll.model_name.human(count: 2) %#>
12
+
13
+ name = local_assigns.has_key?(:name) ? name : :search
14
+ label = local_assigns.has_key?(:label) ? label : nil
15
+ placeholder = local_assigns.has_key?(:placeholder) ? placeholder : t('.placeholder', resource: label)
12
16
 
13
- <% value = filter_param_exists?(name) ? params[name] : nil %>
17
+ value = filter_param_exists?(name) ? params[name] : nil
18
+ %>
14
19
 
15
20
  <% content_for :filters_search do %>
16
- <div class="h-filters-search d-flex">
17
- <input class="form-control me-1" type="search" placeholder="<%= raw placeholder.capitalize %>" aria-label="Search" name="<%= name %>" value="<%= value %>">
18
- <button class="btn h-btn-outline-light d-none d-md-block" type="submit">
19
- <%= t('.button') %>
20
- </button>
21
- </div>
21
+ <input class="form-control" type="search" placeholder="<%= raw placeholder.capitalize %>" aria-label="Search" name="<%= name %>" value="<%= value %>">
22
22
  <% end %>
@@ -1,23 +1,28 @@
1
- <%#
2
- name: headmin/filters/select
3
- accepts block: no
4
- parameters:
5
- name: (string) Name of the parameter
6
- label: (string) Display name
7
- options: (array) List of options to select from
8
- %>
9
- <% label = local_assigns.has_key?(:label) ? label : nil %>
10
- <% name = local_assigns.has_key?(:name) ? name : nil %>
11
- <% options = local_assigns.has_key?(:options) ? options : [] %>
1
+ <%
2
+ # headmin/filters/select
3
+ #
4
+ # ==== Options
5
+ # * <tt>name</tt> - Name of the filter parameter
6
+ # * <tt>label</tt> - Display name
7
+ # * <tt>options</tt> - List of options to select from
8
+ #
9
+ # ==== Examples
10
+ # Basic version
11
+ # <%= render "headmin/filters/select", name: :poll_type, label: 'Type', options: [["General", "general", "Fun", "fun"]] %#>
12
+
13
+ label = local_assigns.has_key?(:label) ? label : nil
14
+ name = local_assigns.has_key?(:name) ? name : nil
15
+ options = local_assigns.has_key?(:options) ? options : []
12
16
 
13
- <% select_options = {
14
- class: "form-select",
15
- prompt: t('.blank'),
16
- include_blank: false,
17
- required: true,
18
- 'data-filters-target': 'input',
19
- 'data-action': "change->filters#update"
20
- } %>
17
+ select_options = {
18
+ class: "form-select",
19
+ prompt: t('.blank'),
20
+ include_blank: false,
21
+ required: true,
22
+ 'data-filters-target': 'input',
23
+ 'data-action': "change->filters#update"
24
+ }
25
+ %>
21
26
 
22
27
  <%= content_for :filters_menu do %>
23
28
  <%= render 'headmin/filters/filter/menu_item', name: name, label: label %>
@@ -30,10 +35,10 @@
30
35
  <% end %>
31
36
 
32
37
  <%= content_for :filters_buttons do %>
33
- <% if filter_param_exists?(name) %>
34
- <% option_name = options.select { |value, key| params[name].include?(key.to_s)}.map{|value, key| value}.join(', ') %>
35
- <%= render 'headmin/filters/filter/button', name: name, label: label, value: option_name do %>
36
- <%= select_tag("#{name}[]", options_for_select(options, params[name]), select_options) %>
38
+ <% (params[name] || []).each_with_index do |param, index| %>
39
+ <% value = options.detect { |value, key, config| key == param } %>
40
+ <%= render 'headmin/filters/filter/button', name: name, label: label, value: value ? value.first : nil, id: "#{name}_#{index}" do %>
41
+ <%= select_tag("#{name}[]", options_for_select(options, param), select_options) %>
37
42
  <% end %>
38
43
  <% end %>
39
44
  <% end %>
@@ -1,22 +1,31 @@
1
1
  <%#
2
- name: headmin/filters/filter/button
2
+ headmin/filters/filter/button
3
3
  accepts block: yes
4
4
  parameters:
5
5
  name: (string) Name of the parameter
6
6
  label: (string) Display name
7
7
  value: (string) Value of the parameter
8
8
  %>
9
+ <% id = local_assigns.has_key?(:id) ? id : Time.now.utc.to_i %>
9
10
  <% name = local_assigns.has_key?(:name) ? name : nil %>
10
11
  <% label = local_assigns.has_key?(:label) ? label : nil %>
11
12
  <% value = local_assigns.has_key?(:value) ? value : nil %>
12
- <% active = local_assigns.has_key?(:active) ? active : false %>
13
13
 
14
- <div class="h-filter me-1" data-controller="filter" data-filters-target="button" data-filter-name="<%= name %>">
15
- <button type="button" class="h-filter-button btn h-btn-outline-transparent ms-1" data-filter-target="button" data-action="click->filter#toggle click@window->filter#close" aria-expanded="<%= active ? 'true' : 'false' %>">
14
+ <div class="h-filter me-1 my-1" data-filter-name="<%= name %>">
15
+
16
+ <button
17
+ type="button"
18
+ class="h-filter-button btn h-btn-outline-transparent"
19
+ data-popup-target="button"
20
+ data-popup-id="<%= id %>"
21
+ data-action="click->popup#open"
22
+ >
16
23
  <%= "#{label}: #{value || t('.all')}" %>
17
24
  <span class="h-filter-remove" data-action="click->filters#remove"><%= bootstrap_icon('x-lg') %></span>
18
25
  </button>
19
- <div class="h-filter-popup <%= ('closed' unless active) %>" data-filter-target="popup">
26
+
27
+ <%= render 'headmin/popup', id: "#{id}" do %>
20
28
  <%= yield if block_given? %>
21
- </div>
29
+ <% end %>
30
+
22
31
  </div>
@@ -1,12 +1,12 @@
1
1
  <%#
2
- name: headmin/filters/filter/menu_item
2
+ headmin/filters/filter/menu_item
3
3
  accepts block: no
4
4
  parameters:
5
5
  name: (string) Name of the parameter
6
6
  label: (string) Display name
7
7
  %>
8
8
  <li>
9
- <a class="dropdown-item" href="#" data-action="click->filters#add" data-filter-name="<%= name %>">
9
+ <a class="dropdown-item" href="#" data-filters-target="menuItem" data-action="click->filters#add" data-filter-name="<%= name %>">
10
10
  <%= label %>
11
11
  </a>
12
12
  </li>
@@ -1,5 +1,5 @@
1
1
  <%#
2
- name: headmin/filters/filter/template
2
+ headmin/filters/filter/template
3
3
  accepts block: yes
4
4
  parameters:
5
5
  name: (string) Name of the parameter
@@ -7,7 +7,7 @@
7
7
  %>
8
8
 
9
9
  <template data-filter-name="<%= name %>" data-filters-target="template">
10
- <%= render 'headmin/filters/filter/button', name: name, label: label, value: nil, active: true do %>
10
+ <%= render 'headmin/filters/filter/button', name: name, label: label, value: nil, id: 'template_id' do %>
11
11
  <%= yield if block_given? %>
12
12
  <% end %>
13
13
  </template>
@@ -1,8 +1,8 @@
1
1
  <%#
2
- name: headmin/forms/actions
2
+ headmin/forms/actions
3
3
  accepts block: true
4
4
  parameters:
5
- form: (string) Form object
5
+ form: (object) Form object
6
6
  %>
7
7
 
8
8
  <div class="card forms-actions shadow-sm mb-3">
@@ -21,12 +21,8 @@
21
21
 
22
22
  <%= yield if block_given? %>
23
23
 
24
- <div class="d-grid">
25
- <%= link_to(t('.delete.title'),[:admin, form.object], class: 'btn btn-outline-danger', method: :delete, data: {confirm: t('.delete.confirm')}) %>
26
- </div>
24
+ <%= render 'headmin/forms/actions/destroy', form: form %>
27
25
  <hr>
28
- <div class="d-grid">
29
- <%= form.submit "Opslaan", class: 'btn btn-lg btn-primary' %>
30
- </div>
26
+ <%= render 'headmin/forms/actions/save', form: form %>
31
27
  </div>
32
28
  </div>
@@ -0,0 +1,60 @@
1
+ <%
2
+ # headmin/forms/base
3
+ #
4
+ # ==== Options
5
+ # * <tt>form<tt> - Form object
6
+ # * <tt>attribute<tt> - Name of the attribute of the form model
7
+ # * <tt>options<tt> - Hash with all HTML options to pass to
8
+ # * <tt>label<tt> - Text to show as label. Label will be hidden if value is false
9
+ # * <tt>required<tt> - Set to true to mark as required
10
+ # * <tt>float<tt> - Set to true if you want to show floating labels
11
+ # * <tt>append<tt> - Text or icon to be shown on the left hand side of the input, Doesn't work with float
12
+ # * <tt>prepend<tt> - Text or icon to be shown on the right hand side of the input, Doesn't work with float
13
+ #
14
+ # ==== Examples
15
+ # Basic version
16
+ # <%= render 'headmin/forms/date', form: form, attribute: :title %#>
17
+ #
18
+ # With datepicker
19
+ # <%= render 'headmin/forms/text', form: form, attribute: :title, datepicker: true %#>
20
+
21
+ append = local_assigns.has_key?(:append) ? append : nil
22
+ float = local_assigns.has_key?(:float) ? float : false
23
+ label = local_assigns.has_key?(:label) ? label : nil
24
+ prepend = local_assigns.has_key?(:prepend) ? prepend : nil
25
+ required = local_assigns.has_key?(:required) ? required : false
26
+
27
+ show_label = label != false
28
+ %>
29
+
30
+ <div class="<%= 'form-floating' if float %> <%= ('mb-3 text-start' if show_label) %>">
31
+ <% if show_label && !float %>
32
+ <%= render 'headmin/forms/label', form: form, attribute: attribute, name: label, required: required %>
33
+ <% end %>
34
+
35
+ <% if float %>
36
+ <%= yield form %>
37
+ <%= render 'headmin/forms/validation', form: form, attribute: attribute %>
38
+ <% else %>
39
+ <div class="input-group w-100">
40
+ <% if prepend %>
41
+ <span class="input-group-text">
42
+ <%= prepend %>
43
+ </span>
44
+ <% end %>
45
+
46
+ <%= yield form %>
47
+ <%= render 'headmin/forms/validation', form: form, attribute: attribute %>
48
+
49
+ <% if append %>
50
+ <span class="input-group-text">
51
+ <%= append %>
52
+ </span>
53
+ <% end %>
54
+ </div>
55
+ <% end %>
56
+
57
+ <% if show_label && float %>
58
+ <%= render 'headmin/forms/label', form: form, attribute: attribute, name: label, required: required %>
59
+ <% end %>
60
+ </div>
@@ -0,0 +1,32 @@
1
+ <%
2
+ # headmin/forms/blocks
3
+ #
4
+ # ==== Options
5
+ # * <tt>form</tt> - Form object
6
+ # * <tt>path</tt> - Directory where to look for block templates
7
+ # * <tt>allow</tt> - Names of block templates that can be added
8
+ #
9
+ # ==== Examples
10
+ # Basic version. This will only look for blocks in 'admin/blocks'
11
+ # <%= render "headmin/forms/blocks", form: form %#>
12
+ #
13
+ # Define the path to look for block templates like this:
14
+ # <%= render "headmin/forms/blocks", form: form, path: 'admin/pages/blocks' %#>
15
+ #
16
+ # Limit the types of blocks
17
+ # <%= render "headmin/forms/blocks", form: form, allow: ['text', 'text-image'] %#>
18
+
19
+ path = local_assigns.has_key?(:path) ? path : nil
20
+ allowed_block_names = local_assigns.has_key?(:allow) ? allow.map(&:to_s) : BlockService.block_names(path: path)
21
+
22
+ templates = allowed_block_names.map { |name| BlockService.form_view(name, path: path) }
23
+ %>
24
+
25
+ <%= render 'headmin/forms/repeater', form: form, attribute: :blocks, templates: templates, label: false do |block| %>
26
+ <% view_path = BlockService.form_view(block.object.name, path: path).gsub('/_', '/') %>
27
+ <%= render view_path, form: block, name: block.object.name %>
28
+
29
+ <span class="position-absolute top-0 end-0 badge bg-light text-dark">
30
+ <%= block.object.name.titleize %>
31
+ </span>
32
+ <% end %>
@@ -0,0 +1,39 @@
1
+ <%
2
+ # headmin/forms/checkbox
3
+ #
4
+ # ==== Options
5
+ # * <tt>form<tt> - Form object
6
+ # * <tt>attribute<tt> - Name of the attribute of the form model
7
+ # * <tt>label<tt> - Text to show as label. Label will be hidden if value is false
8
+ #
9
+ # ==== Examples
10
+ # Basic version
11
+ # <%= render 'headmin/forms/image', form: form, attribute: :image %#>
12
+
13
+ class_names = local_assigns.has_key?(:class) ? local_assigns[:class] : false
14
+ data = local_assigns.has_key?(:data) ? data : nil
15
+ disabled = local_assigns.has_key?(:disabled) ? disabled : false
16
+ label = local_assigns.has_key?(:label) ? label : nil
17
+ readonly = local_assigns.has_key?(:readonly) ? readonly : false
18
+ required = local_assigns.has_key?(:required) ? required : false
19
+
20
+ options = {
21
+ 'aria-describedby': form_field_validation_id(form, attribute),
22
+ class: "form-checkbox-input #{form_field_validation_class(form, attribute)} #{class_names}",
23
+ data: data,
24
+ disabled: disabled,
25
+ placeholder: attribute,
26
+ readonly: readonly,
27
+ required: required,
28
+ }
29
+
30
+ show_label = label != false
31
+ %>
32
+
33
+ <div class="<%= ('mb-3 text-start' if show_label) %>">
34
+ <%= form.check_box(attribute, options) %>
35
+ <% if show_label %>
36
+ <%= render 'headmin/forms/label', form: form, attribute: attribute, name: label, required: required %>
37
+ <% end %>
38
+ <%= render 'headmin/forms/validation', form: form, attribute: attribute %>
39
+ </div>
@@ -0,0 +1,42 @@
1
+ <%
2
+ # headmin/forms/ckeditor
3
+ #
4
+ # ==== Options
5
+ # * <tt>form<tt> - Form object
6
+ # * <tt>attribute<tt> - Name of the attribute of the form model
7
+ # * <tt>label<tt> - Text to show as label. Label will be hidden if value is false
8
+ # * <tt>toolbar<tt> - Array containing the toolbar items to display
9
+ # * <tt>upload_path<tt> - URL to upload images to
10
+ #
11
+ # ==== Examples
12
+ # Basic version
13
+ # <%= render 'headmin/forms/textarea', form: form, attribute: :title %#>
14
+
15
+ class_names = local_assigns.has_key?(:class) ? local_assigns[:class] : false
16
+ data = local_assigns.has_key?(:data) ? data : {}
17
+ disabled = local_assigns.has_key?(:disabled) ? disabled : false
18
+ label = local_assigns.has_key?(:label) ? label : nil
19
+ readonly = local_assigns.has_key?(:readonly) ? readonly : false
20
+ required = local_assigns.has_key?(:required) ? required : false
21
+ toolbar = local_assigns.has_key?(:toolbar) ? toolbar : nil
22
+ upload_path = local_assigns.has_key?(:upload_path) ? upload_path : ''
23
+
24
+ data = data.merge(
25
+ 'ckeditor-toolbar': toolbar,
26
+ 'ckeditor-upload-path': upload_path
27
+ )
28
+
29
+ options = {
30
+ 'aria-describedby': form_field_validation_id(form, attribute),
31
+ class: "ckeditor #{form_field_validation_class(form, attribute)} #{class_names}",
32
+ data: data,
33
+ disabled: disabled,
34
+ placeholder: attribute,
35
+ readonly: readonly,
36
+ required: required,
37
+ }
38
+ %>
39
+
40
+ <%= render 'headmin/forms/base', form: form, attribute: attribute, label: label, required: required do |form| %>
41
+ <%= form.text_area(attribute, options) %>
42
+ <% end %>