mirror of
https://github.com/inventree/inventree-app.git
synced 2025-04-28 13:36:50 +00:00
Adds pre-generated file for mapping icon names to icon hex values (#235)
* Adds pre-generated file for mapping icon names to icon hex values * Remove unused import * Simple method for converting icon string into useable data * Add rendering for category list and location list * Add custom icons to detail views * Updated release notes
This commit is contained in:
parent
8639ccf79e
commit
f339ac249b
@ -1,6 +1,14 @@
|
|||||||
## InvenTree App Release Notes
|
## InvenTree App Release Notes
|
||||||
---
|
---
|
||||||
|
|
||||||
|
### 0.9.2 - December 2022
|
||||||
|
---
|
||||||
|
|
||||||
|
- Support custom icons for part category
|
||||||
|
- Support custom icons for stock location
|
||||||
|
- Updated translations
|
||||||
|
|
||||||
|
|
||||||
### 0.9.1 - December 2022
|
### 0.9.1 - December 2022
|
||||||
---
|
---
|
||||||
|
|
||||||
|
1461
lib/fa_icon_mapping.dart
Normal file
1461
lib/fa_icon_mapping.dart
Normal file
File diff suppressed because it is too large
Load Diff
@ -10,8 +10,9 @@ import "package:url_launcher/url_launcher.dart";
|
|||||||
|
|
||||||
import "package:path/path.dart" as path;
|
import "package:path/path.dart" as path;
|
||||||
|
|
||||||
import "package:inventree/l10.dart";
|
|
||||||
import "package:inventree/api_form.dart";
|
import "package:inventree/api_form.dart";
|
||||||
|
import "package:inventree/fa_icon_mapping.dart";
|
||||||
|
import "package:inventree/l10.dart";
|
||||||
|
|
||||||
|
|
||||||
// Paginated response object
|
// Paginated response object
|
||||||
@ -148,6 +149,61 @@ class InvenTreeModel {
|
|||||||
// Legacy API provided external link as "URL", while newer API uses "link"
|
// Legacy API provided external link as "URL", while newer API uses "link"
|
||||||
String get link => (jsondata["link"] ?? jsondata["URL"] ?? "") as String;
|
String get link => (jsondata["link"] ?? jsondata["URL"] ?? "") as String;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Attempt to extract a custom icon for this model.
|
||||||
|
* If icon data is provided, attempt to convert to a FontAwesome icon
|
||||||
|
*
|
||||||
|
* Icon data *should* be presented something like "fas fa-boxes" / "fab fa-github" (etc):
|
||||||
|
*
|
||||||
|
* - First part specifies the *style*
|
||||||
|
* - Second part specifies the icon
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
FaIcon? get customIcon {
|
||||||
|
String icon = (jsondata["icon"] ?? "").toString();
|
||||||
|
|
||||||
|
// Empty icon (default)
|
||||||
|
if (icon.isEmpty) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
final split = icon.trim().split(" ");
|
||||||
|
|
||||||
|
// Must have two distinct units
|
||||||
|
if (split.length != 2) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
String style = split[0];
|
||||||
|
String name = split[1];
|
||||||
|
|
||||||
|
// Remove "fa-" leading text (if provided)
|
||||||
|
if (name.startsWith("fa-")) {
|
||||||
|
name = name.substring(3);
|
||||||
|
}
|
||||||
|
|
||||||
|
int? iconHex = fontAwesomeIconMap[name];
|
||||||
|
|
||||||
|
// No match for the icon name
|
||||||
|
if (iconHex == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
switch (style) {
|
||||||
|
case "fas":
|
||||||
|
return FaIcon(IconDataSolid(iconHex));
|
||||||
|
case "fab":
|
||||||
|
return FaIcon(IconDataBrands(iconHex));
|
||||||
|
case "fa":
|
||||||
|
return FaIcon(IconDataRegular(iconHex));
|
||||||
|
case "fal":
|
||||||
|
return FaIcon(IconDataLight(iconHex));
|
||||||
|
default:
|
||||||
|
// No match
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/* Extract any custom barcode data available for the model.
|
/* Extract any custom barcode data available for the model.
|
||||||
* Note that old API used 'uid' (only for StockItem),
|
* Note that old API used 'uid' (only for StockItem),
|
||||||
* but this was updated to use 'barcode_hash'
|
* but this was updated to use 'barcode_hash'
|
||||||
|
@ -114,6 +114,7 @@ class _CategoryDisplayState extends RefreshableState<CategoryDisplayWidget> {
|
|||||||
style: TextStyle(fontWeight: FontWeight.bold)
|
style: TextStyle(fontWeight: FontWeight.bold)
|
||||||
),
|
),
|
||||||
subtitle: Text("${category?.description}"),
|
subtitle: Text("${category?.description}"),
|
||||||
|
leading: category!.customIcon ?? FaIcon(FontAwesomeIcons.sitemap),
|
||||||
),
|
),
|
||||||
];
|
];
|
||||||
|
|
||||||
|
@ -112,6 +112,7 @@ class _PaginatedPartCategoryListState extends PaginatedSearchState<PaginatedPart
|
|||||||
title: Text(category.name),
|
title: Text(category.name),
|
||||||
subtitle: Text(category.pathstring),
|
subtitle: Text(category.pathstring),
|
||||||
trailing: Text("${category.partcount}"),
|
trailing: Text("${category.partcount}"),
|
||||||
|
leading: category.customIcon,
|
||||||
onTap: () {
|
onTap: () {
|
||||||
Navigator.push(
|
Navigator.push(
|
||||||
context,
|
context,
|
||||||
|
@ -211,7 +211,7 @@ class _LocationDisplayState extends RefreshableState<LocationDisplayWidget> {
|
|||||||
ListTile(
|
ListTile(
|
||||||
title: Text("${location!.name}"),
|
title: Text("${location!.name}"),
|
||||||
subtitle: Text("${location!.description}"),
|
subtitle: Text("${location!.description}"),
|
||||||
leading: FaIcon(FontAwesomeIcons.boxes),
|
leading: location!.customIcon ?? FaIcon(FontAwesomeIcons.boxes),
|
||||||
),
|
),
|
||||||
];
|
];
|
||||||
|
|
||||||
|
@ -97,6 +97,7 @@ class _PaginatedStockLocationListState extends PaginatedSearchState<PaginatedSto
|
|||||||
title: Text(location.name),
|
title: Text(location.name),
|
||||||
subtitle: Text(location.pathstring),
|
subtitle: Text(location.pathstring),
|
||||||
trailing: Text("${location.itemcount}"),
|
trailing: Text("${location.itemcount}"),
|
||||||
|
leading: location.customIcon,
|
||||||
onTap: () {
|
onTap: () {
|
||||||
Navigator.push(
|
Navigator.push(
|
||||||
context,
|
context,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user