mirror of
https://github.com/inventree/inventree-app.git
synced 2026-03-11 12:45:00 +00:00
Check server state (#782)
This commit is contained in:
14
lib/api.dart
14
lib/api.dart
@@ -410,7 +410,7 @@ class InvenTreeAPI {
|
|||||||
* 5. Request information on available plugins
|
* 5. Request information on available plugins
|
||||||
*/
|
*/
|
||||||
Future<bool> _connectToServer() async {
|
Future<bool> _connectToServer() async {
|
||||||
if (!await _checkServer()) {
|
if (!await checkServer()) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -450,8 +450,8 @@ class InvenTreeAPI {
|
|||||||
* Check that the remote server is available.
|
* Check that the remote server is available.
|
||||||
* Ping the api/ endpoint, which does not require user authentication
|
* Ping the api/ endpoint, which does not require user authentication
|
||||||
*/
|
*/
|
||||||
Future<bool> _checkServer() async {
|
Future<bool> checkServer({String? server}) async {
|
||||||
String address = profile?.server ?? "";
|
String address = server ?? profile?.server ?? "";
|
||||||
|
|
||||||
if (address.isEmpty) {
|
if (address.isEmpty) {
|
||||||
showSnackIcon(
|
showSnackIcon(
|
||||||
@@ -462,8 +462,10 @@ class InvenTreeAPI {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!address.endsWith("/")) {
|
String url = _makeUrl("/api/", base: address);
|
||||||
address = address + "/";
|
|
||||||
|
if (!url.endsWith("/")) {
|
||||||
|
url = url + "/";
|
||||||
}
|
}
|
||||||
|
|
||||||
// Cache the "strictHttps" setting, so we can use it later without async requirement
|
// Cache the "strictHttps" setting, so we can use it later without async requirement
|
||||||
@@ -473,7 +475,7 @@ class InvenTreeAPI {
|
|||||||
|
|
||||||
debug("Connecting to ${apiUrl}");
|
debug("Connecting to ${apiUrl}");
|
||||||
|
|
||||||
APIResponse response = await get("", expectedStatusCode: 200);
|
APIResponse response = await get(url, expectedStatusCode: 200);
|
||||||
|
|
||||||
if (!response.successful()) {
|
if (!response.successful()) {
|
||||||
debug("Server returned invalid response: ${response.statusCode}");
|
debug("Server returned invalid response: ${response.statusCode}");
|
||||||
|
|||||||
@@ -294,6 +294,9 @@
|
|||||||
"confirmScanDetail": "Confirm stock transfer details when scanning barcodes",
|
"confirmScanDetail": "Confirm stock transfer details when scanning barcodes",
|
||||||
"@confirmScanDetail": {},
|
"@confirmScanDetail": {},
|
||||||
|
|
||||||
|
"connectionCheck": "Check Connection",
|
||||||
|
"@connectionCheck": {},
|
||||||
|
|
||||||
"connectionRefused": "Connection Refused",
|
"connectionRefused": "Connection Refused",
|
||||||
"@connectionRefused": {},
|
"@connectionRefused": {},
|
||||||
|
|
||||||
|
|||||||
@@ -298,6 +298,9 @@ class _ProfileEditState extends State<ProfileEditWidget> {
|
|||||||
String name = "";
|
String name = "";
|
||||||
String server = "";
|
String server = "";
|
||||||
|
|
||||||
|
bool? serverStatus;
|
||||||
|
bool serverChecking = false;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return Scaffold(
|
return Scaffold(
|
||||||
@@ -411,6 +414,49 @@ class _ProfileEditState extends State<ProfileEditWidget> {
|
|||||||
return null;
|
return null;
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
|
Divider(),
|
||||||
|
SizedBox(
|
||||||
|
width: double.infinity,
|
||||||
|
child: ElevatedButton.icon(
|
||||||
|
label: Text(L10().connectionCheck),
|
||||||
|
icon: serverStatus == true
|
||||||
|
? Icon(TablerIcons.circle_check, color: COLOR_SUCCESS)
|
||||||
|
: serverStatus == false
|
||||||
|
? Icon(TablerIcons.circle_x, color: COLOR_DANGER)
|
||||||
|
: Icon(TablerIcons.question_mark, color: COLOR_WARNING),
|
||||||
|
onPressed: serverChecking
|
||||||
|
? null
|
||||||
|
: () async {
|
||||||
|
if (serverChecking) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!formKey.currentState!.validate()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (mounted) {
|
||||||
|
setState(() {
|
||||||
|
serverStatus = null;
|
||||||
|
serverChecking = true;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
formKey.currentState!.save();
|
||||||
|
|
||||||
|
InvenTreeAPI().checkServer(server: server).then((
|
||||||
|
result,
|
||||||
|
) {
|
||||||
|
if (mounted) {
|
||||||
|
setState(() {
|
||||||
|
serverStatus = result;
|
||||||
|
serverChecking = false;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
},
|
||||||
|
),
|
||||||
|
),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
padding: EdgeInsets.all(16),
|
padding: EdgeInsets.all(16),
|
||||||
|
|||||||
Reference in New Issue
Block a user