From c6b059604f5ff93784dc7c1991eb3547ee0cb449 Mon Sep 17 00:00:00 2001 From: "sqrd.max" Date: Fri, 10 May 2024 00:52:35 +0300 Subject: [PATCH 1/4] last changes have been made autocomplite and localstorage for directory tree works with bugs --- python/ccdb/webgui/__init__.py | 45 +++---- ...mple_direcotires.html => direcotires.html} | 0 .../{simple_tree.html => directory_tree.html} | 19 ++- python/ccdb/webgui/templates/doc.html | 26 +++- .../templates/{simple_logs.html => logs.html} | 0 python/ccdb/webgui/templates/simple.html | 20 --- python/ccdb/webgui/templates/simple_base.html | 69 ---------- .../ccdb/webgui/templates/test_request.html | 123 +++++++++--------- python/ccdb/webgui/templates/variations.html | 1 + .../{simple_versions.html => versions.html} | 0 10 files changed, 120 insertions(+), 183 deletions(-) rename python/ccdb/webgui/templates/{simple_direcotires.html => direcotires.html} (100%) rename python/ccdb/webgui/templates/{simple_tree.html => directory_tree.html} (89%) rename python/ccdb/webgui/templates/{simple_logs.html => logs.html} (100%) delete mode 100644 python/ccdb/webgui/templates/simple.html delete mode 100644 python/ccdb/webgui/templates/simple_base.html rename python/ccdb/webgui/templates/{simple_versions.html => versions.html} (100%) diff --git a/python/ccdb/webgui/__init__.py b/python/ccdb/webgui/__init__.py index ff2798e..2c932de 100644 --- a/python/ccdb/webgui/__init__.py +++ b/python/ccdb/webgui/__init__.py @@ -30,13 +30,13 @@ def dir_to_ul(directory, level=0): result = '\n' return result @@ -79,21 +79,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' @@ -105,7 +102,7 @@ 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/') def get_dir_info(dir_id): @@ -115,8 +112,6 @@ def get_dir_info(dir_id): return jsonify({"error": "Directory not found"}), 404 return render_template('objects_dir_info.html', directory=directory) - - @app.route('/get-table-info/') def get_table_info(table_id): db: ccdb.AlchemyProvider = g.db @@ -125,8 +120,6 @@ def get_table_info(table_id): 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' @@ -143,7 +136,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/') def versions(table_path): @@ -162,7 +159,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(): @@ -197,10 +194,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) diff --git a/python/ccdb/webgui/templates/simple_direcotires.html b/python/ccdb/webgui/templates/direcotires.html similarity index 100% rename from python/ccdb/webgui/templates/simple_direcotires.html rename to python/ccdb/webgui/templates/direcotires.html diff --git a/python/ccdb/webgui/templates/simple_tree.html b/python/ccdb/webgui/templates/directory_tree.html similarity index 89% rename from python/ccdb/webgui/templates/simple_tree.html rename to python/ccdb/webgui/templates/directory_tree.html index d6c6459..a0bede4 100644 --- a/python/ccdb/webgui/templates/simple_tree.html +++ b/python/ccdb/webgui/templates/directory_tree.html @@ -90,6 +90,10 @@ margin-bottom: 10px; } +.clickable { + cursor: pointer; +} +

{% block title %}Tables{% endblock %}

@@ -169,6 +173,13 @@

{% block title %}Tables{% endblock %}

