Skip to content

Commit f522414

Browse files
authored
Merge pull request #1287 from ElixirTeSS/display-competency-levels
Display competency level more consistently
2 parents 9e582f0 + 2033bd5 commit f522414

12 files changed

Lines changed: 104 additions & 48 deletions

File tree

app/helpers/materials_helper.rb

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -50,17 +50,20 @@ def target_audience_title_for_label(label)
5050
TargetAudienceDictionary.instance.lookup_value(label, 'title') || label
5151
end
5252

53-
def display_difficulty_level(resource)
54-
value = resource.send('difficulty_level')
53+
def display_difficulty_level(value)
54+
data = DifficultyDictionary.instance.lookup(value)
55+
return nil if data.nil? || value == 'notspecified'
5556
if value == 'beginner'
56-
'• ' + value
57+
text = '• ' + data['title']
5758
elsif value == 'intermediate'
58-
'•• ' + value
59+
text = '•• ' + data['title']
5960
elsif value == 'advanced'
60-
'••• ' + value
61+
text = '••• ' + data['title']
6162
else
62-
''
63+
text = data['title']
6364
end
65+
66+
content_tag(:span, text, title: data['description'])
6467
end
6568

6669
def display_attribute(resource, attribute, show_label: true, title: nil, markdown: false, list: false, expandable: false)

app/views/common/_extra_metadata.html.erb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
<%= display_attribute(resource, :licence) { |value| licence_name_for_abbreviation(value) } if resource.respond_to?(:licence) %>
55
<%= display_attribute(resource, :contact) if resource.respond_to?(:contact) %>
66
<%= display_attribute(resource, :keywords) { |values| values.join(', ') } %>
7+
<%= display_attribute(resource, :difficulty_level) { |value| display_difficulty_level(value) } if resource.respond_to?(:difficulty_level) %>
78

89
<% if resource.is_a?(Material) %>
910
<%= display_attribute(resource, :fields) { |values| values.join(', ') } %>

app/views/learning_path_topics/_form.html.erb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
<!-- Field: Level -->
1212
<%= f.input :difficulty_level, collection: DifficultyDictionary.instance.options_for_select,
13-
label: 'Competency level', prompt: 'Select a difficulty level...',
13+
prompt: 'Select a difficulty level...',
1414
errors: @learning_path_topic.errors[:difficulty_level], input_html: { title: t('learning_paths.hints.difficulty') } %>
1515

1616

app/views/learning_path_topics/_learning_path_topic.html.erb

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,16 @@
11
<li class="masonry-brick media-item long">
22
<%= link_to learning_path_topic, class: 'link-overlay' do %>
3-
<h4><%= learning_path_topic.title %></h4>
3+
<div class="masonry-brick-heading">
4+
<h4><%= learning_path_topic.title %></h4>
5+
</div>
6+
7+
<div class="mb-3">
8+
<% competency = display_difficulty_level(learning_path_topic.difficulty_level) %>
9+
<% if competency %>
10+
<span class="label label-default"><%= competency %></span>
11+
<% end %>
12+
<span class="label label-default"><i class="fa fa-book"></i> <%= pluralize(learning_path_topic.materials.count, 'materials') %></span>
13+
</div>
414

515
<div class="markdown-description">
616
<%= render_sanitized_markdown truncate(learning_path_topic.description, length: 300, separator: ' ') %>

app/views/learning_path_topics/show.html.erb

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<div class="wrapper collapsing-wrapper">
22
<div class="collapsing-sidebar" id="sidebar">
3-
<h4 class="nav-heading">Topic</h4>
3+
<h4 class="nav-heading"><%= LearningPathTopic.model_name.human %></h4>
44
<div class="nav-block">
55
<h5>
66
<%= @learning_path_topic.title %>
@@ -11,15 +11,24 @@
1111
</div>
1212
<% end %>
1313
</div>
14-
<h4 class="nav-heading">Keywords</h4>
14+
<h4 class="nav-heading"><%= LearningPathTopic.human_attribute_name(:keywords) %></h4>
1515
<div class="nav-block">
1616
<% if @learning_path_topic.keywords.any? %>
1717
<%= @learning_path_topic.keywords.join(', ') %>
1818
<% else %>
1919
<span class="empty">None</span>
2020
<% end %>
2121
</div>
22-
<h4 class="nav-heading">Owner</h4>
22+
<h4 class="nav-heading"><%= LearningPathTopic.human_attribute_name(:difficulty_level) %></h4>
23+
<div class="nav-block">
24+
<% competency = display_difficulty_level(@learning_path_topic.difficulty_level) %>
25+
<% if competency.present? %>
26+
<span class="label label-default"><%= competency %></span>
27+
<% else %>
28+
<span class="empty">Not specified</span>
29+
<% end %>
30+
</div>
31+
<h4 class="nav-heading"><%= LearningPathTopic.human_attribute_name(:owner) %></h4>
2332
<div class="nav-block">
2433
<%= link_to @learning_path_topic.user.name, @learning_path_topic.user %>
2534
</div>

app/views/learning_paths/_form.html.erb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,12 @@
5555
<%= f.multi_input :target_audience, label: 'Target audiences', errors: @learning_path.errors[:target_audience],
5656
title: t('events.hints.targets'), visibility_toggle: TeSS::Config.feature['learning_paths_disabled'] %>
5757

