forked from instructure/canvas-lms
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refs CNVS-25916 remove dynamic requirements for env configs, use separate jsx loader for client apps, update client app plugin to use old react version, rewrite selenium spec to be an integration test rather than executing arbitrary javascript, and MAJORLY refactor loading patterns of client apps to avoid sharing code with differences delineated by opaque require re-writes. Also moved some code that was in "common" client app but only used by one actual client app down into the app that uses it (simplifies dependency tracing). TEST PLAN: 1) make sure quiz statistics still works ok under require js build, no behavior should have changed 2) also make sure quiz log auding works under require-js Change-Id: I0e5ee3eda9da16e0ad48cf858761735c71df801c Reviewed-on: https://gerrit.instructure.com/69804 Tested-by: Jenkins Reviewed-by: Ryan Taylor <[email protected]> QA-Review: Michael Hargiss <[email protected]> Product-Review: Ethan Vizitei <[email protected]>
- Loading branch information
Showing
37 changed files
with
372 additions
and
738 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,96 +1,96 @@ | ||
define(function(require, exports, module) { | ||
var _ = require('lodash'); | ||
var config = require('app/config/environments/production'); | ||
var callbacks = []; | ||
var loaded; | ||
var config = require('app/config/environments/production'); | ||
var callbacks = []; | ||
var loaded; | ||
|
||
if (!config) { | ||
config = {}; | ||
} | ||
if (!config) { | ||
config = {}; | ||
} | ||
|
||
config.onLoad = function(callback) { | ||
if (loaded) { | ||
callback(); | ||
} | ||
else { | ||
callbacks.push(callback); | ||
} | ||
}; | ||
|
||
//>>excludeStart("production", pragmas.production); | ||
var env = module.config().environment || 'development'; | ||
var extend = _.extend; | ||
var onLoad = function() { | ||
console.log('\tLoaded', env, 'config.'); | ||
loaded = true; | ||
|
||
while (callbacks.length) { | ||
callbacks.shift()(); | ||
} | ||
}; | ||
|
||
console.log('Environment:', env); | ||
|
||
config.onLoad = function(callback) { | ||
if (loaded) { | ||
callback(); | ||
// Install test config: | ||
if (env === 'test') { | ||
require([ 'app/config/environments/test' ], function(testConfig) { | ||
extend(config, testConfig); | ||
onLoad(); | ||
}, onLoad); | ||
} | ||
else { | ||
callbacks.push(callback); | ||
} | ||
}; | ||
var loadLocalConfig = function() { | ||
// Install development and local config: | ||
require([ 'app/config/environments/development_local' ], function(localConfig) { | ||
extend(config, localConfig); | ||
onLoad(); | ||
}, function(e) { | ||
if (e.requireType === 'scripterror') { | ||
onLoad(); | ||
|
||
//>>excludeStart("production", pragmas.production); | ||
var env = module.config().environment || 'development'; | ||
var extend = _.extend; | ||
var onLoad = function() { | ||
console.log('\tLoaded', env, 'config.'); | ||
loaded = true; | ||
// don't whine if the files don't exist: | ||
console.info( | ||
'Hint: you can set up your own private, development-only configuration in', | ||
'"config/environments/development_local.js".'); | ||
} else { | ||
throw e; | ||
} | ||
}); | ||
}; | ||
|
||
while (callbacks.length) { | ||
callbacks.shift()(); | ||
} | ||
}; | ||
var global = window; | ||
var DEBUG = {}; | ||
|
||
console.log('Environment:', env); | ||
// You can use this in development_local.js to expose certain modules that | ||
// are hard to reach from the console. Example: | ||
// | ||
// DEBUG.expose('stores/reports', 'reportStore'); | ||
// DEBUG.reportStore; // ReportStore | ||
DEBUG.expose = function(script, varName) { | ||
require([ script ], function(__script__) { | ||
DEBUG[varName] = __script__; | ||
}); | ||
}; | ||
|
||
// Install test config: | ||
if (env === 'test') { | ||
require([ 'app/config/environments/test' ], function(testConfig) { | ||
extend(config, testConfig); | ||
onLoad(); | ||
}, onLoad); | ||
} | ||
else { | ||
var loadLocalConfig = function() { | ||
// Install development and local config: | ||
require([ 'app/config/environments/development_local' ], function(localConfig) { | ||
extend(config, localConfig); | ||
onLoad(); | ||
global.DEBUG = global.d = DEBUG; | ||
|
||
require([ 'app/config/environments/development' ], function(devConfig) { | ||
extend(config, devConfig); | ||
loadLocalConfig(); | ||
}, function(e) { | ||
// don't whine if the files don't exist: | ||
if (e.requireType === 'scripterror') { | ||
onLoad(); | ||
|
||
// don't whine if the files don't exist: | ||
console.info( | ||
'Hint: you can set up your own private, development-only configuration in', | ||
'"config/environments/development_local.js".'); | ||
'Hint: you can set up a development-only configuration in', | ||
'"config/environments/development.js".'); | ||
|
||
loadLocalConfig(); | ||
} else { | ||
throw e; | ||
} | ||
}); | ||
}; | ||
|
||
var global = window; | ||
var DEBUG = {}; | ||
|
||
// You can use this in development_local.js to expose certain modules that | ||
// are hard to reach from the console. Example: | ||
// | ||
// DEBUG.expose('stores/reports', 'reportStore'); | ||
// DEBUG.reportStore; // ReportStore | ||
DEBUG.expose = function(script, varName) { | ||
require([ script ], function(__script__) { | ||
DEBUG[varName] = __script__; | ||
}); | ||
}; | ||
|
||
global.DEBUG = global.d = DEBUG; | ||
|
||
require([ 'app/config/environments/development' ], function(devConfig) { | ||
extend(config, devConfig); | ||
loadLocalConfig(); | ||
}, function(e) { | ||
// don't whine if the files don't exist: | ||
if (e.requireType === 'scripterror') { | ||
console.info( | ||
'Hint: you can set up a development-only configuration in', | ||
'"config/environments/development.js".'); | ||
|
||
loadLocalConfig(); | ||
} else { | ||
throw e; | ||
} | ||
}); | ||
} | ||
//>>excludeEnd("production"); | ||
} | ||
//>>excludeEnd("production"); | ||
|
||
return config; | ||
}); | ||
return config; | ||
}); |
51 changes: 26 additions & 25 deletions
51
client_apps/canvas_quizzes/apps/common/js/core/adapter.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,39 +1,40 @@ | ||
define(function(require) { | ||
var rawAjax = require('../util/xhr_request'); | ||
var config = require('../config'); | ||
var RSVP = require('rsvp'); | ||
|
||
var Adapter = { | ||
request: function(options) { | ||
var ajax = config.ajax || rawAjax; | ||
var Adapter = function(inputConfig) { | ||
this.config = inputConfig; | ||
}; | ||
|
||
options.headers = options.headers || {}; | ||
options.headers['Content-Type'] = 'application/json'; | ||
options.headers.Accept = 'application/vnd.api+json'; | ||
Adapter.prototype.request = function(options) { | ||
var ajax = this.config.ajax || rawAjax; | ||
|
||
if (config.apiToken) { | ||
options.headers.Authorization = 'Bearer ' + config.apiToken; | ||
} | ||
options.headers = options.headers || {}; | ||
options.headers['Content-Type'] = 'application/json'; | ||
options.headers.Accept = 'application/vnd.api+json'; | ||
|
||
if (options.type !== 'GET' && options.data) { | ||
options.data = JSON.stringify(options.data); | ||
} | ||
if (this.config.apiToken) { | ||
options.headers.Authorization = 'Bearer ' + this.config.apiToken; | ||
} | ||
|
||
//>>excludeStart("production", pragmas.production); | ||
if (config.fakeXHRDelay) { | ||
var svc = RSVP.defer(); | ||
if (options.type !== 'GET' && options.data) { | ||
options.data = JSON.stringify(options.data); | ||
} | ||
|
||
setTimeout(function() { | ||
RSVP.Promise.cast(ajax(options)).then(svc.resolve, svc.reject); | ||
}, config.fakeXHRDelay); | ||
//>>excludeStart("production", pragmas.production); | ||
if (this.config.fakeXHRDelay) { | ||
var svc = RSVP.defer(); | ||
|
||
return svc.promise; | ||
} | ||
//>>excludeEnd("production"); | ||
setTimeout(function() { | ||
RSVP.Promise.cast(ajax(options)).then(svc.resolve, svc.reject); | ||
}, this.config.fakeXHRDelay); | ||
|
||
return RSVP.Promise.cast(ajax(options)); | ||
return svc.promise; | ||
} | ||
}; | ||
//>>excludeEnd("production"); | ||
|
||
return RSVP.Promise.cast(ajax(options)); | ||
} | ||
|
||
return Adapter; | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 7 additions & 3 deletions
10
client_apps/canvas_quizzes/apps/events/js/config/initializers/backbone.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,10 @@ | ||
define(function(require) { | ||
var Adapter = require('canvas_quizzes/core/adapter'); | ||
var config = require('../../config'); | ||
var CoreAdapter = require('canvas_quizzes/core/adapter'); | ||
var Adapter = new CoreAdapter(config); | ||
var Backbone = require('canvas_packages/backbone'); | ||
|
||
Backbone.ajax = Adapter.request; | ||
}); | ||
Backbone.ajax = function(options){ | ||
return Adapter.request(options); | ||
}; | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
define(function(require) { | ||
var CoreDispatcher = require('canvas_quizzes/core/dispatcher'); | ||
var config = require("../config"); | ||
|
||
singleton = new CoreDispatcher(config); | ||
return singleton; | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.