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.
- checksums.yaml +4 -4
- data/Gemfile.lock +2 -2
- data/app/helpers/headmin/admin_helper.rb +3 -59
- data/app/helpers/headmin/bootstrap_helper.rb +9 -0
- data/app/helpers/headmin/filter_helper.rb +7 -3
- data/app/helpers/headmin/form_helper.rb +36 -0
- data/app/helpers/headmin/request_helper.rb +39 -0
- data/app/models/concerns/headmin/fieldable.rb +3 -1
- data/app/services/block_service.rb +8 -4
- data/app/views/examples/admin.html.erb +1 -1
- data/app/views/headmin/_blocks.html.erb +1 -1
- data/app/views/headmin/_card.html.erb +3 -1
- data/app/views/headmin/_filters.html.erb +3 -3
- data/app/views/headmin/_pagination.html.erb +2 -1
- data/app/views/headmin/_table.html.erb +9 -3
- data/app/views/headmin/dropdown/_devise.html.erb +20 -10
- data/app/views/headmin/dropdown/_list.html.erb +17 -7
- data/app/views/headmin/filters/_date.html.erb +5 -3
- data/app/views/headmin/filters/_flatpickr.html.erb +57 -0
- data/app/views/headmin/forms/_base.html.erb +12 -11
- data/app/views/headmin/forms/_blocks.html.erb +11 -4
- data/app/views/headmin/forms/_date.html.erb +24 -12
- data/app/views/headmin/forms/_date_range.html.erb +84 -0
- data/app/views/headmin/forms/_flatpickr.html.erb +55 -0
- data/app/views/headmin/forms/_flatpickr_range.html.erb +61 -0
- data/app/views/headmin/forms/_hidden.html.erb +23 -0
- data/app/views/headmin/forms/_label.html.erb +4 -2
- data/app/views/headmin/forms/_repeater.html.erb +5 -8
- data/app/views/headmin/forms/_select.html.erb +14 -11
- data/app/views/headmin/forms/_text.html.erb +7 -9
- data/app/views/headmin/layout/_main.html.erb +11 -5
- data/app/views/headmin/table/_actions.html.erb +35 -11
- data/app/views/headmin/table/body/_row.html.erb +14 -6
- data/app/views/headmin/views/devise/confirmations/_new.html.erb +1 -1
- data/app/views/headmin/views/devise/passwords/_edit.html.erb +2 -2
- data/app/views/headmin/views/devise/passwords/_new.html.erb +1 -1
- data/app/views/headmin/views/devise/registrations/_edit.html.erb +4 -4
- data/app/views/headmin/views/devise/registrations/_new.html.erb +3 -3
- data/app/views/headmin/views/devise/shared/_links.html.erb +7 -7
- data/app/views/headmin/views/devise/unlocks/_new.html.erb +1 -1
- data/config/locales/activerecord/en.yml +9 -0
- data/config/locales/activerecord/nl.yml +9 -0
- data/config/locales/headmin/table/en.yml +5 -1
- data/config/locales/headmin/table/nl.yml +5 -1
- data/config/locales/headmin/views/en.yml +1 -1
- data/config/locales/headmin/views/nl.yml +14 -14
- data/dist/css/headmin.css +57 -13
- data/dist/js/headmin.js +81 -514
- data/docs/blocks.md +0 -7
- data/lib/generators/headmin/blocks_generator.rb +4 -1
- data/lib/generators/headmin/devise_generator.rb +6 -2
- data/lib/generators/headmin/fields_generator.rb +4 -1
- data/lib/generators/templates/controllers/auth/confirmations_controller.rb +31 -0
- data/lib/generators/templates/controllers/auth/omniauth_callbacks_controller.rb +31 -0
- data/lib/generators/templates/controllers/auth/passwords_controller.rb +35 -0
- data/lib/generators/templates/controllers/auth/registrations_controller.rb +63 -0
- data/lib/generators/templates/controllers/auth/sessions_controller.rb +28 -0
- data/lib/generators/templates/controllers/auth/unlocks_controller.rb +31 -0
- data/lib/headmin/version.rb +1 -1
- data/package.json +3 -2
- data/src/js/headmin/controllers/blocks_controller.js +1 -1
- data/src/js/headmin/controllers/date_range_controller.js +34 -0
- data/src/js/headmin/controllers/filter_controller.js +1 -1
- data/src/js/headmin/controllers/filters_controller.js +1 -1
- data/src/js/headmin/controllers/flatpickr_controller.js +38 -0
- data/src/js/headmin/controllers/popup_controller.js +1 -1
- data/src/js/headmin/controllers/repeater_controller.js +8 -9
- data/src/js/headmin/controllers/table_actions_controller.js +74 -9
- data/src/js/headmin/controllers/table_controller.js +49 -58
- data/src/js/headmin/headmin.js +38 -21
- data/src/scss/headmin/form.scss +4 -0
- data/src/scss/headmin/table.scss +1 -0
- data/yarn.lock +940 -1058
- 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 {
|
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.
|
42
|
-
this.toggleActions()
|
44
|
+
this.updateActions()
|
43
45
|
}
|
44
46
|
|
45
47
|
toggleId(event) {
|
46
48
|
this.toggleIdsCheckboxes(false)
|
47
|
-
this.
|
48
|
-
|
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
|
-
|
52
|
-
|
53
|
-
|
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.
|
70
|
+
return this.totalCount()
|
57
71
|
}
|
58
72
|
}
|
59
73
|
|
60
|
-
|
61
|
-
this.
|
62
|
-
|
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.
|
78
|
-
if(checkbox.checked) {
|
79
|
-
this.addId(checkbox.value)
|
80
|
-
}
|
81
|
-
});
|
78
|
+
return this.countValue
|
82
79
|
}
|
83
80
|
}
|
84
81
|
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
this.
|
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
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
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
|
-
|
108
|
-
|
109
|
-
|
98
|
+
toggleIdsCheckboxes(checked) {
|
99
|
+
this.idsCheckboxTargets.forEach((checkbox) => {
|
100
|
+
checkbox.checked = checked
|
101
|
+
});
|
110
102
|
}
|
111
103
|
|
112
|
-
|
113
|
-
|
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
|
}
|
data/src/js/headmin/headmin.js
CHANGED
@@ -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
|
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>…</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 …</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
|
-
|
124
|
-
|
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
|
|
data/src/scss/headmin/form.scss
CHANGED