Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Create an example Scaffolding::CompletelyConcrete::SimpleSingleton resource #543

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 9 additions & 7 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ GEM
bootsnap (1.15.0)
msgpack (~> 1.2)
builder (3.2.4)
bullet_train (1.1.9)
bullet_train (1.1.10)
awesome_print
bullet_train-fields
bullet_train-has_uuid
Expand Down Expand Up @@ -187,7 +187,7 @@ GEM
rails (>= 7.0.0)
bullet_train-super_load_and_authorize_resource (1.0.1)
rails (>= 6.0.0)
bullet_train-super_scaffolding (1.1.14)
bullet_train-super_scaffolding (1.1.15)
bullet_train
indefinite_article
rails (>= 6.0.0)
Expand Down Expand Up @@ -215,7 +215,7 @@ GEM
charlock_holmes (0.7.7)
chronic (0.10.2)
chunky_png (1.4.0)
cloudinary (1.23.0)
cloudinary (1.24.0)
aws_cf_signer
rest-client (>= 2.0.0)
code_analyzer (0.5.5)
Expand All @@ -230,6 +230,7 @@ GEM
addressable
cssbundling-rails (1.1.1)
railties (>= 6.0.0)
date (3.3.1)
debug (1.7.0)
irb (>= 1.5.0)
reline (>= 0.3.1)
Expand Down Expand Up @@ -338,11 +339,12 @@ GEM
minitest (>= 5.0)
msgpack (1.6.0)
multi_xml (0.6.0)
net-imap (0.3.1)
net-imap (0.3.2)
date
net-protocol
net-pop (0.1.2)
net-protocol
net-protocol (0.1.3)
net-protocol (0.2.1)
timeout
net-smtp (0.3.3)
net-protocol
Expand Down Expand Up @@ -405,7 +407,7 @@ GEM
pry-stack_explorer (0.6.1)
binding_of_caller (~> 1.0)
pry (~> 0.13)
public_suffix (5.0.0)
public_suffix (5.0.1)
puma (6.0.0)
nio4r (~> 2.0)
pwned (2.0.2)
Expand Down Expand Up @@ -533,7 +535,7 @@ GEM
stripe (8.0.0)
thor (1.2.1)
thread-local (1.1.0)
timeout (0.3.0)
timeout (0.3.1)
turbo-rails (1.3.2)
actionpack (>= 6.0.0)
activejob (>= 6.0.0)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
class Account::Scaffolding::CompletelyConcrete::SimpleSingletonsController < Account::ApplicationController
account_load_and_authorize_resource :simple_singleton, through: :absolutely_abstract_creative_concept, through_association: :completely_concrete_simple_singletons

# GET /account/scaffolding/absolutely_abstract/creative_concepts/:absolutely_abstract_creative_concept_id/completely_concrete/simple_singletons
# GET /account/scaffolding/absolutely_abstract/creative_concepts/:absolutely_abstract_creative_concept_id/completely_concrete/simple_singletons.json
def index
delegate_json_to_api
end

# GET /account/scaffolding/completely_concrete/simple_singletons/:id
# GET /account/scaffolding/completely_concrete/simple_singletons/:id.json
def show
delegate_json_to_api
end

# GET /account/scaffolding/absolutely_abstract/creative_concepts/:absolutely_abstract_creative_concept_id/completely_concrete/simple_singletons/new
def new
end

# GET /account/scaffolding/completely_concrete/simple_singletons/:id/edit
def edit
end

# POST /account/scaffolding/absolutely_abstract/creative_concepts/:absolutely_abstract_creative_concept_id/completely_concrete/simple_singletons
# POST /account/scaffolding/absolutely_abstract/creative_concepts/:absolutely_abstract_creative_concept_id/completely_concrete/simple_singletons.json
def create
respond_to do |format|
if @simple_singleton.save
format.html { redirect_to [:account, @absolutely_abstract_creative_concept, :completely_concrete_simple_singletons], notice: I18n.t("scaffolding/completely_concrete/simple_singletons.notifications.created") }
format.json { render :show, status: :created, location: [:account, @simple_singleton] }
else
format.html { render :new, status: :unprocessable_entity }
format.json { render json: @simple_singleton.errors, status: :unprocessable_entity }
end
end
end

