-
Notifications
You must be signed in to change notification settings - Fork 45
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #65 from portabilis/portabilis-patch-2020-03-30
Portabilis patch 30/03/2021
- Loading branch information
Showing
57 changed files
with
412 additions
and
165 deletions.
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
Binary file not shown.
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 |
---|---|---|
@@ -1,59 1,75 @@ | ||
class DisciplineLessonPlanClonerForm < ActiveRecord::Base | ||
has_no_table | ||
|
||
attr_accessor :discipline_lesson_plan_id, :teacher | ||
attr_accessor :discipline_lesson_plan_id, :teacher, :entity_id | ||
|
||
validates :discipline_lesson_plan_id, presence: true | ||
has_many :discipline_lesson_plan_item_cloner_form | ||
accepts_nested_attributes_for :discipline_lesson_plan_item_cloner_form, allow_destroy: true | ||
|
||
def clone! | ||
if valid? | ||
begin | ||
ActiveRecord::Base.transaction do | ||
@classrooms = Classroom.where(id: discipline_lesson_plan_item_cloner_form.map(&:classroom_id).uniq) | ||
discipline_lesson_plan_item_cloner_form.each_with_index do |item, index| | ||
@current_item_index = index | ||
new_lesson_plan = discipline_lesson_plan.dup | ||
new_lesson_plan.teacher_id = teacher.id | ||
new_lesson_plan.lesson_plan = discipline_lesson_plan.lesson_plan.dup | ||
new_lesson_plan.lesson_plan.teacher = teacher | ||
new_lesson_plan.lesson_plan.original_contents = discipline_lesson_plan.lesson_plan.contents | ||
new_lesson_plan.lesson_plan.contents_created_at_position = {} | ||
new_lesson_plan.lesson_plan.original_contents.each_with_index do |content, position| | ||
new_lesson_plan.lesson_plan.contents_created_at_position[content.id] = position | ||
end | ||
|
||
new_lesson_plan.lesson_plan.original_objectives = discipline_lesson_plan.lesson_plan.objectives | ||
new_lesson_plan.lesson_plan.objectives_created_at_position = {} | ||
new_lesson_plan.lesson_plan.original_objectives.each_with_index do |objective, position| | ||
new_lesson_plan.lesson_plan.objectives_created_at_position[objective.id] = position | ||
end | ||
|
||
new_lesson_plan.lesson_plan.start_at = item.start_at | ||
new_lesson_plan.lesson_plan.end_at = item.end_at | ||
new_lesson_plan.lesson_plan.classroom = @classrooms.find_by_id(item.classroom_id) | ||
discipline_lesson_plan.lesson_plan.lesson_plan_attachments.each do |lesson_plan_attachment| | ||
new_lesson_plan.lesson_plan.lesson_plan_attachments << LessonPlanAttachment.new( | ||
attachment: lesson_plan_attachment.attachment | ||
) | ||
end | ||
new_lesson_plan.save! | ||
return unless valid? | ||
|
||
begin | ||
ActiveRecord::Base.transaction do | ||
@classrooms = Classroom.where(id: discipline_lesson_plan_item_cloner_form.map(&:classroom_id).uniq) | ||
discipline_lesson_plan_item_cloner_form.each_with_index do |item, index| | ||
@current_item_index = index | ||
new_lesson_plan = discipline_lesson_plan.dup | ||
new_lesson_plan.teacher_id = teacher.id | ||
new_lesson_plan.lesson_plan = discipline_lesson_plan.lesson_plan.dup | ||
new_lesson_plan.lesson_plan.teacher = teacher | ||
new_lesson_plan.lesson_plan.original_contents = discipline_lesson_plan.lesson_plan.contents | ||
new_lesson_plan.lesson_plan.contents_created_at_position = {} | ||
new_lesson_plan.lesson_plan.original_contents.each_with_index do |content, position| | ||
new_lesson_plan.lesson_plan.contents_created_at_position[content.id] = position | ||
end | ||
|
||
new_lesson_plan.lesson_plan.original_objectives = discipline_lesson_plan.lesson_plan.objectives | ||
new_lesson_plan.lesson_plan.objectives_created_at_position = {} | ||
new_lesson_plan.lesson_plan.original_objectives.each_with_index do |objective, position| | ||
new_lesson_plan.lesson_plan.objectives_created_at_position[objective.id] = position | ||
end | ||
|
||
new_lesson_plan.lesson_plan.start_at = item.start_at | ||
new_lesson_plan.lesson_plan.end_at = item.end_at | ||
new_lesson_plan.lesson_plan.classroom = @classrooms.find_by(id: item.classroom_id) | ||
|
||
original_attachments = {} | ||
discipline_lesson_plan.lesson_plan.lesson_plan_attachments.each do |lesson_plan_attachment| | ||
original_attachments[lesson_plan_attachment.attachment.filename] = lesson_plan_attachment.id | ||
new_lesson_plan.lesson_plan.lesson_plan_attachments << lesson_plan_attachment.dup | ||
end | ||
return true | ||
new_lesson_plan.save! | ||
|
||
copy_attachments(new_lesson_plan.id, original_attachments) | ||
end | ||
rescue ActiveRecord::RecordInvalid => e | ||
message = e.to_s | ||
message.slice!("A validação falhou: ") | ||
errors.add(:classroom_id, "Turma #{e.record.lesson_plan.try(:classroom)}: #{message}") | ||
discipline_lesson_plan_item_cloner_form[@current_item_index].errors.add(:classroom_id, message) | ||
return false | ||
|
||
return true | ||
end | ||
rescue ActiveRecord::RecordInvalid => e | ||
message = e.to_s | ||
message.slice!('A validação falhou: ') | ||
errors.add(:classroom_id, "Turma #{e.record.lesson_plan.try(:classroom)}: #{message}") | ||
discipline_lesson_plan_item_cloner_form[@current_item_index].errors.add(:classroom_id, message) | ||
|
||
return false | ||
end | ||
end | ||
|
||
def discipline_lesson_plan | ||
@discipline_lesson_plan ||= DisciplineLessonPlan.includes(lesson_plan: [:objectives, :contents]) | ||
.find(discipline_lesson_plan_id) | ||
end | ||
|
||
def copy_attachments(new_lesson_plan_id, original_attachments) | ||
return if new_lesson_plan_id.blank? || original_attachments.blank? | ||
|
||
LessonPlanAttachmentCopierWorker.perform_async( | ||
entity_id, | ||
new_lesson_plan_id, | ||
DisciplineLessonPlan, | ||
original_attachments | ||
) | ||
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 |
---|---|---|
@@ -1,62 1,78 @@ | ||
class KnowledgeAreaLessonPlanClonerForm < ActiveRecord::Base | ||
has_no_table | ||
|
||
attr_accessor :knowledge_area_lesson_plan_id, :teacher | ||
attr_accessor :knowledge_area_lesson_plan_id, :teacher, :entity_id | ||
|
||
validates :knowledge_area_lesson_plan_id, presence: true | ||
validates :knowledge_area_lesson_plan_id, presence: true | ||
has_many :knowledge_area_lesson_plan_item_cloner_form | ||
accepts_nested_attributes_for :knowledge_area_lesson_plan_item_cloner_form, :allow_destroy => true | ||
accepts_nested_attributes_for :knowledge_area_lesson_plan_item_cloner_form, allow_destroy: true | ||
|
||
def clone! | ||
if valid? | ||
begin | ||
ActiveRecord::Base.transaction do | ||
@classrooms = Classroom.where(id: knowledge_area_lesson_plan_item_cloner_form.map(&:classroom_id).uniq) | ||
knowledge_area_lesson_plan_item_cloner_form.each_with_index do |item, index| | ||
@current_item_index = index | ||
new_lesson_plan = knowledge_area_lesson_plan.dup | ||
new_lesson_plan.teacher_id = teacher.id | ||
new_lesson_plan.lesson_plan = knowledge_area_lesson_plan.lesson_plan.dup | ||
new_lesson_plan.lesson_plan.teacher = teacher | ||
new_lesson_plan.knowledge_areas = knowledge_area_lesson_plan.knowledge_areas | ||
new_lesson_plan.lesson_plan.original_contents = knowledge_area_lesson_plan.lesson_plan.contents | ||
new_lesson_plan.lesson_plan.contents_created_at_position = {} | ||
|
||
new_lesson_plan.lesson_plan.original_contents.each_with_index do |content, position| | ||
new_lesson_plan.lesson_plan.contents_created_at_position[content.id] = position | ||
end | ||
|
||
new_lesson_plan.lesson_plan.original_objectives = knowledge_area_lesson_plan.lesson_plan.objectives | ||
new_lesson_plan.lesson_plan.objectives_created_at_position = {} | ||
new_lesson_plan.lesson_plan.original_objectives.each_with_index do |objective, position| | ||
new_lesson_plan.lesson_plan.objectives_created_at_position[objective.id] = position | ||
end | ||
|
||
new_lesson_plan.lesson_plan.start_at = item.start_at | ||
new_lesson_plan.lesson_plan.end_at = item.end_at | ||
new_lesson_plan.lesson_plan.classroom = @classrooms.find_by_id(item.classroom_id) | ||
knowledge_area_lesson_plan.lesson_plan.lesson_plan_attachments.each do |lesson_plan_attachment| | ||
new_lesson_plan.lesson_plan.lesson_plan_attachments << LessonPlanAttachment.new( | ||
attachment: lesson_plan_attachment.attachment | ||
) | ||
end | ||
new_lesson_plan.save! | ||
return unless valid? | ||
|
||
begin | ||
ActiveRecord::Base.transaction do | ||
@classrooms = Classroom.where(id: knowledge_area_lesson_plan_item_cloner_form.map(&:classroom_id).uniq) | ||
knowledge_area_lesson_plan_item_cloner_form.each_with_index do |item, index| | ||
@current_item_index = index | ||
new_lesson_plan = knowledge_area_lesson_plan.dup | ||
new_lesson_plan.teacher_id = teacher.id | ||
new_lesson_plan.lesson_plan = knowledge_area_lesson_plan.lesson_plan.dup | ||
new_lesson_plan.lesson_plan.teacher = teacher | ||
new_lesson_plan.knowledge_areas = knowledge_area_lesson_plan.knowledge_areas | ||
new_lesson_plan.lesson_plan.original_contents = knowledge_area_lesson_plan.lesson_plan.contents | ||
new_lesson_plan.lesson_plan.contents_created_at_position = {} | ||
|
||
new_lesson_plan.lesson_plan.original_contents.each_with_index do |content, position| | ||
new_lesson_plan.lesson_plan.contents_created_at_position[content.id] = position | ||
end | ||
|
||
new_lesson_plan.lesson_plan.original_objectives = knowledge_area_lesson_plan.lesson_plan.objectives | ||
new_lesson_plan.lesson_plan.objectives_created_at_position = {} | ||
new_lesson_plan.lesson_plan.original_objectives.each_with_index do |objective, position| | ||
new_lesson_plan.lesson_plan.objectives_created_at_position[objective.id] = position | ||
end | ||
|
||
new_lesson_plan.lesson_plan.start_at = item.start_at | ||
new_lesson_plan.lesson_plan.end_at = item.end_at | ||
new_lesson_plan.lesson_plan.classroom = @classrooms.find_by(id: item.classroom_id) | ||
|
||
original_attachments = {} | ||
knowledge_area_lesson_plan.lesson_plan.lesson_plan_attachments.each do |lesson_plan_attachment| | ||
original_attachments[lesson_plan_attachment.attachment.filename] = lesson_plan_attachment.id | ||
new_lesson_plan.lesson_plan.lesson_plan_attachments << lesson_plan_attachment.dup | ||
end | ||
return true | ||
new_lesson_plan.save! | ||
|
||
copy_attachments(new_lesson_plan.id, original_attachments) | ||
end | ||
rescue ActiveRecord::RecordInvalid => e | ||
message = e.to_s | ||
message.slice!("A validação falhou: ") | ||
message.slice!("Áreas de conhecimento ") | ||
errors.add(:classroom_id, "Turma #{e.record.lesson_plan.try(:classroom)}: #{message}") | ||
knowledge_area_lesson_plan_item_cloner_form[@current_item_index].errors.add(:classroom_id, message) | ||
return false | ||
|
||
return true | ||
end | ||
rescue ActiveRecord::RecordInvalid => e | ||
message = e.to_s | ||
message.slice!('A validação falhou: ') | ||
message.slice!('Áreas de conhecimento ') | ||
errors.add(:classroom_id, "Turma #{e.record.lesson_plan.try(:classroom)}: #{message}") | ||
knowledge_area_lesson_plan_item_cloner_form[@current_item_index].errors.add(:classroom_id, message) | ||
|
||
return false | ||
end | ||
end | ||
|
||
def knowledge_area_lesson_plan | ||
@knowledge_area_lesson_plan ||= KnowledgeAreaLessonPlan.includes(lesson_plan: [:objectives, :contents]) | ||
.find(knowledge_area_lesson_plan_id) | ||
end | ||
|
||
def copy_attachments(new_lesson_plan_id, original_attachments) | ||
return if new_lesson_plan_id.blank? || original_attachments.blank? | ||
|
||
LessonPlanAttachmentCopierWorker.perform_async( | ||
entity_id, | ||
new_lesson_plan_id, | ||
KnowledgeAreaLessonPlan, | ||
original_attachments | ||
) | ||
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
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
Oops, something went wrong.