mumuki-laboratory 7.6.0 → 7.7.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (64) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +184 -2
  3. data/app/assets/javascripts/mumuki_laboratory/application.js +0 -1
  4. data/app/assets/javascripts/mumuki_laboratory/application/assets-loader.js +1 -1
  5. data/app/assets/javascripts/mumuki_laboratory/application/bridge.js +36 -10
  6. data/app/assets/javascripts/mumuki_laboratory/application/button.js +90 -1
  7. data/app/assets/javascripts/mumuki_laboratory/application/codemirror.js +1 -0
  8. data/app/assets/javascripts/mumuki_laboratory/application/custom-editor.js +46 -4
  9. data/app/assets/javascripts/mumuki_laboratory/application/discussions.js +14 -13
  10. data/app/assets/javascripts/mumuki_laboratory/application/kids.js +73 -36
  11. data/app/assets/javascripts/mumuki_laboratory/application/progress.js +3 -0
  12. data/app/assets/javascripts/mumuki_laboratory/application/results-renderer.js +51 -0
  13. data/app/assets/javascripts/mumuki_laboratory/application/submission.js +184 -35
  14. data/app/assets/stylesheets/mumuki_laboratory/application/_modules.scss +1 -0
  15. data/app/assets/stylesheets/mumuki_laboratory/application/modules/_discussion.scss +43 -4
  16. data/app/assets/stylesheets/mumuki_laboratory/application/modules/_kids.scss +3 -3
  17. data/app/assets/stylesheets/mumuki_laboratory/application/modules/_kindergarten.scss +55 -0
  18. data/app/controllers/assets_controller.rb +2 -0
  19. data/app/controllers/concerns/with_authorization.rb +4 -0
  20. data/app/controllers/discussions_controller.rb +5 -0
  21. data/app/controllers/discussions_messages_controller.rb +9 -1
  22. data/app/controllers/exercise_solutions_controller.rb +4 -2
  23. data/app/helpers/application_helper.rb +9 -5
  24. data/app/helpers/discussions_helper.rb +30 -20
  25. data/app/helpers/exercise_input_helper.rb +1 -1
  26. data/app/helpers/icons_helper.rb +3 -3
  27. data/app/views/book_discussions/index.html.erb +3 -3
  28. data/app/views/discussions/_message.html.erb +8 -3
  29. data/app/views/discussions/index.html.erb +0 -1
  30. data/app/views/discussions/new.html.erb +33 -0
  31. data/app/views/discussions/show.html.erb +12 -42
  32. data/app/views/exercise_solutions/_contextualization_results_container.html.erb +1 -1
  33. data/app/views/exercise_solutions/_results_title.html.erb +2 -2
  34. data/app/views/exercises/_read_only.html.erb +33 -6
  35. data/app/views/layouts/_discussions.html.erb +19 -1
  36. data/app/views/layouts/_social_media.html.erb +3 -3
  37. data/app/views/layouts/_test_results.html.erb +1 -1
  38. data/app/views/layouts/exercise_inputs/editors/_custom.html.erb +1 -1
  39. data/app/views/layouts/exercise_inputs/editors/_multiple_files.html.erb +1 -1
  40. data/app/views/layouts/exercise_inputs/forms/_kids_form.html.erb +1 -1
  41. data/app/views/layouts/exercise_inputs/forms/_problem_form.html.erb +1 -1
  42. data/app/views/layouts/exercise_inputs/layouts/_input_bottom.html.erb +1 -1
  43. data/app/views/layouts/exercise_inputs/layouts/_input_kindergarten.html.erb +40 -0
  44. data/app/views/layouts/exercise_inputs/layouts/{_input_kids.html.erb → _input_primary.html.erb} +1 -1
  45. data/app/views/layouts/exercise_inputs/layouts/_input_right.html.erb +1 -1
  46. data/app/views/layouts/modals/_kids_context.html.erb +1 -8
  47. data/app/views/user_mailer/1st_reminder.html.erb +2 -2
  48. data/app/views/user_mailer/2nd_reminder.html.erb +2 -2
  49. data/app/views/user_mailer/3rd_reminder.html.erb +2 -2
  50. data/app/views/user_mailer/no_submissions_reminder.html.erb +2 -2
  51. data/config/routes.rb +2 -1
  52. data/lib/mumuki/laboratory/controllers/results_rendering.rb +1 -2
  53. data/lib/mumuki/laboratory/locales/en.yml +5 -0
  54. data/lib/mumuki/laboratory/locales/es.yml +5 -0
  55. data/lib/mumuki/laboratory/locales/pt.yml +5 -2
  56. data/lib/mumuki/laboratory/version.rb +1 -1
  57. data/spec/controllers/confirmations_controller_spec.rb +1 -1
  58. data/spec/controllers/exercise_solutions_controller_spec.rb +41 -6
  59. data/spec/dummy/db/schema.rb +11 -1
  60. data/spec/features/exercise_flow_spec.rb +1 -1
  61. data/spec/helpers/breadcrumbs_helper_spec.rb +1 -1
  62. metadata +10 -9
  63. data/app/views/layouts/modals/_new_discussion.html.erb +0 -27
  64. data/vendor/assets/javascripts/hotjar.js +0 -8
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 56fcb30522c5c040911bbfc58f2f6e522aa5983f09b09d76cad1e60c8bd2efdd
4
- data.tar.gz: aeec9a44afdf74ea1d21e9f6b4bb548f12c22f7db55fa6470b478372ba7efcb5
3
+ metadata.gz: 3c7dbf715c210c593e2a509411ba1f39bfa2c061c9b4e45ffd132634abcd6060
4
+ data.tar.gz: decfa9f0385134c07cdb7e0fe933c29dcf1c3864741840a7a25573c1c8141c3f
5
5
  SHA512:
6
- metadata.gz: a98ee53e368aefbfc98cb99f8f4164c4e43d0e3c0be8e06c04cf39f48d4b78edf4ef5afaec4bdf94bd341121e0616c38f1ca9419eed8ae530fd395c5a75fd2b6
7
- data.tar.gz: 8c17f74141875921e42b6e8972d37c9c3e53d81646223e83a647c6d5e1f2a14acde33da7ff00b4f80c88a3ffe411378daacbf8580fd44f75efde2a510f971297
6
+ metadata.gz: 11813d4b113221ebbc7012a4fa86c78b69cf070f979706d54fe70afa4b3543193f623f8837665c3879d081fca10fad3b3e1dbba66491e6eca338362f268acdb7
7
+ data.tar.gz: 472fc73e4c480f8f69797ad5639485ffc4baa1887c28861c4aa59d3b03719ac3df5ebae5e356dc00e8d06a343183793b1d9c89b813c09a35377537a1ad54794e
data/README.md CHANGED
@@ -158,7 +158,9 @@ which are granted to be safe and stable.
158
158
  * `.mu-kids-submit-button`
159
159
  * `.mu-multiple-scenarios`
160
160
  * `.mu-scenarios`
161
+ * `.mu-submit-button`
161
162
  * `#mu-actual-state-text`
163
+ * `#mu-${languageName}-custom-editor`
162
164
  * `#mu-custom-editor-default-value`
163
165
  * `#mu-custom-editor-extra`
164
166
  * `#mu-custom-editor-test`
@@ -170,7 +172,6 @@ which are granted to be safe and stable.
170
172
  * `.mu-kids-gbs-board-initial`: Use `.mu-initial-state` instead
171
173
  * `.mu-state-final`: Use `.mu-final-state` instead
172
174
  * `.mu-state-initial`: Use `.mu-initial-state` instead
