From 78cc187f3b58472c6282fd7f3bf4260814033205 Mon Sep 17 00:00:00 2001 From: johnnyq Date: Sat, 21 Nov 2026 21:33:55 -0500 Subject: [PATCH] QoL 79: the date filter box on list pages shows All Time or its date range from the first paint instead of filling in after the page loads --- CHANGELOG.md | 4 +++ admin/ai_usage.php | 2 +- admin/app_logs.php | 2 +- admin/audit_logs.php | 2 +- admin/getting_started.php | 2 ++ admin/mail_queue.php | 2 +- admin/sign_ins.php | 2 +- admin/text_messages.php | 2 +- agent/audit_log.php | 2 +- agent/client_onboarding.php | 2 ++ agent/clients.php | 2 +- agent/expenses.php | 2 +- agent/income.php | 2 +- agent/invoices.php | 2 +- agent/notifications.php | 2 +- agent/projects.php | 2 +- agent/quotes.php | 2 +- agent/tickets.php | 2 +- agent/transactions.php | 2 +- agent/trips.php | 2 +- agent/user/user_activity.php | 2 +- client/includes/header.php | 2 ++ css/itflow_custom.css | 7 ++++ functions/format.php | 18 +++++++++++ includes/header.php | 4 +++ js/date_filter.js | 6 ++++ js/itflow_select.js | 14 +++++--- js/itflow_select_early.js | 62 ++++++++++++++++++++++++++++++++++++ setup/index.php | 2 ++ 29 files changed, 136 insertions(+), 23 deletions(-) create mode 100644 js/itflow_select_early.js diff --git a/CHANGELOG.md b/CHANGELOG.md index 87ecb1c4a..fb287b800 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -25,6 +25,8 @@ Update from Maintenance > Update — Queue Update hands the job to cron, which u - RMM Providers: a device moved to another linked client in Tactical stayed with its asset at the first client, and that asset took the new client's location. It is now matched or made at the client it moved to. The first client's asset stays there, no longer kept up, and its history says where the device went. Devices that moved before this update are put right at the next sync. - RMM Providers: one server with many disks - more than 255 characters of them - stopped every sync of its provider with "Data too long for column 'asset_spec_value'", and as that client was always tried first, no client's devices were brought in again. A device's CPU and storage are now cut to fit, and a device that can't be saved for any other reason no longer stops the sync: the rest come in, and the provider's row names it. - RMM Providers: an answer from the RMM that wasn't a list - an error page sent as a success, or a change to its API - was read as a client with no devices, or an RMM with no clients, and everything in it would have been marked gone. It is now an error, and nothing is changed. +- Pickers: as a page loaded, a picker's "nothing" choice showed as "- Anyone -" for a moment before it became "Anyone" - on the tickets list's filters and in pickers across the app and the client portal. It is "Anyone", in its quieter grey, from the start. +- Lists: the date filter box - on tickets, invoices, quotes, expenses, the audit log and the rest - was empty as the page loaded, then filled in with All Time or its dates a moment later. It says so from the start. ### Developer Updates @@ -40,6 +42,8 @@ Update from Maintenance > Update — Queue Update hands the job to cron, which u - `rmmIsList()` - the Tactical kind's clients, devices and alerts answers must be JSON lists, or the call is an error. Another kind should do the same. - The sync's unlisted devices are held when at least `RMM_GONE_AT_ONCE` (3) of a client's live devices, and at least half, are missing from a whole list, until their `rmm_device_synced_at` - when they were last listed - is `RMM_GONE_HOLD_HOURS` (24) old. Held ids go to `rmmDeviceSave()` and `rmmAssetMatch()` as `$free`, so a reinstalled agent can still take an asset one of them has, deleting its row. Clients the RMM no longer lists stay in that clean-up while they have live devices, not only when first marked. The sync is `ok` false while any are held. - `rmmAlertsCleanup()`, from `cron/nightly_tasks.php`, deletes alerts cleared more than `RMM_ALERTS_KEEP_DAYS` (180) ago. Only open ones are read, so the minute's poll no longer scans every alert there has been. +- `js/itflow_select_early.js`, loaded in the `` of `includes/header.php`, `client/includes/header.php`, `agent/client_onboarding.php`, `admin/getting_started.php` and `setup/index.php` (a file, as the portal allows no inline scripts), watches the page as it is parsed and takes the dashes off a `- None -` option of a `select.select2`, marking it `data-none="1"` - before the first paint, so the raw ` + diff --git a/admin/app_logs.php b/admin/app_logs.php index a878c37f9..606f8a213 100644 --- a/admin/app_logs.php +++ b/admin/app_logs.php @@ -118,7 +118,7 @@ $filters_url = function ($modal) use ($dtf, $dtt, $view, $category_filter) {
- + diff --git a/admin/audit_logs.php b/admin/audit_logs.php index f47d295f9..9d572d542 100644 --- a/admin/audit_logs.php +++ b/admin/audit_logs.php @@ -130,7 +130,7 @@ $view_empty = [
- + diff --git a/admin/getting_started.php b/admin/getting_started.php index a42cd80c0..a1fb9317f 100644 --- a/admin/getting_started.php +++ b/admin/getting_started.php @@ -85,6 +85,8 @@ define('FROM_GETTING_STARTED', true); + + diff --git a/admin/mail_queue.php b/admin/mail_queue.php index c154dc108..aa938755e 100644 --- a/admin/mail_queue.php +++ b/admin/mail_queue.php @@ -131,7 +131,7 @@ $filtered_dates = isset($_GET['dtf']) && $_GET['dtf'] !== '' && $_GET['dtf'] !==
- +
diff --git a/admin/sign_ins.php b/admin/sign_ins.php index f839d2a11..79238899c 100644 --- a/admin/sign_ins.php +++ b/admin/sign_ins.php @@ -182,7 +182,7 @@ $audit_url = function (array $query) use ($dates_query) {
- + diff --git a/admin/text_messages.php b/admin/text_messages.php index a30fd3836..2b09942fa 100644 --- a/admin/text_messages.php +++ b/admin/text_messages.php @@ -129,7 +129,7 @@ $ready = smsReady();
- +
diff --git a/agent/audit_log.php b/agent/audit_log.php index d5a650cc4..84113585b 100644 --- a/agent/audit_log.php +++ b/agent/audit_log.php @@ -122,7 +122,7 @@ $view_empty = [
- + diff --git a/agent/client_onboarding.php b/agent/client_onboarding.php index fb42e0de8..2a541a790 100644 --- a/agent/client_onboarding.php +++ b/agent/client_onboarding.php @@ -98,6 +98,8 @@ define('FROM_CLIENT_ONBOARDING', true); + + diff --git a/agent/clients.php b/agent/clients.php index 4617e22f3..6d87954ae 100644 --- a/agent/clients.php +++ b/agent/clients.php @@ -500,7 +500,7 @@ $total_leads = intval($row['leads']);
- + diff --git a/agent/expenses.php b/agent/expenses.php index d372cf8b4..371e34be4 100644 --- a/agent/expenses.php +++ b/agent/expenses.php @@ -193,7 +193,7 @@ $month_change = $stats['last_to_date'] > 0 ? round(($stats['month'] - $stats['la
- + diff --git a/agent/income.php b/agent/income.php index 556bc90df..8e1222a15 100644 --- a/agent/income.php +++ b/agent/income.php @@ -192,7 +192,7 @@ $invoices_url = 'invoices.php?' . ($client_page ? "client_id=$client_id&" : '')
- + diff --git a/agent/invoices.php b/agent/invoices.php index 7bc4acc7a..486f0b113 100644 --- a/agent/invoices.php +++ b/agent/invoices.php @@ -247,7 +247,7 @@ $stat_money = function ($amount) use ($session_company_currency) {
- + diff --git a/agent/notifications.php b/agent/notifications.php index ab7183a5b..d77d377f2 100644 --- a/agent/notifications.php +++ b/agent/notifications.php @@ -115,7 +115,7 @@ $empty_state_skip = true;
- + diff --git a/agent/projects.php b/agent/projects.php index 65c7e9c87..be175cc73 100644 --- a/agent/projects.php +++ b/agent/projects.php @@ -260,7 +260,7 @@ $hidden_filter_count = $date_filter_active ? 1 : 0;
- + diff --git a/agent/quotes.php b/agent/quotes.php index 956962e60..84cdbdf61 100644 --- a/agent/quotes.php +++ b/agent/quotes.php @@ -189,7 +189,7 @@ $stat_monthly = function ($amount) use ($stat_money) {
- + diff --git a/agent/tickets.php b/agent/tickets.php index b5e4274f8..34920f8a8 100644 --- a/agent/tickets.php +++ b/agent/tickets.php @@ -502,7 +502,7 @@ $export_extra = [
- + diff --git a/agent/transactions.php b/agent/transactions.php index 45c78c58c..e073137a8 100644 --- a/agent/transactions.php +++ b/agent/transactions.php @@ -291,7 +291,7 @@ $is_card = $account && $account['type'] === 3;
- + diff --git a/agent/trips.php b/agent/trips.php index 38f56f76e..b48753d21 100644 --- a/agent/trips.php +++ b/agent/trips.php @@ -214,7 +214,7 @@ $add_url = 'modals/trip/trip_add.php' . ($client_page ? "?client_id=$client_id"
- + diff --git a/agent/user/user_activity.php b/agent/user/user_activity.php index ae775c06f..a28a60318 100644 --- a/agent/user/user_activity.php +++ b/agent/user/user_activity.php @@ -110,7 +110,7 @@ $view_empty = [
- + diff --git a/client/includes/header.php b/client/includes/header.php index f8bea9711..85b513d8f 100644 --- a/client/includes/header.php +++ b/client/includes/header.php @@ -92,6 +92,8 @@ $portal_contact_name = (string) ($contact['contact_name'] ?? ''); + + + + painted before the picker runs already says "Anyone" (js/itflow_select_early.js) */ ?> + + diff --git a/js/date_filter.js b/js/date_filter.js index 0e2a4771d..958510620 100644 --- a/js/date_filter.js +++ b/js/date_filter.js @@ -137,6 +137,12 @@ // first click starts a fresh selection. var allTimeActive = initialKey === ALL_TIME_START + '|' + ALL_TIME_END; + // The page wrote the words in the box already (dateFilterLabel() in functions/format.php), + // so it isn't empty until this runs. Flatpickr would try to read them as dates, so the box + // is emptied for it here - setDisplay() at the end puts the same words back in this same + // step, before the browser draws again, so nothing is seen to change. + input.value = ''; + flatpickr(input, { mode: 'range', dateFormat: 'Y-m-d', diff --git a/js/itflow_select.js b/js/itflow_select.js index 04608aeb3..329766465 100644 --- a/js/itflow_select.js +++ b/js/itflow_select.js @@ -46,7 +46,10 @@ * * functions/format.php has PHP helpers that write these for clients, users, * contacts, tags and categories. Labels written as "- Unassigned -" show - * without the dashes, in a quieter colour, as the "nothing" choice. + * without the dashes, in a quieter colour, as the "nothing" choice. On the + * page as it first loads, js/itflow_select_early.js has already taken the + * dashes off and marked the option data-none="1", so the plain : * @@ -191,7 +194,7 @@ option: option, value: option.value, label: none ? none[1] : raw, - none: !!none || option.value === '', + none: !!none || option.value === '' || data.none === '1', description: data.description || '', icon: icon && icon.indexOf('fa-') === -1 ? 'fas fa-' + icon : icon, image: data.image || '', @@ -398,11 +401,12 @@ return this.multiple ? 'Choose' : 'Select'; }; - /* The option that means "nothing" - an empty value, or a "- None -" label. */ + /* The option that means "nothing" - an empty value, or a "- None -" label (data-none="1" once + js/itflow_select_early.js has taken its dashes off). */ Picker.prototype.noneOption = function () { var options = this.select.options; for (var i = 0; i < options.length; i++) { - if (options[i].value === '' || NONE_LABEL.test(options[i].label || options[i].textContent || '')) { + if (options[i].value === '' || options[i].dataset.none === '1' || NONE_LABEL.test(options[i].label || options[i].textContent || '')) { return options[i]; } } @@ -418,7 +422,7 @@ } var none = this.noneOption(); var chosen = this.select.selectedOptions[0]; - return !!(none && chosen && chosen !== none && !NONE_LABEL.test(chosen.label || '')); + return !!(none && chosen && chosen !== none && chosen.dataset.none !== '1' && !NONE_LABEL.test(chosen.label || '')); }; Picker.prototype.chosen = function () { diff --git a/js/itflow_select_early.js b/js/itflow_select_early.js new file mode 100644 index 000000000..9626a9acd --- /dev/null +++ b/js/itflow_select_early.js @@ -0,0 +1,62 @@ +/* + * ITFlow select, before it runs - loaded in the , ahead of everything on the page. + * + * js/itflow_select.js draws every it has read so far. A "nothing" choice written + * "- Anyone -" showed with its dashes for that moment, then as "Anyone" once the picker drew it. + * This takes the dashes off those labels as the page is read, before anything is painted, and + * marks the option (data-none="1") so the picker still knows it is the "nothing" choice. Its + * quieter colour comes from css/itflow_custom.css. It stops once the page has been read - a + * select added later is drawn by the picker straight away, so it never shows the dashes. + * + * A file rather than an inline script: the client portal's pages allow no inline scripts. + */ +(function () { + 'use strict'; + + var NONE_LABEL = /^\s*-\s*(.*?)\s*-\s*$/; + + function tidy(option) { + if (!option || option.tagName !== 'OPTION' || option.dataset.none === '1' || option.hasAttribute('label')) { + return; + } + var select = option.closest('select'); + if (!select || !select.classList.contains('select2')) { + return; + } + var none = NONE_LABEL.exec(option.textContent || ''); + if (none && none[1] !== '') { + option.dataset.none = '1'; + option.textContent = none[1]; + } + } + + // As the parser adds each option, and the text inside it - in one piece or several + var watcher = new MutationObserver(function (records) { + records.forEach(function (record) { + if (record.type === 'characterData') { + tidy(record.target.parentNode); + return; + } + tidy(record.target); + record.addedNodes.forEach(function (node) { + if (node.nodeType !== 1) { + return; + } + if (node.tagName === 'OPTION') { + tidy(node); + } else if (node.firstElementChild) { + // Added with its insides already there - by a script, not the parser + node.querySelectorAll('select.select2 option').forEach(tidy); + } + }); + }); + }); + watcher.observe(document.documentElement, { childList: true, subtree: true, characterData: true }); + + // Once the page has been read: one last look, then stop + document.addEventListener('DOMContentLoaded', function () { + watcher.disconnect(); + document.querySelectorAll('select.select2 option').forEach(tidy); + }); +})(); diff --git a/setup/index.php b/setup/index.php index 2c59c48b4..2ca64ec75 100644 --- a/setup/index.php +++ b/setup/index.php @@ -545,6 +545,8 @@ $setup_title = ['restore' => 'Restore a backup', 'restored' => 'Backup restored' + +