New: Movie Certifications

This commit is contained in:
Qstick
2020-04-02 20:57:36 -04:00
parent 770e3379fb
commit dd52760095
22 changed files with 412 additions and 36 deletions

View File

@@ -121,6 +121,13 @@
margin-right: 15px;
}
.certification {
margin-right: 15px;
padding: 0 5px;
border: 1px solid;
border-radius: 5px;
}
.detailsLabel {
composes: label from '~Components/Label.css';

View File

@@ -162,6 +162,7 @@ class MovieDetails extends Component {
title,
year,
runtime,
certification,
ratings,
path,
sizeOnDisk,
@@ -329,6 +330,13 @@ class MovieDetails extends Component {
<div className={styles.details}>
<div>
{
!!certification &&
<span className={styles.certification}>
{certification}
</span>
}
{
year > 0 &&
<span className={styles.year}>
@@ -616,6 +624,7 @@ MovieDetails.propTypes = {
title: PropTypes.string.isRequired,
year: PropTypes.number.isRequired,
runtime: PropTypes.number.isRequired,
certification: PropTypes.string,
ratings: PropTypes.object.isRequired,
path: PropTypes.string.isRequired,
sizeOnDisk: PropTypes.number.isRequired,

View File

@@ -116,8 +116,8 @@ class NamingModal extends Component {
const movieTokens = [
{ token: '{Movie Title}', example: 'Movie Title!' },
{ token: '{Movie CleanTitle}', example: 'Movie Title' },
{ token: '{Movie TitleThe}', example: 'Movie Title, The' }
{ token: '{Movie TitleThe}', example: 'Movie Title, The' },
{ token: '{Movie Certification}', example: 'R' }
];
const movieIdTokens = [

View File

@@ -1,21 +1,68 @@
import React from 'react';
import React, { Component } from 'react';
import PageContent from 'Components/Page/PageContent';
import PageContentBodyConnector from 'Components/Page/PageContentBodyConnector';
import SettingsToolbarConnector from 'Settings/SettingsToolbarConnector';
import MetadatasConnector from './Metadata/MetadatasConnector';
import MetadataOptionsConnector from './Options/MetadataOptionsConnector';
function MetadataSettings() {
return (
<PageContent title="Metadata Settings">
<SettingsToolbarConnector
showSave={false}
/>
class MetadataSettings extends Component {
<PageContentBodyConnector>
<MetadatasConnector />
</PageContentBodyConnector>
</PageContent>
);
//
// Lifecycle
constructor(props, context) {
super(props, context);
this._saveCallback = null;
this.state = {
isSaving: false,
hasPendingChanges: false
};
}
//
// Listeners
onChildMounted = (saveCallback) => {
this._saveCallback = saveCallback;
}
onChildStateChange = (payload) => {
this.setState(payload);
}
onSavePress = () => {
if (this._saveCallback) {
this._saveCallback();
}
}
render() {
const {
isSaving,
hasPendingChanges
} = this.state;
return (
<PageContent title="Metadata Settings">
<SettingsToolbarConnector
isSaving={isSaving}
hasPendingChanges={hasPendingChanges}
onSavePress={this.onSavePress}
/>
<PageContentBodyConnector>
<MetadataOptionsConnector
onChildMounted={this.onChildMounted}
onChildStateChange={this.onChildStateChange}
/>
<MetadatasConnector />
</PageContentBodyConnector>
</PageContent>
);
}
}
export default MetadataSettings;

View File

@@ -0,0 +1,66 @@
import PropTypes from 'prop-types';
import React from 'react';
import { inputTypes } from 'Helpers/Props';
import LoadingIndicator from 'Components/Loading/LoadingIndicator';
import FieldSet from 'Components/FieldSet';
import Form from 'Components/Form/Form';
import FormGroup from 'Components/Form/FormGroup';
import FormLabel from 'Components/Form/FormLabel';
import FormInputGroup from 'Components/Form/FormInputGroup';
export const certificationCountryOptions = [
{ key: 'us', value: 'United States' },
{ key: 'gb', value: 'Great Britain' }
];
function MetadataOptions(props) {
const {
isFetching,
error,
settings,
hasSettings,
onInputChange
} = props;
return (
<FieldSet legend="Options">
{
isFetching &&
<LoadingIndicator />
}
{
!isFetching && error &&
<div>Unable to load indexer options</div>
}
{
hasSettings && !isFetching && !error &&
<Form>
<FormGroup>
<FormLabel>Certification Country</FormLabel>
<FormInputGroup
type={inputTypes.SELECT}
name="certificationCountry"
values={certificationCountryOptions}
onChange={onInputChange}
helpText="Select Country for Movie Certifications"
{...settings.certificationCountry}
/>
</FormGroup>
</Form>
}
</FieldSet>
);
}
MetadataOptions.propTypes = {
isFetching: PropTypes.bool.isRequired,
error: PropTypes.object,
settings: PropTypes.object.isRequired,
hasSettings: PropTypes.bool.isRequired,
onInputChange: PropTypes.func.isRequired
};
export default MetadataOptions;

View File

@@ -0,0 +1,101 @@
import PropTypes from 'prop-types';
import React, { Component } from 'react';
import { connect } from 'react-redux';
import { createSelector } from 'reselect';
import createSettingsSectionSelector from 'Store/Selectors/createSettingsSectionSelector';
import { fetchMetadataOptions, setMetadataOptionsValue, saveMetadataOptions } from 'Store/Actions/settingsActions';
import { clearPendingChanges } from 'Store/Actions/baseActions';
import MetadataOptions from './MetadataOptions';
const SECTION = 'metadataOptions';
function createMapStateToProps() {
return createSelector(
(state) => state.settings.advancedSettings,
createSettingsSectionSelector(SECTION),
(advancedSettings, sectionSettings) => {
return {
advancedSettings,
...sectionSettings
};
}
);
}
const mapDispatchToProps = {
dispatchFetchMetadataOptions: fetchMetadataOptions,
dispatchSetMetadataOptionsValue: setMetadataOptionsValue,
dispatchSaveMetadataOptions: saveMetadataOptions,
dispatchClearPendingChanges: clearPendingChanges
};
class MetadataOptionsConnector extends Component {
//
// Lifecycle
componentDidMount() {
const {
dispatchFetchMetadataOptions,
dispatchSaveMetadataOptions,
onChildMounted
} = this.props;
dispatchFetchMetadataOptions();
onChildMounted(dispatchSaveMetadataOptions);
}
componentDidUpdate(prevProps) {
const {
hasPendingChanges,
isSaving,
onChildStateChange
} = this.props;
if (
prevProps.isSaving !== isSaving ||
prevProps.hasPendingChanges !== hasPendingChanges
) {
onChildStateChange({
isSaving,
hasPendingChanges
});
}
}
componentWillUnmount() {
this.props.dispatchClearPendingChanges({ section: SECTION });
}
//
// Listeners
onInputChange = ({ name, value }) => {
this.props.dispatchSetMetadataOptionsValue({ name, value });
}
//
// Render
render() {
return (
<MetadataOptions
onInputChange={this.onInputChange}
{...this.props}
/>
);
}
}
MetadataOptionsConnector.propTypes = {
isSaving: PropTypes.bool.isRequired,
hasPendingChanges: PropTypes.bool.isRequired,
dispatchFetchMetadataOptions: PropTypes.func.isRequired,
dispatchSetMetadataOptionsValue: PropTypes.func.isRequired,
dispatchSaveMetadataOptions: PropTypes.func.isRequired,
dispatchClearPendingChanges: PropTypes.func.isRequired,
onChildMounted: PropTypes.func.isRequired,
onChildStateChange: PropTypes.func.isRequired
};
export default connect(createMapStateToProps, mapDispatchToProps)(MetadataOptionsConnector);

View File

@@ -0,0 +1,64 @@
import { createAction } from 'redux-actions';
import { createThunk } from 'Store/thunks';
import createSetSettingValueReducer from 'Store/Actions/Creators/Reducers/createSetSettingValueReducer';
import createFetchHandler from 'Store/Actions/Creators/createFetchHandler';
import createSaveHandler from 'Store/Actions/Creators/createSaveHandler';
//
// Variables
const section = 'settings.metadataOptions';
//
// Actions Types
export const FETCH_METADATA_OPTIONS = 'settings/metadataOptions/fetchMetadataOptions';
export const SAVE_METADATA_OPTIONS = 'settings/metadataOptions/saveMetadataOptions';
export const SET_METADATA_OPTIONS_VALUE = 'settings/metadataOptions/setMetadataOptionsValue';
//
// Action Creators
export const fetchMetadataOptions = createThunk(FETCH_METADATA_OPTIONS);
export const saveMetadataOptions = createThunk(SAVE_METADATA_OPTIONS);
export const setMetadataOptionsValue = createAction(SET_METADATA_OPTIONS_VALUE, (payload) => {
return {
section,
...payload
};
});
//
// Details
export default {
//
// State
defaultState: {
isFetching: false,
isPopulated: false,
error: null,
pendingChanges: {},
isSaving: false,
saveError: null,
item: {}
},
//
// Action Handlers
actionHandlers: {
[FETCH_METADATA_OPTIONS]: createFetchHandler(section, '/config/metadata'),
[SAVE_METADATA_OPTIONS]: createSaveHandler(section, '/config/metadata')
},
//
// Reducers
reducers: {
[SET_METADATA_OPTIONS_VALUE]: createSetSettingValueReducer(section)
}
};

View File

@@ -158,7 +158,7 @@ export const defaultState = {
{
name: 'certification',
label: 'Certification',
isSortable: false,
isSortable: true,
isVisible: false
},
{
@@ -320,7 +320,21 @@ export const defaultState = {
{
name: 'certification',
label: 'Certification',
type: filterBuilderTypes.EXACT
type: filterBuilderTypes.EXACT,
optionsSelector: function(items) {
const certificationList = items.reduce((acc, movie) => {
if (movie.certification) {
acc.push({
id: movie.certification,
name: movie.certification
});
}
return acc;
}, []);
return certificationList.sort(sortByName);
}
},
{
name: 'tags',

View File

@@ -15,6 +15,7 @@ import netImportOptions from './Settings/netImportOptions';
import netImports from './Settings/netImports';
import mediaManagement from './Settings/mediaManagement';
import metadata from './Settings/metadata';
import metadataOptions from './Settings/metadataOptions';
import naming from './Settings/naming';
import namingExamples from './Settings/namingExamples';
import notifications from './Settings/notifications';
@@ -38,6 +39,7 @@ export * from './Settings/netImportOptions';
export * from './Settings/netImports';
export * from './Settings/mediaManagement';
export * from './Settings/metadata';
export * from './Settings/metadataOptions';
export * from './Settings/naming';
export * from './Settings/namingExamples';
export * from './Settings/notifications';
@@ -72,6 +74,7 @@ export const defaultState = {
netImports: netImports.defaultState,
mediaManagement: mediaManagement.defaultState,
metadata: metadata.defaultState,
metadataOptions: metadataOptions.defaultState,
naming: naming.defaultState,
namingExamples: namingExamples.defaultState,
notifications: notifications.defaultState,
@@ -114,6 +117,7 @@ export const actionHandlers = handleThunks({
...netImports.actionHandlers,
...mediaManagement.actionHandlers,
...metadata.actionHandlers,
...metadataOptions.actionHandlers,
...naming.actionHandlers,
...namingExamples.actionHandlers,
...notifications.actionHandlers,
@@ -147,6 +151,7 @@ export const reducers = createHandleActions({
...netImports.reducers,
...mediaManagement.reducers,
...metadata.reducers,
...metadataOptions.reducers,
...naming.reducers,
...namingExamples.reducers,
...notifications.reducers,