173
- * `#kids-context`: Use `.mu-kids-context` instead
174
175
  * `#kids-results-aborted`: Use `.mu-kids-results-aborted` instead
175
176
  * `#kids-results`: Use `.mu-kids-results` instead
176
177
 
@@ -178,6 +179,8 @@ which are granted to be safe and stable.
178
179
 
179
180
  * `mumuki.bridge.Laboratory`
180
181
  * `.runTests`
182
+ * `mumuki.CustomEditor`
183
+ * `addSource`
181
184
  * `mumuki.editor`
182
185
  * `formatContent`
183
186
  * `reset`
@@ -191,6 +194,7 @@ which are granted to be safe and stable.
191
194
  * `scaleBlocksArea`
192
195
  * `scaleState`
193
196
  * `showResult`
197
+ * `showContext`
194
198
  * `mumuki.renderers`
195
199
  * `SpeechBubbleRenderer`
196
200
  * `renderSpeechBubbleResultItem`
@@ -205,6 +209,9 @@ which are granted to be safe and stable.
205
209
  * `setUpDeleteFiles`
206
210
  * `setUpDeleteFile`
207
211
  * `updateButtonsVisibility`
212
+ * `mumuki.submission`
213
+ * `processSolution`
214
+ * `registerContentSyncer`
208
215
  * `mumuki.version`
209
216
 
210
217
  ### Bridge Response Format
