Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 2 additions & 6 deletions app/controllers/classrooms_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,10 @@ def create
respond_to do |format|
if @classroom.save
@classroom.classroom_programs.reload.each(&:generate_modules!)
format.html { redirect_to school_classrooms_url(@school), notice: "Classroom was successfully created.", status: :see_other }
format.json { render json: @classroom, status: :created }
format.html { redirect_to school_path(@school, tab: "classrooms"), notice: "Classroom was successfully created.", status: :see_other }
else
build_missing_program_enrollments
format.html { render :new, status: :unprocessable_entity }
format.json { render json: @classroom.errors, status: :unprocessable_entity }
end
end
end
Expand All @@ -49,12 +47,10 @@ def update
respond_to do |format|
if @classroom.update(classroom_params)
@classroom.classroom_programs.reload.each(&:generate_modules!)
format.html { redirect_to school_students_url(@classroom.school), notice: "Classroom was successfully updated.", status: :see_other }
format.json { render :show, status: :ok, location: @classroom }
format.html { redirect_to school_path(@classroom.school, tab: "classrooms"), notice: "Classroom was successfully updated.", status: :see_other }
else
build_missing_program_enrollments
format.html { render :edit, status: :unprocessable_entity }
format.json { render json: @classroom.errors, status: :unprocessable_entity }
end
end
end
Expand Down
6 changes: 6 additions & 0 deletions app/controllers/schools_controller.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
class SchoolsController < AdminController
before_action :set_school, only: %i[ show edit update destroy ]
helper_method :school_show_tabs

# GET /schools or /schools.json
def index
Expand All @@ -8,6 +9,7 @@ def index

# GET /schools/1 or /schools/1.json
def show
@active_tab = school_show_tabs.include?(params[:tab]) ? params[:tab] : school_show_tabs.first
end

# GET /schools/new
Expand Down Expand Up @@ -59,6 +61,10 @@ def destroy

private

def school_show_tabs
%w[ students classrooms teachers ]
end

# Use callbacks to share common setup or constraints between actions.
def set_school
@school = School.find(params.expect(:id))
Expand Down
6 changes: 3 additions & 3 deletions app/controllers/students_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def create

respond_to do |format|
if @student.save
format.html { redirect_to school_students_url(@student.school_id), notice: "Student was successfully created." }
format.html { redirect_to school_url(@student.school_id, tab: "students"), notice: "Student was successfully created." }
else
format.html { render :new, status: :unprocessable_entity }
end
Expand All @@ -34,7 +34,7 @@ def create
def update
respond_to do |format|
if @student.update(student_params)
format.html { redirect_to school_students_url(@student.school_id), notice: "Student was successfully updated.", status: :see_other }
format.html { redirect_to school_url(@student.school_id, tab: "students"), notice: "Student was successfully updated.", status: :see_other }
else
format.html { render :edit, status: :unprocessable_entity }
end
Expand All @@ -46,7 +46,7 @@ def destroy
@student.destroy!

respond_to do |format|
format.html { redirect_to school_students_path(@student.school_id), notice: "Student was successfully destroyed.", status: :see_other }
format.html { redirect_to school_path(@student.school_id, tab: "students"), notice: "Student was successfully destroyed.", status: :see_other }
format.json { head :no_content }
end
end
Expand Down
15 changes: 4 additions & 11 deletions app/controllers/teachers_controller.rb
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
class TeachersController < AdminController
before_action :set_school, only: %i[index new create]
before_action :set_teacher, only: %i[show edit update destroy]
before_action :set_teacher, only: %i[edit update destroy]

def index
@teachers = @school.teachers
end

def show
end

def new
@teacher = @school.teachers.build
@classrooms = @school.classrooms
Expand All @@ -24,11 +21,9 @@ def create
@classrooms = @school.classrooms
respond_to do |format|
if @teacher.save
format.html { redirect_to @teacher, notice: "Teacher was successfully created." }
format.json { render :show, status: :created, location: @teacher }
format.html { redirect_to school_url(@school, tab: "teachers"), notice: "Teacher was successfully created." }
else
format.html { render :new, status: :unprocessable_entity }
format.json { render json: @teacher.errors, status: :unprocessable_entity }
end
end
end
Expand All @@ -39,11 +34,9 @@ def update

respond_to do |format|
if @teacher.update(teacher_params)
format.html { redirect_to @teacher, notice: "Teacher was successfully updated.", status: :see_other }
format.json { render :show, status: :ok, location: @teacher }
format.html { redirect_to school_url(@school, tab: "teachers"), notice: "Teacher was successfully updated.", status: :see_other }
else
format.html { render :edit, status: :unprocessable_entity }
format.json { render json: @teacher.errors, status: :unprocessable_entity }
end
end
end
Expand All @@ -52,7 +45,7 @@ def destroy
@teacher.destroy!

