Skip to content

Commit

Permalink
finished select value
Browse files Browse the repository at this point in the history
  • Loading branch information
sqrd-max committed Nov 29, 2023
1 parent 5761d84 commit b952083
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 42 deletions.
4 changes: 2 additions & 2 deletions python/rcdb/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,10 +119,10 @@ class RunPeriod(ModelBase):
id = Column(Integer, primary_key=True)
name = Column(String(255), nullable=False)
description = Column(String(255), nullable=True)
start_date = Column(Date, nullable=True)
end_date = Column(Date, nullable=True)
run_min = Column(Integer, nullable=False)
run_max = Column(Integer, nullable=False)
start_date = Column(Date, nullable=True)
end_date = Column(Date, nullable=True)

def __repr__(self):
return "<RunRange name='{0}' range=[{1}-{2}]>".format(self.name, self.run_min, self.run_max)
Expand Down
22 changes: 12 additions & 10 deletions rcdb_web/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from rcdb.alias import get_default_aliases_by_name
from rcdb.model import Run
from rcdb.model import Run, RunPeriod
from flask import Flask, render_template, g, request, url_for
import rcdb
from datetime import datetime
Expand Down Expand Up @@ -46,22 +46,26 @@ def not_found(error):

@app.route('/sample')
def sample():

return render_template('index.html')


@app.route('/run_periods')
def run_periods():
run_periods = g.tdb.session.query(RunPeriod).all()


@app.route('/')
def index():

# Select the last 50 runs and
runs = g.tdb.session\
.query(Run)\
.order_by(Run.number.desc())\
.options(subqueryload(Run.conditions))\
runs = g.tdb.session \
.query(Run) \
.order_by(Run.number.desc()) \
.options(subqueryload(Run.conditions)) \
.limit(50)
condition_types = g.tdb.get_condition_types()

return render_template("index.html", runs=runs, DefaultConditions=rcdb.DefaultConditions, condition_types=condition_types)
return render_template("index.html", runs=runs, DefaultConditions=rcdb.DefaultConditions,
condition_types=condition_types)


@app.template_filter('remove_dot_conf')
Expand All @@ -82,8 +86,6 @@ def url_for_other_page(page):
app.jinja_env.globals['url_for_other_page'] = url_for_other_page
app.jinja_env.globals['rcdb_default_alias'] = rcdb.alias.default_aliases



app.register_blueprint(runs_module)
app.register_blueprint(logs_module)
app.register_blueprint(files_module)
Expand Down
11 changes: 7 additions & 4 deletions rcdb_web/select_values/veiws.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
# from werkzeug import check_password_hash, generate_password_hash
import rcdb
from collections import defaultdict
from rcdb.model import Run, Condition, ConditionType
from rcdb.model import Run, Condition, ConditionType, RunPeriod
from sqlalchemy.orm import subqueryload

from rcdb.provider import RCDBProvider
Expand All @@ -18,15 +18,17 @@
@mod.route('/')
def index():
all_conditions = g.tdb.session.query(ConditionType).order_by(ConditionType.name.asc()).all()
run_periods = g.tdb.session.query(RunPeriod).all()
run_from_str = request.args.get('runFrom', '')
run_to_str = request.args.get('runTo', '')
search_query = request.args.get('q', '')
req_conditions_str = request.args.get('cnd', '')

print("search" + search_query)
print(run_periods)

