summaryrefslogtreecommitdiff
path: root/frontend/views/page
diff options
context:
space:
mode:
Diffstat (limited to 'frontend/views/page')
-rw-r--r--frontend/views/page/components/page.header.js3
-rw-r--r--frontend/views/page/components/tile.edit.js1
-rw-r--r--frontend/views/page/components/tile.form.js4
-rw-r--r--frontend/views/page/components/tile.new.js1
-rw-r--r--frontend/views/page/page.actions.js32
-rw-r--r--frontend/views/page/page.container.js13
-rw-r--r--frontend/views/page/page.reducer.js6
7 files changed, 49 insertions, 11 deletions
diff --git a/frontend/views/page/components/page.header.js b/frontend/views/page/components/page.header.js
index a6c47ee..3eff339 100644
--- a/frontend/views/page/components/page.header.js
+++ b/frontend/views/page/components/page.header.js
@@ -9,7 +9,7 @@ function PageHeader(props) {
return (
<header>
<div>
- <Link to="/" className="logo"><b>{props.site.siteTitle}</b></Link>
+ <Link to={props.graph.show.res ? "/" + props.graph.show.res.path : "/"} className="logo"><b>{props.site.siteTitle}</b></Link>
</div>
<div>
<button onClick={() => props.pageActions.showAddTileForm()}>+ Add tile</button>
@@ -21,6 +21,7 @@ function PageHeader(props) {
const mapStateToProps = (state) => ({
// auth: state.auth,
site: state.site,
+ graph: state.graph,
// isAuthenticated: state.auth.isAuthenticated,
})
diff --git a/frontend/views/page/components/tile.edit.js b/frontend/views/page/components/tile.edit.js
index 3420505..6d8d835 100644
--- a/frontend/views/page/components/tile.edit.js
+++ b/frontend/views/page/components/tile.edit.js
@@ -36,6 +36,7 @@ class TileEdit extends Component {
<TileForm
data={show.res}
graph={this.props.graph.show.res}
+ page={this.props.page.show.res}
onSubmit={this.handleSubmit.bind(this)}
/>
)
diff --git a/frontend/views/page/components/tile.form.js b/frontend/views/page/components/tile.form.js
index 1e75cd8..6b9d0a7 100644
--- a/frontend/views/page/components/tile.form.js
+++ b/frontend/views/page/components/tile.form.js
@@ -25,7 +25,7 @@ export default class TileForm extends Component {
}
componentDidMount() {
- const { graph, data, isNew } = this.props
+ const { graph, page, data, isNew } = this.props
const title = isNew ? 'new tile' : 'editing ' + data.title
const submitTitle = isNew ? "Create Tile" : "Save Changes"
this.setState({
@@ -33,7 +33,7 @@ export default class TileForm extends Component {
submitTitle,
errorFields: new Set([]),
data: {
- ...newTile({ graph_id: graph.id }),
+ ...newTile({ graph_id: graph.id, page_id: page.id }),
...data,
},
})
diff --git a/frontend/views/page/components/tile.new.js b/frontend/views/page/components/tile.new.js
index 7445f27..cb5eaa8 100644
--- a/frontend/views/page/components/tile.new.js
+++ b/frontend/views/page/components/tile.new.js
@@ -28,6 +28,7 @@ class TileNew extends Component {
<TileForm
isNew
graph={this.props.graph.show.res}
+ page={this.props.page.show.res}
data={{}}
onSubmit={this.handleSubmit.bind(this)}
/>
diff --git a/frontend/views/page/page.actions.js b/frontend/views/page/page.actions.js
index cfd0f98..941bd9b 100644
--- a/frontend/views/page/page.actions.js
+++ b/frontend/views/page/page.actions.js
@@ -1,13 +1,39 @@
import * as types from '../../types'
+import { store } from '../../store'
+import actions from '../../actions'
export const showAddTileForm = () => dispatch => {
- dispatch({ type: types.graph.show_add_tile_form })
+ dispatch({ type: types.page.show_add_tile_form })
}
export const hideAddTileForm = () => dispatch => {
- dispatch({ type: types.graph.hide_add_tile_form })
+ dispatch({ type: types.page.hide_add_tile_form })
}
export const updatePageTile = tile => dispatch => {
- dispatch({ type: types.graph.update_graph_tile, tile })
+ dispatch({ type: types.page.update_graph_tile, tile })
}
+
+export const showGraphAndPageIfUnloaded = ({ graph_name, page_name }) => dispatch => (
+ new Promise((resolve, reject) => {
+ showGraphIfUnloaded({ graph_name })(dispatch)
+ .then(graph => (
+ actions.page.show('name/' + graph_name + '/' + page_name)
+ .then(resolve)
+ .catch(reject)
+ ))
+ .catch(reject)
+ })
+)
+
+export const showGraphIfUnloaded = ({ graph_name }) => dispatch => (
+ new Promise((resolve, reject) => {
+ const { res: graph } = store.getState().graph.show
+ if (graph && graph.path === graph_name) {
+ return resolve(graph)
+ }
+ actions.graph.show('name/' + graph_name)
+ .then(resolve)
+ .catch(reject)
+ })
+) \ No newline at end of file
diff --git a/frontend/views/page/page.container.js b/frontend/views/page/page.container.js
index 2de56bb..bbb1f3a 100644
--- a/frontend/views/page/page.container.js
+++ b/frontend/views/page/page.container.js
@@ -8,8 +8,10 @@ import './page.css'
import actions from '../../actions'
import { Loader } from '../../common'
-// import * as uploadActions from './upload.actions'
+import * as graphActions from '../graph/graph.actions'
+import * as pageActions from './page.actions'
+import PageEdit from '../graph/components/page.edit'
import TileNew from './components/tile.new'
import TileEdit from './components/tile.edit'
@@ -37,9 +39,12 @@ class PageContainer extends Component {
}
load() {
actions.site.setSiteTitle("loading " + this.props.match.params.page_name + "...")
- actions.page.show('name/' + this.props.match.params.graph_name + '/' + this.props.match.params.page_name)
+ this.props.pageActions.showGraphAndPageIfUnloaded(this.props.match.params)
.then(data => {
actions.site.setSiteTitle(data.res.title)
+ if (!data.res.tiles.length) {
+ this.props.pageActions.showAddTileForm()
+ }
})
}
render() {
@@ -61,6 +66,7 @@ class PageContainer extends Component {
<PageHeader />
<div className='body'>
<PageEditor />
+ {this.props.graph.editor.editingPage && <PageEdit />}
{this.props.page.editor.addingTile && <TileNew />}
{this.props.page.editor.editingTile && <TileEdit />}
</div>
@@ -75,7 +81,8 @@ const mapStateToProps = state => ({
})
const mapDispatchToProps = dispatch => ({
- // uploadActions: bindActionCreators({ ...uploadActions }, dispatch),
+ graphActions: bindActionCreators({ ...graphActions }, dispatch),
+ pageActions: bindActionCreators({ ...pageActions }, dispatch),
})
export default connect(mapStateToProps, mapDispatchToProps)(PageContainer)
diff --git a/frontend/views/page/page.reducer.js b/frontend/views/page/page.reducer.js
index d1d6510..1494bc2 100644
--- a/frontend/views/page/page.reducer.js
+++ b/frontend/views/page/page.reducer.js
@@ -42,6 +42,7 @@ export default function pageReducer(state = initialState, action) {
editor: {
...state.editor,
addingTile: true,
+ editingTile: false,
}
}
@@ -59,7 +60,8 @@ export default function pageReducer(state = initialState, action) {
...state,
editor: {
...state.editor,
- addingTile: true,
+ addingTile: false,
+ editingTile: true,
}
}
@@ -68,7 +70,7 @@ export default function pageReducer(state = initialState, action) {
...state,
editor: {
...state.editor,
- addingTile: false,
+ editingTile: false,
}
}