대시보드 화면 디자인 수정 중
This commit is contained in:
@@ -22,4 +22,75 @@ class EnvironmentController < ApplicationController
|
||||
@controller = Controller.find(params[:id])
|
||||
@schedule = Schedule.where(controller_id: params[:id]).order(:hour, :minute)
|
||||
end
|
||||
|
||||
def edit_temp
|
||||
@controller = Controller.find(params[:id])
|
||||
@schedule = Schedule.where(controller_id: params[:id]).order(:hour, :minute)
|
||||
end
|
||||
|
||||
def create
|
||||
@schedule = Schedule.new(schedule_params)
|
||||
|
||||
if @schedule.save
|
||||
redirect_to schedule_edit_schedule_path(@schedule.controller_id), notice: "스케쥴이 추가 되었습니다."
|
||||
else
|
||||
error_messages = @schedule.errors.full_messages.join(", ")
|
||||
redirect_to schedule_edit_schedule_path(@schedule.controller_id), alert: "스케쥴 추가 실패: #{error_messages}"
|
||||
end
|
||||
end
|
||||
|
||||
def destroy
|
||||
@schedule = Schedule.find_by(id: params[:id])
|
||||
|
||||
if @schedule.destroy
|
||||
redirect_to schedule_edit_schedule_path(@schedule.controller_id), notice: "스케줄이 삭제되었습니다."
|
||||
else
|
||||
error_messages = @schedule.errors.full_messages.join(", ")
|
||||
redirect_to schedule_edit_schedule_path(@schedule.controller_id), alert: "스케쥴 삭제 실패: #{error_messages}"
|
||||
end
|
||||
end
|
||||
|
||||
def reset
|
||||
Schedule.where(controller_id: params[:id]).destroy_all
|
||||
ActiveRecord::Base.connection.execute("DELETE FROM sqlite_sequence WHERE name='schedules'")
|
||||
|
||||
redirect_to schedule_edit_schedule_path(params[:id]), notice: "스케줄이 초기화되었습니다."
|
||||
end
|
||||
|
||||
def schedule_edit
|
||||
@controller = Controller.find(params[:id])
|
||||
@schedule = Schedule.where(controller_id: params[:id]).order(:hour, :minute)
|
||||
end
|
||||
|
||||
def schedule_edit_update
|
||||
error_messages = []
|
||||
|
||||
params[:schedule]&.each do |id, attributes|
|
||||
schedule = Schedule.find_by(id: id)
|
||||
next unless schedule
|
||||
|
||||
unless schedule.update(
|
||||
hour: attributes[:hour],
|
||||
minute: attributes[:minute],
|
||||
is_active: attributes[:is_active],
|
||||
temperature: attributes[:temperature]
|
||||
)
|
||||
|
||||
error_detail = schedule.errors.full_messages.join(", ")
|
||||
time_label = "#{attributes[:hour]}시 #{attributes[:minute]}분"
|
||||
error_messages << "#{time_label} - #{error_detail}"
|
||||
end
|
||||
end
|
||||
|
||||
if error_messages.any?
|
||||
redirect_to schedule_edit_schedule_path(params[:controller_id]), alert: error_messages.join("<br>")
|
||||
else
|
||||
redirect_to schedule_edit_schedule_path(params[:controller_id]), notice: "스케줄이 성공적으로 업데이트되었습니다."
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
def schedule_params
|
||||
params.require(:schedule).permit(:controller_id, :hour, :minute, :is_active, :temperature)
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user