Commit 5c990a0c authored by Vladislav Rykov's avatar Vladislav Rykov
Browse files

add dev, dev views added

parent 20405f04
......@@ -10,19 +10,22 @@ import dao.device.device as dd
server = Flask(__name__, template_folder='templates/')
def prep_ids(dev_list):
return "any"
@server.route('/')
def index():
if 'name' in session and len(session['name']) > 0:
ah = ad.ApplicationDao()
apps = ah.get_list(session['name'].encode('utf-8'))
session.pop('appkey', None)
print('apps: ', apps)
if apps[0]:
return render_template('index.html', apps=apps[1])
else:
return render_template('index.html', feedback=apps[1])
return render_template('index.html')
@server.route('/signup', methods=['GET', 'POST'])
......@@ -89,8 +92,16 @@ def app():
ah = ad.ApplicationDao()
if request.method == 'GET':
dh = dd.DeviceDao()
app = ah.get(request.args.get('appkey'))
appkey = None
if 'appkey' in session:
appkey = session['appkey']
else:
appkey = request.args.get('appkey')
session['appkey'] = request.args.get('appkey')
app = ah.get(appkey)
devs = dh.get_list(app[1][1])
print('devs : ', devs)
return render_template('app.html', app=app[1], devs=devs[1])
else:
......@@ -114,6 +125,39 @@ def app():
return redirect(url_for('index'))
@server.route('/add-dev')
def new_dev():
free_ids = 'whatever'
dh = dd.DeviceDao()
dev_list = dh.get_list(session['appkey'])
print('dev list : ', dev_list)
if not dev_list[0]:
return render_template('add-dev.html', feedback=dev_list[1])
else:
return render_template('add-dev.html', free_ids=prep_ids(dev_list[1]))
@server.route('/dev', methods=['GET', 'POST'])
def dev():
dh = dd.DeviceDao()
if request.method == 'GET':
dev = dh.get(session['appkey'], request.args.get('dev_id'))
ltup = 'recently'
return render_template('dev.html', dev=dev[1], ltup=ltup)
else:
res = dh.create(request.form['devname'], request.form['devid'], session['appkey'], request.form['devdesc'])
if not res[0]:
return render_template('add-dev.html', feedback=res[1])
else:
return redirect(url_for('app'))
if __name__ == '__main__':
server.secret_key = 'sdjfklsjf^$654sd^#sPH'
server.run(debug = True, host='0.0.0.0')
......
{% extends 'layout.html' %}
{% block title %} Add new device: {% endblock %}
{% block content %}
<div class="row">
<div class="col-md-6 col-md-offset3">
<form action="dev" method="post">
<div class="form-group">
<label>Name:</label><br>
<input type="text" id="devname" name="devname"><br>
</div>
<div class="form-group">
<label>Description:</label><br>
<textarea id="devdesc" name="devdesc" cols="40" rows="5"></textarea>
</div>
<div class="form-group">
<label>dev_id: {{ free_ids }}</label><br>
<input type="text" id="devid" name="devid"><br>
</div>
<div class="form-group">
<button type="submit" class="btn btn-primary">Add</button>
</div>
{% if feedback %}
<p class="text-danger float-right">{{ feedback }}</p>
{% endif %}
</form>
</div>
</div>
{% endblock %}
......@@ -14,14 +14,14 @@
{% if devs %}
<ol>
{% for dev in devs %}
<li><a href="/device?app_key={{ app[1] }}&dev={{ dev[1] }}"> {{ dev[0] }} </a></li>
<li><a href="/dev?dev_id={{ dev[1] }}"> {{ dev[0] }} </a></li>
{% endfor %}
</ol>
{% else %}
<p> No registed devices </p>
{% endif %}
<a href="/add-device"><button type="submit" class="btn btn-primary">Add Device</button></a>
<a href="/add-dev"><button type="submit" class="btn btn-primary">Add Device</button></a>
<a href="/delete-app"><button type="submit" class="btn btn-danger" onclick="return conf();">Delete Application</button></a>
</div>
</div>
......
{% extends 'layout.html' %}
{% block title %} Device: {% endblock %}
{% block content %}
<div class="row">
<div class="col-md-6 col-md-offset-3">
<p>Name: {{ dev[0] }} </p>
<p>dev_id: {{ dev[1] }} </p>
<p>app-key: {{ dev[2] }} </p>
<p>Description : {{ dev[3] }} </p>
<p>Last time up : {{ ltup }} </p>
<a href="/data"><button type="submit" class="btn btn-primary">Data</button></a>
<a href="/dev-conf"><button type="submit" class="btn btn-primary">Configure</button></a>
<a href="/delete-dev"><button type="submit" class="btn btn-danger" onclick="return conf();">Delete Device</button></a>
</div>
</div>
<script type="text/javascrypt">
function conf() {
return confirm("Are you sure? It will remove all device data.")
}
</script>
{% endblock %}
......@@ -21,7 +21,7 @@
</div>
<div id="navbar" class="collapse navbar-collapse">
<ul class="nav navbar-nav">
<li><a href="/index">Home</a></li>
<li><a href="/">Home</a></li>
{% if session['name'] %}
<li><a href="/logout">Logout</a></li>
{% else %}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment