fix: update template handling to change default from 'high' to 'low' and adjust related logic in database queries and UI

This commit is contained in:
Théophile Diot 2024-12-03 11:26:35 +01:00
parent 3af012b341
commit b2165f09c8
No known key found for this signature in database
GPG key ID: FA995104A0BA376A
3 changed files with 12 additions and 8 deletions

View file

@ -49,7 +49,7 @@ for deps_path in [os_join(sep, "usr", "share", "bunkerweb", *paths) for paths in
from common_utils import bytes_hash # type: ignore
from pymysql import install_as_MySQLdb
from sqlalchemy import create_engine, event, MetaData as sql_metadata, func, join, select as db_select, text, inspect
from sqlalchemy import case, create_engine, event, MetaData as sql_metadata, func, join, select as db_select, text, inspect
from sqlalchemy.engine import Engine
from sqlalchemy.exc import (
ArgumentError,
@ -3659,7 +3659,11 @@ class Database:
def get_templates(self, plugin: Optional[str] = None) -> Dict[str, dict]:
"""Get templates."""
with self._db_session() as session:
query = session.query(Templates).with_entities(Templates.id, Templates.plugin_id, Templates.name)
query = (
session.query(Templates)
.with_entities(Templates.id, Templates.plugin_id, Templates.name)
.order_by(case((Templates.name == "low", 0), else_=1)) # Pass as positional arguments
)
if plugin:
query = query.filter_by(plugin_id=plugin)

View file

@ -56,7 +56,7 @@ $(document).ready(() => {
params.mode = currentMode;
if (currentMode === "advanced" && currentType !== "all")
params.type = currentType;
if (currentMode === "easy" && currentTemplate !== "high")
if (currentMode === "easy" && currentTemplate !== "low")
params.template = currentTemplate;
// If "easy" is selected, remove the "mode" parameter
@ -153,8 +153,8 @@ $(document).ready(() => {
params.type = null; // Remove the type parameter
// If "high" is selected, remove the "template" parameter
if (currentTemplate === "high") {
// If "low" is selected, remove the "template" parameter
if (currentTemplate === "low") {
params.template = null; // Set template to null to remove it from the URL
updateUrlParams(params); // Call the function without the hash (keep it intact)
} else {
@ -983,11 +983,11 @@ $(document).ready(() => {
currentMode === "easy"
) {
$(`button[data-bs-target="#navs-modes-advanced"]`).tab("show");
} else if (usedTemplate !== "high" && currentMode === "easy") {
} else if (usedTemplate !== "low" && currentMode === "easy") {
$(`button[data-bs-target="#navs-templates-${usedTemplate}"]`).tab("show");
}
if (currentMode === "easy" && currentTemplate !== "high") {
if (currentMode === "easy" && currentTemplate !== "low") {
$(`button[data-bs-target="#navs-templates-${currentTemplate}"]`).tab(
"show",
);

View file

@ -10,7 +10,7 @@
id="selected-mode"
name="selected_mode"
value="{{ mode }}">
<input type="hidden" id="used-template" name="used_template" value="{% if current_endpoint == "new" and not clone %}high{% else %}{{ config.get('USE_TEMPLATE', {'value': ''})['value'] }}
<input type="hidden" id="used-template" name="used_template" value="{% if current_endpoint == "new" and not clone %}low{% else %}{{ config.get('USE_TEMPLATE', {'value': ''})['value'] }}
{% endif %}
">
<input type="hidden"