wip: rewrite to webservice library
This commit is contained in:
parent
abbd320b93
commit
52fba2289e
23 changed files with 201 additions and 680 deletions
|
|
@ -13,8 +13,8 @@ class App extends Component {
|
|||
this.websocket = null
|
||||
this.websocket_int_ping = null
|
||||
this.websocket_int_reconnect = null
|
||||
this.wsConnect()
|
||||
this.wsLoop()
|
||||
//this.wsConnect() // XXX
|
||||
//this.wsLoop() // XXX
|
||||
|
||||
this.session = new Session(this)
|
||||
this.session.initialize()
|
||||
|
|
@ -25,7 +25,7 @@ class App extends Component {
|
|||
|
||||
this.startNode = null
|
||||
|
||||
this.setStartNode()
|
||||
//this.setStartNode()
|
||||
}//}}}
|
||||
render() {//{{{
|
||||
let app_el = document.getElementById('app')
|
||||
|
|
@ -114,7 +114,7 @@ class App extends Component {
|
|||
}
|
||||
|
||||
if(this.session.UUID !== '')
|
||||
headers['X-Session-Id'] = this.session.UUID
|
||||
headers['X-Session-ID'] = this.session.UUID
|
||||
|
||||
fetch(url, {
|
||||
method: 'POST',
|
||||
|
|
@ -201,9 +201,24 @@ class Tree extends Component {
|
|||
this.selectedTreeNode = null
|
||||
|
||||
this.props.app.tree = this
|
||||
this.retrieve()
|
||||
}//}}}
|
||||
render({ app }) {//{{{
|
||||
let renderedTreeTrunk = this.treeTrunk.map(node=>{
|
||||
this.treeNodeComponents[node.ID] = createRef()
|
||||
return html`<${TreeNode} key=${"treenode_"+node.ID} tree=${this} node=${node} ref=${this.treeNodeComponents[node.ID]} selected=${node.ID == app.startNode.ID} />`
|
||||
})
|
||||
return html`<div id="tree">${renderedTreeTrunk}</div>`
|
||||
}//}}}
|
||||
|
||||
retrieve(callback = null) {//{{{
|
||||
this.props.app.request('/node/tree', { StartNodeID: 0 })
|
||||
.then(res=>{
|
||||
this.treeNodes = {}
|
||||
this.treeNodeComponents = {}
|
||||
this.treeTrunk = []
|
||||
this.selectedTreeNode = null
|
||||
|
||||
// A tree of nodes is built. This requires the list of nodes
|
||||
// returned from the server to be sorted in such a way that
|
||||
// a parent node always appears before a child node.
|
||||
|
|
@ -235,17 +250,12 @@ class Tree extends Component {
|
|||
this.crumbsUpdateNodes()
|
||||
this.forceUpdate()
|
||||
|
||||
if(callback)
|
||||
callback()
|
||||
|
||||
})
|
||||
.catch(this.responseError)
|
||||
}//}}}
|
||||
render({ app }) {//{{{
|
||||
let renderedTreeTrunk = this.treeTrunk.map(node=>{
|
||||
this.treeNodeComponents[node.ID] = createRef()
|
||||
return html`<${TreeNode} key=${"treenode_"+node.ID} tree=${this} node=${node} ref=${this.treeNodeComponents[node.ID]} selected=${node.ID == app.startNode.ID} />`
|
||||
})
|
||||
return html`<div id="tree">${renderedTreeTrunk}</div>`
|
||||
}//}}}
|
||||
|
||||
setSelected(node) {//{{{
|
||||
if(this.selectedTreeNode)
|
||||
this.selectedTreeNode.selected.value = false
|
||||
|
|
|
|||
|
|
@ -215,7 +215,14 @@ export class NodeUI extends Component {
|
|||
let name = prompt("Name")
|
||||
if(!name)
|
||||
return
|
||||
this.node.value.create(name, nodeID=>this.goToNode(nodeID))
|
||||
this.node.value.create(name, nodeID=>{
|
||||
console.log('before', this.props.app.startNode)
|
||||
this.props.app.startNode = new Node(this.props.app, nodeID)
|
||||
console.log('after', this.props.app.startNode)
|
||||
this.props.app.tree.retrieve(()=>{
|
||||
this.goToNode(nodeID)
|
||||
})
|
||||
})
|
||||
}//}}}
|
||||
saveNode() {//{{{
|
||||
let nodeContent = this.nodeContent.current
|
||||
|
|
|
|||
|
|
@ -10,11 +10,10 @@ export class Session {
|
|||
// Retrieving the stored session UUID, if any.
|
||||
// If one found, validate with server.
|
||||
|
||||
|
||||
// If the browser doesn't know anything about a session,
|
||||
// a call to /session/create is necessary to retrieve a session UUID.
|
||||
let uuid= window.localStorage.getItem("session.UUID")
|
||||
if(uuid === null) {
|
||||
let uuid = window.localStorage.getItem("session.UUID")
|
||||
if (uuid === null) {
|
||||
this.create()
|
||||
return
|
||||
}
|
||||
|
|
@ -25,47 +24,47 @@ export class Session {
|
|||
// A call to /session/retrieve with a session UUID validates that the
|
||||
// session is still valid and returns all session information.
|
||||
this.UUID = uuid
|
||||
this.app.request('/session/retrieve', {})
|
||||
.then(res=>{
|
||||
if(res.Valid) {
|
||||
// Session exists on server.
|
||||
// Not necessarily authenticated.
|
||||
this.UserID = res.Session.UserID // could be 0
|
||||
this.initialized = true
|
||||
this.app.forceUpdate()
|
||||
} else {
|
||||
// Session has probably expired. A new is required.
|
||||
this.create()
|
||||
}
|
||||
})
|
||||
.catch(this.app.responseError)
|
||||
this.app.request('/_session/retrieve', {})
|
||||
.then(res => {
|
||||
if (res.Error === undefined) {
|
||||
// Session exists on server.
|
||||
// Not necessarily authenticated.
|
||||
this.UserID = res.UserID // could be 0
|
||||
this.initialized = true
|
||||
this.app.forceUpdate()
|
||||
} else {
|
||||
// Session has probably expired. A new is required.
|
||||
this.create()
|
||||
}
|
||||
})
|
||||
.catch(this.app.responseError)
|
||||
}//}}}
|
||||
create() {//{{{
|
||||
this.app.request('/session/create', {})
|
||||
.then(res=>{
|
||||
this.UUID = res.Session.UUID
|
||||
window.localStorage.setItem('session.UUID', this.UUID)
|
||||
this.initialized = true
|
||||
this.app.forceUpdate()
|
||||
})
|
||||
.catch(this.responseError)
|
||||
this.app.request('/_session/new', {})
|
||||
.then(res => {
|
||||
this.UUID = res.Session.UUID
|
||||
window.localStorage.setItem('session.UUID', this.Session.UUID)
|
||||
this.initialized = true
|
||||
this.app.forceUpdate()
|
||||
})
|
||||
.catch(this.responseError)
|
||||
}//}}}
|
||||
authenticate(username, password) {//{{{
|
||||
this.app.login.current.authentication_failed.value = false
|
||||
|
||||
this.app.request('/session/authenticate', {
|
||||
this.app.request('/_session/authenticate', {
|
||||
username,
|
||||
password,
|
||||
})
|
||||
.then(res=>{
|
||||
if(res.Authenticated) {
|
||||
this.UserID = res.Session.UserID
|
||||
this.app.forceUpdate()
|
||||
} else {
|
||||
this.app.login.current.authentication_failed.value = true
|
||||
}
|
||||
})
|
||||
.catch(this.app.responseError)
|
||||
.then(res => {
|
||||
if (res.Authenticated) {
|
||||
this.UserID = res.Session.UserID
|
||||
this.app.forceUpdate()
|
||||
} else {
|
||||
this.app.login.current.authentication_failed.value = true
|
||||
}
|
||||
})
|
||||
.catch(this.app.responseError)
|
||||
}//}}}
|
||||
authenticated() {//{{{
|
||||
return this.UserID != 0
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue