mumuki-laboratory 5.5.0 → 5.6.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (149) hide show
  1. checksums.yaml +4 -4
  2. data/app/assets/javascripts/application/discussions.js +43 -0
  3. data/app/assets/stylesheets/application/_modules.scss +2 -0
  4. data/app/assets/stylesheets/application/modules/_checkboxes.scss +21 -8
  5. data/app/assets/stylesheets/application/modules/_discussion.scss +339 -0
  6. data/app/assets/stylesheets/application/modules/_pagination.scss +10 -0
  7. data/app/controllers/application_controller.rb +4 -9
  8. data/app/controllers/book_discussions_controller.rb +7 -0
  9. data/app/controllers/chapters_controller.rb +2 -0
  10. data/app/controllers/discussions_controller.rb +65 -0
  11. data/app/controllers/discussions_messages_controller.rb +25 -0
  12. data/app/controllers/exercises_controller.rb +1 -0
  13. data/app/controllers/guide_container_controller.rb +1 -0
  14. data/app/controllers/messages_controller.rb +1 -1
  15. data/app/controllers/users_controller.rb +1 -0
  16. data/app/helpers/application_helper.rb +7 -0
  17. data/app/helpers/assignment_result_helper.rb +10 -30
  18. data/app/helpers/breadcrumbs_helper.rb +7 -3
  19. data/app/helpers/contextualization_result_helper.rb +31 -0
  20. data/app/helpers/discussions_helper.rb +163 -0
  21. data/app/helpers/exercise_input_helper.rb +33 -5
  22. data/app/helpers/icons_helper.rb +20 -3
  23. data/app/helpers/messages_helper.rb +4 -0
  24. data/app/helpers/status_helper.rb +2 -2
  25. data/app/models/assignment.rb +31 -47
  26. data/app/models/book.rb +3 -0
  27. data/app/models/chapter.rb +2 -0
  28. data/app/models/concerns/contextualization.rb +85 -0
  29. data/app/models/concerns/submittable/solvable.rb +1 -0
  30. data/app/models/concerns/with_assignments.rb +1 -1
  31. data/app/models/concerns/with_discussion_creation.rb +9 -0
  32. data/app/models/concerns/with_discussion_creation/subscription.rb +33 -0
  33. data/app/models/concerns/with_discussion_creation/upvote.rb +28 -0
  34. data/app/models/concerns/with_discussion_status.rb +11 -0
  35. data/app/models/concerns/with_discussions.rb +23 -0
  36. data/app/models/concerns/with_randomizations.rb +34 -0
  37. data/app/models/concerns/with_scoped_queries.rb +47 -0
  38. data/app/models/concerns/with_scoped_queries/filter.rb +15 -0
  39. data/app/models/concerns/with_scoped_queries/page.rb +10 -0
  40. data/app/models/concerns/with_scoped_queries/sort.rb +47 -0
  41. data/app/models/discussion.rb +128 -0
  42. data/app/models/exercise.rb +10 -1
  43. data/app/models/guide.rb +1 -1
  44. data/app/models/message.rb +24 -3
  45. data/app/models/organization.rb +4 -0
  46. data/app/models/submission/confirmation.rb +1 -1
  47. data/app/models/submission/console_submission.rb +1 -1
  48. data/app/models/submission/submission.rb +13 -0
  49. data/app/models/subscription.rb +12 -0
  50. data/app/models/topic.rb +1 -1
  51. data/app/models/upvote.rb +4 -0
  52. data/app/models/user.rb +3 -2
  53. data/app/views/book_discussions/index.html.erb +23 -0
  54. data/app/views/chapters/show.html.erb +0 -1
  55. data/app/views/discussions/_message.html.erb +22 -0
  56. data/app/views/discussions/_message_container.html.erb +8 -0
  57. data/app/views/discussions/_new_message.html.erb +19 -0
  58. data/app/views/discussions/index.html.erb +30 -0
  59. data/app/views/discussions/show.html.erb +76 -0
  60. data/app/views/exercise_solutions/_contextualization_results.html.erb +21 -0
  61. data/app/views/exercise_solutions/_contextualization_results_container.html.erb +4 -0
  62. data/app/views/exercise_solutions/_expectations.html.erb +9 -3
  63. data/app/views/exercise_solutions/_kids_results.html.erb +1 -1
  64. data/app/views/exercise_solutions/_results.html.erb +21 -55
  65. data/app/views/exercise_solutions/_results_title.html.erb +2 -2
  66. data/app/views/exercises/_exercise_assignment.html.erb +20 -0
  67. data/app/views/exercises/_read_only.html.erb +104 -0
  68. data/app/views/exercises/show.html.erb +4 -20
  69. data/app/views/layouts/_discussions.html.erb +68 -0
  70. data/app/views/layouts/_kids.html.erb +9 -6
  71. data/app/views/layouts/_messages.html.erb +1 -1
  72. data/app/views/layouts/_result.html.erb +2 -2
  73. data/app/views/layouts/_test_results.html.erb +6 -6
  74. data/app/views/layouts/application.html.erb +10 -9
  75. data/app/views/layouts/exercise_inputs/forms/_form.html.erb +5 -6
  76. data/app/views/layouts/exercise_inputs/forms/_interactive_form.html.erb +5 -5
  77. data/app/views/layouts/exercise_inputs/forms/_kids_form.html.erb +9 -17
  78. data/app/views/layouts/exercise_inputs/forms/_playground_form.html.erb +5 -5
  79. data/app/views/layouts/exercise_inputs/forms/_problem_form.html.erb +11 -11
  80. data/app/views/layouts/exercise_inputs/forms/_reading_form.html.erb +1 -1
  81. data/app/views/layouts/exercise_inputs/layouts/_input_bottom.html.erb +1 -1
  82. data/app/views/layouts/exercise_inputs/layouts/_input_kids.html.erb +7 -7
  83. data/app/views/layouts/exercise_inputs/layouts/_input_right.html.erb +1 -1
  84. data/app/views/layouts/exercise_inputs/read_only_editors/_code.html.erb +3 -0
  85. data/app/views/layouts/exercise_inputs/read_only_editors/_custom.html.erb +6 -0
  86. data/app/views/layouts/exercise_inputs/read_only_editors/_multiple_choice.html.erb +8 -0
  87. data/app/views/layouts/exercise_inputs/read_only_editors/_single_choice.html.erb +8 -0
  88. data/app/views/layouts/modals/_kids_context.html.erb +2 -2
  89. data/app/views/layouts/modals/_new_discussion.html.erb +27 -0
  90. data/app/views/users/show.html.erb +23 -3
  91. data/config/routes.rb +21 -1
  92. data/db/migrate/20180504173548_create_discussions.rb +12 -0
  93. data/db/migrate/20180504185845_add_discussion_id_to_message.rb +5 -0
  94. data/db/migrate/20180605143727_add_submission_to_discussion.rb +16 -0
  95. data/db/migrate/20180619182555_create_subscriptions.rb +9 -0
  96. data/db/migrate/20180702153442_create_upvotes.rb +8 -0
  97. data/db/migrate/20180702175220_add_upvotes_count_to_discussions.rb +5 -0
  98. data/db/migrate/20180704150839_rename_assignment_status_to_submission_status.rb +5 -0
  99. data/lib/mumuki/laboratory.rb +2 -0
  100. data/lib/mumuki/laboratory/controllers.rb +2 -1
  101. data/lib/mumuki/laboratory/controllers/content.rb +12 -0
  102. data/lib/mumuki/laboratory/controllers/notifications.rb +31 -0
  103. data/lib/mumuki/laboratory/controllers/results_rendering.rb +1 -1
  104. data/lib/mumuki/laboratory/engine.rb +0 -2
  105. data/lib/mumuki/laboratory/evaluation/manual.rb +1 -1
  106. data/lib/mumuki/laboratory/locales/en.yml +37 -1
  107. data/lib/mumuki/laboratory/locales/es.yml +42 -1
  108. data/lib/mumuki/laboratory/locales/pt.yml +33 -1
  109. data/lib/mumuki/laboratory/status.rb +51 -44
  110. data/lib/mumuki/laboratory/status/discussion/closed.rb +15 -0
  111. data/lib/mumuki/laboratory/status/discussion/discussion.rb +56 -0
  112. data/lib/mumuki/laboratory/status/discussion/opened.rb +27 -0
  113. data/lib/mumuki/laboratory/status/discussion/pending_review.rb +15 -0
  114. data/lib/mumuki/laboratory/status/discussion/solved.rb +19 -0
  115. data/lib/mumuki/laboratory/status/submission/aborted.rb +11 -0
  116. data/lib/mumuki/laboratory/status/submission/errored.rb +15 -0
  117. data/lib/mumuki/laboratory/status/{failed.rb → submission/failed.rb} +2 -2
  118. data/lib/mumuki/laboratory/status/submission/manual_evaluation_pending.rb +15 -0
  119. data/lib/mumuki/laboratory/status/{passed.rb → submission/passed.rb} +2 -2
  120. data/lib/mumuki/laboratory/status/{passed_with_warnings.rb → submission/passed_with_warnings.rb} +2 -2
  121. data/lib/mumuki/laboratory/status/submission/pending.rb +11 -0
  122. data/lib/mumuki/laboratory/status/submission/running.rb +11 -0
  123. data/lib/mumuki/laboratory/status/submission/submission.rb +49 -0
  124. data/lib/mumuki/laboratory/status/{unknown.rb → submission/unknown.rb} +2 -2
  125. data/lib/mumuki/laboratory/version.rb +1 -1
  126. data/spec/controllers/chapters_controller_spec.rb +17 -0
  127. data/spec/controllers/discussions_controller_spec.rb +19 -0
  128. data/spec/dummy/config/environments/development.rb +0 -2
  129. data/spec/dummy/config/environments/test.rb +0 -2
  130. data/spec/dummy/db/schema.rb +42 -2
  131. data/spec/evaluation_helper.rb +1 -1
  132. data/spec/factories/discussion_factory.rb +8 -0
  133. data/spec/features/dynamic_exam_spec.rb +1 -1
  134. data/spec/helpers/exercise_input_helper_spec.rb +25 -0
  135. data/spec/helpers/test_results_rendering_spec.rb +7 -7
  136. data/spec/models/assignment_spec.rb +17 -2
  137. data/spec/models/discussion_spec.rb +153 -0
  138. metadata +108 -27
  139. data/app/models/concerns/with_status.rb +0 -43
  140. data/app/models/status_rendering_verbosity.rb +0 -40
  141. data/lib/mumuki/laboratory/controllers/messages.rb +0 -9
  142. data/lib/mumuki/laboratory/status/aborted.rb +0 -7
  143. data/lib/mumuki/laboratory/status/base.rb +0 -47
  144. data/lib/mumuki/laboratory/status/errored.rb +0 -15
  145. data/lib/mumuki/laboratory/status/manual_evaluation_pending.rb +0 -15
  146. data/lib/mumuki/laboratory/status/pending.rb +0 -11
  147. data/lib/mumuki/laboratory/status/running.rb +0 -11
  148. data/spec/models/randomizer_spec.rb +0 -18
  149. data/spec/models/verbosity_spec.rb +0 -24
@@ -5,7 +5,7 @@ class ApplicationController < ActionController::Base
5
5
  include Mumukit::Login::AuthenticationHelpers
6
6
 
7
7
  include Mumuki::Laboratory::Controllers::Authorization
8
- include Mumuki::Laboratory::Controllers::Messages
8
+ include Mumuki::Laboratory::Controllers::Notifications
9
9
  include Mumuki::Laboratory::Controllers::DynamicErrors
10
10
 
11
11
  before_action :set_current_organization!
@@ -13,12 +13,12 @@ class ApplicationController < ActionController::Base
13
13
  before_action :redirect_to_main_organization!, if: :should_redirect_to_main_organization?
14
14
  before_action :authorize_if_private!
15
15
  before_action :validate_user_profile!, if: :current_user?
16
- before_action :validate_used_here!
17
16
  before_action :visit_organization!, if: :current_user?
18
17
 
19
18
  helper_method :login_button,
20
- :messages_count,
21
- :has_messages?,
19
+ :notifications_count,
20
+ :user_notifications_path,
21
+ :has_notifications?,
22
22
  :subject,
23
23
  :should_choose_organization?,
24
24
  :theme_stylesheet_url,
@@ -38,11 +38,6 @@ class ApplicationController < ActionController::Base
38
38
  Mumukit::Platform.implicit_organization?(request)
39
39
  end
40
40
 
41
- # ensures contents are in current organization's path
42
- def validate_used_here!
43
- raise Mumuki::Laboratory::NotFoundError if subject && !subject.used_in?(Organization.current)
44
- end
45
-
46
41
  # ensures contents are accessible to current user
47
42
  def validate_accessible!
48
43
  accessible_subject.validate_accessible_for!(current_user) unless (current_user? && current_user.teacher_here?)
@@ -0,0 +1,7 @@
1
+ class BookDiscussionsController < DiscussionsController
2
+ private
3
+
4
+ def set_debatable
5
+ @debatable = Organization.current.book
6
+ end
7
+ end
@@ -1,6 +1,8 @@
1
1
  require 'addressable/uri'
2
2
 
3
3
  class ChaptersController < ApplicationController
4
+ include Mumuki::Laboratory::Controllers::Content
5
+
4
6
  def show
5
7
  end
6
8
 
@@ -0,0 +1,65 @@
1
+ class DiscussionsController < AjaxController
2
+ include Mumuki::Laboratory::Controllers::Content
3
+
4
+ before_action :set_debatable, except: [:subscription]
5
+ before_action :authenticate!, only: [:update, :create]
6
+ before_action :discussion_filter_params, only: :index
7
+ before_action :read_discussion, only: :show
8
+
9
+ helper_method :discussion_filter_params
10
+
11
+ def index
12
+ @discussions = current_content_discussions.for_user(current_user)
13
+ @filtered_discussions = @discussions.scoped_query_by(discussion_filter_params)
14
+ end
15
+
16
+ def show
17
+ end
18
+
19
+ def update
20
+ subject.update_status! params[:status], current_user
21
+ redirect_to [@debatable, subject], notice: I18n.t(:discussion_updated)
22
+ end
23
+
24
+ def subscription
25
+ current_user&.toggle_subscription!(subject)
26
+ head :ok
27
+ end
28
+
29
+ def upvote
30
+ current_user&.toggle_upvote!(subject)
31
+ head :ok
32
+ end
33
+
34
+ def create
35
+ discussion = @debatable.discuss! current_user, discussion_params
36
+ redirect_to [@debatable, discussion]
37
+ end
38
+
39
+ private
40
+
41
+ def current_content_discussions
42
+ @debatable.discussions
43
+ end
44
+
45
+ def set_debatable
46
+ @debatable_class = params[:debatable_class]
47
+ @debatable = Discussion.debatable_for(@debatable_class, params)
48
+ end
49
+
50
+ def subject
51
+ @discussion ||= Discussion.find_by(id: params[:id])
52
+ end
53
+
54
+ def read_discussion
55
+ @discussion.subscription_for(current_user)&.read!
56
+ end
57
+
58
+ def discussion_params
59
+ params.require(:discussion).permit(:title, :description)
60
+ end
61
+
62
+ def discussion_filter_params
63
+ @filter_params ||= params.permit(Discussion.permitted_query_params)
64
+ end
65
+ end
@@ -0,0 +1,25 @@
1
+ class DiscussionsMessagesController < AjaxController
2
+ before_action :set_discussion!, only: [:create, :destroy]
3
+
4
+ def create
5
+ @discussion.submit_message! message_params, current_user
6
+ redirect_back(fallback_location: root_path)
7
+ end
8
+
9
+ def destroy
10
+ message = Message.find(params[:id])
11
+ message.authorize!
12
+ message.destroy!
13
+ redirect_back(fallback_location: root_path)
14
+ end
15
+
16
+ private
17
+
18
+ def set_discussion!
19
+ @discussion ||= Discussion.find_by(id: params[:discussion_id])
20
+ end
21
+
22
+ def message_params
23
+ params.require(:message).permit(:content)
24
+ end
25
+ end
@@ -1,4 +1,5 @@
1
1
  class ExercisesController < ApplicationController
