diff --git a/lib/inventree/company.dart b/lib/inventree/company.dart index a5d65b25..da34f14a 100644 --- a/lib/inventree/company.dart +++ b/lib/inventree/company.dart @@ -9,9 +9,6 @@ import 'model.dart'; class InvenTreeCompany extends InvenTreeModel { - @override - String NAME = "Company"; - @override String get URL => "company/"; diff --git a/lib/inventree/model.dart b/lib/inventree/model.dart index 2d18db59..7c708672 100644 --- a/lib/inventree/model.dart +++ b/lib/inventree/model.dart @@ -1,5 +1,6 @@ import 'dart:async'; +import 'package:font_awesome_flutter/font_awesome_flutter.dart'; import 'package:inventree/api.dart'; import 'package:flutter/cupertino.dart'; import 'package:inventree/inventree/sentry.dart'; @@ -44,8 +45,6 @@ class InvenTreeModel { // Note: If the WEB_URL is the same (except for /api/) as URL then just leave blank String WEB_URL = ""; - String NAME = "Model"; - String get webUrl { if (api.isConnected()) { @@ -453,3 +452,60 @@ class InvenTreeModel { } +class InvenTreeAttachment extends InvenTreeModel { + // Class representing an "attachment" file + + InvenTreeAttachment() : super(); + + String get attachment => jsondata["attachment"] ?? ''; + + // Return the filename of the attachment + String get filename { + return attachment.split("/").last; + } + + IconData get icon { + String fn = filename.toLowerCase(); + + if (fn.endsWith(".pdf")) { + return FontAwesomeIcons.filePdf; + } else if (fn.endsWith(".csv")) { + return FontAwesomeIcons.fileCsv; + } else if (fn.endsWith(".doc") || fn.endsWith(".docx")) { + return FontAwesomeIcons.fileWord; + } else if (fn.endsWith(".xls") || fn.endsWith(".xlsx")) { + return FontAwesomeIcons.fileExcel; + } + + // Image formats + final List img_formats = [ + ".png", + ".jpg", + ".gif", + ".bmp", + ".svg", + ]; + + for (String fmt in img_formats) { + if (fn.endsWith(fmt)) { + return FontAwesomeIcons.fileImage; + } + } + + return FontAwesomeIcons.fileAlt; + } + + String get comment => jsondata["comment"] ?? ''; + + DateTime? get uploadDate { + if (jsondata.containsKey("upload_date")) { + return DateTime.tryParse(jsondata["upload_date"] ?? ''); + } else { + return null; + } + } + + InvenTreeAttachment.fromJson(Map json) : super.fromJson(json); +} + + diff --git a/lib/inventree/part.dart b/lib/inventree/part.dart index 57678467..dcd18df3 100644 --- a/lib/inventree/part.dart +++ b/lib/inventree/part.dart @@ -10,9 +10,6 @@ import 'package:http/http.dart' as http; class InvenTreePartCategory extends InvenTreeModel { - @override - String NAME = "PartCategory"; - @override String get URL => "part/category/"; @@ -74,9 +71,6 @@ class InvenTreePartCategory extends InvenTreeModel { class InvenTreePartTestTemplate extends InvenTreeModel { - @override - String NAME = "PartTestTemplate"; - @override String get URL => "part/test-template/"; @@ -131,9 +125,6 @@ class InvenTreePartTestTemplate extends InvenTreeModel { class InvenTreePart extends InvenTreeModel { - @override - String NAME = "Part"; - @override String get URL => "part/"; @@ -396,4 +387,21 @@ class InvenTreePart extends InvenTreeModel { return part; } +} + + +class InvenTreePartAttachment extends InvenTreeAttachment { + + InvenTreePartAttachment() : super(); + + @override + String get URL => "part/attachment/"; + + InvenTreePartAttachment.fromJson(Map json) : super.fromJson(json); + + @override + InvenTreeModel createFromJson(Map json) { + return InvenTreePartAttachment.fromJson(json); + } + } \ No newline at end of file diff --git a/lib/inventree/stock.dart b/lib/inventree/stock.dart index ac03a1fa..c83cba08 100644 --- a/lib/inventree/stock.dart +++ b/lib/inventree/stock.dart @@ -14,9 +14,6 @@ import 'package:inventree/api.dart'; class InvenTreeStockItemTestResult extends InvenTreeModel { - @override - String NAME = "StockItemTestResult"; - @override String get URL => "stock/test/"; @@ -99,9 +96,6 @@ class InvenTreeStockItem extends InvenTreeModel { } } - @override - String NAME = "StockItem"; - @override String get URL => "stock/"; @@ -464,11 +458,7 @@ class InvenTreeStockItem extends InvenTreeModel { @override InvenTreeModel createFromJson(Map json) { - var item = InvenTreeStockItem.fromJson(json); - - // TODO? - - return item; + return InvenTreeStockItem.fromJson(json); } /* @@ -553,9 +543,6 @@ class InvenTreeStockItem extends InvenTreeModel { class InvenTreeStockLocation extends InvenTreeModel { - @override - String NAME = "StockLocation"; - @override String get URL => "stock/location/"; @@ -591,9 +578,7 @@ class InvenTreeStockLocation extends InvenTreeModel { InvenTreeStockLocation() : super(); - InvenTreeStockLocation.fromJson(Map json) : super.fromJson(json) { - // TODO - } + InvenTreeStockLocation.fromJson(Map json) : super.fromJson(json); @override InvenTreeModel createFromJson(Map json) { diff --git a/lib/l10n b/lib/l10n index 94daf512..20dce387 160000 --- a/lib/l10n +++ b/lib/l10n @@ -1 +1 @@ -Subproject commit 94daf51226f555c1c3a7ad4893931727d0369dda +Subproject commit 20dce387ab4088e22b67c6ffd1fb50b6a1f252e8