Skip to content
Snippets Groups Projects
Commit 70fbd116 authored by iaibrys's avatar iaibrys
Browse files

Move coffeescript to es6; add webpack

parent 459f6a29
Branches
No related tags found
1 merge request!1Feature/remove coffeescript
Pipeline #320 failed
Showing
with 391 additions and 599 deletions
defaults
......@@ -8,5 +8,6 @@ node_modules
load_test/node_modules
vendor/assets/components/
public/assets/
public/packs/
module.exports = {
"extends": ["eslint:recommended", "airbnb-base"],
"env": {
"browser": true,
"commonjs": true,
"es6": true,
"jquery": true
},
"globals": {
},
rules: {
'no-console': 'off',
"no-restricted-syntax": ["error", "ForInStatement", "LabeledStatement", "WithStatement"],
"class-methods-use-this": 'off',
"no-param-reassign": 'off',
"max-len": ["error", 120, 2],
},
};
---
parserOptions:
sourceType: module
ecmaFeatures:
jsx: true
env:
amd: true
browser: true
es6: true
jquery: true
node: true
# http://eslint.org/docs/rules/
rules:
# Possible Errors
no-await-in-loop: off
no-cond-assign: error
no-console: off
no-constant-condition: error
no-control-regex: error
no-debugger: error
no-dupe-args: error
no-dupe-keys: error
no-duplicate-case: error
no-empty-character-class: error
no-empty: error
no-ex-assign: error
no-extra-boolean-cast: error
no-extra-parens: off
no-extra-semi: error
no-func-assign: error
no-inner-declarations:
- error
- functions
no-invalid-regexp: error
no-irregular-whitespace: error
no-negated-in-lhs: error
no-obj-calls: error
no-prototype-builtins: off
no-regex-spaces: error
no-sparse-arrays: error
no-template-curly-in-string: off
no-unexpected-multiline: error
no-unreachable: error
no-unsafe-finally: off
no-unsafe-negation: off
use-isnan: error
valid-jsdoc: off
valid-typeof: error
# Best Practices
accessor-pairs: error
array-callback-return: off
block-scoped-var: off
class-methods-use-this: off
complexity:
- error
- 6
consistent-return: off
curly: off
default-case: off
dot-location: off
dot-notation: off
eqeqeq: error
guard-for-in: error
no-alert: error
no-caller: error
no-case-declarations: error
no-div-regex: error
no-else-return: off
no-empty-function: off
no-empty-pattern: error
no-eq-null: error
no-eval: error
no-extend-native: error
no-extra-bind: error
no-extra-label: off
no-fallthrough: error
no-floating-decimal: off
no-global-assign: off
no-implicit-coercion: off
no-implied-eval: error
no-invalid-this: off
no-iterator: error
no-labels:
- error
- allowLoop: true
allowSwitch: true
no-lone-blocks: error
no-loop-func: error
no-magic-number: off
no-multi-spaces: off
no-multi-str: off
no-native-reassign: error
no-new-func: error
no-new-wrappers: error
no-new: error
no-octal-escape: error
no-octal: error
no-param-reassign: off
no-proto: error
no-redeclare: error
no-restricted-properties: off
no-return-assign: error
no-return-await: off
no-script-url: error
no-self-assign: off
no-self-compare: error
no-sequences: off
no-throw-literal: off
no-unmodified-loop-condition: off
no-unused-expressions: error
no-unused-labels: off
no-useless-call: error
no-useless-concat: error
no-useless-escape: off
no-useless-return: off
no-void: error
no-warning-comments: off
no-with: error
prefer-promise-reject-errors: off
radix: error
require-await: off
vars-on-top: off
wrap-iife: error
yoda: off
# Strict
strict: off
# Variables
init-declarations: off
no-catch-shadow: error
no-delete-var: error
no-label-var: error
no-restricted-globals: off
no-shadow-restricted-names: error
no-shadow: off
no-undef-init: error
no-undef: off
no-undefined: off
no-unused-vars: off
no-use-before-define: off
# Node.js and CommonJS
callback-return: error
global-require: error
handle-callback-err: error
no-mixed-requires: off
no-new-require: off
no-path-concat: error
no-process-env: off
no-process-exit: error
no-restricted-modules: off
no-sync: off
# Stylistic Issues
array-bracket-spacing: off
block-spacing: off
brace-style: off
camelcase: off
capitalized-comments: off
comma-dangle:
- error
- never
comma-spacing: off
comma-style: off
computed-property-spacing: off
consistent-this: off
eol-last: off
func-call-spacing: off
func-name-matching: off
func-names: off
func-style: off
id-length: off
id-match: off
indent: off
jsx-quotes: off
key-spacing: off
keyword-spacing: off
line-comment-position: off
linebreak-style: off
lines-around-comment: off
lines-around-directive: off
max-depth: off
max-len: off
max-nested-callbacks: off
max-params: off
max-statements-per-line: off
max-statements:
- error
- 30
multiline-ternary: off
new-cap: off
new-parens: off
newline-after-var: off
newline-before-return: off
newline-per-chained-call: off
no-array-constructor: off
no-bitwise: off
no-continue: off
no-inline-comments: off
no-lonely-if: off
no-mixed-operators: off
no-mixed-spaces-and-tabs: off
no-multi-assign: off
no-multiple-empty-lines: off
no-negated-condition: off
no-nested-ternary: off
no-new-object: off
no-plusplus: off
no-restricted-syntax: off
no-spaced-func: off
no-tabs: off
no-ternary: off
no-trailing-spaces: off
no-underscore-dangle: off
no-unneeded-ternary: off
object-curly-newline: off
object-curly-spacing: off
object-property-newline: off
one-var-declaration-per-line: off
one-var: off
operator-assignment: off
operator-linebreak: off
padded-blocks: off
quote-props: off
quotes: off
require-jsdoc: off
semi-spacing: off
semi: off
sort-keys: off
sort-vars: off
space-before-blocks: off
space-before-function-paren: off
space-in-parens: off
space-infix-ops: off
space-unary-ops: off
spaced-comment: off
template-tag-spacing: off
unicode-bom: off
wrap-regex: off
# ECMAScript 6
arrow-body-style: off
arrow-parens: off
arrow-spacing: off
constructor-super: off
generator-star-spacing: off
no-class-assign: off
no-confusing-arrow: off
no-const-assign: off
no-dupe-class-members: off
no-duplicate-imports: off
no-new-symbol: off
no-restricted-imports: off
no-this-before-super: off
no-useless-computed-key: off
no-useless-constructor: off
no-useless-rename: off
no-var: off
object-shorthand: off
prefer-arrow-callback: off
prefer-const: off
prefer-destructuring: off
prefer-numeric-literals: off
prefer-rest-params: off
prefer-reflect: off
prefer-spread: off
prefer-template: off
require-yield: off
rest-spread-spacing: off
sort-imports: off
symbol-description: off
template-curly-spacing: off
yield-star-spacing: off
......@@ -29,3 +29,9 @@
/app/assets/images/0*
/public/packs
/public/packs-test
/node_modules
/yarn-error.log
yarn-debug.log*
.yarn-integrity
......@@ -16,10 +16,20 @@ EXPOSE 3000
ENV APP_ROOT /app
WORKDIR $APP_ROOT
# https://github.com/yarnpkg/yarn/issues/3189
#RUN sudo apt-get remove cmdinstall
RUN sudo apt update
RUN sudo apt remove -y cmdtest
RUN sudo apt remove -y yarn
RUN sudo npm install -g yarn
USER dtuuser
ENV CHOWN=dtuuser:dtugroup
RUN yarn --version
# Install the necessary gems
COPY deps ${APP_ROOT}/deps
COPY Gemfile $APP_ROOT/Gemfile
......@@ -27,6 +37,13 @@ COPY Gemfile $APP_ROOT/Gemfile
RUN bundle config github.https true
RUN bundle install
# install node packaages
COPY package.json ${APP_ROOT}/package.json
COPY yarn.lock ${APP_ROOT}/yarn.lock
RUN sudo chown -R ${CHOWN} ~/.npm
RUN sudo chown -R ${CHOWN} ~/.config
RUN yarn install --frozen-lockfile
# Copy application code to container
COPY . $APP_ROOT
RUN sudo chown -R ${CHOWN} $APP_ROOT
......@@ -43,6 +60,9 @@ RUN cp ./known_hosts ~/.ssh
RUN ssh-keygen -R github.com
# precompile assets
RUN ls -als bin
RUN bin/webpack --version
RUN ls
RUN RAILS_ENV=production PRECOMPILE=1 bundle exec rake assets:precompile --trace
RUN echo "Docker container built at $(date)" > ${APP_ROOT}/CONTAINER_INFO.txt
......
......@@ -8,6 +8,8 @@ ruby '2.5.1'
gem 'rails', '~> 5.1.4'
gem 'responders', '~> 2.0'
gem 'sprockets','~> 4.0.0.beta8'
# Use SCSS for stylesheets
gem 'sass-rails', '~> 5.0'
# Use Uglifier as compressor for JavaScript assets
......@@ -138,3 +140,5 @@ group :test do
end
gem 'clipboard-rails'
gem "webpacker", "~> 4.0"
......@@ -94,7 +94,7 @@ GEM
execjs
coffee-script-source (1.12.2)
colorize (0.8.1)
concurrent-ruby (1.1.4)
concurrent-ruby (1.1.5)
crass (1.0.4)
daemons (1.3.1)
data_uri (0.1.0)
......@@ -229,9 +229,11 @@ GEM
method_source (~> 0.9.0)
psych (3.1.0)
public_suffix (3.0.3)
rack (2.0.6)
rack (2.0.7)
rack-cache (1.9.0)
rack (>= 0.4)
rack-proxy (0.6.5)
rack
rack-rewrite (1.5.1)
rack-test (1.1.0)
rack (>= 1.0, < 3)
......@@ -352,7 +354,7 @@ GEM
json (~> 1.7, >= 1.7.7)
rdoc (~> 4.0)
shellany (0.0.1)
sprockets (3.7.2)
sprockets (4.0.0.beta8)
concurrent-ruby (~> 1.0)
rack (> 1, < 3)
sprockets-rails (3.2.1)
......@@ -377,6 +379,10 @@ GEM
activemodel (>= 5.0)
bindex (>= 0.4.0)
railties (>= 5.0)
webpacker (4.0.2)
activesupport (>= 4.2)
rack-proxy (>= 0.6.1)
railties (>= 4.2)
websocket-driver (0.6.5)
websocket-extensions (>= 0.1.0)
websocket-extensions (0.1.3)
......@@ -446,10 +452,12 @@ DEPENDENCIES
rubycas-client (~> 2.3.8)!
sass-rails (~> 5.0)
sdoc (~> 0.4.0)
sprockets (~> 4.0.0.beta8)
thin (~> 1.7.2)
uglifier (>= 1.3.0)
underscore-rails
web-console (~> 3.5.1)
webpacker (~> 4.0)
websocket-rails (= 0.7.0)
RUBY VERSION
......
//= link_tree ../images
//= link_directory ../javascripts .js
//= link application.css
"use strict";
// https://jsfiddle.net/drzaus/9g5qoxwj/
_.mixin({
shallowDiff: function(a, b) {
return _.omit(a, function(v, k) {
return b[k] === v;
})
shallowDiff(a, b) {
return _.omit(a, (v, k) => b[k] === v);
},
diff: function(a, b) {
var r = {};
_.each(a, function(v, k) {
diff(a, b) {
const r = {};
_.each(a, (v, k) => {
if (b[k] === v) return;
if (_.isObject(v)) {
var diff_k = _.diff(v, b[k]);
const diff_k = _.diff(v, b[k]);
if (!_.isEmpty(diff_k)) r[k] = diff_k;
return;
}
r[k] = v;
});
return r;
}
},
});
function Answer() {
this.settings = {}
this.settings = {};
this.quiz_id = function (qid) {
this.settings.quiz_id = qid;
......@@ -53,82 +50,74 @@ function Answer() {
function AjaxAnswer() {
Answer.call(this);
var self = this;
const self = this;
this.setAnswer = function (answer) {
var resource_url = "/quizinstances/" + this.settings.quiz_id +
"/questions/" + this.settings.question_id +
"/answers/" + this.settings.answer_id;
const resource_url = `/quizinstances/${this.settings.quiz_id
}/questions/${this.settings.question_id
}/answers/${this.settings.answer_id}`;
$.ajax({
method: "PUT",
method: 'PUT',
url: resource_url,
data: JSON.stringify(answer, null, 2)
data: JSON.stringify(answer, null, 2),
})
.done(function (data, textStatus, jqXHR) {
self.settings.success.apply(self, arguments);
})
.fail(function (jqXHR, textStatus, errorThrown) {
self.settings.fail.apply(self, arguments)
self.settings.fail.apply(self, arguments);
});
}
};
}
function WebSocketAnswer() {
Answer.call(this);
var self = this;
const self = this;
this.setAnswer = function (answer) {
answer = {
new_answer: answer,
quiz_id: this.settings.quiz_id,
question_id: this.settings.question_id,
answer_id: this.settings.answer_id
answer_id: this.settings.answer_id,
};
window.QUIZ_GLOBALS.dispatcher.trigger('answers.answer', answer, this.settings.success, this.settings.fail);
}
};
}
function getIds(target_node) {
var question = target_node.closest(".quiz-question");
var quiz = question.closest("article.quiz");
const question = target_node.closest('.quiz-question');
const quiz = question.closest('article.quiz');
return {
quiz_id: quiz.attr('id'),
quiz: quiz,
quiz,
question_id: question.attr('id'),
question: question,
question,
target_id: target_node.attr('id'),
target: target_node
}
target: target_node,
};
}
function getModelIndices(ids) {
const question_idx = _.findIndex(window.QUIZ_GLOBALS.quiz_model.sections, q => q._id && (q._id.$oid === ids.question_id));
var question_idx = _.findIndex(window.QUIZ_GLOBALS.quiz_model.sections, function(q) {
return q._id && (q._id.$oid === ids.question_id)
})
var answer_idx = _.findIndex(window.QUIZ_GLOBALS.quiz_model.sections[question_idx].answers, function(a) {
return a._id && (a._id.$oid === ids.target_id)
})
const answer_idx = _.findIndex(window.QUIZ_GLOBALS.quiz_model.sections[question_idx].answers, a => a._id && (a._id.$oid === ids.target_id));
return {
question_idx: question_idx,
answer_idx: answer_idx
question_idx,
answer_idx,
};
}
// update the internal model with the one from the server
function updateAnswer(ids, new_answer) {
const model_indices = getModelIndices(ids);
var model_indices = getModelIndices(ids);
var current_question = window.QUIZ_GLOBALS.quiz_model.sections[model_indices.question_idx]
var current_answer = current_question.answers[model_indices.answer_idx]
const current_question = window.QUIZ_GLOBALS.quiz_model.sections[model_indices.question_idx];
const current_answer = current_question.answers[model_indices.answer_idx];
current_answer.user_set = true;
if (new_answer.hasOwnProperty('text')) {
......@@ -138,12 +127,12 @@ function updateAnswer(ids, new_answer) {
} else if (new_answer.hasOwnProperty('image')) {
current_answer.image = new_answer.image;
} else {
_.each(_.range(current_question.answers.length), function(i) {
_.each(_.range(current_question.answers.length), (i) => {
if (current_question.answers[i].user_set) {
current_question.answers[i].value = i === model_indices.answer_idx;
current_question.answers[i].user_set = i === model_indices.answer_idx;
}
})
});
}
window.QUIZ_GLOBALS.last_edit_time = (new Date());
......@@ -152,12 +141,11 @@ function updateAnswer(ids, new_answer) {
}
function selfCheckAnswer(ids, server_question) {
const model_indices = getModelIndices(ids);
var model_indices = getModelIndices(ids);
var diff = _.diff(window.QUIZ_GLOBALS.quiz_model.sections[model_indices.question_idx], server_question);
const diff = _.diff(window.QUIZ_GLOBALS.quiz_model.sections[model_indices.question_idx], server_question);
console.log("question diffs:");
console.log('question diffs:');
console.log(diff);
if (!_.isEmpty(diff)) {
console.error('Differences detected!');
......@@ -167,30 +155,30 @@ function selfCheckAnswer(ids, server_question) {
}
function setAnswer(e, new_answer) {
var ids = getIds($((e || window.event).target));
const ids = getIds($((e || window.event).target));
ids.question.removeClass("quiz-question-touched");
ids.question.removeClass('quiz-question-touched');
var success = function(data, textStatus, jqXHR) {
const success = function (data, textStatus, jqXHR) {
selfCheckAnswer(ids, data);
ids.question.addClass("quiz-question-touched");
}
ids.question.addClass('quiz-question-touched');
};
var fail = function(jqXHR, textStatus, errorThrown) {
console.error("failed answer set: " + JSON.stringify(jqXHR, null, 2));
ids.question.addClass("quiz-question-failed-to-update");
const fail = function (jqXHR, textStatus, errorThrown) {
console.error(`failed answer set: ${JSON.stringify(jqXHR, null, 2)}`);
ids.question.addClass('quiz-question-failed-to-update');
connectionTimeout();
}
};
var a;
let a;
if (preferredConnection() === 'websockets') {
a = (new WebSocketAnswer());
} else {
a = (new AjaxAnswer());
}
var answer = new_answer(ids);
const answer = new_answer(ids);
updateAnswer(ids, answer);
......@@ -203,72 +191,67 @@ function setAnswer(e, new_answer) {
}
function mcChange(e) {
setAnswer(e, function(ids) {
return {}
});
setAnswer(e, ids => ({}));
}
function cbChange(e) {
setAnswer(e, function(ids) {
setAnswer(e, (ids) => {
// ISSUE #105 :
// For reasons unknown, it seems that at least in Chrome checked does not go away when the button is unchecked.
// So we take a more heavy-handed approach here.
var model_indices = getModelIndices(ids)
const model_indices = getModelIndices(ids);
var current_question = window.QUIZ_GLOBALS.quiz_model.sections[model_indices.question_idx]
var current_answer = current_question.answers[model_indices.answer_idx]
const current_question = window.QUIZ_GLOBALS.quiz_model.sections[model_indices.question_idx];
const current_answer = current_question.answers[model_indices.answer_idx];
var new_ans = !current_answer.value
const new_ans = !current_answer.value;
if (new_ans) {
ids.target.attr("checked", "checked")
ids.target.attr('checked', 'checked');
} else {
ids.target.removeAttr("checked")
ids.target.removeAttr('checked');
}
return {
checked: ids.target.is(":checked")
}
checked: ids.target.is(':checked'),
};
});
}
function freeTextChanged(e) {
setAnswer(e, function(ids) {
return {
text: ids.target.val()
}
});
setAnswer(e, ids => ({
text: ids.target.val(),
}));
}
function freeTextEdit(e) {
var ids = getIds($((e || window.event).target));
const ids = getIds($((e || window.event).target));
if (window.QUIZ_GLOBALS.hasOwnProperty("textChangeTimer" + ids.question_id)) {
clearTimeout(window.QUIZ_GLOBALS["textChangeTimer" + ids.question_id])
delete window.QUIZ_GLOBALS["textChangeTimer" + ids.question_id]
if (window.QUIZ_GLOBALS.hasOwnProperty(`textChangeTimer${ids.question_id}`)) {
clearTimeout(window.QUIZ_GLOBALS[`textChangeTimer${ids.question_id}`]);
delete window.QUIZ_GLOBALS[`textChangeTimer${ids.question_id}`];
}
window.QUIZ_GLOBALS["textChangeTimer" + ids.question_id] = setTimeout(function() {
delete window.QUIZ_GLOBALS["textChangeTimer" + ids.question_id]
freeTextChanged(e)
}, 1000)
window.QUIZ_GLOBALS[`textChangeTimer${ids.question_id}`] = setTimeout(() => {
delete window.QUIZ_GLOBALS[`textChangeTimer${ids.question_id}`];
freeTextChanged(e);
}, 1000);
}
function fillInTheBlankEdit(e) {
freeTextEdit(e)
freeTextEdit(e);
}
function surveyEdit(e) {
freeTextEdit(e)
freeTextEdit(e);
}
function fillInTheBlankChanged(e) {
freeTextChanged(e)
freeTextChanged(e);
}
function surveyChanged(e) {
freeTextChanged(e)
freeTextChanged(e);
}
......@@ -30,6 +30,5 @@
//= require dtu_core_app/application
"use strict";
$('.datetimepicker').datetimepicker();
"use strict";
// From http://stackoverflow.com/questions/9850707/how-to-show-line-numbers-for-a-code-block-using-javascript
function addCodeLineNumbers(code) {
if (typeof (code) === 'undefined') {
$("code").each(function() {
$('code').each(function () {
console.log(this);
addCodeLineNumbers(this);
});
......@@ -12,14 +11,14 @@ function addCodeLineNumbers(code) {
return;
}
var line = 0;
code.innerHTML = (code.innerHTML.replace(/^/gm, function() {
let line = 0;
code.innerHTML = (code.innerHTML.replace(/^/gm, () => {
line++;
return '<span class="line-number-position">&#x200b;<span class="line-number">ii!' + line + '</span></span>';
return `<span class="line-number-position">&#x200b;<span class="line-number">ii!${line}</span></span>`;
}));
}
$(document).ready(function() {
$(document).ready(() => {
// Not needed is kramdown's default to number if the language is specified is sufficient.
// addCodeLineNumbers()
});
......@@ -3,8 +3,8 @@ function connectionTimeout() {
// modal is already open
// TODO: maybe show some indication of continued checking?
} else {
console.warn("toggle timeout")
$("#connection-timeout-modal").modal('toggle');
console.warn('toggle timeout');
$('#connection-timeout-modal').modal('toggle');
setTimeout(checkConnection, 2000);
}
......@@ -12,14 +12,13 @@ function connectionTimeout() {
function connectionOk() {
if ($('#connection-timeout-modal').hasClass('in')) {
$("#connection-timeout-modal").modal('toggle');
$('#connection-timeout-modal').modal('toggle');
}
}
function checkConnection() {
if (window.QUIZ_GLOBALS.dispatcher.connection_stale()) {
var rec = window.QUIZ_GLOBALS.dispatcher.reconnect();
const rec = window.QUIZ_GLOBALS.dispatcher.reconnect();
setTimeout(checkConnection, 2000);
} else {
connectionOk();
......@@ -33,14 +32,12 @@ function connectionProblem(data) {
}
function preferredConnection() {
if (window.QUIZ_GLOBALS.preferred_connection === 'websockets' && window.QUIZ_GLOBALS.dispatcher)
return "websockets";
return "ajax";
if (window.QUIZ_GLOBALS.preferred_connection === 'websockets' && window.QUIZ_GLOBALS.dispatcher) return 'websockets';
return 'ajax';
}
$(document).on('ready page:load', function() {
var pathparts = window.location.pathname.split('/');
$(document).on('ready page:load', () => {
const pathparts = window.location.pathname.split('/');
if (pathparts[1] !== 'quiz') {
closePage();
......@@ -50,10 +47,10 @@ $(document).on('ready page:load', function() {
return;
}
var url = window.location.href;
var host_and_url = url.split('/')[2];
const url = window.location.href;
const host_and_url = url.split('/')[2];
var dispatcher = new WebSocketRails(host_and_url + '/websocket');
const dispatcher = new WebSocketRails(`${host_and_url}/websocket`);
window.QUIZ_GLOBALS.dispatcher = null;
window.QUIZ_GLOBALS.timer = null;
......@@ -69,7 +66,7 @@ $(document).on('ready page:load', function() {
connectionOk();
beginQuiz();
}
};
dispatcher.on_error = connectionProblem;
dispatcher.bind('connection_error', connectionProblem);
......@@ -97,6 +94,6 @@ function closePage() {
}
}
$(window).on('hashchange', function() {
$(window).on('hashchange', () => {
console.log('hash change');
})
\ No newline at end of file
});
# Place all the behaviors and hooks related to the matching controller here.
# All this logic will automatically be available in application.js.
# You can use CoffeeScript in this file: http://coffeescript.org/
class CoursesPage
constructor: () ->
self = this
if (CoursesPage.instance)
console?.error "Multiple CoursesPage"
return
CoursesPage.instance = this
console?.log "CoursesPage"
# prevent the value from being selected if we return to this page via
# the back button
# Issue#106
$("#course-selector")[0].selectedIndex = -1
#
# Helpers
#
#
# Data
#
@instance: null
@initPage: () ->
instance = CoursesPage()
@isCoursesPage: () ->
parts = window.location.pathname.split('/').filter (d) ->
return d
if (parts.length != 1)
return false
return (parts[0] == "courses")
window.CoursesPage = CoursesPage
/*
* decaffeinate suggestions:
* DS102: Remove unnecessary code created because of implicit returns
* DS206: Consider reworking classes to avoid initClass
* DS207: Consider shorter variations of null checks
* Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
*/
// Place all the behaviors and hooks related to the matching controller here.
// All this logic will automatically be available in application.js.
// You can use CoffeeScript in this file: http://coffeescript.org/
class CoursesPage {
static initClass() {
//
// Helpers
//
//
// Data
//
this.instance = null;
}
constructor() {
const self = this;
if (CoursesPage.instance) {
if (typeof console !== 'undefined' && console !== null) {
console.error('Multiple CoursesPage');
}
return;
}
CoursesPage.instance = this;
if (typeof console !== 'undefined' && console !== null) {
console.log('CoursesPage');
}
// prevent the value from being selected if we return to this page via
// the back button
// Issue#106
$('#course-selector')[0].selectedIndex = -1;
}
static initPage() {
let instance;
return instance = CoursesPage();
}
static isCoursesPage() {
const parts = window.location.pathname.split('/').filter(d => d);
if (parts.length !== 1) {
return false;
}
return (parts[0] === 'courses');
}
}
CoursesPage.initClass();
window.CoursesPage = CoursesPage;
......@@ -6,16 +6,16 @@ function crc32 ( str ) {
// * example 1: crc32('Kevin van Zonneveld');
// * returns 1: 1249991249
var table = "00000000 77073096 EE0E612C 990951BA 076DC419 706AF48F E963A535 9E6495A3 0EDB8832 79DCB8A4 E0D5E91E 97D2D988 09B64C2B 7EB17CBD E7B82D07 90BF1D91 1DB71064 6AB020F2 F3B97148 84BE41DE 1ADAD47D 6DDDE4EB F4D4B551 83D385C7 136C9856 646BA8C0 FD62F97A 8A65C9EC 14015C4F 63066CD9 FA0F3D63 8D080DF5 3B6E20C8 4C69105E D56041E4 A2677172 3C03E4D1 4B04D447 D20D85FD A50AB56B 35B5A8FA 42B2986C DBBBC9D6 ACBCF940 32D86CE3 45DF5C75 DCD60DCF ABD13D59 26D930AC 51DE003A C8D75180 BFD06116 21B4F4B5 56B3C423 CFBA9599 B8BDA50F 2802B89E 5F058808 C60CD9B2 B10BE924 2F6F7C87 58684C11 C1611DAB B6662D3D 76DC4190 01DB7106 98D220BC EFD5102A 71B18589 06B6B51F 9FBFE4A5 E8B8D433 7807C9A2 0F00F934 9609A88E E10E9818 7F6A0DBB 086D3D2D 91646C97 E6635C01 6B6B51F4 1C6C6162 856530D8 F262004E 6C0695ED 1B01A57B 8208F4C1 F50FC457 65B0D9C6 12B7E950 8BBEB8EA FCB9887C 62DD1DDF 15DA2D49 8CD37CF3 FBD44C65 4DB26158 3AB551CE A3BC0074 D4BB30E2 4ADFA541 3DD895D7 A4D1C46D D3D6F4FB 4369E96A 346ED9FC AD678846 DA60B8D0 44042D73 33031DE5 AA0A4C5F DD0D7CC9 5005713C 270241AA BE0B1010 C90C2086 5768B525 206F85B3 B966D409 CE61E49F 5EDEF90E 29D9C998 B0D09822 C7D7A8B4 59B33D17 2EB40D81 B7BD5C3B C0BA6CAD EDB88320 9ABFB3B6 03B6E20C 74B1D29A EAD54739 9DD277AF 04DB2615 73DC1683 E3630B12 94643B84 0D6D6A3E 7A6A5AA8 E40ECF0B 9309FF9D 0A00AE27 7D079EB1 F00F9344 8708A3D2 1E01F268 6906C2FE F762575D 806567CB 196C3671 6E6B06E7 FED41B76 89D32BE0 10DA7A5A 67DD4ACC F9B9DF6F 8EBEEFF9 17B7BE43 60B08ED5 D6D6A3E8 A1D1937E 38D8C2C4 4FDFF252 D1BB67F1 A6BC5767 3FB506DD 48B2364B D80D2BDA AF0A1B4C 36034AF6 41047A60 DF60EFC3 A867DF55 316E8EEF 4669BE79 CB61B38C BC66831A 256FD2A0 5268E236 CC0C7795 BB0B4703 220216B9 5505262F C5BA3BBE B2BD0B28 2BB45A92 5CB36A04 C2D7FFA7 B5D0CF31 2CD99E8B 5BDEAE1D 9B64C2B0 EC63F226 756AA39C 026D930A 9C0906A9 EB0E363F 72076785 05005713 95BF4A82 E2B87A14 7BB12BAE 0CB61B38 92D28E9B E5D5BE0D 7CDCEFB7 0BDBDF21 86D3D2D4 F1D4E242 68DDB3F8 1FDA836E 81BE16CD F6B9265B 6FB077E1 18B74777 88085AE6 FF0F6A70 66063BCA 11010B5C 8F659EFF F862AE69 616BFFD3 166CCF45 A00AE278 D70DD2EE 4E048354 3903B3C2 A7672661 D06016F7 4969474D 3E6E77DB AED16A4A D9D65ADC 40DF0B66 37D83BF0 A9BCAE53 DEBB9EC5 47B2CF7F 30B5FFE9 BDBDF21C CABAC28A 53B39330 24B4A3A6 BAD03605 CDD70693 54DE5729 23D967BF B3667A2E C4614AB8 5D681B02 2A6F2B94 B40BBE37 C30C8EA1 5A05DF1B 2D02EF8D";
const table = '00000000 77073096 EE0E612C 990951BA 076DC419 706AF48F E963A535 9E6495A3 0EDB8832 79DCB8A4 E0D5E91E 97D2D988 09B64C2B 7EB17CBD E7B82D07 90BF1D91 1DB71064 6AB020F2 F3B97148 84BE41DE 1ADAD47D 6DDDE4EB F4D4B551 83D385C7 136C9856 646BA8C0 FD62F97A 8A65C9EC 14015C4F 63066CD9 FA0F3D63 8D080DF5 3B6E20C8 4C69105E D56041E4 A2677172 3C03E4D1 4B04D447 D20D85FD A50AB56B 35B5A8FA 42B2986C DBBBC9D6 ACBCF940 32D86CE3 45DF5C75 DCD60DCF ABD13D59 26D930AC 51DE003A C8D75180 BFD06116 21B4F4B5 56B3C423 CFBA9599 B8BDA50F 2802B89E 5F058808 C60CD9B2 B10BE924 2F6F7C87 58684C11 C1611DAB B6662D3D 76DC4190 01DB7106 98D220BC EFD5102A 71B18589 06B6B51F 9FBFE4A5 E8B8D433 7807C9A2 0F00F934 9609A88E E10E9818 7F6A0DBB 086D3D2D 91646C97 E6635C01 6B6B51F4 1C6C6162 856530D8 F262004E 6C0695ED 1B01A57B 8208F4C1 F50FC457 65B0D9C6 12B7E950 8BBEB8EA FCB9887C 62DD1DDF 15DA2D49 8CD37CF3 FBD44C65 4DB26158 3AB551CE A3BC0074 D4BB30E2 4ADFA541 3DD895D7 A4D1C46D D3D6F4FB 4369E96A 346ED9FC AD678846 DA60B8D0 44042D73 33031DE5 AA0A4C5F DD0D7CC9 5005713C 270241AA BE0B1010 C90C2086 5768B525 206F85B3 B966D409 CE61E49F 5EDEF90E 29D9C998 B0D09822 C7D7A8B4 59B33D17 2EB40D81 B7BD5C3B C0BA6CAD EDB88320 9ABFB3B6 03B6E20C 74B1D29A EAD54739 9DD277AF 04DB2615 73DC1683 E3630B12 94643B84 0D6D6A3E 7A6A5AA8 E40ECF0B 9309FF9D 0A00AE27 7D079EB1 F00F9344 8708A3D2 1E01F268 6906C2FE F762575D 806567CB 196C3671 6E6B06E7 FED41B76 89D32BE0 10DA7A5A 67DD4ACC F9B9DF6F 8EBEEFF9 17B7BE43 60B08ED5 D6D6A3E8 A1D1937E 38D8C2C4 4FDFF252 D1BB67F1 A6BC5767 3FB506DD 48B2364B D80D2BDA AF0A1B4C 36034AF6 41047A60 DF60EFC3 A867DF55 316E8EEF 4669BE79 CB61B38C BC66831A 256FD2A0 5268E236 CC0C7795 BB0B4703 220216B9 5505262F C5BA3BBE B2BD0B28 2BB45A92 5CB36A04 C2D7FFA7 B5D0CF31 2CD99E8B 5BDEAE1D 9B64C2B0 EC63F226 756AA39C 026D930A 9C0906A9 EB0E363F 72076785 05005713 95BF4A82 E2B87A14 7BB12BAE 0CB61B38 92D28E9B E5D5BE0D 7CDCEFB7 0BDBDF21 86D3D2D4 F1D4E242 68DDB3F8 1FDA836E 81BE16CD F6B9265B 6FB077E1 18B74777 88085AE6 FF0F6A70 66063BCA 11010B5C 8F659EFF F862AE69 616BFFD3 166CCF45 A00AE278 D70DD2EE 4E048354 3903B3C2 A7672661 D06016F7 4969474D 3E6E77DB AED16A4A D9D65ADC 40DF0B66 37D83BF0 A9BCAE53 DEBB9EC5 47B2CF7F 30B5FFE9 BDBDF21C CABAC28A 53B39330 24B4A3A6 BAD03605 CDD70693 54DE5729 23D967BF B3667A2E C4614AB8 5D681B02 2A6F2B94 B40BBE37 C30C8EA1 5A05DF1B 2D02EF8D';
var crc = 0;
var x = 0;
var y = 0;
let crc = 0;
let x = 0;
let y = 0;
crc = crc ^ (-1);
for( var i = 0, iTop = str.length; i < iTop; i++ ) {
crc ^= (-1);
for (let i = 0, iTop = str.length; i < iTop; i++) {
y = (crc ^ str.charCodeAt(i)) & 0xFF;
x = "0x" + table.substr( y * 9, 8 );
x = `0x${table.substr(y * 9, 8)}`;
crc = (crc >>> 8) ^ x;
}
......
class DontKnow
constructor: ->
self = this
cb = (v) ->
self.changed(v, this)
$(".dont-know input").change( cb )
changed: (v, el) ->
self = this
checkbox = $(el)
dis = checkbox.is(':checked') ? 'disabled' : 'enabled'
success = () ->
checkbox
.closest('.quiz-question')
.find('.quiz-student-answer input')
.attr('disabled', dis)
fail = () ->
self.updateDontKnowLocalState(checkbox, !dis)
this.setDontKnow(checkbox, success, fail)
updateDontKnowLocalState: (el, state) ->
if (state)
el.attr("checked", "checked")
else
el.removeAttr("checked")
setDontKnow: (el, success, fail) ->
this.setDontKnowAjax(el, success, fail)
setDontKnowAjax: (el, success, fail) ->
ids = getIds(el)
dis = el.is(':checked') ? 'disabled' : 'enabled'
resource_url = "/quizinstances/" +
ids.quiz_id +
"/questions/" +
ids.question_id +
"/dontknow/x"
ajax_parms = {
method: "PUT",
url: resource_url,
data: JSON.stringify({ new_dontknow: dis }, null, 2)
}
$.ajax(ajax_parms)
.done(success)
.fail(fail)
setDontKnowWebsocket: (el, success, fail) ->
ids = getIds($(el))
req = {
quiz_id: ids.quiz_id,
question_id: ids.question_id,
hint_id: ids.target_id
}
disp = window.QUIZ_GLOBALS.dispatcher
disp.trigger('dontknow.request_dontknow', req, success, fail)
window.DontKnow = DontKnow
\ No newline at end of file
/*
* decaffeinate suggestions:
* DS102: Remove unnecessary code created because of implicit returns
* DS104: Avoid inline assignments
* DS207: Consider shorter variations of null checks
* Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
*/
class DontKnow {
constructor() {
const self = this;
const cb = function (v) {
return self.changed(v, this);
};
$('.dont-know input').change(cb);
}
changed(v, el) {
let left;
const self = this;
const checkbox = $(el);
const dis = (left = checkbox.is(':checked')) != null ? left : { disabled: 'enabled' };
const success = () => checkbox
.closest('.quiz-question')
.find('.quiz-student-answer input')
.attr('disabled', dis);
const fail = () => self.updateDontKnowLocalState(checkbox, !dis);
return this.setDontKnow(checkbox, success, fail);
}
updateDontKnowLocalState(el, state) {
if (state) {
return el.attr('checked', 'checked');
}
return el.removeAttr('checked');
}
setDontKnow(el, success, fail) {
return this.setDontKnowAjax(el, success, fail);
}
setDontKnowAjax(el, success, fail) {
let left;
const ids = getIds(el);
const dis = (left = el.is(':checked')) != null ? left : { disabled: 'enabled' };
const resource_url = `/quizinstances/${
ids.quiz_id
}/questions/${
ids.question_id
}/dontknow/x`;
const ajax_parms = {
method: 'PUT',
url: resource_url,
data: JSON.stringify({ new_dontknow: dis }, null, 2),
};
return $.ajax(ajax_parms)
.done(success)
.fail(fail);
}
setDontKnowWebsocket(el, success, fail) {
const ids = getIds($(el));
const req = {
quiz_id: ids.quiz_id,
question_id: ids.question_id,
hint_id: ids.target_id,
};
const disp = window.QUIZ_GLOBALS.dispatcher;
return disp.trigger('dontknow.request_dontknow', req, success, fail);
}
}
window.DontKnow = DontKnow;
function flash(kind, message) {
var allowed_kinds = ['alert-success', 'alert-info', 'alert-warning', 'alert-danger']
const allowed_kinds = ['alert-success', 'alert-info', 'alert-warning', 'alert-danger'];
if (allowed_kinds.indexOf(kind) === -1) {
console.error("ASSERT: invalid flash message kind " + kind)
console.error(`ASSERT: invalid flash message kind ${kind}`);
}
var now = new Date()
var timestamp = ('0' + now.getHours()).slice(-2) + ":" + ('0' + now.getMinutes()).slice(-2)
const now = new Date();
const timestamp = `${(`0${now.getHours()}`).slice(-2)}:${(`0${now.getMinutes()}`).slice(-2)}`;
var flash_html =
'<div class="alert ' + kind + ' fade in">' +
'<button class="close" data-dismiss="alert">&times;</button>' +
'<b>' + timestamp + '</b>: ' + message +
'</div>';
const flash_html = `<div class="alert ${kind} fade in">`
+ '<button class="close" data-dismiss="alert">&times;</button>'
+ `<b>${timestamp}</b>: ${message
}</div>`;
var flash_msg = $(flash_html)
const flash_msg = $(flash_html);
// flash_msg.prependTo($("#main-container"))
$("#flash-message").empty()
flash_msg.prependTo("#flash-message")
$('#flash-message').empty();
flash_msg.prependTo('#flash-message');
}
"use strict";
function requestHintAjax(success, fail) {
var ids = getIds($(this));
const ids = getIds($(this));
var resource_url = "/quizinstances/" + ids.quiz_id + "/questions/" + ids.question_id + "/hints/" + ids.target_id;
const resource_url = `/quizinstances/${ids.quiz_id}/questions/${ids.question_id}/hints/${ids.target_id}`;
var ajax_parms = {
method: "GET",
const ajax_parms = {
method: 'GET',
url: resource_url,
data: JSON.stringify({}, null, 2)
data: JSON.stringify({}, null, 2),
};
$.ajax(ajax_parms)
......@@ -17,50 +17,49 @@ function requestHintAjax(success, fail) {
}
function requestHintWebsocket(success, fail) {
var ids = getIds($(this));
const ids = getIds($(this));
var req = {
const req = {
quiz_id: ids.quiz_id,
question_id: ids.question_id,
hint_id: ids.target_id
hint_id: ids.target_id,
};
window.QUIZ_GLOBALS.dispatcher.trigger('hints.request_hint', req, success, fail);
}
function requestHint() {
var hintButton = this;
var success = function(data) {
var hints = $(hintButton).closest('.quiz-hint-list')
var id = $(hintButton).attr('id')
var name = $(hintButton).attr('name')
var hint_html =
'<div id="' + id + '" name="' + name + '" class="span9 hint-toolbar">' +
'<div class="span9 quiz-hint-item-container ">' +
'<div class="quiz-hint-label">' +
'<div class="">Hint</div>' +
'</div>' +
'<div class="hint quiz-hint-item ">' +
data.text +
'</div>' +
'</div>' +
'</div>'
$(hintButton).replaceWith(hint_html)
MathJax.Hub.Queue(["Typeset", MathJax.Hub, id]);
var nextHint = hints.find('.hidden-hint:first')
nextHint.removeClass("hidden-hint")
nextHint.prop("disabled", false)
console.log("succeeded hint request set: " + JSON.stringify(data, null, 2));
}
const hintButton = this;
const success = function (data) {
const hints = $(hintButton).closest('.quiz-hint-list');
const id = $(hintButton).attr('id');
const name = $(hintButton).attr('name');
const hint_html = `<div id="${id}" name="${name}" class="span9 hint-toolbar">`
+ '<div class="span9 quiz-hint-item-container ">'
+ '<div class="quiz-hint-label">'
+ '<div class="">Hint</div>'
+ '</div>'
+ `<div class="hint quiz-hint-item ">${
data.text
}</div>`
+ '</div>'
+ '</div>';
$(hintButton).replaceWith(hint_html);
MathJax.Hub.Queue(['Typeset', MathJax.Hub, id]);
const nextHint = hints.find('.hidden-hint:first');
nextHint.removeClass('hidden-hint');
nextHint.prop('disabled', false);
console.log(`succeeded hint request set: ${JSON.stringify(data, null, 2)}`);
};
var fail = function(jqXHR, textStatus, errorThrown) {
console.log("failed hint request set: " + JSON.stringify(jqXHR, null, 2));
const fail = function (jqXHR, textStatus, errorThrown) {
console.log(`failed hint request set: ${JSON.stringify(jqXHR, null, 2)}`);
connectionTimeout();
}
};
if (preferredConnection() === 'websockets') {
requestHintWebsocket.call(this, success, fail);
......@@ -70,10 +69,10 @@ function requestHint() {
}
function onShowHintModal(e) {
var hintButton = e.relatedTarget;
var modal = e.target;
const hintButton = e.relatedTarget;
const modal = e.target;
$('button[data-result="take-hint"]').unbind('click').on('click', function(e) {
$('button[data-result="take-hint"]').unbind('click').on('click', (e) => {
$(modal).modal('toggle');
requestHint.call(hintButton);
});
......@@ -81,7 +80,6 @@ function onShowHintModal(e) {
// page:load required to deal with turbo links issue: http://stackoverflow.com/questions/18770517/rails-4-how-to-use-document-ready-with-turbo-links
$(document).on('ready page:load', function() {
"use strict";
$('#take-hint-modal').on('show.bs.modal', onShowHintModal)
$(document).on('ready page:load', () => {
$('#take-hint-modal').on('show.bs.modal', onShowHintModal);
});
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment