todo-webclient/client/task.ls

95 lines
2.2 KiB
Plaintext
Raw Normal View History

2019-11-22 16:52:50 +01:00
h = require 'maquette' .h
nmd = require "nano-markdown"
2019-12-06 04:10:00 +01:00
TaskCreationModal = require './task-creation-modal.ls'
2019-12-06 04:07:19 +01:00
TaskRemovalModal = require './task-removal-modal.ls'
2019-11-22 16:52:50 +01:00
2019-12-25 01:27:20 +01:00
maquette-css-transitions = require "maquette-css-transitions"
{create-exit-css-transition, create-enter-css-transition} = maquette-css-transitions
2019-12-24 22:25:01 +01:00
{media, title} = require "./bulma.ls"
2019-12-20 01:34:41 +01:00
{icon} = require "./font-awesome.ls"
2019-12-22 19:48:21 +01:00
Task = (self, project, todod-ws, users-cache) ->
2019-12-06 01:56:32 +01:00
modal = void
self.render-login = (uid) ->
2019-12-22 19:48:21 +01:00
h \p [
if user = users-cache.get-user uid
2019-12-25 01:43:11 +01:00
[
if avatar = user.profile?.avatar
h \figure.image.is-32x32.is-pulled-left [
h \img.is-rounded {
src=avatar
alt=""
}
]
'@' + user.login
]
2019-12-22 19:48:21 +01:00
else
'@' + uid.to-string!
]
2019-12-12 21:49:15 +01:00
self.render = (args) ->
args or= {}
2019-12-09 03:31:11 +01:00
background-color = "grey"
if self.extra_properties && self.extra_properties.background-color
background-color = self.extra_properties.background-color
2019-12-09 03:09:06 +01:00
2019-12-12 21:49:15 +01:00
h "div.card.is-#{background-color}" {
classes: {
"is-selected": args.is-selected
}
2019-12-09 03:09:06 +01:00
key: self.id
2019-12-12 21:49:15 +01:00
onclick: (e) ->
if args.onclick
args.onclick(e)
2019-12-09 03:09:06 +01:00
} [
2019-12-06 04:07:19 +01:00
h \div.card-content [
2019-12-24 22:25:01 +01:00
media {
content: [
title 5 self.title
if uid = self.assigned_to
self.render-login uid
2019-12-06 04:07:19 +01:00
]
2019-12-24 22:25:01 +01:00
right: [
h \a.has-text-grey.is-pulled-right {
onclick: ->
modal := TaskCreationModal project, todod-ws, self, users-cache
} [
icon \cog.visible-on-hover
]
h \br
h \a.has-text-danger.is-pulled-right {
onclick: ->
modal := TaskRemovalModal project.id, todod-ws, self
} [
icon \skull-crossbones.visible-on-hover
]
]
}
2019-12-09 03:31:11 +01:00
2019-12-24 22:25:01 +01:00
if args.is-selected && self.description.length > 0
2019-12-12 21:49:15 +01:00
h \div.content {
key: "task-description-#{self.id}"
2019-12-25 01:27:20 +01:00
enter-animation: create-enter-css-transition \fade-in
exit-animation: create-exit-css-transition \fade-out
} [
# FIXME: It may be more efficient to keep the cached markdown.
h \div.description {
after-create: (dom) ->
dom.innerHTML = nmd self.description
}
]
2019-12-06 04:07:19 +01:00
]
2019-12-12 21:49:15 +01:00
2019-12-06 01:56:32 +01:00
if modal
modal.render!
]
2019-12-05 02:28:17 +01:00
self
2019-11-22 16:52:50 +01:00
2019-12-05 02:28:17 +01:00
module.exports = Task