mirror of
https://github.com/lidarr/Lidarr
synced 2025-03-14 15:58:48 +00:00
New: Download Client Tags
(cherry picked from commit f6ae9fd6c5173cbf1540341fa99d2f120be1d28e)
This commit is contained in:
parent
39f5fc1808
commit
eb9f56e1eb
25 changed files with 498 additions and 36 deletions
|
@ -3,6 +3,7 @@ import React, { Component } from 'react';
|
|||
import Card from 'Components/Card';
|
||||
import Label from 'Components/Label';
|
||||
import ConfirmModal from 'Components/Modal/ConfirmModal';
|
||||
import TagList from 'Components/TagList';
|
||||
import { kinds } from 'Helpers/Props';
|
||||
import translate from 'Utilities/String/translate';
|
||||
import EditDownloadClientModalConnector from './EditDownloadClientModalConnector';
|
||||
|
@ -56,7 +57,9 @@ class DownloadClient extends Component {
|
|||
id,
|
||||
name,
|
||||
enable,
|
||||
priority
|
||||
priority,
|
||||
tags,
|
||||
tagList
|
||||
} = this.props;
|
||||
|
||||
return (
|
||||
|
@ -94,6 +97,11 @@ class DownloadClient extends Component {
|
|||
}
|
||||
</div>
|
||||
|
||||
<TagList
|
||||
tags={tags}
|
||||
tagList={tagList}
|
||||
/>
|
||||
|
||||
<EditDownloadClientModalConnector
|
||||
id={id}
|
||||
isOpen={this.state.isEditDownloadClientModalOpen}
|
||||
|
@ -120,6 +128,8 @@ DownloadClient.propTypes = {
|
|||
name: PropTypes.string.isRequired,
|
||||
enable: PropTypes.bool.isRequired,
|
||||
priority: PropTypes.number.isRequired,
|
||||
tags: PropTypes.arrayOf(PropTypes.number).isRequired,
|
||||
tagList: PropTypes.arrayOf(PropTypes.object).isRequired,
|
||||
onConfirmDeleteDownloadClient: PropTypes.func.isRequired
|
||||
};
|
||||
|
||||
|
|
|
@ -50,6 +50,7 @@ class DownloadClients extends Component {
|
|||
const {
|
||||
items,
|
||||
onConfirmDeleteDownloadClient,
|
||||
tagList,
|
||||
...otherProps
|
||||
} = this.props;
|
||||
|
||||
|
@ -71,6 +72,7 @@ class DownloadClients extends Component {
|
|||
<DownloadClient
|
||||
key={item.id}
|
||||
{...item}
|
||||
tagList={tagList}
|
||||
onConfirmDeleteDownloadClient={onConfirmDeleteDownloadClient}
|
||||
/>
|
||||
);
|
||||
|
@ -109,6 +111,7 @@ DownloadClients.propTypes = {
|
|||
isFetching: PropTypes.bool.isRequired,
|
||||
error: PropTypes.object,
|
||||
items: PropTypes.arrayOf(PropTypes.object).isRequired,
|
||||
tagList: PropTypes.arrayOf(PropTypes.object).isRequired,
|
||||
onConfirmDeleteDownloadClient: PropTypes.func.isRequired
|
||||
};
|
||||
|
||||
|
|
|
@ -4,13 +4,20 @@ import { connect } from 'react-redux';
|
|||
import { createSelector } from 'reselect';
|
||||
import { deleteDownloadClient, fetchDownloadClients } from 'Store/Actions/settingsActions';
|
||||
import createSortedSectionSelector from 'Store/Selectors/createSortedSectionSelector';
|
||||
import createTagsSelector from 'Store/Selectors/createTagsSelector';
|
||||
import sortByName from 'Utilities/Array/sortByName';
|
||||
import DownloadClients from './DownloadClients';
|
||||
|
||||
function createMapStateToProps() {
|
||||
return createSelector(
|
||||
createSortedSectionSelector('settings.downloadClients', sortByName),
|
||||
(downloadClients) => downloadClients
|
||||
createTagsSelector(),
|
||||
(downloadClients, tagList) => {
|
||||
return {
|
||||
...downloadClients,
|
||||
tagList
|
||||
};
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
|
|
|
@ -51,6 +51,7 @@ class EditDownloadClientModalContent extends Component {
|
|||
removeCompletedDownloads,
|
||||
removeFailedDownloads,
|
||||
fields,
|
||||
tags,
|
||||
message
|
||||
} = item;
|
||||
|
||||
|
@ -146,6 +147,18 @@ class EditDownloadClientModalContent extends Component {
|
|||
/>
|
||||
</FormGroup>
|
||||
|
||||
<FormGroup>
|
||||
<FormLabel>{translate('Tags')}</FormLabel>
|
||||
|
||||
<FormInputGroup
|
||||
type={inputTypes.TAG}
|
||||
name="tags"
|
||||
helpText={translate('DownloadClientTagHelpText')}
|
||||
{...tags}
|
||||
onChange={onInputChange}
|
||||
/>
|
||||
</FormGroup>
|
||||
|
||||
<FieldSet
|
||||
size={sizes.SMALL}
|
||||
legend={translate('CompletedDownloadHandling')}
|
||||
|
|
|
@ -25,6 +25,7 @@ import translate from 'Utilities/String/translate';
|
|||
import getSelectedIds from 'Utilities/Table/getSelectedIds';
|
||||
import ManageDownloadClientsEditModal from './Edit/ManageDownloadClientsEditModal';
|
||||
import ManageDownloadClientsModalRow from './ManageDownloadClientsModalRow';
|
||||
import TagsModal from './Tags/TagsModal';
|
||||
import styles from './ManageDownloadClientsModalContent.css';
|
||||
|
||||
// TODO: This feels janky to do, but not sure of a better way currently
|
||||
|
@ -69,6 +70,12 @@ const COLUMNS = [
|
|||
isSortable: true,
|
||||
isVisible: true,
|
||||
},
|
||||
{
|
||||
name: 'tags',
|
||||
label: 'Tags',
|
||||
isSortable: true,
|
||||
isVisible: true,
|
||||
},
|
||||
];
|
||||
|
||||
interface ManageDownloadClientsModalContentProps {
|
||||
|
@ -94,6 +101,8 @@ function ManageDownloadClientsModalContent(
|
|||
|
||||
const [isDeleteModalOpen, setIsDeleteModalOpen] = useState(false);
|
||||
const [isEditModalOpen, setIsEditModalOpen] = useState(false);
|
||||
const [isTagsModalOpen, setIsTagsModalOpen] = useState(false);
|
||||
const [isSavingTags, setIsSavingTags] = useState(false);
|
||||
|
||||
const [selectState, setSelectState] = useSelectState();
|
||||
|
||||
|
@ -140,6 +149,30 @@ function ManageDownloadClientsModalContent(
|
|||
[selectedIds, dispatch]
|
||||
);
|
||||
|
||||
const onTagsPress = useCallback(() => {
|
||||
setIsTagsModalOpen(true);
|
||||
}, [setIsTagsModalOpen]);
|
||||
|
||||
const onTagsModalClose = useCallback(() => {
|
||||
setIsTagsModalOpen(false);
|
||||
}, [setIsTagsModalOpen]);
|
||||
|
||||
const onApplyTagsPress = useCallback(
|
||||
(tags: number[], applyTags: string) => {
|
||||
setIsSavingTags(true);
|
||||
setIsTagsModalOpen(false);
|
||||
|
||||
dispatch(
|
||||
bulkEditDownloadClients({
|
||||
ids: selectedIds,
|
||||
tags,
|
||||
applyTags,
|
||||
})
|
||||
);
|
||||
},
|
||||
[selectedIds, dispatch]
|
||||
);
|
||||
|
||||
const onSelectAllChange = useCallback(
|
||||
({ value }: SelectStateInputProps) => {
|
||||
setSelectState({ type: value ? 'selectAll' : 'unselectAll', items });
|
||||
|
@ -222,6 +255,14 @@ function ManageDownloadClientsModalContent(
|
|||
>
|
||||
{translate('Edit')}
|
||||
</SpinnerButton>
|
||||
|
||||
<SpinnerButton
|
||||
isSpinning={isSaving && isSavingTags}
|
||||
isDisabled={!anySelected}
|
||||
onPress={onTagsPress}
|
||||
>
|
||||
{translate('SetTags')}
|
||||
</SpinnerButton>
|
||||
</div>
|
||||
|
||||
<Button onPress={onModalClose}>{translate('Close')}</Button>
|
||||
|
@ -234,6 +275,13 @@ function ManageDownloadClientsModalContent(
|
|||
downloadClientIds={selectedIds}
|
||||
/>
|
||||
|
||||
<TagsModal
|
||||
isOpen={isTagsModalOpen}
|
||||
ids={selectedIds}
|
||||
onApplyTagsPress={onApplyTagsPress}
|
||||
onModalClose={onTagsModalClose}
|
||||
/>
|
||||
|
||||
<ConfirmModal
|
||||
isOpen={isDeleteModalOpen}
|
||||
kind={kinds.DANGER}
|
||||
|
|
|
@ -4,6 +4,7 @@ import TableRowCell from 'Components/Table/Cells/TableRowCell';
|
|||
import TableSelectCell from 'Components/Table/Cells/TableSelectCell';
|
||||
import Column from 'Components/Table/Column';
|
||||
import TableRow from 'Components/Table/TableRow';
|
||||
import TagListConnector from 'Components/TagListConnector';
|
||||
import { kinds } from 'Helpers/Props';
|
||||
import { SelectStateInputProps } from 'typings/props';
|
||||
import translate from 'Utilities/String/translate';
|
||||
|
@ -17,6 +18,7 @@ interface ManageDownloadClientsModalRowProps {
|
|||
removeCompletedDownloads: boolean;
|
||||
removeFailedDownloads: boolean;
|
||||
implementation: string;
|
||||
tags: number[];
|
||||
columns: Column[];
|
||||
isSelected?: boolean;
|
||||
onSelectedChange(result: SelectStateInputProps): void;
|
||||
|
@ -34,6 +36,7 @@ function ManageDownloadClientsModalRow(
|
|||
removeCompletedDownloads,
|
||||
removeFailedDownloads,
|
||||
implementation,
|
||||
tags,
|
||||
onSelectedChange,
|
||||
} = props;
|
||||
|
||||
|
@ -75,6 +78,10 @@ function ManageDownloadClientsModalRow(
|
|||
<TableRowCell className={styles.removeFailedDownloads}>
|
||||
{removeFailedDownloads ? translate('Yes') : translate('No')}
|
||||
</TableRowCell>
|
||||
|
||||
<TableRowCell className={styles.tags}>
|
||||
<TagListConnector tags={tags} />
|
||||
</TableRowCell>
|
||||
</TableRow>
|
||||
);
|
||||
}
|
||||
|
|
|
@ -0,0 +1,22 @@
|
|||
import React from 'react';
|
||||
import Modal from 'Components/Modal/Modal';
|
||||
import TagsModalContent from './TagsModalContent';
|
||||
|
||||
interface TagsModalProps {
|
||||
isOpen: boolean;
|
||||
ids: number[];
|
||||
onApplyTagsPress: (tags: number[], applyTags: string) => void;
|
||||
onModalClose: () => void;
|
||||
}
|
||||
|
||||
function TagsModal(props: TagsModalProps) {
|
||||
const { isOpen, onModalClose, ...otherProps } = props;
|
||||
|
||||
return (
|
||||
<Modal isOpen={isOpen} onModalClose={onModalClose}>
|
||||
<TagsModalContent {...otherProps} onModalClose={onModalClose} />
|
||||
</Modal>
|
||||
);
|
||||
}
|
||||
|
||||
export default TagsModal;
|
|
@ -0,0 +1,12 @@
|
|||
.renameIcon {
|
||||
margin-left: 5px;
|
||||
}
|
||||
|
||||
.message {
|
||||
margin-top: 20px;
|
||||
margin-bottom: 10px;
|
||||
}
|
||||
|
||||
.result {
|
||||
padding-top: 4px;
|
||||
}
|
9
frontend/src/Settings/DownloadClients/DownloadClients/Manage/Tags/TagsModalContent.css.d.ts
vendored
Normal file
9
frontend/src/Settings/DownloadClients/DownloadClients/Manage/Tags/TagsModalContent.css.d.ts
vendored
Normal file
|
@ -0,0 +1,9 @@
|
|||
// This file is automatically generated.
|
||||
// Please do not change this file!
|
||||
interface CssExports {
|
||||
'message': string;
|
||||
'renameIcon': string;
|
||||
'result': string;
|
||||
}
|
||||
export const cssExports: CssExports;
|
||||
export default cssExports;
|
|
@ -0,0 +1,185 @@
|
|||
import { uniq } from 'lodash';
|
||||
import React, { useCallback, useMemo, useState } from 'react';
|
||||
import { useSelector } from 'react-redux';
|
||||
import AppState from 'App/State/AppState';
|
||||
import { DownloadClientAppState } from 'App/State/SettingsAppState';
|
||||
import { Tag } from 'App/State/TagsAppState';
|
||||
import Form from 'Components/Form/Form';
|
||||
import FormGroup from 'Components/Form/FormGroup';
|
||||
import FormInputGroup from 'Components/Form/FormInputGroup';
|
||||
import FormLabel from 'Components/Form/FormLabel';
|
||||
import Label from 'Components/Label';
|
||||
import Button from 'Components/Link/Button';
|
||||
import ModalBody from 'Components/Modal/ModalBody';
|
||||
import ModalContent from 'Components/Modal/ModalContent';
|
||||
import ModalFooter from 'Components/Modal/ModalFooter';
|
||||
import ModalHeader from 'Components/Modal/ModalHeader';
|
||||
import { inputTypes, kinds, sizes } from 'Helpers/Props';
|
||||
import createTagsSelector from 'Store/Selectors/createTagsSelector';
|
||||
import DownloadClient from 'typings/DownloadClient';
|
||||
import translate from 'Utilities/String/translate';
|
||||
import styles from './TagsModalContent.css';
|
||||
|
||||
interface TagsModalContentProps {
|
||||
ids: number[];
|
||||
onApplyTagsPress: (tags: number[], applyTags: string) => void;
|
||||
onModalClose: () => void;
|
||||
}
|
||||
|
||||
function TagsModalContent(props: TagsModalContentProps) {
|
||||
const { ids, onModalClose, onApplyTagsPress } = props;
|
||||
|
||||
const allDownloadClients: DownloadClientAppState = useSelector(
|
||||
(state: AppState) => state.settings.downloadClients
|
||||
);
|
||||
const tagList: Tag[] = useSelector(createTagsSelector());
|
||||
|
||||
const [tags, setTags] = useState<number[]>([]);
|
||||
const [applyTags, setApplyTags] = useState('add');
|
||||
|
||||
const downloadClientsTags = useMemo(() => {
|
||||
const tags = ids.reduce((acc: number[], id) => {
|
||||
const s = allDownloadClients.items.find(
|
||||
(s: DownloadClient) => s.id === id
|
||||
);
|
||||
|
||||
if (s) {
|
||||
acc.push(...s.tags);
|
||||
}
|
||||
|
||||
return acc;
|
||||
}, []);
|
||||
|
||||
return uniq(tags);
|
||||
}, [ids, allDownloadClients]);
|
||||
|
||||
const onTagsChange = useCallback(
|
||||
({ value }: { value: number[] }) => {
|
||||
setTags(value);
|
||||
},
|
||||
[setTags]
|
||||
);
|
||||
|
||||
const onApplyTagsChange = useCallback(
|
||||
({ value }: { value: string }) => {
|
||||
setApplyTags(value);
|
||||
},
|
||||
[setApplyTags]
|
||||
);
|
||||
|
||||
const onApplyPress = useCallback(() => {
|
||||
onApplyTagsPress(tags, applyTags);
|
||||
}, [tags, applyTags, onApplyTagsPress]);
|
||||
|
||||
const applyTagsOptions = [
|
||||
{ key: 'add', value: translate('Add') },
|
||||
{ key: 'remove', value: translate('Remove') },
|
||||
{ key: 'replace', value: translate('Replace') },
|
||||
];
|
||||
|
||||
return (
|
||||
<ModalContent onModalClose={onModalClose}>
|
||||
<ModalHeader>{translate('Tags')}</ModalHeader>
|
||||
|
||||
<ModalBody>
|
||||
<Form>
|
||||
<FormGroup>
|
||||
<FormLabel>{translate('Tags')}</FormLabel>
|
||||
|
||||
<FormInputGroup
|
||||
type={inputTypes.TAG}
|
||||
name="tags"
|
||||
value={tags}
|
||||
onChange={onTagsChange}
|
||||
/>
|
||||
</FormGroup>
|
||||
|
||||
<FormGroup>
|
||||
<FormLabel>{translate('ApplyTags')}</FormLabel>
|
||||
|
||||
<FormInputGroup
|
||||
type={inputTypes.SELECT}
|
||||
name="applyTags"
|
||||
value={applyTags}
|
||||
values={applyTagsOptions}
|
||||
helpTexts={[
|
||||
translate('ApplyTagsHelpTexts1'),
|
||||
translate('ApplyTagsHelpTexts2'),
|
||||
translate('ApplyTagsHelpTexts3'),
|
||||
translate('ApplyTagsHelpTexts4'),
|
||||
]}
|
||||
onChange={onApplyTagsChange}
|
||||
/>
|
||||
</FormGroup>
|
||||
|
||||
<FormGroup>
|
||||
<FormLabel>{translate('Result')}</FormLabel>
|
||||
|
||||
<div className={styles.result}>
|
||||
{downloadClientsTags.map((id) => {
|
||||
const tag = tagList.find((t) => t.id === id);
|
||||
|
||||
if (!tag) {
|
||||
return null;
|
||||
}
|
||||
|
||||
const removeTag =
|
||||
(applyTags === 'remove' && tags.indexOf(id) > -1) ||
|
||||
(applyTags === 'replace' && tags.indexOf(id) === -1);
|
||||
|
||||
return (
|
||||
<Label
|
||||
key={tag.id}
|
||||
title={
|
||||
removeTag
|
||||
? translate('RemovingTag')
|
||||
: translate('ExistingTag')
|
||||
}
|
||||
kind={removeTag ? kinds.INVERSE : kinds.INFO}
|
||||
size={sizes.LARGE}
|
||||
>
|
||||
{tag.label}
|
||||
</Label>
|
||||
);
|
||||
})}
|
||||
|
||||
{(applyTags === 'add' || applyTags === 'replace') &&
|
||||
tags.map((id) => {
|
||||
const tag = tagList.find((t) => t.id === id);
|
||||
|
||||
if (!tag) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (downloadClientsTags.indexOf(id) > -1) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return (
|
||||
<Label
|
||||
key={tag.id}
|
||||
title={translate('AddingTag')}
|
||||
kind={kinds.SUCCESS}
|
||||
size={sizes.LARGE}
|
||||
>
|
||||
{tag.label}
|
||||
</Label>
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
</FormGroup>
|
||||
</Form>
|
||||
</ModalBody>
|
||||
|
||||
<ModalFooter>
|
||||
<Button onPress={onModalClose}>{translate('Cancel')}</Button>
|
||||
|
||||
<Button kind={kinds.PRIMARY} onPress={onApplyPress}>
|
||||
{translate('Apply')}
|
||||
</Button>
|
||||
</ModalFooter>
|
||||
</ModalContent>
|
||||
);
|
||||
}
|
||||
|
||||
export default TagsModalContent;
|
|
@ -22,6 +22,7 @@ function TagDetailsModalContent(props) {
|
|||
notifications,
|
||||
releaseProfiles,
|
||||
indexers,
|
||||
downloadClients,
|
||||
onModalClose,
|
||||
onDeleteTagPress
|
||||
} = props;
|
||||
|
@ -180,6 +181,22 @@ function TagDetailsModalContent(props) {
|
|||
</FieldSet> :
|
||||
null
|
||||
}
|
||||
|
||||
{
|
||||
downloadClients.length ?
|
||||
<FieldSet legend={translate('DownloadClients')}>
|
||||
{
|
||||
downloadClients.map((item) => {
|
||||
return (
|
||||
<div key={item.id}>
|
||||
{item.name}
|
||||
</div>
|
||||
);
|
||||
})
|
||||
}
|
||||
</FieldSet> :
|
||||
null
|
||||
}
|
||||
</ModalBody>
|
||||
|
||||
<ModalFooter>
|
||||
|
@ -214,6 +231,7 @@ TagDetailsModalContent.propTypes = {
|
|||
notifications: PropTypes.arrayOf(PropTypes.object).isRequired,
|
||||
releaseProfiles: PropTypes.arrayOf(PropTypes.object).isRequired,
|
||||
indexers: PropTypes.arrayOf(PropTypes.object).isRequired,
|
||||
downloadClients: PropTypes.arrayOf(PropTypes.object).isRequired,
|
||||
onModalClose: PropTypes.func.isRequired,
|
||||
onDeleteTagPress: PropTypes.func.isRequired
|
||||
};
|
||||
|
|
|
@ -77,6 +77,14 @@ function createMatchingIndexersSelector() {
|
|||
);
|
||||
}
|
||||
|
||||
function createMatchingDownloadClientsSelector() {
|
||||
return createSelector(
|
||||
(state, { downloadClientIds }) => downloadClientIds,
|
||||
(state) => state.settings.downloadClients.items,
|
||||
findMatchingItems
|
||||
);
|
||||
}
|
||||
|
||||
function createMapStateToProps() {
|
||||
return createSelector(
|
||||
createMatchingArtistSelector(),
|
||||
|
@ -85,14 +93,16 @@ function createMapStateToProps() {
|
|||
createMatchingNotificationsSelector(),
|
||||
createMatchingReleaseProfilesSelector(),
|
||||
createMatchingIndexersSelector(),
|
||||
(artist, delayProfiles, importLists, notifications, releaseProfiles, indexers) => {
|
||||
createMatchingDownloadClientsSelector(),
|
||||
(artist, delayProfiles, importLists, notifications, releaseProfiles, indexers, downloadClients) => {
|
||||
return {
|
||||
artist,
|
||||
delayProfiles,
|
||||
importLists,
|
||||
notifications,
|
||||
releaseProfiles,
|
||||
indexers
|
||||
indexers,
|
||||
downloadClients
|
||||
};
|
||||
}
|
||||
);
|
||||
|
|
|
@ -57,8 +57,9 @@ class Tag extends Component {
|
|||
importListIds,
|
||||
notificationIds,
|
||||
restrictionIds,
|
||||
artistIds,
|
||||
indexerIds,
|
||||
artistIds
|
||||
downloadClientIds
|
||||
} = this.props;
|
||||
|
||||
const {
|
||||
|
@ -71,8 +72,9 @@ class Tag extends Component {
|
|||
importListIds.length ||
|
||||
notificationIds.length ||
|
||||
restrictionIds.length ||
|
||||
artistIds.length ||
|
||||
indexerIds.length ||
|
||||
artistIds.length
|
||||
downloadClientIds.length
|
||||
);
|
||||
|
||||
return (
|
||||
|
@ -134,6 +136,14 @@ class Tag extends Component {
|
|||
</div> :
|
||||
null
|
||||
}
|
||||
|
||||
{
|
||||
downloadClientIds.length ?
|
||||
<div>
|
||||
{downloadClientIds.length} download client{indexerIds.length > 1 && 's'}
|
||||
</div> :
|
||||
null
|
||||
}
|
||||
</div>
|
||||
}
|
||||
|
||||
|
@ -153,6 +163,7 @@ class Tag extends Component {
|
|||
notificationIds={notificationIds}
|
||||
restrictionIds={restrictionIds}
|
||||
indexerIds={indexerIds}
|
||||
downloadClientIds={downloadClientIds}
|
||||
isOpen={isDetailsModalOpen}
|
||||
onModalClose={this.onDetailsModalClose}
|
||||
onDeleteTagPress={this.onDeleteTagPress}
|
||||
|
@ -179,8 +190,9 @@ Tag.propTypes = {
|
|||
importListIds: PropTypes.arrayOf(PropTypes.number).isRequired,
|
||||
notificationIds: PropTypes.arrayOf(PropTypes.number).isRequired,
|
||||
restrictionIds: PropTypes.arrayOf(PropTypes.number).isRequired,
|
||||
indexerIds: PropTypes.arrayOf(PropTypes.number).isRequired,
|
||||
artistIds: PropTypes.arrayOf(PropTypes.number).isRequired,
|
||||
indexerIds: PropTypes.arrayOf(PropTypes.number).isRequired,
|
||||
downloadClientIds: PropTypes.arrayOf(PropTypes.number).isRequired,
|
||||
onConfirmDeleteTag: PropTypes.func.isRequired
|
||||
};
|
||||
|
||||
|
@ -189,8 +201,9 @@ Tag.defaultProps = {
|
|||
importListIds: [],
|
||||
notificationIds: [],
|
||||
restrictionIds: [],
|
||||
artistIds: [],
|
||||
indexerIds: [],
|
||||
artistIds: []
|
||||
downloadClientIds: []
|
||||
};
|
||||
|
||||
export default Tag;
|
||||
|
|
|
@ -2,7 +2,7 @@ import PropTypes from 'prop-types';
|
|||
import React, { Component } from 'react';
|
||||
import { connect } from 'react-redux';
|
||||
import { createSelector } from 'reselect';
|
||||
import { fetchDelayProfiles, fetchImportLists, fetchIndexers, fetchNotifications, fetchReleaseProfiles } from 'Store/Actions/settingsActions';
|
||||
import { fetchDelayProfiles, fetchDownloadClients, fetchImportLists, fetchIndexers, fetchNotifications, fetchReleaseProfiles } from 'Store/Actions/settingsActions';
|
||||
import { fetchTagDetails } from 'Store/Actions/tagActions';
|
||||
import Tags from './Tags';
|
||||
|
||||
|
@ -30,7 +30,8 @@ const mapDispatchToProps = {
|
|||
dispatchFetchImportLists: fetchImportLists,
|
||||
dispatchFetchNotifications: fetchNotifications,
|
||||
dispatchFetchReleaseProfiles: fetchReleaseProfiles,
|
||||
dispatchFetchIndexers: fetchIndexers
|
||||
dispatchFetchIndexers: fetchIndexers,
|
||||
dispatchFetchDownloadClients: fetchDownloadClients
|
||||
};
|
||||
|
||||
class MetadatasConnector extends Component {
|
||||
|
@ -45,7 +46,8 @@ class MetadatasConnector extends Component {
|
|||
dispatchFetchImportLists,
|
||||
dispatchFetchNotifications,
|
||||
dispatchFetchReleaseProfiles,
|
||||
dispatchFetchIndexers
|
||||
dispatchFetchIndexers,
|
||||
dispatchFetchDownloadClients
|
||||
} = this.props;
|
||||
|
||||
dispatchFetchTagDetails();
|
||||
|
@ -54,6 +56,7 @@ class MetadatasConnector extends Component {
|
|||
dispatchFetchNotifications();
|
||||
dispatchFetchReleaseProfiles();
|
||||
dispatchFetchIndexers();
|
||||
dispatchFetchDownloadClients();
|
||||
}
|
||||
|
||||
//
|
||||
|
@ -74,7 +77,8 @@ MetadatasConnector.propTypes = {
|
|||
dispatchFetchImportLists: PropTypes.func.isRequired,
|
||||
dispatchFetchNotifications: PropTypes.func.isRequired,
|
||||
dispatchFetchReleaseProfiles: PropTypes.func.isRequired,
|
||||
dispatchFetchIndexers: PropTypes.func.isRequired
|
||||
dispatchFetchIndexers: PropTypes.func.isRequired,
|
||||
dispatchFetchDownloadClients: PropTypes.func.isRequired
|
||||
};
|
||||
|
||||
export default connect(createMapStateToProps, mapDispatchToProps)(MetadatasConnector);
|
||||
|
|
|
@ -12,8 +12,9 @@ namespace Lidarr.Api.V1.Tags
|
|||
public List<int> ImportListIds { get; set; }
|
||||
public List<int> NotificationIds { get; set; }
|
||||
public List<int> RestrictionIds { get; set; }
|
||||
public List<int> IndexerIds { get; set; }
|
||||
public List<int> ArtistIds { get; set; }
|
||||
public List<int> IndexerIds { get; set; }
|
||||
public List<int> DownloadClientIds { get; set; }
|
||||
}
|
||||
|
||||
public static class TagDetailsResourceMapper
|
||||
|
@ -33,8 +34,9 @@ namespace Lidarr.Api.V1.Tags
|
|||
ImportListIds = model.ImportListIds,
|
||||
NotificationIds = model.NotificationIds,
|
||||
RestrictionIds = model.RestrictionIds,
|
||||
ArtistIds = model.ArtistIds,
|
||||
IndexerIds = model.IndexerIds,
|
||||
ArtistIds = model.ArtistIds
|
||||
DownloadClientIds = model.DownloadClientIds,
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
@ -34,7 +34,7 @@ namespace NzbDrone.Core.Test.Download
|
|||
.Returns(_blockedProviders);
|
||||
}
|
||||
|
||||
private Mock<IDownloadClient> WithUsenetClient(int priority = 0)
|
||||
private Mock<IDownloadClient> WithUsenetClient(int priority = 0, HashSet<int> tags = null)
|
||||
{
|
||||
var mock = new Mock<IDownloadClient>(MockBehavior.Default);
|
||||
mock.SetupGet(s => s.Definition)
|
||||
|
@ -42,6 +42,7 @@ namespace NzbDrone.Core.Test.Download
|
|||
.CreateNew()
|
||||
.With(v => v.Id = _nextId++)
|
||||
.With(v => v.Priority = priority)
|
||||
.With(v => v.Tags = tags ?? new HashSet<int>())
|
||||
.Build());
|
||||
|
||||
_downloadClients.Add(mock.Object);
|
||||
|
@ -51,7 +52,7 @@ namespace NzbDrone.Core.Test.Download
|
|||
return mock;
|
||||
}
|
||||
|
||||
private Mock<IDownloadClient> WithTorrentClient(int priority = 0)
|
||||
private Mock<IDownloadClient> WithTorrentClient(int priority = 0, HashSet<int> tags = null)
|
||||
{
|
||||
var mock = new Mock<IDownloadClient>(MockBehavior.Default);
|
||||
mock.SetupGet(s => s.Definition)
|
||||
|
@ -59,6 +60,7 @@ namespace NzbDrone.Core.Test.Download
|
|||
.CreateNew()
|
||||
.With(v => v.Id = _nextId++)
|
||||
.With(v => v.Priority = priority)
|
||||
.With(v => v.Tags = tags ?? new HashSet<int>())
|
||||
.Build());
|
||||
|
||||
_downloadClients.Add(mock.Object);
|
||||
|
@ -148,6 +150,69 @@ namespace NzbDrone.Core.Test.Download
|
|||
client4.Definition.Id.Should().Be(2);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_roundrobin_over_clients_with_matching_tags()
|
||||
{
|
||||
var seriesTags = new HashSet<int> { 1 };
|
||||
var clientTags = new HashSet<int> { 1 };
|
||||
|
||||
WithTorrentClient();
|
||||
WithTorrentClient(0, clientTags);
|
||||
WithTorrentClient();
|
||||
WithTorrentClient(0, clientTags);
|
||||
|
||||
var client1 = Subject.GetDownloadClient(DownloadProtocol.Torrent, 0, false, seriesTags);
|
||||
var client2 = Subject.GetDownloadClient(DownloadProtocol.Torrent, 0, false, seriesTags);
|
||||
var client3 = Subject.GetDownloadClient(DownloadProtocol.Torrent, 0, false, seriesTags);
|
||||
var client4 = Subject.GetDownloadClient(DownloadProtocol.Torrent, 0, false, seriesTags);
|
||||
|
||||
client1.Definition.Id.Should().Be(2);
|
||||
client2.Definition.Id.Should().Be(4);
|
||||
client3.Definition.Id.Should().Be(2);
|
||||
client4.Definition.Id.Should().Be(4);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_roundrobin_over_non_tagged_when_no_matching_tags()
|
||||
{
|
||||
var seriesTags = new HashSet<int> { 2 };
|
||||
var clientTags = new HashSet<int> { 1 };
|
||||
|
||||
WithTorrentClient();
|
||||
WithTorrentClient(0, clientTags);
|
||||
WithTorrentClient();
|
||||
WithTorrentClient(0, clientTags);
|
||||
|
||||
var client1 = Subject.GetDownloadClient(DownloadProtocol.Torrent, 0, false, seriesTags);
|
||||
var client2 = Subject.GetDownloadClient(DownloadProtocol.Torrent, 0, false, seriesTags);
|
||||
var client3 = Subject.GetDownloadClient(DownloadProtocol.Torrent, 0, false, seriesTags);
|
||||
var client4 = Subject.GetDownloadClient(DownloadProtocol.Torrent, 0, false, seriesTags);
|
||||
|
||||
client1.Definition.Id.Should().Be(1);
|
||||
client2.Definition.Id.Should().Be(3);
|
||||
client3.Definition.Id.Should().Be(1);
|
||||
client4.Definition.Id.Should().Be(3);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_fail_to_choose_when_clients_have_tags_but_no_match()
|
||||
{
|
||||
var seriesTags = new HashSet<int> { 2 };
|
||||
var clientTags = new HashSet<int> { 1 };
|
||||
|
||||
WithTorrentClient(0, clientTags);
|
||||
WithTorrentClient(0, clientTags);
|
||||
WithTorrentClient(0, clientTags);
|
||||
WithTorrentClient(0, clientTags);
|
||||
|
||||
var client1 = Subject.GetDownloadClient(DownloadProtocol.Torrent, 0, false, seriesTags);
|
||||
var client2 = Subject.GetDownloadClient(DownloadProtocol.Torrent, 0, false, seriesTags);
|
||||
var client3 = Subject.GetDownloadClient(DownloadProtocol.Torrent, 0, false, seriesTags);
|
||||
var client4 = Subject.GetDownloadClient(DownloadProtocol.Torrent, 0, false, seriesTags);
|
||||
|
||||
Subject.GetDownloadClient(DownloadProtocol.Torrent, 0, false, seriesTags).Should().BeNull();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_skip_blocked_torrent_client()
|
||||
{
|
||||
|
@ -162,7 +227,6 @@ namespace NzbDrone.Core.Test.Download
|
|||
var client2 = Subject.GetDownloadClient(DownloadProtocol.Torrent);
|
||||
var client3 = Subject.GetDownloadClient(DownloadProtocol.Torrent);
|
||||
var client4 = Subject.GetDownloadClient(DownloadProtocol.Torrent);
|
||||
var client5 = Subject.GetDownloadClient(DownloadProtocol.Torrent);
|
||||
|
||||
client1.Definition.Id.Should().Be(2);
|
||||
client2.Definition.Id.Should().Be(4);
|
||||
|
|
|
@ -31,8 +31,8 @@ namespace NzbDrone.Core.Test.Download
|
|||
.Returns(_downloadClients);
|
||||
|
||||
Mocker.GetMock<IProvideDownloadClient>()
|
||||
.Setup(v => v.GetDownloadClient(It.IsAny<DownloadProtocol>(), It.IsAny<int>(), It.IsAny<bool>()))
|
||||
.Returns<DownloadProtocol, int, bool>((v, i, f) => _downloadClients.FirstOrDefault(d => d.Protocol == v));
|
||||
.Setup(v => v.GetDownloadClient(It.IsAny<DownloadProtocol>(), It.IsAny<int>(), It.IsAny<bool>(), It.IsAny<HashSet<int>>()))
|
||||
.Returns<DownloadProtocol, int, bool, HashSet<int>>((v, i, f, t) => _downloadClients.FirstOrDefault(d => d.Protocol == v));
|
||||
|
||||
var episodes = Builder<Album>.CreateListOfSize(2)
|
||||
.TheFirst(1).With(s => s.Id = 12)
|
||||
|
|
|
@ -0,0 +1,14 @@
|
|||
using FluentMigrator;
|
||||
using NzbDrone.Core.Datastore.Migration.Framework;
|
||||
|
||||
namespace NzbDrone.Core.Datastore.Migration
|
||||
{
|
||||
[Migration(070)]
|
||||
public class add_download_client_tags : NzbDroneMigrationBase
|
||||
{
|
||||
protected override void MainDbUpgrade()
|
||||
{
|
||||
Alter.Table("DownloadClients").AddColumn("Tags").AsString().Nullable();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -100,8 +100,7 @@ namespace NzbDrone.Core.Datastore
|
|||
|
||||
Mapper.Entity<DownloadClientDefinition>("DownloadClients").RegisterModel()
|
||||
.Ignore(x => x.ImplementationName)
|
||||
.Ignore(d => d.Protocol)
|
||||
.Ignore(d => d.Tags);
|
||||
.Ignore(d => d.Protocol);
|
||||
|
||||
Mapper.Entity<EntityHistory>("History").RegisterModel();
|
||||
|
||||
|
|
|
@ -2,6 +2,7 @@ using System.Collections.Generic;
|
|||
using System.Linq;
|
||||
using NLog;
|
||||
using NzbDrone.Common.Cache;
|
||||
using NzbDrone.Common.Extensions;
|
||||
using NzbDrone.Core.Download.Clients;
|
||||
using NzbDrone.Core.Indexers;
|
||||
|
||||
|
@ -9,7 +10,7 @@ namespace NzbDrone.Core.Download
|
|||
{
|
||||
public interface IProvideDownloadClient
|
||||
{
|
||||
IDownloadClient GetDownloadClient(DownloadProtocol downloadProtocol, int indexerId = 0, bool filterBlockedClients = false);
|
||||
IDownloadClient GetDownloadClient(DownloadProtocol downloadProtocol, int indexerId = 0, bool filterBlockedClients = false, HashSet<int> tags = null);
|
||||
IEnumerable<IDownloadClient> GetDownloadClients(bool filterBlockedClients = false);
|
||||
IDownloadClient Get(int id);
|
||||
}
|
||||
|
@ -35,11 +36,20 @@ namespace NzbDrone.Core.Download
|
|||
_lastUsedDownloadClient = cacheManager.GetCache<int>(GetType(), "lastDownloadClientId");
|
||||
}
|
||||
|
||||
public IDownloadClient GetDownloadClient(DownloadProtocol downloadProtocol, int indexerId = 0, bool filterBlockedClients = false)
|
||||
public IDownloadClient GetDownloadClient(DownloadProtocol downloadProtocol, int indexerId = 0, bool filterBlockedClients = false, HashSet<int> tags = null)
|
||||
{
|
||||
var blockedProviders = new HashSet<int>(_downloadClientStatusService.GetBlockedProviders().Select(v => v.ProviderId));
|
||||
var availableProviders = _downloadClientFactory.GetAvailableProviders().Where(v => v.Protocol == downloadProtocol).ToList();
|
||||
|
||||
if (tags != null)
|
||||
{
|
||||
var matchingTagsClients = availableProviders.Where(i => i.Definition.Tags.Intersect(tags).Any()).ToList();
|
||||
|
||||
availableProviders = matchingTagsClients.Count > 0 ?
|
||||
matchingTagsClients :
|
||||
availableProviders.Where(i => i.Definition.Tags.Empty()).ToList();
|
||||
}
|
||||
|
||||
if (!availableProviders.Any())
|
||||
{
|
||||
return null;
|
||||
|
|
|
@ -56,7 +56,8 @@ namespace NzbDrone.Core.Download
|
|||
|
||||
var downloadTitle = remoteAlbum.Release.Title;
|
||||
var filterBlockedClients = remoteAlbum.Release.PendingReleaseReason == PendingReleaseReason.DownloadClientUnavailable;
|
||||
var downloadClient = _downloadClientProvider.GetDownloadClient(remoteAlbum.Release.DownloadProtocol, remoteAlbum.Release.IndexerId, filterBlockedClients);
|
||||
var tags = remoteAlbum.Artist?.Tags;
|
||||
var downloadClient = _downloadClientProvider.GetDownloadClient(remoteAlbum.Release.DownloadProtocol, remoteAlbum.Release.IndexerId, filterBlockedClients, tags);
|
||||
|
||||
if (downloadClient == null)
|
||||
{
|
||||
|
|
|
@ -19,7 +19,7 @@ namespace NzbDrone.Core.Housekeeping.Housekeepers
|
|||
public void Clean()
|
||||
{
|
||||
using var mapper = _database.OpenConnection();
|
||||
var usedTags = new[] { "Artists", "Notifications", "DelayProfiles", "ReleaseProfiles", "ImportLists", "Indexers" }
|
||||
var usedTags = new[] { "Artists", "Notifications", "DelayProfiles", "ReleaseProfiles", "ImportLists", "Indexers", "DownloadClients" }
|
||||
.SelectMany(v => GetUsedTags(v, mapper))
|
||||
.Distinct()
|
||||
.ToArray();
|
||||
|
|
|
@ -92,9 +92,9 @@
|
|||
"Authentication": "Authentication",
|
||||
"AuthenticationMethodHelpText": "Require Username and Password to access Lidarr",
|
||||
"AutoAdd": "Auto Add",
|
||||
"AutomaticAdd": "Automatic Add",
|
||||
"AutoRedownloadFailedHelpText": "Automatically search for and attempt to download a different release",
|
||||
"Automatic": "Automatic",
|
||||
"AutomaticAdd": "Automatic Add",
|
||||
"AutomaticallySwitchRelease": "Automatically Switch Release",
|
||||
"Backup": "Backup",
|
||||
"BackupFolderHelpText": "Relative paths will be under Lidarr's AppData directory",
|
||||
|
@ -267,6 +267,7 @@
|
|||
"DownloadClientSortingCheckMessage": "Download client {0} has {1} sorting enabled for Lidarr's category. You should disable sorting in your download client to avoid import issues.",
|
||||
"DownloadClientStatusCheckAllClientMessage": "All download clients are unavailable due to failures",
|
||||
"DownloadClientStatusCheckSingleClientMessage": "Download clients unavailable due to failures: {0}",
|
||||
"DownloadClientTagHelpText": "Only use this download client for artists with at least one matching tag. Leave blank to use with all artists.",
|
||||
"DownloadClients": "Download Clients",
|
||||
"DownloadFailed": "Download Failed",
|
||||
"DownloadFailedCheckDownloadClientForMoreDetails": "Download failed: check download client for more details",
|
||||
|
|
|
@ -14,13 +14,15 @@ namespace NzbDrone.Core.Tags
|
|||
public List<int> ImportListIds { get; set; }
|
||||
public List<int> RootFolderIds { get; set; }
|
||||
public List<int> IndexerIds { get; set; }
|
||||
public List<int> DownloadClientIds { get; set; }
|
||||
|
||||
public bool InUse
|
||||
{
|
||||
get
|
||||
{
|
||||
return ArtistIds.Any() || NotificationIds.Any() || RestrictionIds.Any() || DelayProfileIds.Any() || ImportListIds.Any() || RootFolderIds.Any() || IndexerIds.Any();
|
||||
}
|
||||
}
|
||||
public bool InUse => ArtistIds.Any() ||
|
||||
NotificationIds.Any() ||
|
||||
RestrictionIds.Any() ||
|
||||
DelayProfileIds.Any() ||
|
||||
ImportListIds.Any() ||
|
||||
RootFolderIds.Any() ||
|
||||
IndexerIds.Any() ||
|
||||
DownloadClientIds.Any();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using NzbDrone.Core.Datastore;
|
||||
using NzbDrone.Core.Download;
|
||||
using NzbDrone.Core.ImportLists;
|
||||
using NzbDrone.Core.Indexers;
|
||||
using NzbDrone.Core.Messaging.Events;
|
||||
|
@ -35,6 +36,7 @@ namespace NzbDrone.Core.Tags
|
|||
private readonly IArtistService _artistService;
|
||||
private readonly IRootFolderService _rootFolderService;
|
||||
private readonly IIndexerFactory _indexerService;
|
||||
private readonly IDownloadClientFactory _downloadClientFactory;
|
||||
|
||||
public TagService(ITagRepository repo,
|
||||
IEventAggregator eventAggregator,
|
||||
|
@ -44,7 +46,8 @@ namespace NzbDrone.Core.Tags
|
|||
IReleaseProfileService releaseProfileService,
|
||||
IArtistService artistService,
|
||||
IRootFolderService rootFolderService,
|
||||
IIndexerFactory indexerService)
|
||||
IIndexerFactory indexerService,
|
||||
IDownloadClientFactory downloadClientFactory)
|
||||
{
|
||||
_repo = repo;
|
||||
_eventAggregator = eventAggregator;
|
||||
|
@ -55,6 +58,7 @@ namespace NzbDrone.Core.Tags
|
|||
_artistService = artistService;
|
||||
_rootFolderService = rootFolderService;
|
||||
_indexerService = indexerService;
|
||||
_downloadClientFactory = downloadClientFactory;
|
||||
}
|
||||
|
||||
public Tag GetTag(int tagId)
|
||||
|
@ -84,6 +88,7 @@ namespace NzbDrone.Core.Tags
|
|||
var artist = _artistService.AllForTag(tagId);
|
||||
var rootFolders = _rootFolderService.AllForTag(tagId);
|
||||
var indexers = _indexerService.AllForTag(tagId);
|
||||
var downloadClients = _downloadClientFactory.AllForTag(tagId);
|
||||
|
||||
return new TagDetails
|
||||
{
|
||||
|
@ -95,7 +100,8 @@ namespace NzbDrone.Core.Tags
|
|||
RestrictionIds = restrictions.Select(c => c.Id).ToList(),
|
||||
ArtistIds = artist.Select(c => c.Id).ToList(),
|
||||
RootFolderIds = rootFolders.Select(c => c.Id).ToList(),
|
||||
IndexerIds = indexers.Select(c => c.Id).ToList()
|
||||
IndexerIds = indexers.Select(c => c.Id).ToList(),
|
||||
DownloadClientIds = downloadClients.Select(c => c.Id).ToList()
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -109,6 +115,7 @@ namespace NzbDrone.Core.Tags
|
|||
var artists = _artistService.GetAllArtistsTags();
|
||||
var rootFolders = _rootFolderService.All();
|
||||
var indexers = _indexerService.All();
|
||||
var downloadClients = _downloadClientFactory.All();
|
||||
|
||||
var details = new List<TagDetails>();
|
||||
|
||||
|
@ -124,7 +131,8 @@ namespace NzbDrone.Core.Tags
|
|||
RestrictionIds = restrictions.Where(c => c.Tags.Contains(tag.Id)).Select(c => c.Id).ToList(),
|
||||
ArtistIds = artists.Where(c => c.Value.Contains(tag.Id)).Select(c => c.Key).ToList(),
|
||||
RootFolderIds = rootFolders.Where(c => c.DefaultTags.Contains(tag.Id)).Select(c => c.Id).ToList(),
|
||||
IndexerIds = indexers.Where(c => c.Tags.Contains(tag.Id)).Select(c => c.Id).ToList()
|
||||
IndexerIds = indexers.Where(c => c.Tags.Contains(tag.Id)).Select(c => c.Id).ToList(),
|
||||
DownloadClientIds = downloadClients.Where(c => c.Tags.Contains(tag.Id)).Select(c => c.Id).ToList(),
|
||||
});
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue