diff --git a/components/Dialogs/ImportFolder/EditTab.jsx b/components/Dialogs/ImportFolder/EditTab.jsx index 565b63318..46da9a053 100644 --- a/components/Dialogs/ImportFolder/EditTab.jsx +++ b/components/Dialogs/ImportFolder/EditTab.jsx @@ -54,7 +54,7 @@ class EditTab extends React.Component { let buttons; if (!form.ImportFolderID) { - let folders = []; + const folders = []; let i = 0; forEach(items, (item) => { i++; diff --git a/components/Panels/TimeUpdated.jsx b/components/Panels/TimeUpdated.jsx index 8845f00db..7fc2abb0c 100644 --- a/components/Panels/TimeUpdated.jsx +++ b/components/Panels/TimeUpdated.jsx @@ -10,7 +10,7 @@ class TimeUpdated extends React.Component { render() { const { timestamp, className, isFetching } = this.props; - let dateString = (timestamp) ? moment(timestamp, 'x').format('YYYY-MM-DD HH:mm:ss') : '--'; + const dateString = (timestamp) ? moment(timestamp, 'x').format('YYYY-MM-DD HH:mm:ss') : '--'; return ( {isFetching ? : null} diff --git a/core/actions.js b/core/actions.js index 467d79ba5..835370419 100644 --- a/core/actions.js +++ b/core/actions.js @@ -94,8 +94,6 @@ export const SIDEBAR_TOGGLE = 'SIDEBAR_TOGGLE'; export const toggleSidebar = createAction(SIDEBAR_TOGGLE); export const SELECT_IMPORT_FOLDER_SERIES = 'SELECT_IMPORT_FOLDER_SERIES'; export const selectImportFolderSeries = createAction(SELECT_IMPORT_FOLDER_SERIES); -export const SETTINGS = 'SETTINGS'; -export const updateSettings = createAction(SETTINGS); /* Async actions - API calls */ export const QUEUE_STATUS = 'QUEUE_STATUS'; @@ -146,7 +144,7 @@ export const jmmVersionAsync = export const IMPORT_FOLDER_SERIES = 'IMPORT_FOLDER_SERIES'; export const importFolderSeriesAsync = createAsyncAction(IMPORT_FOLDER_SERIES, - 'importFolderSeries', '/serie/byfolder/'); + 'importFolderSeries', '/serie/byfolder'); /* Timer */ function autoUpdateTick() { diff --git a/core/actions/settings/Log.js b/core/actions/settings/Log.js new file mode 100644 index 000000000..d05b628bd --- /dev/null +++ b/core/actions/settings/Log.js @@ -0,0 +1,6 @@ +import { createAsyncAction, createAsyncPostAction } from '../../actions'; + +export const GET_LOG = 'SETTINGS_GET_LOG'; +export const getLog = createAsyncAction(GET_LOG, 'logs', '/log/rotate'); +export const SET_LOG = 'SETTINGS_SET_LOG'; +export const setLog = createAsyncPostAction(SET_LOG, 'setLogs', '/log/rotate'); diff --git a/core/reducers.js b/core/reducers.js index 6f69d774d..5d9cc6e38 100644 --- a/core/reducers.js +++ b/core/reducers.js @@ -18,9 +18,9 @@ import { JMM_VERSION, IMPORT_FOLDER_SERIES, SELECT_IMPORT_FOLDER_SERIES, - SETTINGS, } from './actions'; import modals from './reducers/modals'; +import settings from './reducers/settings'; const VERSION = __VERSION__; // eslint-disable-line no-undef @@ -90,9 +90,6 @@ const autoUpdate = handleAction(SET_AUTOUPDATE, const selectedImportFolderSeries = handleAction(SELECT_IMPORT_FOLDER_SERIES, (state, action) => (action.error ? state : action.payload) , {}); -const settings = handleAction(SETTINGS, - (state, action) => (action.error ? state : Object.assign({}, state, action.payload)) - , {}); const rootReducer = combineReducers({ apiSession, diff --git a/core/reducers/settings.js b/core/reducers/settings.js new file mode 100644 index 000000000..bc1623acb --- /dev/null +++ b/core/reducers/settings.js @@ -0,0 +1,6 @@ +import { combineReducers } from 'redux'; +import { logs } from './settings/Log'; + +export default combineReducers({ + logs, +}); diff --git a/core/reducers/settings/Log.js b/core/reducers/settings/Log.js new file mode 100644 index 000000000..0e956587a --- /dev/null +++ b/core/reducers/settings/Log.js @@ -0,0 +1,10 @@ +import { combineReducers } from 'redux'; +import { createApiReducer } from '../../reducers'; +import { GET_LOG, SET_LOG } from '../../actions/settings/Log'; + +export const logs = createApiReducer(GET_LOG); +export const setLogs = createApiReducer(SET_LOG); + +export default combineReducers({ + logs, +}); diff --git a/package.json b/package.json index d11b186fe..885dbd540 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "jmmserver-webui", - "version": "0.1.11", + "version": "0.1.12-dev", "private": true, "engines": { "node": ">=6", diff --git a/pages/import/ImportFolderSeries.jsx b/pages/import/ImportFolderSeries.jsx index f611a0d81..c7973181c 100644 --- a/pages/import/ImportFolderSeries.jsx +++ b/pages/import/ImportFolderSeries.jsx @@ -41,8 +41,8 @@ class ImportFolderSeries extends React.Component { render() { const { items, isFetching, lastUpdated, importFolders, selectedFolder } = this.props; - let series = []; - let folders = []; + const series = []; + const folders = []; let i = 0; forEach(items, (item) => { i++; diff --git a/pages/main/Commands.jsx b/pages/main/Commands.jsx index 95d66cfaf..eb434a2ab 100644 --- a/pages/main/Commands.jsx +++ b/pages/main/Commands.jsx @@ -16,7 +16,7 @@ class Commands extends React.Component { render() { const { items, isFetching, lastUpdated, className } = this.props; - let commands = []; + const commands = []; forEach(items, (item, key) => { commands.push( { i++; diff --git a/pages/main/News.jsx b/pages/main/News.jsx index 48c58b755..0edeb8257 100644 --- a/pages/main/News.jsx +++ b/pages/main/News.jsx @@ -14,7 +14,7 @@ class News extends React.Component { render() { const { items, isFetching, lastUpdated, className } = this.props; - let news = []; + const news = []; let i = 0; forEach(items, (item) => { i++; diff --git a/pages/main/QuickActions.jsx b/pages/main/QuickActions.jsx index 03bd25e47..1d9fb8386 100644 --- a/pages/main/QuickActions.jsx +++ b/pages/main/QuickActions.jsx @@ -12,9 +12,9 @@ class QuickActions extends React.Component { const { lastUpdated } = this.props; const shouldComeFromStore = ['Run Import', 'Update Images', 'Sync Votes', 'Remove Missing Files', 'Update All Stats', 'Update All TvDB Info']; - let actions = []; + const actions = []; - for (let [index, item] of shouldComeFromStore.entries()) { + for (const [index, item] of shouldComeFromStore.entries()) { actions.push(); } diff --git a/pages/main/RecentFiles.jsx b/pages/main/RecentFiles.jsx index be568578b..139c8e4e8 100644 --- a/pages/main/RecentFiles.jsx +++ b/pages/main/RecentFiles.jsx @@ -19,7 +19,7 @@ class RecentFiles extends React.Component { render() { const { items, isFetching, lastUpdated } = this.props; - let files = []; + const files = []; let i = 0; forEach(items, (item) => { i++; diff --git a/pages/settings/LogOptions.jsx b/pages/settings/LogOptions.jsx index 9ad916274..cad31269f 100644 --- a/pages/settings/LogOptions.jsx +++ b/pages/settings/LogOptions.jsx @@ -2,6 +2,7 @@ import React, { PropTypes } from 'react'; import { connect } from 'react-redux'; import { ButtonGroup, Button } from 'react-bootstrap'; import FixedPanel from '../../components/Panels/FixedPanel'; +import { setLog, getLog } from '../../core/actions/settings/Log'; class LogOptions extends React.Component { static propTypes = { @@ -9,11 +10,29 @@ class LogOptions extends React.Component { isFetching: PropTypes.bool, lastUpdated: PropTypes.number, logRotation: PropTypes.bool, - compressLogs: PropTypes.string, + compressLogs: PropTypes.bool, deleteLogs: PropTypes.bool, deleteLogsInterval: PropTypes.string, }; + constructor(props) { + super(props); + this.handleChange = this.handleChange.bind(this); + } + + handleChange(key, value) { + const { logRotation, compressLogs, deleteLogs, deleteLogsInterval } = this.props; + const items = Object.assign({}, { + rotate: logRotation, + zip: compressLogs, + delete: deleteLogs, + days: deleteLogsInterval, + }, { [key]: value }); + setLog(items).then( + () => getLog() + ); + } + render() { const { isFetching, lastUpdated, logRotation, compressLogs, deleteLogs, deleteLogsInterval, className } = this.props; @@ -32,24 +51,29 @@ class LogOptions extends React.Component { Enable Log Rotation - - + + - Compress Log Interval + Compress Log + onClick={() => { this.handleChange('zip', false); }} + bsStyle={compressLogs ? 'default' : 'danger'} + >No - + onClick={() => { this.handleChange('zip', true); }} + bsStyle={compressLogs ? 'success' : 'default'} + >Yes @@ -57,8 +81,14 @@ class LogOptions extends React.Component { Delete Older Logs - - + + @@ -67,14 +97,17 @@ class LogOptions extends React.Component { - + onClick={() => { this.handleChange('days', 30); }} + bsStyle={deleteLogsInterval === 30 ? 'success' : 'default'} + >Monthly + @@ -88,18 +121,14 @@ class LogOptions extends React.Component { function mapStateToProps(state) { const { settings } = state; - const { - logRotation, - compressLogs, - deleteLogs, - deleteLogsInterval, - } = settings; + const { items } = settings.logs; return { - logRotation, - compressLogs, - deleteLogs, - deleteLogsInterval, + logRotation: items.rotate, + compressLogs: items.zip, + deleteLogs: items.delete, + deleteLogsInterval: items.days, + isFetching: settings.logs.isFetching, }; } diff --git a/pages/settings/index.jsx b/pages/settings/index.jsx index bd9a5b209..d1dc333c0 100644 --- a/pages/settings/index.jsx +++ b/pages/settings/index.jsx @@ -2,7 +2,7 @@ import React from 'react'; import { Panel } from 'react-bootstrap'; import history from '../../core/history'; import store from '../../core/store'; -import { updateSettings } from '../../core/actions'; +import { getLog } from '../../core/actions/settings/Log'; import Layout from '../../components/Layout/Layout'; import InfoPanel from '../../components/Panels/InfoPanel'; import Overview from '../main/Overview'; @@ -21,16 +21,7 @@ class SettingsPage extends React.Component { }); } - const settings = { - theme: 'light', - notifications: false, - logRotation: true, - compressLogs: 'weekly', - deleteLogs: false, - deleteLogsInterval: 'monthly', - }; - - store.dispatch(updateSettings(settings)); + getLog(); } render() {