Skip to content

Commit

Permalink
貸出ステータスと書籍在庫の登録・参照ページを追加。
Browse files Browse the repository at this point in the history
  • Loading branch information
mikoto2000 committed Sep 7, 2024
1 parent 326a87e commit f048caa
Show file tree
Hide file tree
Showing 39 changed files with 1,245 additions and 1 deletion.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,5 @@
!/app/assets/builds/.keep

/node_modules

vendor/
65 changes: 65 additions & 0 deletions app/controllers/book_stock_statuses_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
class BookStockStatusesController < ApplicationController
include Pagy::Backend
before_action :set_book_stock_status, only: %i[show edit update destroy]

# GET /book_stock_statuses
def index
@book_stock_statuses = BookStockStatus
.all
@q = @book_stock_statuses.ransack(params[:q])
@q.sorts = "id asc" if @q.sorts.empty?
@pagy, @book_stock_statuses = pagy(@q.result, page: params[:page], items: params[:items])
end

# GET /book_stock_statuses/1
def show
end

# GET /book_stock_statuses/new
def new
@book_stock_status = BookStockStatus.new
end

# GET /book_stock_statuses/1/edit
def edit
end

# POST /book_stock_statuses
def create
@book_stock_status = BookStockStatus.new(book_stock_status_params)

if @book_stock_status.save
redirect_to @book_stock_status, notice: t("controller.create.success", model: BookStockStatus.model_name.human)
else
render :new, status: :unprocessable_entity
end
end

# PATCH/PUT /book_stock_statuses/1
def update
if @book_stock_status.update(book_stock_status_params)
redirect_to @book_stock_status, notice: t("controller.edit.success", model: BookStockStatus.model_name.human)
else
render :edit, status: :unprocessable_entity
end
end

# DELETE /book_stock_statuses/1
def destroy
@book_stock_status.destroy!
redirect_to book_stock_statuses_url, notice: t("controller.destroy.success", model: BookStockStatus.model_name.human)

Check failure on line 50 in app/controllers/book_stock_statuses_controller.rb

View workflow job for this annotation

GitHub Actions / lint

Layout/LineLength: Line is too long. [121/120]
end

private

# Use callbacks to share common setup or constraints between actions.
def set_book_stock_status
@book_stock_status = BookStockStatus
.find(params[:id])
end

# Only allow a list of trusted parameters through.
def book_stock_status_params
params.require(:book_stock_status).permit(:name)
end
end
68 changes: 68 additions & 0 deletions app/controllers/book_stocks_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
class BookStocksController < ApplicationController
include Pagy::Backend
before_action :set_book_stock, only: %i[show edit update destroy]

# GET /book_stocks
def index
@book_stocks = BookStock
.eager_load(:book_master)
.eager_load(:book_stock_status)
@q = @book_stocks.ransack(params[:q])
@q.sorts = "id asc" if @q.sorts.empty?
@pagy, @book_stocks = pagy(@q.result, page: params[:page], items: params[:items])
end

# GET /book_stocks/1
def show
end

# GET /book_stocks/new
def new
@book_stock = BookStock.new
end

# GET /book_stocks/1/edit
def edit
end

# POST /book_stocks
def create
@book_stock = BookStock.new(book_stock_params)

if @book_stock.save
redirect_to @book_stock, notice: t("controller.create.success", model: BookStock.model_name.human)
else
render :new, status: :unprocessable_entity
end
end

# PATCH/PUT /book_stocks/1
def update
if @book_stock.update(book_stock_params)
redirect_to @book_stock, notice: t("controller.edit.success", model: BookStock.model_name.human)
else
render :edit, status: :unprocessable_entity
end
end

# DELETE /book_stocks/1
def destroy
@book_stock.destroy!
redirect_to book_stocks_url, notice: t("controller.destroy.success", model: BookStock.model_name.human)
end

private

# Use callbacks to share common setup or constraints between actions.
def set_book_stock
@book_stock = BookStock
.eager_load(:book_master)
.eager_load(:book_stock_status)
.find(params[:id])
end

