From 8bd022bccdaf237b729d119807ba564bcdedc336 Mon Sep 17 00:00:00 2001 From: Oliver Walters Date: Tue, 14 Apr 2020 22:18:05 +1000 Subject: [PATCH] Progress dialog is now a part of the model GET request --- lib/barcode.dart | 25 +++---------------------- lib/inventree/company.dart | 4 ++++ lib/inventree/model.dart | 10 +++++++++- lib/inventree/part.dart | 7 +++++++ lib/inventree/stock.dart | 8 ++++++++ lib/widget/category_display.dart | 6 +++--- lib/widget/company_list.dart | 2 +- lib/widget/location_display.dart | 6 +++--- lib/widget/part_detail.dart | 2 +- lib/widget/stock_detail.dart | 4 ++-- 10 files changed, 41 insertions(+), 33 deletions(-) diff --git a/lib/barcode.dart b/lib/barcode.dart index 9f608a33..fc1d02c1 100644 --- a/lib/barcode.dart +++ b/lib/barcode.dart @@ -98,14 +98,7 @@ void _handleBarcode(BuildContext context, Map data) { id = data['stocklocation']['id'] ?? null; if (id != null) { - // Try to open a stock location... - - showProgressDialog(context, "Loading data", "Requesting stock location information from server"); - - InvenTreeStockLocation().get(id).then((var loc) { - - hideProgressDialog(context); - + InvenTreeStockLocation().get(context, id).then((var loc) { if (loc is InvenTreeStockLocation) { Navigator.push(context, MaterialPageRoute(builder: (context) => LocationDisplayWidget(loc))); } @@ -117,13 +110,7 @@ void _handleBarcode(BuildContext context, Map data) { id = data['stockitem']['id'] ?? null; if (id != null) { - - showProgressDialog(context, "Loading data", "Requesting stock item information from server"); - - InvenTreeStockItem().get(id).then((var item) { - - hideProgressDialog(context); - + InvenTreeStockItem().get(context, id).then((var item) { Navigator.push(context, MaterialPageRoute(builder: (context) => StockDetailWidget(item))); }); } @@ -132,13 +119,7 @@ void _handleBarcode(BuildContext context, Map data) { id = data['part']['id'] ?? null; if (id != null) { - - showProgressDialog(context, "Loading data", "Requesting part information from server"); - - InvenTreePart().get(id).then((var part) { - - hideProgressDialog(context); - + InvenTreePart().get(context, id).then((var part) { Navigator.push(context, MaterialPageRoute(builder: (context) => PartDetailWidget(part))); }); diff --git a/lib/inventree/company.dart b/lib/inventree/company.dart index 74ff87c8..7958d7f3 100644 --- a/lib/inventree/company.dart +++ b/lib/inventree/company.dart @@ -5,6 +5,10 @@ import 'model.dart'; * The InvenTreeCompany class repreents the Company model in the InvenTree database. */ class InvenTreeCompany extends InvenTreeModel { + + @override + String NAME = "Company"; + @override String URL = "company/"; diff --git a/lib/inventree/model.dart b/lib/inventree/model.dart index a501ce7a..47b4bf6d 100644 --- a/lib/inventree/model.dart +++ b/lib/inventree/model.dart @@ -1,4 +1,6 @@ import 'package:InvenTree/api.dart'; +import 'package:InvenTree/widget/dialogs.dart'; +import 'package:flutter/cupertino.dart'; import 'dart:convert'; @@ -15,6 +17,8 @@ class InvenTreeModel { // Override the endpoint URL for each subclass String URL = ""; + String NAME = "Model"; + // JSON data which defines this object Map jsondata = {}; @@ -100,7 +104,7 @@ class InvenTreeModel { } // Return the detail view for the associated pk - Future get(int pk, {Map filters}) async { + Future get(BuildContext context, int pk, {Map filters}) async { // TODO - Add "timeout" // TODO - Add error catching @@ -122,8 +126,12 @@ class InvenTreeModel { print("GET: $addr ${params.toString()}"); + showProgressDialog(context, "Requesting Data", "Requesting ${NAME} data from server"); + var response = await api.get(addr, params: params); + hideProgressDialog(context); + if (response.statusCode != 200) { print("Error retrieving data"); return null; diff --git a/lib/inventree/part.dart b/lib/inventree/part.dart index 3283a19c..4732fa2a 100644 --- a/lib/inventree/part.dart +++ b/lib/inventree/part.dart @@ -9,6 +9,10 @@ import 'package:path/path.dart' as path; import 'package:http/http.dart' as http; class InvenTreePartCategory extends InvenTreeModel { + + @override + String NAME = "PartCategory"; + @override String URL = "part/category/"; @@ -61,6 +65,9 @@ class InvenTreePartCategory extends InvenTreeModel { class InvenTreePart extends InvenTreeModel { + @override + String Name = "Part"; + @override String URL = "part/"; diff --git a/lib/inventree/stock.dart b/lib/inventree/stock.dart index e8cfcf22..ebcef711 100644 --- a/lib/inventree/stock.dart +++ b/lib/inventree/stock.dart @@ -6,6 +6,10 @@ import 'model.dart'; import 'package:InvenTree/api.dart'; class InvenTreeStockItem extends InvenTreeModel { + + @override + String NAME = "StockItem"; + @override String URL = "stock/"; @@ -208,6 +212,10 @@ class InvenTreeStockItem extends InvenTreeModel { class InvenTreeStockLocation extends InvenTreeModel { + + @override + String NAME = "StockLocation"; + @override String URL = "stock/location/"; diff --git a/lib/widget/category_display.dart b/lib/widget/category_display.dart index 7f7f47d2..4de2ac42 100644 --- a/lib/widget/category_display.dart +++ b/lib/widget/category_display.dart @@ -112,7 +112,7 @@ class _CategoryDisplayState extends State { Navigator.push(context, MaterialPageRoute(builder: (context) => CategoryDisplayWidget(null))); } else { // TODO - Refactor this code into the InvenTreePart class - InvenTreePartCategory().get(category.parentId).then((var cat) { + InvenTreePartCategory().get(context, category.parentId).then((var cat) { if (cat is InvenTreePartCategory) { Navigator.push(context, MaterialPageRoute(builder: (context) => CategoryDisplayWidget(cat))); } @@ -211,7 +211,7 @@ class SubcategoryList extends StatelessWidget { void _openCategory(BuildContext context, int pk) { // Attempt to load the sub-category. - InvenTreePartCategory().get(pk).then((var cat) { + InvenTreePartCategory().get(context, pk).then((var cat) { if (cat is InvenTreePartCategory) { Navigator.push(context, MaterialPageRoute(builder: (context) => CategoryDisplayWidget(cat))); @@ -252,7 +252,7 @@ class PartList extends StatelessWidget { void _openPart(BuildContext context, int pk) { // Attempt to load the part information - InvenTreePart().get(pk).then((var part) { + InvenTreePart().get(context, pk).then((var part) { if (part is InvenTreePart) { Navigator.push(context, MaterialPageRoute(builder: (context) => PartDetailWidget(part))); diff --git a/lib/widget/company_list.dart b/lib/widget/company_list.dart index 512c198f..760a9b8c 100644 --- a/lib/widget/company_list.dart +++ b/lib/widget/company_list.dart @@ -85,7 +85,7 @@ class _CompanyListState extends State { ), onTap: () { if (company.pk > 0) { - InvenTreeCompany().get(company.pk).then((var c) { + InvenTreeCompany().get(context, company.pk).then((var c) { Navigator.push(context, MaterialPageRoute(builder: (context) => CompanyDetailWidget(c))); }); } diff --git a/lib/widget/location_display.dart b/lib/widget/location_display.dart index fa1456ac..15b970f1 100644 --- a/lib/widget/location_display.dart +++ b/lib/widget/location_display.dart @@ -119,7 +119,7 @@ class _LocationDisplayState extends State { if (location.parentId < 0) { Navigator.push(context, MaterialPageRoute(builder: (context) => LocationDisplayWidget(null))); } else { - InvenTreeStockLocation().get(location.parentId).then((var loc) { + InvenTreeStockLocation().get(context, location.parentId).then((var loc) { if (loc is InvenTreeStockLocation) { Navigator.push(context, MaterialPageRoute(builder: (context) => LocationDisplayWidget(loc))); } @@ -208,7 +208,7 @@ class SublocationList extends StatelessWidget { void _openLocation(BuildContext context, int pk) { - InvenTreeStockLocation().get(pk).then((var loc) { + InvenTreeStockLocation().get(context, pk).then((var loc) { if (loc is InvenTreeStockLocation) { Navigator.push(context, MaterialPageRoute(builder: (context) => LocationDisplayWidget(loc))); @@ -244,7 +244,7 @@ class StockList extends StatelessWidget { StockList(this._items); void _openItem(BuildContext context, int pk) { - InvenTreeStockItem().get(pk).then((var item) { + InvenTreeStockItem().get(context, pk).then((var item) { if (item is InvenTreeStockItem) { Navigator.push(context, MaterialPageRoute(builder: (context) => StockDetailWidget(item))); } diff --git a/lib/widget/part_detail.dart b/lib/widget/part_detail.dart index e207db40..3c441a1b 100644 --- a/lib/widget/part_detail.dart +++ b/lib/widget/part_detail.dart @@ -62,7 +62,7 @@ class _PartDisplayState extends State { leading: FaIcon(FontAwesomeIcons.stream), onTap: () { if (part.categoryId > 0) { - InvenTreePartCategory().get(part.categoryId).then((var cat) { + InvenTreePartCategory().get(context, part.categoryId).then((var cat) { Navigator.push(context, MaterialPageRoute( builder: (context) => CategoryDisplayWidget(cat))); }); diff --git a/lib/widget/stock_detail.dart b/lib/widget/stock_detail.dart index a76873e5..175db487 100644 --- a/lib/widget/stock_detail.dart +++ b/lib/widget/stock_detail.dart @@ -322,7 +322,7 @@ class _StockItemDisplayState extends State { leading: FaIcon(FontAwesomeIcons.shapes), onTap: () { if (item.partId > 0) { - InvenTreePart().get(item.partId).then((var part) { + InvenTreePart().get(context, item.partId).then((var part) { if (part is InvenTreePart) { Navigator.push(context, MaterialPageRoute(builder: (context) => PartDetailWidget(part))); } @@ -362,7 +362,7 @@ class _StockItemDisplayState extends State { leading: FaIcon(FontAwesomeIcons.mapMarkerAlt), onTap: () { if (item.locationId > 0) { - InvenTreeStockLocation().get(item.locationId).then((var loc) { + InvenTreeStockLocation().get(context, item.locationId).then((var loc) { Navigator.push(context, MaterialPageRoute( builder: (context) => LocationDisplayWidget(loc))); });