Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Link dropdown menu to values in database. #14

Merged
merged 1 commit into from
Oct 3, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion ecsopendata/database.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,3 @@ def init_db():
# import all modules here that might define models so that
# they will be registered properly on the metadata. Otherwise
# you will have to import them first before calling init_db()

30 changes: 20 additions & 10 deletions ecsopendata/server.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from flask import Flask, render_template, url_for, redirect, request, abort
from flask import Flask, render_template, url_for, redirect, request, abort, jsonify
from flask_security import Security, login_required, \
SQLAlchemySessionUserDatastore, current_user
import flask_admin
Expand Down Expand Up @@ -38,15 +38,7 @@ def create_user():
if not user_datastore.get_user('user'):
user_datastore.create_user(email='user', password='password')
db_session.commit()
#def create_user():
# init_db()
# if not user_datastore.get_user('admin'):
# print("creating new 'admin' user with password 'password'")
# admin_user = user_datastore.create_user(email='admin', password='password')
## user_datastore.add_role_to_user(user=admin_user, role='admin')
## if not user_datastore.get_user('user'):
## user_datastore.create_user(email='user', password='password')
## db_session.commit()


# Views
@app.route('/')
Expand All @@ -55,6 +47,24 @@ def home():
return render_template('index.html')


@app.route('/fetchExperiment', methods=['GET'])
def fetchTypes():
"""
Stand in for now.
Eventually will retun the unique experiment types from the MasterTable

"""
experiments = User.query.all()

exp_types = []
for experiment in experiments:
if experiment.password not in exp_types:
exp_types.append(experiment.password)

print(exp_types)
return jsonify(exp_types=exp_types)


# Create admin
admin = flask_admin.Admin(
app,
Expand Down
32 changes: 21 additions & 11 deletions ecsopendata/static/templates/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
<link rel="stylesheet" href="static/css/master.css">

</head>
<body>
<body bgcolor="#FF69B4">
<header>
<nav class="navbar navbar-expand-md navbar-dark fixed-top bg-dark">
<a class="navbar-brand" href="">ECS OpenData</a>
Expand Down Expand Up @@ -62,11 +62,7 @@
<div class="row" id="first-row">
<div class="col" id="filters">
<h2>Filters</h2>
<select class="custom-select">
<option selected>Open this select menu</option>
<option value="1">One</option>
<option value="2">Two</option>
<option value="3">Three</option>
<select class="custom-select" id="select-experiment-type">
</select>
</div>
<div class="col" id="visualization">
Expand All @@ -76,7 +72,7 @@ <h2>Visualization</h2>
</div>
<div class="row" id="table-row">
<div class="col">
<table id="table_id" class="display">
<table id="table_id" class="display hover">
<thead>
<tr>
<th>Column 1</th>
Expand All @@ -98,17 +94,31 @@ <h2>Visualization</h2>
</div>
</div>

<script src="https://code.jquery.com/jquery-3.2.1.slim.min.js" integrity="sha384-KJ3o2DKtIkvYIK3UENzmM7KCkRr/rE9/Qpg6aAZGJwFDMVNA/GpGFF93hXpG5KkN" crossorigin="anonymous"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.3/umd/popper.min.js" integrity="sha384-vFJXuSJphROIrBnz7yo7oB41mKfc8JzQZiCq4NCceLEaO4IHwicKwpJf9c9IpFgh" crossorigin="anonymous"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta.2/js/bootstrap.min.js" integrity="sha384-alpBpkh1PFOepccYVYDB4do5UnbKysX5WZXm3XxPqe5iKTfUKjNkCk9SaVuEZflJ" crossorigin="anonymous"></script>

<!-- DataTables -->
<script src="https://cdn.datatables.net/1.10.18/js/jquery.dataTables.min.js"></script>
<script src="https://cdn.datatables.net/1.10.18/js/dataTables.bootstrap4.min.js"></script>
<script type="text/javascript">
$(document).ready( function () {
$('#table_id').DataTable();
} );
$(document).ready( function () {
$('#table_id').DataTable();
} );
</script>

<!-- Fetch data -->
<script type="text/javascript">
$.getJSON( "/fetchExperiment", function( data ) {
console.log(data);
$.each(data['exp_types'], function( key, val ) {
console.log(key)
$('#select-experiment-type')
.append($("<option></option>")
.attr("value", key)
.text(val));
});
});
</script>
</body>
</html>