1
0
mirror of https://github.com/Radarr/Radarr.git synced 2024-11-04 10:02:40 +01:00

Fixed: Add Delete Button to Custom Formats

This commit is contained in:
Qstick 2019-10-22 20:42:46 -04:00
parent dd00c9b53e
commit fb4aa58a75
4 changed files with 38 additions and 23 deletions

View File

@ -118,7 +118,16 @@ class CustomFormat extends Component {
isOpen={this.state.isDeleteCustomFormatModalOpen} isOpen={this.state.isDeleteCustomFormatModalOpen}
kind={kinds.DANGER} kind={kinds.DANGER}
title="Delete Custom Format" title="Delete Custom Format"
message={`Are you sure you want to delete the custom format '${name}'?`} message={
<div>
<div>
Are you sure you want to delete custom format '{name}'?
</div>
<div>
This will remove all associations to this format in the DB. This may result in existing files being updated.
</div>
</div>
}
confirmLabel="Delete" confirmLabel="Delete"
isSpinning={isDeleting} isSpinning={isDeleting}
onConfirm={this.onConfirmDeleteCustomFormat} onConfirm={this.onConfirmDeleteCustomFormat}

View File

@ -0,0 +1,5 @@
.deleteButton {
composes: button from '~Components/Link/Button.css';
margin-right: auto;
}

View File

@ -1,6 +1,6 @@
import PropTypes from 'prop-types'; import PropTypes from 'prop-types';
import React, { Component } from 'react'; import React, { Component } from 'react';
import { inputTypes } from 'Helpers/Props'; import { inputTypes, kinds } from 'Helpers/Props';
import Button from 'Components/Link/Button'; import Button from 'Components/Link/Button';
import SpinnerErrorButton from 'Components/Link/SpinnerErrorButton'; import SpinnerErrorButton from 'Components/Link/SpinnerErrorButton';
import LoadingIndicator from 'Components/Loading/LoadingIndicator'; import LoadingIndicator from 'Components/Loading/LoadingIndicator';
@ -12,6 +12,7 @@ import Form from 'Components/Form/Form';
import FormGroup from 'Components/Form/FormGroup'; import FormGroup from 'Components/Form/FormGroup';
import FormLabel from 'Components/Form/FormLabel'; import FormLabel from 'Components/Form/FormLabel';
import FormInputGroup from 'Components/Form/FormInputGroup'; import FormInputGroup from 'Components/Form/FormInputGroup';
import styles from './EditCustomFormatModalContent.css';
class EditCustomFormatModalContent extends Component { class EditCustomFormatModalContent extends Component {
@ -28,6 +29,7 @@ class EditCustomFormatModalContent extends Component {
onInputChange, onInputChange,
onSavePress, onSavePress,
onModalClose, onModalClose,
onDeleteCustomFormatPress,
...otherProps ...otherProps
} = this.props; } = this.props;
@ -92,6 +94,17 @@ class EditCustomFormatModalContent extends Component {
</div> </div>
</ModalBody> </ModalBody>
<ModalFooter> <ModalFooter>
{
id &&
<Button
className={styles.deleteButton}
kind={kinds.DANGER}
onPress={onDeleteCustomFormatPress}
>
Delete
</Button>
}
<Button <Button
onPress={onModalClose} onPress={onModalClose}
> >
@ -120,7 +133,8 @@ EditCustomFormatModalContent.propTypes = {
onInputChange: PropTypes.func.isRequired, onInputChange: PropTypes.func.isRequired,
onSavePress: PropTypes.func.isRequired, onSavePress: PropTypes.func.isRequired,
onContentHeightChange: PropTypes.func.isRequired, onContentHeightChange: PropTypes.func.isRequired,
onModalClose: PropTypes.func.isRequired onModalClose: PropTypes.func.isRequired,
onDeleteCustomFormatPress: PropTypes.func
}; };
export default EditCustomFormatModalContent; export default EditCustomFormatModalContent;

View File

@ -130,27 +130,14 @@ public void Delete(int id)
private void DeleteInRepo<TModel>(IBasicRepository<TModel> repository, Func<TModel, List<CustomFormat>> queryFunc, private void DeleteInRepo<TModel>(IBasicRepository<TModel> repository, Func<TModel, List<CustomFormat>> queryFunc,
Func<TModel, List<CustomFormat>, TModel> updateFunc, int customFormatId) where TModel : ModelBase, new() Func<TModel, List<CustomFormat>, TModel> updateFunc, int customFormatId) where TModel : ModelBase, new()
{ {
var pagingSpec = new PagingSpec<TModel> var allItems = repository.All();
{
Page = 0, var toUpdate = allItems.Where(r => queryFunc(r).Exists(c => c.Id == customFormatId)).Select(r =>
PageSize = 2000
};
while (true)
{
var allItems = repository.GetPaged(pagingSpec);
var toUpdate = allItems.Records.Where(r => queryFunc(r).Exists(c => c.Id == customFormatId)).Select(r =>
{ {
return updateFunc(r, queryFunc(r).Where(c => c.Id != customFormatId).ToList()); return updateFunc(r, queryFunc(r).Where(c => c.Id != customFormatId).ToList());
}); });
repository.UpdateMany(toUpdate.ToList()); repository.UpdateMany(toUpdate.ToList());
if (pagingSpec.Page * pagingSpec.PageSize >= allItems.TotalRecords)
{
break;
}
pagingSpec.Page += 1;
}
} }
private Dictionary<int, CustomFormat> AllDictionary() private Dictionary<int, CustomFormat> AllDictionary()