UI: Dynamic window titles including URL

This commit is contained in:
Max Berger
2026-04-22 21:39:02 +02:00
parent ecac9c6ced
commit 66d4827250
12 changed files with 92 additions and 2 deletions

View File

@@ -19,6 +19,7 @@ Integration test for basic operations
""" """
import pathlib import pathlib
import re
from typing import Any, Generator from typing import Any, Generator
import pytest import pytest
@@ -44,7 +45,7 @@ def test_index_html_loads(page: Page, radicale_server: str, config: Config) -> N
console_msgs: list[str] = [] console_msgs: list[str] = []
page.on("console", lambda msg: console_msgs.append(msg.text)) page.on("console", lambda msg: console_msgs.append(msg.text))
page.goto(radicale_server) page.goto(radicale_server)
expect(page).to_have_title("Radicale Web Interface") expect(page).to_have_title(re.compile("Radicale Web Interface - .* - Login"))
# There should be no errors on the console, except for the expected 401/403 from auto-login check # There should be no errors on the console, except for the expected 401/403 from auto-login check
errors = [ errors = [
msg msg

View File

@@ -312,4 +312,10 @@ export class CollectionsScene {
} }
is_transient() { return false; } is_transient() { return false; }
title_object() {
if (this._principal_collection.displayname && this._principal_collection.displayname.length > 0)
return this._principal_collection.displayname;
else return this._user;
}
} }

View File

@@ -22,6 +22,7 @@
import { create_collection, edit_collection } from "../api/api.js"; import { create_collection, edit_collection } from "../api/api.js";
import { COLOR_RE } from "../constants.js"; import { COLOR_RE } from "../constants.js";
import { Collection, CollectionType } from "../models/collection.js"; import { Collection, CollectionType } from "../models/collection.js";
import { extract_title } from "../utils/collection_utils.js";
import { collectionsCache } from "../utils/collections_cache.js"; import { collectionsCache } from "../utils/collections_cache.js";
import { ErrorHandler } from "../utils/error.js"; import { ErrorHandler } from "../utils/error.js";
import { FormValidator, validate_color, validate_href } from "../utils/form_validator.js"; import { FormValidator, validate_color, validate_href } from "../utils/form_validator.js";
@@ -224,4 +225,9 @@ export class CreateEditCollectionScene {
this._create_edit_req = null; this._create_edit_req = null;
} }
} }
title_object() {
return extract_title(this._collection);
}
} }

View File

@@ -21,6 +21,7 @@
import { Share, add_share_by_map, add_share_by_token, get_property_key, update_share_by_map, update_share_by_token } from "../api/sharing.js"; import { Share, add_share_by_map, add_share_by_token, get_property_key, update_share_by_map, update_share_by_token } from "../api/sharing.js";
import { CollectionType, Permission } from "../models/collection.js"; import { CollectionType, Permission } from "../models/collection.js";
import { extract_title } from "../utils/collection_utils.js";
import { collectionsCache } from "../utils/collections_cache.js"; import { collectionsCache } from "../utils/collections_cache.js";
import { ErrorHandler } from "../utils/error.js"; import { ErrorHandler } from "../utils/error.js";
import { FormValidator, validate_href, validate_non_empty, validate_not_empty_or_equals } from "../utils/form_validator.js"; import { FormValidator, validate_href, validate_non_empty, validate_not_empty_or_equals } from "../utils/form_validator.js";
@@ -416,4 +417,9 @@ export class CreateEditShareScene {
} }
is_transient() { return false; } is_transient() { return false; }
title_object() {
return extract_title(this._collection);
}
} }

View File

@@ -153,4 +153,6 @@ export class DeleteConfirmationScene {
this._delete_req = null; this._delete_req = null;
} }
} }
title_object() { return ""; }
} }

View File

