todo-webclient/client/project.ls

224 lines
5.1 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-12-20 01:34:41 +01:00
ColumnEditModal = require './column-edit-modal.ls'
{icon} = require './font-awesome.ls'
deep-copy = (object) ->
JSON.parse JSON.stringify object
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
# configured column, but inexistant (maybe removed since)
inexistant-column = (task, columns) ->
2019-12-24 23:08:57 +01:00
! columns.find((.id == task.extra_properties.column))
2019-12-08 02:17:55 +01:00
orphan-tasks = (tasks, columns) ->
2019-12-24 23:08:57 +01:00
tasks.filter (task) ->
(! task.extra_properties?.column) || inexistant-column task, columns
2019-12-08 02:17:55 +01:00
2019-12-22 19:48:21 +01:00
Project = (self, todod-ws, users-cache) ->
console.log "CREATING PROJECT", users-cache
2019-12-05 02:28:17 +01:00
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-24 22:25:01 +01:00
self.selected-tasks = []
2019-12-12 21:49:15 +01:00
2019-12-05 02:28:17 +01:00
modal = void
2019-11-22 16:52:50 +01:00
2019-12-24 22:25:01 +01:00
self.remove-column = (column) ->
extra_properties = deep-copy(self.extra_properties)
extra_properties.columns = extra_properties.columns.filter((.id != column.id))
todod-ws.edit-list self.id, {
extra_properties: extra_properties
}
2019-12-24 23:08:57 +01:00
self.edit-column = (column) ->
extra_properties = deep-copy self.extra_properties
extra_properties.columns = extra_properties.columns.map (old-column) ->
if old-column.id == column.id
column
else
old-column
todod-ws.edit-list self.id, {
extra_properties: extra_properties
}
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-20 01:34:41 +01:00
h \p.title.is-4 [
column.title
2019-12-24 22:25:01 +01:00
h \div.is-pulled-right.visible-on-hover [
if tasks-to-display.length == 0
h \a.icon.has-text-danger {
key: \remove
onclick: ->
modal := Modal {
+visible
content: [ "Are you sure you want to remove this column?" ]
on-validation: ->
modal.visible := false
self.remove-column column
}
} [
icon \skull-crossbones
]
h \a.icon.has-text-grey {
key: \edit
onclick: ->
2019-12-24 22:25:01 +01:00
modal := ColumnEditModal self, column, {
on-validation: (column) ->
console.log "column update:", column
modal.visible := false
2019-12-24 23:08:57 +01:00
self.edit-column column
}
} [
2019-12-24 22:25:01 +01:00
icon \cog
]
2019-12-20 01:34:41 +01:00
]
]
2019-12-12 21:49:15 +01:00
tasks-to-display.map (task) ->
task.render {
2019-12-24 22:25:01 +01:00
is-selected: self.selected-tasks.includes task.id
2019-12-12 21:49:15 +01:00
onclick: ->
2019-12-24 22:25:01 +01:00
if self.selected-tasks.includes task.id
self.selected-tasks :=
self.selected-tasks.filter (!= task.id)
2019-12-12 21:49:15 +01:00
else
2019-12-24 22:25:01 +01:00
self.selected-tasks.push task.id
2019-12-12 21:49:15 +01:00
}
h \div.button.is-outlined.is-success.visible-on-hover.is-large.is-fullwidth {
onclick: ->
modal := TaskCreationModal self, self.todod-ws, {
extra_properties: { column: column.id }
}, users-cache
} [
"+"
]
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-20 01:34:41 +01:00
h \a.navbar-item.has-text-success {
2019-12-12 01:25:36 +01:00
key: "navbar-new-task"
2019-12-20 01:34:41 +01:00
onclick: ->
2019-12-23 23:56:19 +01:00
modal := TaskCreationModal self, self.todod-ws, {}, users-cache
2019-12-12 01:25:36 +01:00
} [
2019-12-20 01:34:41 +01:00
h \span [ "New task" ]
icon \plus
2019-12-06 21:07:39 +01:00
]
2019-12-20 01:34:41 +01:00
h \a.navbar-item {
2019-12-12 01:25:36 +01:00
key: "navbar-edit-project"
2019-12-20 01:34:41 +01:00
onclick: ->
modal := ProjectCreationModal {
project: self
on-validation: (project) ->
console.log "Requesting edit for", project
self.todod-ws.edit-list project.id, project
users-cache: users-cache
2019-12-20 01:34:41 +01:00
}
2019-12-12 01:25:36 +01:00
} [
2019-12-20 01:34:41 +01:00
icon \cog
# "Edit this project"
2019-12-07 00:44:02 +01:00
]
2019-12-05 04:47:29 +01:00
2019-12-20 01:34:41 +01:00
h \a.navbar-item.has-text-danger {
2019-12-12 01:25:36 +01:00
key: "navbar-delete-project"
2019-12-20 01:34:41 +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
}
2019-12-12 01:25:36 +01:00
} [
2019-12-20 01:34:41 +01:00
icon \skull-crossbones
# "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 column in columns
is-last = column == columns[columns.length-1]
2019-12-12 21:49:15 +01:00
if is-last
2019-12-12 21:49:15 +01:00
self.render-column column, is-last
else
[
self.render-column column, is-last
h \div.is-divider-vertical {key: column.id + ".divider"}
]
h \div.is-divider-vertical {
key: "final.divider"
}
h \div.column.is-narrow [
h \div.button.is-outlined.is-large {
onclick: ->
modal := ColumnEditModal self, void, {
on-validation: (column) ->
console.log "column creation:", column
modal.visible := false
extra_properties = deep-copy(self.extra_properties)
extra_properties.columns.push column
todod-ws.edit-list self.id, {
extra_properties: extra_properties
}
}
} [
"+"
2019-12-12 21:49:15 +01:00
]
]
]
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