parent
dd11f74073
commit
5b7339cd73
@ -0,0 +1,98 @@
|
||||
import _ from 'lodash';
|
||||
import PropTypes from 'prop-types';
|
||||
import React, { Component } from 'react';
|
||||
import { connect } from 'react-redux';
|
||||
import { createSelector } from 'reselect';
|
||||
import sortByName from 'Utilities/Array/sortByName';
|
||||
import SelectInput from './SelectInput';
|
||||
|
||||
function createMapStateToProps() {
|
||||
return createSelector(
|
||||
(state) => state.settings.metadataProfiles,
|
||||
(state, { includeNoChange }) => includeNoChange,
|
||||
(state, { includeMixed }) => includeMixed,
|
||||
(metadataProfiles, includeNoChange, includeMixed) => {
|
||||
const values = _.map(metadataProfiles.items.sort(sortByName), (metadataProfile) => {
|
||||
return {
|
||||
key: metadataProfile.id,
|
||||
value: metadataProfile.name
|
||||
};
|
||||
});
|
||||
|
||||
if (includeNoChange) {
|
||||
values.unshift({
|
||||
key: 'noChange',
|
||||
value: 'No Change',
|
||||
disabled: true
|
||||
});
|
||||
}
|
||||
|
||||
if (includeMixed) {
|
||||
values.unshift({
|
||||
key: 'mixed',
|
||||
value: '(Mixed)',
|
||||
disabled: true
|
||||
});
|
||||
}
|
||||
|
||||
return {
|
||||
values
|
||||
};
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
class MetadataProfileSelectInputConnector extends Component {
|
||||
|
||||
//
|
||||
// Lifecycle
|
||||
|
||||
componentDidMount() {
|
||||
const {
|
||||
name,
|
||||
value,
|
||||
values
|
||||
} = this.props;
|
||||
|
||||
if (!value || !_.some(values, (option) => parseInt(option.key) === value)) {
|
||||
const firstValue = _.find(values, (option) => !isNaN(parseInt(option.key)));
|
||||
|
||||
if (firstValue) {
|
||||
this.onChange({ name, value: firstValue.key });
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// Listeners
|
||||
|
||||
onChange = ({ name, value }) => {
|
||||
this.props.onChange({ name, value: parseInt(value) });
|
||||
}
|
||||
|
||||
//
|
||||
// Render
|
||||
|
||||
render() {
|
||||
return (
|
||||
<SelectInput
|
||||
{...this.props}
|
||||
onChange={this.onChange}
|
||||
/>
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
MetadataProfileSelectInputConnector.propTypes = {
|
||||
name: PropTypes.string.isRequired,
|
||||
value: PropTypes.oneOfType([PropTypes.number, PropTypes.string]),
|
||||
values: PropTypes.arrayOf(PropTypes.object).isRequired,
|
||||
includeNoChange: PropTypes.bool.isRequired,
|
||||
onChange: PropTypes.func.isRequired
|
||||
};
|
||||
|
||||
MetadataProfileSelectInputConnector.defaultProps = {
|
||||
includeNoChange: false
|
||||
};
|
||||
|
||||
export default connect(createMapStateToProps)(MetadataProfileSelectInputConnector);
|
@ -0,0 +1,25 @@
|
||||
import PropTypes from 'prop-types';
|
||||
import React from 'react';
|
||||
import Modal from 'Components/Modal/Modal';
|
||||
import EditMetadataProfileModalContentConnector from './EditMetadataProfileModalContentConnector';
|
||||
|
||||
function EditMetadataProfileModal({ isOpen, onModalClose, ...otherProps }) {
|
||||
return (
|
||||
<Modal
|
||||
isOpen={isOpen}
|
||||
onModalClose={onModalClose}
|
||||
>
|
||||
<EditMetadataProfileModalContentConnector
|
||||
{...otherProps}
|
||||
onModalClose={onModalClose}
|
||||
/>
|
||||
</Modal>
|
||||
);
|
||||
}
|
||||
|
||||
EditMetadataProfileModal.propTypes = {
|
||||
isOpen: PropTypes.bool.isRequired,
|
||||
onModalClose: PropTypes.func.isRequired
|
||||
};
|
||||
|
||||
export default EditMetadataProfileModal;
|
@ -0,0 +1,43 @@
|
||||
import PropTypes from 'prop-types';
|
||||
import React, { Component } from 'react';
|
||||
import { connect } from 'react-redux';
|
||||
import { clearPendingChanges } from 'Store/Actions/baseActions';
|
||||
import EditMetadataProfileModal from './EditMetadataProfileModal';
|
||||
|
||||
function mapStateToProps() {
|
||||
return {};
|
||||
}
|
||||
|
||||
const mapDispatchToProps = {
|
||||
clearPendingChanges
|
||||
};
|
||||
|
||||
class EditMetadataProfileModalConnector extends Component {
|
||||
|
||||
//
|
||||
// Listeners
|
||||
|
||||
onModalClose = () => {
|
||||
this.props.clearPendingChanges({ section: 'metadataProfiles' });
|
||||
this.props.onModalClose();
|
||||
}
|
||||
|
||||
//
|
||||
// Render
|
||||
|
||||
render() {
|
||||
return (
|
||||
<EditMetadataProfileModal
|
||||
{...this.props}
|
||||
onModalClose={this.onModalClose}
|
||||
/>
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
EditMetadataProfileModalConnector.propTypes = {
|
||||
onModalClose: PropTypes.func.isRequired,
|
||||
clearPendingChanges: PropTypes.func.isRequired
|
||||
};
|
||||
|
||||
export default connect(mapStateToProps, mapDispatchToProps)(EditMetadataProfileModalConnector);
|
@ -0,0 +1,3 @@
|
||||
.deleteButtonContainer {
|
||||
margin-right: auto;
|
||||
}
|
@ -0,0 +1,145 @@
|
||||
import PropTypes from 'prop-types';
|
||||
import React from 'react';
|
||||
import { inputTypes, kinds } from 'Helpers/Props';
|
||||
import Button from 'Components/Link/Button';
|
||||
import SpinnerErrorButton from 'Components/Link/SpinnerErrorButton';
|
||||
import LoadingIndicator from 'Components/Loading/LoadingIndicator';
|
||||
import ModalContent from 'Components/Modal/ModalContent';
|
||||
import ModalHeader from 'Components/Modal/ModalHeader';
|
||||
import ModalBody from 'Components/Modal/ModalBody';
|
||||
import ModalFooter from 'Components/Modal/ModalFooter';
|
||||
import Form from 'Components/Form/Form';
|
||||
import FormGroup from 'Components/Form/FormGroup';
|
||||
import FormLabel from 'Components/Form/FormLabel';
|
||||
import FormInputGroup from 'Components/Form/FormInputGroup';
|
||||
import PrimaryTypeItems from './PrimaryTypeItems';
|
||||
import SecondaryTypeItems from './SecondaryTypeItems';
|
||||
import styles from './EditMetadataProfileModalContent.css';
|
||||
|
||||
function EditMetadataProfileModalContent(props) {
|
||||
const {
|
||||
isFetching,
|
||||
error,
|
||||
isSaving,
|
||||
saveError,
|
||||
primaryAlbumTypes,
|
||||
secondaryAlbumTypes,
|
||||
item,
|
||||
isInUse,
|
||||
onInputChange,
|
||||
onSavePress,
|
||||
onModalClose,
|
||||
onDeleteMetadataProfilePress,
|
||||
...otherProps
|
||||
} = props;
|
||||
|
||||
const {
|
||||
id,
|
||||
name,
|
||||
primaryAlbumTypes: itemPrimaryAlbumTypes,
|
||||
secondaryAlbumTypes: itemSecondaryAlbumTypes
|
||||
} = item;
|
||||
|
||||
return (
|
||||
<ModalContent onModalClose={onModalClose}>
|
||||
<ModalHeader>
|
||||
{id ? 'Edit Metadata Profile' : 'Add Metadata Profile'}
|
||||
</ModalHeader>
|
||||
|
||||
<ModalBody>
|
||||
{
|
||||
isFetching &&
|
||||
<LoadingIndicator />
|
||||
}
|
||||
|
||||
{
|
||||
!isFetching && !!error &&
|
||||
<div>Unable to add a new metadata profile, please try again.</div>
|
||||
}
|
||||
|
||||
{
|
||||
!isFetching && !error &&
|
||||
<Form
|
||||
{...otherProps}
|
||||
>
|
||||
<FormGroup>
|
||||
<FormLabel>Name</FormLabel>
|
||||
|
||||
<FormInputGroup
|
||||
type={inputTypes.TEXT}
|
||||
name="name"
|
||||
{...name}
|
||||
onChange={onInputChange}
|
||||
/>
|
||||
</FormGroup>
|
||||
|
||||
<PrimaryTypeItems
|
||||
metadataProfileItems={itemPrimaryAlbumTypes.value}
|
||||
errors={itemPrimaryAlbumTypes.errors}
|
||||
warnings={itemPrimaryAlbumTypes.warnings}
|
||||
formLabel="Primary Album Types"
|
||||
{...otherProps}
|
||||
/>
|
||||
|
||||
<SecondaryTypeItems
|
||||
metadataProfileItems={itemSecondaryAlbumTypes.value}
|
||||
errors={itemSecondaryAlbumTypes.errors}
|
||||
warnings={itemSecondaryAlbumTypes.warnings}
|
||||
formLabel="Secondary Album Types"
|
||||
{...otherProps}
|
||||
/>
|
||||
|
||||
</Form>
|
||||
}
|
||||
</ModalBody>
|
||||
<ModalFooter>
|
||||
{
|
||||
id &&
|
||||
<div
|
||||
className={styles.deleteButtonContainer}
|
||||
title={isInUse && 'Can\'t delete a metadata profile that is attached to a artist'}
|
||||
>
|
||||
<Button
|
||||
kind={kinds.DANGER}
|
||||
isDisabled={isInUse}
|
||||
onPress={onDeleteMetadataProfilePress}
|
||||
>
|
||||
Delete
|
||||
</Button>
|
||||
</div>
|
||||
}
|
||||
|
||||
<Button
|
||||
onPress={onModalClose}
|
||||
>
|
||||
Cancel
|
||||
</Button>
|
||||
|
||||
<SpinnerErrorButton
|
||||
isSpinning={isSaving}
|
||||
error={saveError}
|
||||
onPress={onSavePress}
|
||||
>
|
||||
Save
|
||||
</SpinnerErrorButton>
|
||||
</ModalFooter>
|
||||
</ModalContent>
|
||||
);
|
||||
}
|
||||
|
||||
EditMetadataProfileModalContent.propTypes = {
|
||||
isFetching: PropTypes.bool.isRequired,
|
||||
error: PropTypes.object,
|
||||
isSaving: PropTypes.bool.isRequired,
|
||||
saveError: PropTypes.object,
|
||||
primaryAlbumTypes: PropTypes.arrayOf(PropTypes.object).isRequired,
|
||||
secondaryAlbumTypes: PropTypes.arrayOf(PropTypes.object).isRequired,
|
||||
item: PropTypes.object.isRequired,
|
||||
isInUse: PropTypes.bool.isRequired,
|
||||
onInputChange: PropTypes.func.isRequired,
|
||||
onSavePress: PropTypes.func.isRequired,
|
||||
onModalClose: PropTypes.func.isRequired,
|
||||
onDeleteMetadataProfilePress: PropTypes.func
|
||||
};
|
||||
|
||||
export default EditMetadataProfileModalContent;
|
@ -0,0 +1,180 @@
|
||||
import _ from 'lodash';
|
||||
import PropTypes from 'prop-types';
|
||||
import React, { Component } from 'react';
|
||||
import { createSelector } from 'reselect';
|
||||
import createProfileInUseSelector from 'Store/Selectors/createProfileInUseSelector';
|
||||
import createProviderSettingsSelector from 'Store/Selectors/createProviderSettingsSelector';
|
||||
import { fetchMetadataProfileSchema, setMetadataProfileValue, saveMetadataProfile } from 'Store/Actions/settingsActions';
|
||||
import connectSection from 'Store/connectSection';
|
||||
import EditMetadataProfileModalContent from './EditMetadataProfileModalContent';
|
||||
|
||||
function createPrimaryAlbumTypesSelector() {
|
||||
return createSelector(
|
||||
createProviderSettingsSelector(),
|
||||
(metadataProfile) => {
|
||||
const primaryAlbumTypes = metadataProfile.item.primaryAlbumTypes;
|
||||
if (!primaryAlbumTypes || !primaryAlbumTypes.value) {
|
||||
return [];
|
||||
}
|
||||
|
||||
return _.reduceRight(primaryAlbumTypes.value, (result, { allowed, albumType }) => {
|
||||
if (allowed) {
|
||||
result.push({
|
||||
key: albumType.id,
|
||||
value: albumType.name
|
||||
});
|
||||
}
|
||||
|
||||
return result;
|
||||
}, []);
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
function createSecondaryAlbumTypesSelector() {
|
||||
return createSelector(
|
||||
createProviderSettingsSelector(),
|
||||
(metadataProfile) => {
|
||||
const secondaryAlbumTypes = metadataProfile.item.secondaryAlbumTypes;
|
||||
if (!secondaryAlbumTypes || !secondaryAlbumTypes.value) {
|
||||
return [];
|
||||
}
|
||||
|
||||
return _.reduceRight(secondaryAlbumTypes.value, (result, { allowed, albumType }) => {
|
||||
if (allowed) {
|
||||
result.push({
|
||||
key: albumType.id,
|
||||
value: albumType.name
|
||||
});
|
||||
}
|
||||
|
||||
return result;
|
||||
}, []);
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
function createMapStateToProps() {
|
||||
return createSelector(
|
||||
createProviderSettingsSelector(),
|
||||
createPrimaryAlbumTypesSelector(),
|
||||
createSecondaryAlbumTypesSelector(),
|
||||
createProfileInUseSelector('metadataProfileId'),
|
||||
(metadataProfile, primaryAlbumTypes, secondaryAlbumTypes, isInUse) => {
|
||||
return {
|
||||
primaryAlbumTypes,
|
||||
secondaryAlbumTypes,
|
||||
...metadataProfile,
|
||||
isInUse
|
||||
};
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
const mapDispatchToProps = {
|
||||
fetchMetadataProfileSchema,
|
||||
setMetadataProfileValue,
|
||||
saveMetadataProfile
|
||||
};
|
||||
|
||||
class EditMetadataProfileModalContentConnector extends Component {
|
||||
|
||||
//
|
||||
// Lifecycle
|
||||
|
||||
constructor(props, context) {
|
||||
super(props, context);
|
||||
|
||||
this.state = {
|
||||
dragIndex: null,
|
||||
dropIndex: null
|
||||
};
|
||||
}
|
||||
|
||||
componentDidMount() {
|
||||
if (!this.props.id) {
|
||||
this.props.fetchMetadataProfileSchema();
|
||||
}
|
||||
}
|
||||
|
||||
componentDidUpdate(prevProps, prevState) {
|
||||
if (prevProps.isSaving && !this.props.isSaving && !this.props.saveError) {
|
||||
this.props.onModalClose();
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// Listeners
|
||||
|
||||
onInputChange = ({ name, value }) => {
|
||||
this.props.setMetadataProfileValue({ name, value });
|
||||
}
|
||||
|
||||
onSavePress = () => {
|
||||
this.props.saveMetadataProfile({ id: this.props.id });
|
||||
}
|
||||
|
||||
onMetadataPrimaryTypeItemAllowedChange = (id, allowed) => {
|
||||
const metadataProfile = _.cloneDeep(this.props.item);
|
||||
|
||||
const item = _.find(metadataProfile.primaryAlbumTypes.value, (i) => i.albumType.id === id);
|
||||
item.allowed = allowed;
|
||||
|
||||
this.props.setMetadataProfileValue({
|
||||
name: 'primaryAlbumTypes',
|
||||
value: metadataProfile.primaryAlbumTypes.value
|
||||
});
|
||||
}
|
||||
|
||||
onMetadataSecondaryTypeItemAllowedChange = (id, allowed) => {
|
||||
const metadataProfile = _.cloneDeep(this.props.item);
|
||||
|
||||
const item = _.find(metadataProfile.secondaryAlbumTypes.value, (i) => i.albumType.id === id);
|
||||
item.allowed = allowed;
|
||||
|
||||
this.props.setMetadataProfileValue({
|
||||
name: 'secondaryAlbumTypes',
|
||||
value: metadataProfile.secondaryAlbumTypes.value
|
||||
});
|
||||
}
|
||||
|
||||
//
|
||||
// Render
|
||||
|
||||
render() {
|
||||
if (_.isEmpty(this.props.item.primaryAlbumTypes) && !this.props.isFetching) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return (
|
||||
<EditMetadataProfileModalContent
|
||||
{...this.state}
|
||||
{...this.props}
|
||||
onSavePress={this.onSavePress}
|
||||
onInputChange={this.onInputChange}
|
||||
onMetadataPrimaryTypeItemAllowedChange={this.onMetadataPrimaryTypeItemAllowedChange}
|
||||
onMetadataSecondaryTypeItemAllowedChange={this.onMetadataSecondaryTypeItemAllowedChange}
|
||||
/>
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
EditMetadataProfileModalContentConnector.propTypes = {
|
||||
id: PropTypes.number,
|
||||
isFetching: PropTypes.bool.isRequired,
|
||||
isSaving: PropTypes.bool.isRequired,
|
||||
saveError: PropTypes.object,
|
||||
item: PropTypes.object.isRequired,
|
||||
setMetadataProfileValue: PropTypes.func.isRequired,
|
||||
fetchMetadataProfileSchema: PropTypes.func.isRequired,
|
||||
saveMetadataProfile: PropTypes.func.isRequired,
|
||||
onModalClose: PropTypes.func.isRequired
|
||||
};
|
||||
|
||||
export default connectSection(
|
||||
createMapStateToProps,
|
||||
mapDispatchToProps,
|
||||
undefined,
|
||||
undefined,
|
||||
{ section: 'metadataProfiles' }
|
||||
)(EditMetadataProfileModalContentConnector);
|
@ -0,0 +1,19 @@
|
||||
.metadataProfile {
|
||||
composes: card from 'Components/Card.css';
|
||||
|
||||
width: 300px;
|
||||
}
|
||||
|
||||
.name {
|
||||
@add-mixin truncate;
|
||||
|
||||
margin-bottom: 20px;
|
||||
font-weight: 300;
|
||||
font-size: 24px;
|
||||
}
|
||||
|
||||
.albumTypes {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
margin-top: 5px;
|
||||
}
|
@ -0,0 +1,142 @@
|
||||
import PropTypes from 'prop-types';
|
||||
import React, { Component } from 'react';
|
||||
import { kinds } from 'Helpers/Props';
|
||||
import Card from 'Components/Card';
|
||||
import Label from 'Components/Label';
|
||||
import ConfirmModal from 'Components/Modal/ConfirmModal';
|
||||
import EditMetadataProfileModalConnector from './EditMetadataProfileModalConnector';
|
||||
import styles from './MetadataProfile.css';
|
||||
|
||||
class MetadataProfile extends Component {
|
||||
|
||||
//
|
||||
// Lifecycle
|
||||
|
||||
constructor(props, context) {
|
||||
super(props, context);
|
||||
|
||||
this.state = {
|
||||
isEditMetadataProfileModalOpen: false,
|
||||
isDeleteMetadataProfileModalOpen: false
|
||||
};
|
||||
}
|
||||
|
||||
//
|
||||
// Listeners
|
||||
|
||||
onEditMetadataProfilePress = () => {
|
||||
this.setState({ isEditMetadataProfileModalOpen: true });
|
||||
}
|
||||
|
||||
onEditMetadataProfileModalClose = () => {
|
||||
this.setState({ isEditMetadataProfileModalOpen: false });
|
||||
}
|
||||
|
||||
onDeleteMetadataProfilePress = () => {
|
||||
this.setState({
|
||||
isEditMetadataProfileModalOpen: false,
|
||||
isDeleteMetadataProfileModalOpen: true
|
||||
});
|
||||
}
|
||||
|
||||
onDeleteMetadataProfileModalClose = () => {
|
||||
this.setState({ isDeleteMetadataProfileModalOpen: false });
|
||||
}
|
||||
|
||||
onConfirmDeleteMetadataProfile = () => {
|
||||
this.props.onConfirmDeleteMetadataProfile(this.props.id);
|
||||
}
|
||||
|
||||
//
|
||||
// Render
|
||||
|
||||
render() {
|
||||
const {
|
||||
id,
|
||||
name,
|
||||
primaryAlbumTypes,
|
||||
secondaryAlbumTypes,
|
||||
isDeleting
|
||||
} = this.props;
|
||||
|
||||
return (
|
||||
<Card
|
||||
className={styles.metadataProfile}
|
||||
onPress={this.onEditMetadataProfilePress}
|
||||
>
|
||||
<div className={styles.name}>
|
||||
{name}
|
||||
</div>
|
||||
|
||||
<div className={styles.albumTypes}>
|
||||
{
|
||||
primaryAlbumTypes.map((item) => {
|
||||
if (!item.allowed) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return (
|
||||
<Label
|
||||
key={item.albumType.id}
|
||||
kind={kinds.default}
|
||||
title={null}
|
||||
>
|
||||
{item.albumType.name}
|
||||
</Label>
|
||||
);
|
||||
})
|
||||
}
|
||||
</div>
|
||||
|
||||
<div className={styles.albumTypes}>
|
||||
{
|
||||
secondaryAlbumTypes.map((item) => {
|
||||
if (!item.allowed) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return (
|
||||
<Label
|
||||
key={item.albumType.id}
|
||||
kind={kinds.INFO}
|
||||
title={null}
|
||||
>
|
||||
{item.albumType.name}
|
||||
</Label>
|
||||
);
|
||||
})
|
||||
}
|
||||
</div>
|
||||
|
||||
<EditMetadataProfileModalConnector
|
||||
id={id}
|
||||
isOpen={this.state.isEditMetadataProfileModalOpen}
|
||||
onModalClose={this.onEditMetadataProfileModalClose}
|
||||
onDeleteMetadataProfilePress={this.onDeleteMetadataProfilePress}
|
||||
/>
|
||||
|
||||
<ConfirmModal
|
||||
isOpen={this.state.isDeleteMetadataProfileModalOpen}
|
||||
kind={kinds.DANGER}
|
||||
title="Delete Metadata Profile"
|
||||
message={`Are you sure you want to delete the metadata profile '${name}'?`}
|
||||
confirmLabel="Delete"
|
||||
isSpinning={isDeleting}
|
||||
onConfirm={this.onConfirmDeleteMetadataProfile}
|
||||
onCancel={this.onDeleteMetadataProfileModalClose}
|
||||
/>
|
||||
</Card>
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
MetadataProfile.propTypes = {
|
||||
id: PropTypes.number.isRequired,
|
||||
name: PropTypes.string.isRequired,
|
||||
primaryAlbumTypes: PropTypes.arrayOf(PropTypes.object).isRequired,
|
||||
secondaryAlbumTypes: PropTypes.arrayOf(PropTypes.object).isRequired,
|
||||
isDeleting: PropTypes.bool.isRequired,
|
||||
onConfirmDeleteMetadataProfile: PropTypes.func.isRequired
|
||||
};
|
||||
|
||||
export default MetadataProfile;
|
@ -0,0 +1,21 @@
|
||||
.metadataProfiles {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
}
|
||||
|
||||
.addMetadataProfile {
|
||||
composes: metadataProfile from './MetadataProfile.css';
|
||||
|
||||
background-color: $cardAlternateBackgroundColor;
|
||||
color: $gray;
|
||||
text-align: center;
|
||||
font-size: 45px;
|
||||
}
|
||||
|
||||
.center {
|
||||
display: inline-block;
|
||||
padding: 5px 20px 0;
|
||||
border: 1px solid $borderColor;
|
||||
border-radius: 4px;
|
||||
background-color: $white;
|
||||
}
|
@ -0,0 +1,102 @@
|
||||
import PropTypes from 'prop-types';
|
||||
import React, { Component } from 'react';
|
||||
import sortByName from 'Utilities/Array/sortByName';
|
||||
import { icons } from 'Helpers/Props';
|
||||
import FieldSet from 'Components/FieldSet';
|
||||
import Card from 'Components/Card';
|
||||
import Icon from 'Components/Icon';
|
||||
import PageSectionContent from 'Components/Page/PageSectionContent';
|
||||
import MetadataProfile from './MetadataProfile';
|
||||
import EditMetadataProfileModalConnector from './EditMetadataProfileModalConnector';
|
||||
import styles from './MetadataProfiles.css';
|
||||
|
||||
class MetadataProfiles extends Component {
|
||||
|
||||
//
|
||||
// Lifecycle
|
||||
|
||||
constructor(props, context) {
|
||||
super(props, context);
|
||||
|
||||
this.state = {
|
||||
isMetadataProfileModalOpen: false
|
||||
};
|
||||
}
|
||||
|
||||
//
|
||||
// Listeners
|
||||
|
||||
onEditMetadataProfilePress = () => {
|
||||
this.setState({ isMetadataProfileModalOpen: true });
|
||||
}
|
||||
|
||||
onModalClose = () => {
|
||||
this.setState({ isMetadataProfileModalOpen: false });
|
||||
}
|
||||
|
||||
//
|
||||
// Render
|
||||
|
||||
render() {
|
||||
const {
|
||||
items,
|
||||
isDeleting,
|
||||
onConfirmDeleteMetadataProfile,
|
||||
...otherProps
|
||||
} = this.props;
|
||||
|
||||
return (
|
||||
<FieldSet
|
||||
legend="Metadata Profiles"
|
||||
>
|
||||
<PageSectionContent
|
||||
errorMessage="Unable to load Metadata Profiles"
|
||||
{...otherProps}
|
||||
>
|
||||
<div className={styles.metadataProfiles}>
|
||||
{
|
||||
items.sort(sortByName).map((item) => {
|
||||
return (
|
||||
<MetadataProfile
|
||||
key={item.id}
|
||||
{...item}
|
||||
isDeleting={isDeleting}
|
||||
onConfirmDeleteMetadataProfile={onConfirmDeleteMetadataProfile}
|
||||
/>
|
||||
);
|
||||
})
|
||||
}
|
||||
|
||||
<Card
|
||||
className={styles.addMetadataProfile}
|
||||
onPress={this.onEditMetadataProfilePress}
|
||||
>
|
||||
<div className={styles.center}>
|
||||
<Icon
|
||||
name={icons.ADD}
|
||||
size={45}
|
||||
/>
|
||||
</div>
|
||||
</Card>
|
||||
</div>
|
||||
|
||||
<EditMetadataProfileModalConnector
|
||||
isOpen={this.state.isMetadataProfileModalOpen}
|
||||
onModalClose={this.onModalClose}
|
||||
/>
|
||||
</PageSectionContent>
|
||||
</FieldSet>
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
MetadataProfiles.propTypes = {
|
||||
advancedSettings: PropTypes.bool.isRequired,
|
||||
isFetching: PropTypes.bool.isRequired,
|
||||
error: PropTypes.object,
|
||||
items: PropTypes.arrayOf(PropTypes.object).isRequired,
|
||||
isDeleting: PropTypes.bool.isRequired,
|
||||
onConfirmDeleteMetadataProfile: PropTypes.func.isRequired
|
||||
};
|
||||
|
||||
export default MetadataProfiles;
|
@ -0,0 +1,60 @@
|
||||
import PropTypes from 'prop-types';
|
||||
import React, { Component } from 'react';
|
||||
import { connect } from 'react-redux';
|
||||
import { createSelector } from 'reselect';
|
||||
import { fetchMetadataProfiles, deleteMetadataProfile } from 'Store/Actions/settingsActions';
|
||||
import MetadataProfiles from './MetadataProfiles';
|
||||
|
||||
function createMapStateToProps() {
|
||||
return createSelector(
|
||||
(state) => state.settings.advancedSettings,
|
||||
(state) => state.settings.metadataProfiles,
|
||||
(advancedSettings, metadataProfiles) => {
|
||||
return {
|
||||
advancedSettings,
|
||||
...metadataProfiles
|
||||
};
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
const mapDispatchToProps = {
|
||||
fetchMetadataProfiles,
|
||||
deleteMetadataProfile
|
||||
};
|
||||
|
||||
class MetadataProfilesConnector extends Component {
|
||||
|
||||
//
|
||||
// Lifecycle
|
||||
|
||||
componentDidMount() {
|
||||
this.props.fetchMetadataProfiles();
|
||||
}
|
||||
|
||||
//
|
||||
// Listeners
|
||||
|
||||
onConfirmDeleteMetadataProfile = (id) => {
|
||||
this.props.deleteMetadataProfile({ id });
|
||||
}
|
||||
|
||||
//
|
||||
// Render
|
||||
|
||||
render() {
|
||||
return (
|
||||
<MetadataProfiles
|
||||
onConfirmDeleteMetadataProfile={this.onConfirmDeleteMetadataProfile}
|
||||
{...this.props}
|
||||
/>
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
MetadataProfilesConnector.propTypes = {
|
||||
fetchMetadataProfiles: PropTypes.func.isRequired,
|
||||
deleteMetadataProfile: PropTypes.func.isRequired
|
||||
};
|
||||
|
||||
export default connect(createMapStateToProps, mapDispatchToProps)(MetadataProfilesConnector);
|
@ -0,0 +1,60 @@
|
||||
import PropTypes from 'prop-types';
|
||||
import React, { Component } from 'react';
|
||||
import classNames from 'classnames';
|
||||
import CheckInput from 'Components/Form/CheckInput';
|
||||
import styles from './TypeItem.css';
|
||||
|
||||
class PrimaryTypeItem extends Component {
|
||||
|
||||
//
|
||||
// Listeners
|
||||
|
||||
onAllowedChange = ({ value }) => {
|
||||
const {
|
||||
albumTypeId,
|
||||
onMetadataPrimaryTypeItemAllowedChange
|
||||
} = this.props;
|
||||
|
||||
onMetadataPrimaryTypeItemAllowedChange(albumTypeId, value);
|
||||
}
|
||||
|
||||
//
|
||||
// Render
|
||||
|
||||
render() {
|
||||
const {
|
||||
name,
|
||||
allowed
|
||||
} = this.props;
|
||||
|
||||
return (
|
||||
<div
|
||||
className={classNames(
|
||||
styles.metadataProfileItem
|
||||
)}
|
||||
>
|
||||
<label
|
||||
className={styles.albumTypeName}
|
||||
>
|
||||
<CheckInput
|
||||
containerClassName={styles.checkContainer}
|
||||
name={name}
|
||||
value={allowed}
|
||||
onChange={this.onAllowedChange}
|
||||
/>
|
||||
{name}
|
||||
</label>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
PrimaryTypeItem.propTypes = {
|
||||
albumTypeId: PropTypes.number.isRequired,
|
||||
name: PropTypes.string.isRequired,
|
||||
allowed: PropTypes.bool.isRequired,
|
||||
sortIndex: PropTypes.number.isRequired,
|
||||
onMetadataPrimaryTypeItemAllowedChange: PropTypes.func
|
||||
};
|
||||
|
||||
export default PrimaryTypeItem;
|
@ -0,0 +1,87 @@
|
||||
import PropTypes from 'prop-types';
|
||||
import React, { Component } from 'react';
|
||||
import FormGroup from 'Components/Form/FormGroup';
|
||||
import FormLabel from 'Components/Form/FormLabel';
|
||||
import FormInputHelpText from 'Components/Form/FormInputHelpText';
|
||||
import PrimaryTypeItem from './PrimaryTypeItem';
|
||||
import styles from './TypeItems.css';
|
||||
|
||||
class PrimaryTypeItems extends Component {
|
||||
|
||||
//
|
||||
// Render
|
||||
|
||||
render() {
|
||||
const {
|
||||
metadataProfileItems,
|
||||
errors,
|
||||
warnings,
|
||||
...otherProps
|
||||
} = this.props;
|
||||
|
||||
return (
|
||||
<FormGroup>
|
||||
<FormLabel>Primary Types</FormLabel>
|
||||
<div>
|
||||
|
||||
{
|
||||
errors.map((error, index) => {
|
||||
return (
|
||||
<FormInputHelpText
|
||||
key={index}
|
||||
text={error.message}
|
||||
isError={true}
|
||||
isCheckInput={false}
|
||||
/>
|
||||
);
|
||||
})
|
||||
}
|
||||
|
||||
{
|
||||
warnings.map((warning, index) => {
|
||||
return (
|
||||
<FormInputHelpText
|
||||
key={index}
|
||||
text={warning.message}
|
||||
isWarning={true}
|
||||
isCheckInput={false}
|
||||
/>
|
||||
);
|
||||
})
|
||||
}
|
||||
|
||||
<div className={styles.albumTypes}>
|
||||
{
|
||||
metadataProfileItems.map(({ allowed, albumType }, index) => {
|
||||
return (
|
||||
<PrimaryTypeItem
|
||||
key={albumType.id}
|
||||
albumTypeId={albumType.id}
|
||||
name={albumType.name}
|
||||
allowed={allowed}
|
||||
sortIndex={index}
|
||||
{...otherProps}
|
||||
/>
|
||||
);
|
||||
}).reverse()
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
</FormGroup>
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
PrimaryTypeItems.propTypes = {
|
||||
metadataProfileItems: PropTypes.arrayOf(PropTypes.object).isRequired,
|
||||
errors: PropTypes.arrayOf(PropTypes.object),
|
||||
warnings: PropTypes.arrayOf(PropTypes.object),
|
||||
formLabel: PropTypes.string
|
||||
};
|
||||
|
||||
PrimaryTypeItems.defaultProps = {
|
||||
errors: [],
|
||||
warnings: []
|
||||
};
|
||||
|
||||
export default PrimaryTypeItems;
|
@ -0,0 +1,60 @@
|
||||
import PropTypes from 'prop-types';
|
||||
import React, { Component } from 'react';
|
||||
import classNames from 'classnames';
|
||||
import CheckInput from 'Components/Form/CheckInput';
|
||||
import styles from './TypeItem.css';
|
||||
|
||||
class SecondaryTypeItem extends Component {
|
||||
|
||||
//
|
||||
// Listeners
|
||||
|
||||
onAllowedChange = ({ value }) => {
|
||||
const {
|
||||
albumTypeId,
|
||||
onMetadataSecondaryTypeItemAllowedChange
|
||||
} = this.props;
|
||||
|
||||
onMetadataSecondaryTypeItemAllowedChange(albumTypeId, value);
|
||||
}
|
||||
|
||||
//
|
||||
// Render
|
||||
|
||||
render() {
|
||||
const {
|
||||
name,
|
||||
allowed
|
||||
} = this.props;
|
||||
|
||||
return (
|
||||
<div
|
||||
className={classNames(
|
||||
styles.metadataProfileItem
|
||||
)}
|
||||
>
|
||||
<label
|
||||
className={styles.albumTypeName}
|
||||
>
|
||||
<CheckInput
|
||||
containerClassName={styles.checkContainer}
|
||||
name={name}
|
||||
value={allowed}
|
||||
onChange={this.onAllowedChange}
|
||||
/>
|
||||
{name}
|
||||
</label>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
SecondaryTypeItem.propTypes = {
|
||||
albumTypeId: PropTypes.number.isRequired,
|
||||
name: PropTypes.string.isRequired,
|
||||
allowed: PropTypes.bool.isRequired,
|
||||
sortIndex: PropTypes.number.isRequired,
|
||||
onMetadataSecondaryTypeItemAllowedChange: PropTypes.func
|
||||
};
|
||||
|
||||
export default SecondaryTypeItem;
|
@ -0,0 +1,87 @@
|
||||
import PropTypes from 'prop-types';
|
||||
import React, { Component } from 'react';
|
||||
import FormGroup from 'Components/Form/FormGroup';
|
||||
import FormLabel from 'Components/Form/FormLabel';
|
||||
import FormInputHelpText from 'Components/Form/FormInputHelpText';
|
||||
import SecondaryTypeItem from './SecondaryTypeItem';
|
||||
import styles from './TypeItems.css';
|
||||
|
||||
class SecondaryTypeItems extends Component {
|
||||
|
||||
//
|
||||
// Render
|
||||
|
||||
render() {
|
||||
const {
|
||||
metadataProfileItems,
|
||||
errors,
|
||||
warnings,
|
||||
...otherProps
|
||||
} = this.props;
|
||||
|
||||
return (
|
||||
<FormGroup>
|
||||
<FormLabel>Secondary Types</FormLabel>
|
||||
<div>
|
||||
|
||||
{
|
||||
errors.map((error, index) => {
|
||||
return (
|
||||
<FormInputHelpText
|
||||
key={index}
|
||||
text={error.message}
|
||||
isError={true}
|
||||
isCheckInput={false}
|
||||
/>
|
||||
);
|
||||
})
|
||||
}
|
||||
|
||||
{
|
||||
warnings.map((warning, index) => {
|
||||
return (
|
||||
<FormInputHelpText
|
||||
key={index}
|
||||
text={warning.message}
|
||||
isWarning={true}
|
||||
isCheckInput={false}
|
||||
/>
|
||||
);
|
||||
})
|
||||
}
|
||||
|
||||
<div className={styles.albumTypes}>
|
||||
{
|
||||
metadataProfileItems.map(({ allowed, albumType }, index) => {
|
||||
return (
|
||||
<SecondaryTypeItem
|
||||
key={albumType.id}
|
||||
albumTypeId={albumType.id}
|
||||
name={albumType.name}
|
||||
allowed={allowed}
|
||||
sortIndex={index}
|
||||
{...otherProps}
|
||||
/>
|
||||
);
|
||||
}).reverse()
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
</FormGroup>
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
SecondaryTypeItems.propTypes = {
|
||||
metadataProfileItems: PropTypes.arrayOf(PropTypes.object).isRequired,
|
||||
errors: PropTypes.arrayOf(PropTypes.object),
|
||||
warnings: PropTypes.arrayOf(PropTypes.object),
|
||||
formLabel: PropTypes.string
|
||||
};
|
||||
|
||||
SecondaryTypeItems.defaultProps = {
|
||||
errors: [],
|
||||
warnings: []
|
||||
};
|
||||
|
||||
export default SecondaryTypeItems;
|
@ -0,0 +1,25 @@
|
||||
.metadataProfileItem {
|
||||
display: flex;
|
||||
align-items: stretch;
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.checkContainer {
|
||||
position: relative;
|
||||
margin-right: 4px;
|
||||
margin-bottom: 7px;
|
||||
margin-left: 8px;
|
||||
}
|
||||
|
||||
.albumTypeName {
|
||||
display: flex;
|
||||
flex-grow: 1;
|
||||
margin-bottom: 0;
|
||||
margin-left: 2px;
|
||||
font-weight: normal;
|
||||
line-height: 36px;
|
||||
}
|
||||
|
||||
.isDragging {
|
||||
opacity: 0.25;
|
||||
}
|
@ -0,0 +1,6 @@
|
||||
.albumTypes {
|
||||
margin-top: 10px;
|
||||
/* TODO: This should consider the number of types in the list */
|
||||
min-height: 200px;
|
||||
user-select: none;
|
||||
}
|
@ -0,0 +1,14 @@
|
||||
import _ from 'lodash';
|
||||
import { createSelector } from 'reselect';
|
||||
|
||||
function createMetadataProfileSelector() {
|
||||
return createSelector(
|
||||
(state, { metadataProfileId }) => metadataProfileId,
|
||||
(state) => state.settings.metadataProfiles.items,
|
||||
(metadataProfileId, metadataProfiles) => {
|
||||
return _.find(metadataProfiles, { id: metadataProfileId });
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
export default createMetadataProfileSelector;
|
@ -0,0 +1,57 @@
|
||||
using System.Collections.Generic;
|
||||
using FluentValidation;
|
||||
using NzbDrone.Core.Profiles.Metadata;
|
||||
using Lidarr.Http;
|
||||
|
||||
namespace Lidarr.Api.V1.Profiles.Metadata
|
||||
{
|
||||
public class MetadataProfileModule : LidarrRestModule<MetadataProfileResource>
|
||||
{
|
||||
private readonly IMetadataProfileService _profileService;
|
||||
|
||||
public MetadataProfileModule(IMetadataProfileService profileService)
|
||||
{
|
||||
_profileService = profileService;
|
||||
SharedValidator.RuleFor(c => c.Name).NotEmpty();
|
||||
SharedValidator.RuleFor(c => c.PrimaryAlbumTypes).MustHaveAllowedPrimaryType();
|
||||
SharedValidator.RuleFor(c => c.SecondaryAlbumTypes).MustHaveAllowedSecondaryType();
|
||||
|
||||
GetResourceAll = GetAll;
|
||||
GetResourceById = GetById;
|
||||
UpdateResource = Update;
|
||||
CreateResource = Create;
|
||||
DeleteResource = DeleteProfile;
|
||||
}
|
||||
|
||||
private int Create(MetadataProfileResource resource)
|
||||
{
|
||||
var model = resource.ToModel();
|
||||
model = _profileService.Add(model);
|
||||
return model.Id;
|
||||
}
|
||||
|
||||
private void DeleteProfile(int id)
|
||||
{
|
||||
_profileService.Delete(id);
|
||||
}
|
||||
|
||||
private void Update(MetadataProfileResource resource)
|
||||
{
|
||||
var model = resource.ToModel();
|
||||
|
||||
_profileService.Update(model);
|
||||
}
|
||||
|
||||
private MetadataProfileResource GetById(int id)
|
||||
{
|
||||
return _profileService.Get(id).ToResource();
|
||||
}
|
||||
|
||||
private List<MetadataProfileResource> GetAll()
|
||||
{
|
||||
var profiles = _profileService.All().ToResource();
|
||||
|
||||
return profiles;
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,110 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using NzbDrone.Core.Profiles.Metadata;
|
||||
using Lidarr.Http.REST;
|
||||
|
||||
namespace Lidarr.Api.V1.Profiles.Metadata
|
||||
{
|
||||
public class MetadataProfileResource : RestResource
|
||||
{
|
||||
public string Name { get; set; }
|
||||
public List<ProfilePrimaryAlbumTypeItemResource> PrimaryAlbumTypes { get; set; }
|
||||
public List<ProfileSecondaryAlbumTypeItemResource> SecondaryAlbumTypes { get; set; }
|
||||
}
|
||||
|
||||
public class ProfilePrimaryAlbumTypeItemResource : RestResource
|
||||
{
|
||||
public NzbDrone.Core.Music.PrimaryAlbumType AlbumType { get; set; }
|
||||
public bool Allowed { get; set; }
|
||||
}
|
||||
|
||||
public class ProfileSecondaryAlbumTypeItemResource : RestResource
|
||||
{
|
||||
public NzbDrone.Core.Music.SecondaryAlbumType AlbumType { get; set; }
|
||||
public bool Allowed { get; set; }
|
||||
}
|
||||
|
||||
public static class MetadataProfileResourceMapper
|
||||
{
|
||||
public static MetadataProfileResource ToResource(this MetadataProfile model)
|
||||
{
|
||||
if (model == null) return null;
|
||||
|
||||
return new MetadataProfileResource
|
||||
{
|
||||
Id = model.Id,
|
||||
Name = model.Name,
|
||||
PrimaryAlbumTypes = model.PrimaryAlbumTypes.ConvertAll(ToResource),
|
||||
SecondaryAlbumTypes = model.SecondaryAlbumTypes.ConvertAll(ToResource)
|
||||
};
|
||||
}
|
||||
|
||||
public static ProfilePrimaryAlbumTypeItemResource ToResource(this ProfilePrimaryAlbumTypeItem model)
|
||||
{
|
||||
if (model == null) return null;
|
||||
|
||||
return new ProfilePrimaryAlbumTypeItemResource
|
||||
{
|
||||
AlbumType = model.PrimaryAlbumType,
|
||||
Allowed = model.Allowed
|
||||
};
|
||||
}
|
||||
|
||||
public static ProfileSecondaryAlbumTypeItemResource ToResource(this ProfileSecondaryAlbumTypeItem model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
return new ProfileSecondaryAlbumTypeItemResource
|
||||
{
|
||||
AlbumType = model.SecondaryAlbumType,
|
||||
Allowed = model.Allowed
|
||||
};
|
||||
}
|
||||
|
||||
public static MetadataProfile ToModel(this MetadataProfileResource resource)
|
||||
{
|
||||
if (resource == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
return new MetadataProfile
|
||||
{
|
||||
Id = resource.Id,
|
||||
Name = resource.Name,
|
||||
PrimaryAlbumTypes = resource.PrimaryAlbumTypes.ConvertAll(ToModel),
|
||||
SecondaryAlbumTypes = resource.SecondaryAlbumTypes.ConvertAll(ToModel)
|
||||
};
|
||||
}
|
||||
|
||||
public static ProfilePrimaryAlbumTypeItem ToModel(this ProfilePrimaryAlbumTypeItemResource resource)
|
||||
{
|
||||
if (resource == null) return null;
|
||||
|
||||
return new ProfilePrimaryAlbumTypeItem
|
||||
{
|
||||
PrimaryAlbumType = (NzbDrone.Core.Music.PrimaryAlbumType)resource.AlbumType.Id,
|
||||
Allowed = resource.Allowed
|
||||
};
|
||||
}
|
||||
|
||||
public static ProfileSecondaryAlbumTypeItem ToModel(this ProfileSecondaryAlbumTypeItemResource resource)
|
||||
{
|
||||
if (resource == null) return null;
|
||||
|
||||
return new ProfileSecondaryAlbumTypeItem
|
||||
{
|
||||
SecondaryAlbumType = (NzbDrone.Core.Music.SecondaryAlbumType)resource.AlbumType.Id,
|
||||
Allowed = resource.Allowed
|
||||
};
|
||||
}
|
||||
|
||||
public static List<MetadataProfileResource> ToResource(this IEnumerable<MetadataProfile> models)
|
||||
{
|
||||
return models.Select(ToResource).ToList();
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,41 @@
|
||||
using System.Linq;
|
||||
using NzbDrone.Core.Profiles.Metadata;
|
||||
using Lidarr.Http;
|
||||
|
||||
namespace Lidarr.Api.V1.Profiles.Metadata
|
||||
{
|
||||
public class MetadataProfileSchemaModule : LidarrRestModule<MetadataProfileResource>
|
||||
{
|
||||
|
||||
public MetadataProfileSchemaModule()
|
||||
: base("/metadataprofile/schema")
|
||||
{
|
||||
GetResourceSingle = GetAll;
|
||||
}
|
||||
|
||||
private MetadataProfileResource GetAll()
|
||||
{
|
||||
var orderedPrimTypes = NzbDrone.Core.Music.PrimaryAlbumType.All
|
||||
.OrderByDescending(l => l.Id)
|
||||
.ToList();
|
||||
|
||||
var orderedSecTypes = NzbDrone.Core.Music.SecondaryAlbumType.All
|
||||
.OrderByDescending(l => l.Id)
|
||||
.ToList();
|
||||
|
||||
var primTypes = orderedPrimTypes.Select(v => new ProfilePrimaryAlbumTypeItem {PrimaryAlbumType = v, Allowed = false})
|
||||
.ToList();
|
||||
|
||||
var secTypes = orderedSecTypes.Select(v => new ProfileSecondaryAlbumTypeItem { SecondaryAlbumType = v, Allowed = false })
|
||||
.ToList();
|
||||
|
||||
var profile = new MetadataProfile
|
||||
{
|
||||
PrimaryAlbumTypes = primTypes,
|
||||
SecondaryAlbumTypes = secTypes
|
||||
};
|
||||
|
||||
return profile.ToResource();
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,75 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using FluentValidation;
|
||||
using FluentValidation.Validators;
|
||||
|
||||
namespace Lidarr.Api.V1.Profiles.Metadata
|
||||
{
|
||||
public static class MetadataValidation
|
||||
{
|
||||
public static IRuleBuilderOptions<T, IList<ProfilePrimaryAlbumTypeItemResource>> MustHaveAllowedPrimaryType<T>(this IRuleBuilder<T, IList<ProfilePrimaryAlbumTypeItemResource>> ruleBuilder)
|
||||
{
|
||||
ruleBuilder.SetValidator(new NotEmptyValidator(null));
|
||||
|
||||
return ruleBuilder.SetValidator(new PrimaryTypeValidator<T>());
|
||||
}
|
||||
|
||||
public static IRuleBuilderOptions<T, IList<ProfileSecondaryAlbumTypeItemResource>> MustHaveAllowedSecondaryType<T>(this IRuleBuilder<T, IList<ProfileSecondaryAlbumTypeItemResource>> ruleBuilder)
|
||||
{
|
||||
ruleBuilder.SetValidator(new NotEmptyValidator(null));
|
||||
|
||||
return ruleBuilder.SetValidator(new SecondaryTypeValidator<T>());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public class PrimaryTypeValidator<T> : PropertyValidator
|
||||
{
|
||||
public PrimaryTypeValidator()
|
||||
: base("Must have at least one allowed primary type")
|
||||
{
|
||||
}
|
||||
|
||||
protected override bool IsValid(PropertyValidatorContext context)
|
||||
{
|
||||
var list = context.PropertyValue as IList<ProfilePrimaryAlbumTypeItemResource>;
|
||||
|
||||
if (list == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!list.Any(c => c.Allowed))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
public class SecondaryTypeValidator<T> : PropertyValidator
|
||||
{
|
||||
public SecondaryTypeValidator()
|
||||
: base("Must have at least one allowed secondary type")
|
||||
{
|
||||
}
|
||||
|
||||
protected override bool IsValid(PropertyValidatorContext context)
|
||||
{
|
||||
var list = context.PropertyValue as IList<ProfileSecondaryAlbumTypeItemResource>;
|
||||
|
||||
if (list == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!list.Any(c => c.Allowed))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,42 @@
|
||||
using FluentAssertions;
|
||||
using System.Linq;
|
||||
using NUnit.Framework;
|
||||
using NzbDrone.Core.Music;
|
||||
using NzbDrone.Core.Test.Framework;
|
||||
using NzbDrone.Core.Profiles.Metadata;
|
||||
|
||||
namespace NzbDrone.Core.Test.Profiles.Metadata
|
||||
{
|
||||
[TestFixture]
|
||||
public class MetadataProfileRepositoryFixture : DbTest<MetadataProfileRepository, MetadataProfile>
|
||||
{
|
||||
[Test]
|
||||
public void should_be_able_to_read_and_write()
|
||||
{
|
||||
var profile = new MetadataProfile
|
||||
{
|
||||
PrimaryAlbumTypes = PrimaryAlbumType.All.OrderByDescending(l => l.Name).Select(l => new ProfilePrimaryAlbumTypeItem
|
||||
{
|
||||
PrimaryAlbumType = l,
|
||||
Allowed = l == PrimaryAlbumType.Album
|
||||
}).ToList(),
|
||||
|
||||
SecondaryAlbumTypes = SecondaryAlbumType.All.OrderByDescending(l => l.Name).Select(l => new ProfileSecondaryAlbumTypeItem
|
||||
{
|
||||
SecondaryAlbumType = l,
|
||||
Allowed = l == SecondaryAlbumType.Studio
|
||||
}).ToList(),
|
||||
|
||||
Name = "TestProfile"
|
||||
};
|
||||
|
||||
Subject.Insert(profile);
|
||||
|
||||
|
||||
StoredModel.Name.Should().Be(profile.Name);
|
||||
|
||||
StoredModel.PrimaryAlbumTypes.Should().Equal(profile.PrimaryAlbumTypes, (a, b) => a.PrimaryAlbumType == b.PrimaryAlbumType && a.Allowed == b.Allowed);
|
||||
StoredModel.SecondaryAlbumTypes.Should().Equal(profile.SecondaryAlbumTypes, (a, b) => a.SecondaryAlbumType == b.SecondaryAlbumType && a.Allowed == b.Allowed);
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,75 @@
|
||||
using System.Linq;
|
||||
using FizzWare.NBuilder;
|
||||
using Moq;
|
||||
using NUnit.Framework;
|
||||
using NzbDrone.Core.Lifecycle;
|
||||
using NzbDrone.Core.Test.Framework;
|
||||
using NzbDrone.Core.Music;
|
||||
using NzbDrone.Core.Profiles.Metadata;
|
||||
|
||||
namespace NzbDrone.Core.Test.Profiles.Metadata
|
||||
{
|
||||
[TestFixture]
|
||||
|
||||
public class MetadataProfileServiceFixture : CoreTest<MetadataProfileService>
|
||||
{
|
||||
[Test]
|
||||
public void init_should_add_default_profiles()
|
||||
{
|
||||
Subject.Handle(new ApplicationStartedEvent());
|
||||
|
||||
Mocker.GetMock<IMetadataProfileRepository>()
|
||||
.Verify(v => v.Insert(It.IsAny<MetadataProfile>()), Times.Once());
|
||||
}
|
||||
|
||||
[Test]
|
||||
//This confirms that new profiles are added only if no other profiles exists.
|
||||
//We don't want to keep adding them back if a user deleted them on purpose.
|
||||
public void Init_should_skip_if_any_profiles_already_exist()
|
||||
{
|
||||
Mocker.GetMock<IMetadataProfileRepository>()
|
||||
.Setup(s => s.All())
|
||||
.Returns(Builder<MetadataProfile>.CreateListOfSize(2).Build().ToList());
|
||||
|
||||
Subject.Handle(new ApplicationStartedEvent());
|
||||
|
||||
Mocker.GetMock<IMetadataProfileRepository>()
|
||||
.Verify(v => v.Insert(It.IsAny<MetadataProfile>()), Times.Never());
|
||||
}
|
||||
|
||||
|
||||
[Test]
|
||||
public void should_not_be_able_to_delete_profile_if_assigned_to_artist()
|
||||
{
|
||||
var artistList = Builder<Artist>.CreateListOfSize(3)
|
||||
.Random(1)
|
||||
.With(c => c.MetadataProfileId = 2)
|
||||
.Build().ToList();
|
||||
|
||||
|
||||
Mocker.GetMock<IArtistService>().Setup(c => c.GetAllArtists()).Returns(artistList);
|
||||
|
||||
Assert.Throws<MetadataProfileInUseException>(() => Subject.Delete(2));
|
||||
|
||||
Mocker.GetMock<IMetadataProfileRepository>().Verify(c => c.Delete(It.IsAny<int>()), Times.Never());
|
||||
|
||||
}
|
||||
|
||||
|
||||
[Test]
|
||||
public void should_delete_profile_if_not_assigned_to_series()
|
||||
{
|
||||
var artistList = Builder<Artist>.CreateListOfSize(3)
|
||||
.All()
|
||||
.With(c => c.MetadataProfileId = 2)
|
||||
.Build().ToList();
|
||||
|
||||
|
||||
Mocker.GetMock<IArtistService>().Setup(c => c.GetAllArtists()).Returns(artistList);
|
||||
|
||||
Subject.Delete(1);
|
||||
|
||||
Mocker.GetMock<IMetadataProfileRepository>().Verify(c => c.Delete(1), Times.Once());
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,63 @@
|
||||
using Marr.Data.Converters;
|
||||
using Marr.Data.Mapping;
|
||||
using Newtonsoft.Json;
|
||||
using NzbDrone.Core.Music;
|
||||
using System;
|
||||
|
||||
namespace NzbDrone.Core.Datastore.Converters
|
||||
{
|
||||
public class PrimaryAlbumTypeIntConverter : JsonConverter, IConverter
|
||||
{
|
||||
public object FromDB(ConverterContext context)
|
||||
{
|
||||
if (context.DbValue == DBNull.Value)
|
||||
{
|
||||
return PrimaryAlbumType.Album;
|
||||
}
|
||||
|
||||
var val = Convert.ToInt32(context.DbValue);
|
||||
|
||||
return (PrimaryAlbumType) val;
|
||||
}
|
||||
|
||||
public object FromDB(ColumnMap map, object dbValue)
|
||||
{
|
||||
return FromDB(new ConverterContext {ColumnMap = map, DbValue = dbValue});
|
||||
}
|
||||
|
||||
public object ToDB(object clrValue)
|
||||
{
|
||||
if (clrValue == DBNull.Value)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (clrValue as PrimaryAlbumType == null)
|
||||
{
|
||||
throw new InvalidOperationException("Attempted to save a albumtype that isn't really a albumtype");
|
||||
}
|
||||
|
||||
var language = (PrimaryAlbumType) clrValue;
|
||||
return (int) language;
|
||||
}
|
||||
|
||||
public Type DbType => typeof(int);
|
||||
|
||||
public override bool CanConvert(Type objectType)
|
||||
{
|
||||
return objectType == typeof(PrimaryAlbumType);
|
||||
}
|
||||
|
||||
public override object ReadJson(JsonReader reader, Type objectType, object existingValue,
|
||||
JsonSerializer serializer)
|
||||
{
|
||||
var item = reader.Value;
|
||||
return (PrimaryAlbumType) Convert.ToInt32(item);
|
||||
}
|
||||
|
||||
public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
|
||||
{
|
||||
writer.WriteValue(ToDB(value));
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,63 @@
|
||||
using System;
|
||||
using Marr.Data.Converters;
|
||||
using Marr.Data.Mapping;
|
||||
using Newtonsoft.Json;
|
||||
using NzbDrone.Core.Music;
|
||||
|
||||
namespace NzbDrone.Core.Datastore.Converters
|
||||
{
|
||||
public class SecondaryAlbumTypeIntConverter : JsonConverter, IConverter
|
||||
{
|
||||
public object FromDB(ConverterContext context)
|
||||
{
|
||||
if (context.DbValue == DBNull.Value)
|
||||
{
|
||||
return SecondaryAlbumType.Studio;
|
||||
}
|
||||
|
||||
var val = Convert.ToInt32(context.DbValue);
|
||||
|
||||
return (SecondaryAlbumType) val;
|
||||
}
|
||||
|
||||
public object FromDB(ColumnMap map, object dbValue)
|
||||
{
|
||||
return FromDB(new ConverterContext {ColumnMap = map, DbValue = dbValue});
|
||||
}
|
||||
|
||||
public object ToDB(object clrValue)
|
||||
{
|
||||
if (clrValue == DBNull.Value)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (clrValue as SecondaryAlbumType == null)
|
||||
{
|
||||
throw new InvalidOperationException("Attempted to save a albumtype that isn't really a albumtype");
|
||||
}
|
||||
|
||||
var language = (SecondaryAlbumType) clrValue;
|
||||
return (int) language;
|
||||
}
|
||||
|
||||
public Type DbType => typeof(int);
|
||||
|
||||
public override bool CanConvert(Type objectType)
|
||||
{
|
||||
return objectType == typeof(SecondaryAlbumType);
|
||||
}
|
||||
|
||||
public override object ReadJson(JsonReader reader, Type objectType, object existingValue,
|
||||
JsonSerializer serializer)
|
||||
{
|
||||
var item = reader.Value;
|
||||
return (SecondaryAlbumType) Convert.ToInt32(item);
|
||||
}
|
||||
|
||||
public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
|
||||
{
|
||||
writer.WriteValue(ToDB(value));
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,25 @@
|
||||
using FluentMigrator;
|
||||
using NzbDrone.Core.Datastore.Migration.Framework;
|
||||
|
||||
namespace NzbDrone.Core.Datastore.Migration
|
||||
{
|
||||
[Migration(5)]
|
||||
public class metadata_profiles : NzbDroneMigrationBase
|
||||
{
|
||||
protected override void MainDbUpgrade()
|
||||
{
|
||||
Create.TableForModel("MetadataProfiles")
|
||||
.WithColumn("Name").AsString().Unique()
|
||||
.WithColumn("PrimaryAlbumTypes").AsString()
|
||||
.WithColumn("SecondaryAlbumTypes").AsString();
|
||||
|
||||
Alter.Table("Artists").AddColumn("MetadataProfileId").AsInt32().WithDefaultValue(1);
|
||||
|
||||
Delete.Column("PrimaryAlbumTypes").FromTable("Artists");
|
||||
Delete.Column("SecondaryAlbumTypes").FromTable("Artists");
|
||||
|
||||
Alter.Table("Albums").AddColumn("SecondaryTypes").AsString().Nullable();
|
||||
|
||||
}
|
||||
}
|
||||
}
|
@ -1,11 +1,12 @@
|
||||
using NzbDrone.Core.Music;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using NzbDrone.Core.Profiles.Metadata;
|
||||
|
||||
namespace NzbDrone.Core.MetadataSource
|
||||
{
|
||||
public interface IProvideArtistInfo
|
||||
{
|
||||
Tuple<Artist, List<Album>> GetArtistInfo(string lidarrId, List<string> primaryAlbumTypes, List<string> secondaryAlbumTypes);
|
||||
Tuple<Artist, List<Album>> GetArtistInfo(string lidarrId, int metadataProfileId);
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,121 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using NzbDrone.Core.Datastore;
|
||||
|
||||
namespace NzbDrone.Core.Music
|
||||
{
|
||||
public class PrimaryAlbumType : IEmbeddedDocument, IEquatable<PrimaryAlbumType>
|
||||
{
|
||||
public int Id { get; set; }
|
||||
public string Name { get; set; }
|
||||
|
||||
public PrimaryAlbumType()
|
||||
{
|
||||
}
|
||||
|
||||
private PrimaryAlbumType(int id, string name)
|
||||
{
|
||||
Id = id;
|
||||
Name = name;
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return Name;
|
||||
}
|
||||
|
||||
public override int GetHashCode()
|
||||
{
|
||||
return Id.GetHashCode();
|
||||
}
|
||||
|
||||
public bool Equals(PrimaryAlbumType other)
|
||||
{
|
||||
if (ReferenceEquals(null, other))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (ReferenceEquals(this, other))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
return Id.Equals(other.Id);
|
||||
}
|
||||
|
||||
public override bool Equals(object obj)
|
||||
{
|
||||
if (ReferenceEquals(null, obj))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return ReferenceEquals(this, obj) || Equals(obj as PrimaryAlbumType);
|
||||
}
|
||||
|
||||
public static bool operator ==(PrimaryAlbumType left, PrimaryAlbumType right)
|
||||
{
|
||||
return Equals(left, right);
|
||||
}
|
||||
|
||||
public static bool operator !=(PrimaryAlbumType left, PrimaryAlbumType right)
|
||||
{
|
||||
return !Equals(left, right);
|
||||
}
|
||||
|
||||
public static PrimaryAlbumType Album => new PrimaryAlbumType(0, "Album");
|
||||
public static PrimaryAlbumType EP => new PrimaryAlbumType(1, "EP");
|
||||
public static PrimaryAlbumType Single => new PrimaryAlbumType(2, "Single");
|
||||
public static PrimaryAlbumType Broadcast => new PrimaryAlbumType(3, "Broadcast");
|
||||
public static PrimaryAlbumType Other => new PrimaryAlbumType(4, "Other");
|
||||
|
||||
|
||||
public static readonly List<PrimaryAlbumType> All = new List<PrimaryAlbumType>
|
||||
{
|
||||
Album,
|
||||
EP,
|
||||
Single,
|
||||
Broadcast,
|
||||
Other
|
||||
};
|
||||
|
||||
|
||||
public static PrimaryAlbumType FindById(int id)
|
||||
{
|
||||
if (id == 0)
|
||||
{
|
||||
return Album;
|
||||
}
|
||||
|
||||
PrimaryAlbumType albumType = All.FirstOrDefault(v => v.Id == id);
|
||||
|
||||
if (albumType == null)
|
||||
{
|
||||
throw new ArgumentException(@"ID does not match a known album type", nameof(id));
|
||||
}
|
||||
|
||||
return albumType;
|
||||
}
|
||||
|
||||
public static explicit operator PrimaryAlbumType(int id)
|
||||
{
|
||||
return FindById(id);
|
||||
}
|
||||
|
||||
public static explicit operator int(PrimaryAlbumType albumType)
|
||||
{
|
||||
return albumType.Id;
|
||||
}
|
||||
|
||||
public static explicit operator PrimaryAlbumType(string type)
|
||||
{
|
||||
var albumType = All.FirstOrDefault(v => v.Name.Equals(type, StringComparison.InvariantCultureIgnoreCase));
|
||||
|
||||
if (albumType == null)
|
||||
{
|
||||
throw new ArgumentException(@"Type does not match a known album type", nameof(type));
|
||||
}
|
||||
|
||||
return albumType;
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,131 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using NzbDrone.Core.Datastore;
|
||||
|
||||
namespace NzbDrone.Core.Music
|
||||
{
|
||||
public class SecondaryAlbumType : IEmbeddedDocument, IEquatable<SecondaryAlbumType>
|
||||
{
|
||||
public int Id { get; set; }
|
||||
public string Name { get; set; }
|
||||
|
||||
public SecondaryAlbumType()
|
||||
{
|
||||
}
|
||||
|
||||
private SecondaryAlbumType(int id, string name)
|
||||
{
|
||||
Id = id;
|
||||
Name = name;
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return Name;
|
||||
}
|
||||
|
||||
public override int GetHashCode()
|
||||
{
|
||||
return Id.GetHashCode();
|
||||
}
|
||||
|
||||
public bool Equals(SecondaryAlbumType other)
|
||||
{
|
||||
if (ReferenceEquals(null, other))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (ReferenceEquals(this, other))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
return Id.Equals(other.Id);
|
||||
}
|
||||
|
||||
public override bool Equals(object obj)
|
||||
{
|
||||
if (ReferenceEquals(null, obj))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return ReferenceEquals(this, obj) || Equals(obj as SecondaryAlbumType);
|
||||
}
|
||||
|
||||
public static bool operator ==(SecondaryAlbumType left, SecondaryAlbumType right)
|
||||
{
|
||||
return Equals(left, right);
|
||||
}
|
||||
|
||||
public static bool operator !=(SecondaryAlbumType left, SecondaryAlbumType right)
|
||||
{
|
||||
return !Equals(left, right);
|
||||
}
|
||||
|
||||
public static SecondaryAlbumType Studio => new SecondaryAlbumType(0, "Studio");
|
||||
public static SecondaryAlbumType Compilation => new SecondaryAlbumType(1, "Compilation");
|
||||
public static SecondaryAlbumType Soundtrack => new SecondaryAlbumType(2, "Soundtrack");
|
||||
public static SecondaryAlbumType Spokenword => new SecondaryAlbumType(3, "Spokenword");
|
||||
public static SecondaryAlbumType Interview => new SecondaryAlbumType(4, "Interview");
|
||||
public static SecondaryAlbumType Audiobook => new SecondaryAlbumType(5, "Audiobook");
|
||||
public static SecondaryAlbumType Live => new SecondaryAlbumType(6, "Live");
|
||||
public static SecondaryAlbumType Remix => new SecondaryAlbumType(7, "Remix");
|
||||
public static SecondaryAlbumType DJMix => new SecondaryAlbumType(8, "DJ-Mix");
|
||||
public static SecondaryAlbumType Mixtape => new SecondaryAlbumType(9, "Mixtape/Street");
|
||||
public static SecondaryAlbumType Demo => new SecondaryAlbumType(10, "Demo");
|
||||
|
||||
|
||||
public static readonly List<SecondaryAlbumType> All = new List<SecondaryAlbumType>
|
||||
{
|
||||
Studio,
|
||||
Compilation,
|
||||
Soundtrack,
|
||||
Spokenword,
|
||||
Interview,
|
||||
Live,
|
||||
Remix,
|
||||
DJMix,
|
||||
Mixtape
|
||||
};
|
||||
|
||||
|
||||
public static SecondaryAlbumType FindById(int id)
|
||||
{
|
||||
if (id == 0)
|
||||
{
|
||||
return Studio;
|
||||
}
|
||||
|
||||
SecondaryAlbumType albumType = All.FirstOrDefault(v => v.Id == id);
|
||||
|
||||
if (albumType == null)
|
||||
{
|
||||
throw new ArgumentException(@"ID does not match a known album type", nameof(id));
|
||||
}
|
||||
|
||||
return albumType;
|
||||
}
|
||||
|
||||
public static explicit operator SecondaryAlbumType(int id)
|
||||
{
|
||||
return FindById(id);
|
||||
}
|
||||
|
||||
public static explicit operator int(SecondaryAlbumType albumType)
|
||||
{
|
||||
return albumType.Id;
|
||||
}
|
||||
|
||||
public static explicit operator SecondaryAlbumType(string type)
|
||||
{
|
||||
var albumType = All.FirstOrDefault(v => v.Name.Equals(type, StringComparison.InvariantCultureIgnoreCase));
|
||||
|
||||
if (albumType == null)
|
||||
{
|
||||
throw new ArgumentException(@"Type does not match a known album type", nameof(type));
|
||||
}
|
||||
|
||||
return albumType;
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,14 @@
|
||||
using System.Collections.Generic;
|
||||
using NzbDrone.Core.Datastore;
|
||||
using NzbDrone.Core.Indexers;
|
||||
|
||||
namespace NzbDrone.Core.Profiles.Metadata
|
||||
{
|
||||
public class MetadataProfile : ModelBase
|
||||
{
|
||||
public string Name { get; set; }
|
||||
public List<ProfilePrimaryAlbumTypeItem> PrimaryAlbumTypes { get; set; }
|
||||
public List<ProfileSecondaryAlbumTypeItem> SecondaryAlbumTypes { get; set; }
|
||||
|
||||
}
|
||||
}
|
@ -0,0 +1,13 @@
|
||||
using NzbDrone.Common.Exceptions;
|
||||
|
||||
namespace NzbDrone.Core.Profiles.Metadata
|
||||
{
|
||||
public class MetadataProfileInUseException : NzbDroneException
|
||||
{
|
||||
public MetadataProfileInUseException(int profileId)
|
||||
: base("Metadata profile [{0}] is in use.", profileId)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,23 @@
|
||||
using NzbDrone.Core.Datastore;
|
||||
using NzbDrone.Core.Messaging.Events;
|
||||
|
||||
namespace NzbDrone.Core.Profiles.Metadata
|
||||
{
|
||||
public interface IMetadataProfileRepository : IBasicRepository<MetadataProfile>
|
||||
{
|
||||
bool Exists(int id);
|
||||
}
|
||||
|
||||
public class MetadataProfileRepository : BasicRepository<MetadataProfile>, IMetadataProfileRepository
|
||||
{
|
||||
public MetadataProfileRepository(IMainDatabase database, IEventAggregator eventAggregator)
|
||||
: base(database, eventAggregator)
|
||||
{
|
||||
}
|
||||
|
||||
public bool Exists(int id)
|
||||
{
|
||||
return DataMapper.Query<MetadataProfile>().Where(p => p.Id == id).GetRowCount() == 1;
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,102 @@
|
||||
using NLog;
|
||||
using NzbDrone.Core.Lifecycle;
|
||||
using NzbDrone.Core.Messaging.Events;
|
||||
using NzbDrone.Core.Music;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
namespace NzbDrone.Core.Profiles.Metadata
|
||||
{
|
||||
public interface IMetadataProfileService
|
||||
{
|
||||
MetadataProfile Add(MetadataProfile profile);
|
||||
void Update(MetadataProfile profile);
|
||||
void Delete(int id);
|
||||
List<MetadataProfile> All();
|
||||
MetadataProfile Get(int id);
|
||||
bool Exists(int id);
|
||||
}
|
||||
|
||||
public class MetadataProfileService : IMetadataProfileService, IHandle<ApplicationStartedEvent>
|
||||
{
|
||||
private readonly IMetadataProfileRepository _profileRepository;
|
||||
private readonly IArtistService _artistService;
|
||||
private readonly Logger _logger;
|
||||
|
||||
public MetadataProfileService(IMetadataProfileRepository profileRepository, IArtistService artistService, Logger logger)
|
||||
{
|
||||
_profileRepository = profileRepository;
|
||||
_artistService = artistService;
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
public MetadataProfile Add(MetadataProfile profile)
|
||||
{
|
||||
return _profileRepository.Insert(profile);
|
||||
}
|
||||
|
||||
public void Update(MetadataProfile profile)
|
||||
{
|
||||
_profileRepository.Update(profile);
|
||||
}
|
||||
|
||||
public void Delete(int id)
|
||||
{
|
||||
if (_artistService.GetAllArtists().Any(c => c.MetadataProfileId == id))
|
||||
{
|
||||
throw new MetadataProfileInUseException(id);
|
||||
}
|
||||
|
||||
_profileRepository.Delete(id);
|
||||
}
|
||||
|
||||
public List<MetadataProfile> All()
|
||||
{
|
||||
return _profileRepository.All().ToList();
|
||||
}
|
||||
|
||||
public MetadataProfile Get(int id)
|
||||
{
|
||||
return _profileRepository.Get(id);
|
||||
}
|
||||
|
||||
public bool Exists(int id)
|
||||
{
|
||||
return _profileRepository.Exists(id);
|
||||
}
|
||||
|
||||
private void AddDefaultProfile(string name, List<PrimaryAlbumType> primAllowed, List<SecondaryAlbumType> secAllowed)
|
||||
{
|
||||
var primaryTypes = PrimaryAlbumType.All
|
||||
.OrderByDescending(l => l.Name)
|
||||
.Select(v => new ProfilePrimaryAlbumTypeItem { PrimaryAlbumType = v, Allowed = primAllowed.Contains(v) })
|
||||
.ToList();
|
||||
|
||||
var secondaryTypes = SecondaryAlbumType.All
|
||||
.OrderByDescending(l => l.Name)
|
||||
.Select(v => new ProfileSecondaryAlbumTypeItem { SecondaryAlbumType = v, Allowed = secAllowed.Contains(v) })
|
||||
.ToList();
|
||||
|
||||
var profile = new MetadataProfile
|
||||
{
|
||||
Name = name,
|
||||
PrimaryAlbumTypes = primaryTypes,
|
||||
SecondaryAlbumTypes = secondaryTypes
|
||||
};
|
||||
|
||||
Add(profile);
|
||||
}
|
||||
|
||||
public void Handle(ApplicationStartedEvent message)
|
||||
{
|
||||
if (All().Any())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
_logger.Info("Setting up default metadata profile");
|
||||
|
||||
AddDefaultProfile("Standard", new List<PrimaryAlbumType>{PrimaryAlbumType.Album}, new List<SecondaryAlbumType>{ SecondaryAlbumType.Studio });
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,11 @@
|
||||
using NzbDrone.Core.Datastore;
|
||||
using NzbDrone.Core.Music;
|
||||
|
||||
namespace NzbDrone.Core.Profiles.Metadata
|
||||
{
|
||||
public class ProfilePrimaryAlbumTypeItem : IEmbeddedDocument
|
||||
{
|
||||
public PrimaryAlbumType PrimaryAlbumType { get; set; }
|
||||
public bool Allowed { get; set; }
|
||||
}
|
||||
}
|
@ -0,0 +1,11 @@
|
||||
using NzbDrone.Core.Datastore;
|
||||
using NzbDrone.Core.Music;
|
||||
|
||||
namespace NzbDrone.Core.Profiles.Metadata
|
||||
{
|
||||
public class ProfileSecondaryAlbumTypeItem : IEmbeddedDocument
|
||||
{
|
||||
public SecondaryAlbumType SecondaryAlbumType { get; set; }
|
||||
public bool Allowed { get; set; }
|
||||
}
|
||||
}
|
Loading…
Reference in new issue