@@ -213,7 +220,6 @@ which are granted to be safe and stable.
213
220
  {
214
221
  "status": "passed|passed_with_warnings|failed",
215
222
  "guide_finished_by_solution": "boolean",
216
- "class_for_progress_list_item": "string",
217
223
  "html": "string",
218
224
  "remaining_attempts_html": "string" ,
219
225
  "title_html": "string", // kids-only
@@ -243,6 +249,182 @@ which are granted to be safe and stable.
243
249
  2. Laboratory Kids Layout Initialization
244
250
  3. Runner Editor HTML
245
251
 
252
+ ## Custom editors
253
+
254
+ Mumuki provides several editor types: code editors, multiple choice, file upload, and so on.
255
+ However, some runners will require custom editors in order to provide better ways of entering
256
+ solutions.
257
+
258
+ The process to do so is not difficult, but tricky, since there are a few hooks you need to implement. Let's look at them:
259
+
260
+ ### 1. Before state: adding layout assets
261
+
262
+ If you need to provide a custom editor, chances are that you also need to provide assets to augment the layout, e.g. providing ways
263
+ to render some custom components on descriptions or corollaries. That code will be included first.
264
+
265
+ In order to do that, add to your runner the layout html, css and js code. Layout code has no further requirements. It can customize any public selector previously.
266
+
267
+ Although it is not required, it is recommended that your layout code works with any of the mumuki layouts:
268
+
269
+ * `input_right`
270
+ * `input_bottom`
271
+ * `input_primary`
272
+ * `input_kindergarten`
273
+
274
+ :warning: Not all the selectors will be available to all layouts.
275
+
276
+ Then expose code in the `MetadataHook`:
277
+
278
+ ```ruby
279
+ class ... < Mumukit::Hook
280
+ def metadata
281
+ {
282
+ layout_assets_urls: {
283
+ js: [
284
+ 'assets/....'
285
+ ],
286
+ css: [
287
+ 'assets/....'
288
+ ],
289
+ html: [
290
+ 'assets/....'
291
+ ]
292
+ }
293
+ }
294
+ end
295
+ end
296
+ ```
297
+
298
+ Finally, it is _recommended_ that you layout code calls `mumuki.assetsLoadedFor('layout')` when fully loaded.
299
+
300
+ That's it!
301
+
302
+ ### 2. Adding custom editor assets
303
+
304
+ The process for registering custom editors is more involving.
305
+
306
+ #### 2.1 Add your assets and expose them
307
+
308
+ Add your js, css and html assets to your runner, and expose them in `MetadataHook`:
309
+
310
+ ```ruby
311
+ class ... < Mumukit::Hook
312
+ def metadata
313
+ {
314
+ editor_assets_urls: {
315
+ js: [
316
+ 'assets/....'
317
+ ],
318
+ css: [
319
+ 'assets/....'
320
+ ],
321
+ html: [
322
+ 'assets/....'
323
+ ]
324
+ }
325
+ }
326
+ end
327
+ end
328
+ ```
329
+
330
+ These assets will only be loaded when the editor `custom` is used.
331
+
332
+ #### 2.2 Add your components to the custom editor
333
+
334
+ Using JavaScript, append your components the custom-editor root, which can be found using the following selectors:
335
+
336
+ * `mu-${languageName}-custom-editor`
337
+ * `#mu-${languageName}-custom-editor`
338
+ * `.mu-${languageName}-custom-editor`
339
+
340
+ ```javascript
341
+ $('#mu-mylang-custom-editor').append(/* ... */)
342
+ ```
343
+
344
+ #### 2.3 Extract the test
345
+
346
+ If necessary, read the test definition from `#mu-custom-editor-test`, and plump into your custom components
347
+
348
+ ```javascript
349
+ const test = $('#mu-custom-editor-test').val()
350
+ //...use test...
351
+ ```
352
+
353
+ #### 2.4 Exposing your content
354
+
355
+ Before sending a submission, mumuki needs to be able to your read you editor components
356
+ contents. There are two different approaches:
357
+
358
+ * Register a syncer that writes `#mu-custom-editor-value` or any other custom editor selectors
359
+ * Add one or more content sources
360
+
361
+ ```javascript
362
+ // simplest method - you can register just one
363
+ mumuki.submission.registerContentSyncer(() => {
364
+ // ... write here your custom component content...
365
+ $('#mu-custom-editor-value').val(/* ... */);
366
+ });
367
+
368
+ // alternate method
369
+ // you can register many sources
370
+ mumuki.CustomEditor.addSource({
371
+ getContent() {
372
+ return { name: "solution[content]", value: /* ... */ } ;
373
+ }
374
+ });
375
+ ```
376
+
377
+ #### 2.5 Optional: Sending your solution to the server programmatically
378
+
379
+ Your solution will be automatically sent to the client when the submit button is pressed. However,
380
+ if you need to trigger submission process programmatically, call `mumuki.submission.processSolution`:
381
+
382
+ ```javascript
383
+ mumuki.submission.processSolution({solution: {content: /* ... */}});
384
+ ```
385
+
386
+ #### 2.6 Optional: customizing your submit button
387
+
388
+ You can alternatively override the default submit button UI and behaviour, by replacing it with a custom component. In order to
389
+ do that, override the `.mu-submit-button` or the kids-specific `.mu-kids-submit-button`:
390
+
391
+ ```javascript
392
+ $(".mu-submit-button").html(/* ... */);
393
+ ```
394
+
395
+ However, doing this is tricky, since you will need to manually update the UI and connecting to the server. See:
396
+
397
+ * `mumuki.kids.showResult`
398
+ * `mumuki.bridge.Laboratory.runTests`
399
+ * `mumuki.updateProgressBarAndShowModal`
400
+
401
+ #### 2.7 Register kids scalers
402
+
403
+ Kids layouts have some special areas:
404
+
405
+ * _state area_: its display initial and/or final states of the exercise
406
+ * _blocks area_: a workspace that contains the building blocks of the solution - which are not necessary programming or blockly blocks, actually
407
+
408
+ If you want to support kids layouts, you **need** to register scalers that will be called when device is resized. Skip this step otherwise.
409
+
410
+ ```javascript
411
+ mumuki.kids.registerStateScaler(($state, fullMargin, preferredWidth, preferredHeight) => {
412
+ // ... resize your components ...
413
+ });
414
+
415
+ mumuki.kids.registerBlocksAreaScaler(($blocks) => {
416
+ // ... resize your components ...
417
+ });
418
+ ```
419
+
420
+ #### 2.8 Notify when your assets have been loaded
421
+
422
+ In order to remove loading spinners, you will need to call `mumuki.assetsLoadedFor` when your code is ready.
423
+
424
+ ```javascript
425
+ mumuki.assetsLoadedFor('editor');
426
+ ```
427
+
246
428
  ## Transparent Navigation API Docs
247
429
 
248
430
  In order to be able to link content, laboratory exposes slug-based routes that will redirect to the actual
@@ -27,7 +27,6 @@
27
27
  //= require codemirror-autorefresh
28
28
  //= require codemirror-modes
29
29
  //= require analytics
30
- //= require hotjar
31
30
  //= require muvment
32
31
 
33
32
  //= require_tree ./application
@@ -1,4 +1,4 @@
1
- const assetsLoader = {
1
+ var assetsLoader = {
2
2
  layout: {
3
3
  onLoadingStarted: function () {
4
4
 
@@ -1,3 +1,11 @@
1
+ /**
2
+ * @typedef {{status: string, test_results: [{status: string, title: string}]}} ClientResult
3
+ */
4
+
5
+ /**
6
+ * @typedef {{solution: object, client_result?: ClientResult}} Submission
7
+ */
8
+
1
9
  var mumuki = mumuki || {};
2
10
 
3
11
  (function (mumuki) {
@@ -19,19 +27,28 @@ var mumuki = mumuki || {};
19
27
  return lastSubmission.result && lastSubmission.result.status !== 'aborted';
20
28
  }
21
29
 
22
- function sendNewSolution(solution){
30
+ function sendNewSolution(submission){
23
31
  var token = new mumuki.CsrfToken();
24
32
  var request = token.newRequest({
25
33
  type: 'POST',
26
34
  url: window.location.origin + window.location.pathname + '/solutions' + window.location.search,
27
- data: solution
35
+ data: submission
28
36
  });
29
37
 
30
- return $.ajax(request).done(function (result) {
31
- lastSubmission = { content: solution, result: result };
38
+ return $.ajax(request).then(preRenderResult).done(function (result) {
39
+ lastSubmission = { content: {solution: submission.solution}, result: result };
32
40
  });
33
41
  }
34
42
 
43
+
44
+ /**
45
+ * Pre-renders some html parts of submission UI
46
+ * */
47
+ function preRenderResult(result) {
48
+ result.class_for_progress_list_item = mumuki.renderers.progressListItemClassForStatus(result.status, true)
49
+ return result;
50
+ }
51
+
35
52
  mumuki.load(function () {
36
53
  lastSubmission = {};
37
54
  });
@@ -42,8 +59,12 @@ var mumuki = mumuki || {};
42
59
  // Public API
43
60
  // ==========
44
61
 
45
- // Runs tests for the current exercise using the given submission
46
- // content.
62
+ /**
63
+ * Runs tests for the current exercise using the given submission
64
+ * content.
65
+ *
66
+ * @param {object} content the content object
67
+ * */
47
68
  runTests: function(content) {
48
69
  return this._submitSolution({ solution: content });
49
70
  },
@@ -52,13 +73,18 @@ var mumuki = mumuki || {};
52
73
  // Private API
53
74
  // ===========
54
75
 
55
- _submitSolution: function (solution) {
56
- if(lastSubmissionFinishedSuccessfully() && sameAsLastSolution(solution)){
76
+ /**
77
+ * Sends a solution object
78
+ *
79
+ * @param {Submission} submission the submission object
80
+ */
81
+ _submitSolution: function (submission) {
82
+ if(lastSubmissionFinishedSuccessfully() && sameAsLastSolution(submission)){
57
83
  return $.Deferred().resolve(lastSubmission.result);
58
84
  } else {
59
- return sendNewSolution(solution);
85
+ return sendNewSolution(submission);
60
86
  }
61
- },
87
+ }
62
88
  };
63
89
 
64
90
  mumuki.bridge = {
@@ -1,3 +1,20 @@
1
+ /**
2
+ * A generic button component.
3
+ *
4
+ * It exposes three APIs: low level, common and high level.
5
+ *
6
+ * The low level allows you to control all aspects of the button, but it is legacy
7
+ * and should not be used in new code.
8
+ *
9
+ * The common API offers the start function, which can be used under both the low
10
+ * and high level APIs to configure the initial on-click button handler.
11
+ *
12
+ * The high level allows to implement a simple state-like button handling
13
+ * that goes as follow:
14
+ *
15
+ * 1. simple flow: {init} -start-> {enabled} -wait-> {waiting} -continue-> {enabled}
16
+ * 2. extended flow: {init} -start-> {enabled} -wait-> {waiting} -ready-> {ready-to-continue} -continue-> {enabled}
17
+ */
1
18
  mumuki.Button = class {
2
19
 
3
20
  constructor($button, $container) {
@@ -6,10 +23,78 @@ mumuki.Button = class {
6
23
  this.originalContent = $button.html();
7
24
  }
8
25
 
26
+ // ==========
27
+ // Common API
28
+ // ==========
29
+
30
+ /**
31
+ * Initializes the button, configuring the action that will be called
32
+ * before wating, moving it into the {enabled} state.
33
+ */
34
+ start(main) {
35
+ this.main = (e) => {
36
+ e.preventDefault();
37
+ main();
38
+ };
39
+ this.$button.on('click', this.main)
40
+ }
41
+
42
+ // ==============
43
+ // High level API
44
+ // ==============
45
+
46
+ /**
47
+ * Moves this button into the {waiting} state,
48
+ * disabling its usage and updating its legend
49
+ */
50
+ wait() {
51
+ this.$button.off('click');
52
+
53
+ this.setWaiting();
54
+ }
55
+
56
+ /**
57
+ * Moves this button into {ready-to-continue} state,
58
+ * and sets the given callback to be called before continue.
59
+ *
60
+ * Going through this state is optional.
61
+ */
62
+ ready(secondary) {
63
+ this.$button.off('click');
64
+
65
+ this.undisable();
66
+ this.setRetryText();
67
+
68
+ this.$button.on('click', (e) => {
69
+ e.preventDefault();
70
+ secondary();
71
+ });
72
+ }
73
+
74
+ /**
75
+ * Puts this button back in the {enabled} state,
76
+ * making it ready-to-use.
77
+ */
78
+ continue() {
79
+ this.$button.off('click');
80
+
81
+ this.enable();
82
+
83
+ this.$button.on('click', this.main)
84
+ }
85
+
86
+ // =============
87
+ // Low level API
88
+ // =============
89
+
9
90
  disable () {
10
91
  this.$container.attr('disabled', 'disabled');
11
92
  }
12
93
 
94
+ undisable() {
95
+ this.$container.removeAttr('disabled');
96
+ }
97
+
13
98
  setWaiting () {
14
99
  this.preventClick();
15
100
  this.setWaitingText();
@@ -17,13 +102,17 @@ mumuki.Button = class {
17
102
 
18
103
  enable () {
19
104
  this.setOriginalContent();
20
- this.$container.removeAttr('disabled');
105
+ this.undisable();
21
106
  }
22
107
 
23
108
  setWaitingText () {
24
109
  this.$button.html('<i class="fa fa-refresh fa-spin"></i> ' + this.$button.attr('data-waiting'));
25
110
  }
26
111
 
112
+ setRetryText() {
113
+ this.$button.html('<i class="fa fa-undo"></i>');
114
+ }
115
+
27
116
  setOriginalContent () {
28
117
  this.$button.html(this.originalContent);
29
118
  }