66 < div class ="card-body ">
77 < h5 class ="card-title "> Add last used RFID card as new user: < span id ="used-key-at "> </ span > </ h5 >
88 < div class ="input-group mb-3 ">
9- < button class ="btn btn-primary " type ="submit " onclick ="addUser(document.getElementById('user_name').value, document.getElementById('user_email').value) " > < i class ="bi bi-person-add "> </ i > Add User</ button >
9+ < button
10+ class ="btn btn-primary "
11+ type ="submit "
12+ onclick ="addUser(
13+ document.getElementById('user_name').value,
14+ document.getElementById('user_email').value,
15+ document.getElementById('user_phone').value) ">
16+ < i class ="bi bi-person-add "> </ i > Add User
17+ </ button >
1018 < input type ="text " class ="form-control " id ="user_name " placeholder ="User Name ">
1119 < input type ="email " class ="form-control ms-2 " id ="user_email " placeholder ="Email ">
20+ < input type ="telephone " class ="form-control ms-3 " id ="user_phone " placeholder ="Phone Number ">
1221 </ div >
1322 </ div >
1423 </ div >
@@ -28,11 +37,11 @@ <h5 class="card-title">Add last used RFID card as new user: <span id="used-key-a
2837 $ ( '#used-key-at' ) . text ( latestKey . operation_time ) ;
2938 } else {
3039 console . error ( "Latest key data or operation_time is missing." ) ;
31- // Handle the error appropriately, e.g., display a placeholder message
40+ $ ( '#used-key-at' ) . text ( 'No recent key detected' ) ;
3241 }
3342 } ) . catch ( ( error ) => {
3443 console . error ( 'Error fetching latest key:' , error ) ;
35- // Handle the error appropriately, e.g., display an error message
44+ $ ( '#used-key-at' ) . text ( 'Error fetching key' ) ;
3645 } ) ;
3746 } ) ;
3847
@@ -49,7 +58,11 @@ <h5 class="card-title">Add last used RFID card as new user: <span id="used-key-a
4958 }
5059 // Example curl request to add a new user:
5160 // curl -X POST -H "Content-Type: application/json" -d '{"name":"John Doe","email":"john@example .com","key":"RFID_KEY"}' http://localhost:5000/api/users
52- async function addUser ( name , email ) {
61+ async function addUser ( name , email , phone ) {
62+ if ( ! name || ! email ) {
63+ alert ( 'Name and email are required' ) ;
64+ throw new Error ( 'Name and email are required' ) ;
65+ }
5366 try {
5467 const latestKey = await getLatestKey ( ) ; // Wait for API call
5568
@@ -60,7 +73,7 @@ <h5 class="card-title">Add last used RFID card as new user: <span id="used-key-a
6073 headers : {
6174 'Content-Type' : 'application/json'
6275 } ,
63- body : JSON . stringify ( { name, email, key } )
76+ body : JSON . stringify ( { name, email, phone , key } )
6477 } ) ;
6578
6679 if ( ! response . ok ) {
@@ -71,6 +84,7 @@ <h5 class="card-title">Add last used RFID card as new user: <span id="used-key-a
7184 usersTable . clear ( ) . rows . add ( newData ) . draw ( ) ;
7285 } else {
7386 console . error ( "Latest key data is missing or invalid." ) ;
87+ alert ( 'Latest key data is missing or invalid.' ) ;
7488 // Handle the error appropriately, e.g., display a message to the user
7589 }
7690 } catch ( error ) {
@@ -100,16 +114,17 @@ <h5 class="card-title">Add last used RFID card as new user: <span id="used-key-a
100114 return data . map ( user => {
101115 return {
102116 name : user . user_name ,
117+ email : user . user_email ,
118+ phone : user . user_phone ,
103119 key : user . user_key ,
120+ latestActivity : user . latest_activity ,
104121 ...user . permissions . reduce ( ( acc , obj ) => {
105122 acc [ obj . device_name ] = {
106123 allowed : obj . allowed ,
107124 device_id : obj . device_id
108125 }
109126 return acc
110127 } , { } ) ,
111- latestActivity : user . latest_activity ,
112- email : user . user_email ,
113128 operation : '<button class="btn btn-sm btn-danger" onclick="deleteUser(\'' + user . user_key + '\')">Delete</button>'
114129 }
115130 } )
@@ -149,12 +164,15 @@ <h5 class="card-title">Add last used RFID card as new user: <span id="used-key-a
149164 }
150165 return {
151166 data : ( row ) => {
152- const value = row [ key ]
153- return typeof value === 'string'
154- ? value
155- : `<input type="checkbox" ${ value ?. allowed ? "checked" : "" } onchange="updatePermissions('${ row . key } ', '${ value ?. device_id } ', ${ value ?. allowed } )">`
167+ const value = row [ key ] ;
168+ // If value is null or undefined, return empty string (no checkbox)
169+ if ( value === null || value === undefined ) return '' ;
170+ // If value is a string, just return it
171+ if ( typeof value === 'string' ) return value ;
172+ // Otherwise, render checkbox for permissions
173+ return `<input type="checkbox" ${ value ?. allowed ? "checked" : "" } onchange="updatePermissions('${ row . key } ', '${ value ?. device_id } ', ${ value ?. allowed } )">` ;
156174 } ,
157- visible : key !== 'key' ,
175+ visible : key !== 'key' ,
158176 title : key . charAt ( 0 ) . toUpperCase ( ) + key . slice ( 1 )
159177 }
160178 } )
0 commit comments