Skip to content

Commit

Permalink
Bom optional (#227)
Browse files Browse the repository at this point in the history
* Split part settings onto different screen

* show_bom setting controls whether BOM information is displayed

* linting
  • Loading branch information
SchrodingersGat authored Dec 4, 2022
1 parent 971c6bf commit efb6fc3
Show file tree
Hide file tree
Showing 7 changed files with 145 additions and 95 deletions.
1 change: 1 addition & 0 deletions assets/release_notes.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
- Add support for structural part categories
- Add support for structural stock locations
- Allow deletion of attachments via app
- Adds option for controlling BOM display
- Updated translations


Expand Down
6 changes: 6 additions & 0 deletions lib/l10n/app_en.arb
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,9 @@
"bom": "BOM",
"@bom": {},

"bomEnable": "Display Bill of Materials",
"@bomEnable": {},

"build": "Build",
"@build": {},

Expand Down Expand Up @@ -619,6 +622,9 @@
"partNoResults": "No parts matching query",
"@partNoResults": {},

"partSettings": "Part Settings",
"@partSettings": {},

"partsStarred": "Subscribed Parts",
"@partsStarred": {},

Expand Down
3 changes: 1 addition & 2 deletions lib/preferences.dart
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,14 @@ const String INV_SOUNDS_SERVER = "serverSounds";

// Part settings
const String INV_PART_SHOW_PARAMETERS = "partShowParameters";
const String INV_PART_SHOW_BOM = "partShowBom";

// Stock settings
const String INV_STOCK_SHOW_HISTORY = "stockShowHistory";

const String INV_REPORT_ERRORS = "reportErrors";

const String INV_STRICT_HTTPS = "strictHttps";


/*
* Class for storing InvenTree preferences in a NoSql DB
*/
Expand Down
55 changes: 0 additions & 55 deletions lib/settings/app_settings.dart
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,6 @@ class _InvenTreeAppSettingsState extends State<InvenTreeAppSettingsWidget> {
bool barcodeSounds = true;
bool serverSounds = true;

// Part settings
bool partShowParameters = true;

// Stock settings
bool stockShowHistory = false;

bool reportErrors = true;
bool strictHttps = false;

Expand All @@ -44,16 +38,8 @@ class _InvenTreeAppSettingsState extends State<InvenTreeAppSettingsWidget> {
}

Future <void> loadSettings() async {

// Load initial settings

barcodeSounds = await InvenTreeSettingsManager().getValue(INV_SOUNDS_BARCODE, true) as bool;
serverSounds = await InvenTreeSettingsManager().getValue(INV_SOUNDS_SERVER, true) as bool;

partShowParameters = await InvenTreeSettingsManager().getValue(INV_PART_SHOW_PARAMETERS, true) as bool;

stockShowHistory = await InvenTreeSettingsManager().getValue(INV_STOCK_SHOW_HISTORY, false) as bool;

reportErrors = await InvenTreeSettingsManager().getValue(INV_REPORT_ERRORS, true) as bool;
strictHttps = await InvenTreeSettingsManager().getValue(INV_STRICT_HTTPS, false) as bool;

Expand Down Expand Up @@ -137,47 +123,6 @@ class _InvenTreeAppSettingsState extends State<InvenTreeAppSettingsWidget> {
body: Container(
child: ListView(
children: [
/* Part Settings */
ListTile(
title: Text(L10().part, style: TextStyle(fontWeight: FontWeight.bold)),
leading: FaIcon(FontAwesomeIcons.shapes),
),
ListTile(
title: Text(L10().parameters),
subtitle: Text(L10().parametersSettingDetail),
leading: FaIcon(FontAwesomeIcons.thList),
trailing: Switch(
value: partShowParameters,
onChanged: (bool value) {
InvenTreeSettingsManager().setValue(INV_PART_SHOW_PARAMETERS, value);
setState(() {
partShowParameters = value;
});
},
),
),
Divider(),
/* Stock Settings */
ListTile(
title: Text(L10().stock,
style: TextStyle(fontWeight: FontWeight.bold),
),
leading: FaIcon(FontAwesomeIcons.boxes),
),
ListTile(
title: Text(L10().stockItemHistory),
subtitle: Text(L10().stockItemHistoryDetail),
leading: FaIcon(FontAwesomeIcons.history),
trailing: Switch(
value: stockShowHistory,
onChanged: (bool value) {
InvenTreeSettingsManager().setValue(INV_STOCK_SHOW_HISTORY, value);
setState(() {
stockShowHistory = value;
});
},
),
),
/* Sound Settings */
Divider(height: 3),
ListTile(
Expand Down
94 changes: 94 additions & 0 deletions lib/settings/part_settings.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@

import "package:flutter/material.dart";
import "package:font_awesome_flutter/font_awesome_flutter.dart";
import "package:inventree/l10.dart";
import "package:inventree/preferences.dart";


class InvenTreePartSettingsWidget extends StatefulWidget {
@override
_InvenTreePartSettingsState createState() => _InvenTreePartSettingsState();
}


class _InvenTreePartSettingsState extends State<InvenTreePartSettingsWidget> {

_InvenTreePartSettingsState();

bool partShowParameters = true;
bool partShowBom = true;
bool stockShowHistory = false;

@override
void initState() {
super.initState();

loadSettings();
}

Future<void> loadSettings() async {
partShowParameters = await InvenTreeSettingsManager().getValue(INV_PART_SHOW_PARAMETERS, true) as bool;
partShowBom = await InvenTreeSettingsManager().getValue(INV_PART_SHOW_BOM, true) as bool;
stockShowHistory = await InvenTreeSettingsManager().getValue(INV_STOCK_SHOW_HISTORY, false) as bool;

if (mounted) {
setState(() {
});
}
}

@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(title: Text(L10().part)),
body: Container(
child: ListView(
children: [
ListTile(
title: Text(L10().parameters),
subtitle: Text(L10().parametersSettingDetail),
leading: FaIcon(FontAwesomeIcons.thList),
trailing: Switch(
value: partShowParameters,
onChanged: (bool value) {
InvenTreeSettingsManager().setValue(INV_PART_SHOW_PARAMETERS, value);
setState(() {
partShowParameters = value;
});
},
),
),
ListTile(
title: Text(L10().bom),
subtitle: Text(L10().bomEnable),
leading: FaIcon(FontAwesomeIcons.list),
trailing: Switch(
value: partShowBom,
onChanged: (bool value) {
InvenTreeSettingsManager().setValue(INV_PART_SHOW_BOM, value);
setState(() {
partShowBom = value;
});
},
),
),
ListTile(
title: Text(L10().stockItemHistory),
subtitle: Text(L10().stockItemHistoryDetail),
leading: FaIcon(FontAwesomeIcons.history),
trailing: Switch(
value: stockShowHistory,
onChanged: (bool value) {
InvenTreeSettingsManager().setValue(INV_STOCK_SHOW_HISTORY, value);
setState(() {
stockShowHistory = value;
});
},
),
),
]
)
)
);
}
}
43 changes: 22 additions & 21 deletions lib/settings/settings.dart
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import "package:flutter/material.dart";
import "package:font_awesome_flutter/font_awesome_flutter.dart";

import "package:inventree/app_colors.dart";
import "package:inventree/l10.dart";
import "package:inventree/settings/app_settings.dart";
import "package:inventree/settings/home_settings.dart";
import "package:inventree/settings/login.dart";

import "package:flutter/material.dart";
import "package:font_awesome_flutter/font_awesome_flutter.dart";
import "package:inventree/l10.dart";
import "package:inventree/settings/part_settings.dart";


class InvenTreeSettingsWidget extends StatefulWidget {
Expand Down Expand Up @@ -37,38 +38,38 @@ class _InvenTreeSettingsState extends State<InvenTreeSettingsWidget> {
title: Text(L10().server),
subtitle: Text(L10().configureServer),
leading: FaIcon(FontAwesomeIcons.server, color: COLOR_CLICK),
onTap: _editServerSettings,
onTap: () {
Navigator.push(context, MaterialPageRoute(builder: (context) => InvenTreeLoginSettingsWidget()));
},
),
ListTile(
title: Text(L10().homeScreen),
subtitle: Text(L10().homeScreenSettings),
leading: FaIcon(FontAwesomeIcons.home, color: COLOR_CLICK),
onTap: _editHomeScreenSettings,
onTap: () {
Navigator.push(context, MaterialPageRoute(builder: (context) => HomeScreenSettingsWidget()));
}
),
ListTile(
title: Text(L10().appSettings),
subtitle: Text(L10().appSettingsDetails),
leading: FaIcon(FontAwesomeIcons.cogs, color: COLOR_CLICK),
onTap: _editAppSettings,
onTap: () {
Navigator.push(context, MaterialPageRoute(builder: (context) => InvenTreeAppSettingsWidget()));
}
),
ListTile(
title: Text(L10().part),
subtitle: Text(L10().partSettings),
leading: FaIcon(FontAwesomeIcons.shapes, color: COLOR_CLICK),
onTap: () {
Navigator.push(context, MaterialPageRoute(builder: (context) => InvenTreePartSettingsWidget()));
}
)
]
).toList()
)
)
);
}

Future <void> _editServerSettings() async {

Navigator.push(context, MaterialPageRoute(builder: (context) => InvenTreeLoginSettingsWidget()));
}

Future<void> _editHomeScreenSettings() async {
Navigator.push(context, MaterialPageRoute(builder: (context) => HomeScreenSettingsWidget()));
}

Future <void> _editAppSettings() async {
Navigator.push(context, MaterialPageRoute(builder: (context) => InvenTreeAppSettingsWidget()));
}

}
38 changes: 21 additions & 17 deletions lib/widget/part_detail.dart
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ class _PartDisplayState extends RefreshableState<PartDetailWidget> {

bool showParameters = false;

bool showBom = false;

int attachmentCount = 0;

int bomCount = 0;
Expand Down Expand Up @@ -169,6 +171,8 @@ class _PartDisplayState extends RefreshableState<PartDetailWidget> {
}
});

