From 5aa1cf7147f4752c4d7c4d8177542a7a94ab2e22 Mon Sep 17 00:00:00 2001 From: David Mosbach Date: Sun, 16 Jun 2024 23:35:21 +0000 Subject: [PATCH] feat(dbtable): added sync table variant --- frontend/src/utils/async-table/async-table.ts | 18 ++++++++++-------- .../src/utils/exam-correct/exam-correct.js | 4 ++-- src/Handler/Utils/Table/Pagination.hs | 12 ++++++++++-- templates/table/layout-wrapper.hamlet | 5 +++-- tsconfig.json | 2 +- 5 files changed, 26 insertions(+), 15 deletions(-) diff --git a/frontend/src/utils/async-table/async-table.ts b/frontend/src/utils/async-table/async-table.ts index cf36f8694..617c88d72 100644 --- a/frontend/src/utils/async-table/async-table.ts +++ b/frontend/src/utils/async-table/async-table.ts @@ -62,6 +62,7 @@ export class AsyncTable { _active = true; constructor(element, app) { + alert("async table constructor"); if (!element) { throw new Error('Async Table utility cannot be setup without an element!'); } @@ -76,7 +77,7 @@ export class AsyncTable { this._eventManager = new EventManager(); if (this._element.classList.contains(ASYNC_TABLE_INITIALIZED_CLASS)) { - return false; + return null; } // param asyncTableDbHeader @@ -126,7 +127,7 @@ export class AsyncTable { this._element.classList.add(ASYNC_TABLE_INITIALIZED_CLASS); } - _historyListener(historyState) { + _historyListener(historyState?) { if (!this._active) return; @@ -227,7 +228,7 @@ export class AsyncTable { _gatherTableFilterInputs(tableFilterForm) { Array.from(tableFilterForm.querySelectorAll('input')).forEach((input) => { - const inputType = input.getAttribute('type'); + const inputType = (input).getAttribute('type'); if (inputType === 'search') { this._tableFilterInputs.search.push(input); } else if (['text','date','time','datetime-local'].includes(inputType)) { @@ -311,7 +312,7 @@ export class AsyncTable { _updateFromTableFilter(tableFilterForm) { const url = this._serializeTableFilterToURL(tableFilterForm); let callback = null; - alert(`update from table filter: ${url}`) + alert(`ASYNC update from table filter: ${url}`) const focusedInput = tableFilterForm.querySelector(':focus, :active'); // focus previously focused input @@ -341,7 +342,7 @@ export class AsyncTable { this._debugLog('_serializeTableFilterToURL', Array.from(formData.entries()), url.href); - const searchParams = new URLSearchParams(Array.from(formData.entries())); + const searchParams = new URLSearchParams(Array.from(formData.entries())); url.search = searchParams.toString(); this._debugLog('_serializeTableFilterToURL', url.href); @@ -415,9 +416,9 @@ export class AsyncTable { }; // fetches new sorted element from url with params and replaces contents of current element - _updateTableFrom(url, callback, isPopState) { + _updateTableFrom(url, callback?, isPopState?) { url = new URL(url); - alert(`update table from: ${url}`) + alert(`ASYNC update table from: ${url}`) const cancelPendingUpdates = (() => { this._cancelPendingUpdates.forEach(f => f()); @@ -467,7 +468,7 @@ export class AsyncTable { ).finally(() => this._element.classList.remove(ASYNC_TABLE_LOADING_CLASS)); } - _debugLog() {} + _debugLog(fName, ...args) {} //_debugLog(fName, ...args) { // console.log(`[DEBUGLOG] AsyncTable.${fName}`, { args: args, instance: this }); // } @@ -478,6 +479,7 @@ export class AsyncTable { }) export class SyncTable extends AsyncTable { constructor(element, app) { + alert("SYNC table constr!"); super(element, app); alert("h"); } diff --git a/frontend/src/utils/exam-correct/exam-correct.js b/frontend/src/utils/exam-correct/exam-correct.js index 7685c00e1..4fbcc6c48 100644 --- a/frontend/src/utils/exam-correct/exam-correct.js +++ b/frontend/src/utils/exam-correct/exam-correct.js @@ -1,4 +1,4 @@ -// SPDX-FileCopyrightText: 2022 Gregor Kleen ,Sarah Vaupel ,Sarah Vaupel +// SPDX-FileCopyrightText: 2022-2024 Gregor Kleen ,Sarah Vaupel ,Sarah Vaupel ,David Mosbach // // SPDX-License-Identifier: AGPL-3.0-or-later @@ -301,7 +301,7 @@ export class ExamCorrect { users: [user], status: STATUS.LOADING, }; - if (results && results !== {}) rowInfo.results = results; + if (results && results != {}) rowInfo.results = results; if (result !== undefined) rowInfo.result = result; this._addRow(rowInfo); diff --git a/src/Handler/Utils/Table/Pagination.hs b/src/Handler/Utils/Table/Pagination.hs index 91f731f75..125f500a3 100644 --- a/src/Handler/Utils/Table/Pagination.hs +++ b/src/Handler/Utils/Table/Pagination.hs @@ -1,4 +1,4 @@ --- SPDX-FileCopyrightText: 2022-24 Felix Hamann ,Gregor Kleen ,Sarah Vaupel ,Sarah Vaupel ,Steffen Jost ,Steffen Jost ,Winnie Ros ,Steffen Jost +-- SPDX-FileCopyrightText: 2022-24 Felix Hamann ,Gregor Kleen ,Sarah Vaupel ,Sarah Vaupel ,Steffen Jost ,Steffen Jost ,Winnie Ros ,Steffen Jost ,David Mosbach -- -- SPDX-License-Identifier: AGPL-3.0-or-later @@ -647,9 +647,10 @@ defaultDBSFilterLayout filterWdgt filterEnctype filterAction scrolltable , formAction = Just filterAction , formEncoding = filterEnctype , formAttrs = [("class", "table-filter-form"), ("autocomplete", "off")] - , formSubmit = FormAutoSubmit + , formSubmit = FormSubmit --FormAutoSubmit --TODO not for sync-tables , formAnchor = Nothing :: Maybe Text } + syncButton = [whamlet|
|]-- [whamlet|