|
|
|
|
@ -4,6 +4,7 @@ import 'dart:typed_data';
|
|
|
|
|
|
|
|
|
|
import 'package:easy_localization/easy_localization.dart';
|
|
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
|
import 'package:mohem_flutter_app/app_state/app_state.dart';
|
|
|
|
|
import 'package:mohem_flutter_app/classes/colors.dart';
|
|
|
|
|
import 'package:mohem_flutter_app/extensions/int_extensions.dart';
|
|
|
|
|
import 'package:mohem_flutter_app/extensions/string_extensions.dart';
|
|
|
|
|
@ -25,9 +26,21 @@ class EtqanOvrRequestDetailed extends StatefulWidget {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
class _EtqanOvrRequestDetailedState extends State<EtqanOvrRequestDetailed> {
|
|
|
|
|
List<String> get fieldOrder => ['Project', 'Created', 'Occurrence Time', 'OVR Reference No', 'Involved Employee Number', 'Description'];
|
|
|
|
|
|
|
|
|
|
List<String> get hiddenFields => ['OVR Id', 'Is Anonymous'];
|
|
|
|
|
List<String> get fieldOrder => ['Status', 'Project', 'Created', 'Is Anonymous', 'Occurrence Time', 'OVR Reference No', 'Involved Employee Number', 'Description'];
|
|
|
|
|
|
|
|
|
|
List<String> get hiddenFields => ['OVR Id'];
|
|
|
|
|
|
|
|
|
|
Color _getStatusColor(String status) {
|
|
|
|
|
String statusLower = status.toLowerCase();
|
|
|
|
|
if (statusLower.contains('open') || statusLower.contains('مفتوح')) {
|
|
|
|
|
return const Color(0xff2196F3); // Blue for open
|
|
|
|
|
} else if (statusLower.contains('progress') || statusLower.contains('قيد التنفيذ')) {
|
|
|
|
|
return const Color(0xffFF9800); // Orange for in progress
|
|
|
|
|
} else if (statusLower.contains('closed') || statusLower.contains('مغلق')) {
|
|
|
|
|
return const Color(0xff4CAF50); // Green for closed
|
|
|
|
|
}
|
|
|
|
|
return MyColors.grey70Color; // Default gray
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Future<void> _viewAttachment(BuildContext context, String base64Data) async {
|
|
|
|
|
try {
|
|
|
|
|
@ -47,15 +60,33 @@ class _EtqanOvrRequestDetailedState extends State<EtqanOvrRequestDetailed> {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
List<EtqanGetIncidentRequestResponse> _getOrderedList(List<EtqanGetIncidentRequestResponse> list) {
|
|
|
|
|
List<EtqanGetIncidentRequestResponse> _getOrderedList(List<EtqanGetIncidentRequestResponse> list, EtqanOvrProviderModel provider) {
|
|
|
|
|
List<EtqanGetIncidentRequestResponse> orderedList = [];
|
|
|
|
|
|
|
|
|
|
List<EtqanGetIncidentRequestResponse> filteredList = list.where((EtqanGetIncidentRequestResponse item) => !hiddenFields.any((f) => f.toLowerCase() == item.key?.toLowerCase())).toList();
|
|
|
|
|
|
|
|
|
|
for (String fieldName in fieldOrder) {
|
|
|
|
|
var item = filteredList.firstWhere((e) => e.key?.toLowerCase() == fieldName.toLowerCase(), orElse: () => EtqanGetIncidentRequestResponse());
|
|
|
|
|
if (item.key != null) {
|
|
|
|
|
orderedList.add(item);
|
|
|
|
|
// Check if this is Status or Is Anonymous - inject from provider
|
|
|
|
|
if (fieldName.toLowerCase() == 'status' && provider.getCurrentStatus.isNotEmpty) {
|
|
|
|
|
orderedList.add(EtqanGetIncidentRequestResponse(
|
|
|
|
|
key: 'Status',
|
|
|
|
|
keyAr: 'الحالة',
|
|
|
|
|
value: provider.getCurrentStatus,
|
|
|
|
|
valueAr: provider.getCurrentStatusAr.isNotEmpty ? provider.getCurrentStatusAr : provider.getCurrentStatus,
|
|
|
|
|
));
|
|
|
|
|
} else if (fieldName.toLowerCase() == 'is anonymous') {
|
|
|
|
|
orderedList.add(EtqanGetIncidentRequestResponse(
|
|
|
|
|
key: 'Is Anonymous',
|
|
|
|
|
keyAr: 'مجهول',
|
|
|
|
|
value: provider.getCurrentIsAnonymous.toString(),
|
|
|
|
|
valueAr: provider.getCurrentIsAnonymous.toString(),
|
|
|
|
|
));
|
|
|
|
|
} else {
|
|
|
|
|
// Regular field from API
|
|
|
|
|
var item = filteredList.firstWhere((e) => e.key?.toLowerCase() == fieldName.toLowerCase(), orElse: () => EtqanGetIncidentRequestResponse());
|
|
|
|
|
if (item.key != null) {
|
|
|
|
|
orderedList.add(item);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@ -88,7 +119,7 @@ class _EtqanOvrRequestDetailedState extends State<EtqanOvrRequestDetailed> {
|
|
|
|
|
return Utils.getNoDataWidget(context);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
List<EtqanGetIncidentRequestResponse> orderedList = _getOrderedList(provider.getEtqanEmployeeIncidnetRequest!);
|
|
|
|
|
List<EtqanGetIncidentRequestResponse> orderedList = _getOrderedList(provider.getEtqanEmployeeIncidnetRequest!, provider);
|
|
|
|
|
|
|
|
|
|
return SingleChildScrollView(
|
|
|
|
|
physics: const BouncingScrollPhysics(),
|
|
|
|
|
@ -108,6 +139,8 @@ class _EtqanOvrRequestDetailedState extends State<EtqanOvrRequestDetailed> {
|
|
|
|
|
EtqanGetIncidentRequestResponse data = entry.value;
|
|
|
|
|
bool isLast = index == orderedList.length - 1;
|
|
|
|
|
bool isAttachment = data.key?.toLowerCase() == 'attachment';
|
|
|
|
|
bool isStatus = data.key?.toLowerCase() == 'status';
|
|
|
|
|
bool isAnonymous = data.key?.toLowerCase() == 'is anonymous';
|
|
|
|
|
|
|
|
|
|
String displayKey = context.locale.languageCode == "ar" ? (data.keyAr ?? data.key ?? "") : (data.key ?? "");
|
|
|
|
|
String displayValue = context.locale.languageCode == "ar" ? (data.valueAr ?? data.value ?? "") : (data.value ?? "");
|
|
|
|
|
@ -125,58 +158,65 @@ class _EtqanOvrRequestDetailedState extends State<EtqanOvrRequestDetailed> {
|
|
|
|
|
8.width,
|
|
|
|
|
Expanded(
|
|
|
|
|
flex: 3,
|
|
|
|
|
child:
|
|
|
|
|
isAttachment && hasSubValues
|
|
|
|
|
? Column(
|
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
|
|
|
children:
|
|
|
|
|
data.subValues!.asMap().entries.map((entry) {
|
|
|
|
|
int subIndex = entry.key;
|
|
|
|
|
String base64Data = entry.value;
|
|
|
|
|
return Padding(
|
|
|
|
|
padding: EdgeInsets.only(bottom: subIndex < data.subValues!.length - 1 ? 8.0 : 0),
|
|
|
|
|
child: GestureDetector(
|
|
|
|
|
onTap: () => _viewAttachment(context, base64Data),
|
|
|
|
|
child: Row(
|
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
|
|
|
mainAxisAlignment: context.locale.languageCode == "ar" ? MainAxisAlignment.end : MainAxisAlignment.start,
|
|
|
|
|
children: [
|
|
|
|
|
Text(
|
|
|
|
|
data.subValues!.length > 1 ? '${LocaleKeys.viewAttachment.tr()} ${subIndex + 1}' : LocaleKeys.viewAttachment.tr(),
|
|
|
|
|
// textAlign: context.locale.languageCode == "ar" ? TextAlign.start : TextAlign.start,
|
|
|
|
|
style: const TextStyle(
|
|
|
|
|
fontSize: 14,
|
|
|
|
|
color: MyColors.green9CColor,
|
|
|
|
|
decoration: TextDecoration.underline,
|
|
|
|
|
decorationColor: MyColors.green9CColor,
|
|
|
|
|
child: isStatus
|
|
|
|
|
? displayValue.toText14(
|
|
|
|
|
color: _getStatusColor(displayValue),
|
|
|
|
|
isBold: true,
|
|
|
|
|
)
|
|
|
|
|
: isAnonymous
|
|
|
|
|
? (displayValue.toLowerCase() == 'true' || displayValue.toLowerCase() == 'yes' || displayValue == '1'
|
|
|
|
|
? (context.locale.languageCode == "ar" ? "نعم" : "Yes")
|
|
|
|
|
: (context.locale.languageCode == "ar" ? "لا" : "No")
|
|
|
|
|
).toText14(color: MyColors.darkTextColor)
|
|
|
|
|
: isAttachment && hasSubValues
|
|
|
|
|
? Column(
|
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
|
|
|
children: data.subValues!.asMap().entries.map((entry) {
|
|
|
|
|
int subIndex = entry.key;
|
|
|
|
|
String base64Data = entry.value;
|
|
|
|
|
return Padding(
|
|
|
|
|
padding: EdgeInsets.only(bottom: subIndex < data.subValues!.length - 1 ? 8.0 : 0),
|
|
|
|
|
child: GestureDetector(
|
|
|
|
|
onTap: () => _viewAttachment(context, base64Data),
|
|
|
|
|
child: Row(
|
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
|
|
|
mainAxisAlignment: context.locale.languageCode == "ar" ? MainAxisAlignment.end : MainAxisAlignment.start,
|
|
|
|
|
children: [
|
|
|
|
|
Text(
|
|
|
|
|
data.subValues!.length > 1 ? '${LocaleKeys.viewAttachment.tr()} ${subIndex + 1}' : LocaleKeys.viewAttachment.tr(),
|
|
|
|
|
style: const TextStyle(
|
|
|
|
|
fontSize: 14,
|
|
|
|
|
color: MyColors.green9CColor,
|
|
|
|
|
decoration: TextDecoration.underline,
|
|
|
|
|
decorationColor: MyColors.green9CColor,
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
],
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
);
|
|
|
|
|
}).toList(),
|
|
|
|
|
)
|
|
|
|
|
: hasSubValues
|
|
|
|
|
? Column(
|
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
|
|
|
children: [
|
|
|
|
|
if (displayValue.isNotEmpty) displayValue.toText14(color: MyColors.darkTextColor),
|
|
|
|
|
if (displayValue.isNotEmpty) 8.height,
|
|
|
|
|
...data.subValues!
|
|
|
|
|
.map(
|
|
|
|
|
(subValue) => Padding(
|
|
|
|
|
padding: const EdgeInsets.only(bottom: 4),
|
|
|
|
|
child: Row(
|
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
|
|
|
children: [const Text("• ", style: TextStyle(fontSize: 14)), Expanded(child: subValue.toText14(color: MyColors.darkTextColor))],
|
|
|
|
|
],
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
)
|
|
|
|
|
.toList(),
|
|
|
|
|
],
|
|
|
|
|
)
|
|
|
|
|
: (displayValue.isNotEmpty ? displayValue : "-").toText14(color: MyColors.darkTextColor),
|
|
|
|
|
);
|
|
|
|
|
}).toList(),
|
|
|
|
|
)
|
|
|
|
|
: hasSubValues
|
|
|
|
|
? Column(
|
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
|
|
|
children: [
|
|
|
|
|
if (displayValue.isNotEmpty) displayValue.toText14(color: MyColors.darkTextColor),
|
|
|
|
|
if (displayValue.isNotEmpty) 8.height,
|
|
|
|
|
...data.subValues!
|
|
|
|
|
.map(
|
|
|
|
|
(subValue) => Padding(
|
|
|
|
|
padding: const EdgeInsets.only(bottom: 4),
|
|
|
|
|
child: Row(
|
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
|
|
|
children: [const Text("• ", style: TextStyle(fontSize: 14)), Expanded(child: subValue.toText14(color: MyColors.darkTextColor))],
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
)
|
|
|
|
|
.toList(),
|
|
|
|
|
],
|
|
|
|
|
)
|
|
|
|
|
: (displayValue.isNotEmpty ? displayValue : "-").toText14(color: MyColors.darkTextColor),
|
|
|
|
|
),
|
|
|
|
|
],
|
|
|
|
|
),
|
|
|
|
|
|