showBom = await InvenTreeSettingsManager().getValue(INV_PART_SHOW_BOM, true) as bool;

// Request the number of BOM items
InvenTreePart().count(
filters: {
Expand Down Expand Up @@ -424,7 +428,7 @@ class _PartDisplayState extends RefreshableState<PartDetailWidget> {
// Tiles for an "assembly" part
if (part.isAssembly) {

if (bomCount > 0) {
if (showBom && bomCount > 0) {
tiles.add(
ListTile(
title: Text(L10().billOfMaterials),
Expand Down Expand Up @@ -457,7 +461,7 @@ class _PartDisplayState extends RefreshableState<PartDetailWidget> {
}

if (part.isComponent) {
if (usedInCount > 0) {
if (showBom && usedInCount > 0) {
tiles.add(
ListTile(
title: Text(L10().usedIn),
Expand Down Expand Up @@ -534,21 +538,6 @@ class _PartDisplayState extends RefreshableState<PartDetailWidget> {
);
}

// Notes field
tiles.add(
ListTile(
title: Text(L10().notes),
leading: FaIcon(FontAwesomeIcons.stickyNote, color: COLOR_CLICK),
trailing: Text(""),
onTap: () {
Navigator.push(
context,
MaterialPageRoute(builder: (context) => PartNotesWidget(part))
);
},
)
);

if (showParameters) {
tiles.add(
ListTile(
Expand All @@ -567,6 +556,21 @@ class _PartDisplayState extends RefreshableState<PartDetailWidget> {
);
}

// Notes field
tiles.add(
ListTile(
title: Text(L10().notes),
leading: FaIcon(FontAwesomeIcons.stickyNote, color: COLOR_CLICK),
trailing: Text(""),
onTap: () {
Navigator.push(
context,
MaterialPageRoute(builder: (context) => PartNotesWidget(part))
);
},
)
);

tiles.add(
ListTile(
title: Text(L10().attachments),
Expand Down

0 comments on commit efb6fc3

Please sign in to comment.