-
Notifications
You must be signed in to change notification settings - Fork 8
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 #320 from cs169/main
CS169 Spring 2024 Final Changes
- Loading branch information
Showing
38 changed files
with
992 additions
and
92 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
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,55 @@ | ||
# frozen_string_literal: true | ||
|
||
class MergeController < ApplicationController | ||
before_action :require_admin | ||
|
||
def preview | ||
@from_teacher = Teacher.find(params[:from]) | ||
@into_teacher = Teacher.find(params[:into]) | ||
@result_teacher = merge_teachers(@from_teacher, @into_teacher) | ||
end | ||
|
||
def execute | ||
@from_teacher = Teacher.find(params[:from]) | ||
@into_teacher = Teacher.find(params[:into]) | ||
@merged_teacher = merge_teachers(@from_teacher, @into_teacher) | ||
|
||
merged_attributes = @merged_teacher.attributes.except("id") | ||
@into_teacher.update!(merged_attributes) | ||
@from_teacher.destroy | ||
redirect_to teachers_path, notice: "Teachers merged successfully." | ||
end | ||
|
||
private | ||
# Returns a merged teacher without saving it to the database. | ||
# Rendered in the preview, and only saved to the DB in a call to merge. | ||
def merge_teachers(from_teacher, into_teacher) | ||
merged_attributes = {} | ||
into_teacher.attributes.each do |attr_name, attr_value| | ||
from_teacher_attr_value = from_teacher.attributes[attr_name] | ||
if attr_value.blank? | ||
merged_attributes[attr_name] = from_teacher_attr_value | ||
elsif from_teacher_attr_value.blank? | ||
merged_attributes[attr_name] = attr_value | ||
else | ||
case attr_name | ||
when "session_count" | ||
merged_attributes[attr_name] = attr_value + from_teacher_attr_value | ||
when "ip_history" | ||
merged_attributes[attr_name] = (attr_value + from_teacher_attr_value).uniq | ||
when "last_session_at" | ||
# The resulting last session time is the most recent one | ||
merged_attributes[attr_name] = attr_value > from_teacher_attr_value ? attr_value : from_teacher_attr_value | ||
when "created_at" | ||
# The resulting record creation time is the least recent one | ||
merged_attributes[attr_name] = attr_value < from_teacher_attr_value ? attr_value : from_teacher_attr_value | ||
else | ||
merged_attributes[attr_name] = attr_value | ||
end | ||
end | ||
end | ||
|
||
merged_teacher = Teacher.new(merged_attributes) | ||
merged_teacher | ||
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,41 @@ | ||
/* Modal styling */ | ||
.merge_modal { | ||
display: none; /* Hide the modal by default */ | ||
position: fixed; | ||
z-index: 1000; /* Ensure modal appears on top of other elements */ | ||
left: 0; | ||
top: 0; | ||
width: 100%; | ||
height: 100%; | ||
overflow: auto; /* Enable scrolling if content exceeds the modal size */ | ||
background-color: rgba(0, 0, 0, 0.4); /* Semi-transparent black background */ | ||
} | ||
|
||
/* Modal content */ | ||
.merge_modal-content { | ||
background-color: #fefefe; | ||
margin: 15% auto; /* Center modal vertically and horizontally */ | ||
padding: 20px; /* You can increase the padding to add more hspace */ | ||
border: 1px solid #888; | ||
border-radius: 5px; | ||
width: 95%; /* You can adjust the width of the modal content as needed */ | ||
position: relative; /* Enable positioning of the close button */ | ||
} | ||
|
||
/* Close button */ | ||
.close { | ||
position: absolute; /* Position the close button absolutely */ | ||
top: 10px; /* Adjust this value to move the close button up or down */ | ||
right: 10px; /* Position the close button on the right side of the modal content */ | ||
color: #aaa; | ||
font-size: 28px; | ||
font-weight: bold; | ||
cursor: pointer; | ||
} | ||
|
||
.close:hover, | ||
.close:focus { | ||
color: black; | ||
text-decoration: none; | ||
cursor: pointer; | ||
} |
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.