mirror of
https://github.com/Readarr/Readarr.git
synced 2026-04-18 21:34:28 -04:00
New: Add index views for all books
This commit is contained in:
@@ -2,9 +2,10 @@ import _ from 'lodash';
|
||||
import { createAction } from 'redux-actions';
|
||||
import { batchActions } from 'redux-batched-actions';
|
||||
import bookEntities from 'Book/bookEntities';
|
||||
import { sortDirections } from 'Helpers/Props';
|
||||
import { filterTypePredicates, filterTypes, sortDirections } from 'Helpers/Props';
|
||||
import { createThunk, handleThunks } from 'Store/thunks';
|
||||
import createAjaxRequest from 'Utilities/createAjaxRequest';
|
||||
import dateFilterPredicate from 'Utilities/Date/dateFilterPredicate';
|
||||
import { updateItem } from './baseActions';
|
||||
import createFetchHandler from './Creators/createFetchHandler';
|
||||
import createHandleActions from './Creators/createHandleActions';
|
||||
@@ -19,6 +20,113 @@ import createSetTableOptionReducer from './Creators/Reducers/createSetTableOptio
|
||||
|
||||
export const section = 'books';
|
||||
|
||||
export const filters = [
|
||||
{
|
||||
key: 'all',
|
||||
label: 'All',
|
||||
filters: []
|
||||
},
|
||||
{
|
||||
key: 'monitored',
|
||||
label: 'Monitored Only',
|
||||
filters: [
|
||||
{
|
||||
key: 'monitored',
|
||||
value: true,
|
||||
type: filterTypes.EQUAL
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
key: 'unmonitored',
|
||||
label: 'Unmonitored Only',
|
||||
filters: [
|
||||
{
|
||||
key: 'monitored',
|
||||
value: false,
|
||||
type: filterTypes.EQUAL
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
key: 'missing',
|
||||
label: 'Missing Books',
|
||||
filters: [
|
||||
{
|
||||
key: 'missing',
|
||||
value: true,
|
||||
type: filterTypes.EQUAL
|
||||
}
|
||||
]
|
||||
}
|
||||
];
|
||||
|
||||
export const filterPredicates = {
|
||||
missing: function(item) {
|
||||
const { statistics = {} } = item;
|
||||
|
||||
return statistics.bookFileCount === 0;
|
||||
},
|
||||
|
||||
releaseDate: function(item, filterValue, type) {
|
||||
return dateFilterPredicate(item.releaseDate, filterValue, type);
|
||||
},
|
||||
|
||||
added: function(item, filterValue, type) {
|
||||
return dateFilterPredicate(item.added, filterValue, type);
|
||||
},
|
||||
|
||||
qualityProfileId: function(item, filterValue, type) {
|
||||
const predicate = filterTypePredicates[type];
|
||||
|
||||
return predicate(item.author.qualityProfileId, filterValue);
|
||||
},
|
||||
|
||||
ratings: function(item, filterValue, type) {
|
||||
const predicate = filterTypePredicates[type];
|
||||
|
||||
return predicate(item.ratings.value * 10, filterValue);
|
||||
},
|
||||
|
||||
bookFileCount: function(item, filterValue, type) {
|
||||
const predicate = filterTypePredicates[type];
|
||||
const bookCount = item.statistics ? item.statistics.bookFileCount : 0;
|
||||
|
||||
return predicate(bookCount, filterValue);
|
||||
},
|
||||
|
||||
sizeOnDisk: function(item, filterValue, type) {
|
||||
const predicate = filterTypePredicates[type];
|
||||
const sizeOnDisk = item.statistics && item.statistics.sizeOnDisk ?
|
||||
item.statistics.sizeOnDisk :
|
||||
0;
|
||||
|
||||
return predicate(sizeOnDisk, filterValue);
|
||||
}
|
||||
};
|
||||
|
||||
export const sortPredicates = {
|
||||
status: function(item) {
|
||||
let result = 0;
|
||||
|
||||
if (item.monitored) {
|
||||
result += 2;
|
||||
}
|
||||
|
||||
if (item.status === 'continuing') {
|
||||
result++;
|
||||
}
|
||||
|
||||
return result;
|
||||
},
|
||||
|
||||
sizeOnDisk: function(item) {
|
||||
const { statistics = {} } = item;
|
||||
|
||||
return statistics.sizeOnDisk || 0;
|
||||
}
|
||||
};
|
||||
|
||||
//
|
||||
// State
|
||||
|
||||
|
||||
318
frontend/src/Store/Actions/bookIndexActions.js
Normal file
318
frontend/src/Store/Actions/bookIndexActions.js
Normal file
@@ -0,0 +1,318 @@
|
||||
import { createAction } from 'redux-actions';
|
||||
import { filterBuilderTypes, filterBuilderValueTypes, sortDirections } from 'Helpers/Props';
|
||||
import sortByName from 'Utilities/Array/sortByName';
|
||||
import { filterPredicates, filters, sortPredicates } from './bookActions';
|
||||
import createHandleActions from './Creators/createHandleActions';
|
||||
import createSetClientSideCollectionFilterReducer from './Creators/Reducers/createSetClientSideCollectionFilterReducer';
|
||||
import createSetClientSideCollectionSortReducer from './Creators/Reducers/createSetClientSideCollectionSortReducer';
|
||||
import createSetTableOptionReducer from './Creators/Reducers/createSetTableOptionReducer';
|
||||
|
||||
//
|
||||
// Variables
|
||||
|
||||
export const section = 'bookIndex';
|
||||
|
||||
//
|
||||
// State
|
||||
|
||||
export const defaultState = {
|
||||
sortKey: 'title',
|
||||
sortDirection: sortDirections.ASCENDING,
|
||||
secondarySortKey: 'title',
|
||||
secondarySortDirection: sortDirections.ASCENDING,
|
||||
view: 'posters',
|
||||
|
||||
posterOptions: {
|
||||
detailedProgressBar: false,
|
||||
size: 'large',
|
||||
showTitle: true,
|
||||
showAuthor: true,
|
||||
showMonitored: true,
|
||||
showQualityProfile: true,
|
||||
showSearchAction: false
|
||||
},
|
||||
|
||||
overviewOptions: {
|
||||
detailedProgressBar: false,
|
||||
size: 'medium',
|
||||
showReleaseDate: true,
|
||||
showMonitored: true,
|
||||
showQualityProfile: true,
|
||||
showAdded: false,
|
||||
showPath: false,
|
||||
showSizeOnDisk: false,
|
||||
showSearchAction: false
|
||||
},
|
||||
|
||||
tableOptions: {
|
||||
showSearchAction: false
|
||||
},
|
||||
|
||||
columns: [
|
||||
{
|
||||
name: 'status',
|
||||
columnLabel: 'Status',
|
||||
isSortable: true,
|
||||
isVisible: true,
|
||||
isModifiable: false
|
||||
},
|
||||
{
|
||||
name: 'title',
|
||||
label: 'Book',
|
||||
isSortable: true,
|
||||
isVisible: true,
|
||||
isModifiable: false
|
||||
},
|
||||
{
|
||||
name: 'authorName',
|
||||
label: 'Author',
|
||||
isSortable: true,
|
||||
isVisible: true,
|
||||
isModifiable: true
|
||||
},
|
||||
{
|
||||
name: 'releaseDate',
|
||||
label: 'Release Date',
|
||||
isSortable: true,
|
||||
isVisible: false
|
||||
},
|
||||
{
|
||||
name: 'qualityProfileId',
|
||||
label: 'Quality Profile',
|
||||
isSortable: true,
|
||||
isVisible: true
|
||||
},
|
||||
{
|
||||
name: 'added',
|
||||
label: 'Added',
|
||||
isSortable: true,
|
||||
isVisible: false
|
||||
},
|
||||
{
|
||||
name: 'bookFileCount',
|
||||
label: 'File Count',
|
||||
isSortable: true,
|
||||
isVisible: true
|
||||
},
|
||||
{
|
||||
name: 'path',
|
||||
label: 'Path',
|
||||
isSortable: true,
|
||||
isVisible: false
|
||||
},
|
||||
{
|
||||
name: 'sizeOnDisk',
|
||||
label: 'Size on Disk',
|
||||
isSortable: true,
|
||||
isVisible: false
|
||||
},
|
||||
{
|
||||
name: 'genres',
|
||||
label: 'Genres',
|
||||
isSortable: false,
|
||||
isVisible: false
|
||||
},
|
||||
{
|
||||
name: 'ratings',
|
||||
label: 'Rating',
|
||||
isSortable: true,
|
||||
isVisible: false
|
||||
},
|
||||
{
|
||||
name: 'tags',
|
||||
label: 'Tags',
|
||||
isSortable: false,
|
||||
isVisible: false
|
||||
},
|
||||
{
|
||||
name: 'actions',
|
||||
columnLabel: 'Actions',
|
||||
isVisible: true,
|
||||
isModifiable: false
|
||||
}
|
||||
],
|
||||
|
||||
sortPredicates: {
|
||||
...sortPredicates,
|
||||
|
||||
bookFileCount: function(item) {
|
||||
const { statistics = {} } = item;
|
||||
|
||||
return statistics.bookCount || 0;
|
||||
},
|
||||
|
||||
ratings: function(item) {
|
||||
const { ratings = {} } = item;
|
||||
|
||||
return ratings.value;
|
||||
}
|
||||
},
|
||||
|
||||
selectedFilterKey: 'all',
|
||||
|
||||
filters,
|
||||
|
||||
filterPredicates: {
|
||||
...filterPredicates
|
||||
},
|
||||
|
||||
filterBuilderProps: [
|
||||
{
|
||||
name: 'monitored',
|
||||
label: 'Monitored',
|
||||
type: filterBuilderTypes.EXACT,
|
||||
valueType: filterBuilderValueTypes.BOOL
|
||||
},
|
||||
{
|
||||
name: 'qualityProfileId',
|
||||
label: 'Quality Profile',
|
||||
type: filterBuilderTypes.EXACT,
|
||||
valueType: filterBuilderValueTypes.QUALITY_PROFILE
|
||||
},
|
||||
{
|
||||
name: 'releaseDate',
|
||||
label: 'Release Date',
|
||||
type: filterBuilderTypes.DATE,
|
||||
valueType: filterBuilderValueTypes.DATE
|
||||
},
|
||||
{
|
||||
name: 'added',
|
||||
label: 'Added',
|
||||
type: filterBuilderTypes.DATE,
|
||||
valueType: filterBuilderValueTypes.DATE
|
||||
},
|
||||
{
|
||||
name: 'bookFileCount',
|
||||
label: 'File Count',
|
||||
type: filterBuilderTypes.NUMBER
|
||||
},
|
||||
{
|
||||
name: 'path',
|
||||
label: 'Path',
|
||||
type: filterBuilderTypes.STRING
|
||||
},
|
||||
{
|
||||
name: 'sizeOnDisk',
|
||||
label: 'Size on Disk',
|
||||
type: filterBuilderTypes.NUMBER,
|
||||
valueType: filterBuilderValueTypes.BYTES
|
||||
},
|
||||
{
|
||||
name: 'genres',
|
||||
label: 'Genres',
|
||||
type: filterBuilderTypes.ARRAY,
|
||||
optionsSelector: function(items) {
|
||||
const tagList = items.reduce((acc, Book) => {
|
||||
Book.genres.forEach((genre) => {
|
||||
acc.push({
|
||||
id: genre,
|
||||
name: genre
|
||||
});
|
||||
});
|
||||
|
||||
return acc;
|
||||
}, []);
|
||||
|
||||
return tagList.sort(sortByName);
|
||||
}
|
||||
},
|
||||
{
|
||||
name: 'ratings',
|
||||
label: 'Rating',
|
||||
type: filterBuilderTypes.NUMBER
|
||||
},
|
||||
{
|
||||
name: 'tags',
|
||||
label: 'Tags',
|
||||
type: filterBuilderTypes.ARRAY,
|
||||
valueType: filterBuilderValueTypes.TAG
|
||||
}
|
||||
]
|
||||
};
|
||||
|
||||
export const persistState = [
|
||||
'bookIndex.sortKey',
|
||||
'bookIndex.sortDirection',
|
||||
'bookIndex.selectedFilterKey',
|
||||
'bookIndex.customFilters',
|
||||
'bookIndex.view',
|
||||
'bookIndex.columns',
|
||||
'bookIndex.posterOptions',
|
||||
'bookIndex.bannerOptions',
|
||||
'bookIndex.overviewOptions',
|
||||
'bookIndex.tableOptions'
|
||||
];
|
||||
|
||||
//
|
||||
// Actions Types
|
||||
|
||||
export const SET_BOOK_SORT = 'bookIndex/setBookSort';
|
||||
export const SET_BOOK_FILTER = 'bookIndex/setBookFilter';
|
||||
export const SET_BOOK_VIEW = 'bookIndex/setBookView';
|
||||
export const SET_BOOK_TABLE_OPTION = 'bookIndex/setBookTableOption';
|
||||
export const SET_BOOK_POSTER_OPTION = 'bookIndex/setBookPosterOption';
|
||||
export const SET_BOOK_BANNER_OPTION = 'bookIndex/setBookBannerOption';
|
||||
export const SET_BOOK_OVERVIEW_OPTION = 'bookIndex/setBookOverviewOption';
|
||||
|
||||
//
|
||||
// Action Creators
|
||||
|
||||
export const setBookSort = createAction(SET_BOOK_SORT);
|
||||
export const setBookFilter = createAction(SET_BOOK_FILTER);
|
||||
export const setBookView = createAction(SET_BOOK_VIEW);
|
||||
export const setBookTableOption = createAction(SET_BOOK_TABLE_OPTION);
|
||||
export const setBookPosterOption = createAction(SET_BOOK_POSTER_OPTION);
|
||||
export const setBookBannerOption = createAction(SET_BOOK_BANNER_OPTION);
|
||||
export const setBookOverviewOption = createAction(SET_BOOK_OVERVIEW_OPTION);
|
||||
|
||||
//
|
||||
// Reducers
|
||||
|
||||
export const reducers = createHandleActions({
|
||||
|
||||
[SET_BOOK_SORT]: createSetClientSideCollectionSortReducer(section),
|
||||
[SET_BOOK_FILTER]: createSetClientSideCollectionFilterReducer(section),
|
||||
|
||||
[SET_BOOK_VIEW]: function(state, { payload }) {
|
||||
return Object.assign({}, state, { view: payload.view });
|
||||
},
|
||||
|
||||
[SET_BOOK_TABLE_OPTION]: createSetTableOptionReducer(section),
|
||||
|
||||
[SET_BOOK_POSTER_OPTION]: function(state, { payload }) {
|
||||
const posterOptions = state.posterOptions;
|
||||
|
||||
return {
|
||||
...state,
|
||||
posterOptions: {
|
||||
...posterOptions,
|
||||
...payload
|
||||
}
|
||||
};
|
||||
},
|
||||
|
||||
[SET_BOOK_BANNER_OPTION]: function(state, { payload }) {
|
||||
const bannerOptions = state.bannerOptions;
|
||||
|
||||
return {
|
||||
...state,
|
||||
bannerOptions: {
|
||||
...bannerOptions,
|
||||
...payload
|
||||
}
|
||||
};
|
||||
},
|
||||
|
||||
[SET_BOOK_OVERVIEW_OPTION]: function(state, { payload }) {
|
||||
const overviewOptions = state.overviewOptions;
|
||||
|
||||
return {
|
||||
...state,
|
||||
overviewOptions: {
|
||||
...overviewOptions,
|
||||
...payload
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
}, defaultState, section);
|
||||
@@ -7,6 +7,7 @@ import * as blacklist from './blacklistActions';
|
||||
import * as books from './bookActions';
|
||||
import * as bookFiles from './bookFileActions';
|
||||
import * as bookHistory from './bookHistoryActions';
|
||||
import * as bookIndex from './bookIndexActions';
|
||||
import * as bookStudio from './bookshelfActions';
|
||||
import * as calendar from './calendarActions';
|
||||
import * as captcha from './captchaActions';
|
||||
@@ -38,6 +39,7 @@ export default [
|
||||
books,
|
||||
bookFiles,
|
||||
bookHistory,
|
||||
bookIndex,
|
||||
history,
|
||||
interactiveImportActions,
|
||||
oAuth,
|
||||
|
||||
@@ -0,0 +1,47 @@
|
||||
import { createSelector, createSelectorCreator, defaultMemoize } from 'reselect';
|
||||
import hasDifferentItemsOrOrder from 'Utilities/Object/hasDifferentItemsOrOrder';
|
||||
import createClientSideCollectionSelector from './createClientSideCollectionSelector';
|
||||
|
||||
function createUnoptimizedSelector(uiSection) {
|
||||
return createSelector(
|
||||
createClientSideCollectionSelector('books', uiSection),
|
||||
(books) => {
|
||||
const items = books.items.map((s) => {
|
||||
const {
|
||||
id,
|
||||
title,
|
||||
authorTitle
|
||||
} = s;
|
||||
|
||||
return {
|
||||
id,
|
||||
title,
|
||||
authorTitle
|
||||
};
|
||||
});
|
||||
|
||||
return {
|
||||
...books,
|
||||
items
|
||||
};
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
function bookListEqual(a, b) {
|
||||
return hasDifferentItemsOrOrder(a, b);
|
||||
}
|
||||
|
||||
const createBookEqualSelector = createSelectorCreator(
|
||||
defaultMemoize,
|
||||
bookListEqual
|
||||
);
|
||||
|
||||
function createBookClientSideCollectionItemsSelector(uiSection) {
|
||||
return createBookEqualSelector(
|
||||
createUnoptimizedSelector(uiSection),
|
||||
(book) => book
|
||||
);
|
||||
}
|
||||
|
||||
export default createBookClientSideCollectionItemsSelector;
|
||||
@@ -0,0 +1,16 @@
|
||||
import { createSelector } from 'reselect';
|
||||
import createBookSelector from './createBookSelector';
|
||||
|
||||
function createBookQualityProfileSelector() {
|
||||
return createSelector(
|
||||
(state) => state.settings.qualityProfiles.items,
|
||||
createBookSelector(),
|
||||
(qualityProfiles, book = {}) => {
|
||||
return qualityProfiles.find((profile) => {
|
||||
return profile.id === book.author.qualityProfileId;
|
||||
});
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
export default createBookQualityProfileSelector;
|
||||
@@ -1,5 +1,6 @@
|
||||
const scrollPositions = {
|
||||
authorIndex: 0
|
||||
authorIndex: 0,
|
||||
bookIndex: 0
|
||||
};
|
||||
|
||||
export default scrollPositions;
|
||||
|
||||
Reference in New Issue
Block a user