[enh] start an app page

This commit is contained in:
Laurent Peuch 2018-11-03 06:11:38 +01:00
parent 2b10a70d6d
commit 892905093d
3 changed files with 68 additions and 0 deletions

20
run.py
View file

@ -451,6 +451,20 @@ async def ws_job(request, websocket, job_id):
await websocket.recv()
@app.websocket('/apps-ws')
async def ws_apps(request, websocket):
# subscribe(websocket, f"job-{job.id}")
await websocket.send(ujson.dumps({
"action": "init_apps",
"data": map(model_to_dict, Repo.select().order_by(Repo.name))
}))
while True:
# do nothing with input but wait
await websocket.recv()
def require_token():
def decorator(f):
@wraps(f)
@ -615,6 +629,12 @@ async def job(request, job_id):
return {"job": job[0], 'relative_path_to_root': '../', 'path': request.path}
@app.route('/apps/')
@jinja.template('apps.html')
async def apps(request):
return {'relative_path_to_root': '../', 'path': request.path}
@app.route('/')
@jinja.template('index.html')
async def index(request):

44
templates/apps.html Normal file
View file

@ -0,0 +1,44 @@
<% extends "base.html" %>
<% block content %>
<section class="section">
<div class="container">
<h1 class="title">Apps</h1>
<div id="apps">
<table class="table is-bordered is-hoverable is-striped is-fullwidth">
<thead>
<th>App</th>
</thead>
<tr v-for="(app, index) in apps" :id="app.id">
<td>{{app.name}}</td>
</tr>
</table>
</div>
</div>
</section>
<% endblock %>
<% block javascript %>
<script>
(function() {
var app = new Vue({
el: '#apps',
data: {
apps: []
}
})
ws = new ReconnectingWebSocket(websocketPrefix() + '://' + document.domain + ':' + location.port + websocketRelativePath('<{ path }>') + '/apps-ws');
ws.onmessage = function (event) {
var message = JSON.parse(event.data);
var data = message.data;
var action = message.action;
if (action == "init_apps") {
app.apps = data;
}
};
})()
</script>
<% endblock %>

View file

@ -16,6 +16,10 @@
<a class="navbar-item" href="<{ relative_path_to_root }>">
Home
</a>
<a class="navbar-item" href="<{ relative_path_to_root }>/apps/">
Apps
</a>
</div>
</div>
</nav>