Added javascript code to add a result in the background without refreshing the page
This commit is contained in:
parent
b4bd116367
commit
5919226dec
@ -1,6 +1,8 @@
|
|||||||
$ ->
|
$ ->
|
||||||
console.log('ready.')
|
console.log('ready.')
|
||||||
|
|
||||||
|
$('#result-form').on('submit', addResult)
|
||||||
|
|
||||||
$('#report-benchmarks').on('change', ->
|
$('#report-benchmarks').on('change', ->
|
||||||
url = '/api/benchmark/' + $('#report-benchmarks').val() + '/tests'
|
url = '/api/benchmark/' + $('#report-benchmarks').val() + '/tests'
|
||||||
$.get(url, (data) ->
|
$.get(url, (data) ->
|
||||||
@ -17,3 +19,18 @@ addOption = (test) ->
|
|||||||
.attr('value', test.id)
|
.attr('value', test.id)
|
||||||
.text(test.title)
|
.text(test.title)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
addResult = (e) ->
|
||||||
|
e.preventDefault() # prevent browser from traveling to another page
|
||||||
|
|
||||||
|
$.post('/result/add', {
|
||||||
|
redirect: false
|
||||||
|
result_test: $('#result_test').val()
|
||||||
|
result_component: $('#result_component').val()
|
||||||
|
result_benchmark: $('#result_benchmark').val()
|
||||||
|
result_avg: $('#result_avg').val()
|
||||||
|
result_min: $('#result_min').val()
|
||||||
|
result_max: $('#result_max').val()
|
||||||
|
}, (data) ->
|
||||||
|
console.log(data)
|
||||||
|
)
|
||||||
|
@ -24,6 +24,7 @@ class ResultController extends Controller {
|
|||||||
|
|
||||||
$result->save();
|
$result->save();
|
||||||
|
|
||||||
|
if (!isset($params['redirect']) || $params['redirect'])
|
||||||
// redirect the user back to the home page
|
// redirect the user back to the home page
|
||||||
$routeContext = RouteContext::fromRequest($request);
|
$routeContext = RouteContext::fromRequest($request);
|
||||||
$routeParser = $routeContext->getRouteParser();
|
$routeParser = $routeContext->getRouteParser();
|
||||||
@ -32,6 +33,12 @@ class ResultController extends Controller {
|
|||||||
'test_id' => $result->test_id
|
'test_id' => $result->test_id
|
||||||
]))
|
]))
|
||||||
->withStatus(302);
|
->withStatus(302);
|
||||||
|
} else {
|
||||||
|
$payload = json_encode('Success!');
|
||||||
|
$response->getBody()->write($payload);
|
||||||
|
return $response
|
||||||
|
->withHeader('Content-Type', 'application/json');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -17,7 +17,7 @@
|
|||||||
<form id="result-form" class="u-full-width" action="{{ url_for('result.add') }}" method="POST">
|
<form id="result-form" class="u-full-width" action="{{ url_for('result.add') }}" method="POST">
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="four columns">
|
<div class="four columns">
|
||||||
<select class="u-full-width" name="result_benchmark">
|
<select id="result_benchmark" class="u-full-width" name="result_benchmark">
|
||||||
{% for b in test.benchmarks %}
|
{% for b in test.benchmarks %}
|
||||||
<option value="{{ b.id }}">{{ b.name }}</option>
|
<option value="{{ b.id }}">{{ b.name }}</option>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
@ -25,13 +25,13 @@
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="two columns">
|
<div class="two columns">
|
||||||
<input type="number" step="0.01" name="result_avg" placeholder="0.0">
|
<input id="result_avg" type="number" step="0.01" name="result_avg" placeholder="0.0">
|
||||||
</div>
|
</div>
|
||||||
<div class="two columns">
|
<div class="two columns">
|
||||||
<input type="number" step="0.01" name="result_min" placeholder="0.0">
|
<input id="result_min" type="number" step="0.01" name="result_min" placeholder="0.0">
|
||||||
</div>
|
</div>
|
||||||
<div class="two columns">
|
<div class="two columns">
|
||||||
<input type="number" step="0.01" name="result_max" placeholder="0.0">
|
<input id="result_max" type="number" step="0.01" name="result_max" placeholder="0.0">
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="two columns">
|
<div class="two columns">
|
||||||
@ -39,8 +39,8 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<input type="hidden" name="result_test" value="{{ test.id }}">
|
<input id="result_test" type="hidden" name="result_test" value="{{ test.id }}">
|
||||||
<input type="hidden" name="result_component" value="{{ test.component().id }}">
|
<input id="result_component" type="hidden" name="result_component" value="{{ test.component().id }}">
|
||||||
</form>
|
</form>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
Loading…
Reference in New Issue
Block a user