users management
This commit is contained in:
parent
a9e28065bf
commit
6518f71787
@ -6,12 +6,22 @@ module.exports = {
|
||||
create-socket: (socket-url) ->
|
||||
self = {}
|
||||
|
||||
self.token = ""
|
||||
|
||||
request-types = {
|
||||
"get-token": 0
|
||||
"add-user": 1
|
||||
"get-user": 2
|
||||
"get-user-by-credentials": 3
|
||||
"mod-user": 4
|
||||
|
||||
# TODO: code these messages
|
||||
"register": 5
|
||||
"get-extra": 6
|
||||
"set-extra": 7
|
||||
"update-password": 8
|
||||
|
||||
"list-users": 9
|
||||
}
|
||||
|
||||
response-types = {
|
||||
@ -20,6 +30,9 @@ module.exports = {
|
||||
"user": 2
|
||||
"user-added": 3
|
||||
"user-edited": 4
|
||||
"extra": 5
|
||||
"extra-updated": 6
|
||||
"users-list": 7
|
||||
}
|
||||
|
||||
# TODO: naming convention
|
||||
@ -92,6 +105,15 @@ module.exports = {
|
||||
uid: uid
|
||||
}
|
||||
|
||||
self.list-users = ->
|
||||
self.send request-types[\list-users], JSON.stringify {
|
||||
token: self.token
|
||||
# FIXME: this will be removed once the authd program will accept
|
||||
# any list-users requests from any user
|
||||
# which is the only logical choice since any user can create projects and assign people to it
|
||||
key: "nico-nico-nii"
|
||||
}
|
||||
|
||||
# TODO: authd overhaul
|
||||
#self.add-user = (login, password) ->
|
||||
# self.send request-types[\add-user], JSON.stringify {
|
||||
|
@ -56,9 +56,6 @@ model = {
|
||||
|
||||
# current-view: "testing-modals"
|
||||
|
||||
# { uid => user data }
|
||||
users: {}
|
||||
|
||||
# list of Project objects
|
||||
project-list: []
|
||||
|
||||
@ -71,6 +68,9 @@ model = {
|
||||
|
||||
previous-error: undefined
|
||||
error: undefined
|
||||
|
||||
# { uid => user data }
|
||||
users: {}
|
||||
}
|
||||
|
||||
model.authd-url =
|
||||
@ -124,20 +124,27 @@ model.authd-ws.user-on-socket-close ++= [ authd-on-websocket-close ]
|
||||
|
||||
model.authd-ws.add-event-listener \token, (message) ->
|
||||
model.current-view := "project-list"
|
||||
model.authd-ws.token := message.token
|
||||
model.todod-ws.token := message.token
|
||||
model.todod-ws.list-lists!
|
||||
model.authd-ws.list-users!
|
||||
projector.schedule-render!
|
||||
|
||||
model.authd-ws.add-event-listener \error, (message) ->
|
||||
# console.log "authd error", message
|
||||
console.log "authd error", message
|
||||
projector.schedule-render!
|
||||
|
||||
model.authd-ws.add-event-listener \user, (message) ->
|
||||
model.users[message.user.uid] := message.user
|
||||
projector.schedule-render!
|
||||
|
||||
# TODO: user-added, user-edited
|
||||
model.authd-ws.add-event-listener \users-list, (message) ->
|
||||
console.log "Received users: ", message
|
||||
message.users.map (user) ->
|
||||
model.users[user.uid] := user
|
||||
projector.schedule-render!
|
||||
|
||||
# TODO: user-added, user-edited
|
||||
|
||||
|
||||
#
|
||||
@ -167,7 +174,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
|
||||
new-project = Project x, model.todod-ws, model.users
|
||||
|
||||
if old-project && new-project.id == old-project.id
|
||||
new-project.tasks = old-project.tasks
|
||||
@ -179,13 +186,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.project-list := model.project-list ++ [ (Project message.list, model.todod-ws, model.users) ]
|
||||
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
|
||||
new-project = Project message.list, model.todod-ws, model.users
|
||||
|
||||
model.project-list := model.project-list.map (project) ->
|
||||
if project.id == message.list.id
|
||||
|
@ -24,30 +24,22 @@ col-to-lines = (column, self) ->
|
||||
} [ "DELETE" ]
|
||||
]
|
||||
|
||||
# TODO FIXME XXX HARDCODE
|
||||
users = [
|
||||
{ login: "jean", id: "1003" }
|
||||
{ login: "martin", id: "1004" }
|
||||
{ login: "damien", id: "1005" }
|
||||
]
|
||||
|
||||
user-form-selection = (self, user) ->
|
||||
h \option {
|
||||
value: user.id
|
||||
value: user.uid
|
||||
} [ user.login ]
|
||||
|
||||
permission-groups = [
|
||||
"Admin"
|
||||
"Write"
|
||||
permission-groups =
|
||||
"Read"
|
||||
]
|
||||
"Write"
|
||||
"Admin"
|
||||
|
||||
permission-to-form-selection = (self, permission) ->
|
||||
h \option {
|
||||
value: permission
|
||||
} [ permission ]
|
||||
|
||||
ProjectCreationModal = (project, todod-ws) ->
|
||||
ProjectCreationModal = (project, todod-ws, users) ->
|
||||
|
||||
# work on a copy of the columns
|
||||
# in case of cancelled modifications, only the copies are changed
|
||||
@ -62,13 +54,14 @@ ProjectCreationModal = (project, todod-ws) ->
|
||||
title: project.title || ""
|
||||
permissions: project.permissions || [[]]
|
||||
# new-user: "New user"
|
||||
new-user-permission: {
|
||||
|
||||
tmp:
|
||||
new-user-permission:
|
||||
id: void
|
||||
permission: void
|
||||
}
|
||||
new-column-input: {
|
||||
permission: permission-groups[0]
|
||||
new-column-input:
|
||||
title: "New column !"
|
||||
}
|
||||
users: users || []
|
||||
|
||||
extra_properties:
|
||||
columns: columns-copy
|
||||
@ -120,31 +113,37 @@ ProjectCreationModal = (project, todod-ws) ->
|
||||
|
||||
h \p [ "Adding new user" ]
|
||||
|
||||
# TODO:
|
||||
# 1. select a permission groups
|
||||
# 2. select an user
|
||||
|
||||
h \div.field.has-addons {
|
||||
key: "adding-user"
|
||||
} [
|
||||
h \div.select.control [
|
||||
h \select {
|
||||
onchange: (e) ->
|
||||
self.new-user-permission.permission := e.target.value
|
||||
self.tmp.new-user-permission.permission := e.target.value
|
||||
} permission-groups.map (permission) -> permission-to-form-selection self, permission
|
||||
]
|
||||
|
||||
h \div.select.control.is-expanded [
|
||||
h \select {
|
||||
onchange: (e) ->
|
||||
self.new-user-permission.id := e.target.value
|
||||
} users.map (user) -> user-form-selection self, user
|
||||
self.tmp.new-user-permission.uid := e.target.value
|
||||
} [
|
||||
user-form-selection self, { login: "Choose a user", uid: "-" }
|
||||
for user-id, user of self.tmp.users
|
||||
user-form-selection self, user
|
||||
]
|
||||
]
|
||||
|
||||
h \div.control.button.is-success.is-outlined {
|
||||
onclick: ->
|
||||
# TODO
|
||||
console.log "right: #{self.new-user-permission.permission}, user #{self.new-user-permission.id}"
|
||||
if self.tmp.new-user-permission.uid == void || self.tmp.new-user-permission.uid == "-"
|
||||
console.log "adding an user permission on the kanban: failed, no user selected"
|
||||
else
|
||||
# TODO:
|
||||
# adding the permissions in self.permissions
|
||||
# then editing the project in the db via todod-ws
|
||||
# self.permissions
|
||||
console.log "right: #{self.tmp.new-user-permission.permission}, user #{self.tmp.new-user-permission.uid}"
|
||||
} [ "+" ]
|
||||
]
|
||||
|
||||
@ -162,9 +161,9 @@ ProjectCreationModal = (project, todod-ws) ->
|
||||
} [
|
||||
h \p.control.is-expanded [
|
||||
h \input.input {
|
||||
value: self.new-column-input.title
|
||||
value: self.tmp.new-column-input.title
|
||||
oninput: (e) ->
|
||||
self.new-column-input.title := e.target.value
|
||||
self.tmp.new-column-input.title := e.target.value
|
||||
} [ ]
|
||||
]
|
||||
|
||||
@ -172,19 +171,21 @@ ProjectCreationModal = (project, todod-ws) ->
|
||||
onclick: ->
|
||||
new-col = {
|
||||
id: UUID!
|
||||
title: self.new-column-input.title
|
||||
title: self.tmp.new-column-input.title
|
||||
}
|
||||
self.extra_properties.columns ++= [ new-col ]
|
||||
self.new-column-input.title := "New column !"
|
||||
self.tmp.new-column-input.title := "New column !"
|
||||
} [ "+" ]
|
||||
]
|
||||
]
|
||||
|
||||
on-validation: ->
|
||||
tmp = delete self.tmp
|
||||
if project.id
|
||||
todod-ws.edit-list project.id, self
|
||||
else
|
||||
todod-ws.add-list self.title, self
|
||||
self.tmp := tmp
|
||||
}, self
|
||||
|
||||
self.render = ->
|
||||
|
@ -4,7 +4,7 @@ bulma = require "./bulma.ls"
|
||||
Task = require "./task.ls"
|
||||
Modal = require './modal.ls'
|
||||
TaskCreationModal = require './task-creation-modal.ls'
|
||||
ProjectCreationModal = require "./project-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
|
||||
@ -20,9 +20,10 @@ orphan-tasks = (tasks, columns) ->
|
||||
tasks.filter (task) -> (! has-column) || inexistant-column task, columns
|
||||
|
||||
|
||||
Project = (self, todod-ws) ->
|
||||
Project = (self, todod-ws, users) ->
|
||||
self.todod-ws = todod-ws
|
||||
self.tasks = []
|
||||
self.users = users || []
|
||||
|
||||
modal = void
|
||||
|
||||
@ -62,7 +63,7 @@ Project = (self, todod-ws) ->
|
||||
h \div.navbar-item [
|
||||
h \div.button.is-outlined {
|
||||
onclick: ->
|
||||
modal := ProjectCreationModal self, self.todod-ws
|
||||
modal := ProjectCreationModal self, self.todod-ws, self.users
|
||||
} [ "Edit this project" ]
|
||||
]
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user