From 57b9acaeef407e16853103593a440a725b6f3964 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20Marseault?= <22910497+Larsluph@users.noreply.github.com> Date: Sun, 19 Mar 2023 10:34:38 +0100 Subject: [PATCH] perf: Add missing fields in dashboard / sortOptions (#713) @Larsluph --- .../Settings/Tabs/VueTorrent/VDesktopCard.vue | 39 +- .../Settings/Tabs/VueTorrent/VGeneral.vue | 1 + .../Settings/Tabs/VueTorrent/VMobileCard.vue | 24 +- .../Torrent/DashboardItems/AddedOn.vue | 2 +- .../Torrent/DashboardItems/AmountLeft.vue | 25 ++ .../Torrent/DashboardItems/Availability.vue | 2 +- .../Torrent/DashboardItems/Category.vue | 2 +- .../Torrent/DashboardItems/CompletedOn.vue | 2 +- .../Torrent/DashboardItems/ContentPath.vue | 20 + .../Torrent/DashboardItems/DownloadLimit.vue | 23 ++ .../Torrent/DashboardItems/DownloadPath.vue | 20 + .../{Download.vue => DownloadSpeed.vue} | 4 +- .../Torrent/DashboardItems/Downloaded.vue | 6 +- .../DashboardItems/DownloadedSession.vue | 25 ++ src/components/Torrent/DashboardItems/ETA.vue | 2 +- .../Torrent/DashboardItems/GlobalSpeed.vue | 2 +- .../Torrent/DashboardItems/GlobalVolume.vue | 2 +- .../Torrent/DashboardItems/Hash.vue | 20 + .../Torrent/DashboardItems/InfoHashV1.vue | 20 + .../Torrent/DashboardItems/InfoHashV2.vue | 20 + .../Torrent/DashboardItems/LastActivity.vue | 2 +- .../Torrent/DashboardItems/Peers.vue | 6 +- .../Torrent/DashboardItems/Progress.vue | 2 +- .../Torrent/DashboardItems/Ratio.vue | 2 +- .../{Directory.vue => SavePath.vue} | 4 +- .../Torrent/DashboardItems/Seeds.vue | 4 +- .../Torrent/DashboardItems/SeenComplete.vue | 20 + .../Torrent/DashboardItems/Size.vue | 2 +- .../Torrent/DashboardItems/Status.vue | 2 +- .../Torrent/DashboardItems/Tags.vue | 2 +- .../Torrent/DashboardItems/TimeActive.vue | 20 + .../Torrent/DashboardItems/TotalSize.vue | 25 ++ .../Torrent/DashboardItems/Tracker.vue | 4 +- .../Torrent/DashboardItems/TrackersCount.vue | 20 + .../Torrent/DashboardItems/UploadLimit.vue | 23 ++ .../{Upload.vue => UploadSpeed.vue} | 4 +- .../Torrent/DashboardItems/Uploaded.vue | 2 +- .../DashboardItems/UploadedSession.vue | 4 +- .../Torrent/DashboardItems/index.ts | 98 +++-- src/components/Torrent/MobileCard.vue | 16 +- src/components/TorrentDetail/Tabs/Info.vue | 4 +- src/enums/vuetorrent/DashboardProperty.ts | 48 ++- src/lang/en.json | 99 ++++- src/models/Torrent.ts | 131 +++--- src/schemas/StoreState.ts | 56 ++- src/store/index.ts | 24 +- src/types/qbit/models/Torrent.ts | 99 +++-- src/views/Dashboard.vue | 79 ++-- tests/unit/DesktopCard.spec.js | 153 +++---- tests/unit/MobileCard.spec.js | 85 ++++ .../__snapshots__/DesktopCard.spec.js.snap | 376 +++++++++++++++++- .../__snapshots__/MobileCard.spec.js.snap | 178 +++++++++ 52 files changed, 1474 insertions(+), 381 deletions(-) create mode 100644 src/components/Torrent/DashboardItems/AmountLeft.vue create mode 100644 src/components/Torrent/DashboardItems/ContentPath.vue create mode 100644 src/components/Torrent/DashboardItems/DownloadLimit.vue create mode 100644 src/components/Torrent/DashboardItems/DownloadPath.vue rename src/components/Torrent/DashboardItems/{Download.vue => DownloadSpeed.vue} (84%) create mode 100644 src/components/Torrent/DashboardItems/DownloadedSession.vue create mode 100644 src/components/Torrent/DashboardItems/Hash.vue create mode 100644 src/components/Torrent/DashboardItems/InfoHashV1.vue create mode 100644 src/components/Torrent/DashboardItems/InfoHashV2.vue rename src/components/Torrent/DashboardItems/{Directory.vue => SavePath.vue} (82%) create mode 100644 src/components/Torrent/DashboardItems/SeenComplete.vue create mode 100644 src/components/Torrent/DashboardItems/TimeActive.vue create mode 100644 src/components/Torrent/DashboardItems/TotalSize.vue create mode 100644 src/components/Torrent/DashboardItems/TrackersCount.vue create mode 100644 src/components/Torrent/DashboardItems/UploadLimit.vue rename src/components/Torrent/DashboardItems/{Upload.vue => UploadSpeed.vue} (85%) create mode 100644 tests/unit/MobileCard.spec.js create mode 100644 tests/unit/__snapshots__/MobileCard.spec.js.snap diff --git a/src/components/Settings/Tabs/VueTorrent/VDesktopCard.vue b/src/components/Settings/Tabs/VueTorrent/VDesktopCard.vue index a6383335..6d15da5a 100644 --- a/src/components/Settings/Tabs/VueTorrent/VDesktopCard.vue +++ b/src/components/Settings/Tabs/VueTorrent/VDesktopCard.vue @@ -54,6 +54,7 @@ import draggable from 'vuedraggable' import { mdiMenu } from '@mdi/js' import { i18n } from '@/plugins/i18n' +import { mapState } from 'vuex' export default { name: 'VDesktopCard', @@ -64,41 +65,23 @@ export default { mdiMenu }), computed: { + ...mapState(['webuiSettings']), busyDesktopTorrentProperties() { - return this.injectLocalization(this.$store.state.webuiSettings.busyDesktopTorrentProperties) + return this.injectLocalization(this.webuiSettings.busyDesktopTorrentProperties) }, doneDesktopTorrentProperties() { - return this.injectLocalization(this.$store.state.webuiSettings.doneDesktopTorrentProperties) + return this.injectLocalization(this.webuiSettings.doneDesktopTorrentProperties) } }, methods: { injectLocalization(properties) { - const localePrefix = 'modals.settings.pageVueTorrent.properties' - const localeMap = { - Size: i18n.t(`${localePrefix}.size`), - Progress: i18n.t(`${localePrefix}.progress`), - Download: i18n.t(`${localePrefix}.downloadSpeed`), - Upload: i18n.t(`${localePrefix}.uploadSpeed`), - Downloaded: i18n.t(`${localePrefix}.downloaded`), - Directory: i18n.t(`${localePrefix}.save_path`), - Uploaded: i18n.t(`${localePrefix}.uploaded`), - ETA: i18n.t(`${localePrefix}.ETA`), - Peers: i18n.t(`${localePrefix}.peers`), - Seeds: i18n.t(`${localePrefix}.seeds`), - Status: i18n.t(`${localePrefix}.state`), - Ratio: i18n.t(`${localePrefix}.ratio`), - Tracker: i18n.t(`${localePrefix}.tracker`), - Category: i18n.t(`${localePrefix}.category`), - Tags: i18n.t(`${localePrefix}.tags`), - AddedOn: i18n.t(`${localePrefix}.addedOn`), - Availability: i18n.t(`${localePrefix}.availability`), - LastActivity: i18n.t(`${localePrefix}.last_activity`), - CompletedOn: i18n.t(`${localePrefix}.completion_on`), - GlobalSpeed: i18n.t(`${localePrefix}.globalSpeed`), - GlobalVolume: i18n.t(`${localePrefix}.globalVolume`) - } - - properties.forEach(property => (property.label = localeMap[property.name])) + properties.forEach(property => { + // convert component name from PascalCase to snake_case to match locale key + const value = property.name + .replace(/\.?([A-Z]+)/g, (x, y) => "_" + y.toLowerCase()) + .replace(/^_/, "") + property.label = i18n.t(`torrent.properties.${value}`) + }) return properties } } diff --git a/src/components/Settings/Tabs/VueTorrent/VGeneral.vue b/src/components/Settings/Tabs/VueTorrent/VGeneral.vue index e61bfba1..6287ca12 100644 --- a/src/components/Settings/Tabs/VueTorrent/VGeneral.vue +++ b/src/components/Settings/Tabs/VueTorrent/VGeneral.vue @@ -276,6 +276,7 @@ export default { const ajv = new Ajv() const validate = ajv.compile(StoreStateSchema) isValidJson = validate(userState) + console.error(validate.errors) } catch (e) { console.error(e) isValidJson = false diff --git a/src/components/Settings/Tabs/VueTorrent/VMobileCard.vue b/src/components/Settings/Tabs/VueTorrent/VMobileCard.vue index 5f9cc2dc..4d324b18 100644 --- a/src/components/Settings/Tabs/VueTorrent/VMobileCard.vue +++ b/src/components/Settings/Tabs/VueTorrent/VMobileCard.vue @@ -61,24 +61,12 @@ export default { }, methods: { injectLocalization(properties) { - const localePrefix = 'modals.settings.pageVueTorrent.properties' - const localeMap = { - Size: i18n.t(`${localePrefix}.size`), - Progress: i18n.t(`${localePrefix}.progress`), - Download: i18n.t(`${localePrefix}.downloadSpeed`), - Upload: i18n.t(`${localePrefix}.uploadSpeed`), - ETA: i18n.t(`${localePrefix}.ETA`), - Peers: i18n.t(`${localePrefix}.peers`), - Seeds: i18n.t(`${localePrefix}.seeds`), - Status: i18n.t(`${localePrefix}.state`), - Ratio: i18n.t(`${localePrefix}.ratio`), - Uploaded: i18n.t(`${localePrefix}.uploaded`), - Tracker: i18n.t(`${localePrefix}.tracker`), - Category: i18n.t(`${localePrefix}.category`), - Tags: i18n.t(`${localePrefix}.tags`) - } - - properties.forEach(property => (property.label = localeMap[property.name])) + properties.forEach(property => { + const value = property.name + .replace(/\.?([A-Z]+)/g, (x, y) => "_" + y.toLowerCase()) + .replace(/^_/, "") + property.label = i18n.t(`torrent.properties.${value}`) + }) return properties } } diff --git a/src/components/Torrent/DashboardItems/AddedOn.vue b/src/components/Torrent/DashboardItems/AddedOn.vue index 04f9e81d..78d24365 100644 --- a/src/components/Torrent/DashboardItems/AddedOn.vue +++ b/src/components/Torrent/DashboardItems/AddedOn.vue @@ -1,7 +1,7 @@