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];
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.ownerUUID.value, local['CLU_OWNER_ID']);
@ -197,6 +198,7 @@ class _BottomArrowLinkedLocalsComponentWidgetState extends State<BottomArrowLink
if (local['CLU_STATUS'] == 'A') {
await StorageHelper().set(KeychainStorageKey.clientUUID.value, local['CLI_ID']);
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']);
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');
}
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);
}),
));

View File

@ -59,8 +59,8 @@ class _PetsHistoryScreenState extends State<PetsHistoryScreen> 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',

View File

@ -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(

View File

@ -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<bool> 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<LocalProfileBloc>().add(LocalProfileEvent());
// LocalsRepositoryImpl.license.add(response);
return response;
}

View File

@ -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<LocalProfileEvent, LocalProfileState> {
Future<void> _onLocalProfileEvent(LocalProfileEvent event, Emitter<LocalProfileState> 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<LocalProfileEvent, LocalProfileState> {
class LocalProfileComponentModel extends FlutterFlowModel<LocalProfileComponentWidget> {
String cliName = '';
String cliUUID = '';
String ownerName = '';
VoidCallback? setStateCallback;
@override
@ -60,6 +64,7 @@ class LocalProfileComponentModel extends FlutterFlowModel<LocalProfileComponentW
Future<void> 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();
}

View File

@ -211,33 +211,61 @@ class _LocalProfileComponentWidgetState extends State<LocalProfileComponentWidge
),
),
Expanded(
child: Tooltip(
message: valueOrDefault<String>(
convertToUppercase(state.cliName),
FFLocalizations.of(context).getVariableText(
ptText: 'SEM LOCAL VINCULADO',
enText: 'NO LINKED LOCAL',
),
),
child: Text(
valueOrDefault<String>(
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<String>(
convertToUppercase(state.cliName),
FFLocalizations.of(context).getVariableText(
ptText: 'SEM LOCAL VINCULADO',
enText: 'NO LINKED LOCAL',
),
),
child: Text(
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,
maxLines: 1,
style: FlutterFlowTheme.of(context).labelMedium.override(
Tooltip(
message: valueOrDefault<String>(
' '+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',
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)),

View File

@ -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<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.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);
}

View File

@ -14,7 +14,7 @@ import '../../../modules/domain/entities/index.dart';
abstract class MenuLocalDataSource {
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<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> processExpirationDate(String expirationDate, MenuEntry entry);
}
@ -50,7 +50,7 @@ class MenuLocalDataSourceImpl implements MenuLocalDataSource {
}
@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 {
switch (display.value) {
case 'VISIVEL':
@ -76,12 +76,13 @@ class MenuLocalDataSourceImpl implements MenuLocalDataSource {
try {
if (startDate.isEmpty) return true;
final start = DateTime.tryParse(startDate);
return start != null && DateTime.now().isAfter(start);
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<bool> processExpirationDate(String expirationDate, MenuEntry opt) async {

View File

@ -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<List<MenuItem?>> generateMenuEntries(List<MenuEntry> menuEntries, EnumMenuItem item) async {
log('Generating menu entries for $item');
List<MenuItem?> 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<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 = [
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<MenuEntry> getEntriesByType(MenuEntryType type) {

View File

@ -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;
''';

View File

@ -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<void> setDisplayByKey(final List<String?> 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<void> setDisplayByKey(final List<String> 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<void> set<T>(String key, T value) async {
value as Map<String, dynamic>;
if (value.isEmpty) return;
if (key == 'null') return;
log('Setting: ${value['key']} : ${value['display']}');
await DatabaseStorage.database.insert(
tableLicense,
{

View File

@ -46,25 +46,25 @@ class LicenseRemoteDataSourceImpl implements LicenseRemoteDataSource {
.where((module) => module.display == ModuleStatus.inactive.key)
.map((module) => module.key)
.toList();
log('Módulos inativos: $inactiveModuleKey');
final List<String> activeModuleKey = license.modules
.where((module) => module.display == ModuleStatus.active.key)
.map((module) => module.key)
.toList();
log('Módulos ativos: $activeModuleKey');
final List<String> 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) {
@ -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<Future<void>> 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<void> _saveModule(final dynamic body) async {
log('Salvando módulo: ${body['key']}');
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'),
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,

View File

@ -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<void> _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);
}
}

View File

@ -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: