Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor flutter #517

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
314 changes: 192 additions & 122 deletions APP/lib/common/appbar.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,57 +11,20 @@ import 'package:ogree_app/widgets/login/change_password_popup.dart';
import 'package:ogree_app/widgets/tenants/popups/create_server_popup.dart';
import 'package:ogree_app/widgets/tools/download_tool_popup.dart';

AppBar myAppBar(context, userEmail, {isTenantMode = false}) {
final localeMsg = AppLocalizations.of(context)!;
Future logout() => Navigator.of(context).push(
MaterialPageRoute(
builder: (context) => const LoginPage(),
),
);

final List<PopupMenuEntry<String>> entries = <PopupMenuEntry<String>>[
PopupMenuItem(
value: "change",
child: Text(AppLocalizations.of(context)!.changePassword),
),
const PopupMenuItem(
value: "logout",
child: Text("Logout"),
),
];
if (isTenantMode) {
entries.insert(
0,
PopupMenuItem(
value: "new",
child: Text(backendType == BackendType.kubernetes
? localeMsg.addKube
: localeMsg.addServer,),
),);
} else {
entries.insert(
0,
PopupMenuItem(
value: Tools.unity.name,
child: Text(localeMsg.downloadUnity),
),);
entries.insert(
0,
PopupMenuItem(
value: Tools.cli.name,
child: Text(localeMsg.downloadCli),
),);
if (isTenantAdmin) {
entries.insert(
0,
PopupMenuItem(
value: "tenant",
child: Text(localeMsg.tenantParameters),
),);
}
}
enum PopupMenuEntries {
passwordChange,
logout,
createNewServer,
tenantParams,
downloadUnity,
downloadCli
}

AppBar myAppBar(BuildContext context, String userEmail,
{bool isTenantMode = false}) {
final localeMsg = AppLocalizations.of(context)!;
final bool isSmallDisplay = MediaQuery.of(context).size.width < 600;

return AppBar(
backgroundColor: Colors.grey.shade900,
leadingWidth: 160,
Expand All @@ -73,15 +36,17 @@ AppBar myAppBar(context, userEmail, {isTenantMode = false}) {
child: const Text(
'OGrEE',
style: TextStyle(
fontSize: 21,
fontWeight: FontWeight.w700,
color: Colors.white,),
fontSize: 21,
fontWeight: FontWeight.w700,
color: Colors.white,
),
),
onPressed: () => Navigator.of(context).push(
MaterialPageRoute(
builder: (context) => ProjectsPage(
userEmail: isTenantMode ? "admin" : userEmail,
isTenantMode: isTenantMode,),
userEmail: isTenantMode ? "admin" : userEmail,
isTenantMode: isTenantMode,
),
),
),
),
Expand All @@ -93,80 +58,185 @@ AppBar myAppBar(context, userEmail, {isTenantMode = false}) {
),
),
actions: [
if (isSmallDisplay) Container() else Padding(
padding: const EdgeInsets.only(right: 20),
child: Row(
children: [
if (backendType == BackendType.kubernetes) Padding(
padding: const EdgeInsets.only(right: 8),
child: Container(
decoration: BoxDecoration(
borderRadius:
const BorderRadius.all(Radius.circular(8)),
border: Border.all(color: Colors.white),
),
child: Badge(
backgroundColor: Colors.grey.shade900,
label: const Text("KUBE"),
),
),
) else Container(),
Text(isTenantMode ? apiUrl : tenantName,
style: const TextStyle(color: Colors.white),),
],
),
),
getInfoBadge(isTenantMode, isSmallDisplay),
const Padding(
padding: EdgeInsets.symmetric(vertical: 15),
child: LanguageToggle(),
),
const SizedBox(width: 17),
PopupMenuButton<String>(
onSelected: (value) {
if (value == "logout") {
logout();
} else if (value == "new") {
showCustomPopup(
context, CreateServerPopup(parentCallback: () {}),);
} else if (value == "tenant") {
Navigator.of(context).push(MaterialPageRoute(
builder: (context) => const TenantPage(userEmail: "admin"),
),);
} else if (value == Tools.unity.name) {
showCustomPopup(context, const DownloadToolPopup(tool: Tools.unity),
isDismissible: true,);
} else if (value == Tools.cli.name) {
showCustomPopup(context, const DownloadToolPopup(tool: Tools.cli),
isDismissible: true,);
} else {
showCustomPopup(context, const ChangePasswordPopup());
}
},
itemBuilder: (_) => entries,
child: Row(
children: [
const Icon(
Icons.account_circle,
color: Colors.white,
),
const SizedBox(width: 10),
if (isSmallDisplay) Tooltip(
message: isTenantMode
? (backendType == BackendType.kubernetes
? "(KUBE) $apiUrl"
: apiUrl)
: tenantName,
triggerMode: TooltipTriggerMode.tap,
child: const Icon(
Icons.info_outline_rounded,
color: Colors.white,
),) else Text(
isTenantMode ? "admin" : userEmail,
style: const TextStyle(color: Colors.white),
),
],
),),
getPopupMenuButton(
isTenantMode, isSmallDisplay, userEmail, localeMsg, context),
const SizedBox(width: 40),
],
);
}