# Only allow a list of trusted parameters through.
def book_stock_params
params.require(:book_stock).permit(:book_master_id, :book_stock_status_id, :memo)
end
end
3 changes: 3 additions & 0 deletions app/helpers/book_stock_statuses_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module BookStockStatusesHelper
include Pagy::Frontend
end
3 changes: 3 additions & 0 deletions app/helpers/book_stocks_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module BookStocksHelper
include Pagy::Frontend
end
7 changes: 7 additions & 0 deletions app/models/book_stock.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
class BookStock < ApplicationRecord
def self.ransackable_attributes(_auth_object = nil)
%w[book_master_id book_stock_status_id memo id created_at updated_at]
end
belongs_to :book_master
belongs_to :book_stock_status
end
5 changes: 5 additions & 0 deletions app/models/book_stock_status.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class BookStockStatus < ApplicationRecord
def self.ransackable_attributes(_auth_object = nil)
%w[name id created_at updated_at]
end
end
42 changes: 42 additions & 0 deletions app/views/book_stock_statuses/_book_stock_status.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<div id="<%= dom_id book_stock_status %>">
<table class="table table-hover">
<tr>
<td>
<strong>Id:</strong>
</td>
<td>
<%= book_stock_status.id %>
</td>
</tr>
<tr>
<td>
<strong>
<%= BookStockStatus.human_attribute_name(:name) %>
</strong>
</td>
<td>
<%= book_stock_status.name %>
</td>
</tr>
<tr>
<td>
<strong>
<%= BookStockStatus.human_attribute_name(:created_at) %>
</strong>
</td>
<td>
<%= book_stock_status.created_at && l(book_stock_status.created_at) %>
</td>
</tr>
<tr>
<td>
<strong>
<%= BookStockStatus.human_attribute_name(:updated_at) %>
</strong>
</td>
<td>
<%= book_stock_status.updated_at && l(book_stock_status.updated_at) %>
</td>
</tr>
</table>
</div>
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
json.extract! book_stock_status, :id, :name, :created_at, :updated_at
json.url book_stock_status_url(book_stock_status, format: :json)
45 changes: 45 additions & 0 deletions app/views/book_stock_statuses/_form.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<%= form_with(model: book_stock_status, html: { class: %w[form-control form-control-sm] }) do |form| -%>
<%- if book_stock_status.errors.any? -%>
<div style="color: red">
<h2><%= t("errors.template.header", model: BookStockStatus.model_name.human, count: book_stock_status.errors.count) %></h2>

<ul>
<% book_stock_status.errors.each do |error| %>
<li><%= error.full_message %></li>
<%- end -%>
</ul>
</div>
<%- end -%>

<%- if book_stock_status.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 book_stock_status.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 %>
9 changes: 9 additions & 0 deletions app/views/book_stock_statuses/edit.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<h1><%= t("view.edit.title", model: BookStockStatus.model_name.human) %></h1>
<%= render "form", book_stock_status: @book_stock_status %>

<br>

<div>
<%= link_to t("view.edit.move_to_show", model: BookStockStatus.model_name.human), @book_stock_status %> |
<%= link_to t("view.edit.move_to_index", model: BookStockStatus.model_name.human.pluralize), book_stock_statuses_path %>
</div>
111 changes: 111 additions & 0 deletions app/views/book_stock_statuses/index.html.erb
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><%= BookStockStatus.model_name.human %><%= link_to "", new_book_stock_status_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="book_stock_statuses" 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>
<%- @book_stock_statuses.each do |book_stock_status| %>
<tr
tabindex="0"
role="button"
onkeypress="handleEnterKeypressListIten(arguments[0], this, '<%= url_target(nil, book_stock_status).to_s %>')"
onclick="handleClickListItem(arguments[0], this, '<%= url_target(nil, book_stock_status).to_s %>')">
<td><%= book_stock_status.id %></td>
<td><%= book_stock_status.name %></td>
<td><%= book_stock_status.created_at && l(book_stock_status.created_at) %></td>
<td><%= book_stock_status.updated_at && l(book_stock_status.updated_at) %></td>
<td>
<%= button_to(
t("helpers.submit.delete"),
book_stock_status,
method: :delete,
tabindex: 0,
class: %w[btn btn-primary],
onclick: "handleDeleteListItem(arguments[0], this)",
data: { turbo_confirm: t("helpers.dialog.delete", id: book_stock_status.id) }
) %>
</td>
</tr>
<%- end %>
</tbody>
</table>
</div>
<div>
<%== pagy_bootstrap_nav(@pagy) %>
<%== pagy_limit_selector_js(@pagy, item_name: "Book stock status".pluralize(@pagy.count), id: "pagy-limit-selector") %>
<%= link_to(
t("view.index.update_item_per_page", model: BookStockStatus.model_name.human),
"javascript:void(0);",
onClick: "updateItemPerPage(arguments[0],
this)"
) %>
</div>
<% end %>
</main>
</div>
1 change: 1 addition & 0 deletions app/views/book_stock_statuses/index.json.jbuilder
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
json.array! @book_stock_statuses, partial: "book_stock_statuses/book_stock_status", as: :book_stock_status
8 changes: 8 additions & 0 deletions app/views/book_stock_statuses/new.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<h1><%= t("view.new.title", model: BookStockStatus.model_name.human) %></h1>
<%= render "form", book_stock_status: @book_stock_status %>

<br>

<div>
<%= link_to t("view.new.move_to_index", model: BookStockStatus.model_name.human.pluralize), book_stock_statuses_path %>
</div>
Loading

0 comments on commit f048caa

Please sign in to comment.