Skip to content

Commit 66eea9a

Browse files
committed
added inline edit demo to dummy app
1 parent 1c5bf6a commit 66eea9a

File tree

5 files changed

+85
-0
lines changed

5 files changed

+85
-0
lines changed

spec/dummy/app/controllers/my_app_controller.rb

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,10 @@ def collection
3030
responder_for(Pages::MyApp::Collection)
3131
end
3232

33+
def inline_edit
34+
responder_for(Pages::MyApp::InlineEdit)
35+
end
36+
3337
def some_action
3438
render json: {}, status: :ok
3539
end
@@ -47,6 +51,20 @@ def form_action
4751
end
4852
end
4953

54+
def inline_form_action
55+
@dummy_model = DummyModel.find(params[:id])
56+
@dummy_model.update(dummy_model_params)
57+
if @dummy_model.errors.any?
58+
render json: {
59+
errors: @dummy_model.errors,
60+
message: "Test Model could not be saved!"
61+
}, status: :unproccessable_entity
62+
else
63+
broadcast "test_model_created"
64+
render json: @dummy_model, status: :created
65+
end
66+
end
67+
5068
def delete_dummy_model
5169
@dummy_model = DummyModel.find(params[:id])
5270
if @dummy_model.destroy

spec/dummy/app/matestack/apps/my_app.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,9 @@ def navigation_section
3939
transition path: :collection_path do
4040
button text: "Collection"
4141
end
42+
transition path: :inline_edit_path do
43+
button text: "Inline Edit"
44+
end
4245
end
4346
}
4447
end
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
class Pages::MyApp::InlineEdit < Matestack::Ui::Page
2+
3+
def prepare
4+
@my_model = DummyModel.last
5+
end
6+
7+
def response
8+
components {
9+
heading size: 2, text: "Inline Edit"
10+
11+
partial :show_value
12+
partial :show_form
13+
}
14+
end
15+
16+
def show_value
17+
partial {
18+
async rerender_on: "item_updated", show_on: "item_updated", hide_on: "update_item", init_show: true do
19+
onclick emit: "update_item" do
20+
plain @my_model.title
21+
plain "(click me)"
22+
end
23+
end
24+
}
25+
end
26+
27+
def show_form
28+
partial {
29+
async rerender_on: "item_updated", show_on: "update_item", hide_on: "item_updated" do
30+
form some_form_config, :include do
31+
form_input key: :title, type: :text
32+
form_submit do
33+
button text: "save"
34+
end
35+
end
36+
onclick emit: "item_updated" do
37+
button text: "abort"
38+
end
39+
end
40+
}
41+
end
42+
43+
def some_form_config
44+
{
45+
for: @my_model,
46+
method: :post,
47+
path: :inline_form_action_path,
48+
params: {
49+
id: @my_model.id
50+
},
51+
success:{
52+
emit: "item_updated"
53+
}
54+
}
55+
end
56+
57+
58+
end

spec/dummy/app/matestack/pages/my_app/my_first_page.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
class Pages::MyApp::MyFirstPage < Matestack::Ui::Page
22

3+
def prepare
4+
@my_model = DummyModel.last
5+
end
6+
37
def response
48
components {
59
heading size: 2, text: "This is Page 1"

spec/dummy/config/routes.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,11 @@
2727
get 'my_fifth_page', to: 'my_app#my_fifth_page'
2828
get 'my_sixth_page', to: 'my_app#my_sixth_page'
2929
get 'collection', to: 'my_app#collection'
30+
get 'inline_edit', to: 'my_app#inline_edit'
3031

3132
post 'some_action', to: 'my_app#some_action'
3233
post 'form_action', to: 'my_app#form_action'
34+
post 'inline_form_action/:id', to: 'my_app#inline_form_action', as: "inline_form_action"
3335

3436
delete 'delete_dummy_model', to: 'my_app#delete_dummy_model'
3537
end

0 commit comments

Comments
 (0)