// KUBE + API URL + TenantName
Widget getInfoBadge(bool isTenantMode, bool isSmallDisplay) {
if (isSmallDisplay) {
return Container();
} else {
return Padding(
padding: const EdgeInsets.only(right: 20),
child: Row(
children: [
if (backendType == BackendType.kubernetes)
Padding(
padding: const EdgeInsets.only(right: 8),
child: Container(
decoration: BoxDecoration(
borderRadius: const BorderRadius.all(Radius.circular(8)),
border: Border.all(color: Colors.white),
),
child: Badge(
backgroundColor: Colors.grey.shade900,
label: const Text("KUBE"),
),
),
)
else
Container(),
Text(
isTenantMode ? apiUrl : tenantName,
style: const TextStyle(color: Colors.white),
),
],
),
);
}
}

// POPUP MENU
PopupMenuButton<PopupMenuEntries> getPopupMenuButton(
bool isTenantMode,
bool isSmallDisplay,
String userEmail,
AppLocalizations localeMsg,
BuildContext context) {
return PopupMenuButton<PopupMenuEntries>(
onSelected: (value) => onMenuEntrySelected(value, context),
itemBuilder: (_) => getPopupMenuEntries(isTenantMode, localeMsg),
child: Row(
children: [
const Icon(
Icons.account_circle,
color: Colors.white,
),
const SizedBox(width: 10),
if (isSmallDisplay)
Tooltip(
message: isTenantMode
? (backendType == BackendType.kubernetes
? "(KUBE) $apiUrl"
: apiUrl)
: tenantName,
triggerMode: TooltipTriggerMode.tap,
child: const Icon(
Icons.info_outline_rounded,
color: Colors.white,
),
)
else
Text(
isTenantMode ? "admin" : userEmail,
style: const TextStyle(color: Colors.white),
),
],
),
);
}

List<PopupMenuEntry<PopupMenuEntries>> getPopupMenuEntries(
bool isTenantMode, AppLocalizations localeMsg) {
final List<PopupMenuEntry<PopupMenuEntries>> entries =
<PopupMenuEntry<PopupMenuEntries>>[
PopupMenuItem(
value: PopupMenuEntries.passwordChange,
child: Text(localeMsg.changePassword),
),
const PopupMenuItem(
value: PopupMenuEntries.logout,
child: Text("Logout"),
),
];
if (isTenantMode) {
entries.insert(
0,
PopupMenuItem(
value: PopupMenuEntries.createNewServer,
child: Text(
backendType == BackendType.kubernetes
? localeMsg.addKube
: localeMsg.addServer,
),
),
);
} else {
entries.insert(
0,
PopupMenuItem(
value: PopupMenuEntries.downloadUnity,
child: Text(localeMsg.downloadUnity),
),
);
entries.insert(
0,
PopupMenuItem(
value: PopupMenuEntries.downloadCli,
child: Text(localeMsg.downloadCli),
),
);
if (isTenantAdmin) {
entries.insert(
0,
PopupMenuItem(
value: PopupMenuEntries.tenantParams,
child: Text(localeMsg.tenantParameters),
),
);
}
}
return entries;
}

onMenuEntrySelected(PopupMenuEntries selectedEntry, BuildContext context) {
switch (selectedEntry) {
case PopupMenuEntries.logout:
Navigator.of(context).push(
MaterialPageRoute(
builder: (context) => const LoginPage(),
),
);
break;
case PopupMenuEntries.tenantParams:
Navigator.of(context).push(
MaterialPageRoute(
builder: (context) => const TenantPage(userEmail: "admin"),
),
);
break;
case PopupMenuEntries.downloadUnity:
showCustomPopup(
context,
const DownloadToolPopup(tool: Tools.unity),
isDismissible: true,
);
break;
case PopupMenuEntries.downloadCli:
showCustomPopup(
context,
const DownloadToolPopup(tool: Tools.cli),
isDismissible: true,
);
break;
case PopupMenuEntries.passwordChange:
showCustomPopup(context, const ChangePasswordPopup());
break;
case PopupMenuEntries.createNewServer:
showCustomPopup(
context,
CreateServerPopup(parentCallback: () {}),
);
break;
}
}
2 changes: 1 addition & 1 deletion APP/lib/common/csv.dart
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ saveCSV(String desiredFileName, List<List<String>> rows,
html.AnchorElement(
href: 'data:application/octet-stream;base64,${base64Encode(bytes)}',
)
..setAttribute("download", "report.csv")
..setAttribute("download", "$desiredFileName.csv")
..click();
} else {
// Save to local filesystem
Expand Down
Loading