From 20a8f1cbe7e898266444bbeabe0320e1c6fd8a4d Mon Sep 17 00:00:00 2001 From: jack-mil <62065280+jack-mil@users.noreply.github.com> Date: Mon, 10 Jul 2023 23:49:00 -0400 Subject: [PATCH] New: Custom Format Score column in queue (cherry picked from commit a6f2db9139c4a6b01d162ccf8884fc02c874b4cf) Closes #8788 --- frontend/src/Activity/Queue/QueueRow.css | 6 ++++++ frontend/src/Activity/Queue/QueueRow.css.d.ts | 1 + frontend/src/Activity/Queue/QueueRow.js | 14 ++++++++++++++ frontend/src/Store/Actions/queueActions.js | 13 ++++++++++++- .../Utilities/Number/formatPreferredWordScore.js | 16 ++++++++++++++++ src/Radarr.Api.V3/Queue/QueueResource.cs | 7 ++++++- 6 files changed, 55 insertions(+), 2 deletions(-) create mode 100644 frontend/src/Utilities/Number/formatPreferredWordScore.js diff --git a/frontend/src/Activity/Queue/QueueRow.css b/frontend/src/Activity/Queue/QueueRow.css index ee0483f96..4a9ff08b9 100644 --- a/frontend/src/Activity/Queue/QueueRow.css +++ b/frontend/src/Activity/Queue/QueueRow.css @@ -16,6 +16,12 @@ width: 150px; } +.customFormatScore { + composes: cell from '~Components/Table/Cells/TableRowCell.css'; + + width: 55px; +} + .actions { composes: cell from '~Components/Table/Cells/TableRowCell.css'; diff --git a/frontend/src/Activity/Queue/QueueRow.css.d.ts b/frontend/src/Activity/Queue/QueueRow.css.d.ts index be7fcd916..13d67ea3a 100644 --- a/frontend/src/Activity/Queue/QueueRow.css.d.ts +++ b/frontend/src/Activity/Queue/QueueRow.css.d.ts @@ -2,6 +2,7 @@ // Please do not change this file! interface CssExports { 'actions': string; + 'customFormatScore': string; 'progress': string; 'protocol': string; 'quality': string; diff --git a/frontend/src/Activity/Queue/QueueRow.js b/frontend/src/Activity/Queue/QueueRow.js index 225c6d4d5..3aeff169c 100644 --- a/frontend/src/Activity/Queue/QueueRow.js +++ b/frontend/src/Activity/Queue/QueueRow.js @@ -15,6 +15,7 @@ import MovieLanguage from 'Movie/MovieLanguage'; import MovieQuality from 'Movie/MovieQuality'; import MovieTitleLink from 'Movie/MovieTitleLink'; import formatBytes from 'Utilities/Number/formatBytes'; +import formatPreferredWordScore from 'Utilities/Number/formatPreferredWordScore'; import translate from 'Utilities/String/translate'; import QueueStatusCell from './QueueStatusCell'; import RemoveQueueItemModal from './RemoveQueueItemModal'; @@ -88,6 +89,7 @@ class QueueRow extends Component { movie, quality, customFormats, + customFormatScore, languages, protocol, indexer, @@ -201,6 +203,17 @@ class QueueRow extends Component { ); } + if (name === 'customFormatScore') { + return ( + + {formatPreferredWordScore(customFormatScore)} + + ); + } + if (name === 'protocol') { return ( @@ -365,6 +378,7 @@ QueueRow.propTypes = { movie: PropTypes.object, quality: PropTypes.object.isRequired, customFormats: PropTypes.arrayOf(PropTypes.object), + customFormatScore: PropTypes.number.isRequired, languages: PropTypes.arrayOf(PropTypes.object).isRequired, protocol: PropTypes.string.isRequired, indexer: PropTypes.string, diff --git a/frontend/src/Store/Actions/queueActions.js b/frontend/src/Store/Actions/queueActions.js index 9bdd26725..9551d0ea8 100644 --- a/frontend/src/Store/Actions/queueActions.js +++ b/frontend/src/Store/Actions/queueActions.js @@ -1,8 +1,10 @@ import _ from 'lodash'; import moment from 'moment'; +import React from 'react'; import { createAction } from 'redux-actions'; import { batchActions } from 'redux-batched-actions'; -import { sortDirections } from 'Helpers/Props'; +import Icon from 'Components/Icon'; +import { icons, sortDirections } from 'Helpers/Props'; import { createThunk, handleThunks } from 'Store/thunks'; import createAjaxRequest from 'Utilities/createAjaxRequest'; import serverSideCollectionHandlers from 'Utilities/serverSideCollectionHandlers'; @@ -88,6 +90,15 @@ export const defaultState = { isSortable: false, isVisible: true }, + { + name: 'customFormatScore', + columnLabel: translate( 'CustomFormatScore'), + label: React.createElement(Icon, { + name: icons.SCORE, + title: translate( 'CustomFormatScore') + }), + isVisible: false + }, { name: 'protocol', label: translate('Protocol'), diff --git a/frontend/src/Utilities/Number/formatPreferredWordScore.js b/frontend/src/Utilities/Number/formatPreferredWordScore.js new file mode 100644 index 000000000..5869f0052 --- /dev/null +++ b/frontend/src/Utilities/Number/formatPreferredWordScore.js @@ -0,0 +1,16 @@ + +function formatPreferredWordScore(input, customFormatsLength = 0) { + const score = Number(input); + + if (score > 0) { + return `+${score}`; + } + + if (score < 0) { + return score; + } + + return customFormatsLength > 0 ? '+0' : ''; +} + +export default formatPreferredWordScore; diff --git a/src/Radarr.Api.V3/Queue/QueueResource.cs b/src/Radarr.Api.V3/Queue/QueueResource.cs index 0e083bf5c..2f2bfd954 100644 --- a/src/Radarr.Api.V3/Queue/QueueResource.cs +++ b/src/Radarr.Api.V3/Queue/QueueResource.cs @@ -19,6 +19,7 @@ namespace Radarr.Api.V3.Queue public List Languages { get; set; } public QualityModel Quality { get; set; } public List CustomFormats { get; set; } + public int CustomFormatScore { get; set; } public decimal Size { get; set; } public string Title { get; set; } public decimal Sizeleft { get; set; } @@ -45,6 +46,9 @@ namespace Radarr.Api.V3.Queue return null; } + var customFormats = model.RemoteMovie?.CustomFormats; + var customFormatScore = model.Movie?.Profile?.CalculateCustomFormatScore(customFormats) ?? 0; + return new QueueResource { Id = model.Id, @@ -52,7 +56,8 @@ namespace Radarr.Api.V3.Queue Movie = includeMovie && model.Movie != null ? model.Movie.ToResource(0) : null, Languages = model.Languages, Quality = model.Quality, - CustomFormats = model.RemoteMovie?.CustomFormats?.ToResource(false), + CustomFormats = customFormats?.ToResource(false), + CustomFormatScore = customFormatScore, Size = model.Size, Title = model.Title, Sizeleft = model.Sizeleft,