TF-1014: add quotas out of storage
This commit is contained in:
@@ -7,6 +7,7 @@ import 'package:tmail_ui_user/features/base/base_controller.dart';
|
||||
import 'package:tmail_ui_user/features/mailbox_dashboard/presentation/controller/mailbox_dashboard_controller.dart';
|
||||
import 'package:tmail_ui_user/features/quotas/domain/state/get_quotas_state.dart';
|
||||
import 'package:tmail_ui_user/features/quotas/domain/use_case/get_quotas_interactor.dart';
|
||||
import 'package:tmail_ui_user/features/quotas/presentation/model/quotas_state.dart';
|
||||
|
||||
class QuotasController extends BaseController {
|
||||
final MailboxDashBoardController mailboxDashBoardController = Get.find<MailboxDashBoardController>();
|
||||
@@ -15,6 +16,7 @@ class QuotasController extends BaseController {
|
||||
final softLimitCapacity = Rx<num>(0);
|
||||
final warningLimitCapacity = Rx<num>(0);
|
||||
final enableShowQuotas = false.obs;
|
||||
final quotasState = QuotasState.normal.obs;
|
||||
late Worker accountIdWorker;
|
||||
|
||||
double get progressUsedCapacity => softLimitCapacity.value != 0
|
||||
@@ -22,7 +24,9 @@ class QuotasController extends BaseController {
|
||||
: 0;
|
||||
|
||||
bool get enableShowWarningQuotas =>
|
||||
enableShowQuotas.value && usedCapacity.value >= warningLimitCapacity.value;
|
||||
enableShowQuotas.isTrue &&
|
||||
(quotasState.value == QuotasState.runningOutOfStorage
|
||||
|| quotasState.value == QuotasState.runOutOfStorage);
|
||||
|
||||
final ImagePaths imagePaths = Get.find<ImagePaths>();
|
||||
final ResponsiveUtils responsiveUtils = Get.find<ResponsiveUtils>();
|
||||
@@ -32,27 +36,33 @@ class QuotasController extends BaseController {
|
||||
void _initWorker() {
|
||||
accountIdWorker = ever(mailboxDashBoardController.accountId, (accountId) {
|
||||
if (accountId is AccountId) {
|
||||
enableShowQuotas.value = mailboxDashBoardController.sessionCurrent != null &&
|
||||
mailboxDashBoardController.sessionCurrent!.capabilities.containsValue(CapabilityIdentifier.jmapQuota);
|
||||
consumeState(_getQuotasInteractor.execute(mailboxDashBoardController.accountId.value!));
|
||||
_getQuotasAction(accountId);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
void _getQuotasAction(AccountId accountId) {
|
||||
enableShowQuotas.value = mailboxDashBoardController.sessionCurrent != null &&
|
||||
mailboxDashBoardController.sessionCurrent!.capabilities.containsValue(CapabilityIdentifier.jmapQuota);
|
||||
|
||||
if(enableShowQuotas.isTrue) {
|
||||
consumeState(_getQuotasInteractor.execute(mailboxDashBoardController.accountId.value!));
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
void onDone() {
|
||||
viewState.value.fold(
|
||||
(failure) {
|
||||
if (failure is GetQuotasFailure) {
|
||||
logError('QuotasController::onDone():[GetQuotasFailure]: ${failure.exception}');
|
||||
}
|
||||
},
|
||||
(success) {
|
||||
if (success is GetQuotasSuccess) {
|
||||
_handleGetQuotasSuccess(success);
|
||||
}
|
||||
(failure) {
|
||||
if (failure is GetQuotasFailure) {
|
||||
logError('QuotasController::onDone():[GetQuotasFailure]: ${failure.exception}');
|
||||
}
|
||||
},
|
||||
(success) {
|
||||
if (success is GetQuotasSuccess) {
|
||||
_handleGetQuotasSuccess(success);
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
@@ -62,10 +72,16 @@ class QuotasController extends BaseController {
|
||||
usedCapacity.value = quotas.used.value;
|
||||
warningLimitCapacity.value = quotas.warnLimit?.value ?? 0;
|
||||
softLimitCapacity.value = quotas.softLimit?.value ?? 0;
|
||||
if(usedCapacity.value >= softLimitCapacity.value) {
|
||||
quotasState.value = QuotasState.runOutOfStorage;
|
||||
} else if (usedCapacity.value >= warningLimitCapacity.value) {
|
||||
quotasState.value = QuotasState.runningOutOfStorage;
|
||||
} else {
|
||||
quotasState.value = QuotasState.normal;
|
||||
}
|
||||
} catch (e) {
|
||||
logError('QuotasController::_handleGetQuotasSuccess():[NotFoundException]: $e');
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@override
|
||||
|
||||
Reference in New Issue
Block a user