-
Notifications
You must be signed in to change notification settings - Fork 4
Issue/7 - 修改預設日期及時間 以及 更新行事曆上資料 #21
Conversation
@@ -31,6 +31,10 @@ def show; end | |||
|
|||
def edit; end | |||
|
|||
def drop | |||
@event.update(event_params) |
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.
想問:
1.drop是'拖拉事件'方法?
2.需要加上 @event.save 嗎?
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.
打API把dates傳回來更新
我不覺得使用update需要用.save
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.
update
方法裡已內建 save
,所以的確是不用再另外執行
想問這邊當初為何需要分為 date 跟 time 兩個欄位,而不是直接給 datetime? t.date "start_date", null: false
t.time "start_time"
t.date "end_date", null: false
t.time "end_time" |
本來應該是 只有兩個欄位(開始、結束)都用datetime |
const id = e.event.id; | ||
const url = `/events/${id}/drop`; | ||
const data = { start_date, start_time, end_date, end_time }; | ||
console.log(data); |
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.
console.log()
記得移除
test/models/calendar_test.rb
Outdated
# test "the truth" do | ||
# assert true | ||
# end | ||
end |
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.
不用的檔案可刪
@@ -19,7 +19,7 @@ export default class extends Controller { | |||
flatpickr(this.startDateTarget, { | |||
enableTime: false, | |||
minDate: "today", | |||
defaultDate: "today", | |||
|
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.
如果希望有資料的時候顯示資料內容,沒有資料的時候顯示預設,可以在 _form.html.erb 裡改成
<%= form.date_field :start_date, value: event.start_date || Date.today, class:'form-input', required: true, data:{ datepicker_target:"startDate"} %>
加上 value: event.start_date || Date.today
,其他欄位同理
@@ -31,6 +31,10 @@ def show; end | |||
|
|||
def edit; end | |||
|
|||
def drop | |||
@event.update(event_params) | |||
end |
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.
這邊優化部分可以另外開票,就是若是今天有更新失敗的時候錯誤處理會是怎樣
例如跳 notice 之類的
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.
#32
我先開一個 之後處理
app/views/events/index.html.erb
Outdated
</div> | ||
</div> | ||
|
||
|
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.
這個空兩行跑 rubocop 會錯吧?
可以養成習慣在推上來之前跑一下 rubocop
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.
這邊 沒有說有問題
我手動調整了
const start_time = start[1].split(".")[0]; | ||
const end = new Date(end_at).toISOString().split("T"); | ||
const end_date = end[0]; | ||
const end_time = end[1].split(".")[0]; |
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.
這邊處理時間的話建議可以找 js 處理時間的套件
會方便非常多
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.
感謝建議 我再來找找
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.
使用 dayjs:
const start_at = dayjs.utc(e.event.start);
const end_at = dayjs.utc(e.event.end);
const start_date = start_at.format("YYYY-MM-DD");
const start_time = start_at.format("HH:mm:ss");
const end_date = end_at.format("YYYY-MM-DD");
const end_time = end_at.format("HH:mm:ss");
… current time and date for now
cbedad5
Screen.Recording.0005-12-20.at.10.48.22.AM.mov
Screen.Recording.0005-12-20.at.10.50.32.AM.mov