return render_template("select_values/index.html",
all_conditions=all_conditions,
run_periods=run_periods,
run_from_str=run_from_str,
run_to_str=run_to_str,
search_query=search_query,
Expand All @@ -36,6 +38,7 @@ def index():
@mod.route('/search', methods=['GET'])
def search():
all_conditions = g.tdb.session.query(ConditionType).order_by(ConditionType.name.asc()).all()
run_periods = g.tdb.session.query(RunPeriod).all()
run_range = request.args.get('rr', '')
search_query = request.args.get('q', '')
req_conditions_str = request.args.get('cnd', '')
Expand All @@ -52,15 +55,15 @@ def search():
try:
table = g.tdb.select_values(val_names=req_conditions_values, search_str=search_query, run_min=run_from,
run_max=run_to, sort_desc=True)
print(req_conditions_values, run_from, run_to)
except Exception as err:
flash("Error in performing request: {}".format(err), 'danger')
return redirect(url_for('select_values.index'))

print(search_query)


return render_template("select_values/index.html",
all_conditions=all_conditions,
run_periods=run_periods,
run_range=run_range,
run_from=run_from,
run_to=run_to,
Expand Down
43 changes: 19 additions & 24 deletions rcdb_web/templates/run_search_box.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{% macro run_search_box(condition_types=[], run_from=-1, run_to=-1, search_query="", form_url=url_for("runs.search"), req_conditions_str="", show_req_conditions=False) %}
{% macro run_search_box(condition_types=[], run_periods=[], run_from=-1, run_to=-1, search_query="", form_url=url_for("runs.search"), req_conditions_str="", show_req_conditions=False) %}
{% set run_from_str = "" if run_from == -1 else run_from %}
{% set run_to_str = "" if run_to == -1 else run_to %}

Expand All @@ -18,15 +18,9 @@
<ul class="dropdown-menu">
<li><p class="text-center"><strong>Run periods:</strong></p></li>
<li class="divider"></li>
<li><a class="rr-min-selector" data-run-min="70000" data-run-max="79999" href="#">[70000+] 2019-01 2020</a></li>
<li><a class="rr-min-selector" data-run-min="60000" data-run-max="69999" href="#">[60000+] 2019-01 2019-04 – DIRC-com/PrimEx</a></li>
<li><a class="rr-min-selector" data-run-min="50000" data-run-max="59999" href="#">[50000+] 2018-08 2018-11 – 78B GlueX-I/PrimEx-Com</a></li>
<li><a class="rr-min-selector" data-run-min="40000" data-run-max="49999" href="#">[40000+] 2018-01 2018-05 – 145B</a></li>
<li><a class="rr-min-selector" data-run-min="30000" data-run-max="39999" href="#">[30000+] 2017-01 2017-04 – 50B 12 GeV e-</a></li>
<li><a class="rr-min-selector" data-run-min="20000" data-run-max="29999" href="#">[20000+] 2016-10 2016-12 – 7B 12 GeV e-</a></li>
<li><a class="rr-min-selector" data-run-min="10000" data-run-max="19999" href="#">[10000+] 2016-02</a></li>
<li><a class="rr-min-selector" data-run-min="3939" data-run-max="9999" href="#">[3939, 10000) 2015-12</a></li>
<li><a class="rr-min-selector" data-run-min="3607" data-run-max="3939" href="#">[3607, 3939]2015-06</a></li>
{% for period in run_periods %}
<li><a class="rr-min-selector" data-run-min="{{ period.run_min }}" data-run-max="{{ period.run_max }}" href="#">{{ period.description }}</a></li>
{% endfor %}
</ul>
</div>
</div>
Expand All @@ -40,21 +34,25 @@
<ul class="dropdown-menu">
<li><p class="text-center"><strong>Run periods:</strong></p></li>
<li class="divider"></li>
<li><a class="rr-min-selector" data-run-min="70000" data-run-max="79999" href="#">[70000+] 2019-01 2020</a></li>
<li><a class="rr-min-selector" data-run-min="60000" data-run-max="69999" href="#">[60000+] 2019-01 2019-04 – DIRC-com/PrimEx</a></li>
<li><a class="rr-min-selector" data-run-min="50000" data-run-max="59999" href="#">[50000+] 2018-08 2018-11 – 78B GlueX-I/PrimEx-Com</a></li>
<li><a class="rr-min-selector" data-run-min="40000" data-run-max="49999" href="#">[40000+] 2018-01 2018-05 – 145B</a></li>
<li><a class="rr-min-selector" data-run-min="30000" data-run-max="39999" href="#">[30000+] 2017-01 2017-04 – 50B 12 GeV e-</a></li>
<li><a class="rr-min-selector" data-run-min="20000" data-run-max="29999" href="#">[20000+] 2016-10 2016-12 – 7B 12 GeV e-</a></li>
<li><a class="rr-min-selector" data-run-min="10000" data-run-max="19999" href="#">[10000+] 2016-02</a></li>
<li><a class="rr-min-selector" data-run-min="3939" data-run-max="9999" href="#">[3939, 10000) 2015-12</a></li>
<li><a class="rr-min-selector" data-run-min="3607" data-run-max="3939" href="#">[3607, 3939]2015-06</a></li>
{% for period in run_periods %}
<li><a class="rr-min-selector" data-run-min="{{ period.run_min }}" data-run-max="{{ period.run_max }}" href="#">{{ period.name + " " + period.description }}</a></li>
{% endfor %}
</ul>
</div>
</div>
</div>
</div>
</div>
{# Primex, GluexI, Gluex-II, CLASS-12, CSR,#}
{# <li><a class="rr-min-selector" data-run-min="70000" data-run-max="79999" href="#">[70000+] 2019-01 2020</a></li>#}
{# <li><a class="rr-min-selector" data-run-min="60000" data-run-max="69999" href="#">[60000+] 2019-01 2019-04 – DIRC-com/PrimEx</a></li>#}
{# <li><a class="rr-min-selector" data-run-min="50000" data-run-max="59999" href="#">[50000+] 2018-08 2018-11 – 78B GlueX-I/PrimEx-Com</a></li>#}
{# <li><a class="rr-min-selector" data-run-min="40000" data-run-max="49999" href="#">[40000+] 2018-01 2018-05 – 145B</a></li>#}
{# <li><a class="rr-min-selector" data-run-min="30000" data-run-max="39999" href="#">[30000+] 2017-01 2017-04 – 50B 12 GeV e-</a></li>#}
{# <li><a class="rr-min-selector" data-run-min="20000" data-run-max="29999" href="#">[20000+] 2016-10 2016-12 – 7B 12 GeV e-</a></li>#}
{# <li><a class="rr-min-selector" data-run-min="10000" data-run-max="19999" href="#">[10000+] 2016-02</a></li>#}
{# <li><a class="rr-min-selector" data-run-min="3939" data-run-max="9999" href="#">[3939, 10000) 2015-12</a></li>#}
{# <li><a class="rr-min-selector" data-run-min="3607" data-run-max="3939" href="#">[3607, 3939]2015-06</a></li>#}
<div class="col-sm-9">
<label class="small" for="queryInput">Search query</label>
<div class="input-group ">
Expand Down Expand Up @@ -93,7 +91,6 @@
</div>
</form>
</div>

<!-- Modal -->
<div class="modal fade " id="slectConditionTypeModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
<div class="modal-dialog" role="document">
Expand Down Expand Up @@ -225,10 +222,8 @@ <h4 class="modal-title" id="myModalLabel">Select conditions</h4>
}
});

let myForm = document.getElementById("main_form");
console.log(myForm);

myForm.addEventListener('submit', handleFormSubmission);
let mainForm = document.getElementById("main_form");
mainForm.addEventListener('submit', handleFormSubmission);
});

const toggleButton = document.getElementById('toggleButton');
Expand Down
4 changes: 2 additions & 2 deletions rcdb_web/templates/select_values/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

{% block container %}

{{ search_box.run_search_box(condition_types=all_conditions, run_from=run_from, run_to=run_to, search_query=search_query, req_conditions_str=req_conditions_str, form_url=url_for("select_values.search"), show_req_conditions=True) }}
{{ search_box.run_search_box(condition_types=all_conditions, run_periods=run_periods, run_from=run_from, run_to=run_to, search_query=search_query, req_conditions_str=req_conditions_str, form_url=url_for("select_values.search"), show_req_conditions=True) }}

<div class="container">

Expand Down Expand Up @@ -116,5 +116,5 @@


</script>
{{ search_box.run_search_box_scripts(condition_types) }}
{{ search_box.run_search_box_scripts(condition_types, run_periods) }}
{% endblock %}

0 comments on commit b952083

Please sign in to comment.