2
0
mirror of https://github.com/inventree/inventree-app.git synced 2025-04-28 13:36:50 +00:00

Merge pull request #51 from SchrodingersGat/sentry-refactor

Sentry refactor
This commit is contained in:
Oliver 2021-06-29 22:43:07 +10:00 committed by GitHub
commit 5343bc23b0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 83 additions and 59 deletions

View File

@ -247,7 +247,11 @@ class StockItemBarcodeAssignmentHandler extends BarcodeHandler {
final InvenTreeStockItem item; final InvenTreeStockItem item;
StockItemBarcodeAssignmentHandler(this.item); StockItemBarcodeAssignmentHandler(this.item) {
if (item == null) {
throw new AssertionError("null StockItem passed to barcode handler");
}
}
@override @override
String getOverlayText(BuildContext context) => L10().barcodeScanAssign; String getOverlayText(BuildContext context) => L10().barcodeScanAssign;
@ -322,7 +326,11 @@ class StockItemScanIntoLocationHandler extends BarcodeHandler {
final InvenTreeStockItem item; final InvenTreeStockItem item;
StockItemScanIntoLocationHandler(this.item); StockItemScanIntoLocationHandler(this.item) {
if (item == null) {
throw new AssertionError("null StockItem passed to StockItemScanIntoLocationHandler");
}
}
@override @override
String getOverlayText(BuildContext context) => L10().barcodeScanLocation; String getOverlayText(BuildContext context) => L10().barcodeScanLocation;
@ -378,7 +386,11 @@ class StockLocationScanInItemsHandler extends BarcodeHandler {
final InvenTreeStockLocation location; final InvenTreeStockLocation location;
StockLocationScanInItemsHandler(this.location); StockLocationScanInItemsHandler(this.location) {
if (location == null) {
throw new AssertionError("null StockLocation passed to StockLocationScanInItemsHandler");
}
}
@override @override
String getOverlayText(BuildContext context) => L10().barcodeScanItem; String getOverlayText(BuildContext context) => L10().barcodeScanItem;

View File

@ -86,7 +86,7 @@ bool isInDebugMode() {
Future<void> sentryReportError(dynamic error, dynamic stackTrace) async { Future<void> sentryReportError(dynamic error, dynamic stackTrace) async {
print('Intercepted error: $error'); print('----- Sentry Intercepted error: $error -----');
print(stackTrace); print(stackTrace);
// Errors thrown in development mode are unlikely to be interesting. You can // Errors thrown in development mode are unlikely to be interesting. You can
@ -94,7 +94,7 @@ Future<void> sentryReportError(dynamic error, dynamic stackTrace) async {
// the report. // the report.
if (isInDebugMode()) { if (isInDebugMode()) {
print('In dev mode. Not sending report to Sentry.io.'); print('----- In dev mode. Not sending report to Sentry.io -----');
return; return;
} }

@ -1 +1 @@
Subproject commit 7a23f04bfc11dd099511536bdb8b72a9b35edecf Subproject commit 05a5cbf63b4b5479162905def9fdadf21041212e

View File

@ -12,37 +12,32 @@ import 'package:one_context/one_context.dart';
import 'dsn.dart'; import 'dsn.dart';
import 'package:flutter/foundation.dart';
import 'package:sentry_flutter/sentry_flutter.dart'; import 'package:sentry_flutter/sentry_flutter.dart';
void main() async { Future<void> main() async {
await Sentry.init((options) {
options.dsn = SENTRY_DSN_KEY;
},
//appRunner: () => runApp(InvenTreeApp())
);
await runZonedGuarded<Future<void>>(() async { await runZonedGuarded<Future<void>>(() async {
WidgetsFlutterBinding.ensureInitialized(); await Sentry.init((options) {
options.dsn = SENTRY_DSN_KEY;
});
// This captures errors reported by the Flutter framework. WidgetsFlutterBinding.ensureInitialized();
FlutterError.onError = (FlutterErrorDetails details) async {
if (isInDebugMode()) {
// In development mode simply print to console.
FlutterError.dumpErrorToConsole(details);
} else {
// In production mode report to the application zone to report to
// Sentry.
Zone.current.handleUncaughtError(details.exception, details.stack);
}
};
runApp(InvenTreeApp()); // Pass any flutter errors off to the Sentry reporting context!
FlutterError.onError = (FlutterErrorDetails details) async {
}, (Object error, StackTrace stackTrace) { // Ensure that the error gets reported to sentry!
await sentryReportError(details.exception, details.stack);
};
runApp(
InvenTreeApp()
);
}, (Object error, StackTrace stackTrace) async {
sentryReportError(error, stackTrace); sentryReportError(error, stackTrace);
}); });
@ -81,6 +76,7 @@ class InvenTreeApp extends StatelessWidget {
const Locale('tr', ''), const Locale('tr', ''),
const Locale('zh', ''), const Locale('zh', ''),
], ],
); );
} }
} }

View File

@ -297,27 +297,29 @@ List<Widget> detailTiles() {
List<Widget> tiles = []; List<Widget> tiles = [];
tiles.add(locationDescriptionCard(includeActions: false)); tiles.add(locationDescriptionCard(includeActions: false));
// Stock adjustment actions if (location != null) {
if (InvenTreeAPI().checkPermission('stock', 'change')) { // Stock adjustment actions
// Scan items into location if (InvenTreeAPI().checkPermission('stock', 'change')) {
tiles.add( // Scan items into location
ListTile( tiles.add(
title: Text(L10().barcodeScanInItems), ListTile(
leading: FaIcon(FontAwesomeIcons.exchangeAlt), title: Text(L10().barcodeScanInItems),
trailing: FaIcon(FontAwesomeIcons.qrcode), leading: FaIcon(FontAwesomeIcons.exchangeAlt),
onTap: () { trailing: FaIcon(FontAwesomeIcons.qrcode),
Navigator.push( onTap: () {
context, Navigator.push(
MaterialPageRoute(builder: (context) => context,
InvenTreeQRView( MaterialPageRoute(builder: (context) =>
StockLocationScanInItemsHandler(location))) InvenTreeQRView(
).then((context) { StockLocationScanInItemsHandler(location)))
refresh(); ).then((context) {
}); refresh();
}, });
) },
); )
);
}
} }
// Move location into another location // Move location into another location
@ -332,6 +334,19 @@ List<Widget> detailTiles() {
); );
*/ */
if (tiles.length <= 1) {
tiles.add(
ListTile(
title: Text(
L10().actionsNone,
style: TextStyle(
fontStyle: FontStyle.italic
),
)
)
);
}
return tiles; return tiles;
} }

