todo-webclient/client/project.ls

100 lines
2.3 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-12-06 21:07:39 +01:00
TaskCreationModal = require './task-creation-modal.ls'
ProjectCreationModal = require "./project-creation-modal.ls"
2019-11-22 16:52:50 +01:00
2019-12-08 02:17:55 +01:00
is-right-column = (task, column-id) ->
task.extra_properties && task.extra_properties.column && task.extra_properties.column == column-id
has-column = (task) ->
task.extra_properties && task.extra_properties.column
# configured column, but inexistant (maybe removed since)
inexistant-column = (task, columns) ->
columns.filter((.id == task.extra_properties.column)).length == 0
orphan-tasks = (tasks, columns) ->
tasks.filter (task) -> (! has-column) || inexistant-column task, columns
2019-12-05 02:28:17 +01:00
Project = (self, todod-ws) ->
self.todod-ws = todod-ws
2019-12-06 01:56:32 +01:00
self.tasks = []
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
2019-12-05 04:47:29 +01:00
self.render-column = (column, first) ->
2019-12-07 00:44:02 +01:00
2019-12-08 02:17:55 +01:00
tasks-to-display = self.tasks.filter (task) -> is-right-column task, column.id
if first
tasks-to-display ++= orphan-tasks self.tasks, self.extra_properties.columns
h \div.column {
key: column.id
} [
2019-12-06 05:04:55 +01:00
h \div.card { key: self.id } [
h \div.cart-head [
h \p.title.is-4 [ column.title ]
]
h \div.card-content { key: self.id } [
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-07 00:44:02 +01:00
self.inner-nav-render = ->
h \div.navbar-item [ h \a.subtitle.is-3 [ self.title ] ]
2019-11-22 16:52:50 +01:00
2019-12-07 00:44:02 +01:00
self.right-nav-render = ->
[
h \div.navbar-item [
2019-12-08 15:23:46 +01:00
h \div.button.is-success.is-outlined {
2019-12-07 00:44:02 +01:00
onclick: ->
2019-12-08 15:23:46 +01:00
modal := TaskCreationModal self, self.todod-ws
} [ "New task" ]
2019-12-06 21:07:39 +01:00
]
2019-12-07 00:44:02 +01:00
h \div.navbar-item [
2019-12-08 15:23:46 +01:00
h \div.button.is-outlined {
2019-12-07 00:44:02 +01:00
onclick: ->
2019-12-08 15:23:46 +01:00
modal := ProjectCreationModal self, self.todod-ws
} [ "Edit this project" ]
2019-12-07 00:44:02 +01:00
]
2019-12-05 04:47:29 +01:00
2019-12-07 00:44:02 +01:00
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
}
} [ "Delete this project" ]
2019-12-05 04:47:29 +01:00
]
2019-12-06 21:07:39 +01:00
]
self.render = ->
h \div.project {} [
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