list lists ok
This commit is contained in:
parent
4f3517eb03
commit
9f749b3067
@ -3,37 +3,39 @@ h = require 'maquette' .h
|
|||||||
|
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
create-socket: ->
|
create-socket: (socket-url) ->
|
||||||
self = {}
|
self = {}
|
||||||
|
|
||||||
request-types = {
|
request-types = {
|
||||||
\get-token: 0
|
"get-token": 0
|
||||||
\add-user: 1
|
"add-user": 1
|
||||||
\get-user: 2
|
"get-user": 2
|
||||||
\get-user-by-credentials: 3
|
"get-user-by-credentials": 3
|
||||||
\mod-user: 4
|
"mod-user": 4
|
||||||
}
|
}
|
||||||
|
|
||||||
response-types = {
|
response-types = {
|
||||||
\error: 0
|
"error": 0
|
||||||
\token: 1
|
"token": 1
|
||||||
\user: 2
|
"user": 2
|
||||||
\user-added: 3
|
"user-added": 3
|
||||||
\user-edited: 4
|
"user-edited": 4
|
||||||
}
|
}
|
||||||
|
|
||||||
# TODO: naming convention
|
# TODO: naming convention
|
||||||
# users can record functions to run on events
|
# users can record functions to run on events
|
||||||
self.user-on-socket-error = []
|
self.user-on-socket-error = []
|
||||||
self.user-on-close = []
|
self.user-on-socket-close = []
|
||||||
|
|
||||||
self.callbacks = {}
|
self.callbacks = {}
|
||||||
for key, value in response-types
|
for key, value of response-types
|
||||||
self.callbacks[key] = []
|
self.callbacks[value] = []
|
||||||
|
|
||||||
# self.user-on-message = []
|
# self.user-on-message = []
|
||||||
|
|
||||||
self.add-event-listener = (type, callback) ->
|
self.add-event-listener = (type, callback) ->
|
||||||
|
console.log "authd: add event listener", type, callback, response-types[type]
|
||||||
|
console.log response-types
|
||||||
type = response-types[type]
|
type = response-types[type]
|
||||||
|
|
||||||
self.callbacks[type] ++= [callback]
|
self.callbacks[type] ++= [callback]
|
||||||
@ -48,13 +50,14 @@ module.exports = {
|
|||||||
self.socket.close!
|
self.socket.close!
|
||||||
|
|
||||||
self.socket.onclose = (event) ->
|
self.socket.onclose = (event) ->
|
||||||
for f in self.user-on-close
|
for f in self.user-on-socket-close
|
||||||
f event
|
f event
|
||||||
|
|
||||||
self.socket.onmessage = (event) ->
|
self.socket.onmessage = (event) ->
|
||||||
message = JSON.parse(event.data)
|
message = JSON.parse(event.data)
|
||||||
|
console.log "authd message received: ", message
|
||||||
|
|
||||||
for f in self.callbacks[message.type]
|
for f in self.callbacks[message.mtype]
|
||||||
f JSON.parse(message.payload)
|
f JSON.parse(message.payload)
|
||||||
|
|
||||||
self.reopen = ->
|
self.reopen = ->
|
||||||
@ -68,13 +71,13 @@ module.exports = {
|
|||||||
self.socket.send JSON.stringify { mtype: type, payload: opts }
|
self.socket.send JSON.stringify { mtype: type, payload: opts }
|
||||||
|
|
||||||
self.get-token = (login, password) ->
|
self.get-token = (login, password) ->
|
||||||
self.send request-type.get-token, JSON.stringify {
|
self.send request-types[\get-token], JSON.stringify {
|
||||||
login: login
|
login: login
|
||||||
password: password
|
password: password
|
||||||
}
|
}
|
||||||
|
|
||||||
self.get-user-by-credentials = (login, password) ->
|
self.get-user-by-credentials = (login, password) ->
|
||||||
self.send request-type.get-user-by-credentials, JSON.stringify {
|
self.send request-types[\get-user-by-credentials], JSON.stringify {
|
||||||
login: login
|
login: login
|
||||||
password: password
|
password: password
|
||||||
}
|
}
|
||||||
@ -85,20 +88,20 @@ module.exports = {
|
|||||||
|
|
||||||
|
|
||||||
self.get-user = (uid) ->
|
self.get-user = (uid) ->
|
||||||
self.send request-type.get-user, JSON.stringify {
|
self.send request-types[\get-user], JSON.stringify {
|
||||||
uid: uid
|
uid: uid
|
||||||
}
|
}
|
||||||
|
|
||||||
# TODO: authd overhaul
|
# TODO: authd overhaul
|
||||||
#self.add-user = (login, password) ->
|
#self.add-user = (login, password) ->
|
||||||
# self.send request-type.add-user, JSON.stringify {
|
# self.send request-types[\add-user], JSON.stringify {
|
||||||
# login: login
|
# login: login
|
||||||
# password: password
|
# password: password
|
||||||
# }
|
# }
|
||||||
|
|
||||||
# TODO: authd overhaul
|
# TODO: authd overhaul
|
||||||
#self.mod-user = (uid) ->
|
#self.mod-user = (uid) ->
|
||||||
# self.send request-type.mod-user, JSON.stringify {
|
# self.send request-types[\mod-user], JSON.stringify {
|
||||||
# uid: uid
|
# uid: uid
|
||||||
# }
|
# }
|
||||||
|
|
||||||
|
@ -85,7 +85,7 @@ model.todod-url =
|
|||||||
(if location.protocol == 'https' then 'wss' else 'ws') +
|
(if location.protocol == 'https' then 'wss' else 'ws') +
|
||||||
'://' + location.hostname + \: +
|
'://' + location.hostname + \: +
|
||||||
model.port +
|
model.port +
|
||||||
"/kanban.JSON"
|
"/todo.JSON"
|
||||||
|
|
||||||
console.log "authd url: " + model.authd-url
|
console.log "authd url: " + model.authd-url
|
||||||
console.log "todod url: " + model.todod-url
|
console.log "todod url: " + model.todod-url
|
||||||
@ -119,21 +119,22 @@ authd-on-websocket-close = (event) ->
|
|||||||
|
|
||||||
# record changes that need to happen on a network event
|
# record changes that need to happen on a network event
|
||||||
model.authd-ws.user-on-socket-error ++= [ authd-on-websocket-error ]
|
model.authd-ws.user-on-socket-error ++= [ authd-on-websocket-error ]
|
||||||
model.authd-ws.user-on-close ++= [ authd-on-websocket-close ]
|
model.authd-ws.user-on-socket-close ++= [ authd-on-websocket-close ]
|
||||||
|
|
||||||
|
|
||||||
# authd message handlers
|
# authd message handlers
|
||||||
|
|
||||||
authd.add-event-listener \token, (message) ->
|
model.authd-ws.add-event-listener \token, (message) ->
|
||||||
model.jwt := message.token
|
model.jwt := message.token
|
||||||
model.current-view := "todo-list"
|
model.current-view := "todo-list"
|
||||||
|
model.todod-ws.list-lists model.jwt
|
||||||
projector.schedule-render!
|
projector.schedule-render!
|
||||||
|
|
||||||
authd.add-event-listener \error, (message) ->
|
model.authd-ws.add-event-listener \error, (message) ->
|
||||||
console.log "authd error", message
|
console.log "authd error", message
|
||||||
projector.schedule-render!
|
projector.schedule-render!
|
||||||
|
|
||||||
authd.add-event-listener \user, (message) ->
|
model.authd-ws.add-event-listener \user, (message) ->
|
||||||
model.users[message.user.uid] := message.user
|
model.users[message.user.uid] := message.user
|
||||||
projector.schedule-render!
|
projector.schedule-render!
|
||||||
|
|
||||||
@ -159,33 +160,29 @@ on-websocket-close = (event) ->
|
|||||||
projector.schedule-render!
|
projector.schedule-render!
|
||||||
|
|
||||||
|
|
||||||
on-websocket-message = (data) ->
|
# TODO
|
||||||
message = JSON.parse data
|
# on-websocket-message = (data) ->
|
||||||
|
# message = JSON.parse data
|
||||||
switch message.type
|
#
|
||||||
when "login"
|
# switch message.type
|
||||||
model.current-view := "todo-list"
|
# when "login"
|
||||||
when "list-projects"
|
# model.current-view := "todo-list"
|
||||||
model.todo-list := message.projects || []
|
# when "list-projects"
|
||||||
when "project"
|
# when "project"
|
||||||
model.projects[message.project.id] = Project.new message.project, model
|
# model.projects[message.project.id] = Project.new message.project, model
|
||||||
when "user"
|
# when "user"
|
||||||
if message.user
|
# if message.user
|
||||||
model.users[message.user.uid] := message.user
|
# model.users[message.user.uid] := message.user
|
||||||
when "login-error"
|
|
||||||
model.login-error = message.error
|
|
||||||
else
|
|
||||||
console.log "RECEIVED UNKNOWN MESSAGE TYPE: #{message.type}"
|
|
||||||
|
|
||||||
projector.schedule-render!
|
|
||||||
|
|
||||||
console.log message
|
|
||||||
|
|
||||||
# record changes that need to happen on a network event
|
# record changes that need to happen on a network event
|
||||||
model.todod-ws.user-on-socket-error ++= [ on-websocket-error ]
|
model.todod-ws.user-on-socket-error ++= [ on-websocket-error ]
|
||||||
model.todod-ws.user-on-close ++= [ on-websocket-close ]
|
model.todod-ws.user-on-socket-close ++= [ on-websocket-close ]
|
||||||
model.todod-ws.user-on-message ++= [ on-websocket-message ]
|
|
||||||
|
|
||||||
|
model.todod-ws.add-event-listener \lists-list, (message) ->
|
||||||
|
console.log message
|
||||||
|
model.todo-list := message.lists
|
||||||
|
|
||||||
|
projector.schedule-render!
|
||||||
|
|
||||||
render-navbar = ->
|
render-navbar = ->
|
||||||
h \div.navbar [
|
h \div.navbar [
|
||||||
@ -215,7 +212,7 @@ render-todo-list = ->
|
|||||||
model.viewed-project := project.id
|
model.viewed-project := project.id
|
||||||
model.todod-ws.get-project project.id
|
model.todod-ws.get-project project.id
|
||||||
} [
|
} [
|
||||||
bulma.title 4 project.name
|
bulma.title 4 project.title
|
||||||
]
|
]
|
||||||
|
|
||||||
render-new-project-button = ->
|
render-new-project-button = ->
|
||||||
|
@ -8,29 +8,66 @@ module.exports = {
|
|||||||
create-socket: (socket-url) ->
|
create-socket: (socket-url) ->
|
||||||
self = {}
|
self = {}
|
||||||
|
|
||||||
|
request-types = {
|
||||||
|
"list-lists": 0
|
||||||
|
"get-list": 1
|
||||||
|
"add-list": 2
|
||||||
|
"edit-list": 3
|
||||||
|
"remove-list": 4
|
||||||
|
"get-tasks": 5
|
||||||
|
"get-task": 6
|
||||||
|
"add-task": 7
|
||||||
|
"remove-task": 8
|
||||||
|
"edit-task": 9
|
||||||
|
}
|
||||||
|
|
||||||
|
response-types = {
|
||||||
|
"ok": 0
|
||||||
|
"error": 1
|
||||||
|
"lists-list": 2
|
||||||
|
"new-list": 3
|
||||||
|
"list-removed": 4
|
||||||
|
"list-updated": 5
|
||||||
|
"tasks": 6
|
||||||
|
"task": 7
|
||||||
|
"task-created": 8
|
||||||
|
"task-removed": 9
|
||||||
|
"task-updated": 10
|
||||||
|
}
|
||||||
|
|
||||||
# users can record functions to run on events
|
# users can record functions to run on events
|
||||||
self.user-on-error = []
|
self.user-on-socket-error = []
|
||||||
self.user-on-close = []
|
self.user-on-socket-close = []
|
||||||
self.user-on-message = []
|
|
||||||
|
self.callbacks = {}
|
||||||
|
for key, value of response-types
|
||||||
|
self.callbacks[value] = []
|
||||||
|
|
||||||
|
self.add-event-listener = (type, callback) ->
|
||||||
|
console.log "add event listener", type, callback, response-types[type]
|
||||||
|
type = response-types[type]
|
||||||
|
|
||||||
|
self.callbacks[type] ++= [callback]
|
||||||
|
|
||||||
self.open-socket = ->
|
self.open-socket = ->
|
||||||
console.log "Opening socket to #{socket-url}"
|
console.log "Opening socket to #{socket-url}"
|
||||||
self.socket := new WebSocket socket-url
|
self.socket := new WebSocket socket-url
|
||||||
|
|
||||||
self.socket.onerror = (event) ->
|
self.socket.onerror = (event) ->
|
||||||
for f in self.user-on-error
|
for f in self.user-on-socket-error
|
||||||
f event
|
f event
|
||||||
self.socket.close!
|
self.socket.close!
|
||||||
|
|
||||||
self.socket.onclose = (event) ->
|
self.socket.onclose = (event) ->
|
||||||
for f in self.user-on-close
|
for f in self.user-on-socket-close
|
||||||
f event
|
f event
|
||||||
|
|
||||||
self.socket.onmessage = (event) ->
|
self.socket.onmessage = (event) ->
|
||||||
data = JSON.parse(event.data).payload
|
message = JSON.parse(event.data)
|
||||||
|
console.log "todod message received: ", message
|
||||||
|
|
||||||
for f in self.user-on-message
|
for f in self.callbacks[message.mtype]
|
||||||
f data
|
f JSON.parse(message.payload)
|
||||||
|
|
||||||
self.reopen = ->
|
self.reopen = ->
|
||||||
self.socket.close!
|
self.socket.close!
|
||||||
@ -38,109 +75,95 @@ module.exports = {
|
|||||||
|
|
||||||
self.open-socket!
|
self.open-socket!
|
||||||
|
|
||||||
self.send = (opts) ->
|
self.send = (type, opts) ->
|
||||||
console.log JSON.stringify {
|
console.log JSON.stringify { mtype: type, payload: opts }
|
||||||
mtype: 0,
|
self.socket.send JSON.stringify { mtype: type, payload: opts }
|
||||||
payload: opts
|
|
||||||
|
|
||||||
|
self.list-lists = (token) ->
|
||||||
|
self.send request-types[\list-lists], JSON.stringify {
|
||||||
|
token: token
|
||||||
}
|
}
|
||||||
|
|
||||||
self.socket.send JSON.stringify {
|
# self.get-user = (uid) ->
|
||||||
mtype: 0,
|
# self.send JSON.stringify {
|
||||||
payload: opts
|
# type: "get-user"
|
||||||
}
|
# uid: uid
|
||||||
|
# }
|
||||||
|
|
||||||
self.get-project = (project-id) ->
|
# self.new-project = (name) ->
|
||||||
self.send JSON.stringify {
|
# self.send JSON.stringify {
|
||||||
type: "project",
|
# type: "new-project"
|
||||||
project: project-id
|
# name: name
|
||||||
}
|
# }
|
||||||
|
|
||||||
self.login = (login, password) ->
|
# self.edit-task = (project-id, task-id, options) ->
|
||||||
self.send JSON.stringify {
|
# payload = {
|
||||||
type: "login",
|
# type: "edit-task"
|
||||||
login: login
|
# project: project-id
|
||||||
password: password
|
# task: task-id
|
||||||
}
|
# }
|
||||||
|
|
||||||
self.get-user = (uid) ->
|
# for key, value of options
|
||||||
self.send JSON.stringify {
|
# payload[key] = value
|
||||||
type: "get-user"
|
|
||||||
uid: uid
|
|
||||||
}
|
|
||||||
|
|
||||||
self.new-project = (name) ->
|
# self.send JSON.stringify payload
|
||||||
self.send JSON.stringify {
|
|
||||||
type: "new-project"
|
|
||||||
name: name
|
|
||||||
}
|
|
||||||
|
|
||||||
self.edit-task = (project-id, task-id, options) ->
|
# self.delete-task = (project-id, task-id) ->
|
||||||
payload = {
|
# self.send JSON.stringify {
|
||||||
type: "edit-task"
|
# type: "delete-task"
|
||||||
project: project-id
|
# project: project-id
|
||||||
task: task-id
|
# task: task-id
|
||||||
}
|
# }
|
||||||
|
|
||||||
for key, value of options
|
# self.edit-column = (project-id, column-id, options) ->
|
||||||
payload[key] = value
|
# payload = {
|
||||||
|
# type: "edit-column"
|
||||||
|
# project: project-id
|
||||||
|
# column: column-id
|
||||||
|
# }
|
||||||
|
|
||||||
self.send JSON.stringify payload
|
# for key, value of options
|
||||||
|
# payload[key] = value
|
||||||
|
|
||||||
self.delete-task = (project-id, task-id) ->
|
# self.send JSON.stringify payload
|
||||||
self.send JSON.stringify {
|
|
||||||
type: "delete-task"
|
|
||||||
project: project-id
|
|
||||||
task: task-id
|
|
||||||
}
|
|
||||||
|
|
||||||
self.edit-column = (project-id, column-id, options) ->
|
# self.delete-column = (project-id, column-id) ->
|
||||||
payload = {
|
# self.send JSON.stringify {
|
||||||
type: "edit-column"
|
# type: "delete-column"
|
||||||
project: project-id
|
# project: project-id
|
||||||
column: column-id
|
# column: column-id
|
||||||
}
|
# }
|
||||||
|
|
||||||
for key, value of options
|
# self.new-column = (project-id, name) ->
|
||||||
payload[key] = value
|
# self.send JSON.stringify {
|
||||||
|
# type: "new-column"
|
||||||
|
# project: project-id
|
||||||
|
# name: name
|
||||||
|
# }
|
||||||
|
|
||||||
self.send JSON.stringify payload
|
# self.new-task = (project-id, column-id, options) ->
|
||||||
|
# payload = {
|
||||||
|
# type: "new-task"
|
||||||
|
# project: project-id
|
||||||
|
# column: column-id
|
||||||
|
# }
|
||||||
|
|
||||||
self.delete-column = (project-id, column-id) ->
|
# for key, value of options
|
||||||
self.send JSON.stringify {
|
# payload[key] = value
|
||||||
type: "delete-column"
|
|
||||||
project: project-id
|
|
||||||
column: column-id
|
|
||||||
}
|
|
||||||
|
|
||||||
self.new-column = (project-id, name) ->
|
# self.send JSON.stringify payload
|
||||||
self.send JSON.stringify {
|
|
||||||
type: "new-column"
|
|
||||||
project: project-id
|
|
||||||
name: name
|
|
||||||
}
|
|
||||||
|
|
||||||
self.new-task = (project-id, column-id, options) ->
|
# self.edit-project = (project-id, options) ->
|
||||||
payload = {
|
# payload = {
|
||||||
type: "new-task"
|
# type: "edit-project"
|
||||||
project: project-id
|
# project: project-id
|
||||||
column: column-id
|
# }
|
||||||
}
|
|
||||||
|
|
||||||
for key, value of options
|
# for key, value of options
|
||||||
payload[key] = value
|
# payload[key] = value
|
||||||
|
|
||||||
self.send JSON.stringify payload
|
# self.send JSON.stringify payload
|
||||||
|
|
||||||
self.edit-project = (project-id, options) ->
|
|
||||||
payload = {
|
|
||||||
type: "edit-project"
|
|
||||||
project: project-id
|
|
||||||
}
|
|
||||||
|
|
||||||
for key, value of options
|
|
||||||
payload[key] = value
|
|
||||||
|
|
||||||
self.send JSON.stringify payload
|
|
||||||
|
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user