User name displayed properly.
parent
d4d21dd3fa
commit
2871f515cf
5
Makefile
5
Makefile
|
@ -18,7 +18,7 @@ main.js: main.bundle.js
|
|||
$(Q)npx babel --minified main.bundle.js -o main.js
|
||||
|
||||
|
||||
main.bundle.js: client/index.ls client/authws.ls client/bulma.ls client/card.ls client/column-edit-modal.ls client/font-awesome.ls client/modal.ls client/navbar.ls client/project-creation-modal.ls client/project.ls client/task-creation-modal.ls client/task.ls client/task-removal-modal.ls client/todowebsocket.ls client/validation-modal.ls
|
||||
main.bundle.js: client/index.ls client/authws.ls client/bulma.ls client/card.ls client/column-edit-modal.ls client/font-awesome.ls client/modal.ls client/navbar.ls client/project-creation-modal.ls client/project.ls client/task-creation-modal.ls client/task.ls client/task-removal-modal.ls client/todowebsocket.ls client/users-cache.ls client/validation-modal.ls
|
||||
@echo '[01;32m BUN > [01;37mmain.bundle.js[00m'
|
||||
$(Q)npx browserify -t browserify-livescript client/index.ls -o main.bundle.js
|
||||
|
||||
|
@ -109,6 +109,7 @@ $(PACKAGE)-$(VERSION).tar.gz: distdir
|
|||
$(PACKAGE)-$(VERSION)/client/task.ls \
|
||||
$(PACKAGE)-$(VERSION)/client/task-removal-modal.ls \
|
||||
$(PACKAGE)-$(VERSION)/client/todowebsocket.ls \
|
||||
$(PACKAGE)-$(VERSION)/client/users-cache.ls \
|
||||
$(PACKAGE)-$(VERSION)/client/validation-modal.ls
|
||||
|
||||
dist-xz: $(PACKAGE)-$(VERSION).tar.xz
|
||||
|
@ -130,6 +131,7 @@ $(PACKAGE)-$(VERSION).tar.xz: distdir
|
|||
$(PACKAGE)-$(VERSION)/client/task.ls \
|
||||
$(PACKAGE)-$(VERSION)/client/task-removal-modal.ls \
|
||||
$(PACKAGE)-$(VERSION)/client/todowebsocket.ls \
|
||||
$(PACKAGE)-$(VERSION)/client/users-cache.ls \
|
||||
$(PACKAGE)-$(VERSION)/client/validation-modal.ls
|
||||
|
||||
dist-bz2: $(PACKAGE)-$(VERSION).tar.bz2
|
||||
|
@ -151,6 +153,7 @@ $(PACKAGE)-$(VERSION).tar.bz2: distdir
|
|||
$(PACKAGE)-$(VERSION)/client/task.ls \
|
||||
$(PACKAGE)-$(VERSION)/client/task-removal-modal.ls \
|
||||
$(PACKAGE)-$(VERSION)/client/todowebsocket.ls \
|
||||
$(PACKAGE)-$(VERSION)/client/users-cache.ls \
|
||||
$(PACKAGE)-$(VERSION)/client/validation-modal.ls
|
||||
|
||||
help:
|
||||
|
|
|
@ -86,9 +86,9 @@ AuthWS = (socket-url) ->
|
|||
self.get-user-by-credentials login, password
|
||||
|
||||
|
||||
self.get-user = (uid) ->
|
||||
self.get-user = (login_or_uid) ->
|
||||
self.send request-types[\get-user], JSON.stringify {
|
||||
uid: uid
|
||||
user: login_or_uid
|
||||
}
|
||||
|
||||
self.register = (login, password) ->
|
||||
|
|
|
@ -9,13 +9,15 @@ Task = require "./task.ls"
|
|||
Project = require "./project.ls"
|
||||
Modal = require "./modal.ls"
|
||||
Navbar = require "./navbar.ls"
|
||||
# ValidationModal = require "./validation-modal.ls"
|
||||
UsersCache = require "./users-cache.ls"
|
||||
|
||||
{create-projector, h} = maquette
|
||||
projector = create-projector!
|
||||
|
||||
model = {
|
||||
# view: login, project-list, project, network-error (TODO: other views, such as rights)
|
||||
# FIXME: Replace model.current-view by an object that has a .render
|
||||
# method.
|
||||
current-view: "login"
|
||||
|
||||
viewed-project: void
|
||||
|
@ -35,6 +37,9 @@ model = {
|
|||
|
||||
# { uid => user data }
|
||||
users: {}
|
||||
|
||||
# uninitialized UserCache
|
||||
users-cache: void
|
||||
}
|
||||
|
||||
model.authd-url =
|
||||
|
@ -52,7 +57,6 @@ model.todod-url =
|
|||
console.log "authd url: " + model.authd-url
|
||||
console.log "todod url: " + model.todod-url
|
||||
|
||||
|
||||
#
|
||||
# network configuration
|
||||
#
|
||||
|
@ -61,6 +65,9 @@ model.authd-ws = AuthWS model.authd-url
|
|||
model.todod-ws = todows.create-socket model.todod-url
|
||||
|
||||
|
||||
model.users-cache = UsersCache model.authd-ws, ->
|
||||
projector.schedule-render!
|
||||
|
||||
#
|
||||
# authd messages management
|
||||
#
|
||||
|
@ -147,7 +154,7 @@ model.todod-ws.add-event-listener \lists-list, (message) ->
|
|||
|
||||
model.project-list := message.lists.map (x) ->
|
||||
old-project = model.project-list.find((.id == x.id))
|
||||
new-project = Project x, model.todod-ws, model.users
|
||||
new-project = Project x, model.todod-ws, model.users-cache
|
||||
|
||||
if old-project && new-project.id == old-project.id
|
||||
new-project.tasks = old-project.tasks
|
||||
|
@ -159,13 +166,13 @@ model.todod-ws.add-event-listener \lists-list, (message) ->
|
|||
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, model.users) ]
|
||||
model.project-list := model.project-list ++ [ (Project message.list, model.todod-ws, model.users-cache) ]
|
||||
projector.schedule-render!
|
||||
|
||||
model.todod-ws.add-event-listener \list-updated, (message) ->
|
||||
console.log "Project updated", message
|
||||
|
||||
new-project = Project message.list, model.todod-ws, model.users
|
||||
new-project = Project message.list, model.todod-ws, model.users-cache
|
||||
|
||||
model.project-list := model.project-list.map (project) ->
|
||||
if project.id == message.list.id
|
||||
|
@ -175,7 +182,7 @@ model.todod-ws.add-event-listener \list-updated, (message) ->
|
|||
|
||||
if model.viewed-project && model.viewed-project.id == message.list.id
|
||||
# create tasks in order to have the updated project properties
|
||||
new-project.tasks = model.viewed-project.tasks.map (task) -> Task task, new-project, model.todod-ws
|
||||
new-project.tasks = model.viewed-project.tasks.map (task) -> Task task, new-project, model.todod-ws, model.users-cache
|
||||
model.viewed-project = new-project
|
||||
|
||||
projector.schedule-render!
|
||||
|
@ -197,7 +204,7 @@ 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
|
||||
project.tasks := message.tasks.map (e) -> Task e, project, model.todod-ws, model.users-cache
|
||||
|
||||
if model.viewed-project && model.viewed-project.id == project.id
|
||||
model.viewed-project := project
|
||||
|
@ -213,7 +220,7 @@ model.todod-ws.add-event-listener \task-created, (message) ->
|
|||
model.viewed-project := list
|
||||
|
||||
if list
|
||||
list.tasks ++= [ Task task, list, model.todod-ws ]
|
||||
list.tasks ++= [ Task task, list, model.todod-ws, model.users-cache ]
|
||||
projector.schedule-render!
|
||||
|
||||
|
||||
|
@ -226,7 +233,7 @@ model.todod-ws.add-event-listener \task-updated, (message) ->
|
|||
if list
|
||||
list.tasks = list.tasks.map (e) ->
|
||||
if e.id == task.id
|
||||
Task task, list, model.todod-ws
|
||||
Task task, list, model.todod-ws, model.users-cache
|
||||
else
|
||||
e
|
||||
projector.schedule-render!
|
||||
|
|
|
@ -26,10 +26,11 @@ orphan-tasks = (tasks, columns) ->
|
|||
tasks.filter (task) -> (! has-column) || inexistant-column task, columns
|
||||
|
||||
|
||||
Project = (self, todod-ws, users) ->
|
||||
Project = (self, todod-ws, users-cache) ->
|
||||
console.log "CREATING PROJECT", users-cache
|
||||
|
||||
self.todod-ws = todod-ws
|
||||
self.tasks = []
|
||||
self.users = users || []
|
||||
|
||||
self.selected-task-id = void
|
||||
|
||||
|
@ -94,7 +95,7 @@ Project = (self, todod-ws, users) ->
|
|||
h \a.navbar-item.has-text-success {
|
||||
key: "navbar-new-task"
|
||||
onclick: ->
|
||||
modal := TaskCreationModal self, self.todod-ws, void, self.users
|
||||
modal := TaskCreationModal self, self.todod-ws, users-cache
|
||||
} [
|
||||
h \span [ "New task" ]
|
||||
|
||||
|
|
|
@ -43,13 +43,18 @@ color-to-form-selection = (self, color, current-color) ->
|
|||
selected: current-color && current-color == color
|
||||
} [ color ]
|
||||
|
||||
user-form-selection = (self, uid, is-selected) ->
|
||||
user-form-selection = (users-cache, uid, is-selected) ->
|
||||
h \option {
|
||||
selected: is-selected
|
||||
value: uid.to-string!
|
||||
} [ uid.to-string! ]
|
||||
} [
|
||||
if user = users-cache.get-user uid
|
||||
(user.profile?.full_name) || user.login
|
||||
else
|
||||
uid.to-string!
|
||||
]
|
||||
|
||||
TaskCreationModal = (project, todod-ws, task, users) ->
|
||||
TaskCreationModal = (project, todod-ws, task, users-cache) ->
|
||||
task ||= {}
|
||||
|
||||
# copy not to override anything on cancel
|
||||
|
@ -141,7 +146,7 @@ TaskCreationModal = (project, todod-ws, task, users) ->
|
|||
for permission in PERMISSION_LEVELS
|
||||
[
|
||||
for uid in project.permissions[permission]
|
||||
user-form-selection self, uid,
|
||||
user-form-selection users-cache, uid,
|
||||
(self.assigned_to == uid)
|
||||
]
|
||||
]
|
||||
|
|
|
@ -6,11 +6,16 @@ TaskRemovalModal = require './task-removal-modal.ls'
|
|||
|
||||
{icon} = require "./font-awesome.ls"
|
||||
|
||||
Task = (self, project, todod-ws) ->
|
||||
Task = (self, project, todod-ws, users-cache) ->
|
||||
modal = void
|
||||
|
||||
self.render-login = (uid) ->
|
||||
h \p [ '@' + uid.to-string! ]
|
||||
h \p [
|
||||
if user = users-cache.get-user uid
|
||||
'@' + user.login
|
||||
else
|
||||
'@' + uid.to-string!
|
||||
]
|
||||
|
||||
self.render = (args) ->
|
||||
args or= {}
|
||||
|
@ -32,7 +37,7 @@ Task = (self, project, todod-ws) ->
|
|||
h \div.title.is-5 [
|
||||
h \a.has-text-grey.is-pulled-right {
|
||||
onclick: ->
|
||||
modal := TaskCreationModal project, todod-ws, self, project.users
|
||||
modal := TaskCreationModal project, todod-ws, self, users-cache
|
||||
} [
|
||||
icon \cog
|
||||
]
|
||||
|
|
|
@ -0,0 +1,27 @@
|
|||
|
||||
UsersCache = (authd-ws, on-user) ->
|
||||
self = {}
|
||||
|
||||
on-user ||= (user) ->
|
||||
|
||||
# uid => user
|
||||
self.users = {}
|
||||
|
||||
authd-ws.add-event-listener \user, (message) ->
|
||||
user = message.user
|
||||
|
||||
self.users[user.uid] := user
|
||||
|
||||
on-user user
|
||||
|
||||
self.get-user = (uid) ->
|
||||
if user = self.users[uid]
|
||||
user
|
||||
else
|
||||
console.log "Sending request for #{uid}"
|
||||
authd-ws.get-user uid
|
||||
|
||||
self
|
||||
|
||||
module.exports = UsersCache
|
||||
|
Loading…
Reference in New Issue