Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/v2-main' into v2-main
Browse files Browse the repository at this point in the history
  • Loading branch information
DraTeots committed Jun 17, 2024
2 parents 9bfd379 + 145e153 commit 40786af
Show file tree
Hide file tree
Showing 12 changed files with 189 additions and 227 deletions.
15 changes: 13 additions & 2 deletions python/ccdb/provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -298,10 +298,21 @@ def create_directory(self, new_dir_name, parent_dir_or_path, comment=""):
return directory

def get_directory_by_id(self, dir_id):
return self.session.query(Directory).filter(Directory.id == dir_id).one()
self._ensure_dirs_loaded()
return self.dirs_by_id[dir_id]

def get_type_table_by_id(self, table_id):
return self.session.query(TypeTable).filter(TypeTable.id == table_id).one()
type_table = self.session.query(TypeTable).filter(TypeTable.id == table_id).one()
assert isinstance(type_table, TypeTable)

# We set parent_dir here manually because we want to ensure that
# the directory comes after self._ensure_dirs_loaded() is called
# this is important to have all directories correct full paths to be set
# and consequently to have correct full path set for the table!!!!!!
parent_dir = self.get_directory_by_id(type_table.parent_dir_id)
type_table.parent_dir = parent_dir

return parent_dir

# @brief Updates directory
#
Expand Down
60 changes: 31 additions & 29 deletions python/ccdb/webgui/__init__.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import ccdb
from ccdb.model import User
from ccdb.model import User, TypeTable
from ccdb.path_utils import parse_request, ParseRequestResult
from flask import Flask, g, render_template, url_for, jsonify

from python.ccdb.errors import ObjectIsNotFoundInDbError
from ccdb.model import Directory
from ccdb.errors import ObjectIsNotFoundInDbError


