WIP: backup

This commit is contained in:
J. A. Messias 2024-12-05 17:12:34 -03:00
parent 758ee5148e
commit 4925433c92
17 changed files with 224 additions and 134 deletions

View File

@ -106,6 +106,7 @@ class _BottomArrowLinkedLocalsComponentWidgetState extends State<BottomArrowLink
final local = locals[0]; final local = locals[0];
await StorageHelper().set(KeychainStorageKey.clientName.value, local['CLI_NOME']); await StorageHelper().set(KeychainStorageKey.clientName.value, local['CLI_NOME']);
await StorageHelper().set(KeychainStorageKey.ownerName.value, local['CLU_OWNER_DSC']);
await StorageHelper().set(KeychainStorageKey.clientUUID.value, local['CLI_ID']); await StorageHelper().set(KeychainStorageKey.clientUUID.value, local['CLI_ID']);
await StorageHelper().set(KeychainStorageKey.ownerUUID.value, local['CLU_OWNER_ID']); await StorageHelper().set(KeychainStorageKey.ownerUUID.value, local['CLU_OWNER_ID']);
@ -197,6 +198,7 @@ class _BottomArrowLinkedLocalsComponentWidgetState extends State<BottomArrowLink
if (local['CLU_STATUS'] == 'A') { if (local['CLU_STATUS'] == 'A') {
await StorageHelper().set(KeychainStorageKey.clientUUID.value, local['CLI_ID']); await StorageHelper().set(KeychainStorageKey.clientUUID.value, local['CLI_ID']);
await StorageHelper().set(KeychainStorageKey.clientName.value, local['CLI_NOME']); await StorageHelper().set(KeychainStorageKey.clientName.value, local['CLI_NOME']);
await StorageHelper().set(KeychainStorageKey.ownerName.value, local['CLU_OWNER_DSC']);
await StorageHelper().set(KeychainStorageKey.ownerUUID.value, local['CLU_OWNER_ID']); await StorageHelper().set(KeychainStorageKey.ownerUUID.value, local['CLU_OWNER_ID']);
context.pop(true); context.pop(true);

View File

@ -42,7 +42,7 @@ Future<Map<String, String>> stringToMap(String v) async {
throw FormatException('Invalid key-value pair: $part of $v'); throw FormatException('Invalid key-value pair: $part of $v');
} }
final key = keyValue[0].trim(); 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); return MapEntry(key, value);
}), }),
)); ));

View File

