Moves getting poc address to view helper function, adds ability to configure POC address
This commit is contained in:
@@ -145,6 +145,8 @@ def main(global_config, **settings):
|
||||
config.add_route('json_config', '/json/config')
|
||||
config.add_route('config', '/config')
|
||||
|
||||
config.add_route('admin', '/admin')
|
||||
|
||||
# JSON-ONLY ROUTES
|
||||
config.add_route('json_lastcard', "/json/lastcard")
|
||||
config.add_route('json_runstatusnow', "/json/runstatusnow")
|
||||
@@ -162,6 +164,7 @@ def main(global_config, **settings):
|
||||
config.add_route("json_cmd_start", "/json/cmd/start")
|
||||
config.add_route("json_cmd_stop", "/json/cmd/stop")
|
||||
config.add_route("json_cmd_shake", "/json/cmd/shake")
|
||||
config.add_route("json_update_poc_address", "/json/updatepocaddress")
|
||||
|
||||
config.scan()
|
||||
return config.make_wsgi_app()
|
||||
|
||||
@@ -162,11 +162,7 @@ def json_updateconfig(request):
|
||||
|
||||
@view_config(route_name="json_cmd_start", renderer="prettyjson")
|
||||
def json_start(request):
|
||||
addr_obj = list(request.db['pocConfiguration'].find({"_id": "pocIPAddress"}))
|
||||
address = 'localhost'
|
||||
if len(addr_obj) > 0:
|
||||
address = addr_obj[0]['pocIPAddress']
|
||||
|
||||
address = get_poc_address(request) or 'localhost'
|
||||
start_url = "http://{}:8000/command?start=true".format(address)
|
||||
r = requests.get(start_url)
|
||||
return r.text if r.status_code == 200 else {"status": "failure sending command"}
|
||||
@@ -174,11 +170,7 @@ def json_start(request):
|
||||
|
||||
@view_config(route_name="json_cmd_stop", renderer="prettyjson")
|
||||
def json_stop(request):
|
||||
addr_obj = list(request.db['pocConfiguration'].find({"_id": "pocIPAddress"}))
|
||||
address = 'localhost'
|
||||
if len(addr_obj) > 0:
|
||||
address = addr_obj[0]['pocIPAddress']
|
||||
|
||||
address = get_poc_address(request) or 'localhost'
|
||||
stop_url = "http://{}:8000/command?stop=true".format(address)
|
||||
r = requests.get(stop_url)
|
||||
return r.text if r.status_code == 200 else {"status": "failure sending command"}
|
||||
@@ -186,11 +178,17 @@ def json_stop(request):
|
||||
|
||||
@view_config(route_name="json_cmd_shake", renderer="prettyjson")
|
||||
def json_shake(request):
|
||||
addr_obj = list(request.db['pocConfiguration'].find({"_id": "pocIPAddress"}))
|
||||
address = 'localhost'
|
||||
if len(addr_obj) > 0:
|
||||
address = addr_obj[0]['pocIPAddress']
|
||||
|
||||
address = get_poc_address(request) or 'localhost'
|
||||
shake_url = "http://{}:8000/shake".format(address)
|
||||
r = requests.get(shake_url)
|
||||
return r.text if r.status_code == 200 else {"status": "failure sending command"}
|
||||
|
||||
|
||||
@view_config(route_name="json_update_poc_address", renderer="prettyjson", request_method='POST')
|
||||
def json_update_poc_address(request):
|
||||
try:
|
||||
new_addr = request.json_body['pocIPAddress']
|
||||
upsert = request.db['pocConfiguration'].update_one({"_id": "pocIPAddress"}, {"$set": {'pocIPAddress': new_addr}}, upsert=True)
|
||||
return {"status": "OK"}
|
||||
except KeyError:
|
||||
return {"status": "failure"}
|
||||
|
||||
59
www/pocwww/pocwww/templates/admin.jinja2
Normal file
59
www/pocwww/pocwww/templates/admin.jinja2
Normal file
@@ -0,0 +1,59 @@
|
||||
{% from 'pagination.jinja2' import render_pagination %}
|
||||
{% extends "layout.jinja2" %}
|
||||
|
||||
{% block content %}
|
||||
|
||||
<div class="content">
|
||||
<div class="row">
|
||||
<div class="col-xs-12">
|
||||
<h2>Well Configuration</h2>
|
||||
<form>
|
||||
<div class="form-group">
|
||||
<label for="pocIPAddress">POC IP Address</label>
|
||||
<input type="text" class="form-control" id="pocIPAddress" value="{{pocIPAddress}}">
|
||||
</div>
|
||||
<hr />
|
||||
<div class="alert alert-success alert-dismissable hidden" id="update-success">
|
||||
<span>
|
||||
<p>Address successfully updated!</p>
|
||||
</span>
|
||||
</div>
|
||||
<div class="alert alert-danger alert-dismissable hidden" id="update-failed">
|
||||
<span>
|
||||
<p>Failed to update address.</p>
|
||||
</span>
|
||||
</div>
|
||||
<button id="submit" class="btn btn-default">Update Address</button>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
|
||||
function configUpdatedSuccessfully(data){
|
||||
console.log(data);
|
||||
if(data.status == "OK"){
|
||||
$('#update-success').removeClass('hidden');
|
||||
} else {
|
||||
$('#update-failed').removeClass('hidden');
|
||||
}
|
||||
}
|
||||
|
||||
$("#submit").click(function(event){
|
||||
event.preventDefault();
|
||||
$('#update-success').addClass('hidden');
|
||||
$('#update-failed').addClass('hidden');
|
||||
var newObject = {};
|
||||
newObject.pocIPAddress = $("#pocIPAddress").val();
|
||||
$.ajax({
|
||||
type: "POST",
|
||||
dataType: 'json',
|
||||
data: JSON.stringify(newObject),
|
||||
contentType: "application/json; charset=utf-8",
|
||||
url: "/json/updatepocaddress",
|
||||
success: configUpdatedSuccessfully
|
||||
});
|
||||
})
|
||||
</script>
|
||||
{% endblock content %}
|
||||
@@ -101,7 +101,7 @@
|
||||
<p>Failed to update configuration.</p>
|
||||
</span>
|
||||
</div>
|
||||
<button id="submit" class="btn btn-default">Update Well Configuration</button><span id="update-result"></span>
|
||||
<button id="submit" class="btn btn-default">Update Well Configuration</button>
|
||||
</form>
|
||||
|
||||
</div>
|
||||
|
||||
@@ -75,3 +75,11 @@ def get_all_dates_with_cards(request):
|
||||
for d in dateagg:
|
||||
datelist.append({'count': d['count'], 'date': datetime.strptime(d['_id'], "%Y-%m-%d").date()})
|
||||
return list(datelist)
|
||||
|
||||
|
||||
def get_poc_address(request):
|
||||
addr_obj = list(request.db['pocConfiguration'].find({"_id": "pocIPAddress"}))
|
||||
address = False
|
||||
if len(addr_obj) > 0:
|
||||
address = addr_obj[0]['pocIPAddress']
|
||||
return address
|
||||
|
||||
@@ -139,3 +139,9 @@ def run_status(request):
|
||||
def well_config(request):
|
||||
current_configuration = list(request.db['wellConfiguration'].find().sort("timestamp", -1).limit(1))[0]
|
||||
return {'navgroup': 'config', 'config': current_configuration}
|
||||
|
||||
|
||||
@view_config(route_name="admin", renderer="templates/admin.jinja2")
|
||||
def admin_view(request):
|
||||
address = get_poc_address(request) or 'localhost'
|
||||
return {'navgroup': 'admin', 'pocIPAddress': address}
|
||||
|
||||
Reference in New Issue
Block a user