summaryrefslogtreecommitdiff
path: root/js/codeq
diff options
context:
space:
mode:
Diffstat (limited to 'js/codeq')
-rw-r--r--js/codeq/comms.js9
-rw-r--r--js/codeq/core.js2
-rw-r--r--js/codeq/login.js257
3 files changed, 94 insertions, 174 deletions
diff --git a/js/codeq/comms.js b/js/codeq/comms.js
index fb5d348..d2c2910 100644
--- a/js/codeq/comms.js
+++ b/js/codeq/comms.js
@@ -59,6 +59,15 @@
sendQuery: function commsSendQuery (json) {
json['sid'] = codeq.sid;
return send('query', codeq.jsonize(json));
+ },
+
+ getProblem: function commsGetProblem (language, problem_group, problem) {
+ return send('get_problem', codeq.jsonize({
+ 'sid': codeq.sid,
+ 'language': language,
+ 'problem_group': problem_group,
+ 'problem': problem
+ }));
}
};
})();
diff --git a/js/codeq/core.js b/js/codeq/core.js
index f13a019..dd417d4 100644
--- a/js/codeq/core.js
+++ b/js/codeq/core.js
@@ -13,7 +13,7 @@ window.codeq = {
/**
* REST API URL prefix.
*/
- urlPrefix: '/codeq/',
+ urlPrefix: '/svc/',
/**
* Returns the number of Unicode code points in the given string.
diff --git a/js/codeq/login.js b/js/codeq/login.js
index d449835..af50b22 100644
--- a/js/codeq/login.js
+++ b/js/codeq/login.js
@@ -1,183 +1,94 @@
(function(){
- var groups = {
- 'family_relations': {
- 'name': 'Family relations',
- 'problems': [
- {'id': 'ancestor_2', 'name': 'ancestor/2'},
- {'id': 'aunt_2', 'name': 'aunt/2'},
- {'id': 'brother_2', 'name': 'brother/2'},
- {'id': 'connected_3', 'name': 'connected/3'},
- {'id': 'cousin_2', 'name': 'cousin/2'}
- ]
- },
- 'lists': {
- 'name': 'Lists',
- 'problems': [
- {'id': '', 'name': ''},
- {'id': '', 'name': ''},
- {'id': '', 'name': ''},
- {'id': '', 'name': ''},
- {'id': '', 'name': ''}
- ]
- },
- 'sorting': {
- 'name': 'Sorting',
- 'problems': [
- {'id': '', 'name': ''},
- {'id': '', 'name': ''},
- {'id': '', 'name': ''},
- {'id': '', 'name': ''},
- {'id': '', 'name': ''}
- ]
- },
- 'other': {
- 'name': 'Other',
- 'problems': [
- {'id': '', 'name': ''},
- {'id': '', 'name': ''},
- {'id': '', 'name': ''},
- {'id': '', 'name': ''},
- {'id': '', 'name': ''}
- ]
- },
- 'sets': {
- 'name': 'Sets',
- 'problems': [
- {'id': '', 'name': ''},
- {'id': '', 'name': ''},
- {'id': '', 'name': ''},
- {'id': '', 'name': ''},
- {'id': '', 'name': ''}
- ]
- },
- 'trees': {
- 'name': 'Trees',
- 'problems': [
- {'id': '', 'name': ''},
- {'id': '', 'name': ''},
- {'id': '', 'name': ''},
- {'id': '', 'name': ''},
- {'id': '', 'name': ''}
- ]
- },
- 'license_plates': {
- 'name': 'License plates',
- },
- 'clp_fd': {
- 'name': 'CLP(FD',
- 'problems': [
- {'id': 'gcd_3', 'name': 'gcd/3'},
- {'id': 'magic_1', 'name': 'magic/1'},
- {'id': 'puzzle_abc_3', 'name': 'puzzle_abc/3'},
- {'id': 'puzzle_beth_1', 'name': 'puzzle_beth/1'},
- {'id': 'puzzle_momson_2', 'name': 'puzzle_momson/2'},
- {'id': 'puzzle_ratio_2', 'name': 'puzzle_ratio/2'},
- {'id': 'tobase_3', 'name': 'tobase/3'}
- ]
- },
- 'clp_r': {
- 'name': 'CLP(R)',
- 'problems': [
- {'id': 'bounding_box_3', 'name': 'bounding_box/3'},
- {'id': 'center_3', 'name': 'center/3'},
- {'id': 'linear_opts_3', 'name': 'linear_opts/3'},
- {'id': 'max_sum_2', 'name': 'max_sum/2'},
- {'id': 'megabytes_2', 'name': 'megabytes/2'},
- {'id': 'turkey_3', 'name': 'turkey/3'}
- ]
- },
- 'dcg': {
- 'name': 'DCG',
- 'problems': [
- {'id': 'ab_2', 'name': 'ab/2'},
- {'id': 'digit_2', 'name': 'digit/2'},
- {'id': 'expr_2', 'name': 'expr/2'},
- {'id': 'expr_3', 'name': 'expr/3'},
- {'id': 'flower_2', 'name': 'flower/2'}
- ]
- },
- 'denotational_semantics': {
- 'name': 'Denotational semantics',
- 'problems': [
- {'id': 'algol_3', 'name': 'algol/3'},
- {'id': 'algol_for_3', 'name': 'algol_for/3'},
- {'id': 'algol_if_3', 'name': 'algol_if/3'},
- {'id': 'prog_8puzzle_2', 'name': 'prog_8puzzle/2'},
- {'id': 'prog_8puzzle_3', 'name': 'prog_8puzzle/3'}
- ]
- },
- 'old_exams': {
- 'name': 'Old exams',
- 'problems': [
- {'id': '', 'name': ''},
- {'id': '', 'name': ''},
- {'id': '', 'name': ''},
- {'id': '', 'name': ''},
- {'id': '', 'name': ''}
- ]
- }
- };
-
- $("#submit").on('click', function () {
- var group = $('#problem_group').val(),
- problem = $('#problems').val();
- if (!group) alert('Choose a problem group');
- else if (!problem) alert('Choose a problem');
- else {
- $.ajax({
- 'type': 'POST',
- 'url': '/codeq/login',
- 'accepts': 'application/json',
- 'contentType': 'application/json; charset=UTF-8',
- 'data': JSON.stringify({
- 'username': $('#username').val(),
- 'password': $('#password').val()
- }),
- 'processData': false,
- 'dataType': 'json',
- 'error': function loginErrorHandler(jqXHR, textStatus, errorThrown) {
- alert('Request for login failed: ' + (errorThrown || textStatus));
- },
- 'success': function loginSuccessHandler(data, textStatus, jqXHR) {
- if (data && (data.code === 0)) {
- window.location = 'prolog.html#sid=' + data.sid + '/grp=' + group + '/prb=' + problem;
- }
- else {
- alert('Login failed: code=' + data.code + ', reason=' + data.message);
- }
- }
- });
- }
- });
+ var urlPrefix = '/svc/';
$(document).ready(function () {
- var jqGroup = $('#problem_group'),
- jqProblems = $('#problems'),
- id, g, first_group, html = [];
- for (id in groups) {
- g = groups[id];
- html.push('<option value="', id, '">', g.name, '</option>\n');
- }
- jqGroup.html(html.join(''));
- first_group = html[1];
- html = null;
+ $.ajax({
+ 'type': 'POST',
+ 'url': urlPrefix + 'list_problems',
+ 'accepts': 'application/json',
+ 'contentType': 'application/json; charset=UTF-8',
+ 'data': JSON.stringify({
+ 'language': 'prolog'
+ }),
+ 'processData': false,
+ 'dataType': 'json',
+ 'error': function loginErrorHandler(jqXHR, textStatus, errorThrown) {
+ $('#disabled').css('cursor', '');
+ alert('Request to obtain list of problems failed: ' + (errorThrown || textStatus));
+ },
+ 'success': function loginSuccessHandler(data, textStatus, jqXHR) {
+ var i, groups, group, problems, problem, first_group,
+ jqGroup = $('#problem_group'),
+ jqProblems = $('#problems'),
+ html = [],
+ mapping = {}
+ onGroupChange = function () {
+ var problems = mapping[jqGroup.val()],
+ html = [],
+ i, p;
+ if (problems) {
+ for (i = 0; i < problems.length; i++) {
+ p = problems[i];
+ html.push('<option value="', p.identifier, '">', p.name, '</option>\n')
+ }
+ }
+ jqProblems.html(html.join(''));
+ };
- jqGroup.on('click', function () {
- var g = groups[jqGroup.val()],
- html = [],
- problems, i, p;
- if (g) {
- problems = g.problems;
- for (i = 0; i < problems.length; i++) {
- p = problems[i];
- if (!p.id) continue;
- html.push('<option value="', p.id, '">', p.name, '</option>\n')
+ if (data && (data.code === 0)) {
+ $('#disabled').css('display', 'none');
+ groups = data.problems;
+ for (i = 0; i < groups.length; i++) {
+ group = groups[i];
+ html.push('<option value="', group.identifier, '">', group.name, '</option>\n');
+ mapping[group.identifier] = group.problems;
+ }
+ jqGroup.html(html.join(''));
+ first_group = html[1];
+ html = null;
+
+ jqGroup.on('click', onGroupChange);
+ jqGroup.val(first_group);
+ onGroupChange();
+
+ $("#submit").on('click', function () {
+ var group = $('#problem_group').val(),
+ problem = $('#problems').val();
+ if (!group) alert('Choose a problem group');
+ else if (!problem) alert('Choose a problem');
+ else {
+ $.ajax({
+ 'type': 'POST',
+ 'url': urlPrefix + 'login',
+ 'accepts': 'application/json',
+ 'contentType': 'application/json; charset=UTF-8',
+ 'data': JSON.stringify({
+ 'username': $('#username').val(),
+ 'password': $('#password').val()
+ }),
+ 'processData': false,
+ 'dataType': 'json',
+ 'error': function loginErrorHandler(jqXHR, textStatus, errorThrown) {
+ alert('Request for login failed: ' + (errorThrown || textStatus));
+ },
+ 'success': function loginSuccessHandler(data, textStatus, jqXHR) {
+ if (data && (data.code === 0)) {
+ window.location = 'prolog.html#sid=' + data.sid + '/grp=' + group + '/prb=' + problem;
+ }
+ else {
+ alert('Login failed: code=' + data.code + ', reason=' + data.message);
+ }
+ }
+ });
+ }
+ });
+ }
+ else {
+ $('#disabled').css('cursor', '');
+ alert('Obtaining list of problems failed: code=' + data.code + ', reason=' + data.message);
}
}
- jqProblems.html(html.join(''));
});
-
- jqGroup.val(first_group);
});
})(); \ No newline at end of file