WIP: LocalsREpositoryImpl().update
This commit is contained in:
parent
747596e833
commit
88f9b1f814
|
@ -35,7 +35,7 @@ class _HomePageWidgetState extends State<HomePageWidget> {
|
||||||
],
|
],
|
||||||
child: Builder(
|
child: Builder(
|
||||||
builder: (context) {
|
builder: (context) {
|
||||||
context.read<LocalProfileBloc>().updateProfile(context);
|
// context.read<LocalProfileBloc>().updateProfile(context);
|
||||||
return Scaffold(
|
return Scaffold(
|
||||||
key: scaffoldKey,
|
key: scaffoldKey,
|
||||||
backgroundColor: FlutterFlowTheme.of(context).primaryBackground,
|
backgroundColor: FlutterFlowTheme.of(context).primaryBackground,
|
||||||
|
|
|
@ -71,7 +71,6 @@ class LocalsRemoteDataSourceImpl implements LocalsRemoteDataSource {
|
||||||
@override
|
@override
|
||||||
Future<bool> processLocals(BuildContext context) async {
|
Future<bool> processLocals(BuildContext context) async {
|
||||||
try {
|
try {
|
||||||
await LicenseRepositoryImpl().cleanLicense();
|
|
||||||
final GetLocalsCall callback = PhpGroup.getLocalsCall;
|
final GetLocalsCall callback = PhpGroup.getLocalsCall;
|
||||||
final ApiCallResponse response = await callback.call();
|
final ApiCallResponse response = await callback.call();
|
||||||
final bool? isError = response.jsonBody['error'];
|
final bool? isError = response.jsonBody['error'];
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
import 'package:flutter/material.dart';
|
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';
|
||||||
|
|
||||||
class LocalsRepositoryImpl implements LocalsRepository {
|
class LocalsRepositoryImpl implements LocalsRepository {
|
||||||
final LocalsRemoteDataSource remoteDataSource = LocalsRemoteDataSourceImpl();
|
final LocalsRemoteDataSource remoteDataSource = LocalsRemoteDataSourceImpl();
|
||||||
|
@ -12,7 +13,7 @@ class LocalsRepositoryImpl implements LocalsRepository {
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Future<bool> update(BuildContext context) async {
|
Future<bool> update(BuildContext context) async {
|
||||||
final bool response = await remoteDataSource.processLocals(context);
|
final bool response = await LicenseRepositoryImpl().updateLicense();
|
||||||
context.read<LocalProfileBloc>().add(LocalProfileEvent());
|
context.read<LocalProfileBloc>().add(LocalProfileEvent());
|
||||||
return response;
|
return response;
|
||||||
}
|
}
|
||||||
|
|
|
@ -36,10 +36,10 @@ class LocalProfileBloc extends Bloc<LocalProfileEvent, LocalProfileState> {
|
||||||
emit(state.copyWith(cliName: cliName, cliUUID: cliUUID));
|
emit(state.copyWith(cliName: cliName, cliUUID: cliUUID));
|
||||||
}
|
}
|
||||||
|
|
||||||
void updateProfile(BuildContext context) {
|
// void updateProfile(BuildContext context) {
|
||||||
add(LocalProfileEvent());
|
// add(LocalProfileEvent());
|
||||||
LocalsRepositoryImpl().update(context);
|
// LocalsRepositoryImpl().update(context);
|
||||||
}
|
// }
|
||||||
}
|
}
|
||||||
|
|
||||||
class LocalProfileComponentModel extends FlutterFlowModel<LocalProfileComponentWidget> {
|
class LocalProfileComponentModel extends FlutterFlowModel<LocalProfileComponentWidget> {
|
||||||
|
|
|
@ -15,6 +15,7 @@ class MenuRepositoryImpl implements MenuRepository {
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Future<List<MenuItem?>> generateMenuEntries(List<MenuEntry> menuOptions, EnumMenuItem item) async {
|
Future<List<MenuItem?>> generateMenuEntries(List<MenuEntry> menuOptions, EnumMenuItem item) async {
|
||||||
|
log('Generating menu entries for $item');
|
||||||
List<MenuItem?> entries = [];
|
List<MenuItem?> entries = [];
|
||||||
try {
|
try {
|
||||||
for (var opt in menuOptions) {
|
for (var opt in menuOptions) {
|
||||||
|
|
|
@ -13,7 +13,7 @@ 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<void> setupLicense(Database database, bool isNewVersion);
|
Future<bool> setupLicense(Database database, bool isNewVersion);
|
||||||
}
|
}
|
||||||
|
|
||||||
class LicenseRemoteDataSourceImpl implements LicenseRemoteDataSource {
|
class LicenseRemoteDataSourceImpl implements LicenseRemoteDataSource {
|
||||||
|
@ -22,8 +22,8 @@ class LicenseRemoteDataSourceImpl implements LicenseRemoteDataSource {
|
||||||
LicenseRemoteDataSourceImpl._internal();
|
LicenseRemoteDataSourceImpl._internal();
|
||||||
|
|
||||||
|
|
||||||
final StreamController<void> _completerController = StreamController<void>.broadcast();
|
final StreamController<void> completerController = StreamController<void>.broadcast();
|
||||||
Stream<void> get streamCompleterController => _completerController.stream;
|
Stream<void> get streamCompleterController => completerController.stream;
|
||||||
|
|
||||||
|
|
||||||
@override
|
@override
|
||||||
|
@ -36,7 +36,8 @@ class LicenseRemoteDataSourceImpl implements LicenseRemoteDataSource {
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Future<void> setupLicense(Database database, bool isNewVersion) async {
|
Future<bool> setupLicense(Database database, bool isNewVersion) async {
|
||||||
|
log('Setting up license...');
|
||||||
final License license = await License.getLicense(isNewVersion);
|
final License license = await License.getLicense(isNewVersion);
|
||||||
|
|
||||||
final List<String> inactiveModuleKey = license.modules
|
final List<String> inactiveModuleKey = license.modules
|
||||||
|
@ -63,11 +64,12 @@ class LicenseRemoteDataSourceImpl implements LicenseRemoteDataSource {
|
||||||
await LicenseLocalDataSourceImpl().setDisplayByKey(disabledModuleKey, 'DESABILITADO');
|
await LicenseLocalDataSourceImpl().setDisplayByKey(disabledModuleKey, 'DESABILITADO');
|
||||||
}
|
}
|
||||||
|
|
||||||
LicenseRepositoryImpl.license.add(true);
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Future<bool> fetchLicenses(bool isNewVersion) async {
|
Future<bool> fetchLicenses(bool isNewVersion) async {
|
||||||
|
log('Fetching licenses...');
|
||||||
try {
|
try {
|
||||||
final response = await PhpGroup.getLicense();
|
final response = await PhpGroup.getLicense();
|
||||||
final dynamic responseBody = response.jsonBody;
|
final dynamic responseBody = response.jsonBody;
|
||||||
|
@ -83,9 +85,7 @@ class LicenseRemoteDataSourceImpl implements LicenseRemoteDataSource {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (responseBody == []) {
|
if (responseBody == []) {
|
||||||
await setupLicense(DatabaseStorage.database, isNewVersion);
|
return await setupLicense(DatabaseStorage.database, isNewVersion);
|
||||||
LicenseRepositoryImpl.license.add(false);
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
List<Future<void>> saveOperations = [];
|
List<Future<void>> saveOperations = [];
|
||||||
|
@ -95,15 +95,10 @@ class LicenseRemoteDataSourceImpl implements LicenseRemoteDataSource {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
await Future.wait(saveOperations);
|
await Future.wait(saveOperations);
|
||||||
|
|
||||||
LicenseRepositoryImpl.license.add(true);
|
|
||||||
_completerController.add(null);
|
|
||||||
|
|
||||||
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);
|
||||||
await setupLicense(DatabaseStorage.database, isNewVersion);
|
return await setupLicense(DatabaseStorage.database, isNewVersion);
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -18,12 +18,16 @@ class LicenseRepositoryImpl implements LicenseRepository {
|
||||||
static get stream => license.stream;
|
static get stream => license.stream;
|
||||||
|
|
||||||
Future<bool> updateLicense() async {
|
Future<bool> updateLicense() async {
|
||||||
|
LicenseRepositoryImpl.license.add(false);
|
||||||
|
bool result = false;
|
||||||
final bool isNewVersion = await localDataSource.isNewVersion();
|
final bool isNewVersion = await localDataSource.isNewVersion();
|
||||||
await remoteDataSource.setupLicense(database, isNewVersion);
|
result = await remoteDataSource.setupLicense(database, isNewVersion);
|
||||||
if (isNewVersion) {
|
if (isNewVersion) {
|
||||||
return await remoteDataSource.fetchLicenses(isNewVersion);
|
result = await remoteDataSource.fetchLicenses(isNewVersion);
|
||||||
}
|
}
|
||||||
return false;
|
|
||||||
|
LicenseRepositoryImpl.license.add(result);
|
||||||
|
return result;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -46,6 +46,9 @@ class DatabaseStorage {
|
||||||
if (version >= 3) {
|
if (version >= 3) {
|
||||||
await database.execute(updateDisplayTrigger);
|
await database.execute(updateDisplayTrigger);
|
||||||
}
|
}
|
||||||
|
if (version >= 4) {
|
||||||
|
await database.execute(updatePeopleDisplayTrigger);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> _onUpgrade(Database database, int oldVersion, int newVersion) async {
|
Future<void> _onUpgrade(Database database, int oldVersion, int newVersion) async {
|
||||||
|
|
Loading…
Reference in New Issue