b4um_generators 0.2.17 → 0.4.0
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/CHANGELOG.md +30 -0
- data/README.de.md +418 -4
- data/README.md +405 -5
- data/lib/b4um_generators/version.rb +1 -1
- data/lib/generators/b4um/admin/admin_generator.rb +614 -0
- data/lib/generators/b4um/admin/templates/add_admin_fields_migration.rb.tt +10 -0
- data/lib/generators/b4um/admin/templates/admin_base_controller.rb.tt +5 -0
- data/lib/generators/b4um/admin/templates/admin_dashboard.html.erb.tt +19 -0
- data/lib/generators/b4um/admin/templates/admin_dashboard_controller.rb.tt +6 -0
- data/lib/generators/b4um/admin/templates/admin_users_controller.rb.tt +70 -0
- data/lib/generators/b4um/admin/templates/admin_users_index.html.erb.tt +110 -0
- data/lib/generators/b4um/admin/templates/b4um_admin.rake.tt +106 -0
- data/lib/generators/b4um/authentication/authentication_generator.rb +90 -1
- data/lib/generators/b4um/guest/guest_generator.rb +673 -0
- data/lib/generators/b4um/guest/templates/add_guest_fields_migration.rb.tt +12 -0
- data/lib/generators/b4um/guest/templates/b4um_guests.rake.tt +12 -0
- data/lib/generators/b4um/guest/templates/edit.html.erb.tt +156 -0
- data/lib/generators/b4um/guest/templates/guest_expiration_warning.html.erb.tt +12 -0
- data/lib/generators/b4um/guest/templates/guests_controller.rb.tt +88 -0
- data/lib/generators/b4um/guest/templates/new.html.erb.tt +136 -0
- data/lib/generators/b4um/help/help_generator.rb +228 -0
- data/lib/generators/b4um/install/templates/b4um/sortable.css +158 -0
- data/lib/generators/b4um/install/templates/b4um.css +1 -0
- data/lib/generators/b4um/pagination/pagination_generator.rb +32 -5
- data/lib/generators/b4um/scaffold/scaffold_generator.rb +50 -0
- data/lib/generators/b4um/scaffold/templates/_form.html.erb.tt +18 -14
- data/lib/generators/b4um/search/search_generator.rb +22 -8
- data/lib/generators/b4um/sortable/sortable_generator.rb +529 -0
- data/lib/generators/b4um/sortable/templates/_sortable.html.erb.tt +40 -0
- data/lib/generators/b4um/sortable/templates/add_position_migration.rb.tt +26 -0
- data/lib/generators/b4um/sortable/templates/sort.html.erb.tt +3 -0
- data/lib/generators/b4um/sortable/templates/sortable_controller.js +166 -0
- metadata +22 -1
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
import { Controller } from '@hotwired/stimulus'
|
|
2
|
+
|
|
3
|
+
export default class extends Controller {
|
|
4
|
+
static values = {
|
|
5
|
+
updateUrl: String
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
connect() {
|
|
9
|
+
this.draggedItem = null
|
|
10
|
+
this.draggedFromPosition = null
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
dragStart(event) {
|
|
14
|
+
const item = event.currentTarget.closest('[data-sortable-id]')
|
|
15
|
+
|
|
16
|
+
if (!item) return
|
|
17
|
+
|
|
18
|
+
this.draggedItem = item
|
|
19
|
+
this.draggedFromPosition = this.positionFor(item)
|
|
20
|
+
|
|
21
|
+
event.dataTransfer.effectAllowed = 'move'
|
|
22
|
+
event.dataTransfer.setData('text/plain', item.dataset.sortableId)
|
|
23
|
+
|
|
24
|
+
item.classList.add('b4um-sortable__item--dragging')
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
dragEnd() {
|
|
28
|
+
if (this.draggedItem) {
|
|
29
|
+
this.draggedItem.classList.remove('b4um-sortable__item--dragging')
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
this.draggedItem = null
|
|
33
|
+
this.draggedFromPosition = null
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
dragOver(event) {
|
|
37
|
+
event.preventDefault()
|
|
38
|
+
|
|
39
|
+
if (!this.draggedItem) return
|
|
40
|
+
|
|
41
|
+
const target = event.currentTarget
|
|
42
|
+
|
|
43
|
+
if (target === this.draggedItem) return
|
|
44
|
+
|
|
45
|
+
const bounds = target.getBoundingClientRect()
|
|
46
|
+
const insertAfter = event.clientY > bounds.top + bounds.height / 2
|
|
47
|
+
|
|
48
|
+
if (insertAfter) {
|
|
49
|
+
target.after(this.draggedItem)
|
|
50
|
+
} else {
|
|
51
|
+
target.before(this.draggedItem)
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
drop(event) {
|
|
56
|
+
event.preventDefault()
|
|
57
|
+
|
|
58
|
+
if (!this.draggedItem) return
|
|
59
|
+
|
|
60
|
+
const item = this.draggedItem
|
|
61
|
+
const position = this.positionAfterDrop(item)
|
|
62
|
+
|
|
63
|
+
if (!position) {
|
|
64
|
+
window.location.reload()
|
|
65
|
+
return
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
this.persist(item.dataset.sortableId, position)
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
positionKeydown(event) {
|
|
72
|
+
if (event.key !== 'Enter') return
|
|
73
|
+
|
|
74
|
+
event.preventDefault()
|
|
75
|
+
event.currentTarget.blur()
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
positionChanged(event) {
|
|
79
|
+
const input = event.currentTarget
|
|
80
|
+
const item = input.closest('[data-sortable-id]')
|
|
81
|
+
|
|
82
|
+
if (!item) return
|
|
83
|
+
|
|
84
|
+
const position = Number.parseInt(input.value, 10)
|
|
85
|
+
|
|
86
|
+
if (Number.isNaN(position) || position < 1) {
|
|
87
|
+
window.location.reload()
|
|
88
|
+
return
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
this.persist(item.dataset.sortableId, position)
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
positionFor(item) {
|
|
95
|
+
const input = item.querySelector('.b4um-sortable__position')
|
|
96
|
+
|
|
97
|
+
if (!input) return null
|
|
98
|
+
|
|
99
|
+
const position = Number.parseInt(input.value, 10)
|
|
100
|
+
|
|
101
|
+
return Number.isNaN(position) ? null : position
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
positionAfterDrop(item) {
|
|
105
|
+
const previousItem = item.previousElementSibling
|
|
106
|
+
const nextItem = item.nextElementSibling
|
|
107
|
+
|
|
108
|
+
if (previousItem?.matches('[data-sortable-id]')) {
|
|
109
|
+
const previousPosition = this.positionFor(previousItem)
|
|
110
|
+
|
|
111
|
+
if (previousPosition) {
|
|
112
|
+
if (this.draggedFromPosition && this.draggedFromPosition < previousPosition) {
|
|
113
|
+
return previousPosition
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
return previousPosition + 1
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
if (nextItem?.matches('[data-sortable-id]')) {
|
|
121
|
+
const nextPosition = this.positionFor(nextItem)
|
|
122
|
+
|
|
123
|
+
if (nextPosition) {
|
|
124
|
+
if (this.draggedFromPosition && this.draggedFromPosition > nextPosition) {
|
|
125
|
+
return nextPosition
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
return Math.max(1, nextPosition - 1)
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
return this.draggedFromPosition
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
async persist(id, position) {
|
|
136
|
+
if (!this.hasUpdateUrlValue || !this.updateUrlValue) return
|
|
137
|
+
|
|
138
|
+
try {
|
|
139
|
+
const response = await fetch(this.updateUrlValue, {
|
|
140
|
+
method: 'PATCH',
|
|
141
|
+
headers: {
|
|
142
|
+
'Content-Type': 'application/json',
|
|
143
|
+
Accept: 'application/json',
|
|
144
|
+
'X-CSRF-Token': this.csrfToken()
|
|
145
|
+
},
|
|
146
|
+
body: JSON.stringify({
|
|
147
|
+
id,
|
|
148
|
+
position
|
|
149
|
+
})
|
|
150
|
+
})
|
|
151
|
+
|
|
152
|
+
if (!response.ok) {
|
|
153
|
+
throw new Error(`Sortable update failed: ${response.status}`)
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
window.location.reload()
|
|
157
|
+
} catch (error) {
|
|
158
|
+
console.error(error)
|
|
159
|
+
window.location.reload()
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
csrfToken() {
|
|
164
|
+
return document.querySelector('meta[name="csrf-token"]')?.content || ''
|
|
165
|
+
}
|
|
166
|
+
}
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: b4um_generators
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.4.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Alexander Baum
|
|
@@ -49,6 +49,14 @@ files:
|
|
|
49
49
|
- bin/setup
|
|
50
50
|
- lib/b4um_generators.rb
|
|
51
51
|
- lib/b4um_generators/version.rb
|
|
52
|
+
- lib/generators/b4um/admin/admin_generator.rb
|
|
53
|
+
- lib/generators/b4um/admin/templates/add_admin_fields_migration.rb.tt
|
|
54
|
+
- lib/generators/b4um/admin/templates/admin_base_controller.rb.tt
|
|
55
|
+
- lib/generators/b4um/admin/templates/admin_dashboard.html.erb.tt
|
|
56
|
+
- lib/generators/b4um/admin/templates/admin_dashboard_controller.rb.tt
|
|
57
|
+
- lib/generators/b4um/admin/templates/admin_users_controller.rb.tt
|
|
58
|
+
- lib/generators/b4um/admin/templates/admin_users_index.html.erb.tt
|
|
59
|
+
- lib/generators/b4um/admin/templates/b4um_admin.rake.tt
|
|
52
60
|
- lib/generators/b4um/attachment/attachment_generator.rb
|
|
53
61
|
- lib/generators/b4um/authentication/authentication_generator.rb
|
|
54
62
|
- lib/generators/b4um/authentication/templates/new.html.erb.tt
|
|
@@ -64,6 +72,13 @@ files:
|
|
|
64
72
|
- lib/generators/b4um/comments/templates/comments_controller.rb.tt
|
|
65
73
|
- lib/generators/b4um/comments/templates/create_comments.rb.tt
|
|
66
74
|
- lib/generators/b4um/controller/controller_generator.rb
|
|
75
|
+
- lib/generators/b4um/guest/guest_generator.rb
|
|
76
|
+
- lib/generators/b4um/guest/templates/add_guest_fields_migration.rb.tt
|
|
77
|
+
- lib/generators/b4um/guest/templates/b4um_guests.rake.tt
|
|
78
|
+
- lib/generators/b4um/guest/templates/edit.html.erb.tt
|
|
79
|
+
- lib/generators/b4um/guest/templates/guest_expiration_warning.html.erb.tt
|
|
80
|
+
- lib/generators/b4um/guest/templates/guests_controller.rb.tt
|
|
81
|
+
- lib/generators/b4um/guest/templates/new.html.erb.tt
|
|
67
82
|
- lib/generators/b4um/help/help_generator.rb
|
|
68
83
|
- lib/generators/b4um/in_place/in_place_generator.rb
|
|
69
84
|
- lib/generators/b4um/in_place/templates/_flash.html.erb
|
|
@@ -115,6 +130,7 @@ files:
|
|
|
115
130
|
- lib/generators/b4um/install/templates/b4um/pagination.css
|
|
116
131
|
- lib/generators/b4um/install/templates/b4um/resources.css
|
|
117
132
|
- lib/generators/b4um/install/templates/b4um/search.css
|
|
133
|
+
- lib/generators/b4um/install/templates/b4um/sortable.css
|
|
118
134
|
- lib/generators/b4um/install/templates/b4um/tables.css
|
|
119
135
|
- lib/generators/b4um/install/templates/b4um/theme-switcher.css
|
|
120
136
|
- lib/generators/b4um/install/templates/b4um/theme.css
|
|
@@ -145,6 +161,11 @@ files:
|
|
|
145
161
|
- lib/generators/b4um/search/search_generator.rb
|
|
146
162
|
- lib/generators/b4um/search/templates/search.rb
|
|
147
163
|
- lib/generators/b4um/search/templates/search_form.html.erb.tt
|
|
164
|
+
- lib/generators/b4um/sortable/sortable_generator.rb
|
|
165
|
+
- lib/generators/b4um/sortable/templates/_sortable.html.erb.tt
|
|
166
|
+
- lib/generators/b4um/sortable/templates/add_position_migration.rb.tt
|
|
167
|
+
- lib/generators/b4um/sortable/templates/sort.html.erb.tt
|
|
168
|
+
- lib/generators/b4um/sortable/templates/sortable_controller.js
|
|
148
169
|
- lib/generators/b4um/table/table_generator.rb
|
|
149
170
|
- lib/generators/b4um/table/templates/_table.html.erb.tt
|
|
150
171
|
- lib/generators/b4um/trix/templates/b4um_rich_text_helper.rb
|