Skip to content

Commit

Permalink
TF-2668 Add warning icon in item rule
Browse files Browse the repository at this point in the history
  • Loading branch information
dab246 committed Sep 18, 2024
1 parent 9f3ddba commit 4c1703d
Show file tree
Hide file tree
Showing 11 changed files with 197 additions and 44 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import 'package:core/presentation/state/failure.dart';
import 'package:core/presentation/state/success.dart';
import 'package:core/utils/app_logger.dart';
import 'package:dartz/dartz.dart';
import 'package:jmap_dart_client/jmap/account_id.dart';
import 'package:jmap_dart_client/jmap/core/session/session.dart';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@ import 'package:core/presentation/state/failure.dart';
import 'package:core/presentation/state/success.dart';
import 'package:rule_filter/rule_filter/tmail_rule.dart';

class GetAllRulesLoading extends LoadingState {}

class GetAllRulesSuccess extends UIState {
final List<TMailRule>? rules;
final List<TMailRule> rules;

GetAllRulesSuccess(this.rules);

@override
List<Object?> get props => [rules];
List<Object> get props => [rules];
}

class GetAllRulesFailure extends FeatureFailure {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class DeleteEmailRuleInteractor {

Stream<Either<Failure, Success>> execute(AccountId accountId, DeleteEmailRuleRequest deleteEmailRuleRequest) async* {
try {
final result = await _ruleFilterRepository.deleteTMailRule(accountId, deleteEmailRuleRequest);
final result = await _ruleFilterRepository.deleteTMailRule(accountId, deleteEmailRuleRequest);
yield Right(DeleteEmailRuleSuccess(result));
} catch (exception) {
yield Left(DeleteEmailRuleFailure(exception));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,18 @@
import 'package:core/data/model/source_type/data_source_type.dart';
import 'package:get/get.dart';
import 'package:tmail_ui_user/features/base/interactors_bindings.dart';
import 'package:tmail_ui_user/features/mailbox/data/datasource/mailbox_datasource.dart';
import 'package:tmail_ui_user/features/mailbox/data/datasource/state_datasource.dart';
import 'package:tmail_ui_user/features/mailbox/data/datasource_impl/mailbox_cache_datasource_impl.dart';
import 'package:tmail_ui_user/features/mailbox/data/datasource_impl/mailbox_datasource_impl.dart';
import 'package:tmail_ui_user/features/mailbox/data/datasource_impl/state_datasource_impl.dart';
import 'package:tmail_ui_user/features/mailbox/data/local/mailbox_cache_manager.dart';
import 'package:tmail_ui_user/features/mailbox/data/local/state_cache_manager.dart';
import 'package:tmail_ui_user/features/mailbox/data/network/mailbox_api.dart';
import 'package:tmail_ui_user/features/mailbox/data/network/mailbox_isolate_worker.dart';
import 'package:tmail_ui_user/features/mailbox/data/repository/mailbox_repository_impl.dart';
import 'package:tmail_ui_user/features/mailbox/domain/repository/mailbox_repository.dart';
import 'package:tmail_ui_user/features/mailbox/domain/usecases/get_list_mailbox_by_id_interactor.dart';
import 'package:tmail_ui_user/features/manage_account/data/datasource/rule_filter_datasource.dart';
import 'package:tmail_ui_user/features/manage_account/data/datasource_impl/rule_filter_datasource_impl.dart';
import 'package:tmail_ui_user/features/manage_account/data/network/rule_filter_api.dart';
Expand All @@ -9,20 +22,35 @@ import 'package:tmail_ui_user/features/manage_account/domain/usecases/delete_ema
import 'package:tmail_ui_user/features/manage_account/domain/usecases/create_new_email_rule_filter_interactor.dart';
import 'package:tmail_ui_user/features/manage_account/domain/usecases/edit_email_rule_filter_interactor.dart';
import 'package:tmail_ui_user/features/manage_account/domain/usecases/get_all_rules_interactor.dart';
import 'package:tmail_ui_user/main/exceptions/cache_exception_thrower.dart';
import 'package:tmail_ui_user/main/exceptions/remote_exception_thrower.dart';
import 'package:tmail_ui_user/main/utils/ios_sharing_manager.dart';

class EmailRulesInteractorBindings extends InteractorsBindings {

@override
void bindingsDataSource() {
Get.lazyPut<RuleFilterDataSource>(() => Get.find<RuleFilterDataSourceImpl>());
Get.lazyPut<MailboxDataSource>(() => Get.find<MailboxDataSourceImpl>());
Get.lazyPut<StateDataSource>(() => Get.find<StateDataSourceImpl>());
}

@override
void bindingsDataSourceImpl() {
Get.lazyPut(() => RuleFilterDataSourceImpl(
Get.find<RuleFilterAPI>(),
Get.find<RemoteExceptionThrower>()));
Get.lazyPut(() => MailboxDataSourceImpl(
Get.find<MailboxAPI>(),
Get.find<MailboxIsolateWorker>(),
Get.find<RemoteExceptionThrower>()));
Get.lazyPut(() => MailboxCacheDataSourceImpl(
Get.find<MailboxCacheManager>(),
Get.find<CacheExceptionThrower>()));
Get.lazyPut(() => StateDataSourceImpl(
Get.find<StateCacheManager>(),
Get.find<IOSSharingManager>(),
Get.find<CacheExceptionThrower>()));
}

@override
Expand All @@ -31,15 +59,24 @@ class EmailRulesInteractorBindings extends InteractorsBindings {
Get.lazyPut(() => DeleteEmailRuleInteractor(Get.find<RuleFilterRepository>()));
Get.lazyPut(() => CreateNewEmailRuleFilterInteractor(Get.find<RuleFilterRepository>()));
Get.lazyPut(() => EditEmailRuleFilterInteractor(Get.find<RuleFilterRepository>()));
Get.lazyPut(() => GetListMailboxByIdInteractor(Get.find<MailboxRepository>()));
}

@override
void bindingsRepository() {
Get.lazyPut<RuleFilterRepository>(() => Get.find<RuleFilterRepositoryImpl>());
Get.lazyPut<MailboxRepository>(() => Get.find<MailboxRepositoryImpl>());
}

@override
void bindingsRepositoryImpl() {
Get.lazyPut(() => RuleFilterRepositoryImpl(Get.find<RuleFilterDataSource>()));
Get.lazyPut(() => MailboxRepositoryImpl(
{
DataSourceType.network: Get.find<MailboxDataSource>(),
DataSourceType.local: Get.find<MailboxCacheDataSourceImpl>()
},
Get.find<StateDataSource>(),
));
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import 'package:core/presentation/extensions/color_extension.dart';
import 'package:core/presentation/state/failure.dart';
import 'package:core/presentation/state/success.dart';
import 'package:core/presentation/views/bottom_popup/confirmation_dialog_action_sheet_builder.dart';
import 'package:core/presentation/views/dialog/confirmation_dialog_builder.dart';
Expand All @@ -8,9 +9,12 @@ import 'package:flutter/material.dart';
import 'package:flutter_svg/flutter_svg.dart';
import 'package:get/get.dart';
import 'package:jmap_dart_client/jmap/account_id.dart';
import 'package:jmap_dart_client/jmap/mail/mailbox/mailbox.dart';
import 'package:pointer_interceptor/pointer_interceptor.dart';
import 'package:rule_filter/rule_filter/tmail_rule.dart';
import 'package:tmail_ui_user/features/base/base_controller.dart';
import 'package:tmail_ui_user/features/mailbox/domain/state/get_list_mailbox_by_id_state.dart';
import 'package:tmail_ui_user/features/mailbox/domain/usecases/get_list_mailbox_by_id_interactor.dart';
import 'package:tmail_ui_user/features/manage_account/domain/model/create_new_email_rule_filter_request.dart';
import 'package:tmail_ui_user/features/manage_account/domain/model/delete_email_rule_request.dart';
import 'package:tmail_ui_user/features/manage_account/domain/model/edit_email_rule_filter_request.dart';
Expand All @@ -23,6 +27,7 @@ import 'package:tmail_ui_user/features/manage_account/domain/usecases/delete_ema
import 'package:tmail_ui_user/features/manage_account/domain/usecases/edit_email_rule_filter_interactor.dart';
import 'package:tmail_ui_user/features/manage_account/domain/usecases/get_all_rules_interactor.dart';
import 'package:tmail_ui_user/features/manage_account/presentation/email_rules/widgets/email_rule_bottom_sheet_action_tile_builder.dart';
import 'package:tmail_ui_user/features/manage_account/presentation/extensions/list_tmail_rule_extension.dart';
import 'package:tmail_ui_user/features/manage_account/presentation/manage_account_dashboard_controller.dart';
import 'package:tmail_ui_user/features/rules_filter_creator/presentation/model/creator_action_type.dart';
import 'package:tmail_ui_user/features/rules_filter_creator/presentation/model/rules_filter_creator_arguments.dart';
Expand All @@ -37,19 +42,22 @@ class EmailRulesController extends BaseController {
DeleteEmailRuleInteractor? _deleteEmailRuleInteractor;
CreateNewEmailRuleFilterInteractor? _createNewEmailRuleFilterInteractor;
EditEmailRuleFilterInteractor? _editEmailRuleFilterInteractor;
GetListMailboxByIdInteractor? _getListMailboxByIdInteractor;

final _accountDashBoardController = Get.find<ManageAccountDashBoardController>();

final listEmailRule = <TMailRule>[].obs;
final listMailboxIdsAppendIn = Rxn<List<MailboxId>>();

@override
void onInit() {
super.onInit();
try {
_getAllRulesInteractor = Get.find<GetAllRulesInteractor>();
_deleteEmailRuleInteractor = Get.find<DeleteEmailRuleInteractor>();
_createNewEmailRuleFilterInteractor = Get.find<CreateNewEmailRuleFilterInteractor>();
_editEmailRuleFilterInteractor = Get.find<EditEmailRuleFilterInteractor>();
_getAllRulesInteractor = getBinding<GetAllRulesInteractor>();
_deleteEmailRuleInteractor = getBinding<DeleteEmailRuleInteractor>();
_createNewEmailRuleFilterInteractor = getBinding<CreateNewEmailRuleFilterInteractor>();
_editEmailRuleFilterInteractor = getBinding<EditEmailRuleFilterInteractor>();
_getListMailboxByIdInteractor = getBinding<GetListMailboxByIdInteractor>();
} catch (e) {
logError('EmailRulesController::onInit(): ${e.toString()}');
}
Expand All @@ -65,15 +73,29 @@ class EmailRulesController extends BaseController {
void handleSuccessViewState(Success success) {
super.handleSuccessViewState(success);
if (success is GetAllRulesSuccess) {
if (success.rules?.isNotEmpty == true) {
listEmailRule.addAll(success.rules!);
}
listEmailRule.value = success.rules;
_validateRuleMailboxAppendInExist();
} else if (success is DeleteEmailRuleSuccess) {
_handleDeleteEmailRuleSuccess(success);
_validateRuleMailboxAppendInExist();
} else if (success is CreateNewRuleFilterSuccess) {
_createNewRuleFilterSuccess(success);
_validateRuleMailboxAppendInExist();
} else if (success is EditEmailRuleFilterSuccess) {
_editEmailRuleFilterSuccess(success);
_validateRuleMailboxAppendInExist();
} else if (success is GetListMailboxByIdSuccess) {
listMailboxIdsAppendIn.value = success.mailboxIds;
}
}

@override
void handleFailureViewState(Failure failure) {
log('EmailRulesController::handleFailureViewState: ${failure.runtimeType}');
if (failure is GetListMailboxByIdFailure) {
listMailboxIdsAppendIn.value = [];
} else {
super.handleFailureViewState(failure);
}
}

Expand Down Expand Up @@ -109,6 +131,7 @@ class EmailRulesController extends BaseController {
currentOverlayContext!,
AppLocalizations.of(currentContext!).newFilterWasCreated);
}
listMailboxIdsAppendIn.value = null;
listEmailRule.value = success.newListRules;
listEmailRule.refresh();
}
Expand Down Expand Up @@ -150,6 +173,7 @@ class EmailRulesController extends BaseController {
currentOverlayContext!,
AppLocalizations.of(currentContext!).yourFilterHasBeenUpdated);
}
listMailboxIdsAppendIn.value = null;
listEmailRule.value = success.listRulesUpdated;
listEmailRule.refresh();
}
Expand Down Expand Up @@ -237,6 +261,7 @@ class EmailRulesController extends BaseController {
}

if (success.rules?.isNotEmpty == true) {
listMailboxIdsAppendIn.value = null;
listEmailRule.clear();
listEmailRule.addAll(success.rules!);
}
Expand Down Expand Up @@ -290,4 +315,23 @@ class EmailRulesController extends BaseController {
}))
.build();
}

void _validateRuleMailboxAppendInExist() {
final listMailboxIds = listEmailRule.mailboxesAppendIn;
final accountId = _accountDashBoardController.accountId.value;
final session = _accountDashBoardController.sessionCurrent;

if (listMailboxIds.isEmpty ||
accountId == null ||
session == null ||
_getListMailboxByIdInteractor == null) {
return;
}

consumeState(_getListMailboxByIdInteractor!.execute(
session,
accountId,
listMailboxIds
));
}
}
Original file line number Diff line number Diff line change
@@ -1,20 +1,37 @@
import 'package:core/core.dart';
import 'package:core/presentation/extensions/color_extension.dart';
import 'package:core/presentation/resources/image_paths.dart';
import 'package:core/presentation/utils/responsive_utils.dart';
import 'package:core/presentation/views/button/icon_button_web.dart';
import 'package:core/presentation/views/button/tmail_button_widget.dart';
import 'package:flutter/material.dart';
import 'package:flutter_svg/flutter_svg.dart';
import 'package:get/get.dart';
import 'package:jmap_dart_client/jmap/mail/mailbox/mailbox.dart';
import 'package:rule_filter/rule_filter/tmail_rule.dart';
import 'package:tmail_ui_user/features/manage_account/presentation/email_rules/email_rules_controller.dart';
import 'package:tmail_ui_user/main/localizations/app_localizations.dart';

typedef EditRuleAction = Function(BuildContext context, TMailRule rule);
typedef DeleteRuleAction = Function(BuildContext context, TMailRule rule);
typedef OpenEditRuleMenuAction = Function(BuildContext context, TMailRule rule);

class EmailRulesItemWidget extends StatelessWidget {
final _responsiveUtils = Get.find<ResponsiveUtils>();
final _imagePaths = Get.find<ImagePaths>();
final _emailRuleController = Get.find<EmailRulesController>();

final ResponsiveUtils responsiveUtils;
final ImagePaths imagePaths;
final TMailRule rule;
final List<MailboxId>? mailboxIds;
final EditRuleAction? editRuleAction;
final DeleteRuleAction? deleteRuleAction;
final OpenEditRuleMenuAction? openEditRuleMenuAction;

EmailRulesItemWidget({
const EmailRulesItemWidget({
Key? key,
required this.rule,
required this.responsiveUtils,
required this.imagePaths,
this.mailboxIds,
this.editRuleAction,
this.deleteRuleAction,
this.openEditRuleMenuAction,
}) : super(key: key);

@override
Expand All @@ -23,47 +40,68 @@ class EmailRulesItemWidget extends StatelessWidget {
padding: EdgeInsets.only(
top: 15,
bottom: 15,
left: _responsiveUtils.isMobile(context) ? 16 : 24,
right: _responsiveUtils.isMobile(context) ? 0 : 24
left: responsiveUtils.isMobile(context) ? 16 : 24,
right: responsiveUtils.isMobile(context) ? 0 : 24
),
color: Colors.white,
child: Row(crossAxisAlignment: CrossAxisAlignment.center, children: [
Text(rule.name,
style: const TextStyle(
fontSize: 16,
fontWeight: FontWeight.w400,
color: Colors.black)),
Text(
rule.name,
style: Theme.of(context).textTheme.labelSmall?.copyWith(
fontSize: 16,
fontWeight: FontWeight.w400,
color: Colors.black
)
),
if (_isMailboxAppendInNotExist)
TMailButtonWidget.fromIcon(
icon: imagePaths.icQuotasWarning,
iconSize: 20,
margin: const EdgeInsetsDirectional.only(start: 4),
padding: const EdgeInsets.all(3),
iconColor: AppColor.colorBackgroundQuotasWarning,
tooltipMessage: AppLocalizations.of(context).warningRuleCannotAppliedWhenTargetFolderNoExist,
backgroundColor: Colors.transparent,
),
const Spacer(),
if (!_responsiveUtils.isMobile(context))
if (!responsiveUtils.isMobile(context))
buildIconWeb(
icon: SvgPicture.asset(
_imagePaths.icEditRule,
imagePaths.icEditRule,
fit: BoxFit.fill,
colorFilter: AppColor.primaryColor.asFilter(),
),
onTap: () {
_emailRuleController.editEmailRule(context, rule);
editRuleAction?.call(context, rule);
}),
if (!_responsiveUtils.isMobile(context))
if (!responsiveUtils.isMobile(context))
buildIconWeb(
icon: SvgPicture.asset(
_imagePaths.icDeleteRule,
imagePaths.icDeleteRule,
fit: BoxFit.fill,
),
onTap: () {
_emailRuleController.deleteEmailRule(context, rule);
deleteRuleAction?.call(context, rule);
}),
if (_responsiveUtils.isMobile(context))
if (responsiveUtils.isMobile(context))
buildIconWeb(
icon: SvgPicture.asset(
_imagePaths.icOpenEditRule,
imagePaths.icOpenEditRule,
fit: BoxFit.fill,
),
iconPadding: const EdgeInsets.all(0),
onTap: () {
_emailRuleController.openEditRuleMenuAction(context, rule);
openEditRuleMenuAction?.call(context, rule);
}),
]),
);
}

bool get _isMailboxAppendInNotExist {
final ruleMailboxIds= rule.action.appendIn.mailboxIds;

return mailboxIds != null
&& ruleMailboxIds.isNotEmpty
&& ruleMailboxIds.any((mailboxId) => !mailboxIds!.contains(mailboxId));
}
}
Loading

0 comments on commit 4c1703d

Please sign in to comment.