Skip to content

Commit 16bd1ca

Browse files
committed
INTEGRITY: Improve 'Compare Fileset' feature
The filtering for searching filesets for comparing is now done using the fileset search page, with additional button 'Compare' for redirecting to the merge page.
1 parent 5991a6c commit 16bd1ca

File tree

2 files changed

+27
-112
lines changed

2 files changed

+27
-112
lines changed

src/app/fileset.py

Lines changed: 16 additions & 110 deletions
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ def fileset():
154154
"""
155155
if old_id is not None:
156156
html += f"""<h3><u>Redirected from Fileset: {old_id}</u></h3>"""
157-
html += f"<button type='button' onclick=\"location.href='/fileset/{id}/merge'\">Manual Merge</button>"
157+
html += f"<button type='button' onclick=\"location.href='/fileset/{id}/merge'\">Compare Filesets</button>"
158158
html += f"""
159159
<form action="/fileset/{id}/mark_full" method="post" style="display:inline;">
160160
<button type='submit'>Mark as full</button>
@@ -836,111 +836,8 @@ def update_fileset(id):
836836

837837
@app.route("/fileset/<int:id>/merge", methods=["GET", "POST"])
838838
def merge_fileset(id):
839-
if request.method == "POST":
840-
search_query = request.form["search"]
841-
842-
connection = db_connect()
843-
844-
try:
845-
with connection.cursor() as cursor:
846-
query = f"""
847-
SELECT
848-
fs.*,
849-
g.name AS game_name,
850-
g.engine AS game_engine,
851-
g.platform AS game_platform,
852-
g.language AS game_language,
853-
g.extra AS extra
854-
FROM
855-
fileset fs
856-
LEFT JOIN
857-
game g ON fs.game = g.id
858-
WHERE g.name LIKE '%{search_query}%' OR g.platform LIKE '%{search_query}%' OR g.language LIKE '%{search_query}%'
859-
"""
860-
cursor.execute(query)
861-
results = cursor.fetchall()
862-
863-
html = f"""
864-
<!DOCTYPE html>
865-
<html>
866-
<head>
867-
<link rel="stylesheet" type="text/css" href="{{{{ url_for('static', filename='style.css') }}}}">
868-
<link rel="icon" type="image/png" sizes="32x32" href="/static/favicon-32x32.png">
869-
<link rel="icon" type="image/png" sizes="16x16" href="/static/favicon-16x16.png">
870-
</head>
871-
<body>
872-
<nav>
873-
<div class="logo">
874-
<a href="{{{{ url_for('home') }}}}">
875-
<img src="{{{{ url_for('static', filename='integrity_service_logo_256.png') }}}}" alt="Logo">
876-
</a>
877-
</div>
878-
<div class="nav-buttons">
879-
<a href="{{{{ url_for('user_games_list') }}}}">User Games List</a>
880-
<a href="{{{{ url_for('ready_for_review') }}}}">Ready for review</a>
881-
<a href="{{{{ url_for('fileset_search') }}}}">Fileset Search</a>
882-
<a href="{{{{ url_for('logs') }}}}">Logs</a>
883-
<a href="{{{{ url_for('config') }}}}">Config</a>
884-
</div>
885-
</nav>
886-
<h2 style="margin-top: 80px;">Search Results for '{search_query}'</h2>
887-
<form method="POST">
888-
<input type="text" name="search" placeholder="Search fileset">
889-
<input type="submit" value="Search">
890-
</form>
891-
<table>
892-
<tr><th>ID</th><th>Game Name</th><th>Platform</th><th>Language</th><th>Extra</th><th>Action</th></tr>
893-
"""
894-
for result in results:
895-
html += f"""
896-
<tr>
897-
<td>{result["id"]}</td>
898-
<td>{result["game_name"]}</td>
899-
<td>{result["game_platform"]}</td>
900-
<td>{result["game_language"]}</td>
901-
<td>{result["extra"]}</td>
902-
<td><a href="/fileset/{id}/merge/confirm?target_id={result["id"]}">Select</a></td>
903-
</tr>
904-
"""
905-
html += "</table>\n"
906-
html += "</body>\n</html>"
907-
908-
return render_template_string(html)
909-
910-
finally:
911-
connection.close()
912-
913-
return """
914-
<!DOCTYPE html>
915-
<html>
916-
<head>
917-
<link rel="stylesheet" type="text/css" href="{{ url_for('static', filename='style.css') }}">
918-
<link rel="icon" type="image/png" sizes="32x32" href="/static/favicon-32x32.png">
919-
<link rel="icon" type="image/png" sizes="16x16" href="/static/favicon-16x16.png">
920-
</head>
921-
<body>
922-
<nav>
923-
<div class="logo">
924-
<a href="{{ url_for('home') }}">
925-
<img src="{{ url_for('static', filename='integrity_service_logo_256.png') }}" alt="Logo">
926-
</a>
927-
</div>
928-
<div class="nav-buttons">
929-
<a href="{{ url_for('user_games_list') }}">User Games List</a>
930-
<a href="{{ url_for('ready_for_review') }}">Ready for review</a>
931-
<a href="{{ url_for('fileset_search') }}">Fileset Search</a>
932-
<a href="{{ url_for('logs') }}">Logs</a>
933-
<a href="{{ url_for('config') }}">Config</a>
934-
</div>
935-
</nav>
936-
<h2 style="margin-top: 80px;">Search Fileset to Merge</h2>
937-
<form method="POST">
938-
<input type="text" name="search" placeholder="Search fileset">
939-
<input type="submit" value="Search">
940-
</form>
941-
</body>
942-
</html>
943-
"""
839+
url = f"/fileset_search?source_id={id}"
840+
return redirect(url)
944841

