Additional typing fixes

This commit is contained in:
Max Berger
2026-03-02 22:38:10 +01:00
parent c88b3699cb
commit 8af1c8c1b3
3 changed files with 247 additions and 233 deletions

View File

@@ -18,16 +18,16 @@
* 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 { Scene, push_scene, pop_scene, scene_stack } from "./scene_manager.js";
import { CreateEditCollectionScene } from "./CreateEditCollectionScene.js"; import { CreateEditCollectionScene } from "./CreateEditCollectionScene.js";
import { CreateShareCollectionScene } from "./ShareCollectionScene.js";
import { UploadCollectionScene } from "./UploadCollectionScene.js";
import { DeleteCollectionScene } from "./DeleteCollectionScene.js"; import { DeleteCollectionScene } from "./DeleteCollectionScene.js";
import { LoadingScene } from "./LoadingScene.js"; import { LoadingScene } from "./LoadingScene.js";
import { CreateShareCollectionScene } from "./ShareCollectionScene.js";
import { UploadCollectionScene } from "./UploadCollectionScene.js";
import { get_collections } from "./api.js"; import { get_collections } from "./api.js";
import { Collection, CollectionType } from "./models.js";
import { bytesToHumanReadable } from "./utils.js";
import { SERVER } from "./constants.js"; import { SERVER } from "./constants.js";
import { Collection, CollectionType } from "./models.js";
import { Scene, pop_scene, push_scene, scene_stack } from "./scene_manager.js";
import { bytesToHumanReadable } from "./utils.js";
/** /**
* @constructor * @constructor
@@ -38,7 +38,8 @@ import { SERVER } from "./constants.js";
* @param {function(string):void} onerror Called when an error occurs, before the * @param {function(string):void} onerror Called when an error occurs, before the
* scene is popped. * scene is popped.
*/ */
export function CollectionsScene(user, password, collection, onerror) { export class CollectionsScene {
constructor(user, password, collection, onerror) {
/** @type {HTMLElement} */ let html_scene = document.getElementById("collectionsscene"); /** @type {HTMLElement} */ let html_scene = document.getElementById("collectionsscene");
/** @type {HTMLElement} */ let template = html_scene.querySelector("[data-name=collectiontemplate]"); /** @type {HTMLElement} */ let template = html_scene.querySelector("[data-name=collectiontemplate]");
/** @type {HTMLElement} */ let new_btn = html_scene.querySelector("[data-name=new]"); /** @type {HTMLElement} */ let new_btn = html_scene.querySelector("[data-name=new]");
@@ -53,7 +54,7 @@ export function CollectionsScene(user, password, collection, onerror) {
try { try {
let create_collection_scene = new CreateEditCollectionScene(user, password, collection); let create_collection_scene = new CreateEditCollectionScene(user, password, collection);
push_scene(create_collection_scene, false); push_scene(create_collection_scene, false);
} catch(err) { } catch (err) {
console.error(err); console.error(err);
} }
return false; return false;
@@ -63,7 +64,7 @@ export function CollectionsScene(user, password, collection, onerror) {
try { try {
let upload_scene = new UploadCollectionScene(user, password, collection); let upload_scene = new UploadCollectionScene(user, password, collection);
push_scene(upload_scene, false); push_scene(upload_scene, false);
} catch(err) { } catch (err) {
console.error(err); console.error(err);
} }
return false; return false;
@@ -73,7 +74,7 @@ export function CollectionsScene(user, password, collection, onerror) {
try { try {
let edit_collection_scene = new CreateEditCollectionScene(user, password, collection); let edit_collection_scene = new CreateEditCollectionScene(user, password, collection);
push_scene(edit_collection_scene, false); push_scene(edit_collection_scene, false);
} catch(err) { } catch (err) {
console.error(err); console.error(err);
} }
return false; return false;
@@ -83,7 +84,7 @@ export function CollectionsScene(user, password, collection, onerror) {
try { try {
let share_collection_scene = new CreateShareCollectionScene(user, password, collection); let share_collection_scene = new CreateShareCollectionScene(user, password, collection);
push_scene(share_collection_scene, false); push_scene(share_collection_scene, false);
} catch(err) { } catch (err) {
console.error(err); console.error(err);
} }
return false; return false;
@@ -93,23 +94,24 @@ export function CollectionsScene(user, password, collection, onerror) {
try { try {
let delete_collection_scene = new DeleteCollectionScene(user, password, collection); let delete_collection_scene = new DeleteCollectionScene(user, password, collection);
push_scene(delete_collection_scene, false); push_scene(delete_collection_scene, false);
} catch(err) { } catch (err) {
console.error(err); console.error(err);
} }
return false; return false;
} }
function show_collections(collections) { function show_collections(collections) {
let heightOfNavBar = document.querySelector("#logoutview").offsetHeight + "px"; /** @type {HTMLElement} */ let navBar = document.querySelector("#logoutview");
let heightOfNavBar = navBar.offsetHeight + "px";
html_scene.style.marginTop = heightOfNavBar; html_scene.style.marginTop = heightOfNavBar;
html_scene.style.height = "calc(100vh - " + heightOfNavBar +")"; html_scene.style.height = "calc(100vh - " + heightOfNavBar + ")";
collections.forEach(function (collection) { collections.forEach(function (collection) {
/** @type {HTMLElement} */ let node = template.cloneNode(true); /** @type {HTMLElement} */ let node = /** @type {HTMLElement} */(template.cloneNode(true));
node.classList.remove("hidden"); node.classList.remove("hidden");
/** @type {HTMLElement} */ let title_form = node.querySelector("[data-name=title]"); /** @type {HTMLElement} */ let title_form = node.querySelector("[data-name=title]");
/** @type {HTMLElement} */ let description_form = node.querySelector("[data-name=description]"); /** @type {HTMLElement} */ let description_form = node.querySelector("[data-name=description]");
/** @type {HTMLElement} */ let contentcount_form = node.querySelector("[data-name=contentcount]"); /** @type {HTMLElement} */ let contentcount_form = node.querySelector("[data-name=contentcount]");
/** @type {HTMLElement} */ let url_form = node.querySelector("[data-name=url]"); /** @type {HTMLInputElement} */ let url_form = node.querySelector("[data-name=url]");
/** @type {HTMLElement} */ let color_form = node.querySelector("[data-name=color]"); /** @type {HTMLElement} */ let color_form = node.querySelector("[data-name=color]");
/** @type {HTMLElement} */ let delete_btn = node.querySelector("[data-name=delete]"); /** @type {HTMLElement} */ let delete_btn = node.querySelector("[data-name=delete]");
/** @type {HTMLElement} */ let edit_btn = node.querySelector("[data-name=edit]"); /** @type {HTMLElement} */ let edit_btn = node.querySelector("[data-name=edit]");
@@ -119,31 +121,31 @@ export function CollectionsScene(user, password, collection, onerror) {
color_form.style.background = collection.color; color_form.style.background = collection.color;
} }
let possible_types = [CollectionType.ADDRESSBOOK, CollectionType.WEBCAL]; let possible_types = [CollectionType.ADDRESSBOOK, CollectionType.WEBCAL];
[CollectionType.CALENDAR, ""].forEach(function(e) { [CollectionType.CALENDAR, ""].forEach(function (e) {
[CollectionType.union(e, CollectionType.JOURNAL), e].forEach(function(e) { [CollectionType.union(e, CollectionType.JOURNAL), e].forEach(function (e) {
[CollectionType.union(e, CollectionType.TASKS), e].forEach(function(e) { [CollectionType.union(e, CollectionType.TASKS), e].forEach(function (e) {
if (e) { if (e) {
possible_types.push(e); possible_types.push(e);
} }
}); });
}); });
}); });
possible_types.forEach(function(e) { possible_types.forEach(function (e) {
if (e !== collection.type) { if (e !== collection.type) {
node.querySelector("[data-name=" + e + "]").classList.add("hidden"); node.querySelector("[data-name=" + e + "]").classList.add("hidden");
} }
}); });
title_form.textContent = collection.displayname || collection.href; title_form.textContent = collection.displayname || collection.href;
if(title_form.textContent.length > 30){ if (title_form.textContent.length > 30) {
title_form.classList.add("smalltext"); title_form.classList.add("smalltext");
} }
description_form.textContent = collection.description; description_form.textContent = collection.description;
if(description_form.textContent.length > 150){ if (description_form.textContent.length > 150) {
description_form.classList.add("smalltext"); description_form.classList.add("smalltext");
} }
if(collection.type != CollectionType.WEBCAL){ if (collection.type != CollectionType.WEBCAL) {
let contentcount_form_txt = (collection.contentcount > 0 ? Number(collection.contentcount).toLocaleString() : "No") + " item" + (collection.contentcount == 1 ? "" : "s") + " in collection"; let contentcount_form_txt = (collection.contentcount > 0 ? Number(collection.contentcount).toLocaleString() : "No") + " item" + (collection.contentcount == 1 ? "" : "s") + " in collection";
if(collection.contentcount > 0){ if (collection.contentcount > 0) {
contentcount_form_txt += " (" + bytesToHumanReadable(collection.size) + ")"; contentcount_form_txt += " (" + bytesToHumanReadable(collection.size) + ")";
} }
contentcount_form.textContent = contentcount_form_txt; contentcount_form.textContent = contentcount_form_txt;
@@ -151,12 +153,12 @@ export function CollectionsScene(user, password, collection, onerror) {
let href = SERVER + collection.href; let href = SERVER + collection.href;
url_form.value = href; url_form.value = href;
download_btn.href = href; download_btn.href = href;
if(collection.type == CollectionType.WEBCAL){ if (collection.type == CollectionType.WEBCAL) {
download_btn.parentElement.classList.add("hidden"); download_btn.parentElement.classList.add("hidden");
} }
delete_btn.onclick = function() {return ondelete(collection);}; delete_btn.onclick = function () { return ondelete(collection); };
edit_btn.onclick = function() {return onedit(collection);}; edit_btn.onclick = function () { return onedit(collection); };
share_btn.onclick = function() {return onshare(collection);}; share_btn.onclick = function () { return onshare(collection); };
node.classList.remove("hidden"); node.classList.remove("hidden");
nodes.push(node); nodes.push(node);
template.parentNode.insertBefore(node, template); template.parentNode.insertBefore(node, template);
@@ -166,7 +168,7 @@ export function CollectionsScene(user, password, collection, onerror) {
function update() { function update() {
let loading_scene = new LoadingScene(); let loading_scene = new LoadingScene();
push_scene(loading_scene, false); push_scene(loading_scene, false);
collections_req = get_collections(user, password, collection, function(collections1, error) { collections_req = get_collections(user, password, collection, function (collections1, error) {
if (scene_index === null) { if (scene_index === null) {
return; return;
} }
@@ -181,7 +183,7 @@ export function CollectionsScene(user, password, collection, onerror) {
}); });
} }
this.show = function() { this.show = function () {
html_scene.classList.remove("hidden"); html_scene.classList.remove("hidden");
new_btn.onclick = onnew; new_btn.onclick = onnew;
upload_btn.onclick = onupload; upload_btn.onclick = onupload;
@@ -192,19 +194,19 @@ export function CollectionsScene(user, password, collection, onerror) {
show_collections(collections); show_collections(collections);
} }
}; };
this.hide = function() { this.hide = function () {
html_scene.classList.add("hidden"); html_scene.classList.add("hidden");
scene_index = scene_stack.length - 1; scene_index = scene_stack.length - 1;
new_btn.onclick = null; new_btn.onclick = null;
upload_btn.onclick = null; upload_btn.onclick = null;
collections = null; collections = null;
// remove collection // remove collection
nodes.forEach(function(node) { nodes.forEach(function (node) {
node.parentNode.removeChild(node); node.parentNode.removeChild(node);
}); });
nodes = []; nodes = [];
}; };
this.release = function() { this.release = function () {
scene_index = null; scene_index = null;
if (collections_req !== null) { if (collections_req !== null) {
collections_req.abort(); collections_req.abort();
@@ -212,4 +214,5 @@ export function CollectionsScene(user, password, collection, onerror) {
} }
collections = null; collections = null;
}; };
}
} }

View File

@@ -25,7 +25,7 @@ import {
server_features, server_features,
} from "./api.js"; } from "./api.js";
import { Collection } from "./models.js"; import { Collection } from "./models.js";
import { pop_scene, scene_stack } from "./scene_manager.js"; import { Scene, pop_scene, scene_stack } from "./scene_manager.js";
/** /**
* @constructor * @constructor
@@ -34,17 +34,25 @@ import { pop_scene, scene_stack } from "./scene_manager.js";
* @param {string} password * @param {string} password
* @param {Collection} collection The collection on which to edit sharing setting. Must exist. * @param {Collection} collection The collection on which to edit sharing setting. Must exist.
*/ */
export function CreateShareCollectionScene(user, password, collection) { /**
* @constructor
* @implements {Scene}
* @param {string} user
* @param {string} password
* @param {Collection} collection The collection on which to edit sharing setting. Must exist.
*/
export class CreateShareCollectionScene {
constructor(user, password, collection) {
/** @type {?number} */ let scene_index = null; /** @type {?number} */ let scene_index = null;
let html_scene = document.getElementById("sharecollectionscene"); let html_scene = document.getElementById("sharecollectionscene");
/** @type {HTMLElement} */ let cancel_btn = html_scene.querySelector("[data-name=cancel]"); /** @type {HTMLElement} */ let cancel_btn = html_scene.querySelector("[data-name=cancel]");
/** @type {HTMLElement} */ let share_by_token_btn_ro = html_scene.querySelector( /** @type {HTMLElement} */ let share_by_token_btn_ro = html_scene.querySelector(
"[data-name=sharebytoken_ro]", "[data-name=sharebytoken_ro]"
); );
/** @type {HTMLElement} */ let share_by_token_btn_rw = html_scene.querySelector( /** @type {HTMLElement} */ let share_by_token_btn_rw = html_scene.querySelector(
"[data-name=sharebytoken_rw]", "[data-name=sharebytoken_rw]"
); );
/** @type {HTMLElement} */ let title = html_scene.querySelector("[data-name=title]"); /** @type {HTMLElement} */ let title = html_scene.querySelector("[data-name=title]");
@@ -92,6 +100,7 @@ export function CreateShareCollectionScene(user, password, collection) {
this.release = function () { this.release = function () {
scene_index = null; scene_index = null;
}; };
}
} }
function update_share_list(user, password, collection) { function update_share_list(user, password, collection) {

View File

@@ -21,19 +21,21 @@
/** /**
* @interface * @interface
*/ */
export function Scene() {} export class Scene {
/** constructor() { }
/**
* Scene is on top of stack and visible. * Scene is on top of stack and visible.
*/ */
Scene.prototype.show = function() {}; show() { }
/** /**
* Scene is no longer visible. * Scene is no longer visible.
*/ */
Scene.prototype.hide = function() {}; hide() { }
/** /**
* Scene is removed from scene stack. * Scene is removed from scene stack.
*/ */
Scene.prototype.release = function() {}; release() { }
}
/** /**