Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
KNIGHT
Asyst Moodle Plugin
Commits
9fdc9f0b
Commit
9fdc9f0b
authored
Dec 01, 2024
by
Artem Baranovskyi
Browse files
Code style fixes.
parent
4e4b130c
Changes
2
Hide whitespace changes
Inline
Side-by-side
js/grade.js
View file @
9fdc9f0b
...
@@ -2,12 +2,6 @@ M.local_asystgrade = {
...
@@ -2,12 +2,6 @@ M.local_asystgrade = {
init
:
function
(
Y
,
jsData
)
{
init
:
function
(
Y
,
jsData
)
{
const
isDebuggingEnabled
=
true
;
// Set this to false in production
const
isDebuggingEnabled
=
true
;
// Set this to false in production
function
log
(
message
)
{
if
(
isDebuggingEnabled
)
{
console
.
log
(
message
);
}
}
window
.
gradeData
=
jsData
;
window
.
gradeData
=
jsData
;
document
.
addEventListener
(
'
DOMContentLoaded
'
,
function
()
{
document
.
addEventListener
(
'
DOMContentLoaded
'
,
function
()
{
const
apiEndpoint
=
M
.
cfg
.
wwwroot
+
'
/local/asystgrade/api.php
'
;
const
apiEndpoint
=
M
.
cfg
.
wwwroot
+
'
/local/asystgrade/api.php
'
;
...
@@ -30,16 +24,16 @@ M.local_asystgrade = {
...
@@ -30,16 +24,16 @@ M.local_asystgrade = {
.
then
(
response
=>
response
.
json
())
.
then
(
response
=>
response
.
json
())
.
then
(
data
=>
{
.
then
(
data
=>
{
if
(
data
.
success
&&
data
.
grades
)
{
if
(
data
.
success
&&
data
.
grades
)
{
log
(
data
.
grades
);
console
.
log
(
data
.
grades
);
updateMarks
(
data
.
grades
);
updateMarks
(
data
.
grades
);
}
else
{
}
else
{
error
(
'
Error in grade response:
'
,
data
.
error
);
console
.
log
(
'
Error in grade response:
'
,
data
.
error
);
}
}
// Return the data to keep the Promise chain intact
// Return the data to keep the Promise chain intact
return
data
;
return
data
;
})
})
.
catch
(
error
=>
{
.
catch
(
error
=>
{
error
(
'
Error:
'
,
error
);
console
.
log
(
'
Error:
'
,
error
);
// Return the error to keep the Promise chain intact
// Return the error to keep the Promise chain intact
throw
error
;
throw
error
;
});
});
...
@@ -53,7 +47,7 @@ M.local_asystgrade = {
...
@@ -53,7 +47,7 @@ M.local_asystgrade = {
if
(
inputs
[
index
])
{
if
(
inputs
[
index
])
{
inputs
[
index
].
value
=
predictedGrade
;
inputs
[
index
].
value
=
predictedGrade
;
}
else
{
}
else
{
error
(
`No grade input found for index:
${
index
}
`
);
console
.
log
(
`No grade input found for index:
${
index
}
`
);
}
}
});
});
}
}
...
...
tests/quiz_api_test.php
View file @
9fdc9f0b
...
@@ -34,7 +34,6 @@ use dml_exception;
...
@@ -34,7 +34,6 @@ use dml_exception;
use
Exception
;
use
Exception
;
use
local_asystgrade
\
api\client
;
use
local_asystgrade
\
api\client
;
use
local_asystgrade\api\http_client
;
use
local_asystgrade\api\http_client
;
use
local_asystgrade
\
utils
;
defined
(
'MOODLE_INTERNAL'
)
||
die
();
defined
(
'MOODLE_INTERNAL'
)
||
die
();
...
@@ -46,6 +45,7 @@ require_once($CFG->dirroot . '/mod/quiz/tests/generator/lib.php');
...
@@ -46,6 +45,7 @@ require_once($CFG->dirroot . '/mod/quiz/tests/generator/lib.php');
/**
/**
* Class quiz_api_test
* Class quiz_api_test
* @package local_asystgrade
* @package local_asystgrade
* @covers \local_asystgrade
*/
*/
final
class
quiz_api_test
extends
advanced_testcase
{
final
class
quiz_api_test
extends
advanced_testcase
{
...
@@ -68,6 +68,7 @@ final class quiz_api_test extends advanced_testcase {
...
@@ -68,6 +68,7 @@ final class quiz_api_test extends advanced_testcase {
/**
/**
* Tests the quiz API by creating quiz attempts and validating responses.
* Tests the quiz API by creating quiz attempts and validating responses.
* @throws Exception
* @throws Exception
* @covers \local_asystgrade
*/
*/
public
function
test_quiz_api
():
void
{
public
function
test_quiz_api
():
void
{
global
$DB
;
global
$DB
;
...
@@ -152,7 +153,7 @@ final class quiz_api_test extends advanced_testcase {
...
@@ -152,7 +153,7 @@ final class quiz_api_test extends advanced_testcase {
* @throws coding_exception
* @throws coding_exception
* @throws dml_exception
* @throws dml_exception
*/
*/
private
function
create_question_category
(
int
$contextid
)
{
private
function
create_question_category
(
int
$contextid
)
:
mixed
{
global
$DB
;
global
$DB
;
$category
=
[
$category
=
[
...
@@ -181,7 +182,7 @@ final class quiz_api_test extends advanced_testcase {
...
@@ -181,7 +182,7 @@ final class quiz_api_test extends advanced_testcase {
* @param $context
* @param $context
* @return mixed
* @return mixed
*/
*/
private
function
create_question
(
$questiongen
,
$questiondata
,
$category
,
$modifiedby
,
$context
)
{
private
function
create_question
(
$questiongen
,
$questiondata
,
$category
,
$modifiedby
,
$context
)
:
mixed
{
return
$questiongen
->
create_question
(
$questiondata
[
'qtype'
],
null
,
[
return
$questiongen
->
create_question
(
$questiondata
[
'qtype'
],
null
,
[
'category'
=>
$category
->
id
,
'category'
=>
$category
->
id
,
'questiontext'
=>
[
'text'
=>
$questiondata
[
'questiontext'
],
'format'
=>
FORMAT_HTML
],
'questiontext'
=>
[
'text'
=>
$questiondata
[
'questiontext'
],
'format'
=>
FORMAT_HTML
],
...
@@ -200,7 +201,7 @@ final class quiz_api_test extends advanced_testcase {
...
@@ -200,7 +201,7 @@ final class quiz_api_test extends advanced_testcase {
* @return void
* @return void
* @throws dml_exception
* @throws dml_exception
*/
*/
private
function
add_question_to_quiz
(
$quiz
,
$question
)
{
private
function
add_question_to_quiz
(
$quiz
,
$question
)
:
void
{
global
$DB
;
global
$DB
;
$slotdata
=
[
$slotdata
=
[
...
@@ -228,7 +229,7 @@ final class quiz_api_test extends advanced_testcase {
...
@@ -228,7 +229,7 @@ final class quiz_api_test extends advanced_testcase {
* @return void
* @return void
* @throws dml_exception
* @throws dml_exception
*/
*/
private
function
create_quiz_attempt
(
$quizid
,
$userid
,
$answer
)
{
private
function
create_quiz_attempt
(
$quizid
,
$userid
,
$answer
)
:
void
{
global
$DB
;
global
$DB
;
$uniqueid
=
$DB
->
get_field_sql
(
'SELECT COALESCE(MAX(uniqueid), 0) + 1 FROM {quiz_attempts}'
);
$uniqueid
=
$DB
->
get_field_sql
(
'SELECT COALESCE(MAX(uniqueid), 0) + 1 FROM {quiz_attempts}'
);
...
@@ -258,7 +259,7 @@ final class quiz_api_test extends advanced_testcase {
...
@@ -258,7 +259,7 @@ final class quiz_api_test extends advanced_testcase {
* @param $requestdata
* @param $requestdata
* @return void
* @return void
*/
*/
private
function
send_answers_to_api
(
$requestdata
)
{
private
function
send_answers_to_api
(
$requestdata
)
:
void
{
try
{
try
{
$apiendpoint
=
utils
::
get_api_endpoint
();
$apiendpoint
=
utils
::
get_api_endpoint
();
$httpclient
=
new
http_client
();
$httpclient
=
new
http_client
();
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new 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