headmin 0.2.4 → 0.2.8

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 (74) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile.lock +2 -2
  3. data/app/helpers/headmin/admin_helper.rb +3 -59
  4. data/app/helpers/headmin/bootstrap_helper.rb +9 -0
  5. data/app/helpers/headmin/filter_helper.rb +7 -3
  6. data/app/helpers/headmin/form_helper.rb +36 -0
  7. data/app/helpers/headmin/request_helper.rb +39 -0
  8. data/app/models/concerns/headmin/fieldable.rb +3 -1
  9. data/app/services/block_service.rb +8 -4
  10. data/app/views/examples/admin.html.erb +1 -1
  11. data/app/views/headmin/_blocks.html.erb +1 -1
  12. data/app/views/headmin/_card.html.erb +3 -1
  13. data/app/views/headmin/_filters.html.erb +3 -3
  14. data/app/views/headmin/_pagination.html.erb +2 -1
  15. data/app/views/headmin/_table.html.erb +9 -3
  16. data/app/views/headmin/dropdown/_devise.html.erb +20 -10
  17. data/app/views/headmin/dropdown/_list.html.erb +17 -7
  18. data/app/views/headmin/filters/_date.html.erb +5 -3
  19. data/app/views/headmin/filters/_flatpickr.html.erb +57 -0
  20. data/app/views/headmin/forms/_base.html.erb +12 -11
  21. data/app/views/headmin/forms/_blocks.html.erb +11 -4
  22. data/app/views/headmin/forms/_date.html.erb +24 -12
  23. data/app/views/headmin/forms/_date_range.html.erb +84 -0
  24. data/app/views/headmin/forms/_flatpickr.html.erb +55 -0
  25. data/app/views/headmin/forms/_flatpickr_range.html.erb +61 -0
  26. data/app/views/headmin/forms/_hidden.html.erb +23 -0
  27. data/app/views/headmin/forms/_label.html.erb +4 -2
  28. data/app/views/headmin/forms/_repeater.html.erb +5 -8
  29. data/app/views/headmin/forms/_select.html.erb +14 -11
  30. data/app/views/headmin/forms/_text.html.erb +7 -9
  31. data/app/views/headmin/layout/_main.html.erb +11 -5
  32. data/app/views/headmin/table/_actions.html.erb +35 -11
  33. data/app/views/headmin/table/body/_row.html.erb +14 -6
  34. data/app/views/headmin/views/devise/confirmations/_new.html.erb +1 -1
  35. data/app/views/headmin/views/devise/passwords/_edit.html.erb +2 -2
  36. data/app/views/headmin/views/devise/passwords/_new.html.erb +1 -1
  37. data/app/views/headmin/views/devise/registrations/_edit.html.erb +4 -4
  38. data/app/views/headmin/views/devise/registrations/_new.html.erb +3 -3
  39. data/app/views/headmin/views/devise/shared/_links.html.erb +7 -7
  40. data/app/views/headmin/views/devise/unlocks/_new.html.erb +1 -1
  41. data/config/locales/activerecord/en.yml +9 -0
  42. data/config/locales/activerecord/nl.yml +9 -0
  43. data/config/locales/headmin/table/en.yml +5 -1
  44. data/config/locales/headmin/table/nl.yml +5 -1
  45. data/config/locales/headmin/views/en.yml +1 -1
  46. data/config/locales/headmin/views/nl.yml +14 -14
  47. data/dist/css/headmin.css +57 -13
  48. data/dist/js/headmin.js +81 -514
  49. data/docs/blocks.md +0 -7
  50. data/lib/generators/headmin/blocks_generator.rb +4 -1
  51. data/lib/generators/headmin/devise_generator.rb +6 -2
  52. data/lib/generators/headmin/fields_generator.rb +4 -1
  53. data/lib/generators/templates/controllers/auth/confirmations_controller.rb +31 -0
  54. data/lib/generators/templates/controllers/auth/omniauth_callbacks_controller.rb +31 -0
  55. data/lib/generators/templates/controllers/auth/passwords_controller.rb +35 -0
  56. data/lib/generators/templates/controllers/auth/registrations_controller.rb +63 -0
  57. data/lib/generators/templates/controllers/auth/sessions_controller.rb +28 -0
  58. data/lib/generators/templates/controllers/auth/unlocks_controller.rb +31 -0
  59. data/lib/headmin/version.rb +1 -1
  60. data/package.json +3 -2
  61. data/src/js/headmin/controllers/blocks_controller.js +1 -1
  62. data/src/js/headmin/controllers/date_range_controller.js +34 -0
  63. data/src/js/headmin/controllers/filter_controller.js +1 -1
  64. data/src/js/headmin/controllers/filters_controller.js +1 -1
  65. data/src/js/headmin/controllers/flatpickr_controller.js +38 -0
  66. data/src/js/headmin/controllers/popup_controller.js +1 -1
  67. data/src/js/headmin/controllers/repeater_controller.js +8 -9
  68. data/src/js/headmin/controllers/table_actions_controller.js +74 -9
  69. data/src/js/headmin/controllers/table_controller.js +49 -58
  70. data/src/js/headmin/headmin.js +38 -21
  71. data/src/scss/headmin/form.scss +4 -0
  72. data/src/scss/headmin/table.scss +1 -0
  73. data/yarn.lock +940 -1058
  74. metadata +20 -2
