Skip to content

Edit button for the organisations #23

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 25 additions & 12 deletions api/pages/org/list.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,19 +110,32 @@ def run(API, environ, indata, session):
orgname = indata.get('name', 'Foo')
orgdesc = indata.get('desc', '')
orgid = indata.get('id', str(int(time.time())))
queryMethod = indata.get('querymethod', 'update')
if session.DB.ES.exists(index=session.DB.dbname, doc_type='organisation', id = orgid):
raise API.exception(403, "Organisation ID already in use!")

doc = {
'id': orgid,
'name': orgname,
'description': orgdesc,
'admins': []
}
session.DB.ES.index(index=session.DB.dbname, doc_type='organisation', id = orgid, body = doc)
time.sleep(1.5)
yield json.dumps({"okay": True, "message": "Organisation created!"})
return
if queryMethod == 'update':
doc = {
'id': orgid,
'name': orgname,
'description': orgdesc,
'admins': []
}
session.DB.ES.index(index=session.DB.dbname, doc_type='organisation',id= orgid, body = doc)
time.sleep(1.5)
yield json.dumps({"okay": True, "message": "Organisation updated!"})
return
else:
raise API.exception(403, "Organisation ID already in use!")
else:
doc = {
'id': orgid,
'name': orgname,
'description': orgdesc,
'admins': []
}
session.DB.ES.index(index=session.DB.dbname, doc_type='organisation', id = orgid, body = doc)
time.sleep(1.5)
yield json.dumps({"okay": True, "message": "Organisation created!"})
return
else:
raise API.exception(403, "Only administrators can create new organisations.")

Expand Down
5 changes: 5 additions & 0 deletions api/yaml/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,15 @@ components:
description: The name of the organisation to create
example: Kibble, Inc.
type: string
querymethod:
description: Update or new
example: update
type: string
required:
- id
- name
- desc
- querymethod
OrgMembers:
properties:
admins:
Expand Down
6 changes: 6 additions & 0 deletions api/yaml/openapi/components/schemas/NewOrg.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,13 @@ properties:
description: The name of the organisation to create
example: Kibble, Inc.
type: string
querymethod:
description: Update or new
example: update
type: string

required:
- id
- name
- desc
- querymethod
5 changes: 5 additions & 0 deletions api/yaml/openapi/components/schemas/Organisation.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,12 @@ properties:
description: An array containing the IDs of the admins of this org
type: array
exammple: ['foo@bar', 'bar@foo']
querymethod:
description: Update or new
example: update
type: string
required:
- id
- name
- querymethod

34 changes: 28 additions & 6 deletions ui/js/coffee/kibble_organisation.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -40,21 +40,39 @@ defaultOrgChanged = (json, state) ->
location.reload()
, 1000)

makeOrg = () ->
makeOrg = (queryMethod) ->
orgname = get('orgname').value
orgdesc = get('orgdesc').value
orgid = get('orgid').value
if orgid.length == 0
orgid = parseInt(Math.random()*987654321).toString(16)
if queryMethod == 'new'
if orgid.length == 0
orgid = parseInt(Math.random()*987654321).toString(16)
if orgname.length == 0
alert("Please enter a name for the organisation!")
return
if orgdesc.length == 0
alert("Please enter a description of the organisation!")
return
put('org/list', {id: orgid, name: orgname, desc: orgdesc}, {}, orgCreated)

put('org/list', {id: orgid, name: orgname, desc: orgdesc, querymethod: queryMethod}, {}, orgCreated)

edit = (org) ->
document
.getElementById 'orgname'
.value = org.name
document
.getElementById 'orgdesc'
.value = org.desc
document
.getElementById 'orgid'
.value = org.id
document
.getElementById 'create_btn'
.disabled = true
document
.getElementById 'create_btn'
.scrollIntoView = false
window
.scrollTo(0,document.body.scrollHeight)
orglist = (json, state) ->
items = []
if json.organisations.length == 0
Expand All @@ -81,6 +99,8 @@ orglist = (json, state) ->
if not isDefault
dbtn = new HTML('input', { style: { marginTop: "10px", width: "120px"},class: "btn btn-primary btn-block", type: "button", onclick: "setDefaultOrg('#{org.id}');", value: "Set as current"})
div.inject(dbtn)
dbtn = new HTML('i', { style: { float: "right" }, class: "fa fa-edit", type: "icon", title: "Edit Organisation", onclick: "edit({name: '#{org.name}', desc: '#{org.description}', id: '#{org.id}'});",href: "#create_btn"})
div.inject(dbtn)
odiv.inject(new HTML('hr'))
state.widget.inject(odiv, true)

Expand All @@ -95,7 +115,9 @@ orglist = (json, state) ->

fieldset.inject(new HTML('p', {}, "You'll be able to add users and owners once the organisation has been created."))

btn = new HTML('input', { style: { width: "200px"},class: "btn btn-primary btn-block", type: "button", onclick: "makeOrg();", value: "Create organisation"})
btn = new HTML('input', { style: { width: "200px"},class: "btn btn-primary btn-block", type: "button",id: 'create_btn', onclick: "makeOrg('new');", value: "Create organisation"})
fieldset.inject(btn)
btn = new HTML('input', { style: { width: "200px"},class: "btn btn-primary btn-block", type: "button",id: 'edit_btn', onclick: "makeOrg('update');", value: "Edit organisation"})
fieldset.inject(btn)

state.widget.inject(fieldset)
Expand Down
45 changes: 40 additions & 5 deletions ui/js/kibble.v1.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.