58+
<!-- Field: Level -->
59+
<%= f.input :difficulty_level, collection: DifficultyDictionary.instance.options_for_select,
60+
prompt: 'Select a difficulty level...',
61+
errors: @learning_path.errors[:difficulty_level], input_html: { title: t('learning_paths.hints.difficulty') },
62+
visibility_toggle: TeSS::Config.feature['learning_paths_disabled'] %>
63+
5864
<!-- Field: Prerequisites -->
5965
<%= f.input :prerequisites, as: :markdown_area,
6066
input_html: { rows: '3', title: t('learning_paths.hints.prerequisites') },
Lines changed: 40 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,47 @@
1-
<li class="masonry-brick media-item large block-item learning-path-bg-<%= (learning_path.id % 4) + 1 -%>">
2-
<%= link_to learning_path, class: 'link-overlay' do %>
3-
<%= item_order_badge(collection_item) if defined? collection_item %>
1+
<% cache(learning_path, expires_in: 1.hour) do %>
2+
<li class="masonry-brick media-item large block-item learning-path-bg-<%= (learning_path.id % 4) + 1 -%>">
3+
<%= link_to learning_path, class: 'link-overlay' do %>
4+
<%= item_order_badge(collection_item) if defined? collection_item %>
45

5-
<div class="masonry-brick-heading">
6-
<div class="masonry-icons">
7-
<% if current_user&.is_admin? %>
8-
<%= missing_icon(learning_path) %>
9-
<%= scrape_status_icon(learning_path) %>
10-
<%= suggestion_icon(learning_path) %>
11-
<% end %>
12-
</div>
13-
<div class="sub-heading">
14-
<%= display_attribute_no_label(learning_path, :learning_path_type) %>
15-
</div>
16-
<h4 class="mb-3"><%= learning_path.title %></h4>
17-
</div>
6+
<div class="masonry-brick-heading">
7+
<div class="masonry-icons">
8+
<% if current_user&.is_admin? %>
9+
<%= missing_icon(learning_path) %>
10+
<%= scrape_status_icon(learning_path) %>
11+
<%= suggestion_icon(learning_path) %>
12+
<% end %>
13+
</div>
14+
<div class="sub-heading">
15+
<%= display_attribute_no_label(learning_path, :learning_path_type) %>
16+
</div>
17+
<h4 class="mb-3"><%= learning_path.title %></h4>
18+
<%= rand %>
1819

19-
<div class="clearfix">
20-
<div class="pull-right">
21-
<% if controller_name != 'content_providers' && learning_path.content_provider %>
22-
<%= image_tag(learning_path.content_provider.image.url, class: 'provider-avatar') %>
23-
<% end %>
2420
</div>
2521

26-
<div>
27-
<span class="label label-default"><i class="fa fa-folder-open"></i> <%= pluralize(learning_path.topics.count, 'topic') %></span>
28-
<span class="label label-default"><i class="fa fa-book"></i> <%= pluralize(learning_path.topics_materials.count, 'materials') %></span>
29-
</div>
22+
<div class="clearfix">
23+
<div class="pull-right">
24+
<% if controller_name != 'content_providers' && learning_path.content_provider %>
25+
<%= image_tag(learning_path.content_provider.image.url, class: 'provider-avatar') %>
26+
<% end %>
27+
</div>
3028

31-
<div>
32-
<%= keywords_and_topics(learning_path, limit: 10) %>
29+
<div>
30+
<% competency = display_difficulty_level(learning_path.difficulty_level) %>
31+
<% if competency %>
32+
<span class="label label-default"><%= competency %></span>
33+
<% end %>
34+
<span class="label label-default"><i class="fa fa-folder-open"></i> <%= pluralize(learning_path.topics.count, 'topic') %></span>
35+
<span class="label label-default"><i class="fa fa-book"></i> <%= pluralize(learning_path.topics_materials.count, 'materials') %></span>
36+
</div>
37+
38+
<div>
39+
<%= keywords_and_topics(learning_path, limit: 10) %>
40+
</div>
3341
</div>
34-
</div>
3542

36-
<%= item_comment(collection_item) if defined? collection_item %>
37-
<% end %>
38-
</li>
43+
<%= item_comment(collection_item) if defined? collection_item %>
44+
<% end %>
45+
</li>
46+
<% end %>
47+

app/views/learning_paths/show.html.erb

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,9 @@
6666
<div class="learning-path-topic-order"><%= lpt.order %></div>
6767
<div class="learning-path-topic-title">
6868
<h4><%= lpt.topic.title %> <i class="icon icon-md expand-icon"></i></h4>
69-
<% if lpt.topic.difficulty_level.present? %>
70-
<span class="label label-default"><%= display_difficulty_level(lpt.topic) %></span>
69+
<% competency = display_difficulty_level(lpt.topic.difficulty_level) %>
70+
<% if competency %>
71+
<span class="label label-default"><%= competency %></span>
7172
<% end %>
7273
<span class="label label-default">
7374
<i class="fa fa-book"></i> <%= pluralize(lpt.topic.material_items.count, 'material') %>

app/views/materials/_form.html.erb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@
9393

9494
<!-- Field: Level -->
9595
<%= f.input :difficulty_level, collection: DifficultyDictionary.instance.options_for_select,
96-
label: 'Competency level', prompt: 'Select a difficulty level...', field_lock: true,
96+
prompt: 'Select a difficulty level...', field_lock: true,
9797
errors: @material.errors[:difficulty_level], input_html: { title: t('materials.hints.difficulty') },
9898
visibility_toggle: TeSS::Config.feature['materials_disabled'] %>
9999

app/views/materials/_material.html.erb

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,10 @@
3434
<% end %>
3535
</div>
3636

37-
<div class="font-size-lg"><%= display_difficulty_level(material) %></div>
37+
<% competency = display_difficulty_level(material.difficulty_level) %>
38+
<% if competency %>
39+
<div class="font-size-lg"><%= competency %></div>
40+
<% end %>
3841

3942
<%= keywords_and_topics(material, limit: 10) %>
4043
</div>

0 commit comments

Comments
 (0)