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