wip
This commit is contained in:
parent
8478d0d372
commit
8ae8ce849f
|
@ -18,7 +18,11 @@ const _kPrivateApiFunctionName = 'ffPrivateApiCall';
|
||||||
|
|
||||||
/// Start PHP Group Code
|
/// Start PHP Group Code
|
||||||
|
|
||||||
class PhpGroup {
|
abstract class Api {
|
||||||
|
GetLicense getLicense = GetLicense();
|
||||||
|
}
|
||||||
|
|
||||||
|
class PhpGroup extends Api {
|
||||||
static String getBaseUrl() => 'https://freaccess.com.br/freaccess';
|
static String getBaseUrl() => 'https://freaccess.com.br/freaccess';
|
||||||
static Map<String, String> headers = {};
|
static Map<String, String> headers = {};
|
||||||
static LoginCall loginCall = LoginCall();
|
static LoginCall loginCall = LoginCall();
|
||||||
|
@ -62,7 +66,7 @@ class PhpGroup {
|
||||||
static GetResidentsByProperty getResidentsByProperty =
|
static GetResidentsByProperty getResidentsByProperty =
|
||||||
GetResidentsByProperty();
|
GetResidentsByProperty();
|
||||||
static GetOpenedVisits getOpenedVisits = GetOpenedVisits();
|
static GetOpenedVisits getOpenedVisits = GetOpenedVisits();
|
||||||
static GetLicense getLicense = GetLicense();
|
GetLicense getLicense = GetLicense();
|
||||||
static GetProvSchedules getProvSchedules = GetProvSchedules();
|
static GetProvSchedules getProvSchedules = GetProvSchedules();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -2,6 +2,7 @@ import 'dart:developer';
|
||||||
|
|
||||||
import 'package:hub/features/menu/index.dart';
|
import 'package:hub/features/menu/index.dart';
|
||||||
import 'package:hub/features/module/index.dart';
|
import 'package:hub/features/module/index.dart';
|
||||||
|
import 'package:hub/features/storage/index.dart';
|
||||||
import 'package:hub/flutter_flow/custom_functions.dart';
|
import 'package:hub/flutter_flow/custom_functions.dart';
|
||||||
|
|
||||||
class MenuRepositoryImpl implements MenuRepository {
|
class MenuRepositoryImpl implements MenuRepository {
|
||||||
|
@ -55,7 +56,7 @@ class MenuRepositoryImpl implements MenuRepository {
|
||||||
if (await _shouldUpdateDisplay(module, isNewVersion)) {
|
if (await _shouldUpdateDisplay(module, isNewVersion)) {
|
||||||
final displayValue =
|
final displayValue =
|
||||||
module['display'] == EnumDisplay.active ? 'VISIVEL' : 'INVISIVEL';
|
module['display'] == EnumDisplay.active ? 'VISIVEL' : 'INVISIVEL';
|
||||||
await LicenseLocalDataSourceImpl()
|
await LicenseLocalDataSourceImpl(DatabaseService.database)
|
||||||
.setDisplayByKey(['FRE-HUB-ABOUT-PROPERTY'], displayValue);
|
.setDisplayByKey(['FRE-HUB-ABOUT-PROPERTY'], displayValue);
|
||||||
return EnumDisplay.fromString(displayValue);
|
return EnumDisplay.fromString(displayValue);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
import 'dart:async';
|
import 'dart:async';
|
||||||
|
|
||||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||||
|
import 'package:hub/features/backend/index.dart';
|
||||||
import 'package:hub/features/menu/index.dart';
|
import 'package:hub/features/menu/index.dart';
|
||||||
import 'package:hub/features/module/index.dart';
|
import 'package:hub/features/module/index.dart';
|
||||||
import 'package:hub/features/local/index.dart';
|
import 'package:hub/features/local/index.dart';
|
||||||
|
@ -36,7 +37,7 @@ class MenuBloc extends Bloc<MenuEvent, MenuState> {
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> _onMenuEvent(MenuEvent event, Emitter<MenuState> emit) async {
|
Future<void> _onMenuEvent(MenuEvent event, Emitter<MenuState> emit) async {
|
||||||
await LicenseRemoteDataSourceImpl().waitForSaveCompletion();
|
await LicenseRemoteDataSourceImpl(PhpGroup()).waitForSaveCompletion();
|
||||||
|
|
||||||
final List<MenuItem?> newEntries =
|
final List<MenuItem?> newEntries =
|
||||||
await MenuRepositoryImpl().generateMenuEntries(entries, item);
|
await MenuRepositoryImpl().generateMenuEntries(entries, item);
|
||||||
|
|
|
@ -1,6 +1,9 @@
|
||||||
|
import 'dart:developer';
|
||||||
|
|
||||||
import 'package:hub/features/module/index.dart';
|
import 'package:hub/features/module/index.dart';
|
||||||
import 'package:hub/features/storage/index.dart';
|
import 'package:hub/features/storage/index.dart';
|
||||||
import 'package:hub/shared/extensions/string_extensions.dart';
|
import 'package:hub/shared/extensions/string_extensions.dart';
|
||||||
|
import 'package:sqflite/sqflite.dart';
|
||||||
|
|
||||||
abstract class LicenseLocalDataSource {
|
abstract class LicenseLocalDataSource {
|
||||||
Future<void> init();
|
Future<void> init();
|
||||||
|
@ -9,13 +12,22 @@ abstract class LicenseLocalDataSource {
|
||||||
Future<String?> get(String key);
|
Future<String?> get(String key);
|
||||||
Future<void> set<T>(String key, T value);
|
Future<void> set<T>(String key, T value);
|
||||||
Future<void> del(String key);
|
Future<void> del(String key);
|
||||||
|
Future<bool> setupLicense(bool isNewVersion);
|
||||||
|
|
||||||
Future<void> clear();
|
Future<void> clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
class LicenseLocalDataSourceImpl implements LicenseLocalDataSource {
|
class LicenseLocalDataSourceImpl implements LicenseLocalDataSource {
|
||||||
|
late final Database database;
|
||||||
|
|
||||||
static final LicenseLocalDataSourceImpl _instance =
|
static final LicenseLocalDataSourceImpl _instance =
|
||||||
LicenseLocalDataSourceImpl._internal();
|
LicenseLocalDataSourceImpl._internal();
|
||||||
factory LicenseLocalDataSourceImpl() => _instance;
|
|
||||||
|
factory LicenseLocalDataSourceImpl(Database database) {
|
||||||
|
_instance.database = database;
|
||||||
|
return _instance;
|
||||||
|
}
|
||||||
|
|
||||||
LicenseLocalDataSourceImpl._internal();
|
LicenseLocalDataSourceImpl._internal();
|
||||||
|
|
||||||
@override
|
@override
|
||||||
|
@ -23,6 +35,38 @@ class LicenseLocalDataSourceImpl implements LicenseLocalDataSource {
|
||||||
await DatabaseService.instance.init();
|
await DatabaseService.instance.init();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
Future<bool> setupLicense(bool isNewVersion) async {
|
||||||
|
log('Setting up license...');
|
||||||
|
try {
|
||||||
|
final License license = await License.getLicense(isNewVersion);
|
||||||
|
|
||||||
|
final List<String> inactiveModuleKey = license.modules
|
||||||
|
.where((module) => module.display == ModuleStatus.inactive.key)
|
||||||
|
.map((module) => module.key)
|
||||||
|
.toList();
|
||||||
|
|
||||||
|
final List<String> activeModuleKey = license.modules
|
||||||
|
.where((module) => module.display == ModuleStatus.active.key)
|
||||||
|
.map((module) => module.key)
|
||||||
|
.toList();
|
||||||
|
|
||||||
|
final List<String> disabledModuleKey = license.modules
|
||||||
|
.where((module) => module.display == ModuleStatus.disabled.key)
|
||||||
|
.map((module) => module.key)
|
||||||
|
.toList();
|
||||||
|
|
||||||
|
await setDisplayByKey(inactiveModuleKey, 'INVISIVEL');
|
||||||
|
await setDisplayByKey(activeModuleKey, 'VISIVEL');
|
||||||
|
await setDisplayByKey(disabledModuleKey, 'DESABILITADO');
|
||||||
|
|
||||||
|
return true;
|
||||||
|
} catch (e, s) {
|
||||||
|
log('Erro ao configurar licenças: $e', stackTrace: s);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Future<void> setDisplayByKey(
|
Future<void> setDisplayByKey(
|
||||||
final List<String> keys, final String display) async {
|
final List<String> keys, final String display) async {
|
||||||
|
@ -48,8 +92,8 @@ class LicenseLocalDataSourceImpl implements LicenseLocalDataSource {
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Future<String?> get(String key) async {
|
Future<String?> get(String key) async {
|
||||||
var response = await DatabaseService.database
|
var response =
|
||||||
.query(tableLicense, where: 'key = ?', whereArgs: [key]);
|
await database.query(tableLicense, where: 'key = ?', whereArgs: [key]);
|
||||||
if (response.isEmpty) {
|
if (response.isEmpty) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
@ -63,7 +107,7 @@ class LicenseLocalDataSourceImpl implements LicenseLocalDataSource {
|
||||||
if (value.isEmpty) return;
|
if (value.isEmpty) return;
|
||||||
if (key == 'null') return;
|
if (key == 'null') return;
|
||||||
|
|
||||||
await DatabaseService.database.rawInsert(
|
await database.rawInsert(
|
||||||
'INSERT OR REPLACE INTO $tableLicense (key, display, expirationDate, startDate, quantity) VALUES (?, ?, ?, ?, ?)',
|
'INSERT OR REPLACE INTO $tableLicense (key, display, expirationDate, startDate, quantity) VALUES (?, ?, ?, ?, ?)',
|
||||||
[
|
[
|
||||||
key,
|
key,
|
||||||
|
@ -78,12 +122,11 @@ class LicenseLocalDataSourceImpl implements LicenseLocalDataSource {
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Future<void> del(String key) async {
|
Future<void> del(String key) async {
|
||||||
await DatabaseService.database
|
await database.delete(tableLicense, where: 'key = ?', whereArgs: [key]);
|
||||||
.delete(tableLicense, where: 'key = ?', whereArgs: [key]);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Future<void> clear() async {
|
Future<void> clear() async {
|
||||||
await DatabaseService.database.delete(tableLicense);
|
await database.delete(tableLicense);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,19 +7,23 @@ import 'package:hub/features/backend/index.dart';
|
||||||
import 'package:hub/features/local/data/repositories/locals_repository_impl.dart';
|
import 'package:hub/features/local/data/repositories/locals_repository_impl.dart';
|
||||||
import 'package:hub/features/module/index.dart';
|
import 'package:hub/features/module/index.dart';
|
||||||
|
|
||||||
import 'package:sqflite/sqflite.dart';
|
|
||||||
|
|
||||||
abstract class LicenseRemoteDataSource {
|
abstract class LicenseRemoteDataSource {
|
||||||
Future<bool> fetchLicenses(bool isNewVersion);
|
Future<bool> fetchLicenses(bool isNewVersion);
|
||||||
Future<void> cleanLicense();
|
Future<void> cleanLicense();
|
||||||
Future<void> processLicense();
|
Future<void> processLicense();
|
||||||
Future<bool> setupLicense(Database database, bool isNewVersion);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
class LicenseRemoteDataSourceImpl implements LicenseRemoteDataSource {
|
class LicenseRemoteDataSourceImpl implements LicenseRemoteDataSource {
|
||||||
|
late final Api api;
|
||||||
|
|
||||||
static final LicenseRemoteDataSourceImpl _instance =
|
static final LicenseRemoteDataSourceImpl _instance =
|
||||||
LicenseRemoteDataSourceImpl._internal();
|
LicenseRemoteDataSourceImpl._internal();
|
||||||
factory LicenseRemoteDataSourceImpl() => _instance;
|
|
||||||
|
factory LicenseRemoteDataSourceImpl(Api api) {
|
||||||
|
_instance.api = api;
|
||||||
|
return _instance;
|
||||||
|
}
|
||||||
|
|
||||||
LicenseRemoteDataSourceImpl._internal();
|
LicenseRemoteDataSourceImpl._internal();
|
||||||
|
|
||||||
@override
|
@override
|
||||||
|
@ -30,46 +34,11 @@ class LicenseRemoteDataSourceImpl implements LicenseRemoteDataSource {
|
||||||
LocalsRepositoryImpl.license.add(false);
|
LocalsRepositoryImpl.license.add(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
|
||||||
Future<bool> setupLicense(Database database, bool isNewVersion) async {
|
|
||||||
log('Setting up license...');
|
|
||||||
try {
|
|
||||||
final License license = await License.getLicense(isNewVersion);
|
|
||||||
|
|
||||||
final List<String> inactiveModuleKey = license.modules
|
|
||||||
.where((module) => module.display == ModuleStatus.inactive.key)
|
|
||||||
.map((module) => module.key)
|
|
||||||
.toList();
|
|
||||||
|
|
||||||
final List<String> activeModuleKey = license.modules
|
|
||||||
.where((module) => module.display == ModuleStatus.active.key)
|
|
||||||
.map((module) => module.key)
|
|
||||||
.toList();
|
|
||||||
|
|
||||||
final List<String> disabledModuleKey = license.modules
|
|
||||||
.where((module) => module.display == ModuleStatus.disabled.key)
|
|
||||||
.map((module) => module.key)
|
|
||||||
.toList();
|
|
||||||
|
|
||||||
await LicenseLocalDataSourceImpl()
|
|
||||||
.setDisplayByKey(inactiveModuleKey, 'INVISIVEL');
|
|
||||||
await LicenseLocalDataSourceImpl()
|
|
||||||
.setDisplayByKey(activeModuleKey, 'VISIVEL');
|
|
||||||
await LicenseLocalDataSourceImpl()
|
|
||||||
.setDisplayByKey(disabledModuleKey, 'DESABILITADO');
|
|
||||||
|
|
||||||
return true;
|
|
||||||
} catch (e, s) {
|
|
||||||
log('Erro ao configurar licenças: $e', stackTrace: s);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Future<bool> fetchLicenses(bool isNewVersion) async {
|
Future<bool> fetchLicenses(bool isNewVersion) async {
|
||||||
log('Fetching licenses...');
|
log('Fetching licenses...');
|
||||||
try {
|
try {
|
||||||
final response = await PhpGroup.getLicense();
|
final response = await _instance.api.getLicense();
|
||||||
final dynamic responseBody = response.jsonBody;
|
final dynamic responseBody = response.jsonBody;
|
||||||
|
|
||||||
if (responseBody == []) {
|
if (responseBody == []) {
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
import 'dart:developer';
|
import 'dart:developer';
|
||||||
|
|
||||||
|
import 'package:hub/features/backend/index.dart';
|
||||||
import 'package:hub/features/module/data/data_sources/index.dart';
|
import 'package:hub/features/module/data/data_sources/index.dart';
|
||||||
import 'package:hub/features/module/domain/index.dart';
|
import 'package:hub/features/module/domain/index.dart';
|
||||||
import 'package:hub/features/storage/index.dart';
|
import 'package:hub/features/storage/index.dart';
|
||||||
|
@ -8,19 +9,33 @@ import 'package:sqflite/sqflite.dart';
|
||||||
typedef LicenseStatus = bool;
|
typedef LicenseStatus = bool;
|
||||||
|
|
||||||
class LicenseRepositoryImpl implements LicenseRepository {
|
class LicenseRepositoryImpl implements LicenseRepository {
|
||||||
final LicenseLocalDataSource localDataSource = LicenseLocalDataSourceImpl();
|
late final Database database;
|
||||||
final LicenseRemoteDataSource remoteDataSource =
|
late final PhpGroup api;
|
||||||
LicenseRemoteDataSourceImpl();
|
late final LicenseLocalDataSource localDataSource;
|
||||||
final Database database = DatabaseService.database;
|
late final LicenseRemoteDataSource remoteDataSource;
|
||||||
|
|
||||||
LicenseRepositoryImpl();
|
LicenseRepositoryImpl([Database? database, PhpGroup? api]) {
|
||||||
|
if (database != null) {
|
||||||
|
this.database = database;
|
||||||
|
} else {
|
||||||
|
this.database = DatabaseService.database;
|
||||||
|
}
|
||||||
|
if (api != null) {
|
||||||
|
this.api = api;
|
||||||
|
} else {
|
||||||
|
this.api = PhpGroup();
|
||||||
|
}
|
||||||
|
|
||||||
|
localDataSource = LicenseLocalDataSourceImpl(this.database);
|
||||||
|
remoteDataSource = LicenseRemoteDataSourceImpl(this.api);
|
||||||
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Future<bool> updateLicense() async {
|
Future<bool> updateLicense() async {
|
||||||
log('updateLicense');
|
log('updateLicense');
|
||||||
bool result = false;
|
bool result = false;
|
||||||
final bool isNewVersion = await localDataSource.isNewVersion();
|
final bool isNewVersion = await localDataSource.isNewVersion();
|
||||||
result = await remoteDataSource.setupLicense(database, isNewVersion);
|
result = await localDataSource.setupLicense(isNewVersion);
|
||||||
if (isNewVersion) {
|
if (isNewVersion) {
|
||||||
result = await remoteDataSource.fetchLicenses(isNewVersion);
|
result = await remoteDataSource.fetchLicenses(isNewVersion);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue