mirror of
https://github.com/inventree/inventree-app.git
synced 2025-04-29 05:56:47 +00:00
PartTestTemplate is now class based
This commit is contained in:
parent
70ca369529
commit
0a5419eb6d
@ -1,6 +1,7 @@
|
||||
import 'dart:convert';
|
||||
|
||||
import 'package:InvenTree/api.dart';
|
||||
import 'package:flutter/cupertino.dart';
|
||||
|
||||
import 'model.dart';
|
||||
import 'dart:io';
|
||||
@ -63,6 +64,28 @@ class InvenTreePartCategory extends InvenTreeModel {
|
||||
}
|
||||
|
||||
|
||||
class InvenTreePartTestTemplate extends InvenTreeModel {
|
||||
|
||||
@override
|
||||
String NAME = "PartTestTemplate";
|
||||
|
||||
@override
|
||||
String URL = "part/test-template/";
|
||||
|
||||
InvenTreePartTestTemplate() : super();
|
||||
|
||||
InvenTreePartTestTemplate.fromJson(Map<String, dynamic> json) : super.fromJson(json) {
|
||||
}
|
||||
|
||||
@override
|
||||
InvenTreeModel createFromJson(Map<String, dynamic> json) {
|
||||
var template = InvenTreePartTestTemplate.fromJson(json);
|
||||
|
||||
return template;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
class InvenTreePart extends InvenTreeModel {
|
||||
|
||||
@override
|
||||
@ -71,31 +94,28 @@ class InvenTreePart extends InvenTreeModel {
|
||||
@override
|
||||
String URL = "part/";
|
||||
|
||||
List<dynamic> testTemplates;
|
||||
List<InvenTreePartTestTemplate> testingTemplates = List<InvenTreePartTestTemplate>();
|
||||
|
||||
int get testTemplateCount {
|
||||
if (testTemplates == null) {
|
||||
return 0;
|
||||
} else {
|
||||
return testTemplates.length;
|
||||
}
|
||||
}
|
||||
int get testTemplateCount => testingTemplates.length;
|
||||
|
||||
Future<void> getTestTemplates() async {
|
||||
Future<void> getTestTemplates(BuildContext context, {bool showDialog=false}) async {
|
||||
|
||||
var response = await api.get("/part/test-template/", params: {
|
||||
InvenTreePartTestTemplate().list(
|
||||
context,
|
||||
filters: {
|
||||
"part": "${pk}",
|
||||
})
|
||||
.timeout(Duration(seconds: 10))
|
||||
.catchError((e) {
|
||||
return;
|
||||
},
|
||||
dialog: showDialog,
|
||||
).then((var templates) {
|
||||
|
||||
testingTemplates.clear();
|
||||
|
||||
for (var t in templates) {
|
||||
if (t is InvenTreePartTestTemplate) {
|
||||
testingTemplates.add(t);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
print("Status: " + response.statusCode.toString());
|
||||
|
||||
testTemplates = json.decode(response.body);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
// Get the number of stock on order for this Part
|
||||
|
@ -42,7 +42,7 @@ class _PartDisplayState extends RefreshableState<PartDetailWidget> {
|
||||
@override
|
||||
Future<void> request(BuildContext context) async {
|
||||
await part.reload(context);
|
||||
await part.getTestTemplates();
|
||||
await part.getTestTemplates(context);
|
||||
}
|
||||
|
||||
void _savePart(Map<String, String> values) async {
|
||||
|
Loading…
x
Reference in New Issue
Block a user