mirror of
https://github.com/inventree/inventree-app.git
synced 2025-04-28 13:36:50 +00:00
Open web links
This commit is contained in:
parent
1ac6b7e7dc
commit
b0aaccb9e3
@ -23,8 +23,31 @@ class InvenTreeModel {
|
|||||||
// Override the endpoint URL for each subclass
|
// Override the endpoint URL for each subclass
|
||||||
String URL = "";
|
String URL = "";
|
||||||
|
|
||||||
|
// Override the web URL for each subclass
|
||||||
|
// Note: If the WEB_URL is the same (except for /api/) as URL then just leave blank
|
||||||
|
String WEB_URL = "";
|
||||||
|
|
||||||
String NAME = "Model";
|
String NAME = "Model";
|
||||||
|
|
||||||
|
String get webUrl {
|
||||||
|
|
||||||
|
if (api.isConnected()) {
|
||||||
|
String web = InvenTreeAPI().baseUrl;
|
||||||
|
|
||||||
|
web += WEB_URL.isNotEmpty ? WEB_URL : URL;
|
||||||
|
|
||||||
|
web += "/${pk}/";
|
||||||
|
|
||||||
|
web = web.replaceAll("//", "/");
|
||||||
|
|
||||||
|
return web;
|
||||||
|
|
||||||
|
} else {
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
// JSON data which defines this object
|
// JSON data which defines this object
|
||||||
Map<String, dynamic> jsondata = {};
|
Map<String, dynamic> jsondata = {};
|
||||||
|
|
||||||
@ -58,6 +81,15 @@ 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'] ?? '';
|
String get link => jsondata['link'] ?? jsondata['URL'] ?? '';
|
||||||
|
|
||||||
|
void goToInvenTreePage() async {
|
||||||
|
|
||||||
|
if (await canLaunch(webUrl)) {
|
||||||
|
await launch(webUrl);
|
||||||
|
} else {
|
||||||
|
// TODO
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void openLink() async {
|
void openLink() async {
|
||||||
|
|
||||||
if (link.isNotEmpty) {
|
if (link.isNotEmpty) {
|
||||||
|
@ -42,6 +42,10 @@ class _PartDisplayState extends RefreshableState<PartDetailWidget> {
|
|||||||
@override
|
@override
|
||||||
List<Widget> getAppBarActions(BuildContext context) {
|
List<Widget> getAppBarActions(BuildContext context) {
|
||||||
return <Widget>[
|
return <Widget>[
|
||||||
|
IconButton(
|
||||||
|
icon: FaIcon(FontAwesomeIcons.globe),
|
||||||
|
onPressed: _openInvenTreePage,
|
||||||
|
),
|
||||||
// TODO: Hide the 'edit' button if the user does not have permission!!
|
// TODO: Hide the 'edit' button if the user does not have permission!!
|
||||||
IconButton(
|
IconButton(
|
||||||
icon: FaIcon(FontAwesomeIcons.edit),
|
icon: FaIcon(FontAwesomeIcons.edit),
|
||||||
@ -55,6 +59,10 @@ class _PartDisplayState extends RefreshableState<PartDetailWidget> {
|
|||||||
// TODO
|
// TODO
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Future<void> _openInvenTreePage() async {
|
||||||
|
part.goToInvenTreePage();
|
||||||
|
}
|
||||||
|
|
||||||
InvenTreePart part;
|
InvenTreePart part;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
@ -291,7 +299,7 @@ class _PartDisplayState extends RefreshableState<PartDetailWidget> {
|
|||||||
ListTile(
|
ListTile(
|
||||||
title: Text("${part.link}"),
|
title: Text("${part.link}"),
|
||||||
leading: FaIcon(FontAwesomeIcons.link),
|
leading: FaIcon(FontAwesomeIcons.link),
|
||||||
trailing: Text(""),
|
trailing: FaIcon(FontAwesomeIcons.externalLinkAlt),
|
||||||
onTap: () {
|
onTap: () {
|
||||||
part.openLink();
|
part.openLink();
|
||||||
},
|
},
|
||||||
|
@ -55,6 +55,28 @@ class _StockItemDisplayState extends RefreshableState<StockDetailWidget> {
|
|||||||
_StockItemDisplayState(this.item) {
|
_StockItemDisplayState(this.item) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
List<Widget> getAppBarActions(BuildContext context) {
|
||||||
|
return <Widget>[
|
||||||
|
IconButton(
|
||||||
|
icon: FaIcon(FontAwesomeIcons.globe),
|
||||||
|
onPressed: _openInvenTreePage,
|
||||||
|
),
|
||||||
|
// TODO: Hide the 'edit' button if the user does not have permission!!
|
||||||
|
/*
|
||||||
|
IconButton(
|
||||||
|
icon: FaIcon(FontAwesomeIcons.edit),
|
||||||
|
tooltip: I18N.of(context).edit,
|
||||||
|
onPressed: _editPartDialog,
|
||||||
|
)
|
||||||
|
*/
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<void> _openInvenTreePage() async {
|
||||||
|
item.goToInvenTreePage();
|
||||||
|
}
|
||||||
|
|
||||||
// StockItem object
|
// StockItem object
|
||||||
final InvenTreeStockItem item;
|
final InvenTreeStockItem item;
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user