@@ -24,8 +24,8 @@ import { collectionsCache } from "../utils/collections_cache.js";
import { ErrorHandler } from "../utils/error.js"; import { ErrorHandler } from "../utils/error.js";
import { get_element, get_element_by_id } from "../utils/misc.js"; import { get_element, get_element_by_id } from "../utils/misc.js";
import { displayPermissionsOrConversion } from "../utils/permissions.js"; import { displayPermissionsOrConversion } from "../utils/permissions.js";
import { Scene, pop_scene } from "./scene_manager.js";
import { UrlTextHandler } from "../utils/url_text.js"; import { UrlTextHandler } from "../utils/url_text.js";
import { Scene, pop_scene } from "./scene_manager.js";
/** /**
* @implements {Scene} * @implements {Scene}
@@ -166,4 +166,6 @@ export class IncomingSharingScene {
}); });
this._nodes = []; this._nodes = [];
} }
title_object() { return ""; }
} }

View File

@@ -37,4 +37,5 @@ export class LoadingScene {
} }
release() { } release() { }
is_transient() { return true; } is_transient() { return true; }
title_object() { return "Loading..."}
} }

View File

@@ -196,4 +196,7 @@ export class LoginScene {
} }
this._remove_logout(); this._remove_logout();
} }
title_object() { return "Login" }
} }

View File

@@ -25,6 +25,7 @@ import {
reload_sharing_list, reload_sharing_list,
} from "../api/sharing.js"; } from "../api/sharing.js";
import { Collection, Permission } from "../models/collection.js"; import { Collection, Permission } from "../models/collection.js";
import { extract_title } from "../utils/collection_utils.js";
import { ErrorHandler } from "../utils/error.js"; import { ErrorHandler } from "../utils/error.js";
import { get_element, get_element_by_id } from "../utils/misc.js"; import { get_element, get_element_by_id } from "../utils/misc.js";
@@ -126,6 +127,11 @@ export class ShareCollectionScene {
} }
is_transient() { return false; } is_transient() { return false; }
title_object() {
return extract_title(this._collection);
}
} }
/** /**

View File

@@ -241,4 +241,6 @@ export class UploadCollectionScene {
this._upload_req = null; this._upload_req = null;
} }
} }
title_object() { return ""; }
} }

View File

@@ -19,6 +19,8 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
import { SERVER } from "../constants.js";
/** /**
* @interface * @interface
*/ */
@@ -41,6 +43,9 @@ export class Scene {
* @returns boolean * @returns boolean
*/ */
is_transient() { return false; } is_transient() { return false; }
/** @returns str */
title_object() { return ""; }
} }
@@ -54,6 +59,18 @@ let history_array = [];
let current_history_index = -1; let current_history_index = -1;
let is_navigating_history = false; let is_navigating_history = false;
function update_window_title() {
let title_parts = ["Radicale Web Interface", SERVER];
if (scene_stack.length > 0) {
let title = scene_stack[scene_stack.length - 1].title_object();
if (title) {
title_parts.push(title);
}
}
document.title = title_parts.join(" - ");
}
function record_history() { function record_history() {
if (is_navigating_history) return; if (is_navigating_history) return;
@@ -120,6 +137,7 @@ if (typeof window !== "undefined" && window.history) {
} }
current_history_index = new_index; current_history_index = new_index;
update_window_title();
} finally { } finally {
is_navigating_history = false; is_navigating_history = false;
} }
@@ -141,6 +159,7 @@ export function push_scene(scene) {
scene_stack.push(scene); scene_stack.push(scene);
scene.show(); scene.show();
record_history(); record_history();
update_window_title();
} }
/** /**
@@ -154,6 +173,7 @@ function pop_and_release() {
if (scene) { if (scene) {
scene.release(); scene.release();
} }
update_window_title();
} }
/** /**
@@ -168,6 +188,7 @@ export function replace_scene(scene) {
scene_stack.push(scene); scene_stack.push(scene);
scene.show(); scene.show();
record_history(); record_history();
update_window_title();
} }
/** /**
@@ -183,6 +204,7 @@ export function pop_scene() {
scene_stack[scene_stack.length - 1].show(); scene_stack[scene_stack.length - 1].show();
} }
record_history(); record_history();
update_window_title();
} }
/** /**
@@ -202,6 +224,7 @@ export function pop_to_parent() {
scene_stack[scene_stack.length - 1].show(); scene_stack[scene_stack.length - 1].show();
} }
record_history(); record_history();
update_window_title();
} }
/** /**
@@ -222,6 +245,7 @@ export function pop_to_root() {
scene_stack[0].show(); // Ensure the root scene is visible scene_stack[0].show(); // Ensure the root scene is visible
} }
record_history(); record_history();
update_window_title();
} }
/** /**

View File

@@ -0,0 +1,31 @@
/**
* This file is part of Radicale Server - Calendar Server
* Copyright © 2017-2024 Unrud <unrud@outlook.com>
* Copyright © 2023-2024 Matthew Hana <matthew.hana@gmail.com>
* Copyright © 2024-2025 Peter Bieringer <pb@bieringer.de>
* Copyright © 2026-2026 Max Berger <max@berger.name>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
/**
* @param {import("../models/collection.js").Collection} collection
* @returns str
*/
export function extract_title(collection) {
if (collection.displayname && collection.displayname.length > 0) {
return collection.displayname;
} else
return collection.href;
}