Commit a9aaa7ff authored by Jure's avatar Jure

Disable collaboration by replacing a CollabSession with a DocumentSession.

parent 72dea07a
node_modules/*
Makefile
*.sublime-*
app/registry/Substance/ReactLensReader.js
......@@ -22,7 +22,6 @@ class DocumentStore {
collection.addFragment(fragment)
return collection.save()
}).then(function (collection) {
console.log('hohooh', fragment)
return cb(null, fragment)
}).catch(function (err) {
console.log(err)
......
......@@ -112,7 +112,9 @@ export function createFragment (fragment) {
body: JSON.stringify(fragment)})
.then(response => {
if (response.ok) {
return response.json()
return response.json().then(response => {
dispatch(createFragmentSuccess(response))
})
} else {
return response.json().then(response => {
dispatch(createFragmentFailure(response.message))
......
......@@ -2,7 +2,7 @@ import fetch from 'isomorphic-fetch'
import { API_ENDPOINT } from '../../config.js'
import * as T from './types'
import { createFragmentSuccess, createFragmentRequest } from './index'
import { createFragmentFailure, createFragmentSuccess, createFragmentRequest } from './index'
// CREATE substance document
export function createSubstanceDocument (document) {
......@@ -14,7 +14,7 @@ export function createSubstanceDocument (document) {
headers: {
'Accept': 'application/json',
'Authorization': 'Bearer ' + token,
'Content-Type': 'application/json',
'Content-Type': 'application/json'
},
body: JSON.stringify(document)})
.then(response => {
......
......@@ -14,7 +14,7 @@ export default class BlogpostCreator extends React.Component {
title: this.refs.title.getValue(),
status: 'unpublished',
version: 1,
data: ''
source: undefined
})
}
......
......@@ -17,7 +17,6 @@ export default class BlogpostList extends React.Component {
})
return (
<div className={styles['list']}>
<h3 className={styles['header']}>Blog posts</h3>
<table className='table table-hover'>
<thead>
<tr>
......
......@@ -18,13 +18,12 @@ class BlogManager extends React.Component {
<div className='bootstrap'>
<Grid>
{ error ? <Alert bsStyle='warning'>{error}</Alert> : null}
<div blog={blog} className={styles.vote}>
<BlogpostList
update={actions.updateFragment}
delete={actions.deleteFragment}
blogposts={blogposts} />
<BlogpostCreator create={actions.createSubstanceDocument} />
</div>
<h3 className={styles['header']}>{blog && blog.title} blog posts</h3>
<BlogpostList
update={actions.updateFragment}
delete={actions.deleteFragment}
blogposts={blogposts} />
<BlogpostCreator create={actions.createFragment} />
</Grid>
</div>
)
......@@ -38,7 +37,7 @@ BlogManager.propTypes = {
error: React.PropTypes.object
}
function mapStateToProps (state) {
function mapState (state) {
return {
blog: state.collections[0],
blogposts: state.fragments,
......@@ -46,13 +45,13 @@ function mapStateToProps (state) {
}
}
function mapDispatchToProps (dispatch) {
function mapDispatch (dispatch) {
return {
actions: bindActionCreators(Actions, dispatch)
}
}
export default connect(
mapStateToProps,
mapDispatchToProps
mapState,
mapDispatch
)(BlogManager)
......@@ -2,7 +2,7 @@ import React from 'react'
import { bindActionCreators } from 'redux'
import { connect } from 'react-redux'
import * as Actions from '../../actions'
// import _ from 'lodash'
import _ from 'lodash'
import fetch from 'isomorphic-fetch'
// Which editor component to import?
......@@ -12,7 +12,7 @@ export default class EditorWrapper extends React.Component {
constructor (props) {
super(props)
this.props.actions.getSubstanceDocument(this.props.id)
// this.props.actions.getSubstanceDocument(this.props.id)
}
uploadFile (file, callback) {
......@@ -34,7 +34,7 @@ export default class EditorWrapper extends React.Component {
if (this.props.document) {
editor = <Editor
document={this.props.document}
// save={this.props.actions.updateFragment}
save={this.props.actions.updateFragment}
uploadFile={this.uploadFile}
/>
} else {
......@@ -56,10 +56,11 @@ EditorWrapper.propTypes = {
}
function mapStateToProps (state) {
console.log(state)
return {
id: state.router.params.id,
document: state.substance
document: _.find(state.fragments, function (f) {
return f._id === state.router.params.id
})
}
}
......
var React = require('react');
var LensReader = require('lens/LensReader');
var Component = require('substance/ui/Component');
var $$ = Component.$$;
var LensArticleImporter = require('lens/model/LensArticleImporter');
var importer = new LensArticleImporter();
var React = require('react')
var LensReader = require('lens/LensReader')
var Component = require('lens/node_modules/substance/ui/Component')
var DocumentSession = require('substance/model/DocumentSession')
const JSONConverter = require('substance/model/JSONConverter')
const defaultLensArticle = require('lens/model/defaultLensArticle')
// LensReader wrapped in a React component
// ------------------
var ReactLensReader = React.createClass({
getReader: function() {
return this.reader;
},
getContent: function() {
return this.reader.getDocument().toXml();
},
class ReactLensReader extends React.Component {
// New props arrived, update the editor
componentDidUpdate: function() {
var doc = this.createDoc(this.props.content);
componentDidUpdate () {
var doc = this.createDoc(this.props.content)
this.reader.extendProps({
doc: doc
});
},
createDoc: function(xmlContent) {
var doc = importer.importDocument(xmlContent);
doc.updateCollections();
return doc;
},
componentDidMount: function() {
var el = React.findDOMNode(this);
var doc = this.createDoc(this.props.content);
})
}
createDocumentSession () {
var doc = this.createDoc(this.props.content)
return new DocumentSession(doc)
}
createDoc (source) {
var converter = new JSONConverter()
var doc = defaultLensArticle.createEmptyArticle()
converter.importDocument(doc, source)
return doc
}
componentDidMount () {
var el = React.findDOMNode(this)
var documentSession = this.createDocumentSession()
this.reader = Component.mount(LensReader, {
doc: doc
}, el);
},
documentSession: documentSession
}, el)
}
componentWillUnmount: function() {
this.reader.dispose();
},
componentWillUnmount () {
this.reader.dispose()
}
render: function() {
render () {
return React.DOM.div({
className: 'lens-reader-wrapper'
});
})
}
});
}
ReactLensReader.propTypes = {
content: React.PropTypes.string // XML source of the document
};
content: React.PropTypes.object // JSON source of the document
}
module.exports = ReactLensReader;
module.exports = ReactLensReader
var React = require('react')
var LensWriter = require('lens/LensWriter')
var Component = require('lens/node_modules/substance/ui/Component')
var CollabSession = require('substance/collab/CollabSession')
var CollabClient = require('substance/collab/CollabClient')
var DocumentSession = require('substance/model/DocumentSession')
// var CollabSession = require('substance/collab/CollabSession')
// var CollabClient = require('substance/collab/CollabClient')
// var $$ = Component.$$
......@@ -24,32 +25,26 @@ class ReactLensWriter extends React.Component {
return this
}
// Delegators
_onSave (doc, changes, cb) {
// var xml = exporter.exportDocument(doc)
// this.props.onSave(xml, cb)
}
_onUploadFile (file, cb) {
// this.props.onUploadFile(file, cb)
}
getContent () {
// var doc = this.writer.getDocument()
// var xml = exporter.exportDocument(doc)
// return xml
}
createDocumentSession () {
var doc = this.createDoc(this.props.content, this.props.format)
var collabClient = new CollabClient({
wsUrl: 'ws://' + document.location.hostname + ':8080'
})
var documentSession = new CollabSession(doc, {
docId: this.props.documentId,
docVersion: this.props.version,
collabClient: collabClient
})
var content = this.props.content ? this.props.content : {
'schema': {'name': 'lens-article', 'version': '3.0.0'},
'nodes': [
{'type': 'container', 'id': 'main', 'nodes': ['p1']},
{'type': 'article-meta', 'id': 'article-meta', 'title': 'Untitled', 'authors': [], 'abstract': 'Enter abstract'},
{'type': 'paragraph', 'id': 'p1', 'content': 'Enter text here'}
]}
var format = this.props.format ? this.props.format : 'json'
var doc = this.createDoc(content, format)
// var collabClient = new CollabClient({
// wsUrl: 'ws://' + document.location.hostname + ':8080'
// })
var documentSession = new DocumentSession(doc)
// var documentSession = new CollabSession(doc, {
// docId: this.props.documentId,
// docVersion: this.props.version,
// collabClient: collabClient
// })
return documentSession
}
......@@ -74,14 +69,19 @@ class ReactLensWriter extends React.Component {
return doc
}
save (source, changes, callback) {
var converter = new JSONConverter()
this.props.onSave(converter.exportDocument(source), callback)
}
componentDidMount () {
var el = React.findDOMNode(this)
var documentSession = this.createDocumentSession()
this.writer = Component.mount(LensWriter, {
documentSession: documentSession,
onSave: this._onSave,
onUploadFile: this._onUploadFile
onSave: this.save.bind(this),
onUploadFile: this.props.onUploadFile
}, el)
}
......@@ -98,6 +98,7 @@ class ReactLensWriter extends React.Component {
ReactLensWriter.propTypes = {
onSave: React.PropTypes.func,
onUploadFile: React.PropTypes.func,
format: React.PropTypes.string,
documentId: React.PropTypes.string,
content: React.PropTypes.object,
......
......@@ -17,7 +17,7 @@ export default class Reader extends React.Component {
Reader.propTypes = {
// Data
content: React.PropTypes.string
content: React.PropTypes.object
}
export default Reader
......@@ -7,10 +7,10 @@ export default class Summary extends React.Component {
render () {
const { fragment } = this.props
let summary
if (fragment.presentation) {
summary = fragment.presentation.match(/<abstract>(.*?)<\/abstract>/)
if (fragment.source) {
summary = fragment.source.nodes
if (summary && summary[1]) {
summary = summary[1]
summary = summary[1].abstract
}
}
if (!summary) {
......@@ -23,7 +23,7 @@ export default class Summary extends React.Component {
<Row key={fragment._id}>
<Col xs={12} md={8} mdOffset={2}>
<h2>{fragment.title}</h2>
<div><em>Published by {fragment.author} on {publishDate}.</em></div>
<div><em>Published by {fragment.owner} on {publishDate}.</em></div>
<div dangerouslySetInnerHTML={{__html: summary}}></div>
<LinkContainer to={`/${fragment._id}`}><a>Read more</a></LinkContainer>&nbsp;
</Col>
......
......@@ -11,39 +11,27 @@ class Writer extends React.Component {
this.uploadFile = this.uploadFile.bind(this)
}
save (content, callback) {
// let fragment = Object.assign(this.props.fragment, {
// source: content,
// presentation: content
// })
// this.props.save(fragment)
// callback(null, content)
save (source, callback) {
let doc = Object.assign(this.props.document, {
source: source
})
this.props.save(doc)
callback(null, source)
}
uploadFile (file, callback) {
// return this.props.uploadFile(file, callback)
return this.props.uploadFile(file, callback)
}
render () {
let editor
// let content
if (this.props.document.data) {
editor = <LensWriter
documentId={this.props.document._id}
version={this.props.document.version}
content={this.props.document.data}
onSave={this.save}
format='json'
onUploadFile={this.uploadFile}
/>
} else {
editor = <p>Loading</p>
}
return (
<div>{editor}</div>
)
return <LensWriter
documentId={this.props.document._id}
version={this.props.document.version}
content={this.props.document.source}
onSave={this.save}
format='json'
onUploadFile={this.uploadFile}
/>
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment