diff --git a/lib/components/organism_components/bottom_arrow_linked_locals_component/bottom_arrow_linked_locals_component_widget.dart b/lib/components/organism_components/bottom_arrow_linked_locals_component/bottom_arrow_linked_locals_component_widget.dart index 8d781daa..58be572b 100644 --- a/lib/components/organism_components/bottom_arrow_linked_locals_component/bottom_arrow_linked_locals_component_widget.dart +++ b/lib/components/organism_components/bottom_arrow_linked_locals_component/bottom_arrow_linked_locals_component_widget.dart @@ -106,6 +106,7 @@ class _BottomArrowLinkedLocalsComponentWidgetState extends State> stringToMap(String v) async { throw FormatException('Invalid key-value pair: $part of $v'); } final key = keyValue[0].trim(); - final value = keyValue.length > 1 ? keyValue[1].trim() : ''; + final value = keyValue.sublist(1).join(':').trim(); // Join the remaining parts to handle DateTime correctly return MapEntry(key, value); }), )); diff --git a/lib/pages/pets_on_the_property_page/pets_history_screen.dart b/lib/pages/pets_on_the_property_page/pets_history_screen.dart index b0663b1d..b32ba509 100644 --- a/lib/pages/pets_on_the_property_page/pets_history_screen.dart +++ b/lib/pages/pets_on_the_property_page/pets_history_screen.dart @@ -59,8 +59,8 @@ class _PetsHistoryScreenState extends State with TickerProvid backgroundColor: FlutterFlowTheme.of(context).primaryBackground, automaticallyImplyLeading: false, title: Text(FFLocalizations.of(context).getVariableText( - ptText: 'Cadastrar Pets', - enText: 'Pets Register', + ptText: 'Pets', + enText: 'Pets', ), style: FlutterFlowTheme.of(context).headlineMedium.override( fontFamily: 'Nunito', diff --git a/lib/shared/components/molecules/locals/data/data_sources/locals_remote_data_source.dart b/lib/shared/components/molecules/locals/data/data_sources/locals_remote_data_source.dart index 2fe1c4c4..ea9fa7a9 100644 --- a/lib/shared/components/molecules/locals/data/data_sources/locals_remote_data_source.dart +++ b/lib/shared/components/molecules/locals/data/data_sources/locals_remote_data_source.dart @@ -46,7 +46,7 @@ class LocalsRemoteDataSourceImpl implements LocalsRemoteDataSource { enText: 'Verify your connection', ptText: 'Verifique sua conexão', ); - await DialogUtil.error(context, errorMsg).whenComplete(() => selectLocal(context, response)); + // await DialogUtil.error(context, errorMsg).whenComplete(() async => await selectLocal(context, response)); return; } @@ -86,7 +86,7 @@ class LocalsRemoteDataSourceImpl implements LocalsRemoteDataSource { enText: 'Verify your connection', ptText: 'Verifique sua conexão', ); - await DialogUtil.error(context, errorMsg).whenComplete(() => selectLocal(context, response)); + // await DialogUtil.error(context, errorMsg).whenComplete(() async => await selectLocal(context, response)); return false; } @@ -137,7 +137,7 @@ class LocalsRemoteDataSourceImpl implements LocalsRemoteDataSource { enText: 'Error getting locals, verify your connection', ptText: 'Erro ao obter locais, verifique sua conexão', ); - await DialogUtil.error(context, errorMsg).whenComplete(() => selectLocal(context, null)); + // await DialogUtil.error(context, errorMsg).whenComplete(() async => await selectLocal(context, null)); return false; } } @@ -154,7 +154,7 @@ class LocalsRemoteDataSourceImpl implements LocalsRemoteDataSource { enText: 'Verify your connection', ptText: 'Verifique sua conexão', ); - await DialogUtil.error(context, errorMsg).whenComplete(() => selectLocal(context, response)); + // await DialogUtil.error(context, errorMsg).whenComplete(() async => await selectLocal(context, response)); return false; } @@ -163,7 +163,7 @@ class LocalsRemoteDataSourceImpl implements LocalsRemoteDataSource { final GetLocalsCall callback = PhpGroup.getLocalsCall; response = await callback.call(); final String errorMsg = response.jsonBody['error_msg'] ?? 'Local indisponível'; - await DialogUtil.error(context, errorMsg).whenComplete(() => selectLocal(context, response)); + // await DialogUtil.error(context, errorMsg).whenComplete(() async => await selectLocal(context, response)); return false; } else { await LocalUtil.updateStorageUtil(response.jsonBody); @@ -175,7 +175,7 @@ class LocalsRemoteDataSourceImpl implements LocalsRemoteDataSource { enText: 'Error getting data, verify your connection', ptText: 'Erro ao obter dados, verifique sua conexão', ); - await DialogUtil.error(context, errorMsg).whenComplete(() => selectLocal(context, null)); + // await DialogUtil.error(context, errorMsg).whenComplete(() async => await selectLocal(context, null)); return false; } } @@ -212,6 +212,7 @@ class LocalsRemoteDataSourceImpl implements LocalsRemoteDataSource { await PhpGroup.resopndeVinculo.call(tarefa: 'I').then((value) async { if (value.jsonBody['error'] == false) { await StorageHelper().set(KeychainStorageKey.clientName.value, ''); + await StorageHelper().set(KeychainStorageKey.ownerName.value, ''); await StorageHelper().set(KeychainStorageKey.clientUUID.value, ''); context.pop(); context.go( diff --git a/lib/shared/components/molecules/locals/data/repositories/locals_repository_impl.dart b/lib/shared/components/molecules/locals/data/repositories/locals_repository_impl.dart index 7d2d79fa..1c8580ad 100644 --- a/lib/shared/components/molecules/locals/data/repositories/locals_repository_impl.dart +++ b/lib/shared/components/molecules/locals/data/repositories/locals_repository_impl.dart @@ -4,6 +4,9 @@ import 'package:flutter/material.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:hub/shared/components/molecules/locals/index.dart'; import 'package:hub/shared/components/molecules/modules/index.dart'; +import 'package:hub/shared/helpers/storage/base_storage.dart'; +import 'package:hub/shared/helpers/storage/storage_helper.dart'; +import 'package:hub/shared/utils/dialog_util.dart'; import 'package:rxdart/rxdart.dart'; class LocalsRepositoryImpl implements LocalsRepository { @@ -19,10 +22,16 @@ class LocalsRepositoryImpl implements LocalsRepository { @override Future update(BuildContext context) async { - // LocalsRepositoryImpl.license.add(false); - final bool response = await remoteDataSource.processLocals(context); + bool response = false; + while (!response) { + response = await remoteDataSource.processLocals(context); + if (!response) { + await StorageHelper().set(KeychainStorageKey.clientUUID.value, ''); + const String errorMsg = 'Erro ao atualizar locais'; + await DialogUtil.error(context, errorMsg); + } + } context.read().add(LocalProfileEvent()); - // LocalsRepositoryImpl.license.add(response); return response; } diff --git a/lib/shared/components/molecules/locals/presentation/blocs/local_profile_bloc.dart b/lib/shared/components/molecules/locals/presentation/blocs/local_profile_bloc.dart index db8d2a02..95faea30 100644 --- a/lib/shared/components/molecules/locals/presentation/blocs/local_profile_bloc.dart +++ b/lib/shared/components/molecules/locals/presentation/blocs/local_profile_bloc.dart @@ -16,13 +16,15 @@ class LocalProfileEvent { class LocalProfileState { final String cliName; final String cliUUID; + final String ownerName; - LocalProfileState({this.cliName = '', this.cliUUID = ''}); + LocalProfileState({this.cliName = '', this.cliUUID = '', this.ownerName = ''}); - LocalProfileState copyWith({String? cliName, String? cliUUID}) { + LocalProfileState copyWith({String? cliName, String? ownerName, String? cliUUID}) { return LocalProfileState( cliName: cliName ?? this.cliName, + ownerName: ownerName ?? this.ownerName, cliUUID: cliUUID ?? this.cliUUID, ); } @@ -36,8 +38,9 @@ class LocalProfileBloc extends Bloc { Future _onLocalProfileEvent(LocalProfileEvent event, Emitter emit) async { log('LocalProfileBloc: _onLocalProfileEvent'); final cliName = (await StorageHelper().get(KeychainStorageKey.clientName.value)) ?? ''; + final ownerName = (await StorageHelper().get(KeychainStorageKey.ownerName.value)) ?? ''; final cliUUID = (await StorageHelper().get(KeychainStorageKey.clientUUID.value)) ?? ''; - emit(state.copyWith(cliName: cliName, cliUUID: cliUUID)); + emit(state.copyWith(cliName: cliName, cliUUID: cliUUID, ownerName: ownerName)); } // void updateProfile(BuildContext context) { @@ -51,6 +54,7 @@ class LocalProfileBloc extends Bloc { class LocalProfileComponentModel extends FlutterFlowModel { String cliName = ''; String cliUUID = ''; + String ownerName = ''; VoidCallback? setStateCallback; @override @@ -60,6 +64,7 @@ class LocalProfileComponentModel extends FlutterFlowModel getData() async { cliName = (await StorageHelper().get(KeychainStorageKey.clientName.value)) ?? ''; + ownerName = (await StorageHelper().get(KeychainStorageKey.ownerName.value)) ?? ''; cliUUID = (await StorageHelper().get(KeychainStorageKey.clientUUID.value)) ?? ''; setStateCallback?.call(); } diff --git a/lib/shared/components/molecules/locals/presentation/widgets/local_profile/local_profile_widget.dart b/lib/shared/components/molecules/locals/presentation/widgets/local_profile/local_profile_widget.dart index cfcfa437..297a7d0d 100644 --- a/lib/shared/components/molecules/locals/presentation/widgets/local_profile/local_profile_widget.dart +++ b/lib/shared/components/molecules/locals/presentation/widgets/local_profile/local_profile_widget.dart @@ -211,33 +211,61 @@ class _LocalProfileComponentWidgetState extends State( - convertToUppercase(state.cliName), - FFLocalizations.of(context).getVariableText( - ptText: 'SEM LOCAL VINCULADO', - enText: 'NO LINKED LOCAL', - ), - ), - child: Text( - valueOrDefault( - convertToUppercase(state.cliName), - FFLocalizations.of(context).getVariableText( - ptText: 'SEM LOCAL VINCULADO', - enText: 'NO LINKED LOCAL', + child: Column( + crossAxisAlignment: CrossAxisAlignment.start, + mainAxisAlignment: MainAxisAlignment.center, + children: [ + Tooltip( + message: valueOrDefault( + convertToUppercase(state.cliName), + FFLocalizations.of(context).getVariableText( + ptText: 'SEM LOCAL VINCULADO', + enText: 'NO LINKED LOCAL', + ), + ), + child: Text( + valueOrDefault( + convertToUppercase(state.cliName), + FFLocalizations.of(context).getVariableText( + ptText: 'SEM LOCAL VINCULADO', + enText: 'NO LINKED LOCAL', + ), + ), + overflow: TextOverflow.ellipsis, + maxLines: 1, + style: FlutterFlowTheme.of(context).labelMedium.override( + fontFamily: 'Nunito', + color: FlutterFlowTheme.of(context).info, + fontSize: limitedFontSize, + letterSpacing: 0.0, + fontWeight: FontWeight.w500, + useGoogleFonts: GoogleFonts.asMap().containsKey('Nunito'), + ), ), ), - overflow: TextOverflow.ellipsis, - maxLines: 1, - style: FlutterFlowTheme.of(context).labelMedium.override( + Tooltip( + message: valueOrDefault( + ' '+state.ownerName, + '' + ), + child: Text( + valueOrDefault( + state.ownerName.length > 30 ? '${state.ownerName.substring(0, 20)}...' : state.ownerName, + '' + ), + overflow: TextOverflow.ellipsis, + maxLines: 1, + style: FlutterFlowTheme.of(context).labelMedium.override( fontFamily: 'Nunito', color: FlutterFlowTheme.of(context).info, fontSize: limitedFontSize, letterSpacing: 0.0, fontWeight: FontWeight.w500, useGoogleFonts: GoogleFonts.asMap().containsKey('Nunito'), + ), ), - ), + ), + ], ), ), ].divide(const SizedBox(width: 20.0)).addToStart(const SizedBox(width: 20.0)).addToEnd(const SizedBox(width: 20.0)), diff --git a/lib/shared/components/molecules/locals/utils/local_util.dart b/lib/shared/components/molecules/locals/utils/local_util.dart index 8c6395a5..8fe8350d 100644 --- a/lib/shared/components/molecules/locals/utils/local_util.dart +++ b/lib/shared/components/molecules/locals/utils/local_util.dart @@ -36,7 +36,7 @@ class LocalUtil { await DialogUtil.warning(context, errorMsg); return; } - await DialogUtil.error(context, errorMsg).whenComplete(() async => await LocalsRemoteDataSourceImpl().selectLocal(context, null)); + // await DialogUtil.error(context, errorMsg).whenComplete(() async => await LocalsRemoteDataSourceImpl().selectLocal(context, null)); } static Future handleUnavailable(BuildContext context, List locals) async { @@ -45,11 +45,15 @@ class LocalUtil { await StorageHelper().set(KeychainStorageKey.clientUUID.value, locals[0]['CLI_ID']); await StorageHelper().set(KeychainStorageKey.ownerUUID.value, locals[0]['CLU_OWNER_ID']); await StorageHelper().set(KeychainStorageKey.clientName.value, locals[0]['CLI_NOME']); + await StorageHelper().set(KeychainStorageKey.ownerName.value, locals[0]['CLU_OWNER_DSC']); + var response = await PhpGroup.resopndeVinculo.call(tarefa: 'A'); if (response.jsonBody['error'] == true) { await StorageHelper().set(KeychainStorageKey.clientUUID.value, ''); await StorageHelper().set(KeychainStorageKey.ownerUUID.value, ''); await StorageHelper().set(KeychainStorageKey.clientName.value, ''); + await StorageHelper().set(KeychainStorageKey.ownerName.value, ''); + return false; } if (response.jsonBody['error'] == false) return await LocalsRemoteDataSourceImpl().processData(context).then((value) => value); @@ -66,6 +70,7 @@ class LocalUtil { await StorageHelper().set(KeychainStorageKey.clientUUID.value, local['CLI_ID']); await StorageHelper().set(KeychainStorageKey.ownerUUID.value, local['CLU_OWNER_ID']); await StorageHelper().set(KeychainStorageKey.clientName.value, local['CLI_NOME']); + await StorageHelper().set(KeychainStorageKey.ownerName.value, local['CLU_OWNER_DSC']); await StorageHelper().set(KeychainStorageKey.userName.value, local['USU_NOME']); return await LocalsRemoteDataSourceImpl().processData(context); } diff --git a/lib/shared/components/molecules/menu/data/data_sources/menu_local_data_source.dart b/lib/shared/components/molecules/menu/data/data_sources/menu_local_data_source.dart index 536eef3a..113df0e4 100644 --- a/lib/shared/components/molecules/menu/data/data_sources/menu_local_data_source.dart +++ b/lib/shared/components/molecules/menu/data/data_sources/menu_local_data_source.dart @@ -14,7 +14,7 @@ import '../../../modules/domain/entities/index.dart'; abstract class MenuLocalDataSource { Future addMenuEntry(EnumMenuItem item, List entries, IconData icon, String text, Function() action); Future processDisplayDefault(EnumMenuItem item, MenuEntry opt, List entries); - Future processDisplay(EnumMenuItem item, EnumDisplay display, MenuEntry opt, List entries); + Future handleMenu(EnumMenuItem item, EnumDisplay display, MenuEntry opt, List entries); Future processStartDate(String startDate, MenuEntry entry); Future processExpirationDate(String expirationDate, MenuEntry entry); } @@ -50,7 +50,7 @@ class MenuLocalDataSourceImpl implements MenuLocalDataSource { } @override - Future processDisplay(EnumMenuItem item, EnumDisplay display, MenuEntry opt, List entries) async { + Future handleMenu(EnumMenuItem item, EnumDisplay display, MenuEntry opt, List entries) async { try { switch (display.value) { case 'VISIVEL': @@ -75,13 +75,14 @@ class MenuLocalDataSourceImpl implements MenuLocalDataSource { Future processStartDate(String startDate, MenuEntry opt) async { try { if (startDate.isEmpty) return true; - final start = DateTime.tryParse(startDate); - return start != null && DateTime.now().isAfter(start); + final start = DateTime.tryParse(startDate); + if (start == null) return false; + return DateTime.now().isAfter(start); } catch (e) { log('Error processing start date for module ${opt.key}: $e'); } return false; - } + } @override Future processExpirationDate(String expirationDate, MenuEntry opt) async { diff --git a/lib/shared/components/molecules/menu/data/repositories/menu_repository_impl.dart b/lib/shared/components/molecules/menu/data/repositories/menu_repository_impl.dart index 36ca3e67..3f2c2f6f 100644 --- a/lib/shared/components/molecules/menu/data/repositories/menu_repository_impl.dart +++ b/lib/shared/components/molecules/menu/data/repositories/menu_repository_impl.dart @@ -1,12 +1,17 @@ +import 'dart:convert'; import 'dart:developer'; import 'package:hub/flutter_flow/custom_functions.dart'; +import 'package:hub/main.dart'; import 'package:hub/shared/components/molecules/menu/data/data_sources/menu_local_data_source.dart'; import 'package:hub/shared/components/molecules/menu/domain/respositories/menu_repository.dart'; import 'package:hub/shared/components/molecules/menu/index.dart'; import 'package:hub/shared/components/molecules/modules/index.dart'; +import 'package:hub/shared/extensions/string_extensions.dart'; +import 'package:hub/shared/helpers/storage/base_storage.dart'; +import 'package:hub/shared/helpers/storage/storage_helper.dart'; class MenuRepositoryImpl implements MenuRepository { @@ -17,21 +22,31 @@ class MenuRepositoryImpl implements MenuRepository { Future> generateMenuEntries(List menuEntries, EnumMenuItem item) async { log('Generating menu entries for $item'); List entries = []; + final bool isNewVersion = await StorageHelper().get(KeychainStorageKey.isNewVersion.value).then((v) => v.toBoolean()); + try { for (var entry in menuEntries) { - // log('Processing entry: ${entry.key}'); + log('Processing entry: ${entry.key}'); final bool isDefault = await menuDataSource.processDisplayDefault(item, entry, entries); if (isDefault) continue; final licenseValue = await LicenseRepositoryImpl().getLicense(entry.key); if (licenseValue != null) { final licenseMap = await stringToMap(licenseValue); - final display = EnumDisplay.fromString(licenseMap['display']); + final display = await processDisplay(licenseMap, isNewVersion); final startDate = licenseMap['startDate'] ?? ''; final expirationDate = licenseMap['expirationDate'] ?? ''; final isStarted = await menuDataSource.processStartDate(startDate, entry); final isExpired = await menuDataSource.processExpirationDate(expirationDate, entry); if (isStarted && !isExpired) { - await menuDataSource.processDisplay(item, display, entry, entries); + await menuDataSource.handleMenu(item, display, entry, entries); + } + if (isExpired) { + log('Entry ${entry.key} is expired'); + await menuDataSource.handleMenu(item, EnumDisplay.inactive, entry, entries); + } + if (!isStarted) { + log('Entry ${entry.key} is not started'); + await menuDataSource.handleMenu(item, EnumDisplay.inactive, entry, entries); } } } @@ -41,7 +56,21 @@ class MenuRepositoryImpl implements MenuRepository { return entries; } + Future processDisplay(Map module, bool isNewVersion) async { + const keysToCheck = [ + LicenseKeys.residents, + LicenseKeys.vehicles, + LicenseKeys.openedVisits + ]; + if (isNewVersion && keysToCheck.any((key) => module['key'] == key.value)) { + final displayValue = module['display'] == EnumDisplay.active ? 'VISIVEL' : 'INVISIVEL'; + await LicenseLocalDataSourceImpl().setDisplayByKey(['FRE-HUB-ABOUT-PROPERTY'], displayValue); + return EnumDisplay.fromString(displayValue); + } + + return EnumDisplay.fromString(module['display']); + } } \ No newline at end of file diff --git a/lib/shared/components/molecules/menu/presentation/mappers/menu_entry.dart b/lib/shared/components/molecules/menu/presentation/mappers/menu_entry.dart index 87875b39..02b59717 100644 --- a/lib/shared/components/molecules/menu/presentation/mappers/menu_entry.dart +++ b/lib/shared/components/molecules/menu/presentation/mappers/menu_entry.dart @@ -22,7 +22,7 @@ class MenuEntry implements BaseModule { static List entries = [ MenuEntry( - key: 'FRE-HUB-AGE-PROV-PRESTADOR', + key: 'FRE-HUB-AGE-PROV-PREST', icon: Icons.engineering_outlined, name: FFLocalizations.of(navigatorKey.currentContext!).getVariableText( ptText: 'Agendar Prestadores', @@ -61,12 +61,52 @@ class MenuEntry implements BaseModule { route: '/scheduleCompleteVisitPage', types: [MenuEntryType.Home, MenuEntryType.Drawer], ), + MenuEntry( + key: 'FRE-HUB-RESIDENTS', + icon: Icons.groups, + name: FFLocalizations.of(navigatorKey.currentContext!).getVariableText( + ptText: 'Moradores', + enText: 'Residents', + ), + route: '/residentsOnThePropertyPage', + types: [MenuEntryType.Property], + ), + MenuEntry( + key: 'FRE-HUB-VEHICLES', + icon: Icons.directions_car, + name: FFLocalizations.of(navigatorKey.currentContext!).getVariableText( + ptText: 'Veículos', + enText: 'Vehicles', + ), + route: '/vehiclesOnThePropertyPage', + types: [MenuEntryType.Property], + ), + MenuEntry( + key: 'FRE-HUB-OPENED-VISITS', + icon: Icons.perm_contact_calendar, + name: FFLocalizations.of(navigatorKey.currentContext!).getVariableText( + ptText: 'Visitas Abertas', + enText: 'Opened Visits', + ), + route: '/visitsOnThePropertyPage', + types: [MenuEntryType.Property], + ), + MenuEntry( + key: 'FRE-HUB-PETS-HISTORY', + icon: Icons.pets, + name: FFLocalizations.of(navigatorKey.currentContext!).getVariableText( + ptText: 'Pets', + enText: 'Pets', + ), + route: '/petsOnThePropertyPage', + types: [MenuEntryType.Property], + ), MenuEntry( key: 'FRE-HUB-ORDERS', icon: Icons.inventory_2_outlined, name: FFLocalizations.of(navigatorKey.currentContext!).getVariableText( - ptText: 'Minhas Encomendas', - enText: 'My Orders', + ptText: 'Encomendas', + enText: 'Orders', ), route: '/packageOrder', types: [MenuEntryType.Home, MenuEntryType.Drawer, MenuEntryType.Property], @@ -142,7 +182,7 @@ class MenuEntry implements BaseModule { types: [MenuEntryType.Home, MenuEntryType.Drawer], ), MenuEntry( - key: 'FRE-HUB-PROPERTY', + key: 'FRE-HUB-ABOUT-PROPERTY', icon: Icons.home, name: FFLocalizations.of(navigatorKey.currentContext!).getVariableText( ptText: 'Sobre a Propriedade', @@ -182,46 +222,6 @@ class MenuEntry implements BaseModule { route: '/WelcomePage', types: [MenuEntryType.Drawer], ), - MenuEntry( - key: 'FRE-HUB-RESIDENTS', - icon: Icons.groups, - name: FFLocalizations.of(navigatorKey.currentContext!).getVariableText( - ptText: 'Moradores', - enText: 'Residents', - ), - route: '/residentsOnThePropertyPage', - types: [MenuEntryType.Property], - ), - MenuEntry( - key: 'FRE-HUB-VEHICLES', - icon: Icons.directions_car, - name: FFLocalizations.of(navigatorKey.currentContext!).getVariableText( - ptText: 'Veículos na Propriedade', - enText: 'Vehicles on the Property', - ), - route: '/vehiclesOnThePropertyPage', - types: [MenuEntryType.Property], - ), - MenuEntry( - key: 'FRE-HUB-OPENED-VISITS', - icon: Icons.perm_contact_calendar, - name: FFLocalizations.of(navigatorKey.currentContext!).getVariableText( - ptText: 'Visitas Abertas', - enText: 'Opened Visits', - ), - route: '/visitsOnThePropertyPage', - types: [MenuEntryType.Property], - ), - MenuEntry( - key: 'FRE-HUB-PETS-HISTORY', - icon: Icons.pets, - name: FFLocalizations.of(navigatorKey.currentContext!).getVariableText( - ptText: 'Histórico de Pets', - enText: 'Pets History', - ), - route: '/petsOnThePropertyPage', - types: [MenuEntryType.Property], - ), ]; static List getEntriesByType(MenuEntryType type) { diff --git a/lib/shared/components/molecules/modules/constants/license_constants.dart b/lib/shared/components/molecules/modules/constants/license_constants.dart index 37ce1daf..9f12dd9a 100644 --- a/lib/shared/components/molecules/modules/constants/license_constants.dart +++ b/lib/shared/components/molecules/modules/constants/license_constants.dart @@ -27,15 +27,16 @@ String get updateDisplayTrigger => ''' CREATE TRIGGER update_display_trigger - AFTER UPDATE ON $tableLicense + AFTER INSERT ON $tableLicense WHEN NEW.key IN ('FRE-HUB-OPENED-VISITS', 'FRE-HUB-VEHICLES', 'FRE-HUB-RESIDENTS') BEGIN UPDATE $tableLicense - SET display = CASE - WHEN (SELECT COUNT(*) FROM $tableLicense WHERE key IN ('FRE-HUB-OPENED-VISITS', 'FRE-HUB-VEHICLES', 'FRE-HUB-RESIDENTS') AND display = 'VISIVEL') > 0 - THEN 'VISIVEL' - ELSE 'INVISIVEL' - END + SET display = + CASE + WHEN (SELECT COUNT(*) FROM $tableLicense WHERE key IN ('FRE-HUB-OPENED-VISITS', 'FRE-HUB-VEHICLES', 'FRE-HUB-RESIDENTS') AND display = 'VISIVEL') > 0 + THEN 'VISIVEL' + ELSE 'INVISIVEL' + END WHERE key = 'FRE-HUB-ABOUT-PROPERTY'; END; '''; diff --git a/lib/shared/components/molecules/modules/data/data_sources/license_local_data_source.dart b/lib/shared/components/molecules/modules/data/data_sources/license_local_data_source.dart index 138e114f..65291d10 100644 --- a/lib/shared/components/molecules/modules/data/data_sources/license_local_data_source.dart +++ b/lib/shared/components/molecules/modules/data/data_sources/license_local_data_source.dart @@ -1,4 +1,6 @@ +import 'dart:developer'; + import 'package:hub/shared/components/molecules/modules/index.dart'; import 'package:hub/shared/helpers/database/database_helper.dart'; import 'package:hub/shared/helpers/storage/base_storage.dart'; @@ -28,17 +30,17 @@ class LicenseLocalDataSourceImpl implements LicenseLocalDataSource { } @override - Future setDisplayByKey(final List key, final String display) async { - if (key.isEmpty) return; - for (var element in key) { - if (element != null) { - await set(element, { - 'display': display, - 'expirationDate': '', - 'startDate': '', - 'quantity': '', - }); - } + Future setDisplayByKey(final List keys, final String display) async { + if (keys.isEmpty) return; + final validKeys = keys.where((key) => key.isNotEmpty).toList(); + for (var key in validKeys) { + log('Setting display: $key : $display'); + await set(key, { + 'display': display, + 'expirationDate': '', + 'startDate': '', + 'quantity': '', + }); } } @@ -55,13 +57,20 @@ class LicenseLocalDataSourceImpl implements LicenseLocalDataSource { if (response.isEmpty) { return null; } - return response.first.toString(); + + log('Getting StartDate: ${response.toString()}'); + + return response.toString(); } @override Future set(String key, T value) async { value as Map; + if (value.isEmpty) return; + if (key == 'null') return; + + log('Setting: ${value['key']} : ${value['display']}'); await DatabaseStorage.database.insert( tableLicense, { diff --git a/lib/shared/components/molecules/modules/data/data_sources/license_remote_data_source.dart b/lib/shared/components/molecules/modules/data/data_sources/license_remote_data_source.dart index 23427808..bd0cee47 100644 --- a/lib/shared/components/molecules/modules/data/data_sources/license_remote_data_source.dart +++ b/lib/shared/components/molecules/modules/data/data_sources/license_remote_data_source.dart @@ -46,26 +46,26 @@ class LicenseRemoteDataSourceImpl implements LicenseRemoteDataSource { .where((module) => module.display == ModuleStatus.inactive.key) .map((module) => module.key) .toList(); + log('Módulos inativos: $inactiveModuleKey'); final List activeModuleKey = license.modules .where((module) => module.display == ModuleStatus.active.key) .map((module) => module.key) .toList(); + log('Módulos ativos: $activeModuleKey'); final List disabledModuleKey = license.modules .where((module) => module.display == ModuleStatus.disabled.key) .map((module) => module.key) .toList(); + log('Módulos desabilitados: $disabledModuleKey'); await LicenseLocalDataSourceImpl().setDisplayByKey(inactiveModuleKey, 'INVISIVEL'); await LicenseLocalDataSourceImpl().setDisplayByKey(activeModuleKey, 'VISIVEL'); - if (isNewVersion == true) { - await LicenseLocalDataSourceImpl().setDisplayByKey(disabledModuleKey, 'VISIVEL'); - await LicenseLocalDataSourceImpl().setDisplayByKey(['FRE-HUB-PROPERTY'], 'VISIVEL'); - } else { - await LicenseLocalDataSourceImpl().setDisplayByKey(disabledModuleKey, 'DESABILITADO'); - } - + await LicenseLocalDataSourceImpl().setDisplayByKey(disabledModuleKey, 'DESABILITADO'); + + + return true; } catch (e, s) { log('Erro ao configurar licenças: $e', stackTrace: s); @@ -92,16 +92,21 @@ class LicenseRemoteDataSourceImpl implements LicenseRemoteDataSource { if (responseBody == []) { // return await setupLicense(DatabaseStorage.database, isNewVersion); - return false; + return true; } + log('Valores: ${LicenseKeys.values.map((e) => e.value).toList()}'); List> saveOperations = []; for (var element in responseBody) { + log('Elemento: ${element['key']}'); if (licenseContainsKey(element['key'])) { + log('Salvando licença: ${element['key']}'); saveOperations.add(_saveModule(element)); } } await Future.wait(saveOperations); + final String? v = await LicenseRepositoryImpl().getLicense(LicenseKeys.property.value); + log('Licenças obtidas: $v'); return true; } catch (e, s) { log('Erro ao obter licenças: $e', stackTrace: s); @@ -115,11 +120,14 @@ class LicenseRemoteDataSourceImpl implements LicenseRemoteDataSource { } static bool licenseContainsKey(final String key) { - return LicenseKeys.values.map((e) => e.value).contains(key); + log('licenseContainsKey: $key'); + + return LicenseKeys.values.map((e) => e.value).toList().contains(key); } static Future _saveModule(final dynamic body) async { + log('Salvando módulo: ${body['key']}'); if (body is! Map) return; - await LicenseLocalDataSourceImpl().set(body['key'], body); + await LicenseRepositoryImpl().setLicense(body['key'], body); } } diff --git a/lib/shared/components/molecules/modules/domain/entities/license.dart b/lib/shared/components/molecules/modules/domain/entities/license.dart index a89b241b..66ed8bd2 100644 --- a/lib/shared/components/molecules/modules/domain/entities/license.dart +++ b/lib/shared/components/molecules/modules/domain/entities/license.dart @@ -18,9 +18,9 @@ enum LicenseKeys { pets('FRE-HUB-PETS'), orders('FRE-HUB-ORDERS'), completeSchedule('FRE-HUB-COMPLETE-SCHEDULE'), - providerSchedule('FRE-HUB-AGE-PROV-PRESTADOR'), + providerSchedule('FRE-HUB-AGE-PROV-PREST'), deliverySchedule('FRE-HUB-AGE-PROV-DELIVERY'), - property('FRE-HUB-PROPERTY'), + property('FRE-HUB-ABOUT-PROPERTY'), fastPass('FRE-HUB-FASTPASS'), visitors('FRE-HUB-VISITORS'), qrCode('FRE-HUB-QRCODE'), @@ -198,7 +198,7 @@ class License { ), Module( key: LicenseKeys.property.value, - display: isNewVersionWithModule ? ModuleStatus.active.key : ModuleStatus.inactive.key, + display: isNewVersionWithModule ? ModuleStatus.inactive.key : ModuleStatus.inactive.key, expirationDate: '', startDate: '', quantity: 0, diff --git a/lib/shared/helpers/database/database_helper.dart b/lib/shared/helpers/database/database_helper.dart index 258e81d7..bd8f1e2d 100644 --- a/lib/shared/helpers/database/database_helper.dart +++ b/lib/shared/helpers/database/database_helper.dart @@ -7,7 +7,7 @@ import 'dart:developer'; class DatabaseStorage { static final String _dbName = 'database.db'; - static final int _dbVersion = 4; + static final int _dbVersion = 2; static final DatabaseStorage instance = DatabaseStorage._internal(); factory DatabaseStorage() => instance; @@ -42,11 +42,6 @@ class DatabaseStorage { await database.execute(createLicenseTable); if (version >= 2) { await database.execute(updatePetsHistoryTrigger); - } - if (version >= 3) { - await database.execute(updateDisplayTrigger); - } - if (version >= 4) { await database.execute(updatePeopleDisplayTrigger); } } @@ -56,24 +51,18 @@ class DatabaseStorage { if (oldVersion < 2 && newVersion >= 2) { await database.execute(createLicenseTable); await database.execute(updatePetsHistoryTrigger); - } - if (oldVersion < 3 && newVersion >= 3) { - await database.execute(updateDisplayTrigger); - } - if (oldVersion < 4 && newVersion >= 4) { await database.execute(updatePeopleDisplayTrigger); } + + + } Future _onDowngrade(Database database, int oldVersion, int newVersion) async { log('Downgrading database from version $oldVersion to $newVersion...'); - if (oldVersion >= 4 && newVersion < 4) { - await database.execute(dropPeopleDisplayTrigger); - } - if (oldVersion >= 3 && newVersion < 3) { - await database.execute(dropDisplayTrigger); - } if (oldVersion >= 2 && newVersion < 2) { + await database.execute(deleteLicenseTable); + await database.execute(dropPeopleDisplayTrigger); await database.execute(dropPetsHistoryTrigger); } } diff --git a/lib/shared/helpers/storage/base_storage.dart b/lib/shared/helpers/storage/base_storage.dart index fa1d47c7..f63582ec 100644 --- a/lib/shared/helpers/storage/base_storage.dart +++ b/lib/shared/helpers/storage/base_storage.dart @@ -80,6 +80,7 @@ enum KeychainStorageKey { status, userName, clientUUID, + ownerName, ownerUUID, clientName, petAmount, @@ -115,6 +116,8 @@ extension KeychainStorageKeyExtension on KeychainStorageKey { return 'fre_ownerUUID'; case KeychainStorageKey.clientName: return 'fre_cliName'; + case KeychainStorageKey.ownerName: + return 'fre_ownerName'; case KeychainStorageKey.petAmount: return 'fre_petAmountRegister'; case KeychainStorageKey.whatsapp: