@@ -6,7 +6,7 @@ function buildSettingsHtml() {
66 jsCreateElement ( 'div' , {
77 attrs : {
88 class : 'tabButtons' ,
9- style : 'display: grid ; grid-template-columns: 1fr 1fr 1fr 1fr; width: 600px; grid-gap: 30px; margin-bottom: 60px; height: 40px;'
9+ style : 'display: grid ; grid-template-columns: 1fr 1fr 1fr 1fr 1fr ; width: 600px; grid-gap: 30px; margin-bottom: 60px; height: 40px;'
1010 } ,
1111 children : [
1212 jsCreateElement ( 'button' , {
@@ -36,6 +36,13 @@ function buildSettingsHtml() {
3636 onclick : 'showTab("webhooks")'
3737 } ,
3838 children : [ 'Webhooks' ]
39+ } ) ,
40+ jsCreateElement ( 'button' , {
41+ attrs : {
42+ class : 'tabButton w100p' ,
43+ onclick : 'showTab("users")'
44+ } ,
45+ children : [ 'Users' ]
3946 } )
4047 ]
4148 } ) ,
@@ -126,6 +133,33 @@ function showTab(tab) {
126133
127134 } ) ;
128135 }
136+
137+ if ( tab == "users" ) {
138+ buildSettingsUsers ( ) . then ( ( html ) => {
139+ tabContent . appendChild ( jsRender ( jsCreateElement ( 'div' , { attrs : { style : "" } , children : html } ) ) ) ;
140+ labelFloater ( ) ;
141+
142+ var objTableUsers = new Tabulator ( "#usersTable" , {
143+ height : '500px' ,
144+ layout :"fitColumns" ,
145+ ajaxURL :"/api/settings/users" ,
146+ progressiveLoad :"load" ,
147+ columns :[
148+ { title : "ID" , field : "id" , visible : false } ,
149+ { title : "Email" , field : "email" } ,
150+ { title : "Created At" , field : "created_at" } ,
151+ { title : "Delete" , field : "delete" , width : 40 }
152+ ]
153+ } ) ;
154+
155+ objTableUsers . on ( "cellClick" , function ( e , cell ) {
156+ if ( cell . getColumn ( ) . getField ( ) == "delete" ) {
157+ deleteUser ( cell . getData ( ) . id ) ;
158+ }
159+ } ) ;
160+ } ) ;
161+
162+ }
129163}
130164
131165/*
@@ -681,3 +715,138 @@ function addWebhook() {
681715 window . location . reload ( ) ;
682716 } ) ;
683717}
718+
719+
720+
721+ /*
722+
723+ Users
724+
725+ */
726+
727+ async function buildSettingsUsers ( ) {
728+
729+ let html = [ ] ;
730+
731+ html . push (
732+ jsCreateElement ( 'div' , {
733+ attrs : {
734+ class : 'mb40'
735+ } ,
736+ children : [
737+ jsCreateElement ( 'div' , {
738+ attrs : {
739+ class : 'itemBlock mb20'
740+ } ,
741+ children : [
742+ jsCreateElement ( 'label' , {
743+ attrs : {
744+ class : 'forinput'
745+ } ,
746+ children : [ "Email" ]
747+ } ) ,
748+ jsCreateElement ( 'input' , {
749+ attrs : {
750+ id : 'userEmail' ,
751+ value : '' ,
752+ placeholder : 'Enter email' ,
753+ class : ''
754+ }
755+ } ) ,
756+ ]
757+ } ) ,
758+ jsCreateElement ( 'div' , {
759+ attrs : {
760+ class : 'itemBlock mb20'
761+ } ,
762+ children : [
763+ jsCreateElement ( 'label' , {
764+ attrs : {
765+ class : 'forinput'
766+ } ,
767+ children : [ "Password" ]
768+ } ) ,
769+ jsCreateElement ( 'input' , {
770+ attrs : {
771+ id : 'userPassword' ,
772+ value : '' ,
773+ placeholder : 'Enter password' ,
774+ class : ''
775+ }
776+ } ) ,
777+ ]
778+ } ) ,
779+ jsCreateElement ( 'button' , {
780+ attrs : {
781+ id : 'user_create' ,
782+ class : 'buttonIcon' ,
783+ onclick : 'createUser()'
784+ } ,
785+ rawHtml : [
786+ '<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor" class="size-6"><path stroke-linecap="round" stroke-linejoin="round" d="M12 9v6m3-3H9m12 0a9 9 0 1 1-18 0 9 9 0 0 1 18 0Z" /></svg><div class="ml10">Add new user</div>'
787+ ]
788+ } )
789+ ]
790+ } )
791+ ) ;
792+
793+ html . push (
794+ jsCreateElement ( 'div' , {
795+ attrs : {
796+ id : 'usersTable'
797+ }
798+ } )
799+ ) ;
800+
801+ return html ;
802+ }
803+
804+ function deleteUser ( id ) {
805+ const html = jsCreateElement ( 'div' , {
806+ attrs : {
807+ } ,
808+ children : [
809+ jsCreateElement ( 'div' , {
810+ attrs : {
811+ class : 'headingH3 mb20'
812+ } ,
813+ children : [ "Delete user" ]
814+ } ) ,
815+ jsCreateElement ( 'button' , {
816+ attrs : {
817+ class : "buttonIcon" ,
818+ onclick : 'deleteUserDo("' + id + '")'
819+ } ,
820+ rawHtml : [
821+ '<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor" class="size-6"><path stroke-linecap="round" stroke-linejoin="round" d="M6 18L18 6M6 6l12 12" /></svg><div class="ml10">Delete</div>'
822+ ]
823+ } )
824+ ]
825+ } ) ;
826+
827+ rawModalLoader ( jsRender ( html ) ) ;
828+ }
829+
830+ function deleteUserDo ( id ) {
831+ fetch ( '/api/users/delete?userID=' + id , {
832+ method : 'DELETE'
833+ } )
834+ . then ( manageErrors )
835+ . then ( ( ) => {
836+ window . location . reload ( ) ;
837+ } ) ;
838+ }
839+
840+ function createUser ( ) {
841+ fetch ( '/api/users/create' , {
842+ method : 'POST' ,
843+ body : new URLSearchParams ( {
844+ email : dqs ( "#userEmail" ) . value ,
845+ password : dqs ( "#userPassword" ) . value
846+ } )
847+ } )
848+ . then ( manageErrors )
849+ . then ( ( ) => {
850+ window . location . reload ( ) ;
851+ } ) ;
852+ }
0 commit comments