Skip to content

Commit

Permalink
semesters to planner
Browse files Browse the repository at this point in the history
  • Loading branch information
santiagoguridi committed Jan 15, 2025
1 parent b7c4ba7 commit 54a107e
Show file tree
Hide file tree
Showing 9 changed files with 83 additions and 39 deletions.
9 changes: 5 additions & 4 deletions app/controllers/planned_subjects_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ def index
end

def create
current_user.planned_subjects.create(subject_id: params[:subject_id])
current_user.planned_subjects.create(subject_id: params[:subject_id], semester: params[:semester])

redirect_to planned_subjects_path
end
Expand All @@ -26,8 +26,9 @@ def ensure_feature_enabled!
end

def set_planned_and_not_planned_subjects
@planned_subjects, @not_planned_subjects = TreePreloader.new.preload.partition do |subject|
current_student.approved?(subject) || current_user.planned?(subject)
end
@planned_subjects = current_user.planned_subjects.includes(:subject).order(:semester)
@not_planned_approved_subjects, @not_planned_subjects = TreePreloader.new.preload.reject { |subject|
current_user.planned?(subject)
}.partition { |subject| current_student.approved?(subject) }
end
end
15 changes: 15 additions & 0 deletions app/helpers/subjects_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,21 @@ def formatted_category(category)
end
end

def semester_display_name(semester)
case semester
when 1 then 'Primer semestre'
when 2 then 'Segundo semestre'
when 3 then 'Tercer semestre'
when 4 then 'Cuarto semestre'
when 5 then 'Quinto semestre'
when 6 then 'Sexto semestre'
when 7 then 'Séptimo semestre'
when 8 then 'Octavo semestre'
when 9 then 'Noveno semestre'
when 10 then 'Décimo semestre'
end
end

def display_name(subject)
"#{subject.code} - #{subject.short_name || subject.name}"
end
Expand Down
10 changes: 7 additions & 3 deletions app/javascript/controllers/autosave_check_controller.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
import { Controller } from "@hotwired/stimulus"
import { Turbo } from "@hotwired/turbo-rails"
import { Controller } from "@hotwired/stimulus";
import { Turbo } from "@hotwired/turbo-rails";

export default class extends Controller {
update(e) {
e.preventDefault();
Turbo.navigator.submitForm(this.element)
Turbo.navigator.submitForm(this.element);
}

stopPropagation(e) {
e.preventDefault();
}
}
6 changes: 1 addition & 5 deletions app/views/planned_subjects/_credits_counter.html.erb
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
<div class="mdc-deprecated-list-group__subheader mdc-typography--subtitle2">
<strong> Créditos actuales:</strong> <%= current_student.total_credits %>
</div>

<div class="mdc-deprecated-list-group__subheader mdc-typography--subtitle2">
<% planned_approvable_ids = planned_subjects.map { |subject| [subject.course.id, subject.exam&.id] }.flatten.compact %>
<% planned_approvable_ids = planned_subjects.map { |planned_subject| [planned_subject.subject.course.id, planned_subject.subject.exam&.id] }.flatten.compact %>
<strong> Créditos planeados:</strong> <%= Subject.approved_credits(planned_approvable_ids) %>
</div>
19 changes: 14 additions & 5 deletions app/views/planned_subjects/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,23 @@
<% end %>

<div class="mdc-deprecated-list-group subjects-list">
<h3 class="mdc-deprecated-list-group__subheader mdc-typography--subtitle2">
Materias planeadas
</h3>
<div class="subject-group-header">
<h3 class="mdc-deprecated-list-group__subheader mdc-typography--subtitle2">
Materias planeadas
</h3>
<%= render partial: "credits_counter", locals: { planned_subjects: @planned_subjects } %>
</div>

<%= render partial: "subjects/planned_subjects_list", locals: { subjects: @planned_subjects } %>
<%= render partial: "subjects/planned_subjects_list", locals: { planned_subjects: @planned_subjects } %>

<hr class="mdc-deprecated-list-divider">

