forked from instructure/canvas-lms
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathalignments_helper.rb
50 lines (47 loc) · 1.36 KB
/
alignments_helper.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
module AlignmentsHelper
def link_to_outcome_alignment(context, outcome, alignment=nil)
html_class = [
"title"
]
html_class << "icon-#{alignment.content_type.downcase}" if alignment
link_to(alignment.try(:title) || nbsp, outcome_alignment_url(context, outcome, alignment), {
class: html_class
})
end
def outcome_alignment_tag(context, outcome, alignment=nil, &block)
options = {
id: "alignment_#{alignment.try(:id) || "blank"}",
class: [
"alignment",
alignment.try(:content_type_class),
alignment.try(:graded?) ? "also_assignment" : nil
].compact,
data: {
id: alignment.try(:id),
has_rubric_association: alignment.try(:has_rubric_association?),
url: outcome_alignment_url(
context, outcome, alignment
)
}.delete_if { |_, v|
!v.present?
}
}
options[:style] = hidden unless alignment
content_tag(:li, options, &block)
end
def outcome_alignment_url(context, outcome, alignment=nil)
if alignment.present?
[
context_prefix(alignment.context_code), "outcomes",
outcome.id, "alignments", alignment.id
].join('/')
elsif !context.is_a?(Account)
context_url(
context, :context_outcome_alignment_redirect_url,
outcome.id, "{{ id }}"
)
else
nil
end
end
end