@@ -1,14 +1,17 @@
1
- import {Controller} from "stimulus"
1
+ import {Controller} from "@hotwired/stimulus"
2
2
  import Sortable from "sortablejs";
3
3
  import Rails from "@rails/ujs";
4
4
 
5
5
  export default class extends Controller {
6
6
  static get values() {
7
- return {url: String}
7
+ return {
8
+ url: String,
9
+ count: Number
10
+ }
8
11
  }
9
12
 
10
13
  static get targets() {
11
- return ["table", "body", "actions", "idCheckbox", "idsCheckbox"]
14
+ return ["table", "body", "actions", "idCheckbox", "idsCheckbox", "row"]
12
15
  }
13
16
 
14
17
  connect() {
@@ -38,82 +41,70 @@ export default class extends Controller {
38
41
  const checkbox = event.target
39
42
  this.toggleIdsCheckboxes(checkbox.checked)
40
43
  this.toggleIdCheckboxes(checkbox.checked)
41
- this.syncFields()
42
- this.toggleActions()
44
+ this.updateActions()
43
45
  }
44
46
 
45
47
  toggleId(event) {
46
48
  this.toggleIdsCheckboxes(false)
47
- this.syncFields()
48
- this.toggleActions()
49
+ this.updateActions()
50
+ }
51
+
52
+ updateActions() {
53
+ this.actionsTarget.dispatchEvent(
54
+ new CustomEvent(
55
+ 'idSelectionChanged',
56
+ {
57
+ detail: {
58
+ ids: this.ids(),
59
+ count: this.selectedIdsCount()
60
+ }
61
+ }
62
+ )
63
+ )
49
64
  }
50
65
 
51
- toggleActions() {
52
- const idFields = this.getIdFields()
53
- if(idFields.length > 0) {
54
- this.actionsTarget.classList.remove('d-none')
66
+ selectedIdsCount() {
67
+ if (this.ids() instanceof Array) {
68
+ return this.ids().length
55
69
  } else {
56
- this.actionsTarget.classList.add('d-none')
70
+ return this.totalCount()
57
71
  }
58
72
  }
59
73
 
60
- toggleIdsCheckboxes(checked) {
61
- this.idsCheckboxTargets.forEach((checkbox) => {
62
- checkbox.checked = checked
63
- });
64
- }
65
-
66
- toggleIdCheckboxes(checked) {
67
- this.idCheckboxTargets.forEach((checkbox) => {
68
- checkbox.checked = checked
69
- });
70
- }
71
-
72
- syncFields() {
73
- this.removeIds()
74
- if(this.idsCheckboxTarget.checked) {
75
- this.addId('')
74
+ totalCount() {
75
+ if(this.countValue === 0) {
76
+ return this.rowTargets.length
76
77
  } else {
77
- this.idCheckboxTargets.forEach((checkbox) => {
78
- if(checkbox.checked) {
79
- this.addId(checkbox.value)
80
- }
81
- });
78
+ return this.countValue
82
79
  }
83
80
  }
84
81
 
85
- addId(id) {
86
- let field = this.getIdField(id)
87
- if (!field) {
88
- field = this.newIdField(id)
89
- this.actionsTarget.querySelector('form').insertAdjacentHTML('afterbegin', field)
82
+ ids() {
83
+ if (this.idsCheckboxTarget.checked) {
84
+ return null
85
+ } else {
86
+ return this.selectedIdCheckboxes().map((checkbox) => {
87
+ return checkbox.value
88
+ })
90
89
  }
91
90
  }
92
91
 
93
- removeIds() {
94
- const fields = this.getIdFields()
95
- fields.forEach((field) => {
96
- this.actionsTarget.querySelector('form').removeChild(field)
97
- });
98
- }
99
-
100
- removeId(id) {
101
- const field = this.getIdField(id)
102
- if (field) {
103
- this.actionsTarget.querySelector('form').removeChild(field)
104
- }
92
+ selectedIdCheckboxes() {
93
+ return this.idCheckboxTargets.filter((checkbox) => {
94
+ return checkbox.checked
95
+ })
105
96
  }
106
97
 
107
- newIdField(id) {
108
- const template = this.actionsTarget.querySelector('[data-table-target="idFieldTemplate"]')
109
- return template.innerHTML.replace(/ID/g, id)
98
+ toggleIdsCheckboxes(checked) {
99
+ this.idsCheckboxTargets.forEach((checkbox) => {
100
+ checkbox.checked = checked
101
+ });
110
102
  }
111
103
 
112
- getIdFields() {
113
- return this.actionsTarget.querySelectorAll(`input[name="ids[]"]`);
104
+ toggleIdCheckboxes(checked) {
105
+ this.idCheckboxTargets.forEach((checkbox) => {
106
+ checkbox.checked = checked
107
+ });
114
108
  }
115
109
 
116
- getIdField(id) {
117
- return this.actionsTarget.querySelector(`input[name="ids[]"][value="${id}"]`);
118
- }
119
110
  }
@@ -1,17 +1,19 @@
1
1
  import 'ckeditor5-build-classic-simple-upload-adapter-image-resize';
2
2
  import TomSelect from "tom-select";
3
- import flatpickr from "flatpickr";
4
3
  import bootstrap from "bootstrap/dist/js/bootstrap.bundle";
5
4
  import Rails from "@rails/ujs";
6
5
 
7
- import {Application} from "stimulus";
8
- import {definitionsFromContext} from "stimulus/webpack-helpers";
6
+ import {Application} from "@hotwired/stimulus"
7
+ import {definitionsFromContext} from "@hotwired/stimulus-webpack-helpers"
9
8
 
10
9
  export class Headmin {
11
10
  static start() {
12
11
  // Init Rails UJS
13
12
  Rails.start()
14
13
 
14
+ // Set locale
15
+ this.setLocale()
16
+
15
17
  // Init Stimulus
16
18
  const application = Application.start()
17
19
  const context = require.context("./controllers", true, /\.js$/)
@@ -27,9 +29,14 @@ export class Headmin {
27
29
 
28
30
  }
29
31
 
32
+ static setLocale() {
33
+ const locale = document.querySelector('html').getAttribute('lang')
34
+ window.I18n = {}
35
+ I18n.locale = locale || 'en'
36
+ }
37
+
30
38
  static initPlugins() {
31
39
  this.initTomSelects()
32
- this.initFlatpickrs()
33
40
  this.initToasts()
34
41
  this.initPopovers()
35
42
  this.initCKEditors()
@@ -48,20 +55,6 @@ export class Headmin {
48
55
  })
49
56
  }
50
57
 
51
- static initFlatpickrs() {
52
- document.querySelectorAll('.flatpickr').forEach((element) => {
53
- this.initFlatpickr(element)
54
- })
55
- }
56
-
57
- static initFlatpickr(element) {
58
- flatpickr(element, {
59
- allowInput: true,
60
- altInput: true,
61
- altFormat: 'd/m/Y',
62
- });
63
- }
64
-
65
58
  static initCKEditors() {
66
59
  document.querySelectorAll('.ckeditor').forEach((element) => {
67
60
  this.initCKEditor(element)
@@ -119,10 +112,34 @@ export class Headmin {
119
112
  }
120
113
 
121
114
  static initTomSelects() {
115
+ const defaultOptions = {
116
+ en: {
117
+ render: {
118
+ option_create: function (data, escape) {
119
+ return '<div class="create">Add <strong>' + escape(data.input) + '</strong>&hellip;</div>';
120
+ },
121
+ no_results: function (data, escape) {
122
+ return '<div class="no-results">No results found</div>';
123
+ }
124
+ }
125
+ },
126
+ nl: {
127
+ render: {
128
+ option_create: function (data, escape) {
129
+ return '<div class="create">Voeg <strong>' + escape(data.input) + '</strong> toe &hellip;</div>';
130
+ },
131
+ no_results: function (data, escape) {
132
+ return '<div class="no-results">Geen resultaten gevonden</div>';
133
+ }
134
+ }
135
+ }
136
+ }
137
+
122
138
  document.querySelectorAll('select[multiple]').forEach((select) => {
123
- new TomSelect(select, {
124
- create: select.dataset['tags'] === "true"
125
- });
139
+ const withTags = select.dataset['tags'] === "true"
140
+ const options = {create: withTags}
141
+
142
+ new TomSelect(select, {...defaultOptions[I18n.locale], ...options});
126
143
  })
127
144
  }
128
145
 
@@ -5,6 +5,10 @@ input[type="search"] {
5
5
  padding-left: 35px
6
6
  }
7
7
 
8
+ .form-control[readonly] {
9
+ background-color: transparent;
10
+ }
11
+
8
12
  .form-label[required="required"]:after {
9
13
  content: '*';
10
14
  margin-left: 1px;
@@ -4,6 +4,7 @@
4
4
  color: $table-color;
5
5
  letter-spacing: 0.05em;
6
6
  font-size: $font-size-base * 0.85;
7
+ position: relative;
7
8
  }
8
9
 
9
10
  a {