@ -59,8 +59,8 @@ class _PetsHistoryScreenState extends State<PetsHistoryScreen> with TickerProvid
backgroundColor: FlutterFlowTheme.of(context).primaryBackground, backgroundColor: FlutterFlowTheme.of(context).primaryBackground,
automaticallyImplyLeading: false, automaticallyImplyLeading: false,
title: Text(FFLocalizations.of(context).getVariableText( title: Text(FFLocalizations.of(context).getVariableText(
ptText: 'Cadastrar Pets', ptText: 'Pets',
enText: 'Pets Register', enText: 'Pets',
), ),
style: FlutterFlowTheme.of(context).headlineMedium.override( style: FlutterFlowTheme.of(context).headlineMedium.override(
fontFamily: 'Nunito', fontFamily: 'Nunito',

View File

@ -46,7 +46,7 @@ class LocalsRemoteDataSourceImpl implements LocalsRemoteDataSource {
enText: 'Verify your connection', enText: 'Verify your connection',
ptText: 'Verifique sua conexão', 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; return;
} }
@ -86,7 +86,7 @@ class LocalsRemoteDataSourceImpl implements LocalsRemoteDataSource {
enText: 'Verify your connection', enText: 'Verify your connection',
ptText: 'Verifique sua conexão', 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; return false;
} }
@ -137,7 +137,7 @@ class LocalsRemoteDataSourceImpl implements LocalsRemoteDataSource {
enText: 'Error getting locals, verify your connection', enText: 'Error getting locals, verify your connection',
ptText: 'Erro ao obter locais, verifique sua conexão', 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; return false;
} }
} }
@ -154,7 +154,7 @@ class LocalsRemoteDataSourceImpl implements LocalsRemoteDataSource {
enText: 'Verify your connection', enText: 'Verify your connection',
ptText: 'Verifique sua conexão', 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; return false;
} }
@ -163,7 +163,7 @@ class LocalsRemoteDataSourceImpl implements LocalsRemoteDataSource {
final GetLocalsCall callback = PhpGroup.getLocalsCall; final GetLocalsCall callback = PhpGroup.getLocalsCall;
response = await callback.call(); response = await callback.call();
final String errorMsg = response.jsonBody['error_msg'] ?? 'Local indisponível'; 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; return false;
} else { } else {
await LocalUtil.updateStorageUtil(response.jsonBody); await LocalUtil.updateStorageUtil(response.jsonBody);
@ -175,7 +175,7 @@ class LocalsRemoteDataSourceImpl implements LocalsRemoteDataSource {
enText: 'Error getting data, verify your connection', enText: 'Error getting data, verify your connection',
ptText: 'Erro ao obter dados, verifique sua conexão', 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; return false;
} }
} }
@ -212,6 +212,7 @@ class LocalsRemoteDataSourceImpl implements LocalsRemoteDataSource {
await PhpGroup.resopndeVinculo.call(tarefa: 'I').then((value) async { await PhpGroup.resopndeVinculo.call(tarefa: 'I').then((value) async {
if (value.jsonBody['error'] == false) { if (value.jsonBody['error'] == false) {
await StorageHelper().set(KeychainStorageKey.clientName.value, ''); await StorageHelper().set(KeychainStorageKey.clientName.value, '');
await StorageHelper().set(KeychainStorageKey.ownerName.value, '');
await StorageHelper().set(KeychainStorageKey.clientUUID.value, ''); await StorageHelper().set(KeychainStorageKey.clientUUID.value, '');
context.pop(); context.pop();
context.go( context.go(

View File

@ -4,6 +4,9 @@ import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:hub/shared/components/molecules/locals/index.dart'; import 'package:hub/shared/components/molecules/locals/index.dart';
import 'package:hub/shared/components/molecules/modules/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'; import 'package:rxdart/rxdart.dart';
class LocalsRepositoryImpl implements LocalsRepository { class LocalsRepositoryImpl implements LocalsRepository {
@ -19,10 +22,16 @@ class LocalsRepositoryImpl implements LocalsRepository {
@override @override
Future<bool> update(BuildContext context) async { Future<bool> update(BuildContext context) async {
// LocalsRepositoryImpl.license.add(false); bool response = false;
final bool response = await remoteDataSource.processLocals(context); 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<LocalProfileBloc>().add(LocalProfileEvent()); context.read<LocalProfileBloc>().add(LocalProfileEvent());
// LocalsRepositoryImpl.license.add(response);
return response; return response;
} }

View File

@ -16,13 +16,15 @@ class LocalProfileEvent {
class LocalProfileState { class LocalProfileState {
final String cliName; final String cliName;
final String cliUUID; 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( return LocalProfileState(
cliName: cliName ?? this.cliName, cliName: cliName ?? this.cliName,
ownerName: ownerName ?? this.ownerName,
cliUUID: cliUUID ?? this.cliUUID, cliUUID: cliUUID ?? this.cliUUID,
); );
} }
@ -36,8 +38,9 @@ class LocalProfileBloc extends Bloc<LocalProfileEvent, LocalProfileState> {
Future<void> _onLocalProfileEvent(LocalProfileEvent event, Emitter<LocalProfileState> emit) async { Future<void> _onLocalProfileEvent(LocalProfileEvent event, Emitter<LocalProfileState> emit) async {
log('LocalProfileBloc: _onLocalProfileEvent'); log('LocalProfileBloc: _onLocalProfileEvent');
final cliName = (await StorageHelper().get(KeychainStorageKey.clientName.value)) ?? ''; final cliName = (await StorageHelper().get(KeychainStorageKey.clientName.value)) ?? '';
final ownerName = (await StorageHelper().get(KeychainStorageKey.ownerName.value)) ?? '';
final cliUUID = (await StorageHelper().get(KeychainStorageKey.clientUUID.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) { // void updateProfile(BuildContext context) {
@ -51,6 +54,7 @@ class LocalProfileBloc extends Bloc<LocalProfileEvent, LocalProfileState> {
class LocalProfileComponentModel extends FlutterFlowModel<LocalProfileComponentWidget> { class LocalProfileComponentModel extends FlutterFlowModel<LocalProfileComponentWidget> {
String cliName = ''; String cliName = '';
String cliUUID = ''; String cliUUID = '';
String ownerName = '';
VoidCallback? setStateCallback; VoidCallback? setStateCallback;
@override @override
@ -60,6 +64,7 @@ class LocalProfileComponentModel extends FlutterFlowModel<LocalProfileComponentW
Future<void> getData() async { Future<void> getData() async {
cliName = (await StorageHelper().get(KeychainStorageKey.clientName.value)) ?? ''; cliName = (await StorageHelper().get(KeychainStorageKey.clientName.value)) ?? '';
ownerName = (await StorageHelper().get(KeychainStorageKey.ownerName.value)) ?? '';
cliUUID = (await StorageHelper().get(KeychainStorageKey.clientUUID.value)) ?? ''; cliUUID = (await StorageHelper().get(KeychainStorageKey.clientUUID.value)) ?? '';
setStateCallback?.call(); setStateCallback?.call();
} }

View File

@ -211,33 +211,61 @@ class _LocalProfileComponentWidgetState extends State<LocalProfileComponentWidge
), ),
), ),
Expanded( Expanded(
child: Tooltip( child: Column(
message: valueOrDefault<String>( crossAxisAlignment: CrossAxisAlignment.start,
convertToUppercase(state.cliName), mainAxisAlignment: MainAxisAlignment.center,
FFLocalizations.of(context).getVariableText( children: [
ptText: 'SEM LOCAL VINCULADO', Tooltip(
enText: 'NO LINKED LOCAL', message: valueOrDefault<String>(
), convertToUppercase(state.cliName),
), FFLocalizations.of(context).getVariableText(
child: Text( ptText: 'SEM LOCAL VINCULADO',
valueOrDefault<String>( enText: 'NO LINKED LOCAL',
convertToUppercase(state.cliName), ),
FFLocalizations.of(context).getVariableText( ),
ptText: 'SEM LOCAL VINCULADO', child: Text(
enText: 'NO LINKED LOCAL', valueOrDefault<String>(
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, Tooltip(
maxLines: 1, message: valueOrDefault<String>(
style: FlutterFlowTheme.of(context).labelMedium.override( ' '+state.ownerName,
''
),
child: Text(
valueOrDefault<String>(
state.ownerName.length > 30 ? '${state.ownerName.substring(0, 20)}...' : state.ownerName,
''
),
overflow: TextOverflow.ellipsis,
maxLines: 1,
style: FlutterFlowTheme.of(context).labelMedium.override(
fontFamily: 'Nunito', fontFamily: 'Nunito',
color: FlutterFlowTheme.of(context).info, color: FlutterFlowTheme.of(context).info,
fontSize: limitedFontSize, fontSize: limitedFontSize,
letterSpacing: 0.0, letterSpacing: 0.0,
fontWeight: FontWeight.w500, fontWeight: FontWeight.w500,
useGoogleFonts: GoogleFonts.asMap().containsKey('Nunito'), useGoogleFonts: GoogleFonts.asMap().containsKey('Nunito'),
),
), ),
), ),
],
), ),
), ),
].divide(const SizedBox(width: 20.0)).addToStart(const SizedBox(width: 20.0)).addToEnd(const SizedBox(width: 20.0)), ].divide(const SizedBox(width: 20.0)).addToStart(const SizedBox(width: 20.0)).addToEnd(const SizedBox(width: 20.0)),

View File

@ -36,7 +36,7 @@ class LocalUtil {
await DialogUtil.warning(context, errorMsg); await DialogUtil.warning(context, errorMsg);
return; 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<bool> handleUnavailable(BuildContext context, List<dynamic> locals) async { static Future<bool> handleUnavailable(BuildContext context, List<dynamic> locals) async {
@ -45,11 +45,15 @@ class LocalUtil {
await StorageHelper().set(KeychainStorageKey.clientUUID.value, locals[0]['CLI_ID']); 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.ownerUUID.value, locals[0]['CLU_OWNER_ID']);
await StorageHelper().set(KeychainStorageKey.clientName.value, locals[0]['CLI_NOME']); 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'); var response = await PhpGroup.resopndeVinculo.call(tarefa: 'A');
if (response.jsonBody['error'] == true) { if (response.jsonBody['error'] == true) {
await StorageHelper().set(KeychainStorageKey.clientUUID.value, ''); await StorageHelper().set(KeychainStorageKey.clientUUID.value, '');
await StorageHelper().set(KeychainStorageKey.ownerUUID.value, ''); await StorageHelper().set(KeychainStorageKey.ownerUUID.value, '');
await StorageHelper().set(KeychainStorageKey.clientName.value, ''); await StorageHelper().set(KeychainStorageKey.clientName.value, '');
await StorageHelper().set(KeychainStorageKey.ownerName.value, '');
return false; return false;
} }
if (response.jsonBody['error'] == false) return await LocalsRemoteDataSourceImpl().processData(context).then((value) => value); 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.clientUUID.value, local['CLI_ID']);
await StorageHelper().set(KeychainStorageKey.ownerUUID.value, local['CLU_OWNER_ID']); await StorageHelper().set(KeychainStorageKey.ownerUUID.value, local['CLU_OWNER_ID']);
await StorageHelper().set(KeychainStorageKey.clientName.value, local['CLI_NOME']); 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']); await StorageHelper().set(KeychainStorageKey.userName.value, local['USU_NOME']);
return await LocalsRemoteDataSourceImpl().processData(context); return await LocalsRemoteDataSourceImpl().processData(context);
} }

View File

@ -14,7 +14,7 @@ import '../../../modules/domain/entities/index.dart';
abstract class MenuLocalDataSource { abstract class MenuLocalDataSource {
Future<MenuItem?> addMenuEntry(EnumMenuItem item, List<MenuItem?> entries, IconData icon, String text, Function() action); Future<MenuItem?> addMenuEntry(EnumMenuItem item, List<MenuItem?> entries, IconData icon, String text, Function() action);
Future<bool> processDisplayDefault(EnumMenuItem item, MenuEntry opt, List<MenuItem?> entries); Future<bool> processDisplayDefault(EnumMenuItem item, MenuEntry opt, List<MenuItem?> entries);
Future<void> processDisplay(EnumMenuItem item, EnumDisplay display, MenuEntry opt, List<MenuItem?> entries); Future<void> handleMenu(EnumMenuItem item, EnumDisplay display, MenuEntry opt, List<MenuItem?> entries);
Future<bool> processStartDate(String startDate, MenuEntry entry); Future<bool> processStartDate(String startDate, MenuEntry entry);
Future<bool> processExpirationDate(String expirationDate, MenuEntry entry); Future<bool> processExpirationDate(String expirationDate, MenuEntry entry);
} }
@ -50,7 +50,7 @@ class MenuLocalDataSourceImpl implements MenuLocalDataSource {
} }
@override @override
Future<void> processDisplay(EnumMenuItem item, EnumDisplay display, MenuEntry opt, List<MenuItem?> entries) async { Future<void> handleMenu(EnumMenuItem item, EnumDisplay display, MenuEntry opt, List<MenuItem?> entries) async {
try { try {
switch (display.value) { switch (display.value) {
case 'VISIVEL': case 'VISIVEL':
@ -75,13 +75,14 @@ class MenuLocalDataSourceImpl implements MenuLocalDataSource {
Future<bool> processStartDate(String startDate, MenuEntry opt) async { Future<bool> processStartDate(String startDate, MenuEntry opt) async {
try { try {
if (startDate.isEmpty) return true; if (startDate.isEmpty) return true;
final start = DateTime.tryParse(startDate); final start = DateTime.tryParse(startDate);
return start != null && DateTime.now().isAfter(start); if (start == null) return false;
return DateTime.now().isAfter(start);
} catch (e) { } catch (e) {
log('Error processing start date for module ${opt.key}: $e'); log('Error processing start date for module ${opt.key}: $e');
} }
return false; return false;
} }
@override @override
Future<bool> processExpirationDate(String expirationDate, MenuEntry opt) async { Future<bool> processExpirationDate(String expirationDate, MenuEntry opt) async {

View File

@ -1,12 +1,17 @@
import 'dart:convert';
import 'dart:developer'; import 'dart:developer';
import 'package:hub/flutter_flow/custom_functions.dart'; 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/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/domain/respositories/menu_repository.dart';
import 'package:hub/shared/components/molecules/menu/index.dart'; import 'package:hub/shared/components/molecules/menu/index.dart';
import 'package:hub/shared/components/molecules/modules/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 { class MenuRepositoryImpl implements MenuRepository {
@ -17,21 +22,31 @@ class MenuRepositoryImpl implements MenuRepository {
Future<List<MenuItem?>> generateMenuEntries(List<MenuEntry> menuEntries, EnumMenuItem item) async { Future<List<MenuItem?>> generateMenuEntries(List<MenuEntry> menuEntries, EnumMenuItem item) async {
log('Generating menu entries for $item'); log('Generating menu entries for $item');
List<MenuItem?> entries = []; List<MenuItem?> entries = [];
final bool isNewVersion = await StorageHelper().get(KeychainStorageKey.isNewVersion.value).then((v) => v.toBoolean());
try { try {
for (var entry in menuEntries) { for (var entry in menuEntries) {
// log('Processing entry: ${entry.key}'); log('Processing entry: ${entry.key}');
final bool isDefault = await menuDataSource.processDisplayDefault(item, entry, entries); final bool isDefault = await menuDataSource.processDisplayDefault(item, entry, entries);
if (isDefault) continue; if (isDefault) continue;
final licenseValue = await LicenseRepositoryImpl().getLicense(entry.key); final licenseValue = await LicenseRepositoryImpl().getLicense(entry.key);
if (licenseValue != null) { if (licenseValue != null) {
final licenseMap = await stringToMap(licenseValue); final licenseMap = await stringToMap(licenseValue);
final display = EnumDisplay.fromString(licenseMap['display']); final display = await processDisplay(licenseMap, isNewVersion);
final startDate = licenseMap['startDate'] ?? ''; final startDate = licenseMap['startDate'] ?? '';
final expirationDate = licenseMap['expirationDate'] ?? ''; final expirationDate = licenseMap['expirationDate'] ?? '';
final isStarted = await menuDataSource.processStartDate(startDate, entry); final isStarted = await menuDataSource.processStartDate(startDate, entry);
final isExpired = await menuDataSource.processExpirationDate(expirationDate, entry); final isExpired = await menuDataSource.processExpirationDate(expirationDate, entry);
if (isStarted && !isExpired) { 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; return entries;
} }
Future<EnumDisplay> processDisplay(Map<String, dynamic> 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']);
}
} }

View File

@ -22,7 +22,7 @@ class MenuEntry implements BaseModule {
static List<MenuEntry> entries = [ static List<MenuEntry> entries = [
MenuEntry( MenuEntry(
key: 'FRE-HUB-AGE-PROV-PRESTADOR', key: 'FRE-HUB-AGE-PROV-PREST',
icon: Icons.engineering_outlined, icon: Icons.engineering_outlined,
name: FFLocalizations.of(navigatorKey.currentContext!).getVariableText( name: FFLocalizations.of(navigatorKey.currentContext!).getVariableText(
ptText: 'Agendar Prestadores', ptText: 'Agendar Prestadores',
@ -61,12 +61,52 @@ class MenuEntry implements BaseModule {
route: '/scheduleCompleteVisitPage', route: '/scheduleCompleteVisitPage',
types: [MenuEntryType.Home, MenuEntryType.Drawer], 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( MenuEntry(
key: 'FRE-HUB-ORDERS', key: 'FRE-HUB-ORDERS',
icon: Icons.inventory_2_outlined, icon: Icons.inventory_2_outlined,
name: FFLocalizations.of(navigatorKey.currentContext!).getVariableText( name: FFLocalizations.of(navigatorKey.currentContext!).getVariableText(
ptText: 'Minhas Encomendas', ptText: 'Encomendas',
enText: 'My Orders', enText: 'Orders',
), ),
route: '/packageOrder', route: '/packageOrder',
types: [MenuEntryType.Home, MenuEntryType.Drawer, MenuEntryType.Property], types: [MenuEntryType.Home, MenuEntryType.Drawer, MenuEntryType.Property],
@ -142,7 +182,7 @@ class MenuEntry implements BaseModule {
types: [MenuEntryType.Home, MenuEntryType.Drawer], types: [MenuEntryType.Home, MenuEntryType.Drawer],
), ),
MenuEntry( MenuEntry(
key: 'FRE-HUB-PROPERTY', key: 'FRE-HUB-ABOUT-PROPERTY',
icon: Icons.home, icon: Icons.home,
name: FFLocalizations.of(navigatorKey.currentContext!).getVariableText( name: FFLocalizations.of(navigatorKey.currentContext!).getVariableText(
ptText: 'Sobre a Propriedade', ptText: 'Sobre a Propriedade',
@ -182,46 +222,6 @@ class MenuEntry implements BaseModule {
route: '/WelcomePage', route: '/WelcomePage',
types: [MenuEntryType.Drawer], 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<MenuEntry> getEntriesByType(MenuEntryType type) { static List<MenuEntry> getEntriesByType(MenuEntryType type) {

View File

@ -27,15 +27,16 @@
String get updateDisplayTrigger => ''' String get updateDisplayTrigger => '''
CREATE TRIGGER update_display_trigger 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') WHEN NEW.key IN ('FRE-HUB-OPENED-VISITS', 'FRE-HUB-VEHICLES', 'FRE-HUB-RESIDENTS')
BEGIN BEGIN
UPDATE $tableLicense UPDATE $tableLicense
SET display = CASE SET display =
WHEN (SELECT COUNT(*) FROM $tableLicense WHERE key IN ('FRE-HUB-OPENED-VISITS', 'FRE-HUB-VEHICLES', 'FRE-HUB-RESIDENTS') AND display = 'VISIVEL') > 0 CASE
THEN 'VISIVEL' WHEN (SELECT COUNT(*) FROM $tableLicense WHERE key IN ('FRE-HUB-OPENED-VISITS', 'FRE-HUB-VEHICLES', 'FRE-HUB-RESIDENTS') AND display = 'VISIVEL') > 0
ELSE 'INVISIVEL' THEN 'VISIVEL'
END ELSE 'INVISIVEL'
END
WHERE key = 'FRE-HUB-ABOUT-PROPERTY'; WHERE key = 'FRE-HUB-ABOUT-PROPERTY';
END; END;
'''; ''';

View File

@ -1,4 +1,6 @@
import 'dart:developer';
import 'package:hub/shared/components/molecules/modules/index.dart'; import 'package:hub/shared/components/molecules/modules/index.dart';
import 'package:hub/shared/helpers/database/database_helper.dart'; import 'package:hub/shared/helpers/database/database_helper.dart';
import 'package:hub/shared/helpers/storage/base_storage.dart'; import 'package:hub/shared/helpers/storage/base_storage.dart';
@ -28,17 +30,17 @@ class LicenseLocalDataSourceImpl implements LicenseLocalDataSource {
} }
@override @override
Future<void> setDisplayByKey(final List<String?> key, final String display) async { Future<void> setDisplayByKey(final List<String> keys, final String display) async {
if (key.isEmpty) return; if (keys.isEmpty) return;
for (var element in key) { final validKeys = keys.where((key) => key.isNotEmpty).toList();
if (element != null) { for (var key in validKeys) {
await set(element, { log('Setting display: $key : $display');
'display': display, await set(key, {
'expirationDate': '', 'display': display,
'startDate': '', 'expirationDate': '',
'quantity': '', 'startDate': '',
}); 'quantity': '',
} });
} }
} }
@ -55,13 +57,20 @@ class LicenseLocalDataSourceImpl implements LicenseLocalDataSource {
if (response.isEmpty) { if (response.isEmpty) {
return null; return null;
} }
return response.first.toString();
log('Getting StartDate: ${response.toString()}');
return response.toString();
} }
@override @override
Future<void> set<T>(String key, T value) async { Future<void> set<T>(String key, T value) async {
value as Map<String, dynamic>; value as Map<String, dynamic>;
if (value.isEmpty) return;
if (key == 'null') return;
log('Setting: ${value['key']} : ${value['display']}');
await DatabaseStorage.database.insert( await DatabaseStorage.database.insert(
tableLicense, tableLicense,
{ {

View File

@ -46,26 +46,26 @@ class LicenseRemoteDataSourceImpl implements LicenseRemoteDataSource {
.where((module) => module.display == ModuleStatus.inactive.key) .where((module) => module.display == ModuleStatus.inactive.key)
.map((module) => module.key) .map((module) => module.key)
.toList(); .toList();
log('Módulos inativos: $inactiveModuleKey');
final List<String> activeModuleKey = license.modules final List<String> activeModuleKey = license.modules
.where((module) => module.display == ModuleStatus.active.key) .where((module) => module.display == ModuleStatus.active.key)
.map((module) => module.key) .map((module) => module.key)
.toList(); .toList();
log('Módulos ativos: $activeModuleKey');
final List<String> disabledModuleKey = license.modules final List<String> disabledModuleKey = license.modules
.where((module) => module.display == ModuleStatus.disabled.key) .where((module) => module.display == ModuleStatus.disabled.key)
.map((module) => module.key) .map((module) => module.key)
.toList(); .toList();
log('Módulos desabilitados: $disabledModuleKey');
await LicenseLocalDataSourceImpl().setDisplayByKey(inactiveModuleKey, 'INVISIVEL'); await LicenseLocalDataSourceImpl().setDisplayByKey(inactiveModuleKey, 'INVISIVEL');
await LicenseLocalDataSourceImpl().setDisplayByKey(activeModuleKey, 'VISIVEL'); await LicenseLocalDataSourceImpl().setDisplayByKey(activeModuleKey, 'VISIVEL');
if (isNewVersion == true) { await LicenseLocalDataSourceImpl().setDisplayByKey(disabledModuleKey, 'DESABILITADO');
await LicenseLocalDataSourceImpl().setDisplayByKey(disabledModuleKey, 'VISIVEL');
await LicenseLocalDataSourceImpl().setDisplayByKey(['FRE-HUB-PROPERTY'], 'VISIVEL');
} else {
await LicenseLocalDataSourceImpl().setDisplayByKey(disabledModuleKey, 'DESABILITADO');
}
return true; return true;
} catch (e, s) { } catch (e, s) {
log('Erro ao configurar licenças: $e', stackTrace: s); log('Erro ao configurar licenças: $e', stackTrace: s);
@ -92,16 +92,21 @@ class LicenseRemoteDataSourceImpl implements LicenseRemoteDataSource {
if (responseBody == []) { if (responseBody == []) {
// return await setupLicense(DatabaseStorage.database, isNewVersion); // return await setupLicense(DatabaseStorage.database, isNewVersion);
return false; return true;
} }
log('Valores: ${LicenseKeys.values.map((e) => e.value).toList()}');
List<Future<void>> saveOperations = []; List<Future<void>> saveOperations = [];
for (var element in responseBody) { for (var element in responseBody) {
log('Elemento: ${element['key']}');
if (licenseContainsKey(element['key'])) { if (licenseContainsKey(element['key'])) {
log('Salvando licença: ${element['key']}');
saveOperations.add(_saveModule(element)); saveOperations.add(_saveModule(element));
} }
} }
await Future.wait(saveOperations); await Future.wait(saveOperations);
final String? v = await LicenseRepositoryImpl().getLicense(LicenseKeys.property.value);
log('Licenças obtidas: $v');
return true; return true;
} catch (e, s) { } catch (e, s) {
log('Erro ao obter licenças: $e', stackTrace: s); log('Erro ao obter licenças: $e', stackTrace: s);
@ -115,11 +120,14 @@ class LicenseRemoteDataSourceImpl implements LicenseRemoteDataSource {
} }
static bool licenseContainsKey(final String key) { 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<void> _saveModule(final dynamic body) async { static Future<void> _saveModule(final dynamic body) async {
log('Salvando módulo: ${body['key']}');
if (body is! Map<String, dynamic>) return; if (body is! Map<String, dynamic>) return;
await LicenseLocalDataSourceImpl().set(body['key'], body); await LicenseRepositoryImpl().setLicense(body['key'], body);
} }
} }

View File

@ -18,9 +18,9 @@ enum LicenseKeys {
pets('FRE-HUB-PETS'), pets('FRE-HUB-PETS'),
orders('FRE-HUB-ORDERS'), orders('FRE-HUB-ORDERS'),
completeSchedule('FRE-HUB-COMPLETE-SCHEDULE'), completeSchedule('FRE-HUB-COMPLETE-SCHEDULE'),
providerSchedule('FRE-HUB-AGE-PROV-PRESTADOR'), providerSchedule('FRE-HUB-AGE-PROV-PREST'),
deliverySchedule('FRE-HUB-AGE-PROV-DELIVERY'), deliverySchedule('FRE-HUB-AGE-PROV-DELIVERY'),
property('FRE-HUB-PROPERTY'), property('FRE-HUB-ABOUT-PROPERTY'),
fastPass('FRE-HUB-FASTPASS'), fastPass('FRE-HUB-FASTPASS'),
visitors('FRE-HUB-VISITORS'), visitors('FRE-HUB-VISITORS'),
qrCode('FRE-HUB-QRCODE'), qrCode('FRE-HUB-QRCODE'),
@ -198,7 +198,7 @@ class License {
), ),
Module( Module(
key: LicenseKeys.property.value, key: LicenseKeys.property.value,
display: isNewVersionWithModule ? ModuleStatus.active.key : ModuleStatus.inactive.key, display: isNewVersionWithModule ? ModuleStatus.inactive.key : ModuleStatus.inactive.key,
expirationDate: '', expirationDate: '',
startDate: '', startDate: '',
quantity: 0, quantity: 0,

View File

@ -7,7 +7,7 @@ import 'dart:developer';
class DatabaseStorage { class DatabaseStorage {
static final String _dbName = 'database.db'; static final String _dbName = 'database.db';
static final int _dbVersion = 4; static final int _dbVersion = 2;
static final DatabaseStorage instance = DatabaseStorage._internal(); static final DatabaseStorage instance = DatabaseStorage._internal();
factory DatabaseStorage() => instance; factory DatabaseStorage() => instance;
@ -42,11 +42,6 @@ class DatabaseStorage {
await database.execute(createLicenseTable); await database.execute(createLicenseTable);
if (version >= 2) { if (version >= 2) {
await database.execute(updatePetsHistoryTrigger); await database.execute(updatePetsHistoryTrigger);
}
if (version >= 3) {
await database.execute(updateDisplayTrigger);
}
if (version >= 4) {
await database.execute(updatePeopleDisplayTrigger); await database.execute(updatePeopleDisplayTrigger);
} }
} }
@ -56,24 +51,18 @@ class DatabaseStorage {
if (oldVersion < 2 && newVersion >= 2) { if (oldVersion < 2 && newVersion >= 2) {
await database.execute(createLicenseTable); await database.execute(createLicenseTable);
await database.execute(updatePetsHistoryTrigger); await database.execute(updatePetsHistoryTrigger);
}
if (oldVersion < 3 && newVersion >= 3) {
await database.execute(updateDisplayTrigger);
}
if (oldVersion < 4 && newVersion >= 4) {
await database.execute(updatePeopleDisplayTrigger); await database.execute(updatePeopleDisplayTrigger);
} }
} }
Future<void> _onDowngrade(Database database, int oldVersion, int newVersion) async { Future<void> _onDowngrade(Database database, int oldVersion, int newVersion) async {
log('Downgrading database from version $oldVersion to $newVersion...'); 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) { if (oldVersion >= 2 && newVersion < 2) {
await database.execute(deleteLicenseTable);
await database.execute(dropPeopleDisplayTrigger);
await database.execute(dropPetsHistoryTrigger); await database.execute(dropPetsHistoryTrigger);
} }
} }

View File

@ -80,6 +80,7 @@ enum KeychainStorageKey {
status, status,
userName, userName,
clientUUID, clientUUID,
ownerName,
ownerUUID, ownerUUID,
clientName, clientName,
petAmount, petAmount,
@ -115,6 +116,8 @@ extension KeychainStorageKeyExtension on KeychainStorageKey {
return 'fre_ownerUUID'; return 'fre_ownerUUID';
case KeychainStorageKey.clientName: case KeychainStorageKey.clientName:
return 'fre_cliName'; return 'fre_cliName';
case KeychainStorageKey.ownerName:
return 'fre_ownerName';
case KeychainStorageKey.petAmount: case KeychainStorageKey.petAmount:
return 'fre_petAmountRegister'; return 'fre_petAmountRegister';
case KeychainStorageKey.whatsapp: case KeychainStorageKey.whatsapp: