new project navbar

This commit is contained in:
Philippe PITTOLI 2019-12-07 00:44:02 +01:00
parent fb46723759
commit 7cfe504890
2 changed files with 64 additions and 44 deletions

View File

@ -164,13 +164,21 @@ model.todod-ws.user-on-socket-close ++= [ on-websocket-close ]
model.todod-ws.add-event-listener \lists-list, (message) ->
console.log "Project list received", message
model.project-list := message.lists.map (x) ->
Project x, model.todod-ws
old-project = model.project-list.find((.id == x.id))
new-project = Project x, model.todod-ws
if old-project && new-project.id == old-project.id
new-project.tasks = old-project.tasks
new-project
projector.schedule-render!
model.todod-ws.add-event-listener \new-list, (message) ->
console.log "New project", message
model.project-list := model.project-list ++ [ (Project message.list, model.todod-ws) ]
projector.schedule-render!
@ -186,18 +194,14 @@ model.todod-ws.add-event-listener \list-updated, (message) ->
project
if model.viewed-project && model.viewed-project.id == message.list.id
new-project.tasks = model.viewed-project.tasks
model.viewed-project = new-project
projector.schedule-render!
model.todod-ws.add-event-listener \tasks, (message) ->
console.log "Tasks received", message
project = model.project-list.find((.id == message.list))
model.project-list.find((.id == message.list)).tasks := message.tasks.map (e) -> Task e, project, model.todod-ws
projector.schedule-render!
model.todod-ws.add-event-listener \list-removed, (message) ->
console.log "A list has been removed", message
if model.current-view == "project" && model.viewed-project.id == message.list
model.current-view := "project-list"
model.viewed-project := void
@ -205,12 +209,27 @@ model.todod-ws.add-event-listener \list-removed, (message) ->
model.project-list := model.project-list.filter((.id != message.list))
# tasks
model.todod-ws.add-event-listener \tasks, (message) ->
console.log "Tasks received", message
project = model.project-list.find((.id == message.list))
project.tasks := message.tasks.map (e) -> Task e, project, model.todod-ws
if model.viewed-project.id == project.id
model.viewed-project := project
projector.schedule-render!
model.todod-ws.add-event-listener \task-created, (message) ->
console.log "A task has been created", message
task = message.task
list = model.project-list.find((.id == task.list))
# console.log task, list
if list.id == model.viewed-project.id
model.viewed-project := list
if list
list.tasks ++= [ Task task, list, model.todod-ws ]
@ -222,7 +241,6 @@ model.todod-ws.add-event-listener \task-updated, (message) ->
task = message.task
list = model.project-list.find((.id == task.list))
# console.log task, list
if list
list.tasks = list.tasks.map (e) ->
@ -242,7 +260,9 @@ model.todod-ws.add-event-listener \task-removed, (message) ->
projector.schedule-render!
render-navbar = ->
h \div.navbar [
h \div.navbar-start [
h \a.navbar-item.is-size-2 {
@ -253,7 +273,15 @@ render-navbar = ->
model.current-view := "project-list"
} [ "⌂" ]
]
if model.viewed-project
model.viewed-project.inner-nav-render!
h \div.navbar-end [
if model.viewed-project
model.viewed-project.right-nav-render!
h \a.navbar-item {
onclick: ->
model.current-view := "login"

View File

@ -13,6 +13,7 @@ Project = (self, todod-ws) ->
modal = void
self.render-column = (column, first) ->
tasks-to-display = self.tasks.filter (task) ->
task.extra_properties && task.extra_properties.column && task.extra_properties.column == column.id
|| ((! task.extra_properties || ! task.extra_properties.column) && first)
@ -29,43 +30,36 @@ Project = (self, todod-ws) ->
]
]
self.render-navbar = ->
h \div.navbar [
self.inner-nav-render = ->
h \div.navbar-item [ h \a.subtitle.is-3 [ self.title ] ]
h \div.navbar-brand [
h \div.navbar-item [
self.title
]
self.right-nav-render = ->
[
h \div.navbar-item [
h \div.button.is-outlined {
onclick: ->
modal := ProjectCreationModal self, self.todod-ws
} [ "Edit this project" ]
]
h \div.navbar-end [
h \div.navbar-item [
h \div.button.is-success.is-outlined {
onclick: ->
modal := TaskCreationModal self, self.todod-ws
} [ "New task" ]
]
h \div.navbar-item [
h \div.button.is-danger.is-outlined {
onclick: ->
modal := ProjectCreationModal self, self.todod-ws
} [ "EDIT" ]
]
h \div.navbar-item [
h \div.button.is-success.is-outlined {
onclick: ->
modal := TaskCreationModal self, self.todod-ws
} [ "+" ]
]
h \div.navbar-item [
h \div.button.is-danger.is-outlined {
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
}
} [ "X" ]
]
h \div.navbar-item [
h \div.button.is-danger.is-outlined {
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" ]
]
]
@ -74,8 +68,6 @@ Project = (self, todod-ws) ->
# console.log "Project to render: ", self
h \div.project {} [
self.render-navbar!
h \div.columns [
if columns = self.extra_properties.columns
for dom in columns.map((column, index) -> self.render-column(column, index == 0))