mumuki-laboratory 7.10.3 → 7.12.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (85) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +26 -7
  3. data/Rakefile +9 -2
  4. data/app/assets/javascripts/mumuki_laboratory/application/bridge.js +26 -5
  5. data/app/assets/javascripts/mumuki_laboratory/application/gamification.js +85 -0
  6. data/app/assets/javascripts/mumuki_laboratory/application/kindergarten.js +145 -0
  7. data/app/assets/javascripts/mumuki_laboratory/application/profile.js +31 -16
  8. data/app/assets/javascripts/mumuki_laboratory/application/submission.js +1 -0
  9. data/app/assets/javascripts/mumuki_laboratory/application/submissions-store.js +19 -2
  10. data/app/assets/stylesheets/mumuki_laboratory/application/_errors.scss +3 -4
  11. data/app/assets/stylesheets/mumuki_laboratory/application/_modules.scss +3 -1
  12. data/app/assets/stylesheets/mumuki_laboratory/application/modules/_avatar.scss +21 -0
  13. data/app/assets/stylesheets/mumuki_laboratory/application/modules/{_chapter_show.scss → _content_show.scss} +0 -0
  14. data/app/assets/stylesheets/mumuki_laboratory/application/modules/_kindergarten.scss +401 -12
  15. data/app/assets/stylesheets/mumuki_laboratory/application/modules/_medal.scss +48 -0
  16. data/app/assets/stylesheets/mumuki_laboratory/application/modules/_terms.scss +44 -0
  17. data/app/assets/stylesheets/mumuki_laboratory/application/modules/_user_profile.scss +9 -0
  18. data/app/controllers/application_controller.rb +15 -8
  19. data/app/controllers/book_discussions_controller.rb +4 -0
  20. data/app/controllers/users_controller.rb +8 -2
  21. data/app/helpers/application_helper.rb +2 -2
  22. data/app/helpers/avatar_helper.rb +11 -3
  23. data/app/helpers/kindergarten_helper.rb +5 -0
  24. data/app/helpers/links_helper.rb +8 -0
  25. data/app/helpers/medal_helper.rb +36 -0
  26. data/app/helpers/open_graph_helper.rb +2 -2
  27. data/app/helpers/organization_list_helper.rb +1 -1
  28. data/app/helpers/overlapped_buttons_helper.rb +1 -1
  29. data/app/helpers/page_title_helper.rb +2 -2
  30. data/app/helpers/profile_helper.rb +9 -1
  31. data/app/views/book/_header.html.erb +17 -0
  32. data/app/views/book/show.html.erb +1 -18
  33. data/app/views/discussions/terms.html.erb +10 -0
  34. data/app/views/exercises/show.html.erb +1 -0
  35. data/app/views/invitations/_invitation_form.html.erb +1 -0
  36. data/app/views/layouts/_discussions.html.erb +5 -1
  37. data/app/views/layouts/_error.html.erb +3 -6
  38. data/app/views/layouts/_guide.html.erb +10 -3
  39. data/app/views/layouts/_kindergarten.html.erb +38 -0
  40. data/app/views/layouts/_main.html.erb +3 -1
  41. data/app/views/layouts/_organization_chooser.html.erb +0 -7
  42. data/app/views/layouts/_terms_acceptance_disclaimer.html.erb +6 -0
  43. data/app/views/layouts/application.html.erb +3 -2
  44. data/app/views/layouts/exercise_inputs/layouts/_input_kindergarten.html.erb +27 -27
  45. data/app/views/layouts/modals/_guide_corollary.html.erb +9 -0
  46. data/app/views/layouts/modals/_kindergarten_context.html.erb +30 -0
  47. data/app/views/layouts/modals/_kindergarten_results.html.erb +23 -0
  48. data/app/views/layouts/modals/_kindergarten_results_aborted.html.erb +24 -0
  49. data/app/views/users/_avatar_list.html.erb +6 -2
  50. data/app/views/users/_edit_user_form.html.erb +9 -4
  51. data/app/views/users/_term.html.erb +10 -0
  52. data/app/views/users/_user_form.html.erb +5 -1
  53. data/app/views/users/terms.html.erb +18 -0
  54. data/config/routes.rb +2 -0
  55. data/lib/mumuki/laboratory/controllers/current_organization.rb +1 -1
  56. data/lib/mumuki/laboratory/controllers/results_rendering.rb +3 -2
  57. data/lib/mumuki/laboratory/locales/en.yml +10 -5
  58. data/lib/mumuki/laboratory/locales/es-CL.yml +5 -4
  59. data/lib/mumuki/laboratory/locales/es.yml +12 -7
  60. data/lib/mumuki/laboratory/locales/pt.yml +12 -7
  61. data/lib/mumuki/laboratory/version.rb +1 -1
  62. data/spec/capybara_helper.rb +99 -0
  63. data/spec/controllers/exercise_solutions_controller_spec.rb +3 -4
  64. data/spec/dummy/db/schema.rb +37 -1
  65. data/spec/dummy/public/medal/outline.svg +1089 -0
  66. data/spec/features/choose_organization_spec.rb +12 -30
  67. data/spec/features/disable_user_flow_spec.rb +3 -5
  68. data/spec/features/disabled_organization_flow_spec.rb +9 -14
  69. data/spec/features/exercise_flow_spec.rb +2 -2
  70. data/spec/features/guide_reset_spec.rb +1 -1
  71. data/spec/features/guides_flow_spec.rb +1 -1
  72. data/spec/features/home_private_flow_spec.rb +1 -3
  73. data/spec/features/home_public_flow_spec.rb +6 -12
  74. data/spec/features/invitations_flow_spec.rb +2 -2
  75. data/spec/features/login_flow_spec.rb +2 -2
  76. data/spec/features/not_found_private_flow_spec.rb +4 -4
  77. data/spec/features/not_found_public_flow_spec.rb +1 -6
  78. data/spec/features/profile_flow_spec.rb +1 -1
  79. data/spec/helpers/page_title_helper_spec.rb +3 -3
  80. data/spec/javascripts/editors-spec.js +23 -0
  81. data/spec/javascripts/gamification-spec.js +58 -0
  82. data/spec/javascripts/submissions-store-spec.js +139 -6
  83. data/spec/spec_helper.rb +2 -0
  84. data/spec/teaspoon_env.rb +24 -6
  85. metadata +40 -7
