mirror of
https://github.com/SyncrowIOT/web.git
synced 2026-10-26 21:57:57 +00:00
Compare commits
1
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
921da20d3f |
@@ -1,10 +0,0 @@
|
|||||||
version: 2
|
|
||||||
updates:
|
|
||||||
- package-ecosystem: "github-actions"
|
|
||||||
directory: "/"
|
|
||||||
schedule:
|
|
||||||
interval: "daily"
|
|
||||||
- package-ecosystem: "pub"
|
|
||||||
directory: "/"
|
|
||||||
schedule:
|
|
||||||
interval: "daily"
|
|
||||||
+7
-7
@@ -11,6 +11,7 @@ import 'package:syncrow_web/pages/home/bloc/home_event.dart';
|
|||||||
import 'package:syncrow_web/pages/routines/bloc/create_routine_bloc/create_routine_bloc.dart';
|
import 'package:syncrow_web/pages/routines/bloc/create_routine_bloc/create_routine_bloc.dart';
|
||||||
import 'package:syncrow_web/pages/routines/bloc/routine_bloc/routine_bloc.dart';
|
import 'package:syncrow_web/pages/routines/bloc/routine_bloc/routine_bloc.dart';
|
||||||
import 'package:syncrow_web/pages/space_tree/bloc/space_tree_bloc.dart';
|
import 'package:syncrow_web/pages/space_tree/bloc/space_tree_bloc.dart';
|
||||||
|
import 'package:syncrow_web/pages/space_tree/bloc/space_tree_event.dart';
|
||||||
import 'package:syncrow_web/pages/visitor_password/bloc/visitor_password_bloc.dart';
|
import 'package:syncrow_web/pages/visitor_password/bloc/visitor_password_bloc.dart';
|
||||||
import 'package:syncrow_web/services/locator.dart';
|
import 'package:syncrow_web/services/locator.dart';
|
||||||
import 'package:syncrow_web/utils/app_routes.dart';
|
import 'package:syncrow_web/utils/app_routes.dart';
|
||||||
@@ -20,10 +21,8 @@ import 'package:syncrow_web/utils/theme/theme.dart';
|
|||||||
|
|
||||||
Future<void> main() async {
|
Future<void> main() async {
|
||||||
try {
|
try {
|
||||||
const environment = String.fromEnvironment(
|
const environment =
|
||||||
'FLAVOR',
|
String.fromEnvironment('FLAVOR', defaultValue: 'production');
|
||||||
defaultValue: 'production',
|
|
||||||
);
|
|
||||||
await dotenv.load(fileName: '.env.$environment');
|
await dotenv.load(fileName: '.env.$environment');
|
||||||
WidgetsFlutterBinding.ensureInitialized();
|
WidgetsFlutterBinding.ensureInitialized();
|
||||||
await Firebase.initializeApp(
|
await Firebase.initializeApp(
|
||||||
@@ -41,7 +40,7 @@ class MyApp extends StatelessWidget {
|
|||||||
initialLocation: RoutesConst.auth,
|
initialLocation: RoutesConst.auth,
|
||||||
routes: AppRoutes.getRoutes(),
|
routes: AppRoutes.getRoutes(),
|
||||||
redirect: (context, state) async {
|
redirect: (context, state) async {
|
||||||
final checkToken = await AuthBloc.getTokenAndValidate();
|
String checkToken = await AuthBloc.getTokenAndValidate();
|
||||||
final loggedIn = checkToken == 'Success';
|
final loggedIn = checkToken == 'Success';
|
||||||
final goingToLogin = state.uri.toString() == RoutesConst.auth;
|
final goingToLogin = state.uri.toString() == RoutesConst.auth;
|
||||||
|
|
||||||
@@ -59,7 +58,8 @@ class MyApp extends StatelessWidget {
|
|||||||
BlocProvider<CreateRoutineBloc>(
|
BlocProvider<CreateRoutineBloc>(
|
||||||
create: (context) => CreateRoutineBloc(),
|
create: (context) => CreateRoutineBloc(),
|
||||||
),
|
),
|
||||||
BlocProvider(create: (context) => HomeBloc()..add(FetchUserInfo())),
|
BlocProvider(
|
||||||
|
create: (context) => HomeBloc()..add(const FetchUserInfo())),
|
||||||
BlocProvider<VisitorPasswordBloc>(
|
BlocProvider<VisitorPasswordBloc>(
|
||||||
create: (context) => VisitorPasswordBloc(),
|
create: (context) => VisitorPasswordBloc(),
|
||||||
),
|
),
|
||||||
@@ -67,7 +67,7 @@ class MyApp extends StatelessWidget {
|
|||||||
create: (context) => RoutineBloc(),
|
create: (context) => RoutineBloc(),
|
||||||
),
|
),
|
||||||
BlocProvider<SpaceTreeBloc>(
|
BlocProvider<SpaceTreeBloc>(
|
||||||
create: (context) => SpaceTreeBloc(),
|
create: (context) => SpaceTreeBloc()..add(InitialEvent()),
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
child: MaterialApp.router(
|
child: MaterialApp.router(
|
||||||
|
|||||||
+5
-7
@@ -11,6 +11,7 @@ import 'package:syncrow_web/pages/home/bloc/home_event.dart';
|
|||||||
import 'package:syncrow_web/pages/routines/bloc/create_routine_bloc/create_routine_bloc.dart';
|
import 'package:syncrow_web/pages/routines/bloc/create_routine_bloc/create_routine_bloc.dart';
|
||||||
import 'package:syncrow_web/pages/routines/bloc/routine_bloc/routine_bloc.dart';
|
import 'package:syncrow_web/pages/routines/bloc/routine_bloc/routine_bloc.dart';
|
||||||
import 'package:syncrow_web/pages/space_tree/bloc/space_tree_bloc.dart';
|
import 'package:syncrow_web/pages/space_tree/bloc/space_tree_bloc.dart';
|
||||||
|
import 'package:syncrow_web/pages/space_tree/bloc/space_tree_event.dart';
|
||||||
import 'package:syncrow_web/pages/visitor_password/bloc/visitor_password_bloc.dart';
|
import 'package:syncrow_web/pages/visitor_password/bloc/visitor_password_bloc.dart';
|
||||||
import 'package:syncrow_web/services/locator.dart';
|
import 'package:syncrow_web/services/locator.dart';
|
||||||
import 'package:syncrow_web/utils/app_routes.dart';
|
import 'package:syncrow_web/utils/app_routes.dart';
|
||||||
@@ -20,10 +21,7 @@ import 'package:syncrow_web/utils/theme/theme.dart';
|
|||||||
|
|
||||||
Future<void> main() async {
|
Future<void> main() async {
|
||||||
try {
|
try {
|
||||||
const environment = String.fromEnvironment(
|
const environment = String.fromEnvironment('FLAVOR', defaultValue: 'development');
|
||||||
'FLAVOR',
|
|
||||||
defaultValue: 'development',
|
|
||||||
);
|
|
||||||
await dotenv.load(fileName: '.env.$environment');
|
await dotenv.load(fileName: '.env.$environment');
|
||||||
WidgetsFlutterBinding.ensureInitialized();
|
WidgetsFlutterBinding.ensureInitialized();
|
||||||
await Firebase.initializeApp(
|
await Firebase.initializeApp(
|
||||||
@@ -41,7 +39,7 @@ class MyApp extends StatelessWidget {
|
|||||||
initialLocation: RoutesConst.auth,
|
initialLocation: RoutesConst.auth,
|
||||||
routes: AppRoutes.getRoutes(),
|
routes: AppRoutes.getRoutes(),
|
||||||
redirect: (context, state) async {
|
redirect: (context, state) async {
|
||||||
final checkToken = await AuthBloc.getTokenAndValidate();
|
String checkToken = await AuthBloc.getTokenAndValidate();
|
||||||
final loggedIn = checkToken == 'Success';
|
final loggedIn = checkToken == 'Success';
|
||||||
final goingToLogin = state.uri.toString() == RoutesConst.auth;
|
final goingToLogin = state.uri.toString() == RoutesConst.auth;
|
||||||
|
|
||||||
@@ -59,7 +57,7 @@ class MyApp extends StatelessWidget {
|
|||||||
BlocProvider<CreateRoutineBloc>(
|
BlocProvider<CreateRoutineBloc>(
|
||||||
create: (context) => CreateRoutineBloc(),
|
create: (context) => CreateRoutineBloc(),
|
||||||
),
|
),
|
||||||
BlocProvider(create: (context) => HomeBloc()..add(FetchUserInfo())),
|
BlocProvider(create: (context) => HomeBloc()..add(const FetchUserInfo())),
|
||||||
BlocProvider<VisitorPasswordBloc>(
|
BlocProvider<VisitorPasswordBloc>(
|
||||||
create: (context) => VisitorPasswordBloc(),
|
create: (context) => VisitorPasswordBloc(),
|
||||||
),
|
),
|
||||||
@@ -67,7 +65,7 @@ class MyApp extends StatelessWidget {
|
|||||||
create: (context) => RoutineBloc(),
|
create: (context) => RoutineBloc(),
|
||||||
),
|
),
|
||||||
BlocProvider<SpaceTreeBloc>(
|
BlocProvider<SpaceTreeBloc>(
|
||||||
create: (context) => SpaceTreeBloc(),
|
create: (context) => SpaceTreeBloc()..add(InitialEvent()),
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
child: MaterialApp.router(
|
child: MaterialApp.router(
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ import 'package:syncrow_web/pages/home/bloc/home_event.dart';
|
|||||||
import 'package:syncrow_web/pages/routines/bloc/create_routine_bloc/create_routine_bloc.dart';
|
import 'package:syncrow_web/pages/routines/bloc/create_routine_bloc/create_routine_bloc.dart';
|
||||||
import 'package:syncrow_web/pages/routines/bloc/routine_bloc/routine_bloc.dart';
|
import 'package:syncrow_web/pages/routines/bloc/routine_bloc/routine_bloc.dart';
|
||||||
import 'package:syncrow_web/pages/space_tree/bloc/space_tree_bloc.dart';
|
import 'package:syncrow_web/pages/space_tree/bloc/space_tree_bloc.dart';
|
||||||
|
import 'package:syncrow_web/pages/space_tree/bloc/space_tree_event.dart';
|
||||||
import 'package:syncrow_web/pages/visitor_password/bloc/visitor_password_bloc.dart';
|
import 'package:syncrow_web/pages/visitor_password/bloc/visitor_password_bloc.dart';
|
||||||
import 'package:syncrow_web/services/locator.dart';
|
import 'package:syncrow_web/services/locator.dart';
|
||||||
import 'package:syncrow_web/utils/app_routes.dart';
|
import 'package:syncrow_web/utils/app_routes.dart';
|
||||||
@@ -38,7 +39,7 @@ class MyApp extends StatelessWidget {
|
|||||||
initialLocation: RoutesConst.auth,
|
initialLocation: RoutesConst.auth,
|
||||||
routes: AppRoutes.getRoutes(),
|
routes: AppRoutes.getRoutes(),
|
||||||
redirect: (context, state) async {
|
redirect: (context, state) async {
|
||||||
final checkToken = await AuthBloc.getTokenAndValidate();
|
String checkToken = await AuthBloc.getTokenAndValidate();
|
||||||
final loggedIn = checkToken == 'Success';
|
final loggedIn = checkToken == 'Success';
|
||||||
final goingToLogin = state.uri.toString() == RoutesConst.auth;
|
final goingToLogin = state.uri.toString() == RoutesConst.auth;
|
||||||
|
|
||||||
@@ -56,7 +57,7 @@ class MyApp extends StatelessWidget {
|
|||||||
BlocProvider<CreateRoutineBloc>(
|
BlocProvider<CreateRoutineBloc>(
|
||||||
create: (context) => CreateRoutineBloc(),
|
create: (context) => CreateRoutineBloc(),
|
||||||
),
|
),
|
||||||
BlocProvider(create: (context) => HomeBloc()..add(FetchUserInfo())),
|
BlocProvider(create: (context) => HomeBloc()..add(const FetchUserInfo())),
|
||||||
BlocProvider<VisitorPasswordBloc>(
|
BlocProvider<VisitorPasswordBloc>(
|
||||||
create: (context) => VisitorPasswordBloc(),
|
create: (context) => VisitorPasswordBloc(),
|
||||||
),
|
),
|
||||||
@@ -64,7 +65,7 @@ class MyApp extends StatelessWidget {
|
|||||||
create: (context) => RoutineBloc(),
|
create: (context) => RoutineBloc(),
|
||||||
),
|
),
|
||||||
BlocProvider<SpaceTreeBloc>(
|
BlocProvider<SpaceTreeBloc>(
|
||||||
create: (context) => SpaceTreeBloc(),
|
create: (context) => SpaceTreeBloc()..add(InitialEvent()),
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
child: MaterialApp.router(
|
child: MaterialApp.router(
|
||||||
|
|||||||
@@ -31,8 +31,6 @@ import 'package:syncrow_web/pages/analytics/services/range_of_aqi/remote_range_o
|
|||||||
import 'package:syncrow_web/pages/analytics/services/realtime_device_service/firebase_realtime_device_service.dart';
|
import 'package:syncrow_web/pages/analytics/services/realtime_device_service/firebase_realtime_device_service.dart';
|
||||||
import 'package:syncrow_web/pages/analytics/services/total_energy_consumption/remote_total_energy_consumption_service.dart';
|
import 'package:syncrow_web/pages/analytics/services/total_energy_consumption/remote_total_energy_consumption_service.dart';
|
||||||
import 'package:syncrow_web/pages/device_managment/shared/navigate_home_grid_view.dart';
|
import 'package:syncrow_web/pages/device_managment/shared/navigate_home_grid_view.dart';
|
||||||
import 'package:syncrow_web/pages/space_tree/bloc/space_tree_bloc.dart';
|
|
||||||
import 'package:syncrow_web/pages/space_tree/bloc/space_tree_event.dart';
|
|
||||||
import 'package:syncrow_web/services/api/http_service.dart';
|
import 'package:syncrow_web/services/api/http_service.dart';
|
||||||
import 'package:syncrow_web/utils/theme/responsive_text_theme.dart';
|
import 'package:syncrow_web/utils/theme/responsive_text_theme.dart';
|
||||||
import 'package:syncrow_web/web_layout/web_scaffold.dart';
|
import 'package:syncrow_web/web_layout/web_scaffold.dart';
|
||||||
@@ -132,19 +130,9 @@ class _AnalyticsPageState extends State<AnalyticsPage> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class AnalyticsPageForm extends StatefulWidget {
|
class AnalyticsPageForm extends StatelessWidget {
|
||||||
const AnalyticsPageForm({super.key});
|
const AnalyticsPageForm({super.key});
|
||||||
|
|
||||||
@override
|
|
||||||
State<AnalyticsPageForm> createState() => _AnalyticsPageFormState();
|
|
||||||
}
|
|
||||||
|
|
||||||
class _AnalyticsPageFormState extends State<AnalyticsPageForm> {
|
|
||||||
@override
|
|
||||||
void initState() {
|
|
||||||
context.read<SpaceTreeBloc>().add(InitialEvent());
|
|
||||||
super.initState();
|
|
||||||
}
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return WebScaffold(
|
return WebScaffold(
|
||||||
|
|||||||
+12
-8
@@ -41,15 +41,19 @@ class AnalyticsPageTabsAndChildren extends StatelessWidget {
|
|||||||
mainAxisAlignment: MainAxisAlignment.start,
|
mainAxisAlignment: MainAxisAlignment.start,
|
||||||
crossAxisAlignment: CrossAxisAlignment.center,
|
crossAxisAlignment: CrossAxisAlignment.center,
|
||||||
children: [
|
children: [
|
||||||
...AnalyticsPageTab.values.map(
|
...AnalyticsPageTab.values
|
||||||
(tab) => _buildAnimation(
|
.where(
|
||||||
child: AnalyticsPageTabButton(
|
(tab) => tab != AnalyticsPageTab.airQuality,
|
||||||
key: ValueKey(selectedTab),
|
)
|
||||||
tab: tab,
|
.map(
|
||||||
isSelected: tab == selectedTab,
|
(tab) => _buildAnimation(
|
||||||
|
child: AnalyticsPageTabButton(
|
||||||
|
key: ValueKey(selectedTab),
|
||||||
|
tab: tab,
|
||||||
|
isSelected: tab == selectedTab,
|
||||||
|
),
|
||||||
|
),
|
||||||
),
|
),
|
||||||
),
|
|
||||||
),
|
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
|||||||
@@ -8,28 +8,15 @@ import 'package:syncrow_web/pages/routines/bloc/create_routine_bloc/create_routi
|
|||||||
import 'package:syncrow_web/pages/routines/bloc/routine_bloc/routine_bloc.dart';
|
import 'package:syncrow_web/pages/routines/bloc/routine_bloc/routine_bloc.dart';
|
||||||
import 'package:syncrow_web/pages/routines/view/create_new_routine_view.dart';
|
import 'package:syncrow_web/pages/routines/view/create_new_routine_view.dart';
|
||||||
import 'package:syncrow_web/pages/routines/view/routines_view.dart';
|
import 'package:syncrow_web/pages/routines/view/routines_view.dart';
|
||||||
import 'package:syncrow_web/pages/space_tree/bloc/space_tree_bloc.dart';
|
|
||||||
import 'package:syncrow_web/pages/space_tree/bloc/space_tree_event.dart';
|
|
||||||
import 'package:syncrow_web/utils/color_manager.dart';
|
import 'package:syncrow_web/utils/color_manager.dart';
|
||||||
import 'package:syncrow_web/utils/extension/build_context_x.dart';
|
import 'package:syncrow_web/utils/extension/build_context_x.dart';
|
||||||
import 'package:syncrow_web/utils/helpers/responsice_layout_helper/responsive_layout_helper.dart';
|
import 'package:syncrow_web/utils/helpers/responsice_layout_helper/responsive_layout_helper.dart';
|
||||||
import 'package:syncrow_web/utils/theme/responsive_text_theme.dart';
|
import 'package:syncrow_web/utils/theme/responsive_text_theme.dart';
|
||||||
import 'package:syncrow_web/web_layout/web_scaffold.dart';
|
import 'package:syncrow_web/web_layout/web_scaffold.dart';
|
||||||
|
|
||||||
class DeviceManagementPage extends StatefulWidget with HelperResponsiveLayout {
|
class DeviceManagementPage extends StatelessWidget with HelperResponsiveLayout {
|
||||||
const DeviceManagementPage({super.key});
|
const DeviceManagementPage({super.key});
|
||||||
|
|
||||||
@override
|
|
||||||
State<DeviceManagementPage> createState() => _DeviceManagementPageState();
|
|
||||||
}
|
|
||||||
|
|
||||||
class _DeviceManagementPageState extends State<DeviceManagementPage> {
|
|
||||||
|
|
||||||
@override
|
|
||||||
void initState() {
|
|
||||||
context.read<SpaceTreeBloc>().add(InitialEvent());
|
|
||||||
super.initState();
|
|
||||||
}
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return MultiBlocProvider(
|
return MultiBlocProvider(
|
||||||
|
|||||||
@@ -13,32 +13,30 @@ import 'package:syncrow_web/pages/space_tree/bloc/space_tree_event.dart';
|
|||||||
import 'package:syncrow_web/services/home_api.dart';
|
import 'package:syncrow_web/services/home_api.dart';
|
||||||
import 'package:syncrow_web/utils/constants/assets.dart';
|
import 'package:syncrow_web/utils/constants/assets.dart';
|
||||||
import 'package:syncrow_web/utils/constants/routes_const.dart';
|
import 'package:syncrow_web/utils/constants/routes_const.dart';
|
||||||
|
import 'package:syncrow_web/utils/navigation_service.dart';
|
||||||
|
|
||||||
class HomeBloc extends Bloc<HomeEvent, HomeState> {
|
class HomeBloc extends Bloc<HomeEvent, HomeState> {
|
||||||
UserModel? user;
|
UserModel? user;
|
||||||
String terms = '';
|
String terms = '';
|
||||||
String policy = '';
|
String policy = '';
|
||||||
|
|
||||||
HomeBloc() : super(HomeInitial()) {
|
HomeBloc() : super((HomeInitial())) {
|
||||||
|
// on<CreateNewNode>(_createNode);
|
||||||
on<FetchUserInfo>(_fetchUserInfo);
|
on<FetchUserInfo>(_fetchUserInfo);
|
||||||
on<FetchTermEvent>(_fetchTerms);
|
on<FetchTermEvent>(_fetchTerms);
|
||||||
on<FetchPolicyEvent>(_fetchPolicy);
|
on<FetchPolicyEvent>(_fetchPolicy);
|
||||||
on<ConfirmUserAgreementEvent>(_confirmUserAgreement);
|
on<ConfirmUserAgreementEvent>(_confirmUserAgreement);
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> _fetchUserInfo(
|
Future _fetchUserInfo(FetchUserInfo event, Emitter<HomeState> emit) async {
|
||||||
FetchUserInfo event,
|
|
||||||
Emitter<HomeState> emit,
|
|
||||||
) async {
|
|
||||||
try {
|
try {
|
||||||
final uuid =
|
var uuid =
|
||||||
await const FlutterSecureStorage().read(key: UserModel.userUuidKey);
|
await const FlutterSecureStorage().read(key: UserModel.userUuidKey);
|
||||||
if (uuid != null) {
|
user = await HomeApi().fetchUserInfo(uuid);
|
||||||
user = await HomeApi().fetchUserInfo(uuid);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (user != null && user?.project != null) {
|
if (user != null && user!.project != null) {
|
||||||
await ProjectManager.setProjectUUID(user!.project!.uuid);
|
await ProjectManager.setProjectUUID(user!.project!.uuid);
|
||||||
|
|
||||||
}
|
}
|
||||||
add(FetchTermEvent());
|
add(FetchTermEvent());
|
||||||
add(FetchPolicyEvent());
|
add(FetchPolicyEvent());
|
||||||
@@ -49,7 +47,7 @@ class HomeBloc extends Bloc<HomeEvent, HomeState> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> _fetchTerms(FetchTermEvent event, Emitter<HomeState> emit) async {
|
Future _fetchTerms(FetchTermEvent event, Emitter<HomeState> emit) async {
|
||||||
try {
|
try {
|
||||||
emit(LoadingHome());
|
emit(LoadingHome());
|
||||||
terms = await HomeApi().fetchTerms();
|
terms = await HomeApi().fetchTerms();
|
||||||
@@ -59,22 +57,22 @@ class HomeBloc extends Bloc<HomeEvent, HomeState> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> _fetchPolicy(FetchPolicyEvent event, Emitter<HomeState> emit) async {
|
Future _fetchPolicy(FetchPolicyEvent event, Emitter<HomeState> emit) async {
|
||||||
try {
|
try {
|
||||||
emit(LoadingHome());
|
emit(LoadingHome());
|
||||||
policy = await HomeApi().fetchPolicy();
|
policy = await HomeApi().fetchPolicy();
|
||||||
emit(HomeInitial());
|
emit(HomeInitial());
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
debugPrint('Error fetching policy: $e');
|
debugPrint("Error fetching policy: $e");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> _confirmUserAgreement(
|
Future _confirmUserAgreement(
|
||||||
ConfirmUserAgreementEvent event, Emitter<HomeState> emit) async {
|
ConfirmUserAgreementEvent event, Emitter<HomeState> emit) async {
|
||||||
try {
|
try {
|
||||||
emit(LoadingHome());
|
emit(LoadingHome());
|
||||||
final uuid =
|
var uuid =
|
||||||
await const FlutterSecureStorage().read(key: UserModel.userUuidKey);
|
await const FlutterSecureStorage().read(key: UserModel.userUuidKey);
|
||||||
policy = await HomeApi().confirmUserAgreements(uuid);
|
policy = await HomeApi().confirmUserAgreements(uuid);
|
||||||
emit(PolicyAgreement());
|
emit(PolicyAgreement());
|
||||||
@@ -83,7 +81,7 @@ class HomeBloc extends Bloc<HomeEvent, HomeState> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
final List<HomeItemModel> homeItems = [
|
List<HomeItemModel> homeItems = [
|
||||||
HomeItemModel(
|
HomeItemModel(
|
||||||
title: 'Access Management',
|
title: 'Access Management',
|
||||||
icon: Assets.accessIcon,
|
icon: Assets.accessIcon,
|
||||||
@@ -128,5 +126,41 @@ class HomeBloc extends Bloc<HomeEvent, HomeState> {
|
|||||||
},
|
},
|
||||||
color: const Color(0xFF023DFE),
|
color: const Color(0xFF023DFE),
|
||||||
),
|
),
|
||||||
|
|
||||||
|
// HomeItemModel(
|
||||||
|
// title: 'Move in',
|
||||||
|
// icon: Assets.moveinIcon,
|
||||||
|
// active: false,
|
||||||
|
// onPress: (context) {},
|
||||||
|
// color: ColorsManager.primaryColor,
|
||||||
|
// ),
|
||||||
|
// HomeItemModel(
|
||||||
|
// title: 'Construction',
|
||||||
|
// icon: Assets.constructionIcon,
|
||||||
|
// active: false,
|
||||||
|
// onPress: (context) {},
|
||||||
|
// color: ColorsManager.primaryColor,
|
||||||
|
// ),
|
||||||
|
// HomeItemModel(
|
||||||
|
// title: 'Energy',
|
||||||
|
// icon: Assets.energyIcon,
|
||||||
|
// active: false,
|
||||||
|
// onPress: (context) {},
|
||||||
|
// color: ColorsManager.slidingBlueColor.withOpacity(0.2),
|
||||||
|
// ),
|
||||||
|
// HomeItemModel(
|
||||||
|
// title: 'Integrations',
|
||||||
|
// icon: Assets.integrationsIcon,
|
||||||
|
// active: false,
|
||||||
|
// onPress: (context) {},
|
||||||
|
// color: ColorsManager.slidingBlueColor.withOpacity(0.2),
|
||||||
|
// ),
|
||||||
|
// HomeItemModel(
|
||||||
|
// title: 'Asset',
|
||||||
|
// icon: Assets.assetIcon,
|
||||||
|
// active: false,
|
||||||
|
// onPress: (context) {},
|
||||||
|
// color: ColorsManager.slidingBlueColor.withOpacity(0.2),
|
||||||
|
// ),
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,37 +1,17 @@
|
|||||||
import 'package:flutter/cupertino.dart';
|
import 'package:flutter/cupertino.dart';
|
||||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
|
||||||
import 'package:syncrow_web/pages/home/bloc/home_bloc.dart';
|
|
||||||
import 'package:syncrow_web/pages/home/bloc/home_event.dart';
|
|
||||||
import 'package:syncrow_web/pages/home/view/home_page_mobile.dart';
|
import 'package:syncrow_web/pages/home/view/home_page_mobile.dart';
|
||||||
import 'package:syncrow_web/pages/home/view/home_page_web.dart';
|
import 'package:syncrow_web/pages/home/view/home_page_web.dart';
|
||||||
import 'package:syncrow_web/utils/helpers/responsice_layout_helper/responsive_layout_helper.dart';
|
import 'package:syncrow_web/utils/helpers/responsice_layout_helper/responsive_layout_helper.dart';
|
||||||
|
|
||||||
class HomePage extends StatefulWidget {
|
class HomePage extends StatelessWidget with HelperResponsiveLayout {
|
||||||
const HomePage({super.key});
|
const HomePage({super.key});
|
||||||
|
|
||||||
@override
|
|
||||||
State<HomePage> createState() => _HomePageState();
|
|
||||||
}
|
|
||||||
|
|
||||||
class _HomePageState extends State<HomePage> with HelperResponsiveLayout {
|
|
||||||
@override
|
|
||||||
void initState() {
|
|
||||||
_fetchUserInfo();
|
|
||||||
|
|
||||||
super.initState();
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
if (isSmallScreenSize(context) || isMediumScreenSize(context)) {
|
final isSmallScreen = isSmallScreenSize(context);
|
||||||
return HomeMobilePage();
|
final isMediumScreen = isMediumScreenSize(context);
|
||||||
}
|
return isSmallScreen || isMediumScreen
|
||||||
|
? HomeMobilePage()
|
||||||
return const HomeWebPage();
|
: const HomeWebPage();
|
||||||
}
|
|
||||||
|
|
||||||
void _fetchUserInfo() {
|
|
||||||
final bloc = context.read<HomeBloc>();
|
|
||||||
if (bloc.user == null) bloc.add(const FetchUserInfo());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,6 +19,7 @@ import 'package:syncrow_web/utils/color_manager.dart';
|
|||||||
import 'package:syncrow_web/utils/constants/assets.dart';
|
import 'package:syncrow_web/utils/constants/assets.dart';
|
||||||
import 'package:syncrow_web/utils/extension/build_context_x.dart';
|
import 'package:syncrow_web/utils/extension/build_context_x.dart';
|
||||||
import 'package:syncrow_web/utils/style.dart';
|
import 'package:syncrow_web/utils/style.dart';
|
||||||
|
|
||||||
class UsersPage extends StatelessWidget {
|
class UsersPage extends StatelessWidget {
|
||||||
UsersPage({super.key});
|
UsersPage({super.key});
|
||||||
|
|
||||||
|
|||||||
@@ -13,35 +13,6 @@ class FunctionBloc extends Bloc<FunctionBlocEvent, FunctionBlocState> {
|
|||||||
on<AddFunction>(_onAddFunction);
|
on<AddFunction>(_onAddFunction);
|
||||||
on<SelectFunction>(_onSelectFunction);
|
on<SelectFunction>(_onSelectFunction);
|
||||||
}
|
}
|
||||||
// void _onAddFunction(AddFunction event, Emitter<FunctionBlocState> emit) {
|
|
||||||
// final functions = List<DeviceFunctionData>.from(state.addedFunctions);
|
|
||||||
// final existingIndex = functions.indexWhere(
|
|
||||||
// (f) => f.functionCode == event.functionData.functionCode,
|
|
||||||
// );
|
|
||||||
|
|
||||||
// if (existingIndex != -1) {
|
|
||||||
// final existingData = functions[existingIndex];
|
|
||||||
// functions[existingIndex] = DeviceFunctionData(
|
|
||||||
// entityId: event.functionData.entityId,
|
|
||||||
// functionCode: event.functionData.functionCode,
|
|
||||||
// operationName: event.functionData.operationName,
|
|
||||||
// value: event.functionData.value ?? existingData.value,
|
|
||||||
// valueDescription: event.functionData.valueDescription ??
|
|
||||||
// existingData.valueDescription,
|
|
||||||
// condition: event.functionData.condition ?? existingData.condition,
|
|
||||||
// step: event.functionData.step ?? existingData.step,
|
|
||||||
// );
|
|
||||||
// } else {
|
|
||||||
// functions.clear();
|
|
||||||
// functions.add(event.functionData);
|
|
||||||
// }
|
|
||||||
|
|
||||||
// emit(state.copyWith(
|
|
||||||
// addedFunctions: functions,
|
|
||||||
// selectedFunction: event.functionData.functionCode,
|
|
||||||
// ));
|
|
||||||
// }
|
|
||||||
|
|
||||||
void _onAddFunction(AddFunction event, Emitter<FunctionBlocState> emit) {
|
void _onAddFunction(AddFunction event, Emitter<FunctionBlocState> emit) {
|
||||||
final functions = List<DeviceFunctionData>.from(state.addedFunctions);
|
final functions = List<DeviceFunctionData>.from(state.addedFunctions);
|
||||||
final existingIndex = functions.indexWhere(
|
final existingIndex = functions.indexWhere(
|
||||||
@@ -49,10 +20,19 @@ class FunctionBloc extends Bloc<FunctionBlocEvent, FunctionBlocState> {
|
|||||||
);
|
);
|
||||||
|
|
||||||
if (existingIndex != -1) {
|
if (existingIndex != -1) {
|
||||||
// Update the function value
|
final existingData = functions[existingIndex];
|
||||||
functions[existingIndex] = event.functionData;
|
functions[existingIndex] = DeviceFunctionData(
|
||||||
|
entityId: event.functionData.entityId,
|
||||||
|
functionCode: event.functionData.functionCode,
|
||||||
|
operationName: event.functionData.operationName,
|
||||||
|
value: event.functionData.value ?? existingData.value,
|
||||||
|
valueDescription: event.functionData.valueDescription ??
|
||||||
|
existingData.valueDescription,
|
||||||
|
condition: event.functionData.condition ?? existingData.condition,
|
||||||
|
step: event.functionData.step ?? existingData.step,
|
||||||
|
);
|
||||||
} else {
|
} else {
|
||||||
// Add new function value
|
functions.clear();
|
||||||
functions.add(event.functionData);
|
functions.add(event.functionData);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -4,8 +4,8 @@ import 'package:bloc/bloc.dart';
|
|||||||
import 'package:dio/dio.dart';
|
import 'package:dio/dio.dart';
|
||||||
import 'package:equatable/equatable.dart';
|
import 'package:equatable/equatable.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
|
||||||
import 'package:syncrow_web/pages/common/bloc/project_manager.dart';
|
import 'package:syncrow_web/pages/common/bloc/project_manager.dart';
|
||||||
|
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||||
import 'package:syncrow_web/pages/device_managment/all_devices/models/devices_model.dart';
|
import 'package:syncrow_web/pages/device_managment/all_devices/models/devices_model.dart';
|
||||||
import 'package:syncrow_web/pages/routines/bloc/automation_scene_trigger_bloc/automation_status_update.dart';
|
import 'package:syncrow_web/pages/routines/bloc/automation_scene_trigger_bloc/automation_status_update.dart';
|
||||||
import 'package:syncrow_web/pages/routines/bloc/create_routine_bloc/create_routine_bloc.dart';
|
import 'package:syncrow_web/pages/routines/bloc/create_routine_bloc/create_routine_bloc.dart';
|
||||||
@@ -27,6 +27,9 @@ import 'package:uuid/uuid.dart';
|
|||||||
part 'routine_event.dart';
|
part 'routine_event.dart';
|
||||||
part 'routine_state.dart';
|
part 'routine_state.dart';
|
||||||
|
|
||||||
|
// String spaceId = '25c96044-fadf-44bb-93c7-3c079e527ce6';
|
||||||
|
// String communityId = 'aff21a57-2f91-4e5c-b99b-0182c3ab65a9';
|
||||||
|
|
||||||
class RoutineBloc extends Bloc<RoutineEvent, RoutineState> {
|
class RoutineBloc extends Bloc<RoutineEvent, RoutineState> {
|
||||||
RoutineBloc() : super(const RoutineState()) {
|
RoutineBloc() : super(const RoutineState()) {
|
||||||
on<AddToIfContainer>(_onAddToIfContainer);
|
on<AddToIfContainer>(_onAddToIfContainer);
|
||||||
@@ -170,45 +173,45 @@ class RoutineBloc extends Bloc<RoutineEvent, RoutineState> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> _onLoadScenes(
|
Future<void> _onLoadScenes(
|
||||||
LoadScenes event, Emitter<RoutineState> emit) async {
|
LoadScenes event, Emitter<RoutineState> emit) async {
|
||||||
emit(state.copyWith(isLoading: true, errorMessage: null));
|
emit(state.copyWith(isLoading: true, errorMessage: null));
|
||||||
List<ScenesModel> scenes = [];
|
List<ScenesModel> scenes = [];
|
||||||
try {
|
try {
|
||||||
BuildContext context = NavigationService.navigatorKey.currentContext!;
|
BuildContext context = NavigationService.navigatorKey.currentContext!;
|
||||||
var createRoutineBloc = context.read<CreateRoutineBloc>();
|
var createRoutineBloc = context.read<CreateRoutineBloc>();
|
||||||
final projectUuid = await ProjectManager.getProjectUUID() ?? '';
|
final projectUuid = await ProjectManager.getProjectUUID() ?? '';
|
||||||
if (createRoutineBloc.selectedSpaceId == '' &&
|
if (createRoutineBloc.selectedSpaceId == '' &&
|
||||||
createRoutineBloc.selectedCommunityId == '') {
|
createRoutineBloc.selectedCommunityId == '') {
|
||||||
var spaceBloc = context.read<SpaceTreeBloc>();
|
var spaceBloc = context.read<SpaceTreeBloc>();
|
||||||
for (var communityId in spaceBloc.state.selectedCommunities) {
|
for (var communityId in spaceBloc.state.selectedCommunities) {
|
||||||
List<String> spacesList =
|
List<String> spacesList =
|
||||||
spaceBloc.state.selectedCommunityAndSpaces[communityId] ?? [];
|
spaceBloc.state.selectedCommunityAndSpaces[communityId] ?? [];
|
||||||
for (var spaceId in spacesList) {
|
for (var spaceId in spacesList) {
|
||||||
scenes.addAll(
|
scenes.addAll(
|
||||||
await SceneApi.getScenes(spaceId, communityId, projectUuid));
|
await SceneApi.getScenes(spaceId, communityId, projectUuid));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
scenes.addAll(await SceneApi.getScenes(
|
||||||
|
createRoutineBloc.selectedSpaceId,
|
||||||
|
createRoutineBloc.selectedCommunityId,
|
||||||
|
projectUuid));
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
scenes.addAll(await SceneApi.getScenes(
|
|
||||||
createRoutineBloc.selectedSpaceId,
|
|
||||||
createRoutineBloc.selectedCommunityId,
|
|
||||||
projectUuid));
|
|
||||||
}
|
|
||||||
|
|
||||||
emit(state.copyWith(
|
emit(state.copyWith(
|
||||||
scenes: scenes,
|
scenes: scenes,
|
||||||
isLoading: false,
|
|
||||||
));
|
|
||||||
} catch (e) {
|
|
||||||
emit(state.copyWith(
|
|
||||||
isLoading: false,
|
isLoading: false,
|
||||||
loadScenesErrorMessage: 'Failed to load scenes',
|
));
|
||||||
errorMessage: '',
|
} catch (e) {
|
||||||
loadAutomationErrorMessage: '',
|
emit(state.copyWith(
|
||||||
scenes: scenes));
|
isLoading: false,
|
||||||
|
loadScenesErrorMessage: 'Failed to load scenes',
|
||||||
|
errorMessage: '',
|
||||||
|
loadAutomationErrorMessage: '',
|
||||||
|
scenes: scenes));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
Future<void> _onLoadAutomation(
|
Future<void> _onLoadAutomation(
|
||||||
LoadAutomation event, Emitter<RoutineState> emit) async {
|
LoadAutomation event, Emitter<RoutineState> emit) async {
|
||||||
@@ -1160,8 +1163,8 @@ Future<void> _onLoadScenes(
|
|||||||
|
|
||||||
if (result['success']) {
|
if (result['success']) {
|
||||||
add(ResetRoutineState());
|
add(ResetRoutineState());
|
||||||
add(const LoadAutomation());
|
add(LoadAutomation());
|
||||||
add(const LoadScenes());
|
add(LoadScenes());
|
||||||
} else {
|
} else {
|
||||||
emit(state.copyWith(
|
emit(state.copyWith(
|
||||||
isLoading: false,
|
isLoading: false,
|
||||||
@@ -1419,17 +1422,15 @@ Future<void> _onLoadScenes(
|
|||||||
event.automationId, event.automationStatusUpdate, projectId);
|
event.automationId, event.automationStatusUpdate, projectId);
|
||||||
|
|
||||||
if (success) {
|
if (success) {
|
||||||
// await SceneApi.getAutomationByUnitId(
|
final updatedAutomations = await SceneApi.getAutomationByUnitId(
|
||||||
// event.automationStatusUpdate.spaceUuid,
|
event.automationStatusUpdate.spaceUuid,
|
||||||
// event.communityId,
|
event.communityId,
|
||||||
// projectId);
|
projectId);
|
||||||
|
|
||||||
// Remove from loading set safely
|
// Remove from loading set safely
|
||||||
|
|
||||||
final updatedLoadingIds = {...state.loadingAutomationIds!}
|
final updatedLoadingIds = {...state.loadingAutomationIds!}
|
||||||
..remove(event.automationId);
|
..remove(event.automationId);
|
||||||
final updatedAutomations = changeItemStateOnToggelingSceen(
|
|
||||||
state.automations, event.automationId);
|
|
||||||
emit(state.copyWith(
|
emit(state.copyWith(
|
||||||
automations: updatedAutomations,
|
automations: updatedAutomations,
|
||||||
loadingAutomationIds: updatedLoadingIds,
|
loadingAutomationIds: updatedLoadingIds,
|
||||||
@@ -1451,24 +1452,4 @@ Future<void> _onLoadScenes(
|
|||||||
));
|
));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
List<ScenesModel> changeItemStateOnToggelingSceen(
|
|
||||||
List<ScenesModel> oldSceen, String automationId) {
|
|
||||||
return oldSceen.map((scene) {
|
|
||||||
if (scene.id == automationId) {
|
|
||||||
return ScenesModel(
|
|
||||||
id: scene.id,
|
|
||||||
sceneTuyaId: scene.sceneTuyaId,
|
|
||||||
name: scene.name,
|
|
||||||
status: scene.status == 'enable' ? 'disable' : 'enable',
|
|
||||||
type: scene.type,
|
|
||||||
spaceName: scene.spaceName,
|
|
||||||
spaceId: scene.spaceId,
|
|
||||||
communityId: scene.communityId,
|
|
||||||
icon: scene.icon,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
return scene;
|
|
||||||
}).toList();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -117,7 +117,7 @@ class _DropdownContentState extends State<_DropdownContent> {
|
|||||||
final selectedCommunity = _findCommunity(state, state.selectedSpaceId);
|
final selectedCommunity = _findCommunity(state, state.selectedSpaceId);
|
||||||
|
|
||||||
return Container(
|
return Container(
|
||||||
height: 40,
|
height: 46,
|
||||||
decoration: BoxDecoration(
|
decoration: BoxDecoration(
|
||||||
border: Border.all(color: Colors.grey.shade300),
|
border: Border.all(color: Colors.grey.shade300),
|
||||||
borderRadius: BorderRadius.circular(12),
|
borderRadius: BorderRadius.circular(12),
|
||||||
@@ -149,7 +149,7 @@ class _DropdownContentState extends State<_DropdownContent> {
|
|||||||
),
|
),
|
||||||
),
|
),
|
||||||
height: 45,
|
height: 45,
|
||||||
width: 44,
|
width: 33,
|
||||||
child: const Icon(
|
child: const Icon(
|
||||||
Icons.keyboard_arrow_down,
|
Icons.keyboard_arrow_down,
|
||||||
color: ColorsManager.textGray,
|
color: ColorsManager.textGray,
|
||||||
|
|||||||
@@ -44,156 +44,144 @@ class _CreateNewRoutinesDialogState extends State<CreateNewRoutinesDialog> {
|
|||||||
_selectedSpace = null;
|
_selectedSpace = null;
|
||||||
_selectedCommunity = _selectedId;
|
_selectedCommunity = _selectedId;
|
||||||
}
|
}
|
||||||
return Dialog(
|
return AlertDialog(
|
||||||
backgroundColor: Colors.white,
|
backgroundColor: Colors.white,
|
||||||
insetPadding: const EdgeInsets.symmetric(
|
insetPadding: EdgeInsets.zero,
|
||||||
horizontal: 20,
|
contentPadding: EdgeInsets.zero,
|
||||||
),
|
|
||||||
shape: RoundedRectangleBorder(
|
shape: RoundedRectangleBorder(
|
||||||
borderRadius: BorderRadius.circular(12)),
|
borderRadius: BorderRadius.circular(12)),
|
||||||
child: Container(
|
title: Text(
|
||||||
width: 450,
|
'Create New Routines',
|
||||||
child: Stack(
|
textAlign: TextAlign.center,
|
||||||
children: [
|
style: Theme.of(context).textTheme.bodyMedium!.copyWith(
|
||||||
Column(
|
color: ColorsManager.spaceColor,
|
||||||
mainAxisSize: MainAxisSize.min,
|
fontSize: 20,
|
||||||
children: [
|
fontWeight: FontWeight.w700,
|
||||||
const SizedBox(height: 20),
|
),
|
||||||
Text(
|
),
|
||||||
'Create New Routines',
|
content: Stack(
|
||||||
textAlign: TextAlign.center,
|
children: [
|
||||||
style:
|
Column(
|
||||||
Theme.of(context).textTheme.bodyMedium!.copyWith(
|
mainAxisSize: MainAxisSize.min,
|
||||||
color: ColorsManager.spaceColor,
|
children: [
|
||||||
fontSize: 20,
|
const Divider(),
|
||||||
fontWeight: FontWeight.w700,
|
const SizedBox(height: 20),
|
||||||
),
|
Column(
|
||||||
),
|
children: [
|
||||||
const Divider(),
|
Padding(
|
||||||
const SizedBox(height: 20),
|
padding:
|
||||||
Column(
|
const EdgeInsets.only(left: 13, right: 8),
|
||||||
children: [
|
child: Column(
|
||||||
Column(
|
children: [
|
||||||
children: [
|
SpaceTreeDropdown(
|
||||||
Padding(
|
selectedSpaceId: _selectedId,
|
||||||
padding: const EdgeInsets.only(
|
|
||||||
left: 13, right: 10),
|
|
||||||
child: Column(
|
|
||||||
children: [
|
|
||||||
SpaceTreeDropdown(
|
|
||||||
selectedSpaceId: _selectedId,
|
|
||||||
onChanged: (String? newValue) {
|
|
||||||
setState(
|
|
||||||
() => _selectedId = newValue!);
|
|
||||||
if (_selectedId != null) {
|
|
||||||
_bloc.add(
|
|
||||||
SpaceOnlyWithDevicesEvent(
|
|
||||||
_selectedId!));
|
|
||||||
}
|
|
||||||
},
|
|
||||||
),
|
|
||||||
],
|
|
||||||
)),
|
|
||||||
const SizedBox(height: 21),
|
|
||||||
Padding(
|
|
||||||
padding: const EdgeInsets.only(
|
|
||||||
left: 15, right: 20),
|
|
||||||
child: SpaceDropdown(
|
|
||||||
hintMessage: spaceHint,
|
|
||||||
spaces: spaces,
|
|
||||||
selectedValue: _selectedSpace,
|
|
||||||
onChanged: (String? newValue) {
|
onChanged: (String? newValue) {
|
||||||
setState(() {
|
setState(() => _selectedId = newValue!);
|
||||||
_selectedSpace = newValue;
|
if (_selectedId != null) {
|
||||||
});
|
_bloc.add(SpaceOnlyWithDevicesEvent(
|
||||||
|
_selectedId!));
|
||||||
|
}
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
),
|
],
|
||||||
],
|
)),
|
||||||
|
const SizedBox(height: 5),
|
||||||
|
const SizedBox(height: 8),
|
||||||
|
Padding(
|
||||||
|
padding: const EdgeInsets.only(left: 15, right: 15),
|
||||||
|
child: SpaceDropdown(
|
||||||
|
hintMessage: spaceHint,
|
||||||
|
spaces: spaces,
|
||||||
|
selectedValue: _selectedSpace,
|
||||||
|
onChanged: (String? newValue) {
|
||||||
|
setState(() {
|
||||||
|
_selectedSpace = newValue;
|
||||||
|
});
|
||||||
|
},
|
||||||
),
|
),
|
||||||
],
|
),
|
||||||
),
|
],
|
||||||
const SizedBox(height: 20),
|
|
||||||
const Divider(),
|
|
||||||
Row(
|
|
||||||
mainAxisAlignment: MainAxisAlignment.spaceAround,
|
|
||||||
children: [
|
|
||||||
Padding(
|
|
||||||
padding: const EdgeInsets.only(
|
|
||||||
left: 20,
|
|
||||||
right: 20,
|
|
||||||
),
|
|
||||||
child: TextButton(
|
|
||||||
onPressed: () {
|
|
||||||
Navigator.of(context).pop();
|
|
||||||
},
|
|
||||||
child: Text(
|
|
||||||
'Cancel',
|
|
||||||
style: Theme.of(context)
|
|
||||||
.textTheme
|
|
||||||
.bodyMedium!
|
|
||||||
.copyWith(
|
|
||||||
fontWeight: FontWeight.w400,
|
|
||||||
fontSize: 14,
|
|
||||||
color: ColorsManager.blackColor,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
Padding(
|
|
||||||
padding: const EdgeInsets.only(
|
|
||||||
left: 20,
|
|
||||||
right: 20,
|
|
||||||
),
|
|
||||||
child: TextButton(
|
|
||||||
onPressed: _selectedCommunity != null &&
|
|
||||||
_selectedSpace != null
|
|
||||||
? () {
|
|
||||||
Navigator.of(context).pop({
|
|
||||||
'community': _selectedCommunity,
|
|
||||||
'space': _selectedSpace,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
: null,
|
|
||||||
child: Text(
|
|
||||||
'Next',
|
|
||||||
style: Theme.of(context)
|
|
||||||
.textTheme
|
|
||||||
.bodyMedium!
|
|
||||||
.copyWith(
|
|
||||||
fontWeight: FontWeight.w400,
|
|
||||||
fontSize: 14,
|
|
||||||
color: _selectedCommunity != null &&
|
|
||||||
_selectedSpace != null
|
|
||||||
? ColorsManager.blueColor
|
|
||||||
: Colors.blue.shade100,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
const SizedBox(height: 10),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
if (isLoadingCommunities)
|
|
||||||
const SizedBox(
|
|
||||||
height: 200,
|
|
||||||
child: Column(
|
|
||||||
mainAxisSize: MainAxisSize.min,
|
|
||||||
mainAxisAlignment: MainAxisAlignment.center,
|
|
||||||
crossAxisAlignment: CrossAxisAlignment.center,
|
|
||||||
children: [
|
|
||||||
Center(
|
|
||||||
child: CircularProgressIndicator(
|
|
||||||
color: ColorsManager.primaryColor,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
),
|
),
|
||||||
],
|
const SizedBox(height: 20),
|
||||||
),
|
const Divider(),
|
||||||
|
Row(
|
||||||
|
mainAxisAlignment: MainAxisAlignment.spaceAround,
|
||||||
|
children: [
|
||||||
|
Padding(
|
||||||
|
padding: const EdgeInsets.only(
|
||||||
|
left: 20,
|
||||||
|
right: 20,
|
||||||
|
),
|
||||||
|
child: TextButton(
|
||||||
|
onPressed: () {
|
||||||
|
Navigator.of(context).pop();
|
||||||
|
},
|
||||||
|
child: Text(
|
||||||
|
'Cancel',
|
||||||
|
style: Theme.of(context)
|
||||||
|
.textTheme
|
||||||
|
.bodyMedium!
|
||||||
|
.copyWith(
|
||||||
|
fontWeight: FontWeight.w400,
|
||||||
|
fontSize: 14,
|
||||||
|
color: ColorsManager.blackColor,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
Padding(
|
||||||
|
padding: const EdgeInsets.only(
|
||||||
|
left: 20,
|
||||||
|
right: 20,
|
||||||
|
),
|
||||||
|
child: TextButton(
|
||||||
|
onPressed: _selectedCommunity != null &&
|
||||||
|
_selectedSpace != null
|
||||||
|
? () {
|
||||||
|
Navigator.of(context).pop({
|
||||||
|
'community': _selectedCommunity,
|
||||||
|
'space': _selectedSpace,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
: null,
|
||||||
|
child: Text(
|
||||||
|
'Next',
|
||||||
|
style: Theme.of(context)
|
||||||
|
.textTheme
|
||||||
|
.bodyMedium!
|
||||||
|
.copyWith(
|
||||||
|
fontWeight: FontWeight.w400,
|
||||||
|
fontSize: 14,
|
||||||
|
color: _selectedCommunity != null &&
|
||||||
|
_selectedSpace != null
|
||||||
|
? ColorsManager.blueColor
|
||||||
|
: Colors.blue.shade100,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
const SizedBox(height: 10),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
if (isLoadingCommunities)
|
||||||
|
const SizedBox(
|
||||||
|
height: 200,
|
||||||
|
child: Column(
|
||||||
|
mainAxisSize: MainAxisSize.min,
|
||||||
|
mainAxisAlignment: MainAxisAlignment.center,
|
||||||
|
crossAxisAlignment: CrossAxisAlignment.center,
|
||||||
|
children: [
|
||||||
|
Center(
|
||||||
|
child: CircularProgressIndicator(
|
||||||
|
color: ColorsManager.primaryColor,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -34,9 +34,7 @@ class SpaceDropdown extends StatelessWidget {
|
|||||||
),
|
),
|
||||||
SizedBox(
|
SizedBox(
|
||||||
child: Container(
|
child: Container(
|
||||||
height: 40,
|
|
||||||
decoration: BoxDecoration(
|
decoration: BoxDecoration(
|
||||||
color: ColorsManager.whiteColors,
|
|
||||||
borderRadius: BorderRadius.circular(10),
|
borderRadius: BorderRadius.circular(10),
|
||||||
),
|
),
|
||||||
child: DropdownButton2<String>(
|
child: DropdownButton2<String>(
|
||||||
@@ -47,7 +45,7 @@ class SpaceDropdown extends StatelessWidget {
|
|||||||
value: space.uuid,
|
value: space.uuid,
|
||||||
child: Column(
|
child: Column(
|
||||||
crossAxisAlignment: CrossAxisAlignment.start,
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
mainAxisAlignment: MainAxisAlignment.center,
|
mainAxisAlignment: MainAxisAlignment.start,
|
||||||
children: [
|
children: [
|
||||||
Text(
|
Text(
|
||||||
' ${space.name}',
|
' ${space.name}',
|
||||||
@@ -90,7 +88,7 @@ class SpaceDropdown extends StatelessWidget {
|
|||||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||||
children: [
|
children: [
|
||||||
Expanded(
|
Expanded(
|
||||||
flex: 8,
|
flex: 6,
|
||||||
child: Padding(
|
child: Padding(
|
||||||
padding: const EdgeInsets.only(left: 10),
|
padding: const EdgeInsets.only(left: 10),
|
||||||
child: Text(
|
child: Text(
|
||||||
@@ -131,7 +129,6 @@ class SpaceDropdown extends StatelessWidget {
|
|||||||
dropdownStyleData: DropdownStyleData(
|
dropdownStyleData: DropdownStyleData(
|
||||||
maxHeight: MediaQuery.of(context).size.height * 0.4,
|
maxHeight: MediaQuery.of(context).size.height * 0.4,
|
||||||
decoration: BoxDecoration(
|
decoration: BoxDecoration(
|
||||||
color: ColorsManager.whiteColors,
|
|
||||||
borderRadius: BorderRadius.circular(10),
|
borderRadius: BorderRadius.circular(10),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
|||||||
@@ -17,10 +17,9 @@ class SaveRoutineHelper {
|
|||||||
builder: (context) {
|
builder: (context) {
|
||||||
return BlocBuilder<RoutineBloc, RoutineState>(
|
return BlocBuilder<RoutineBloc, RoutineState>(
|
||||||
builder: (context, state) {
|
builder: (context, state) {
|
||||||
final selectedConditionLabel =
|
final selectedConditionLabel = state.selectedAutomationOperator == 'and'
|
||||||
state.selectedAutomationOperator == 'and'
|
? 'All Conditions are met'
|
||||||
? 'All Conditions are met'
|
: 'Any Condition is met';
|
||||||
: 'Any Condition is met';
|
|
||||||
|
|
||||||
return AlertDialog(
|
return AlertDialog(
|
||||||
contentPadding: EdgeInsets.zero,
|
contentPadding: EdgeInsets.zero,
|
||||||
@@ -38,11 +37,10 @@ class SaveRoutineHelper {
|
|||||||
Text(
|
Text(
|
||||||
'Create a scene: ${state.routineName ?? ""}',
|
'Create a scene: ${state.routineName ?? ""}',
|
||||||
textAlign: TextAlign.center,
|
textAlign: TextAlign.center,
|
||||||
style:
|
style: Theme.of(context).textTheme.headlineMedium!.copyWith(
|
||||||
Theme.of(context).textTheme.headlineMedium!.copyWith(
|
color: ColorsManager.primaryColorWithOpacity,
|
||||||
color: ColorsManager.primaryColorWithOpacity,
|
fontWeight: FontWeight.bold,
|
||||||
fontWeight: FontWeight.bold,
|
),
|
||||||
),
|
|
||||||
),
|
),
|
||||||
const SizedBox(height: 18),
|
const SizedBox(height: 18),
|
||||||
_buildDivider(),
|
_buildDivider(),
|
||||||
@@ -60,8 +58,7 @@ class SaveRoutineHelper {
|
|||||||
_buildIfConditions(state, context),
|
_buildIfConditions(state, context),
|
||||||
Container(
|
Container(
|
||||||
width: 1,
|
width: 1,
|
||||||
color: ColorsManager.greyColor
|
color: ColorsManager.greyColor.withValues(alpha: 0.8),
|
||||||
.withValues(alpha: 0.8),
|
|
||||||
),
|
),
|
||||||
_buildThenActions(state, context),
|
_buildThenActions(state, context),
|
||||||
],
|
],
|
||||||
@@ -100,8 +97,7 @@ class SaveRoutineHelper {
|
|||||||
child: Row(
|
child: Row(
|
||||||
spacing: 16,
|
spacing: 16,
|
||||||
children: [
|
children: [
|
||||||
Expanded(
|
Expanded(child: Text('IF: $selectedConditionLabel', style: textStyle)),
|
||||||
child: Text('IF: $selectedConditionLabel', style: textStyle)),
|
|
||||||
const Expanded(child: Text('THEN:', style: textStyle)),
|
const Expanded(child: Text('THEN:', style: textStyle)),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
@@ -113,7 +109,7 @@ class SaveRoutineHelper {
|
|||||||
spacing: 16,
|
spacing: 16,
|
||||||
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
|
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
|
||||||
children: [
|
children: [
|
||||||
DialogFooterButton(
|
DialogFooterButton(
|
||||||
text: 'Back',
|
text: 'Back',
|
||||||
onTap: () => Navigator.pop(context),
|
onTap: () => Navigator.pop(context),
|
||||||
),
|
),
|
||||||
@@ -147,8 +143,7 @@ class SaveRoutineHelper {
|
|||||||
child: ListView(
|
child: ListView(
|
||||||
// shrinkWrap: true,
|
// shrinkWrap: true,
|
||||||
children: state.thenItems.map((item) {
|
children: state.thenItems.map((item) {
|
||||||
final functions =
|
final functions = state.selectedFunctions[item['uniqueCustomId']] ?? [];
|
||||||
state.selectedFunctions[item['uniqueCustomId']] ?? [];
|
|
||||||
return functionRow(item, context, functions);
|
return functionRow(item, context, functions);
|
||||||
}).toList(),
|
}).toList(),
|
||||||
),
|
),
|
||||||
@@ -208,20 +203,19 @@ class SaveRoutineHelper {
|
|||||||
),
|
),
|
||||||
),
|
),
|
||||||
child: Center(
|
child: Center(
|
||||||
child:
|
child: item['type'] == 'tap_to_run' || item['type'] == 'scene'
|
||||||
item['type'] == 'tap_to_run' || item['type'] == 'scene'
|
? Image.memory(
|
||||||
? Image.memory(
|
base64Decode(item['icon']),
|
||||||
base64Decode(item['icon']),
|
width: 12,
|
||||||
width: 12,
|
height: 22,
|
||||||
height: 22,
|
fit: BoxFit.scaleDown,
|
||||||
fit: BoxFit.scaleDown,
|
)
|
||||||
)
|
: SvgPicture.asset(
|
||||||
: SvgPicture.asset(
|
item['imagePath'],
|
||||||
item['imagePath'],
|
width: 12,
|
||||||
width: 12,
|
height: 12,
|
||||||
height: 12,
|
fit: BoxFit.scaleDown,
|
||||||
fit: BoxFit.scaleDown,
|
),
|
||||||
),
|
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
Flexible(
|
Flexible(
|
||||||
|
|||||||
@@ -405,8 +405,8 @@ class PowerFactorCStatusFunction extends EnergyClampFunctions {
|
|||||||
code: 'PowerFactorC',
|
code: 'PowerFactorC',
|
||||||
operationName: 'Power Factor C',
|
operationName: 'Power Factor C',
|
||||||
icon: Assets.speedoMeter,
|
icon: Assets.speedoMeter,
|
||||||
min: 0.0,
|
min: 0.00,
|
||||||
max: 1.0,
|
max: 1.00,
|
||||||
step: 0.1,
|
step: 0.1,
|
||||||
unit: "",
|
unit: "",
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -117,22 +117,10 @@ class ACHelper {
|
|||||||
},
|
},
|
||||||
onConfirm: state.addedFunctions.isNotEmpty
|
onConfirm: state.addedFunctions.isNotEmpty
|
||||||
? () {
|
? () {
|
||||||
final selectedFunctionData =
|
|
||||||
state.addedFunctions.firstWhere(
|
|
||||||
(f) =>
|
|
||||||
f.functionCode == state.selectedFunction,
|
|
||||||
orElse: () => DeviceFunctionData(
|
|
||||||
entityId: '',
|
|
||||||
functionCode: state.selectedFunction ?? '',
|
|
||||||
operationName: '',
|
|
||||||
value: null,
|
|
||||||
),
|
|
||||||
);
|
|
||||||
|
|
||||||
/// add the functions to the routine bloc
|
/// add the functions to the routine bloc
|
||||||
context.read<RoutineBloc>().add(
|
context.read<RoutineBloc>().add(
|
||||||
AddFunctionToRoutine(
|
AddFunctionToRoutine(
|
||||||
[selectedFunctionData],
|
state.addedFunctions,
|
||||||
uniqueCustomId,
|
uniqueCustomId,
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
|||||||
+1
-11
@@ -78,22 +78,12 @@ class _CeilingSensorDialogState extends State<CeilingSensorDialog> {
|
|||||||
onCancel: () => Navigator.pop(context),
|
onCancel: () => Navigator.pop(context),
|
||||||
onConfirm: state.addedFunctions.isNotEmpty
|
onConfirm: state.addedFunctions.isNotEmpty
|
||||||
? () {
|
? () {
|
||||||
final selectedFunctionData =
|
|
||||||
state.addedFunctions.firstWhere(
|
|
||||||
(f) => f.functionCode == state.selectedFunction,
|
|
||||||
orElse: () => DeviceFunctionData(
|
|
||||||
entityId: '',
|
|
||||||
functionCode: state.selectedFunction ?? '',
|
|
||||||
operationName: '',
|
|
||||||
value: null,
|
|
||||||
),
|
|
||||||
);
|
|
||||||
final functions = _updateValuesForAddedFunctions(
|
final functions = _updateValuesForAddedFunctions(
|
||||||
state.addedFunctions,
|
state.addedFunctions,
|
||||||
);
|
);
|
||||||
context.read<RoutineBloc>().add(
|
context.read<RoutineBloc>().add(
|
||||||
AddFunctionToRoutine(
|
AddFunctionToRoutine(
|
||||||
[selectedFunctionData],
|
functions,
|
||||||
'${widget.uniqueCustomId}',
|
'${widget.uniqueCustomId}',
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
|||||||
+1
-10
@@ -192,18 +192,9 @@ class _WallPresenceSensorState extends State<FlushPresenceSensor> {
|
|||||||
onCancel: () => Navigator.pop(context),
|
onCancel: () => Navigator.pop(context),
|
||||||
onConfirm: state.addedFunctions.isNotEmpty
|
onConfirm: state.addedFunctions.isNotEmpty
|
||||||
? () {
|
? () {
|
||||||
final selectedFunctionData = state.addedFunctions.firstWhere(
|
|
||||||
(f) => f.functionCode == state.selectedFunction,
|
|
||||||
orElse: () => DeviceFunctionData(
|
|
||||||
entityId: '',
|
|
||||||
functionCode: state.selectedFunction ?? '',
|
|
||||||
operationName: '',
|
|
||||||
value: null,
|
|
||||||
),
|
|
||||||
);
|
|
||||||
context.read<RoutineBloc>().add(
|
context.read<RoutineBloc>().add(
|
||||||
AddFunctionToRoutine(
|
AddFunctionToRoutine(
|
||||||
[selectedFunctionData],
|
state.addedFunctions,
|
||||||
widget.uniqueCustomId!,
|
widget.uniqueCustomId!,
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -115,18 +115,9 @@ class _GatewayDialogState extends State<GatewayDialog> {
|
|||||||
onCancel: () => Navigator.pop(context),
|
onCancel: () => Navigator.pop(context),
|
||||||
onConfirm: state.addedFunctions.isNotEmpty
|
onConfirm: state.addedFunctions.isNotEmpty
|
||||||
? () {
|
? () {
|
||||||
final selectedFunctionData = state.addedFunctions.firstWhere(
|
|
||||||
(f) => f.functionCode == state.selectedFunction,
|
|
||||||
orElse: () => DeviceFunctionData(
|
|
||||||
entityId: '',
|
|
||||||
functionCode: state.selectedFunction ?? '',
|
|
||||||
operationName: '',
|
|
||||||
value: null,
|
|
||||||
),
|
|
||||||
);
|
|
||||||
context.read<RoutineBloc>().add(
|
context.read<RoutineBloc>().add(
|
||||||
AddFunctionToRoutine(
|
AddFunctionToRoutine(
|
||||||
[selectedFunctionData],
|
state.addedFunctions,
|
||||||
widget.uniqueCustomId ?? '-1',
|
widget.uniqueCustomId ?? '-1',
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -147,7 +147,7 @@ class OneGangSwitchHelper {
|
|||||||
// }
|
// }
|
||||||
context.read<RoutineBloc>().add(
|
context.read<RoutineBloc>().add(
|
||||||
AddFunctionToRoutine(
|
AddFunctionToRoutine(
|
||||||
[selectedFunctionData],
|
state.addedFunctions,
|
||||||
uniqueCustomId,
|
uniqueCustomId,
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
|||||||
+1
-10
@@ -250,18 +250,9 @@ class _EnergyClampDialogState extends State<EnergyClampDialog> {
|
|||||||
onCancel: () => Navigator.pop(context),
|
onCancel: () => Navigator.pop(context),
|
||||||
onConfirm: state.addedFunctions.isNotEmpty
|
onConfirm: state.addedFunctions.isNotEmpty
|
||||||
? () {
|
? () {
|
||||||
final selectedFunctionData = state.addedFunctions.firstWhere(
|
|
||||||
(f) => f.functionCode == state.selectedFunction,
|
|
||||||
orElse: () => DeviceFunctionData(
|
|
||||||
entityId: '',
|
|
||||||
functionCode: state.selectedFunction ?? '',
|
|
||||||
operationName: '',
|
|
||||||
value: null,
|
|
||||||
),
|
|
||||||
);
|
|
||||||
context.read<RoutineBloc>().add(
|
context.read<RoutineBloc>().add(
|
||||||
AddFunctionToRoutine(
|
AddFunctionToRoutine(
|
||||||
[selectedFunctionData],
|
state.addedFunctions,
|
||||||
widget.uniqueCustomId!,
|
widget.uniqueCustomId!,
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
|||||||
+6
-5
@@ -27,16 +27,17 @@ class EnergyValueSelectorWidget extends StatelessWidget {
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
final selectedFn = functions.firstWhere((f) => f.code == selectedFunction);
|
final selectedFn =
|
||||||
|
functions.firstWhere((f) => f.code == selectedFunction);
|
||||||
final values = selectedFn.getOperationalValues();
|
final values = selectedFn.getOperationalValues();
|
||||||
final step = selectedFn.step;
|
final step = selectedFn.step ?? 1.0;
|
||||||
final _unit = selectedFn.unit ?? '';
|
final _unit = selectedFn.unit ?? '';
|
||||||
final (double, double) sliderRange =
|
final (double, double) sliderRange =
|
||||||
(selectedFn.min ?? 0.0, selectedFn.max ?? 100.0);
|
(selectedFn.min ?? 0.0, selectedFn.max ?? 100.0);
|
||||||
|
|
||||||
if (_isSliderFunction(selectedFunction)) {
|
if (_isSliderFunction(selectedFunction)) {
|
||||||
return CustomRoutinesTextbox(
|
return CustomRoutinesTextbox(
|
||||||
withSpecialChar: true,
|
withSpecialChar: false,
|
||||||
currentCondition: functionData.condition,
|
currentCondition: functionData.condition,
|
||||||
dialogType: dialogType,
|
dialogType: dialogType,
|
||||||
sliderRange: sliderRange,
|
sliderRange: sliderRange,
|
||||||
@@ -59,14 +60,14 @@ class EnergyValueSelectorWidget extends StatelessWidget {
|
|||||||
entityId: device?.uuid ?? '',
|
entityId: device?.uuid ?? '',
|
||||||
functionCode: selectedFunction,
|
functionCode: selectedFunction,
|
||||||
operationName: functionData.operationName,
|
operationName: functionData.operationName,
|
||||||
value: value,
|
value: value.toInt(),
|
||||||
condition: functionData.condition,
|
condition: functionData.condition,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
unit: _unit,
|
unit: _unit,
|
||||||
dividendOfRange: 1,
|
dividendOfRange: 1,
|
||||||
stepIncreaseAmount: step!,
|
stepIncreaseAmount: step,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -145,22 +145,9 @@ class TwoGangSwitchHelper {
|
|||||||
// ),
|
// ),
|
||||||
// );
|
// );
|
||||||
// }
|
// }
|
||||||
final selectedFunctionData =
|
|
||||||
state.addedFunctions.firstWhere(
|
|
||||||
(f) =>
|
|
||||||
f.functionCode ==
|
|
||||||
state.selectedFunction,
|
|
||||||
orElse: () => DeviceFunctionData(
|
|
||||||
entityId: '',
|
|
||||||
functionCode:
|
|
||||||
state.selectedFunction ?? '',
|
|
||||||
operationName: '',
|
|
||||||
value: null,
|
|
||||||
),
|
|
||||||
);
|
|
||||||
context.read<RoutineBloc>().add(
|
context.read<RoutineBloc>().add(
|
||||||
AddFunctionToRoutine(
|
AddFunctionToRoutine(
|
||||||
[selectedFunctionData],
|
state.addedFunctions,
|
||||||
uniqueCustomId,
|
uniqueCustomId,
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -210,18 +210,9 @@ class _WallPresenceSensorState extends State<WallPresenceSensor> {
|
|||||||
onCancel: () => Navigator.pop(context),
|
onCancel: () => Navigator.pop(context),
|
||||||
onConfirm: state.addedFunctions.isNotEmpty
|
onConfirm: state.addedFunctions.isNotEmpty
|
||||||
? () {
|
? () {
|
||||||
final selectedFunctionData = state.addedFunctions.firstWhere(
|
|
||||||
(f) => f.functionCode == state.selectedFunction,
|
|
||||||
orElse: () => DeviceFunctionData(
|
|
||||||
entityId: '',
|
|
||||||
functionCode: state.selectedFunction ?? '',
|
|
||||||
operationName: '',
|
|
||||||
value: null,
|
|
||||||
),
|
|
||||||
);
|
|
||||||
context.read<RoutineBloc>().add(
|
context.read<RoutineBloc>().add(
|
||||||
AddFunctionToRoutine(
|
AddFunctionToRoutine(
|
||||||
[selectedFunctionData],
|
state.addedFunctions,
|
||||||
widget.uniqueCustomId!,
|
widget.uniqueCustomId!,
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
|||||||
+1
-10
@@ -188,18 +188,9 @@ class _WaterHeaterDialogRoutinesState extends State<WaterHeaterDialogRoutines> {
|
|||||||
onCancel: () => Navigator.pop(context),
|
onCancel: () => Navigator.pop(context),
|
||||||
onConfirm: state.addedFunctions.isNotEmpty
|
onConfirm: state.addedFunctions.isNotEmpty
|
||||||
? () {
|
? () {
|
||||||
final selectedFunctionData = state.addedFunctions.firstWhere(
|
|
||||||
(f) => f.functionCode == state.selectedFunction,
|
|
||||||
orElse: () => DeviceFunctionData(
|
|
||||||
entityId: '',
|
|
||||||
functionCode: state.selectedFunction ?? '',
|
|
||||||
operationName: '',
|
|
||||||
value: null,
|
|
||||||
),
|
|
||||||
);
|
|
||||||
context.read<RoutineBloc>().add(
|
context.read<RoutineBloc>().add(
|
||||||
AddFunctionToRoutine(
|
AddFunctionToRoutine(
|
||||||
[selectedFunctionData],
|
state.addedFunctions,
|
||||||
widget.uniqueCustomId!,
|
widget.uniqueCustomId!,
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
|||||||
-34
@@ -1,34 +0,0 @@
|
|||||||
import 'package:dio/dio.dart';
|
|
||||||
import 'package:syncrow_web/pages/space_management_v2/modules/communities/domain/models/community_model.dart';
|
|
||||||
import 'package:syncrow_web/pages/space_management_v2/modules/communities/domain/params/load_communities_param.dart';
|
|
||||||
import 'package:syncrow_web/pages/space_management_v2/modules/communities/domain/services/communities_service.dart';
|
|
||||||
import 'package:syncrow_web/services/api/api_exception.dart';
|
|
||||||
import 'package:syncrow_web/services/api/http_service.dart';
|
|
||||||
|
|
||||||
class RemoteCommunitiesService implements CommunitiesService {
|
|
||||||
const RemoteCommunitiesService(this._httpService);
|
|
||||||
|
|
||||||
final HTTPService _httpService;
|
|
||||||
|
|
||||||
static const _defaultErrorMessage = 'Failed to load communities';
|
|
||||||
|
|
||||||
@override
|
|
||||||
Future<List<CommunityModel>> getCommunity(LoadCommunitiesParam param) async {
|
|
||||||
try {
|
|
||||||
return _httpService.get(
|
|
||||||
path: '/api/communities/',
|
|
||||||
expectedResponseModel: (json) => (json as List<dynamic>)
|
|
||||||
.map((e) => CommunityModel.fromJson(e as Map<String, dynamic>))
|
|
||||||
.toList(),
|
|
||||||
);
|
|
||||||
} on DioException catch (e) {
|
|
||||||
final message = e.response?.data as Map<String, dynamic>?;
|
|
||||||
final error = message?['error'] as Map<String, dynamic>?;
|
|
||||||
final errorMessage = error?['error'] as String? ?? '';
|
|
||||||
throw APIException(errorMessage);
|
|
||||||
} catch (e) {
|
|
||||||
final formattedErrorMessage = [_defaultErrorMessage, '$e'].join(': ');
|
|
||||||
throw APIException(formattedErrorMessage);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,27 +0,0 @@
|
|||||||
import 'package:equatable/equatable.dart';
|
|
||||||
import 'package:syncrow_web/pages/space_management_v2/modules/communities/domain/models/space_model.dart';
|
|
||||||
|
|
||||||
class CommunityModel extends Equatable {
|
|
||||||
final String uuid;
|
|
||||||
final String name;
|
|
||||||
final List<SpaceModel> spaces;
|
|
||||||
|
|
||||||
const CommunityModel({
|
|
||||||
required this.uuid,
|
|
||||||
required this.name,
|
|
||||||
required this.spaces,
|
|
||||||
});
|
|
||||||
|
|
||||||
factory CommunityModel.fromJson(Map<String, dynamic> json) {
|
|
||||||
return CommunityModel(
|
|
||||||
uuid: json['uuid'] as String,
|
|
||||||
name: json['name'] as String,
|
|
||||||
spaces: (json['spaces'] as List<dynamic>)
|
|
||||||
.map((e) => SpaceModel.fromJson(e as Map<String, dynamic>))
|
|
||||||
.toList(),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
|
||||||
List<Object?> get props => [uuid, name, spaces];
|
|
||||||
}
|
|
||||||
@@ -1,30 +0,0 @@
|
|||||||
import 'package:equatable/equatable.dart';
|
|
||||||
|
|
||||||
class SpaceModel extends Equatable {
|
|
||||||
final String uuid;
|
|
||||||
final String spaceName;
|
|
||||||
final String icon;
|
|
||||||
final List<SpaceModel> children;
|
|
||||||
|
|
||||||
const SpaceModel({
|
|
||||||
required this.uuid,
|
|
||||||
required this.spaceName,
|
|
||||||
required this.icon,
|
|
||||||
required this.children,
|
|
||||||
});
|
|
||||||
|
|
||||||
factory SpaceModel.fromJson(Map<String, dynamic> json) {
|
|
||||||
return SpaceModel(
|
|
||||||
uuid: json['uuid'] as String,
|
|
||||||
spaceName: json['spaceName'] as String,
|
|
||||||
icon: json['icon'] as String,
|
|
||||||
children: (json['children'] as List<dynamic>?)
|
|
||||||
?.map((e) => SpaceModel.fromJson(e as Map<String, dynamic>))
|
|
||||||
.toList() ??
|
|
||||||
[],
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
|
||||||
List<Object?> get props => [uuid, spaceName, icon, children];
|
|
||||||
}
|
|
||||||
-3
@@ -1,3 +0,0 @@
|
|||||||
class LoadCommunitiesParam {
|
|
||||||
const LoadCommunitiesParam();
|
|
||||||
}
|
|
||||||
-6
@@ -1,6 +0,0 @@
|
|||||||
import 'package:syncrow_web/pages/space_management_v2/modules/communities/domain/models/community_model.dart';
|
|
||||||
import 'package:syncrow_web/pages/space_management_v2/modules/communities/domain/params/load_communities_param.dart';
|
|
||||||
|
|
||||||
abstract class CommunitiesService {
|
|
||||||
Future<List<CommunityModel>> getCommunity(LoadCommunitiesParam param);
|
|
||||||
}
|
|
||||||
-50
@@ -1,50 +0,0 @@
|
|||||||
import 'package:equatable/equatable.dart';
|
|
||||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
|
||||||
import 'package:syncrow_web/pages/space_management_v2/modules/communities/domain/models/community_model.dart';
|
|
||||||
import 'package:syncrow_web/pages/space_management_v2/modules/communities/domain/params/load_communities_param.dart';
|
|
||||||
import 'package:syncrow_web/pages/space_management_v2/modules/communities/domain/services/communities_service.dart';
|
|
||||||
import 'package:syncrow_web/services/api/api_exception.dart';
|
|
||||||
|
|
||||||
part 'communities_event.dart';
|
|
||||||
part 'communities_state.dart';
|
|
||||||
|
|
||||||
class CommunitiesBloc extends Bloc<CommunitiesEvent, CommunitiesState> {
|
|
||||||
CommunitiesBloc({
|
|
||||||
required CommunitiesService communitiesService,
|
|
||||||
}) : _communitiesService = communitiesService,
|
|
||||||
super(const CommunitiesState()) {
|
|
||||||
on<LoadCommunities>(_onLoadCommunities);
|
|
||||||
}
|
|
||||||
|
|
||||||
final CommunitiesService _communitiesService;
|
|
||||||
|
|
||||||
Future<void> _onLoadCommunities(
|
|
||||||
LoadCommunities event,
|
|
||||||
Emitter<CommunitiesState> emit,
|
|
||||||
) async {
|
|
||||||
try {
|
|
||||||
emit(const CommunitiesState(status: CommunitiesStatus.loading));
|
|
||||||
final communities = await _communitiesService.getCommunity(event.param);
|
|
||||||
emit(
|
|
||||||
CommunitiesState(
|
|
||||||
status: CommunitiesStatus.success,
|
|
||||||
communities: communities,
|
|
||||||
),
|
|
||||||
);
|
|
||||||
} on APIException catch (e) {
|
|
||||||
emit(
|
|
||||||
CommunitiesState(
|
|
||||||
status: CommunitiesStatus.failure,
|
|
||||||
errorMessage: e.message,
|
|
||||||
),
|
|
||||||
);
|
|
||||||
} catch (e) {
|
|
||||||
emit(
|
|
||||||
CommunitiesState(
|
|
||||||
status: CommunitiesStatus.failure,
|
|
||||||
errorMessage: e.toString(),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
-17
@@ -1,17 +0,0 @@
|
|||||||
part of 'communities_bloc.dart';
|
|
||||||
|
|
||||||
sealed class CommunitiesEvent extends Equatable {
|
|
||||||
const CommunitiesEvent();
|
|
||||||
|
|
||||||
@override
|
|
||||||
List<Object?> get props => [];
|
|
||||||
}
|
|
||||||
|
|
||||||
class LoadCommunities extends CommunitiesEvent {
|
|
||||||
const LoadCommunities(this.param);
|
|
||||||
|
|
||||||
final LoadCommunitiesParam param;
|
|
||||||
|
|
||||||
@override
|
|
||||||
List<Object?> get props => [param];
|
|
||||||
}
|
|
||||||
-18
@@ -1,18 +0,0 @@
|
|||||||
part of 'communities_bloc.dart';
|
|
||||||
|
|
||||||
enum CommunitiesStatus { initial, loading, success, failure }
|
|
||||||
|
|
||||||
final class CommunitiesState extends Equatable {
|
|
||||||
const CommunitiesState({
|
|
||||||
this.status = CommunitiesStatus.initial,
|
|
||||||
this.communities = const [],
|
|
||||||
this.errorMessage,
|
|
||||||
});
|
|
||||||
|
|
||||||
final CommunitiesStatus status;
|
|
||||||
final List<CommunityModel> communities;
|
|
||||||
final String? errorMessage;
|
|
||||||
|
|
||||||
@override
|
|
||||||
List<Object?> get props => [status, communities, errorMessage];
|
|
||||||
}
|
|
||||||
-39
@@ -1,39 +0,0 @@
|
|||||||
import 'package:dio/dio.dart';
|
|
||||||
import 'package:syncrow_web/pages/space_management_v2/modules/communities/domain/models/community_model.dart';
|
|
||||||
import 'package:syncrow_web/pages/space_management_v2/modules/create_community/domain/param/create_community_param.dart';
|
|
||||||
import 'package:syncrow_web/pages/space_management_v2/modules/create_community/domain/services/create_community_service.dart';
|
|
||||||
import 'package:syncrow_web/services/api/api_exception.dart';
|
|
||||||
import 'package:syncrow_web/services/api/http_service.dart';
|
|
||||||
|
|
||||||
class RemoteCreateCommunityService implements CreateCommunityService {
|
|
||||||
const RemoteCreateCommunityService(this._httpService);
|
|
||||||
|
|
||||||
final HTTPService _httpService;
|
|
||||||
|
|
||||||
static const _defaultErrorMessage = 'Failed to create community';
|
|
||||||
|
|
||||||
@override
|
|
||||||
Future<CommunityModel> createCommunity(CreateCommunityParam param) async {
|
|
||||||
try {
|
|
||||||
final response = await _httpService.post(
|
|
||||||
path: 'endpoint',
|
|
||||||
expectedResponseModel: (data) => CommunityModel.fromJson(
|
|
||||||
data as Map<String, dynamic>,
|
|
||||||
),
|
|
||||||
);
|
|
||||||
return response;
|
|
||||||
} on DioException catch (e) {
|
|
||||||
final message = e.response?.data as Map<String, dynamic>?;
|
|
||||||
final error = message?['error'] as Map<String, dynamic>?;
|
|
||||||
final errorMessage = error?['error'] as String? ?? '';
|
|
||||||
final formattedErrorMessage = [
|
|
||||||
_defaultErrorMessage,
|
|
||||||
errorMessage,
|
|
||||||
].join(': ');
|
|
||||||
throw APIException(formattedErrorMessage);
|
|
||||||
} catch (e) {
|
|
||||||
final formattedErrorMessage = [_defaultErrorMessage, '$e'].join(': ');
|
|
||||||
throw APIException(formattedErrorMessage);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
-10
@@ -1,10 +0,0 @@
|
|||||||
import 'package:equatable/equatable.dart';
|
|
||||||
|
|
||||||
class CreateCommunityParam extends Equatable {
|
|
||||||
const CreateCommunityParam({required this.name});
|
|
||||||
|
|
||||||
final String name;
|
|
||||||
|
|
||||||
@override
|
|
||||||
List<Object> get props => [name];
|
|
||||||
}
|
|
||||||
-6
@@ -1,6 +0,0 @@
|
|||||||
import 'package:syncrow_web/pages/space_management_v2/modules/communities/domain/models/community_model.dart';
|
|
||||||
import 'package:syncrow_web/pages/space_management_v2/modules/create_community/domain/param/create_community_param.dart';
|
|
||||||
|
|
||||||
abstract class CreateCommunityService {
|
|
||||||
Future<CommunityModel> createCommunity(CreateCommunityParam param);
|
|
||||||
}
|
|
||||||
-36
@@ -1,36 +0,0 @@
|
|||||||
import 'package:bloc/bloc.dart';
|
|
||||||
import 'package:equatable/equatable.dart';
|
|
||||||
import 'package:syncrow_web/pages/space_management_v2/modules/communities/domain/models/community_model.dart';
|
|
||||||
import 'package:syncrow_web/pages/space_management_v2/modules/create_community/domain/param/create_community_param.dart';
|
|
||||||
import 'package:syncrow_web/pages/space_management_v2/modules/create_community/domain/services/create_community_service.dart';
|
|
||||||
import 'package:syncrow_web/services/api/api_exception.dart';
|
|
||||||
|
|
||||||
part 'create_community_event.dart';
|
|
||||||
part 'create_community_state.dart';
|
|
||||||
|
|
||||||
class CreateCommunityBloc extends Bloc<CreateCommunityEvent, CreateCommunityState> {
|
|
||||||
final CreateCommunityService _createCommunityService;
|
|
||||||
|
|
||||||
CreateCommunityBloc(
|
|
||||||
this._createCommunityService,
|
|
||||||
) : super(CreateCommunityInitial()) {
|
|
||||||
on<CreateCommunity>(_onCreateCommunity);
|
|
||||||
}
|
|
||||||
|
|
||||||
Future<void> _onCreateCommunity(
|
|
||||||
CreateCommunity event,
|
|
||||||
Emitter<CreateCommunityState> emit,
|
|
||||||
) async {
|
|
||||||
emit(CreateCommunityLoading());
|
|
||||||
try {
|
|
||||||
final createdCommunity = await _createCommunityService.createCommunity(
|
|
||||||
event.param,
|
|
||||||
);
|
|
||||||
emit(CreateCommunitySuccess(createdCommunity));
|
|
||||||
} on APIException catch (e) {
|
|
||||||
emit(CreateCommunityFailure(e.message));
|
|
||||||
} catch (e) {
|
|
||||||
emit(CreateCommunityFailure(e.toString()));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
-17
@@ -1,17 +0,0 @@
|
|||||||
part of 'create_community_bloc.dart';
|
|
||||||
|
|
||||||
sealed class CreateCommunityEvent extends Equatable {
|
|
||||||
const CreateCommunityEvent();
|
|
||||||
|
|
||||||
@override
|
|
||||||
List<Object> get props => [];
|
|
||||||
}
|
|
||||||
|
|
||||||
final class CreateCommunity extends CreateCommunityEvent {
|
|
||||||
const CreateCommunity(this.param);
|
|
||||||
|
|
||||||
final CreateCommunityParam param;
|
|
||||||
|
|
||||||
@override
|
|
||||||
List<Object> get props => [param];
|
|
||||||
}
|
|
||||||
-30
@@ -1,30 +0,0 @@
|
|||||||
part of 'create_community_bloc.dart';
|
|
||||||
|
|
||||||
sealed class CreateCommunityState extends Equatable {
|
|
||||||
const CreateCommunityState();
|
|
||||||
|
|
||||||
@override
|
|
||||||
List<Object> get props => [];
|
|
||||||
}
|
|
||||||
|
|
||||||
final class CreateCommunityInitial extends CreateCommunityState {}
|
|
||||||
|
|
||||||
final class CreateCommunityLoading extends CreateCommunityState {}
|
|
||||||
|
|
||||||
final class CreateCommunitySuccess extends CreateCommunityState {
|
|
||||||
const CreateCommunitySuccess(this.community);
|
|
||||||
|
|
||||||
final CommunityModel community;
|
|
||||||
|
|
||||||
@override
|
|
||||||
List<Object> get props => [community];
|
|
||||||
}
|
|
||||||
|
|
||||||
final class CreateCommunityFailure extends CreateCommunityState {
|
|
||||||
final String message;
|
|
||||||
|
|
||||||
const CreateCommunityFailure(this.message);
|
|
||||||
|
|
||||||
@override
|
|
||||||
List<Object> get props => [message];
|
|
||||||
}
|
|
||||||
-46
@@ -1,46 +0,0 @@
|
|||||||
import 'package:dio/dio.dart';
|
|
||||||
import 'package:syncrow_web/pages/space_management_v2/modules/products/domain/models/product.dart';
|
|
||||||
import 'package:syncrow_web/pages/space_management_v2/modules/products/domain/params/load_products_param.dart';
|
|
||||||
import 'package:syncrow_web/pages/space_management_v2/modules/products/domain/services/products_service.dart';
|
|
||||||
import 'package:syncrow_web/services/api/api_exception.dart';
|
|
||||||
import 'package:syncrow_web/services/api/http_service.dart';
|
|
||||||
|
|
||||||
class RemoteProductsService implements ProductsService {
|
|
||||||
const RemoteProductsService(this._httpService);
|
|
||||||
|
|
||||||
final HTTPService _httpService;
|
|
||||||
|
|
||||||
static const _defaultErrorMessage = 'Failed to load devices';
|
|
||||||
|
|
||||||
@override
|
|
||||||
Future<List<Product>> getProducts(LoadProductsParam param) async {
|
|
||||||
try {
|
|
||||||
final response = await _httpService.get(
|
|
||||||
path: 'devices',
|
|
||||||
queryParameters: {
|
|
||||||
'spaceUuid': param.spaceUuid,
|
|
||||||
if (param.type != null) 'type': param.type,
|
|
||||||
if (param.status != null) 'status': param.status,
|
|
||||||
},
|
|
||||||
expectedResponseModel: (data) {
|
|
||||||
return (data as List)
|
|
||||||
.map((e) => Product.fromJson(e as Map<String, dynamic>))
|
|
||||||
.toList();
|
|
||||||
},
|
|
||||||
);
|
|
||||||
return response;
|
|
||||||
} on DioException catch (e) {
|
|
||||||
final message = e.response?.data as Map<String, dynamic>?;
|
|
||||||
final error = message?['error'] as Map<String, dynamic>?;
|
|
||||||
final errorMessage = error?['error'] as String? ?? '';
|
|
||||||
final formattedErrorMessage = [
|
|
||||||
_defaultErrorMessage,
|
|
||||||
errorMessage,
|
|
||||||
].join(': ');
|
|
||||||
throw APIException(formattedErrorMessage);
|
|
||||||
} catch (e) {
|
|
||||||
final formattedErrorMessage = [_defaultErrorMessage, '$e'].join(': ');
|
|
||||||
throw APIException(formattedErrorMessage);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,28 +0,0 @@
|
|||||||
import 'package:equatable/equatable.dart';
|
|
||||||
|
|
||||||
class Product extends Equatable {
|
|
||||||
final String uuid;
|
|
||||||
final String name;
|
|
||||||
|
|
||||||
const Product({
|
|
||||||
required this.uuid,
|
|
||||||
required this.name,
|
|
||||||
});
|
|
||||||
|
|
||||||
factory Product.fromJson(Map<String, dynamic> json) {
|
|
||||||
return Product(
|
|
||||||
uuid: json['uuid'] as String,
|
|
||||||
name: json['name'] as String,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
Map<String, dynamic> toJson() {
|
|
||||||
return {
|
|
||||||
'uuid': uuid,
|
|
||||||
'name': name,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
|
||||||
List<Object?> get props => [uuid, name];
|
|
||||||
}
|
|
||||||
@@ -1,11 +0,0 @@
|
|||||||
class LoadProductsParam {
|
|
||||||
final String spaceUuid;
|
|
||||||
final String? type;
|
|
||||||
final String? status;
|
|
||||||
|
|
||||||
const LoadProductsParam({
|
|
||||||
required this.spaceUuid,
|
|
||||||
this.type,
|
|
||||||
this.status,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
@@ -1,6 +0,0 @@
|
|||||||
import 'package:syncrow_web/pages/space_management_v2/modules/products/domain/models/product.dart';
|
|
||||||
import 'package:syncrow_web/pages/space_management_v2/modules/products/domain/params/load_products_param.dart';
|
|
||||||
|
|
||||||
abstract class ProductsService {
|
|
||||||
Future<List<Product>> getProducts(LoadProductsParam param);
|
|
||||||
}
|
|
||||||
@@ -1,32 +0,0 @@
|
|||||||
import 'package:bloc/bloc.dart';
|
|
||||||
import 'package:equatable/equatable.dart';
|
|
||||||
import 'package:syncrow_web/pages/space_management_v2/modules/products/domain/models/product.dart';
|
|
||||||
import 'package:syncrow_web/pages/space_management_v2/modules/products/domain/params/load_products_param.dart';
|
|
||||||
import 'package:syncrow_web/pages/space_management_v2/modules/products/domain/services/products_service.dart';
|
|
||||||
import 'package:syncrow_web/services/api/api_exception.dart';
|
|
||||||
|
|
||||||
part 'products_event.dart';
|
|
||||||
part 'products_state.dart';
|
|
||||||
|
|
||||||
class ProductsBloc extends Bloc<ProductsEvent, ProductsState> {
|
|
||||||
final ProductsService _deviceService;
|
|
||||||
|
|
||||||
ProductsBloc(this._deviceService) : super(ProductsInitial()) {
|
|
||||||
on<LoadProducts>(_onLoadProducts);
|
|
||||||
}
|
|
||||||
|
|
||||||
Future<void> _onLoadProducts(
|
|
||||||
LoadProducts event,
|
|
||||||
Emitter<ProductsState> emit,
|
|
||||||
) async {
|
|
||||||
emit(ProductsLoading());
|
|
||||||
try {
|
|
||||||
final devices = await _deviceService.getProducts(event.param);
|
|
||||||
emit(ProductsLoaded(devices));
|
|
||||||
} on APIException catch (e) {
|
|
||||||
emit(ProductsFailure(e.message));
|
|
||||||
} catch (e) {
|
|
||||||
emit(ProductsFailure(e.toString()));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,17 +0,0 @@
|
|||||||
part of 'products_bloc.dart';
|
|
||||||
|
|
||||||
sealed class ProductsEvent extends Equatable {
|
|
||||||
const ProductsEvent();
|
|
||||||
|
|
||||||
@override
|
|
||||||
List<Object> get props => [];
|
|
||||||
}
|
|
||||||
|
|
||||||
final class LoadProducts extends ProductsEvent {
|
|
||||||
const LoadProducts(this.param);
|
|
||||||
|
|
||||||
final LoadProductsParam param;
|
|
||||||
|
|
||||||
@override
|
|
||||||
List<Object> get props => [param];
|
|
||||||
}
|
|
||||||
@@ -1,30 +0,0 @@
|
|||||||
part of 'products_bloc.dart';
|
|
||||||
|
|
||||||
sealed class ProductsState extends Equatable {
|
|
||||||
const ProductsState();
|
|
||||||
|
|
||||||
@override
|
|
||||||
List<Object> get props => [];
|
|
||||||
}
|
|
||||||
|
|
||||||
final class ProductsInitial extends ProductsState {}
|
|
||||||
|
|
||||||
final class ProductsLoading extends ProductsState {}
|
|
||||||
|
|
||||||
final class ProductsLoaded extends ProductsState {
|
|
||||||
final List<Product> products;
|
|
||||||
|
|
||||||
const ProductsLoaded(this.products);
|
|
||||||
|
|
||||||
@override
|
|
||||||
List<Object> get props => [products];
|
|
||||||
}
|
|
||||||
|
|
||||||
final class ProductsFailure extends ProductsState {
|
|
||||||
final String message;
|
|
||||||
|
|
||||||
const ProductsFailure(this.message);
|
|
||||||
|
|
||||||
@override
|
|
||||||
List<Object> get props => [message];
|
|
||||||
}
|
|
||||||
-40
@@ -1,40 +0,0 @@
|
|||||||
import 'package:dio/dio.dart';
|
|
||||||
import 'package:syncrow_web/pages/space_management_v2/modules/space_details/domain/models/space_details_model.dart';
|
|
||||||
import 'package:syncrow_web/pages/space_management_v2/modules/space_details/domain/params/load_spaces_param.dart';
|
|
||||||
import 'package:syncrow_web/pages/space_management_v2/modules/space_details/domain/services/space_details_service.dart';
|
|
||||||
import 'package:syncrow_web/services/api/api_exception.dart';
|
|
||||||
import 'package:syncrow_web/services/api/http_service.dart';
|
|
||||||
|
|
||||||
class RemoteSpaceDetailsService implements SpaceDetailsService {
|
|
||||||
final HTTPService _httpService;
|
|
||||||
|
|
||||||
RemoteSpaceDetailsService({
|
|
||||||
required HTTPService httpService,
|
|
||||||
}) : _httpService = httpService;
|
|
||||||
|
|
||||||
static const _defaultErrorMessage = 'Failed to load space details';
|
|
||||||
|
|
||||||
@override
|
|
||||||
Future<SpaceDetailsModel> getSpaceDetails(LoadSpacesParam param) async {
|
|
||||||
try {
|
|
||||||
final response = await _httpService.get(
|
|
||||||
path: 'endpoint',
|
|
||||||
expectedResponseModel: (data) {
|
|
||||||
return SpaceDetailsModel.fromJson(data as Map<String, dynamic>);
|
|
||||||
},
|
|
||||||
);
|
|
||||||
return response;
|
|
||||||
} on DioException catch (e) {
|
|
||||||
final message = e.response?.data as Map<String, dynamic>?;
|
|
||||||
final error = message?['error'] as Map<String, dynamic>?;
|
|
||||||
final errorMessage = error?['error'] as String? ?? '';
|
|
||||||
final formattedErrorMessage = [_defaultErrorMessage, errorMessage].join(
|
|
||||||
': ',
|
|
||||||
);
|
|
||||||
throw APIException(formattedErrorMessage);
|
|
||||||
} catch (e) {
|
|
||||||
final formattedErrorMessage = [_defaultErrorMessage, '$e'].join(': ');
|
|
||||||
throw APIException(formattedErrorMessage);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
-108
@@ -1,108 +0,0 @@
|
|||||||
import 'package:equatable/equatable.dart';
|
|
||||||
import 'package:syncrow_web/pages/space_management_v2/modules/products/domain/models/product.dart';
|
|
||||||
import 'package:syncrow_web/pages/space_management_v2/modules/tags/domain/models/tag.dart';
|
|
||||||
|
|
||||||
class SpaceDetailsModel extends Equatable {
|
|
||||||
final String uuid;
|
|
||||||
final String spaceName;
|
|
||||||
final String icon;
|
|
||||||
final List<ProductAllocation> productAllocations;
|
|
||||||
final List<Subspace> subspaces;
|
|
||||||
|
|
||||||
const SpaceDetailsModel({
|
|
||||||
required this.uuid,
|
|
||||||
required this.spaceName,
|
|
||||||
required this.icon,
|
|
||||||
required this.productAllocations,
|
|
||||||
required this.subspaces,
|
|
||||||
});
|
|
||||||
|
|
||||||
factory SpaceDetailsModel.fromJson(Map<String, dynamic> json) {
|
|
||||||
return SpaceDetailsModel(
|
|
||||||
uuid: json['uuid'] as String,
|
|
||||||
spaceName: json['spaceName'] as String,
|
|
||||||
icon: json['icon'] as String,
|
|
||||||
productAllocations: (json['productAllocations'] as List)
|
|
||||||
.map((e) => ProductAllocation.fromJson(e as Map<String, dynamic>))
|
|
||||||
.toList(),
|
|
||||||
subspaces: (json['subspaces'] as List)
|
|
||||||
.map((e) => Subspace.fromJson(e as Map<String, dynamic>))
|
|
||||||
.toList(),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
Map<String, dynamic> toJson() {
|
|
||||||
return {
|
|
||||||
'uuid': uuid,
|
|
||||||
'spaceName': spaceName,
|
|
||||||
'icon': icon,
|
|
||||||
'productAllocations': productAllocations.map((e) => e.toJson()).toList(),
|
|
||||||
'subspaces': subspaces.map((e) => e.toJson()).toList(),
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
|
||||||
List<Object?> get props => [uuid, spaceName, icon, productAllocations, subspaces];
|
|
||||||
}
|
|
||||||
|
|
||||||
class ProductAllocation extends Equatable {
|
|
||||||
final Product product;
|
|
||||||
final Tag tag;
|
|
||||||
final String? location;
|
|
||||||
|
|
||||||
const ProductAllocation({
|
|
||||||
required this.product,
|
|
||||||
required this.tag,
|
|
||||||
this.location,
|
|
||||||
});
|
|
||||||
|
|
||||||
factory ProductAllocation.fromJson(Map<String, dynamic> json) {
|
|
||||||
return ProductAllocation(
|
|
||||||
product: Product.fromJson(json['product'] as Map<String, dynamic>),
|
|
||||||
tag: Tag.fromJson(json['tag'] as Map<String, dynamic>),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
Map<String, dynamic> toJson() {
|
|
||||||
return {
|
|
||||||
'product': product.toJson(),
|
|
||||||
'tag': tag.toJson(),
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
|
||||||
List<Object?> get props => [product, tag];
|
|
||||||
}
|
|
||||||
|
|
||||||
class Subspace extends Equatable {
|
|
||||||
final String uuid;
|
|
||||||
final String name;
|
|
||||||
final List<ProductAllocation> productAllocations;
|
|
||||||
|
|
||||||
const Subspace({
|
|
||||||
required this.uuid,
|
|
||||||
required this.name,
|
|
||||||
required this.productAllocations,
|
|
||||||
});
|
|
||||||
|
|
||||||
factory Subspace.fromJson(Map<String, dynamic> json) {
|
|
||||||
return Subspace(
|
|
||||||
uuid: json['uuid'] as String,
|
|
||||||
name: json['name'] as String,
|
|
||||||
productAllocations: (json['productAllocations'] as List)
|
|
||||||
.map((e) => ProductAllocation.fromJson(e as Map<String, dynamic>))
|
|
||||||
.toList(),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
Map<String, dynamic> toJson() {
|
|
||||||
return {
|
|
||||||
'uuid': uuid,
|
|
||||||
'name': name,
|
|
||||||
'productAllocations': productAllocations.map((e) => e.toJson()).toList(),
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
|
||||||
List<Object?> get props => [uuid, name, productAllocations];
|
|
||||||
}
|
|
||||||
-3
@@ -1,3 +0,0 @@
|
|||||||
class LoadSpacesParam {
|
|
||||||
const LoadSpacesParam();
|
|
||||||
}
|
|
||||||
-6
@@ -1,6 +0,0 @@
|
|||||||
import 'package:syncrow_web/pages/space_management_v2/modules/space_details/domain/models/space_details_model.dart';
|
|
||||||
import 'package:syncrow_web/pages/space_management_v2/modules/space_details/domain/params/load_spaces_param.dart';
|
|
||||||
|
|
||||||
abstract class SpaceDetailsService {
|
|
||||||
Future<SpaceDetailsModel> getSpaceDetails(LoadSpacesParam param);
|
|
||||||
}
|
|
||||||
-34
@@ -1,34 +0,0 @@
|
|||||||
import 'package:bloc/bloc.dart';
|
|
||||||
import 'package:equatable/equatable.dart';
|
|
||||||
import 'package:syncrow_web/pages/space_management_v2/modules/space_details/domain/models/space_details_model.dart';
|
|
||||||
import 'package:syncrow_web/pages/space_management_v2/modules/space_details/domain/params/load_spaces_param.dart';
|
|
||||||
import 'package:syncrow_web/pages/space_management_v2/modules/space_details/domain/services/space_details_service.dart';
|
|
||||||
import 'package:syncrow_web/services/api/api_exception.dart';
|
|
||||||
|
|
||||||
part 'space_details_event.dart';
|
|
||||||
part 'space_details_state.dart';
|
|
||||||
|
|
||||||
class SpaceDetailsBloc extends Bloc<SpaceDetailsEvent, SpaceDetailsState> {
|
|
||||||
final SpaceDetailsService _spaceDetailsService;
|
|
||||||
|
|
||||||
SpaceDetailsBloc(this._spaceDetailsService) : super(SpaceDetailsInitial()) {
|
|
||||||
on<LoadSpaceDetails>(_onLoadSpaceDetails);
|
|
||||||
}
|
|
||||||
|
|
||||||
Future<void> _onLoadSpaceDetails(
|
|
||||||
LoadSpaceDetails event,
|
|
||||||
Emitter<SpaceDetailsState> emit,
|
|
||||||
) async {
|
|
||||||
emit(SpaceDetailsLoading());
|
|
||||||
try {
|
|
||||||
final spaceDetails = await _spaceDetailsService.getSpaceDetails(
|
|
||||||
event.param,
|
|
||||||
);
|
|
||||||
emit(SpaceDetailsLoaded(spaceDetails));
|
|
||||||
} on APIException catch (e) {
|
|
||||||
emit(SpaceDetailsFailure(e.message));
|
|
||||||
} catch (e) {
|
|
||||||
emit(SpaceDetailsFailure(e.toString()));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
-17
@@ -1,17 +0,0 @@
|
|||||||
part of 'space_details_bloc.dart';
|
|
||||||
|
|
||||||
sealed class SpaceDetailsEvent extends Equatable {
|
|
||||||
const SpaceDetailsEvent();
|
|
||||||
|
|
||||||
@override
|
|
||||||
List<Object> get props => [];
|
|
||||||
}
|
|
||||||
|
|
||||||
class LoadSpaceDetails extends SpaceDetailsEvent {
|
|
||||||
const LoadSpaceDetails(this.param);
|
|
||||||
|
|
||||||
final LoadSpacesParam param;
|
|
||||||
|
|
||||||
@override
|
|
||||||
List<Object> get props => [param];
|
|
||||||
}
|
|
||||||
-30
@@ -1,30 +0,0 @@
|
|||||||
part of 'space_details_bloc.dart';
|
|
||||||
|
|
||||||
sealed class SpaceDetailsState extends Equatable {
|
|
||||||
const SpaceDetailsState();
|
|
||||||
|
|
||||||
@override
|
|
||||||
List<Object> get props => [];
|
|
||||||
}
|
|
||||||
|
|
||||||
final class SpaceDetailsInitial extends SpaceDetailsState {}
|
|
||||||
|
|
||||||
final class SpaceDetailsLoading extends SpaceDetailsState {}
|
|
||||||
|
|
||||||
final class SpaceDetailsLoaded extends SpaceDetailsState {
|
|
||||||
final SpaceDetailsModel spaceDetails;
|
|
||||||
|
|
||||||
const SpaceDetailsLoaded(this.spaceDetails);
|
|
||||||
|
|
||||||
@override
|
|
||||||
List<Object> get props => [spaceDetails];
|
|
||||||
}
|
|
||||||
|
|
||||||
final class SpaceDetailsFailure extends SpaceDetailsState {
|
|
||||||
final String message;
|
|
||||||
|
|
||||||
const SpaceDetailsFailure(this.message);
|
|
||||||
|
|
||||||
@override
|
|
||||||
List<Object> get props => [message];
|
|
||||||
}
|
|
||||||
@@ -1,49 +0,0 @@
|
|||||||
import 'package:dio/dio.dart';
|
|
||||||
import 'package:syncrow_web/pages/space_management_v2/modules/tags/domain/models/tag.dart';
|
|
||||||
import 'package:syncrow_web/pages/space_management_v2/modules/tags/domain/params/load_tags_param.dart';
|
|
||||||
import 'package:syncrow_web/pages/space_management_v2/modules/tags/domain/services/tags_service.dart';
|
|
||||||
import 'package:syncrow_web/services/api/api_exception.dart';
|
|
||||||
import 'package:syncrow_web/services/api/http_service.dart';
|
|
||||||
import 'package:syncrow_web/utils/constants/api_const.dart';
|
|
||||||
|
|
||||||
final class RemoteTagsService implements TagsService {
|
|
||||||
const RemoteTagsService(this._httpService);
|
|
||||||
|
|
||||||
final HTTPService _httpService;
|
|
||||||
|
|
||||||
static const _defaultErrorMessage = 'Failed to load tags';
|
|
||||||
|
|
||||||
@override
|
|
||||||
Future<List<Tag>> loadTags(LoadTagsParam param) async {
|
|
||||||
if (param.projectUuid == null) {
|
|
||||||
throw Exception('Project UUID is required');
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
|
||||||
final response = await _httpService.get(
|
|
||||||
path: ApiEndpoints.listTags.replaceAll(
|
|
||||||
'{projectUuid}',
|
|
||||||
param.projectUuid!,
|
|
||||||
),
|
|
||||||
expectedResponseModel: (json) {
|
|
||||||
final result = json as Map<String, dynamic>;
|
|
||||||
final data = result['data'] as List<dynamic>;
|
|
||||||
return data.map((e) => Tag.fromJson(e as Map<String, dynamic>)).toList();
|
|
||||||
},
|
|
||||||
);
|
|
||||||
return response;
|
|
||||||
} on DioException catch (e) {
|
|
||||||
final message = e.response?.data as Map<String, dynamic>?;
|
|
||||||
final error = message?['error'] as Map<String, dynamic>?;
|
|
||||||
final errorMessage = error?['error'] as String? ?? '';
|
|
||||||
final formattedErrorMessage = [
|
|
||||||
_defaultErrorMessage,
|
|
||||||
errorMessage,
|
|
||||||
].join(': ');
|
|
||||||
throw APIException(formattedErrorMessage);
|
|
||||||
} catch (e) {
|
|
||||||
final formattedErrorMessage = [_defaultErrorMessage, '$e'].join(': ');
|
|
||||||
throw APIException(formattedErrorMessage);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,36 +0,0 @@
|
|||||||
import 'package:equatable/equatable.dart';
|
|
||||||
|
|
||||||
class Tag extends Equatable {
|
|
||||||
final String uuid;
|
|
||||||
final String name;
|
|
||||||
final String createdAt;
|
|
||||||
final String updatedAt;
|
|
||||||
|
|
||||||
const Tag({
|
|
||||||
required this.uuid,
|
|
||||||
required this.name,
|
|
||||||
required this.createdAt,
|
|
||||||
required this.updatedAt,
|
|
||||||
});
|
|
||||||
|
|
||||||
factory Tag.fromJson(Map<String, dynamic> json) {
|
|
||||||
return Tag(
|
|
||||||
uuid: json['uuid'] as String,
|
|
||||||
name: json['name'] as String,
|
|
||||||
createdAt: json['createdAt'] as String,
|
|
||||||
updatedAt: json['updatedAt'] as String,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
Map<String, dynamic> toJson() {
|
|
||||||
return {
|
|
||||||
'uuid': uuid,
|
|
||||||
'name': name,
|
|
||||||
'createdAt': createdAt,
|
|
||||||
'updatedAt': updatedAt,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
|
||||||
List<Object?> get props => [uuid, name, createdAt, updatedAt];
|
|
||||||
}
|
|
||||||
@@ -1,5 +0,0 @@
|
|||||||
class LoadTagsParam {
|
|
||||||
final String? projectUuid;
|
|
||||||
|
|
||||||
const LoadTagsParam({this.projectUuid});
|
|
||||||
}
|
|
||||||
@@ -1,6 +0,0 @@
|
|||||||
import 'package:syncrow_web/pages/space_management_v2/modules/tags/domain/models/tag.dart';
|
|
||||||
import 'package:syncrow_web/pages/space_management_v2/modules/tags/domain/params/load_tags_param.dart';
|
|
||||||
|
|
||||||
abstract interface class TagsService {
|
|
||||||
Future<List<Tag>> loadTags(LoadTagsParam param);
|
|
||||||
}
|
|
||||||
@@ -1,32 +0,0 @@
|
|||||||
import 'package:bloc/bloc.dart';
|
|
||||||
import 'package:equatable/equatable.dart';
|
|
||||||
import 'package:syncrow_web/pages/space_management_v2/modules/tags/domain/models/tag.dart';
|
|
||||||
import 'package:syncrow_web/pages/space_management_v2/modules/tags/domain/params/load_tags_param.dart';
|
|
||||||
import 'package:syncrow_web/pages/space_management_v2/modules/tags/domain/services/tags_service.dart';
|
|
||||||
import 'package:syncrow_web/services/api/api_exception.dart';
|
|
||||||
|
|
||||||
part 'tags_event.dart';
|
|
||||||
part 'tags_state.dart';
|
|
||||||
|
|
||||||
class TagsBloc extends Bloc<TagsEvent, TagsState> {
|
|
||||||
final TagsService _tagsService;
|
|
||||||
|
|
||||||
TagsBloc(this._tagsService) : super(TagsInitial()) {
|
|
||||||
on<LoadTags>(_onLoadTags);
|
|
||||||
}
|
|
||||||
|
|
||||||
Future<void> _onLoadTags(
|
|
||||||
LoadTags event,
|
|
||||||
Emitter<TagsState> emit,
|
|
||||||
) async {
|
|
||||||
emit(TagsLoading());
|
|
||||||
try {
|
|
||||||
final tags = await _tagsService.loadTags(event.param);
|
|
||||||
emit(TagsLoaded(tags));
|
|
||||||
} on APIException catch (e) {
|
|
||||||
emit(TagsFailure(e.message));
|
|
||||||
} catch (e) {
|
|
||||||
emit(TagsFailure(e.toString()));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,17 +0,0 @@
|
|||||||
part of 'tags_bloc.dart';
|
|
||||||
|
|
||||||
abstract class TagsEvent extends Equatable {
|
|
||||||
const TagsEvent();
|
|
||||||
|
|
||||||
@override
|
|
||||||
List<Object?> get props => [];
|
|
||||||
}
|
|
||||||
|
|
||||||
class LoadTags extends TagsEvent {
|
|
||||||
final LoadTagsParam param;
|
|
||||||
|
|
||||||
const LoadTags(this.param);
|
|
||||||
|
|
||||||
@override
|
|
||||||
List<Object?> get props => [param];
|
|
||||||
}
|
|
||||||
@@ -1,30 +0,0 @@
|
|||||||
part of 'tags_bloc.dart';
|
|
||||||
|
|
||||||
abstract class TagsState extends Equatable {
|
|
||||||
const TagsState();
|
|
||||||
|
|
||||||
@override
|
|
||||||
List<Object?> get props => [];
|
|
||||||
}
|
|
||||||
|
|
||||||
class TagsInitial extends TagsState {}
|
|
||||||
|
|
||||||
class TagsLoading extends TagsState {}
|
|
||||||
|
|
||||||
class TagsLoaded extends TagsState {
|
|
||||||
final List<Tag> tags;
|
|
||||||
|
|
||||||
const TagsLoaded(this.tags);
|
|
||||||
|
|
||||||
@override
|
|
||||||
List<Object?> get props => [tags];
|
|
||||||
}
|
|
||||||
|
|
||||||
class TagsFailure extends TagsState {
|
|
||||||
final String message;
|
|
||||||
|
|
||||||
const TagsFailure(this.message);
|
|
||||||
|
|
||||||
@override
|
|
||||||
List<Object?> get props => [message];
|
|
||||||
}
|
|
||||||
-39
@@ -1,39 +0,0 @@
|
|||||||
import 'package:dio/dio.dart';
|
|
||||||
import 'package:syncrow_web/pages/space_management_v2/modules/communities/domain/models/community_model.dart';
|
|
||||||
import 'package:syncrow_web/pages/space_management_v2/modules/update_community/domain/params/update_community_param.dart';
|
|
||||||
import 'package:syncrow_web/pages/space_management_v2/modules/update_community/domain/services/update_community_service.dart';
|
|
||||||
import 'package:syncrow_web/services/api/api_exception.dart';
|
|
||||||
import 'package:syncrow_web/services/api/http_service.dart';
|
|
||||||
|
|
||||||
class RemoteUpdateCommunityService implements UpdateCommunityService {
|
|
||||||
const RemoteUpdateCommunityService(this._httpService);
|
|
||||||
|
|
||||||
final HTTPService _httpService;
|
|
||||||
|
|
||||||
static const _defaultErrorMessage = 'Failed to update community';
|
|
||||||
|
|
||||||
@override
|
|
||||||
Future<CommunityModel> updateCommunity(UpdateCommunityParam param) async {
|
|
||||||
try {
|
|
||||||
final response = await _httpService.put(
|
|
||||||
path: 'endpoint',
|
|
||||||
expectedResponseModel: (data) => CommunityModel.fromJson(
|
|
||||||
data as Map<String, dynamic>,
|
|
||||||
),
|
|
||||||
);
|
|
||||||
return response;
|
|
||||||
} on DioException catch (e) {
|
|
||||||
final message = e.response?.data as Map<String, dynamic>?;
|
|
||||||
final error = message?['error'] as Map<String, dynamic>?;
|
|
||||||
final errorMessage = error?['error'] as String? ?? '';
|
|
||||||
final formattedErrorMessage = [
|
|
||||||
_defaultErrorMessage,
|
|
||||||
errorMessage,
|
|
||||||
].join(': ');
|
|
||||||
throw APIException(formattedErrorMessage);
|
|
||||||
} catch (e) {
|
|
||||||
final formattedErrorMessage = [_defaultErrorMessage, '$e'].join(': ');
|
|
||||||
throw APIException(formattedErrorMessage);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
-10
@@ -1,10 +0,0 @@
|
|||||||
import 'package:equatable/equatable.dart';
|
|
||||||
|
|
||||||
class UpdateCommunityParam extends Equatable {
|
|
||||||
const UpdateCommunityParam({required this.name});
|
|
||||||
|
|
||||||
final String name;
|
|
||||||
|
|
||||||
@override
|
|
||||||
List<Object> get props => [name];
|
|
||||||
}
|
|
||||||
-6
@@ -1,6 +0,0 @@
|
|||||||
import 'package:syncrow_web/pages/space_management_v2/modules/communities/domain/models/community_model.dart';
|
|
||||||
import 'package:syncrow_web/pages/space_management_v2/modules/update_community/domain/params/update_community_param.dart';
|
|
||||||
|
|
||||||
abstract class UpdateCommunityService {
|
|
||||||
Future<CommunityModel> updateCommunity(UpdateCommunityParam param);
|
|
||||||
}
|
|
||||||
-36
@@ -1,36 +0,0 @@
|
|||||||
import 'package:bloc/bloc.dart';
|
|
||||||
import 'package:equatable/equatable.dart';
|
|
||||||
import 'package:syncrow_web/pages/space_management_v2/modules/communities/domain/models/community_model.dart';
|
|
||||||
import 'package:syncrow_web/pages/space_management_v2/modules/update_community/domain/params/update_community_param.dart';
|
|
||||||
import 'package:syncrow_web/pages/space_management_v2/modules/update_community/domain/services/update_community_service.dart';
|
|
||||||
import 'package:syncrow_web/services/api/api_exception.dart';
|
|
||||||
|
|
||||||
part 'update_community_event.dart';
|
|
||||||
part 'update_community_state.dart';
|
|
||||||
|
|
||||||
class UpdateCommunityBloc extends Bloc<UpdateCommunityEvent, UpdateCommunityState> {
|
|
||||||
final UpdateCommunityService _updateCommunityService;
|
|
||||||
|
|
||||||
UpdateCommunityBloc(
|
|
||||||
this._updateCommunityService,
|
|
||||||
) : super(UpdateCommunityInitial()) {
|
|
||||||
on<UpdateCommunity>(_onUpdateCommunity);
|
|
||||||
}
|
|
||||||
|
|
||||||
Future<void> _onUpdateCommunity(
|
|
||||||
UpdateCommunity event,
|
|
||||||
Emitter<UpdateCommunityState> emit,
|
|
||||||
) async {
|
|
||||||
emit(UpdateCommunityLoading());
|
|
||||||
try {
|
|
||||||
final updatedCommunity = await _updateCommunityService.updateCommunity(
|
|
||||||
event.param,
|
|
||||||
);
|
|
||||||
emit(UpdateCommunitySuccess(updatedCommunity));
|
|
||||||
} on APIException catch (e) {
|
|
||||||
emit(UpdateCommunityFailure(e.message));
|
|
||||||
} catch (e) {
|
|
||||||
emit(UpdateCommunityFailure(e.toString()));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
-17
@@ -1,17 +0,0 @@
|
|||||||
part of 'update_community_bloc.dart';
|
|
||||||
|
|
||||||
sealed class UpdateCommunityEvent extends Equatable {
|
|
||||||
const UpdateCommunityEvent();
|
|
||||||
|
|
||||||
@override
|
|
||||||
List<Object> get props => [];
|
|
||||||
}
|
|
||||||
|
|
||||||
final class UpdateCommunity extends UpdateCommunityEvent {
|
|
||||||
const UpdateCommunity(this.param);
|
|
||||||
|
|
||||||
final UpdateCommunityParam param;
|
|
||||||
|
|
||||||
@override
|
|
||||||
List<Object> get props => [param];
|
|
||||||
}
|
|
||||||
-30
@@ -1,30 +0,0 @@
|
|||||||
part of 'update_community_bloc.dart';
|
|
||||||
|
|
||||||
sealed class UpdateCommunityState extends Equatable {
|
|
||||||
const UpdateCommunityState();
|
|
||||||
|
|
||||||
@override
|
|
||||||
List<Object> get props => [];
|
|
||||||
}
|
|
||||||
|
|
||||||
final class UpdateCommunityInitial extends UpdateCommunityState {}
|
|
||||||
|
|
||||||
final class UpdateCommunityLoading extends UpdateCommunityState {}
|
|
||||||
|
|
||||||
final class UpdateCommunitySuccess extends UpdateCommunityState {
|
|
||||||
final CommunityModel community;
|
|
||||||
|
|
||||||
const UpdateCommunitySuccess(this.community);
|
|
||||||
|
|
||||||
@override
|
|
||||||
List<Object> get props => [community];
|
|
||||||
}
|
|
||||||
|
|
||||||
final class UpdateCommunityFailure extends UpdateCommunityState {
|
|
||||||
final String message;
|
|
||||||
|
|
||||||
const UpdateCommunityFailure(this.message);
|
|
||||||
|
|
||||||
@override
|
|
||||||
List<Object> get props => [message];
|
|
||||||
}
|
|
||||||
-40
@@ -1,40 +0,0 @@
|
|||||||
import 'package:dio/dio.dart';
|
|
||||||
import 'package:syncrow_web/pages/space_management_v2/modules/space_details/domain/models/space_details_model.dart';
|
|
||||||
import 'package:syncrow_web/pages/space_management_v2/modules/update_space/domain/services/update_space_service.dart';
|
|
||||||
import 'package:syncrow_web/services/api/api_exception.dart';
|
|
||||||
import 'package:syncrow_web/services/api/http_service.dart';
|
|
||||||
|
|
||||||
class RemoteUpdateSpaceService implements UpdateSpaceService {
|
|
||||||
const RemoteUpdateSpaceService(this._httpService);
|
|
||||||
|
|
||||||
final HTTPService _httpService;
|
|
||||||
|
|
||||||
static const _defaultErrorMessage = 'Failed to update space';
|
|
||||||
|
|
||||||
@override
|
|
||||||
Future<SpaceDetailsModel> updateSpace(SpaceDetailsModel space) async {
|
|
||||||
try {
|
|
||||||
final response = await _httpService.put(
|
|
||||||
path: 'endpoint',
|
|
||||||
body: space.toJson(),
|
|
||||||
expectedResponseModel: (data) => SpaceDetailsModel.fromJson(
|
|
||||||
data as Map<String, dynamic>,
|
|
||||||
),
|
|
||||||
);
|
|
||||||
|
|
||||||
return response;
|
|
||||||
} on DioException catch (e) {
|
|
||||||
final message = e.response?.data as Map<String, dynamic>?;
|
|
||||||
final error = message?['error'] as Map<String, dynamic>?;
|
|
||||||
final errorMessage = error?['error'] as String? ?? '';
|
|
||||||
final formattedErrorMessage = [
|
|
||||||
_defaultErrorMessage,
|
|
||||||
errorMessage,
|
|
||||||
].join(': ');
|
|
||||||
throw APIException(formattedErrorMessage);
|
|
||||||
} catch (e) {
|
|
||||||
final formattedErrorMessage = [_defaultErrorMessage, '$e'].join(': ');
|
|
||||||
throw APIException(formattedErrorMessage);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
-5
@@ -1,5 +0,0 @@
|
|||||||
import 'package:syncrow_web/pages/space_management_v2/modules/space_details/domain/models/space_details_model.dart';
|
|
||||||
|
|
||||||
abstract class UpdateSpaceService {
|
|
||||||
Future<SpaceDetailsModel> updateSpace(SpaceDetailsModel space);
|
|
||||||
}
|
|
||||||
-31
@@ -1,31 +0,0 @@
|
|||||||
import 'package:bloc/bloc.dart';
|
|
||||||
import 'package:equatable/equatable.dart';
|
|
||||||
import 'package:syncrow_web/pages/space_management_v2/modules/space_details/domain/models/space_details_model.dart';
|
|
||||||
import 'package:syncrow_web/pages/space_management_v2/modules/update_space/domain/services/update_space_service.dart';
|
|
||||||
import 'package:syncrow_web/services/api/api_exception.dart';
|
|
||||||
|
|
||||||
part 'update_space_event.dart';
|
|
||||||
part 'update_space_state.dart';
|
|
||||||
|
|
||||||
class UpdateSpaceBloc extends Bloc<UpdateSpaceEvent, UpdateSpaceState> {
|
|
||||||
final UpdateSpaceService _updateSpaceService;
|
|
||||||
|
|
||||||
UpdateSpaceBloc(this._updateSpaceService) : super(UpdateSpaceInitial()) {
|
|
||||||
on<UpdateSpace>(_onUpdateSpace);
|
|
||||||
}
|
|
||||||
|
|
||||||
Future<void> _onUpdateSpace(
|
|
||||||
UpdateSpace event,
|
|
||||||
Emitter<UpdateSpaceState> emit,
|
|
||||||
) async {
|
|
||||||
emit(UpdateSpaceLoading());
|
|
||||||
try {
|
|
||||||
final updatedSpace = await _updateSpaceService.updateSpace(event.space);
|
|
||||||
emit(UpdateSpaceSuccess(updatedSpace));
|
|
||||||
} on APIException catch (e) {
|
|
||||||
emit(UpdateSpaceFailure(e.message));
|
|
||||||
} catch (e) {
|
|
||||||
emit(UpdateSpaceFailure(e.toString()));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
-17
@@ -1,17 +0,0 @@
|
|||||||
part of 'update_space_bloc.dart';
|
|
||||||
|
|
||||||
sealed class UpdateSpaceEvent extends Equatable {
|
|
||||||
const UpdateSpaceEvent();
|
|
||||||
|
|
||||||
@override
|
|
||||||
List<Object> get props => [];
|
|
||||||
}
|
|
||||||
|
|
||||||
final class UpdateSpace extends UpdateSpaceEvent {
|
|
||||||
const UpdateSpace(this.space);
|
|
||||||
|
|
||||||
final SpaceDetailsModel space;
|
|
||||||
|
|
||||||
@override
|
|
||||||
List<Object> get props => [space];
|
|
||||||
}
|
|
||||||
-30
@@ -1,30 +0,0 @@
|
|||||||
part of 'update_space_bloc.dart';
|
|
||||||
|
|
||||||
sealed class UpdateSpaceState extends Equatable {
|
|
||||||
const UpdateSpaceState();
|
|
||||||
|
|
||||||
@override
|
|
||||||
List<Object> get props => [];
|
|
||||||
}
|
|
||||||
|
|
||||||
final class UpdateSpaceInitial extends UpdateSpaceState {}
|
|
||||||
|
|
||||||
final class UpdateSpaceLoading extends UpdateSpaceState {}
|
|
||||||
|
|
||||||
final class UpdateSpaceSuccess extends UpdateSpaceState {
|
|
||||||
final SpaceDetailsModel space;
|
|
||||||
|
|
||||||
const UpdateSpaceSuccess(this.space);
|
|
||||||
|
|
||||||
@override
|
|
||||||
List<Object> get props => [space];
|
|
||||||
}
|
|
||||||
|
|
||||||
final class UpdateSpaceFailure extends UpdateSpaceState {
|
|
||||||
final String message;
|
|
||||||
|
|
||||||
const UpdateSpaceFailure(this.message);
|
|
||||||
|
|
||||||
@override
|
|
||||||
List<Object> get props => [message];
|
|
||||||
}
|
|
||||||
@@ -2,7 +2,6 @@ import 'package:flutter/material.dart';
|
|||||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||||
import 'package:syncrow_web/pages/device_managment/shared/navigate_home_grid_view.dart';
|
import 'package:syncrow_web/pages/device_managment/shared/navigate_home_grid_view.dart';
|
||||||
import 'package:syncrow_web/pages/space_tree/bloc/space_tree_bloc.dart';
|
import 'package:syncrow_web/pages/space_tree/bloc/space_tree_bloc.dart';
|
||||||
import 'package:syncrow_web/pages/space_tree/bloc/space_tree_event.dart';
|
|
||||||
import 'package:syncrow_web/pages/spaces_management/structure_selector/bloc/center_body_bloc.dart';
|
import 'package:syncrow_web/pages/spaces_management/structure_selector/bloc/center_body_bloc.dart';
|
||||||
import 'package:syncrow_web/pages/spaces_management/all_spaces/bloc/space_management_bloc.dart';
|
import 'package:syncrow_web/pages/spaces_management/all_spaces/bloc/space_management_bloc.dart';
|
||||||
import 'package:syncrow_web/pages/spaces_management/all_spaces/bloc/space_management_event.dart';
|
import 'package:syncrow_web/pages/spaces_management/all_spaces/bloc/space_management_event.dart';
|
||||||
@@ -26,12 +25,6 @@ class SpaceManagementPageState extends State<SpaceManagementPage> {
|
|||||||
final CommunitySpaceManagementApi _api = CommunitySpaceManagementApi();
|
final CommunitySpaceManagementApi _api = CommunitySpaceManagementApi();
|
||||||
final ProductApi _productApi = ProductApi();
|
final ProductApi _productApi = ProductApi();
|
||||||
final SpaceModelManagementApi _spaceModelApi = SpaceModelManagementApi();
|
final SpaceModelManagementApi _spaceModelApi = SpaceModelManagementApi();
|
||||||
|
|
||||||
@override
|
|
||||||
void initState() {
|
|
||||||
context.read<SpaceTreeBloc>().add(InitialEvent());
|
|
||||||
super.initState();
|
|
||||||
}
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return MultiBlocProvider(
|
return MultiBlocProvider(
|
||||||
|
|||||||
@@ -3,20 +3,14 @@ import 'package:syncrow_web/services/api/http_service.dart';
|
|||||||
import 'package:syncrow_web/utils/constants/api_const.dart';
|
import 'package:syncrow_web/utils/constants/api_const.dart';
|
||||||
|
|
||||||
class HomeApi {
|
class HomeApi {
|
||||||
Future<UserModel?> fetchUserInfo(String userId) async {
|
Future fetchUserInfo(userId) async {
|
||||||
try {
|
final response = await HTTPService().get(
|
||||||
final response = await HTTPService().get(
|
path: ApiEndpoints.getUser.replaceAll('{userUuid}', userId!),
|
||||||
path: ApiEndpoints.getUser.replaceAll('{userUuid}', userId),
|
|
||||||
showServerMessage: true,
|
showServerMessage: true,
|
||||||
expectedResponseModel: (json) {
|
expectedResponseModel: (json) {
|
||||||
final user = UserModel.fromJson(json as Map<String, dynamic>);
|
return UserModel.fromJson(json);
|
||||||
return user;
|
});
|
||||||
},
|
return response;
|
||||||
);
|
|
||||||
return response;
|
|
||||||
} catch (e) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Future fetchTerms() async {
|
Future fetchTerms() async {
|
||||||
|
|||||||
@@ -34,8 +34,9 @@ class UserPermissionApi {
|
|||||||
path: ApiEndpoints.roleTypes,
|
path: ApiEndpoints.roleTypes,
|
||||||
showServerMessage: true,
|
showServerMessage: true,
|
||||||
expectedResponseModel: (json) {
|
expectedResponseModel: (json) {
|
||||||
final List<RoleTypeModel> fetchedRoles =
|
final List<RoleTypeModel> fetchedRoles = (json['data'] as List)
|
||||||
(json['data'] as List).map((item) => RoleTypeModel.fromJson(item)).toList();
|
.map((item) => RoleTypeModel.fromJson(item))
|
||||||
|
.toList();
|
||||||
return fetchedRoles;
|
return fetchedRoles;
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
@@ -47,7 +48,9 @@ class UserPermissionApi {
|
|||||||
path: ApiEndpoints.permission.replaceAll("roleUuid", roleUuid),
|
path: ApiEndpoints.permission.replaceAll("roleUuid", roleUuid),
|
||||||
showServerMessage: true,
|
showServerMessage: true,
|
||||||
expectedResponseModel: (json) {
|
expectedResponseModel: (json) {
|
||||||
return (json as List).map((data) => PermissionOption.fromJson(data)).toList();
|
return (json as List)
|
||||||
|
.map((data) => PermissionOption.fromJson(data))
|
||||||
|
.toList();
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
return response ?? [];
|
return response ?? [];
|
||||||
@@ -192,10 +195,14 @@ class UserPermissionApi {
|
|||||||
|
|
||||||
Future<bool> changeUserStatusById(userUuid, status, String projectUuid) async {
|
Future<bool> changeUserStatusById(userUuid, status, String projectUuid) async {
|
||||||
try {
|
try {
|
||||||
Map<String, dynamic> bodya = {"disable": status, "projectUuid": projectUuid};
|
Map<String, dynamic> bodya = {
|
||||||
|
"disable": status,
|
||||||
|
"projectUuid": projectUuid
|
||||||
|
};
|
||||||
|
|
||||||
final response = await _httpService.put(
|
final response = await _httpService.put(
|
||||||
path: ApiEndpoints.changeUserStatus.replaceAll("{invitedUserUuid}", userUuid),
|
path: ApiEndpoints.changeUserStatus
|
||||||
|
.replaceAll("{invitedUserUuid}", userUuid),
|
||||||
body: bodya,
|
body: bodya,
|
||||||
expectedResponseModel: (json) {
|
expectedResponseModel: (json) {
|
||||||
return json['success'];
|
return json['success'];
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import 'package:flutter_dotenv/flutter_dotenv.dart';
|
import 'package:flutter_dotenv/flutter_dotenv.dart';
|
||||||
|
|
||||||
abstract class ApiEndpoints {
|
abstract class ApiEndpoints {
|
||||||
static const String projectUuid = "bcda711e-9fc2-4168-a05e-171b4026d1ff";
|
static const String projectUuid = "0e62577c-06fa-41b9-8a92-99a21fbaf51c";
|
||||||
static String baseUrl = dotenv.env['BASE_URL'] ?? '';
|
static String baseUrl = dotenv.env['BASE_URL'] ?? '';
|
||||||
static const String signUp = '/authentication/user/signup';
|
static const String signUp = '/authentication/user/signup';
|
||||||
static const String login = '/authentication/user/login';
|
static const String login = '/authentication/user/login';
|
||||||
|
|||||||
@@ -1,3 +1,3 @@
|
|||||||
class TempConst {
|
class TempConst {
|
||||||
static const projectId = 'bcda711e-9fc2-4168-a05e-171b4026d1ff';
|
static const projectId = '0e62577c-06fa-41b9-8a92-99a21fbaf51c';
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user