-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
2827c6a
commit 326a87e
Showing
31 changed files
with
769 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
class AuthorsController < ApplicationController | ||
include Pagy::Backend | ||
before_action :set_author, only: %i[show edit update destroy] | ||
|
||
# GET /authors | ||
def index | ||
@authors = Author | ||
.all | ||
@q = @authors.ransack(params[:q]) | ||
@q.sorts = "id asc" if @q.sorts.empty? | ||
@pagy, @authors = pagy(@q.result, page: params[:page], items: params[:items]) | ||
end | ||
|
||
# GET /authors/1 | ||
def show | ||
end | ||
|
||
# GET /authors/new | ||
def new | ||
@author = Author.new | ||
end | ||
|
||
# GET /authors/1/edit | ||
def edit | ||
end | ||
|
||
# POST /authors | ||
def create | ||
@author = Author.new(author_params) | ||
|
||
if @author.save | ||
redirect_to @author, notice: t("controller.create.success", model: Author.model_name.human) | ||
else | ||
render :new, status: :unprocessable_entity | ||
end | ||
end | ||
|
||
# PATCH/PUT /authors/1 | ||
def update | ||
if @author.update(author_params) | ||
redirect_to @author, notice: t("controller.edit.success", model: Author.model_name.human) | ||
else | ||
render :edit, status: :unprocessable_entity | ||
end | ||
end | ||
|
||
# DELETE /authors/1 | ||
def destroy | ||
@author.destroy! | ||
redirect_to authors_url, notice: t("controller.destroy.success", model: Author.model_name.human) | ||
end | ||
|
||
private | ||
|
||
# Use callbacks to share common setup or constraints between actions. | ||
def set_author | ||
@author = Author | ||
.find(params[:id]) | ||
end | ||
|
||
# Only allow a list of trusted parameters through. | ||
def author_params | ||
params.require(:author).permit(:name) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
module AuthorsHelper | ||
include Pagy::Frontend | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
class Author < ApplicationRecord | ||
def self.ransackable_attributes(_auth_object = nil) | ||
%w[name id created_at updated_at] | ||
end | ||
|
||
has_many :book_author_relationship | ||
has_many :book_masters, through: :book_author_relationship | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
class BookAuthorRelationship < ApplicationRecord | ||
def self.ransackable_attributes(_auth_object = nil) | ||
%w[book_master_id author_id id created_at updated_at] | ||
end | ||
belongs_to :book_master | ||
belongs_to :author | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,11 @@ | ||
class BookMaster < ApplicationRecord | ||
def self.ransackable_attributes(_auth_object = nil) | ||
%w[isbn title publication_date ndc_category_id id created_at updated_at] | ||
%w[isbn title publication_date ndc_category_id author_id id created_at updated_at] | ||
end | ||
def self.ransackable_associations(auth_object = nil) | ||
Check failure on line 5 in app/models/book_master.rb GitHub Actions / lint
Check failure on line 5 in app/models/book_master.rb GitHub Actions / lint
|
||
["authors", "book_author_relationship", "ndc_category"] | ||
end | ||
belongs_to :ndc_category | ||
has_many :book_author_relationship | ||
has_many :authors, through: :book_author_relationship | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
<div id="<%= dom_id author %>"> | ||
<table class="table table-hover"> | ||
<tr> | ||
<td> | ||
<strong>Id:</strong> | ||
</td> | ||
<td> | ||
<%= author.id %> | ||
</td> | ||
</tr> | ||
<tr> | ||
<td> | ||
<strong> | ||
<%= Author.human_attribute_name(:name) %> | ||
</strong> | ||
</td> | ||
<td> | ||
<%= author.name %> | ||
</td> | ||
</tr> | ||
<tr> | ||
<td> | ||
<strong> | ||
<%= Author.human_attribute_name(:created_at) %> | ||
</strong> | ||
</td> | ||
<td> | ||
<%= author.created_at && l(author.created_at) %> | ||
</td> | ||
</tr> | ||
<tr> | ||
<td> | ||
<strong> | ||
<%= Author.human_attribute_name(:updated_at) %> | ||
</strong> | ||
</td> | ||
<td> | ||
<%= author.updated_at && l(author.updated_at) %> | ||
</td> | ||
</tr> | ||
</table> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
json.extract! author, :id, :name, :created_at, :updated_at | ||
json.url author_url(author, format: :json) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
<%= form_with(model: author, html: { class: %w[form-control form-control-sm] }) do |form| -%> | ||
<%- if author.errors.any? -%> | ||
<div style="color: red"> | ||
<h2><%= t("errors.template.header", model: Author.model_name.human, count: author.errors.count) %></h2> | ||
|
||
<ul> | ||
<% author.errors.each do |error| %> | ||
<li><%= error.full_message %></li> | ||
<%- end -%> | ||
</ul> | ||
</div> | ||
<%- end -%> | ||
|
||
<%- if author.persisted? -%> | ||
<div> | ||
<%= form.label :id, style: "display: block" %> | ||
<div class="ps-2"> | ||
<%= form.number_field :id, class: %w[form-control form-control-sm], disabled: true %> | ||
</div> | ||
</div> | ||
<%- end -%> | ||
<div> | ||
<%= form.label :name, style: "display: block" %> | ||
<div class="ps-2"> | ||
<%= form.text_field :name, class: %w[form-control form-control-sm] %> | ||
</div> | ||
</div> | ||
<%- if author.persisted? -%> | ||
<div> | ||
<%= form.label :created_at, style: "display: block" %> | ||
<div class="ps-2"> | ||
<%= form.datetime_field :created_at, class: %w[form-control form-control-sm], disabled: true %> | ||
</div> | ||
</div> | ||
<div> | ||
<%= form.label :updated_at, style: "display: block" %> | ||
<div class="ps-2"> | ||
<%= form.datetime_field :updated_at, class: %w[form-control form-control-sm], disabled: true %> | ||
</div> | ||
</div> | ||
<%- end -%> | ||
<div> | ||
<%= form.submit class: %w[btn btn-primary] %> | ||
</div> | ||
<% end %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<h1><%= t("view.edit.title", model: Author.model_name.human) %></h1> | ||
<%= render "form", author: @author %> | ||
|
||
<br> | ||
|
||
<div> | ||
<%= link_to t("view.edit.move_to_show", model: Author.model_name.human), @author %> | | ||
<%= link_to t("view.edit.move_to_index", model: Author.model_name.human.pluralize), authors_path %> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
<div style="display: flex;flex-direction: column;height: 100vh;"> | ||
|
||
<header class="main-content-header"> | ||
<p style="color: green"><%= notice %></p> | ||
|
||
<h1><%= Author.model_name.human %><%= link_to "", new_author_path, class: %w[bi bi-plus-circle-fill ms-2] %></h1> | ||
|
||
<div class="accordion"> | ||
<div class="accordion-item"> | ||
<h2 class="accordion-header" id="search-form-header"> | ||
<button | ||
class="accordion-button collapsed" | ||
type="button" | ||
data-bs-toggle="collapse" | ||
data-bs-target="#search-form" | ||
aria-expanded="false" | ||
aria-controls="search-form"><%= t("view.index.search_condition") %></button> | ||
</h2> | ||
<div id="search-form" class="panel panel-default accordion-collapse collapse" aria-labelledby="headingOne"> | ||
<%= search_form_for @q, html: { class: %w[form-control form-control-sm], data: { turbo_frame: "list" } } do |f| %> | ||
<div> | ||
<%= f.label :id_eq %> | ||
<div class="ps-2"> | ||
<%= f.number_field :id_eq, class: %w[form-control form-control-sm] %> | ||
</div> | ||
</div> | ||
<div> | ||
<%= f.label :name_cont %> | ||
<div class="ps-2"> | ||
<%= f.search_field :name_cont, class: %w[form-control form-control-sm] %> | ||
</div> | ||
</div> | ||
<div> | ||
<%= f.label :created_at %> | ||
<div class="ps-2"> | ||
<%= f.datetime_field :created_at_gteq, class: %w[form-control form-control-sm] %> | ||
~ | ||
<%= f.datetime_field :created_at_lteq_end_of_minute, class: %w[form-control form-control-sm] %> | ||
</div> | ||
</div> | ||
<div> | ||
<%= f.label :updated_at %> | ||
<div class="ps-2"> | ||
<%= f.datetime_field :updated_at_gteq, class: %w[form-control form-control-sm] %> | ||
~ | ||
<%= f.datetime_field :updated_at_lteq_end_of_minute, class: %w[form-control form-control-sm] %> | ||
</div> | ||
</div> | ||
<%= f.hidden_field :limit, id: "f-limit", value: params[:limit] || Pagy::DEFAULT[:limit] %> | ||
<%= f.submit class: %w[btn btn-primary] %> | ||
<input | ||
type="reset" | ||
class="btn btn-primary" | ||
onclick="clear_form(arguments[0], this)" | ||
value="<%= t("helpers.submit.clear") %>"> | ||
<%- end -%> | ||
</div> | ||
</div> | ||
</header> | ||
|
||
<main style="flex-grow: 1;flex-shrink: 1;overflow-y: auto;"> | ||
<%= turbo_frame_tag "list" do %> | ||
<div id="authors" class="text-nowrap"> | ||
<table class="table table-hover text-nowrap"> | ||
<thead class="table-light sticky-top"> | ||
<th><%= sort_link(@q, :id, default_order: :asc, class: "d-block") %></th> | ||
<th><%= sort_link(@q, :name, default_order: :asc, class: "d-block") %></th> | ||
<th><%= sort_link(@q, :created_at, default_order: :asc, class: "d-block") %></th> | ||
<th><%= sort_link(@q, :updated_at, default_order: :asc, class: "d-block") %></th> | ||
<th><%= t("view.index.operation") %></th> | ||
</thead> | ||
<tbody> | ||
<%- @authors.each do |author| %> | ||
<tr | ||
tabindex="0" | ||
role="button" | ||
onkeypress="handleEnterKeypressListIten(arguments[0], this, '<%= url_target(nil, author).to_s %>')" | ||
onclick="handleClickListItem(arguments[0], this, '<%= url_target(nil, author).to_s %>')"> | ||
<td><%= author.id %></td> | ||
<td><%= author.name %></td> | ||
<td><%= author.created_at && l(author.created_at) %></td> | ||
<td><%= author.updated_at && l(author.updated_at) %></td> | ||
<td> | ||
<%= button_to( | ||
t("helpers.submit.delete"), | ||
author, | ||
method: :delete, | ||
tabindex: 0, | ||
class: %w[btn btn-primary], | ||
onclick: "handleDeleteListItem(arguments[0], this)", | ||
data: { turbo_confirm: t("helpers.dialog.delete", id: author.id) } | ||
) %> | ||
</td> | ||
</tr> | ||
<%- end %> | ||
</tbody> | ||
</table> | ||
</div> | ||
<div> | ||
<%== pagy_bootstrap_nav(@pagy) %> | ||
<%== pagy_limit_selector_js(@pagy, item_name: "Author".pluralize(@pagy.count), id: "pagy-limit-selector") %> | ||
<%= link_to( | ||
t("view.index.update_item_per_page", model: Author.model_name.human), | ||
"javascript:void(0);", | ||
onClick: "updateItemPerPage(arguments[0], | ||
this)" | ||
) %> | ||
</div> | ||
<% end %> | ||
</main> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
json.array! @authors, partial: "authors/author", as: :author |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<h1><%= t("view.new.title", model: Author.model_name.human) %></h1> | ||
<%= render "form", author: @author %> | ||
|
||
<br> | ||
|
||
<div> | ||
<%= link_to t("view.new.move_to_index", model: Author.model_name.human.pluralize), authors_path %> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<p style="color: green"><%= notice %></p> | ||
|
||
<h1><%= Author.model_name.human %></h1> | ||
|
||
<%= render @author %> | ||
|
||
<div> | ||
<%= link_to t("view.show.move_to_update", model: Author.model_name.human), edit_author_path(@author) %> | | ||
<%= link_to t("view.show.move_to_index", model: Author.model_name.human.pluralize), authors_path %> | ||
|
||
<%= button_to t("helpers.submit.delete"), | ||
@author, | ||
method: :delete, | ||
class: %w[btn btn-primary], | ||
data: { turbo_confirm: t("helpers.dialog.delete", id: @author.id) } %> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
json.partial! "authors/author", author: @author |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.