Basic feature implemented, very basic poc

This commit is contained in:
David Schärer 2024-07-16 20:22:59 +02:00
parent 216089a3e7
commit 48c0067076
118 changed files with 2113 additions and 20 deletions

View file

@ -0,0 +1,13 @@
<%%= bootstrap_form_with(model: <%= model_resource_name %>) do |form| %>
<% attributes.each do |attribute| -%>
<% if attribute.password_digest? -%>
<%%= form.password_field :password %>
<%%= form.password_field :password_confirmation %>
<% elsif attribute.attachments? -%>
<%%= form.<%= attribute.field_type %> :<%= attribute.column_name %>, multiple: true %>
<% else -%>
<%%= form.<%= attribute.field_type %> :<%= attribute.column_name %> %>
<% end -%>
<% end -%>
<%%= form.submit %>
<%% end %>

View file

@ -0,0 +1,8 @@
<h1><%%= t("scaffold.pagetitle_edit", model: <%= class_name %>.model_name.human) %></h1>
<%%= render "form", <%= singular_table_name %>: @<%= singular_table_name %> %>
<div class="action-row">
<%%= link_to t("scaffold.link_show", model: <%= class_name %>.model_name.human), <%= model_resource_name(prefix: "@") %> %>
<%%= link_to t("scaffold.link_index", model: <%= class_name %>.model_name.human(count: 2)), <%= index_helper(type: :path) %> %>
</div>

View file

@ -0,0 +1,25 @@
<h1><%%= t("scaffold.pagetitle_index", model: <%= class_name %>.model_name.human(count: 2)) %></h1>
<table class="table table-striped">
<thead>
<tr>
<th><%%= <%= class_name %>.human_attribute_name(:id) %></th>
<% attributes.each do |attribute| %>
<th><%%= <%= class_name %>.human_attribute_name(:<%= attribute.column_name %>) %></th>
<% end %>
</thead>
<tbody>
<%% @<%= plural_table_name %>.each do |<%= singular_table_name %>| %>
<tr>
<td><%%= link_to(<%= singular_table_name %>.id, url_for(<%= singular_table_name %>)) %></td>
<% attributes.each do |attribute| %>
<td><%%= link_to(<%= singular_table_name %>.<%= attribute.column_name %>, url_for(<%= singular_table_name %>)) %></td>
<% end %>
</tr>
<%% end %>
</tbody>
</table>
<div class="action-row">
<%%= link_to t("scaffold.link_new", model: <%= class_name %>.model_name.human), new_<%= singular_table_name %>_path %>
</div>

View file

@ -0,0 +1,7 @@
<h1><%%= t("scaffold.pagetitle_new", model: <%= class_name %>.model_name.human) %></h1>
<%%= render "form", <%= singular_table_name %>: @<%= singular_table_name %> %>
<div class="action-row">
<%%= link_to t("scaffold.link_index", model: <%= class_name %>.model_name.human(count: 2)), <%= plural_table_name %>_path %>
</div>

View file

@ -0,0 +1,17 @@
<div id="<%%= dom_id <%= singular_name %> %>">
<% attributes.reject(&:password_digest?).each do |attribute| -%>
<p>
<strong><%= attribute.human_name %>:</strong>
<% if attribute.attachment? -%>
<%%= link_to <%= singular_name %>.<%= attribute.column_name %>.filename, <%= singular_name %>.<%= attribute.column_name %> if <%= singular_name %>.<%= attribute.column_name %>.attached? %>
<% elsif attribute.attachments? -%>
<%% <%= singular_name %>.<%= attribute.column_name %>.each do |<%= attribute.singular_name %>| %>
<div><%%= link_to <%= attribute.singular_name %>.filename, <%= attribute.singular_name %> %></div>
<%% end %>
<% else -%>
<%%= <%= singular_name %>.<%= attribute.column_name %> %>
<% end -%>
</p>
<% end -%>
</div>

View file

@ -0,0 +1,9 @@
<h1><%%= t("scaffold.pagetitle_show", model: @<%= singular_table_name %>.class.model_name.human) %></h1>
<%%= render @<%= singular_table_name %> %>
<div class="action-row">
<%%= link_to t("scaffold.link_edit", model: @<%= singular_table_name %>.model_name.human), <%= edit_helper(type: :path) %> %>
<%%= link_to t("scaffold.link_index", model: @<%= singular_table_name %>.model_name.human(count: 2)), <%= index_helper(type: :path) %> %>
<%%= button_to t("scaffold.link_destroy", model: @<%= singular_table_name %>.model_name.human), <%= model_resource_name(prefix: "@") %>, method: :delete, class: "btn btn-warning" %>
</div>

View file

@ -0,0 +1,64 @@
<% module_namespacing do -%>
class <%= controller_class_name %>Controller < ApplicationController
before_action :set_<%= singular_table_name %>, only: %i[ show edit update destroy ]
# GET <%= route_url %>
def index
@<%= plural_table_name %> = <%= orm_class.all(class_name) %>
end
# GET <%= route_url %>/1
def show
end
# GET <%= route_url %>/new
def new
@<%= singular_table_name %> = <%= orm_class.build(class_name) %>
end
# GET <%= route_url %>/1/edit
def edit
end
# POST <%= route_url %>
def create
@<%= singular_table_name %> = <%= orm_class.build(class_name, "#{singular_table_name}_params") %>
if @<%= orm_instance.save %>
redirect_to <%= redirect_resource_name %>, notice: <%= %("#{human_name} was successfully created.") %>
else
render :new, status: :unprocessable_entity
end
end
# PATCH/PUT <%= route_url %>/1
def update
if @<%= orm_instance.update("#{singular_table_name}_params") %>
redirect_to <%= redirect_resource_name %>, notice: <%= %("#{human_name} was successfully updated.") %>, status: :see_other
else
render :edit, status: :unprocessable_entity
end
end
# DELETE <%= route_url %>/1
def destroy
@<%= orm_instance.destroy %>
redirect_to <%= index_helper %>_url, notice: <%= %("#{human_name} was successfully destroyed.") %>, status: :see_other
end
private
# Use callbacks to share common setup or constraints between actions.
def set_<%= singular_table_name %>
@<%= singular_table_name %> = <%= orm_class.find(class_name, "params[:id]") %>
end
# Only allow a list of trusted parameters through.
def <%= "#{singular_table_name}_params" %>
<%- if attributes_names.empty? -%>
params.fetch(:<%= singular_table_name %>, {})
<%- else -%>
params.require(:<%= singular_table_name %>).permit(<%= permitted_params %>)
<%- end -%>
end
end
<% end -%>