summaryrefslogtreecommitdiff
path: root/js
diff options
context:
space:
mode:
Diffstat (limited to 'js')
-rw-r--r--js/codeq/aaiLogin.js2
-rw-r--r--js/codeq/about.js3
-rw-r--r--js/codeq/change_password.js3
-rw-r--r--js/codeq/comms.js21
-rw-r--r--js/codeq/core.js16
-rw-r--r--js/codeq/language.js2
-rw-r--r--js/codeq/login.js2
-rw-r--r--js/codeq/navigation.js42
-rw-r--r--js/codeq/problem_list.js2
-rw-r--r--js/codeq/profile.js10
-rw-r--r--js/codeq/prolog.js1
-rw-r--r--js/codeq/python.js2
-rw-r--r--js/codeq/robot.js22
-rw-r--r--js/codeq/settings.js3
-rw-r--r--js/codeq/signup.js2
-rw-r--r--js/codeq/upgrade_to_aai.js2
16 files changed, 114 insertions, 21 deletions
diff --git a/js/codeq/aaiLogin.js b/js/codeq/aaiLogin.js
index a0a8e68..abe7283 100644
--- a/js/codeq/aaiLogin.js
+++ b/js/codeq/aaiLogin.js
@@ -29,6 +29,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. */
samlLoginUrl = '';
codeq.globalStateMachine.register('aailogin',{
+ 'jqScreen': jqScreen,
+
'enter': function(){
jqDisabledOverlay.css('display', '');
codeq.samlLogin = true;//set the flag
diff --git a/js/codeq/about.js b/js/codeq/about.js
index 25fa829..f56d9fd 100644
--- a/js/codeq/about.js
+++ b/js/codeq/about.js
@@ -23,6 +23,9 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. */
jqBtnGoBack = $("#btnAboutGoBack");
codeq.globalStateMachine.register('about',{
+ 'jqScreen': jqScreen,
+ 'isModal': true,
+
'enter': function(){
jqBtnGoBack.on('click',function(){
history.back();//forces a transition to the previous state
diff --git a/js/codeq/change_password.js b/js/codeq/change_password.js
index dc5db39..6ebd6dd 100644
--- a/js/codeq/change_password.js
+++ b/js/codeq/change_password.js
@@ -26,6 +26,9 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. */
jqChangePassForm = $('#formChangePassword');
codeq.globalStateMachine.register('changePassword',{
+ 'jqScreen': jqScreen,
+ 'isModal': true,
+
'enter': function(){
jqCancelBtn.on('click',function(){
history.back();//forces a transition to the previous state
diff --git a/js/codeq/comms.js b/js/codeq/comms.js
index e964f20..5e046b7 100644
--- a/js/codeq/comms.js
+++ b/js/codeq/comms.js
@@ -557,6 +557,27 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. */
'samlLogout': function(){
return this.send({'action':'saml_logout'});
+ },
+
+ 'forceReset': function () {
+ var p;
+ if (sid !== null) {
+ p = Q.Promise(function (resolve, reject, notify) {
+ var t = setTimeout(function () {
+ t = null;
+ resolve();
+ }, 3000); // 3 seconds
+ codeq.comms.logout().then(function () {
+ if (t !== null) {
+ clearTimeout(t);
+ t = null;
+ resolve();
+ }
+ });
+ });
+ }
+ else p = Q();
+ return p.fin(codeq.comms.disconnect);
}
};
})();
diff --git a/js/codeq/core.js b/js/codeq/core.js
index 22f6a50..b53ce70 100644
--- a/js/codeq/core.js
+++ b/js/codeq/core.js
@@ -15,7 +15,7 @@ You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>. */
(function () {
- window.siteDefinition = {logLevel: 'debug'}; // for debug purposes
+ window.siteDefinition = {logLevel: 'debug'/*, 'logService': '/ws/clientlog'*/}; // for debug purposes
// ================================================================================
// JSON-ization (stringification) function
@@ -123,7 +123,6 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. */
logs = [];
$.ajax({
contentType: 'application/json',
- dataType: 'application/json',
type: 'POST',
url: logServiceUrl,
data: copyOfLogs,
@@ -148,6 +147,12 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. */
return logger;
})();
+ // uncaught error reporting
+ window.onerror = function (msg, url, lineNumber) {
+ if ((msg !== null) && (msg instanceof Object)) msg = msg.toString();
+ codeq.log.error('Uncaught error at line ' + lineNumber + ' in ' + url + ': ' + msg);
+ };
+
// ================================================================================
// The core CodeQ module
// ================================================================================
@@ -610,15 +615,16 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. */
codeq.log.info('App reset: ' + (reason || 'no reason given'));
codeq.globalStateMachine.transition('login');
codeq.wait(
- codeq.comms.getSid() == null ? Q() : codeq.comms.logout()
+/* codeq.comms.getSid() == null ? Q() : codeq.comms.logout()
.finally(
codeq.comms.disconnect
)
.fail(function (e) {
codeq.log.debug(e)
- }) // ignore errors
+ }) // ignore errors*/
+ codeq.comms.forceReset
)
- .then(function () {
+ .fin(function () {
if (reason) {
alert(reason);
}
diff --git a/js/codeq/language.js b/js/codeq/language.js
index 5433c84..cacdb32 100644
--- a/js/codeq/language.js
+++ b/js/codeq/language.js
@@ -28,6 +28,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. */
};
codeq.globalStateMachine.register('language',{
+ 'jqScreen': jqScreen,
+
'enter': function(){
jqScreen.css('display', '');
jqProlog.on('click', function (e) { e.preventDefault(); choose('prolog') });
diff --git a/js/codeq/login.js b/js/codeq/login.js
index 162e336..f7ddeb3 100644
--- a/js/codeq/login.js
+++ b/js/codeq/login.js
@@ -78,6 +78,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. */
formInputs = $('#username, #password');
codeq.globalStateMachine.register('login',{
+ 'jqScreen': jqScreen,
+
'enter': function(){
jqNavigationHomeBtn.off('click');//remove the click listener of this element here
jqNavBarRight.css('display','none');//hide settings etc.
diff --git a/js/codeq/navigation.js b/js/codeq/navigation.js
index 62344e5..d806eea 100644
--- a/js/codeq/navigation.js
+++ b/js/codeq/navigation.js
@@ -49,7 +49,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. */
//the global state machine is a bit different - so it'll be implemented here
var makeGlobalStateMachine = function (def) {
- var currState = null;
+ var currState = null,
+ waitingState = null; // state hidden with a modal form
var stateChangeFun = function historyStateChangeHandler() {
var historyState = History.getState();
codeq.globalStateMachine.actualTransition.apply(codeq.globalStateMachine, $.merge([historyState.data.state] ,historyState.data.params));
@@ -77,11 +78,14 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. */
}
},
'destroy': function () {
+ var i;
if (currState) currState.exit();
currState = null;
+ if (waitingState) waitingState.exit();
+ waitingState = null;
History.Adapter.unbind(window, 'statechange', stateChangeFun);
},
- 'register': function (name, state) {
+ 'register': function (name, state, props) {
if (name in def) codeq.log.error('The state ' + name + ' is already registered, overriding');
def[name] = state;
},
@@ -92,10 +96,36 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. */
}
var newState = def[name];//if the newState is not the same as the old or if it doesn't exist at all is already checked at this point
- if (currState) currState.exit();
-
- currState = newState;
- currState.enter.apply(currState, Array.prototype.slice.apply(arguments, [1]));
+ if (currState) {
+ if (newState.isModal) {
+ if (currState.isModal) currState.exit();
+ else {
+ waitingState = currState;
+ waitingState.jqScreen.css('display', 'none');
+ }
+ currState = newState;
+ currState.enter.apply(currState, Array.prototype.slice.apply(arguments, [1]));
+ }
+ else {
+ currState.exit();
+ currState = newState;
+ if (waitingState === newState) {
+ waitingState.jqScreen.css('display', '');
+ waitingState = null;
+ }
+ else {
+ if (waitingState) {
+ waitingState.exit();
+ waitingState = null;
+ }
+ currState.enter.apply(currState, Array.prototype.slice.apply(arguments, [1]));
+ }
+ }
+ }
+ else {
+ currState = newState;
+ currState.enter.apply(currState, Array.prototype.slice.apply(arguments, [1]));
+ }
}
}
};
diff --git a/js/codeq/problem_list.js b/js/codeq/problem_list.js
index 4e81927..645a58a 100644
--- a/js/codeq/problem_list.js
+++ b/js/codeq/problem_list.js
@@ -414,6 +414,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. */
// ================================================================================
codeq.globalStateMachine.register('problem_list', {
+ 'jqScreen': jqScreen,
+
'enter': function(language){
var data = languageCache[language]; // language data
diff --git a/js/codeq/profile.js b/js/codeq/profile.js
index 09a0e05..f863140 100644
--- a/js/codeq/profile.js
+++ b/js/codeq/profile.js
@@ -20,13 +20,17 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. */
(function(){
- var jqBtnChangePass = $("#change_pass_profile"),
+ var jqScreen = $("#screen_profile"),
+ jqBtnChangePass = $("#change_pass_profile"),
jqBtnGoBack = $("#btnProfileGoBack");
codeq.profile = {
};
codeq.globalStateMachine.register('profile',{
+ 'jqScreen': jqScreen,
+ 'isModal': true,
+
'enter': function(){
jqBtnChangePass.on('click',function(){
codeq.globalStateMachine.transition('changePassword');
@@ -35,7 +39,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. */
history.back();//forces a transition to the previous state
});
if(codeq.samlLogin) $('#loggedInViaSamlSpan').css("display","");//show the span if we actually logged in with SAML
- $("#screen_profile").css('display', '');
+ jqScreen.css('display', '');
$('#disabled').css('display', 'none');
codeq.comms.getUserStat()
.then(function (data) {
@@ -78,7 +82,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. */
'exit' : function(){
jqBtnChangePass.off('click');
jqBtnGoBack.off('click');
- $("#screen_profile").css('display', 'none');
+ jqScreen.css('display', 'none');
$('#loggedInViaSamlSpan').css("display","none");
}
});
diff --git a/js/codeq/prolog.js b/js/codeq/prolog.js
index 0bbf547..b772685 100644
--- a/js/codeq/prolog.js
+++ b/js/codeq/prolog.js
@@ -103,6 +103,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. */
var prologHandler; //created when we enter the prolog state and destroyed once we leave it
codeq.globalStateMachine.register('prolog', {
+ 'jqScreen': jqScreen,
//'enter': function (problemDef, commonDef, currentSolution) {
'enter': function (ref, data) {//function (problemDef, commonDef, currentSolution) {//
diff --git a/js/codeq/python.js b/js/codeq/python.js
index 472d700..0fb7d2b 100644
--- a/js/codeq/python.js
+++ b/js/codeq/python.js
@@ -113,6 +113,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. */
};
codeq.globalStateMachine.register('python', {
+ 'jqScreen': jqScreen,
+
'enter': function (ref, data) {//function (problemDef, commonDef, currentSolution) {//
codeq.loadProblemData(ref,data).then(function(problem){
diff --git a/js/codeq/robot.js b/js/codeq/robot.js
index ffccc62..ee6eda6 100644
--- a/js/codeq/robot.js
+++ b/js/codeq/robot.js
@@ -108,6 +108,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. */
var robotHandler; //created when we enter the robot state and destroyed once we leave it
codeq.globalStateMachine.register('robot', {
+ 'jqScreen': jqScreen,
+
//'enter': function (problemDef, commonDef, currentSolution) {
'enter': function (ref, data) {//function (problemDef, commonDef, currentSolution) {//
@@ -174,13 +176,9 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. */
var makeRobotTerminalHandler = function (jqConsole, editor, problem_id, activityHandler) {
var terminal = codeq.makeConsole(jqConsole, {
- 'greeting': 'CodeQ Robot terminal proxy',
- 'autoHistory': true
+ 'greeting': 'Robot messages\n--------------\n\n',
});
-
- terminal.onInput = function (text) {
- terminal.append('Not implemented.\n', 'output');
- };
+ terminal.inputDisable();
return terminal;
};
@@ -191,7 +189,9 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. */
var createRobotHandler = function (problemDef, commonDef, currentSolution) {
var jqDescriptionContent = jqDescription.find('.description'),
jqEditor = jqCode.find('.code_editor'),
+ jqTerminal = jqConsole.find('.console'),
jqHints = jqInfo.find('.hints'),
+ jqStatus = jqConsole.find('.status'),
editor = codeq.makeEditor(jqEditor[0],
{
mode: 'python',
@@ -202,6 +202,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. */
jqBtnRun.focus();
}),
activityHandler = codeq.makeActivityHandler(editor, problemDef.id),
+ terminal = makeRobotTerminalHandler(jqTerminal, editor, problemDef.id, activityHandler),
hinter = codeq.makeHinter(jqHints, jqEditor, editor, 'robot_hints', problemDef, commonDef),
commError = function (error) {
alert(error);
@@ -213,6 +214,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. */
// set up the websocket events
socket.on('close', function (data) {
console.log('websocket closed, trying to reopen in 1 s');
+ jqStatus.html('Not connected.');
reconnectTimer = setTimeout(function () {
reconnectTimer = null;
socket.open();
@@ -228,7 +230,11 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. */
if (!sensors.hasOwnProperty(sensor)) continue;
text += sensor + ': ' + sensors[sensor] + '<br />\n'
}
- $('div.console').html('<p style="color: lightgreen; font-family: monospace;">'+text+'</p>');
+ jqStatus.html(text);
+ }
+ else if (json_obj.event == 'output') {
+ text = json_obj.text;
+ terminal.append(text, 'output');
}
});
@@ -286,10 +292,12 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. */
var program = editor.getDoc().getValue();
activityHandler.queueTrace({'typ': 'robot_run', 'program': program});
socket.send(JSON.stringify({action: 'run', program: program}));
+ terminal.append('<run>\n', 'output');
});
jqBtnStop.on('click', function () {
activityHandler.queueTrace({'typ': 'robot_stop'});
socket.send(JSON.stringify({action: 'stop'}));
+ terminal.append('<stop>\n', 'output');
});
codeq.comms.loadProblem(problemDef.id).done();
diff --git a/js/codeq/settings.js b/js/codeq/settings.js
index 3e72cbd..6fec614 100644
--- a/js/codeq/settings.js
+++ b/js/codeq/settings.js
@@ -34,6 +34,9 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. */
});
codeq.globalStateMachine.register('settings',{
+ 'jqScreen': jqScreenSettings,
+ 'isModal': true,
+
'enter':function(){
jqDisabledOverlay.css('display', '');
robotAddressInput.val(codeq.settings['robot_address']);//set the robot address once we enter the state
diff --git a/js/codeq/signup.js b/js/codeq/signup.js
index 2667fe4..5f3f2be 100644
--- a/js/codeq/signup.js
+++ b/js/codeq/signup.js
@@ -32,6 +32,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. */
jqNavigationHomeBtn = $('#navigation-home');
codeq.globalStateMachine.register('signup',{
+ 'jqScreen': jqScreen,
+
'enter': function(){
jqNavigationHomeBtn.off('click');//remove the click listener of this element here
jqNavBarRight.css('display','none');//hide settings etc.
diff --git a/js/codeq/upgrade_to_aai.js b/js/codeq/upgrade_to_aai.js
index 6ea5855..5357a29 100644
--- a/js/codeq/upgrade_to_aai.js
+++ b/js/codeq/upgrade_to_aai.js
@@ -26,6 +26,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. */
jqLangSelect = jqScreen.find('.lang-select');
codeq.globalStateMachine.register('upgradeToAAI',{
+ 'jqScreen': jqScreen,
+
'enter': function(){
jqNoBtn.on('click',function(){
codeq.comms.samlLogin(false)