You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
262 lines
6.2 KiB
262 lines
6.2 KiB
import { createAction } from 'redux-actions';
|
|
import { batchActions } from 'redux-batched-actions';
|
|
import createAjaxRequest from 'Utilities/createAjaxRequest';
|
|
import { filterBuilderTypes, filterBuilderValueTypes, sortDirections } from 'Helpers/Props';
|
|
import { createThunk, handleThunks } from 'Store/thunks';
|
|
import createSetTableOptionReducer from './Creators/Reducers/createSetTableOptionReducer';
|
|
import createSetClientSideCollectionSortReducer from './Creators/Reducers/createSetClientSideCollectionSortReducer';
|
|
import createSetClientSideCollectionFilterReducer from './Creators/Reducers/createSetClientSideCollectionFilterReducer';
|
|
import createHandleActions from './Creators/createHandleActions';
|
|
import { set, updateItem } from './baseActions';
|
|
import { filters, filterPredicates, sortPredicates } from './seriesActions';
|
|
|
|
//
|
|
// Variables
|
|
|
|
export const section = 'seriesEditor';
|
|
|
|
//
|
|
// State
|
|
|
|
export const defaultState = {
|
|
isSaving: false,
|
|
saveError: null,
|
|
isDeleting: false,
|
|
deleteError: null,
|
|
sortKey: 'sortTitle',
|
|
sortDirection: sortDirections.ASCENDING,
|
|
secondarySortKey: 'sortTitle',
|
|
secondarySortDirection: sortDirections.ASCENDING,
|
|
selectedFilterKey: 'all',
|
|
filters,
|
|
filterPredicates,
|
|
|
|
columns: [
|
|
{
|
|
name: 'status',
|
|
columnLabel: 'Status',
|
|
isSortable: true,
|
|
isVisible: true,
|
|
isModifiable: false
|
|
},
|
|
{
|
|
name: 'sortTitle',
|
|
label: 'Series Title',
|
|
isSortable: true,
|
|
isVisible: true,
|
|
isModifiable: false
|
|
},
|
|
{
|
|
name: 'qualityProfileId',
|
|
label: 'Quality Profile',
|
|
isSortable: true,
|
|
isVisible: true
|
|
},
|
|
{
|
|
name: 'languageProfileId',
|
|
label: 'Language Profile',
|
|
isSortable: false,
|
|
isVisible: true
|
|
},
|
|
{
|
|
name: 'seriesType',
|
|
label: 'Type',
|
|
isSortable: true,
|
|
isVisible: true
|
|
},
|
|
{
|
|
name: 'seasonFolder',
|
|
label: 'Season Folder',
|
|
isSortable: true,
|
|
isVisible: true
|
|
},
|
|
{
|
|
name: 'path',
|
|
label: 'Path',
|
|
isSortable: true,
|
|
isVisible: true
|
|
},
|
|
{
|
|
name: 'sizeOnDisk',
|
|
label: 'Size on Disk',
|
|
isSortable: true,
|
|
isVisible: false
|
|
},
|
|
{
|
|
name: 'tags',
|
|
label: 'Tags',
|
|
isSortable: false,
|
|
isVisible: true
|
|
}
|
|
],
|
|
|
|
filterBuilderProps: [
|
|
{
|
|
name: 'monitored',
|
|
label: 'Monitored',
|
|
type: filterBuilderTypes.EXACT,
|
|
valueType: filterBuilderValueTypes.BOOL
|
|
},
|
|
{
|
|
name: 'status',
|
|
label: 'Status',
|
|
type: filterBuilderTypes.EXACT,
|
|
valueType: filterBuilderValueTypes.SERIES_STATUS
|
|
},
|
|
{
|
|
name: 'seriesType',
|
|
label: 'Series Type',
|
|
type: filterBuilderTypes.EXACT
|
|
},
|
|
{
|
|
name: 'qualityProfileId',
|
|
label: 'Quality Profile',
|
|
type: filterBuilderTypes.EXACT,
|
|
valueType: filterBuilderValueTypes.QUALITY_PROFILE
|
|
},
|
|
{
|
|
name: 'languageProfileId',
|
|
label: 'Language Profile',
|
|
type: filterBuilderTypes.EXACT,
|
|
valueType: filterBuilderValueTypes.LANGUAGE_PROFILE
|
|
},
|
|
{
|
|
name: 'path',
|
|
label: 'Path',
|
|
type: filterBuilderTypes.STRING
|
|
},
|
|
{
|
|
name: 'rootFolderPath',
|
|
label: 'Root Folder Path',
|
|
type: filterBuilderTypes.EXACT
|
|
},
|
|
{
|
|
name: 'sizeOnDisk',
|
|
label: 'Size on Disk',
|
|
type: filterBuilderTypes.NUMBER,
|
|
valueType: filterBuilderValueTypes.BYTES
|
|
},
|
|
{
|
|
name: 'tags',
|
|
label: 'Tags',
|
|
type: filterBuilderTypes.ARRAY,
|
|
valueType: filterBuilderValueTypes.TAG
|
|
}
|
|
],
|
|
|
|
sortPredicates
|
|
};
|
|
|
|
export const persistState = [
|
|
'seriesEditor.sortKey',
|
|
'seriesEditor.sortDirection',
|
|
'seriesEditor.selectedFilterKey',
|
|
'seriesEditor.customFilters'
|
|
];
|
|
|
|
//
|
|
// Actions Types
|
|
|
|
export const SET_SERIES_EDITOR_SORT = 'seriesEditor/setSeriesEditorSort';
|
|
export const SET_SERIES_EDITOR_FILTER = 'seriesEditor/setSeriesEditorFilter';
|
|
export const SAVE_SERIES_EDITOR = 'seriesEditor/saveSeriesEditor';
|
|
export const BULK_DELETE_SERIES = 'seriesEditor/bulkDeleteSeries';
|
|
export const SET_SERIES_EDITOR_TABLE_OPTION = 'seriesIndex/setSeriesEditorTableOption';
|
|
|
|
//
|
|
// Action Creators
|
|
|
|
export const setSeriesEditorSort = createAction(SET_SERIES_EDITOR_SORT);
|
|
export const setSeriesEditorFilter = createAction(SET_SERIES_EDITOR_FILTER);
|
|
export const saveSeriesEditor = createThunk(SAVE_SERIES_EDITOR);
|
|
export const bulkDeleteSeries = createThunk(BULK_DELETE_SERIES);
|
|
export const setSeriesEditorTableOption = createAction(SET_SERIES_EDITOR_TABLE_OPTION);
|
|
|
|
//
|
|
// Action Handlers
|
|
|
|
export const actionHandlers = handleThunks({
|
|
[SAVE_SERIES_EDITOR]: function(getState, payload, dispatch) {
|
|
dispatch(set({
|
|
section,
|
|
isSaving: true
|
|
}));
|
|
|
|
const promise = createAjaxRequest({
|
|
url: '/series/editor',
|
|
method: 'PUT',
|
|
data: JSON.stringify(payload),
|
|
dataType: 'json'
|
|
}).request;
|
|
|
|
promise.done((data) => {
|
|
dispatch(batchActions([
|
|
...data.map((series) => {
|
|
return updateItem({
|
|
id: series.id,
|
|
section: 'series',
|
|
...series
|
|
});
|
|
}),
|
|
|
|
set({
|
|
section,
|
|
isSaving: false,
|
|
saveError: null
|
|
})
|
|
]));
|
|
});
|
|
|
|
promise.fail((xhr) => {
|
|
dispatch(set({
|
|
section,
|
|
isSaving: false,
|
|
saveError: xhr
|
|
}));
|
|
});
|
|
},
|
|
|
|
[BULK_DELETE_SERIES]: function(getState, payload, dispatch) {
|
|
dispatch(set({
|
|
section,
|
|
isDeleting: true
|
|
}));
|
|
|
|
const promise = createAjaxRequest({
|
|
url: '/series/editor',
|
|
method: 'DELETE',
|
|
data: JSON.stringify(payload),
|
|
dataType: 'json'
|
|
}).request;
|
|
|
|
promise.done(() => {
|
|
// SignaR will take care of removing the series from the collection
|
|
|
|
dispatch(set({
|
|
section,
|
|
isDeleting: false,
|
|
deleteError: null
|
|
}));
|
|
});
|
|
|
|
promise.fail((xhr) => {
|
|
dispatch(set({
|
|
section,
|
|
isDeleting: false,
|
|
deleteError: xhr
|
|
}));
|
|
});
|
|
}
|
|
});
|
|
|
|
//
|
|
// Reducers
|
|
|
|
export const reducers = createHandleActions({
|
|
|
|
[SET_SERIES_EDITOR_TABLE_OPTION]: createSetTableOptionReducer(section),
|
|
[SET_SERIES_EDITOR_SORT]: createSetClientSideCollectionSortReducer(section),
|
|
[SET_SERIES_EDITOR_FILTER]: createSetClientSideCollectionFilterReducer(section)
|
|
|
|
}, defaultState, section);
|