def print_app_functions(app):
Expand All @@ -25,18 +26,24 @@ def dir_to_ul(directory, level=0):
:rtype; str
"""

opened_class = 'bi-folder2-open'
closed_class = 'bi-folder'
file_class = 'bi-table'

if not len(directory.sub_dirs) and not len(directory.type_tables):
return "<ul></ul>"

result = '<ul>\n'
for sub_dir in directory.sub_dirs:
result += f'<li><span>{sub_dir.name}</span> <button onclick="showDirInfo({sub_dir.id})">&#128712;</button>'
assert isinstance(sub_dir, Directory)
result += f'<li data="{sub_dir.path}" class="directory"><i class="indicator bi {closed_class}"></i><span class="clickable">{sub_dir.name}</span><button onclick="showDirInfo({sub_dir.id})">&#128712;</button>'
result += dir_to_ul(sub_dir, level + 1)
result += '</li>\n'

for table in directory.type_tables:
assert isinstance(table, TypeTable)
table_url = url_for('versions', table_path=table.path)
result += f'<li><a href="{table_url}">{table.name}</a> <button onclick="showTableInfo({table.id})">&#128712;</button></li>\n'
result += f'<li data="{table.path}"><i class="indicator bi {file_class}"></i><a class="clickable" href="{table_url}">{table.name}</a> <button onclick="showTableInfo({table.id})">&#128712;</button></li>\n'

result += '</ul>\n'
return result
Expand All @@ -47,7 +54,7 @@ def cerate_ccdb_flask_app(test_config=None):
app = Flask(__name__, instance_relative_config=True)
app.config.from_mapping(
# a default secret that should be overridden by instance config
SQL_CONNECTION_STRING="mysql://ccdb_user@localhost/ccdb"
SQL_CONNECTION_STRING="mysql://ccdb_user@hallddb.jlab.org/ccdb2"
)

@app.before_request
Expand Down Expand Up @@ -79,21 +86,18 @@ def directories():
db.get_root_directory()

# Render a template with the directories
return render_template("simple_direcotires.html", dirs_by_path=db.dirs_by_path)
return render_template("direcotires.html", dirs_by_path=db.dirs_by_path)

@app.route('/')
def index():
return render_template(
"dash_base.html",
app_name="Material Dashboard with Bokeh embedded in Flask",
app_description="This Dashboard is served by a Bokeh server embedded in Flask.",
app_icon="timeline"
)

@app.route('/doc')
def documentation():
return render_template("doc.html")
# @app.route('/')
# def index():
# return render_template(
# "dash_base.html",
# app_name="Material Dashboard with Bokeh embedded in Flask",
# app_description="This Dashboard is served by a Bokeh server embedded in Flask.",
# app_icon="timeline"
# )

@app.route('/')
@app.route('/tree')
def directory_tree():
# Get ccdb Alchemy provider from flask global state 'g'
Expand All @@ -105,28 +109,26 @@ def directory_tree():
# Generate html code of directory tree
html_tree = dir_to_ul(root_dir, level=0)

return render_template("simple_tree.html", html_tree=html_tree)
return render_template("directory_tree.html", html_tree=html_tree, dirs_by_path=db.dirs_by_path)

@app.route('/get-dir-info/<int:dir_id>')
def get_dir_info(dir_id):
db: ccdb.AlchemyProvider = g.db
db._ensure_dirs_loaded()
directory = db.get_directory_by_id(dir_id)
if not directory:
return jsonify({"error": "Directory not found"}), 404
return render_template('objects_dir_info.html', directory=directory)



@app.route('/get-table-info/<int:table_id>')
def get_table_info(table_id):
db: ccdb.AlchemyProvider = g.db
db._ensure_dirs_loaded()
table = db.get_type_table_by_id(table_id)
if not table:
return jsonify({"error": "Table not found"}), 404
return render_template('objects_table_info.html', table=table)



@app.route('/vars')
def variations():
# Get ccdb Alchemy provider from flask global state 'g'
Expand All @@ -143,7 +145,11 @@ def log_records():

records = db.get_log_records(1000)

return render_template("simple_logs.html", records=records)
return render_template("logs.html", records=records)

@app.route('/doc')
def documentation():
return render_template("doc.html")

@app.route('/versions/<path:table_path>')
def versions(table_path):
Expand All @@ -162,7 +168,7 @@ def versions(table_path):
except ccdb.errors.ObjectIsNotFoundInDbError as e:
return render_template("error.html", message=str(e), table_path=table_path), 404

return render_template("simple_versions.html", assignments=assignments, table_path=table_path)
return render_template("versions.html", assignments=assignments, table_path=table_path)

@app.route('/test_request')
def test_request():
Expand Down Expand Up @@ -197,10 +203,6 @@ def show_request():
run_range = ""
comment = ""

# get request from web form

#str_request = "/test/test_vars/test_table:0:default:2012-10-30_23-48-41"

# parse request and prepare time
request = parse_request(str_request)
assert isinstance(request, ParseRequestResult)
Expand Down
58 changes: 32 additions & 26 deletions python/ccdb/webgui/templates/dash_base.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<!doctype html>
<html lang="en">
<head>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<meta name="description" content="">
Expand All @@ -9,29 +9,40 @@

<title>CCDB Dashboard</title>

<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-QWTKZyjpPEjISv5WaRU9OFeRpok6YctnYmDr5pNlyT2bRjXh0JMhjY6hW+ALEwIH" crossorigin="anonymous">
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet">
<link href="https://cdn.jsdelivr.net/npm/bootstrap-icons/font/bootstrap-icons.css" rel="stylesheet">
<!-- Bootstrap core CSS -->
<link href="{{ url_for('static', filename='css/bootstrap.min.css') }}" rel="stylesheet">

<!-- Custom styles for this template -->
<link href="{{ url_for('static', filename='css/dashboard.css') }}" rel="stylesheet">
</head>
<style>
.navbar {
z-index: 1060;
width: 100%;

}
.navbar-brand {
padding-left: 2rem;
width: 19rem;

}
.sidebar {
z-index: 1040;
width: 19rem;
}

<body class="d-flex flex-column min-vh-100">
<nav class="navbar navbar-dark sticky-top bg-dark flex-md-nowrap p-0">
<a class="navbar-brand col-sm-3 col-md-2 mr-0" href="{{ url_for('directory_tree') }}">CCDB v 2.0</a>
<input class="form-control form-control-dark w-100" type="text" placeholder="Search" aria-label="Search">
<ul class="navbar-nav px-3">
<li class="nav-item text-nowrap">
<a class="nav-link" href="#">test_ccdb</a>
</li>
</ul>
</style>
</head>
<body class="d-flex flex-column min-vh-100">
<nav class="navbar navbar-dark sticky-top bg-dark flex-md-nowrap p-0 align-items-center">
<a class="navbar-brand ms-0" href="{{ url_for('directory_tree') }}">CCDB v 2.0</a>
<button id="toggleSidebarButton" class="btn btn-primary d-md-none ms-auto" type="button" data-bs-toggle="collapse" data-bs-target="#sidebarMenu" aria-controls="sidebarMenu" aria-expanded="false" aria-label="Toggle navigation" style="position: relative;">
<i class="bi bi-list"></i>
</button>
</nav>


<div class="container-fluid flex-grow-1">
<div class="row">
<nav class="col-md-2 d-none d-md-block bg-light sidebar">
<nav class="col-md-2 d-md-block bg-light sidebar collapse" id="sidebarMenu">
<div class="sidebar-sticky">
<ul class="nav flex-column">
<li class="nav-item">
Expand Down Expand Up @@ -68,7 +79,7 @@
</div>
</nav>

<section class="container mt-4">
<section class="col-md-10 mt-4 content-section" style="margin-left:auto;">
<header>
{% block header %}{% endblock %}
</header>
Expand All @@ -81,21 +92,16 @@
</div>
</div>

<footer class="footer mt-auto py-3 bg-light">
<footer class="footer mt-auto py-3 bg-light">
<div class="container">
<span class="text-muted">CCDB Calibration and Conditions database. <a href="https://halldweb1.jlab.org/mantisbt/bug_report_page.php">Report a bug</a></span>
</div>
</footer>


<!-- Bootstrap core JavaScript
================================================== -->
<!-- Placed at the end of the document so the pages load faster -->
<!-- Icons -->
<script src="https://unpkg.com/feather-icons/dist/feather.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"></script>
<script>
feather.replace()
feather.replace();
</script>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"></script>
</body>
</body>
</html>
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,10 @@
margin-bottom: 10px;
}

.clickable {
cursor: pointer;
}

</style>

<h1 class="text-center my-4">{% block title %}Tables{% endblock %}</h1>
Expand Down Expand Up @@ -164,37 +168,49 @@ <h1 class="text-center my-4">{% block title %}Tables{% endblock %}</h1>

$('#infoModal').on('shown.bs.modal', adjustModal);

$('#tree2').treed({
openedClass: 'bi-folder2-open',
closedClass: 'bi-folder',
fileClass: 'bi-table'
});
$('#tree2').treed();

});

$.fn.extend({
treed: function (o) {
var openedClass = o.openedClass;
var closedClass = o.closedClass;
var fileClass = o.fileClass;
const openedClass = 'bi-folder2-open';
const closedClass = 'bi-folder';
const fileClass ='bi-table';

let tree = $(this);

var tree = $(this);
tree.addClass("tree");
tree.find('li').has("ul").each(function () {
tree.find('.directory').each(function () {
var branch = $(this);
branch.prepend("<i class='indicator bi " + closedClass + "'></i>");
branch.addClass('branch');
let branchElement = this;
let fullPath = branchElement.getAttribute("data");
let localStorageKey = `branch-${fullPath}`;

branch.on('click', function (e) {
if (!$(e.target).is('a') && !$(e.target).is('button') && !$(e.target).closest('button').length) {
var icon = $(this).children('i:first');

icon.toggleClass(openedClass + " " + closedClass);
$(this).children().children().toggle();
e.stopPropagation();



if (icon.hasClass(openedClass)) {
localStorage.setItem(localStorageKey , 'open');
} else {
localStorage.removeItem(localStorageKey);
}
}
});

branch.children().children().toggle();
if (localStorage.getItem(localStorageKey) === 'open') {
// console.log(directory);
branch.children('.indicator').click();
}
});

tree.find('li:not(:has(ul))').prepend("<i class='indicator bi " + fileClass + "'></i>");

tree.find('.indicator').on('click', function (e) {
$(this).closest('li').click();
Expand Down
26 changes: 20 additions & 6 deletions python/ccdb/webgui/templates/doc.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,27 @@ <h1 class="mt-4 mb-4 text-center" style="font-size: 2.5rem;">Information</h1>

{% block content %}
<div class="container mt-5">
<div class="card">
<div class="card-body" style="font-size: 1.25rem;">
<p>
<a target="_blank" href="https://halldweb1.jlab.org/wiki/index.php/Calibration_Database"
class="btn btn-primary text-white" style="text-decoration: none;">
Visit the Calibration Database GluEX Wiki Page
</a>
</p>

<!-- GitHub Link -->
<div class="row">
<h4 class="col-auto">GitHub Repository</h4>-
<p class="col-auto"><a href="https://github.com/JeffersonLab/ccdb" target="_blank">Jefferson Lab CCDB GitHub repository</a>.</p>
</div>

<!-- GitHub Issues Link -->
<div class="row">
<h4 class="col-auto">Support & Issues</h4>-
<p class="col-auto"><a href="https://github.com/JeffersonLab/ccdb/issues" target="_blank">GitHub Issues page</a>.</p>
</div>

<!-- Wiki Link -->
<div class="row">
<h4 class="col-auto">Documentation & Resources</h4>-
<p class="col-auto"><a href="https://halldweb1.jlab.org/wiki/index.php/Calibration_Database" target="_blank">Calibration Database GluEX Wiki Page</a>.</p>
</div>
</div>
</div>
</div>
{% endblock %}
File renamed without changes.
20 changes: 0 additions & 20 deletions python/ccdb/webgui/templates/simple.html

This file was deleted.

Loading

0 comments on commit 40786af

Please sign in to comment.