# PATCH/PUT /account/scaffolding/completely_concrete/simple_singletons/:id
# PATCH/PUT /account/scaffolding/completely_concrete/simple_singletons/:id.json
def update
respond_to do |format|
if @simple_singleton.update(simple_singleton_params)
format.html { redirect_to [:account, @simple_singleton], notice: I18n.t("scaffolding/completely_concrete/simple_singletons.notifications.updated") }
format.json { render :show, status: :ok, location: [:account, @simple_singleton] }
else
format.html { render :edit, status: :unprocessable_entity }
format.json { render json: @simple_singleton.errors, status: :unprocessable_entity }
end
end
end

# DELETE /account/scaffolding/completely_concrete/simple_singletons/:id
# DELETE /account/scaffolding/completely_concrete/simple_singletons/:id.json
def destroy
@simple_singleton.destroy
respond_to do |format|
format.html { redirect_to [:account, @absolutely_abstract_creative_concept, :completely_concrete_simple_singletons], notice: I18n.t("scaffolding/completely_concrete/simple_singletons.notifications.destroyed") }
format.json { head :no_content }
end
end

private

include strong_parameters_from_api

def process_params(strong_params)
# 🚅 super scaffolding will insert processing for new fields above this line.
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
class Api::V1::Scaffolding::CompletelyConcrete::SimpleSingletonsController < Api::V1::ApplicationController
account_load_and_authorize_resource :simple_singleton, through: :absolutely_abstract_creative_concept, through_association: :completely_concrete_simple_singletons

# GET /api/v1/scaffolding/absolutely_abstract/creative_concepts/:absolutely_abstract_creative_concept_id/completely_concrete/simple_singletons
def index
end

# GET /api/v1/scaffolding/completely_concrete/simple_singletons/:id
def show
end

# POST /api/v1/scaffolding/absolutely_abstract/creative_concepts/:absolutely_abstract_creative_concept_id/completely_concrete/simple_singletons
def create
if @simple_singleton.save
render :show, status: :created, location: [:api, :v1, @simple_singleton]
else
render json: @simple_singleton.errors, status: :unprocessable_entity
end
end

# PATCH/PUT /api/v1/scaffolding/completely_concrete/simple_singletons/:id
def update
if @simple_singleton.update(simple_singleton_params)
render :show
else
render json: @simple_singleton.errors, status: :unprocessable_entity
end
end

# DELETE /api/v1/scaffolding/completely_concrete/simple_singletons/:id
def destroy
@simple_singleton.destroy
end

private

module StrongParameters
# Only allow a list of trusted parameters through.
def simple_singleton_params
strong_params = params.require(:scaffolding_completely_concrete_simple_singleton).permit(
*permitted_fields,
:name,
# 🚅 super scaffolding will insert new fields above this line.
*permitted_arrays,
# 🚅 super scaffolding will insert new arrays above this line.
)

process_params(strong_params)

strong_params
end
end

include StrongParameters
end
5 changes: 5 additions & 0 deletions app/models/scaffolding/completely_concrete.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module Scaffolding::CompletelyConcrete
def self.table_name_prefix
"scaffolding_completely_concrete_"
end
end
24 changes: 24 additions & 0 deletions app/models/scaffolding/completely_concrete/simple_singleton.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
class Scaffolding::CompletelyConcrete::SimpleSingleton < ApplicationRecord
# 🚅 add concerns above.

# 🚅 add attribute accessors above.

belongs_to :absolutely_abstract_creative_concept, class_name: "Scaffolding::AbsolutelyAbstract::CreativeConcept"
# 🚅 add belongs_to associations above.

# 🚅 add has_many associations above.

has_one :team, through: :absolutely_abstract_creative_concept
# 🚅 add has_one associations above.

# 🚅 add scopes above.

validates :name, presence: true
# 🚅 add validations above.

# 🚅 add callbacks above.

# 🚅 add delegations above.

# 🚅 add methods above.
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<% simple_singleton ||= @simple_singleton %>
<% absolutely_abstract_creative_concept ||= @absolutely_abstract_creative_concept || simple_singleton&.absolutely_abstract_creative_concept %>
<%= render 'account/scaffolding/absolutely_abstract/creative_concepts/breadcrumbs', creative_concept: absolutely_abstract_creative_concept %>
<%= render 'account/shared/breadcrumb', label: t('.label'), url: [:account, absolutely_abstract_creative_concept, :completely_concrete_simple_singletons] %>
<% if simple_singleton&.persisted? %>
<%= render 'account/shared/breadcrumb', label: simple_singleton.label_string, url: [:account, simple_singleton] %>
<% end %>
<%= render 'account/shared/breadcrumbs/actions', only_for: 'scaffolding/completely_concrete/simple_singletons' %>
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<% cancel_path ||= simple_singleton.persisted? ? [:account, simple_singleton] : [:account, @absolutely_abstract_creative_concept, :completely_concrete_simple_singletons] %>

<%= form_with model: simple_singleton, url: (simple_singleton.persisted? ? [:account, simple_singleton] : [:account, @absolutely_abstract_creative_concept, :completely_concrete_simple_singletons]), local: true, class: 'form' do |form| %>
<%= render "shared/limits/form", form: form, cancel_path: cancel_path do %>
<%= render 'account/shared/forms/errors', form: form %>

<% with_field_settings form: form do %>
<%= render 'shared/fields/text_field', method: :name, options: {autofocus: true} %>
<%# 🚅 super scaffolding will insert new fields above this line. %>
<% end %>

<div class="buttons">
<%= form.submit (form.object.persisted? ? t('.buttons.update') : t('.buttons.create')), class: "button" %>
<%= link_to t('global.buttons.cancel'), cancel_path, class: "button-secondary" %>
</div>
<% end %>
<% end %>
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
<% absolutely_abstract_creative_concept = @absolutely_abstract_creative_concept || @creative_concept %>
<% context ||= absolutely_abstract_creative_concept %>
<% collection ||= :completely_concrete_simple_singletons %>
<% hide_actions ||= false %>
<% hide_back ||= false %>

<% simple_singletons = simple_singletons.order(:id) unless has_order?(simple_singletons) %>
<% pagy, simple_singletons = pagy(simple_singletons, page_param: :simple_singletons_page) %>

<%= action_model_select_controller do %>
<%= updates_for context, collection do %>
<%= render 'account/shared/box', pagy: pagy do |p| %>
<% p.content_for :title, t(".contexts.#{context.class.name.underscore}.header") %>
<% p.content_for :description do %>
<%= t(".contexts.#{context.class.name.underscore}.description#{"_empty" unless simple_singletons.any?}") %>
<%= render "shared/limits/index", model: simple_singletons.model %>
<% end %>

