mirror of
https://github.com/inventree/inventree-app.git
synced 2025-04-28 13:36:50 +00:00
Upload test result - now with ability to attach a file!
This commit is contained in:
parent
7bfc26b5a0
commit
54f045afd8
@ -297,7 +297,6 @@ class InvenTreeAPI {
|
|||||||
var response = await request.send();
|
var response = await request.send();
|
||||||
|
|
||||||
return response;
|
return response;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Perform a POST request
|
// Perform a POST request
|
||||||
|
@ -5,6 +5,9 @@ import 'package:flutter/cupertino.dart';
|
|||||||
import 'package:http/http.dart' as http;
|
import 'package:http/http.dart' as http;
|
||||||
import 'model.dart';
|
import 'model.dart';
|
||||||
|
|
||||||
|
import 'dart:async';
|
||||||
|
import 'dart:io';
|
||||||
|
|
||||||
import 'package:InvenTree/api.dart';
|
import 'package:InvenTree/api.dart';
|
||||||
|
|
||||||
|
|
||||||
@ -129,12 +132,12 @@ class InvenTreeStockItem extends InvenTreeModel {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<bool> uploadTestResult(BuildContext context, String testName, bool result, {String value, String notes}) async {
|
Future<bool> uploadTestResult(BuildContext context, String testName, bool result, {String value, String notes, File attachment}) async {
|
||||||
|
|
||||||
Map<String, dynamic> data = {
|
Map<String, String> data = {
|
||||||
"stock_item": pk,
|
"stock_item": pk.toString(),
|
||||||
"test": testName,
|
"test": testName,
|
||||||
"result": result,
|
"result": result.toString(),
|
||||||
};
|
};
|
||||||
|
|
||||||
if (value != null && !value.isEmpty) {
|
if (value != null && !value.isEmpty) {
|
||||||
@ -145,15 +148,23 @@ class InvenTreeStockItem extends InvenTreeModel {
|
|||||||
data["notes"] = notes;
|
data["notes"] = notes;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool _result = false;
|
/*
|
||||||
|
* Upload is performed in different ways, depending if an attachment is provided.
|
||||||
|
* TODO: Is there a nice way to refactor this one?
|
||||||
|
*/
|
||||||
|
if (attachment == null) {
|
||||||
|
var _result = await InvenTreeStockItemTestResult().create(context, data);
|
||||||
|
|
||||||
await InvenTreeStockItemTestResult().create(context, data).then((InvenTreeModel model) {
|
return (_result != null) && (_result is InvenTreeStockItemTestResult);
|
||||||
|
} else {
|
||||||
|
var url = InvenTreeStockItemTestResult().URL;
|
||||||
|
http.StreamedResponse _uploadResponse = await InvenTreeAPI().uploadFile(url, attachment, fields: data);
|
||||||
|
|
||||||
_result = model != null && model is InvenTreeStockItemTestResult;
|
// Check that the HTTP status code is HTTP_201_CREATED
|
||||||
|
return _uploadResponse.statusCode == 201;
|
||||||
|
}
|
||||||
|
|
||||||
});
|
return false;
|
||||||
|
|
||||||
return _result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int get partId => jsondata['part'] ?? -1;
|
int get partId => jsondata['part'] ?? -1;
|
||||||
|
@ -12,6 +12,7 @@ import 'package:flutter/material.dart';
|
|||||||
import 'package:InvenTree/widget/refreshable_state.dart';
|
import 'package:InvenTree/widget/refreshable_state.dart';
|
||||||
import 'package:flutter_speed_dial/flutter_speed_dial.dart';
|
import 'package:flutter_speed_dial/flutter_speed_dial.dart';
|
||||||
import 'package:font_awesome_flutter/font_awesome_flutter.dart';
|
import 'package:font_awesome_flutter/font_awesome_flutter.dart';
|
||||||
|
import 'package:image_picker/image_picker.dart';
|
||||||
|
|
||||||
class StockItemTestResultsWidget extends StatefulWidget {
|
class StockItemTestResultsWidget extends StatefulWidget {
|
||||||
|
|
||||||
@ -41,7 +42,7 @@ class _StockItemTestResultDisplayState extends RefreshableState<StockItemTestRes
|
|||||||
|
|
||||||
_StockItemTestResultDisplayState(this.item);
|
_StockItemTestResultDisplayState(this.item);
|
||||||
|
|
||||||
void uploadTestResult(String name, bool result, String value, String notes) async {
|
void uploadTestResult(String name, bool result, String value, String notes, File attachment) async {
|
||||||
|
|
||||||
item.uploadTestResult(
|
item.uploadTestResult(
|
||||||
context,
|
context,
|
||||||
@ -49,6 +50,7 @@ class _StockItemTestResultDisplayState extends RefreshableState<StockItemTestRes
|
|||||||
result,
|
result,
|
||||||
value: value,
|
value: value,
|
||||||
notes: notes,
|
notes: notes,
|
||||||
|
attachment: attachment
|
||||||
).then((bool success) {
|
).then((bool success) {
|
||||||
if (success) {
|
if (success) {
|
||||||
// TODO - Show a SnackBar here!
|
// TODO - Show a SnackBar here!
|
||||||
@ -65,6 +67,7 @@ class _StockItemTestResultDisplayState extends RefreshableState<StockItemTestRes
|
|||||||
bool _result;
|
bool _result;
|
||||||
String _value;
|
String _value;
|
||||||
String _notes;
|
String _notes;
|
||||||
|
File _attachment;
|
||||||
|
|
||||||
showFormDialog(context, "Add Test Data",
|
showFormDialog(context, "Add Test Data",
|
||||||
key: _addResultKey,
|
key: _addResultKey,
|
||||||
@ -81,7 +84,7 @@ class _StockItemTestResultDisplayState extends RefreshableState<StockItemTestRes
|
|||||||
if (_addResultKey.currentState.validate()) {
|
if (_addResultKey.currentState.validate()) {
|
||||||
_addResultKey.currentState.save();
|
_addResultKey.currentState.save();
|
||||||
Navigator.pop(context);
|
Navigator.pop(context);
|
||||||
uploadTestResult(_name, _result, _value, _notes);
|
uploadTestResult(_name, _result, _value, _notes, _attachment);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
@ -111,6 +114,11 @@ class _StockItemTestResultDisplayState extends RefreshableState<StockItemTestRes
|
|||||||
return null;
|
return null;
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
|
ImagePickerField(
|
||||||
|
label: "Attach Image",
|
||||||
|
required: attachmentRequired,
|
||||||
|
onSaved: (attachment) => _attachment = attachment,
|
||||||
|
),
|
||||||
StringField(
|
StringField(
|
||||||
allowEmpty: true,
|
allowEmpty: true,
|
||||||
label: "Notes",
|
label: "Notes",
|
||||||
|
Loading…
x
Reference in New Issue
Block a user