Sha256: fc540eeede8940848aa6f3cba54a8957fcf671115a4d4c9caeb952f6f550c616

Contents?: true

Size: 1.31 KB

Versions: 11

Compression:

Stored size: 1.31 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',
      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

11 entries across 11 versions & 1 rubygems

Version Path
mumuki-laboratory-5.6.3 app/assets/javascripts/application/bridge.js
mumuki-laboratory-5.6.2 app/assets/javascripts/application/bridge.js
mumuki-laboratory-5.6.1 app/assets/javascripts/application/bridge.js
mumuki-laboratory-5.6.0 app/assets/javascripts/application/bridge.js
mumuki-laboratory-5.5.0 app/assets/javascripts/application/bridge.js
mumuki-laboratory-5.4.0 app/assets/javascripts/application/bridge.js
mumuki-laboratory-5.3.0 app/assets/javascripts/application/bridge.js
mumuki-laboratory-5.2.1 app/assets/javascripts/application/bridge.js
mumuki-laboratory-5.2.0 app/assets/javascripts/application/bridge.js
mumuki-laboratory-5.1.1 app/assets/javascripts/application/bridge.js
mumuki-laboratory-5.1.0 app/assets/javascripts/application/bridge.js