TF-1014: change limit parameter

This commit is contained in:
ManhNTX
2022-11-10 15:09:39 +07:00
committed by Dat H. Pham
parent 181915f071
commit d5d8921af2
3 changed files with 27 additions and 31 deletions
@@ -2,25 +2,28 @@ import 'package:core/core.dart';
import 'package:get/get.dart'; import 'package:get/get.dart';
import 'package:jmap_dart_client/jmap/account_id.dart'; import 'package:jmap_dart_client/jmap/account_id.dart';
import 'package:jmap_dart_client/jmap/core/capability/capability_identifier.dart'; import 'package:jmap_dart_client/jmap/core/capability/capability_identifier.dart';
import 'package:jmap_dart_client/jmap/core/session/session.dart';
import 'package:jmap_dart_client/jmap/quotas/data_types.dart'; import 'package:jmap_dart_client/jmap/quotas/data_types.dart';
import 'package:tmail_ui_user/features/base/base_controller.dart'; 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/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/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/domain/use_case/get_quotas_interactor.dart';
import 'package:tmail_ui_user/features/quotas/presentation/model/quotas_state.dart'; import 'package:tmail_ui_user/features/quotas/presentation/model/quotas_state.dart';
import 'package:tmail_ui_user/main/error/capability_validator.dart';
class QuotasController extends BaseController { class QuotasController extends BaseController {
final MailboxDashBoardController mailboxDashBoardController = Get.find<MailboxDashBoardController>(); final MailboxDashBoardController mailboxDashBoardController = Get.find<MailboxDashBoardController>();
final GetQuotasInteractor _getQuotasInteractor; final GetQuotasInteractor _getQuotasInteractor;
final usedCapacity = Rx<num>(0); final usedCapacity = Rx<num>(0);
final softLimitCapacity = Rx<num>(0); final limitCapacity = Rx<num>(0);
final warningLimitCapacity = Rx<num>(0); final warningLimitCapacity = Rx<num>(0);
final enableShowQuotas = false.obs; final enableShowQuotas = false.obs;
final quotasState = QuotasState.normal.obs; final quotasState = QuotasState.normal.obs;
final warningProgressConstant = 0.9;
late Worker accountIdWorker; late Worker accountIdWorker;
double get progressUsedCapacity => softLimitCapacity.value != 0 double get progressUsedCapacity => limitCapacity.value != 0
? (usedCapacity.value / softLimitCapacity.value) ? (usedCapacity.value / limitCapacity.value)
: 0; : 0;
bool get enableShowWarningQuotas => bool get enableShowWarningQuotas =>
@@ -35,18 +38,19 @@ class QuotasController extends BaseController {
void _initWorker() { void _initWorker() {
accountIdWorker = ever(mailboxDashBoardController.accountId, (accountId) { accountIdWorker = ever(mailboxDashBoardController.accountId, (accountId) {
if (accountId is AccountId) { if (accountId is AccountId && mailboxDashBoardController.sessionCurrent!= null) {
_getQuotasAction(accountId); _getQuotasAction(accountId, mailboxDashBoardController.sessionCurrent!);
} }
}); });
} }
void _getQuotasAction(AccountId accountId) { void _getQuotasAction(AccountId accountId, Session session) {
enableShowQuotas.value = mailboxDashBoardController.sessionCurrent != null && try {
mailboxDashBoardController.sessionCurrent!.capabilities.containsValue(CapabilityIdentifier.jmapQuota); requireCapability(session, accountId, [CapabilityIdentifier.jmapQuota]);
enableShowQuotas.value = true;
if(enableShowQuotas.isTrue) {
consumeState(_getQuotasInteractor.execute(mailboxDashBoardController.accountId.value!)); consumeState(_getQuotasInteractor.execute(mailboxDashBoardController.accountId.value!));
} catch (e) {
logError('QuotasController::_getQuotasAction():$e');
} }
} }
@@ -70,9 +74,9 @@ class QuotasController extends BaseController {
try { try {
final quotas = success.quotas.firstWhere((e) => e.resourceType == ResourceType.octets); final quotas = success.quotas.firstWhere((e) => e.resourceType == ResourceType.octets);
usedCapacity.value = quotas.used.value; usedCapacity.value = quotas.used.value;
warningLimitCapacity.value = quotas.warnLimit?.value ?? 0; warningLimitCapacity.value = quotas.limit.value * warningProgressConstant;
softLimitCapacity.value = quotas.softLimit?.value ?? 0; limitCapacity.value = quotas.limit.value;
if(usedCapacity.value >= softLimitCapacity.value) { if(usedCapacity.value >= limitCapacity.value) {
quotasState.value = QuotasState.runOutOfStorage; quotasState.value = QuotasState.runOutOfStorage;
} else if (usedCapacity.value >= warningLimitCapacity.value) { } else if (usedCapacity.value >= warningLimitCapacity.value) {
quotasState.value = QuotasState.runningOutOfStorage; quotasState.value = QuotasState.runningOutOfStorage;
@@ -46,7 +46,7 @@ class QuotasFooterWidget extends GetWidget<QuotasController> {
controller.quotasState.value.getQuotasFooterText( controller.quotasState.value.getQuotasFooterText(
context, context,
controller.usedCapacity.value, controller.usedCapacity.value,
controller.softLimitCapacity.value, controller.limitCapacity.value,
), ),
style: TextStyle( style: TextStyle(
fontSize: 13, fontSize: 13,
+9 -17
View File
@@ -1,13 +1,5 @@
{ {
<<<<<<< HEAD "@@last_modified": "2022-11-10T15:16:34.946211",
<<<<<<< HEAD
"@@last_modified": "2022-11-08T16:55:51.988372",
=======
"@@last_modified": "2022-11-09T17:10:23.172672",
>>>>>>> 24967b2c (TF-1014: [Dev] Show quota at the bottom of mailbox)
=======
"@@last_modified": "2022-11-10T10:33:41.637215",
>>>>>>> 1ad5dd5c (TF-1014: add quotas out of storage)
"initializing_data": "Initializing data...", "initializing_data": "Initializing data...",
"@initializing_data": { "@initializing_data": {
"type": "text", "type": "text",
@@ -2420,18 +2412,12 @@
"placeholders_order": [], "placeholders_order": [],
"placeholders": {} "placeholders": {}
}, },
<<<<<<< HEAD
"forwardingSettingExplanation": "Allows a new recipient to see the email sent if they were not originally included in the email chain.", "forwardingSettingExplanation": "Allows a new recipient to see the email sent if they were not originally included in the email chain.",
"@forwardingSettingExplanation": { "@forwardingSettingExplanation": {
=======
"storageQuotas": "Storage",
"@storageQuotas": {
>>>>>>> 24967b2c (TF-1014: [Dev] Show quota at the bottom of mailbox)
"type": "text", "type": "text",
"placeholders_order": [], "placeholders_order": [],
"placeholders": {} "placeholders": {}
}, },
<<<<<<< HEAD
"addRecipientButton": "Add recipient", "addRecipientButton": "Add recipient",
"@addRecipientButton": { "@addRecipientButton": {
"type": "text", "type": "text",
@@ -2458,7 +2444,14 @@
], ],
"placeholders": { "placeholders": {
"count": {} "count": {}
======= }
},
"storageQuotas": "Storage",
"@storageQuotas": {
"type": "text",
"placeholders_order": [],
"placeholders": {}
},
"textQuotasUsed": "{used} GB of {softLimit} GB Used", "textQuotasUsed": "{used} GB of {softLimit} GB Used",
"@textQuotasUsed": { "@textQuotasUsed": {
"type": "text", "type": "text",
@@ -2479,7 +2472,6 @@
], ],
"placeholders": { "placeholders": {
"progress": {} "progress": {}
>>>>>>> 24967b2c (TF-1014: [Dev] Show quota at the bottom of mailbox)
} }
}, },
"textQuotasRunningOutOfStorageContent": "Soon you won't be able to email in Team Mail. Please clean your storage or upgrade your storage to get full features in Team Mail.", "textQuotasRunningOutOfStorageContent": "Soon you won't be able to email in Team Mail. Please clean your storage or upgrade your storage to get full features in Team Mail.",