summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--cli/app/controllers/graph_controller.py20
-rw-r--r--cli/app/controllers/page_controller.py2
-rw-r--r--cli/app/controllers/tile_controller.py4
-rw-r--r--cli/app/server/web.py1
-rw-r--r--frontend/actions.js4
-rw-r--r--frontend/app.js10
-rw-r--r--frontend/common/header.component.js7
-rw-r--r--frontend/store.js2
-rw-r--r--frontend/types.js4
-rw-r--r--frontend/views/graph/graph.container.js66
-rw-r--r--frontend/views/graph/graph.css3
-rw-r--r--frontend/views/index.js1
-rw-r--r--frontend/views/index/components/graph.form.js2
-rw-r--r--frontend/views/index/graph.reducer.js2
-rw-r--r--frontend/views/index/index.container.js15
-rw-r--r--frontend/views/site/site.actions.js9
-rw-r--r--frontend/views/site/site.reducer.js20
-rw-r--r--frontend/views/upload/upload.container.js5
18 files changed, 151 insertions, 26 deletions
diff --git a/cli/app/controllers/graph_controller.py b/cli/app/controllers/graph_controller.py
index 25b49aa..3fa4cce 100644
--- a/cli/app/controllers/graph_controller.py
+++ b/cli/app/controllers/graph_controller.py
@@ -16,3 +16,23 @@ class GraphView(CrudView):
for item in item.pages:
session.query(Tile).filter(Tile.page_id == item.id).delete(synchronize_session=False)
session.query(Page).filter(Page.graph_id == item.id).delete(synchronize_session=False)
+
+ @route('/name/<path>', methods=['GET'])
+ def get_name(self, path: str):
+ """
+ Fetch a single {model}.
+ """
+ session = Session()
+ item = session.query(self.model).filter(self.model.path == path).first()
+ if not item:
+ session.close()
+ return jsonify({
+ 'status': 'error',
+ 'error': 'item not found'
+ })
+ result = {
+ 'status': 'ok',
+ 'res': item.toFullJSON() if hasattr(item, 'toFullJSON') else item.toJSON(),
+ }
+ session.close()
+ return jsonify(result)
diff --git a/cli/app/controllers/page_controller.py b/cli/app/controllers/page_controller.py
index d393625..1f53171 100644
--- a/cli/app/controllers/page_controller.py
+++ b/cli/app/controllers/page_controller.py
@@ -14,7 +14,7 @@ class PageView(CrudView):
def where(self, query, args):
graph_id = args.get('graph_id', default=None)
if graph_id is not None:
- query = query.where(Page.graph_id == int(graph_id))
+ query = query.filter(Page.graph_id == int(graph_id))
return query
def on_destroy(self, session, item):
diff --git a/cli/app/controllers/tile_controller.py b/cli/app/controllers/tile_controller.py
index fc36943..58fd6d0 100644
--- a/cli/app/controllers/tile_controller.py
+++ b/cli/app/controllers/tile_controller.py
@@ -13,8 +13,8 @@ class TileView(CrudView):
def where(self, query, args):
graph_id = args.get('graph_id', default=None)
if graph_id is not None:
- query = query.where(Tile.graph_id == int(graph_id))
+ query = query.filter(Tile.graph_id == int(graph_id))
page_id = args.get('page_id', default=None)
if page_id is not None:
- query = query.where(Tile.page_id == int(page_id))
+ query = query.filter(Tile.page_id == int(page_id))
return query
diff --git a/cli/app/server/web.py b/cli/app/server/web.py
index 739f271..83dbc24 100644
--- a/cli/app/server/web.py
+++ b/cli/app/server/web.py
@@ -30,6 +30,7 @@ def create_app(script_info=None):
app = Flask(__name__, static_folder=app_cfg.DIR_STATIC, static_url_path='/static')
app.config['SQLALCHEMY_DATABASE_URI'] = connection_url
app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False
+ app.url_map.strict_slashes = False
db.init_app(app)
diff --git a/frontend/actions.js b/frontend/actions.js
index 31e0a52..69b06f0 100644
--- a/frontend/actions.js
+++ b/frontend/actions.js
@@ -1,7 +1,7 @@
import { bindActionCreators } from 'redux'
import { actions as crudActions } from './api'
-// import * as dashboardActions from './views/dashboard/dashboard.actions'
+import * as siteActions from './views/site/site.actions'
import { store } from './store'
@@ -9,7 +9,7 @@ export default
Object.keys(crudActions)
.map(a => [a, crudActions[a]])
.concat([
- // ['dashboard', dashboardActions],
+ ['site', siteActions],
])
.map(p => [p[0], bindActionCreators(p[1], store.dispatch)])
.concat([
diff --git a/frontend/app.js b/frontend/app.js
index da8dccb..5be0c0f 100644
--- a/frontend/app.js
+++ b/frontend/app.js
@@ -10,8 +10,16 @@ import * as views from './views'
const viewList = Object.keys(views).map(name => {
const view = views[name]
+ let path
+ if (name === 'graph') {
+ path = '/:graph_name'
+ } else if (name === 'page') {
+ path = '/:graph_name/:page_name'
+ } else {
+ path = '/' + name
+ }
return (
- <Route key={name} path={'/' + name} component={view} />
+ <Route key={name} path={path} component={view} />
)
})
diff --git a/frontend/common/header.component.js b/frontend/common/header.component.js
index 5cb15b5..9e96e80 100644
--- a/frontend/common/header.component.js
+++ b/frontend/common/header.component.js
@@ -8,7 +8,7 @@ function Header(props) {
return (
<header>
<div>
- <Link to="/" className="logo"><b>swimmer</b></Link>
+ <Link to="/" className="logo"><b>{props.site.siteTitle}</b></Link>
</div>
<div>
<span className='username' onClick={() => changeUsername()}>
@@ -29,9 +29,10 @@ const changeUsername = () => {
const mapStateToProps = (state) => ({
- auth: state.auth,
+ // auth: state.auth,
+ site: state.site,
username: session.get('username'),
- isAuthenticated: state.auth.isAuthenticated,
+ // isAuthenticated: state.auth.isAuthenticated,
})
const mapDispatchToProps = (dispatch) => ({
diff --git a/frontend/store.js b/frontend/store.js
index d21dffb..e0432c4 100644
--- a/frontend/store.js
+++ b/frontend/store.js
@@ -6,12 +6,14 @@ import thunk from 'redux-thunk'
import uploadReducer from './views/upload/upload.reducer'
import graphReducer from './views/index/graph.reducer'
+import siteReducer from './views/site/site.reducer'
// import collectionReducer from './views/collection/collection.reducer'
const createRootReducer = history => (
combineReducers({
auth: (state = {}) => state,
router: connectRouter(history),
+ site: siteReducer,
graph: graphReducer,
upload: uploadReducer,
// collection: collectionReducer,
diff --git a/frontend/types.js b/frontend/types.js
index cf48b67..b326994 100644
--- a/frontend/types.js
+++ b/frontend/types.js
@@ -6,6 +6,10 @@ export const page = crud_type('page', [])
export const tile = crud_type('tile', [])
export const upload = crud_type('upload', [])
+export const site = with_type('site', [
+ 'set_site_title',
+])
+
export const system = with_type('system', [
'load_site',
])
diff --git a/frontend/views/graph/graph.container.js b/frontend/views/graph/graph.container.js
new file mode 100644
index 0000000..40e2e6a
--- /dev/null
+++ b/frontend/views/graph/graph.container.js
@@ -0,0 +1,66 @@
+import React, { Component } from 'react'
+import { Route } from 'react-router-dom'
+import { bindActionCreators } from 'redux'
+import { connect } from 'react-redux'
+
+import './graph.css'
+
+import actions from '../../actions'
+import { Loader } from '../../common'
+
+// import * as uploadActions from './upload.actions'
+
+// import GraphIndex from './containers/graph.index'
+
+class GraphContainer extends Component {
+ componentDidMount() {
+ if (this.shouldShowGraph()) this.load()
+ }
+ componentDidUpdate(prevProps) {
+ if (this.shouldLoadGraph(prevProps)) this.load()
+ }
+ shouldShowGraph() {
+ const { graph_name, page_name } = this.props.match.params
+ return (graph_name && !page_name && graph_name !== 'index')
+ }
+ shouldLoadGraph(prevProps) {
+ const { graph, location } = this.props
+ const { key } = location
+ if (key === prevProps.location.key) return false
+ if (!this.shouldShowGraph()) return false
+ return (graph.show.name === prevProps.graph.show.name)
+ }
+ load() {
+ actions.site.setSiteTitle("loading " + this.props.match.params.graph_name + "...")
+ actions.graph.show('name/' + this.props.match.params.graph_name)
+ .then(data => {
+ actions.site.setSiteTitle(data.res.title)
+ })
+ }
+ render() {
+ if (!this.shouldShowGraph()) return null
+ if (this.props.graph.show.loading) {
+ return (
+ <div className='index'>
+ <Loader />
+ </div>
+ )
+ }
+ console.log(this.props.graph.show)
+ return (
+ <div className='index'>
+ </div>
+ )
+ }
+}
+
+ // <Route exact path='/:graph_name' component={GraphView} />
+const mapStateToProps = state => ({
+ graph: state.graph,
+})
+
+const mapDispatchToProps = dispatch => ({
+ // uploadActions: bindActionCreators({ ...uploadActions }, dispatch),
+})
+
+export default connect(mapStateToProps, mapDispatchToProps)(GraphContainer)
diff --git a/frontend/views/graph/graph.css b/frontend/views/graph/graph.css
new file mode 100644
index 0000000..0a490f9
--- /dev/null
+++ b/frontend/views/graph/graph.css
@@ -0,0 +1,3 @@
+* {
+
+} \ No newline at end of file
diff --git a/frontend/views/index.js b/frontend/views/index.js
index 69bb70e..07e7284 100644
--- a/frontend/views/index.js
+++ b/frontend/views/index.js
@@ -1,2 +1,3 @@
export { default as index } from './index/index.container'
+export { default as graph } from './graph/graph.container'
export { default as upload } from './upload/upload.container'
diff --git a/frontend/views/index/components/graph.form.js b/frontend/views/index/components/graph.form.js
index a6a0dd6..50f9773 100644
--- a/frontend/views/index/components/graph.form.js
+++ b/frontend/views/index/components/graph.form.js
@@ -22,7 +22,7 @@ export default class GraphForm extends Component {
componentDidMount() {
const { data, isNew } = this.props
- const title = isNew ? 'new graph' : 'editing ' + data.title
+ const title = isNew ? 'new project' : 'editing ' + data.title
const submitTitle = isNew ? "Create Graph" : "Save Changes"
this.setState({
title,
diff --git a/frontend/views/index/graph.reducer.js b/frontend/views/index/graph.reducer.js
index 20aed8e..612ac14 100644
--- a/frontend/views/index/graph.reducer.js
+++ b/frontend/views/index/graph.reducer.js
@@ -11,7 +11,7 @@ const initialState = crudState('graph', {
const reducer = crudReducer('graph')
export default function graphReducer(state = initialState, action) {
- console.log(action.type, action)
+ // console.log(action.type, action)
state = reducer(state, action)
switch (action.type) {
default:
diff --git a/frontend/views/index/index.container.js b/frontend/views/index/index.container.js
index 0e7127a..1e2326b 100644
--- a/frontend/views/index/index.container.js
+++ b/frontend/views/index/index.container.js
@@ -5,7 +5,7 @@ import { connect } from 'react-redux'
import './index.css'
-// import actions from '../../actions'
+import actions from '../../actions'
// import * as uploadActions from './upload.actions'
import GraphIndex from './containers/graph.index'
@@ -13,6 +13,9 @@ import GraphNew from './containers/graph.new'
import GraphEdit from './containers/graph.edit'
class Container extends Component {
+ componentDidMount() {
+ actions.site.setSiteTitle("swimmer")
+ }
render() {
return (
<div className='index'>
@@ -24,12 +27,4 @@ class Container extends Component {
}
}
-const mapStateToProps = state => ({
- // upload: state.upload,
-})
-
-const mapDispatchToProps = dispatch => ({
- // uploadActions: bindActionCreators({ ...uploadActions }, dispatch),
-})
-
-export default connect(mapStateToProps, mapDispatchToProps)(Container)
+export default Container
diff --git a/frontend/views/site/site.actions.js b/frontend/views/site/site.actions.js
new file mode 100644
index 0000000..74ce72d
--- /dev/null
+++ b/frontend/views/site/site.actions.js
@@ -0,0 +1,9 @@
+import * as types from '../../types'
+import { store, history } from '../../store'
+import { api, post, pad, preloadImage } from '../../util'
+import actions from '../../actions'
+import { session } from '../../session'
+
+export const setSiteTitle = title => dispatch => (
+ dispatch({ type: types.site.set_site_title, payload: title })
+) \ No newline at end of file
diff --git a/frontend/views/site/site.reducer.js b/frontend/views/site/site.reducer.js
new file mode 100644
index 0000000..c9a25dd
--- /dev/null
+++ b/frontend/views/site/site.reducer.js
@@ -0,0 +1,20 @@
+import * as types from '../../types'
+// import { session, getDefault, getDefaultInt } from '../../session'
+
+const initialState = {
+ 'siteTitle': 'swimmer',
+}
+
+export default function graphReducer(state = initialState, action) {
+ // console.log(action.type, action)
+ switch (action.type) {
+ case types.site.set_site_title:
+ return {
+ ...state,
+ siteTitle: action.payload,
+ }
+
+ default:
+ return state
+ }
+}
diff --git a/frontend/views/upload/upload.container.js b/frontend/views/upload/upload.container.js
index 0096b4f..ea9df5a 100644
--- a/frontend/views/upload/upload.container.js
+++ b/frontend/views/upload/upload.container.js
@@ -25,11 +25,6 @@ class Container extends Component {
}
}
-/*
- <Route exact path='/collection/:id/show/' component={CollectionShow} />
- <Route exact path='/collection/' component={CollectionIndex} />
-*/
-
const mapStateToProps = state => ({
upload: state.upload,
searchOptions: state.search.options,