Skip to content

Commit 10d734f

Browse files
committed
try to make info tables
1 parent 84b77f4 commit 10d734f

File tree

5 files changed

+125
-30
lines changed

5 files changed

+125
-30
lines changed

python/ccdb/provider.py

+6
Original file line numberDiff line numberDiff line change
@@ -297,6 +297,12 @@ def create_directory(self, new_dir_name, parent_dir_or_path, comment=""):
297297

298298
return directory
299299

300+
def get_directory_by_id(self, dir_id):
301+
return self.session.query(Directory).filter(Directory.id == dir_id).one()
302+
303+
def get_type_table_by_id(self, table_id):
304+
return self.session.query(TypeTable).filter(TypeTable.id == table_id).one()
305+
300306
# @brief Updates directory
301307
#
302308
# @warning in current realization, if operation succeeded

python/ccdb/webgui/__init__.py

+23-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import ccdb
22
from ccdb.model import User
33
from ccdb.path_utils import parse_request, ParseRequestResult
4-
from flask import Flask, g, render_template, url_for
4+
from flask import Flask, g, render_template, url_for, jsonify
55

66
from python.ccdb.errors import ObjectIsNotFoundInDbError
77

@@ -128,6 +128,25 @@ def directory_tree():
128128

129129
return render_template("simple_tree.html", html_tree=html_tree)
130130

131+
@app.route('/get-dir-info/<int:dir_id>')
132+
def get_dir_info(dir_id):
133+
db: ccdb.AlchemyProvider = g.db
134+
try:
135+
directory = db.get_directory_by_id(dir_id)
136+
return render_template('objects_dir_info.html', directory=directory)
137+
except ObjectIsNotFoundInDbError:
138+
return jsonify({"error": "Directory not found"}), 404
139+
140+
141+
@app.route('/get-table-info/<int:table_id>')
142+
def get_table_info(table_id):
143+
db: ccdb.AlchemyProvider = g.db
144+
try:
145+
table = db.get_type_table_by_id(table_id)
146+
return render_template('objects_table_info.html', table=table)
147+
except ObjectIsNotFoundInDbError:
148+
return jsonify({"error": "Table not found"}), 404
149+
131150
@app.route('/vars')
132151
def variations():
133152
# Get ccdb Alchemy provider from flask global state 'g'
@@ -288,6 +307,9 @@ def download_request():
288307

289308
return result
290309

310+
311+
312+
291313
# THIS IS FOR FUTURE
292314
# ====================================================================
293315
# from ccdb.webgui.data_timeline import bp as time_line_bp
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
{% macro modal_directory_info(directory) %}
2+
<div class="modal fade" id="directoryInfoModal" tabindex="-1" aria-labelledby="directoryInfoModalLabel" aria-hidden="true">
3+
<div class="modal-dialog modal-dialog-scrollable modal-lg">
4+
<div class="modal-content">
5+
<div class="modal-header">
6+
<h5 class="modal-title" id="directoryInfoModalLabel">{{ directory.name }}</h5>
7+
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
8+
</div>
9+
<div class="modal-body">
10+
<table class="table">
11+
<tbody>
12+
<tr>
13+
<th scope="row">DB ID</th>
14+
<td>{{ directory.id }}</td>
15+
</tr>
16+
<tr>
17+
<th scope="row">Full path</th>
18+
<td>{{ directory.path }}</td>
19+
</tr>
20+
<tr>
21+
<th scope="row">Created</th>
22+
<td>{{ directory.created.strftime('%Y-%m-%d %H:%M:%S') }}</td>
23+
</tr>
24+
<tr>
25+
<th scope="row">Modified</th>
26+
<td>{{ directory.modified.strftime('%Y-%m-%d %H:%M:%S') }}</td>
27+
</tr>
28+
<tr>
29+
<th scope="row">Author</th>
30+
<td>{{ directory.author_id }}</td>
31+
</tr>
32+
<tr>
33+
<th scope="row">Comment</th>
34+
<td>{{ directory.comment }}</td>
35+
</tr>
36+
</tbody>
37+
</table>
38+
</div>
39+
<div class="modal-footer">
40+
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Close</button>
41+
</div>
42+
</div>
43+
</div>
44+
</div>
45+
{% endmacro %}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
@require(id, name, path, created, modified, author, comment)
2+
3+
<span class="file"><a href="versions?table=@path" class="table_link">@name</a>&nbsp;&nbsp;<a class="tree_link object_more_info" rel="Table @name">?</a></span>
4+
<div style="display: none">
5+
<table>
6+
<tr style="color: gray"><td style="width:auto">DB ID:</td><td style="width: 100%">:&nbsp;&nbsp;&nbsp;@id</td></tr>
7+
<tr><td style="font-weight: bolder">Full path </td><td>:&nbsp;&nbsp;&nbsp; @path</td></tr>
8+
<tr><td>Created </td><td>:&nbsp;&nbsp;&nbsp; @created</td></tr>
9+
<tr><td>Modified </td><td>:&nbsp;&nbsp;&nbsp; @modified</td></tr>
10+
<tr><td>Author </td><td>:&nbsp;&nbsp;&nbsp; @author</td></tr>
11+
<tr><td>Comment </td><td>:&nbsp;&nbsp;&nbsp; @comment</td></tr>
12+
</table>
13+
</div>

