Added ability to add benchmark results to a test
This commit is contained in:
parent
c1da3b6a57
commit
2b5193dccf
@ -1,5 +1,18 @@
|
|||||||
testId = $('#results-table').data('test-id')
|
testId = $('#results-table').data('test-id')
|
||||||
|
|
||||||
|
$ ->
|
||||||
|
$('#test-result-form').on 'submit', (e) ->
|
||||||
|
e.preventDefault()
|
||||||
|
|
||||||
|
form = $(this)
|
||||||
|
formData = $(this).serialize()
|
||||||
|
benchmarkId = $(this).find('[name="result_benchmark"]').val()
|
||||||
|
|
||||||
|
$.post '/api/v1/result/add', formData, (response) ->
|
||||||
|
if response == 'success'
|
||||||
|
fetchTestBenchmarkResults(testId, benchmarkId)
|
||||||
|
form[0].reset()
|
||||||
|
|
||||||
fetchTestBenchmarkResults = (testId, benchmarkId) ->
|
fetchTestBenchmarkResults = (testId, benchmarkId) ->
|
||||||
try
|
try
|
||||||
benchmarkSearchParams = new URLSearchParams
|
benchmarkSearchParams = new URLSearchParams
|
||||||
@ -18,12 +31,14 @@ fetchTestBenchmarkResults = (testId, benchmarkId) ->
|
|||||||
max_total = 0
|
max_total = 0
|
||||||
|
|
||||||
for result in resultData
|
for result in resultData
|
||||||
avg_total += result.avg_score
|
avg_total += result.avgScore
|
||||||
min_total += result.min_score
|
min_total += result.minScore
|
||||||
max_total += result.max_score
|
max_total += result.maxScore
|
||||||
|
|
||||||
tableRow = $("#results-table tr[data-benchmark-id=#{benchmarkId}]")
|
tableRow = $("#results-table tr[data-benchmark-id=#{benchmarkId}]")
|
||||||
|
|
||||||
|
tableRow.empty()
|
||||||
|
|
||||||
tableRow.append('<td>' + benchmarkData.name + '</td>')
|
tableRow.append('<td>' + benchmarkData.name + '</td>')
|
||||||
tableRow.append('<td>' + benchmarkData.scoring + '</td>')
|
tableRow.append('<td>' + benchmarkData.scoring + '</td>')
|
||||||
tableRow.append('<td>' + resultData.length + '</td>')
|
tableRow.append('<td>' + resultData.length + '</td>')
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
const Benchmark = require('../models').models.Benchmark;
|
const Benchmark = require('../models').models.Benchmark;
|
||||||
const Result = require('../models').models.Result;
|
const Result = require('../models').models.Result;
|
||||||
|
const Test = require('../models').models.Test;
|
||||||
|
|
||||||
// GET /api/v1/benchmark/details
|
// GET /api/v1/benchmark/details
|
||||||
exports.getBenchmarkDetails = async function(req, res) {
|
exports.getBenchmarkDetails = async function(req, res) {
|
||||||
@ -37,3 +38,26 @@ exports.getResultList = async function(req, res) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// POST /api/v1/result/add - add a benchmark result to the database
|
||||||
|
exports.postResultAdd = async function(req, res) {
|
||||||
|
try {
|
||||||
|
const result = await Result.create({
|
||||||
|
avgScore: req.body.result_avg,
|
||||||
|
minScore: req.body.result_min,
|
||||||
|
maxScore: req.body.result_max
|
||||||
|
});
|
||||||
|
|
||||||
|
let benchmark = await Benchmark.findByPk(req.body.result_benchmark);
|
||||||
|
result.setBenchmark(benchmark);
|
||||||
|
|
||||||
|
let test = await Test.findByPk(req.body.result_test);
|
||||||
|
result.setTest(test);
|
||||||
|
|
||||||
|
res.json('success');
|
||||||
|
} catch (err) {
|
||||||
|
res.status(500).json({
|
||||||
|
error: 'Internal server error occurred while adding result.'
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
|
@ -34,5 +34,6 @@ module.exports = function(app) {
|
|||||||
// API v1 routes
|
// API v1 routes
|
||||||
app.get('/api/v1/benchmark/details', apiv1Routes.getBenchmarkDetails);
|
app.get('/api/v1/benchmark/details', apiv1Routes.getBenchmarkDetails);
|
||||||
app.get('/api/v1/result/list', apiv1Routes.getResultList);
|
app.get('/api/v1/result/list', apiv1Routes.getResultList);
|
||||||
|
app.post('/api/v1/result/add', apiv1Routes.postResultAdd);
|
||||||
|
|
||||||
};
|
};
|
||||||
|
@ -10,7 +10,7 @@
|
|||||||
<hr>
|
<hr>
|
||||||
|
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<form id="result_form" class="twelve columns" action="/result/add" method="post">
|
<form id="test-result-form" class="twelve columns" action="/api/v1/result/add" method="post">
|
||||||
<input type="hidden" name="result_test" value="{{ test.id }}">
|
<input type="hidden" name="result_test" value="{{ test.id }}">
|
||||||
|
|
||||||
<div class="row">
|
<div class="row">
|
||||||
@ -28,21 +28,21 @@
|
|||||||
<div class="two columns">
|
<div class="two columns">
|
||||||
<label for="result_avg">
|
<label for="result_avg">
|
||||||
Average:
|
Average:
|
||||||
<input type="number" id="result_avg" class="u-full-width" name="result_avg">
|
<input type="number" id="result_avg" class="u-full-width" name="result_avg" step="0.01" required>
|
||||||
</label>
|
</label>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="two columns">
|
<div class="two columns">
|
||||||
<label for="result_min">
|
<label for="result_min">
|
||||||
Minimum:
|
Minimum:
|
||||||
<input type="number" id="result_min" class="u-full-width" name="result_min">
|
<input type="number" id="result_min" class="u-full-width" name="result_min" step="0.01">
|
||||||
</label>
|
</label>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="two columns">
|
<div class="two columns">
|
||||||
<label for="result_max">
|
<label for="result_max">
|
||||||
Maximum:
|
Maximum:
|
||||||
<input type="number" id="result_max" class="u-full-width" name="result_max">
|
<input type="number" id="result_max" class="u-full-width" name="result_max" step="0.01">
|
||||||
</label>
|
</label>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user