945842

946843
@app.route("/fileset/<int:id>/possible_merge", methods=["GET", "POST"])
@@ -1296,7 +1193,7 @@ def highlight_differences(source, target):
12961193
# For matched_files, files is a tuple of filename from source file and target file
12971194
# For unmatched_files, files is the filename of the files that was not common.
12981195
for files in file_category:
1299-
if is_common_file:
1196+
if is_common_file and len(matched_files) != 0:
13001197
(target_filename, source_filename) = files
13011198

13021199
# Also remove common files from source and target filenames set
@@ -1325,7 +1222,11 @@ def highlight_differences(source, target):
13251222

13261223
keys = sorted(set(source_dict.keys()) | set(target_dict.keys()))
13271224

1328-
tr_class = "matched" if is_common_file else "unmatched"
1225+
tr_class = (
1226+
"matched"
1227+
if (is_common_file and len(matched_files) != 0)
1228+
else "unmatched"
1229+
)
13291230
html += f"""<tr class="{tr_class}">
13301231
<td colspan='3'>
13311232
<strong>{source_filename}</strong> {" - mac_file" if is_mac_file else ""}
@@ -1369,9 +1270,14 @@ def highlight_differences(source, target):
13691270
and source_filename.lower() in detection_files_set
13701271
):
13711272
is_detection = "1"
1372-
fname = source_to_target_matched_map[
1273+
fname = (
13731274
source_filename.lower()
1374-
]
1275+
if source_filename.lower()
1276+
not in source_to_target_matched_map
1277+
else source_to_target_matched_map[
1278+
source_filename.lower()
1279+
]
1280+
)
13751281
detection_type = target_files_map[fname].get(
13761282
"detection_type", ""
13771283
)

src/app/pagination.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ def create_page(
6464
where_clauses = []
6565

6666
for key, value in request.args.items():
67-
if key in ("page", "sort") or value == "":
67+
if key in ("page", "sort", "source_id") or value == "":
6868
continue
6969
tables.add(filters[key])
7070
col = f"{filters[key]}.{'id' if key == 'fileset' else key}"
@@ -181,7 +181,6 @@ def create_page(
181181
width = get_width(name, default)
182182
html += f"<col style='width: {width}%;'>"
183183
html += "</colgroup>"
184-
185184
if filters:
186185
html += """<tr class='filter'><td class='filter'><input type='submit' value='Submit'></td>"""
187186
for key in filters.keys():
@@ -245,6 +244,14 @@ def create_page(
245244
</a>
246245
</th>"""
247246

247+
compare_fileset_source_id = request.args.get("source_id", "")
248+
if compare_fileset_source_id != "":
249+
html += """<th>
250+
<div style="display:flex; align-items:center; width:100%;">
251+
<span style="flex:1; text-align:center;">Action</span>
252+
</div>
253+
</th>"""
254+
248255
if results:
249256
counter = offset + 1
250257
for row in results:
@@ -284,6 +291,8 @@ def create_page(
284291
)
285292

286293
html += f"<td>{'' if value is None else value}</td>\n"
294+
if compare_fileset_source_id != "":
295+
html += f"""<td><a href="/fileset/{compare_fileset_source_id}/merge/confirm?target_id={fileset_id}">Compare</a></td>"""
287296
html += "</tr>\n"
288297
counter += 1
289298

0 commit comments

Comments
 (0)