@@ -0,0 +1,48 @@
1
+ .mu-medal {
2
+ &.outline {
3
+ position: absolute;
4
+
5
+ &.content {
6
+ height: 75px;
7
+
8
+ margin-left: 10px;
9
+ }
10
+
11
+ &.corollary {
12
+ height: 150px;
13
+
14
+ margin-left: auto;
15
+ margin-right: auto;
16
+ left: 0;
17
+ right: 0;
18
+ }
19
+ }
20
+
21
+ &.inlay {
22
+ position: relative;
23
+ border-radius: 50%;
24
+
25
+ &.content {
26
+ height: 55px;
27
+
28
+ left: 20px;
29
+ top: 17px;
30
+
31
+ margin-right: 30px;
32
+ margin-bottom: 15px;
33
+ }
34
+
35
+ &.corollary {
36
+ height: 107px;
37
+
38
+ display: block;
39
+ top: 35px;
40
+
41
+ margin: 0 auto 20px;
42
+ }
43
+ }
44
+
45
+ &.unacquired {
46
+ filter: grayscale(100%);
47
+ }
48
+ }
@@ -0,0 +1,44 @@
1
+ summary.terms-summary {
2
+ font-size: 29px;
3
+ outline: 0;
4
+ cursor: pointer;
5
+ .terms-summary-title {
6
+ display: inline;
7
+ }
8
+ }
9
+
10
+ .terms-card {
11
+ position: relative;
12
+ display: -ms-flexbox;
13
+ display: flex;
14
+ -ms-flex-direction: column;
15
+ flex-direction: column;
16
+ min-width: 0;
17
+ word-wrap: break-word;
18
+ background-color: #fff;
19
+ background-clip: border-box;
20
+ border: 1px solid rgba(0,0,0,.125);
21
+ border-radius: .25rem;
22
+ &:not(:first-child) {
23
+ border-top: none;
24
+ }
25
+ .terms-card-header {
26
+ cursor: pointer;
27
+ font-weight: bold;
28
+ padding: .75rem 1.25rem;
29
+ margin-bottom: 0;
30
+ background-color: rgba(0,0,0,.03);
31
+ border-bottom: 1px solid rgba(0,0,0,.125);
32
+ }
33
+ &:first-child .terms-card-header{
34
+ border-radius: calc(.25rem - 1px) calc(.25rem - 1px) 0 0;
35
+ }
36
+ }
37
+ .terms-card-body {
38
+ padding: 1.25rem;
39
+ }
40
+
41
+ .terms-acceptance-btn {
42
+ margin-top: 10px;
43
+ display: block
44
+ }
@@ -20,6 +20,15 @@
20
20
  border-color: lighten($mu-color-complementary, 15%);
