diff --git a/arangopipe/arangopipe_frontend/app/src/actions/auth/index.js b/arangopipe/arangopipe_frontend/app/src/actions/auth/index.js index 1de8124..3845538 100755 --- a/arangopipe/arangopipe_frontend/app/src/actions/auth/index.js +++ b/arangopipe/arangopipe_frontend/app/src/actions/auth/index.js @@ -13,7 +13,19 @@ export const signin = (obj) => { return API(data).then(res => { localStorage.setItem('token', res.data.jwt); - return dispatch({ type: USER.SIGNED_IN, payload: res.data.username }) + let get_dbs = { + method: 'GET', + url: '_api/database/user?_='+Date.now() + } + + const username = res.data.user + + return AUTHAPI(get_dbs).then(res => { + return dispatch({ + type: USER.SIGNED_IN, + payload: { name: username, isAdmin: res.data.result.includes('_system') }}) + }) + }).catch(err => { message.error('Wrong ID or Password!'); throw err @@ -24,15 +36,27 @@ export const signin = (obj) => { export const currentUser = () => { return (dispatch) => { - let data = { + let get_token = { method: 'GET', url: '_admin/aardvark/whoAmI?_='+Date.now() } - return AUTHAPI(data).then(res => { - console.log('success') - return dispatch({ type: USER.SIGNED_IN, payload: res.data.user }) + + return AUTHAPI(get_token).then(res => { + + let get_dbs = { + method: 'GET', + url: '_api/database/user?_='+Date.now() + } + + const username = res.data.user + + return AUTHAPI(get_dbs).then(res => { + return dispatch({ + type: USER.SIGNED_IN, + payload: { name: username, isAdmin: res.data.result.includes('_system') }}) + }) + }).catch(err => { - console.log(err) localStorage.removeItem('token'); return dispatch({ type: USER.SIGNED_OUT }) }) diff --git a/arangopipe/arangopipe_frontend/app/src/actions/counter.js b/arangopipe/arangopipe_frontend/app/src/actions/counter.js deleted file mode 100755 index 765fb4d..0000000 --- a/arangopipe/arangopipe_frontend/app/src/actions/counter.js +++ /dev/null @@ -1,56 +0,0 @@ -export const DECREMENT = 'counter/DECREMENT'; -export const DECREMENT_REQUESTED = 'counter/DECREMENT_REQUESTED'; -export const INCREMENT = 'counter/INCREMENT'; -export const INCREMENT_REQUESTED = 'counter/INCREMENT_REQUESTED'; - -export const decrement = () => { - return dispatch => { - dispatch({ - type: DECREMENT_REQUESTED - }); - - dispatch({ - type: DECREMENT - }); - }; -}; - -export const decrementAsync = () => { - return dispatch => { - dispatch({ - type: DECREMENT_REQUESTED - }); - - return setTimeout(() => { - dispatch({ - type: DECREMENT - }); - }, 3000); - }; -}; - -export const increment = () => { - return dispatch => { - dispatch({ - type: INCREMENT_REQUESTED - }); - - dispatch({ - type: INCREMENT - }); - }; -}; - -export const incrementAsync = () => { - return dispatch => { - dispatch({ - type: INCREMENT_REQUESTED - }); - - return setTimeout(() => { - dispatch({ - type: INCREMENT - }); - }, 3000); - }; -}; diff --git a/arangopipe/arangopipe_frontend/app/src/actions/document/index.js b/arangopipe/arangopipe_frontend/app/src/actions/document/index.js index b6d7947..dce509a 100755 --- a/arangopipe/arangopipe_frontend/app/src/actions/document/index.js +++ b/arangopipe/arangopipe_frontend/app/src/actions/document/index.js @@ -1,4 +1,4 @@ -import { DOCUMENT, GRAPH } from '../../reducers/type' +import { DOCUMENT } from '../../reducers/type' import AUTHAPI from '../AUTHAPI' import moment from 'moment'; import { message } from 'antd' diff --git a/arangopipe/arangopipe_frontend/app/src/actions/query/index.js b/arangopipe/arangopipe_frontend/app/src/actions/query/index.js index eebff32..c1cb1f3 100644 --- a/arangopipe/arangopipe_frontend/app/src/actions/query/index.js +++ b/arangopipe/arangopipe_frontend/app/src/actions/query/index.js @@ -1,7 +1,5 @@ import { QUERY } from '../../reducers/type' import AUTHAPI from '../AUTHAPI' -import moment from 'moment'; -import { message } from 'antd' //Get Default Query diff --git a/arangopipe/arangopipe_frontend/app/src/components/Form/MetaSearchForm.jsx b/arangopipe/arangopipe_frontend/app/src/components/Form/MetaSearchForm.jsx index cd0b67b..748bded 100755 --- a/arangopipe/arangopipe_frontend/app/src/components/Form/MetaSearchForm.jsx +++ b/arangopipe/arangopipe_frontend/app/src/components/Form/MetaSearchForm.jsx @@ -7,7 +7,7 @@ import { } from '../../actions/document' -import { Form, Icon, Input, Button, Select } from 'antd'; +import { Form, Input, Button, Select } from 'antd'; import { FIND_OPTIONS, WITH_OPTIONS, DEPLOY_QUERY } from "../../constants/searchOptions"; const { Option } = Select; diff --git a/arangopipe/arangopipe_frontend/app/src/components/Modal/TreeGraph.jsx b/arangopipe/arangopipe_frontend/app/src/components/Modal/TreeGraph.jsx index e7dc93a..0b20d2f 100644 --- a/arangopipe/arangopipe_frontend/app/src/components/Modal/TreeGraph.jsx +++ b/arangopipe/arangopipe_frontend/app/src/components/Modal/TreeGraph.jsx @@ -13,8 +13,11 @@ const { Option } = Select; class TreeGraphForm extends React.Component { + state = { graph: null, + engine: 'dot', + format: 'svg', visible: 'hidden' } @@ -168,7 +171,7 @@ class TreeGraphForm extends React.Component { renderGraph(); } - componentWillMount() { + componentDidMount() { const d_tag = this.props.deploymentTag.trim() const queries = [] @@ -185,7 +188,7 @@ class TreeGraphForm extends React.Component { this.props.getGraphData(queries) } - componentWillReceiveProps(props, state){ + componentWillReceiveProps(props){ if (this.props != props) { let gdata = Object.assign([], props.gdata) @@ -212,28 +215,35 @@ class TreeGraphForm extends React.Component { }` this.setState({ - graph: tree + graph: tree, + visible: 'visible' }) + } } } - handleSubmit = e => { - e.preventDefault(); - this.props.form.validateFields((err, values) => { - if (!err) { - this.setState({ - visible: 'visible' - }) - this.drawGraph(values.engine, values.format, this.state.graph) - } - }); + + handleEngineChange = value => { + this.setState({ + engine: value + }) }; + handleFormatChange = value => { + this.setState({ + format: value + }) + }; + + render() { const { getFieldDecorator } = this.props.form; + if(this.state.graph != null) + this.drawGraph(this.state.engine, this.state.format, this.state.graph) + return (
-
+ {getFieldDecorator('engine', { initialValue: 'dot', rules: [{ required: true, message: 'Please input your Password!' }], })( - @@ -266,7 +276,7 @@ class TreeGraphForm extends React.Component { initialValue: 'svg', rules: [{ required: true, message: 'Please input your Password!' }], })( - @@ -277,11 +287,7 @@ class TreeGraphForm extends React.Component { )} - - - +
diff --git a/arangopipe/arangopipe_frontend/app/src/components/Sidebar.jsx b/arangopipe/arangopipe_frontend/app/src/components/Sidebar.jsx index 6915ff6..0137e44 100755 --- a/arangopipe/arangopipe_frontend/app/src/components/Sidebar.jsx +++ b/arangopipe/arangopipe_frontend/app/src/components/Sidebar.jsx @@ -33,24 +33,31 @@ class Sidebar extends React.Component{ Home - - - - User - - - - - - Deployment - - - - - - Project - - + {this.props.isAdmin && + + + + User + + + } + + {this.props.isAdmin && + + + + Deployment + + + } + {this.props.isAdmin && + + + + Project + + + } diff --git a/arangopipe/arangopipe_frontend/app/src/components/Table/QueryResult.jsx b/arangopipe/arangopipe_frontend/app/src/components/Table/QueryResult.jsx index d0f1765..6ef4888 100644 --- a/arangopipe/arangopipe_frontend/app/src/components/Table/QueryResult.jsx +++ b/arangopipe/arangopipe_frontend/app/src/components/Table/QueryResult.jsx @@ -1,5 +1,5 @@ import React from 'react'; -import { Table, Button } from 'antd'; +import { Table } from 'antd'; const capitalizeFLetter = (str) => { return str[0].toUpperCase() + diff --git a/arangopipe/arangopipe_frontend/app/src/containers/App/App.jsx b/arangopipe/arangopipe_frontend/app/src/containers/App/App.jsx index e8957ae..eddd090 100755 --- a/arangopipe/arangopipe_frontend/app/src/containers/App/App.jsx +++ b/arangopipe/arangopipe_frontend/app/src/containers/App/App.jsx @@ -16,10 +16,9 @@ import Project from '../Project/Project'; import Query from '../Query/Query'; import './App.css' -import config from '../../utils/config' -import { Layout, Menu, Avatar, Affix, Drawer, Button, Icon, Breadcrumb, Input } from 'antd'; -const { Header, Content, Footer, Sider } = Layout; +import { Layout, Menu, Avatar, Affix, Drawer, Button, Icon, Input } from 'antd'; +const { Header, Content, Footer } = Layout; const { SubMenu } = Menu; const { Search } = Input; @@ -50,7 +49,7 @@ class App extends React.Component{ await this.props.currentUser() } - componentWillMount(){ + componentDidMount(){ if(!this.props.auth.is_authed){ window.location = '/login' } else { @@ -60,13 +59,14 @@ class App extends React.Component{ render() { const username = this.props.auth.user || ''; + const isAdmin = this.props.auth.isAdmin || false; const avatarPath = require('../../assets/avatar.jpeg') const currentPage = this.props.location.pathname.split('/')[1] return ( - +
diff --git a/arangopipe/arangopipe_frontend/app/src/containers/Home/Home.jsx b/arangopipe/arangopipe_frontend/app/src/containers/Home/Home.jsx index 437f8b8..3da67a3 100755 --- a/arangopipe/arangopipe_frontend/app/src/containers/Home/Home.jsx +++ b/arangopipe/arangopipe_frontend/app/src/containers/Home/Home.jsx @@ -1,14 +1,6 @@ import React from 'react'; import { bindActionCreators } from 'redux'; import { connect } from 'react-redux'; -import { Link } from 'react-router-dom'; -import { - getUploadedDocuments, - processDocument, - deleteDocument, - saveToCSV, - clearDB -} from '../../actions/document' import { Table, Input, Button, Icon, Row, Col, Card, Divider, Modal } from 'antd'; import Highlighter from 'react-highlight-words'; diff --git a/arangopipe/arangopipe_frontend/app/src/containers/Query/Query.jsx b/arangopipe/arangopipe_frontend/app/src/containers/Query/Query.jsx index 6b3bca6..6e78ef1 100644 --- a/arangopipe/arangopipe_frontend/app/src/containers/Query/Query.jsx +++ b/arangopipe/arangopipe_frontend/app/src/containers/Query/Query.jsx @@ -1,7 +1,7 @@ import React from 'react'; import { bindActionCreators } from 'redux'; import { connect } from 'react-redux'; -import { Link } from 'react-router-dom'; + import brace from 'brace'; import AceEditor from 'react-ace'; @@ -20,9 +20,8 @@ import { explainQuery } from '../../actions/query' -import { Table, Input, Button, Icon, Row, Col, Popconfirm, Alert, - Tag, Divider, Card, Menu, Tooltip, notification, Switch } from 'antd'; -import Highlighter from 'react-highlight-words'; +import { Button, Icon, Row, Col, Popconfirm, Alert, + Tag, Card, Menu, Tooltip, notification, Switch } from 'antd'; class Query extends React.Component { diff --git a/arangopipe/arangopipe_frontend/app/src/reducers/auth/index.js b/arangopipe/arangopipe_frontend/app/src/reducers/auth/index.js index 8e1ea8a..d1baaa4 100755 --- a/arangopipe/arangopipe_frontend/app/src/reducers/auth/index.js +++ b/arangopipe/arangopipe_frontend/app/src/reducers/auth/index.js @@ -2,7 +2,11 @@ import { USER } from '../type' -const initState = { is_authed: localStorage.getItem('token') ? true : false, user: '' }; +const initState = { + is_authed: localStorage.getItem('token') ? true : false, + user: '', + isAdmin: false +}; const AuthReducer = (state = initState, action) => { @@ -12,7 +16,8 @@ const AuthReducer = (state = initState, action) => { case USER.SIGNED_IN: state.is_authed = true; - state.user = payload; + state.user = payload.name; + state.isAdmin = payload.isAdmin; return { ...state, diff --git a/arangopipe/arangopipe_frontend/app/src/reducers/document/index.js b/arangopipe/arangopipe_frontend/app/src/reducers/document/index.js index 22ad00c..beab32e 100755 --- a/arangopipe/arangopipe_frontend/app/src/reducers/document/index.js +++ b/arangopipe/arangopipe_frontend/app/src/reducers/document/index.js @@ -1,5 +1,5 @@ -import { DOCUMENT, GRAPH } from '../type' +import { DOCUMENT } from '../type' const initState = {} diff --git a/arangopipe/arangopipe_frontend/app/src/reducers/query/index.js b/arangopipe/arangopipe_frontend/app/src/reducers/query/index.js index c8415ce..6709183 100644 --- a/arangopipe/arangopipe_frontend/app/src/reducers/query/index.js +++ b/arangopipe/arangopipe_frontend/app/src/reducers/query/index.js @@ -1,5 +1,5 @@ -import { QUERY, GRAPH } from '../type' +import { QUERY } from '../type' const initState = {default_query: [], saved_query: []}