add interactor get all rules
This commit is contained in:
@@ -0,0 +1,32 @@
|
||||
import 'package:get/get.dart';
|
||||
import 'package:tmail_ui_user/features/base/base_bindings.dart';
|
||||
import 'package:tmail_ui_user/features/manage_account/domain/repository/manage_account_repository.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/email_rules_controller.dart';
|
||||
|
||||
class EmailRulesBindings extends BaseBindings {
|
||||
|
||||
@override
|
||||
void bindingsController() {
|
||||
Get.lazyPut(() => EmailRulesController(
|
||||
Get.find<GetAllRulesInteractor>(),
|
||||
));
|
||||
}
|
||||
|
||||
@override
|
||||
void bindingsDataSource() {}
|
||||
|
||||
@override
|
||||
void bindingsDataSourceImpl() {}
|
||||
|
||||
@override
|
||||
void bindingsInteractor() {
|
||||
Get.lazyPut(() => GetAllRulesInteractor(Get.find<ManageAccountRepository>()));
|
||||
}
|
||||
|
||||
@override
|
||||
void bindingsRepository() {}
|
||||
|
||||
@override
|
||||
void bindingsRepositoryImpl() {}
|
||||
}
|
||||
@@ -1,34 +1,65 @@
|
||||
import 'package:get/get.dart';
|
||||
import 'package:jmap_dart_client/jmap/account_id.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/manage_account/domain/state/get_all_rules_state.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/manage_account_dashboard_controller.dart';
|
||||
|
||||
class EmailRulesController extends BaseController {
|
||||
|
||||
final listEmailRule = <TMailRule>[].obs;
|
||||
final _accountDashBoardController = Get.find<ManageAccountDashBoardController>();
|
||||
final GetAllRulesInteractor _getAllRulesInteractor;
|
||||
late Worker accountIdWorker;
|
||||
|
||||
EmailRulesController();
|
||||
EmailRulesController(this._getAllRulesInteractor);
|
||||
|
||||
@override
|
||||
void onReady() {
|
||||
super.onReady();
|
||||
void _clearWorker() {
|
||||
accountIdWorker.call();
|
||||
}
|
||||
|
||||
@override
|
||||
void onDone() {
|
||||
viewState.value.fold(
|
||||
(failure) {},
|
||||
(success) {
|
||||
if (success is GetAllRulesSuccess) {
|
||||
if (success.rules?.isNotEmpty == true) {
|
||||
listEmailRule.addAll(success.rules!);
|
||||
}
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
void onError(error) {}
|
||||
|
||||
@override
|
||||
void onInit() {
|
||||
_getAllRules(_accountDashBoardController.accountId.value!);
|
||||
super.onInit();
|
||||
}
|
||||
|
||||
@override
|
||||
void onClose() {
|
||||
_clearWorker();
|
||||
super.onClose();
|
||||
}
|
||||
|
||||
void goToCreateNewRule() {
|
||||
//TODO: goToCreateNewRule
|
||||
}
|
||||
|
||||
void editEmailRule(TMailRule rule){
|
||||
void editEmailRule(TMailRule rule) {
|
||||
//TODO: editEmailRule
|
||||
}
|
||||
|
||||
void deleteEmailRule(TMailRule rule){
|
||||
void deleteEmailRule(TMailRule rule) {
|
||||
//TODO: deleteEmailRule
|
||||
}
|
||||
|
||||
void _getAllRules(AccountId accountId) {
|
||||
consumeState(_getAllRulesInteractor.execute(accountId));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,11 +1,12 @@
|
||||
import 'package:core/core.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:get/get.dart';
|
||||
import 'package:tmail_ui_user/features/base/mixin/app_loader_mixin.dart';
|
||||
import 'package:tmail_ui_user/features/manage_account/presentation/email_rules/email_rules_controller.dart';
|
||||
import 'package:tmail_ui_user/features/manage_account/presentation/email_rules/widgets/email_rules_header_widget.dart';
|
||||
import 'package:tmail_ui_user/features/manage_account/presentation/email_rules/widgets/list_email_rules_widget.dart';
|
||||
|
||||
class EmailRulesView extends GetWidget<EmailRulesController> {
|
||||
class EmailRulesView extends GetWidget<EmailRulesController> with AppLoaderMixin {
|
||||
final _responsiveUtils = Get.find<ResponsiveUtils>();
|
||||
final _imagePaths = Get.find<ImagePaths>();
|
||||
|
||||
@@ -41,6 +42,7 @@ class EmailRulesView extends GetWidget<EmailRulesController> {
|
||||
},
|
||||
),
|
||||
const SizedBox(height: 22),
|
||||
_buildLoadingView(),
|
||||
const Expanded(child: ListEmailRulesWidget())
|
||||
],
|
||||
),
|
||||
@@ -49,4 +51,15 @@ class EmailRulesView extends GetWidget<EmailRulesController> {
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildLoadingView() {
|
||||
return Obx(() => controller.viewState.value.fold(
|
||||
(failure) => const SizedBox.shrink(),
|
||||
(success) => success is LoadingState
|
||||
? Padding(
|
||||
padding: const EdgeInsets.only(bottom: 24),
|
||||
child: loadingWidget)
|
||||
: const SizedBox.shrink()
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
+2
-2
@@ -24,7 +24,7 @@ class EmailRulesItemWidget extends GetWidget<EmailRulesController> {
|
||||
return Container(
|
||||
padding: const EdgeInsets.symmetric(vertical: 20, horizontal: 24),
|
||||
color: Colors.white,
|
||||
child: Row(crossAxisAlignment: CrossAxisAlignment.start, children: [
|
||||
child: Row(crossAxisAlignment: CrossAxisAlignment.center, children: [
|
||||
Text(rule.name,
|
||||
style: const TextStyle(
|
||||
fontSize: 16,
|
||||
@@ -41,7 +41,7 @@ class EmailRulesItemWidget extends GetWidget<EmailRulesController> {
|
||||
}),
|
||||
buildIconWeb(
|
||||
icon: SvgPicture.asset(
|
||||
_imagePaths.icDeleteAttachment,
|
||||
_imagePaths.icDeleteRule,
|
||||
fit: BoxFit.fill,
|
||||
),
|
||||
onTap: () {
|
||||
|
||||
+43
-38
@@ -15,48 +15,53 @@ class ListEmailRulesWidget extends GetWidget<EmailRulesController> {
|
||||
color: AppColor.colorBackgroundWrapIconStyleCode,
|
||||
borderRadius: BorderRadius.circular(16),
|
||||
),
|
||||
child: Column(crossAxisAlignment: CrossAxisAlignment.start, children: [
|
||||
Padding(
|
||||
padding: const EdgeInsets.symmetric(
|
||||
vertical: 28,
|
||||
horizontal: 24,
|
||||
),
|
||||
child: Text(AppLocalizations.of(context).headerNameOfRules,
|
||||
style: const TextStyle(
|
||||
fontSize: 16,
|
||||
fontWeight: FontWeight.w500,
|
||||
color: AppColor.colorTextButtonHeaderThread)),
|
||||
),
|
||||
const Divider(
|
||||
color: AppColor.lineItemListColor,
|
||||
height: 1,
|
||||
thickness: 0.2,
|
||||
),
|
||||
Expanded(
|
||||
child: ListView.separated(
|
||||
shrinkWrap: true,
|
||||
itemCount: controller.listEmailRule.length,
|
||||
itemBuilder: (context, index) {
|
||||
final rule = controller.listEmailRule[index];
|
||||
return EmailRulesItemWidget(
|
||||
rule: rule,
|
||||
editRule: (rule) {
|
||||
controller.editEmailRule(rule);
|
||||
},
|
||||
deleteRule: (rule) {
|
||||
controller.editEmailRule(rule);
|
||||
},
|
||||
);
|
||||
},
|
||||
separatorBuilder: (BuildContext context, int index) =>
|
||||
const Divider(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
Padding(
|
||||
padding: const EdgeInsets.symmetric(
|
||||
vertical: 28,
|
||||
horizontal: 24,
|
||||
),
|
||||
child: Text(AppLocalizations.of(context).headerNameOfRules,
|
||||
style: const TextStyle(
|
||||
fontSize: 16,
|
||||
fontWeight: FontWeight.w500,
|
||||
color: AppColor.colorTextButtonHeaderThread)),
|
||||
),
|
||||
const Divider(
|
||||
color: AppColor.lineItemListColor,
|
||||
height: 1,
|
||||
thickness: 0.2,
|
||||
),
|
||||
),
|
||||
),
|
||||
]),
|
||||
Expanded(
|
||||
child: Obx(
|
||||
() => ListView.separated(
|
||||
shrinkWrap: true,
|
||||
itemCount: controller.listEmailRule.length,
|
||||
itemBuilder: (context, index) {
|
||||
final rule = controller.listEmailRule[index];
|
||||
return EmailRulesItemWidget(
|
||||
rule: rule,
|
||||
editRule: (rule) {
|
||||
controller.editEmailRule(rule);
|
||||
},
|
||||
deleteRule: (rule) {
|
||||
controller.editEmailRule(rule);
|
||||
},
|
||||
);
|
||||
},
|
||||
separatorBuilder: (BuildContext context, int index) =>
|
||||
const Divider(
|
||||
color: AppColor.lineItemListColor,
|
||||
height: 1,
|
||||
thickness: 0.2,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
]),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import 'package:get/get.dart';
|
||||
import 'package:tmail_ui_user/features/base/base_bindings.dart';
|
||||
import 'package:tmail_ui_user/features/manage_account/presentation/email_rules/email_rules_bindings.dart';
|
||||
import 'package:tmail_ui_user/features/manage_account/presentation/profiles/identities/identities_bindings.dart';
|
||||
import 'package:tmail_ui_user/features/manage_account/presentation/profiles/profiles_controller.dart';
|
||||
|
||||
@@ -9,6 +10,7 @@ class ProfileBindings extends BaseBindings {
|
||||
void dependencies() {
|
||||
super.dependencies();
|
||||
IdentitiesBindings().dependencies();
|
||||
EmailRulesBindings().dependencies();
|
||||
}
|
||||
|
||||
@override
|
||||
|
||||
Reference in New Issue
Block a user