diff --git a/client/package.json b/client/package.json index 0ad7562..afeecbc 100644 --- a/client/package.json +++ b/client/package.json @@ -27,5 +27,5 @@ "not ie <= 11", "not op_mini all" ], - "proxy": "http://localhost:3001" + "proxy": "http://localhost:9051" } diff --git a/client/public/favicon.ico b/client/public/favicon.ico index 604d06d..01303c6 100644 Binary files a/client/public/favicon.ico and b/client/public/favicon.ico differ diff --git a/client/public/images/logo.jpg b/client/public/images/logo.jpg new file mode 100644 index 0000000..661afbc Binary files /dev/null and b/client/public/images/logo.jpg differ diff --git a/client/public/index.html b/client/public/index.html index c5fecfc..3bcf542 100755 --- a/client/public/index.html +++ b/client/public/index.html @@ -22,7 +22,7 @@ work correctly both with client-side routing and a non-root public URL. Learn how to configure a non-root public URL by running `npm run build`. --> - NWAP - Stand der Dinge + Quarantale diff --git a/client/src/actions/appActions.js b/client/src/actions/appActions.js index 8b00b49..bdb3dbf 100644 --- a/client/src/actions/appActions.js +++ b/client/src/actions/appActions.js @@ -1,218 +1,22 @@ import ApiService from '../services/ApiService'; import { - CONFIG_LOADED, - CONFIG_LOAD_ERROR, - CONFIG_UPDATED, - CONFIG_SAVED, - OBJECT_STARTED, - OBJECT_PAUSED, - OBJECT_STOPPED, - OBJECT_STATUS_LOADED, - FILE_UPLOADED, - FILES_LOADED, - FILE_DELETED, - PARAMS_LOADED, - PARAMS_LOAD_ERROR, - PLAYERS_LOADED, - PLAYERS_LOAD_ERROR + QUESTIONS_LOADED, + QUESTIONS_LOAD_ERROR, } from './types'; - -export const loadConfig = (onSuccess, onError) => dispatch => { +export const loadQuestions = (userId) => dispatch => { const service = new ApiService(); const scb = (data) => { dispatch({ - type: CONFIG_LOADED, - config: data + type: QUESTIONS_LOADED, + data: data }); - if (onSuccess) onSuccess(data); } const ecb = (error) => { dispatch({ - type: CONFIG_LOAD_ERROR, + type: QUESTIONS_LOAD_ERROR, error: error }); - if (onError) onError(error); } - service.getConfig(scb, ecb); -}; - -export const updateConfig = (requestData, onSuccess, onError) => dispatch => { - const service = new ApiService(); - const scb = (data) => { - dispatch({ - type: CONFIG_UPDATED, - config: data - }); - if (onSuccess) onSuccess(data); - } - const ecb = (error) => { - if (onError) onError(error); - } - service.udpateConfig(requestData, scb, ecb); -}; - -export const saveConfig = (onSuccess, onError) => dispatch => { - const service = new ApiService(); - const scb = (data) => { - dispatch({ - type: CONFIG_SAVED, - config: data - }); - if (onSuccess) onSuccess(data); - } - const ecb = (error) => { - if (onError) onError(error); - } - service.saveConfig(scb, ecb); -}; - -export const getObjectConfig = (onSuccess, onError) => dispatch => { - const service = new ApiService(); - const scb = (data) => { - dispatch({ - type: OBJECT_STATUS_LOADED, - status: data.status - }); - if (onSuccess) onSuccess(data); - } - const ecb = (error) => { - if (onError) onError(error); - } - service.getObjectStatus(scb, ecb); -}; - -export const startObject = (onSuccess, onError) => dispatch => { - const service = new ApiService(); - const scb = (data) => { - dispatch({ - type: OBJECT_STARTED, - status: data.status - }); - if (onSuccess) onSuccess(data); - } - const ecb = (error) => { - if (onError) onError(error); - } - service.startObject(scb, ecb); -}; - -export const pauseObject = (onSuccess, onError) => dispatch => { - const service = new ApiService(); - const scb = (data) => { - dispatch({ - type: OBJECT_PAUSED, - status: data.status - }); - if (onSuccess) onSuccess(data); - } - const ecb = (error) => { - if (onError) onError(error); - } - service.pauseObject(scb, ecb); -}; - -export const stopObject = (onSuccess, onError) => dispatch => { - const service = new ApiService(); - const scb = (data) => { - dispatch({ - type: OBJECT_STOPPED, - status: data.status - }); - if (onSuccess) onSuccess(data); - } - const ecb = (error) => { - if (onError) onError(error); - } - service.stopObject(scb, ecb); -}; - -export const fileUploaded = (fileData) => dispatch => { - dispatch({ - type: FILE_UPLOADED, - file: fileData - }); -} - -export const loadFiles = (onSuccess, onError) => dispatch => { - const service = new ApiService(); - const scb = (data) => { - dispatch({ - type: FILES_LOADED, - files: data - }); - if (onSuccess) onSuccess(data); - } - const ecb = (error) => { - if (onError) onError(error); - } - service.getFiles(scb, ecb); -}; - -export const uploadFile = (formData, onSuccess, onError) => dispatch => { - const service = new ApiService(); - const scb = (data) => { - dispatch({ - type: FILE_UPLOADED, - file: data - }); - if (onSuccess) onSuccess(data); - } - const ecb = (error) => { - if (onError) onError(error); - } - service.uploadFile(formData, scb, ecb); -}; - -export const deleteFile = (name, onSuccess, onError) => dispatch => { - const service = new ApiService(); - const scb = (data) => { - dispatch({ - type: FILE_DELETED, - fileName: name - }); - if (onSuccess) onSuccess(data); - } - const ecb = (error) => { - if (onError) onError(error); - } - service.deleteFile(name, scb, ecb); -}; - -export const loadParams = (onSuccess, onError) => dispatch => { - const service = new ApiService(); - const scb = (data) => { - dispatch({ - type: PARAMS_LOADED, - params: data - }); - if (onSuccess) onSuccess(data); - } - const ecb = (error) => { - dispatch({ - type: PARAMS_LOAD_ERROR, - error: error - }); - if (onError) onError(error); - } - service.getParams(scb, ecb); -}; - -export const loadPlayers = (showId, onSuccess, onError) => dispatch => { - const service = new ApiService(); - const scb = (data) => { - dispatch({ - type: PLAYERS_LOADED, - players: data - }); - //if (onSuccess) onSuccess(data); - } - const ecb = (error) => { - dispatch({ - type: PLAYERS_LOAD_ERROR, - error: error - }); - //if (onError) onError(error); - } - service.getPlayers(showId, scb, ecb); + service.getQuestions(userId, scb, ecb); }; diff --git a/client/src/actions/types.js b/client/src/actions/types.js index ce34662..522d434 100644 --- a/client/src/actions/types.js +++ b/client/src/actions/types.js @@ -1,15 +1,2 @@ -export const CONFIG_LOADED = 'CONFIG_LOADED'; -export const CONFIG_LOAD_ERROR = 'CONFIG_LOAD_ERROR'; -export const CONFIG_UPDATED = 'CONFIG_SAVED'; -export const CONFIG_SAVED = 'CONFIG_SAVED'; -export const OBJECT_STARTED = 'OBJECT_STARTED'; -export const OBJECT_PAUSED = 'OBJECT_PAUSED'; -export const OBJECT_STOPPED = 'OBJECT_STOPPED'; -export const OBJECT_STATUS_LOADED = 'OBJECT_STATUS_LOADED'; -export const FILE_UPLOADED = 'FILE_UPLOADED'; -export const FILES_LOADED = 'FILES_LOADED'; -export const FILE_DELETED = 'FILE_DELETED'; -export const PARAMS_LOADED = 'PARAMS_LOADED'; -export const PARAMS_LOAD_ERROR = 'PARAMS_LOAD_ERROR'; -export const PLAYERS_LOADED = 'PLAYERS_LOADED'; -export const PLAYERS_LOAD_ERROR = 'PLAYERS_LOAD_ERROR'; +export const QUESTIONS_LOADED = 'QUESTIONS_LOADED'; +export const QUESTIONS_LOAD_ERROR = 'QUESTIONS_LOADED'; diff --git a/client/src/components/AppConfig/AppConfig.js b/client/src/components/AppConfig/AppConfig.js deleted file mode 100644 index dc56fa8..0000000 --- a/client/src/components/AppConfig/AppConfig.js +++ /dev/null @@ -1,395 +0,0 @@ -import React, { Component } from 'react'; -import PropTypes from 'prop-types'; -import { connect } from 'react-redux'; -import { loadConfig, updateConfig, saveConfig } from '../../actions/appActions'; -import { Form, Switch, Select, Input, Button, Icon, Card, Tooltip } from 'antd'; -import FormItem from 'antd/lib/form/FormItem'; -import { NumericInput } from '../'; - -class AppConfig extends Component { - - constructor(props) { - super(props); - this.state = { - config: {}, - loadingConfig: true, - updatingConfig: false, - savingConfig: false, - configLoadError: false, - configUpdateError: false, - configSaveError: false - } - } - - componentWillMount() { - let scb = (data) => { - if (data.custom === undefined) { - data.custom = {}; - }; - if (data.custom.printer === undefined) { - data.custom.printer = {}; - } - if (data.custom.printer.margins === undefined) { - data.custom.printer.margins = { - top: 0, - bottom: 0, - left: 10, - right: 10 - }; - } - this.setState({ - config: data, - loadingConfig: false - }); - } - let ecb = (error) => { - this.setState({ - configLoadError: error, - loadingConfig: false - }); - } - this.props.loadConfig(scb, ecb); - } - - updateConfig = (e) => { - e.preventDefault(); - this.setState({ - updatingConfig: true - }); - - let scb = (data) => { - this.setState({ - config: data, - updatingConfig: false - }); - } - let ecb = (error) => { - this.setState({ - configUpdateError: error, - updatingConfig: false - }); - } - - this.props.updateConfig(this.state.config, scb, ecb); - }; - - saveConfig = (e) => { - e.preventDefault(); - this.setState({ - savingConfig: true - }); - - let scb = (data) => { - this.setState({ - config: data, - savingConfig: false - }); - } - let ecb = (error) => { - this.setState({ - configSaveError: error, - savingConfig: false - }); - } - this.props.saveConfig(scb, ecb); - }; - - handleChange = name => event => { - let v = 0; - let c = JSON.parse(JSON.stringify(this.state.config)); - switch (name) { - case 'key': - c.objectOptions.key = event.target.value; - break; - case 'objectType': - c.objectType = event; - break; - case 'secret': - c.objectOptions.secret = event.target.value; - break; - case 'server': - c.objectOptions.server = event.target.value; - break; - case 'dataDir': - c.dataDir = event.target.value; - break; - case 'tempDir': - c.tempDir = event.target.value; - break; - case 'polling': - const pi = parseInt(event, 10); - c.objectOptions.pollingInterval = pi; - break; - case 'start': - c.startsImmediately = !c.startsImmediately; - break; - case 'printermargintop': - v = parseInt(event, 10); - c.custom.printer.margins.top = v; - break; - case 'printermarginbottom': - v = parseInt(event, 10); - c.custom.printer.margins.bottom = v; - break; - case 'printermarginleft': - v = parseInt(event, 10); - c.custom.printer.margins.left = v; - break; - case 'printermarginright': - v = parseInt(event, 10); - c.custom.printer.margins.right = v; - break; - case 'printerAdditionalCmdArgs': - c.custom.printer.additionalCmdArgs = event.target.value; - break; - default: - // do nothing - } - this.setState({ - config: c - }); - }; - - render() { - - const formItemLayout = { - labelCol: { - xs: { span: 24 }, - sm: { span: 8 }, - }, - wrapperCol: { - xs: { span: 24 }, - sm: { span: 16 }, - }, - }; - - const tailFormItemLayout = { - wrapperCol: { - xs: { - span: 24, - offset: 0, - }, - sm: { - span: 16, - offset: 8, - }, - }, - }; - - let updateButtonDisabled = JSON.stringify(this.props.config) === JSON.stringify(this.state.config); - - let saveButtonDisabled = true; - if (updateButtonDisabled === true && this.state.config.saved === false) saveButtonDisabled = false; - - let error = ''; - if (this.state.configUpdateError) error = this.state.configUpdateError; - if (this.state.configSaveError) error = this.state.configSaveError; - - const Option = Select.Option; - - return ( - - - - {this.state.loadingConfig && -
loading config...
- } - - {!this.state.loadingConfig && -
- - starts immediately - - )}> - - - - object type - - )}> - - - - data directory - - )}> - - - - temp directory - - )}> - - - - server - - )}> - - - - object key - - )}> - - - - object secret - - )}> - - - - polling interval - - )}> - - - - saved - - )}> - {this.state.config.saved && - - } - -
- - custom printer - - )}> - - - margin top - - )}> - - - - margin bottom - - )}> - - - - margin left - - )}> - - - - margin right - - )}> - - - - additional cmd args - - )}> - - -
- - - - - - -
- } -
- ) - }; -} - -AppConfig.propTypes = { - loadConfig: PropTypes.func.isRequired, - updateConfig: PropTypes.func.isRequired, - saveConfig: PropTypes.func.isRequired, - config: PropTypes.object -} - -const mapStateToProps = state => ({ - config: state.appData.config, - configLoadError: state.appData.configLoadError -}); - -export default connect(mapStateToProps, { loadConfig, updateConfig, saveConfig })(AppConfig); diff --git a/client/src/components/AppHeader/AppHeader.js b/client/src/components/AppHeader/AppHeader.js index 2514c38..acc3b9a 100644 --- a/client/src/components/AppHeader/AppHeader.js +++ b/client/src/components/AppHeader/AppHeader.js @@ -1,10 +1,10 @@ import React, { Component } from 'react'; -import PropTypes from 'prop-types'; +//import PropTypes from 'prop-types'; import { connect } from 'react-redux'; -import { loadParams } from '../../actions/appActions'; +//import { loadParams } from '../../actions/appActions'; import { Link } from 'react-router-dom'; import { withRouter } from "react-router"; -import { Layout, Menu } from 'antd'; +import { Layout } from 'antd'; import 'antd/dist/antd.css'; const { Header } = Layout; @@ -15,7 +15,7 @@ const styles = { color: 'white', fontSize: '1.4em', marginRight: 30, - fontFamily: 'Super-FamiFont' + fontFamily: 'Helvetica' }, logoImage: { @@ -40,60 +40,25 @@ class AppHeader extends Component { render() { - let selectedKeys = []; - if (this.props.location.pathname === '/controls') selectedKeys = (['controls']); - if (this.props.location.pathname === '/config') selectedKeys = (['config']); - if (this.props.location.pathname === '/files') selectedKeys = (['files']); - let menu; - if (selectedKeys.length > 0) { - menu = - - - controls - - - config - - - files - - - } - - let currentShow = this.props.params.find((param) => { - return param.key === 'current show'; - }); - if (currentShow) { - currentShow = currentShow.value; - } else { - currentShow = ''; - } - return (
- - Post Labour Index - {currentShow} + + Quarantale
- {menu}
) } }; AppHeader.propTypes = { - loadParams: PropTypes.func.isRequired, - params: PropTypes.array +// loadParams: PropTypes.func.isRequired, +// params: PropTypes.array }; const mapStateToProps = state => ({ - params: state.appData.params, - paramsLoadError: state.appData.paramsLoadError +// params: state.appData.params, +// paramsLoadError: state.appData.paramsLoadError }); -export default withRouter(connect(mapStateToProps, { loadParams })(AppHeader)); +export default withRouter(connect(mapStateToProps, { })(AppHeader)); diff --git a/client/src/components/AppRouter.js b/client/src/components/AppRouter.js index e23a53b..38f37b1 100644 --- a/client/src/components/AppRouter.js +++ b/client/src/components/AppRouter.js @@ -1,9 +1,9 @@ import React, { Component } from 'react'; -import PropTypes from 'prop-types'; +//import PropTypes from 'prop-types'; import { connect } from 'react-redux'; -import { loadParams } from '../actions/appActions'; +//import { loadParams } from '../actions/appActions'; import { BrowserRouter as Router, Route } from 'react-router-dom'; -import { ConfigPage, ControlsPage, FilesPage, ScoreboardPage } from '../pages'; +import { DashboardPage } from '../pages'; import { Layout } from 'antd'; import { AppHeader } from '../components'; import 'antd/dist/antd.css'; @@ -13,7 +13,7 @@ const { Content } = Layout; class AppRouter extends Component { componentWillMount() { - this.props.loadParams(); + }; render() { @@ -24,10 +24,7 @@ class AppRouter extends Component {
- - - - +
@@ -37,13 +34,9 @@ class AppRouter extends Component { }; AppRouter.propTypes = { - loadParams: PropTypes.func.isRequired, - params: PropTypes.array }; const mapStateToProps = state => ({ - params: state.appData.players, - paramsLoadError: state.appData.paramsLoadError }); -export default connect(mapStateToProps, { loadParams })(AppRouter); +export default connect(mapStateToProps, { })(AppRouter); diff --git a/client/src/components/FileList/FileList.js b/client/src/components/FileList/FileList.js deleted file mode 100644 index a1238f7..0000000 --- a/client/src/components/FileList/FileList.js +++ /dev/null @@ -1,71 +0,0 @@ -import React, { Component } from 'react'; -import PropTypes from 'prop-types'; -import { connect } from 'react-redux'; -import { loadFiles, deleteFile } from '../../actions/appActions'; -import { Card, Table, Button, notification } from 'antd'; - -class FileList extends Component { - - componentWillMount() { - this.props.loadFiles(); - }; - - openNotificationWithIcon = (type, title, description) => { - notification[type]({ - message: title, - description: description, - }); - }; - - _deleteFile(record) { - let _this = this; - const scb = (data) => { - _this.openNotificationWithIcon('success', 'File deleted', ''); - } - const ecb = (error) => { - _this.openNotificationWithIcon('error', 'Error deleting file', error.message); - } - this.props.deleteFile(record.name, scb, ecb); - }; - - render() { - - const _this = this; - - const columns = [{ - title: 'Name', - dataIndex: 'name', - key: 'name', - }, { - title: 'Action', - key: 'action', - render: (text, record) => ( - - ) - }]; - - return ( - - - - ) - }; -}; - - -FileList.propTypes = { - loadFiles: PropTypes.func.isRequired, - deleteFile: PropTypes.func.isRequired, - files: PropTypes.array -} - -const mapStateToProps = state => ({ - files: state.appData.files -}); - -export default connect(mapStateToProps, { loadFiles, deleteFile })(FileList); diff --git a/client/src/components/FileUpload/FileUpload.js b/client/src/components/FileUpload/FileUpload.js deleted file mode 100644 index 53508c6..0000000 --- a/client/src/components/FileUpload/FileUpload.js +++ /dev/null @@ -1,77 +0,0 @@ -import React, { Component } from 'react'; -import PropTypes from 'prop-types'; -import { connect } from 'react-redux'; -import { uploadFile, fileUploaded } from '../../actions/appActions'; -import { Button, Icon, Card, Upload, notification } from 'antd'; - -class FileUpload extends Component { - - openNotificationWithIcon = (type, title, description) => { - notification[type]({ - message: title, - description: description, - }); - }; - - render() { - - let _this = this; - - const uploadProps = { - action: '/api/files', - multiple: false, - headers: {}, - onStart(file) { - }, - onSuccess(ret, file) { - _this.openNotificationWithIcon('success', 'Upload successful', ''); - }, - onError(err) { - _this.openNotificationWithIcon('error', 'Upload failed', err.message); - }, - onProgress({ percent }, file) { - console.log('onProgress', `${percent}%`, file.name); - }, - customRequest({ - action, - data, - file, - filename, - headers, - onError, - onProgress, - onSuccess, - }) { - const formData = new FormData(); - formData.append(filename, file); - - _this.props.uploadFile(formData, onSuccess, onError); - - return { - abort() { - console.log('upload progress is aborted.'); - }, - }; - }, - }; - - return ( - - - - - - ) - } -}; - -FileUpload.propTypes = { - uploadFile: PropTypes.func.isRequired, - fileUploaded: PropTypes.func.isRequired -} - -const mapStateToProps = state => ({}); - -export default connect(mapStateToProps, {uploadFile, fileUploaded })(FileUpload); \ No newline at end of file diff --git a/client/src/components/NumericInput/NumericInput.js b/client/src/components/NumericInput/NumericInput.js deleted file mode 100644 index e9a2134..0000000 --- a/client/src/components/NumericInput/NumericInput.js +++ /dev/null @@ -1,42 +0,0 @@ -import React, { Component } from 'react'; -import { Input } from 'antd'; - -class NumericInput extends Component { - - formatNumber = (value) => { - value += ''; - const list = value.split('.'); - const prefix = list[0].charAt(0) === '-' ? '-' : ''; - let num = prefix ? list[0].slice(1) : list[0]; - let result = ''; - while (num.length > 3) { - result = `,${num.slice(-3)}${result}`; - num = num.slice(0, num.length - 3); - } - if (num) { - result = num + result; - } - return `${prefix}${result}${list[1] ? `.${list[1]}` : ''}`; - } - - onChange = (e) => { - const { value } = e.target; - const reg = /^-?(0|[1-9][0-9]*)(\.[0-9]*)?$/; - if ((!Number.isNaN(value) && reg.test(value)) || value === '' || value === '-') { - this.props.onChange(value); - } - } - - render() { - return ( - - ); - } -}; - -export default NumericInput; diff --git a/client/src/components/PostLabourIndex/PostLabourIndex.js b/client/src/components/PostLabourIndex/PostLabourIndex.js deleted file mode 100644 index ab26258..0000000 --- a/client/src/components/PostLabourIndex/PostLabourIndex.js +++ /dev/null @@ -1,166 +0,0 @@ -import React, { Component } from 'react'; -import PropTypes from 'prop-types'; -import { connect } from 'react-redux'; -import { withRouter } from "react-router"; -import { loadPlayers, loadParams } from '../../actions/appActions'; -import { Avatar } from 'antd'; - -const styles = { - rowGrundig: { - backgroundColor: '#333', - color: '#eee', - border: '1px solid lightgrey' - }, - rowNormal: { - backgroundColor: 'white', - color: '#111', - border: '1px solid lightgrey' - }, - tbl: { - border: '1px solid lightgrey', - cellPadding: '4', - cellSpacing: '4' - }, - hiddenText: { - color: 'white' - }, - textGrundig: { - fontSize: '1.8em', - fontWeight: 'bold' - } -}; - -class PostLabourIndex extends Component { - - constructor(props) { - super(props); - this.state = { - players: [], - playersLoadError: false, - params: [] - }; - this.loadPlayerInterval = null; - } - - componentDidMount() { - this.loadPlayerInterval = setInterval( - () => this.loadPlayers(), - 3000 - ); - }; - - componentWillUnmount() { - clearInterval(this.loadPlayerInterval); - }; - - loadPlayers = () => { - let currentShow = this.props.params.find((param) => { - return param.key === 'current show'; - }); - if (currentShow) { - this.props.loadPlayers(currentShow.value); - } - }; - - render() { - - const tableHeight = window.innerHeight - 150; - const tableContentStyle = { - tblContent: { - overflow: 'scroll', - height: tableHeight - } - } - - let orderedPlayers = this.props.players.sort(function (a, b) { - return b.values.score - a.values.score; - }); - - for (var i = 0; i < orderedPlayers.length; i++) { - orderedPlayers[i].standing = i + 1; - } - - const rows = orderedPlayers.map((player) => { - const standing = - const avatar = - const name = - if (player.group === 'grundig') { - return ( - - {standing} - {avatar} - {name} - - - ) - } else { - return ( - - {standing} - {avatar} - {name} - - - - - - - - ) - } - }); - - return ( -
-
{player.standing}{player.name}
G.R.UN.DIG.
{player.cluster}{player.values.lust}{player.values.power}{player.values.psyche}{player.values.structure}{player.values.score}
- - - - - - - - - - - - - -
AvatarNameBerufsfeldMachtPsycheStrukturPost Labour Score
-
- - - {rows} - - - - - - - - - - - - -
  num player: {orderedPlayers.length}     
-
- - ) - } -} - -PostLabourIndex.propTypes = { - loadPlayers: PropTypes.func.isRequired, - players: PropTypes.array, - loadParams: PropTypes.func.isRequired, - params: PropTypes.array -}; - -const mapStateToProps = state => ({ - players: state.appData.players, - playersLoadError: state.appData.playersLoadError, - params: state.appData.params -}); - -export default withRouter(connect(mapStateToProps, { loadPlayers, loadParams })(PostLabourIndex)); diff --git a/client/src/components/QuestionList/QuestionList.js b/client/src/components/QuestionList/QuestionList.js new file mode 100644 index 0000000..052e54e --- /dev/null +++ b/client/src/components/QuestionList/QuestionList.js @@ -0,0 +1,25 @@ +import React, { Component } from 'react'; +import PropTypes from 'prop-types'; +import { loadQuestions } from '../../actions/appActions'; +import { connect } from 'react-redux'; + +class QuestionList extends Component { + + render() { + return ( +

Questions

+ ) + }; +}; + +QuestionList.propTypes = { + loadQuestions: PropTypes.func.isRequired, + questions: PropTypes.array, +}; + +const mapStateToProps = state => ({ + questions: state.appData.questions, + questionsLoadError: state.appData.questionsLoadError +}); + +export default connect(mapStateToProps, { loadQuestions })(QuestionList); diff --git a/client/src/components/Scoreboard/Scoreboard.js b/client/src/components/Scoreboard/Scoreboard.js deleted file mode 100644 index 2d1b5aa..0000000 --- a/client/src/components/Scoreboard/Scoreboard.js +++ /dev/null @@ -1,126 +0,0 @@ -import React, { Component } from 'react'; -import PropTypes from 'prop-types'; -import { connect } from 'react-redux'; -import { loadPlayers, loadParams } from '../../actions/appActions'; -import { Avatar, Table } from 'antd'; - -class Scoreboard extends Component { - - constructor(props) { - super(props); - this.state = { - players: [], - playersLoadError: false, - params: [] - }; - this.loadPlayerInterval = null; - } - - componentDidMount() { - this.loadPlayerInterval = setInterval( - () => this.loadPlayers(), - 3000 - ); - }; - - componentWillUnmount() { - clearInterval(this.loadPlayerInterval); - }; - - loadPlayers = () => { - let currentShow = this.props.params.find((param) => { - return param.key === 'current show'; - }); - if (currentShow) { - this.props.loadPlayers(currentShow.value); - } - }; - - render() { - - let orderedPlayers = this.props.players.sort(function (a, b) { - return b.values.score - a.values.score; - }); - - for (var i = 0; i < orderedPlayers.length; i++) { - orderedPlayers[i].standing = i + 1; - } - - const columns = [ - { - title: '', - dataIndex: 'standing', - key: 'standing', - width: 50 - }, { - title: 'Avatar', - dataIndex: 'playerId', - key: 'playerId', - width: 100, - render: (playerId) => ( - - ) - }, { - title: 'Name', - dataIndex: 'name', - key: 'name', - style: 'tableHeader' - }, { - title: 'Berufsfeld', - dataIndex: 'cluster', - key: 'cluster' - }, { - title: 'Macht', - dataIndex: 'values.power', - key: 'macht', - width: 100 - }, { - title: 'Psyche', - dataIndex: 'values.psyche', - key: 'psyche', - width: 100 - }, { - title: 'Struktur', - dataIndex: 'values.structure', - key: 'structure', - width: 100 - }, { - title: 'Post Labour Score', - dataIndex: 'values.score', - key: 'score', - width: 200, - render: (score) => ( - {score} - ) - } - ] - - return ( -
- - - ) - } -} - -Scoreboard.propTypes = { - loadPlayers: PropTypes.func.isRequired, - players: PropTypes.array, - loadParams: PropTypes.func.isRequired, - params: PropTypes.array -}; - -const mapStateToProps = state => ({ - players: state.appData.players, - playersLoadError: state.appData.playersLoadError, - params: state.appData.params -}); - -export default connect(mapStateToProps, { loadPlayers, loadParams })(Scoreboard); diff --git a/client/src/components/TotoObjectControls/TotoObjectControls.js b/client/src/components/TotoObjectControls/TotoObjectControls.js deleted file mode 100644 index 5029bab..0000000 --- a/client/src/components/TotoObjectControls/TotoObjectControls.js +++ /dev/null @@ -1,101 +0,0 @@ -import React, { Component } from 'react'; -import PropTypes from 'prop-types'; -import { connect } from 'react-redux'; -import { Card, Button, notification } from 'antd'; -import { startObject, pauseObject, stopObject, getObjectConfig } from '../../actions/appActions'; - -class TotoObjectControls extends Component { - - componentWillMount() { - this.props.getObjectConfig(); - } - - openNotificationWithIcon = (type, title, description) => { - notification[type]({ - message: title, - description: description, - }); - }; - - _startObject = () => { - const scb = (data) => { - this.openNotificationWithIcon('success', 'object started', ''); - } - const ecb = (error) => { - this.openNotificationWithIcon('error', 'error starting object', error.message); - } - this.props.startObject(scb, ecb); - } - - _pauseObject = () => { - const scb = (data) => { - this.openNotificationWithIcon('success', 'object paused', ''); - } - const ecb = (error) => { - this.openNotificationWithIcon('error', 'error pausing object', error.message); - } - this.props.pauseObject(scb, ecb); - } - - _stopObject = () => { - const scb = (data) => { - this.openNotificationWithIcon('success', 'object stopped', ''); - } - const ecb = (error) => { - this.openNotificationWithIcon('error', 'error stopping object', error.message); - } - this.props.stopObject(scb, ecb); - } - - render() { - - const startObjectDisabled = this.props.status === 'running'; - const pauseObjectDisabled = this.props.status === 'paused' || this.props.status === 'stopped'; - const stopObjectDisabled = this.props.status === 'stopped'; - - return ( - -
-

status: {this.props.status}

-
-
- - - -
-
- ) - } -} - -TotoObjectControls.propTypes = { - getObjectConfig: PropTypes.func.isRequired, - startObject: PropTypes.func.isRequired, - pauseObject: PropTypes.func.isRequired, - stopObject: PropTypes.func.isRequired, - status: PropTypes.string -} - -const mapStateToProps = state => ({ - status: state.appData.status -}); - -export default connect(mapStateToProps, { startObject, pauseObject, stopObject, getObjectConfig })(TotoObjectControls); diff --git a/client/src/components/index.js b/client/src/components/index.js index d301b5b..3792e0d 100644 --- a/client/src/components/index.js +++ b/client/src/components/index.js @@ -1,19 +1,7 @@ -import AppConfig from './AppConfig/AppConfig'; import AppHeader from './AppHeader/AppHeader'; -import FileList from './FileList/FileList'; -import FileUpload from './FileUpload/FileUpload'; -import NumericInput from './NumericInput/NumericInput'; -import PostLabourIndex from './PostLabourIndex/PostLabourIndex'; -import Scoreboard from './Scoreboard/Scoreboard'; -import TotoObjectControls from './TotoObjectControls/TotoObjectControls'; +import QuestionList from './QuestionList/QuestionList'; export { - AppConfig, AppHeader, - FileList, - FileUpload, - NumericInput, - PostLabourIndex, - Scoreboard, - TotoObjectControls + QuestionList }; diff --git a/client/src/pages/ConfigPage/ConfigPage.js b/client/src/pages/ConfigPage/ConfigPage.js deleted file mode 100644 index d1c48c9..0000000 --- a/client/src/pages/ConfigPage/ConfigPage.js +++ /dev/null @@ -1,15 +0,0 @@ -import React, { Component } from 'react'; -import { AppConfig } from '../../components'; - -class ConfigPage extends Component { - - render() { - return ( -
- -
- ) - } -} - -export default ConfigPage; diff --git a/client/src/pages/ControlsPage/ControlsPage.js b/client/src/pages/ControlsPage/ControlsPage.js deleted file mode 100644 index c7c7796..0000000 --- a/client/src/pages/ControlsPage/ControlsPage.js +++ /dev/null @@ -1,15 +0,0 @@ -import React, { Component } from 'react'; -import { TotoObjectControls } from '../../components'; - -class ControlsPage extends Component { - - render() { - return ( -
- -
- ) - } -} - -export default ControlsPage; diff --git a/client/src/pages/DashboardPage/DashboardPage.js b/client/src/pages/DashboardPage/DashboardPage.js new file mode 100644 index 0000000..0a23135 --- /dev/null +++ b/client/src/pages/DashboardPage/DashboardPage.js @@ -0,0 +1,15 @@ +import React, { Component } from 'react'; +//import { QuestionList } from '../../components/QuestionList'; + +class DashboardPage extends Component { + + render() { + return ( +
+ QuestionList +
+ ) + } +} + +export default DashboardPage; diff --git a/client/src/pages/FilesPage/FilesPage.js b/client/src/pages/FilesPage/FilesPage.js deleted file mode 100644 index c9f5d21..0000000 --- a/client/src/pages/FilesPage/FilesPage.js +++ /dev/null @@ -1,17 +0,0 @@ -import React, { Component } from 'react'; -import { FileList, FileUpload } from '../../components'; - -class FilesPage extends Component { - - render() { - return ( -
- -
- -
- ); - } -}; - -export default FilesPage; diff --git a/client/src/pages/ScoreboardPage/ScoreboardPage.js b/client/src/pages/ScoreboardPage/ScoreboardPage.js deleted file mode 100644 index 9e70746..0000000 --- a/client/src/pages/ScoreboardPage/ScoreboardPage.js +++ /dev/null @@ -1,16 +0,0 @@ -import React, { Component } from 'react'; -import { PostLabourIndex } from '../../components'; - -class ScoreboardPage extends Component { - - render() { - return ( -
- -
- ) - } - -} - -export default ScoreboardPage; \ No newline at end of file diff --git a/client/src/pages/index.js b/client/src/pages/index.js index 678f0b8..22aad7e 100644 --- a/client/src/pages/index.js +++ b/client/src/pages/index.js @@ -1,11 +1,5 @@ -import ConfigPage from './ConfigPage/ConfigPage'; -import ControlsPage from './ControlsPage/ControlsPage'; -import FilesPage from './FilesPage/FilesPage'; -import ScoreboardPage from './ScoreboardPage/ScoreboardPage'; +import DashboardPage from './DashboardPage/DashboardPage'; export { - ConfigPage, - ControlsPage, - FilesPage, - ScoreboardPage + DashboardPage }; diff --git a/client/src/reducers/appData.js b/client/src/reducers/appData.js index 7075f81..59cebee 100644 --- a/client/src/reducers/appData.js +++ b/client/src/reducers/appData.js @@ -1,134 +1,25 @@ import { - CONFIG_LOADED, - CONFIG_LOAD_ERROR, - CONFIG_UPDATED, - CONFIG_SAVED, - OBJECT_STARTED, - OBJECT_PAUSED, - OBJECT_STOPPED, - OBJECT_STATUS_LOADED, - FILE_UPLOADED, - FILES_LOADED, - FILE_DELETED, - PARAMS_LOADED, - PARAMS_LOAD_ERROR, - PLAYERS_LOADED, - PLAYERS_LOAD_ERROR + QUESTIONS_LOADED, + QUESTIONS_LOAD_ERROR } from '../actions/types'; const initialState = { - config: undefined, - params: [], - files: [], - players: [] + questions: [] }; export default function (state = initialState, action) { switch (action.type) { - case CONFIG_LOADED: { + case QUESTIONS_LOADED: { return { ...state, - config: action.config + questions: action.data } } - case CONFIG_UPDATED: { + case QUESTIONS_LOAD_ERROR: { return { ...state, - config: action.config - } - } - case CONFIG_SAVED: { - return { - ...state, - config: action.config - } - } - case CONFIG_LOAD_ERROR: { - return { - ...state, - configLoadError: action.error - } - } - case OBJECT_STARTED: { - return { - ...state, - status: action.status - } - } - case OBJECT_PAUSED: { - return { - ...state, - status: action.status - } - } - case OBJECT_STOPPED: { - return { - ...state, - status: action.status - } - } - case OBJECT_STATUS_LOADED: { - return { - ...state, - status: action.status - }; - } - case FILE_UPLOADED: { - let files = JSON.parse(JSON.stringify(state.files)); - files.push({ - key: action.file.name, - name: action.file.name - }); - return { - ...state, - files: files - }; - } - case FILES_LOADED: { - let files = action.files.map((file) => { - return { - key: file.name, - name: file.name - } - }); - return { - ...state, - files: files - }; - } - case FILE_DELETED: { - let files = state.files.filter((file) => { - return file.name !== action.fileName - }); - return { - ...state, - files: files - }; - } - case PLAYERS_LOADED: { - return { - ...state, - players: action.players - }; - } - case PLAYERS_LOAD_ERROR: { - return { - ...state, - players: [], - playersLoadError: action.error - }; - } - case PARAMS_LOADED: { - return { - ...state, - params: action.params - }; - } - case PARAMS_LOAD_ERROR: { - return { - ...state, - paramsLoadError: action.error + questionsLoadError: action.error } } default: diff --git a/client/src/services/ApiService.js b/client/src/services/ApiService.js index d1127e0..b40473f 100644 --- a/client/src/services/ApiService.js +++ b/client/src/services/ApiService.js @@ -1,65 +1,9 @@ class ApiService { - getConfig(onSuccess, onError) { - this._get('/api/config', onSuccess, onError); + getQuestions(userId, onSuccess, onError) { + this._get('/api/questions' + userId, onSuccess, onError); }; - udpateConfig(requestData, onSuccess, onError) { - this._put('/api/config/update', requestData, onSuccess, onError); - }; - - saveConfig(onSuccess, onError) { - this._post('/api/config/save', {}, onSuccess, onError); - }; - - startObject(onSuccess, onError) { - this._post('/api/obj/start', {}, onSuccess, onError); - }; - - pauseObject(onSuccess, onError) { - this._post('/api/obj/pause', {}, onSuccess, onError); - }; - - stopObject(onSuccess, onError) { - this._post('/api/obj/stop', {}, onSuccess, onError); - }; - - getObjectStatus(onSuccess, onError) { - this._get('/api/obj/status', onSuccess, onError); - }; - - getFiles(onSuccess, onError) { - this._get('/api/files', onSuccess, onError); - }; - - getParams(onSuccess, onError) { - this._get('/api/nwap/params', onSuccess, onError); - }; - - getPlayers(showId, onSuccess, onError) { - this._get('/api/nwap/show/' + showId, onSuccess, onError); - }; - - uploadFile(formData, onSuccess, onError) { - fetch('/api/files', { - method: 'POST', - body: formData - }) - .then(this._handleResponse(onSuccess, onError)) - .catch((error) => { - onError({ error: error.message }); - }); - }; - - deleteFile(name, onSuccess, onError) { - const url = '/api/files/' + name; - fetch(url, { method: 'DELETE' }) - .then(this._handleResponse(onSuccess, onError)) - .catch((error) => { - onError({ error: error.message }); - }); - } - _get(url, onSuccess, onError) { fetch(url) .then(this._handleResponse(onSuccess, onError))