todo-webclient/client/project.ls

123 lines
2.8 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'
2019-12-10 05:59:52 +01:00
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-10 05:59:52 +01:00
Project = (self, todod-ws, users) ->
2019-12-05 02:28:17 +01:00
self.todod-ws = todod-ws
2019-12-06 01:56:32 +01:00
self.tasks = []
2019-12-10 05:59:52 +01:00
self.users = users || []
2019-11-22 16:52:50 +01:00
2019-12-12 21:49:15 +01:00
self.selected-task-id = void
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
2019-12-12 01:25:36 +01:00
#
# COLUMNS
#
2019-12-12 21:49:15 +01:00
h \div.column.cards-list {
key: column.id
} [
2019-12-12 21:49:15 +01:00
h \p.title.is-4 [ column.title ]
tasks-to-display.map (task) ->
task.render {
is-selected: (task.id == self.selected-task-id)
onclick: ->
if self.selected-task-id == task.id
self.selected-task-id := void
else
self.selected-task-id := task.id
}
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 = ->
[
2019-12-12 01:25:36 +01:00
h \div.navbar-item {
key: "navbar-new-task"
} [
2019-12-12 21:49:15 +01:00
h \div.button.is-success.is-outlined.is-medium {
2019-12-07 00:44:02 +01:00
onclick: ->
2019-12-12 01:25:36 +01:00
modal := TaskCreationModal self, self.todod-ws, void, self.users
2019-12-08 15:23:46 +01:00
} [ "New task" ]
2019-12-06 21:07:39 +01:00
]
2019-12-12 01:25:36 +01:00
h \div.navbar-item {
key: "navbar-edit-project"
} [
2019-12-12 21:49:15 +01:00
h \div.button.is-dark.is-outlined.is-medium {
2019-12-07 00:44:02 +01:00
onclick: ->
2019-12-10 05:59:52 +01:00
modal := ProjectCreationModal self, self.todod-ws, self.users
2019-12-08 15:23:46 +01:00
} [ "Edit this project" ]
2019-12-07 00:44:02 +01:00
]
2019-12-05 04:47:29 +01:00
2019-12-12 01:25:36 +01:00
h \div.navbar-item {
key: "navbar-delete-project"
} [
2019-12-12 21:49:15 +01:00
h \div.button.is-danger.is-outlined.is-medium {
2019-12-07 00:44:02 +01:00
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
2019-12-12 21:49:15 +01:00
for column in columns
is-last = column == columns[columns.length-1]
if is-last
self.render-column column, is-last
else
[
self.render-column column, is-last
h \div.is-divider-vertical
]
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