respond_to do |format|
format.html { redirect_to school_teachers_url(@teacher.school), notice: "Teacher was successfully destroyed.", status: :see_other }
format.html { redirect_to school_url(@teacher.school, tab: "teachers"), notice: "Teacher was successfully destroyed.", status: :see_other }
format.json { head :no_content }
end
end
Expand Down
3 changes: 1 addition & 2 deletions app/views/classrooms/edit.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@
<nav class="breadcrumbs text-sm">
<ul>
<li><%= link_to "All Schools", schools_path %></li>
<li><%= link_to @classroom.school.name, school_students_path(@classroom.school) %></li>
<li><%= link_to "Classrooms", school_classrooms_path(@classroom.school) %></li>
<li><%= link_to @classroom.school.name, school_path(@classroom.school, tab: "classrooms") %></li>
<li>Edit Classroom</li>
</ul>
</nav>
Expand Down
87 changes: 38 additions & 49 deletions app/views/classrooms/index.html.erb
Original file line number Diff line number Diff line change
@@ -1,53 +1,42 @@
<p style="color: green"><%= notice %></p>
<%= turbo_frame_tag dom_id(@school, :classrooms) do %>
<p style="color: green"><%= notice %></p>

<% content_for :title, [ @school.name, "Classrooms" ].join(" - ") %>
<header class="flex items-center justify-between mb-4">
<h2 class="text-xl">Classrooms</h2>
<%= link_to "New classroom", new_school_classroom_path(@school), data: { turbo_frame: "_top" }, class: "btn btn-primary" %>
</header>

<nav class="breadcrumbs text-sm">
<ul>
<li><%= link_to "All Schools", schools_path %></li>
<li><%= link_to @school.name, school_students_path(@school) %></li>
<li>Classrooms</li>
</ul>
</nav>

<header class="flex items-center justify-between mb-4">
<h1 class="text-2xl">Classrooms for <%= @school.name %></h1>
<div class="flex gap-2">
<%= link_to "Students", school_students_path(@school), class: "btn btn-ghost" %>
<%= link_to "New classroom", new_school_classroom_path(@school), class: "btn btn-primary" %>
</div>
</header>

<div class="overflow-x-auto rounded-box border border-base-content/5 bg-base-100">
<table id="classrooms" class="table">
<thead>
<tr>
<th>Name</th>
<th>Teacher</th>
<th>Programs</th>
<th>Students</th>
<th>Actions</th>
</tr>
</thead>
<tbody>
<% @classrooms.each do |classroom| %>
<div class="overflow-x-auto rounded-box border border-base-content/5 bg-base-100">
<table id="classrooms" class="table">
<thead>
<tr>
<td><%= classroom.name %></td>
<td><%= classroom.teacher&.name || "None assigned" %></td>
<td>
<% classroom.classroom_programs.each do |enrollment| %>
<span class="badge badge-ghost"><%= enrollment.program.name %> &middot; <%= enrollment.level.humanize %></span>
<% end %>
</td>
<td><%= classroom.students.size %></td>
<td>
<div class="flex gap-2">
<%= link_to "Edit", edit_classroom_path(classroom), class: "btn btn-primary" %>
<%= link_to "Schedule", schedule_classroom_path(classroom), class: "btn btn-ghost" %>
</div>
</td>
<th>Name</th>
<th>Teacher</th>
<th>Programs</th>
<th>Students</th>
<th>Actions</th>
</tr>
<% end %>
</tbody>
</table>
</div>
</thead>
<tbody>
<% @classrooms.each do |classroom| %>
<tr>
<td><%= classroom.name %></td>
<td><%= classroom.teacher&.name || "None assigned" %></td>
<td>
<% classroom.classroom_programs.each do |enrollment| %>
<span class="badge badge-ghost"><%= enrollment.program.name %> &middot; <%= enrollment.level.humanize %></span>
<% end %>
</td>
<td><%= classroom.students.size %></td>
<td>
<div class="flex gap-2">
<%= link_to "Edit", edit_classroom_path(classroom), data: { turbo_frame: "_top" }, class: "btn btn-primary" %>
<%= link_to "Schedule", schedule_classroom_path(classroom), data: { turbo_frame: "_top" }, class: "btn btn-ghost" %>
</div>
</td>
</tr>
<% end %>
</tbody>
</table>
</div>
<% end %>
3 changes: 1 addition & 2 deletions app/views/classrooms/new.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@
<nav class="breadcrumbs text-sm">
<ul>
<li><%= link_to "All Schools", schools_path %></li>
<li><%= link_to @school.name, school_students_path(@school) %></li>
<li><%= link_to "Classrooms", school_classrooms_path(@school) %></li>
<li><%= link_to @school.name, school_path(@school, tab: "classrooms") %></li>
<li>New Classroom</li>
</ul>
</nav>
Expand Down
5 changes: 2 additions & 3 deletions app/views/classrooms/schedule.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@
<nav class="breadcrumbs text-sm">
<ul>
<li><%= link_to "All Schools", schools_path %></li>
<li><%= link_to @classroom.school.name, school_students_path(@classroom.school) %></li>
<li><%= link_to "Classrooms", school_classrooms_path(@classroom.school) %></li>
<li><%= link_to @classroom.school.name, school_path(@classroom.school, tab: "classrooms") %></li>
<li><%= link_to "Edit Classroom", edit_classroom_path(@classroom) %></li>
<li>Schedule</li>
</ul>
Expand All @@ -16,7 +15,7 @@

