canvas-lms/app/services/course_pacing/pace_contexts_service.rb

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

53 lines
2.2 KiB
Ruby
Raw Normal View History

# frozen_string_literal: true
#
# Copyright (C) 2022 - present Instructure, Inc.
#
# This file is part of Canvas.
#
# Canvas is free software: you can redistribute it and/or modify it under
# the terms of the GNU Affero General Public License as published by the Free
# Software Foundation, version 3 of the License.
#
# Canvas is distributed in the hope that it will be useful, but WITHOUT ANY
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
# A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
# details.
#
# You should have received a copy of the GNU Affero General Public License along
# with this program. If not, see <http://www.gnu.org/licenses/>.
class CoursePacing::PaceContextsService
attr_reader :course
def initialize(course)
@course = course
end
def contexts_of_type(type, params: {})
case type
when "course"
[course]
when "section"
sections = course.active_course_sections
sections = sections.where("name ILIKE ?", "%#{params[:search_term]}%") if params[:search_term].present?
Inline loading spinner for background publishing jobs - A new loading spinner in the “Last Modified” column to indicate the pace is being published - Sync Redux with active pace publishing jobs on app initialization closes LS-3538, LS-3634 flag=course_paces_redesign test plan: 1- With the course_paces_redesign flag enabled 2- Create a course with several sections and students 3- Enable course pacing in the course and add a module 4- Go to the course pacing page and create the default pace 5- Notice the page does not get the blank space in the container, and the pace contexts table is immediately shown 6-Create a section pace and close the modal as soon as the close button gets enabled 7-Notice the spinner in the “last modified” column for the section you are publishing 8-Repeat steps 6 and 7 for students 9-Notice that when the jobs finish the affected rows get updated and an alert appears indicating the context and the action e.g. “Student 1 Pace created” - Sync on mount 1-Make the jobs get queued or take much time to complete 2-Create or update some paces 3-Notice the loading spinner for all of the paces 4-Notice that the spinners persist when switching between sections and students 5-Refresh the page and expect to see the loading spinner in the paces publishing Change-Id: Iccb923a780ed4423fac6ed5f33816b406bbf3119 Reviewed-on: https://gerrit.instructure.com/c/canvas-lms/+/307527 Tested-by: Service Cloud Jenkins <svc.cloudjenkins@instructure.com> Product-Review: Jonathan Guardado <jonathan.guardado@instructure.com> Reviewed-by: Robin Kuss <rkuss@instructure.com> QA-Review: Robin Kuss <rkuss@instructure.com>
2022-12-16 04:50:07 +08:00
sections = sections.where("id in ( ? )", JSON.parse(params[:contexts])) if params[:contexts].present?
sections = sections.order(params[:sort]) if params[:sort] == "name"
sections = sections.reverse_order if params[:order] == "desc"
sections
when "student_enrollment"
student_enrollments = course.all_real_student_enrollments.current_and_future.order(:user_id, created_at: :desc).select("DISTINCT ON(enrollments.user_id) enrollments.*")
student_enrollments = student_enrollments.joins(:user).where("users.name ILIKE ?", "%#{params[:search_term]}%") if params[:search_term].present?
student_enrollments = student_enrollments.joins(:user).where("enrollments.id in ( ? )", JSON.parse(params[:contexts])) if params[:contexts].present?
student_enrollments = student_enrollments.joins(:user).order("users.sortable_name") if params[:sort] == "name"
student_enrollments = student_enrollments.reverse_order if params[:order] == "desc"
student_enrollments.to_a
else
Canvas::Errors.capture_exception(
:pace_contexts_service,
"Expected a value of 'course', 'section', or 'student_enrollment', got '#{type}'"
)
end
end
end