-
Notifications
You must be signed in to change notification settings - Fork 0
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
生理周期登録機能 #49
Merged
Merged
生理周期登録機能 #49
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
bce32b6
:+1: vision boardのフォームエラーメッセージ表示を改善
sarii0213 73efc20
:sparkles: 生理周期 (period) のMVC etc. 作成
sarii0213 b5d5526
:heavy_plus_sign: kaminari追加してpagination実装
sarii0213 ea83726
:+1: pathなど修正
sarii0213 0e4b4b9
:shirt: rubocop & erb_lint
sarii0213 f60b920
Merge branch 'main' into issue-39/periods_feature
sarii0213 0239b42
:+1: period model validation追加, UI調整
sarii0213 9f9af54
:bug: turbo_streamとhtmlの二重リクエストになるのを解消
sarii0213 bc73c0b
:+1: paginationのviewを改善
sarii0213 be29b23
:bug: turbo streamとHTMLで二重リクエストが送られる問題を解消
sarii0213 c0a86b1
:shirt: rubocop
sarii0213 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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
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,50 @@ | ||
# frozen_string_literal: true | ||
|
||
class PeriodsController < ApplicationController | ||
before_action :authenticate_user! | ||
before_action :set_period, only: %i[edit update destroy] | ||
|
||
def index | ||
@periods = current_user.periods.order(started_on: :desc).page(params[:page]).per(5) | ||
end | ||
|
||
def new | ||
@period = Period.new(started_on: Time.zone.today, ended_on: Time.zone.today.advance(weeks: 1)) | ||
end | ||
|
||
def edit; end | ||
|
||
def create | ||
@period = Period.new(period_params) | ||
if @period.save | ||
flash[:notice] = t('period.created') | ||
render turbo_stream: turbo_stream.action(:redirect, periods_path) | ||
else | ||
render :new, status: :unprocessable_entity | ||
end | ||
end | ||
|
||
def update | ||
if @period.update(period_params) | ||
flash[:notice] = t('period.updated') | ||
render turbo_stream: turbo_stream.action(:redirect, periods_path) | ||
else | ||
render :edit, status: :unprocessable_entity | ||
end | ||
end | ||
|
||
def destroy | ||
@period.destroy | ||
flash.now[:notice] = t('period.destroyed') | ||
end | ||
|
||
private | ||
|
||
def period_params | ||
params.require(:period).permit(:started_on, :ended_on).merge(user_id: current_user.id) | ||
end | ||
|
||
def set_period | ||
@period = current_user.periods.find(params[:id]) | ||
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
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,36 @@ | ||
# frozen_string_literal: true | ||
|
||
# == Schema Information | ||
# | ||
# Table name: periods | ||
# | ||
# id :bigint not null, primary key | ||
# ended_on :date not null | ||
# started_on :date not null | ||
# created_at :datetime not null | ||
# updated_at :datetime not null | ||
# user_id :bigint not null | ||
# | ||
# Indexes | ||
# | ||
# index_periods_on_user_id_and_started_on (user_id,started_on) UNIQUE | ||
# | ||
# Foreign Keys | ||
# | ||
# fk_rails_... (user_id => users.id) | ||
# | ||
class Period < ApplicationRecord | ||
belongs_to :user | ||
|
||
validates :started_on, presence: true, uniqueness: { scope: :user_id } | ||
validates :ended_on, presence: true, comparison: { greater_than: :started_on } | ||
validate :date_difference | ||
|
||
private | ||
|
||
def date_difference | ||
return unless ended_on > started_on.advance(weeks: 2) | ||
|
||
errors.add(:ended_on, 'は開始日から2週間以内に設定してください') | ||
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 @@ | ||
<%= link_to url, class: 'item', title: t('views.pagination.first').html_safe, remote: remote do %> | ||
<i class="angle double left icon"></i> | ||
<% 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,3 @@ | ||
<div class="item"> | ||
<%= t('views.pagination.truncate').html_safe %> | ||
</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,3 @@ | ||
<%= link_to url, class: 'item', title: t('views.pagination.last').html_safe, remote: remote do %> | ||
<i class="angle double right icon"></i> | ||
<% 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,3 @@ | ||
<%= link_to url, class: 'item', title: t('views.pagination.next').html_safe, remote: remote do %> | ||
<i class="right angle icon"></i> | ||
<% 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 @@ | ||
<% if page.current? %> | ||
<%= link_to url, class: 'item active', title: page, remote: remote do %> | ||
<%= page %> | ||
<% end %> | ||
<% else %> | ||
<%= link_to url, class: 'item', title: page, remote: remote do %> | ||
<%= page %> | ||
<% 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<%= paginator.render do %> | ||
<nav class="ui pagination menu"> | ||
<%= first_page_tag unless current_page.first? %> | ||
<%= prev_page_tag unless current_page.first? %> | ||
<% each_page do |page| %> | ||
<% if page.left_outer? || page.right_outer? || page.inside_window? %> | ||
<%= page_tag page %> | ||
<% elsif !page.was_truncated? %> | ||
<%= gap_tag %> | ||
<% end %> | ||
<% end %> | ||
<%= next_page_tag unless current_page.last? %> | ||
<%= last_page_tag unless current_page.last? %> | ||
</nav> | ||
<% 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,3 @@ | ||
<%= link_to url, class: 'item', title: t('views.pagination.previous').html_safe, remote: remote do %> | ||
<i class="left angle icon"></i> | ||
<% 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,11 +1,11 @@ | ||
<div class="ui borderless bottom fixed labeled icon menu three item grey"> | ||
<%= link_to objectives_path, class: "item #{'active' if current_page?(objectives_path)}" do %> | ||
<%= link_to objectives_path, class: "item #{'active' if current_page?(objectives_path) || current_page?(root_path)}" do %> | ||
<i class="compass icon"></i>vision board | ||
<% end %> | ||
<%= link_to records_path, class: "item #{'active' if current_page?(records_path)}" do %> | ||
<i class="map icon"></i>weight | ||
<% end %> | ||
<%= link_to user_setting_path, class: "item #{'active' if current_page?(root_path)}" do %> | ||
<%= link_to user_setting_path, class: "item #{'active' if current_page?(user_setting_path)}" do %> | ||
<i class="cogs icon"></i>setting | ||
<% end %> | ||
</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
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 |
---|---|---|
|
@@ -40,3 +40,7 @@ | |
</div> | ||
<% end %> | ||
</div> | ||
|
||
<div style="margin-top:50px; text-align:center"> | ||
<%= paginate @objectives %> | ||
</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,22 @@ | ||
<%= turbo_frame_tag 'form' do %> | ||
<%= form_with model: period, method: :post, class: "ui form #{period.errors.any? ? 'error' : ''}", data: { modal_target: 'form', action: 'turbo:submit-end->modal#close' } do |f| %> | ||
<div class="field"> | ||
<%= f.label :started_on, '開始日' %> | ||
<%= f.date_field :started_on %> | ||
</div> | ||
<div class="field"> | ||
<%= f.label :ended_on, '終了日' %> | ||
<%= f.date_field :ended_on %> | ||
</div> | ||
<% if period.errors.any? %> | ||
<div class="ui error message"> | ||
<ul class="list"> | ||
<% period.errors.each do |error| %> | ||
<li><%= error.full_message %></li> | ||
<% end %> | ||
</ul> | ||
</div> | ||
<% end %> | ||
<%= f.submit '登録', class: 'actions ui fluid large teal submit button' %> | ||
<% 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<div style="display: flex; justify-content: space-between; padding-right: 10px"> | ||
<span><%= period.started_on %> - <%= period.ended_on %></span> | ||
<div> | ||
<%# TODO: edit, deleteをiconに %> | ||
<%= link_to edit_period_path(period), data: { turbo_frame: period } do %> | ||
<i class="edit icon"></i> | ||
<% end %> | ||
<%= link_to period, data: { turbo_method: :delete, turbo_confirm: '削除しますか?' } do %> | ||
<i class="trash icon"></i> | ||
<% end %> | ||
</div> | ||
</div> | ||
<div class="ui divider"></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 @@ | ||
<%= turbo_stream.remove @period %> | ||
<%= turbo_stream_flash %> |
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,29 @@ | ||
<%= turbo_frame_tag @period do %> | ||
<%= form_with model: @period, method: :put, class: "ui form #{@period.errors.any? ? 'error' : ''}" do |f| %> | ||
<div style="display: flex; justify-content: space-between"> | ||
<div style="display: flex; align-items: center;"> | ||
<div class="inline field" style="margin:0"> | ||
<%= f.date_field :started_on %> | ||
</div> | ||
<div style="padding:10px">-</div> | ||
<div class="inline field" style="margin:0"> | ||
<%= f.date_field :ended_on %> | ||
</div> | ||
</div> | ||
<div style="display: flex; align-items: center"> | ||
<%= f.submit '更新', class: 'ui mini button' %> | ||
<%= link_to 'キャンセル', periods_path, class: 'ui mini button' %> | ||
</div> | ||
</div> | ||
<% if @period.errors.any? %> | ||
<div class="ui error message"> | ||
<ul class="list"> | ||
<% @period.errors.each do |error| %> | ||
<li><%= error.full_message %></li> | ||
<% end %> | ||
</ul> | ||
</div> | ||
<% end %> | ||
<% end %> | ||
<div class="ui divider"></div> | ||
<% end %> |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
turbo_stream, htmlの二重のリクエストにレスポンスが返され、フラッシュメッセージが表示されない
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
✅ hotwired/turbo-rails#367 (comment)