diff --git a/client/index.ls b/client/index.ls index 64d62d4..da90db8 100644 --- a/client/index.ls +++ b/client/index.ls @@ -59,6 +59,7 @@ model = { # { uid => user data } users: {} + # list of Project objects project-list: [] port: 9999 @@ -162,7 +163,7 @@ model.todod-ws.user-on-socket-error ++= [ on-websocket-error ] model.todod-ws.user-on-socket-close ++= [ on-websocket-close ] model.todod-ws.add-event-listener \lists-list, (message) -> - console.log message + # console.log message model.project-list := message.lists.map (x) -> Project x, model.todod-ws @@ -174,12 +175,13 @@ model.todod-ws.add-event-listener \new-list, (message) -> projector.schedule-render! model.todod-ws.add-event-listener \tasks, (message) -> - console.log message + console.log "RECEIVED TASKS MESSAGE", message model.project-list.find((.id == message.list)).tasks := message.tasks + model.project-list.find((.id == message.list)).tasks-updated! projector.schedule-render! model.todod-ws.add-event-listener \list-removed, (message) -> - console.log message + console.log "A list has been removed", message if model.current-view == "project" && model.viewed-project == message.list model.current-view := "project-list" model.viewed-project := void @@ -187,22 +189,12 @@ model.todod-ws.add-event-listener \list-removed, (message) -> model.project-list := model.project-list.filter((.id != message.list)) -model.todod-ws.add-event-listener \tasks, (message) -> - console.log message - - project = model.project-list.find((.id == message.list)) - - if project - tasks = message.tasks.map (e) -> Task e, project, model - project.tasks = tasks - projector.schedule-render! - model.todod-ws.add-event-listener \task-created, (message) -> - console.log message + console.log "A task has been created", message task = message.task list = model.project-list.find((.id == task.list)) - console.log task, list + # console.log task, list if list list.tasks ++= [ Task task, list, model ] @@ -272,14 +264,6 @@ render-project = (project-id) -> bulma.title 3 "Error, we did not get the project id " + project-id ] -# -# Pages: -# login -# project-list -# project -# network-error -# - render-body = -> h \div.section [ switch model.current-view diff --git a/client/project.ls b/client/project.ls index 6bb4152..b2a0687 100644 --- a/client/project.ls +++ b/client/project.ls @@ -6,18 +6,26 @@ Modal = require './modal.ls' Project = (self, todod-ws) -> self.todod-ws = todod-ws - self.tasks = self.tasks.map (e) -> Task e, self, {} + self.tasks-objects = self.tasks.map (e) -> Task e, self, {} modal = void + self.tasks-updated = -> + self.tasks-objects = self.tasks.map (e) -> Task e, self, {} self.render-column = (column, first) -> # FIXME: display unregistred tasks in the first column + tasks-to-display = self.tasks-objects.filter (task) -> + task.extra_properties && task.extra_properties.column && task.extra_properties.column == column.id || ((! task.extra_properties || ! task.extra_properties.column) && first) + + console.log "TASKS", self.tasks + console.log "TASKS-OBJECTS", self.tasks-objects + console.log "TASKS TO DISPLAY", tasks-to-display + h \div.column [ bulma.title 4 column.title - self.tasks.filter (task) -> - task-column = task.extra_properties.column - task-column == column.id || (! task-column && first) + tasks-to-display.map (task) -> + h \div [ task.title ] ] self.render = -> diff --git a/client/task.ls b/client/task.ls index 4edf69a..135e019 100644 --- a/client/task.ls +++ b/client/task.ls @@ -32,197 +32,200 @@ get-next = (collection, element) -> Task = (self, project, model) -> self.render = -> - author = model.users[self.author] - if typeof(author) != "object" and author != "request sent" - model.users[self.author] = "request sent" - # FIXME: This should go directly to authd. - model.todod-ws.get-user self.author + h \div [ "coucou" ] - assigned_to = model.users[self.assigned_to] - if self.assigned_to and typeof(assigned_to) != "object" and assigned_to != "request sent" - model.users[self.assigned_to] = "request sent" - # FIXME: This should go directly to authd. - model.todod-ws.get-user self.assigned_to + # self.render-old = -> + # author = model.users[self.author] + # if typeof(author) != "object" and author != "request sent" + # model.users[self.author] = "request sent" + # # FIXME: This should go directly to authd. + # model.todod-ws.get-user self.author - is-selected = model.selected == self.id + # assigned_to = model.users[self.assigned_to] + # if self.assigned_to and typeof(assigned_to) != "object" and assigned_to != "request sent" + # model.users[self.assigned_to] = "request sent" + # # FIXME: This should go directly to authd. + # model.todod-ws.get-user self.assigned_to - h (\div.card.is- + (self.color || "dark")), { - key: self.id - classes: { - "is-selected": is-selected - } - onclick: -> - model.selected := self.id - } [ - h \div.card-content [ - h \div.media [ - h \div.media-left [ - h \img.image.is-48x48.avatar { - alt: "user image" - src: if typeof(assigned_to) == "object" - assigned_to.avatar - else - "https://bulma.io/images/placeholders/96x96.png" - } - ] - h \div.media-content [ - if model.editing == self.id + ".title" - h \input.input { - value: self.title - onchange: (e) -> - model.editing := undefined - model.todod-ws.edit-task project.id, self.id, { - title: e.target.value - } - } [ self.title ] - else - h \a [ - bulma.title 4 self.title - ] + # is-selected = model.selected == self.id - if typeof(model.users[self.assigned_to]) == "object" - user = model.users[self.assigned_to] + # h (\div.card.is- + (self.color || "dark")), { + # key: self.id + # classes: { + # "is-selected": is-selected + # } + # onclick: -> + # model.selected := self.id + # } [ + # h \div.card-content [ + # h \div.media [ + # h \div.media-left [ + # h \img.image.is-48x48.avatar { + # alt: "user image" + # src: if typeof(assigned_to) == "object" + # assigned_to.avatar + # else + # "https://bulma.io/images/placeholders/96x96.png" + # } + # ] + # h \div.media-content [ + # if model.editing == self.id + ".title" + # h \input.input { + # value: self.title + # onchange: (e) -> + # model.editing := undefined + # model.todod-ws.edit-task project.id, self.id, { + # title: e.target.value + # } + # } [ self.title ] + # else + # h \a [ + # bulma.title 4 self.title + # ] - h \div.subtitle.is-6 [ - "@" + (user.full_name || user.login) - ] - ] - if ! is-selected && self.description != "" - h \div.media-right {key: "description-icon"} [ - h \span.icon.is-size-1 [ "🗎" ] - ] + # if typeof(model.users[self.assigned_to]) == "object" + # user = model.users[self.assigned_to] - if is-selected - h \div.media-right {key: "edit"} [ - h \a.small { - onclick: -> - if model.editing == self.id + ".title" - model.editing := undefined - else - model.editing := self.id + ".title" - } [ - "Edit" - ] - ] + # h \div.subtitle.is-6 [ + # "@" + (user.full_name || user.login) + # ] + # ] + # if ! is-selected && self.description != "" + # h \div.media-right {key: "description-icon"} [ + # h \span.icon.is-size-1 [ "🗎" ] + # ] - if is-selected - h \div.media-right {key: "delete"} [ - h \a.small { - onclick: -> - model.editing := self.id + ".delete" - } [ - "Delete" - ] - ] - ] + # if is-selected + # h \div.media-right {key: "edit"} [ + # h \a.small { + # onclick: -> + # if model.editing == self.id + ".title" + # model.editing := undefined + # else + # model.editing := self.id + ".title" + # } [ + # "Edit" + # ] + # ] - if is-selected - h \div.content { - key: self.description - after-create: (dom) -> - dom.innerHTML = nmd self.description - } [ - if model.editing == self.id + ".description" - h \form.form [ - h \textarea.textarea { - value: model.editing-data - oninput: (e) -> - model.editing-data := e.target.value - } - h \div.button.is-fullwidth { - onclick: -> - model.todod-ws.edit-task project.id, self.id, { - description: model.editing-data - } - model.editing-data := undefined - model.editing := undefined - } [ "Update" ] - ] - ] + # if is-selected + # h \div.media-right {key: "delete"} [ + # h \a.small { + # onclick: -> + # model.editing := self.id + ".delete" + # } [ + # "Delete" + # ] + # ] + # ] - if is-selected - h \span.button.is-small { - onclick: -> - model.editing-data := self.description - model.editing := self.id + ".description" - } [ - "edit" - ] - ] + # if is-selected + # h \div.content { + # key: self.description + # after-create: (dom) -> + # dom.innerHTML = nmd self.description + # } [ + # if model.editing == self.id + ".description" + # h \form.form [ + # h \textarea.textarea { + # value: model.editing-data + # oninput: (e) -> + # model.editing-data := e.target.value + # } + # h \div.button.is-fullwidth { + # onclick: -> + # model.todod-ws.edit-task project.id, self.id, { + # description: model.editing-data + # } + # model.editing-data := undefined + # model.editing := undefined + # } [ "Update" ] + # ] + # ] - if is-selected - h \div.card-footer {key: "assign"} [ - if model.editing == self.id + ".assigned_to" - h \div.card-footer-item { - key: "assign.clicked" - } [ - h \input.input { - onchange: (e) -> - model.editing := undefined - model.todod-ws.edit-task project.id, self.id, { - assigned_to: Number e.target.value - } - } - ] - else - h \a.card-footer-item { - key: "assign" - onclick: -> - model.editing := self.id + ".assigned_to" - } [ "Assign" ] - ] + # if is-selected + # h \span.button.is-small { + # onclick: -> + # model.editing-data := self.description + # model.editing := self.id + ".description" + # } [ + # "edit" + # ] + # ] - if is-selected - h \div.card-footer {key: "color"} [ - if model.editing == self.id + ".color" - h \div.card-footer-item { - key: "color.clicked" - } [ - h \input.input { - onchange: (e) -> - model.editing := undefined - model.todod-ws.edit-task project.id, self.id, { - color: e.target.value - } - } - ] - else - h \a.card-footer-item { - key: "assign" - onclick: -> - model.editing := self.id + ".color" - } [ "Change Color" ] - ] + # if is-selected + # h \div.card-footer {key: "assign"} [ + # if model.editing == self.id + ".assigned_to" + # h \div.card-footer-item { + # key: "assign.clicked" + # } [ + # h \input.input { + # onchange: (e) -> + # model.editing := undefined + # model.todod-ws.edit-task project.id, self.id, { + # assigned_to: Number e.target.value + # } + # } + # ] + # else + # h \a.card-footer-item { + # key: "assign" + # onclick: -> + # model.editing := self.id + ".assigned_to" + # } [ "Assign" ] + # ] - if is-selected - h \div.card-footer {key: "move"} [ - h \a.card-footer-item { - key: "⇐" - onclick: -> - model.todod-ws.edit-task project.id, self.id, { - column: get-previous project.columns.map((.id)), self.column - } - } [ "⇐" ] + # if is-selected + # h \div.card-footer {key: "color"} [ + # if model.editing == self.id + ".color" + # h \div.card-footer-item { + # key: "color.clicked" + # } [ + # h \input.input { + # onchange: (e) -> + # model.editing := undefined + # model.todod-ws.edit-task project.id, self.id, { + # color: e.target.value + # } + # } + # ] + # else + # h \a.card-footer-item { + # key: "assign" + # onclick: -> + # model.editing := self.id + ".color" + # } [ "Change Color" ] + # ] - if model.editing == self.id + ".delete" - h \a.card-footer-item { - key: "delete" - } [ - h \div.button.is-danger { - onclick: -> - model.todod-ws.delete-task project.id, self.id - } [ "Delete! For real!" ] - ] + # if is-selected + # h \div.card-footer {key: "move"} [ + # h \a.card-footer-item { + # key: "⇐" + # onclick: -> + # model.todod-ws.edit-task project.id, self.id, { + # column: get-previous project.columns.map((.id)), self.column + # } + # } [ "⇐" ] - h \a.card-footer-item { - key: "⇒" - onclick: -> - model.todod-ws.edit-task project.id, self.id, { - column: get-next project.columns.map((.id)), self.column - } - } [ "⇒" ] - ] - ] + # if model.editing == self.id + ".delete" + # h \a.card-footer-item { + # key: "delete" + # } [ + # h \div.button.is-danger { + # onclick: -> + # model.todod-ws.delete-task project.id, self.id + # } [ "Delete! For real!" ] + # ] + + # h \a.card-footer-item { + # key: "⇒" + # onclick: -> + # model.todod-ws.edit-task project.id, self.id, { + # column: get-next project.columns.map((.id)), self.column + # } + # } [ "⇒" ] + # ] + # ] self