mirror of
https://github.com/inventree/inventree-app.git
synced 2025-04-28 05:26:47 +00:00
rename InvenTreeObject to InvenTreeModel
This commit is contained in:
parent
cc4f5091c7
commit
e9b0cc3128
@ -7,10 +7,10 @@ import 'package:http/http.dart' as http;
|
|||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The InvenTreeObject class provides a base-level object
|
* The InvenTreeModel class provides a base-level object
|
||||||
* for interacting with InvenTree data.
|
* for interacting with InvenTree data.
|
||||||
*/
|
*/
|
||||||
class InvenTreeObject {
|
class InvenTreeModel {
|
||||||
|
|
||||||
// Override the endpoint URL for each subclass
|
// Override the endpoint URL for each subclass
|
||||||
String URL = "";
|
String URL = "";
|
||||||
@ -22,12 +22,12 @@ class InvenTreeObject {
|
|||||||
var api = InvenTreeAPI();
|
var api = InvenTreeAPI();
|
||||||
|
|
||||||
// Default empty object constructor
|
// Default empty object constructor
|
||||||
InvenTreeObject() {
|
InvenTreeModel() {
|
||||||
jsondata.clear();
|
jsondata.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Construct an InvenTreeObject from a JSON data object
|
// Construct an InvenTreeModel from a JSON data object
|
||||||
InvenTreeObject.fromJson(Map<String, dynamic> json) {
|
InvenTreeModel.fromJson(Map<String, dynamic> json) {
|
||||||
|
|
||||||
// Store the json object
|
// Store the json object
|
||||||
jsondata = json;
|
jsondata = json;
|
||||||
@ -44,31 +44,47 @@ class InvenTreeObject {
|
|||||||
int get parentId => jsondata['parent'] ?? -1;
|
int get parentId => jsondata['parent'] ?? -1;
|
||||||
|
|
||||||
// Create a new object from JSON data (not a constructor!)
|
// Create a new object from JSON data (not a constructor!)
|
||||||
InvenTreeObject createFromJson(Map<String, dynamic> json) {
|
InvenTreeModel createFromJson(Map<String, dynamic> json) {
|
||||||
|
|
||||||
var obj = InvenTreeObject.fromJson(json);
|
var obj = InvenTreeModel.fromJson(json);
|
||||||
|
|
||||||
return obj;
|
return obj;
|
||||||
}
|
}
|
||||||
|
|
||||||
String get url{ return path.join(URL, pk.toString()); }
|
String get url{ return path.join(URL, pk.toString()); }
|
||||||
|
|
||||||
|
/*
|
||||||
|
// Search this Model type in the database
|
||||||
|
Future<List<InvenTreeModel>> search(String searchTerm) async {
|
||||||
|
|
||||||
|
String addr = url + "?search=" + search;
|
||||||
|
|
||||||
|
print("Searching endpoint: $url");
|
||||||
|
|
||||||
|
// TODO - Add "timeout"
|
||||||
|
// TODO - Add error catching
|
||||||
|
|
||||||
|
var response =
|
||||||
|
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
// Return list of objects from the database, with optional filters
|
// Return list of objects from the database, with optional filters
|
||||||
Future<List<InvenTreeObject>> list({Map<String, String> filters}) async {
|
Future<List<InvenTreeModel>> list({Map<String, String> filters}) async {
|
||||||
|
|
||||||
if (filters == null) {
|
if (filters == null) {
|
||||||
filters = {};
|
filters = {};
|
||||||
}
|
}
|
||||||
|
|
||||||
print("Listing endpoint: " + URL);
|
print("Listing endpoint: $URL");
|
||||||
|
|
||||||
// TODO - Add "timeout"
|
// TODO - Add "timeout"
|
||||||
// TODO - Add error catching
|
// TODO - Add error catching
|
||||||
|
|
||||||
var response = await InvenTreeAPI().get(URL, params:filters);
|
var response = await InvenTreeAPI().get(URL, params:filters);
|
||||||
|
|
||||||
// A list of "InvenTreeObject" items
|
// A list of "InvenTreeModel" items
|
||||||
List<InvenTreeObject> results = new List<InvenTreeObject>();
|
List<InvenTreeModel> results = new List<InvenTreeModel>();
|
||||||
|
|
||||||
if (response.statusCode != 200) {
|
if (response.statusCode != 200) {
|
||||||
print("Error retreiving data");
|
print("Error retreiving data");
|
||||||
@ -84,7 +100,7 @@ class InvenTreeObject {
|
|||||||
for (var d in data) {
|
for (var d in data) {
|
||||||
|
|
||||||
// Create a new object (of the current class type
|
// Create a new object (of the current class type
|
||||||
InvenTreeObject obj = createFromJson(d);
|
InvenTreeModel obj = createFromJson(d);
|
||||||
|
|
||||||
if (obj != null) {
|
if (obj != null) {
|
||||||
results.add(obj);
|
results.add(obj);
|
||||||
|
@ -6,7 +6,7 @@ import 'dart:convert';
|
|||||||
import 'package:path/path.dart' as path;
|
import 'package:path/path.dart' as path;
|
||||||
import 'package:http/http.dart' as http;
|
import 'package:http/http.dart' as http;
|
||||||
|
|
||||||
class InvenTreePartCategory extends InvenTreeObject {
|
class InvenTreePartCategory extends InvenTreeModel {
|
||||||
@override
|
@override
|
||||||
String URL = "part/category/";
|
String URL = "part/category/";
|
||||||
|
|
||||||
@ -19,7 +19,7 @@ class InvenTreePartCategory extends InvenTreeObject {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
InvenTreeObject createFromJson(Map<String, dynamic> json) {
|
InvenTreeModel createFromJson(Map<String, dynamic> json) {
|
||||||
var cat = InvenTreePartCategory.fromJson(json);
|
var cat = InvenTreePartCategory.fromJson(json);
|
||||||
|
|
||||||
// TODO ?
|
// TODO ?
|
||||||
@ -29,7 +29,7 @@ class InvenTreePartCategory extends InvenTreeObject {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
class InvenTreePart extends InvenTreeObject {
|
class InvenTreePart extends InvenTreeModel {
|
||||||
|
|
||||||
@override
|
@override
|
||||||
String URL = "part/";
|
String URL = "part/";
|
||||||
@ -45,7 +45,7 @@ class InvenTreePart extends InvenTreeObject {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
InvenTreeObject createFromJson(Map<String, dynamic> json) {
|
InvenTreeModel createFromJson(Map<String, dynamic> json) {
|
||||||
|
|
||||||
var part = InvenTreePart.fromJson(json);
|
var part = InvenTreePart.fromJson(json);
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user