2
+ include Mumuki::Laboratory::Controllers::Content
2
3
  include Mumuki::Laboratory::Controllers::ExerciseSeed
3
4
 
4
5
  before_action :set_guide!, only: :show
@@ -1,4 +1,5 @@
1
1
  class GuideContainerController < ApplicationController
2
+ include Mumuki::Laboratory::Controllers::Content
2
3
 
3
4
  before_action :set_guide
4
5
 
@@ -22,7 +22,7 @@ class MessagesController < AjaxController
22
22
  private
23
23
 
24
24
  def set_exercise!
25
- exercise_id = params.dig(:message, :exercise_id) || params[:exercise_id]
25
+ exercise_id = params.dig(:message, :exercise_id) || params[:exercise_id]
26
26
  @exercise = Exercise.find(exercise_id)
27
27
  end
28
28
 
@@ -4,6 +4,7 @@ class UsersController < ApplicationController
4
4
 
5
5
  def show
6
6
  @messages = current_user.messages || []
7
+ @watched_discussions = current_user.watched_discussions
7
8
  end
8
9
 
9
10
  def update
@@ -40,4 +40,11 @@ module ApplicationHelper
40
40
  def chapter_finished(chapter)
41
41
  t :chapter_finished_html, chapter: link_to_path_element(chapter) if chapter
