todo-webclient/client/project.ls

86 lines
2.0 KiB
Plaintext
Raw Normal View History

2019-11-22 16:52:50 +01:00
h = require 'maquette' .h
bulma = require "./bulma.ls"
Task = require "./task.ls"
2019-12-05 02:28:17 +01:00
Modal = require './modal.ls'
2019-11-22 16:52:50 +01:00
2019-12-05 02:28:17 +01:00
Project = (self, todod-ws) ->
self.todod-ws = todod-ws
self.tasks-objects = self.tasks.map (e) -> Task e, self, {}
2019-11-22 16:52:50 +01:00
2019-12-05 02:28:17 +01:00
modal = void
2019-11-22 16:52:50 +01:00
self.tasks-updated = ->
self.tasks-objects = self.tasks.map (e) -> Task e, self, {}
2019-11-22 16:52:50 +01:00
2019-12-05 04:47:29 +01:00
self.render-column = (column, first) ->
# FIXME: display unregistred tasks in the first column
tasks-to-display = self.tasks-objects.filter (task) ->
task.extra_properties && task.extra_properties.column && task.extra_properties.column == column.id || ((! task.extra_properties || ! task.extra_properties.column) && first)
console.log "TASKS", self.tasks
console.log "TASKS-OBJECTS", self.tasks-objects
console.log "TASKS TO DISPLAY", tasks-to-display
2019-12-05 04:47:29 +01:00
h \div.column [
bulma.title 4 column.title
2019-12-06 00:13:59 +01:00
for task in tasks-to-display
task.render!
2019-12-05 04:47:29 +01:00
]
2019-11-22 16:52:50 +01:00
2019-12-05 02:28:17 +01:00
self.render = ->
2019-11-22 16:52:50 +01:00
2019-12-05 02:28:17 +01:00
# console.log "Project to render: ", self
h \div.project {} [
2019-12-05 04:47:29 +01:00
h \div.navbar [
h \div.navbar-brand [
h \div.navbar-item [
self.title
]
]
h \div.navbar-end [
h \div.navbar-item [
h \div.button.is-success.is-outlined {
onclick: ->
modal := Modal {
+visible
content:
h \p [ "New task lol?" ]
on-validation: ->
self.todod-ws.add-task self.id, "Hello There", {}
}
} [ "+" ]
]
h \div.navbar-item [
h \div.button.is-danger.is-outlined {
onclick: ->
modal := Modal {
+visible
content:
h \p [ "Are you sure you want to remove board #{self.title}?" ]
on-validation: ->
self.todod-ws.remove-list self.id
}
} [ "X" ]
]
]
]
2019-12-05 02:28:17 +01:00
h \div.columns [
2019-12-05 04:47:29 +01:00
if columns = self.extra_properties.columns
for dom in columns.map((column, index) -> self.render-column(column, index == 0))
2019-12-05 02:28:17 +01:00
dom
2019-11-22 16:52:50 +01:00
]
2019-12-05 02:28:17 +01:00
if modal
modal.render!
]
2019-12-05 02:28:17 +01:00
self
2019-12-05 02:28:17 +01:00
module.exports = Project