On terms page link to filtered courses list
closes OUT-6556 flag=none Test plan: - Go to Account > Terms - Click on the Default term courses count link - verify that the query string id is correct and the courses are correctly filtered - On Terms page click on "+ Add new term" - Create a new term - Click on the courses count link - check the query string Change-Id: I69ee028c6954df573a930f59433d2792fc91bed1 Reviewed-on: https://gerrit.instructure.com/c/canvas-lms/+/353446 Tested-by: Service Cloud Jenkins <svc.cloudjenkins@instructure.com> Reviewed-by: Wilmer Corrales <wilmer.corrales@instructure.com> QA-Review: Wilmer Corrales <wilmer.corrales@instructure.com> Product-Review: Sam Garza <sam.garza@instructure.com>
This commit is contained in:
parent
c558a589a5
commit
1a7604bec7
|
@ -185,7 +185,7 @@ class TermsController < ApplicationController
|
|||
if api_request?
|
||||
enrollment_term_json(@term, @current_user, session, nil, ["overrides"])
|
||||
else
|
||||
@term.as_json(include: :enrollment_dates_overrides)
|
||||
@term.as_json(include: :enrollment_dates_overrides, methods: :filter_courses_by_term)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -20,7 +20,6 @@
|
|||
|
||||
class EnrollmentTerm < ActiveRecord::Base
|
||||
DEFAULT_TERM_NAME = "Default Term"
|
||||
|
||||
include Workflow
|
||||
|
||||
belongs_to :root_account, class_name: "Account"
|
||||
|
@ -202,6 +201,10 @@ class EnrollmentTerm < ActiveRecord::Base
|
|||
end
|
||||
end
|
||||
|
||||
def filter_courses_by_term
|
||||
"/accounts/#{root_account_id}?enrollment_term_id=#{id}"
|
||||
end
|
||||
|
||||
scope :active, -> { where("enrollment_terms.workflow_state<>'deleted'") }
|
||||
scope :ended, -> { where(enrollment_terms: { end_at: ...Time.now.utc }) }
|
||||
scope :started, -> { where("enrollment_terms.start_at IS NULL OR enrollment_terms.start_at < ?", Time.now.utc) }
|
||||
|
|
|
@ -38,7 +38,9 @@
|
|||
</span>
|
||||
</div>
|
||||
<% end %>
|
||||
<%= t(:course_count, "Course", :count => @course_counts_by_term[term&.id] || 0) %><br/>
|
||||
<a id="filter_link_<%= term&.id || "new" %>" class="filter_link" target="_blank" href="<%= context_url(@context, :account_url, enrollment_term_id: term&.id) %>">
|
||||
<%= t(:course_count, "Course", :count => @course_counts_by_term[term&.id] || 0) %>
|
||||
</a><br/>
|
||||
</div>
|
||||
<%= form_for (term || EnrollmentTerm.new), :url => (term ? context_url(@context, :context_term_url, term.id) : context_url(@context, :context_terms_url)), :html => {:class => "enrollment_term_form", :method => (term ? :put : :post)} do |f| %>
|
||||
<div class="control-group edit_term">
|
||||
|
|
|
@ -31,4 +31,16 @@ describe "terms_api/index" do
|
|||
page = Nokogiri("<document>" + response.body + "</document>")
|
||||
expect(page.css(".delete_term_link")[0]["class"]).to include("delete_term_link")
|
||||
end
|
||||
|
||||
it "creates a link to the courses belonging to that term" do
|
||||
assign(:context, assign(:root_account, Account.default))
|
||||
term = Account.default.enrollment_terms.create!
|
||||
terms = assign(:terms, Account.default.enrollment_terms.active.sort_by { |t| t.start_at || t.created_at }.reverse)
|
||||
assign(:course_counts_by_term, EnrollmentTerm.course_counts(terms))
|
||||
link_url = "/accounts/#{term.root_account_id}?enrollment_term_id=#{term.id}"
|
||||
render "terms_api/index"
|
||||
page = Nokogiri("<document>" + response.body + "</document>")
|
||||
expect(page.css("a#filter_link_#{term.id}").length).to eq 1
|
||||
expect(page.css("a#filter_link_#{term.id}")[0]["href"]).to eq link_url
|
||||
end
|
||||
end
|
||||
|
|
|
@ -151,9 +151,9 @@ $(document).ready(() => {
|
|||
$tr.fillTemplateData({data: term})
|
||||
$tr.attr('id', `term_${term.id}`)
|
||||
$tr.fillFormData(data, {object_name: 'enrollment_term'})
|
||||
|
||||
$tr.removeClass('editing_term')
|
||||
$('.edit_term_link', $tr).focus()
|
||||
$('#term_' + term.id + ' a.filter_link').prop('href', term.filter_courses_by_term)
|
||||
},
|
||||
|
||||
error(data) {
|
||||
|
|
Loading…
Reference in New Issue