123 lines
2.8 KiB
Plaintext
123 lines
2.8 KiB
Plaintext
|
||
h = require 'maquette' .h
|
||
bulma = require "./bulma.ls"
|
||
Task = require "./task.ls"
|
||
Modal = require './modal.ls'
|
||
TaskCreationModal = require './task-creation-modal.ls'
|
||
ProjectCreationModal = require './project-creation-modal.ls'
|
||
|
||
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
|
||
|
||
|
||
Project = (self, todod-ws, users) ->
|
||
self.todod-ws = todod-ws
|
||
self.tasks = []
|
||
self.users = users || []
|
||
|
||
self.selected-task-id = void
|
||
|
||
modal = void
|
||
|
||
self.render-column = (column, first) ->
|
||
|
||
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
|
||
|
||
#
|
||
# COLUMNS
|
||
#
|
||
|
||
h \div.column.cards-list {
|
||
key: column.id
|
||
} [
|
||
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
|
||
}
|
||
]
|
||
|
||
self.inner-nav-render = ->
|
||
h \div.navbar-item [ h \a.subtitle.is-3 [ self.title ] ]
|
||
|
||
self.right-nav-render = ->
|
||
[
|
||
h \div.navbar-item {
|
||
key: "navbar-new-task"
|
||
} [
|
||
h \div.button.is-success.is-outlined.is-medium {
|
||
onclick: ->
|
||
modal := TaskCreationModal self, self.todod-ws, void, self.users
|
||
} [ "New task" ]
|
||
]
|
||
|
||
h \div.navbar-item {
|
||
key: "navbar-edit-project"
|
||
} [
|
||
h \div.button.is-dark.is-outlined.is-medium {
|
||
onclick: ->
|
||
modal := ProjectCreationModal self, self.todod-ws, self.users
|
||
} [ "Edit this project" ]
|
||
]
|
||
|
||
h \div.navbar-item {
|
||
key: "navbar-delete-project"
|
||
} [
|
||
h \div.button.is-danger.is-outlined.is-medium {
|
||
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" ]
|
||
]
|
||
]
|
||
|
||
self.render = ->
|
||
|
||
h \div.project {} [
|
||
|
||
h \div.columns [
|
||
if columns = self.extra_properties.columns
|
||
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
|
||
]
|
||
]
|
||
|
||
if modal
|
||
modal.render!
|
||
]
|
||
|
||
self
|
||
|
||
module.exports = Project
|