From 380c1ed643b82a827997a6205c0f1fd60aa4d4ab Mon Sep 17 00:00:00 2001 From: patrikx3 Date: Sun, 19 Jan 2025 19:53:49 +0100 Subject: [PATCH] r0b08x [chore] 1/19/2025, 7:53:49 PM --- README.md | 4 +- package.json | 2 +- src/angular/pages/main/p3xr-main-key.js | 109 +++++++++++++++++++----- 3 files changed, 92 insertions(+), 23 deletions(-) diff --git a/README.md b/README.md index 6d91c1d..d950182 100644 --- a/README.md +++ b/README.md @@ -12,7 +12,7 @@ https://corifeus.com/redis-ui --- -# 💿 The p3x-redis-ui-material web interface that connects to the p3x-redis-ui-server via http and socket.io v2025.4.126 +# 💿 The p3x-redis-ui-material web interface that connects to the p3x-redis-ui-server via http and socket.io v2025.4.127 @@ -109,7 +109,7 @@ All my domains, including [patrikx3.com](https://patrikx3.com), [corifeus.eu](ht --- -[**P3X-REDIS-UI-MATERIAL**](https://corifeus.com/redis-ui-material) Build v2025.4.126 +[**P3X-REDIS-UI-MATERIAL**](https://corifeus.com/redis-ui-material) Build v2025.4.127 [![NPM](https://img.shields.io/npm/v/p3x-redis-ui-material.svg)](https://www.npmjs.com/package/p3x-redis-ui-material) [![Donate for Corifeus / P3X](https://img.shields.io/badge/Donate-Corifeus-003087.svg)](https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=QZVM4V6HVZJW6) [![Contact Corifeus / P3X](https://img.shields.io/badge/Contact-P3X-ff9900.svg)](https://www.patrikx3.com/en/front/contact) [![Like Corifeus @ Facebook](https://img.shields.io/badge/LIKE-Corifeus-3b5998.svg)](https://www.facebook.com/corifeus.software) diff --git a/package.json b/package.json index 1c84929..b7b509c 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "p3x-redis-ui-material", - "version": "2025.4.126", + "version": "2025.4.127", "description": "💿 The p3x-redis-ui-material web interface that connects to the p3x-redis-ui-server via http and socket.io", "corifeus": { "icon": "fas fa-database", diff --git a/src/angular/pages/main/p3xr-main-key.js b/src/angular/pages/main/p3xr-main-key.js index 80b14d3..34b05da 100644 --- a/src/angular/pages/main/p3xr-main-key.js +++ b/src/angular/pages/main/p3xr-main-key.js @@ -103,21 +103,44 @@ p3xr.ng.component('p3xrMainKey', { this.loading = false const loadKey = async (options = {}) => { - const { withoutParent = false } = options; - + $interval.cancel(interval) + let {withoutParent} = options + if (withoutParent === undefined) { + withoutParent = false + } + + + let hadError = undefined try { - this.loading = true; - + + // it can throw an error, when we switch the database + //p3xr.ui.overlay.show({ + // message: p3xr.strings.intention.getKey + //}) + this.loading = true + + setTimeout(() => { + $scope.$digest(); + }) + + //const type = p3xr.state.keysInfo[$stateParams.key].type + //console.warn('$stateParams.key', $stateParams.key) const response = await p3xrSocket.request({ action: 'key-get', - payload: { key: $stateParams.key }, - }); - + payload: { + key: $stateParams.key, + //type: type, + } + }) + this.response = response + + //const type = response.type if (response.ttl === -2) { - checkTtl(); + checkTtl() return; } - + response.size = 0 + const { type, valueBuffer } = response; switch (type) { @@ -170,23 +193,69 @@ p3xr.ng.component('p3xrMainKey', { response.value = valueBuffer.map((entry) => decodeStreamEntry(entry)); break; } - - //console.log('response', response); - this.response = response; - loadTtl(); + if (response.type !== 'stream') { + if (typeof response.valueBuffer === 'object' && response.length > 0) { + for (let keys of Object.keys(response.valueBuffer)) { + response.size += response.valueBuffer[keys].byteLength + } + } else if (Array.isArray(response.valueBuffer)) { + for (let i = 0; i < response.valueBuffer.length; i++) { + response.size += response.valueBuffer[i].byteLength + } + } else { + response.size = response.valueBuffer.byteLength + } + } else { + //console.log('response', response) + function sumMaxByteLength(arr) { + let total = 0; + + function processElement(element) { + if (ArrayBuffer.isView(element) || element instanceof ArrayBuffer) { + total += element.byteLength; + } else if (Array.isArray(element)) { + element.forEach(processElement); + } + } + + arr.forEach(processElement); + return total; + } + response.size = sumMaxByteLength(response.valueBuffer) + } + + if (response.ttl > -1) { + wasExpiring = true + } + loadTtl() + $scope.$digest() + } catch (e) { - console.error(e); + hadError = e + console.error(e) if (!p3xr.settings.handleConnectionIsClosed(e, $rootScope)) { - p3xrCommon.alert(p3xr.strings.label.unableToLoadKey({ key: $stateParams.key })); - } else { - p3xrCommon.alert(e.message); + p3xrCommon.alert(p3xr.strings.label.unableToLoadKey({ key: $stateParams.key })) + } else{ + p3xrCommon.alert(e.message) } + //p3xrCommon.generalHandleError(e) } finally { - this.loading = false; + //p3xr.ui.overlay.hide() + if (hadError !== undefined) { + $state.go('main.statistics'); + } else if (!withoutParent && $stateParams.resize !== null) { + $stateParams.resize() + } + + $timeout(() => { + this.loading = false + $scope.$digest() + }, p3xr.settings.debounce) + } - }; - + + } const generateHighlight = () => { $('#p3xr-theme-styles-tree-key').remove()