View File

@ -94,7 +94,7 @@ class _PartDisplayState extends RefreshableState<PartDetailWidget> {
void _toggleStar() async { void _toggleStar() async {
if (InvenTreeAPI().checkPermission('part', 'change')) { if (InvenTreeAPI().checkPermission('part', 'view')) {
await part.update(context, values: {"starred": "${!part.starred}"}); await part.update(context, values: {"starred": "${!part.starred}"});
refresh(); refresh();
} }
@ -105,7 +105,7 @@ class _PartDisplayState extends RefreshableState<PartDetailWidget> {
final bool result = await part.update(context, values: values); final bool result = await part.update(context, values: values);
if (result) { if (result) {
showSnackIcon("Part edited", success: true); showSnackIcon(L10().partEdited, success: true);
} }
/* /*
showSnackIcon( showSnackIcon(
@ -130,14 +130,15 @@ class _PartDisplayState extends RefreshableState<PartDetailWidget> {
L10().imageUploadSuccess, L10().imageUploadSuccess,
success: true success: true
); );
refresh();
} else { } else {
showSnackIcon( showSnackIcon(
L10().imageUploadFailure, L10().imageUploadFailure,
success: false, success: false,
); );
} }
refresh();
} }
void _selectImage() { void _selectImage() {
@ -432,7 +433,7 @@ class _PartDisplayState extends RefreshableState<PartDetailWidget> {
L10().stockItems, L10().stockItems,
style: TextStyle(fontWeight: FontWeight.bold), style: TextStyle(fontWeight: FontWeight.bold),
), ),
subtitle: part.stockItems.isEmpty ? Text("No stock items available") : null, subtitle: part.stockItems.isEmpty ? Text(L10().stockItemsNotAvailable) : null,
trailing: part.stockItems.isNotEmpty ? Text("${part.stockItems.length}") : null, trailing: part.stockItems.isNotEmpty ? Text("${part.stockItems.length}") : null,
) )
); );
@ -463,7 +464,7 @@ class _PartDisplayState extends RefreshableState<PartDetailWidget> {
tiles.add( tiles.add(
ListTile( ListTile(
title: Text("Scan New Stock Item"), title: Text(L10().barcodeScanItem),
leading: FaIcon(FontAwesomeIcons.box), leading: FaIcon(FontAwesomeIcons.box),
trailing: FaIcon(FontAwesomeIcons.qrcode), trailing: FaIcon(FontAwesomeIcons.qrcode),
onTap: null, onTap: null,

View File

@ -141,7 +141,7 @@ class _StockItemDisplayState extends RefreshableState<StockDetailWidget> {
void _stockUpdateMessage(bool result) { void _stockUpdateMessage(bool result) {
if (result) { if (result) {
showSnackIcon("Stock item updated", success: true); showSnackIcon(L10().stockItemUpdated, success: true);
} }
} }
@ -258,7 +258,7 @@ class _StockItemDisplayState extends RefreshableState<StockDetailWidget> {
refresh(); refresh();
if (result) { if (result) {
showSnackIcon("Stock item transferred", success: true); showSnackIcon(L10().stockItemTransferred, success: true);
} }
} }
@ -287,7 +287,7 @@ class _StockItemDisplayState extends RefreshableState<StockDetailWidget> {
controller: _selectedController, controller: _selectedController,
autofocus: true, autofocus: true,
decoration: InputDecoration( decoration: InputDecoration(
hintText: "Search for location", hintText: L10().searchLocation,
border: OutlineInputBorder() border: OutlineInputBorder()
) )
), ),
@ -575,7 +575,7 @@ class _StockItemDisplayState extends RefreshableState<StockDetailWidget> {
); );
// Add or remove custom barcode // Add or remove custom barcode
if (item.uid.isEmpty) { if (item != null && item.uid.isEmpty) {
tiles.add( tiles.add(
ListTile( ListTile(
title: Text(L10().barcodeAssign), title: Text(L10().barcodeAssign),