Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
bwinf
medal
Commits
1d4c99d7
Commit
1d4c99d7
authored
May 28, 2019
by
Robert Czechowski
Browse files
Add minimal wrapper for Algorea platform tasks
parent
a13db7e8
Pipeline
#106
passed with stage
in 4 minutes and 3 seconds
Changes
5
Pipelines
1
Expand all
Hide whitespace changes
Inline
Side-by-side
src/db_apply_migrations.rs
View file @
1d4c99d7
...
...
@@ -4,6 +4,7 @@ use std::io::Read;
use
db_conn
::
MedalConnection
;
pub
fn
test
<
C
:
MedalConnection
>
(
conn
:
&
mut
C
)
{
println!
(
"reading dirs"
);
let
mut
paths
:
Vec
<
_
>
=
fs
::
read_dir
(
format!
(
"migrations/{}"
,
conn
.dbtype
()))
.unwrap
()
.map
(|
r
|
r
.unwrap
())
...
...
@@ -26,4 +27,5 @@ pub fn test<C: MedalConnection>(conn: &mut C) {
println!("Found: {}. Already applied", path.path().display());
}*/
}
println!
(
"finished"
);
}
src/main.rs
View file @
1d4c99d7
...
...
@@ -216,9 +216,13 @@ fn main() {
Connection
::
create
(
&
Path
::
new
(
"medal.db"
))
}
};
println!
(
"connected!"
);
println!
(
"applying migrations …"
);
db_apply_migrations
::
test
(
&
mut
conn
);
println!
(
"scanning for contests …"
);
refresh_all_contests
(
&
mut
conn
);
add_admin_user
(
&
mut
conn
,
opt
.resetadminpw
);
...
...
static/lib/fioipem/jschannel-190528.js
0 → 100644
View file @
1d4c99d7
This diff is collapsed.
Click to expand it.
static/lib/fioipem/task-pr-190528.js
0 → 100644
View file @
1d4c99d7
(
function
()
{
'
use strict
'
;
/*
* Same domain task proxy implementation for Bebras task API - v1.0 - 08/2014
*
* Depends on jQuery.
*
*/
var
functionsToTrigger
=
{
load
:
true
,
unload
:
true
,
reloadAnswer
:
true
,
showViews
:
true
,
reloadState
:
true
};
function
taskCaller
(
task
,
request
,
content
,
error
)
{
if
(
!
error
)
{
error
=
function
()
{};
}
// TODO: handle case where iframe_loaded is false and caller expects a result...
if
(
!
task
.
iframe_loaded
)
{
setTimeout
(
function
()
{
taskCaller
(
task
,
request
,
content
);
},
100
);
}
else
{
if
(
task
.
distantTask
&&
typeof
task
.
distantTask
[
request
]
===
'
function
'
)
{
if
(
typeof
content
===
'
string
'
||
(
typeof
content
===
'
object
'
&&
Object
.
prototype
.
toString
.
call
(
content
)
!==
'
[object Array]
'
))
{
content
=
[
content
];
}
var
askedCallbackIdx
=
(
typeof
content
[
content
.
length
-
2
]
===
'
function
'
)
?
content
.
length
-
2
:
content
.
length
-
1
;
if
(
typeof
content
[
askedCallbackIdx
]
!==
'
function
'
)
{
error
(
'
calls to task must contain a callback
'
);
return
;
}
var
oldCallback
=
content
[
askedCallbackIdx
];
var
timeout
=
window
.
setTimeout
(
function
()
{
error
(
'
timeout reached for
'
+
request
);
},
20000
);
var
newCallback
=
function
()
{
window
.
clearTimeout
(
timeout
);
if
(
functionsToTrigger
[
request
])
{
task
.
distantPlatform
.
trigger
(
request
,
content
);
}
oldCallback
(
arguments
[
0
],
arguments
[
1
],
arguments
[
3
]);
};
content
[
askedCallbackIdx
]
=
newCallback
;
if
(
typeof
window
.
taskPrNoCatch
!==
'
undefined
'
)
{
task
.
distantTask
[
request
].
apply
(
task
.
distantTask
,
content
);
}
else
{
try
{
task
.
distantTask
[
request
].
apply
(
task
.
distantTask
,
content
);
}
catch
(
e
)
{
window
.
clearTimeout
(
timeout
);
error
(
e
.
name
+
'
:
'
+
e
.
message
);
}
}
}
else
if
(
task
.
distantTask
)
{
error
(
"
Task
"
+
task
.
Id
+
"
doesn't implement
"
+
request
);
}
else
{
error
(
'
call to
'
+
request
+
'
on task with no distant task
'
);
}
}
}
/*
* Task object, created from an iframe DOM element
*/
function
Task
(
iframe
,
callback
)
{
this
.
iframe
=
iframe
;
this
.
iframe_loaded
=
false
;
this
.
distantTask
=
null
;
this
.
Id
=
iframe
.
attr
(
'
id
'
);
this
.
elementsLoaded
=
false
;
this
.
platform
=
null
;
var
that
=
this
;
this
.
setPlatform
=
function
(
platform
)
{
this
.
platform
=
platform
;
if
(
this
.
iframe_loaded
)
{
this
.
distantPlatform
.
setPlatform
(
platform
);
}
};
this
.
iframeLoaded
=
function
()
{
if
(
that
.
iframe_loaded
)
{
return
;
}
that
.
iframe_loaded
=
true
;
that
.
distantTask
=
that
.
iframe
[
0
].
contentWindow
.
task
;
that
.
distantPlatform
=
that
.
iframe
[
0
].
contentWindow
.
platform
;
that
.
iframe
[
0
].
contentWindow
.
platform
.
parentLoadedFlag
=
true
;
if
(
that
.
platform
)
{
that
.
distantPlatform
.
setPlatform
(
that
.
platform
);
}
callback
();
};
// checking if platform is already available
var
iframeDoc
=
that
.
iframe
[
0
].
contentDocument
||
that
.
iframe
[
0
].
contentWindow
.
document
;
if
(
iframeDoc
&&
iframeDoc
.
readyState
==
'
complete
'
&&
that
.
iframe
[
0
].
contentWindow
.
platform
&&
!
that
.
iframe
[
0
].
contentWindow
.
platform
.
parentLoadedFlag
)
{
that
.
iframe
[
0
].
contentWindow
.
platform
.
initCallback
(
that
.
iframeLoaded
);
}
else
{
if
(
document
.
addEventListener
)
{
// ie > 8
$
(
that
.
iframe
).
on
(
"
load
"
,
function
()
{
that
.
iframe
[
0
].
contentWindow
.
platform
.
initCallback
(
that
.
iframeLoaded
);
});
}
else
{
setTimeout
(
function
()
{
that
.
iframeLoaded
();
},
100
);
}
}
}
Task
.
prototype
.
getSourceId
=
function
()
{
return
this
.
Id
;
};
Task
.
prototype
.
getTargetUrl
=
function
()
{
return
this
.
iframe
.
attr
(
'
src
'
);
};
Task
.
prototype
.
getTarget
=
function
()
{
return
this
.
iframe
[
0
].
contentWindow
;
};
Task
.
prototype
.
getDomain
=
function
()
{
var
url
=
this
.
getTargetUrl
();
return
url
.
substr
(
0
,
url
.
indexOf
(
'
/
'
,
7
));
};
/**
* Task API functions
*/
Task
.
prototype
.
load
=
function
(
views
,
success
,
error
)
{
return
taskCaller
(
this
,
'
load
'
,
[
views
,
success
,
error
],
error
);
};
Task
.
prototype
.
unload
=
function
(
success
,
error
)
{
return
taskCaller
(
this
,
'
unload
'
,
[
success
,
error
],
error
);
};
Task
.
prototype
.
getHeight
=
function
(
success
,
error
)
{
return
taskCaller
(
this
,
'
getHeight
'
,
[
success
,
error
],
error
);
};
Task
.
prototype
.
updateToken
=
function
(
token
,
success
,
error
)
{
return
taskCaller
(
this
,
'
updateToken
'
,
[
token
,
success
,
error
],
error
);
};
Task
.
prototype
.
getAnswer
=
function
(
success
,
error
)
{
return
taskCaller
(
this
,
'
getAnswer
'
,
[
success
,
error
],
error
);
};
Task
.
prototype
.
reloadAnswer
=
function
(
answer
,
success
,
error
)
{
return
taskCaller
(
this
,
'
reloadAnswer
'
,
[
answer
,
success
,
error
],
error
);
};
Task
.
prototype
.
getState
=
function
(
success
,
error
)
{
return
taskCaller
(
this
,
'
getState
'
,
[
success
,
error
],
error
);
};
Task
.
prototype
.
reloadState
=
function
(
state
,
success
,
error
)
{
return
taskCaller
(
this
,
'
reloadState
'
,
[
state
,
success
,
error
],
error
);
};
Task
.
prototype
.
getViews
=
function
(
success
,
error
)
{
return
taskCaller
(
this
,
'
getViews
'
,
[
success
,
error
],
error
);
};
Task
.
prototype
.
getMetaData
=
function
(
success
,
error
)
{
return
taskCaller
(
this
,
'
getMetaData
'
,
[
success
,
error
],
error
);
};
Task
.
prototype
.
showViews
=
function
(
views
,
success
,
error
)
{
return
taskCaller
(
this
,
'
showViews
'
,
[
views
,
success
,
error
],
error
);
};
// TODO: put error back in argument list, for this 2015 tasks must be changed
Task
.
prototype
.
gradeAnswer
=
function
(
answer
,
answerToken
,
success
,
error
)
{
return
taskCaller
(
this
,
'
gradeAnswer
'
,
[
answer
,
answerToken
,
success
],
error
);
};
Task
.
prototype
.
getResources
=
function
(
success
,
error
)
{
return
taskCaller
(
this
,
'
getResources
'
,
[
success
,
error
],
error
);
};
// for grader.gradeTask
// TODO: put error back in argument list, for this 2015 tasks must be changed
Task
.
prototype
.
gradeTask
=
function
(
answer
,
answerToken
,
success
,
error
)
{
return
taskCaller
(
this
,
'
gradeTask
'
,
[
answer
,
answerToken
,
success
],
error
);
};
window
.
TaskProxyManager
=
{
tasks
:
{},
platforms
:
{},
getTaskProxy
:
function
(
idFrame
,
callback
,
force
)
{
if
(
!
force
&&
TaskProxyManager
.
tasks
[
idFrame
])
{
callback
(
TaskProxyManager
.
tasks
[
idFrame
]);
}
else
{
if
(
force
)
{
TaskProxyManager
.
deleteTaskProxy
(
idFrame
);
}
$
(
'
#
'
+
idFrame
).
each
(
function
()
{
TaskProxyManager
.
tasks
[
idFrame
]
=
new
Task
(
$
(
this
),
function
()
{
setTimeout
(
function
()
{
if
(
idFrame
in
TaskProxyManager
.
platforms
)
{
TaskProxyManager
.
tasks
[
idFrame
].
setPlatform
(
TaskProxyManager
.
platforms
[
idFrame
]);
}
callback
(
TaskProxyManager
.
tasks
[
idFrame
]);
});});
});
}
},
setPlatform
:
function
(
task
,
platform
)
{
TaskProxyManager
.
platforms
[
task
.
Id
]
=
platform
;
TaskProxyManager
.
tasks
[
task
.
Id
].
setPlatform
(
platform
);
},
deleteTaskProxy
:
function
(
idFrame
)
{
delete
(
TaskProxyManager
.
tasks
[
idFrame
]);
delete
(
TaskProxyManager
.
platforms
[
idFrame
]);
},
getUrl
:
function
(
taskUrl
,
sToken
,
sPlatform
,
prefix
)
{
return
taskUrl
+
'
?sToken=
'
+
encodeURIComponent
(
sToken
)
+
'
&sPlatform=
'
+
encodeURIComponent
(
sPlatform
);
}
};
window
.
TaskProxyManager
.
getGraderProxy
=
TaskProxyManager
.
getTaskProxy
;
}());
/*
* Platform object definition, created from a Task object (see below)
*/
function
Platform
(
task
)
{
this
.
task
=
task
;
}
Platform
.
prototype
.
getTask
=
function
()
{
return
this
.
task
;
};
/*
* Simple prototypes for platform API functions, to be overriden by your
* platform's specific functions (for each platform object)
*/
Platform
.
prototype
.
validate
=
function
(
mode
)
{};
Platform
.
prototype
.
showView
=
function
(
views
)
{};
Platform
.
prototype
.
askHint
=
function
(
platformToken
)
{};
Platform
.
prototype
.
updateHeight
=
function
(
height
)
{
this
.
task
.
iframe
.
height
(
parseInt
(
height
)
+
40
);};
Platform
.
prototype
.
getTaskParams
=
function
(
key
,
defaultValue
,
success
,
error
)
{
var
res
=
{
minScore
:
-
3
,
maxScore
:
10
,
randomSeed
:
0
,
noScore
:
0
,
readOnly
:
false
,
options
:
{}};
if
(
key
)
{
if
(
key
!==
'
options
'
&&
key
in
res
)
{
res
=
res
[
key
];
}
else
if
(
res
.
options
&&
key
in
res
.
options
)
{
res
=
res
.
options
[
key
];
}
else
{
res
=
(
typeof
defaultValue
!==
'
undefined
'
)
?
defaultValue
:
null
;
}
}
success
(
res
);
};
Platform
.
prototype
.
openUrl
=
function
(
url
)
{
// TODO
};
tasks/jwinf2/wrapper.html
0 → 100644
View file @
1d4c99d7
<!DOCTYPE html>
<html
lang=
"en"
>
<head>
<meta
charset=
"utf-8"
>
<title>
title
</title>
<script
src=
"/static/lib/jquery/jquery-3.2.1.min.js"
></script>
<script
src=
"/static/lib/fioipem/jschannel-190528.js"
></script>
<script
src=
"/static/lib/fioipem/task-pr-190528.js"
></script>
<script
src=
"/static/lib/medal/medal-0.0.2.js"
></script>
</head>
<body
style=
"margin:0px; padding:0px; overflow: hidden;"
>
<!--iframe src="task.html?channelId=ifr" id="ifr"></iframe-->
<script>
$
(
"
body
"
).
prepend
(
'
<iframe src="
'
+
location
.
search
.
substr
(
1
)
+
'
?channelId=task" id="ifr" style="border: 0px; width:100vw; height:100vh;margin:0px; padding:0px; "></iframe>
'
);
var
options
=
{
minScore
:
0
,
maxScore
:
4
,
noScore
:
0
,
randomSeed
:
0
,
readOnly
:
false
,
options
:{
difficulty
:
"
easy
"
},
}
setTimeout
(
function
()
{
TaskProxyManager
.
getTaskProxy
(
"
ifr
"
,
function
(
task
){
var
platform
=
{
getTaskParams
:
function
(
key
,
def
,
cb
,
ecb
)
{
console
.
log
(
"
In platform.getTaskParams:
"
);
console
.
log
(
key
);
console
.
log
(
def
);
cb
(
options
);
},
updateDisplay
:
function
(
opt
,
cb
,
ecb
)
{
console
.
log
(
"
In platform.updateDisplay:
"
);
console
.
log
(
opt
);
cb
();
},
validate
:
function
(
mode
,
cb
,
ecb
)
{
console
.
log
(
"
In platform.validate:
"
);
console
.
log
(
mode
);
task
.
getAnswer
(
function
(
answer
){
console
.
log
(
answer
);
task
.
gradeAnswer
(
answer
,
{},
function
(
score
,
message
,
scoreToken
){
console
.
log
(
"
answer graded:
"
);
console
.
log
(
score
);
console
.
log
(
message
);
window
.
save_task_object
(
{
"
text
"
:
answer
},
score
,
function
(){
document
.
println
(
"
OK transmission
"
);
});
},
function
(){
console
.
log
(
"
gradeAnswer error
"
);})
},
function
(){
console
.
log
(
"
getAnswer error
"
);})
if
(
cb
)
{
cb
();}
}
};
TaskProxyManager
.
setPlatform
(
task
,
platform
);
console
.
log
(
"
yay
"
);
task
.
getViews
(
function
(
views
){
console
.
log
(
views
);
task
.
load
({
editor
:
true
,
forum
:
true
,
hints
:
true
,
submission
:
true
,
task
:
true
,
grade
:
true
,
metadata
:
true
},
function
(){
console
.
log
(
"
loaded
"
);
window
.
load_task_object
(
function
(
data
){
if
(
"
text
"
in
data
)
{
task
.
reloadAnswer
(
data
[
"
text
"
],
function
(){
console
.
log
(
"
reloadAnswer success
"
);},
function
(){
console
.
log
(
"
reloadAnswer fail
"
);});
}
});
},
function
(
e
){
console
.
log
(
"
load failed
"
);
console
.
log
(
e
);})
},
function
(
e
){
console
.
log
(
"
error
"
);});
},
false
,
function
(){
console
.
log
(
"
nay
"
);});
console
.
log
(
"
hm
"
);
},
1
);
</script>
</body>
</html>
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment