From e83633430b18ac231282f3f9c4d204659808af0c Mon Sep 17 00:00:00 2001 From: "J. A. Messias" Date: Mon, 18 Nov 2024 16:29:53 -0300 Subject: [PATCH] WIP --- .../menu_component/menu_component_model.dart | 144 +++--------------- .../menu_component/menu_component_widget.dart | 5 +- .../helpers/license/license_helper.dart | 68 +++++---- .../services/license/license_service.dart | 6 +- 4 files changed, 63 insertions(+), 160 deletions(-) diff --git a/lib/components/organism_components/menu_component/menu_component_model.dart b/lib/components/organism_components/menu_component/menu_component_model.dart index cbbed6e1..3aadf479 100644 --- a/lib/components/organism_components/menu_component/menu_component_model.dart +++ b/lib/components/organism_components/menu_component/menu_component_model.dart @@ -1,3 +1,5 @@ +import 'dart:developer'; + import 'package:flutter/material.dart'; import 'package:hub/backend/schema/enums/enums.dart'; import 'package:hub/components/atomic_components/menu_button_item/menu_button_item_widget.dart'; @@ -10,6 +12,7 @@ import 'package:hub/components/organism_components/menu_staggered_view_component import 'package:hub/flutter_flow/flutter_flow_util.dart'; import 'package:hub/flutter_flow/nav/nav.dart'; import 'package:hub/shared/extensions/dialog_extensions.dart'; +import 'package:hub/shared/helpers/license/license_helper.dart'; import 'package:hub/shared/helpers/storage/base_storage.dart'; import 'package:hub/shared/helpers/storage/storage_helper.dart'; import 'package:hub/shared/services/authentication/authentication_service.dart'; @@ -22,7 +25,7 @@ class MenuComponentModel extends FlutterFlowModel { final MenuView style; final MenuItem item; final bool expandable; - final List menuOptions; + final List menuOptions; MenuComponentModel({required this.style, required this.item, required this.expandable, required this.menuOptions}); @@ -45,9 +48,9 @@ class MenuComponentModel extends FlutterFlowModel { menuStaggeredViewComponentModel.dispose(); } - List generateMenuEntries(BuildContext context, MenuItem item, List options) { + Future> generateMenuEntries(BuildContext context, MenuItem item, List options) async { List entries = []; - MenuEntry? addMenuEntry(IconData icon, String enText, String ptText, Function() action) { + Future addMenuEntry(IconData icon, String enText, String ptText, Function() action) async { entries.add( item == MenuItem.button ? MenuButtonWidget( @@ -72,126 +75,23 @@ class MenuComponentModel extends FlutterFlowModel { return null; } - if (options.contains(MenuOption.WorkersOnTheProperty)) - addMenuEntry(Icons.engineering_outlined, 'Schedule Providers', 'Agendar Prestadores', () async { - if (await StorageHelper().g(KeychainStorageKey.provisional.value) == 'true') - await open(context, '/provisionalSchedule'); - else + for (var opt in options) { + String? v = await LicenseHelper().g(opt.value); + log('Module: ${opt.value} - License: $v'); + switch (v) { + case 'VISIVEL': + addMenuEntry(Icons.engineering_outlined, 'Schedule Providers', 'Agendar Prestadores', () async { + await open(context, '/provisionalSchedule'); + }); + break; + case 'INVISIVEL': DialogUnavailable.unavailableFeature(context); - safeSetState; - }); - if (options.contains(MenuOption.DeliverySchedule)) - addMenuEntry(Icons.sports_motorsports_outlined, 'Schedule Deliveries', 'Agendar Entregas', () async { - if (await StorageHelper().g(KeychainStorageKey.provisional.value) == 'true') - await open(context, '/deliverySchedule'); - else - DialogUnavailable.unavailableFeature(context); - safeSetState; - }); - if (options.contains(MenuOption.FastPassSchedule)) - addMenuEntry(Icons.attach_email_outlined, 'Invite Visitor', 'Convidar Visitante', () async { - if (await StorageHelper().g(KeychainStorageKey.whatsapp.value) == 'true') - await open(context, '/fastPassPage'); - else - DialogUnavailable.unavailableFeature(context); - safeSetState; - }); - if (options.contains(MenuOption.CompleteSchedule)) - addMenuEntry(Icons.event, 'Complete Schedule', 'Agenda Completa', () async { - await open(context, '/scheduleCompleteVisitPage'); - safeSetState; - }); - if (options.contains(MenuOption.PackagesOnTheProperty)) - addMenuEntry(Icons.inventory_2_outlined, 'Orders', 'Encomendas', () async { - if (await StorageHelper().g(KeychainStorageKey.whatsapp.value) == 'true') - await open(context, '/packageOrder'); - else - DialogUnavailable.unavailableFeature(context); - safeSetState; - }); - if (options.contains(MenuOption.ReservationsOnTheLocal)) - addMenuEntry(Icons.event_available, 'Reservations', 'Reservas', () async { - if (await StorageHelper().g(KeychainStorageKey.whatsapp.value) == 'true') - await open(context, '/reservation'); - else - DialogUnavailable.unavailableFeature(context); - safeSetState; - }); - if (options.contains(MenuOption.VisitorsRegister)) - addMenuEntry(Icons.person_add_alt_1_outlined, 'Register Visitor', 'Cadastrar Visitante', () async { - await open(context, '/registerVisitorPage'); - safeSetState; - }); - if (options.contains(MenuOption.QRCodeAccessInProperty)) - addMenuEntry(Icons.qr_code, 'QRCode Access', 'QRCode de Acesso', () async { - await open(context, '/qrCodePage'); - safeSetState; - }); - if (options.contains(MenuOption.PetsOnTheProperty)) - addMenuEntry(Icons.pets, 'Pets', 'Pets', () async { - if (await StorageHelper().g(KeychainStorageKey.pets.value) == 'true') - await open(context, '/petsOnThePropertyPage'); - else - DialogUnavailable.unavailableFeature(context); - safeSetState; - }); - if (options.contains(MenuOption.PetsRegister)) - addMenuEntry(Icons.pets, 'Pets Register', 'Cadastrar Pet', () async { - if (await StorageHelper().g(KeychainStorageKey.pets.value) == 'true') - await open(context, '/petsPage'); - else - DialogUnavailable.unavailableFeature(context); - safeSetState; - }); - if (options.contains(MenuOption.AccessOnTheProperty)) - addMenuEntry(Icons.transfer_within_a_station_outlined, 'Access History', 'Consultar Acessos', () async { - await open(context, '/acessHistoryPage'); - safeSetState; - }); - if (options.contains(MenuOption.ResidentsOnTheProperty)) - addMenuEntry(Icons.groups, 'Residents', 'Moradores', () async { - await open(context, '/peopleOnThePropertyPage'); - safeSetState; - }); - if (options.contains(MenuOption.LiberationsOnTheProperty)) - addMenuEntry(Icons.how_to_reg_outlined, 'Liberations History', 'Consultar Liberações', () async { - await open(context, '/liberationHistory'); - safeSetState; - }); - if (options.contains(MenuOption.MessagesOnTheProperty)) - addMenuEntry(Icons.chat_outlined, 'Message History', 'Consultar Mensagens', () async { - await open(context, '/messageHistoryPage'); - safeSetState; - }); - if (options.contains(MenuOption.VehiclesOnTheProperty)) - addMenuEntry(Symbols.directions_car, 'Vehicles', 'Veículos', () async { - await open(context, '/vehiclesOnThePropertyPage'); - safeSetState; - }); - if (options.contains(MenuOption.VisitsOnTheProperty)) - addMenuEntry(Symbols.perm_contact_calendar, 'Opened Visits', 'Visitas em Aberto', () async { - await open(context, '/visitsOnThePropertyPage'); - safeSetState; - }); - - if (options.contains(MenuOption.AboutProperty)) - addMenuEntry(Icons.home, 'About Property', 'Sobre a Propriedade', () async { - if (await StorageHelper().g(KeychainStorageKey.whatsapp.value) == 'true') - await open(context, '/aboutProperty'); - else - DialogUnavailable.unavailableFeature(context); - safeSetState; - }); - if (options.contains(MenuOption.SettingsOnTheApp)) - addMenuEntry(Icons.settings, 'System Settings', 'Opções do Sistema', () async { - await open(context, '/preferencesSettings'); - safeSetState; - }); - if (options.contains(MenuOption.LogoutOnTheApp)) - addMenuEntry(Icons.logout, 'Logout', 'Sair', () async { - await out(context); - safeSetState; - }); + break; + default: + break; + } + safeSetState(); + } return entries; } diff --git a/lib/components/organism_components/menu_component/menu_component_widget.dart b/lib/components/organism_components/menu_component/menu_component_widget.dart index 795982cd..b6cb84ca 100644 --- a/lib/components/organism_components/menu_component/menu_component_widget.dart +++ b/lib/components/organism_components/menu_component/menu_component_widget.dart @@ -30,9 +30,10 @@ class _MenuComponentWidgetState extends State { } @override - void didChangeDependencies() { + void didChangeDependencies() async { super.didChangeDependencies(); - widget.model.menuEntries = widget.model.generateMenuEntries(context, widget.model.item, widget.model.menuOptions); + widget.model.menuEntries = + await widget.model.generateMenuEntries(context, widget.model.item, widget.model.menuOptions); } @override diff --git a/lib/shared/helpers/license/license_helper.dart b/lib/shared/helpers/license/license_helper.dart index 52ee305a..6ca74666 100644 --- a/lib/shared/helpers/license/license_helper.dart +++ b/lib/shared/helpers/license/license_helper.dart @@ -3,13 +3,13 @@ import 'dart:developer'; import 'package:hub/shared/helpers/database/database_helper.dart'; import 'package:sqflite/sqflite.dart'; -enum InactiveLicenseKey { +enum InactiveModuleKey { residents, vehicles, openedVisits, } -enum ActiveLicenseKey { +enum ActiveModuleKey { messages, liberations, reservations, @@ -21,14 +21,14 @@ enum ActiveLicenseKey { fastPass, } -extension InactiveLicenseKeyExtension on InactiveLicenseKey { +extension InactiveModuleKeyExtension on InactiveModuleKey { String get value { switch (this) { - case InactiveLicenseKey.residents: + case InactiveModuleKey.residents: return 'FRE-HUB-RESIDENTS'; - case InactiveLicenseKey.vehicles: + case InactiveModuleKey.vehicles: return 'FRE-HUB-VEHICLES'; - case InactiveLicenseKey.openedVisits: + case InactiveModuleKey.openedVisits: return 'FRE-HUB-OPENED-VISITS'; default: return ''; @@ -36,26 +36,26 @@ extension InactiveLicenseKeyExtension on InactiveLicenseKey { } } -extension ActiveLicenseKeyExtension on ActiveLicenseKey { +extension ActiveModuleKeyExtension on ActiveModuleKey { String get value { switch (this) { - case ActiveLicenseKey.messages: + case ActiveModuleKey.messages: return 'FRE-HUB-MESSAGES'; - case ActiveLicenseKey.liberations: + case ActiveModuleKey.liberations: return 'FRE-HUB-LIBERATIONS'; - case ActiveLicenseKey.reservations: + case ActiveModuleKey.reservations: return 'FRE-HUB-RESERVATIONS'; - case ActiveLicenseKey.access: + case ActiveModuleKey.access: return 'FRE-HUB-ACCESS'; - case ActiveLicenseKey.orders: + case ActiveModuleKey.orders: return 'FRE-HUB-ORDERS'; - case ActiveLicenseKey.completeSchedule: + case ActiveModuleKey.completeSchedule: return 'FRE-HUB-COMPLETE-SCHEDULE'; - case ActiveLicenseKey.providerSchedule: + case ActiveModuleKey.providerSchedule: return 'FRE-HUB-AGE-PROV-PRESTADOR'; - case ActiveLicenseKey.deliverySchedule: + case ActiveModuleKey.deliverySchedule: return 'FRE-HUB-AGE-PROV-DELIVERY'; - case ActiveLicenseKey.fastPass: + case ActiveModuleKey.fastPass: return 'FRE-HUB-FASTPASS'; default: return ''; @@ -63,7 +63,7 @@ extension ActiveLicenseKeyExtension on ActiveLicenseKey { } } -enum LicenseStorageKey { +enum Module { messages, liberations, reservations, @@ -79,34 +79,34 @@ enum LicenseStorageKey { fastPass, } -extension LicenseKeyExtension on LicenseStorageKey { +extension LicenseKeyExtension on Module { String get value { switch (this) { - case LicenseStorageKey.messages: + case Module.messages: return 'FRE-HUB-MESSAGES'; - case LicenseStorageKey.liberations: + case Module.liberations: return 'FRE-HUB-LIBERATIONS'; - case LicenseStorageKey.reservations: + case Module.reservations: return 'FRE-HUB-RESERVATIONS'; - case LicenseStorageKey.access: + case Module.access: return 'FRE-HUB-ACCESS'; - case LicenseStorageKey.openedVisits: + case Module.openedVisits: return 'FRE-HUB-OPENED-VISITS'; - case LicenseStorageKey.vehicles: + case Module.vehicles: return 'FRE-HUB-VEHICLES'; - case LicenseStorageKey.residents: + case Module.residents: return 'FRE-HUB-RESIDENTS'; - case LicenseStorageKey.pets: + case Module.pets: return 'FRE-HUB-PETS'; - case LicenseStorageKey.orders: + case Module.orders: return 'FRE-HUB-ORDERS'; - case LicenseStorageKey.completeSchedule: + case Module.completeSchedule: return 'FRE-HUB-COMPLETE-SCHEDULE'; - case LicenseStorageKey.providerSchedule: + case Module.providerSchedule: return 'FRE-HUB-AGE-PROV-PRESTADOR'; - case LicenseStorageKey.deliverySchedule: + case Module.deliverySchedule: return 'FRE-HUB-AGE-PROV-DELIVERY'; - case LicenseStorageKey.fastPass: + case Module.fastPass: return 'FRE-HUB-FASTPASS'; default: return ''; @@ -115,9 +115,11 @@ extension LicenseKeyExtension on LicenseStorageKey { } class LicenseHelper { - LicenseHelper._(); + static final LicenseHelper _instance = LicenseHelper._internal(); - static final LicenseHelper instance = LicenseHelper._(); + factory LicenseHelper() => _instance; + + LicenseHelper._internal(); static const String tableLicense = 'license'; diff --git a/lib/shared/services/license/license_service.dart b/lib/shared/services/license/license_service.dart index bea7bc4a..b2ea7651 100644 --- a/lib/shared/services/license/license_service.dart +++ b/lib/shared/services/license/license_service.dart @@ -17,8 +17,8 @@ class LicenseService { LicenseService._internal(); static Future setupLicense(Database database) async { - await LicenseHelper.insertLicenseFoo(InactiveLicenseKey.values.map((e) => e.value).toList(), 'INVISIVEL'); - await LicenseHelper.insertLicenseFoo(ActiveLicenseKey.values.map((e) => e.value).toList(), 'VISIVEL'); + await LicenseHelper.insertLicenseFoo(InactiveModuleKey.values.map((e) => e.value).toList(), 'INVISIVEL'); + await LicenseHelper.insertLicenseFoo(ActiveModuleKey.values.map((e) => e.value).toList(), 'VISIVEL'); } static Future initLicenseService() async { @@ -74,7 +74,7 @@ class LicenseService { } static bool licenseContainsKey(final String key) { - return LicenseStorageKey.values.map((e) => e.value).toList().contains(key); + return Module.values.map((e) => e.value).toList().contains(key); } static Future _saveModule(final dynamic body) async {