From 8495d5b165d4705c8082b4efe94f4446c75692cd Mon Sep 17 00:00:00 2001 From: Someone <10882916+InterN0te@users.noreply.github.com> Date: Mon, 6 Nov 2023 00:15:20 +0000 Subject: [PATCH 01/11] Added global ratio (only selected labels) and filtered torrents list ratio --- .../locales/en/modules/torrents-status.json | 8 +++++- src/widgets/torrent/TorrentTile.tsx | 26 ++++++++++++++++++- 2 files changed, 32 insertions(+), 2 deletions(-) diff --git a/public/locales/en/modules/torrents-status.json b/public/locales/en/modules/torrents-status.json index 3f83a6396..cdca86767 100644 --- a/public/locales/en/modules/torrents-status.json +++ b/public/locales/en/modules/torrents-status.json @@ -19,13 +19,19 @@ "labelFilter": { "label": "Label list", "description": "When 'is whitelist' checked, this will act as a whitelist. If not checked, this is a blacklist. Will not do anything when empty" + }, + "displayRatioWithFilter": { + "label": "View filtered torrent list ratio", + "description": "When 'is whitelist' checked, this will act as a whitelist. If not checked, this is a blacklist. Will not do anything when empty" } } }, "card": { "footer": { "error": "Error", - "lastUpdated": "Last updated {{time}} ago" + "lastUpdated": "Last updated {{time}} ago", + "ratioGlobal": "Global ratio", + "ratioWithFilter": "Ratio with filter" }, "table": { "header": { diff --git a/src/widgets/torrent/TorrentTile.tsx b/src/widgets/torrent/TorrentTile.tsx index 79c52b28d..d2316101d 100644 --- a/src/widgets/torrent/TorrentTile.tsx +++ b/src/widgets/torrent/TorrentTile.tsx @@ -52,6 +52,10 @@ const definition = defineWidget({ type: 'multiple-text', defaultValue: [] as string[], }, + displayRatioWithFilter: { + type: 'switch', + defaultValue: true, + }, }, gridstack: { minWidth: 2, @@ -140,6 +144,9 @@ function TorrentTile({ widget }: TorrentTileProps) { const duration = dayjs.duration(difference, 'ms'); const humanizedDuration = duration.humanize(); + const ratioGlobal = getRatio(widget, torrents, false); + const ratioWithFilter = getRatio(widget, torrents, true); + return ( @@ -184,7 +191,7 @@ function TorrentTile({ widget }: TorrentTileProps) { )} - {t('card.footer.lastUpdated', { time: humanizedDuration })} + {t('card.footer.lastUpdated', { time: humanizedDuration })} - {t('card.footer.ratioGlobal')} : {ratioGlobal === -1 ? "∞" : ratioGlobal.toFixed(2)} {widget.properties.displayRatioWithFilter && ` - ${t('card.footer.ratioWithFilter')} : ${ratioWithFilter === -1 ? "∞" : ratioWithFilter.toFixed(2)}`} @@ -230,4 +237,21 @@ const filterTorrentsByLabels = ( return torrents.filter((torrent) => !labels.includes(torrent.label as string)); }; +const getRatio = ( + widget: ITorrent, + torrents: NormalizedTorrent[], + applyAllFilter:boolean +) => { + + if(applyAllFilter) { + torrents = filterTorrents(widget,torrents) + } else { + torrents = filterTorrentsByLabels(torrents, widget.properties.labelFilter,widget.properties.labelFilterIsWhitelist) + } + + let totalDownloadedSum = torrents.reduce((sum, torrent) => sum + torrent.totalDownloaded, 0); + + return totalDownloadedSum > 0 ? torrents.reduce((sum, torrent) => sum + torrent.totalUploaded, 0) / totalDownloadedSum : -1; +} + export default definition; From 37191b971b75c72f0de20ba1ce65ff61392e1404 Mon Sep 17 00:00:00 2001 From: Someone <10882916+InterN0te@users.noreply.github.com> Date: Mon, 6 Nov 2023 00:18:24 +0000 Subject: [PATCH 02/11] Used label filter only if necessary --- src/widgets/torrent/TorrentTile.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/widgets/torrent/TorrentTile.tsx b/src/widgets/torrent/TorrentTile.tsx index d2316101d..700903cac 100644 --- a/src/widgets/torrent/TorrentTile.tsx +++ b/src/widgets/torrent/TorrentTile.tsx @@ -245,7 +245,7 @@ const getRatio = ( if(applyAllFilter) { torrents = filterTorrents(widget,torrents) - } else { + } else if (widget.properties.labelFilter.length > 0) { torrents = filterTorrentsByLabels(torrents, widget.properties.labelFilter,widget.properties.labelFilterIsWhitelist) } From 8abec93aad742c3df2346b35534cfa4becf5f14f Mon Sep 17 00:00:00 2001 From: Someone <10882916+InterN0te@users.noreply.github.com> Date: Mon, 6 Nov 2023 01:51:55 +0100 Subject: [PATCH 03/11] Update torrents-status.json Fix label and description --- public/locales/en/modules/torrents-status.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/public/locales/en/modules/torrents-status.json b/public/locales/en/modules/torrents-status.json index cdca86767..d78e4e016 100644 --- a/public/locales/en/modules/torrents-status.json +++ b/public/locales/en/modules/torrents-status.json @@ -21,8 +21,8 @@ "description": "When 'is whitelist' checked, this will act as a whitelist. If not checked, this is a blacklist. Will not do anything when empty" }, "displayRatioWithFilter": { - "label": "View filtered torrent list ratio", - "description": "When 'is whitelist' checked, this will act as a whitelist. If not checked, this is a blacklist. Will not do anything when empty" + "label": "Display filtered torrents list ratio", + "description": "If disable, only global ratio will be display. Global ratio still use labels if set" } } }, From c8dc3abab6d98ba42ec022cdd696b20abe1eee32 Mon Sep 17 00:00:00 2001 From: Someone <10882916+InterN0te@users.noreply.github.com> Date: Mon, 6 Nov 2023 01:54:55 +0100 Subject: [PATCH 04/11] Rename fonction to more explicite name --- src/widgets/torrent/TorrentTile.tsx | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/widgets/torrent/TorrentTile.tsx b/src/widgets/torrent/TorrentTile.tsx index 700903cac..02b7d1441 100644 --- a/src/widgets/torrent/TorrentTile.tsx +++ b/src/widgets/torrent/TorrentTile.tsx @@ -144,8 +144,8 @@ function TorrentTile({ widget }: TorrentTileProps) { const duration = dayjs.duration(difference, 'ms'); const humanizedDuration = duration.humanize(); - const ratioGlobal = getRatio(widget, torrents, false); - const ratioWithFilter = getRatio(widget, torrents, true); + const ratioGlobal = getTorrentsRatio(widget, torrents, false); + const ratioWithFilter = getTorrentsRatio(widget, torrents, true); return ( @@ -237,7 +237,7 @@ const filterTorrentsByLabels = ( return torrents.filter((torrent) => !labels.includes(torrent.label as string)); }; -const getRatio = ( +const getTorrentsRatio = ( widget: ITorrent, torrents: NormalizedTorrent[], applyAllFilter:boolean From 69d1e4e491730d0aba2dd4dc0829dea3da314844 Mon Sep 17 00:00:00 2001 From: Someone <10882916+InterN0te@users.noreply.github.com> Date: Mon, 6 Nov 2023 02:28:07 +0100 Subject: [PATCH 05/11] Add Calcul ratio test --- src/widgets/torrent/TorrentTile.spec.ts | 129 ++++++++++++++++++++---- 1 file changed, 110 insertions(+), 19 deletions(-) diff --git a/src/widgets/torrent/TorrentTile.spec.ts b/src/widgets/torrent/TorrentTile.spec.ts index f3a4148fd..99104fbc1 100644 --- a/src/widgets/torrent/TorrentTile.spec.ts +++ b/src/widgets/torrent/TorrentTile.spec.ts @@ -1,7 +1,7 @@ import { NormalizedTorrent, TorrentState } from '@ctrl/shared-torrent'; import { describe, expect, it } from 'vitest'; -import { ITorrent, filterTorrents } from './TorrentTile'; +import { ITorrent, filterTorrents, getTorrentsRatio } from './TorrentTile'; describe('TorrentTile', () => { it('filter torrents when stale', () => { @@ -20,13 +20,15 @@ describe('TorrentTile', () => { labelFilter: [], labelFilterIsWhitelist: false, displayCompletedTorrents: true, + displayActiveTorrents: true, + speedLimitOfActiveTorrents: 10, displayStaleTorrents: false, }, }; const torrents: NormalizedTorrent[] = [ - constructTorrent('ABC', 'Nice Torrent', false, 672), - constructTorrent('HH', 'I am completed', true, 0), - constructTorrent('HH', 'I am stale', false, 0), + constructTorrent('ABC', 'Nice Torrent', false, 672, 672), + constructTorrent('HH', 'I am completed', true, 0, 0), + constructTorrent('HH', 'I am stale', false, 0, 0), ]; // act @@ -55,13 +57,15 @@ describe('TorrentTile', () => { labelFilter: [], labelFilterIsWhitelist: false, displayCompletedTorrents: true, + displayActiveTorrents: true, + speedLimitOfActiveTorrents: 10, displayStaleTorrents: true, }, }; const torrents: NormalizedTorrent[] = [ - constructTorrent('ABC', 'Nice Torrent', false, 672), - constructTorrent('HH', 'I am completed', true, 0), - constructTorrent('HH', 'I am stale', false, 0), + constructTorrent('ABC', 'Nice Torrent', false, 672, 672), + constructTorrent('HH', 'I am completed', true, 0, 0), + constructTorrent('HH', 'I am stale', false, 0, 0), ]; // act @@ -74,7 +78,7 @@ describe('TorrentTile', () => { expect(filtered.includes(torrents[2])).toBe(true); }); - it('filter when completed', () => { + it('filter when completed without active torrent', () => { // arrange const widget: ITorrent = { id: 'abc', @@ -90,13 +94,15 @@ describe('TorrentTile', () => { labelFilter: [], labelFilterIsWhitelist: false, displayCompletedTorrents: false, + displayActiveTorrents: false, + speedLimitOfActiveTorrents: 10, displayStaleTorrents: true, }, }; const torrents: NormalizedTorrent[] = [ - constructTorrent('ABC', 'Nice Torrent', false, 672), - constructTorrent('HH', 'I am completed', true, 0), - constructTorrent('HH', 'I am stale', false, 0), + constructTorrent('ABC', 'Nice Torrent', false, 672, 672), + constructTorrent('HH', 'I am completed', true, 0, 672), + constructTorrent('HH', 'I am stale', false, 0, 0), ]; // act @@ -109,6 +115,47 @@ describe('TorrentTile', () => { expect(filtered.at(1)).toBe(torrents[2]); }); + it('filter when completed with active torrent', () => { + // arrange + const widget: ITorrent = { + id: 'abc', + area: { + type: 'sidebar', + properties: { + location: 'left', + }, + }, + shape: {}, + type: 'torrents-status', + properties: { + labelFilter: [], + labelFilterIsWhitelist: false, + displayCompletedTorrents: false, + displayActiveTorrents: true, + speedLimitOfActiveTorrents: 10, + displayStaleTorrents: true, + }, + }; + const torrents: NormalizedTorrent[] = [ + constructTorrent('ABC', 'Nice Torrent', false, 672, 672), + constructTorrent('HH', 'I am completed and uploading less than 10 ko/s (10239 ≈ 9.99ko/s)', true, 0, 10239), + constructTorrent('HH', 'I am completed and uploading more than 10 ko/s (10241 ≈ 10.01ko/s)', true, 0, 10241), + constructTorrent('HH', 'I am completed', true, 0, 0), + constructTorrent('HH', 'I am stale', false, 0, 0), + ]; + + // act + const filtered = filterTorrents(widget, torrents); + + // assert + expect(filtered.length).toBe(3); + expect(filtered.at(0)).toBe(torrents[0]); + expect(filtered.includes(torrents[1])).toBe(false); + expect(filtered.at(1)).toBe(torrents[2]); + expect(filtered.includes(torrents[3])).toBe(false); + expect(filtered.at(2)).toBe(torrents[4]); + }); + it('filter by label when whitelist', () => { // arrange const widget: ITorrent = { @@ -125,13 +172,15 @@ describe('TorrentTile', () => { labelFilter: ['music', 'movie'], labelFilterIsWhitelist: true, displayCompletedTorrents: true, + displayActiveTorrents: true, + speedLimitOfActiveTorrents: 10, displayStaleTorrents: true, }, }; const torrents: NormalizedTorrent[] = [ - constructTorrent('1', 'A sick drop', false, 672, 'music'), - constructTorrent('2', 'I cried', true, 0, 'movie'), - constructTorrent('3', 'Great Animations', false, 0, 'anime'), + constructTorrent('1', 'A sick drop', false, 672, 672, 'music'), + constructTorrent('2', 'I cried', true, 0, 0, 'movie'), + constructTorrent('3', 'Great Animations', false, 0, 0, 'anime'), ]; // act @@ -160,13 +209,15 @@ describe('TorrentTile', () => { labelFilter: ['music', 'movie'], labelFilterIsWhitelist: false, displayCompletedTorrents: false, + displayActiveTorrents: false, + speedLimitOfActiveTorrents: 10, displayStaleTorrents: true, }, }; const torrents: NormalizedTorrent[] = [ - constructTorrent('ABC', 'Nice Torrent', false, 672, 'anime'), - constructTorrent('HH', 'I am completed', true, 0, 'movie'), - constructTorrent('HH', 'I am stale', false, 0, 'tv'), + constructTorrent('ABC', 'Nice Torrent', false, 672, 672, 'anime'), + constructTorrent('HH', 'I am completed', true, 0, 0, 'movie'), + constructTorrent('HH', 'I am stale', false, 0, 0, 'tv'), ]; // act @@ -178,13 +229,53 @@ describe('TorrentTile', () => { expect(filtered.includes(torrents[1])).toBe(false); expect(filtered.at(1)).toBe(torrents[2]); }); + + it('calcul ratio with and without torrent', () => { + // arrange + const widget: ITorrent = { + id: 'abc', + area: { + type: 'sidebar', + properties: { + location: 'left', + }, + }, + shape: {}, + type: 'torrents-status', + properties: { + labelFilter: [], + labelFilterIsWhitelist: false, + displayCompletedTorrents: false, + displayActiveTorrents: false, + speedLimitOfActiveTorrents: 10, + displayStaleTorrents: true, + }, + }; + const torrents: NormalizedTorrent[] = [ + constructTorrent('HH', 'I am completed', true, 0, 672), + ]; + + // act + const filtered = filterTorrents(widget, torrents); + const ratioGlobal = getTorrentsRatio(widget, torrents, false); + const ratioWithFilter = getTorrentsRatio(widget, torrents, true); + + // assert + expect(filtered.length).toBe(0); + expect(filtered.includes(torrents[1])).toBe(false); + expect(ratioGlobal).toBe(378535535/23024335); + expect(ratioWithFilter).toBe(-1); //infinite ratio + + }); + }); const constructTorrent = ( id: string, name: string, isCompleted: boolean, - downloadSpeed: number, + downloadSpeed: number, // Bytes per second in @ctrl/shared-torrent + uploadSpeed: number, // Bytes per second in @ctrl/shared-torrent label?: string ): NormalizedTorrent => ({ id, @@ -208,6 +299,6 @@ const constructTorrent = ( totalSize: 839539535, totalSelected: 0, totalUploaded: 378535535, - uploadSpeed: 8349, + uploadSpeed, label, }); From 7a81742a199f72ba95e7a5f3a85cf3ab5dfea016 Mon Sep 17 00:00:00 2001 From: Someone <10882916+InterN0te@users.noreply.github.com> Date: Mon, 6 Nov 2023 02:34:45 +0100 Subject: [PATCH 06/11] Remove test from other PR --- src/widgets/torrent/TorrentTile.spec.ts | 96 ++++++------------------- 1 file changed, 21 insertions(+), 75 deletions(-) diff --git a/src/widgets/torrent/TorrentTile.spec.ts b/src/widgets/torrent/TorrentTile.spec.ts index 99104fbc1..64f620593 100644 --- a/src/widgets/torrent/TorrentTile.spec.ts +++ b/src/widgets/torrent/TorrentTile.spec.ts @@ -20,15 +20,13 @@ describe('TorrentTile', () => { labelFilter: [], labelFilterIsWhitelist: false, displayCompletedTorrents: true, - displayActiveTorrents: true, - speedLimitOfActiveTorrents: 10, displayStaleTorrents: false, }, }; const torrents: NormalizedTorrent[] = [ - constructTorrent('ABC', 'Nice Torrent', false, 672, 672), - constructTorrent('HH', 'I am completed', true, 0, 0), - constructTorrent('HH', 'I am stale', false, 0, 0), + constructTorrent('ABC', 'Nice Torrent', false, 672), + constructTorrent('HH', 'I am completed', true, 0), + constructTorrent('HH', 'I am stale', false, 0), ]; // act @@ -57,15 +55,13 @@ describe('TorrentTile', () => { labelFilter: [], labelFilterIsWhitelist: false, displayCompletedTorrents: true, - displayActiveTorrents: true, - speedLimitOfActiveTorrents: 10, displayStaleTorrents: true, }, }; const torrents: NormalizedTorrent[] = [ - constructTorrent('ABC', 'Nice Torrent', false, 672, 672), - constructTorrent('HH', 'I am completed', true, 0, 0), - constructTorrent('HH', 'I am stale', false, 0, 0), + constructTorrent('ABC', 'Nice Torrent', false, 672), + constructTorrent('HH', 'I am completed', true, 0), + constructTorrent('HH', 'I am stale', false, 0), ]; // act @@ -78,7 +74,7 @@ describe('TorrentTile', () => { expect(filtered.includes(torrents[2])).toBe(true); }); - it('filter when completed without active torrent', () => { + it('filter when completed', () => { // arrange const widget: ITorrent = { id: 'abc', @@ -94,15 +90,13 @@ describe('TorrentTile', () => { labelFilter: [], labelFilterIsWhitelist: false, displayCompletedTorrents: false, - displayActiveTorrents: false, - speedLimitOfActiveTorrents: 10, displayStaleTorrents: true, }, }; const torrents: NormalizedTorrent[] = [ - constructTorrent('ABC', 'Nice Torrent', false, 672, 672), - constructTorrent('HH', 'I am completed', true, 0, 672), - constructTorrent('HH', 'I am stale', false, 0, 0), + constructTorrent('ABC', 'Nice Torrent', false, 672), + constructTorrent('HH', 'I am completed', true, 0), + constructTorrent('HH', 'I am stale', false, 0), ]; // act @@ -115,47 +109,6 @@ describe('TorrentTile', () => { expect(filtered.at(1)).toBe(torrents[2]); }); - it('filter when completed with active torrent', () => { - // arrange - const widget: ITorrent = { - id: 'abc', - area: { - type: 'sidebar', - properties: { - location: 'left', - }, - }, - shape: {}, - type: 'torrents-status', - properties: { - labelFilter: [], - labelFilterIsWhitelist: false, - displayCompletedTorrents: false, - displayActiveTorrents: true, - speedLimitOfActiveTorrents: 10, - displayStaleTorrents: true, - }, - }; - const torrents: NormalizedTorrent[] = [ - constructTorrent('ABC', 'Nice Torrent', false, 672, 672), - constructTorrent('HH', 'I am completed and uploading less than 10 ko/s (10239 ≈ 9.99ko/s)', true, 0, 10239), - constructTorrent('HH', 'I am completed and uploading more than 10 ko/s (10241 ≈ 10.01ko/s)', true, 0, 10241), - constructTorrent('HH', 'I am completed', true, 0, 0), - constructTorrent('HH', 'I am stale', false, 0, 0), - ]; - - // act - const filtered = filterTorrents(widget, torrents); - - // assert - expect(filtered.length).toBe(3); - expect(filtered.at(0)).toBe(torrents[0]); - expect(filtered.includes(torrents[1])).toBe(false); - expect(filtered.at(1)).toBe(torrents[2]); - expect(filtered.includes(torrents[3])).toBe(false); - expect(filtered.at(2)).toBe(torrents[4]); - }); - it('filter by label when whitelist', () => { // arrange const widget: ITorrent = { @@ -172,15 +125,13 @@ describe('TorrentTile', () => { labelFilter: ['music', 'movie'], labelFilterIsWhitelist: true, displayCompletedTorrents: true, - displayActiveTorrents: true, - speedLimitOfActiveTorrents: 10, displayStaleTorrents: true, }, }; const torrents: NormalizedTorrent[] = [ - constructTorrent('1', 'A sick drop', false, 672, 672, 'music'), - constructTorrent('2', 'I cried', true, 0, 0, 'movie'), - constructTorrent('3', 'Great Animations', false, 0, 0, 'anime'), + constructTorrent('1', 'A sick drop', false, 672, 'music'), + constructTorrent('2', 'I cried', true, 0, 'movie'), + constructTorrent('3', 'Great Animations', false, 0, 'anime'), ]; // act @@ -209,15 +160,13 @@ describe('TorrentTile', () => { labelFilter: ['music', 'movie'], labelFilterIsWhitelist: false, displayCompletedTorrents: false, - displayActiveTorrents: false, - speedLimitOfActiveTorrents: 10, displayStaleTorrents: true, }, }; const torrents: NormalizedTorrent[] = [ - constructTorrent('ABC', 'Nice Torrent', false, 672, 672, 'anime'), - constructTorrent('HH', 'I am completed', true, 0, 0, 'movie'), - constructTorrent('HH', 'I am stale', false, 0, 0, 'tv'), + constructTorrent('ABC', 'Nice Torrent', false, 672, 'anime'), + constructTorrent('HH', 'I am completed', true, 0, 'movie'), + constructTorrent('HH', 'I am stale', false, 0, 'tv'), ]; // act @@ -229,8 +178,8 @@ describe('TorrentTile', () => { expect(filtered.includes(torrents[1])).toBe(false); expect(filtered.at(1)).toBe(torrents[2]); }); - - it('calcul ratio with and without torrent', () => { + + it('calcul ratio', () => { // arrange const widget: ITorrent = { id: 'abc', @@ -252,7 +201,7 @@ describe('TorrentTile', () => { }, }; const torrents: NormalizedTorrent[] = [ - constructTorrent('HH', 'I am completed', true, 0, 672), + constructTorrent('HH', 'I am completed', true, 0), ]; // act @@ -265,17 +214,14 @@ describe('TorrentTile', () => { expect(filtered.includes(torrents[1])).toBe(false); expect(ratioGlobal).toBe(378535535/23024335); expect(ratioWithFilter).toBe(-1); //infinite ratio - }); - }); const constructTorrent = ( id: string, name: string, isCompleted: boolean, - downloadSpeed: number, // Bytes per second in @ctrl/shared-torrent - uploadSpeed: number, // Bytes per second in @ctrl/shared-torrent + downloadSpeed: number, label?: string ): NormalizedTorrent => ({ id, @@ -299,6 +245,6 @@ const constructTorrent = ( totalSize: 839539535, totalSelected: 0, totalUploaded: 378535535, - uploadSpeed, + uploadSpeed: 8349, label, }); From 17871f62f56b5b253710f5888c86ac53bbfd4ce0 Mon Sep 17 00:00:00 2001 From: Someone <10882916+InterN0te@users.noreply.github.com> Date: Mon, 6 Nov 2023 02:38:52 +0100 Subject: [PATCH 07/11] Fixed test Export getTorrentsRatio function to be called in test --- src/widgets/torrent/TorrentTile.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/widgets/torrent/TorrentTile.tsx b/src/widgets/torrent/TorrentTile.tsx index 02b7d1441..93c7ad673 100644 --- a/src/widgets/torrent/TorrentTile.tsx +++ b/src/widgets/torrent/TorrentTile.tsx @@ -237,7 +237,7 @@ const filterTorrentsByLabels = ( return torrents.filter((torrent) => !labels.includes(torrent.label as string)); }; -const getTorrentsRatio = ( +export const getTorrentsRatio = ( widget: ITorrent, torrents: NormalizedTorrent[], applyAllFilter:boolean From ff582e5dcb132b1c6654c155679435507987db45 Mon Sep 17 00:00:00 2001 From: Someone <10882916+InterN0te@users.noreply.github.com> Date: Tue, 7 Nov 2023 11:46:32 +0100 Subject: [PATCH 08/11] More readable code Co-authored-by: Tagaishi --- src/widgets/torrent/TorrentTile.tsx | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/widgets/torrent/TorrentTile.tsx b/src/widgets/torrent/TorrentTile.tsx index 93c7ad673..83f4b8a4b 100644 --- a/src/widgets/torrent/TorrentTile.tsx +++ b/src/widgets/torrent/TorrentTile.tsx @@ -191,7 +191,14 @@ function TorrentTile({ widget }: TorrentTileProps) { )} - {t('card.footer.lastUpdated', { time: humanizedDuration })} - {t('card.footer.ratioGlobal')} : {ratioGlobal === -1 ? "∞" : ratioGlobal.toFixed(2)} {widget.properties.displayRatioWithFilter && ` - ${t('card.footer.ratioWithFilter')} : ${ratioWithFilter === -1 ? "∞" : ratioWithFilter.toFixed(2)}`} + {t('card.footer.lastUpdated', { time: humanizedDuration })} + {` - ${t('card.footer.ratioGlobal')} : ${ + ratioGlobal === -1 ? '∞' : ratioGlobal.toFixed(2) + }`} + {widget.properties.displayRatioWithFilter && + ` - ${t('card.footer.ratioWithFilter')} : ${ + ratioWithFilter === -1 ? '∞' : ratioWithFilter.toFixed(2) + }`} From df2d7bebab62a36b618dcd4772c671a6955be9bc Mon Sep 17 00:00:00 2001 From: Someone <10882916+InterN0te@users.noreply.github.com> Date: Tue, 7 Nov 2023 11:48:51 +0100 Subject: [PATCH 09/11] Fix bad English Co-authored-by: Tagaishi --- public/locales/en/modules/torrents-status.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/public/locales/en/modules/torrents-status.json b/public/locales/en/modules/torrents-status.json index d78e4e016..e06c0a969 100644 --- a/public/locales/en/modules/torrents-status.json +++ b/public/locales/en/modules/torrents-status.json @@ -22,7 +22,7 @@ }, "displayRatioWithFilter": { "label": "Display filtered torrents list ratio", - "description": "If disable, only global ratio will be display. Global ratio still use labels if set" + "description": "If disabled, only the global ratio will be display. The global ratio will still use the labels if set" } } }, From bb92c564d673c5c53c1f1cc74db83027fdc141ea Mon Sep 17 00:00:00 2001 From: Someone <10882916+InterN0te@users.noreply.github.com> Date: Tue, 7 Nov 2023 12:08:24 +0100 Subject: [PATCH 10/11] Format code with VSC --- src/widgets/torrent/TorrentTile.tsx | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/src/widgets/torrent/TorrentTile.tsx b/src/widgets/torrent/TorrentTile.tsx index 83f4b8a4b..4cf0ad86a 100644 --- a/src/widgets/torrent/TorrentTile.tsx +++ b/src/widgets/torrent/TorrentTile.tsx @@ -247,18 +247,27 @@ const filterTorrentsByLabels = ( export const getTorrentsRatio = ( widget: ITorrent, torrents: NormalizedTorrent[], - applyAllFilter:boolean + applyAllFilter: boolean ) => { - - if(applyAllFilter) { - torrents = filterTorrents(widget,torrents) + if (applyAllFilter) { + torrents = filterTorrents(widget, torrents); } else if (widget.properties.labelFilter.length > 0) { - torrents = filterTorrentsByLabels(torrents, widget.properties.labelFilter,widget.properties.labelFilterIsWhitelist) + torrents = filterTorrentsByLabels( + torrents, + widget.properties.labelFilter, + widget.properties.labelFilterIsWhitelist + ); } - let totalDownloadedSum = torrents.reduce((sum, torrent) => sum + torrent.totalDownloaded, 0); + let totalDownloadedSum = torrents.reduce( + (sum, torrent) => sum + torrent.totalDownloaded, + 0 + ); - return totalDownloadedSum > 0 ? torrents.reduce((sum, torrent) => sum + torrent.totalUploaded, 0) / totalDownloadedSum : -1; -} + return totalDownloadedSum > 0 + ? torrents.reduce((sum, torrent) => sum + torrent.totalUploaded, 0) / + totalDownloadedSum + : -1; +}; export default definition; From 314ccc7a233bb2f8f62ae0885ff4a4a57d228ca7 Mon Sep 17 00:00:00 2001 From: Someone <10882916+InterN0te@users.noreply.github.com> Date: Tue, 7 Nov 2023 12:15:56 +0100 Subject: [PATCH 11/11] Fix info for displayRatioWithFilter switch --- public/locales/en/modules/torrents-status.json | 2 +- src/widgets/torrent/TorrentTile.tsx | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/public/locales/en/modules/torrents-status.json b/public/locales/en/modules/torrents-status.json index e06c0a969..64da470a1 100644 --- a/public/locales/en/modules/torrents-status.json +++ b/public/locales/en/modules/torrents-status.json @@ -22,7 +22,7 @@ }, "displayRatioWithFilter": { "label": "Display filtered torrents list ratio", - "description": "If disabled, only the global ratio will be display. The global ratio will still use the labels if set" + "info": "If disabled, only the global ratio will be display. The global ratio will still use the labels if set" } } }, diff --git a/src/widgets/torrent/TorrentTile.tsx b/src/widgets/torrent/TorrentTile.tsx index 4cf0ad86a..3f6100ff2 100644 --- a/src/widgets/torrent/TorrentTile.tsx +++ b/src/widgets/torrent/TorrentTile.tsx @@ -55,6 +55,7 @@ const definition = defineWidget({ displayRatioWithFilter: { type: 'switch', defaultValue: true, + info: true, }, }, gridstack: {