42
42
  end
43
+
44
+ def span_toggle(hidden_text, active_text, active)
45
+ %Q{
46
+ <span class="#{'hidden' if active}">#{hidden_text}</span>
47
+ <span class="#{'hidden' unless active}">#{active_text}</span>
48
+ }.html_safe
49
+ end
43
50
  end
@@ -1,34 +1,4 @@
1
1
  module AssignmentResultHelper
2
- def t_expectation(expectation)
3
- raw Mumukit::Inspection::Expectation.parse(expectation).translate
4
- end
5
-
6
- def render_feedback?(assignment)
7
- StatusRenderingVerbosity.render_feedback?(assignment.feedback)
8
- end
9
-
10
- def t_assignment_status(assignment)
11
- t assignment_status assignment
12
- end
13
-
14
- def assignment_status(assignment)
15
- if assignment.exercise.hidden?
16
- :hidden_done
17
- elsif assignment.exercise.choices?
18
- assignment.passed? ? :correct_answer : :wrong_answer
19
- else
20
- assignment.status
21
- end
22
- end
23
-
24
- def render_test_results(assignment)
25
- if assignment.test_results.present?
26
- render partial: 'layouts/test_results', locals: { assignment: assignment }
27
- else
28
- render partial: 'layouts/result', locals: { assignment: assignment }
29
- end
30
- end
31
-
32
2
  def solution_download_link(assignment)
33
3
  link_to fa_icon(:download, text: t(:download)),
34
4
  solution_octet_data(assignment),
@@ -49,6 +19,16 @@ module AssignmentResultHelper
49
19
  end
50
20
  end
51
21
 
22
+ def report_bug_link(assignment, organization=Organization.current)
23
+ if organization.report_issue_enabled?
24
+ mail_to contact_email,
25
+ fa_icon(:bug, text: t(:notify_problem_with_exercise), class: 'fa-fw'),
26
+ subject: t(:problem_with_exercise, title: @exercise.name),
27
+ body: assignment_help_email_body(assignment),
28
+ class: 'warning'
29
+ end
30
+ end
31
+
52
32
  def manual_evaluation_comment(assignment)
53
33
  if assignment.manual_evaluation_comment?
54
34
  Mumukit::ContentType::Markdown.to_html assignment.manual_evaluation_comment
@@ -22,16 +22,20 @@ module BreadcrumbsHelper
22
22
  HTML
23
23
  end
24
24
 
25
+ def breadcrumb_list_item(last, item)
26
+ "<li #{breadcrumb_item_class(last)}>#{item}</li>".html_safe
27
+ end
28
+
25
29
  private
26
30
 