21
21
  }
22
22
  }
23
+
24
+ &.mobile {
25
+ text-align: center;
26
+ margin: 20px 5px -20px -10px;
27
+
28
+ .btn {
29
+ width: calc(50% - 20px);
30
+ }
31
+ }
23
32
  }
24
33
 
25
34
  .mu-profile-info {
@@ -19,7 +19,7 @@ class ApplicationController < ActionController::Base
19
19
  before_action :ensure_user_enabled!, if: :current_user?
20
20
  before_action :validate_active_organization!
21
21
 
22
- before_action :redirect_to_main_organization!, if: :should_redirect_to_main_organization?
22
+ before_action :redirect_to_proper_context!, if: :immersive_context_wrong?
23
23
 
24
24
  before_action :authorize_if_private!
25
25
  before_action :validate_active_organization!
@@ -39,18 +39,20 @@ class ApplicationController < ActionController::Base
39
39
  :theme_stylesheet_url,
40
40
  :extension_javascript_url
41
41
 
42
- def should_redirect_to_main_organization?
43
- should_choose_organization? && current_user.has_immersive_main_organization?
42
+ def immersive_context_wrong?
43
+ current_immersive_context != Organization.current
44
44
  end
45
45
 
46
- def redirect_to_main_organization!
47
- redirect_to current_user.main_organization.url_for(request.path)
46
+ def redirect_to_proper_context!
47
+ # TODO: redirect to subject (if it exists on the immersive context)
48
+ redirect_to current_immersive_context.url_for('/')
48
49
  end
49
50
 
50
51
  def should_choose_organization?
51
- current_user? &&
52
- current_user.has_student_granted_organizations? &&
53
- Mumukit::Platform.implicit_organization?(request)
52
+ return false unless current_user?
53
+
54
+ # TODO: replace `nil` with `subject` to consider exercise, guide, etc
55
+ current_user.immersive_organizations_at(nil).size > 1
54
56
  end
55
57
 
56
58
  # ensures contents are accessible to current user
@@ -82,6 +84,11 @@ class ApplicationController < ActionController::Base
82
84
 
83
85
  private
84
86
 
87
+ def current_immersive_context
88
+ # TODO: replace `nil` with `subject` to consider exercise, guide, etc
89
+ current_user&.current_immersive_context_at(nil) || Organization.current
90
+ end
91
+
85
92
  def from_sessions?
86
93
  params['controller'] == 'login'
87
94
  end
@@ -1,4 +1,8 @@
1
1
  class BookDiscussionsController < DiscussionsController
2
+ def terms
3
+ @forum_terms ||= Term.forum_related_terms
4
+ end
5
+
2
6
  private
3
7
 
4
8
  def set_debatable
@@ -1,7 +1,7 @@
1
1
  class UsersController < ApplicationController
2
2
  include WithUserParams
3
3
 
4
- before_action :authenticate!
4
+ before_action :authenticate!, except: :terms
5
5
  before_action :set_user!
6
6
 
7
7
  def show
@@ -11,9 +11,14 @@ class UsersController < ApplicationController
11
11
 
12
12
  def update
13
13
  current_user.update_and_notify! user_params
14
+ current_user.accept_profile_terms!
14
15
  redirect_to user_path, notice: I18n.t(:user_data_updated)
15
16
  end
16
17
 
18
+ def terms
19
+ @profile_terms ||= Term.profile_terms_for(current_user)
20
+ end
21
+
17
22
  def unsubscribe
18
23
  user_id = User.unsubscription_verifier.verify(params[:id])
19
24
  User.find(user_id).unsubscribe_from_reminders!
@@ -22,7 +27,7 @@ class UsersController < ApplicationController
22
27
  end
23
28
 
24
29
  def permissible_params
25
- super << :avatar_id
30
+ super << [:avatar_id, :avatar_type]
26
31
  end
27
32
 
28
33
  private
@@ -33,4 +38,5 @@ class UsersController < ApplicationController
33
38
  def set_user!
34
39
  @user = current_user
35
40
  end
41
+
36
42
  end
@@ -7,8 +7,8 @@ module ApplicationHelper
7
7
  end
8
8
 
9
9
  def profile_picture_for(user, **options)
10
- options.merge!(height: 40, onError: "this.onerror = null; this.src = '#{image_url(user.placeholder_image_url)}'")
11
- avatar_image(user.profile_picture, options)
10
+ default_options = { height: 40, onError: "this.onerror = null; this.src = '#{image_url(user.placeholder_image_url)}'" }
11
+ avatar_image(user.profile_picture, default_options.merge(options))
12
12
  end
13
13
 
14
14
  def avatar_image(avatar_url, **options)
@@ -1,9 +1,17 @@
1
1
  module AvatarHelper
2
2
  def avatars_for(user)
3
- (Avatar.with_current_audience_for(user) + [user.avatar]).compact.uniq
3
+ (Avatar.with_current_audience_for(user) + user.acquired_medals + [user.avatar]).compact.uniq
4
4
  end
5
5
 
6
- def show_avatar_item(item)
7
- avatar_image(item.image_url, alt: item.description, 'mu-avatar-id': item.id, class: 'mu-avatar-item')
6
+ def locked_avatars_for(user)
7
+ user.unacquired_medals.compact.uniq
8
+ end
9
+
10
+ def show_locked_avatar_item(item)
11
+ show_avatar_item(item, class: 'mu-avatar-item mu-locked')
12
+ end
13
+
14
+ def show_avatar_item(item, **options)
15
+ avatar_image(item.image_url, alt: item.description, 'mu-avatar-id': item.id, class: 'mu-avatar-item', type: item.class.name, **options)
8
16
  end
9
17
  end
@@ -0,0 +1,5 @@
1
+ module KindergartenHelper
2
+ def kindergarten_full_workspace?(exercise)
3
+ !exercise.initial_state && !exercise.final_state
4
+ end
5
+ end
@@ -51,6 +51,14 @@ module LinksHelper
51
51
  body: permissions_help_email_body(current_user)
52
52
  end
53
53
 
54
+ def link_to_profile_terms
55
+ link_to t(:terms_and_conditions).downcase, user_terms_path, target: '_blank'
56
+ end
57
+
58
+ def link_to_forum_terms
59
+ link_to t(:forum_terms).downcase, discussions_terms_path, target: '_blank'
60
+ end
61
+
54
62
  def turbolinks_enable_for(exercise)
55
63
  %Q{data-turbolinks="#{!exercise.input_kids?}"}.html_safe
56
64
  end
@@ -0,0 +1,36 @@
1
+ module MedalHelper
2
+ def should_display_medal?(content, organization)
3
+ content.medal.present? && organization.gamification_enabled?
4
+ end
5
+
6
+ def content_medal_for(content, user)
7
+ medal_for content, 'content', completion_class_for(content, user)
8
+ end
9
+
10
+ def corollary_medal_for(content)
11
+ medal_for content, 'corollary'
12
+ end
13
+
14
+ private
15
+
16
+ def completion_class_for(content, user)
17
+ content.once_completed_for?(user, Organization.current) ? '' : 'unacquired'
18
+ end
19
+
20
+ def medal_for(content, view, completion='')
21
+ %Q{
22
+ <div class="mu-medal #{completion}">
23
+ #{outline_image(view)}
24
+ #{inlay_image_for(content, view)}
25
+ </div>
26
+ }.html_safe
27
+ end
28
+
29
+ def outline_image(clazz)
30
+ image_tag '/medal/outline.svg', class: "mu-medal outline #{clazz}", alt: I18n.t(:medal)
31
+ end
32
+
33
+ def inlay_image_for(content, clazz)
34
+ image_tag content.medal.image_url, class: "mu-medal inlay #{clazz}", alt: content.medal.description
35
+ end
36
+ end
@@ -1,9 +1,9 @@
1
1
  module OpenGraphHelper
2
2
  def open_graph_tags(subject)
3
3
  %Q{
4
- <meta property="og:site_name" content="#{Organization.current.site_name}" />
4
+ <meta property="og:site_name" content="#{Organization.current.display_name}" />
5
5
  <meta property="og:title" content="#{h page_title(subject)}"/>
6
- <meta property="og:description" content="#{Organization.current.central? ? t(:mumuki_short_description) : Organization.current.description}"/>
6
+ <meta property="og:description" content="#{Organization.current.description}"/>
7
7
  <meta property="og:type" content="website"/>
8
8
  <meta property="og:image" content="#{Organization.current.open_graph_image_url}"/>
9
9
  <meta property="og:url" content="#{request.original_url}"/>
@@ -1,5 +1,5 @@
1
1
  module OrganizationListHelper
2
2
  def organizations_for(user)
3
- (user.student_granted_organizations + [Organization.central]).uniq.compact
3
+ user.immersive_organizations_at(nil)
4
4
  end
5
5
  end
@@ -8,7 +8,7 @@ module OverlappedButtonsHelper
8
8
  end
9
9
 
10
10
  def restart_guide_link(guide)
11
- link_to restart_icon, guide_progress_path(guide), class: 'mu-content-toolbar-item', data: {confirm: t(:confirm_restart)}, method: :delete
11
+ link_to restart_icon, guide_progress_path(guide), class: 'mu-content-toolbar-item mu-restart-guide', data: {confirm: t(:confirm_restart)}, method: :delete
12
12
  end
13
13
 
14
14
  def overlapped_button_icon(key, icon)
@@ -1,11 +1,11 @@
1
1
  module PageTitleHelper
2
2
  def page_title(subject)
3
- name = "Mumuki#{Organization.current.title_suffix}"
3
+ name = Organization.current.page_name
4
4
 
5
5
  if subject && !subject.new_record?
6
6
  "#{subject.friendly} - #{name}"
7
7
  else
8
- "#{name} - #{t :mumuki_catchphrase}"
8
+ "#{name}"
9
9
  end
10
10
  end
11
11
  end
@@ -1,5 +1,13 @@
1
1
  module ProfileHelper
2
2
  def edit_profile_button
3
- link_to t(:edit_profile), edit_user_path, class: 'btn btn-success'
3
+ link_to t(:edit_profile), :edit_user, class: 'btn btn-success'
4
+ end
5
+
6
+ def cancel_edit_profile_button
7
+ link_to t(:cancel), :user, class: 'btn btn-default' if current_user.profile_completed?
8
+ end
9
+
10
+ def save_edit_profile_button(form)
11
+ form.submit t(:save), disabled: true, class: 'btn btn-success mu-edit-profile-btn'
4
12
  end
5
13
  end
@@ -0,0 +1,17 @@
1
+ <% @organization = Organization.current %>
2
+ <div class="book-header <%= current_user? ? '' : 'logged' %>">
3
+ <%#
4
+ H1 is not actually displayed.
5
+ This weird title structure is kept for backward compatibility only
6
+ %>
7
+ <h1><%= @organization.page_name %></h1>
8
+
9
+ <img src="<%= @organization.banner_url %>" alt="<%= @organization.display_name %>">
10
+ <h2><%= @organization.page_name %></h2>
11
+
12
+ <h3><small><%= @organization.description %></small></h3>
13
+ </div>
14
+
15
+ <div class="text-box">
16
+ <%= @organization.page_description_html %>
17
+ </div>
@@ -3,24 +3,7 @@
3
3
  <% end %>
4
4
 
5
5
  <div class="col-md-offset-2 col-md-8">
6
- <div class="book-header <%= current_user? ? '' : 'logged' %>">
7
- <h1>ム mumuki<%= Organization.current.title_suffix %></h1>
8
-
9
- <img src="<%= Organization.current.banner_url %>" alt="<%= Organization.current.name %> - Mumuki">
10
- <h2><%= @book.name %></h2>
11
-
12
- <% unless Organization.current.central? %>
13
- <h3>
14
- <small><%= Organization.current.description %></small>
15
- <br>
16
- <small><%= t :powered_by_mumuki_html %></small>
17
- </h3>
18
- <% end %>
19
- </div>
20
-
21
- <div class="text-box">
22
- <%= @book.description_html %>
23
- </div>
6
+ <%= render partial: 'book/header' %>
24
7
 
25
8
  <% @book.next_lesson_for(current_user).try do |lesson| %>
26
9
  <div class="actions">
@@ -0,0 +1,10 @@
1
+ <div class="mu-user-header">
2
+ <h1><%= t :forum_terms %></h1>
3
+ </div>
4
+
5
+ <div>
6
+ <% @forum_terms.each do |term| %>
7
+ <%= term.content_html %>
8
+ <% end %>
9
+ </div>
10
+
@@ -48,6 +48,7 @@
48
48
  <%= hidden_field_tag "mu-exercise-id", @exercise.id %>
49
49
  <%= hidden_field_tag "mu-exercise-layout", @exercise.layout %>
50
50
  <%= hidden_field_tag "mu-exercise-settings", @exercise.settings.to_json %>
51
+ <%= hidden_field_tag "mu-current-exp", UserStats.exp_for(@current_user) %>
51
52
 
52
53
  <div style="display: none" id="processing-template">
53
54
  <div class="bs-callout bs-callout-info">
@@ -4,6 +4,7 @@
4
4
  <div class="row mu-tab-body">
5
5
  <div class="col-md-12">
6
6
  <%= render partial: 'users/profile_fields', locals: {form: f} %>
7
+ <%= render partial: 'layouts/terms_acceptance_disclaimer', locals: {user: @user} %>
7
8
  </div>
8
9
  </div>
9
10
  </div>
@@ -60,7 +60,7 @@
60
60
  <span><%= discussion.exercise.name %></span>
61
61
  <% if discussion.last_moderator_access_visible_for?(current_user) %>
62
62
  <div class="pull-right discussion-moderator-access" >
63
- <%= profile_picture_for(discussion.last_moderator_access_by, 32) %>
63
+ <%= profile_picture_for(discussion.last_moderator_access_by, height: 32) %>
64
64
  <span class="moderator-initials">
65
65
  <%= discussion.last_moderator_access_by.name_initials %>
66
66
  </span>
@@ -84,3 +84,7 @@
84
84
 
85
85
  <% end %>
86
86
  </div>
87
+
88
+ <span>
89
+ <%= t(:forum_terms_link, terms_link: link_to_forum_terms).html_safe %>
90
+ </span>