closedClass: 'bi-folder', fileClass: 'bi-table' }); + + $('#tree2').find('.branch').each(function() { + var branch = $(this); + if (localStorage.getItem('branch-' + branch.index()) === 'open') { + branch.children('.indicator').click(); + } + }); }); $.fn.extend({ @@ -181,7 +192,7 @@

{% block title %}Tables{% endblock %}

tree.addClass("tree"); tree.find('li').has("ul").each(function () { var branch = $(this); - branch.prepend(""); + branch.prepend(""); branch.addClass('branch'); branch.on('click', function (e) { if (!$(e.target).is('a') && !$(e.target).is('button') && !$(e.target).closest('button').length) { @@ -189,6 +200,12 @@

{% block title %}Tables{% endblock %}

icon.toggleClass(openedClass + " " + closedClass); $(this).children().children().toggle(); e.stopPropagation(); + + if (icon.hasClass(openedClass)) { + localStorage.setItem('branch-' + $(this).index(), 'open'); + } else { + localStorage.removeItem('branch-' + $(this).index()); + } } }); branch.children().children().toggle(); diff --git a/python/ccdb/webgui/templates/doc.html b/python/ccdb/webgui/templates/doc.html index 3404466..a2251aa 100644 --- a/python/ccdb/webgui/templates/doc.html +++ b/python/ccdb/webgui/templates/doc.html @@ -6,13 +6,27 @@

Information

{% block content %}
+
-

- - Visit the Calibration Database GluEX Wiki Page - -

+ + +
+

GitHub Repository

- +

Jefferson Lab CCDB GitHub repository.

+
+ + +
+

Support & Issues

- +

GitHub Issues page.

+
+ + +
+

Documentation & Resources

- +

Calibration Database GluEX Wiki Page.

+
+
{% endblock %} diff --git a/python/ccdb/webgui/templates/simple_logs.html b/python/ccdb/webgui/templates/logs.html similarity index 100% rename from python/ccdb/webgui/templates/simple_logs.html rename to python/ccdb/webgui/templates/logs.html diff --git a/python/ccdb/webgui/templates/simple.html b/python/ccdb/webgui/templates/simple.html deleted file mode 100644 index 4e1837a..0000000 --- a/python/ccdb/webgui/templates/simple.html +++ /dev/null @@ -1,20 +0,0 @@ -{% extends 'simple_base.html' %} - -{% block header %} -

{% block title %}Data Timeline{% endblock %}

- -{% endblock %} - -{% block content %} - -

CCDB 2.0 GUI development is in progress...

- - - - - -{% endblock %} diff --git a/python/ccdb/webgui/templates/simple_base.html b/python/ccdb/webgui/templates/simple_base.html deleted file mode 100644 index 2a1d8c2..0000000 --- a/python/ccdb/webgui/templates/simple_base.html +++ /dev/null @@ -1,69 +0,0 @@ - - - - - - - {% block title %}CCDB Web GUI{% endblock %} - - - - - - - - - -
-
- {% block header %}{% endblock %} -
- {% for message in get_flashed_messages() %} -
{{ message }}
- {% endfor %} - - {% block content %}{% endblock %} -
- -
-
- {% block footer %}CCDB Calibration and Conditions database. Report a bug{% endblock %} -
-
- - {% block additional_scripts %} - - {% endblock %} - - diff --git a/python/ccdb/webgui/templates/test_request.html b/python/ccdb/webgui/templates/test_request.html index 3619411..ef60c2c 100644 --- a/python/ccdb/webgui/templates/test_request.html +++ b/python/ccdb/webgui/templates/test_request.html @@ -62,71 +62,72 @@

{% block title %}CCDB - Test Request{% endblock %}

- + + + tableNameInput.data("ui-autocomplete")._renderItem = function(ul, item) { + return $("") + .attr("data-value", item.value) + .append(item.label) + .appendTo(ul); + }; +}); + + +function combineRequest(event) +{ + console.log(event); + //type table + let type_table = document.getElementById('tableName').value; + if(!type_table) { + alert("Please specify type table"); + return false; + } + + //run number + let run = document.getElementById('runNumber').value + if(!run){ + alert("Please specify run number"); + return false; + } + //variation + let variation = document.getElementById('variationSelect').value; + + //now we have everything to build request + let request = type_table+":"+run +":"+ variation; + + //is there a date? + let date = document.getElementById('dateText').value; + if(date) request = request + ":" +date; + console.log(request) + + // //insert request value to our hidden input and return true + // console.log(request); + // // $("#requestHidden").val(request); + + let hidden = document.getElementById('requestHidden'); + hidden.setAttribute("value", request); + + return false; +} + + {% endblock %} \ No newline at end of file diff --git a/python/ccdb/webgui/templates/variations.html b/python/ccdb/webgui/templates/variations.html index 0e964db..178f0e5 100644 --- a/python/ccdb/webgui/templates/variations.html +++ b/python/ccdb/webgui/templates/variations.html @@ -39,6 +39,7 @@

{% block title %}Variations{% endblock %}

$('#variationsTable').DataTable({ "pagingType": "full_numbers", "order": [[1, "asc"]], + "pageLength": 100, "dom": "<'row'<'col-sm-12 col-md-6'l><'col-sm-12 col-md-6'f>>" + "<'row'<'col-sm-12'tr>>" + "<'row'<'col-sm-12 col-md-5'i><'col-sm-12 col-md-7'p>>", diff --git a/python/ccdb/webgui/templates/simple_versions.html b/python/ccdb/webgui/templates/versions.html similarity index 100% rename from python/ccdb/webgui/templates/simple_versions.html rename to python/ccdb/webgui/templates/versions.html From 2543c9cd3e967c6535c1405c8532e129f28749fe Mon Sep 17 00:00:00 2001 From: Dmitry Romanov Date: Tue, 28 May 2024 16:09:57 -0400 Subject: [PATCH 2/4] Fixed website directory tree logic --- python/ccdb/webgui/__init__.py | 17 +++++--- .../ccdb/webgui/templates/directory_tree.html | 43 +++++++++---------- 2 files changed, 33 insertions(+), 27 deletions(-) diff --git a/python/ccdb/webgui/__init__.py b/python/ccdb/webgui/__init__.py index 2c932de..85acc1d 100644 --- a/python/ccdb/webgui/__init__.py +++ b/python/ccdb/webgui/__init__.py @@ -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): @@ -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 "
    " result = '
      \n' for sub_dir in directory.sub_dirs: - result += f'
    • {sub_dir.name} ' + assert isinstance(sub_dir, Directory) + result += f'
    • {sub_dir.name}' result += dir_to_ul(sub_dir, level + 1) result += '
    • \n' for table in directory.type_tables: + assert isinstance(table, TypeTable) table_url = url_for('versions', table_path=table.path) - result += f'
    • {table.name}
    • \n' + result += f'
    • {table.name}
    • \n' result += '
    \n' return result @@ -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 diff --git a/python/ccdb/webgui/templates/directory_tree.html b/python/ccdb/webgui/templates/directory_tree.html index a0bede4..3f5d364 100644 --- a/python/ccdb/webgui/templates/directory_tree.html +++ b/python/ccdb/webgui/templates/directory_tree.html @@ -168,50 +168,49 @@

    {% block title %}Tables{% endblock %}

    $('#infoModal').on('shown.bs.modal', adjustModal); - $('#tree2').treed({ - openedClass: 'bi-folder2-open', - closedClass: 'bi-folder', - fileClass: 'bi-table' - }); + $('#tree2').treed(); - $('#tree2').find('.branch').each(function() { - var branch = $(this); - if (localStorage.getItem('branch-' + branch.index()) === 'open') { - branch.children('.indicator').click(); - } - }); }); $.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'; - var tree = $(this); - tree.addClass("tree"); - tree.find('li').has("ul").each(function () { + let tree = $(this); + + tree.find('.directory').each(function () { var branch = $(this); - branch.prepend(""); - 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('branch-' + $(this).index(), 'open'); + localStorage.setItem(localStorageKey , 'open'); } else { - localStorage.removeItem('branch-' + $(this).index()); + 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(""); tree.find('.indicator').on('click', function (e) { $(this).closest('li').click(); From 65ba2210f551a5f491599c82d835c3e7ea6b6a25 Mon Sep 17 00:00:00 2001 From: Dmitry Romanov Date: Tue, 28 May 2024 16:23:46 -0400 Subject: [PATCH 3/4] Fixed full path for directories and type_tables when get by ID --- python/ccdb/provider.py | 15 +++++++++++++-- python/ccdb/webgui/__init__.py | 2 ++ 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/python/ccdb/provider.py b/python/ccdb/provider.py index c170a1f..0f59b2a 100644 --- a/python/ccdb/provider.py +++ b/python/ccdb/provider.py @@ -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 # diff --git a/python/ccdb/webgui/__init__.py b/python/ccdb/webgui/__init__.py index 85acc1d..2201fa5 100644 --- a/python/ccdb/webgui/__init__.py +++ b/python/ccdb/webgui/__init__.py @@ -114,6 +114,7 @@ def directory_tree(): @app.route('/get-dir-info/') 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 @@ -122,6 +123,7 @@ def get_dir_info(dir_id): @app.route('/get-table-info/') 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 From 145e153ede0f7383aefa4e1609c3304c10be36e7 Mon Sep 17 00:00:00 2001 From: "sqrd.max" Date: Thu, 30 May 2024 22:24:49 +0300 Subject: [PATCH 4/4] Fixed site adaptation --- python/ccdb/webgui/templates/dash_base.html | 58 ++++++++++++--------- 1 file changed, 32 insertions(+), 26 deletions(-) diff --git a/python/ccdb/webgui/templates/dash_base.html b/python/ccdb/webgui/templates/dash_base.html index 45497b9..0e978ad 100644 --- a/python/ccdb/webgui/templates/dash_base.html +++ b/python/ccdb/webgui/templates/dash_base.html @@ -1,6 +1,6 @@ - + @@ -9,29 +9,40 @@ CCDB Dashboard - + - - - - + + + + +
    -
    -