27
31
  def breadcrumbs0(e, extra=nil, last='')
28
- return "#{breadcrumbs0(e)}<li #{breadcrumb_item_class(last)} >#{extra}</li>".html_safe if extra
32
+ return "#{breadcrumbs0(e)} #{breadcrumb_list_item(last, extra)}".html_safe if extra
29
33
 
30
34
  base = link_to_path_element e
31
35
  if e.navigation_end?
32
- "#{home_breadcrumb}<li #{breadcrumb_item_class(last)}>#{base}</li>".html_safe
36
+ "#{home_breadcrumb} #{breadcrumb_list_item(last, base)}".html_safe
33
37
  else
34
- "#{breadcrumbs0(e.navigable_parent)} <li #{breadcrumb_item_class(last)}>#{base}</li>".html_safe
38
+ "#{breadcrumbs0(e.navigable_parent)} #{breadcrumb_list_item(last, base)}".html_safe
35
39
  end
36
40
  end
37
41
  end
@@ -0,0 +1,31 @@
1
+ module ContextualizationResultHelper
2
+ def humanized_expectation_result_item(expectation_result)
3
+ %Q{<li>#{status_icon(expectation_result[:result])} #{expectation_result[:explanation]}</li>}.html_safe
4
+ end
5
+
6
+ def render_feedback?(contextualization)
7
+ contextualization.feedback.present?
8
+ end
9
+
10
+ def t_contextualization_status(contextualization)
11
+ t contextualization_status contextualization
12
+ end
13
+
14
+ def contextualization_status(contextualization)
15
+ if contextualization.exercise.hidden?
16
+ :hidden_done
17
+ elsif contextualization.exercise.choices?
18
+ contextualization.passed? ? :correct_answer : :wrong_answer
19
+ else
20
+ contextualization.submission_status
21
+ end
22
+ end
23
+
24
+ def render_test_results(contextualization)
25
+ if contextualization.test_results.present?
26
+ render partial: 'layouts/test_results', locals: { contextualization: contextualization}
27
+ else
28
+ render partial: 'layouts/result', locals: { contextualization: contextualization }
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,163 @@
1
+ module DiscussionsHelper
2
+ def read_discussions_link(item)
3
+ discussions_link t(:solve_your_doubts), item_discussions_path(item, default_discussions_params)
4
+ end
5
+
6
+ def solve_discussions_link
7
+ discussions_link t(:solve_doubts), discussions_path(solve_discussion_params_for(current_user))
8
+ end
9
+
10
+ def discussions_icon(text)
11
+ fixed_fa_icon 'comments', text: text
12
+ end
13
+
14
+ def discussions_link(text, path, organization=Organization.current)
15
+ link_to discussions_icon(text), path if organization.forum_enabled?
16
+ end
17
+
18
+ def item_discussion_path(discussion, params={})
19
+ polymorphic_path([discussion.item, discussion], params)
20
+ end
21
+
22
+ def item_discussions_path(item, params={})
23
+ polymorphic_path([item, :discussions], params)
24
+ end
25
+
26
+ def solve_discussion_params_for(user)
27
+ if user&.moderator?
28
+ { status: :pending_review, sort: :created_at_asc }
29
+ else
30
+ { status: :opened, sort: :created_at_asc }
31
+ end
32
+ end
33
+
34
+ def default_discussions_params
35
+ { status: :solved, sort: :upvotes_count_desc }
36
+ end
37
+
38
+ def user_avatar(user, image_class='')
39
+ image_tag user.image_url, height: 40, class: "img-circle #{image_class}"
40
+ end
41
+
42
+ def discussions_link_with_teaser(item)
43
+ %Q{
44
+ <div>
45
+ <h3>#{t(:discussions)}</h3>
46
+ <p>
47
+ #{t(:solve_your_doubts_teaser)}
48
+ #{read_discussions_link(item)}
49
+ </p>
50
+ </div>
51
+ }.html_safe
52
+ end
53
+
54
+ def discussion_messages_icon(discussion)
55
+ %Q{
56
+ <span class="discussion-icon fa-stack fa-xs">
57
+ <i class="fa fa-comment-o fa-stack-2x"></i>
58
+ <i class="fa fa-stack-1x">#{discussion.messages.size}</i>
59
+ </span>
60
+ }.html_safe
61
+ end
62
+
63
+ def discussion_upvotes_icon(discussion)
64
+ if discussion.upvotes_count > 0
65
+ %Q{
66
+ <span class="discussion-icon fa-stack fa-xs">
67
+ <i class="fa fa-star-o fa-stack-2x"></i>
68
+ <i class="fa fa-stack-1x">#{discussion.upvotes_count}</i>
69
+ </span>
70
+ }.html_safe
71
+ end
72
+ end
73
+
74
+ def discussion_update_status_button(status)
75
+ button_to t("to_#{status}"),
76
+ item_discussion_path(@discussion, {status: status}),
77
+ class: "btn btn-discussion-#{status}",
78
+ method: :put
79
+ end
80
+
81
+ def new_discussion_link(teaser_text, link_text)
82
+ %Q{
83
+ <h4>
84
+ <span>#{t(teaser_text)}</span>
85
+ <a>
86
+ <span class="discussion-create">
87
+ #{t(link_text)}
88
+ </span>
89
+ </a>
90
+ </h4>
91
+ }.html_safe
92
+ end
93
+
94
+ def discussion_count_for_status(status, discussions)
95
+ discussions.scoped_query_by(discussion_filter_params, :status).by_status(status).count
96
+ end
97
+
98
+ def discussions_reset_query_link
99
+ link_to fa_icon(:times, text: t(:reset_query)), {}, class: 'discussions-reset-query' unless discussion_filter_params.blank?
100
+ end
101
+
102
+ def discussions_statuses
103
+ Mumuki::Laboratory::Status::Discussion::STATUSES
104
+ end
105
+
106
+ def discussions_languages(discussions)
107
+ discussions.map { |it| it.language.name }.uniq
108
+ end
109
+
110
+ def discussion_status_filter_link(status, discussions)
111
+ discussions_count = discussion_count_for_status(status, discussions)
112
+ if status.should_be_shown?(discussions_count, current_user)
113
+ discussion_filter_item(:status, status) do
114
+ discussion_status_filter(status, discussions_count)
115
+ end
116
+ end
117
+ end
118
+
119
+ def discussion_status_filter(status, discussions_count)
120
+ %Q{
121
+ #{status_fa_icon(status)}
122
+ <span>
123
+ #{discussions_count}
124
+ #{t status}
125
+ </span>
126
+ }.html_safe
127
+ end
128
+
129
+ def discussion_dropdown_filter(label, filters, &block)
130
+ if filters.present?
131
+ %Q{
132
+ <div class="dropdown discussions-toolbar-filter">
133
+ <a id="dropdown-#{label}" data-toggle="dropdown" role="menu">
134
+ #{t label} #{fa_icon :'caret-down', class: 'fa-xs'}
135
+ </a>
136
+ <ul class="dropdown-menu" aria-labelledby="dropdown-#{label}">
137
+ #{discussion_filter_list(label, filters, &block)}
138
+ </ul>
139
+ </div>
140
+ }.html_safe
141
+ end
142
+ end
143
+
144
+ def discussion_filter_list(label, filters, &block)
145
+ filters.map { |it| discussion_filter_item(label, it, &block) }.join("\n")
146
+ end
147
+
148
+ def discussion_filter_item(label, filter, &block)
149
+ content_tag(:li, discussion_filter_link(label, filter, &block), class: "#{'selected' if discussion_filter_selected?(label, filter)}")
150
+ end
151
+
152
+ def discussion_filter_selected?(label, filter)
153
+ filter.to_s == discussion_filter_params[label]
154
+ end
155
+
156
+ def discussion_filter_link(label, filter, &block)
157
+ link_to capture(filter, &block), discussion_filter_params.merge(Hash[label, filter])
158
+ end
159
+
160
+ def discussion_info(discussion)
161
+ "#{t(:time_since, time: time_ago_in_words(discussion.created_at))} · #{t(:message_count, count: discussion.messages.size)}"
162
+ end
163
+ end