Skip to content
This repository has been archived by the owner on Feb 9, 2024. It is now read-only.

Issue/7 - 修改預設日期及時間 以及 更新行事曆上資料 #21

Merged
merged 14 commits into from
Dec 28, 2023

Conversation

AranceLiu
Copy link
Collaborator

  1. 修改 edit events的時候,date 跟 time 不能有預設:
Screen.Recording.0005-12-20.at.10.48.22.AM.mov
  1. 當在行事曆上移動,要更新資料:
Screen.Recording.0005-12-20.at.10.50.32.AM.mov

@AranceLiu AranceLiu changed the title Issue/7 Issue/7 - 修改預設日期及時間 以及 更新行事曆上資料 Dec 20, 2023
@@ -31,6 +31,10 @@ def show; end

def edit; end

def drop
@event.update(event_params)
Copy link
Collaborator

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 嗎?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

打API把dates傳回來更新
我不覺得使用update需要用.save

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

update 方法裡已內建 save,所以的確是不用再另外執行

ryoma510260
ryoma510260 previously approved these changes Dec 20, 2023
@Kkrystalll
Copy link

想問這邊當初為何需要分為 date 跟 time 兩個欄位,而不是直接給 datetime?

t.date "start_date", null: false
t.time "start_time"
t.date "end_date", null: false
t.time "end_time"

@AranceLiu
Copy link
Collaborator Author

想問這邊當初為何需要分為 date 跟 time 兩個欄位,而不是直接給 datetime?

t.date "start_date", null: false

t.time "start_time"

t.date "end_date", null: false

t.time "end_time"

本來應該是 只有兩個欄位(開始、結束)都用datetime
但後來討論可能有時間的話要串Google calendar api,所以分成四個欄位
雖然我也不確定有沒有時間夠不夠到 可以串到

const id = e.event.id;
const url = `/events/${id}/drop`;
const data = { start_date, start_time, end_date, end_time };
console.log(data);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

console.log()

記得移除

# test "the truth" do
# assert true
# end
end

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",

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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

這邊優化部分可以另外開票,就是若是今天有更新失敗的時候錯誤處理會是怎樣
例如跳 notice 之類的

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#32
我先開一個 之後處理

</div>
</div>


Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

這個空兩行跑 rubocop 會錯吧?
可以養成習慣在推上來之前跑一下 rubocop

Copy link
Collaborator Author

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];

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

這邊處理時間的話建議可以找 js 處理時間的套件
會方便非常多

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

感謝建議 我再來找找

Copy link
Collaborator Author

@AranceLiu AranceLiu Dec 22, 2023

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");

TimChaoTW
TimChaoTW previously approved these changes Dec 22, 2023
@TimChaoTW TimChaoTW merged commit 37885da into dev Dec 28, 2023
@TimChaoTW TimChaoTW deleted the issue/7 branch December 28, 2023 14:47
@AranceLiu AranceLiu self-assigned this Jan 24, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants