Commit 5e0a5296 authored by Shoaib's avatar Shoaib
Browse files

Integrated concent api.

No related merge requests found
Showing with 138 additions and 35 deletions
+138 -35
......@@ -8,4 +8,5 @@ class ApiUrl {
static const submitInspection = '$baseUrl/api/forms/submitInspection';
static const getAllUsers = '$baseUrl/api/user/v1/getAllUser';
static const getFormDetails = '$baseUrl/api/forms/getFormById?id=';
static const submitConcent = '$baseUrl/api/forms/consentApplication';
}
......@@ -16,12 +16,21 @@
"previous": "previous",
"inspectionCompleted": "Inspection completed",
"completed": "Completed",
"pending": "Pending",
"sentForInspection": "Sent for inspection",
"noApplications": "No applications at the moment",
"sessionExpiredMessage": "Your session has expired.",
"isGivenInformationCorrect": "Is the given information found correct?",
"typeHere": "Type here",
"cancel": "Cancel",
"submit": "Submit",
"actualValue": "Actual value(s)"
"actualValue": "Actual value(s)",
"pleaseConcentDisagree": "Please concent or disagree",
"status": "Status",
"scheduledOn": "Scheduled on",
"inspetionCompletedOn": "Inspection completed on",
"inspectionSummary": "Inspection Summary",
"leadInspector": "Lead inspector",
"assistingInspectors": "Assisting inspectors",
"iDisagree": "I disagree",
"iConcent": "I concent"
}
\ No newline at end of file
......@@ -5,8 +5,10 @@ import 'package:smf_mobile/constants/app_constants.dart';
import 'package:smf_mobile/constants/color_constants.dart';
import 'package:smf_mobile/models/application_model.dart';
import 'package:smf_mobile/models/form_model.dart';
import 'package:smf_mobile/pages/inspection_completed.dart';
import 'package:smf_mobile/pages/inspection_summary.dart';
import 'package:smf_mobile/pages/login_email_page.dart';
import 'package:smf_mobile/repositories/application_repository.dart';
import 'package:smf_mobile/repositories/form_repository.dart';
import 'package:smf_mobile/util/helper.dart';
import 'package:smf_mobile/widgets/assistant_inspector_application_field.dart';
......@@ -47,6 +49,7 @@ class _ApplicationDetailsPageState extends State<ApplicationDetailsPage>
int _leadInspectorId = 0;
final List<Map> _inspectors = [];
String _inspectionSummary = '';
String _errorMessage = '';
@override
void initState() {
......@@ -93,7 +96,7 @@ class _ApplicationDetailsPageState extends State<ApplicationDetailsPage>
_formData = await Provider.of<FormRespository>(context, listen: false)
.getFormDetails(widget.application.formId);
// print('object');
String _errorMessage =
_errorMessage =
Provider.of<FormRespository>(context, listen: false).errorMessage;
if (_errorMessage != '') {
Helper.toastMessage(_errorMessage);
......@@ -172,19 +175,49 @@ class _ApplicationDetailsPageState extends State<ApplicationDetailsPage>
Future<void> _submitInspection() async {
_validateUser();
Map data = {
'applicationId': widget.application.applicationId,
'dataObject': _data
};
if (_isleadInspector) {
Map data = {
'applicationId': widget.application.applicationId,
'dataObject': _data
};
Navigator.of(context).pushReplacement(MaterialPageRoute(
builder: (context) => InspectionSummaryPage(
// formId: widget.formId,
formId: 1645422297511,
inspectors: widget.application.inspectors,
leadInspector: widget.application.leadInspector,
inspectionData: data,
)));
Navigator.of(context).pushReplacement(MaterialPageRoute(
builder: (context) => InspectionSummaryPage(
// formId: widget.formId,
formId: 1645422297511,
inspectors: widget.application.inspectors,
leadInspector: widget.application.leadInspector,
inspectionData: data,
)));
} else {
if (!_iConcent && !_iDisagree) {
Helper.toastMessage(
AppLocalizations.of(context)!.pleaseConcentDisagree);
return;
}
try {
Map data = {
'applicationId': widget.application.applicationId,
'agree': _iConcent,
'comments': _note
};
final responseCode =
await Provider.of<ApplicationRespository>(context, listen: false)
.submitConcent(data);
if (responseCode != 0) {
Navigator.of(context).pushReplacement(MaterialPageRoute(
builder: (context) => const InspectionCompletedPage()));
} else {
_errorMessage =
Provider.of<ApplicationRespository>(context, listen: false)
.errorMessage;
Helper.toastMessage(_errorMessage);
}
} catch (err) {
throw Exception(err);
}
}
}
triggerUpdate(Map data) {
......@@ -371,7 +404,10 @@ class _ApplicationDetailsPageState extends State<ApplicationDetailsPage>
4),
),
child: Text(
'Status: ${Helper.getInspectionStatus(context, widget.application.status)}',
AppLocalizations.of(
context)!
.status +
': ${Helper.getInspectionStatus(context, widget.application.status)}',
textAlign: TextAlign
.center,
style: GoogleFonts
......@@ -395,7 +431,13 @@ class _ApplicationDetailsPageState extends State<ApplicationDetailsPage>
width:
double.infinity,
child: Text(
'Inspection completed on ${Helper.formatDate(widget.application.scheduledDate)}',
AppLocalizations.of(
context)!
.inspetionCompletedOn +
' ' +
Helper.formatDate(widget
.application
.scheduledDate),
textAlign: TextAlign
.center,
style: GoogleFonts
......@@ -451,7 +493,9 @@ class _ApplicationDetailsPageState extends State<ApplicationDetailsPage>
const EdgeInsets
.only(top: 5),
child: Text(
'Inspection Summary',
AppLocalizations.of(
context)!
.inspectionSummary,
style:
GoogleFonts.lato(
color: AppColors
......@@ -499,7 +543,9 @@ class _ApplicationDetailsPageState extends State<ApplicationDetailsPage>
20,
15),
child: Text(
'Lead inspector',
AppLocalizations.of(
context)!
.leadInspector,
style:
GoogleFonts
.lato(
......@@ -535,7 +581,9 @@ class _ApplicationDetailsPageState extends State<ApplicationDetailsPage>
20,
15),
child: Text(
'Assisting inspectors',
AppLocalizations.of(
context)!
.assistingInspectors,
style: GoogleFonts
.lato(
color: AppColors
......@@ -665,7 +713,8 @@ class _ApplicationDetailsPageState extends State<ApplicationDetailsPage>
child: Row(
children: [
Text(
'I disagree',
AppLocalizations.of(context)!
.iDisagree,
style: GoogleFonts.lato(
color: _iDisagree
? Colors.white
......@@ -717,7 +766,8 @@ class _ApplicationDetailsPageState extends State<ApplicationDetailsPage>
child: Row(
children: [
Text(
'I concent',
AppLocalizations.of(context)!
.iConcent,
style: GoogleFonts.lato(
color: _iConcent
? Colors.white
......@@ -741,6 +791,20 @@ class _ApplicationDetailsPageState extends State<ApplicationDetailsPage>
)),
)
: const Center(),
_iConcent || _iDisagree
? Padding(
padding: const EdgeInsets.only(left: 0),
child: IconButton(
onPressed: () {
_displayCommentDialog();
},
icon: const Icon(
Icons.edit,
color: AppColors.black40,
),
),
)
: const Center()
],
)
: const Center(),
......@@ -798,8 +862,8 @@ class _ApplicationDetailsPageState extends State<ApplicationDetailsPage>
)
],
))
: widget.application.status ==
InspectionStatus.sentForInspection
: widget.application.status !=
InspectionStatus.inspectionCompleted
? TextButton(
onPressed: () {
_submitInspection();
......
......@@ -57,5 +57,19 @@ class ApplicationRespository with ChangeNotifier {
return _data['statusInfo']['statusCode'];
}
Future<dynamic> submitConcent(Map data) async {
try {
final request = await ApplicationService.submitConcent(data);
_data = json.decode(request.body);
} catch (_) {
return _;
}
if (_data['statusInfo']['statusCode'] != 200) {
_errorMessage = _data['statusInfo']['errorMessage'];
}
return _data['statusInfo']['statusCode'];
}
String get errorMessage => _errorMessage;
}
......@@ -4,7 +4,7 @@ import 'package:http/http.dart' as http;
import 'package:smf_mobile/constants/api_endpoints.dart';
import 'package:smf_mobile/constants/app_constants.dart';
import 'package:smf_mobile/services/base_service.dart';
// import 'dart:developer' as developer;
import 'dart:developer' as developer;
class ApplicationService extends BaseService {
ApplicationService(HttpClient client) : super(client);
......@@ -31,4 +31,16 @@ class ApplicationService extends BaseService {
// developer.log(response.body);
return response;
}
static Future<dynamic> submitConcent(Map data) async {
var body = json.encode(data);
Map<String, String> headers = await BaseService.getHeaders();
final response = await http.post(Uri.parse(ApiUrl.submitConcent),
headers: headers, body: body);
developer.log(ApiUrl.submitConcent);
developer.log(body);
developer.log(response.body);
return response;
}
}
......@@ -79,9 +79,9 @@ class Helper {
if (status == InspectionStatus.inspectionCompleted) {
_inspectionStatus = AppLocalizations.of(context)!.completed;
} else if (status == InspectionStatus.sentForInspection) {
_inspectionStatus = AppLocalizations.of(context)!.pending;
_inspectionStatus = AppLocalizations.of(context)!.sentForInspection;
} else {
_inspectionStatus = capitalize(_inspectionStatus);
_inspectionStatus = capitalize(status);
}
// print(_inspectionStatus);
return _inspectionStatus;
......
......@@ -5,6 +5,7 @@ import 'package:smf_mobile/constants/color_constants.dart';
import 'package:smf_mobile/models/application_model.dart';
import 'package:smf_mobile/pages/application_details_page.dart';
import 'package:smf_mobile/util/helper.dart';
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
class ApplicationCard extends StatefulWidget {
static const route = AppUrl.homePage;
......@@ -70,7 +71,8 @@ class _ApplicationCardState extends State<ApplicationCard> {
Padding(
padding: const EdgeInsets.only(bottom: 10),
child: Text(
'Scheduled on: ${Helper.formatDate(widget.application.scheduledDate)}',
AppLocalizations.of(context)!.scheduledOn +
': ${Helper.formatDate(widget.application.scheduledDate)}',
style: GoogleFonts.lato(
color: AppColors.black60,
fontSize: 14.0,
......@@ -82,7 +84,7 @@ class _ApplicationCardState extends State<ApplicationCard> {
children: [
Padding(
padding: const EdgeInsets.only(bottom: 10),
child: Text('Status: ',
child: Text(AppLocalizations.of(context)!.status + ': ',
style: GoogleFonts.lato(
color: AppColors.black60,
fontSize: 14.0,
......
......@@ -188,9 +188,10 @@ class _LeadInspectorApplicationFieldState
for (int i = 0; i < _options.length; i++)
InkWell(
onTap: () {
if (widget.applicationStatus ==
// print(_options[i]);
if (widget.applicationStatus !=
InspectionStatus
.sentForInspection) {
.inspectionCompleted) {
setState(() {
_radioValue = _options[i];
});
......@@ -237,9 +238,9 @@ class _LeadInspectorApplicationFieldState
.shrinkWrap,
onChanged: (val) {
if (widget
.applicationStatus ==
.applicationStatus !=
InspectionStatus
.sentForInspection) {
.inspectionCompleted) {
setState(() {
_radioValue =
_options[i];
......@@ -275,9 +276,9 @@ class _LeadInspectorApplicationFieldState
padding: const EdgeInsets.only(left: 0),
child: IconButton(
onPressed: () {
if (widget.applicationStatus ==
if (widget.applicationStatus !=
InspectionStatus
.sentForInspection &&
.inspectionCompleted &&
_radioValue !=
FieldValue.correct) {
_displayCommentDialog();
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment