Browse Source

more work on ui

main
david 5 years ago
parent
commit
06074e6d80
  1. 48
      factoriocp.py
  2. 2
      static/css/sticky-footer.css
  3. 47
      views/create.tpl
  4. 142
      views/default.tpl
  5. 125
      views/edit.tpl
  6. 6
      views/footer.tpl
  7. 23
      views/header.tpl
  8. 11
      views/login.tpl

48
factoriocp.py

@ -41,11 +41,31 @@ def log_in(username, password):
# get a list of server dicts
def get_servers():
pass
return [{ "name": "Creative fun", "desc": "A creative vanilla server for tests.", "version": "0.14.20", "status": "online", "port": "34197" },
{ "name": "Vanilla on the rocks", "desc": "Vanilla map with some mods.", "version": "0.14.19", "status": "offline", "port": "34198" },
{ "name": "Mad enemies", "desc": "Hazardous map. A lot of enemies.", "version": "0.14.19", "status": "offline", "port": "34199" },
{ "name": "Online Map", "desc": "A modded map for friends.", "version": "0.14.19", "status": "online", "port": "34200" },
{ "name": "Mad enemies2", "desc": "Just a copy of Mad enemies.", "version": "0.14.20", "status": "offline", "port": "34201" }]
return [{ "name": "Creative fun", "desc": "A creative vanilla server for tests.", "version": "0.14.20", "status": "online", "port": "34197", "mods": [ "base", "" ] },
{ "name": "Vanilla on the rocks", "desc": "Vanilla map with some mods.", "version": "0.14.19", "status": "offline", "port": "34198", "mods": [ "base", "" ] },
{ "name": "Mad enemies", "desc": "Hazardous map. A lot of enemies.", "version": "0.14.19", "status": "offline", "port": "34199", "mods": [ "base", "Factorissimo", "long-reach" ] },
{ "name": "Online Map", "desc": "A modded map for friends.", "version": "0.14.19", "status": "online", "port": "34200", "mods": [ "base", "Factorissimo", "long-reach", "FactorioExtended-Extra", "FactorioExtended-Titan", "FactorioExtended-Military", "FactorioExtended-Core", "Factorissimo" ] },
{ "name": "Mad enemies2", "desc": "Just a copy of Mad enemies.", "version": "0.14.20", "status": "offline", "port": "34201", "mods": [ "base", ] }]
# find a available port for new server
def find_port():
ports = [ server['port'] for server in get_servers()]
for port in range(int(config['factorio']['port']),int(config['factorio']['port'])+9):
if str(port) not in ports:
return port
return False
# create new server
def create_server(name, desc, file):
port = find_port()
if port:
#create server directory in factorio base path
#download and unzip factorio headless to this directory
install_headless(path)
# routing
@ -63,6 +83,7 @@ def view_home():
username=username,
servers=servers,
app_name=config['DEFAULT']['app_name'],
fqdn=config['server']['fqdn'],
message=message)
else:
# render login
@ -111,7 +132,7 @@ def send_static(filename):
return static_file(filename, root=config['DEFAULT']['static_files'])
# render server page
@get('/server/<port:int>')
@get('/edit/<port:int>')
def view_server(port):
username = logged_in()
message = request.get_cookie(config['DEFAULT']['cookie_name'] + "_message",
@ -120,7 +141,7 @@ def view_server(port):
servers = get_servers()
server = [ server for server in servers if int(server['port']) == int(port) ]
if server:
return template('server',
return template('edit',
app_name=config['DEFAULT']['app_name'],
server=server[0],
username=username,
@ -141,7 +162,18 @@ def view_server(port):
# create new server
@get('/create')
def create_server():
pass
username = logged_in()
message = request.get_cookie(config['DEFAULT']['cookie_name'] + "_message",
secret=config['DEFAULT']['cookie_secret'])
if username:
return template('create',
app_name=config['DEFAULT']['app_name'],
username=username,
fqdn=config['server']['fqdn'],
message=message)
else:
redirect("/")

2
static/css/sticky-footer.css

@ -11,7 +11,7 @@ body {
a.nounderline {
text-decoration: none;
color: dimgrey;
color: black;
}
.footer {

47
views/create.tpl

@ -0,0 +1,47 @@
%include('header.tpl', app_name=app_name, message=message, page_name="Create server")
<div class="card">
<a class="collapsed nounderline" data-toggle="collapse" data-parent="#accordion" href="#collapseOverview" aria-expanded="false" aria-controls="collapseOverview">
<div class="card-header" role="tab" id="headingOverview">
<h5 class="mb-0">
Name and description
</h5>
</div>
</a>
<div id="collapseOverview" class="collapse in" role="tabpanel" aria-labelledby="headingOverview">
<div class="card-block">
<form>
<div class="form-group">
<label for="createInputName">Server name:</label>
<input type="text" class="form-control" id="createInputName" aria-describedby="nameHelp">
<small id="nameHelp" class="form-text text-muted">This will be visible to clients.</small>
</div>
<div class="form-group">
<label for="createInputDesc">Server description:</label>
<input type="text" class="form-control" id="createInputDesc" aria-describedby="descHelp">
<small id="descHelp" class="form-text text-muted">This will be visible to clients.</small>
</div>
<div class="form-group">
<label for="createInputFile">Savegame:</label>
<input type="file" class="form-control-file" id="createInputFile" aria-describedby="fileHelp">
<small id="fileHelp" class="form-text text-muted">You can import your own map by uploading a savegame(.zip) here. If left empty a new map will be generated.</small>
</div>
<div class="row">
<div class="col-sm-8">
</div>
<div class="col-sm-4 text-xs-right">
<button type="submit" class="btn btn-outline-success">Create new server</button>
</div>
</div>
</form>
</div>
</div>
</div>
%include('footer.tpl', username=username, app_name=app_name)

142
views/default.tpl

@ -1,113 +1,61 @@
%include('header.tpl', app_name=app_name, message=message)
<!-- Begin page content -->
<div class="container">
<div class="row">
<div class="col-sm-8">
<h1>Server overview</h1>
</div>
<div class="col-sm-4 text-xs-right">
<div class="btn-group">
<button type="button" class="btn btn-outline-primary dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
{{ username }}
</button>
<div class="dropdown-menu">
<a class="dropdown-item" href="/">Server overview</a>
<a class="dropdown-item" href="#">Create server</a>
<a class="dropdown-item" href="#">About</a>
<div class="dropdown-divider"></div>
<a class="dropdown-item" href="/logout">Logout</a>
</div>
</div>
</div>
</div>
<p class="lead">Control your <a href="http://factorio.com">Factorio</a> game servers from here.</p>
<!-- <table class="table table-hover">
<thead>
<tr>
<th>Name</th>
<th>Version</th>
<th>Port</th>
<th>Status</th>
<th class="text-xs-right">Actions</th>
</tr>
</thead>
<tbody>
%for server in servers:
%if server['status'] == "online":
<tr>
<th>{{ server['name'] }}</th>
<td>{{ server['version'] }}</td>
<td>{{ server['port'] }}</td>
<td><span class="tag tag-success">{{ server['status'] }}</span></td>
<td class="text-xs-right">
<a href="/stop/{{ server['port' ]}}" type="button" class="btn btn-outline-danger btn-sm">Stop</a>
<a href="/server/{{ server['port'] }}" type="button" class="btn btn-outline-primary btn-sm">Edit</a>
</td>
</tr>
%else:
<tr>
<th>{{ server['name'] }}</th>
<td>{{ server['version'] }}</td>
<td>{{ server['port'] }}</td>
<td><span class="tag tag-danger">{{ server['status'] }}</span></td>
<td class="text-xs-right">
<a href="/start/{{ server['port'] }}" type="button" class="btn btn-outline-success btn-sm">Start</a>
<a href="/delete/{{ server['port'] }}" type="button" class="btn btn-outline-danger btn-sm">Delete</a>
<a href="/server/{{ server['port'] }}" type="button" class="btn btn-outline-primary btn-sm">Edit</a>
</td>
</tr>
%end
%end
</tbody>
</table>
-->
%include('header.tpl', app_name=app_name, message=message, page_name="Server overview")
<!-- Begin Accordion -->
<div id="accordion" role="tablist" aria-multiselectable="true">
%for server in servers:
<!-- Begin Server cards -->
<div class="card">
<a class="collapsed nounderline" data-toggle="collapse" data-parent="#accordion" href="#collapse{{server['port']}}" aria-expanded="false" aria-controls="collapse{{server['port']}}">
<div class="card-header" role="tab" id="heading{{server['port']}}">
<h5 class="mb-0">
<div class="row">
<div class="card-header" role="tab" id="heading{{server['port']}}">
<h5 class="mb-0">
<div class="row">
<div class="col-sm-6">
{{ server['name'] }}
</div>
<div class="col-sm-6 text-xs-right">
%if server['status'] == "online":
<span class="tag tag-success">{{server['status']}}</span>
%else:
<span class="tag tag-danger">{{server['status']}}</span>
%end
</div>
<div class="col-sm-6 text-xs-right">
%if server['status'] == "online":
<span class="text-success">running</span>
%else:
<span class="text-danger">stopped</span>
%end
</div>
</div>
</h5>
</div>
</a>
<div id="collapse{{server['port']}}" class="collapse" role="tabpanel" aria-labelledby="heading{{server['port']}}">
<div class="card-block">
<h4 class="card-title">{{ server['desc'] }}</h4>
<table class="table">
<tr><th>Address</th><td>factorio.bla.com:{{ server['port'] }}</td></tr>
<tr><th>Version</th><td>{{ server['version'] }}</td></tr>
<tr><th>Admins</th><td><span class="tag tag-default">0bsidian0rder</span></td></tr>
</table>
<div class="row">
<div class="col-sm-4">
</div>
<div class="col-sm-8 text-xs-right">
<a href="#" class="btn btn-outline-success">Start</a>
<a href="#" class="btn btn-outline-danger">Stop</a>
<a href="/server/{{server['port']}}" class="btn btn-outline-primary">Edit</a>
</div>
</div>
<div id="collapse{{server['port']}}" class="collapse" role="tabpanel" aria-labelledby="heading{{server['port']}}">
<div class="card-block">
<h4 class="card-title">{{ server['desc'] }}</h4>
<table class="table">
<tr><th>Address:</th><td><code>{{ fqdn }}:{{ server['port'] }}</code></td></tr>
<tr><th>Version:</th><td>{{ server['version'] }}</td></tr>
<tr><th>Mods:</th><td>
%for mod in server['mods']:
<span class="tag tag-default">{{ mod }}</span>
%end
</td></tr>
<tr><th>Admins:</th><td>0bsidian0rder, Singso</td></tr>
</table>
<div class="row">
<div class="col-sm-4"></div>
<div class="col-sm-8 text-xs-right">
%if server['status'] == "online":
<a href="#" class="btn btn-outline-danger">Stop</a>
%else:
<a href="#" class="btn btn-outline-success">Start</a>
%end
<a href="/edit/{{server['port']}}" class="btn btn-outline-primary">Edit</a>
</div>
</div>
</div>
</div>
</div>
</div>
</div> <!-- Server cards -->
%end
</div>
</div>
<!-- Accordion -->
</div> <!-- Page content -->
%include('footer.tpl', username=username)
%include('footer.tpl', username=username, app_name=app_name)

125
views/server.tpl → views/edit.tpl

@ -1,105 +1,98 @@
%include('header.tpl', app_name=app_name, message=message)
<!-- Begin page content -->
<div class="container">
<div class="row">
<div class="col-sm-8">
<h1>Edit Server</h1>
</div>
<div class="col-sm-4 text-xs-right">
<div class="btn-group">
<button type="button" class="btn btn-outline-primary dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
{{ username }}
</button>
<div class="dropdown-menu">
<a class="dropdown-item" href="/">Server overview</a>
<a class="dropdown-item" href="#">Create server</a>
<a class="dropdown-item" href="#">About</a>
<div class="dropdown-divider"></div>
<a class="dropdown-item" href="/logout">Logout</a>
</div>
</div>
</div>
</div>
<p class="lead">Control your <a href="http://factorio.com">Factorio</a> game server from here.</p>
%include('header.tpl', app_name=app_name, message=message, page_name="Edit server")
<!-- Begin Accordion -->
<div id="accordion" role="tablist" aria-multiselectable="true">
<!-- Begin Server card -->
<div class="card">
<a class="collapsed nounderline" data-toggle="collapse" data-parent="#accordion" href="#collapseOverview" aria-expanded="false" aria-controls="collapseOverview">
<a class="collapsed nounderline" data-toggle="collapse" data-parent="#accordion" href="#collapseOverview" aria-expanded="false" aria-controls="collapseOverview">
<div class="card-header" role="tab" id="headingOverview">
<h5 class="mb-0">
<div class="row">
<div class="col-sm-6">
{{ server['name'] }}
</div>
<div class="col-sm-6">
{{ server['name'] }}
</div>
<div class="col-sm-6 text-xs-right">
%if server['status'] == "online":
<span class="text-success">running</span>
%else:
<span class="text-danger">stopped</span>
%end
</div>
</div>
</h5>
</div>
</a>
<div id="collapseOverview" class="collapse in" role="tabpanel" aria-labelledby="headingOverview">
<div class="card-block">
<h4 class="card-title">{{ server['desc'] }}</h4>
<table class="table">
<tr><th>Address:</th><td><code>{{ fqdn }}:{{ server['port'] }}</code></td></tr>
<tr><th>Version:</th><td>{{ server['version'] }}</td></tr>
<tr><th>Mods:</th><td>
%for mod in server['mods']:
<span class="tag tag-default">{{ mod }}</span>
%end
</td></tr>
<tr><th>Admins:</th><td>0bsidian0rder, Singso</td></tr>
</table>
<div class="row">
<div class="col-sm-8"></div>
<div class="col-sm-4 text-xs-right">
%if server['status'] == "online":
<span class="tag tag-success">{{server['status']}}</span>
<a href="#" class="btn btn-outline-danger">Stop</a>
%else:
<span class="tag tag-danger">{{server['status']}}</span>
<a href="#" class="btn btn-outline-success">Start</a>
<a href="#" class="btn btn-outline-danger">Delete</a>
%end
</div>
</h5>
</div>
</div>
</a>
<div id="collapseOverview" class="collapse in" role="tabpanel" aria-labelledby="headingOverview">
<div class="card-block">
<h4 class="card-title">{{ server['desc'] }}</h4>
<table class="table">
<tr><th>Address</th><td>{{ fqdn }}:{{ server['port'] }}</td></tr>
<tr><th>Version</th><td>{{ server['version'] }}</td></tr>
<tr><th>Status</th><td><span class="tag tag-success">{{ server['status'] }}</span></td></tr>
</table>
<div class="row">
<div class="col-sm-8">
</div>
<div class="col-sm-4 text-xs-right">
<a href="#" class="btn btn-outline-success">Start</a> <a href="#" class="btn btn-outline-danger">Stop</a>
</div>
</div>
</div>
</div>
</div>
</div> <!-- Server card -->
<!-- Begin Settings -->
<div class="card">
<a class="collapsed nounderline" data-toggle="collapse" data-parent="#accordion" href="#collapseSettings" aria-expanded="false" aria-controls="collapseSettings">
<div class="card-header" role="tab" id="headingSettings">
<h5 class="mb-0">Settings</h5>
</div>
<div class="card-header" role="tab" id="headingSettings">
<h5 class="mb-0">Settings</h5>
</div>
</a>
<div id="collapseSettings" class="collapse" role="tabpanel" aria-labelledby="headingSettings">
<div class="card-block">
Anim pariatur cliche reprehenderit, enim eiusmod high life accusamus terry richardson ad squid. 3 wolf moon officia aute, non cupidatat skateboard dolor brunch. Food truck quinoa nesciunt laborum eiusmod. Brunch 3 wolf moon tempor, sunt aliqua put a bird on it squid single-origin coffee nulla assumenda shoreditch et. Nihil anim keffiyeh helvetica, craft beer labore wes anderson cred nesciunt sapiente ea proident. Ad vegan excepteur butcher vice lomo. Leggings occaecat craft beer farm-to-table, raw denim aesthetic synth nesciunt you probably haven't heard of them accusamus labore sustainable VHS.
</div>
</div>
</div>
</div> <!-- Settings -->
<!-- Begin Mods -->
<div class="card">
<a class="collapsed nounderline" data-toggle="collapse" data-parent="#accordion" href="#collapseMods" aria-expanded="false" aria-controls="collapseMods">
<div class="card-header" role="tab" id="headingMods">
<h5 class="mb-0">Mods</h5>
</div>
<div class="card-header" role="tab" id="headingMods">
<h5 class="mb-0">Mods</h5>
</div>
</a>
<div id="collapseMods" class="collapse" role="tabpanel" aria-labelledby="headingMods">
<div class="card-block">
Anim pariatur cliche reprehenderit, enim eiusmod high life accusamus terry richardson ad squid. 3 wolf moon officia aute, non cupidatat skateboard dolor brunch. Food truck quinoa nesciunt laborum eiusmod. Brunch 3 wolf moon tempor, sunt aliqua put a bird on it squid single-origin coffee nulla assumenda shoreditch et. Nihil anim keffiyeh helvetica, craft beer labore wes anderson cred nesciunt sapiente ea proident. Ad vegan excepteur butcher vice lomo. Leggings occaecat craft beer farm-to-table, raw denim aesthetic synth nesciunt you probably haven't heard of them accusamus labore sustainable VHS.
</div>
</div>
</div>
</div> <!-- Mods -->
<!-- Backups -->
<div class="card">
<a class="collapsed nounderline" data-toggle="collapse" data-parent="#accordion" href="#collapseBackups" aria-expanded="false" aria-controls="collapseBackups">
<div class="card-header" role="tab" id="headingBackups">
<h5 class="mb-0">Backups</h5>
</div>
<div class="card-header" role="tab" id="headingBackups">
<h5 class="mb-0">Backups</h5>
</div>
</a>
<div id="collapseBackups" class="collapse" role="tabpanel" aria-labelledby="headingBackups">
<div class="card-block">
Anim pariatur cliche reprehenderit, enim eiusmod high life accusamus terry richardson ad squid. 3 wolf moon officia aute, non cupidatat skateboard dolor brunch. Food truck quinoa nesciunt laborum eiusmod. Brunch 3 wolf moon tempor, sunt aliqua put a bird on it squid single-origin coffee nulla assumenda shoreditch et. Nihil anim keffiyeh helvetica, craft beer labore wes anderson cred nesciunt sapiente ea proident. Ad vegan excepteur butcher vice lomo. Leggings occaecat craft beer farm-to-table, raw denim aesthetic synth nesciunt you probably haven't heard of them accusamus labore sustainable VHS.
</div>
</div>
</div>
</div>
</div> <!-- Backups -->
</div> <!-- Accotrdion -->
</div> <!-- Page content -->
%include('footer.tpl', username=username)
%include('footer.tpl', username=username, app_name=app_name)

6
views/footer.tpl

@ -1,3 +1,5 @@
</div> <!-- Page content -->
<footer class="footer">
<div class="container">
<div class="text-muted">
@ -6,9 +8,7 @@
</div>
</footer>
<!-- Bootstrap core JavaScript
================================================== -->
<!-- Placed at the end of the document so the pages load faster -->
<!-- Bootstrap core JavaScript -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
<script>window.jQuery || document.write('<script src="/static/js/vendor/jquery.min.js"><\/script>')</script>
<script src="/static/js/bootstrap.min.js"></script>

23
views/header.tpl

@ -18,6 +18,7 @@
<link href="/static/css/sticky-footer.css" rel="stylesheet">
</head>
<body>
<!-- Begin alert message -->
<div class="container">
<p>
@ -29,3 +30,25 @@
%end
</p>
</div> <!-- alert message -->
<!-- Begin page content -->
<div class="container">
<div class="row">
<div class="col-sm-8">
<h1>{{ page_name }}</h1>
</div>
<div class="col-sm-4 text-xs-right">
<div class="btn-group">
<button type="button" class="btn btn-outline-primary dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
{{ username }}
</button>
<div class="dropdown-menu">
<a class="dropdown-item" href="/">Server overview</a>
<a class="dropdown-item" href="/create">Create server</a>
<div class="dropdown-divider"></div>
<a class="dropdown-item" href="/logout">Logout</a>
</div>
</div>
</div>
</div>
<p class="lead">Control your <a href="http://factorio.com">Factorio</a> game servers from here.</p>

11
views/login.tpl

@ -8,17 +8,15 @@
<meta name="description" content="">
<meta name="author" content="">
<link rel="icon" href="/static/favicon.ico">
<title>{{ app_name }}</title>
<!-- Bootstrap core CSS -->
<link href="/static/css/bootstrap.min.css" rel="stylesheet">
<!-- Custom styles for this template -->
<link href="/static/css/signin.css" rel="stylesheet">
</head>
<body>
<!-- Begin alert message -->
<div class="container">
<p>
@ -30,6 +28,7 @@
%end
</p>
</div> <!-- alert message -->
<!-- Begin page content -->
<div class="container">
<form class="form-signin" action="/login" method="post">
@ -43,9 +42,7 @@
</form>
</div> <!-- Page content -->
<!-- Bootstrap core JavaScript
================================================== -->
<!-- Placed at the end of the document so the pages load faster -->
<!-- Bootstrap core JavaScript -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
<script>window.jQuery || document.write('<script src="/static/js/vendor/jquery.min.js"><\/script>')</script>
<script src="/static/js/bootstrap.min.js"></script>