python/ccdb/webgui/templates/simple_tree.html

+38-29
Original file line numberDiff line numberDiff line change
@@ -126,44 +126,53 @@ <h1 class="text-center my-4">{% block title %}Tables{% endblock %}</h1>
126126
</div>
127127
</div>
128128

129-
<div class="modal" id="infoModal" style="display:none;">
130-
<div class="modal-content">
131-
<span class="close" onclick="closeModal()">&times;</span>
132-
<div id="modal-body"></div>
129+
<div class="modal fade" id="infoModal" tabindex="-1" role="dialog" aria-labelledby="infoModalLabel" aria-hidden="true">
130+
<div class="modal-dialog" role="document">
131+
<div class="modal-content">
132+
<div class="modal-header">
133+
<h5 class="modal-title" id="infoModalLabel">Information</h5>
134+
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
135+
<span aria-hidden="true">&times;</span>
136+
</button>
133137
</div>
138+
<div class="modal-body" id="modal-body">
139+
140+
</div>
141+
</div>
142+
</div>
134143
</div>
135144

136145

137146
<script type="text/javascript">
138147

139148
$(document).on('click', '.btn-icon', function() {
140-
var button = $(this);
141-
if (button.closest('li').has('a').length > 0) {
142-
var tableId = button.closest('li').find('a').attr('href').split('/')[2]; // Предположим, что URL структурирован таким образом
143-
showTableInfo(tableId);
144-
} else {
145-
var dirId = button.data('dir-id');
146-
showDirInfo(dirId);
147-
}
148-
});
149-
150-
function showDirInfo(dirId) {
151-
fetch(`/get-dir-info/${dirId}`)
152-
.then(response => response.text())
153-
.then(html => {
154-
document.getElementById('modal-body').innerHTML = html;
155-
document.getElementById('infoModal').style.display = 'block';
149+
var button = $(this);
150+
if (button.closest('li').has('ul').length > 0) {
151+
var dirId = button.closest('li').data('dir-id');
152+
showDirInfo(dirId);
153+
} else {
154+
var tableId = button.closest('li').find('a').attr('data-table-id');
155+
showTableInfo(tableId);
156+
}
156157
});
157-
}
158158

159-
function showTableInfo(tableId) {
160-
fetch(`/get-table-info/${tableId}`)
161-
.then(response => response.text())
162-
.then(html => {
163-
document.getElementById('modal-body').innerHTML = html;
164-
document.getElementById('infoModal').style.display = 'block';
165-
});
166-
}
159+
function showDirInfo(dirId) {
160+
fetch(`/get-dir-info/${dirId}`)
161+
.then(response => response.text())
162+
.then(html => {
163+
$('#modal-body').html(html);
164+
$('#infoModal').modal('show');
165+
});
166+
}
167+
168+
function showTableInfo(tableId) {
169+
fetch(`/get-table-info/${tableId}`)
170+
.then(response => response.text())
171+
.then(html => {
172+
$('#modal-body').html(html);
173+
$('#infoModal').modal('show');
174+
});
175+
}
167176

168177
function closeModal() {
169178
document.getElementById('infoModal').style.display = 'none';

0 commit comments

Comments
 (0)