From 0594af387f9679610fd1bc887db3915ce345c65b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20Marseault?= <22910497+Larsluph@users.noreply.github.com> Date: Thu, 20 Jul 2023 13:50:46 +0200 Subject: [PATCH] feat(units): customizable units (#984) --- package-lock.json | 74 ---------------- src/actions/DocumentTitle.ts | 17 ++-- src/components/Core/SpeedCard.vue | 27 +++--- src/components/Core/StorageCard.vue | 16 ++-- src/components/Navbar/SpeedGraph.vue | 21 ++--- .../Settings/Tabs/VueTorrent/VGeneral.vue | 77 ++++++++-------- .../Torrent/DashboardItems/AddedOn.vue | 8 +- .../Torrent/DashboardItems/AmountLeft.vue | 10 +-- .../Torrent/DashboardItems/Availability.vue | 6 +- .../Torrent/DashboardItems/Category.vue | 8 +- .../Torrent/DashboardItems/CompletedOn.vue | 6 +- .../Torrent/DashboardItems/ContentPath.vue | 6 +- .../Torrent/DashboardItems/DownloadLimit.vue | 12 +-- .../Torrent/DashboardItems/DownloadPath.vue | 6 +- .../Torrent/DashboardItems/DownloadSpeed.vue | 12 +-- .../Torrent/DashboardItems/Downloaded.vue | 10 +-- .../DashboardItems/DownloadedSession.vue | 10 +-- src/components/Torrent/DashboardItems/ETA.vue | 6 +- .../Torrent/DashboardItems/GlobalSpeed.vue | 12 +-- .../Torrent/DashboardItems/GlobalVolume.vue | 10 +-- .../Torrent/DashboardItems/Hash.vue | 6 +- .../Torrent/DashboardItems/InfoHashV1.vue | 6 +- .../Torrent/DashboardItems/InfoHashV2.vue | 6 +- .../Torrent/DashboardItems/LastActivity.vue | 6 +- .../Torrent/DashboardItems/Peers.vue | 6 +- .../Torrent/DashboardItems/Progress.vue | 10 +-- .../Torrent/DashboardItems/Ratio.vue | 6 +- .../Torrent/DashboardItems/SavePath.vue | 8 +- .../Torrent/DashboardItems/Seeds.vue | 6 +- .../Torrent/DashboardItems/SeenComplete.vue | 6 +- .../Torrent/DashboardItems/Size.vue | 10 +-- .../Torrent/DashboardItems/Status.vue | 6 +- .../Torrent/DashboardItems/Tags.vue | 6 +- .../Torrent/DashboardItems/TimeActive.vue | 6 +- .../Torrent/DashboardItems/TotalSize.vue | 10 +-- .../Torrent/DashboardItems/Tracker.vue | 6 +- .../Torrent/DashboardItems/TrackersCount.vue | 6 +- .../Torrent/DashboardItems/UploadLimit.vue | 12 +-- .../Torrent/DashboardItems/UploadSpeed.vue | 12 +-- .../Torrent/DashboardItems/Uploaded.vue | 10 +-- .../DashboardItems/UploadedSession.vue | 10 +-- src/components/Torrent/MobileCard.vue | 59 +++++++------ src/components/TorrentDetail/Tabs/Content.vue | 6 +- .../TorrentDetail/Tabs/DetailPeers.vue | 17 ++-- src/components/TorrentDetail/Tabs/Info.vue | 20 ++--- .../TorrentDetail/Tabs/Overview.vue | 29 +++--- src/filters.ts | 88 ++++++++----------- src/helpers.js | 16 ---- src/lang/en.json | 2 + src/mixins/TorrentDashboardItem.ts | 4 +- src/schemas/StoreState.ts | 4 + src/store/getters.ts | 8 +- src/store/index.ts | 2 + src/types/vuetorrent/WebUISettings.ts | 2 + tests/helpers.js | 7 +- tests/unit/DesktopCard.spec.js | 3 +- tests/unit/SpeedCard.spec.js | 27 +++--- tests/unit/StorageCard.spec.js | 30 +++++-- tests/unit/__snapshots__/General.spec.ts.snap | 68 ++++++++------ tests/unit/filters.spec.js | 56 +++++++++++- 60 files changed, 444 insertions(+), 518 deletions(-) diff --git a/package-lock.json b/package-lock.json index 5e98bcbd..f26a7444 100644 --- a/package-lock.json +++ b/package-lock.json @@ -2876,23 +2876,6 @@ "url": "https://opencollective.com/typescript-eslint" } }, - "node_modules/@typescript-eslint/scope-manager": { - "version": "6.0.0", - "resolved": "https://registry.npmjs.org/@typescript-eslint/scope-manager/-/scope-manager-6.0.0.tgz", - "integrity": "sha512-o4q0KHlgCZTqjuaZ25nw5W57NeykZT9LiMEG4do/ovwvOcPnDO1BI5BQdCsUkjxFyrCL0cSzLjvIMfR9uo7cWg==", - "dev": true, - "dependencies": { - "@typescript-eslint/types": "6.0.0", - "@typescript-eslint/visitor-keys": "6.0.0" - }, - "engines": { - "node": "^16.0.0 || >=18.0.0" - }, - "funding": { - "type": "opencollective", - "url": "https://opencollective.com/typescript-eslint" - } - }, "node_modules/@typescript-eslint/type-utils": { "version": "6.1.0", "resolved": "https://registry.npmjs.org/@typescript-eslint/type-utils/-/type-utils-6.1.0.tgz", @@ -2977,46 +2960,6 @@ "url": "https://opencollective.com/typescript-eslint" } }, - "node_modules/@typescript-eslint/types": { - "version": "6.0.0", - "resolved": "https://registry.npmjs.org/@typescript-eslint/types/-/types-6.0.0.tgz", - "integrity": "sha512-Zk9KDggyZM6tj0AJWYYKgF0yQyrcnievdhG0g5FqyU3Y2DRxJn4yWY21sJC0QKBckbsdKKjYDV2yVrrEvuTgxg==", - "dev": true, - "engines": { - "node": "^16.0.0 || >=18.0.0" - }, - "funding": { - "type": "opencollective", - "url": "https://opencollective.com/typescript-eslint" - } - }, - "node_modules/@typescript-eslint/typescript-estree": { - "version": "6.0.0", - "resolved": "https://registry.npmjs.org/@typescript-eslint/typescript-estree/-/typescript-estree-6.0.0.tgz", - "integrity": "sha512-2zq4O7P6YCQADfmJ5OTDQTP3ktajnXIRrYAtHM9ofto/CJZV3QfJ89GEaM2BNGeSr1KgmBuLhEkz5FBkS2RQhQ==", - "dev": true, - "dependencies": { - "@typescript-eslint/types": "6.0.0", - "@typescript-eslint/visitor-keys": "6.0.0", - "debug": "^4.3.4", - "globby": "^11.1.0", - "is-glob": "^4.0.3", - "semver": "^7.5.0", - "ts-api-utils": "^1.0.1" - }, - "engines": { - "node": "^16.0.0 || >=18.0.0" - }, - "funding": { - "type": "opencollective", - "url": "https://opencollective.com/typescript-eslint" - }, - "peerDependenciesMeta": { - "typescript": { - "optional": true - } - } - }, "node_modules/@typescript-eslint/utils": { "version": "6.1.0", "resolved": "https://registry.npmjs.org/@typescript-eslint/utils/-/utils-6.1.0.tgz", @@ -3116,23 +3059,6 @@ "url": "https://opencollective.com/typescript-eslint" } }, - "node_modules/@typescript-eslint/visitor-keys": { - "version": "6.0.0", - "resolved": "https://registry.npmjs.org/@typescript-eslint/visitor-keys/-/visitor-keys-6.0.0.tgz", - "integrity": "sha512-cvJ63l8c0yXdeT5POHpL0Q1cZoRcmRKFCtSjNGJxPkcP571EfZMcNbzWAc7oK3D1dRzm/V5EwtkANTZxqvuuUA==", - "dev": true, - "dependencies": { - "@typescript-eslint/types": "6.0.0", - "eslint-visitor-keys": "^3.4.1" - }, - "engines": { - "node": "^16.0.0 || >=18.0.0" - }, - "funding": { - "type": "opencollective", - "url": "https://opencollective.com/typescript-eslint" - } - }, "node_modules/@vitejs/plugin-vue2": { "version": "2.2.0", "resolved": "https://registry.npmjs.org/@vitejs/plugin-vue2/-/plugin-vue2-2.2.0.tgz", diff --git a/src/actions/DocumentTitle.ts b/src/actions/DocumentTitle.ts index 11ac4ff2..7e259474 100644 --- a/src/actions/DocumentTitle.ts +++ b/src/actions/DocumentTitle.ts @@ -1,5 +1,7 @@ -import { formatBytes } from '@/helpers' import store from '@/store' +import {formatSpeed} from '@/filters' +import {formatProgress} from '@/filters' +import {Torrent} from '@/models' export class DocumentTitle { private static setDefault() { @@ -8,25 +10,26 @@ export class DocumentTitle { private static setGlobalSpeed() { const status = store.getters.getStatus() - this.set(`[D: ${formatBytes(status.dlspeed)}/s, U: ${formatBytes(status.upspeed)}/s] VueTorrent`) + const useBitSpeed = store.state.webuiSettings.useBitSpeed + this.set(`[D: ${formatSpeed(status.dlspeed, useBitSpeed)}, U: ${formatSpeed(status.upspeed, useBitSpeed)}] VueTorrent`) } private static setFirstTorrentStatus() { - const torrents = store.getters.getTorrents() - if (!torrents && !torrents.length) return + const useBitSpeed = store.state.webuiSettings.useBitSpeed + const torrents: Torrent[] = store.getters.getTorrents() + if (!torrents || !torrents.length) return const torrent = torrents[0] - this.set(`[D: ${formatBytes(torrent.dlspeed)}/s, U: ${formatBytes(torrent.upspeed)}/s] ${torrent.progress}%`) + this.set(`[D: ${formatSpeed(torrent.dlspeed, useBitSpeed)}, U: ${formatSpeed(torrent.upspeed, useBitSpeed)}] ${formatProgress(torrent.progress)}`) } public static update() { const mode = store.getters.getWebuiSettings().title switch (mode) { - case 'Default': - return this.setDefault() case 'Global Speed': return this.setGlobalSpeed() case 'First Torrent Status': return this.setFirstTorrentStatus() + case 'Default': default: return this.setDefault() } diff --git a/src/components/Core/SpeedCard.vue b/src/components/Core/SpeedCard.vue index a066fb0d..74dba3fb 100644 --- a/src/components/Core/SpeedCard.vue +++ b/src/components/Core/SpeedCard.vue @@ -8,41 +8,34 @@ - - {{ value | getSpeedValue }} - + {{ value | formatSpeedValue(shouldUseBitSpeed()) }} - {{ value | getDataUnit(1) }}/s + {{ value | formatSpeedUnit(shouldUseBitSpeed()) }} -