add delete file option
This commit is contained in:
@@ -1,17 +1,25 @@
|
|||||||
|
import 'dart:convert';
|
||||||
|
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:patient_manager/components/BuildFileView.dart';
|
import 'package:patient_manager/components/BuildFileView.dart';
|
||||||
|
import 'package:patient_manager/components/mihDeleteMessage.dart';
|
||||||
|
import 'package:patient_manager/components/myErrorMessage.dart';
|
||||||
|
import 'package:patient_manager/components/mySuccessMessage.dart';
|
||||||
import 'package:patient_manager/components/mybutton.dart';
|
import 'package:patient_manager/components/mybutton.dart';
|
||||||
import 'package:patient_manager/env/env.dart';
|
import 'package:patient_manager/env/env.dart';
|
||||||
import 'package:patient_manager/main.dart';
|
import 'package:patient_manager/main.dart';
|
||||||
|
import 'package:patient_manager/objects/appUser.dart';
|
||||||
import 'package:patient_manager/objects/files.dart';
|
import 'package:patient_manager/objects/files.dart';
|
||||||
//import 'dart:js' as js;
|
import 'package:supertokens_flutter/http.dart' as http;
|
||||||
import "package:universal_html/html.dart" as html;
|
import "package:universal_html/html.dart" as html;
|
||||||
|
|
||||||
class BuildFilesList extends StatefulWidget {
|
class BuildFilesList extends StatefulWidget {
|
||||||
|
final AppUser signedInUser;
|
||||||
final List<PFile> files;
|
final List<PFile> files;
|
||||||
const BuildFilesList({
|
const BuildFilesList({
|
||||||
super.key,
|
super.key,
|
||||||
required this.files,
|
required this.files,
|
||||||
|
required this.signedInUser,
|
||||||
});
|
});
|
||||||
|
|
||||||
@override
|
@override
|
||||||
@@ -20,8 +28,80 @@ class BuildFilesList extends StatefulWidget {
|
|||||||
|
|
||||||
class _BuildFilesListState extends State<BuildFilesList> {
|
class _BuildFilesListState extends State<BuildFilesList> {
|
||||||
int indexOn = 0;
|
int indexOn = 0;
|
||||||
|
final baseAPI = AppEnviroment.baseApiUrl;
|
||||||
|
|
||||||
void viewFilePopUp(String fileName, String filePath) {
|
Future<void> deleteFileApiCall(String filePath, int fileID) async {
|
||||||
|
// delete file from minio
|
||||||
|
var response = await http.delete(
|
||||||
|
Uri.parse("$baseAPI/minio/delete/file/"),
|
||||||
|
headers: <String, String>{
|
||||||
|
"Content-Type": "application/json; charset=UTF-8"
|
||||||
|
},
|
||||||
|
body: jsonEncode(<String, dynamic>{"file_path": filePath}),
|
||||||
|
);
|
||||||
|
//print("Here4");
|
||||||
|
//print(response.statusCode);
|
||||||
|
if (response.statusCode == 200) {
|
||||||
|
//SQL delete
|
||||||
|
var response2 = await http.delete(
|
||||||
|
Uri.parse("$baseAPI/files/delete/"),
|
||||||
|
headers: <String, String>{
|
||||||
|
"Content-Type": "application/json; charset=UTF-8"
|
||||||
|
},
|
||||||
|
body: jsonEncode(<String, dynamic>{"idpatient_files": fileID}),
|
||||||
|
);
|
||||||
|
if (response2.statusCode == 200) {
|
||||||
|
Navigator.of(context).pop();
|
||||||
|
Navigator.of(context).pop();
|
||||||
|
Navigator.of(context)
|
||||||
|
.pushNamed('/patient-profile', arguments: widget.signedInUser);
|
||||||
|
setState(() {});
|
||||||
|
String message =
|
||||||
|
"The File has been deleted successfully. This means it will no longer be visible on your and cannot be used for future appointments.";
|
||||||
|
successPopUp(message);
|
||||||
|
} else {
|
||||||
|
internetConnectionPopUp();
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
internetConnectionPopUp();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void internetConnectionPopUp() {
|
||||||
|
showDialog(
|
||||||
|
context: context,
|
||||||
|
builder: (context) {
|
||||||
|
return const MyErrorMessage(errorType: "Internet Connection");
|
||||||
|
},
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
void successPopUp(String message) {
|
||||||
|
showDialog(
|
||||||
|
context: context,
|
||||||
|
builder: (context) {
|
||||||
|
return MySuccessMessage(
|
||||||
|
successType: "Success",
|
||||||
|
successMessage: message,
|
||||||
|
);
|
||||||
|
},
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
void deleteFilePopUp(String filePath, int fileID) {
|
||||||
|
showDialog(
|
||||||
|
context: context,
|
||||||
|
barrierDismissible: false,
|
||||||
|
builder: (context) => MIHDeleteMessage(
|
||||||
|
deleteType: "File",
|
||||||
|
onTap: () {
|
||||||
|
deleteFileApiCall(filePath, fileID);
|
||||||
|
},
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
void viewFilePopUp(String fileName, String filePath, int fileID) {
|
||||||
showDialog(
|
showDialog(
|
||||||
context: context,
|
context: context,
|
||||||
barrierDismissible: false,
|
barrierDismissible: false,
|
||||||
@@ -43,16 +123,33 @@ class _BuildFilesListState extends State<BuildFilesList> {
|
|||||||
child: Column(
|
child: Column(
|
||||||
mainAxisSize: MainAxisSize.min,
|
mainAxisSize: MainAxisSize.min,
|
||||||
children: [
|
children: [
|
||||||
Text(
|
Row(
|
||||||
fileName,
|
mainAxisAlignment: MainAxisAlignment.center,
|
||||||
textAlign: TextAlign.center,
|
crossAxisAlignment: CrossAxisAlignment.center,
|
||||||
style: TextStyle(
|
children: [
|
||||||
color: MzanziInnovationHub.of(context)!
|
Text(
|
||||||
.theme
|
fileName,
|
||||||
.secondaryColor(),
|
textAlign: TextAlign.center,
|
||||||
fontSize: 35.0,
|
style: TextStyle(
|
||||||
fontWeight: FontWeight.bold,
|
color: MzanziInnovationHub.of(context)!
|
||||||
),
|
.theme
|
||||||
|
.secondaryColor(),
|
||||||
|
fontSize: 35.0,
|
||||||
|
fontWeight: FontWeight.bold,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
IconButton(
|
||||||
|
onPressed: () {
|
||||||
|
deleteFilePopUp(filePath, fileID);
|
||||||
|
},
|
||||||
|
icon: Icon(
|
||||||
|
Icons.delete,
|
||||||
|
color: MzanziInnovationHub.of(context)!
|
||||||
|
.theme
|
||||||
|
.secondaryColor(),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
),
|
),
|
||||||
const SizedBox(height: 25.0),
|
const SizedBox(height: 25.0),
|
||||||
Expanded(
|
Expanded(
|
||||||
@@ -138,6 +235,7 @@ class _BuildFilesListState extends State<BuildFilesList> {
|
|||||||
viewFilePopUp(
|
viewFilePopUp(
|
||||||
widget.files[index].file_name,
|
widget.files[index].file_name,
|
||||||
widget.files[index].file_path,
|
widget.files[index].file_path,
|
||||||
|
widget.files[index].idpatient_files,
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -169,58 +169,7 @@ class _PatientFilesState extends State<PatientFiles> {
|
|||||||
// end loading circle
|
// end loading circle
|
||||||
Navigator.of(context).pop();
|
Navigator.of(context).pop();
|
||||||
String message =
|
String message =
|
||||||
"The medical certificate ${file.name.replaceAll(RegExp(r' '), '-')} has been successfully generated and added to ${widget.selectedPatient.first_name} ${widget.selectedPatient.last_name}'s record. You can now access and download it for their use.";
|
"The file ${file.name.replaceAll(RegExp(r' '), '-')} has been successfully generated and added to ${widget.selectedPatient.first_name} ${widget.selectedPatient.last_name}'s record. You can now access and download it for their use.";
|
||||||
successPopUp(message);
|
|
||||||
} else {
|
|
||||||
internetConnectionPopUp();
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
internetConnectionPopUp();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Future<void> uploadSelectedFilev1(PlatformFile file) async {
|
|
||||||
//var strem = new http.ByteStream.fromBytes(file.bytes.)
|
|
||||||
//start loading circle
|
|
||||||
showDialog(
|
|
||||||
context: context,
|
|
||||||
builder: (context) {
|
|
||||||
return const Center(
|
|
||||||
child: CircularProgressIndicator(),
|
|
||||||
);
|
|
||||||
},
|
|
||||||
);
|
|
||||||
|
|
||||||
var request = http2.MultipartRequest(
|
|
||||||
'POST', Uri.parse("${AppEnviroment.baseApiUrl}/files/upload/file/"));
|
|
||||||
request.fields['app_id'] = widget.selectedPatient.app_id;
|
|
||||||
request.headers['Content-Type'] = 'multipart/form-data';
|
|
||||||
request.files.add(await http2.MultipartFile.fromBytes('file', file.bytes!,
|
|
||||||
filename: file.name.replaceAll(RegExp(r' '), '-')));
|
|
||||||
var response1 = await request.send();
|
|
||||||
//print(response1.statusCode);
|
|
||||||
if (response1.statusCode == 200) {
|
|
||||||
var response2 = await http.post(
|
|
||||||
Uri.parse(endpointInsertFiles),
|
|
||||||
headers: <String, String>{
|
|
||||||
"Content-Type": "application/json; charset=UTF-8"
|
|
||||||
},
|
|
||||||
body: jsonEncode(<String, dynamic>{
|
|
||||||
"file_path": file.name.replaceAll(RegExp(r' '), '-'),
|
|
||||||
"file_name": file.name.replaceAll(RegExp(r' '), '-'),
|
|
||||||
"patient_id": widget.patientIndex
|
|
||||||
}),
|
|
||||||
);
|
|
||||||
//print(response2.statusCode);
|
|
||||||
if (response2.statusCode == 201) {
|
|
||||||
setState(() {
|
|
||||||
selectedFileController.clear();
|
|
||||||
futueFiles = fetchFiles();
|
|
||||||
});
|
|
||||||
// end loading circle
|
|
||||||
Navigator.of(context).pop();
|
|
||||||
String message =
|
|
||||||
"The medical certificate ${file.name.replaceAll(RegExp(r' '), '-')} has been successfully generated and added to ${widget.selectedPatient.first_name} ${widget.selectedPatient.last_name}'s record. You can now access and download it for their use.";
|
|
||||||
successPopUp(message);
|
successPopUp(message);
|
||||||
} else {
|
} else {
|
||||||
internetConnectionPopUp();
|
internetConnectionPopUp();
|
||||||
@@ -712,7 +661,10 @@ class _PatientFilesState extends State<PatientFiles> {
|
|||||||
.secondaryColor()),
|
.secondaryColor()),
|
||||||
),
|
),
|
||||||
const SizedBox(height: 10),
|
const SizedBox(height: 10),
|
||||||
BuildFilesList(files: filesList),
|
BuildFilesList(
|
||||||
|
files: filesList,
|
||||||
|
signedInUser: widget.signedInUser,
|
||||||
|
),
|
||||||
]),
|
]),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
|||||||
Reference in New Issue
Block a user