Grooming.

This commit is contained in:
Luka Vandervelden 2019-07-09 03:26:08 +02:00
parent 8983e000c0
commit f70f8a17f3

View File

@ -33,19 +33,13 @@ Task = (self, project) ->
if typeof(author) != "object" and author != "request sent" if typeof(author) != "object" and author != "request sent"
model.users[self.author] = "request sent" model.users[self.author] = "request sent"
# FIXME: This should go directly to authd. # FIXME: This should go directly to authd.
socket.send JSON.stringify { socket.get-user self.author
type: "get-user"
uid: self.author
}
assigned_to = model.users[self.assigned_to] assigned_to = model.users[self.assigned_to]
if self.assigned_to and typeof(assigned_to) != "object" and assigned_to != "request sent" if self.assigned_to and typeof(assigned_to) != "object" and assigned_to != "request sent"
model.users[self.assigned_to] = "request sent" model.users[self.assigned_to] = "request sent"
# FIXME: This should go directly to authd. # FIXME: This should go directly to authd.
socket.send JSON.stringify { socket.get-user self.assigned_to
type: "get-user"
uid: self.assigned_to
}
is-selected = model.selected == self.id is-selected = model.selected == self.id
@ -74,10 +68,7 @@ Task = (self, project) ->
value: self.title value: self.title
onchange: (e) -> onchange: (e) ->
model.editing := undefined model.editing := undefined
socket.send JSON.stringify { socket.edit-task project.id, self.id, {
type: "edit-task"
project: project.id
task: self.id
title: e.target.value title: e.target.value
} }
} [ self.title ] } [ self.title ]
@ -137,10 +128,7 @@ Task = (self, project) ->
} }
h \div.button.is-fullwidth { h \div.button.is-fullwidth {
onclick: -> onclick: ->
socket.send JSON.stringify { socket.edit-task project.id, self.id, {
type: "edit-task"
project: project.id
task: self.id
description: model.editing-data description: model.editing-data
} }
model.editing-data := undefined model.editing-data := undefined
@ -168,10 +156,7 @@ Task = (self, project) ->
h \input.input { h \input.input {
onchange: (e) -> onchange: (e) ->
model.editing := undefined model.editing := undefined
socket.send JSON.stringify { socket.edit-task project.id, self.id, {
type: "edit-task"
project: project.id
task: self.id
assigned_to: Number e.target.value assigned_to: Number e.target.value
} }
} }
@ -193,10 +178,7 @@ Task = (self, project) ->
h \input.input { h \input.input {
onchange: (e) -> onchange: (e) ->
model.editing := undefined model.editing := undefined
socket.send JSON.stringify { socket.edit-task project.id, self.id, {
type: "edit-task"
project: project.id
task: self.id
color: e.target.value color: e.target.value
} }
} }
@ -214,10 +196,7 @@ Task = (self, project) ->
h \a.card-footer-item { h \a.card-footer-item {
key: "⇐" key: "⇐"
onclick: -> onclick: ->
socket.send JSON.stringify { socket.edit-task project.id, self.id, {
type: "edit-task"
project: project.id
task: self.id
column: get-previous project.columns.map((.id)), self.column column: get-previous project.columns.map((.id)), self.column
} }
} [ "⇐" ] } [ "⇐" ]
@ -228,21 +207,14 @@ Task = (self, project) ->
} [ } [
h \div.button.is-danger { h \div.button.is-danger {
onclick: -> onclick: ->
socket.send JSON.stringify { socket.delete-task project.id, self.id
type: "delete-task"
project: project.id
task: self.id
}
} [ "Delete! For real!" ] } [ "Delete! For real!" ]
] ]
h \a.card-footer-item { h \a.card-footer-item {
key: "⇒" key: "⇒"
onclick: -> onclick: ->
socket.send JSON.stringify { socket.edit-task project.id, self.id, {
type: "edit-task"
project: project.id
task: self.id
column: get-next project.columns.map((.id)), self.column column: get-next project.columns.map((.id)), self.column
} }
} [ "⇒" ] } [ "⇒" ]
@ -270,10 +242,7 @@ Project = (self) ->
console.log "onchange??" console.log "onchange??"
model.editing := undefined model.editing := undefined
socket.send JSON.stringify { socket.edit-column self.id, column.id, {
type: "edit-column"
project: self.id
column: column.id
name: e.target.value name: e.target.value
} }
} }
@ -306,11 +275,7 @@ Project = (self) ->
h \div.card-content [ h \div.card-content [
h \div.button.is-fullwidth.is-danger { h \div.button.is-fullwidth.is-danger {
onclick: -> onclick: ->
socket.send JSON.stringify { socket.delete-column self.id, column.id
type: "delete-column"
project: self.id
column: column.id
}
} [ "Delete me!"] } [ "Delete me!"]
] ]
] ]
@ -322,10 +287,7 @@ Project = (self) ->
h \div.button.is-fullwidth { h \div.button.is-fullwidth {
onclick: -> onclick: ->
socket.send JSON.stringify { socket.new-task self.id, column.id, {
type: "new-task"
project: self.id
column: column.id
title: "General Kenobi…" title: "General Kenobi…"
description: "" description: ""
} }
@ -350,9 +312,7 @@ Project = (self) ->
h \input.input { h \input.input {
onchange: (e) -> onchange: (e) ->
model.editing := undefined model.editing := undefined
socket.send JSON.stringify { socket.edit-project self.id, {
type: "edit-project"
project: self.id
name: e.target.value name: e.target.value
} }
value: self.name value: self.name
@ -371,11 +331,7 @@ Project = (self) ->
} [ } [
h \div.button.is-fullwidth { h \div.button.is-fullwidth {
onclick: -> onclick: ->
socket.send JSON.stringify { socket.new-column self.id, "Hello, there!"
type: "new-column"
project: self.id
name: "Hello, there!"
}
} [ "New Column" ] } [ "New Column" ]
] ]
] ]
@ -398,21 +354,131 @@ socket-url = protocol + '://' + location.hostname + port + "/socket"
console.log socket-url console.log socket-url
socket = new WebSocket socket-url KanbanSocket = (socket-url) ->
self = {}
socket.onopen = (event) -> self.open-socket = ->
# Nothing to do here ATM. self.socket := new WebSocket socket-url
socket.onerror = (event) -> self.socket.onerror = (event) ->
model.state = "websocket-error" console.log "WebSocket error.", event
model.state := "websocket-error"
self.socket.close!
projector.schedule-render! projector.schedule-render!
socket.onclose = (event) -> self.socket.onclose = (event) ->
model.state = "websocket-error" # Exporting the error in case the UI is able to deal with it.
model.websocket-error = event.reason model.previous-state := model.state
model.state := "websocket-error"
model.websocket-error := event.reason
projector.schedule-render! projector.schedule-render!
socket.onmessage = (event) -> self.socket.onmessage = (event) ->
self.on-message event
self.open-socket!
self.send = (opts) ->
self.socket.send opts
self.get-project = (project-id) ->
self.socket.send JSON.stringify {
type: "project",
project: project-id
}
self.login = (login, password) ->
self.socket.send JSON.stringify {
type: "login",
login: login
password: password
}
self.get-user = (uid) ->
self.socket.send JSON.stringify {
type: "get-user"
uid: uid
}
self.new-project = (name) ->
self.socket.send JSON.stringify {
type: "new-project"
name: name
}
self.edit-task = (project-id, task-id, options) ->
payload = {
type: "edit-task"
project: project-id
task: task-id
}
for key, value of options
payload[key] = value
self.socket.send JSON.stringify payload
self.delete-task = (project-id, task-id) ->
self.socket.send JSON.stringify {
type: "delete-task"
project: project-id
task: task-id
}
self.edit-column = (project-id, column-id, options) ->
payload = {
type: "edit-column"
project: project-id
column: column-id
}
for key, value of options
payload[key] = value
self.socket.send JSON.stringify payload
self.delete-column = (project-id, column-id) ->
self.socket.send JSON.stringify {
type: "delete-column"
project: project-id
column: column-id
}
self.new-column = (project-id, name) ->
self.socket.send JSON.stringify {
type: "new-column"
project: project-id
name: name
}
self.new-task = (project-id, column-id, options) ->
payload = {
type: "new-task"
project: project-id
column: column-id
}
for key, value of options
payload[key] = value
self.socket.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.socket.send JSON.stringify payload
self
socket = KanbanSocket socket-url
socket.on-message = (event) ->
console.log event.data console.log event.data
message = JSON.parse event.data message = JSON.parse event.data
@ -466,11 +532,7 @@ renderer = ->
onclick: (e) -> onclick: (e) ->
e.prevent-default! e.prevent-default!
socket.send JSON.stringify { socket.login model.login, model.password
type: "login",
login: model.login
password: model.password
}
} [ "Letsu go!" ] } [ "Letsu go!" ]
] ]
] ]
@ -498,20 +560,14 @@ renderer = ->
onclick: -> onclick: ->
model.current-view := "project" model.current-view := "project"
model.viewed-project := project.id model.viewed-project := project.id
socket.send JSON.stringify { socket.get-project project.id
type: "project",
project: project.id
}
} [ } [
bulma.title 3 project.name bulma.title 3 project.name
] ]
h \div.button.is-primary.is-large.is-fullwidth { h \div.button.is-primary.is-large.is-fullwidth {
onclick: -> onclick: ->
socket.send JSON.stringify { socket.new-project "Hello, there!"
type: "new-project"
name: "Hello, there!"
}
} [ "New project! (random atm)" ] } [ "New project! (random atm)" ]
] ]
else else