<% if @classroom_programs.any? %>
<div role="tablist" class="tabs tabs-border mb-6">
<% @classroom_programs.each do |enrollment| %>
<% @classroom_programs.each do |enrollment| # herb:debug disable %>
<%= link_to schedule_classroom_path(@classroom, classroom_program_id: enrollment.id),
role: "tab",
aria: { selected: enrollment == @active_enrollment },
Expand Down
2 changes: 1 addition & 1 deletion app/views/content_modules/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
</header>

<div role="tablist" class="tabs tabs-border mb-6">
<% @programs.each do |program| %>
<% @programs.each do |program| # herb:debug disable %>
<%= link_to content_modules_path(program_id: program.id),
role: "tab",
aria: { selected: program == @active_program },
Expand Down
2 changes: 1 addition & 1 deletion app/views/schools/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<ul id="schools" class="list bg-base-100 rounded-box shadow-md">
<% @schools.each do |school| %>
<li class="list-row">
<%= link_to school.name, school_students_path(school), class: "link" %>
<%= link_to school.name, school_path(school), class: "link" %>
Comment thread
sean-dickinson marked this conversation as resolved.
</li>
<% end %>
</ul>
32 changes: 27 additions & 5 deletions app/views/schools/show.html.erb
Original file line number Diff line number Diff line change
@@ -1,11 +1,33 @@
<p style="color: green"><%= notice %></p>

<% content_for :title, @school.name %>
<h1><%= @school.name %></h1>

<div>
<%= link_to "Edit this school", edit_school_path(@school) %> |
<%= link_to "Back to schools", schools_path %>
<header class="flex items-center justify-between mb-4">
<h1 class="text-2xl"><%= @school.name %></h1>
<div class="flex gap-2">
<%= link_to "Edit this school", edit_school_path(@school), class: "btn btn-primary" %>
<%= button_to "Destroy this school", @school, method: :delete, class: "btn btn-error" %>
</div>
</header>

<%= button_to "Destroy this school", @school, method: :delete %>
<div role="tablist" class="tabs tabs-border mb-6">
<% school_show_tabs.each do |tab| # herb:debug disable %>
<%= link_to tab.titleize,
school_path(@school, tab: tab),
role: "tab",
aria: { selected: tab == @active_tab },
class: "tab #{"tab-active" if tab == @active_tab}" %>
<% end %>
</div>

<div class="<%= "hidden" unless @active_tab == "students" %>">
<%= turbo_frame_tag dom_id(@school, :students), src: school_students_path(@school), loading: :lazy %>
</div>

<div class="<%= "hidden" unless @active_tab == "classrooms" %>">
<%= turbo_frame_tag dom_id(@school, :classrooms), src: school_classrooms_path(@school), loading: :lazy %>
</div>

<div class="<%= "hidden" unless @active_tab == "teachers" %>">
<%= turbo_frame_tag dom_id(@school, :teachers), src: school_teachers_path(@school), loading: :lazy %>
</div>
2 changes: 1 addition & 1 deletion app/views/student_homes/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

<% if @classroom_programs.size > 1 %>
<div role="tablist" class="tabs tabs-border mb-6">
<% @classroom_programs.each do |enrollment| %>
<% @classroom_programs.each do |enrollment| # herb:debug disable %>
<%= link_to student_homes_path(classroom_program_id: enrollment.id),
role: "tab",
aria: { selected: enrollment == @active_program },
Expand Down
2 changes: 1 addition & 1 deletion app/views/students/edit.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<nav class="breadcrumbs text-sm">
<ul>
<li><%= link_to "All Schools", schools_path %></li>
<li><%= link_to @student.school.name, school_students_path(@student.school) %></li>
<li><%= link_to @student.school.name, school_path(@student.school, tab: "students") %></li>
<li>Edit Student</li>
</ul>
</nav>
Expand Down
Loading