Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion src/api/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@ export interface AssetManifest {
}

class Api {

public getSubjects(){
return Connector.get('odata/subjects');
}

public getModules() {
return Connector.get('odata/taskModules');
}
Expand Down Expand Up @@ -70,4 +75,4 @@ class Api {
private url = (ID: number, file: string) => `odata/taskModules(${ID})/download(path='${file}')`;
}

export default new Api();
export default new Api();
7 changes: 6 additions & 1 deletion src/app/menus/MainMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@ export const mainListItems = (logged: boolean, onClick: () => void) => (
<NavItem>
<NavLink href="/auth" className="header-title">Вход</NavLink>
</NavItem>)}
{logged && (
<NavItem>
<NavLink href="/test" className="header-title">Тест</NavLink>
</NavItem>
)}
{logged && (
<NavItem>
<NavLink href="/results" className="header-title">Результаты</NavLink>
Expand All @@ -22,4 +27,4 @@ export const mainListItems = (logged: boolean, onClick: () => void) => (
</NavItem>
)}
</Nav>
);
);
1 change: 1 addition & 0 deletions src/app/pages/Modules/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ class Modules extends Component<Props> {
}

public render() {
console.log(this.props);
return (<Container>
<Row>
<Col md={12}>
Expand Down
4 changes: 4 additions & 0 deletions src/app/pages/Test/TTable.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import GTable from "../../containers/Table";
import {Subject} from "../../../redux/reducers/test";

export default class extends GTable<Subject> {}
72 changes: 72 additions & 0 deletions src/app/pages/Test/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
import * as React from 'react';
import {Component} from "react";
import {Col, Container, Row} from "reactstrap";
import {connect} from "react-redux";
import {RootState} from "../../../redux/rootReducer";
import {actions} from "../../../redux/actions";
import {Subject, TestState} from "../../../redux/reducers/test";
import AsyncWrapper from "../../containers/AsyncWrapper";
// import {RouteComponentProps, withRouter} from "react-router";
import {InjectedAuthRouterProps} from "redux-auth-wrapper/history3/redirect";
import T from './TTable';
import {AppState} from "../../../redux/reducers/state";

interface DispatchProps {
getSubjects: any;
}

interface StateToProps {
test: TestState;
state: AppState;
}

type Props = DispatchProps & StateToProps & InjectedAuthRouterProps;
class Test extends Component<Props> {

constructor(props: Props) {
super(props);
}

public render() {
// console.log(this.props);

return (<Container>
<Row>
<Col md={12}>
<h1>
Темы
</h1>
<AsyncWrapper state={[this.props.test]}>
<T
rows={this.props.test.data}
headers={['ID', 'Название', 'Описание']}
renderer={this.renderer}
/>
</AsyncWrapper>
</Col>
</Row>
</Container>);
}

private renderer(row: Subject) {
return (
<React.Fragment>
<th scope="row">
{row.id}
</th>
<td>{row.name}</td>
<td>{row.description}</td>
</React.Fragment>);
}
}

const mapStateToProps = (state: RootState) => ({
test: state.test,
state: state.state,
});

const mapDispatchToProps = {
getSubjects: actions.getSubjects,
};

export default connect(mapStateToProps, mapDispatchToProps)(Test);
4 changes: 3 additions & 1 deletion src/app/router/Routes.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import Results from "../pages/Results";
import { connectedRouterRedirect } from 'redux-auth-wrapper/history4/redirect';
import {RootState} from "../../redux/rootReducer";
import Upload from '../pages/Upload';
import Test from '../pages/Test';

// tslint:disable

Expand All @@ -26,6 +27,7 @@ const Routes = () => (
<Switch>
<Route path="/" exact component={Home} />
<Route path="/auth" exact component={Login}/>
<Route path="/test" component={userIsAuthenticated(Test)}/>
<Route path="/results" exact component={userIsAuthenticated(Results)} />
<Route path="/modules" component={userIsAuthenticated(Modules)}/>
<Route path="/module/:moduleId" component={userIsAuthenticated(Module)}/>
Expand All @@ -34,4 +36,4 @@ const Routes = () => (
</div>
);

export default Routes;
export default Routes;
6 changes: 5 additions & 1 deletion src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,12 @@ import {init} from "./lib/connector";
import {Promise} from 'bluebird';
global.Promise = Promise;

// init({
// hostBase: 'http://gl-backend.svtz.ru:5000/'
// });

init({
hostBase: 'http://gl-backend.svtz.ru:5000/'
hostBase: 'http://bab320a0.ngrok.io/'
});

ReactDOM.render(
Expand Down
5 changes: 4 additions & 1 deletion src/redux/actions/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { state } from './state';
import {createServiceAction} from "./actionCreators";
import {results} from "./results";
import {user} from './user';
import {test} from './test';

export enum ACTION_TYPES {
GET= 'get',
Expand All @@ -13,11 +14,13 @@ export enum ACTION_TYPES {
}

export const actions = {
...test,
...modules,
...state,
...results,
...user,
...createServiceAction('Subject', [ACTION_TYPES.GET]),
...createServiceAction('TaskModule', [ACTION_TYPES.GET, ACTION_TYPES.GET_ONE]),
...createServiceAction('TaskVariantLog', [ACTION_TYPES.GET]),
...createServiceAction('Me', [ACTION_TYPES.GET_ONE]),
};
};
25 changes: 25 additions & 0 deletions src/redux/actions/test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import {Dispatch} from 'redux';
import {actions} from './index';
import {Validation} from 'fp-ts/lib/Validation';
import api from '../../api';
import {Subject} from "../reducers/test";

export const test = {
getSubjects: () => {
return (dispatch: Dispatch) => {
dispatch(actions['getSubjectsAsyncStart']());
api.getSubjects().then(
(res: Validation<string, { value?: Subject[] }>) => {
const data = res.getOrElse({});
if (data.value){
dispatch(actions['getSubjectsAsyncSuccess']({
data: data.value
}));
}else{
dispatch(actions['getSubjectsAsyncFail']());
}
}
);
}
}
};
26 changes: 26 additions & 0 deletions src/redux/reducers/test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import {Reducer} from "redux";
import {createAsyncReducer} from "./asyncReducer";
import {actions} from "../actions";
import {IPageableState} from "../../types/redux";

export interface Subject {
id: number;
name: string;
description: string;
}

//
// export interface Question {
// id: number;
// plain_text: string;
// description: string;
// }


export interface TestState extends IPageableState<Subject> {}

export const reducer: Reducer<TestState> = createAsyncReducer<TestState>({
pending: actions['getSubjectsAsyncStart'],
fail: actions['getSubjectsAsyncFail'],
success: actions['getSubjectsAsyncSuccess'],
});
5 changes: 4 additions & 1 deletion src/redux/rootReducer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@ import {ModuleState, reducer as module} from "./reducers/module";
import {AppState, reducer as state} from "./reducers/state";
import {reducer as results, ResultsState} from "./reducers/results";
import {MyState, reducer as me} from './reducers/me';
import {TestState, reducer as test} from "./reducers/test";

export interface RootState {
test: TestState;
modules: ModulesState;
module: ModuleState;
state: AppState;
Expand All @@ -16,10 +18,11 @@ export interface RootState {
export const rootReducer: Reducer<RootState> = combineReducers<RootState>({
// i18n: i18nReducer,
me,
test,
modules,
module,
results,
state,
});

export default rootReducer;
export default rootReducer;
4 changes: 3 additions & 1 deletion src/redux/store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@ import rootReducer, {RootState} from './rootReducer';
import {getInitialArray, getInitialObject} from "./reducers/asyncReducer";
import {ModuleData} from "./reducers/modules";
import {ResultData} from "./reducers/results";
import {Subject} from "./reducers/test";

const initial = {
test: getInitialArray<Subject>(),
modules: getInitialArray<ModuleData>(),
module: getInitialObject<any>(),
state: { logged: false },
Expand Down Expand Up @@ -36,4 +38,4 @@ export function configureStore(initialState: RootState): Store<RootState> {
return stateStore;
}

export const store = configureStore(initial);
export const store = configureStore(initial);