Sha256: 90c2206097bb1d4694b8c0e6c44737092d798799f5132ec067b100df1dd2e159

Contents?: true

Size: 1.34 KB

Versions: 32

Compression:

Stored size: 1.34 KB

Contents

var mumuki = mumuki || {};

(function (mumuki) {
  var lastSubmission = {};

  function Laboratory(exerciseId){
    this.exerciseId = exerciseId;
  }

  function asString(json){
    return JSON.stringify(json);
  }

  function sameAsLastSolution(newSolution){
    return asString(lastSubmission.content) === asString(newSolution);
  }

  function lastSubmissionFinishedSuccessfully(){
    return lastSubmission.result && lastSubmission.result.status !== 'aborted';
  }

  function sendNewSolution(solution){
    var token = new mumuki.CsrfToken();
    var request = token.newRequest({
      type: 'POST',
      url: window.location.origin + window.location.pathname + '/solutions' + window.location.search,
      data: solution
    });

    return $.ajax(request).done(function (result) {
      lastSubmission = { content: solution, result: result };
    });
  }

  mumuki.load(function () {
    lastSubmission = {};
  });

  Laboratory.prototype = {
    runLocalTests: function (solution) {
      if(lastSubmissionFinishedSuccessfully() && sameAsLastSolution(solution)){
        return $.Deferred().resolve(lastSubmission.result);
      } else {
        return sendNewSolution(solution);
      }
    },
    runTests: function(content) {
      return this.runLocalTests({ solution: content });
    }
  };

  mumuki.bridge = {
    Laboratory: Laboratory
  };

}(mumuki));

Version data entries

32 entries across 32 versions & 1 rubygems

Version Path
mumuki-laboratory-6.5.1 app/assets/javascripts/application/bridge.js
mumuki-laboratory-6.5.0 app/assets/javascripts/application/bridge.js
mumuki-laboratory-6.4.2 app/assets/javascripts/application/bridge.js
mumuki-laboratory-6.4.1 app/assets/javascripts/application/bridge.js
mumuki-laboratory-6.4.0 app/assets/javascripts/application/bridge.js
mumuki-laboratory-6.2.0 app/assets/javascripts/application/bridge.js
mumuki-laboratory-6.1.5 app/assets/javascripts/application/bridge.js
mumuki-laboratory-6.0.4 app/assets/javascripts/application/bridge.js
mumuki-laboratory-6.1.4 app/assets/javascripts/application/bridge.js
mumuki-laboratory-6.1.3 app/assets/javascripts/application/bridge.js
mumuki-laboratory-6.0.3 app/assets/javascripts/application/bridge.js
mumuki-laboratory-6.1.2 app/assets/javascripts/application/bridge.js
mumuki-laboratory-6.1.1 app/assets/javascripts/application/bridge.js
mumuki-laboratory-6.1.0 app/assets/javascripts/application/bridge.js
mumuki-laboratory-6.0.2 app/assets/javascripts/application/bridge.js
mumuki-laboratory-6.0.1 app/assets/javascripts/application/bridge.js
mumuki-laboratory-6.0.0 app/assets/javascripts/application/bridge.js
mumuki-laboratory-5.13.0 app/assets/javascripts/application/bridge.js
mumuki-laboratory-5.12.1 app/assets/javascripts/application/bridge.js
mumuki-laboratory-5.12.0 app/assets/javascripts/application/bridge.js