mirror of
https://github.com/inventree/inventree-app.git
synced 2025-04-28 13:36:50 +00:00
* Catch paginator bug if widget is disposed before request returns * Refactoring paginated query widget - Add option to enable / disable search filters * Major refactor of paginated search widget - Learned something new.. a state can access widget.<attribute> - THIS CHANGES EVERTHING * Preferences: Add code for tri-state values - Also improve unit testing for preferences code * Allow boolean form fields to be optionally tristate * paginator: Allow custom boolean filters * Remove outdated filtering preferences * Refactor filter options - Allow specification of more detailed options * Add custom filters for "part" list * filter tweaks * Remove legacy "SublocationList" widget * Add filtering option for locationlist * Updates for stock location widget * Refactor category display widget * More widget refactoring * Update main search widget * Fix unit tests * Improve filtering on BOM display page
154 lines
3.7 KiB
Dart
154 lines
3.7 KiB
Dart
import "package:flutter/material.dart";
|
|
import "package:font_awesome_flutter/font_awesome_flutter.dart";
|
|
|
|
import "package:inventree/api.dart";
|
|
import "package:inventree/l10.dart";
|
|
|
|
import "package:inventree/inventree/model.dart";
|
|
import "package:inventree/inventree/part.dart";
|
|
|
|
import "package:inventree/widget/paginator.dart";
|
|
import "package:inventree/widget/part_detail.dart";
|
|
import "package:inventree/widget/refreshable_state.dart";
|
|
|
|
|
|
class PartList extends StatefulWidget {
|
|
|
|
const PartList(this.filters, {this.title = ""});
|
|
|
|
final String title;
|
|
|
|
final Map<String, String> filters;
|
|
|
|
@override
|
|
_PartListState createState() => _PartListState(filters, title);
|
|
}
|
|
|
|
|
|
class _PartListState extends RefreshableState<PartList> {
|
|
|
|
_PartListState(this.filters, this.title);
|
|
|
|
final String title;
|
|
|
|
final Map<String, String> filters;
|
|
|
|
bool showFilterOptions = false;
|
|
|
|
@override
|
|
String getAppBarTitle(BuildContext context) => title.isNotEmpty ? title : L10().parts;
|
|
|
|
@override
|
|
List<Widget> getAppBarActions(BuildContext context) => [
|
|
IconButton(
|
|
icon: FaIcon(FontAwesomeIcons.filter),
|
|
onPressed: () async {
|
|
setState(() {
|
|
showFilterOptions = !showFilterOptions;
|
|
});
|
|
},
|
|
)
|
|
];
|
|
|
|
@override
|
|
Widget getBody(BuildContext context) {
|
|
return PaginatedPartList(filters, showFilterOptions);
|
|
}
|
|
|
|
}
|
|
|
|
|
|
class PaginatedPartList extends PaginatedSearchWidget {
|
|
|
|
const PaginatedPartList(Map<String, String> filters, bool showSearch) : super(filters: filters, showSearch: showSearch);
|
|
|
|
@override
|
|
_PaginatedPartListState createState() => _PaginatedPartListState();
|
|
}
|
|
|
|
|
|
class _PaginatedPartListState extends PaginatedSearchState<PaginatedPartList> {
|
|
|
|
_PaginatedPartListState() : super();
|
|
|
|
@override
|
|
String get prefix => "part_";
|
|
|
|
@override
|
|
Map<String, String> get orderingOptions => {
|
|
"name": L10().name,
|
|
"in_stock": L10().stock,
|
|
"IPN": L10().internalPartNumber,
|
|
};
|
|
|
|
@override
|
|
Map<String, Map<String, dynamic>> get filterOptions => {
|
|
"cascade": {
|
|
"default": true,
|
|
"label": L10().includeSubcategories,
|
|
"help_text": L10().includeSubcategoriesDetail,
|
|
},
|
|
"active": {
|
|
"label": L10().filterActive,
|
|
"help_text": L10().filterActiveDetail,
|
|
},
|
|
"assembly": {
|
|
"label": L10().filterAssembly,
|
|
"help_text": L10().filterAssemblyDetail
|
|
},
|
|
"component": {
|
|
"label": L10().filterComponent,
|
|
"help_text": L10().filterComponentDetail,
|
|
},
|
|
"is_template": {
|
|
"label": L10().filterTemplate,
|
|
"help_text": L10().filterTemplateDetail
|
|
},
|
|
"virtual": {
|
|
"label": L10().filterVirtual,
|
|
"help_text": L10().filterVirtualDetail,
|
|
},
|
|
"has_stock": {
|
|
"label": L10().filterInStock,
|
|
"help_text": L10().filterInStockDetail,
|
|
}
|
|
};
|
|
|
|
@override
|
|
Future<InvenTreePageResponse?> requestPage(int limit, int offset, Map<String, String> params) async {
|
|
|
|
final page = await InvenTreePart().listPaginated(limit, offset, filters: params);
|
|
|
|
return page;
|
|
}
|
|
|
|
void _openPart(BuildContext context, int pk) {
|
|
// Attempt to load the part information
|
|
InvenTreePart().get(pk).then((var part) {
|
|
if (part is InvenTreePart) {
|
|
|
|
Navigator.push(context, MaterialPageRoute(builder: (context) => PartDetailWidget(part)));
|
|
}
|
|
});
|
|
}
|
|
|
|
@override
|
|
Widget buildItem(BuildContext context, InvenTreeModel model) {
|
|
|
|
InvenTreePart part = model as InvenTreePart;
|
|
|
|
return ListTile(
|
|
title: Text(part.fullname),
|
|
subtitle: Text(part.description),
|
|
trailing: Text(part.stockString()),
|
|
leading: InvenTreeAPI().getImage(
|
|
part.thumbnail,
|
|
width: 40,
|
|
height: 40,
|
|
),
|
|
onTap: () {
|
|
_openPart(context, part.pk);
|
|
},
|
|
);
|
|
}
|
|
} |