inertia_rails-contrib 0.2.2 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +12 -1
- data/README.md +3 -2
- data/lib/generators/inertia/install/frameworks.yml +28 -3
- data/lib/generators/inertia/install/install_generator.rb +6 -2
- data/lib/generators/inertia/install/templates/react/inertia.ts +4 -4
- data/lib/generators/inertia/install/templates/svelte/InertiaExample.svelte +3 -7
- data/lib/generators/inertia/install/templates/svelte/InertiaExample.ts.svelte +3 -7
- data/lib/generators/inertia/install/templates/svelte/inertia.js +3 -2
- data/lib/generators/inertia/install/templates/svelte/inertia.ts +7 -9
- data/lib/generators/inertia/install/templates/svelte4/InertiaExample.svelte +116 -0
- data/lib/generators/inertia/install/templates/svelte4/InertiaExample.ts.svelte +116 -0
- data/lib/generators/inertia/install/templates/svelte4/inertia.js +29 -0
- data/lib/generators/inertia/install/templates/svelte4/inertia.ts +29 -0
- data/lib/generators/inertia/install/templates/svelte4/svelte.config.js +7 -0
- data/lib/generators/inertia/install/templates/svelte4/tsconfig.json +21 -0
- data/lib/generators/inertia/install/templates/svelte4/tsconfig.node.json +12 -0
- data/lib/generators/inertia/install/templates/svelte4/vite-env.d.ts +2 -0
- data/lib/generators/inertia/install/templates/vue/inertia.ts +3 -3
- data/lib/generators/inertia_templates/controller/templates/svelte4/view.svelte.tt +2 -0
- data/lib/generators/inertia_templates/scaffold/templates/react/Form.jsx.tt +2 -2
- data/lib/generators/inertia_templates/scaffold/templates/svelte/Edit.svelte.tt +3 -4
- data/lib/generators/inertia_templates/scaffold/templates/svelte/Form.svelte.tt +12 -10
- data/lib/generators/inertia_templates/scaffold/templates/svelte/Index.svelte.tt +1 -8
- data/lib/generators/inertia_templates/scaffold/templates/svelte/New.svelte.tt +3 -4
- data/lib/generators/inertia_templates/scaffold/templates/svelte/One.svelte.tt +1 -1
- data/lib/generators/inertia_templates/scaffold/templates/svelte/Show.svelte.tt +4 -9
- data/lib/generators/inertia_templates/scaffold/templates/svelte4/Edit.svelte.tt +37 -0
- data/lib/generators/inertia_templates/scaffold/templates/svelte4/Form.svelte.tt +96 -0
- data/lib/generators/inertia_templates/scaffold/templates/svelte4/Index.svelte.tt +36 -0
- data/lib/generators/inertia_templates/scaffold/templates/svelte4/New.svelte.tt +30 -0
- data/lib/generators/inertia_templates/scaffold/templates/svelte4/One.svelte.tt +28 -0
- data/lib/generators/inertia_templates/scaffold/templates/svelte4/Show.svelte.tt +46 -0
- data/lib/generators/inertia_templates/scaffold/templates/vue/Form.vue.tt +1 -1
- data/lib/generators/inertia_tw_templates/controller/templates/svelte4/view.svelte.tt +2 -0
- data/lib/generators/inertia_tw_templates/scaffold/templates/react/Form.jsx.tt +2 -2
- data/lib/generators/inertia_tw_templates/scaffold/templates/svelte/Edit.svelte.tt +3 -4
- data/lib/generators/inertia_tw_templates/scaffold/templates/svelte/Form.svelte.tt +12 -13
- data/lib/generators/inertia_tw_templates/scaffold/templates/svelte/Index.svelte.tt +1 -8
- data/lib/generators/inertia_tw_templates/scaffold/templates/svelte/New.svelte.tt +3 -4
- data/lib/generators/inertia_tw_templates/scaffold/templates/svelte/One.svelte.tt +1 -1
- data/lib/generators/inertia_tw_templates/scaffold/templates/svelte/Show.svelte.tt +7 -8
- data/lib/generators/inertia_tw_templates/scaffold/templates/svelte4/Edit.svelte.tt +45 -0
- data/lib/generators/inertia_tw_templates/scaffold/templates/svelte4/Form.svelte.tt +120 -0
- data/lib/generators/inertia_tw_templates/scaffold/templates/svelte4/Index.svelte.tt +43 -0
- data/lib/generators/inertia_tw_templates/scaffold/templates/svelte4/New.svelte.tt +33 -0
- data/lib/generators/inertia_tw_templates/scaffold/templates/svelte4/One.svelte.tt +28 -0
- data/lib/generators/inertia_tw_templates/scaffold/templates/svelte4/Show.svelte.tt +58 -0
- data/lib/generators/inertia_tw_templates/scaffold/templates/vue/Form.vue.tt +2 -2
- data/lib/inertia_rails_contrib/generators_helper.rb +4 -3
- data/lib/inertia_rails_contrib/version.rb +1 -1
- metadata +24 -2
@@ -2,10 +2,7 @@
|
|
2
2
|
import { useForm } from '@inertiajs/svelte'
|
3
3
|
import { createEventDispatcher } from 'svelte'
|
4
4
|
|
5
|
-
|
6
|
-
|
7
|
-
export let <%= singular_table_name %>
|
8
|
-
export let submitText
|
5
|
+
let { <%= singular_table_name %>, submitText, onSubmit } = $props()
|
9
6
|
|
10
7
|
const form = useForm({
|
11
8
|
<% attributes.each do |attribute| -%>
|
@@ -17,9 +14,14 @@
|
|
17
14
|
<% end -%>
|
18
15
|
<% end -%>
|
19
16
|
})
|
17
|
+
|
18
|
+
const handleSubmit = (e) => {
|
19
|
+
e.preventDefault()
|
20
|
+
onSubmit({form: $form })
|
21
|
+
}
|
20
22
|
</script>
|
21
23
|
|
22
|
-
<form
|
24
|
+
<form onsubmit={handleSubmit}>
|
23
25
|
<% attributes.each do |attribute| -%>
|
24
26
|
<% if attribute.password_digest? -%>
|
25
27
|
<div>
|
@@ -51,28 +53,28 @@
|
|
51
53
|
<div>
|
52
54
|
<label for="<%= attribute.singular_name %>"><%= attribute.human_name %></label>
|
53
55
|
<% if input_type(attribute) == "text_area" -%>
|
54
|
-
<textarea name="<%= attribute.singular_name %>" id="<%= attribute.singular_name %>" bind:value={$form.<%= attribute.column_name %>}
|
56
|
+
<textarea name="<%= attribute.singular_name %>" id="<%= attribute.singular_name %>" bind:value={$form.<%= attribute.column_name %>}></textarea>
|
55
57
|
<% elsif attribute.attachment? -%>
|
56
58
|
<input
|
57
59
|
type="file"
|
58
60
|
name="<%= attribute.singular_name %>"
|
59
61
|
id="<%= attribute.singular_name %>"
|
60
|
-
|
62
|
+
oninput={(e) => ($form.<%= attribute.column_name %> = e.target.files[0])}
|
61
63
|
/>
|
62
64
|
<% elsif attribute.attachments? -%>
|
63
65
|
<input
|
64
66
|
type="file"
|
65
|
-
multiple
|
67
|
+
multiple
|
66
68
|
name="<%= attribute.singular_name %>[]"
|
67
69
|
id="<%= attribute.singular_name %>"
|
68
|
-
|
70
|
+
oninput={(e) => ($form.<%= attribute.column_name %> = Array.from(e.target.files))}
|
69
71
|
/>
|
70
72
|
<% else -%>
|
71
73
|
<input
|
72
74
|
type="<%= input_type(attribute) %>"
|
73
75
|
name="<%= attribute.singular_name %>"
|
74
76
|
id="<%= attribute.singular_name %>"
|
75
|
-
bind:value
|
77
|
+
<%= input_type(attribute) == "checkbox" ? "bind:checked" : "bind:value" %>={$form.<%= attribute.column_name %>}
|
76
78
|
/>
|
77
79
|
<% end -%>
|
78
80
|
{#if $form.errors.<%= attribute.column_name %>}
|
@@ -2,14 +2,7 @@
|
|
2
2
|
import { Link } from '@inertiajs/svelte'
|
3
3
|
import <%= inertia_component_name %> from './<%= inertia_component_name %>.svelte'
|
4
4
|
|
5
|
-
|
6
|
-
export let flash
|
7
|
-
|
8
|
-
const onDestroy = (e) => {
|
9
|
-
if (!confirm('Are you sure you want to delete this <%= human_name.downcase %>?')) {
|
10
|
-
e.preventDefault()
|
11
|
-
}
|
12
|
-
}
|
5
|
+
let { <%= plural_table_name %>, flash } = $props()
|
13
6
|
</script>
|
14
7
|
|
15
8
|
<svelte:head>
|
@@ -2,10 +2,9 @@
|
|
2
2
|
import { Link } from '@inertiajs/svelte'
|
3
3
|
import Form from './Form.svelte'
|
4
4
|
|
5
|
-
|
5
|
+
let { <%= singular_table_name %> } = $props()
|
6
6
|
|
7
|
-
const handleSubmit = (
|
8
|
-
const { form } = e.detail
|
7
|
+
const handleSubmit = ({ form }) => {
|
9
8
|
form.transform((data) => ({ <%= singular_table_name %>: data }))
|
10
9
|
form.post('<%= js_resources_path %>')
|
11
10
|
}
|
@@ -20,7 +19,7 @@
|
|
20
19
|
<Form
|
21
20
|
{<%= singular_table_name %>}
|
22
21
|
submitText="Create <%= human_name.downcase %>"
|
23
|
-
|
22
|
+
onSubmit={handleSubmit}
|
24
23
|
/>
|
25
24
|
|
26
25
|
<br />
|
@@ -1,9 +1,8 @@
|
|
1
1
|
<script>
|
2
|
-
import {
|
2
|
+
import { Link } from '@inertiajs/svelte'
|
3
3
|
import <%= inertia_component_name %> from './<%= inertia_component_name %>.svelte'
|
4
4
|
|
5
|
-
|
6
|
-
export let flash
|
5
|
+
let { <%= singular_table_name %>, flash } = $props()
|
7
6
|
|
8
7
|
const onDestroy = (e) => {
|
9
8
|
if (!confirm('Are you sure you want to delete this <%= human_name.downcase %>?')) {
|
@@ -30,13 +29,9 @@
|
|
30
29
|
|
31
30
|
<br />
|
32
31
|
|
33
|
-
<
|
34
|
-
use:inertia={{ href: `<%= js_resource_path %>`, method: 'delete' }}
|
35
|
-
on:click={onDestroy}
|
36
|
-
type="button"
|
37
|
-
>
|
32
|
+
<Link href={`<%= js_resource_path %>`} method="delete" onclick={onDestroy}>
|
38
33
|
Destroy this <%= human_name.downcase %>
|
39
|
-
</
|
34
|
+
</Link>
|
40
35
|
</div>
|
41
36
|
|
42
37
|
<style>
|
@@ -0,0 +1,37 @@
|
|
1
|
+
<script>
|
2
|
+
import { Link } from '@inertiajs/svelte'
|
3
|
+
import Form from './Form.svelte'
|
4
|
+
|
5
|
+
export let <%= singular_table_name %>
|
6
|
+
|
7
|
+
const handleSubmit = (e) => {
|
8
|
+
const { form } = e.detail
|
9
|
+
form.transform((data) => ({ <%= singular_table_name %>: data }))
|
10
|
+
<% if attributes.any?(&:attachments?) -%>
|
11
|
+
form.post(`<%= js_resource_path %>`, {
|
12
|
+
headers: { 'X-HTTP-METHOD-OVERRIDE': 'put' },
|
13
|
+
})
|
14
|
+
<% else -%>
|
15
|
+
form.patch(`<%= js_resource_path %>`)
|
16
|
+
<% end -%>
|
17
|
+
}
|
18
|
+
</script>
|
19
|
+
|
20
|
+
<svelte:head>
|
21
|
+
<title>Editing <%= human_name.downcase %></title>
|
22
|
+
</svelte:head>
|
23
|
+
|
24
|
+
<h1>Editing <%= human_name.downcase %></h1>
|
25
|
+
|
26
|
+
<Form
|
27
|
+
{<%= singular_table_name %>}
|
28
|
+
submitText="Update <%= human_name.downcase %>"
|
29
|
+
on:submit={handleSubmit}
|
30
|
+
/>
|
31
|
+
|
32
|
+
<br />
|
33
|
+
|
34
|
+
<div>
|
35
|
+
<Link href={`<%= js_resource_path %>`}>Show this <%= human_name.downcase %></Link> |
|
36
|
+
<Link href="<%= js_resources_path %>">Back to <%= human_name.pluralize.downcase %></Link>
|
37
|
+
</div>
|
@@ -0,0 +1,96 @@
|
|
1
|
+
<script>
|
2
|
+
import { useForm } from '@inertiajs/svelte'
|
3
|
+
import { createEventDispatcher } from 'svelte'
|
4
|
+
|
5
|
+
const dispatch = createEventDispatcher()
|
6
|
+
|
7
|
+
export let <%= singular_table_name %>
|
8
|
+
export let submitText
|
9
|
+
|
10
|
+
const form = useForm({
|
11
|
+
<% attributes.each do |attribute| -%>
|
12
|
+
<% if attribute.password_digest? -%>
|
13
|
+
password: '',
|
14
|
+
password_confirmation: '',
|
15
|
+
<% else -%>
|
16
|
+
<%= attribute.column_name %>: <%= singular_table_name %>.<%= attribute.column_name %> || <%= default_value(attribute) %>,
|
17
|
+
<% end -%>
|
18
|
+
<% end -%>
|
19
|
+
})
|
20
|
+
</script>
|
21
|
+
|
22
|
+
<form on:submit|preventDefault={dispatch('submit', { form: $form })}>
|
23
|
+
<% attributes.each do |attribute| -%>
|
24
|
+
<% if attribute.password_digest? -%>
|
25
|
+
<div>
|
26
|
+
<label for="password">Password</label>
|
27
|
+
<input
|
28
|
+
type="password"
|
29
|
+
name="password"
|
30
|
+
id="password"
|
31
|
+
bind:value={$form.password}
|
32
|
+
/>
|
33
|
+
{#if $form.errors.password}
|
34
|
+
<div class="error">{$form.errors.password.join(', ')}</div>
|
35
|
+
{/if}
|
36
|
+
</div>
|
37
|
+
|
38
|
+
<div>
|
39
|
+
<label for="password_confirmation">Password Confirmation</label>
|
40
|
+
<input
|
41
|
+
type="password"
|
42
|
+
name="password_confirmation"
|
43
|
+
id="password_confirmation"
|
44
|
+
bind:value={$form.password_confirmation}
|
45
|
+
/>
|
46
|
+
{#if $form.errors.password_confirmation}
|
47
|
+
<div class="error">{$form.errors.password_confirmation.join(', ')}</div>
|
48
|
+
{/if}
|
49
|
+
</div>
|
50
|
+
<% else -%>
|
51
|
+
<div>
|
52
|
+
<label for="<%= attribute.singular_name %>"><%= attribute.human_name %></label>
|
53
|
+
<% if input_type(attribute) == "text_area" -%>
|
54
|
+
<textarea name="<%= attribute.singular_name %>" id="<%= attribute.singular_name %>" bind:value={$form.<%= attribute.column_name %>}></textarea>
|
55
|
+
<% elsif attribute.attachment? -%>
|
56
|
+
<input
|
57
|
+
type="file"
|
58
|
+
name="<%= attribute.singular_name %>"
|
59
|
+
id="<%= attribute.singular_name %>"
|
60
|
+
oninput={(e) => ($form.<%= attribute.column_name %> = e.target.files[0])}
|
61
|
+
/>
|
62
|
+
<% elsif attribute.attachments? -%>
|
63
|
+
<input
|
64
|
+
type="file"
|
65
|
+
multiple
|
66
|
+
name="<%= attribute.singular_name %>[]"
|
67
|
+
id="<%= attribute.singular_name %>"
|
68
|
+
oninput={(e) => ($form.<%= attribute.column_name %> = Array.from(e.target.files))}
|
69
|
+
/>
|
70
|
+
<% else -%>
|
71
|
+
<input
|
72
|
+
type="<%= input_type(attribute) %>"
|
73
|
+
name="<%= attribute.singular_name %>"
|
74
|
+
id="<%= attribute.singular_name %>"
|
75
|
+
<%= input_type(attribute) == "checkbox" ? "bind:checked" : "bind:value" %>={$form.<%= attribute.column_name %>}
|
76
|
+
/>
|
77
|
+
<% end -%>
|
78
|
+
{#if $form.errors.<%= attribute.column_name %>}
|
79
|
+
<div class="error">{$form.errors.<%= attribute.column_name %>.join(', ')}</div>
|
80
|
+
{/if}
|
81
|
+
</div>
|
82
|
+
<% end -%>
|
83
|
+
<% end -%>
|
84
|
+
<div>
|
85
|
+
<button type="submit" disabled={$form.processing}>{submitText}</button>
|
86
|
+
</div>
|
87
|
+
</form>
|
88
|
+
|
89
|
+
<style>
|
90
|
+
label {
|
91
|
+
display: block;
|
92
|
+
}
|
93
|
+
.error {
|
94
|
+
color: red;
|
95
|
+
}
|
96
|
+
</style>
|
@@ -0,0 +1,36 @@
|
|
1
|
+
<script>
|
2
|
+
import { Link } from '@inertiajs/svelte'
|
3
|
+
import <%= inertia_component_name %> from './<%= inertia_component_name %>.svelte'
|
4
|
+
|
5
|
+
export let <%= plural_table_name %>
|
6
|
+
export let flash
|
7
|
+
</script>
|
8
|
+
|
9
|
+
<svelte:head>
|
10
|
+
<title><%= human_name.pluralize %></title>
|
11
|
+
</svelte:head>
|
12
|
+
|
13
|
+
{#if flash.notice}
|
14
|
+
<p class="notice">{flash.notice}</p>
|
15
|
+
{/if}
|
16
|
+
|
17
|
+
<h1><%= human_name.pluralize %></h1>
|
18
|
+
|
19
|
+
<div>
|
20
|
+
{#each <%= plural_table_name %> as <%= singular_table_name %> (<%= singular_table_name %>.id)}
|
21
|
+
<div>
|
22
|
+
<<%= inertia_component_name %> {<%= singular_table_name %>} />
|
23
|
+
<p>
|
24
|
+
<Link href={`<%= js_resource_path %>`}>Show this <%= human_name.downcase %></Link>
|
25
|
+
</p>
|
26
|
+
</div>
|
27
|
+
{/each}
|
28
|
+
</div>
|
29
|
+
|
30
|
+
<Link href="<%= js_new_resource_path %>">New <%= human_name.downcase %></Link>
|
31
|
+
|
32
|
+
<style>
|
33
|
+
.notice {
|
34
|
+
color: green;
|
35
|
+
}
|
36
|
+
</style>
|
@@ -0,0 +1,30 @@
|
|
1
|
+
<script>
|
2
|
+
import { Link } from '@inertiajs/svelte'
|
3
|
+
import Form from './Form.svelte'
|
4
|
+
|
5
|
+
export let <%= singular_table_name %>
|
6
|
+
|
7
|
+
const handleSubmit = (e) => {
|
8
|
+
const { form } = e.detail
|
9
|
+
form.transform((data) => ({ <%= singular_table_name %>: data }))
|
10
|
+
form.post('<%= js_resources_path %>')
|
11
|
+
}
|
12
|
+
</script>
|
13
|
+
|
14
|
+
<svelte:head>
|
15
|
+
<title>New <%= human_name.downcase %></title>
|
16
|
+
</svelte:head>
|
17
|
+
|
18
|
+
<h1>New <%= human_name.downcase %></h1>
|
19
|
+
|
20
|
+
<Form
|
21
|
+
{<%= singular_table_name %>}
|
22
|
+
submitText="Create <%= human_name.downcase %>"
|
23
|
+
on:submit={handleSubmit}
|
24
|
+
/>
|
25
|
+
|
26
|
+
<br />
|
27
|
+
|
28
|
+
<div>
|
29
|
+
<Link href="<%= js_resources_path %>">Back to <%= human_name.pluralize.downcase %></Link>
|
30
|
+
</div>
|
@@ -0,0 +1,28 @@
|
|
1
|
+
<script>
|
2
|
+
export let <%= singular_table_name %>
|
3
|
+
</script>
|
4
|
+
|
5
|
+
<div>
|
6
|
+
<% attributes.reject(&:password_digest?).each do |attribute| -%>
|
7
|
+
<p>
|
8
|
+
<strong><%= attribute.human_name %>:</strong>
|
9
|
+
<% if attribute.attachment? -%>
|
10
|
+
{#if <%= singular_table_name %>.<%= attribute.column_name %>}
|
11
|
+
<a href={<%= singular_table_name %>.<%= attribute.column_name %>.url}>
|
12
|
+
{<%= singular_table_name %>.<%= attribute.column_name %>.filename}
|
13
|
+
</a>
|
14
|
+
{/if}
|
15
|
+
</p>
|
16
|
+
<% elsif attribute.attachments? -%>
|
17
|
+
</p>
|
18
|
+
{#each <%= singular_table_name %>.<%= attribute.column_name %> as { url, filename }}
|
19
|
+
<div>
|
20
|
+
<a href={url}>{filename}</a>
|
21
|
+
</div>
|
22
|
+
{/each}
|
23
|
+
<% else -%>
|
24
|
+
{<%= singular_table_name %>.<%= attribute.column_name %>}
|
25
|
+
</p>
|
26
|
+
<% end -%>
|
27
|
+
<% end -%>
|
28
|
+
</div>
|
@@ -0,0 +1,46 @@
|
|
1
|
+
<script>
|
2
|
+
import { inertia, Link } from '@inertiajs/svelte'
|
3
|
+
import <%= inertia_component_name %> from './<%= inertia_component_name %>.svelte'
|
4
|
+
|
5
|
+
export let <%= singular_table_name %>
|
6
|
+
export let flash
|
7
|
+
|
8
|
+
const onDestroy = (e) => {
|
9
|
+
if (!confirm('Are you sure you want to delete this <%= human_name.downcase %>?')) {
|
10
|
+
e.preventDefault()
|
11
|
+
}
|
12
|
+
}
|
13
|
+
</script>
|
14
|
+
|
15
|
+
<svelte:head>
|
16
|
+
<title><%= human_name %> #{<%= singular_table_name %>.id}</title>
|
17
|
+
</svelte:head>
|
18
|
+
|
19
|
+
{#if flash.notice}
|
20
|
+
<p class="notice">{flash.notice}</p>
|
21
|
+
{/if}
|
22
|
+
|
23
|
+
<h1><%= human_name %> #{<%= singular_table_name %>.id}</h1>
|
24
|
+
|
25
|
+
<<%= inertia_component_name %> {<%= singular_table_name %>} />
|
26
|
+
|
27
|
+
<div>
|
28
|
+
<Link href={`<%= js_edit_resource_path %>`}>Edit this <%= human_name.downcase %></Link> |
|
29
|
+
<Link href="<%= js_resources_path %>">Back to <%= human_name.pluralize.downcase %></Link>
|
30
|
+
|
31
|
+
<br />
|
32
|
+
|
33
|
+
<button
|
34
|
+
use:inertia={{ href: `<%= js_resource_path %>`, method: 'delete' }}
|
35
|
+
on:click={onDestroy}
|
36
|
+
type="button"
|
37
|
+
>
|
38
|
+
Destroy this <%= human_name.downcase %>
|
39
|
+
</button>
|
40
|
+
</div>
|
41
|
+
|
42
|
+
<style>
|
43
|
+
.notice {
|
44
|
+
color: green;
|
45
|
+
}
|
46
|
+
</style>
|
@@ -44,7 +44,7 @@
|
|
44
44
|
<% elsif attribute.attachments? -%>
|
45
45
|
<input
|
46
46
|
type="file"
|
47
|
-
multiple
|
47
|
+
multiple
|
48
48
|
name="<%= attribute.singular_name %>[]"
|
49
49
|
id="<%= attribute.singular_name %>"
|
50
50
|
@input="form.<%= attribute.column_name %> = Array.from($event.target.files)"
|
@@ -74,13 +74,13 @@ export default function Form({ <%= singular_table_name %>, onSubmit, submitText
|
|
74
74
|
<% elsif attribute.attachments? -%>
|
75
75
|
<input
|
76
76
|
type="file"
|
77
|
-
multiple
|
77
|
+
multiple
|
78
78
|
name="<%= attribute.singular_name %>[]"
|
79
79
|
id="<%= attribute.singular_name %>"
|
80
80
|
className="block shadow rounded-md border border-gray-400 outline-none px-3 py-2 mt-2 w-full"
|
81
81
|
onChange={(e) => setData('<%= attribute.column_name %>', Array.from(e.target.files))}
|
82
82
|
/>
|
83
|
-
<% elsif attribute
|
83
|
+
<% elsif input_type(attribute) == "checkbox" -%>
|
84
84
|
<input
|
85
85
|
type="<%= input_type(attribute) %>"
|
86
86
|
name="<%= attribute.singular_name %>"
|
@@ -2,10 +2,9 @@
|
|
2
2
|
import { Link } from '@inertiajs/svelte'
|
3
3
|
import Form from './Form.svelte'
|
4
4
|
|
5
|
-
|
5
|
+
let { <%= singular_table_name %> } = $props()
|
6
6
|
|
7
|
-
const handleSubmit = (
|
8
|
-
const { form } = e.detail
|
7
|
+
const handleSubmit = ({ form }) => {
|
9
8
|
form.transform((data) => ({ <%= singular_table_name %>: data }))
|
10
9
|
<% if attributes.any?(&:attachments?) -%>
|
11
10
|
form.post(`<%= js_resource_path %>`, {
|
@@ -27,7 +26,7 @@
|
|
27
26
|
<Form
|
28
27
|
{<%= singular_table_name %>}
|
29
28
|
submitText="Update <%= human_name.downcase %>"
|
30
|
-
|
29
|
+
onSubmit={handleSubmit}
|
31
30
|
/>
|
32
31
|
|
33
32
|
<Link
|
@@ -2,10 +2,7 @@
|
|
2
2
|
import { useForm } from '@inertiajs/svelte'
|
3
3
|
import { createEventDispatcher } from 'svelte'
|
4
4
|
|
5
|
-
|
6
|
-
|
7
|
-
export let <%= singular_table_name %>
|
8
|
-
export let submitText
|
5
|
+
let { <%= singular_table_name %>, submitText, onSubmit } = $props()
|
9
6
|
|
10
7
|
const form = useForm({
|
11
8
|
<% attributes.each do |attribute| -%>
|
@@ -17,12 +14,14 @@
|
|
17
14
|
<% end -%>
|
18
15
|
<% end -%>
|
19
16
|
})
|
17
|
+
|
18
|
+
const handleSubmit = (e) => {
|
19
|
+
e.preventDefault()
|
20
|
+
onSubmit({form: $form })
|
21
|
+
}
|
20
22
|
</script>
|
21
23
|
|
22
|
-
<form
|
23
|
-
class="contents"
|
24
|
-
on:submit|preventDefault={dispatch('submit', { form: $form })}
|
25
|
-
>
|
24
|
+
<form class="contents" onsubmit={handleSubmit}>
|
26
25
|
<% attributes.each do |attribute| -%>
|
27
26
|
<div class="my-5">
|
28
27
|
<% if attribute.password_digest? -%>
|
@@ -64,25 +63,25 @@
|
|
64
63
|
bind:value={$form.<%= attribute.column_name %>}
|
65
64
|
rows="4"
|
66
65
|
class="block shadow rounded-md border border-gray-400 outline-none px-3 py-2 mt-2 w-full"
|
67
|
-
|
66
|
+
></textarea>
|
68
67
|
<% elsif attribute.attachment? -%>
|
69
68
|
<input
|
70
69
|
type="file"
|
71
70
|
name="<%= attribute.singular_name %>"
|
72
71
|
id="<%= attribute.singular_name %>"
|
73
|
-
|
72
|
+
oninput={(e) => ($form.<%= attribute.column_name %> = e.target.files[0])}
|
74
73
|
class="block shadow rounded-md border border-gray-400 outline-none px-3 py-2 mt-2 w-full"
|
75
74
|
/>
|
76
75
|
<% elsif attribute.attachments? -%>
|
77
76
|
<input
|
78
77
|
type="file"
|
79
|
-
multiple
|
78
|
+
multiple
|
80
79
|
name="<%= attribute.singular_name %>[]"
|
81
80
|
id="<%= attribute.singular_name %>"
|
82
|
-
|
81
|
+
oninput={(e) => ($form.<%= attribute.column_name %> = Array.from(e.target.files))}
|
83
82
|
class="block shadow rounded-md border border-gray-400 outline-none px-3 py-2 mt-2 w-full"
|
84
83
|
/>
|
85
|
-
<% elsif attribute
|
84
|
+
<% elsif input_type(attribute) == "checkbox" -%>
|
86
85
|
<input
|
87
86
|
type="<%= input_type(attribute) %>"
|
88
87
|
name="<%= attribute.singular_name %>"
|
@@ -2,14 +2,7 @@
|
|
2
2
|
import { Link } from '@inertiajs/svelte'
|
3
3
|
import <%= inertia_component_name %> from './<%= inertia_component_name %>.svelte'
|
4
4
|
|
5
|
-
|
6
|
-
export let flash
|
7
|
-
|
8
|
-
const onDestroy = (e) => {
|
9
|
-
if (!confirm('Are you sure you want to delete this <%= human_name.downcase %>?')) {
|
10
|
-
e.preventDefault()
|
11
|
-
}
|
12
|
-
}
|
5
|
+
let { <%= plural_table_name %>, flash } = $props()
|
13
6
|
</script>
|
14
7
|
|
15
8
|
<svelte:head>
|
@@ -2,10 +2,9 @@
|
|
2
2
|
import { Link } from '@inertiajs/svelte'
|
3
3
|
import Form from './Form.svelte'
|
4
4
|
|
5
|
-
|
5
|
+
let { <%= singular_table_name %> } = $props()
|
6
6
|
|
7
|
-
const handleSubmit = (
|
8
|
-
const { form } = e.detail
|
7
|
+
const handleSubmit = ({ form }) => {
|
9
8
|
form.transform((data) => ({ <%= singular_table_name %>: data }))
|
10
9
|
form.post('<%= js_resources_path %>')
|
11
10
|
}
|
@@ -21,7 +20,7 @@
|
|
21
20
|
<Form
|
22
21
|
{<%= singular_table_name %>}
|
23
22
|
submitText="Create <%= human_name.downcase %>"
|
24
|
-
|
23
|
+
onSubmit={handleSubmit}
|
25
24
|
/>
|
26
25
|
|
27
26
|
<Link
|
@@ -1,9 +1,8 @@
|
|
1
1
|
<script>
|
2
|
-
import {
|
2
|
+
import { Link } from '@inertiajs/svelte'
|
3
3
|
import <%= inertia_component_name %> from './<%= inertia_component_name %>.svelte'
|
4
4
|
|
5
|
-
|
6
|
-
export let flash
|
5
|
+
let { <%= singular_table_name %>, flash } = $props()
|
7
6
|
|
8
7
|
const onDestroy = (e) => {
|
9
8
|
if (!confirm('Are you sure you want to delete this <%= human_name.downcase %>?')) {
|
@@ -41,14 +40,14 @@
|
|
41
40
|
Back to <%= human_name.pluralize.downcase %>
|
42
41
|
</Link>
|
43
42
|
<div class="inline-block ml-2">
|
44
|
-
<
|
45
|
-
|
46
|
-
|
47
|
-
|
43
|
+
<Link
|
44
|
+
href={`<%= js_resource_path %>`}
|
45
|
+
method="delete"
|
46
|
+
onclick={onDestroy}
|
48
47
|
class="mt-2 rounded-lg py-3 px-5 bg-gray-100 font-medium"
|
49
48
|
>
|
50
49
|
Destroy this <%= human_name.downcase %>
|
51
|
-
</
|
50
|
+
</Link>
|
52
51
|
</div>
|
53
52
|
</div>
|
54
53
|
</div>
|
@@ -0,0 +1,45 @@
|
|
1
|
+
<script>
|
2
|
+
import { Link } from '@inertiajs/svelte'
|
3
|
+
import Form from './Form.svelte'
|
4
|
+
|
5
|
+
export let <%= singular_table_name %>
|
6
|
+
|
7
|
+
const handleSubmit = (e) => {
|
8
|
+
const { form } = e.detail
|
9
|
+
form.transform((data) => ({ <%= singular_table_name %>: data }))
|
10
|
+
<% if attributes.any?(&:attachments?) -%>
|
11
|
+
form.post(`<%= js_resource_path %>`, {
|
12
|
+
headers: { 'X-HTTP-METHOD-OVERRIDE': 'put' },
|
13
|
+
})
|
14
|
+
<% else -%>
|
15
|
+
form.patch(`<%= js_resource_path %>`)
|
16
|
+
<% end -%>
|
17
|
+
}
|
18
|
+
</script>
|
19
|
+
|
20
|
+
<svelte:head>
|
21
|
+
<title>Editing <%= human_name.downcase %></title>
|
22
|
+
</svelte:head>
|
23
|
+
|
24
|
+
<div class="mx-auto md:w-2/3 w-full px-8 pt-8">
|
25
|
+
<h1 class="font-bold text-4xl">Editing <%= human_name.downcase %></h1>
|
26
|
+
|
27
|
+
<Form
|
28
|
+
{<%= singular_table_name %>}
|
29
|
+
submitText="Update <%= human_name.downcase %>"
|
30
|
+
on:submit={handleSubmit}
|
31
|
+
/>
|
32
|
+
|
33
|
+
<Link
|
34
|
+
href={`<%= js_resource_path %>`}
|
35
|
+
class="mt-2 rounded-lg py-3 px-5 bg-gray-100 inline-block font-medium"
|
36
|
+
>
|
37
|
+
Show this <%= human_name.downcase %>
|
38
|
+
</Link>
|
39
|
+
<Link
|
40
|
+
href="<%= js_resources_path %>"
|
41
|
+
class="ml-2 rounded-lg py-3 px-5 bg-gray-100 inline-block font-medium"
|
42
|
+
>
|
43
|
+
Back to <%= human_name.pluralize.downcase %>
|
44
|
+
</Link>
|
45
|
+
</div>
|