<%= render partial: "credits_counter", locals: { planned_subjects: @planned_subjects } %>
<% if @not_planned_approved_subjects.any? %>
<h3 class="mdc-deprecated-list-group__subheader mdc-typography--subtitle2">Materias aprobadas sin semestre asignado</h3>

<%= render partial: "subjects/not_planned_subjects_list", locals: { subjects: @not_planned_approved_subjects } %>
<% end %>

<hr class="mdc-deprecated-list-divider">

<h3 class="mdc-deprecated-list-group__subheader mdc-typography--subtitle2">
Expand Down
5 changes: 5 additions & 0 deletions app/views/subjects/_not_planned_subjects_list.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@
class: 'd-flex',
local: false
) do |form| %>
<select name="semester" data-action="click->autosave-check#stopPropagation">
<% (1..10).each do |semester| %>
<option value="<%= semester %>"> Sem. <%= semester %></option>
<% end %>
</select>
<span class="mdc-deprecated-list-item__meta material-icons" data-action="click->autosave-check#update">add_circle_outline</button>
<% end %>
<% end %>
Expand Down
50 changes: 29 additions & 21 deletions app/views/subjects/_planned_subjects_list.html.erb
Original file line number Diff line number Diff line change
@@ -1,25 +1,33 @@
<div class="mdc-deprecated-list">
<% subjects.each do |subject| %>
<%= link_to subject_path(subject), :class => "mdc-deprecated-list-item" do %>
<span class="mdc-deprecated-list-item__ripple"></span>
<span class="mdc-deprecated-list-item__text">
<%= display_name(subject) %>
</span>
<% if current_student.approved?(subject) %>
<span class="mdc-deprecated-list-item__meta material-icons">done</span>
<% else %>
<%= form_with(
model: subject,
url: planned_subject_path(subject_id: subject.id),
method: :delete,
data: { controller: "autosave-check" },
class: 'd-flex',
locale: false,
) do |form| %>
<span class="mdc-deprecated-list-item__meta material-icons" data-action="click->autosave-check#update">remove_circle_outline</span>
<% end %>
<% if !current_student.available?(subject) %>
<span class="mdc-deprecated-list-item__meta material-icons">lock</span>
<% planned_subjects.group_by(&:semester).each do |semester, planned_subjects| %>
<div class="subject-group-header">
<h3 class="mdc-deprecated-list-group__subheader mdc-typography--subtitle2">
<%= semester_display_name(semester) %>
</h3>
<%= render partial: "credits_counter", locals: { planned_subjects: planned_subjects } %>
</div>
<% planned_subjects.each do |planned_subject| %>
<%= link_to subject_path(planned_subject.subject), :class => "mdc-deprecated-list-item" do %>
<span class="mdc-deprecated-list-item__ripple"></span>
<span class="mdc-deprecated-list-item__text">
<%= display_name(planned_subject.subject) %>
</span>
<% if current_student.approved?(planned_subject.subject) %>
<span class="mdc-deprecated-list-item__meta material-icons">done</span>
<% else %>
<%= form_with(
model: planned_subject.subject,
url: planned_subject_path(subject_id: planned_subject.subject.id),
method: :delete,
data: { controller: "autosave-check" },
class: 'd-flex',
locale: false,
) do |form| %>
<span class="mdc-deprecated-list-item__meta material-icons" data-action="click->autosave-check#update">remove_circle_outline</span>
<% end %>
<% if !current_student.available?(planned_subject.subject) %>
<span class="mdc-deprecated-list-item__meta material-icons">lock</span>
<% end %>
<% end %>
<% end %>
<% end %>
Expand Down
5 changes: 5 additions & 0 deletions db/migrate/20241228220307_add_semester_to_planned_subjects.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class AddSemesterToPlannedSubjects < ActiveRecord::Migration[8.0]
def change
add_column :planned_subjects, :semester, :integer
end
end
3 changes: 2 additions & 1 deletion db/schema.rb

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 54a107e

Please sign in to comment.