Reordering and analytics issues

parent feaa37fd
......@@ -541,7 +541,7 @@ class Analytics:
conditions.append(f"autoselect_id = {placeholder}")
params.append(autoselect_filter)
if analytics_kind:
conditions.append(f"analytics_kind = {placeholder}")
conditions.append(f"(analytics_kind = {placeholder} OR analytics_kind IS NULL)")
params.append(analytics_kind)
return conditions, params
......@@ -986,7 +986,7 @@ class Analytics:
elif user_filter is not None:
query += f' AND user_id = {placeholder}'
params.append(user_filter)
query += f' AND analytics_kind = {placeholder}'
query += f' AND (analytics_kind = {placeholder} OR analytics_kind IS NULL)'
params.append('execution')
if provider_filter:
query += f' AND provider_id = {placeholder}'
......
......@@ -818,7 +818,9 @@ async def dashboard_providers_save(request: Request, config: str = Form(...)):
# Read existing config to preserve condensation settings
with open(config_path) as f:
full_config = json.load(f)
providers_data = _reorder_dict(providers_data, list(providers_data.keys()))
# Update providers section while preserving other keys
full_config['providers'] = providers_data
......@@ -845,6 +847,11 @@ async def dashboard_providers_save(request: Request, config: str = Form(...)):
# Save each provider to database
for provider_key, provider_config in providers_data.items():
db.save_user_provider(current_user_id, provider_key, provider_config)
providers_data = _ordered_resource_map(
providers_data,
db.get_sort_order(current_user_id, 'provider')
)
logger.info(f"Saved {len(providers_data)} provider(s) to database for user {current_user_id}")
......@@ -1364,6 +1371,10 @@ async def dashboard_rotations_save(request: Request, config: str = Form(...)):
# Config admin: save to JSON files
config_path = Path.home() / '.aisbf' / 'rotations.json'
config_path.parent.mkdir(parents=True, exist_ok=True)
rotations_data['rotations'] = _reorder_dict(
rotations_data.get('rotations', {}),
list(rotations_data.get('rotations', {}).keys())
)
with open(config_path, 'w') as f:
json.dump(rotations_data, f, indent=2)
_reload_global_config()
......@@ -1384,6 +1395,11 @@ async def dashboard_rotations_save(request: Request, config: str = Form(...)):
for rotation_key, rotation_config in rotations.items():
db.save_user_rotation(current_user_id, rotation_key, rotation_config)
rotations_data['rotations'] = _ordered_resource_map(
rotations_data.get('rotations', {}),
db.get_sort_order(current_user_id, 'rotation')
)
logger.info(f"Saved {len(rotations)} rotation(s) to database for user {current_user_id}")
if is_config_admin:
......@@ -1656,6 +1672,7 @@ async def dashboard_autoselect_save(request: Request, config: str = Form(...)):
# Config admin: save to JSON files
config_path = Path.home() / '.aisbf' / 'autoselect.json'
config_path.parent.mkdir(parents=True, exist_ok=True)
autoselect_data = _reorder_dict(autoselect_data, list(autoselect_data.keys()))
with open(config_path, 'w') as f:
json.dump(autoselect_data, f, indent=2)
_reload_global_config()
......@@ -1674,6 +1691,11 @@ async def dashboard_autoselect_save(request: Request, config: str = Form(...)):
for autoselect_key, autoselect_config in autoselect_data.items():
db.save_user_autoselect(current_user_id, autoselect_key, autoselect_config)
autoselect_data = _ordered_resource_map(
autoselect_data,
db.get_sort_order(current_user_id, 'autoselect')
)
logger.info(f"Saved {len(autoselect_data)} autoselect(s) to database for user {current_user_id}")
if is_config_admin:
......@@ -2253,6 +2275,13 @@ def _reorder_dict(d: dict, order: list) -> dict:
return result
def _ordered_resource_map(resource_map: dict, saved_order: list | None) -> dict:
"""Apply a saved order to a resource map while keeping unknown keys appended."""
if not saved_order:
return resource_map
return _reorder_dict(resource_map, saved_order)
@router.get("/dashboard/analytics", response_class=HTMLResponse)
async def dashboard_analytics(
request: Request,
......
......@@ -2861,8 +2861,7 @@ async function confirmAddProvider() {
discovery_enabled: true,
client_id: key,
bridge_path: '/coderai/ws',
registration_path: '/coderai/register',
registration_token: ''
registration_path: '/coderai/register'
};
} else if (type === 'runpod') {
providersData[key].runpod_config = {
......
......@@ -2577,8 +2577,7 @@ async function confirmAddProvider() {
discovery_enabled: true,
client_id: key,
bridge_path: '/coderai/ws',
registration_path: '/coderai/register',
registration_token: ''
registration_path: '/coderai/register'
};
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment