Skip to content

Commit

Permalink
added page for viewing model statistics #610
Browse files Browse the repository at this point in the history
this will consume the GET/get-model-statistics/:mid web service end
point and display it for consumption
  • Loading branch information
Matthew Letter committed Mar 25, 2016
1 parent a449577 commit 021647e
Show file tree
Hide file tree
Showing 2 changed files with 84 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# coding=utf-8
def register_slycat_plugin(context):
import os

def page_html(database, model):
import pystache
context = dict()
return pystache.render(open(os.path.join(os.path.dirname(__file__), "ui.html"), "r").read(), context)

'''
Register a custom page
Running this example code:
- Configure your web server to load the slycat-login plugin by adding it to the /etc/slycat/web-server-config.ini for the developer image
- Point a browser to https://your-slycat-server/pages/model-statistics
'''
context.register_page("model-statistics", page_html)
64 changes: 64 additions & 0 deletions web-server/plugins/slycat-model-statistics/ui.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
<div class="bootstrap-styles" style="-webkit-flex:1;flex:1;display:-webkit-flex;display:flex;-webkit-align-items:center;align-items:center;-webkit-justify-content:center;justify-content:center;padding:12px;">
TODO add ui, add json
</div>

<script type="text/javascript">
require(["slycat-server-root", "jquery", "URI"], function(server_root, $, URI)
{
function login()
{
user_name = document.getElementById("Username").value
password = document.getElementById("Password").value
//TODO: add post call for username and password
console.log("calling webservice with")
console.log("login " + user_name + " " + password);
console.log(server_root + "login/")
var sendInfo = JSON.stringify(
{
"user_name": user_name,
"password": password
}
);

$.ajax(
{
contentType: "application/json",
type: "POST",
url: URI(server_root + "login"),
success: function(result)
{
window.alert("success " + result);
console.log("success " + result);
},
error: function(request, status, reason_phrase)
{
window.alert("error request:" + request.responseJSON +" status: "+ status + " reason: " + reason_phrase);
console.log("error request:" + request.responseJSON +" status: "+ status + " reason: " + reason_phrase);
},
data: sendInfo
});

console.log("done")
}

function logout()
{
console.log("logging out");
$.ajax(
{
type: "DELETE",
url: server_root + "logout",
success: function()
{
console.log("success")
},
error: function(request, status, reason_phrase)
{
console.log("fail")
},
});
}
document.getElementById("go").addEventListener("click", login, false);
document.getElementById("logout").addEventListener("click", logout, false);
});
</script>

0 comments on commit 021647e

Please sign in to comment.