parent
7825319d89
commit
cd5b658196
@ -0,0 +1,143 @@
|
||||
import _ from 'lodash';
|
||||
import { handleActions } from 'redux-actions';
|
||||
import getSectionState from 'Utilities/State/getSectionState';
|
||||
import updateSectionState from 'Utilities/State/updateSectionState';
|
||||
import {
|
||||
SET,
|
||||
UPDATE,
|
||||
UPDATE_ITEM,
|
||||
UPDATE_SERVER_SIDE_COLLECTION,
|
||||
CLEAR_PENDING_CHANGES,
|
||||
REMOVE_ITEM
|
||||
} from 'Store/Actions/baseActions';
|
||||
|
||||
const blacklistedProperties = [
|
||||
'section',
|
||||
'id'
|
||||
];
|
||||
|
||||
export default function createHandleActions(handlers, defaultState, section) {
|
||||
return handleActions({
|
||||
|
||||
[SET]: function(state, { payload }) {
|
||||
const payloadSection = payload.section;
|
||||
const [baseSection] = payloadSection.split('.');
|
||||
|
||||
if (section === baseSection) {
|
||||
const newState = Object.assign(getSectionState(state, payloadSection),
|
||||
_.omit(payload, blacklistedProperties));
|
||||
|
||||
return updateSectionState(state, payloadSection, newState);
|
||||
}
|
||||
|
||||
return state;
|
||||
},
|
||||
|
||||
[UPDATE]: function(state, { payload }) {
|
||||
const payloadSection = payload.section;
|
||||
const [baseSection] = payloadSection.split('.');
|
||||
|
||||
if (section === baseSection) {
|
||||
const newState = getSectionState(state, payloadSection);
|
||||
|
||||
if (_.isArray(payload.data)) {
|
||||
newState.items = payload.data;
|
||||
} else {
|
||||
newState.item = payload.data;
|
||||
}
|
||||
|
||||
return updateSectionState(state, payloadSection, newState);
|
||||
}
|
||||
|
||||
return state;
|
||||
},
|
||||
|
||||
[UPDATE_ITEM]: function(state, { payload }) {
|
||||
const {
|
||||
section: payloadSection,
|
||||
updateOnly = false,
|
||||
...otherProps
|
||||
} = payload;
|
||||
|
||||
const [baseSection] = payloadSection.split('.');
|
||||
|
||||
if (section === baseSection) {
|
||||
const newState = getSectionState(state, payloadSection);
|
||||
const items = newState.items;
|
||||
const index = _.findIndex(items, { id: payload.id });
|
||||
|
||||
newState.items = [...items];
|
||||
|
||||
// TODO: Move adding to it's own reducer
|
||||
if (index >= 0) {
|
||||
const item = items[index];
|
||||
|
||||
newState.items.splice(index, 1, { ...item, ...otherProps });
|
||||
} else if (!updateOnly) {
|
||||
newState.items.push({ ...otherProps });
|
||||
}
|
||||
|
||||
return updateSectionState(state, payloadSection, newState);
|
||||
}
|
||||
|
||||
return state;
|
||||
},
|
||||
|
||||
[CLEAR_PENDING_CHANGES]: function(state, { payload }) {
|
||||
const payloadSection = payload.section;
|
||||
const [baseSection] = payloadSection.split('.');
|
||||
|
||||
if (section === baseSection) {
|
||||
const newState = getSectionState(state, payloadSection);
|
||||
newState.pendingChanges = {};
|
||||
|
||||
if (newState.hasOwnProperty('saveError')) {
|
||||
newState.saveError = null;
|
||||
}
|
||||
|
||||
return updateSectionState(state, payloadSection, newState);
|
||||
}
|
||||
|
||||
return state;
|
||||
},
|
||||
|
||||
[REMOVE_ITEM]: function(state, { payload }) {
|
||||
const payloadSection = payload.section;
|
||||
const [baseSection] = payloadSection.split('.');
|
||||
|
||||
if (section === baseSection) {
|
||||
const newState = getSectionState(state, payloadSection);
|
||||
|
||||
newState.items = [...newState.items];
|
||||
_.remove(newState.items, { id: payload.id });
|
||||
|
||||
return updateSectionState(state, payloadSection, newState);
|
||||
}
|
||||
|
||||
return state;
|
||||
},
|
||||
|
||||
[UPDATE_SERVER_SIDE_COLLECTION]: function(state, { payload }) {
|
||||
const payloadSection = payload.section;
|
||||
const [baseSection] = payloadSection.split('.');
|
||||
|
||||
if (section === baseSection) {
|
||||
const data = payload.data;
|
||||
const newState = getSectionState(state, payloadSection);
|
||||
|
||||
const serverState = _.omit(data, ['records']);
|
||||
const calculatedState = {
|
||||
totalPages: Math.max(Math.ceil(data.totalRecords / data.pageSize), 1),
|
||||
items: data.records
|
||||
};
|
||||
|
||||
return updateSectionState(state, payloadSection, Object.assign(newState, serverState, calculatedState));
|
||||
}
|
||||
|
||||
return state;
|
||||
},
|
||||
|
||||
...handlers
|
||||
|
||||
}, defaultState);
|
||||
}
|
@ -0,0 +1,103 @@
|
||||
import _ from 'lodash';
|
||||
import $ from 'jquery';
|
||||
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 createFetchSchemaHandler from 'Store/Actions/Creators/createFetchSchemaHandler';
|
||||
import createSaveProviderHandler from 'Store/Actions/Creators/createSaveProviderHandler';
|
||||
import createRemoveItemHandler from 'Store/Actions/Creators/createRemoveItemHandler';
|
||||
import { update } from 'Store/Actions/baseActions';
|
||||
|
||||
//
|
||||
// Variables
|
||||
|
||||
const section = 'settings.delayProfiles';
|
||||
|
||||
//
|
||||
// Actions Types
|
||||
|
||||
export const FETCH_DELAY_PROFILES = 'settings/delayProfiles/fetchDelayProfiles';
|
||||
export const FETCH_DELAY_PROFILE_SCHEMA = 'settings/delayProfiles/fetchDelayProfileSchema';
|
||||
export const SAVE_DELAY_PROFILE = 'settings/delayProfiles/saveDelayProfile';
|
||||
export const DELETE_DELAY_PROFILE = 'settings/delayProfiles/deleteDelayProfile';
|
||||
export const REORDER_DELAY_PROFILE = 'settings/delayProfiles/reorderDelayProfile';
|
||||
export const SET_DELAY_PROFILE_VALUE = 'settings/delayProfiles/setDelayProfileValue';
|
||||
|
||||
//
|
||||
// Action Creators
|
||||
|
||||
export const fetchDelayProfiles = createThunk(FETCH_DELAY_PROFILES);
|
||||
export const fetchDelayProfileSchema = createThunk(FETCH_DELAY_PROFILE_SCHEMA);
|
||||
export const saveDelayProfile = createThunk(SAVE_DELAY_PROFILE);
|
||||
export const deleteDelayProfile = createThunk(DELETE_DELAY_PROFILE);
|
||||
export const reorderDelayProfile = createThunk(REORDER_DELAY_PROFILE);
|
||||
|
||||
export const setDelayProfileValue = createAction(SET_DELAY_PROFILE_VALUE, (payload) => {
|
||||
return {
|
||||
section,
|
||||
...payload
|
||||
};
|
||||
});
|
||||
|
||||
//
|
||||
// Details
|
||||
|
||||
export default {
|
||||
|
||||
//
|
||||
// State
|
||||
|
||||
defaultState: {
|
||||
isFetching: false,
|
||||
isPopulated: false,
|
||||
error: null,
|
||||
items: [],
|
||||
isSaving: false,
|
||||
saveError: null,
|
||||
pendingChanges: {}
|
||||
},
|
||||
|
||||
//
|
||||
// Action Handlers
|
||||
|
||||
actionHandlers: {
|
||||
[FETCH_DELAY_PROFILES]: createFetchHandler(section, '/delayprofile'),
|
||||
[FETCH_DELAY_PROFILE_SCHEMA]: createFetchSchemaHandler(section, '/delayprofile/schema'),
|
||||
|
||||
[SAVE_DELAY_PROFILE]: createSaveProviderHandler(section, '/delayprofile'),
|
||||
[DELETE_DELAY_PROFILE]: createRemoveItemHandler(section, '/delayprofile'),
|
||||
|
||||
[REORDER_DELAY_PROFILE]: (getState, payload, dispatch) => {
|
||||
const { id, moveIndex } = payload;
|
||||
const moveOrder = moveIndex + 1;
|
||||
const delayProfiles = getState().settings.delayProfiles.items;
|
||||
const moving = _.find(delayProfiles, { id });
|
||||
|
||||
// Don't move if the order hasn't changed
|
||||
if (moving.order === moveOrder) {
|
||||
return;
|
||||
}
|
||||
|
||||
const after = moveIndex > 0 ? _.find(delayProfiles, { order: moveIndex }) : null;
|
||||
const afterQueryParam = after ? `after=${after.id}` : '';
|
||||
|
||||
const promise = $.ajax({
|
||||
method: 'PUT',
|
||||
url: `/delayprofile/reorder/${id}?${afterQueryParam}`
|
||||
});
|
||||
|
||||
promise.done((data) => {
|
||||
dispatch(update({ section, data }));
|
||||
});
|
||||
}
|
||||
},
|
||||
|
||||
//
|
||||
// Reducers
|
||||
|
||||
reducers: {
|
||||
[SET_DELAY_PROFILE_VALUE]: createSetSettingValueReducer(section)
|
||||
}
|
||||
|
||||
};
|
@ -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.downloadClientOptions';
|
||||
|
||||
//
|
||||
// Actions Types
|
||||
|
||||
export const FETCH_DOWNLOAD_CLIENT_OPTIONS = 'FETCH_DOWNLOAD_CLIENT_OPTIONS';
|
||||
export const SET_DOWNLOAD_CLIENT_OPTIONS_VALUE = 'SET_DOWNLOAD_CLIENT_OPTIONS_VALUE';
|
||||
export const SAVE_DOWNLOAD_CLIENT_OPTIONS = 'SAVE_DOWNLOAD_CLIENT_OPTIONS';
|
||||
|
||||
//
|
||||
// Action Creators
|
||||
|
||||
export const fetchDownloadClientOptions = createThunk(FETCH_DOWNLOAD_CLIENT_OPTIONS);
|
||||
export const saveDownloadClientOptions = createThunk(SAVE_DOWNLOAD_CLIENT_OPTIONS);
|
||||
export const setDownloadClientOptionsValue = createAction(SET_DOWNLOAD_CLIENT_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_DOWNLOAD_CLIENT_OPTIONS]: createFetchHandler(section, '/config/downloadclient'),
|
||||
[SAVE_DOWNLOAD_CLIENT_OPTIONS]: createSaveHandler(section, '/config/downloadclient')
|
||||
},
|
||||
|
||||
//
|
||||
// Reducers
|
||||
|
||||
reducers: {
|
||||
[SET_DOWNLOAD_CLIENT_OPTIONS_VALUE]: createSetSettingValueReducer(section)
|
||||
}
|
||||
|
||||
};
|
@ -0,0 +1,112 @@
|
||||
import { createAction } from 'redux-actions';
|
||||
import { createThunk } from 'Store/thunks';
|
||||
import selectProviderSchema from 'Utilities/State/selectProviderSchema';
|
||||
import createSetSettingValueReducer from 'Store/Actions/Creators/Reducers/createSetSettingValueReducer';
|
||||
import createSetProviderFieldValueReducer from 'Store/Actions/Creators/Reducers/createSetProviderFieldValueReducer';
|
||||
import createFetchHandler from 'Store/Actions/Creators/createFetchHandler';
|
||||
import createFetchSchemaHandler from 'Store/Actions/Creators/createFetchSchemaHandler';
|
||||
import createSaveProviderHandler, { createCancelSaveProviderHandler } from 'Store/Actions/Creators/createSaveProviderHandler';
|
||||
import createTestProviderHandler, { createCancelTestProviderHandler } from 'Store/Actions/Creators/createTestProviderHandler';
|
||||
import createRemoveItemHandler from 'Store/Actions/Creators/createRemoveItemHandler';
|
||||
|
||||
//
|
||||
// Variables
|
||||
|
||||
const section = 'settings.downloadClients';
|
||||
|
||||
//
|
||||
// Actions Types
|
||||
|
||||
export const FETCH_DOWNLOAD_CLIENTS = 'settings/downloadClients/fetchDownloadClients';
|
||||
export const FETCH_DOWNLOAD_CLIENT_SCHEMA = 'settings/downloadClients/fetchDownloadClientSchema';
|
||||
export const SELECT_DOWNLOAD_CLIENT_SCHEMA = 'settings/downloadClients/selectDownloadClientSchema';
|
||||
export const SET_DOWNLOAD_CLIENT_VALUE = 'settings/downloadClients/setDownloadClientValue';
|
||||
export const SET_DOWNLOAD_CLIENT_FIELD_VALUE = 'settings/downloadClients/setDownloadClientFieldValue';
|
||||
export const SAVE_DOWNLOAD_CLIENT = 'settings/downloadClients/saveDownloadClient';
|
||||
export const CANCEL_SAVE_DOWNLOAD_CLIENT = 'settings/downloadClients/cancelSaveDownloadClient';
|
||||
export const DELETE_DOWNLOAD_CLIENT = 'settings/downloadClients/deleteDownloadClient';
|
||||
export const TEST_DOWNLOAD_CLIENT = 'settings/downloadClients/testDownloadClient';
|
||||
export const CANCEL_TEST_DOWNLOAD_CLIENT = 'settings/downloadClients/cancelTestDownloadClient';
|
||||
|
||||
//
|
||||
// Action Creators
|
||||
|
||||
export const fetchDownloadClients = createThunk(FETCH_DOWNLOAD_CLIENTS);
|
||||
export const fetchDownloadClientSchema = createThunk(FETCH_DOWNLOAD_CLIENT_SCHEMA);
|
||||
export const selectDownloadClientSchema = createAction(SELECT_DOWNLOAD_CLIENT_SCHEMA);
|
||||
|
||||
export const saveDownloadClient = createThunk(SAVE_DOWNLOAD_CLIENT);
|
||||
export const cancelSaveDownloadClient = createThunk(CANCEL_SAVE_DOWNLOAD_CLIENT);
|
||||
export const deleteDownloadClient = createThunk(DELETE_DOWNLOAD_CLIENT);
|
||||
export const testDownloadClient = createThunk(TEST_DOWNLOAD_CLIENT);
|
||||
export const cancelTestDownloadClient = createThunk(CANCEL_TEST_DOWNLOAD_CLIENT);
|
||||
|
||||
export const setDownloadClientValue = createAction(SET_DOWNLOAD_CLIENT_VALUE, (payload) => {
|
||||
return {
|
||||
section,
|
||||
...payload
|
||||
};
|
||||
});
|
||||
|
||||
export const setDownloadClientFieldValue = createAction(SET_DOWNLOAD_CLIENT_FIELD_VALUE, (payload) => {
|
||||
return {
|
||||
section,
|
||||
...payload
|
||||
};
|
||||
});
|
||||
|
||||
//
|
||||
// Details
|
||||
|
||||
export default {
|
||||
|
||||
//
|
||||
// State
|
||||
|
||||
defaultState: {
|
||||
isFetching: false,
|
||||
isPopulated: false,
|
||||
error: null,
|
||||
isFetchingSchema: false,
|
||||
schemaPopulated: false,
|
||||
schemaError: null,
|
||||
schema: [],
|
||||
selectedSchema: {},
|
||||
isSaving: false,
|
||||
saveError: null,
|
||||
isTesting: false,
|
||||
items: [],
|
||||
pendingChanges: {}
|
||||
},
|
||||
|
||||
//
|
||||
// Action Handlers
|
||||
|
||||
actionHandlers: {
|
||||
[FETCH_DOWNLOAD_CLIENTS]: createFetchHandler(section, '/downloadclient'),
|
||||
[FETCH_DOWNLOAD_CLIENT_SCHEMA]: createFetchSchemaHandler(section, '/downloadclient/schema'),
|
||||
|
||||
[SAVE_DOWNLOAD_CLIENT]: createSaveProviderHandler(section, '/downloadclient'),
|
||||
[CANCEL_SAVE_DOWNLOAD_CLIENT]: createCancelSaveProviderHandler(section),
|
||||
[DELETE_DOWNLOAD_CLIENT]: createRemoveItemHandler(section, '/downloadclient'),
|
||||
[TEST_DOWNLOAD_CLIENT]: createTestProviderHandler(section, '/downloadclient'),
|
||||
[CANCEL_TEST_DOWNLOAD_CLIENT]: createCancelTestProviderHandler(section)
|
||||
},
|
||||
|
||||
//
|
||||
// Reducers
|
||||
|
||||
reducers: {
|
||||
[SET_DOWNLOAD_CLIENT_VALUE]: createSetSettingValueReducer(section),
|
||||
[SET_DOWNLOAD_CLIENT_FIELD_VALUE]: createSetProviderFieldValueReducer(section),
|
||||
|
||||
[SELECT_DOWNLOAD_CLIENT_SCHEMA]: (state, { payload }) => {
|
||||
return selectProviderSchema(state, section, payload, (selectedSchema) => {
|
||||
selectedSchema.enable = true;
|
||||
|
||||
return selectedSchema;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
};
|
@ -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.general';
|
||||
|
||||
//
|
||||
// Actions Types
|
||||
|
||||
export const FETCH_GENERAL_SETTINGS = 'settings/general/fetchGeneralSettings';
|
||||
export const SET_GENERAL_SETTINGS_VALUE = 'settings/general/setGeneralSettingsValue';
|
||||
export const SAVE_GENERAL_SETTINGS = 'settings/general/saveGeneralSettings';
|
||||
|
||||
//
|
||||
// Action Creators
|
||||
|
||||
export const fetchGeneralSettings = createThunk(FETCH_GENERAL_SETTINGS);
|
||||
export const saveGeneralSettings = createThunk(SAVE_GENERAL_SETTINGS);
|
||||
export const setGeneralSettingsValue = createAction(SET_GENERAL_SETTINGS_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_GENERAL_SETTINGS]: createFetchHandler(section, '/config/host'),
|
||||
[SAVE_GENERAL_SETTINGS]: createSaveHandler(section, '/config/host')
|
||||
},
|
||||
|
||||
//
|
||||
// Reducers
|
||||
|
||||
reducers: {
|
||||
[SET_GENERAL_SETTINGS_VALUE]: createSetSettingValueReducer(section)
|
||||
}
|
||||
|
||||
};
|
@ -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.indexerOptions';
|
||||
|
||||
//
|
||||
// Actions Types
|
||||
|
||||
export const FETCH_INDEXER_OPTIONS = 'settings/indexerOptions/fetchIndexerOptions';
|
||||
export const SAVE_INDEXER_OPTIONS = 'settings/indexerOptions/saveIndexerOptions';
|
||||
export const SET_INDEXER_OPTIONS_VALUE = 'settings/indexerOptions/setIndexerOptionsValue';
|
||||
|
||||
//
|
||||
// Action Creators
|
||||
|
||||
export const fetchIndexerOptions = createThunk(FETCH_INDEXER_OPTIONS);
|
||||
export const saveIndexerOptions = createThunk(SAVE_INDEXER_OPTIONS);
|
||||
export const setIndexerOptionsValue = createAction(SET_INDEXER_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_INDEXER_OPTIONS]: createFetchHandler(section, '/config/indexer'),
|
||||
[SAVE_INDEXER_OPTIONS]: createSaveHandler(section, '/config/indexer')
|
||||
},
|
||||
|
||||
//
|
||||
// Reducers
|
||||
|
||||
reducers: {
|
||||
[SET_INDEXER_OPTIONS_VALUE]: createSetSettingValueReducer(section)
|
||||
}
|
||||
|
||||
};
|
@ -0,0 +1,113 @@
|
||||
import { createAction } from 'redux-actions';
|
||||
import { createThunk } from 'Store/thunks';
|
||||
import selectProviderSchema from 'Utilities/State/selectProviderSchema';
|
||||
import createSetSettingValueReducer from 'Store/Actions/Creators/Reducers/createSetSettingValueReducer';
|
||||
import createSetProviderFieldValueReducer from 'Store/Actions/Creators/Reducers/createSetProviderFieldValueReducer';
|
||||
import createFetchHandler from 'Store/Actions/Creators/createFetchHandler';
|
||||
import createFetchSchemaHandler from 'Store/Actions/Creators/createFetchSchemaHandler';
|
||||
import createSaveProviderHandler, { createCancelSaveProviderHandler } from 'Store/Actions/Creators/createSaveProviderHandler';
|
||||
import createTestProviderHandler, { createCancelTestProviderHandler } from 'Store/Actions/Creators/createTestProviderHandler';
|
||||
import createRemoveItemHandler from 'Store/Actions/Creators/createRemoveItemHandler';
|
||||
|
||||
//
|
||||
// Variables
|
||||
|
||||
const section = 'settings.indexers';
|
||||
|
||||
//
|
||||
// Actions Types
|
||||
|
||||
export const FETCH_INDEXERS = 'settings/indexers/fetchIndexers';
|
||||
export const FETCH_INDEXER_SCHEMA = 'settings/indexers/fetchIndexerSchema';
|
||||
export const SELECT_INDEXER_SCHEMA = 'settings/indexers/selectIndexerSchema';
|
||||
export const SET_INDEXER_VALUE = 'settings/indexers/setIndexerValue';
|
||||
export const SET_INDEXER_FIELD_VALUE = 'settings/indexers/setIndexerFieldValue';
|
||||
export const SAVE_INDEXER = 'settings/indexers/saveIndexer';
|
||||
export const CANCEL_SAVE_INDEXER = 'settings/indexers/cancelSaveIndexer';
|
||||
export const DELETE_INDEXER = 'settings/indexers/deleteIndexer';
|
||||
export const TEST_INDEXER = 'settings/indexers/testIndexer';
|
||||
export const CANCEL_TEST_INDEXER = 'settings/indexers/cancelTestIndexer';
|
||||
|
||||
//
|
||||
// Action Creators
|
||||
|
||||
export const fetchIndexers = createThunk(FETCH_INDEXERS);
|
||||
export const fetchIndexerSchema = createThunk(FETCH_INDEXER_SCHEMA);
|
||||
export const selectIndexerSchema = createAction(SELECT_INDEXER_SCHEMA);
|
||||
|
||||
export const saveIndexer = createThunk(SAVE_INDEXER);
|
||||
export const cancelSaveIndexer = createThunk(CANCEL_SAVE_INDEXER);
|
||||
export const deleteIndexer = createThunk(DELETE_INDEXER);
|
||||
export const testIndexer = createThunk(TEST_INDEXER);
|
||||
export const cancelTestIndexer = createThunk(CANCEL_TEST_INDEXER);
|
||||
|
||||
export const setIndexerValue = createAction(SET_INDEXER_VALUE, (payload) => {
|
||||
return {
|
||||
section,
|
||||
...payload
|
||||
};
|
||||
});
|
||||
|
||||
export const setIndexerFieldValue = createAction(SET_INDEXER_FIELD_VALUE, (payload) => {
|
||||
return {
|
||||
section,
|
||||
...payload
|
||||
};
|
||||
});
|
||||
|
||||
//
|
||||
// Details
|
||||
|
||||
export default {
|
||||
|
||||
//
|
||||
// State
|
||||
|
||||
defaultState: {
|
||||
isFetching: false,
|
||||
isPopulated: false,
|
||||
error: null,
|
||||
isFetchingSchema: false,
|
||||
schemaPopulated: false,
|
||||
schemaError: null,
|
||||
schema: [],
|
||||
selectedSchema: {},
|
||||
isSaving: false,
|
||||
saveError: null,
|
||||
isTesting: false,
|
||||
items: [],
|
||||
pendingChanges: {}
|
||||
},
|
||||
|
||||
//
|
||||
// Action Handlers
|
||||
|
||||
actionHandlers: {
|
||||
[FETCH_INDEXERS]: createFetchHandler(section, '/indexer'),
|
||||
[FETCH_INDEXER_SCHEMA]: createFetchSchemaHandler(section, '/indexer/schema'),
|
||||
|
||||
[SAVE_INDEXER]: createSaveProviderHandler(section, '/indexer'),
|
||||
[CANCEL_SAVE_INDEXER]: createCancelSaveProviderHandler(section),
|
||||
[DELETE_INDEXER]: createRemoveItemHandler(section, '/indexer'),
|
||||
[TEST_INDEXER]: createTestProviderHandler(section, '/indexer'),
|
||||
[CANCEL_TEST_INDEXER]: createCancelTestProviderHandler(section)
|
||||
},
|
||||
|
||||
//
|
||||
// Reducers
|
||||
|
||||
reducers: {
|
||||
[SET_INDEXER_VALUE]: createSetSettingValueReducer(section),
|
||||
[SET_INDEXER_FIELD_VALUE]: createSetProviderFieldValueReducer(section),
|
||||
|
||||
[SELECT_INDEXER_SCHEMA]: (state, { payload }) => {
|
||||
return selectProviderSchema(state, section, payload, (selectedSchema) => {
|
||||
selectedSchema.enableRss = selectedSchema.supportsRss;
|
||||
selectedSchema.enableSearch = selectedSchema.supportsSearch;
|
||||
|
||||
return selectedSchema;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
};
|
@ -0,0 +1,79 @@
|
||||
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 createFetchSchemaHandler from 'Store/Actions/Creators/createFetchSchemaHandler';
|
||||
import createSaveProviderHandler from 'Store/Actions/Creators/createSaveProviderHandler';
|
||||
import createRemoveItemHandler from 'Store/Actions/Creators/createRemoveItemHandler';
|
||||
|
||||
//
|
||||
// Variables
|
||||
|
||||
const section = 'settings.languageProfiles';
|
||||
|
||||
//
|
||||
// Actions Types
|
||||
|
||||
export const FETCH_LANGUAGE_PROFILES = 'settings/languageProfiles/fetchLanguageProfiles';
|
||||
export const FETCH_LANGUAGE_PROFILE_SCHEMA = 'settings/languageProfiles/fetchLanguageProfileSchema';
|
||||
export const SAVE_LANGUAGE_PROFILE = 'settings/languageProfiles/saveLanguageProfile';
|
||||
export const DELETE_LANGUAGE_PROFILE = 'settings/languageProfiles/deleteLanguageProfile';
|
||||
export const SET_LANGUAGE_PROFILE_VALUE = 'settings/languageProfiles/setLanguageProfileValue';
|
||||
|
||||
//
|
||||
// Action Creators
|
||||
|
||||
export const fetchLanguageProfiles = createThunk(FETCH_LANGUAGE_PROFILES);
|
||||
export const fetchLanguageProfileSchema = createThunk(FETCH_LANGUAGE_PROFILE_SCHEMA);
|
||||
export const saveLanguageProfile = createThunk(SAVE_LANGUAGE_PROFILE);
|
||||
export const deleteLanguageProfile = createThunk(DELETE_LANGUAGE_PROFILE);
|
||||
|
||||
export const setLanguageProfileValue = createAction(SET_LANGUAGE_PROFILE_VALUE, (payload) => {
|
||||
return {
|
||||
section,
|
||||
...payload
|
||||
};
|
||||
});
|
||||
|
||||
//
|
||||
// Details
|
||||
|
||||
export default {
|
||||
|
||||
//
|
||||
// State
|
||||
|
||||
defaultState: {
|
||||
isFetching: false,
|
||||
isPopulated: false,
|
||||
error: null,
|
||||
isDeleting: false,
|
||||
deleteError: null,
|
||||
isFetchingSchema: false,
|
||||
schemaPopulated: false,
|
||||
schemaError: null,
|
||||
schema: {},
|
||||
isSaving: false,
|
||||
saveError: null,
|
||||
items: [],
|
||||
pendingChanges: {}
|
||||
},
|
||||
|
||||
//
|
||||
// Action Handlers
|
||||
|
||||
actionHandlers: {
|
||||
[FETCH_LANGUAGE_PROFILES]: createFetchHandler(section, '/languageprofile'),
|
||||
[FETCH_LANGUAGE_PROFILE_SCHEMA]: createFetchSchemaHandler(section, '/languageprofile/schema'),
|
||||
[SAVE_LANGUAGE_PROFILE]: createSaveProviderHandler(section, '/languageprofile'),
|
||||
[DELETE_LANGUAGE_PROFILE]: createRemoveItemHandler(section, '/languageprofile')
|
||||
},
|
||||
|
||||
//
|
||||
// Reducers
|
||||
|
||||
reducers: {
|
||||
[SET_LANGUAGE_PROFILE_VALUE]: createSetSettingValueReducer(section)
|
||||
}
|
||||
|
||||
};
|
@ -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.mediaManagement';
|
||||
|
||||
//
|
||||
// Actions Types
|
||||
|
||||
export const FETCH_MEDIA_MANAGEMENT_SETTINGS = 'settings/mediaManagement/fetchMediaManagementSettings';
|
||||
export const SAVE_MEDIA_MANAGEMENT_SETTINGS = 'settings/mediaManagement/saveMediaManagementSettings';
|
||||
export const SET_MEDIA_MANAGEMENT_SETTINGS_VALUE = 'settings/mediaManagement/setMediaManagementSettingsValue';
|
||||
|
||||
//
|
||||
// Action Creators
|
||||
|
||||
export const fetchMediaManagementSettings = createThunk(FETCH_MEDIA_MANAGEMENT_SETTINGS);
|
||||
export const saveMediaManagementSettings = createThunk(SAVE_MEDIA_MANAGEMENT_SETTINGS);
|
||||
export const setMediaManagementSettingsValue = createAction(SET_MEDIA_MANAGEMENT_SETTINGS_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_MEDIA_MANAGEMENT_SETTINGS]: createFetchHandler(section, '/config/mediamanagement'),
|
||||
[SAVE_MEDIA_MANAGEMENT_SETTINGS]: createSaveHandler(section, '/config/mediamanagement')
|
||||
},
|
||||
|
||||
//
|
||||
// Reducers
|
||||
|
||||
reducers: {
|
||||
[SET_MEDIA_MANAGEMENT_SETTINGS_VALUE]: createSetSettingValueReducer(section)
|
||||
}
|
||||
|
||||
};
|
@ -0,0 +1,75 @@
|
||||
import { createAction } from 'redux-actions';
|
||||
import { createThunk } from 'Store/thunks';
|
||||
import createSetSettingValueReducer from 'Store/Actions/Creators/Reducers/createSetSettingValueReducer';
|
||||
import createSetProviderFieldValueReducer from 'Store/Actions/Creators/Reducers/createSetProviderFieldValueReducer';
|
||||
import createFetchHandler from 'Store/Actions/Creators/createFetchHandler';
|
||||
import createSaveProviderHandler from 'Store/Actions/Creators/createSaveProviderHandler';
|
||||
|
||||
//
|
||||
// Variables
|
||||
|
||||
const section = 'settings.metadata';
|
||||
|
||||
//
|
||||
// Actions Types
|
||||
|
||||
export const FETCH_METADATA = 'settings/metadata/fetchMetadata';
|
||||
export const SET_METADATA_VALUE = 'settings/metadata/setMetadataValue';
|
||||
export const SET_METADATA_FIELD_VALUE = 'settings/metadata/setMetadataFieldValue';
|
||||
export const SAVE_METADATA = 'settings/metadata/saveMetadata';
|
||||
|
||||
//
|
||||
// Action Creators
|
||||
|
||||
export const fetchMetadata = createThunk(FETCH_METADATA);
|
||||
export const saveMetadata = createThunk(SAVE_METADATA);
|
||||
|
||||
export const setMetadataValue = createAction(SET_METADATA_VALUE, (payload) => {
|
||||
return {
|
||||
section,
|
||||
...payload
|
||||
};
|
||||
});
|
||||
|
||||
export const setMetadataFieldValue = createAction(SET_METADATA_FIELD_VALUE, (payload) => {
|
||||
return {
|
||||
section,
|
||||
...payload
|
||||
};
|
||||
});
|
||||
|
||||
//
|
||||
// Details
|
||||
|
||||
export default {
|
||||
|
||||
//
|
||||
// State
|
||||
|
||||
defaultState: {
|
||||
isFetching: false,
|
||||
isPopulated: false,
|
||||
error: null,
|
||||
isSaving: false,
|
||||
saveError: null,
|
||||
items: [],
|
||||
pendingChanges: {}
|
||||
},
|
||||
|
||||
//
|
||||
// Action Handlers
|
||||
|
||||
actionHandlers: {
|
||||
[FETCH_METADATA]: createFetchHandler(section, '/metadata'),
|
||||
[SAVE_METADATA]: createSaveProviderHandler(section, '/metadata')
|
||||
},
|
||||
|
||||
//
|
||||
// Reducers
|
||||
|
||||
reducers: {
|
||||
[SET_METADATA_VALUE]: createSetSettingValueReducer(section),
|
||||
[SET_METADATA_FIELD_VALUE]: createSetProviderFieldValueReducer(section)
|
||||
}
|
||||
|
||||
};
|
@ -0,0 +1,79 @@
|
||||
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 createFetchSchemaHandler from 'Store/Actions/Creators/createFetchSchemaHandler';
|
||||
import createSaveProviderHandler from 'Store/Actions/Creators/createSaveProviderHandler';
|
||||
import createRemoveItemHandler from 'Store/Actions/Creators/createRemoveItemHandler';
|
||||
|
||||
//
|
||||
// Variables
|
||||
|
||||
const section = 'settings.metadataProfiles';
|
||||
|
||||
//
|
||||
// Actions Types
|
||||
|
||||
export const FETCH_METADATA_PROFILES = 'settings/metadataProfiles/fetchMetadataProfiles';
|
||||
export const FETCH_METADATA_PROFILE_SCHEMA = 'settings/metadataProfiles/fetchMetadataProfileSchema';
|
||||
export const SAVE_METADATA_PROFILE = 'settings/metadataProfiles/saveMetadataProfile';
|
||||
export const DELETE_METADATA_PROFILE = 'settings/metadataProfiles/deleteMetadataProfile';
|
||||
export const SET_METADATA_PROFILE_VALUE = 'settings/metadataProfiles/setMetadataProfileValue';
|
||||
|
||||
//
|
||||
// Action Creators
|
||||
|
||||
export const fetchMetadataProfiles = createThunk(FETCH_METADATA_PROFILES);
|
||||
export const fetchMetadataProfileSchema = createThunk(FETCH_METADATA_PROFILE_SCHEMA);
|
||||
export const saveMetadataProfile = createThunk(SAVE_METADATA_PROFILE);
|
||||
export const deleteMetadataProfile = createThunk(DELETE_METADATA_PROFILE);
|
||||
|
||||
export const setMetadataProfileValue = createAction(SET_METADATA_PROFILE_VALUE, (payload) => {
|
||||
return {
|
||||
section,
|
||||
...payload
|
||||
};
|
||||
});
|
||||
|
||||
//
|
||||
// Details
|
||||
|
||||
export default {
|
||||
|
||||
//
|
||||
// State
|
||||
|
||||
defaultState: {
|
||||
isFetching: false,
|
||||
isPopulated: false,
|
||||
error: null,
|
||||
isDeleting: false,
|
||||
deleteError: null,
|
||||
isFetchingSchema: false,
|
||||
schemaPopulated: false,
|
||||
schemaError: null,
|
||||
schema: {},
|
||||
isSaving: false,
|
||||
saveError: null,
|
||||
items: [],
|
||||
pendingChanges: {}
|
||||
},
|
||||
|
||||
//
|
||||
// Action Handlers
|
||||
|
||||
actionHandlers: {
|
||||
[FETCH_METADATA_PROFILES]: createFetchHandler(section, '/metadataprofile'),
|
||||
[FETCH_METADATA_PROFILE_SCHEMA]: createFetchSchemaHandler(section, '/metadataprofile/schema'),
|
||||
[SAVE_METADATA_PROFILE]: createSaveProviderHandler(section, '/metadataprofile'),
|
||||
[DELETE_METADATA_PROFILE]: createRemoveItemHandler(section, '/metadataprofile')
|
||||
},
|
||||
|
||||
//
|
||||
// Reducers
|
||||
|
||||
reducers: {
|
||||
[SET_METADATA_PROFILE_VALUE]: createSetSettingValueReducer(section)
|
||||
}
|
||||
|
||||
};
|
@ -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.metadataProvider';
|
||||
|
||||
//
|
||||
// Actions Types
|
||||
|
||||
export const FETCH_METADATA_PROVIDER = 'settings/metadataProvider/fetchMetadataProvider';
|
||||
export const SET_METADATA_PROVIDER_VALUE = 'settings/metadataProvider/setMetadataProviderValue';
|
||||
export const SAVE_METADATA_PROVIDER = 'settings/metadataProvider/saveMetadataProvider';
|
||||
|
||||
//
|
||||
// Action Creators
|
||||
|
||||
export const fetchMetadataProvider = createThunk(FETCH_METADATA_PROVIDER);
|
||||
export const saveMetadataProvider = createThunk(SAVE_METADATA_PROVIDER);
|
||||
export const setMetadataProviderValue = createAction(SET_METADATA_PROVIDER_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_PROVIDER]: createFetchHandler(section, '/config/metadataProvider'),
|
||||
[SAVE_METADATA_PROVIDER]: createSaveHandler(section, '/config/metadataProvider')
|
||||
},
|
||||
|
||||
//
|
||||
// Reducers
|
||||
|
||||
reducers: {
|
||||
[SET_METADATA_PROVIDER_VALUE]: createSetSettingValueReducer(section)
|
||||
}
|
||||
|
||||
};
|
@ -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.naming';
|
||||
|
||||
//
|
||||
// Actions Types
|
||||
|
||||
export const FETCH_NAMING_SETTINGS = 'settings/naming/fetchNamingSettings';
|
||||
export const SAVE_NAMING_SETTINGS = 'settings/naming/saveNamingSettings';
|
||||
export const SET_NAMING_SETTINGS_VALUE = 'settings/naming/setNamingSettingsValue';
|
||||
|
||||
//
|
||||
// Action Creators
|
||||
|
||||
export const fetchNamingSettings = createThunk(FETCH_NAMING_SETTINGS);
|
||||
export const saveNamingSettings = createThunk(SAVE_NAMING_SETTINGS);
|
||||
export const setNamingSettingsValue = createAction(SET_NAMING_SETTINGS_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_NAMING_SETTINGS]: createFetchHandler(section, '/config/naming'),
|
||||
[SAVE_NAMING_SETTINGS]: createSaveHandler(section, '/config/naming')
|
||||
},
|
||||
|
||||
//
|
||||
// Reducers
|
||||
|
||||
reducers: {
|
||||
[SET_NAMING_SETTINGS_VALUE]: createSetSettingValueReducer(section)
|
||||
}
|
||||
|
||||
};
|
@ -0,0 +1,79 @@
|
||||
import $ from 'jquery';
|
||||
import { batchActions } from 'redux-batched-actions';
|
||||
import { createThunk } from 'Store/thunks';
|
||||
import { set, update } from 'Store/Actions/baseActions';
|
||||
|
||||
//
|
||||
// Variables
|
||||
|
||||
const section = 'settings.namingExamples';
|
||||
|
||||
//
|
||||
// Actions Types
|
||||
|
||||
export const FETCH_NAMING_EXAMPLES = 'settings/namingExamples/fetchNamingExamples';
|
||||
|
||||
//
|
||||
// Action Creators
|
||||
|
||||
export const fetchNamingExamples = createThunk(FETCH_NAMING_EXAMPLES);
|
||||
|
||||
//
|
||||
// Details
|
||||
|
||||
export default {
|
||||
|
||||
//
|
||||
// State
|
||||
|
||||
defaultState: {
|
||||
isFetching: false,
|
||||
isPopulated: false,
|
||||
error: null,
|
||||
item: {}
|
||||
},
|
||||
|
||||
//
|
||||
// Action Handlers
|
||||
|
||||
actionHandlers: {
|
||||
[FETCH_NAMING_EXAMPLES]: function(getState, payload, dispatch) {
|
||||
dispatch(set({ section, isFetching: true }));
|
||||
|
||||
const naming = getState().settings.naming;
|
||||
|
||||
const promise = $.ajax({
|
||||
url: '/config/naming/examples',
|
||||
data: Object.assign({}, naming.item, naming.pendingChanges)
|
||||
});
|
||||
|
||||
promise.done((data) => {
|
||||
dispatch(batchActions([
|
||||
update({ section, data }),
|
||||
|
||||
set({
|
||||
section,
|
||||
isFetching: false,
|
||||
isPopulated: true,
|
||||
error: null
|
||||
})
|
||||
]));
|
||||
});
|
||||
|
||||
promise.fail((xhr) => {
|
||||
dispatch(set({
|
||||
section,
|
||||
isFetching: false,
|
||||
isPopulated: false,
|
||||
error: xhr
|
||||
}));
|
||||
});
|
||||
}
|
||||
},
|
||||
|
||||
//
|
||||
// Reducers
|
||||
|
||||
reducers: {}
|
||||
|
||||
};
|
@ -0,0 +1,115 @@
|
||||
import { createAction } from 'redux-actions';
|
||||
import { createThunk } from 'Store/thunks';
|
||||
import selectProviderSchema from 'Utilities/State/selectProviderSchema';
|
||||
import createSetSettingValueReducer from 'Store/Actions/Creators/Reducers/createSetSettingValueReducer';
|
||||
import createSetProviderFieldValueReducer from 'Store/Actions/Creators/Reducers/createSetProviderFieldValueReducer';
|
||||
import createFetchHandler from 'Store/Actions/Creators/createFetchHandler';
|
||||
import createFetchSchemaHandler from 'Store/Actions/Creators/createFetchSchemaHandler';
|
||||
import createSaveProviderHandler, { createCancelSaveProviderHandler } from 'Store/Actions/Creators/createSaveProviderHandler';
|
||||
import createTestProviderHandler, { createCancelTestProviderHandler } from 'Store/Actions/Creators/createTestProviderHandler';
|
||||
import createRemoveItemHandler from 'Store/Actions/Creators/createRemoveItemHandler';
|
||||
|
||||
//
|
||||
// Variables
|
||||
|
||||
const section = 'settings.notifications';
|
||||
|
||||
//
|
||||
// Actions Types
|
||||
|
||||
export const FETCH_NOTIFICATIONS = 'settings/notifications/fetchNotifications';
|
||||
export const FETCH_NOTIFICATION_SCHEMA = 'settings/notifications/fetchNotificationSchema';
|
||||
export const SELECT_NOTIFICATION_SCHEMA = 'settings/notifications/selectNotificationSchema';
|
||||
export const SET_NOTIFICATION_VALUE = 'settings/notifications/setNotificationValue';
|
||||
export const SET_NOTIFICATION_FIELD_VALUE = 'settings/notifications/setNotificationFieldValue';
|
||||
export const SAVE_NOTIFICATION = 'settings/notifications/saveNotification';
|
||||
export const CANCEL_SAVE_NOTIFICATION = 'settings/notifications/cancelSaveNotification';
|
||||
export const DELETE_NOTIFICATION = 'settings/notifications/deleteNotification';
|
||||
export const TEST_NOTIFICATION = 'settings/notifications/testNotification';
|
||||
export const CANCEL_TEST_NOTIFICATION = 'settings/notifications/cancelTestNotification';
|
||||
|
||||
//
|
||||
// Action Creators
|
||||
|
||||
export const fetchNotifications = createThunk(FETCH_NOTIFICATIONS);
|
||||
export const fetchNotificationSchema = createThunk(FETCH_NOTIFICATION_SCHEMA);
|
||||
export const selectNotificationSchema = createAction(SELECT_NOTIFICATION_SCHEMA);
|
||||
|
||||
export const saveNotification = createThunk(SAVE_NOTIFICATION);
|
||||
export const cancelSaveNotification = createThunk(CANCEL_SAVE_NOTIFICATION);
|
||||
export const deleteNotification = createThunk(DELETE_NOTIFICATION);
|
||||
export const testNotification = createThunk(TEST_NOTIFICATION);
|
||||
export const cancelTestNotification = createThunk(CANCEL_TEST_NOTIFICATION);
|
||||
|
||||
export const setNotificationValue = createAction(SET_NOTIFICATION_VALUE, (payload) => {
|
||||
return {
|
||||
section,
|
||||
...payload
|
||||
};
|
||||
});
|
||||
|
||||
export const setNotificationFieldValue = createAction(SET_NOTIFICATION_FIELD_VALUE, (payload) => {
|
||||
return {
|
||||
section,
|
||||
...payload
|
||||
};
|
||||
});
|
||||
|
||||
//
|
||||
// Details
|
||||
|
||||
export default {
|
||||
|
||||
//
|
||||
// State
|
||||
|
||||
defaultState: {
|
||||
isFetching: false,
|
||||
isPopulated: false,
|
||||
error: null,
|
||||
isFetchingSchema: false,
|
||||
schemaPopulated: false,
|
||||
schemaError: null,
|
||||
schema: [],
|
||||
selectedSchema: {},
|
||||
isSaving: false,
|
||||
saveError: null,
|
||||
isTesting: false,
|
||||
items: [],
|
||||
pendingChanges: {}
|
||||
},
|
||||
|
||||
//
|
||||
// Action Handlers
|
||||
|
||||
actionHandlers: {
|
||||
[FETCH_NOTIFICATIONS]: createFetchHandler(section, '/notification'),
|
||||
[FETCH_NOTIFICATION_SCHEMA]: createFetchSchemaHandler(section, '/notification/schema'),
|
||||
|
||||
[SAVE_NOTIFICATION]: createSaveProviderHandler(section, '/notification'),
|
||||
[CANCEL_SAVE_NOTIFICATION]: createCancelSaveProviderHandler(section),
|
||||
[DELETE_NOTIFICATION]: createRemoveItemHandler(section, '/notification'),
|
||||
[TEST_NOTIFICATION]: createTestProviderHandler(section, '/notification'),
|
||||
[CANCEL_TEST_NOTIFICATION]: createCancelTestProviderHandler(section)
|
||||
},
|
||||
|
||||
//
|
||||
// Reducers
|
||||
|
||||
reducers: {
|
||||
[SET_NOTIFICATION_VALUE]: createSetSettingValueReducer(section),
|
||||
[SET_NOTIFICATION_FIELD_VALUE]: createSetProviderFieldValueReducer(section),
|
||||
|
||||
[SELECT_NOTIFICATION_SCHEMA]: (state, { payload }) => {
|
||||
return selectProviderSchema(state, section, payload, (selectedSchema) => {
|
||||
selectedSchema.onGrab = selectedSchema.supportsOnGrab;
|
||||
selectedSchema.onDownload = selectedSchema.supportsOnDownload;
|
||||
selectedSchema.onUpgrade = selectedSchema.supportsOnUpgrade;
|
||||
selectedSchema.onRename = selectedSchema.supportsOnRename;
|
||||
|
||||
return selectedSchema;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
};
|
@ -0,0 +1,116 @@
|
||||
import _ from 'lodash';
|
||||
import $ from 'jquery';
|
||||
import { createAction } from 'redux-actions';
|
||||
import { batchActions } from 'redux-batched-actions';
|
||||
import getSectionState from 'Utilities/State/getSectionState';
|
||||
import updateSectionState from 'Utilities/State/updateSectionState';
|
||||
import { createThunk } from 'Store/thunks';
|
||||
import createFetchHandler from 'Store/Actions/Creators/createFetchHandler';
|
||||
import createSaveHandler from 'Store/Actions/Creators/createSaveHandler';
|
||||
import { clearPendingChanges, update } from 'Store/Actions/baseActions';
|
||||
|
||||
//
|
||||
// Variables
|
||||
|
||||
const section = 'settings.qualityDefinitions';
|
||||
|
||||
//
|
||||
// Actions Types
|
||||
|
||||
export const FETCH_QUALITY_DEFINITIONS = 'settings/qualityDefinitions/fetchQualityDefinitions';
|
||||
export const SAVE_QUALITY_DEFINITIONS = 'settings/qualityDefinitions/saveQualityDefinitions';
|
||||
export const SET_QUALITY_DEFINITION_VALUE = 'settings/qualityDefinitions/setQualityDefinitionValue';
|
||||
|
||||
//
|
||||
// Action Creators
|
||||
|
||||
export const fetchQualityDefinitions = createThunk(FETCH_QUALITY_DEFINITIONS);
|
||||
export const saveQualityDefinitions = createThunk(SAVE_QUALITY_DEFINITIONS);
|
||||
|
||||
export const setQualityDefinitionValue = createAction(SET_QUALITY_DEFINITION_VALUE);
|
||||
|
||||
//
|
||||
// Details
|
||||
|
||||
export default {
|
||||
|
||||
//
|
||||
// State
|
||||
|
||||
defaultState: {
|
||||
isFetching: false,
|
||||
isPopulated: false,
|
||||
error: null,
|
||||
items: [],
|
||||
isSaving: false,
|
||||
saveError: null,
|
||||
pendingChanges: {}
|
||||
},
|
||||
|
||||
//
|
||||
// Action Handlers
|
||||
|
||||
actionHandlers: {
|
||||
[FETCH_QUALITY_DEFINITIONS]: createFetchHandler(section, '/qualitydefinition'),
|
||||
[SAVE_QUALITY_DEFINITIONS]: createSaveHandler(section, '/qualitydefinition'),
|
||||
|
||||
[SAVE_QUALITY_DEFINITIONS]: function(getState, payload, dispatch) {
|
||||
const qualityDefinitions = getState().settings.qualityDefinitions;
|
||||
|
||||
const upatedDefinitions = Object.keys(qualityDefinitions.pendingChanges).map((key) => {
|
||||
const id = parseInt(key);
|
||||
const pendingChanges = qualityDefinitions.pendingChanges[id] || {};
|
||||
const item = _.find(qualityDefinitions.items, { id });
|
||||
|
||||
return Object.assign({}, item, pendingChanges);
|
||||
});
|
||||
|
||||
// If there is nothing to save don't bother isSaving
|
||||
if (!upatedDefinitions || !upatedDefinitions.length) {
|
||||
return;
|
||||
}
|
||||
|
||||
const promise = $.ajax({
|
||||
method: 'PUT',
|
||||
url: '/qualityDefinition/update',
|
||||
data: JSON.stringify(upatedDefinitions)
|
||||
});
|
||||
|
||||
promise.done((data) => {
|
||||
dispatch(batchActions([
|
||||
update({ section, data }),
|
||||
clearPendingChanges({ section })
|
||||
]));
|
||||
});
|
||||
}
|
||||
},
|
||||
|
||||
//
|
||||
// Reducers
|
||||
|
||||
reducers: {
|
||||
[SET_QUALITY_DEFINITION_VALUE]: function(state, { payload }) {
|
||||
const { id, name, value } = payload;
|
||||
const newState = getSectionState(state, section);
|
||||
newState.pendingChanges = _.cloneDeep(newState.pendingChanges);
|
||||
|
||||
const pendingState = newState.pendingChanges[id] || {};
|
||||
const currentValue = _.find(newState.items, { id })[name];
|
||||
|
||||
if (currentValue === value) {
|
||||
delete pendingState[name];
|
||||
} else {
|
||||
pendingState[name] = value;
|
||||
}
|
||||
|
||||
if (_.isEmpty(pendingState)) {
|
||||
delete newState.pendingChanges[id];
|
||||
} else {
|
||||
newState.pendingChanges[id] = pendingState;
|
||||
}
|
||||
|
||||
return updateSectionState(state, section, newState);
|
||||
}
|
||||
}
|
||||
|
||||
};
|
@ -0,0 +1,79 @@
|
||||
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 createFetchSchemaHandler from 'Store/Actions/Creators/createFetchSchemaHandler';
|
||||
import createSaveProviderHandler from 'Store/Actions/Creators/createSaveProviderHandler';
|
||||
import createRemoveItemHandler from 'Store/Actions/Creators/createRemoveItemHandler';
|
||||
|
||||
//
|
||||
// Variables
|
||||
|
||||
const section = 'settings.qualityProfiles';
|
||||
|
||||
//
|
||||
// Actions Types
|
||||
|
||||
export const FETCH_QUALITY_PROFILES = 'settings/qualityProfiles/fetchQualityProfiles';
|
||||
export const FETCH_QUALITY_PROFILE_SCHEMA = 'settings/qualityProfiles/fetchQualityProfileSchema';
|
||||
export const SAVE_QUALITY_PROFILE = 'settings/qualityProfiles/saveQualityProfile';
|
||||
export const DELETE_QUALITY_PROFILE = 'settings/qualityProfiles/deleteQualityProfile';
|
||||
export const SET_QUALITY_PROFILE_VALUE = 'settings/qualityProfiles/setQualityProfileValue';
|
||||
|
||||
//
|
||||
// Action Creators
|
||||
|
||||
export const fetchQualityProfiles = createThunk(FETCH_QUALITY_PROFILES);
|
||||
export const fetchQualityProfileSchema = createThunk(FETCH_QUALITY_PROFILE_SCHEMA);
|
||||
export const saveQualityProfile = createThunk(SAVE_QUALITY_PROFILE);
|
||||
export const deleteQualityProfile = createThunk(DELETE_QUALITY_PROFILE);
|
||||
|
||||
export const setQualityProfileValue = createAction(SET_QUALITY_PROFILE_VALUE, (payload) => {
|
||||
return {
|
||||
section,
|
||||
...payload
|
||||
};
|
||||
});
|
||||
|
||||
//
|
||||
// Details
|
||||
|
||||
export default {
|
||||
|
||||
//
|
||||
// State
|
||||
|
||||
defaultState: {
|
||||
isFetching: false,
|
||||
isPopulated: false,
|
||||
error: null,
|
||||
isDeleting: false,
|
||||
deleteError: null,
|
||||
isFetchingSchema: false,
|
||||
schemaPopulated: false,
|
||||
schemaError: null,
|
||||
schema: {},
|
||||
isSaving: false,
|
||||
saveError: null,
|
||||
items: [],
|
||||
pendingChanges: {}
|
||||
},
|
||||
|
||||
//
|
||||
// Action Handlers
|
||||
|
||||
actionHandlers: {
|
||||
[FETCH_QUALITY_PROFILES]: createFetchHandler(section, '/qualityprofile'),
|
||||
[FETCH_QUALITY_PROFILE_SCHEMA]: createFetchSchemaHandler(section, '/qualityprofile/schema'),
|
||||
[SAVE_QUALITY_PROFILE]: createSaveProviderHandler(section, '/qualityprofile'),
|
||||
[DELETE_QUALITY_PROFILE]: createRemoveItemHandler(section, '/qualityprofile')
|
||||
},
|
||||
|
||||
//
|
||||
// Reducers
|
||||
|
||||
reducers: {
|
||||
[SET_QUALITY_PROFILE_VALUE]: createSetSettingValueReducer(section)
|
||||
}
|
||||
|
||||
};
|
@ -0,0 +1,69 @@
|
||||
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 createSaveProviderHandler from 'Store/Actions/Creators/createSaveProviderHandler';
|
||||
import createRemoveItemHandler from 'Store/Actions/Creators/createRemoveItemHandler';
|
||||
|
||||
//
|
||||
// Variables
|
||||
|
||||
const section = 'settings.remotePathMappings';
|
||||
|
||||
//
|
||||
// Actions Types
|
||||
|
||||
export const FETCH_REMOTE_PATH_MAPPINGS = 'settings/remotePathMappings/fetchRemotePathMappings';
|
||||
export const SAVE_REMOTE_PATH_MAPPING = 'settings/remotePathMappings/saveRemotePathMapping';
|
||||
export const DELETE_REMOTE_PATH_MAPPING = 'settings/remotePathMappings/deleteRemotePathMapping';
|
||||
export const SET_REMOTE_PATH_MAPPING_VALUE = 'settings/remotePathMappings/setRemotePathMappingValue';
|
||||
|
||||
//
|
||||
// Action Creators
|
||||
|
||||
export const fetchRemotePathMappings = createThunk(FETCH_REMOTE_PATH_MAPPINGS);
|
||||
export const saveRemotePathMapping = createThunk(SAVE_REMOTE_PATH_MAPPING);
|
||||
export const deleteRemotePathMapping = createThunk(DELETE_REMOTE_PATH_MAPPING);
|
||||
|
||||
export const setRemotePathMappingValue = createAction(SET_REMOTE_PATH_MAPPING_VALUE, (payload) => {
|
||||
return {
|
||||
section,
|
||||
...payload
|
||||
};
|
||||
});
|
||||
|
||||
//
|
||||
// Details
|
||||
|
||||
export default {
|
||||
|
||||
//
|
||||
// State
|
||||
|
||||
defaultState: {
|
||||
isFetching: false,
|
||||
isPopulated: false,
|
||||
error: null,
|
||||
items: [],
|
||||
isSaving: false,
|
||||
saveError: null,
|
||||
pendingChanges: {}
|
||||
},
|
||||
|
||||
//
|
||||
// Action Handlers
|
||||
|
||||
actionHandlers: {
|
||||
[FETCH_REMOTE_PATH_MAPPINGS]: createFetchHandler(section, '/remotepathmapping'),
|
||||
[SAVE_REMOTE_PATH_MAPPING]: createSaveProviderHandler(section, '/remotepathmapping'),
|
||||
[DELETE_REMOTE_PATH_MAPPING]: createRemoveItemHandler(section, '/remotepathmapping')
|
||||
},
|
||||
|
||||
//
|
||||
// Reducers
|
||||
|
||||
reducers: {
|
||||
[SET_REMOTE_PATH_MAPPING_VALUE]: createSetSettingValueReducer(section)
|
||||
}
|
||||
|
||||
};
|
@ -0,0 +1,71 @@
|
||||
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 createSaveProviderHandler from 'Store/Actions/Creators/createSaveProviderHandler';
|
||||
import createRemoveItemHandler from 'Store/Actions/Creators/createRemoveItemHandler';
|
||||
|
||||
//
|
||||
// Variables
|
||||
|
||||
const section = 'settings.restrictions';
|
||||
|
||||
//
|
||||
// Actions Types
|
||||
|
||||
export const FETCH_RESTRICTIONS = 'settings/restrictions/fetchRestrictions';
|
||||
export const SAVE_RESTRICTION = 'settings/restrictions/saveRestriction';
|
||||
export const DELETE_RESTRICTION = 'settings/restrictions/deleteRestriction';
|
||||
export const SET_RESTRICTION_VALUE = 'settings/restrictions/setRestrictionValue';
|
||||
|
||||
//
|
||||
// Action Creators
|
||||
|
||||
export const fetchRestrictions = createThunk(FETCH_RESTRICTIONS);
|
||||
export const saveRestriction = createThunk(SAVE_RESTRICTION);
|
||||
export const deleteRestriction = createThunk(DELETE_RESTRICTION);
|
||||
|
||||
export const setRestrictionValue = createAction(SET_RESTRICTION_VALUE, (payload) => {
|
||||
return {
|
||||
section,
|
||||
...payload
|
||||
};
|
||||
});
|
||||
|
||||
//
|
||||
// Details
|
||||
|
||||
export default {
|
||||
|
||||
//
|
||||
// State
|
||||
|
||||
defaultState: {
|
||||
isFetching: false,
|
||||
isPopulated: false,
|
||||
error: null,
|
||||
isSaving: false,
|
||||
saveError: null,
|
||||
items: [],
|
||||
pendingChanges: {}
|
||||
},
|
||||
|
||||
//
|
||||
// Action Handlers
|
||||
|
||||
actionHandlers: {
|
||||
[FETCH_RESTRICTIONS]: createFetchHandler(section, '/restriction'),
|
||||
|
||||
[SAVE_RESTRICTION]: createSaveProviderHandler(section, '/restriction'),
|
||||
|
||||
[DELETE_RESTRICTION]: createRemoveItemHandler(section, '/restriction')
|
||||
},
|
||||
|
||||
//
|
||||
// Reducers
|
||||
|
||||
reducers: {
|
||||
[SET_RESTRICTION_VALUE]: createSetSettingValueReducer(section)
|
||||
}
|
||||
|
||||
};
|
@ -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.ui';
|
||||
|
||||
//
|
||||
// Actions Types
|
||||
|
||||
export const FETCH_UI_SETTINGS = 'settings/ui/fetchUiSettings';
|
||||
export const SET_UI_SETTINGS_VALUE = 'SET_UI_SETTINGS_VALUE';
|
||||
export const SAVE_UI_SETTINGS = 'SAVE_UI_SETTINGS';
|
||||
|
||||
//
|
||||
// Action Creators
|
||||
|
||||
export const fetchUISettings = createThunk(FETCH_UI_SETTINGS);
|
||||
export const saveUISettings = createThunk(SAVE_UI_SETTINGS);
|
||||
export const setUISettingsValue = createAction(SET_UI_SETTINGS_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_UI_SETTINGS]: createFetchHandler(section, '/config/ui'),
|
||||
[SAVE_UI_SETTINGS]: createSaveHandler(section, '/config/ui')
|
||||
},
|
||||
|
||||
//
|
||||
// Reducers
|
||||
|
||||
reducers: {
|
||||
[SET_UI_SETTINGS_VALUE]: createSetSettingValueReducer(section)
|
||||
}
|
||||
|
||||
};
|
@ -1,94 +0,0 @@
|
||||
import _ from 'lodash';
|
||||
import $ from 'jquery';
|
||||
import { batchActions } from 'redux-batched-actions';
|
||||
import createAjaxRequest from 'Utilities/createAjaxRequest';
|
||||
import getNewArtist from 'Utilities/Artist/getNewArtist';
|
||||
import * as types from './actionTypes';
|
||||
import { set, update, updateItem } from './baseActions';
|
||||
|
||||
let abortCurrentRequest = null;
|
||||
const section = 'addArtist';
|
||||
|
||||
const addArtistActionHandlers = {
|
||||
[types.LOOKUP_ARTIST]: function(payload) {
|
||||
return function(dispatch, getState) {
|
||||
dispatch(set({ section, isFetching: true }));
|
||||
|
||||
if (abortCurrentRequest) {
|
||||
abortCurrentRequest();
|
||||
}
|
||||
|
||||
const { request, abortRequest } = createAjaxRequest({
|
||||
url: '/artist/lookup',
|
||||
data: {
|
||||
term: payload.term
|
||||
}
|
||||
});
|
||||
|
||||
abortCurrentRequest = abortRequest;
|
||||
|
||||
request.done((data) => {
|
||||
dispatch(batchActions([
|
||||
update({ section, data }),
|
||||
|
||||
set({
|
||||
section,
|
||||
isFetching: false,
|
||||
isPopulated: true,
|
||||
error: null
|
||||
})
|
||||
]));
|
||||
});
|
||||
|
||||
request.fail((xhr) => {
|
||||
dispatch(set({
|
||||
section,
|
||||
isFetching: false,
|
||||
isPopulated: false,
|
||||
error: xhr.aborted ? null : xhr
|
||||
}));
|
||||
});
|
||||
};
|
||||
},
|
||||
|
||||
[types.ADD_ARTIST]: function(payload) {
|
||||
return function(dispatch, getState) {
|
||||
dispatch(set({ section, isAdding: true }));
|
||||
|
||||
const foreignArtistId = payload.foreignArtistId;
|
||||
const items = getState().addArtist.items;
|
||||
const newSeries = getNewArtist(_.cloneDeep(_.find(items, { foreignArtistId })), payload);
|
||||
|
||||
const promise = $.ajax({
|
||||
url: '/artist',
|
||||
method: 'POST',
|
||||
contentType: 'application/json',
|
||||
data: JSON.stringify(newSeries)
|
||||
});
|
||||
|
||||
promise.done((data) => {
|
||||
dispatch(batchActions([
|
||||
updateItem({ section: 'artist', ...data }),
|
||||
|
||||
set({
|
||||
section,
|
||||
isAdding: false,
|
||||
isAdded: true,
|
||||
addError: null
|
||||
})
|
||||
]));
|
||||
});
|
||||
|
||||
promise.fail((xhr) => {
|
||||
dispatch(set({
|
||||
section,
|
||||
isAdding: false,
|
||||
isAdded: false,
|
||||
addError: xhr
|
||||
}));
|
||||
});
|
||||
};
|
||||
}
|
||||
};
|
||||
|
||||
export default addArtistActionHandlers;
|
@ -1,15 +1,180 @@
|
||||
import _ from 'lodash';
|
||||
import $ from 'jquery';
|
||||
import { createAction } from 'redux-actions';
|
||||
import * as types from './actionTypes';
|
||||
import addArtistActionHandlers from './addArtistActionHandlers';
|
||||
import { batchActions } from 'redux-batched-actions';
|
||||
import { createThunk, handleThunks } from 'Store/thunks';
|
||||
import getSectionState from 'Utilities/State/getSectionState';
|
||||
import updateSectionState from 'Utilities/State/updateSectionState';
|
||||
import createAjaxRequest from 'Utilities/createAjaxRequest';
|
||||
import getNewArtist from 'Utilities/Artist/getNewArtist';
|
||||
import createSetSettingValueReducer from './Creators/Reducers/createSetSettingValueReducer';
|
||||
import createHandleActions from './Creators/createHandleActions';
|
||||
import { set, update, updateItem } from './baseActions';
|
||||
|
||||
export const lookupArtist = addArtistActionHandlers[types.LOOKUP_ARTIST];
|
||||
export const addArtist = addArtistActionHandlers[types.ADD_ARTIST];
|
||||
export const clearAddArtist = createAction(types.CLEAR_ADD_ARTIST);
|
||||
export const setAddArtistDefault = createAction(types.SET_ADD_ARTIST_DEFAULT);
|
||||
//
|
||||
// Variables
|
||||
|
||||
export const setAddArtistValue = createAction(types.SET_ADD_ARTIST_VALUE, (payload) => {
|
||||
export const section = 'addArtist';
|
||||
let abortCurrentRequest = null;
|
||||
|
||||
//
|
||||
// State
|
||||
|
||||
export const defaultState = {
|
||||
isFetching: false,
|
||||
isPopulated: false,
|
||||
error: null,
|
||||
isAdding: false,
|
||||
isAdded: false,
|
||||
addError: null,
|
||||
items: [],
|
||||
|
||||
defaults: {
|
||||
rootFolderPath: '',
|
||||
monitor: 'allAlbums',
|
||||
qualityProfileId: 0,
|
||||
languageProfileId: 0,
|
||||
metadataProfileId: 0,
|
||||
albumFolder: true,
|
||||
tags: []
|
||||
}
|
||||
};
|
||||
|
||||
export const persistState = [
|
||||
'addArtist.defaults'
|
||||
];
|
||||
|
||||
//
|
||||
// Actions Types
|
||||
|
||||
export const LOOKUP_ARTIST = 'addArtist/lookupArtist';
|
||||
export const ADD_ARTIST = 'addArtist/addArtist';
|
||||
export const SET_ADD_ARTIST_VALUE = 'addArtist/setAddArtistValue';
|
||||
export const CLEAR_ADD_ARTIST = 'addArtist/clearAddArtist';
|
||||
export const SET_ADD_ARTIST_DEFAULT = 'addArtist/setAddArtistDefault';
|
||||
|
||||
//
|
||||
// Action Creators
|
||||
|
||||
export const lookupArtist = createThunk(LOOKUP_ARTIST);
|
||||
export const addArtist = createThunk(ADD_ARTIST);
|
||||
export const clearAddArtist = createAction(CLEAR_ADD_ARTIST);
|
||||
export const setAddArtistDefault = createAction(SET_ADD_ARTIST_DEFAULT);
|
||||
|
||||
export const setAddArtistValue = createAction(SET_ADD_ARTIST_VALUE, (payload) => {
|
||||
return {
|
||||
section: 'addArtist',
|
||||
section,
|
||||
...payload
|
||||
};
|
||||
});
|
||||
|
||||
//
|
||||
// Action Handlers
|
||||
|
||||
export const actionHandlers = handleThunks({
|
||||
|
||||
[LOOKUP_ARTIST]: function(getState, payload, dispatch) {
|
||||
dispatch(set({ section, isFetching: true }));
|
||||
|
||||
if (abortCurrentRequest) {
|
||||
abortCurrentRequest();
|
||||
}
|
||||
|
||||
const { request, abortRequest } = createAjaxRequest({
|
||||
url: '/artist/lookup',
|
||||
data: {
|
||||
term: payload.term
|
||||
}
|
||||
});
|
||||
|
||||
abortCurrentRequest = abortRequest;
|
||||
|
||||
request.done((data) => {
|
||||
dispatch(batchActions([
|
||||
update({ section, data }),
|
||||
|
||||
set({
|
||||
section,
|
||||
isFetching: false,
|
||||
isPopulated: true,
|
||||
error: null
|
||||
})
|
||||
]));
|
||||
});
|
||||
|
||||
request.fail((xhr) => {
|
||||
dispatch(set({
|
||||
section,
|
||||
isFetching: false,
|
||||
isPopulated: false,
|
||||
error: xhr.aborted ? null : xhr
|
||||
}));
|
||||
});
|
||||
},
|
||||
|
||||
[ADD_ARTIST]: function(getState, payload, dispatch) {
|
||||
dispatch(set({ section, isAdding: true }));
|
||||
|
||||
const foreignArtistId = payload.foreignArtistId;
|
||||
const items = getState().addArtist.items;
|
||||
const newArtist = getNewArtist(_.cloneDeep(_.find(items, { foreignArtistId })), payload);
|
||||
|
||||
const promise = $.ajax({
|
||||
url: '/artist',
|
||||
method: 'POST',
|
||||
contentType: 'application/json',
|
||||
data: JSON.stringify(newArtist)
|
||||
});
|
||||
|
||||
promise.done((data) => {
|
||||
dispatch(batchActions([
|
||||
updateItem({ section: 'artist', ...data }),
|
||||
|
||||
set({
|
||||
section,
|
||||
isAdding: false,
|
||||
isAdded: true,
|
||||
addError: null
|
||||
})
|
||||
]));
|
||||
});
|
||||
|
||||
promise.fail((xhr) => {
|
||||
dispatch(set({
|
||||
section,
|
||||
isAdding: false,
|
||||
isAdded: false,
|
||||
addError: xhr
|
||||
}));
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
//
|
||||
// Reducers
|
||||
|
||||
export const reducers = createHandleActions({
|
||||
|
||||
[SET_ADD_ARTIST_VALUE]: createSetSettingValueReducer(section),
|
||||
|
||||
[SET_ADD_ARTIST_DEFAULT]: function(state, { payload }) {
|
||||
const newState = getSectionState(state, section);
|
||||
|
||||
newState.defaults = {
|
||||
...newState.defaults,
|
||||
...payload
|
||||
};
|
||||
|
||||
return updateSectionState(state, section, newState);
|
||||
},
|
||||
|
||||
[CLEAR_ADD_ARTIST]: function(state) {
|
||||
const {
|
||||
defaults,
|
||||
...otherDefaultState
|
||||
} = defaultState;
|
||||
|
||||
return Object.assign({}, state, otherDefaultState);
|
||||
}
|
||||
|
||||
}, defaultState, section);
|
||||
|
@ -1,75 +0,0 @@
|
||||
import $ from 'jquery';
|
||||
import { batchActions } from 'redux-batched-actions';
|
||||
import { sortDirections } from 'Helpers/Props';
|
||||
import * as types from './actionTypes';
|
||||
import { set, update } from './baseActions';
|
||||
import { fetchAlbumHistory } from './albumHistoryActions';
|
||||
|
||||
const albumHistoryActionHandlers = {
|
||||
[types.FETCH_ALBUM_HISTORY]: function(payload) {
|
||||
const section = 'albumHistory';
|
||||
|
||||
return function(dispatch, getState) {
|
||||
dispatch(set({ section, isFetching: true }));
|
||||
|
||||
const queryParams = {
|
||||
pageSize: 1000,
|
||||
page: 1,
|
||||
filterKey: 'albumId',
|
||||
filterValue: payload.albumId,
|
||||
sortKey: 'date',
|
||||
sortDirection: sortDirections.DESCENDING
|
||||
};
|
||||
|
||||
const promise = $.ajax({
|
||||
url: '/history',
|
||||
data: queryParams
|
||||
});
|
||||
|
||||
promise.done((data) => {
|
||||
dispatch(batchActions([
|
||||
update({ section, data: data.records }),
|
||||
|
||||
set({
|
||||
section,
|
||||
isFetching: false,
|
||||
isPopulated: true,
|
||||
error: null
|
||||
})
|
||||
]));
|
||||
});
|
||||
|
||||
promise.fail((xhr) => {
|
||||
dispatch(set({
|
||||
section,
|
||||
isFetching: false,
|
||||
isPopulated: false,
|
||||
error: xhr
|
||||
}));
|
||||
});
|
||||
};
|
||||
},
|
||||
|
||||
[types.ALBUM_HISTORY_MARK_AS_FAILED]: function(payload) {
|
||||
return function(dispatch, getState) {
|
||||
const {
|
||||
historyId,
|
||||
albumId
|
||||
} = payload;
|
||||
|
||||
const promise = $.ajax({
|
||||
url: '/history/failed',
|
||||
method: 'POST',
|
||||
data: {
|
||||
id: historyId
|
||||
}
|
||||
});
|
||||
|
||||
promise.done(() => {
|
||||
dispatch(fetchAlbumHistory({ albumId }));
|
||||
});
|
||||
};
|
||||
}
|
||||
};
|
||||
|
||||
export default albumHistoryActionHandlers;
|
@ -1,83 +0,0 @@
|
||||
import _ from 'lodash';
|
||||
import $ from 'jquery';
|
||||
import getMonitoringOptions from 'Utilities/Artist/getMonitoringOptions';
|
||||
import * as types from './actionTypes';
|
||||
import { set } from './baseActions';
|
||||
import { fetchArtist } from './artistActions';
|
||||
|
||||
const section = 'albumStudio';
|
||||
|
||||
const albumStudioActionHandlers = {
|
||||
[types.SAVE_ALBUM_STUDIO]: function(payload) {
|
||||
return function(dispatch, getState) {
|
||||
const {
|
||||
artistIds,
|
||||
monitored,
|
||||
monitor
|
||||
} = payload;
|
||||
|
||||
let monitoringOptions = null;
|
||||
const artist = [];
|
||||
const allArtists = getState().artist.items;
|
||||
|
||||
artistIds.forEach((id) => {
|
||||
const s = _.find(allArtists, { id });
|
||||
const artistToUpdate = { id };
|
||||
|
||||
if (payload.hasOwnProperty('monitored')) {
|
||||
artistToUpdate.monitored = monitored;
|
||||
}
|
||||
|
||||
if (monitor) {
|
||||
const {
|
||||
albums,
|
||||
options: artistMonitoringOptions
|
||||
} = getMonitoringOptions(_.cloneDeep(s.albums), monitor);
|
||||
|
||||
if (!monitoringOptions) {
|
||||
monitoringOptions = artistMonitoringOptions;
|
||||
}
|
||||
|
||||
artistToUpdate.albums = albums;
|
||||
}
|
||||
|
||||
artist.push(artistToUpdate);
|
||||
});
|
||||
|
||||
dispatch(set({
|
||||
section,
|
||||
isSaving: true
|
||||
}));
|
||||
|
||||
const promise = $.ajax({
|
||||
url: '/albumStudio',
|
||||
method: 'POST',
|
||||
data: JSON.stringify({
|
||||
artist,
|
||||
monitoringOptions
|
||||
}),
|
||||
dataType: 'json'
|
||||
});
|
||||
|
||||
promise.done((data) => {
|
||||
dispatch(fetchArtist());
|
||||
|
||||
dispatch(set({
|
||||
section,
|
||||
isSaving: false,
|
||||
saveError: null
|
||||
}));
|
||||
});
|
||||
|
||||
promise.fail((xhr) => {
|
||||
dispatch(set({
|
||||
section,
|
||||
isSaving: false,
|
||||
saveError: xhr
|
||||
}));
|
||||
});
|
||||
};
|
||||
}
|
||||
};
|
||||
|
||||
export default albumStudioActionHandlers;
|
@ -1,132 +0,0 @@
|
||||
import _ from 'lodash';
|
||||
import $ from 'jquery';
|
||||
import { batchActions } from 'redux-batched-actions';
|
||||
import * as types from './actionTypes';
|
||||
import createFetchHandler from './Creators/createFetchHandler';
|
||||
import createSaveProviderHandler from './Creators/createSaveProviderHandler';
|
||||
import createRemoveItemHandler from './Creators/createRemoveItemHandler';
|
||||
import { updateItem } from './baseActions';
|
||||
|
||||
const section = 'artist';
|
||||
|
||||
const artistActionHandlers = {
|
||||
[types.FETCH_ARTIST]: createFetchHandler(section, '/artist'),
|
||||
|
||||
[types.SAVE_ARTIST]: createSaveProviderHandler(
|
||||
section,
|
||||
'/artist',
|
||||
(state) => state.artist),
|
||||
|
||||
[types.DELETE_ARTIST]: createRemoveItemHandler(
|
||||
section,
|
||||
'/artist',
|
||||
(state) => state.artist),
|
||||
|
||||
[types.TOGGLE_ARTIST_MONITORED]: function(payload) {
|
||||
return function(dispatch, getState) {
|
||||
const {
|
||||
artistId: id,
|
||||
monitored
|
||||
} = payload;
|
||||
|
||||
const artist = _.find(getState().artist.items, { id });
|
||||
|
||||
dispatch(updateItem({
|
||||
id,
|
||||
section,
|
||||
isSaving: true
|
||||
}));
|
||||
|
||||
const promise = $.ajax({
|
||||
url: `/artist/${id}`,
|
||||
method: 'PUT',
|
||||
data: JSON.stringify({
|
||||
...artist,
|
||||
monitored
|
||||
}),
|
||||
dataType: 'json'
|
||||
});
|
||||
|
||||
promise.done((data) => {
|
||||
dispatch(updateItem({
|
||||
id,
|
||||
section,
|
||||
isSaving: false,
|
||||
monitored
|
||||
}));
|
||||
});
|
||||
|
||||
promise.fail((xhr) => {
|
||||
dispatch(updateItem({
|
||||
id,
|
||||
section,
|
||||
isSaving: false
|
||||
}));
|
||||
});
|
||||
};
|
||||
},
|
||||
|
||||
[types.TOGGLE_ALBUM_MONITORED]: function(payload) {
|
||||
return function(dispatch, getState) {
|
||||
const {
|
||||
artistId: id,
|
||||
seasonNumber,
|
||||
monitored
|
||||
} = payload;
|
||||
|
||||
const artist = _.find(getState().artist.items, { id });
|
||||
const seasons = _.cloneDeep(artist.seasons);
|
||||
const season = _.find(seasons, { seasonNumber });
|
||||
|
||||
season.isSaving = true;
|
||||
|
||||
dispatch(updateItem({
|
||||
id,
|
||||
section,
|
||||
seasons
|
||||
}));
|
||||
|
||||
season.monitored = monitored;
|
||||
|
||||
const promise = $.ajax({
|
||||
url: `/artist/${id}`,
|
||||
method: 'PUT',
|
||||
data: JSON.stringify({
|
||||
...artist,
|
||||
seasons
|
||||
}),
|
||||
dataType: 'json'
|
||||
});
|
||||
|
||||
promise.done((data) => {
|
||||
const episodes = _.filter(getState().episodes.items, { artistId: id, seasonNumber });
|
||||
|
||||
dispatch(batchActions([
|
||||
updateItem({
|
||||
id,
|
||||
section,
|
||||
...data
|
||||
}),
|
||||
|
||||
...episodes.map((episode) => {
|
||||
return updateItem({
|
||||
id: episode.id,
|
||||
section: 'episodes',
|
||||
monitored
|
||||
});
|
||||
})
|
||||
]));
|
||||
});
|
||||
|
||||
promise.fail((xhr) => {
|
||||
dispatch(updateItem({
|
||||
id,
|
||||
section,
|
||||
seasons: artist.seasons
|
||||
}));
|
||||
});
|
||||
};
|
||||
}
|
||||
};
|
||||
|
||||
export default artistActionHandlers;
|
@ -1,16 +1,187 @@
|
||||
import _ from 'lodash';
|
||||
import $ from 'jquery';
|
||||
import { createAction } from 'redux-actions';
|
||||
import * as types from './actionTypes';
|
||||
import artistActionHandlers from './artistActionHandlers';
|
||||
import { batchActions } from 'redux-batched-actions';
|
||||
import { sortDirections } from 'Helpers/Props';
|
||||
import { createThunk, handleThunks } from 'Store/thunks';
|
||||
import createSetSettingValueReducer from './Creators/Reducers/createSetSettingValueReducer';
|
||||
import createFetchHandler from './Creators/createFetchHandler';
|
||||
import createSaveProviderHandler from './Creators/createSaveProviderHandler';
|
||||
import createRemoveItemHandler from './Creators/createRemoveItemHandler';
|
||||
import createHandleActions from './Creators/createHandleActions';
|
||||
import { updateItem } from './baseActions';
|
||||
|
||||
export const fetchArtist = artistActionHandlers[types.FETCH_ARTIST];
|
||||
export const saveArtist = artistActionHandlers[types.SAVE_ARTIST];
|
||||
export const deleteArtist = artistActionHandlers[types.DELETE_ARTIST];
|
||||
export const toggleArtistMonitored = artistActionHandlers[types.TOGGLE_ARTIST_MONITORED];
|
||||
export const toggleSeasonMonitored = artistActionHandlers[types.TOGGLE_ALBUM_MONITORED];
|
||||
//
|
||||
// Variables
|
||||
|
||||
export const setArtistValue = createAction(types.SET_ARTIST_VALUE, (payload) => {
|
||||
export const section = 'artist';
|
||||
|
||||
//
|
||||
// State
|
||||
|
||||
export const defaultState = {
|
||||
isFetching: false,
|
||||
isPopulated: false,
|
||||
error: null,
|
||||
isSaving: false,
|
||||
saveError: null,
|
||||
items: [],
|
||||
sortKey: 'sortName',
|
||||
sortDirection: sortDirections.ASCENDING,
|
||||
pendingChanges: {}
|
||||
};
|
||||
|
||||
//
|
||||
// Actions Types
|
||||
|
||||
export const FETCH_ARTIST = 'artist/fetchArtist';
|
||||
export const SET_ARTIST_VALUE = 'artist/setArtistValue';
|
||||
export const SAVE_ARTIST = 'artist/saveArtist';
|
||||
export const DELETE_ARTIST = 'artist/deleteArtist';
|
||||
|
||||
export const TOGGLE_ARTIST_MONITORED = 'artist/toggleArtistMonitored';
|
||||
export const TOGGLE_ALBUM_MONITORED = 'artist/toggleAlbumMonitored';
|
||||
|
||||
//
|
||||
// Action Creators
|
||||
|
||||
export const fetchArtist = createThunk(FETCH_ARTIST);
|
||||
export const saveArtist = createThunk(SAVE_ARTIST);
|
||||
export const deleteArtist = createThunk(DELETE_ARTIST);
|
||||
export const toggleArtistMonitored = createThunk(TOGGLE_ARTIST_MONITORED);
|
||||
export const toggleAlbumMonitored = createThunk(TOGGLE_ALBUM_MONITORED);
|
||||
|
||||
export const setArtistValue = createAction(SET_ARTIST_VALUE, (payload) => {
|
||||
return {
|
||||
section: 'artist',
|
||||
...payload
|
||||
};
|
||||
});
|
||||
|
||||
//
|
||||
// Action Handlers
|
||||
|
||||
export const actionHandlers = handleThunks({
|
||||
|
||||
[FETCH_ARTIST]: createFetchHandler(section, '/artist'),
|
||||
|
||||
[SAVE_ARTIST]: createSaveProviderHandler(
|
||||
section, '/artist'),
|
||||
|
||||
[DELETE_ARTIST]: createRemoveItemHandler(
|
||||
section,
|
||||
'/artist'
|
||||
),
|
||||
|
||||
[TOGGLE_ARTIST_MONITORED]: (getState, payload, dispatch) => {
|
||||
const {
|
||||
artistId: id,
|
||||
monitored
|
||||
} = payload;
|
||||
|
||||
const artist = _.find(getState().artist.items, { id });
|
||||
|
||||
dispatch(updateItem({
|
||||
id,
|
||||
section,
|
||||
isSaving: true
|
||||
}));
|
||||
|
||||
const promise = $.ajax({
|
||||
url: `/artist/${id}`,
|
||||
method: 'PUT',
|
||||
data: JSON.stringify({
|
||||
...artist,
|
||||
monitored
|
||||
}),
|
||||
dataType: 'json'
|
||||
});
|
||||
|
||||
promise.done((data) => {
|
||||
dispatch(updateItem({
|
||||
id,
|
||||
section,
|
||||
isSaving: false,
|
||||
monitored
|
||||
}));
|
||||
});
|
||||
|
||||
promise.fail((xhr) => {
|
||||
dispatch(updateItem({
|
||||
id,
|
||||
section,
|
||||
isSaving: false
|
||||
}));
|
||||
});
|
||||
},
|
||||
|
||||
[TOGGLE_ALBUM_MONITORED]: (getState, payload, dispatch) => {
|
||||
const {
|
||||
artistId: id,
|
||||
seasonNumber,
|
||||
monitored
|
||||
} = payload;
|
||||
|
||||
const artist = _.find(getState().artist.items, { id });
|
||||
const seasons = _.cloneDeep(artist.seasons);
|
||||
const season = _.find(seasons, { seasonNumber });
|
||||
|
||||
season.isSaving = true;
|
||||
|
||||
dispatch(updateItem({
|
||||
id,
|
||||
section,
|
||||
seasons
|
||||
}));
|
||||
|
||||
season.monitored = monitored;
|
||||
|
||||
const promise = $.ajax({
|
||||
url: `/artist/${id}`,
|
||||
method: 'PUT',
|
||||
data: JSON.stringify({
|
||||
...artist,
|
||||
seasons
|
||||
}),
|
||||
dataType: 'json'
|
||||
});
|
||||
|
||||
promise.done((data) => {
|
||||
const episodes = _.filter(getState().episodes.items, { artistId: id, seasonNumber });
|
||||
|
||||
dispatch(batchActions([
|
||||
updateItem({
|
||||
id,
|
||||
section,
|
||||
...data
|
||||
}),
|
||||
|
||||
...episodes.map((episode) => {
|
||||
return updateItem({
|
||||
id: episode.id,
|
||||
section: 'episodes',
|
||||
monitored
|
||||
});
|
||||
})
|
||||
]));
|
||||
});
|
||||
|
||||
promise.fail((xhr) => {
|
||||
dispatch(updateItem({
|
||||
id,
|
||||
section,
|
||||
seasons: artist.seasons
|
||||
}));
|
||||
});
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
//
|
||||
// Reducers
|
||||
|
||||
export const reducers = createHandleActions({
|
||||
|
||||
[SET_ARTIST_VALUE]: createSetSettingValueReducer(section)
|
||||
|
||||
}, defaultState, section);
|
||||
|
@ -1,86 +0,0 @@
|
||||
import $ from 'jquery';
|
||||
import { batchActions } from 'redux-batched-actions';
|
||||
import * as types from './actionTypes';
|
||||
import { set, updateItem } from './baseActions';
|
||||
|
||||
const section = 'artistEditor';
|
||||
|
||||
const artistEditorActionHandlers = {
|
||||
[types.SAVE_ARTIST_EDITOR]: function(payload) {
|
||||
return function(dispatch, getState) {
|
||||
dispatch(set({
|
||||
section,
|
||||
isSaving: true
|
||||
}));
|
||||
|
||||
const promise = $.ajax({
|
||||
url: '/artist/editor',
|
||||
method: 'PUT',
|
||||
data: JSON.stringify(payload),
|
||||
dataType: 'json'
|
||||
});
|
||||
|
||||
promise.done((data) => {
|
||||
dispatch(batchActions([
|
||||
...data.map((artist) => {
|
||||
return updateItem({
|
||||
id: artist.id,
|
||||
section: 'artist',
|
||||
...artist
|
||||
});
|
||||
}),
|
||||
|
||||
set({
|
||||
section,
|
||||
isSaving: false,
|
||||
saveError: null
|
||||
})
|
||||
]));
|
||||
});
|
||||
|
||||
promise.fail((xhr) => {
|
||||
dispatch(set({
|
||||
section,
|
||||
isSaving: false,
|
||||
saveError: xhr
|
||||
}));
|
||||
});
|
||||
};
|
||||
},
|
||||
|
||||
[types.BULK_DELETE_ARTIST]: function(payload) {
|
||||
return function(dispatch, getState) {
|
||||
dispatch(set({
|
||||
section,
|
||||
isDeleting: true
|
||||
}));
|
||||
|
||||
const promise = $.ajax({
|
||||
url: '/artist/editor',
|
||||
method: 'DELETE',
|
||||
data: JSON.stringify(payload),
|
||||
dataType: 'json'
|
||||
});
|
||||
|
||||
promise.done(() => {
|
||||
// SignaR will take care of removing the serires from the collection
|
||||
|
||||
dispatch(set({
|
||||
section,
|
||||
isDeleting: false,
|
||||
deleteError: null
|
||||
}));
|
||||
});
|
||||
|
||||
promise.fail((xhr) => {
|
||||
dispatch(set({
|
||||
section,
|
||||
isDeleting: false,
|
||||
deleteError: xhr
|
||||
}));
|
||||
});
|
||||
};
|
||||
}
|
||||
};
|
||||
|
||||
export default artistEditorActionHandlers;
|
@ -1,8 +1,142 @@
|
||||
import $ from 'jquery';
|
||||
import { createAction } from 'redux-actions';
|
||||
import * as types from './actionTypes';
|
||||
import artistEditorActionHandlers from './artistEditorActionHandlers';
|
||||
import { batchActions } from 'redux-batched-actions';
|
||||
import { filterTypes, sortDirections } from 'Helpers/Props';
|
||||
import { createThunk, handleThunks } from 'Store/thunks';
|
||||
import createSetClientSideCollectionSortReducer from './Creators/Reducers/createSetClientSideCollectionSortReducer';
|
||||
import createSetClientSideCollectionFilterReducer from './Creators/Reducers/createSetClientSideCollectionFilterReducer';
|
||||
import createHandleActions from './Creators/createHandleActions';
|
||||
import { set, updateItem } from './baseActions';
|
||||
|
||||
export const setArtistEditorSort = createAction(types.SET_ARTIST_EDITOR_SORT);
|
||||
export const setArtistEditorFilter = createAction(types.SET_ARTIST_EDITOR_FILTER);
|
||||
export const saveArtistEditor = artistEditorActionHandlers[types.SAVE_ARTIST_EDITOR];
|
||||
export const bulkDeleteArtist = artistEditorActionHandlers[types.BULK_DELETE_ARTIST];
|
||||
//
|
||||
// Variables
|
||||
|
||||
export const section = 'artistEditor';
|
||||
|
||||
//
|
||||
// State
|
||||
|
||||
export const defaultState = {
|
||||
isSaving: false,
|
||||
saveError: null,
|
||||
isDeleting: false,
|
||||
deleteError: null,
|
||||
sortKey: 'sortName',
|
||||
sortDirection: sortDirections.ASCENDING,
|
||||
secondarySortKey: 'sortName',
|
||||
secondarySortDirection: sortDirections.ASCENDING,
|
||||
filterKey: null,
|
||||
filterValue: null,
|
||||
filterType: filterTypes.EQUAL
|
||||
};
|
||||
|
||||
export const persistState = [
|
||||
'artistEditor.sortKey',
|
||||
'artistEditor.sortDirection',
|
||||
'artistEditor.filterKey',
|
||||
'artistEditor.filterValue',
|
||||
'artistEditor.filterType'
|
||||
];
|
||||
|
||||
//
|
||||
// Actions Types
|
||||
|
||||
export const SET_ARTIST_EDITOR_SORT = 'artistEditor/setArtistEditorSort';
|
||||
export const SET_ARTIST_EDITOR_FILTER = 'artistEditor/setArtistEditorFilter';
|
||||
export const SAVE_ARTIST_EDITOR = 'artistEditor/saveArtistEditor';
|
||||
export const BULK_DELETE_ARTIST = 'artistEditor/bulkDeleteArtist';
|
||||
|
||||
//
|
||||
// Action Creators
|
||||
|
||||
export const setArtistEditorSort = createAction(SET_ARTIST_EDITOR_SORT);
|
||||
export const setArtistEditorFilter = createAction(SET_ARTIST_EDITOR_FILTER);
|
||||
export const saveArtistEditor = createThunk(SAVE_ARTIST_EDITOR);
|
||||
export const bulkDeleteArtist = createThunk(BULK_DELETE_ARTIST);
|
||||
|
||||
//
|
||||
// Action Handlers
|
||||
|
||||
export const actionHandlers = handleThunks({
|
||||
[SAVE_ARTIST_EDITOR]: function(getState, payload, dispatch) {
|
||||
dispatch(set({
|
||||
section,
|
||||
isSaving: true
|
||||
}));
|
||||
|
||||
const promise = $.ajax({
|
||||
url: '/artist/editor',
|
||||
method: 'PUT',
|
||||
data: JSON.stringify(payload),
|
||||
dataType: 'json'
|
||||
});
|
||||
|
||||
promise.done((data) => {
|
||||
dispatch(batchActions([
|
||||
...data.map((artist) => {
|
||||
return updateItem({
|
||||
id: artist.id,
|
||||
section: 'artist',
|
||||
...artist
|
||||
});
|
||||
}),
|
||||
|
||||
set({
|
||||
section,
|
||||
isSaving: false,
|
||||
saveError: null
|
||||
})
|
||||
]));
|
||||
});
|
||||
|
||||
promise.fail((xhr) => {
|
||||
dispatch(set({
|
||||
section,
|
||||
isSaving: false,
|
||||
saveError: xhr
|
||||
}));
|
||||
});
|
||||
},
|
||||
|
||||
[BULK_DELETE_ARTIST]: function(getState, payload, dispatch) {
|
||||
dispatch(set({
|
||||
section,
|
||||
isDeleting: true
|
||||
}));
|
||||
|
||||
const promise = $.ajax({
|
||||
url: '/artist/editor',
|
||||
method: 'DELETE',
|
||||
data: JSON.stringify(payload),
|
||||
dataType: 'json'
|
||||
});
|
||||
|
||||
promise.done(() => {
|
||||
// SignaR will take care of removing the serires 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_ARTIST_EDITOR_SORT]: createSetClientSideCollectionSortReducer(section),
|
||||
[SET_ARTIST_EDITOR_FILTER]: createSetClientSideCollectionFilterReducer(section)
|
||||
|
||||
}, defaultState, section);
|
||||
|
@ -1,10 +1,279 @@
|
||||
import moment from 'moment';
|
||||
import { createAction } from 'redux-actions';
|
||||
import * as types from './actionTypes';
|
||||
|
||||
export const setArtistSort = createAction(types.SET_ARTIST_SORT);
|
||||
export const setArtistFilter = createAction(types.SET_ARTIST_FILTER);
|
||||
export const setArtistView = createAction(types.SET_ARTIST_VIEW);
|
||||
export const setArtistTableOption = createAction(types.SET_ARTIST_TABLE_OPTION);
|
||||
export const setArtistPosterOption = createAction(types.SET_ARTIST_POSTER_OPTION);
|
||||
export const setArtistBannerOption = createAction(types.SET_ARTIST_BANNER_OPTION);
|
||||
export const setArtistOverviewOption = createAction(types.SET_ARTIST_OVERVIEW_OPTION);
|
||||
import { filterTypes, sortDirections } from 'Helpers/Props';
|
||||
import createSetTableOptionReducer from './Creators/Reducers/createSetTableOptionReducer';
|
||||
import createSetClientSideCollectionSortReducer from './Creators/Reducers/createSetClientSideCollectionSortReducer';
|
||||
import createSetClientSideCollectionFilterReducer from './Creators/Reducers/createSetClientSideCollectionFilterReducer';
|
||||
import createHandleActions from './Creators/createHandleActions';
|
||||
|
||||
//
|
||||
// Variables
|
||||
|
||||
export const section = 'artistIndex';
|
||||
|
||||
//
|
||||
// State
|
||||
|
||||
export const defaultState = {
|
||||
sortKey: 'sortName',
|
||||
sortDirection: sortDirections.ASCENDING,
|
||||
secondarySortKey: 'sortName',
|
||||
secondarySortDirection: sortDirections.ASCENDING,
|
||||
filterKey: null,
|
||||
filterValue: null,
|
||||
filterType: filterTypes.EQUAL,
|
||||
view: 'posters',
|
||||
|
||||
posterOptions: {
|
||||
detailedProgressBar: false,
|
||||
size: 'large',
|
||||
showTitle: false,
|
||||
showQualityProfile: true
|
||||
},
|
||||
|
||||
bannerOptions: {
|
||||
detailedProgressBar: false,
|
||||
size: 'large',
|
||||
showTitle: false,
|
||||
showQualityProfile: true
|
||||
},
|
||||
|
||||
overviewOptions: {
|
||||
detailedProgressBar: false,
|
||||
size: 'medium',
|
||||
showNetwork: true,
|
||||
showQualityProfile: true,
|
||||
showPreviousAiring: false,
|
||||
showAdded: false,
|
||||
showAlbumCount: true,
|
||||
showPath: false,
|
||||
showSizeOnDisk: false
|
||||
},
|
||||
|
||||
columns: [
|
||||
{
|
||||
name: 'status',
|
||||
columnLabel: 'Status',
|
||||
isVisible: true,
|
||||
isModifiable: false
|
||||
},
|
||||
{
|
||||
name: 'sortName',
|
||||
label: 'Artist Name',
|
||||
isSortable: true,
|
||||
isVisible: true,
|
||||
isModifiable: false
|
||||
},
|
||||
{
|
||||
name: 'artistType',
|
||||
label: 'Type',
|
||||
isSortable: true,
|
||||
isVisible: true,
|
||||
isModifiable: false
|
||||
},
|
||||
{
|
||||
name: 'qualityProfileId',
|
||||
label: 'Quality Profile',
|
||||
isSortable: true,
|
||||
isVisible: true
|
||||
},
|
||||
{
|
||||
name: 'languageProfileId',
|
||||
label: 'Language Profile',
|
||||
isSortable: true,
|
||||
isVisible: false
|
||||
},
|
||||
{
|
||||
name: 'metadataProfileId',
|
||||
label: 'Metadata Profile',
|
||||
isSortable: true,
|
||||
isVisible: false
|
||||
},
|
||||
{
|
||||
name: 'nextAiring',
|
||||
label: 'Next Airing',
|
||||
isSortable: true,
|
||||
isVisible: true
|
||||
},
|
||||
{
|
||||
name: 'previousAiring',
|
||||
label: 'Previous Airing',
|
||||
isSortable: true,
|
||||
isVisible: false
|
||||
},
|
||||
{
|
||||
name: 'added',
|
||||
label: 'Added',
|
||||
isSortable: true,
|
||||
isVisible: false
|
||||
},
|
||||
{
|
||||
name: 'albumCount',
|
||||
label: 'Albums',
|
||||
isSortable: true,
|
||||
isVisible: true
|
||||
},
|
||||
{
|
||||
name: 'trackProgress',
|
||||
label: 'Tracks',
|
||||
isSortable: true,
|
||||
isVisible: true
|
||||
},
|
||||
{
|
||||
name: 'trackCount',
|
||||
label: 'Track Count',
|
||||
isSortable: true,
|
||||
isVisible: false
|
||||
},
|
||||
{
|
||||
name: 'latestAlbum',
|
||||
label: 'Latest Album',
|
||||
isSortable: true,
|
||||
isVisible: false
|
||||
},
|
||||
{
|
||||
name: 'path',
|
||||
label: 'Path',
|
||||
isSortable: true,
|
||||
isVisible: false
|
||||
},
|
||||
{
|
||||
name: 'sizeOnDisk',
|
||||
label: 'Size on Disk',
|
||||
isSortable: true,
|
||||
isVisible: false
|
||||
},
|
||||
{
|
||||
name: 'tags',
|
||||
label: 'Tags',
|
||||
isSortable: false,
|
||||
isVisible: false
|
||||
},
|
||||
{
|
||||
name: 'actions',
|
||||
columnLabel: 'Actions',
|
||||
isVisible: true,
|
||||
isModifiable: false
|
||||
}
|
||||
],
|
||||
|
||||
sortPredicates: {
|
||||
nextAiring: function(item, direction) {
|
||||
const nextAiring = item.nextAiring;
|
||||
|
||||
if (nextAiring) {
|
||||
return moment(nextAiring).unix();
|
||||
}
|
||||
|
||||
if (direction === sortDirections.DESCENDING) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
return Number.MAX_VALUE;
|
||||
},
|
||||
|
||||
trackProgress: function(item) {
|
||||
const {
|
||||
trackCount = 0,
|
||||
trackFileCount
|
||||
} = item;
|
||||
|
||||
const progress = trackCount ? trackFileCount / trackCount * 100 : 100;
|
||||
|
||||
return progress + trackCount / 1000000;
|
||||
}
|
||||
},
|
||||
|
||||
filterPredicates: {
|
||||
missing: function(item) {
|
||||
return item.trackCount - item.trackFileCount > 0;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
export const persistState = [
|
||||
'artistIndex.sortKey',
|
||||
'artistIndex.sortDirection',
|
||||
'artistIndex.filterKey',
|
||||
'artistIndex.filterValue',
|
||||
'artistIndex.filterType',
|
||||
'artistIndex.view',
|
||||
'artistIndex.columns',
|
||||
'artistIndex.posterOptions',
|
||||
'artistIndex.bannerOptions',
|
||||
'artistIndex.overviewOptions'
|
||||
];
|
||||
|
||||
//
|
||||
// Actions Types
|
||||
|
||||
export const SET_ARTIST_SORT = 'artistIndex/setArtistSort';
|
||||
export const SET_ARTIST_FILTER = 'artistIndex/setArtistFilter';
|
||||
export const SET_ARTIST_VIEW = 'artistIndex/setArtistView';
|
||||
export const SET_ARTIST_TABLE_OPTION = 'artistIndex/setArtistTableOption';
|
||||
export const SET_ARTIST_POSTER_OPTION = 'artistIndex/setArtistPosterOption';
|
||||
export const SET_ARTIST_BANNER_OPTION = 'artistIndex/setArtistBannerOption';
|
||||
export const SET_ARTIST_OVERVIEW_OPTION = 'artistIndex/setArtistOverviewOption';
|
||||
|
||||
//
|
||||
// Action Creators
|
||||
|
||||
export const setArtistSort = createAction(SET_ARTIST_SORT);
|
||||
export const setArtistFilter = createAction(SET_ARTIST_FILTER);
|
||||
export const setArtistView = createAction(SET_ARTIST_VIEW);
|
||||
export const setArtistTableOption = createAction(SET_ARTIST_TABLE_OPTION);
|
||||
export const setArtistPosterOption = createAction(SET_ARTIST_POSTER_OPTION);
|
||||
export const setArtistBannerOption = createAction(SET_ARTIST_BANNER_OPTION);
|
||||
export const setArtistOverviewOption = createAction(SET_ARTIST_OVERVIEW_OPTION);
|
||||
|
||||
//
|
||||
// Reducers
|
||||
|
||||
export const reducers = createHandleActions({
|
||||
|
||||
[SET_ARTIST_SORT]: createSetClientSideCollectionSortReducer(section),
|
||||
[SET_ARTIST_FILTER]: createSetClientSideCollectionFilterReducer(section),
|
||||
|
||||
[SET_ARTIST_VIEW]: function(state, { payload }) {
|
||||
return Object.assign({}, state, { view: payload.view });
|
||||
},
|
||||
|
||||
[SET_ARTIST_TABLE_OPTION]: createSetTableOptionReducer(section),
|
||||
|
||||
[SET_ARTIST_POSTER_OPTION]: function(state, { payload }) {
|
||||
const posterOptions = state.posterOptions;
|
||||
|
||||
return {
|
||||
...state,
|
||||
posterOptions: {
|
||||
...posterOptions,
|
||||
...payload
|
||||
}
|
||||
};
|
||||
},
|
||||
|
||||
[SET_ARTIST_BANNER_OPTION]: function(state, { payload }) {
|
||||
const bannerOptions = state.bannerOptions;
|
||||
|
||||
return {
|
||||
...state,
|
||||
bannerOptions: {
|
||||
...bannerOptions,
|
||||
...payload
|
||||
}
|
||||
};
|
||||
},
|
||||
|
||||
[SET_ARTIST_OVERVIEW_OPTION]: function(state, { payload }) {
|
||||
const overviewOptions = state.overviewOptions;
|
||||
|
||||
return {
|
||||
...state,
|
||||
overviewOptions: {
|
||||
...overviewOptions,
|
||||
...payload
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
}, defaultState, section);
|
||||
|
@ -1,13 +1,29 @@
|
||||
import { createAction } from 'redux-actions';
|
||||
import * as types from './actionTypes';
|
||||
|
||||
export const set = createAction(types.SET);
|
||||
//
|
||||
// Action Types
|
||||
|
||||
export const update = createAction(types.UPDATE);
|
||||
export const updateItem = createAction(types.UPDATE_ITEM);
|
||||
export const updateServerSideCollection = createAction(types.UPDATE_SERVER_SIDE_COLLECTION);
|
||||
export const SET = 'base/set';
|
||||
|
||||
export const setSettingValue = createAction(types.SET_SETTING_VALUE);
|
||||
export const clearPendingChanges = createAction(types.CLEAR_PENDING_CHANGES);
|
||||
export const UPDATE = 'base/update';
|
||||
export const UPDATE_ITEM = 'base/updateItem';
|
||||
export const UPDATE_SERVER_SIDE_COLLECTION = 'base/updateServerSideCollection';
|
||||
|
||||
export const removeItem = createAction(types.REMOVE_ITEM);
|
||||
export const SET_SETTING_VALUE = 'base/setSettingValue';
|
||||
export const CLEAR_PENDING_CHANGES = 'base/clearPendingChanges';
|
||||
|
||||
export const REMOVE_ITEM = 'base/removeItem';
|
||||
|
||||
//
|
||||
// Action Creators
|
||||
|
||||
export const set = createAction(SET);
|
||||
|
||||
export const update = createAction(UPDATE);
|
||||
export const updateItem = createAction(UPDATE_ITEM);
|
||||
export const updateServerSideCollection = createAction(UPDATE_SERVER_SIDE_COLLECTION);
|
||||
|
||||
export const setSettingValue = createAction(SET_SETTING_VALUE);
|
||||
export const clearPendingChanges = createAction(CLEAR_PENDING_CHANGES);
|
||||
|
||||
export const removeItem = createAction(REMOVE_ITEM);
|
||||
|
@ -1,17 +0,0 @@
|
||||
import serverSideCollectionHandlers from 'Utilities/serverSideCollectionHandlers';
|
||||
import * as types from './actionTypes';
|
||||
import createServerSideCollectionHandlers from './Creators/createServerSideCollectionHandlers';
|
||||
|
||||
const blacklistActionHandlers = {
|
||||
...createServerSideCollectionHandlers('blacklist', '/blacklist', (state) => state, {
|
||||
[serverSideCollectionHandlers.FETCH]: types.FETCH_BLACKLIST,
|
||||
[serverSideCollectionHandlers.FIRST_PAGE]: types.GOTO_FIRST_BLACKLIST_PAGE,
|
||||
[serverSideCollectionHandlers.PREVIOUS_PAGE]: types.GOTO_PREVIOUS_BLACKLIST_PAGE,
|
||||
[serverSideCollectionHandlers.NEXT_PAGE]: types.GOTO_NEXT_BLACKLIST_PAGE,
|
||||
[serverSideCollectionHandlers.LAST_PAGE]: types.GOTO_LAST_BLACKLIST_PAGE,
|
||||
[serverSideCollectionHandlers.EXACT_PAGE]: types.GOTO_BLACKLIST_PAGE,
|
||||
[serverSideCollectionHandlers.SORT]: types.SET_BLACKLIST_SORT
|
||||
})
|
||||
};
|
||||
|
||||
export default blacklistActionHandlers;
|
@ -1,12 +1,127 @@
|
||||
import { createAction } from 'redux-actions';
|
||||
import * as types from './actionTypes';
|
||||
import blacklistActionHandlers from './blacklistActionHandlers';
|
||||
|
||||
export const fetchBlacklist = blacklistActionHandlers[types.FETCH_BLACKLIST];
|
||||
export const gotoBlacklistFirstPage = blacklistActionHandlers[types.GOTO_FIRST_BLACKLIST_PAGE];
|
||||
export const gotoBlacklistPreviousPage = blacklistActionHandlers[types.GOTO_PREVIOUS_BLACKLIST_PAGE];
|
||||
export const gotoBlacklistNextPage = blacklistActionHandlers[types.GOTO_NEXT_BLACKLIST_PAGE];
|
||||
export const gotoBlacklistLastPage = blacklistActionHandlers[types.GOTO_LAST_BLACKLIST_PAGE];
|
||||
export const gotoBlacklistPage = blacklistActionHandlers[types.GOTO_BLACKLIST_PAGE];
|
||||
export const setBlacklistSort = blacklistActionHandlers[types.SET_BLACKLIST_SORT];
|
||||
export const setBlacklistTableOption = createAction(types.SET_BLACKLIST_TABLE_OPTION);
|
||||
import serverSideCollectionHandlers from 'Utilities/serverSideCollectionHandlers';
|
||||
import { createThunk, handleThunks } from 'Store/thunks';
|
||||
import { sortDirections } from 'Helpers/Props';
|
||||
import createSetTableOptionReducer from './Creators/Reducers/createSetTableOptionReducer';
|
||||
import createHandleActions from './Creators/createHandleActions';
|
||||
import createServerSideCollectionHandlers from './Creators/createServerSideCollectionHandlers';
|
||||
|
||||
//
|
||||
// Variables
|
||||
|
||||
export const section = 'blacklist';
|
||||
|
||||
//
|
||||
// State
|
||||
|
||||
export const defaultState = {
|
||||
isFetching: false,
|
||||
isPopulated: false,
|
||||
pageSize: 20,
|
||||
sortKey: 'date',
|
||||
sortDirection: sortDirections.DESCENDING,
|
||||
error: null,
|
||||
items: [],
|
||||
|
||||
columns: [
|
||||
{
|
||||
name: 'artist.sortName',
|
||||
label: 'Artist Name',
|
||||
isSortable: true,
|
||||
isVisible: true
|
||||
},
|
||||
{
|
||||
name: 'sourceTitle',
|
||||
label: 'Source Title',
|
||||
isSortable: true,
|
||||
isVisible: true
|
||||
},
|
||||
{
|
||||
name: 'language',
|
||||
label: 'Language',
|
||||
isVisible: false
|
||||
},
|
||||
{
|
||||
name: 'quality',
|
||||
label: 'Quality',
|
||||
isVisible: true
|
||||
},
|
||||
{
|
||||
name: 'date',
|
||||
label: 'Date',
|
||||
isSortable: true,
|
||||
isVisible: true
|
||||
},
|
||||
{
|
||||
name: 'indexer',
|
||||
label: 'Indexer',
|
||||
isSortable: true,
|
||||
isVisible: false
|
||||
},
|
||||
{
|
||||
name: 'details',
|
||||
columnLabel: 'Details',
|
||||
isVisible: true,
|
||||
isModifiable: false
|
||||
}
|
||||
]
|
||||
};
|
||||
|
||||
export const persistState = [
|
||||
'blacklist.pageSize',
|
||||
'blacklist.sortKey',
|
||||
'blacklist.sortDirection',
|
||||
'blacklist.columns'
|
||||
];
|
||||
|
||||
//
|
||||
// Action Types
|
||||
|
||||
export const FETCH_BLACKLIST = 'blacklist/fetchBlacklist';
|
||||
export const GOTO_FIRST_BLACKLIST_PAGE = 'blacklist/gotoBlacklistFirstPage';
|
||||
export const GOTO_PREVIOUS_BLACKLIST_PAGE = 'blacklist/gotoBlacklistPreviousPage';
|
||||
export const GOTO_NEXT_BLACKLIST_PAGE = 'blacklist/gotoBlacklistNextPage';
|
||||
export const GOTO_LAST_BLACKLIST_PAGE = 'blacklist/gotoBlacklistLastPage';
|
||||
export const GOTO_BLACKLIST_PAGE = 'blacklist/gotoBlacklistPage';
|
||||
export const SET_BLACKLIST_SORT = 'blacklist/setBlacklistSort';
|
||||
export const SET_BLACKLIST_TABLE_OPTION = 'blacklist/setBlacklistTableOption';
|
||||
|
||||
//
|
||||
// Action Creators
|
||||
|
||||
export const fetchBlacklist = createThunk(FETCH_BLACKLIST);
|
||||
export const gotoBlacklistFirstPage = createThunk(GOTO_FIRST_BLACKLIST_PAGE);
|
||||
export const gotoBlacklistPreviousPage = createThunk(GOTO_PREVIOUS_BLACKLIST_PAGE);
|
||||
export const gotoBlacklistNextPage = createThunk(GOTO_NEXT_BLACKLIST_PAGE);
|
||||
export const gotoBlacklistLastPage = createThunk(GOTO_LAST_BLACKLIST_PAGE);
|
||||
export const gotoBlacklistPage = createThunk(GOTO_BLACKLIST_PAGE);
|
||||
export const setBlacklistSort = createThunk(SET_BLACKLIST_SORT);
|
||||
export const setBlacklistTableOption = createAction(SET_BLACKLIST_TABLE_OPTION);
|
||||
|
||||
//
|
||||
// Action Handlers
|
||||
|
||||
export const actionHandlers = handleThunks({
|
||||
...createServerSideCollectionHandlers(
|
||||
section,
|
||||
'/blacklist',
|
||||
fetchBlacklist,
|
||||
{
|
||||
[serverSideCollectionHandlers.FETCH]: FETCH_BLACKLIST,
|
||||
[serverSideCollectionHandlers.FIRST_PAGE]: GOTO_FIRST_BLACKLIST_PAGE,
|
||||
[serverSideCollectionHandlers.PREVIOUS_PAGE]: GOTO_PREVIOUS_BLACKLIST_PAGE,
|
||||
[serverSideCollectionHandlers.NEXT_PAGE]: GOTO_NEXT_BLACKLIST_PAGE,
|
||||
[serverSideCollectionHandlers.LAST_PAGE]: GOTO_LAST_BLACKLIST_PAGE,
|
||||
[serverSideCollectionHandlers.EXACT_PAGE]: GOTO_BLACKLIST_PAGE,
|
||||
[serverSideCollectionHandlers.SORT]: SET_BLACKLIST_SORT
|
||||
})
|
||||
});
|
||||
|
||||
//
|
||||
// Reducers
|
||||
|
||||
export const reducers = createHandleActions({
|
||||
|
||||
[SET_BLACKLIST_TABLE_OPTION]: createSetTableOptionReducer(section)
|
||||
|
||||
}, defaultState, section);
|
||||
|
@ -1,264 +0,0 @@
|
||||
import _ from 'lodash';
|
||||
import $ from 'jquery';
|
||||
import moment from 'moment';
|
||||
import { batchActions } from 'redux-batched-actions';
|
||||
import * as calendarViews from 'Calendar/calendarViews';
|
||||
import * as types from './actionTypes';
|
||||
import { set, update } from './baseActions';
|
||||
import { fetchCalendar } from './calendarActions';
|
||||
|
||||
const viewRanges = {
|
||||
[calendarViews.DAY]: 'day',
|
||||
[calendarViews.WEEK]: 'week',
|
||||
[calendarViews.MONTH]: 'month',
|
||||
[calendarViews.FORECAST]: 'day'
|
||||
};
|
||||
|
||||
function getDays(start, end) {
|
||||
const startTime = moment(start);
|
||||
const endTime = moment(end);
|
||||
const difference = endTime.diff(startTime, 'days');
|
||||
|
||||
// Difference is one less than the number of days we need to account for.
|
||||
return _.times(difference + 1, (i) => {
|
||||
return startTime.clone().add(i, 'days').toISOString();
|
||||
});
|
||||
}
|
||||
|
||||
function getDates(time, view, firstDayOfWeek, dayCount) {
|
||||
const weekName = firstDayOfWeek === 0 ? 'week' : 'isoWeek';
|
||||
|
||||
let start = time.clone().startOf('day');
|
||||
let end = time.clone().endOf('day');
|
||||
|
||||
if (view === calendarViews.WEEK) {
|
||||
start = time.clone().startOf(weekName);
|
||||
end = time.clone().endOf(weekName);
|
||||
}
|
||||
|
||||
if (view === calendarViews.FORECAST) {
|
||||
start = time.clone().subtract(1, 'day').startOf('day');
|
||||
end = time.clone().add(dayCount - 2, 'days').endOf('day');
|
||||
}
|
||||
|
||||
if (view === calendarViews.MONTH) {
|
||||
start = time.clone().startOf('month').startOf(weekName);
|
||||
end = time.clone().endOf('month').endOf(weekName);
|
||||
}
|
||||
|
||||
if (view === calendarViews.AGENDA) {
|
||||
start = time.clone().subtract(1, 'day').startOf('day');
|
||||
end = time.clone().add(1, 'month').endOf('day');
|
||||
}
|
||||
|
||||
return {
|
||||
start: start.toISOString(),
|
||||
end: end.toISOString(),
|
||||
time: time.toISOString(),
|
||||
dates: getDays(start, end)
|
||||
};
|
||||
}
|
||||
|
||||
function getPopulatableRange(startDate, endDate, view) {
|
||||
switch (view) {
|
||||
case calendarViews.DAY:
|
||||
return {
|
||||
start: moment(startDate).subtract(1, 'day').toISOString(),
|
||||
end: moment(endDate).add(1, 'day').toISOString()
|
||||
};
|
||||
case calendarViews.WEEK:
|
||||
case calendarViews.FORECAST:
|
||||
return {
|
||||
start: moment(startDate).subtract(1, 'week').toISOString(),
|
||||
end: moment(endDate).add(1, 'week').toISOString()
|
||||
};
|
||||
default:
|
||||
return {
|
||||
start: startDate,
|
||||
end: endDate
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
function isRangePopulated(start, end, state) {
|
||||
const {
|
||||
start: currentStart,
|
||||
end: currentEnd,
|
||||
view: currentView
|
||||
} = state;
|
||||
|
||||
if (!currentStart || !currentEnd) {
|
||||
return false;
|
||||
}
|
||||
|
||||
const {
|
||||
start: currentPopulatedStart,
|
||||
end: currentPopulatedEnd
|
||||
} = getPopulatableRange(currentStart, currentEnd, currentView);
|
||||
|
||||
if (
|
||||
moment(start).isAfter(currentPopulatedStart) &&
|
||||
moment(start).isBefore(currentPopulatedEnd)
|
||||
) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
const section = 'calendar';
|
||||
|
||||
const calendarActionHandlers = {
|
||||
[types.FETCH_CALENDAR]: function(payload) {
|
||||
return function(dispatch, getState) {
|
||||
const state = getState();
|
||||
const unmonitored = state.calendar.unmonitored;
|
||||
|
||||
const {
|
||||
time,
|
||||
view
|
||||
} = payload;
|
||||
|
||||
const dayCount = state.calendar.dayCount;
|
||||
const dates = getDates(moment(time), view, state.settings.ui.item.firstDayOfWeek, dayCount);
|
||||
const { start, end } = getPopulatableRange(dates.start, dates.end, view);
|
||||
const isPrePopulated = isRangePopulated(start, end, state.calendar);
|
||||
|
||||
const basesAttrs = {
|
||||
section,
|
||||
isFetching: true
|
||||
};
|
||||
|
||||
const attrs = isPrePopulated ?
|
||||
{
|
||||
view,
|
||||
...basesAttrs,
|
||||
...dates
|
||||
} :
|
||||
basesAttrs;
|
||||
|
||||
dispatch(set(attrs));
|
||||
|
||||
const promise = $.ajax({
|
||||
url: '/calendar',
|
||||
data: {
|
||||
unmonitored,
|
||||
start,
|
||||
end
|
||||
}
|
||||
});
|
||||
|
||||
promise.done((data) => {
|
||||
dispatch(batchActions([
|
||||
update({ section, data }),
|
||||
|
||||
set({
|
||||
section,
|
||||
view,
|
||||
...dates,
|
||||
isFetching: false,
|
||||
isPopulated: true,
|
||||
error: null
|
||||
})
|
||||
]));
|
||||
});
|
||||
|
||||
promise.fail((xhr) => {
|
||||
dispatch(set({
|
||||
section,
|
||||
isFetching: false,
|
||||
isPopulated: false,
|
||||
error: xhr
|
||||
}));
|
||||
});
|
||||
};
|
||||
},
|
||||
|
||||
[types.SET_CALENDAR_DAYS_COUNT]: function(payload) {
|
||||
return function(dispatch, getState) {
|
||||
if (payload.dayCount === getState().calendar.dayCount) {
|
||||
return;
|
||||
}
|
||||
|
||||
dispatch(set({
|
||||
section,
|
||||
dayCount: payload.dayCount
|
||||
}));
|
||||
|
||||
const state = getState();
|
||||
const { time, view } = state.calendar;
|
||||
|
||||
dispatch(fetchCalendar({ time, view }));
|
||||
};
|
||||
},
|
||||
|
||||
[types.SET_CALENDAR_INCLUDE_UNMONITORED]: function(payload) {
|
||||
return function(dispatch, getState) {
|
||||
dispatch(set({
|
||||
section,
|
||||
unmonitored: payload.unmonitored
|
||||
}));
|
||||
|
||||
const state = getState();
|
||||
const { time, view } = state.calendar;
|
||||
|
||||
dispatch(fetchCalendar({ time, view }));
|
||||
};
|
||||
},
|
||||
|
||||
[types.SET_CALENDAR_VIEW]: function(payload) {
|
||||
return function(dispatch, getState) {
|
||||
const state = getState();
|
||||
const view = payload.view;
|
||||
const time = view === calendarViews.FORECAST ?
|
||||
moment() :
|
||||
state.calendar.time;
|
||||
|
||||
dispatch(fetchCalendar({ time, view }));
|
||||
};
|
||||
},
|
||||
|
||||
[types.GOTO_CALENDAR_TODAY]: function(payload) {
|
||||
return function(dispatch, getState) {
|
||||
const state = getState();
|
||||
const view = state.calendar.view;
|
||||
const time = moment();
|
||||
|
||||
dispatch(fetchCalendar({ time, view }));
|
||||
};
|
||||
},
|
||||
|
||||
[types.GOTO_CALENDAR_PREVIOUS_RANGE]: function(payload) {
|
||||
return function(dispatch, getState) {
|
||||
const state = getState();
|
||||
|
||||
const {
|
||||
view,
|
||||
dayCount
|
||||
} = state.calendar;
|
||||
|
||||
const amount = view === calendarViews.FORECAST ? dayCount : 1;
|
||||
const time = moment(state.calendar.time).subtract(amount, viewRanges[view]);
|
||||
|
||||
dispatch(fetchCalendar({ time, view }));
|
||||
};
|
||||
},
|
||||
|
||||
[types.GOTO_CALENDAR_NEXT_RANGE]: function(payload) {
|
||||
return function(dispatch, getState) {
|
||||
const state = getState();
|
||||
|
||||
const {
|
||||
view,
|
||||
dayCount
|
||||
} = state.calendar;
|
||||
|
||||
const amount = view === calendarViews.FORECAST ? dayCount : 1;
|
||||
const time = moment(state.calendar.time).add(amount, viewRanges[view]);
|
||||
|
||||
dispatch(fetchCalendar({ time, view }));
|
||||
};
|
||||
}
|
||||
};
|
||||
|
||||
export default calendarActionHandlers;
|
@ -1,12 +1,323 @@
|
||||
import _ from 'lodash';
|
||||
import $ from 'jquery';
|
||||
import { createAction } from 'redux-actions';
|
||||
import * as types from './actionTypes';
|
||||
import calendarActionHandlers from './calendarActionHandlers';
|
||||
|
||||
export const fetchCalendar = calendarActionHandlers[types.FETCH_CALENDAR];
|
||||
export const setCalendarDaysCount = calendarActionHandlers[types.SET_CALENDAR_DAYS_COUNT];
|
||||
export const setCalendarIncludeUnmonitored = calendarActionHandlers[types.SET_CALENDAR_INCLUDE_UNMONITORED];
|
||||
export const setCalendarView = calendarActionHandlers[types.SET_CALENDAR_VIEW];
|
||||
export const gotoCalendarToday = calendarActionHandlers[types.GOTO_CALENDAR_TODAY];
|
||||
export const gotoCalendarPreviousRange = calendarActionHandlers[types.GOTO_CALENDAR_PREVIOUS_RANGE];
|
||||
export const gotoCalendarNextRange = calendarActionHandlers[types.GOTO_CALENDAR_NEXT_RANGE];
|
||||
export const clearCalendar = createAction(types.CLEAR_CALENDAR);
|
||||
import { batchActions } from 'redux-batched-actions';
|
||||
import moment from 'moment';
|
||||
import { createThunk, handleThunks } from 'Store/thunks';
|
||||
import * as calendarViews from 'Calendar/calendarViews';
|
||||
import createHandleActions from './Creators/createHandleActions';
|
||||
import { set, update } from './baseActions';
|
||||
|
||||
//
|
||||
// Variables
|
||||
|
||||
export const section = 'calendar';
|
||||
|
||||
const viewRanges = {
|
||||
[calendarViews.DAY]: 'day',
|
||||
[calendarViews.WEEK]: 'week',
|
||||
[calendarViews.MONTH]: 'month',
|
||||
[calendarViews.FORECAST]: 'day'
|
||||
};
|
||||
|
||||
//
|
||||
// State
|
||||
|
||||
export const defaultState = {
|
||||
isFetching: false,
|
||||
isPopulated: false,
|
||||
start: null,
|
||||
end: null,
|
||||
dates: [],
|
||||
dayCount: 7,
|
||||
view: window.innerWidth > 768 ? 'week' : 'day',
|
||||
unmonitored: false,
|
||||
showUpcoming: true,
|
||||
error: null,
|
||||
items: []
|
||||
};
|
||||
|
||||
export const persistState = [
|
||||
'calendar.view',
|
||||
'calendar.unmonitored',
|
||||
'calendar.showUpcoming'
|
||||
];
|
||||
|
||||
//
|
||||
// Actions Types
|
||||
|
||||
export const FETCH_CALENDAR = 'calendar/fetchCalendar';
|
||||
export const SET_CALENDAR_DAYS_COUNT = 'calendar/setCalendarDaysCount';
|
||||
export const SET_CALENDAR_INCLUDE_UNMONITORED = 'calendar/setCalendarIncludeUnmonitored';
|
||||
export const SET_CALENDAR_VIEW = 'calendar/setCalendarView';
|
||||
export const GOTO_CALENDAR_TODAY = 'calendar/gotoCalendarToday';
|
||||
export const GOTO_CALENDAR_PREVIOUS_RANGE = 'calendar/gotoCalendarPreviousRange';
|
||||
export const GOTO_CALENDAR_NEXT_RANGE = 'calendar/gotoCalendarNextRange';
|
||||
export const CLEAR_CALENDAR = 'calendar/clearCalendar';
|
||||
|
||||
//
|
||||
// Helpers
|
||||
|
||||
function getDays(start, end) {
|
||||
const startTime = moment(start);
|
||||
const endTime = moment(end);
|
||||
const difference = endTime.diff(startTime, 'days');
|
||||
|
||||
// Difference is one less than the number of days we need to account for.
|
||||
return _.times(difference + 1, (i) => {
|
||||
return startTime.clone().add(i, 'days').toISOString();
|
||||
});
|
||||
}
|
||||
|
||||
function getDates(time, view, firstDayOfWeek, dayCount) {
|
||||
const weekName = firstDayOfWeek === 0 ? 'week' : 'isoWeek';
|
||||
|
||||
let start = time.clone().startOf('day');
|
||||
let end = time.clone().endOf('day');
|
||||
|
||||
if (view === calendarViews.WEEK) {
|
||||
start = time.clone().startOf(weekName);
|
||||
end = time.clone().endOf(weekName);
|
||||
}
|
||||
|
||||
if (view === calendarViews.FORECAST) {
|
||||
start = time.clone().subtract(1, 'day').startOf('day');
|
||||
end = time.clone().add(dayCount - 2, 'days').endOf('day');
|
||||
}
|
||||
|
||||
if (view === calendarViews.MONTH) {
|
||||
start = time.clone().startOf('month').startOf(weekName);
|
||||
end = time.clone().endOf('month').endOf(weekName);
|
||||
}
|
||||
|
||||
if (view === calendarViews.AGENDA) {
|
||||
start = time.clone().subtract(1, 'day').startOf('day');
|
||||
end = time.clone().add(1, 'month').endOf('day');
|
||||
}
|
||||
|
||||
return {
|
||||
start: start.toISOString(),
|
||||
end: end.toISOString(),
|
||||
time: time.toISOString(),
|
||||
dates: getDays(start, end)
|
||||
};
|
||||
}
|
||||
|
||||
function getPopulatableRange(startDate, endDate, view) {
|
||||
switch (view) {
|
||||
case calendarViews.DAY:
|
||||
return {
|
||||
start: moment(startDate).subtract(1, 'day').toISOString(),
|
||||
end: moment(endDate).add(1, 'day').toISOString()
|
||||
};
|
||||
case calendarViews.WEEK:
|
||||
case calendarViews.FORECAST:
|
||||
return {
|
||||
start: moment(startDate).subtract(1, 'week').toISOString(),
|
||||
end: moment(endDate).add(1, 'week').toISOString()
|
||||
};
|
||||
default:
|
||||
return {
|
||||
start: startDate,
|
||||
end: endDate
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
function isRangePopulated(start, end, state) {
|
||||
const {
|
||||
start: currentStart,
|
||||
end: currentEnd,
|
||||
view: currentView
|
||||
} = state;
|
||||
|
||||
if (!currentStart || !currentEnd) {
|
||||
return false;
|
||||
}
|
||||
|
||||
const {
|
||||
start: currentPopulatedStart,
|
||||
end: currentPopulatedEnd
|
||||
} = getPopulatableRange(currentStart, currentEnd, currentView);
|
||||
|
||||
if (
|
||||
moment(start).isAfter(currentPopulatedStart) &&
|
||||
moment(start).isBefore(currentPopulatedEnd)
|
||||
) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
//
|
||||
// Action Creators
|
||||
|
||||
export const fetchCalendar = createThunk(FETCH_CALENDAR);
|
||||
export const setCalendarDaysCount = createThunk(SET_CALENDAR_DAYS_COUNT);
|
||||
export const setCalendarIncludeUnmonitored = createThunk(SET_CALENDAR_INCLUDE_UNMONITORED);
|
||||
export const setCalendarView = createThunk(SET_CALENDAR_VIEW);
|
||||
export const gotoCalendarToday = createThunk(GOTO_CALENDAR_TODAY);
|
||||
export const gotoCalendarPreviousRange = createThunk(GOTO_CALENDAR_PREVIOUS_RANGE);
|
||||
export const gotoCalendarNextRange = createThunk(GOTO_CALENDAR_NEXT_RANGE);
|
||||
export const clearCalendar = createAction(CLEAR_CALENDAR);
|
||||
|
||||
//
|
||||
// Action Handlers
|
||||
|
||||
export const actionHandlers = handleThunks({
|
||||
[FETCH_CALENDAR]: function(getState, payload, dispatch) {
|
||||
const state = getState();
|
||||
const unmonitored = state.calendar.unmonitored;
|
||||
|
||||
const {
|
||||
time,
|
||||
view
|
||||
} = payload;
|
||||
|
||||
const dayCount = state.calendar.dayCount;
|
||||
const dates = getDates(moment(time), view, state.settings.ui.item.firstDayOfWeek, dayCount);
|
||||
const { start, end } = getPopulatableRange(dates.start, dates.end, view);
|
||||
const isPrePopulated = isRangePopulated(start, end, state.calendar);
|
||||
|
||||
const basesAttrs = {
|
||||
section,
|
||||
isFetching: true
|
||||
};
|
||||
|
||||
const attrs = isPrePopulated ?
|
||||
{
|
||||
view,
|
||||
...basesAttrs,
|
||||
...dates
|
||||
} :
|
||||
basesAttrs;
|
||||
|
||||
dispatch(set(attrs));
|
||||
|
||||
const promise = $.ajax({
|
||||
url: '/calendar',
|
||||
data: {
|
||||
unmonitored,
|
||||
start,
|
||||
end
|
||||
}
|
||||
});
|
||||
|
||||
promise.done((data) => {
|
||||
dispatch(batchActions([
|
||||
update({ section, data }),
|
||||
|
||||
set({
|
||||
section,
|
||||
view,
|
||||
...dates,
|
||||
isFetching: false,
|
||||
isPopulated: true,
|
||||
error: null
|
||||
})
|
||||
]));
|
||||
});
|
||||
|
||||
promise.fail((xhr) => {
|
||||
dispatch(set({
|
||||
section,
|
||||
isFetching: false,
|
||||
isPopulated: false,
|
||||
error: xhr
|
||||
}));
|
||||
});
|
||||
},
|
||||
|
||||
[SET_CALENDAR_DAYS_COUNT]: function(getState, payload, dispatch) {
|
||||
if (payload.dayCount === getState().calendar.dayCount) {
|
||||
return;
|
||||
}
|
||||
|
||||
dispatch(set({
|
||||
section,
|
||||
dayCount: payload.dayCount
|
||||
}));
|
||||
|
||||
const state = getState();
|
||||
const { time, view } = state.calendar;
|
||||
|
||||
dispatch(fetchCalendar({ time, view }));
|
||||
},
|
||||
|
||||
[SET_CALENDAR_INCLUDE_UNMONITORED]: function(getState, payload, dispatch) {
|
||||
dispatch(set({
|
||||
section,
|
||||
unmonitored: payload.unmonitored
|
||||
}));
|
||||
|
||||
const state = getState();
|
||||
const { time, view } = state.calendar;
|
||||
|
||||
dispatch(fetchCalendar({ time, view }));
|
||||
},
|
||||
|
||||
[SET_CALENDAR_VIEW]: function(getState, payload, dispatch) {
|
||||
const state = getState();
|
||||
const view = payload.view;
|
||||
const time = view === calendarViews.FORECAST ?
|
||||
moment() :
|
||||
state.calendar.time;
|
||||
|
||||
dispatch(fetchCalendar({ time, view }));
|
||||
},
|
||||
|
||||
[GOTO_CALENDAR_TODAY]: function(getState, payload, dispatch) {
|
||||
const state = getState();
|
||||
const view = state.calendar.view;
|
||||
const time = moment();
|
||||
|
||||
dispatch(fetchCalendar({ time, view }));
|
||||
},
|
||||
|
||||
[GOTO_CALENDAR_PREVIOUS_RANGE]: function(getState, payload, dispatch) {
|
||||
const state = getState();
|
||||
|
||||
const {
|
||||
view,
|
||||
dayCount
|
||||
} = state.calendar;
|
||||
|
||||
const amount = view === calendarViews.FORECAST ? dayCount : 1;
|
||||
const time = moment(state.calendar.time).subtract(amount, viewRanges[view]);
|
||||
|
||||
dispatch(fetchCalendar({ time, view }));
|
||||
},
|
||||
|
||||
[GOTO_CALENDAR_NEXT_RANGE]: function(getState, payload, dispatch) {
|
||||
const state = getState();
|
||||
|
||||
const {
|
||||
view,
|
||||
dayCount
|
||||
} = state.calendar;
|
||||
|
||||
const amount = view === calendarViews.FORECAST ? dayCount : 1;
|
||||
const time = moment(state.calendar.time).add(amount, viewRanges[view]);
|
||||
|
||||
dispatch(fetchCalendar({ time, view }));
|
||||
}
|
||||
});
|
||||
|
||||
//
|
||||
// Reducers
|
||||
|
||||
export const reducers = createHandleActions({
|
||||
|
||||
[CLEAR_CALENDAR]: (state) => {
|
||||
const {
|
||||
view,
|
||||
unmonitored,
|
||||
showUpcoming,
|
||||
...otherDefaultState
|
||||
} = defaultState;
|
||||
|
||||
return Object.assign({}, state, otherDefaultState);
|
||||
}
|
||||
|
||||
}, defaultState, section);
|
||||
|
@ -1,67 +0,0 @@
|
||||
import requestAction from 'Utilities/requestAction';
|
||||
import * as types from './actionTypes';
|
||||
import { setCaptchaValue } from './captchaActions';
|
||||
|
||||
const captchaActionHandlers = {
|
||||
[types.REFRESH_CAPTCHA]: function(payload) {
|
||||
return (dispatch, getState) => {
|
||||
const actionPayload = {
|
||||
action: 'checkCaptcha',
|
||||
...payload
|
||||
};
|
||||
|
||||
dispatch(setCaptchaValue({
|
||||
refreshing: true
|
||||
}));
|
||||
|
||||
const promise = requestAction(actionPayload);
|
||||
|
||||
promise.done((data) => {
|
||||
if (!data.captchaRequest) {
|
||||
dispatch(setCaptchaValue({
|
||||
refreshing: false
|
||||
}));
|
||||
}
|
||||
|
||||
dispatch(setCaptchaValue({
|
||||
refreshing: false,
|
||||
...data.captchaRequest
|
||||
}));
|
||||
});
|
||||
|
||||
promise.fail(() => {
|
||||
dispatch(setCaptchaValue({
|
||||
refreshing: false
|
||||
}));
|
||||
});
|
||||
};
|
||||
},
|
||||
|
||||
[types.GET_CAPTCHA_COOKIE]: function(payload) {
|
||||
return (dispatch, getState) => {
|
||||
const state = getState().captcha;
|
||||
|
||||
const queryParams = {
|
||||
responseUrl: state.responseUrl,
|
||||
ray: state.ray,
|
||||
captchaResponse: payload.captchaResponse
|
||||
};
|
||||
|
||||
const actionPayload = {
|
||||
action: 'getCaptchaCookie',
|
||||
queryParams,
|
||||
...payload
|
||||
};
|
||||
|
||||
const promise = requestAction(actionPayload);
|
||||
|
||||
promise.done((data) => {
|
||||
dispatch(setCaptchaValue({
|
||||
token: data.captchaToken
|
||||
}));
|
||||
});
|
||||
};
|
||||
}
|
||||
};
|
||||
|
||||
export default captchaActionHandlers;
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in new issue