From b8b98e225a535771fd7b6341a1c7d20bc16f93e9 Mon Sep 17 00:00:00 2001 From: Rao Shahbaz Date: Tue, 17 May 2022 11:14:08 +0500 Subject: [PATCH] url setting and minor changes --- login_app/lib/pages/approval_List.dart | 12 +- login_app/lib/pages/change_Password.dart | 4 +- login_app/lib/pages/dashboard.dart | 77 +++++--- login_app/lib/pages/leavelist.dart | 220 +++++++++++++---------- login_app/lib/pages/login.dart | 36 +++- 5 files changed, 224 insertions(+), 125 deletions(-) diff --git a/login_app/lib/pages/approval_List.dart b/login_app/lib/pages/approval_List.dart index ef928bb..b15480a 100644 --- a/login_app/lib/pages/approval_List.dart +++ b/login_app/lib/pages/approval_List.dart @@ -15,6 +15,7 @@ class _ApprovalListState extends State { late Box box1; var token; + var url; var approvalList = []; var _isLoading = true; String msg = ""; @@ -27,6 +28,7 @@ class _ApprovalListState extends State { void getData() async { if (box1.get('token') != null) { token = box1.get('token'); + url = box1.get('updateUrl'); getApprovals(); } } @@ -41,7 +43,7 @@ class _ApprovalListState extends State { Future getApprovals() async { try { var response = await http.post( - Uri.parse(dotenv.env['API_URL']! + "/api/getlisPendLeave"), + Uri.parse(url + "/api/getlisPendLeave"), headers: { 'Content-Type': 'application/json', 'Authorization': token @@ -58,9 +60,9 @@ class _ApprovalListState extends State { } } void rejectRequest(index) async { - print(Uri.parse(dotenv.env['API_URL']! + "/api/approvalLeave/" + '${approvalList[index]["_id"]}')); + print(Uri.parse(url + "/api/approvalLeave/" + '${approvalList[index]["_id"]}')); var response = await http.put( - Uri.parse(dotenv.env['API_URL']! + "/api/rejectedLeave/" + '${approvalList[index]["_id"]}'), + Uri.parse(url + "/api/rejectedLeave/" + '${approvalList[index]["_id"]}'), headers: { 'Content-Type': 'application/json', 'Authorization': token @@ -85,9 +87,9 @@ class _ApprovalListState extends State { } void approveRequest(index) async { - print(Uri.parse(dotenv.env['API_URL']! + "/api/approvalLeave/" + '${approvalList[index]["_id"]}')); + print(Uri.parse(url + "/api/approvalLeave/" + '${approvalList[index]["_id"]}')); var response = await http.put( - Uri.parse(dotenv.env['API_URL']! + "/api/approvalLeave/" + '${approvalList[index]["_id"]}'), + Uri.parse(url + "/api/approvalLeave/" + '${approvalList[index]["_id"]}'), headers: { 'Content-Type': 'application/json', 'Authorization': token diff --git a/login_app/lib/pages/change_Password.dart b/login_app/lib/pages/change_Password.dart index 9a81265..25551ca 100644 --- a/login_app/lib/pages/change_Password.dart +++ b/login_app/lib/pages/change_Password.dart @@ -29,6 +29,7 @@ class _ChangePasswordState extends State { bool _isHiddenConfirm = true; var token; + var url; late Box box1; var _id; @@ -44,6 +45,7 @@ class _ChangePasswordState extends State { void getData() async { if (box1.get('token') != null) { token = box1.get('token'); + url = box1.get('updateUrl'); _id = box1.get('_id'); } } @@ -51,7 +53,7 @@ class _ChangePasswordState extends State { print(password.text); try { var response = await http.post( - Uri.parse(dotenv.env['API_URL']! + "/api/ChangePassword"), + Uri.parse(url + "/api/ChangePassword"), headers: { 'Content-Type': 'application/json', 'Authorization': token diff --git a/login_app/lib/pages/dashboard.dart b/login_app/lib/pages/dashboard.dart index d645f37..37bb190 100644 --- a/login_app/lib/pages/dashboard.dart +++ b/login_app/lib/pages/dashboard.dart @@ -24,12 +24,14 @@ class _DashboardState extends State { var transactionType = 'i am In'; var token; + var url; var workingHours; var Users = []; String msg = ""; var rightsTitle = ""; var diff_hr; var _isLoading = true; + var _isSignInLoading = true; DateTime signIn = DateTime.now(); // final @@ -64,21 +66,25 @@ class _DashboardState extends State { if (box1.get('token') != null) { token = box1.get('token'); workingHours = box1.get('WorkingHours'); + url = box1.get('updateUrl'); rightsTitle = box1.get('LeaveAccess') ?? ""; getUsers(); } } void getUsers() async { + print(url); + print('url'); try { var response = await http.get( - Uri.parse(dotenv.env['API_URL']! + "/api/gettodayattendance"), + Uri.parse(url + "/api/gettodayattendance"), headers: { 'Content-Type': 'application/json', 'Authorization': token }, ); print(response.body); + print(rightsTitle); setState(() { Users = jsonDecode(response.body)["data"]; @@ -88,6 +94,7 @@ class _DashboardState extends State { transactionType = "i am Out"; } _isLoading = false; + _isSignInLoading = true; }); print("Users"); print(Users); @@ -99,30 +106,33 @@ class _DashboardState extends State { } void attendanceDetails() async { + + _isSignInLoading = false; var obj = {}; if (transactionType == "i am Out" && diff_hr < workingHours) { obj = { 'TransactionType': transactionType, 'EarlyReason': earlyReason.text, 'Date': - _dateTime?.toIso8601String() ?? DateTime.now().toIso8601String(), - 'ManualEntry': _dateTime?.toIso8601String() != null ? true : false + _dateTime?.toUtc().toString() ?? DateTime.now().toUtc().toString(), + 'ManualEntry': _dateTime?.toUtc().toString() != null ? true : false }; } else { obj = { 'TransactionType': transactionType, 'Date': - _dateTime?.toIso8601String() ?? DateTime.now().toIso8601String(), - 'ManualEntry': _dateTime?.toIso8601String() != null ? true : false + _dateTime?.toUtc().toString() ?? DateTime.now().toUtc().toString(), + 'ManualEntry': _dateTime?.toUtc().toString() != null ? true : false }; } var response = await http.post( - Uri.parse(dotenv.env['API_URL']! + "/api/attendance_transaction"), + Uri.parse(url + "/api/attendance_transaction"), headers: { 'Content-Type': 'application/json', 'Authorization': token }, body: jsonEncode(obj)); + print(response.body); print(Users); @@ -146,6 +156,7 @@ class _DashboardState extends State { transactionType = transactionType == 'i am Out' ? "i am In" : 'i am Out'; }); + //_isSignInLoading = true; getData(); msg = jsonDecode(response.body)["message"]; var snackBar = SnackBar( @@ -167,8 +178,24 @@ class _DashboardState extends State { showDialog( context: context, builder: (context) => AlertDialog( - title: Text("Your {$workingHours} Hours of work is not completed yet", - textAlign: TextAlign.center), + title: RichText( + text: new TextSpan( + // Note: Styles for TextSpans must be explicitly defined. + // Child text spans will inherit styles from parent + style: new TextStyle( + fontSize: 20.0, + color: Colors.black, + ), + children: [ + new TextSpan(text: 'Your', style: TextStyle()), + new TextSpan(text: ' $workingHours Hours ', style: new TextStyle(fontWeight: FontWeight.bold)), + new TextSpan(text: 'of work is not completed yet'), + ], + + ), + textAlign: TextAlign.center, + + ), actions: [ TextField( keyboardType: TextInputType.multiline, @@ -327,7 +354,7 @@ class _DashboardState extends State { title: Text('${Users[index]["UserName"]}', style: TextStyle(color: Colors.white, fontSize: 18)), subtitle: Text( - '${DateFormat('dd-MM-yyyy h:mma').format(DateTime.parse(Users[index]["TakenIn"]))}', + '${DateFormat('dd-MM-yyyy h:mma').format(DateTime.parse(Users[index]["TakenIn"]).toLocal())}', style: TextStyle(color: Colors.white, fontSize: 17)), ), ); @@ -344,7 +371,7 @@ class _DashboardState extends State { : getDate(), style: TextStyle(fontSize: 20), ), - FlatButton( + TextButton( onPressed: () { pickDateTime(context); }, @@ -353,17 +380,23 @@ class _DashboardState extends State { Row( mainAxisAlignment: MainAxisAlignment.center, children: [ - RaisedButton( - elevation: 5, + _isSignInLoading ? + ElevatedButton( + style: ElevatedButton.styleFrom( + elevation: 5, + primary: Theme.of(context).primaryColor, + onPrimary: Colors.white, + shape: RoundedRectangleBorder( + borderRadius: BorderRadius.circular(20.0)), + ), + child: Text( transactionType, style: TextStyle(fontSize: 15), ), - color: Theme.of(context).primaryColor, - textColor: Colors.white, - shape: RoundedRectangleBorder( - borderRadius: BorderRadius.circular(20.0)), + onPressed: () { + if (transactionType == "i am In") { signIn = DateTime.now(); print(signIn); @@ -376,8 +409,7 @@ class _DashboardState extends State { if(Users[i]["UserID"] == box1.get("_id")){ print("Found"); print(Users[i]["TakenIn"]); - DateTime signOut = DateTime.now(); - print(box2.get("TakenIn")); + DateTime signOut = DateTime.parse(DateTime.now().toString()); DateTime signin = DateTime.parse(Users[i]["TakenIn"]); print(signin); print('signin'); @@ -389,10 +421,6 @@ class _DashboardState extends State { diff_hr = diff_mins / 60; print(diff_hr); print('time in hours'); - print(durationToString(100)); - print('duration of 100'); - //print(durationToString(diff_hr)); - print('difference in minutes and hours'); print(earlyReason.text); print('reson for early sign out'); if (diff_hr < workingHours) { @@ -412,7 +440,10 @@ class _DashboardState extends State { } }, - ), + ) : Center( + + child: CircularProgressIndicator(), + ), ], ), ], diff --git a/login_app/lib/pages/leavelist.dart b/login_app/lib/pages/leavelist.dart index 1e2a4a7..4b4a3ce 100644 --- a/login_app/lib/pages/leavelist.dart +++ b/login_app/lib/pages/leavelist.dart @@ -20,6 +20,7 @@ class _LeaveListState extends State { DateTime? lastDate; String selectedValue = 'Single leave'; var token; + var url; final reasonController = TextEditingController(); String enteredReason = ""; String msg = ""; @@ -36,6 +37,7 @@ class _LeaveListState extends State { void getData() async { if (box1.get('token') != null) { token = box1.get('token'); + url = box1.get('updateUrl'); getRequests(); } } @@ -43,7 +45,7 @@ class _LeaveListState extends State { void getRequests() async { try { var response = await http.post( - Uri.parse(dotenv.env['API_URL']! + "/api/getUsershowLeave"), + Uri.parse(url + "/api/getUsershowLeave"), headers: { 'Content-Type': 'application/json', 'Authorization': token @@ -79,7 +81,6 @@ class _LeaveListState extends State { super.initState(); } - Future pickDateTime(BuildContext context) async { final date = await pickDate(context); if (date == null) return; @@ -113,6 +114,7 @@ class _LeaveListState extends State { return DateFormat.yMMMEd().format(firstDate!); } } + String getLastDate() { if (lastDate == null) { return 'Select Last Date'; @@ -120,9 +122,10 @@ class _LeaveListState extends State { return DateFormat.yMMMEd().format(lastDate!); } } - void onSubmitData(){ + + void onSubmitData() { enteredReason = reasonController.text; - if(enteredReason.isEmpty || firstDate==null){ + if (enteredReason.isEmpty || firstDate == null) { return; } print(enteredReason); @@ -130,9 +133,10 @@ class _LeaveListState extends State { leaveRequest(); getRequests(); } - void onSubmitDataMultiple(){ + + void onSubmitDataMultiple() { enteredReason = reasonController.text; - if(enteredReason.isEmpty || firstDate==null || lastDate==null){ + if (enteredReason.isEmpty || firstDate == null || lastDate == null) { return; } leaveRequest(); @@ -150,7 +154,6 @@ class _LeaveListState extends State { return newDate!; } - // void getData () async { // if (box1.get('token') != null) { @@ -166,7 +169,7 @@ class _LeaveListState extends State { print(firstDate); print(box1.get('token')); var response = await http.post( - Uri.parse(dotenv.env['API_URL']! + "/api/LeaveReq"), + Uri.parse(url + "/api/LeaveReq"), headers: { 'Content-Type': 'application/json', 'Authorization': token @@ -182,18 +185,16 @@ class _LeaveListState extends State { } else { msg = "Leave Applied Successfully"; var snackBar = SnackBar( - content: Text( - msg, - style: TextStyle(fontSize: 16.5) - ), + content: Text(msg, style: TextStyle(fontSize: 16.5)), backgroundColor: Colors.green, ); ScaffoldMessenger.of(context).showSnackBar(snackBar); Navigator.of(context).pushAndRemoveUntil( MaterialPageRoute(builder: (context) => Dashboard()), - (Route route) => false); + (Route route) => false); } } + final items = ['Single leave', 'Multiple leave']; @override @@ -238,92 +239,124 @@ class _LeaveListState extends State { children: [ (selectedValue == singleLeave) ? Padding( - padding: const EdgeInsets.only(left: 15.0, right: 15.0), - child: Column( - children: [ - RaisedButton( - color: Theme.of(context).primaryColor, - textColor: Colors.white, - shape: RoundedRectangleBorder( - borderRadius: BorderRadius.circular(20.0)), - child: Text('Select Date'),onPressed: () => pickDateTime(context)), - Text(firstDate==null ? 'Select a Date' : getDate()), - TextField( - decoration: InputDecoration(labelText: 'Enter Reason'), - controller: reasonController, - keyboardType: TextInputType.multiline, - maxLines: null, - onSubmitted: (_) => onSubmitData(), - ), - SizedBox(height: 30,), - RaisedButton( - color: Theme.of(context).primaryColor, - textColor: Colors.white, - shape: RoundedRectangleBorder( - borderRadius: BorderRadius.circular(20.0)), - onPressed: () => onSubmitData(), child: Text('Submit'),) - ], - ), - ) - : Column( - children: [ - Row( - mainAxisAlignment: MainAxisAlignment.spaceAround, + padding: + const EdgeInsets.only(left: 15.0, right: 15.0), + child: Column( children: [ RaisedButton( color: Theme.of(context).primaryColor, textColor: Colors.white, shape: RoundedRectangleBorder( - borderRadius: BorderRadius.circular(20.0)), - child: Text('Start Date'),onPressed: () { - pickDateTime(context); - }), - RaisedButton( - color: Theme.of(context).primaryColor, - textColor: Colors.white, + borderRadius: + BorderRadius.circular(20.0)), + child: Text('Select Date'), + onPressed: () => pickDateTime(context)), + Text(firstDate == null + ? 'Select a Date' + : getDate()), + TextField( + decoration: + InputDecoration(labelText: 'Enter Reason'), + controller: reasonController, + keyboardType: TextInputType.multiline, + maxLines: null, + onSubmitted: (_) => onSubmitData(), + ), + SizedBox( + height: 30, + ), + ElevatedButton( + style: ElevatedButton.styleFrom( + primary: Theme.of(context).primaryColor, + onPrimary: Colors.white, shape: RoundedRectangleBorder( - borderRadius: BorderRadius.circular(20.0)), - child: Text('End Date'),onPressed: () { - pickLastDateTime(context); - }), - + borderRadius: + BorderRadius.circular(20.0)), + ), + onPressed: () => onSubmitData(), + child: Text('Submit'), + ) ], ), - Row( - mainAxisAlignment: MainAxisAlignment.spaceAround, - children: [ - - Text(firstDate==null ? 'Select Start Date' : getDate()), - Text(lastDate==null ? 'Select Last Date' : getLastDate()), - ], - ), - - - Padding( - padding: const EdgeInsets.only(left: 15.0, right: 15.0), - child: TextField( - decoration: InputDecoration(labelText: 'Enter Reason'), - controller: reasonController, - keyboardType: TextInputType.multiline, - maxLines: null, - onSubmitted: (_) => onSubmitDataMultiple(), + ) + : Column( + children: [ + Row( + mainAxisAlignment: MainAxisAlignment.spaceAround, + children: [ + ElevatedButton( + style: ElevatedButton.styleFrom( + primary: Theme.of(context).primaryColor, + onPrimary: Colors.white, + shape: RoundedRectangleBorder( + borderRadius: + BorderRadius.circular(20.0)), + ), + child: Text('Start Date'), + onPressed: () { + pickDateTime(context); + }), + ElevatedButton( + style: ElevatedButton.styleFrom( + primary: Theme.of(context).primaryColor, + onPrimary: Colors.white, + shape: RoundedRectangleBorder( + borderRadius: + BorderRadius.circular(20.0)), + ), + child: Text('End Date'), + onPressed: () { + pickLastDateTime(context); + }), + ], ), - ), - SizedBox(height: 30,), - RaisedButton( - color: Theme.of(context).primaryColor, - textColor: Colors.white, - shape: RoundedRectangleBorder( - borderRadius: BorderRadius.circular(20.0)), - onPressed: () => onSubmitDataMultiple(), child: Text('Submit', style: TextStyle(fontSize: 16),),) - ], - ), + Row( + mainAxisAlignment: MainAxisAlignment.spaceAround, + children: [ + Text(firstDate == null + ? 'Select Start Date' + : getDate()), + Text(lastDate == null + ? 'Select Last Date' + : getLastDate()), + ], + ), + Padding( + padding: const EdgeInsets.only( + left: 15.0, right: 15.0), + child: TextField( + decoration: + InputDecoration(labelText: 'Enter Reason'), + controller: reasonController, + keyboardType: TextInputType.multiline, + maxLines: null, + onSubmitted: (_) => onSubmitDataMultiple(), + ), + ), + SizedBox( + height: 30, + ), + ElevatedButton( + style: ElevatedButton.styleFrom( + primary: Theme.of(context).primaryColor, + onPrimary: Colors.white, + shape: RoundedRectangleBorder( + borderRadius: BorderRadius.circular(20.0)), + ), + onPressed: () => onSubmitDataMultiple(), + child: Text( + 'Submit', + style: TextStyle(fontSize: 16), + ), + ) + ], + ), SizedBox(height: 20), SingleChildScrollView( child: SizedBox( height: MediaQuery.of(context).size.height * .5, child: ListView.builder( - itemCount: leaveRequests.length, + itemCount: leaveRequests.length, itemBuilder: (BuildContext context, int index) { return Card( color: Colors.blueGrey, @@ -332,13 +365,17 @@ class _LeaveListState extends State { leading: Icon(Icons.person), title: Text( '${leaveRequests[index]["Status"]}', - style: TextStyle(color: Colors.white, fontSize: 17, fontWeight: FontWeight.bold), + style: TextStyle( + color: Colors.white, + fontSize: 17, + fontWeight: FontWeight.bold), ), subtitle: Text( - '${leaveRequests[index]["Date"]["Day"]}/' - '${leaveRequests[index]["Date"]["Month"] + 1}/' - '${leaveRequests[index]["Date"]["Year"]}', - style: TextStyle(color: Colors.white, fontSize: 15), + '${leaveRequests[index]["Date"]["Day"]}/' + '${leaveRequests[index]["Date"]["Month"] + 1}/' + '${leaveRequests[index]["Date"]["Year"]}', + style: TextStyle( + color: Colors.white, fontSize: 15), ), ), ); @@ -367,7 +404,8 @@ class _LeaveListState extends State { // // ), // ), // ), - )], + ) + ], ), ) ], diff --git a/login_app/lib/pages/login.dart b/login_app/lib/pages/login.dart index c8862e2..b4e361c 100644 --- a/login_app/lib/pages/login.dart +++ b/login_app/lib/pages/login.dart @@ -15,6 +15,7 @@ class Login extends StatefulWidget { class _LoginState extends State { TextEditingController email = TextEditingController(); TextEditingController password = TextEditingController(); + TextEditingController url = TextEditingController(text: dotenv.env['API_URL']); var token; String msg = ""; bool _isHidden = true; @@ -34,7 +35,8 @@ class _LoginState extends State { } void login() async { - if (email.text.isEmpty || password.text.isEmpty) { + var updateUrl = url.text; + if (email.text.isEmpty || password.text.isEmpty || url.text.isEmpty) { const snackBar = SnackBar( content: Text( 'Kindly fill both the fields', @@ -46,7 +48,7 @@ class _LoginState extends State { } else { try { var response = await http.post( - Uri.parse(dotenv.env['API_URL']! + "/api/login"), + Uri.parse(updateUrl + "/api/login"), headers: { 'Content-Type': 'application/json', }, @@ -70,6 +72,10 @@ class _LoginState extends State { _checkPassword(password.text); box1.put('token', data["token"]); box1.put('_id', data["data"]["_id"]); + box1.put('updateUrl', updateUrl); + print('URL FOR '); + print(updateUrl); + print('new urkl'); box1.put('WorkingHours', data["data"]["WorkingHours"]); if(_strength < 1){ Navigator.push( @@ -82,7 +88,13 @@ class _LoginState extends State { box1.put('Name', data["data"]["FirstName"] + " " + data["data"]["LastName"]); if(title.length > 0){ - box1.put('LeaveAccess', title[0]); + for(var i=0; i { } catch (e) { print(e); - msg = dotenv.env['API_URL'] ?? "Url null catch"; + msg = url.text ?? "Url null catch"; var snackBar = SnackBar( content: Text(msg), ); @@ -222,6 +234,20 @@ class _LoginState extends State { const SizedBox( height: 10, ), + TextField( + keyboardType: TextInputType.url, + decoration: const InputDecoration( + hintText: 'URL', + + prefixIcon: Icon(Icons.reply), + border: OutlineInputBorder( + borderSide: BorderSide(width: 2), + borderRadius: BorderRadius.all(Radius.circular(27.0)))), + controller: url, + ), + const SizedBox( + height: 10, + ), ButtonTheme( minWidth: 400, height: 50, @@ -244,7 +270,7 @@ class _LoginState extends State { height: 120, ), Text('Copyrights by Zaavia! © 2022'), - Text('Version 1.0.6'), + Text('Version 1.0.7'), ], ), ),