<% p.content_for :table do %>
<% if simple_singletons.any? %>
<table class="table">
<thead>
<tr>
<%= render "shared/tables/select_all" %>
<th><%= t('.fields.name.heading') %></th>
<%# 🚅 super scaffolding will insert new field headers above this line. %>
<th><%= t('.fields.created_at.heading') %></th>
<th class="text-right"></th>
</tr>
</thead>
<tbody>
<% simple_singletons.each do |simple_singleton| %>
<% with_attribute_settings object: simple_singleton do %>
<tr data-id="<%= simple_singleton.id %>">
<%= render "shared/tables/checkbox", object: simple_singleton %>
<td><%= render 'shared/attributes/text', attribute: :name, url: [:account, simple_singleton] %></td>
<%# 🚅 super scaffolding will insert new fields above this line. %>
<td><%= render 'shared/attributes/date_and_time', attribute: :created_at %></td>
<td class="buttons">
<% unless hide_actions %>
<% if can? :edit, simple_singleton %>
<%= link_to t('.buttons.shorthand.edit'), [:edit, :account, simple_singleton], class: 'button-secondary button-smaller' %>
<% end %>
<% if can? :destroy, simple_singleton %>
<%= button_to t('.buttons.shorthand.destroy'), [:account, simple_singleton], method: :delete, data: { confirm: t('.buttons.confirmations.destroy', model_locales(simple_singleton)) }, class: 'button-secondary button-smaller' %>
<% end %>
<%# 🚅 super scaffolding will insert new action model buttons above this line. %>
<% end %>
</td>
</tr>
<% end %>
<% end %>
</tbody>
</table>
<% end %>
<% end %>

<% p.content_for :actions do %>
<% unless hide_actions %>
<% if context == absolutely_abstract_creative_concept %>
<% if can? :create, Scaffolding::CompletelyConcrete::SimpleSingleton.new(absolutely_abstract_creative_concept: absolutely_abstract_creative_concept) %>
<%= link_to t('.buttons.new'), [:new, :account, absolutely_abstract_creative_concept, :completely_concrete_simple_singleton], class: "#{first_button_primary(:completely_concrete_simple_singleton)} new" %>
<% end %>
<% end %>

<%# 🚅 super scaffolding will insert new targets one parent action model buttons above this line. %>
<%# 🚅 super scaffolding will insert new bulk action model buttons above this line. %>
<%= render "shared/bulk_action_select" %>

<% unless hide_back %>
<%= link_to t('global.buttons.back'), [:account, context], class: "#{first_button_primary(:completely_concrete_simple_singleton)} back" %>
<% end %>
<% end %>
<% end %>

<% p.content_for :raw_footer do %>
<%# 🚅 super scaffolding will insert new action model index views above this line. %>
<% end %>
<% end %>
<% end %>
<% end %>
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<% if can? :read, Scaffolding::CompletelyConcrete::SimpleSingleton.new(team: current_team) %>
<%= render 'account/shared/menu/item', {
url: main_app.polymorphic_path([:account, current_team, :scaffolding_completely_concrete_simple_singletons]),
label: t('scaffolding/completely_concrete/simple_singletons.navigation.label'),
} do |p| %>
<% p.content_for :icon do %>
<i class="<%= t('scaffolding/completely_concrete/simple_singletons.navigation.icon') %>"></i>
<% end %>
<% end %>
<% end %>
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<%= render 'account/shared/page' do |p| %>
<% p.content_for :title, t('.section') %>
<% p.content_for :body do %>
<%= render 'account/shared/box', divider: true do |p| %>
<% p.content_for :title, t('.header') %>
<% p.content_for :description, t('.description') %>
<% p.content_for :body do %>
<%= render 'form', simple_singleton: @simple_singleton %>
<% end %>
<% end %>
<% end %>
<% end %>
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<%= render 'account/shared/page' do |p| %>
<% p.content_for :title, t('.section') %>
<% p.content_for :body do %>
<%= render 'index', simple_singletons: @simple_singletons %>
<% end %>
<% end %>
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<%= render 'account/shared/page' do |p| %>
<% p.content_for :title, t('.section') %>
<% p.content_for :body do %>
<%= render 'account/shared/box', divider: true do |p| %>
<% p.content_for :title, t('.header') %>
<% p.content_for :description, t('.description') %>
<% p.content_for :body do %>
<%= render 'form', simple_singleton: @simple_singleton %>
<% end %>
<% end %>
<% end %>
<% end %>
Loading