mirror of
https://github.com/SyncrowIOT/web.git
synced 2025-07-10 23:27:25 +00:00
Compare commits
93 Commits
fix-bugs-c
...
hotfixes
Author | SHA1 | Date | |
---|---|---|---|
d45fa4c957 | |||
c178c36824 | |||
27dfa0a05a | |||
78979a4375 | |||
ea19387605 | |||
5b33a8617e | |||
34565a7dab | |||
caf1ff5c7e | |||
01e8002c43 | |||
63da660ece | |||
567d0e2d20 | |||
45e6ea3259 | |||
e942957a47 | |||
b9a3b9c719 | |||
f5500dfe50 | |||
6c4bc0d634 | |||
1ba1aba54e | |||
09f2123946 | |||
8fc6e54ecc | |||
5d3380ef82 | |||
5b0710957d | |||
0132805713 | |||
35f975b261 | |||
9600f4fb8b | |||
5cd1384000 | |||
0260523121 | |||
6af96fadbd | |||
737762bbaf | |||
6bcfb77a06 | |||
6b76827f21 | |||
519285fa7c | |||
3eb38d28f7 | |||
2108622b5b | |||
ac44af54a3 | |||
aa141ef54d | |||
b0aea94b91 | |||
96f463229c | |||
4d9145a953 | |||
a2f897c3a6 | |||
249c2fb172 | |||
7a8537d39c | |||
1da0cdad4b | |||
d10df2ffb8 | |||
6ff9c602f1 | |||
5f20d52e57 | |||
362557d0d0 | |||
312d185932 | |||
89e12e47da | |||
a0d9819532 | |||
1316820954 | |||
5591c78d88 | |||
eaff7c4a52 | |||
5b3152e833 | |||
c1d3296b59 | |||
b3069ab749 | |||
37b21ecdfb | |||
8d408867bb | |||
13360fe6f3 | |||
3e5b501167 | |||
4d9f08af31 | |||
28aa3bc406 | |||
51ad74b2be | |||
1567f10827 | |||
cdbd90b54c | |||
03f5c869c6 | |||
4f98891902 | |||
7002bbfa04 | |||
f19120c754 | |||
6b3eca23af | |||
4f4f11c330 | |||
8a25fa798c | |||
6612e91430 | |||
56c613fb0c | |||
8d2d9dd0bb | |||
cfc68f1568 | |||
02e08ad92f | |||
d7899a24f5 | |||
800c0ba47f | |||
fe4e775902 | |||
5247856cb4 | |||
4a8b8a32ba | |||
2abce77eb5 | |||
7efd1c3c87 | |||
7a0d9aefb7 | |||
21cc25cfc4 | |||
e2ec4bbf31 | |||
51b46ae197 | |||
36ee22603a | |||
b0abd42b0c | |||
ba4da78846 | |||
dc20d69f20 | |||
cf6ec231dc | |||
d0530f7fc3 |
10
.github/.github/dependabot.yaml
vendored
Normal file
10
.github/.github/dependabot.yaml
vendored
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
version: 2
|
||||||
|
updates:
|
||||||
|
- package-ecosystem: "github-actions"
|
||||||
|
directory: "/"
|
||||||
|
schedule:
|
||||||
|
interval: "daily"
|
||||||
|
- package-ecosystem: "pub"
|
||||||
|
directory: "/"
|
||||||
|
schedule:
|
||||||
|
interval: "daily"
|
BIN
assets/images/autocad_occupancy_image.png
Normal file
BIN
assets/images/autocad_occupancy_image.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 290 KiB |
@ -11,7 +11,6 @@ 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';
|
||||||
@ -21,8 +20,10 @@ import 'package:syncrow_web/utils/theme/theme.dart';
|
|||||||
|
|
||||||
Future<void> main() async {
|
Future<void> main() async {
|
||||||
try {
|
try {
|
||||||
const environment =
|
const environment = String.fromEnvironment(
|
||||||
String.fromEnvironment('FLAVOR', defaultValue: 'production');
|
'FLAVOR',
|
||||||
|
defaultValue: 'production',
|
||||||
|
);
|
||||||
await dotenv.load(fileName: '.env.$environment');
|
await dotenv.load(fileName: '.env.$environment');
|
||||||
WidgetsFlutterBinding.ensureInitialized();
|
WidgetsFlutterBinding.ensureInitialized();
|
||||||
await Firebase.initializeApp(
|
await Firebase.initializeApp(
|
||||||
@ -40,7 +41,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 {
|
||||||
String checkToken = await AuthBloc.getTokenAndValidate();
|
final 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;
|
||||||
|
|
||||||
@ -58,8 +59,7 @@ class MyApp extends StatelessWidget {
|
|||||||
BlocProvider<CreateRoutineBloc>(
|
BlocProvider<CreateRoutineBloc>(
|
||||||
create: (context) => CreateRoutineBloc(),
|
create: (context) => CreateRoutineBloc(),
|
||||||
),
|
),
|
||||||
BlocProvider(
|
BlocProvider(create: (context) => HomeBloc()..add(FetchUserInfo())),
|
||||||
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()..add(InitialEvent()),
|
create: (context) => SpaceTreeBloc(),
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
child: MaterialApp.router(
|
child: MaterialApp.router(
|
||||||
|
@ -11,7 +11,6 @@ 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';
|
||||||
@ -21,7 +20,10 @@ import 'package:syncrow_web/utils/theme/theme.dart';
|
|||||||
|
|
||||||
Future<void> main() async {
|
Future<void> main() async {
|
||||||
try {
|
try {
|
||||||
const environment = String.fromEnvironment('FLAVOR', defaultValue: 'development');
|
const environment = String.fromEnvironment(
|
||||||
|
'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(
|
||||||
@ -39,7 +41,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 {
|
||||||
String checkToken = await AuthBloc.getTokenAndValidate();
|
final 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;
|
||||||
|
|
||||||
@ -57,7 +59,7 @@ class MyApp extends StatelessWidget {
|
|||||||
BlocProvider<CreateRoutineBloc>(
|
BlocProvider<CreateRoutineBloc>(
|
||||||
create: (context) => CreateRoutineBloc(),
|
create: (context) => CreateRoutineBloc(),
|
||||||
),
|
),
|
||||||
BlocProvider(create: (context) => HomeBloc()..add(const FetchUserInfo())),
|
BlocProvider(create: (context) => HomeBloc()..add(FetchUserInfo())),
|
||||||
BlocProvider<VisitorPasswordBloc>(
|
BlocProvider<VisitorPasswordBloc>(
|
||||||
create: (context) => VisitorPasswordBloc(),
|
create: (context) => VisitorPasswordBloc(),
|
||||||
),
|
),
|
||||||
@ -65,7 +67,7 @@ class MyApp extends StatelessWidget {
|
|||||||
create: (context) => RoutineBloc(),
|
create: (context) => RoutineBloc(),
|
||||||
),
|
),
|
||||||
BlocProvider<SpaceTreeBloc>(
|
BlocProvider<SpaceTreeBloc>(
|
||||||
create: (context) => SpaceTreeBloc()..add(InitialEvent()),
|
create: (context) => SpaceTreeBloc(),
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
child: MaterialApp.router(
|
child: MaterialApp.router(
|
||||||
|
@ -11,7 +11,6 @@ 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';
|
||||||
@ -39,7 +38,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 {
|
||||||
String checkToken = await AuthBloc.getTokenAndValidate();
|
final 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;
|
||||||
|
|
||||||
@ -57,7 +56,7 @@ class MyApp extends StatelessWidget {
|
|||||||
BlocProvider<CreateRoutineBloc>(
|
BlocProvider<CreateRoutineBloc>(
|
||||||
create: (context) => CreateRoutineBloc(),
|
create: (context) => CreateRoutineBloc(),
|
||||||
),
|
),
|
||||||
BlocProvider(create: (context) => HomeBloc()..add(const FetchUserInfo())),
|
BlocProvider(create: (context) => HomeBloc()..add(FetchUserInfo())),
|
||||||
BlocProvider<VisitorPasswordBloc>(
|
BlocProvider<VisitorPasswordBloc>(
|
||||||
create: (context) => VisitorPasswordBloc(),
|
create: (context) => VisitorPasswordBloc(),
|
||||||
),
|
),
|
||||||
@ -65,7 +64,7 @@ class MyApp extends StatelessWidget {
|
|||||||
create: (context) => RoutineBloc(),
|
create: (context) => RoutineBloc(),
|
||||||
),
|
),
|
||||||
BlocProvider<SpaceTreeBloc>(
|
BlocProvider<SpaceTreeBloc>(
|
||||||
create: (context) => SpaceTreeBloc()..add(InitialEvent()),
|
create: (context) => SpaceTreeBloc(),
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
child: MaterialApp.router(
|
child: MaterialApp.router(
|
||||||
|
@ -15,7 +15,9 @@ class AirQualityDataModel extends Equatable {
|
|||||||
return AirQualityDataModel(
|
return AirQualityDataModel(
|
||||||
date: DateTime.parse(json['date'] as String),
|
date: DateTime.parse(json['date'] as String),
|
||||||
data: (json['data'] as List<dynamic>)
|
data: (json['data'] as List<dynamic>)
|
||||||
.map((e) => AirQualityPercentageData.fromJson(e as Map<String, dynamic>))
|
.map(
|
||||||
|
(e) => AirQualityPercentageData.fromJson(e as Map<String, dynamic>),
|
||||||
|
)
|
||||||
.toList(),
|
.toList(),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@ -23,9 +25,9 @@ class AirQualityDataModel extends Equatable {
|
|||||||
static final Map<String, Color> metricColors = {
|
static final Map<String, Color> metricColors = {
|
||||||
'good': ColorsManager.goodGreen.withValues(alpha: 0.7),
|
'good': ColorsManager.goodGreen.withValues(alpha: 0.7),
|
||||||
'moderate': ColorsManager.moderateYellow.withValues(alpha: 0.7),
|
'moderate': ColorsManager.moderateYellow.withValues(alpha: 0.7),
|
||||||
'poor': ColorsManager.poorOrange.withValues(alpha: 0.7),
|
'unhealthy_sensitive': ColorsManager.poorOrange.withValues(alpha: 0.7),
|
||||||
'unhealthy': ColorsManager.unhealthyRed.withValues(alpha: 0.7),
|
'unhealthy': ColorsManager.unhealthyRed.withValues(alpha: 0.7),
|
||||||
'severe': ColorsManager.severePink.withValues(alpha: 0.7),
|
'very_unhealthy': ColorsManager.severePink.withValues(alpha: 0.7),
|
||||||
'hazardous': ColorsManager.hazardousPurple.withValues(alpha: 0.7),
|
'hazardous': ColorsManager.hazardousPurple.withValues(alpha: 0.7),
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -36,22 +38,19 @@ class AirQualityDataModel extends Equatable {
|
|||||||
class AirQualityPercentageData extends Equatable {
|
class AirQualityPercentageData extends Equatable {
|
||||||
const AirQualityPercentageData({
|
const AirQualityPercentageData({
|
||||||
required this.type,
|
required this.type,
|
||||||
required this.name,
|
|
||||||
required this.percentage,
|
required this.percentage,
|
||||||
});
|
});
|
||||||
|
|
||||||
final String type;
|
final String type;
|
||||||
final String name;
|
|
||||||
final double percentage;
|
final double percentage;
|
||||||
|
|
||||||
factory AirQualityPercentageData.fromJson(Map<String, dynamic> json) {
|
factory AirQualityPercentageData.fromJson(Map<String, dynamic> json) {
|
||||||
return AirQualityPercentageData(
|
return AirQualityPercentageData(
|
||||||
type: json['type'] as String? ?? '',
|
type: json['type'] as String? ?? '',
|
||||||
name: json['name'] as String? ?? '',
|
|
||||||
percentage: (json['percentage'] as num?)?.toDouble() ?? 0,
|
percentage: (json['percentage'] as num?)?.toDouble() ?? 0,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
List<Object?> get props => [type, name, percentage];
|
List<Object?> get props => [type, percentage];
|
||||||
}
|
}
|
||||||
|
@ -33,7 +33,6 @@ class AirQualityDistributionBloc
|
|||||||
state.copyWith(
|
state.copyWith(
|
||||||
status: AirQualityDistributionStatus.success,
|
status: AirQualityDistributionStatus.success,
|
||||||
chartData: result,
|
chartData: result,
|
||||||
filteredChartData: _arrangeChartDataByType(result, state.selectedAqiType),
|
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
@ -58,24 +57,6 @@ class AirQualityDistributionBloc
|
|||||||
UpdateAqiTypeEvent event,
|
UpdateAqiTypeEvent event,
|
||||||
Emitter<AirQualityDistributionState> emit,
|
Emitter<AirQualityDistributionState> emit,
|
||||||
) {
|
) {
|
||||||
emit(
|
emit(state.copyWith(selectedAqiType: event.aqiType));
|
||||||
state.copyWith(
|
|
||||||
selectedAqiType: event.aqiType,
|
|
||||||
filteredChartData: _arrangeChartDataByType(state.chartData, event.aqiType),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
List<AirQualityDataModel> _arrangeChartDataByType(
|
|
||||||
List<AirQualityDataModel> data,
|
|
||||||
AqiType aqiType,
|
|
||||||
) {
|
|
||||||
final filteredData = data.map(
|
|
||||||
(data) => AirQualityDataModel(
|
|
||||||
date: data.date,
|
|
||||||
data: data.data.where((value) => value.type == aqiType.code).toList(),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
return filteredData.toList();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -11,28 +11,24 @@ class AirQualityDistributionState extends Equatable {
|
|||||||
const AirQualityDistributionState({
|
const AirQualityDistributionState({
|
||||||
this.status = AirQualityDistributionStatus.initial,
|
this.status = AirQualityDistributionStatus.initial,
|
||||||
this.chartData = const [],
|
this.chartData = const [],
|
||||||
this.filteredChartData = const [],
|
|
||||||
this.errorMessage,
|
this.errorMessage,
|
||||||
this.selectedAqiType = AqiType.aqi,
|
this.selectedAqiType = AqiType.aqi,
|
||||||
});
|
});
|
||||||
|
|
||||||
final AirQualityDistributionStatus status;
|
final AirQualityDistributionStatus status;
|
||||||
final List<AirQualityDataModel> chartData;
|
final List<AirQualityDataModel> chartData;
|
||||||
final List<AirQualityDataModel> filteredChartData;
|
|
||||||
final String? errorMessage;
|
final String? errorMessage;
|
||||||
final AqiType selectedAqiType;
|
final AqiType selectedAqiType;
|
||||||
|
|
||||||
AirQualityDistributionState copyWith({
|
AirQualityDistributionState copyWith({
|
||||||
AirQualityDistributionStatus? status,
|
AirQualityDistributionStatus? status,
|
||||||
List<AirQualityDataModel>? chartData,
|
List<AirQualityDataModel>? chartData,
|
||||||
List<AirQualityDataModel>? filteredChartData,
|
|
||||||
String? errorMessage,
|
String? errorMessage,
|
||||||
AqiType? selectedAqiType,
|
AqiType? selectedAqiType,
|
||||||
}) {
|
}) {
|
||||||
return AirQualityDistributionState(
|
return AirQualityDistributionState(
|
||||||
status: status ?? this.status,
|
status: status ?? this.status,
|
||||||
chartData: chartData ?? this.chartData,
|
chartData: chartData ?? this.chartData,
|
||||||
filteredChartData: filteredChartData ?? this.filteredChartData,
|
|
||||||
errorMessage: errorMessage ?? this.errorMessage,
|
errorMessage: errorMessage ?? this.errorMessage,
|
||||||
selectedAqiType: selectedAqiType ?? this.selectedAqiType,
|
selectedAqiType: selectedAqiType ?? this.selectedAqiType,
|
||||||
);
|
);
|
||||||
|
@ -3,6 +3,7 @@ import 'package:flutter_bloc/flutter_bloc.dart';
|
|||||||
import 'package:syncrow_web/pages/analytics/modules/air_quality/blocs/air_quality_distribution/air_quality_distribution_bloc.dart';
|
import 'package:syncrow_web/pages/analytics/modules/air_quality/blocs/air_quality_distribution/air_quality_distribution_bloc.dart';
|
||||||
import 'package:syncrow_web/pages/analytics/modules/air_quality/blocs/device_location/device_location_bloc.dart';
|
import 'package:syncrow_web/pages/analytics/modules/air_quality/blocs/device_location/device_location_bloc.dart';
|
||||||
import 'package:syncrow_web/pages/analytics/modules/air_quality/blocs/range_of_aqi/range_of_aqi_bloc.dart';
|
import 'package:syncrow_web/pages/analytics/modules/air_quality/blocs/range_of_aqi/range_of_aqi_bloc.dart';
|
||||||
|
import 'package:syncrow_web/pages/analytics/modules/air_quality/widgets/aqi_type_dropdown.dart';
|
||||||
import 'package:syncrow_web/pages/analytics/modules/analytics/blocs/analytics_date_picker_bloc/analytics_date_picker_bloc.dart';
|
import 'package:syncrow_web/pages/analytics/modules/analytics/blocs/analytics_date_picker_bloc/analytics_date_picker_bloc.dart';
|
||||||
import 'package:syncrow_web/pages/analytics/modules/analytics/blocs/analytics_devices/analytics_devices_bloc.dart';
|
import 'package:syncrow_web/pages/analytics/modules/analytics/blocs/analytics_devices/analytics_devices_bloc.dart';
|
||||||
import 'package:syncrow_web/pages/analytics/modules/energy_management/blocs/realtime_device_changes/realtime_device_changes_bloc.dart';
|
import 'package:syncrow_web/pages/analytics/modules/energy_management/blocs/realtime_device_changes/realtime_device_changes_bloc.dart';
|
||||||
@ -22,6 +23,7 @@ abstract final class FetchAirQualityDataHelper {
|
|||||||
bool shouldFetchAnalyticsDevices = true,
|
bool shouldFetchAnalyticsDevices = true,
|
||||||
}) {
|
}) {
|
||||||
final date = context.read<AnalyticsDatePickerBloc>().state.monthlyDate;
|
final date = context.read<AnalyticsDatePickerBloc>().state.monthlyDate;
|
||||||
|
final aqiType = context.read<AirQualityDistributionBloc>().state.selectedAqiType;
|
||||||
loadAnalyticsDevices(
|
loadAnalyticsDevices(
|
||||||
context,
|
context,
|
||||||
communityUuid: communityUuid,
|
communityUuid: communityUuid,
|
||||||
@ -36,6 +38,7 @@ abstract final class FetchAirQualityDataHelper {
|
|||||||
context,
|
context,
|
||||||
spaceUuid: spaceUuid,
|
spaceUuid: spaceUuid,
|
||||||
date: date,
|
date: date,
|
||||||
|
aqiType: aqiType,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -104,10 +107,15 @@ abstract final class FetchAirQualityDataHelper {
|
|||||||
BuildContext context, {
|
BuildContext context, {
|
||||||
required String spaceUuid,
|
required String spaceUuid,
|
||||||
required DateTime date,
|
required DateTime date,
|
||||||
|
required AqiType aqiType,
|
||||||
}) {
|
}) {
|
||||||
context.read<AirQualityDistributionBloc>().add(
|
context.read<AirQualityDistributionBloc>().add(
|
||||||
LoadAirQualityDistribution(
|
LoadAirQualityDistribution(
|
||||||
GetAirQualityDistributionParam(spaceUuid: spaceUuid, date: date),
|
GetAirQualityDistributionParam(
|
||||||
|
spaceUuid: spaceUuid,
|
||||||
|
date: date,
|
||||||
|
aqiType: aqiType,
|
||||||
|
),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -16,11 +16,6 @@ class AqiDistributionChart extends StatelessWidget {
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
final sortedData = List<AirQualityDataModel>.from(chartData)
|
|
||||||
..sort(
|
|
||||||
(a, b) => a.date.compareTo(b.date),
|
|
||||||
);
|
|
||||||
|
|
||||||
return BarChart(
|
return BarChart(
|
||||||
BarChartData(
|
BarChartData(
|
||||||
maxY: 100.1,
|
maxY: 100.1,
|
||||||
@ -30,29 +25,25 @@ class AqiDistributionChart extends StatelessWidget {
|
|||||||
borderData: EnergyManagementChartsHelper.borderData(),
|
borderData: EnergyManagementChartsHelper.borderData(),
|
||||||
barTouchData: _barTouchData(context),
|
barTouchData: _barTouchData(context),
|
||||||
titlesData: _titlesData(context),
|
titlesData: _titlesData(context),
|
||||||
barGroups: _buildBarGroups(sortedData),
|
barGroups: _buildBarGroups(),
|
||||||
),
|
),
|
||||||
duration: Duration.zero,
|
duration: Duration.zero,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
List<BarChartGroupData> _buildBarGroups(List<AirQualityDataModel> sortedData) {
|
List<BarChartGroupData> _buildBarGroups() {
|
||||||
return List.generate(sortedData.length, (index) {
|
return List.generate(chartData.length, (index) {
|
||||||
final data = sortedData[index];
|
final data = chartData[index];
|
||||||
final stackItems = <BarChartRodData>[];
|
final stackItems = <BarChartRodData>[];
|
||||||
double currentY = 0;
|
double currentY = 0;
|
||||||
bool isFirstElement = true;
|
var isFirstElement = true;
|
||||||
|
|
||||||
// Sort data by type to ensure consistent order
|
for (final percentageData in data.data) {
|
||||||
final sortedPercentageData = List<AirQualityPercentageData>.from(data.data)
|
|
||||||
..sort((a, b) => a.type.compareTo(b.type));
|
|
||||||
|
|
||||||
for (final percentageData in sortedPercentageData) {
|
|
||||||
stackItems.add(
|
stackItems.add(
|
||||||
BarChartRodData(
|
BarChartRodData(
|
||||||
fromY: currentY,
|
fromY: currentY,
|
||||||
toY: currentY + percentageData.percentage ,
|
toY: currentY + percentageData.percentage,
|
||||||
color: AirQualityDataModel.metricColors[percentageData.name]!,
|
color: AirQualityDataModel.metricColors[percentageData.type],
|
||||||
borderRadius: isFirstElement
|
borderRadius: isFirstElement
|
||||||
? const BorderRadius.only(
|
? const BorderRadius.only(
|
||||||
topLeft: Radius.circular(22),
|
topLeft: Radius.circular(22),
|
||||||
@ -84,23 +75,21 @@ class AqiDistributionChart extends StatelessWidget {
|
|||||||
tooltipRoundedRadius: 16,
|
tooltipRoundedRadius: 16,
|
||||||
tooltipPadding: const EdgeInsets.all(8),
|
tooltipPadding: const EdgeInsets.all(8),
|
||||||
getTooltipItem: (group, groupIndex, rod, rodIndex) {
|
getTooltipItem: (group, groupIndex, rod, rodIndex) {
|
||||||
final data = chartData[group.x.toInt()];
|
final data = chartData[group.x];
|
||||||
|
|
||||||
final List<TextSpan> children = [];
|
final children = <TextSpan>[];
|
||||||
|
|
||||||
final textStyle = context.textTheme.bodySmall?.copyWith(
|
final textStyle = context.textTheme.bodySmall?.copyWith(
|
||||||
color: ColorsManager.blackColor,
|
color: ColorsManager.blackColor,
|
||||||
fontSize: 12,
|
fontSize: 8,
|
||||||
);
|
);
|
||||||
|
|
||||||
// Sort data by type to ensure consistent order
|
for (final percentageData in data.data) {
|
||||||
final sortedPercentageData = List<AirQualityPercentageData>.from(data.data)
|
final percentage = percentageData.percentage.toStringAsFixed(1);
|
||||||
..sort((a, b) => a.type.compareTo(b.type));
|
final type = percentageData.type[0].toUpperCase() +
|
||||||
|
percentageData.type.substring(1).replaceAll('_', ' ');
|
||||||
for (final percentageData in sortedPercentageData) {
|
|
||||||
children.add(TextSpan(
|
children.add(TextSpan(
|
||||||
text:
|
text: '\n$type: $percentage%',
|
||||||
'\n${percentageData.type.toUpperCase()}: ${percentageData.percentage.toStringAsFixed(1)}%',
|
|
||||||
style: textStyle,
|
style: textStyle,
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
@ -109,9 +98,10 @@ class AqiDistributionChart extends StatelessWidget {
|
|||||||
DateFormat('dd/MM/yyyy').format(data.date),
|
DateFormat('dd/MM/yyyy').format(data.date),
|
||||||
context.textTheme.bodyMedium!.copyWith(
|
context.textTheme.bodyMedium!.copyWith(
|
||||||
color: ColorsManager.blackColor,
|
color: ColorsManager.blackColor,
|
||||||
fontSize: 16,
|
fontSize: 9,
|
||||||
fontWeight: FontWeight.w600,
|
fontWeight: FontWeight.w600,
|
||||||
),
|
),
|
||||||
|
textAlign: TextAlign.start,
|
||||||
children: children,
|
children: children,
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
|
@ -33,7 +33,7 @@ class AqiDistributionChartBox extends StatelessWidget {
|
|||||||
const Divider(),
|
const Divider(),
|
||||||
const SizedBox(height: 20),
|
const SizedBox(height: 20),
|
||||||
Expanded(
|
Expanded(
|
||||||
child: AqiDistributionChart(chartData: state.filteredChartData),
|
child: AqiDistributionChart(chartData: state.chartData),
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
|
@ -2,8 +2,11 @@ import 'package:flutter/material.dart';
|
|||||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||||
import 'package:syncrow_web/pages/analytics/modules/air_quality/blocs/air_quality_distribution/air_quality_distribution_bloc.dart';
|
import 'package:syncrow_web/pages/analytics/modules/air_quality/blocs/air_quality_distribution/air_quality_distribution_bloc.dart';
|
||||||
import 'package:syncrow_web/pages/analytics/modules/air_quality/widgets/aqi_type_dropdown.dart';
|
import 'package:syncrow_web/pages/analytics/modules/air_quality/widgets/aqi_type_dropdown.dart';
|
||||||
|
import 'package:syncrow_web/pages/analytics/modules/analytics/blocs/analytics_date_picker_bloc/analytics_date_picker_bloc.dart';
|
||||||
import 'package:syncrow_web/pages/analytics/modules/energy_management/widgets/chart_title.dart';
|
import 'package:syncrow_web/pages/analytics/modules/energy_management/widgets/chart_title.dart';
|
||||||
|
import 'package:syncrow_web/pages/analytics/params/get_air_quality_distribution_param.dart';
|
||||||
import 'package:syncrow_web/pages/analytics/widgets/charts_loading_widget.dart';
|
import 'package:syncrow_web/pages/analytics/widgets/charts_loading_widget.dart';
|
||||||
|
import 'package:syncrow_web/pages/space_tree/bloc/space_tree_bloc.dart';
|
||||||
|
|
||||||
class AqiDistributionChartTitle extends StatelessWidget {
|
class AqiDistributionChartTitle extends StatelessWidget {
|
||||||
const AqiDistributionChartTitle({required this.isLoading, super.key});
|
const AqiDistributionChartTitle({required this.isLoading, super.key});
|
||||||
@ -31,9 +34,15 @@ class AqiDistributionChartTitle extends StatelessWidget {
|
|||||||
child: AqiTypeDropdown(
|
child: AqiTypeDropdown(
|
||||||
onChanged: (value) {
|
onChanged: (value) {
|
||||||
if (value != null) {
|
if (value != null) {
|
||||||
context
|
final bloc = context.read<AirQualityDistributionBloc>();
|
||||||
.read<AirQualityDistributionBloc>()
|
try {
|
||||||
.add(UpdateAqiTypeEvent(value));
|
final param = _makeLoadAqiDistributionParam(context, value);
|
||||||
|
bloc.add(LoadAirQualityDistribution(param));
|
||||||
|
} catch (_) {
|
||||||
|
return;
|
||||||
|
} finally {
|
||||||
|
bloc.add(UpdateAqiTypeEvent(value));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
@ -41,4 +50,19 @@ class AqiDistributionChartTitle extends StatelessWidget {
|
|||||||
],
|
],
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
GetAirQualityDistributionParam _makeLoadAqiDistributionParam(
|
||||||
|
BuildContext context,
|
||||||
|
AqiType aqiType,
|
||||||
|
) {
|
||||||
|
final date = context.read<AnalyticsDatePickerBloc>().state.monthlyDate;
|
||||||
|
final spaceUuid =
|
||||||
|
context.read<SpaceTreeBloc>().state.selectedSpaces.firstOrNull ?? '';
|
||||||
|
if (spaceUuid.isEmpty) throw Exception('Space UUID is empty');
|
||||||
|
return GetAirQualityDistributionParam(
|
||||||
|
date: date,
|
||||||
|
spaceUuid: spaceUuid,
|
||||||
|
aqiType: aqiType,
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -6,8 +6,8 @@ enum AqiType {
|
|||||||
aqi('AQI', '', 'aqi'),
|
aqi('AQI', '', 'aqi'),
|
||||||
pm25('PM2.5', 'µg/m³', 'pm25'),
|
pm25('PM2.5', 'µg/m³', 'pm25'),
|
||||||
pm10('PM10', 'µg/m³', 'pm10'),
|
pm10('PM10', 'µg/m³', 'pm10'),
|
||||||
hcho('HCHO', 'mg/m³', 'hcho'),
|
hcho('HCHO', 'mg/m³', 'cho2'),
|
||||||
tvoc('TVOC', 'µg/m³', 'tvoc'),
|
tvoc('TVOC', 'µg/m³', 'voc'),
|
||||||
co2('CO2', 'ppm', 'co2');
|
co2('CO2', 'ppm', 'co2');
|
||||||
|
|
||||||
const AqiType(this.value, this.unit, this.code);
|
const AqiType(this.value, this.unit, this.code);
|
||||||
|
@ -63,7 +63,7 @@ class RangeOfAqiChart extends StatelessWidget {
|
|||||||
gradient: LinearGradient(
|
gradient: LinearGradient(
|
||||||
begin: Alignment.bottomCenter,
|
begin: Alignment.bottomCenter,
|
||||||
end: Alignment.topCenter,
|
end: Alignment.topCenter,
|
||||||
stops: [0.0, 0.2, 0.4, 0.6, 0.8, 1.0],
|
stops: const [0.0, 0.2, 0.4, 0.6, 0.8, 1.0],
|
||||||
colors: RangeOfAqiChartsHelper.gradientData.map((e) {
|
colors: RangeOfAqiChartsHelper.gradientData.map((e) {
|
||||||
final (color, _) = e;
|
final (color, _) = e;
|
||||||
return color.withValues(alpha: 0.6);
|
return color.withValues(alpha: 0.6);
|
||||||
|
@ -16,7 +16,7 @@ import 'package:syncrow_web/pages/analytics/modules/energy_management/blocs/real
|
|||||||
import 'package:syncrow_web/pages/analytics/modules/energy_management/blocs/total_energy_consumption/total_energy_consumption_bloc.dart';
|
import 'package:syncrow_web/pages/analytics/modules/energy_management/blocs/total_energy_consumption/total_energy_consumption_bloc.dart';
|
||||||
import 'package:syncrow_web/pages/analytics/modules/occupancy/blocs/occupancy/occupancy_bloc.dart';
|
import 'package:syncrow_web/pages/analytics/modules/occupancy/blocs/occupancy/occupancy_bloc.dart';
|
||||||
import 'package:syncrow_web/pages/analytics/modules/occupancy/blocs/occupancy_heat_map/occupancy_heat_map_bloc.dart';
|
import 'package:syncrow_web/pages/analytics/modules/occupancy/blocs/occupancy_heat_map/occupancy_heat_map_bloc.dart';
|
||||||
import 'package:syncrow_web/pages/analytics/services/air_quality_distribution/fake_air_quality_distribution_service.dart';
|
import 'package:syncrow_web/pages/analytics/services/air_quality_distribution/remote_air_quality_distribution_service.dart';
|
||||||
import 'package:syncrow_web/pages/analytics/services/analytics_devices/analytics_devices_service_delagate.dart';
|
import 'package:syncrow_web/pages/analytics/services/analytics_devices/analytics_devices_service_delagate.dart';
|
||||||
import 'package:syncrow_web/pages/analytics/services/analytics_devices/remote_energy_management_analytics_devices_service.dart';
|
import 'package:syncrow_web/pages/analytics/services/analytics_devices/remote_energy_management_analytics_devices_service.dart';
|
||||||
import 'package:syncrow_web/pages/analytics/services/analytics_devices/remote_occupancy_analytics_devices_service.dart';
|
import 'package:syncrow_web/pages/analytics/services/analytics_devices/remote_occupancy_analytics_devices_service.dart';
|
||||||
@ -27,10 +27,12 @@ import 'package:syncrow_web/pages/analytics/services/energy_consumption_per_devi
|
|||||||
import 'package:syncrow_web/pages/analytics/services/occupacy/remote_occupancy_service.dart';
|
import 'package:syncrow_web/pages/analytics/services/occupacy/remote_occupancy_service.dart';
|
||||||
import 'package:syncrow_web/pages/analytics/services/occupancy_heat_map/remote_occupancy_heat_map_service.dart';
|
import 'package:syncrow_web/pages/analytics/services/occupancy_heat_map/remote_occupancy_heat_map_service.dart';
|
||||||
import 'package:syncrow_web/pages/analytics/services/power_clamp_info/remote_power_clamp_info_service.dart';
|
import 'package:syncrow_web/pages/analytics/services/power_clamp_info/remote_power_clamp_info_service.dart';
|
||||||
import 'package:syncrow_web/pages/analytics/services/range_of_aqi/fake_range_of_aqi_service.dart';
|
import 'package:syncrow_web/pages/analytics/services/range_of_aqi/remote_range_of_aqi_service.dart';
|
||||||
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';
|
||||||
@ -104,12 +106,12 @@ class _AnalyticsPageState extends State<AnalyticsPage> {
|
|||||||
),
|
),
|
||||||
BlocProvider(
|
BlocProvider(
|
||||||
create: (context) => RangeOfAqiBloc(
|
create: (context) => RangeOfAqiBloc(
|
||||||
FakeRangeOfAqiService(),
|
RemoteRangeOfAqiService(_httpService),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
BlocProvider(
|
BlocProvider(
|
||||||
create: (context) => AirQualityDistributionBloc(
|
create: (context) => AirQualityDistributionBloc(
|
||||||
FakeAirQualityDistributionService(),
|
RemoteAirQualityDistributionService(_httpService),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
BlocProvider(
|
BlocProvider(
|
||||||
@ -130,9 +132,19 @@ class _AnalyticsPageState extends State<AnalyticsPage> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class AnalyticsPageForm extends StatelessWidget {
|
class AnalyticsPageForm extends StatefulWidget {
|
||||||
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(
|
||||||
|
@ -20,7 +20,7 @@ class AnalyticsDateFilterButton extends StatefulWidget {
|
|||||||
final void Function(DateTime)? onDateSelected;
|
final void Function(DateTime)? onDateSelected;
|
||||||
final DatePickerType datePickerType;
|
final DatePickerType datePickerType;
|
||||||
|
|
||||||
static final _color = ColorsManager.blackColor.withValues(alpha: 0.8);
|
static final Color _color = ColorsManager.blackColor.withValues(alpha: 0.8);
|
||||||
|
|
||||||
@override
|
@override
|
||||||
State<AnalyticsDateFilterButton> createState() =>
|
State<AnalyticsDateFilterButton> createState() =>
|
||||||
@ -60,23 +60,21 @@ class _AnalyticsDateFilterButtonState extends State<AnalyticsDateFilterButton> {
|
|||||||
),
|
),
|
||||||
),
|
),
|
||||||
onPressed: () {
|
onPressed: () {
|
||||||
showDialog(
|
showDialog<void>(
|
||||||
context: context,
|
context: context,
|
||||||
builder: (_) {
|
builder: (_) => switch (widget.datePickerType) {
|
||||||
return switch (widget.datePickerType) {
|
DatePickerType.month => MonthPickerWidget(
|
||||||
DatePickerType.month => MonthPickerWidget(
|
selectedDate: widget.selectedDate,
|
||||||
selectedDate: widget.selectedDate,
|
onDateSelected: (value) {
|
||||||
onDateSelected: (value) {
|
widget.onDateSelected?.call(value);
|
||||||
widget.onDateSelected?.call(value);
|
},
|
||||||
},
|
),
|
||||||
),
|
DatePickerType.year => YearPickerWidget(
|
||||||
DatePickerType.year => YearPickerWidget(
|
selectedDate: widget.selectedDate,
|
||||||
selectedDate: widget.selectedDate,
|
onDateSelected: (value) {
|
||||||
onDateSelected: (value) {
|
widget.onDateSelected?.call(value);
|
||||||
widget.onDateSelected?.call(value);
|
},
|
||||||
},
|
),
|
||||||
),
|
|
||||||
};
|
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
|
@ -118,7 +118,7 @@ class AnalyticsPageTabsAndChildren extends StatelessWidget {
|
|||||||
communityUuid: communities.firstOrNull ?? '',
|
communityUuid: communities.firstOrNull ?? '',
|
||||||
spaceUuid: spaces.firstOrNull ?? '',
|
spaceUuid: spaces.firstOrNull ?? '',
|
||||||
);
|
);
|
||||||
break;
|
return;
|
||||||
case AnalyticsPageTab.airQuality:
|
case AnalyticsPageTab.airQuality:
|
||||||
_onAirQualityDateChanged(
|
_onAirQualityDateChanged(
|
||||||
context,
|
context,
|
||||||
@ -126,8 +126,9 @@ class AnalyticsPageTabsAndChildren extends StatelessWidget {
|
|||||||
communityUuid: communities.firstOrNull ?? '',
|
communityUuid: communities.firstOrNull ?? '',
|
||||||
spaceUuid: spaces.firstOrNull ?? '',
|
spaceUuid: spaces.firstOrNull ?? '',
|
||||||
);
|
);
|
||||||
|
return;
|
||||||
default:
|
default:
|
||||||
break;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -157,6 +158,7 @@ class AnalyticsPageTabsAndChildren extends StatelessWidget {
|
|||||||
required String communityUuid,
|
required String communityUuid,
|
||||||
required String spaceUuid,
|
required String spaceUuid,
|
||||||
}) {
|
}) {
|
||||||
|
if (spaceUuid.isEmpty) return;
|
||||||
FetchAirQualityDataHelper.loadAirQualityData(
|
FetchAirQualityDataHelper.loadAirQualityData(
|
||||||
context,
|
context,
|
||||||
date: date,
|
date: date,
|
||||||
|
@ -38,7 +38,7 @@ abstract final class EnergyManagementChartsHelper {
|
|||||||
sideTitles: SideTitles(
|
sideTitles: SideTitles(
|
||||||
showTitles: true,
|
showTitles: true,
|
||||||
maxIncluded: false,
|
maxIncluded: false,
|
||||||
minIncluded: true,
|
minIncluded: false,
|
||||||
interval: leftTitlesInterval,
|
interval: leftTitlesInterval,
|
||||||
reservedSize: 110,
|
reservedSize: 110,
|
||||||
getTitlesWidget: (value, meta) => Padding(
|
getTitlesWidget: (value, meta) => Padding(
|
||||||
|
@ -46,7 +46,7 @@ class AnalyticsEnergyManagementView extends StatelessWidget {
|
|||||||
spacing: 32,
|
spacing: 32,
|
||||||
children: [
|
children: [
|
||||||
Expanded(
|
Expanded(
|
||||||
flex: 2,
|
flex: 7,
|
||||||
child: Column(
|
child: Column(
|
||||||
spacing: 20,
|
spacing: 20,
|
||||||
children: [
|
children: [
|
||||||
@ -55,7 +55,7 @@ class AnalyticsEnergyManagementView extends StatelessWidget {
|
|||||||
],
|
],
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
Expanded(child: PowerClampEnergyDataWidget()),
|
Expanded(flex: 4, child: PowerClampEnergyDataWidget()),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
@ -31,12 +31,12 @@ class AnalyticsOccupancyView extends StatelessWidget {
|
|||||||
return SingleChildScrollView(
|
return SingleChildScrollView(
|
||||||
child: Container(
|
child: Container(
|
||||||
padding: _padding,
|
padding: _padding,
|
||||||
height: height * 0.9,
|
height: height * 1,
|
||||||
child: const Row(
|
child: const Row(
|
||||||
spacing: 32,
|
spacing: 32,
|
||||||
children: [
|
children: [
|
||||||
Expanded(
|
Expanded(
|
||||||
flex: 5,
|
flex: 7,
|
||||||
child: Column(
|
child: Column(
|
||||||
spacing: 20,
|
spacing: 20,
|
||||||
children: [
|
children: [
|
||||||
@ -45,7 +45,7 @@ class AnalyticsOccupancyView extends StatelessWidget {
|
|||||||
],
|
],
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
Expanded(flex: 2, child: OccupancyEndSideBar()),
|
Expanded(flex: 4, child: OccupancyEndSideBar()),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
@ -24,37 +24,45 @@ class OccupancyEndSideBar extends StatelessWidget {
|
|||||||
crossAxisAlignment: CrossAxisAlignment.start,
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
children: [
|
children: [
|
||||||
const AnalyticsSidebarHeader(title: 'Presnce Sensor'),
|
const AnalyticsSidebarHeader(title: 'Presnce Sensor'),
|
||||||
SizedBox(
|
Expanded(
|
||||||
height: MediaQuery.sizeOf(context).height * 0.2,
|
child: SizedBox(
|
||||||
child: PowerClampEnergyStatusWidget(
|
// height: MediaQuery.sizeOf(context).height * 0.2,
|
||||||
status: [
|
child: PowerClampEnergyStatusWidget(
|
||||||
PowerClampEnergyStatus(
|
status: [
|
||||||
iconPath: Assets.presenceState,
|
PowerClampEnergyStatus(
|
||||||
title: 'Presence Status',
|
iconPath: Assets.presenceState,
|
||||||
value: _valueFromCode(
|
title: 'Presence Status',
|
||||||
'presence_state',
|
value: _valueFromCode(
|
||||||
state.deviceStatusList,
|
'presence_state',
|
||||||
|
state.deviceStatusList,
|
||||||
|
),
|
||||||
|
unit: '',
|
||||||
),
|
),
|
||||||
unit: '',
|
PowerClampEnergyStatus(
|
||||||
),
|
iconPath: Assets.presenceTimeIcon,
|
||||||
PowerClampEnergyStatus(
|
title: 'Presence Time',
|
||||||
iconPath: Assets.presenceTimeIcon,
|
value:
|
||||||
title: 'Presence Time',
|
'${_valueFromCode('none_body_time', state.deviceStatusList)} Min',
|
||||||
value:
|
unit: '',
|
||||||
'${_valueFromCode('none_body_time', state.deviceStatusList)} Min',
|
),
|
||||||
unit: '',
|
PowerClampEnergyStatus(
|
||||||
),
|
iconPath: Assets.currentDistanceIcon,
|
||||||
PowerClampEnergyStatus(
|
title: 'Detection Distance',
|
||||||
iconPath: Assets.currentDistanceIcon,
|
value:
|
||||||
title: 'Detection Distance',
|
'${_valueFromCode('space_move_val', state.deviceStatusList)} M',
|
||||||
value:
|
unit: '',
|
||||||
'${_valueFromCode('space_move_val', state.deviceStatusList)} M',
|
),
|
||||||
unit: '',
|
],
|
||||||
),
|
),
|
||||||
],
|
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
const SizedBox(height: 20),
|
const SizedBox(height: 20),
|
||||||
|
Expanded(
|
||||||
|
flex: 2,
|
||||||
|
child: FittedBox(
|
||||||
|
child: Image.asset(Assets.autocadOccupancyImage),
|
||||||
|
),
|
||||||
|
),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
@ -34,8 +34,8 @@ class OccupancyHeatMapGradient extends StatelessWidget {
|
|||||||
width: 1,
|
width: 1,
|
||||||
),
|
),
|
||||||
gradient: LinearGradient(
|
gradient: LinearGradient(
|
||||||
begin: AlignmentDirectional.centerEnd,
|
begin: AlignmentDirectional.centerStart,
|
||||||
end: AlignmentDirectional.centerStart,
|
end: AlignmentDirectional.centerEnd,
|
||||||
colors: _heatMapColors(),
|
colors: _heatMapColors(),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
@ -28,11 +28,11 @@ class OccupancyPainter extends CustomPainter {
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
void paint(Canvas canvas, Size size) {
|
void paint(Canvas canvas, Size size) {
|
||||||
final Paint fillPaint = Paint();
|
final fillPaint = Paint();
|
||||||
final Paint borderPaint = Paint()
|
final borderPaint = Paint()
|
||||||
..color = ColorsManager.grayBorder.withValues(alpha: 0.4)
|
..color = ColorsManager.grayBorder.withValues(alpha: 0.4)
|
||||||
..style = PaintingStyle.stroke;
|
..style = PaintingStyle.stroke;
|
||||||
final Paint hoveredBorderPaint = Paint()
|
final hoveredBorderPaint = Paint()
|
||||||
..color = Colors.black
|
..color = Colors.black
|
||||||
..style = PaintingStyle.stroke
|
..style = PaintingStyle.stroke
|
||||||
..strokeWidth = 1.5;
|
..strokeWidth = 1.5;
|
||||||
@ -48,7 +48,6 @@ class OccupancyPainter extends CustomPainter {
|
|||||||
final rect = Rect.fromLTWH(x, y, cellSize, cellSize);
|
final rect = Rect.fromLTWH(x, y, cellSize, cellSize);
|
||||||
canvas.drawRect(rect, fillPaint);
|
canvas.drawRect(rect, fillPaint);
|
||||||
|
|
||||||
// Highlight the hovered item
|
|
||||||
if (hoveredItem != null && hoveredItem!.index == item.index) {
|
if (hoveredItem != null && hoveredItem!.index == item.index) {
|
||||||
canvas.drawRect(rect, hoveredBorderPaint);
|
canvas.drawRect(rect, hoveredBorderPaint);
|
||||||
} else {
|
} else {
|
||||||
@ -73,16 +72,16 @@ class OccupancyPainter extends CustomPainter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void _drawDashedLine(Canvas canvas, Offset start, Offset end, Paint paint) {
|
void _drawDashedLine(Canvas canvas, Offset start, Offset end, Paint paint) {
|
||||||
const double dashWidth = 2.0;
|
const dashWidth = 2.0;
|
||||||
const double dashSpace = 4.0;
|
const dashSpace = 4.0;
|
||||||
final double totalLength = (end - start).distance;
|
final totalLength = (end - start).distance;
|
||||||
final Offset direction = (end - start) / (end - start).distance;
|
final direction = (end - start) / (end - start).distance;
|
||||||
|
|
||||||
double currentLength = 0.0;
|
var currentLength = 0.0;
|
||||||
while (currentLength < totalLength) {
|
while (currentLength < totalLength) {
|
||||||
final Offset dashStart = start + direction * currentLength;
|
final dashStart = start + direction * currentLength;
|
||||||
final double nextLength = currentLength + dashWidth;
|
final nextLength = currentLength + dashWidth;
|
||||||
final Offset dashEnd =
|
final dashEnd =
|
||||||
start + direction * (nextLength < totalLength ? nextLength : totalLength);
|
start + direction * (nextLength < totalLength ? nextLength : totalLength);
|
||||||
canvas.drawLine(dashStart, dashEnd, paint);
|
canvas.drawLine(dashStart, dashEnd, paint);
|
||||||
currentLength = nextLength + dashSpace;
|
currentLength = nextLength + dashSpace;
|
||||||
@ -91,8 +90,9 @@ class OccupancyPainter extends CustomPainter {
|
|||||||
|
|
||||||
Color _getColor(int value) {
|
Color _getColor(int value) {
|
||||||
if (maxValue == 0) return ColorsManager.vividBlue.withValues(alpha: 0);
|
if (maxValue == 0) return ColorsManager.vividBlue.withValues(alpha: 0);
|
||||||
final opacity = value.clamp(0, maxValue) / maxValue;
|
final clampedValue = 0.075 + (1 * value.clamp(0, maxValue) / maxValue);
|
||||||
return ColorsManager.vividBlue.withValues(alpha: opacity);
|
final opacity = value == 0 ? 0 : clampedValue;
|
||||||
|
return ColorsManager.vividBlue.withValues(alpha: opacity.toDouble());
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
|
@ -1,9 +1,14 @@
|
|||||||
|
import 'package:syncrow_web/pages/analytics/modules/air_quality/widgets/aqi_type_dropdown.dart';
|
||||||
|
|
||||||
class GetAirQualityDistributionParam {
|
class GetAirQualityDistributionParam {
|
||||||
final DateTime date;
|
final DateTime date;
|
||||||
final String spaceUuid;
|
final String spaceUuid;
|
||||||
|
final AqiType aqiType;
|
||||||
|
|
||||||
const GetAirQualityDistributionParam({
|
const GetAirQualityDistributionParam(
|
||||||
|
{
|
||||||
required this.date,
|
required this.date,
|
||||||
required this.spaceUuid,
|
required this.spaceUuid,
|
||||||
|
required this.aqiType,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -1,95 +0,0 @@
|
|||||||
import 'dart:math';
|
|
||||||
|
|
||||||
import 'package:syncrow_web/pages/analytics/models/air_quality_data_model.dart';
|
|
||||||
import 'package:syncrow_web/pages/analytics/modules/air_quality/widgets/aqi_type_dropdown.dart';
|
|
||||||
import 'package:syncrow_web/pages/analytics/params/get_air_quality_distribution_param.dart';
|
|
||||||
import 'package:syncrow_web/pages/analytics/services/air_quality_distribution/air_quality_distribution_service.dart';
|
|
||||||
|
|
||||||
class FakeAirQualityDistributionService implements AirQualityDistributionService {
|
|
||||||
final _random = Random();
|
|
||||||
|
|
||||||
@override
|
|
||||||
Future<List<AirQualityDataModel>> getAirQualityDistribution(
|
|
||||||
GetAirQualityDistributionParam param,
|
|
||||||
) async {
|
|
||||||
return Future.delayed(
|
|
||||||
const Duration(milliseconds: 400),
|
|
||||||
() => List.generate(30, (index) {
|
|
||||||
final date = DateTime(2025, 5, 1).add(Duration(days: index));
|
|
||||||
|
|
||||||
final values = _generateRandomPercentages();
|
|
||||||
final nullMask = List.generate(6, (_) => _shouldBeNull());
|
|
||||||
|
|
||||||
if (nullMask.every((isNull) => isNull)) {
|
|
||||||
nullMask[_random.nextInt(6)] = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
final nonNullValues = _redistributePercentages(values, nullMask);
|
|
||||||
|
|
||||||
return AirQualityDataModel(
|
|
||||||
date: date,
|
|
||||||
data: [
|
|
||||||
AirQualityPercentageData(
|
|
||||||
type: AqiType.aqi.code,
|
|
||||||
percentage: nonNullValues[0],
|
|
||||||
name: 'good',
|
|
||||||
),
|
|
||||||
AirQualityPercentageData(
|
|
||||||
name: 'moderate',
|
|
||||||
type: AqiType.co2.code,
|
|
||||||
percentage: nonNullValues[1],
|
|
||||||
),
|
|
||||||
AirQualityPercentageData(
|
|
||||||
name: 'poor',
|
|
||||||
percentage: nonNullValues[2],
|
|
||||||
type: AqiType.hcho.code,
|
|
||||||
|
|
||||||
),
|
|
||||||
AirQualityPercentageData(
|
|
||||||
name: 'unhealthy',
|
|
||||||
percentage: nonNullValues[3],
|
|
||||||
type: AqiType.pm10.code,
|
|
||||||
),
|
|
||||||
AirQualityPercentageData(
|
|
||||||
name: 'severe',
|
|
||||||
type: AqiType.pm25.code,
|
|
||||||
percentage: nonNullValues[4],
|
|
||||||
),
|
|
||||||
AirQualityPercentageData(
|
|
||||||
name: 'hazardous',
|
|
||||||
percentage: nonNullValues[5],
|
|
||||||
type: AqiType.co2.code,
|
|
||||||
),
|
|
||||||
],
|
|
||||||
);
|
|
||||||
}),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
List<double> _redistributePercentages(
|
|
||||||
List<double> originalValues,
|
|
||||||
List<bool> nullMask,
|
|
||||||
) {
|
|
||||||
double nonNullSum = 0;
|
|
||||||
for (int i = 0; i < originalValues.length; i++) {
|
|
||||||
if (!nullMask[i]) {
|
|
||||||
nonNullSum += originalValues[i];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return List.generate(originalValues.length, (i) {
|
|
||||||
if (nullMask[i]) return 0;
|
|
||||||
return (originalValues[i] / nonNullSum * 100).roundToDouble();
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
bool _shouldBeNull() => _random.nextDouble() < 0.6;
|
|
||||||
|
|
||||||
List<double> _generateRandomPercentages() {
|
|
||||||
final values = List.generate(6, (_) => _random.nextDouble());
|
|
||||||
|
|
||||||
final sum = values.reduce((a, b) => a + b);
|
|
||||||
|
|
||||||
return values.map((value) => (value / sum * 100).roundToDouble()).toList();
|
|
||||||
}
|
|
||||||
}
|
|
@ -3,7 +3,8 @@ import 'package:syncrow_web/pages/analytics/params/get_air_quality_distribution_
|
|||||||
import 'package:syncrow_web/pages/analytics/services/air_quality_distribution/air_quality_distribution_service.dart';
|
import 'package:syncrow_web/pages/analytics/services/air_quality_distribution/air_quality_distribution_service.dart';
|
||||||
import 'package:syncrow_web/services/api/http_service.dart';
|
import 'package:syncrow_web/services/api/http_service.dart';
|
||||||
|
|
||||||
class RemoteAirQualityDistributionService implements AirQualityDistributionService {
|
final class RemoteAirQualityDistributionService
|
||||||
|
implements AirQualityDistributionService {
|
||||||
RemoteAirQualityDistributionService(this._httpService);
|
RemoteAirQualityDistributionService(this._httpService);
|
||||||
|
|
||||||
final HTTPService _httpService;
|
final HTTPService _httpService;
|
||||||
@ -14,10 +15,10 @@ class RemoteAirQualityDistributionService implements AirQualityDistributionServi
|
|||||||
) async {
|
) async {
|
||||||
try {
|
try {
|
||||||
final response = await _httpService.get(
|
final response = await _httpService.get(
|
||||||
path: 'endpoint',
|
path: '/aqi/distribution/space/${param.spaceUuid}',
|
||||||
queryParameters: {
|
queryParameters: {
|
||||||
'spaceUuid': param.spaceUuid,
|
'monthDate': _formatDate(param.date),
|
||||||
'date': param.date.toIso8601String(),
|
'pollutantType': param.aqiType.code,
|
||||||
},
|
},
|
||||||
expectedResponseModel: (data) {
|
expectedResponseModel: (data) {
|
||||||
final json = data as Map<String, dynamic>? ?? {};
|
final json = data as Map<String, dynamic>? ?? {};
|
||||||
@ -33,4 +34,8 @@ class RemoteAirQualityDistributionService implements AirQualityDistributionServi
|
|||||||
throw Exception('Failed to load energy consumption per phase: $e');
|
throw Exception('Failed to load energy consumption per phase: $e');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static String _formatDate(DateTime date) {
|
||||||
|
return '${date.year}-${date.month.toString().padLeft(2, '0')}';
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -26,15 +26,15 @@ class DeviceLocationDetailsServiceDecorator implements DeviceLocationService {
|
|||||||
if (data != null) {
|
if (data != null) {
|
||||||
final addressData = data['address'] as Map<String, dynamic>;
|
final addressData = data['address'] as Map<String, dynamic>;
|
||||||
return deviceLocationInfo.copyWith(
|
return deviceLocationInfo.copyWith(
|
||||||
city: addressData['city'],
|
city: addressData['city'] as String?,
|
||||||
country: addressData['country_code'].toString().toUpperCase(),
|
country: addressData['country_code']?.toString().toUpperCase(),
|
||||||
address: addressData['state'],
|
address: addressData['state'] as String?,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
return deviceLocationInfo;
|
return deviceLocationInfo;
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
throw Exception('Failed to load device location info: ${e.toString()}');
|
throw Exception('Failed to load device location info: $e');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,36 +0,0 @@
|
|||||||
import 'package:syncrow_web/pages/analytics/models/range_of_aqi.dart';
|
|
||||||
import 'package:syncrow_web/pages/analytics/modules/air_quality/widgets/aqi_type_dropdown.dart';
|
|
||||||
import 'package:syncrow_web/pages/analytics/params/get_range_of_aqi_param.dart';
|
|
||||||
import 'package:syncrow_web/pages/analytics/services/range_of_aqi/range_of_aqi_service.dart';
|
|
||||||
|
|
||||||
class FakeRangeOfAqiService implements RangeOfAqiService {
|
|
||||||
@override
|
|
||||||
Future<List<RangeOfAqi>> load(GetRangeOfAqiParam param) async {
|
|
||||||
return await Future.delayed(const Duration(milliseconds: 800), () {
|
|
||||||
final random = DateTime.now().millisecondsSinceEpoch;
|
|
||||||
|
|
||||||
return List.generate(30, (index) {
|
|
||||||
final date = DateTime(2025, 5, 1).add(Duration(days: index));
|
|
||||||
|
|
||||||
final min = ((random + index * 17) % 200).toDouble();
|
|
||||||
final avgDelta = ((random + index * 23) % 50).toDouble() + 20;
|
|
||||||
final maxDelta = ((random + index * 31) % 50).toDouble() + 30;
|
|
||||||
|
|
||||||
final avg = (min + avgDelta).clamp(0.0, 301.0);
|
|
||||||
final max = (avg + maxDelta).clamp(0.0, 301.0);
|
|
||||||
|
|
||||||
return RangeOfAqi(
|
|
||||||
data: [
|
|
||||||
RangeOfAqiValue(type: AqiType.aqi.code, min: min, average: avg, max: max),
|
|
||||||
RangeOfAqiValue(type: AqiType.pm25.code, min: min, average: avg, max: max),
|
|
||||||
RangeOfAqiValue(type: AqiType.pm10.code, min: min, average: avg, max: max),
|
|
||||||
RangeOfAqiValue(type: AqiType.hcho.code, min: min, average: avg, max: max),
|
|
||||||
RangeOfAqiValue(type: AqiType.tvoc.code, min: min, average: avg, max: max),
|
|
||||||
RangeOfAqiValue(type: AqiType.co2.code, min: min, average: avg, max: max),
|
|
||||||
],
|
|
||||||
date: date,
|
|
||||||
);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
@ -12,11 +12,8 @@ final class RemoteRangeOfAqiService implements RangeOfAqiService {
|
|||||||
Future<List<RangeOfAqi>> load(GetRangeOfAqiParam param) async {
|
Future<List<RangeOfAqi>> load(GetRangeOfAqiParam param) async {
|
||||||
try {
|
try {
|
||||||
final response = await _httpService.get(
|
final response = await _httpService.get(
|
||||||
path: 'endpoint',
|
path: '/aqi/range/space/${param.spaceUuid}',
|
||||||
queryParameters: {
|
queryParameters: {'monthDate': _formatDate(param.date)},
|
||||||
'spaceUuid': param.spaceUuid,
|
|
||||||
'date': param.date.toIso8601String(),
|
|
||||||
},
|
|
||||||
expectedResponseModel: (data) {
|
expectedResponseModel: (data) {
|
||||||
final json = data as Map<String, dynamic>? ?? {};
|
final json = data as Map<String, dynamic>? ?? {};
|
||||||
final mappedData = json['data'] as List<dynamic>? ?? [];
|
final mappedData = json['data'] as List<dynamic>? ?? [];
|
||||||
@ -28,7 +25,11 @@ final class RemoteRangeOfAqiService implements RangeOfAqiService {
|
|||||||
);
|
);
|
||||||
return response;
|
return response;
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
throw Exception('Failed to load energy consumption per phase: $e');
|
throw Exception('Failed to load range of aqi: $e');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static String _formatDate(DateTime date) {
|
||||||
|
return '${date.year}-${date.month.toString().padLeft(2, '0')}';
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -78,7 +78,7 @@ class CustomWebTextField extends StatelessWidget {
|
|||||||
controller: controller,
|
controller: controller,
|
||||||
style: const TextStyle(color: Colors.black),
|
style: const TextStyle(color: Colors.black),
|
||||||
decoration: textBoxDecoration()!.copyWith(
|
decoration: textBoxDecoration()!.copyWith(
|
||||||
errorStyle: const TextStyle(height: 0),
|
errorStyle: const TextStyle(height: 0.01),
|
||||||
hintStyle: context.textTheme.titleSmall!
|
hintStyle: context.textTheme.titleSmall!
|
||||||
.copyWith(color: Colors.grey, fontSize: 12),
|
.copyWith(color: Colors.grey, fontSize: 12),
|
||||||
hintText: hintText ?? 'Please enter'),
|
hintText: hintText ?? 'Please enter'),
|
||||||
|
@ -8,15 +8,28 @@ 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 StatelessWidget with HelperResponsiveLayout {
|
class DeviceManagementPage extends StatefulWidget 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(
|
||||||
|
@ -1,7 +1,10 @@
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter/services.dart';
|
import 'package:flutter/services.dart';
|
||||||
|
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||||
import 'package:flutter_svg/svg.dart';
|
import 'package:flutter_svg/svg.dart';
|
||||||
|
import 'package:syncrow_web/pages/device_managment/all_devices/bloc/device_mgmt_bloc/device_managment_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/device_managment/device_setting/bloc/setting_bloc_bloc.dart';
|
||||||
import 'package:syncrow_web/pages/device_managment/device_setting/settings_model/device_info_model.dart';
|
import 'package:syncrow_web/pages/device_managment/device_setting/settings_model/device_info_model.dart';
|
||||||
import 'package:syncrow_web/pages/device_managment/device_setting/settings_model/sub_space_model.dart';
|
import 'package:syncrow_web/pages/device_managment/device_setting/settings_model/sub_space_model.dart';
|
||||||
import 'package:syncrow_web/pages/device_managment/device_setting/sub_space_dialog.dart';
|
import 'package:syncrow_web/pages/device_managment/device_setting/sub_space_dialog.dart';
|
||||||
@ -66,14 +69,25 @@ class DeviceManagementContent extends StatelessWidget {
|
|||||||
Padding(
|
Padding(
|
||||||
padding: const EdgeInsets.all(10.0),
|
padding: const EdgeInsets.all(10.0),
|
||||||
child: InkWell(
|
child: InkWell(
|
||||||
onTap: () {
|
onTap: () async {
|
||||||
showSubSpaceDialog(
|
final selectedSubSpace = await showSubSpaceDialog(
|
||||||
context,
|
context,
|
||||||
communityUuid: device.community!.uuid!,
|
communityUuid: device.community!.uuid!,
|
||||||
spaceUuid: device.spaces!.first.uuid!,
|
spaceUuid: device.spaces!.first.uuid!,
|
||||||
subSpaces: subSpaces,
|
subSpaces: subSpaces,
|
||||||
selected: device.subspace!.uuid,
|
selected: deviceInfo.subspace.uuid,
|
||||||
);
|
);
|
||||||
|
if (selectedSubSpace != null) {
|
||||||
|
Future.delayed(const Duration(milliseconds: 500), () {
|
||||||
|
context.read<SettingDeviceBloc>().add(
|
||||||
|
SettingBlocAssignRoom(
|
||||||
|
communityUuid: device.community!.uuid!,
|
||||||
|
spaceUuid: device.spaces!.first.uuid!,
|
||||||
|
subSpaceUuid: selectedSubSpace.id ?? '',
|
||||||
|
),
|
||||||
|
);
|
||||||
|
});
|
||||||
|
}
|
||||||
},
|
},
|
||||||
child: infoRow(
|
child: infoRow(
|
||||||
label: 'Sub-Space:',
|
label: 'Sub-Space:',
|
||||||
|
@ -9,13 +9,11 @@ import 'package:syncrow_web/utils/extension/build_context_x.dart';
|
|||||||
class SubSpaceDialog extends StatefulWidget {
|
class SubSpaceDialog extends StatefulWidget {
|
||||||
final List<SubSpaceModel> subSpaces;
|
final List<SubSpaceModel> subSpaces;
|
||||||
final String? selected;
|
final String? selected;
|
||||||
final void Function(SubSpaceModel?) onConfirmed;
|
|
||||||
|
|
||||||
const SubSpaceDialog({
|
const SubSpaceDialog({
|
||||||
Key? key,
|
Key? key,
|
||||||
required this.subSpaces,
|
required this.subSpaces,
|
||||||
this.selected,
|
this.selected,
|
||||||
required this.onConfirmed,
|
|
||||||
}) : super(key: key);
|
}) : super(key: key);
|
||||||
|
|
||||||
@override
|
@override
|
||||||
@ -86,30 +84,21 @@ class _SubSpaceDialogState extends State<SubSpaceDialog> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void showSubSpaceDialog(
|
Future<SubSpaceModel?> showSubSpaceDialog(
|
||||||
BuildContext context, {
|
BuildContext context, {
|
||||||
required List<SubSpaceModel> subSpaces,
|
required List<SubSpaceModel> subSpaces,
|
||||||
String? selected,
|
String? selected,
|
||||||
required String communityUuid,
|
required String communityUuid,
|
||||||
required String spaceUuid,
|
required String spaceUuid,
|
||||||
}) {
|
}) {
|
||||||
showDialog(
|
return showDialog<SubSpaceModel>(
|
||||||
context: context,
|
context: context,
|
||||||
barrierDismissible: true,
|
builder: (ctx) => BlocProvider.value(
|
||||||
builder: (ctx) => SubSpaceDialog(
|
value: BlocProvider.of<SettingDeviceBloc>(context),
|
||||||
subSpaces: subSpaces,
|
child: SubSpaceDialog(
|
||||||
selected: selected,
|
subSpaces: subSpaces,
|
||||||
onConfirmed: (selectedModel) {
|
selected: selected,
|
||||||
if (selectedModel != null) {
|
),
|
||||||
context.read<SettingDeviceBloc>().add(
|
|
||||||
SettingBlocAssignRoom(
|
|
||||||
communityUuid: communityUuid,
|
|
||||||
spaceUuid: spaceUuid,
|
|
||||||
subSpaceUuid: selectedModel.id ?? '',
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
},
|
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,4 @@
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
|
||||||
import 'package:syncrow_web/pages/device_managment/device_setting/bloc/setting_bloc_bloc.dart';
|
|
||||||
import 'package:syncrow_web/pages/device_managment/device_setting/settings_model/sub_space_model.dart';
|
import 'package:syncrow_web/pages/device_managment/device_setting/settings_model/sub_space_model.dart';
|
||||||
import 'package:syncrow_web/pages/device_managment/device_setting/sub_space_dialog.dart';
|
import 'package:syncrow_web/pages/device_managment/device_setting/sub_space_dialog.dart';
|
||||||
import 'package:syncrow_web/utils/color_manager.dart';
|
import 'package:syncrow_web/utils/color_manager.dart';
|
||||||
@ -62,11 +60,12 @@ class SubSpaceDialogButtons extends StatelessWidget {
|
|||||||
? null
|
? null
|
||||||
: () {
|
: () {
|
||||||
final selectedModel = widget.subSpaces.firstWhere(
|
final selectedModel = widget.subSpaces.firstWhere(
|
||||||
(space) => space.id == _selectedId,
|
(space) => space.id == _selectedId,
|
||||||
orElse: () =>
|
orElse: () =>
|
||||||
SubSpaceModel(id: null, name: '', devices: []));
|
SubSpaceModel(id: null, name: '', devices: []),
|
||||||
widget.onConfirmed(selectedModel);
|
);
|
||||||
Navigator.of(context).pop();
|
Navigator.of(context)
|
||||||
|
.pop(selectedModel);
|
||||||
},
|
},
|
||||||
child: Text(
|
child: Text(
|
||||||
'Confirm',
|
'Confirm',
|
||||||
@ -84,31 +83,3 @@ class SubSpaceDialogButtons extends StatelessWidget {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void showSubSpaceDialog(
|
|
||||||
BuildContext context, {
|
|
||||||
required List<SubSpaceModel> subSpaces,
|
|
||||||
String? selected,
|
|
||||||
required String communityUuid,
|
|
||||||
required String spaceUuid,
|
|
||||||
}) {
|
|
||||||
showDialog(
|
|
||||||
context: context,
|
|
||||||
barrierDismissible: true,
|
|
||||||
builder: (ctx) => SubSpaceDialog(
|
|
||||||
subSpaces: subSpaces,
|
|
||||||
selected: selected,
|
|
||||||
onConfirmed: (selectedModel) {
|
|
||||||
if (selectedModel != null) {
|
|
||||||
context.read<SettingDeviceBloc>().add(
|
|
||||||
SettingBlocAssignRoom(
|
|
||||||
communityUuid: communityUuid,
|
|
||||||
spaceUuid: spaceUuid,
|
|
||||||
subSpaceUuid: selectedModel.id ?? '',
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
},
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
@ -13,30 +13,32 @@ 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 _fetchUserInfo(FetchUserInfo event, Emitter<HomeState> emit) async {
|
Future<void> _fetchUserInfo(
|
||||||
|
FetchUserInfo event,
|
||||||
|
Emitter<HomeState> emit,
|
||||||
|
) async {
|
||||||
try {
|
try {
|
||||||
var uuid =
|
final uuid =
|
||||||
await const FlutterSecureStorage().read(key: UserModel.userUuidKey);
|
await const FlutterSecureStorage().read(key: UserModel.userUuidKey);
|
||||||
user = await HomeApi().fetchUserInfo(uuid);
|
if (uuid != null) {
|
||||||
|
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());
|
||||||
@ -47,7 +49,7 @@ class HomeBloc extends Bloc<HomeEvent, HomeState> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Future _fetchTerms(FetchTermEvent event, Emitter<HomeState> emit) async {
|
Future<void> _fetchTerms(FetchTermEvent event, Emitter<HomeState> emit) async {
|
||||||
try {
|
try {
|
||||||
emit(LoadingHome());
|
emit(LoadingHome());
|
||||||
terms = await HomeApi().fetchTerms();
|
terms = await HomeApi().fetchTerms();
|
||||||
@ -57,22 +59,22 @@ class HomeBloc extends Bloc<HomeEvent, HomeState> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Future _fetchPolicy(FetchPolicyEvent event, Emitter<HomeState> emit) async {
|
Future<void> _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 _confirmUserAgreement(
|
Future<void> _confirmUserAgreement(
|
||||||
ConfirmUserAgreementEvent event, Emitter<HomeState> emit) async {
|
ConfirmUserAgreementEvent event, Emitter<HomeState> emit) async {
|
||||||
try {
|
try {
|
||||||
emit(LoadingHome());
|
emit(LoadingHome());
|
||||||
var uuid =
|
final 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());
|
||||||
@ -81,7 +83,7 @@ class HomeBloc extends Bloc<HomeEvent, HomeState> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
List<HomeItemModel> homeItems = [
|
final List<HomeItemModel> homeItems = [
|
||||||
HomeItemModel(
|
HomeItemModel(
|
||||||
title: 'Access Management',
|
title: 'Access Management',
|
||||||
icon: Assets.accessIcon,
|
icon: Assets.accessIcon,
|
||||||
@ -126,41 +128,5 @@ 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),
|
|
||||||
// ),
|
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
@ -34,17 +34,9 @@ class HomeCard extends StatelessWidget {
|
|||||||
child: Row(
|
child: Row(
|
||||||
mainAxisAlignment: MainAxisAlignment.start,
|
mainAxisAlignment: MainAxisAlignment.start,
|
||||||
children: [
|
children: [
|
||||||
Flexible(
|
Expanded(
|
||||||
child: FittedBox(
|
child: SpliteNameHelperWidget(
|
||||||
fit: BoxFit.scaleDown,
|
name: name,
|
||||||
child: Text(
|
|
||||||
name,
|
|
||||||
style: const TextStyle(
|
|
||||||
fontSize: 20,
|
|
||||||
color: Colors.white,
|
|
||||||
fontWeight: FontWeight.bold,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
@ -63,3 +55,72 @@ class HomeCard extends StatelessWidget {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class SpliteNameHelperWidget extends StatelessWidget {
|
||||||
|
final String name;
|
||||||
|
const SpliteNameHelperWidget({
|
||||||
|
super.key,
|
||||||
|
required this.name,
|
||||||
|
});
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
List<String> parts = name.split(' ');
|
||||||
|
|
||||||
|
if (parts.length == 2) {
|
||||||
|
// Two-word string
|
||||||
|
return Padding(
|
||||||
|
padding: const EdgeInsetsGeometry.only(top: 10, left: 10),
|
||||||
|
child: Column(
|
||||||
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
|
children: [
|
||||||
|
Expanded(
|
||||||
|
child: FittedBox(
|
||||||
|
fit: BoxFit.scaleDown,
|
||||||
|
child: Text(
|
||||||
|
parts[0],
|
||||||
|
style: const TextStyle(
|
||||||
|
fontSize: 30,
|
||||||
|
color: Colors.white,
|
||||||
|
fontWeight: FontWeight.bold,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
Expanded(
|
||||||
|
child: FittedBox(
|
||||||
|
fit: BoxFit.scaleDown,
|
||||||
|
child: Text(
|
||||||
|
parts[1],
|
||||||
|
style: const TextStyle(
|
||||||
|
fontSize: 30,
|
||||||
|
color: Colors.white,
|
||||||
|
fontWeight: FontWeight.bold,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
// One-word string
|
||||||
|
return Text(
|
||||||
|
name,
|
||||||
|
style: const TextStyle(
|
||||||
|
fontSize: 30,
|
||||||
|
color: Colors.white,
|
||||||
|
fontWeight: FontWeight.bold,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// Text(
|
||||||
|
// name,
|
||||||
|
// style: const TextStyle(
|
||||||
|
// fontSize: 32,
|
||||||
|
// color: Colors.white,
|
||||||
|
// fontWeight: FontWeight.bold,
|
||||||
|
// ),
|
||||||
|
// )
|
||||||
|
@ -1,17 +1,37 @@
|
|||||||
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 StatelessWidget with HelperResponsiveLayout {
|
class HomePage extends StatefulWidget {
|
||||||
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) {
|
||||||
final isSmallScreen = isSmallScreenSize(context);
|
if (isSmallScreenSize(context) || isMediumScreenSize(context)) {
|
||||||
final isMediumScreen = isMediumScreenSize(context);
|
return HomeMobilePage();
|
||||||
return isSmallScreen || isMediumScreen
|
}
|
||||||
? HomeMobilePage()
|
|
||||||
: const HomeWebPage();
|
return const HomeWebPage();
|
||||||
|
}
|
||||||
|
|
||||||
|
void _fetchUserInfo() {
|
||||||
|
final bloc = context.read<HomeBloc>();
|
||||||
|
if (bloc.user == null) bloc.add(const FetchUserInfo());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -92,12 +92,12 @@ class _HomeWebPageState extends State<HomeWebPage> {
|
|||||||
flex: 4,
|
flex: 4,
|
||||||
child: SizedBox(
|
child: SizedBox(
|
||||||
height: size.height * 0.6,
|
height: size.height * 0.6,
|
||||||
width: size.width * 0.68,
|
width: size.width * 0.8,
|
||||||
child: GridView.builder(
|
child: GridView.builder(
|
||||||
itemCount: homeBloc.homeItems.length,
|
itemCount: homeBloc.homeItems.length,
|
||||||
gridDelegate:
|
gridDelegate:
|
||||||
const SliverGridDelegateWithFixedCrossAxisCount(
|
const SliverGridDelegateWithFixedCrossAxisCount(
|
||||||
crossAxisCount: 3, // Adjust as needed.
|
crossAxisCount: 4, // Adjust as needed.
|
||||||
crossAxisSpacing: 20.0,
|
crossAxisSpacing: 20.0,
|
||||||
mainAxisSpacing: 20.0,
|
mainAxisSpacing: 20.0,
|
||||||
childAspectRatio: 1.5,
|
childAspectRatio: 1.5,
|
||||||
|
@ -19,7 +19,6 @@ 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,6 +13,35 @@ 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(
|
||||||
@ -20,19 +49,10 @@ class FunctionBloc extends Bloc<FunctionBlocEvent, FunctionBlocState> {
|
|||||||
);
|
);
|
||||||
|
|
||||||
if (existingIndex != -1) {
|
if (existingIndex != -1) {
|
||||||
final existingData = functions[existingIndex];
|
// Update the function value
|
||||||
functions[existingIndex] = DeviceFunctionData(
|
functions[existingIndex] = event.functionData;
|
||||||
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 {
|
||||||
functions.clear();
|
// Add new function value
|
||||||
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:syncrow_web/pages/common/bloc/project_manager.dart';
|
|
||||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||||
|
import 'package:syncrow_web/pages/common/bloc/project_manager.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,9 +27,6 @@ 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);
|
||||||
@ -173,45 +170,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 {
|
||||||
emit(state.copyWith(
|
scenes.addAll(await SceneApi.getScenes(
|
||||||
scenes: scenes,
|
createRoutineBloc.selectedSpaceId,
|
||||||
isLoading: false,
|
createRoutineBloc.selectedCommunityId,
|
||||||
));
|
projectUuid));
|
||||||
} catch (e) {
|
|
||||||
emit(state.copyWith(
|
|
||||||
isLoading: false,
|
|
||||||
loadScenesErrorMessage: 'Failed to load scenes',
|
|
||||||
errorMessage: '',
|
|
||||||
loadAutomationErrorMessage: '',
|
|
||||||
scenes: scenes));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
emit(state.copyWith(
|
||||||
|
scenes: scenes,
|
||||||
|
isLoading: false,
|
||||||
|
));
|
||||||
|
} catch (e) {
|
||||||
|
emit(state.copyWith(
|
||||||
|
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 {
|
||||||
@ -1163,8 +1160,8 @@ class RoutineBloc extends Bloc<RoutineEvent, RoutineState> {
|
|||||||
|
|
||||||
if (result['success']) {
|
if (result['success']) {
|
||||||
add(ResetRoutineState());
|
add(ResetRoutineState());
|
||||||
add(LoadAutomation());
|
add(const LoadAutomation());
|
||||||
add(LoadScenes());
|
add(const LoadScenes());
|
||||||
} else {
|
} else {
|
||||||
emit(state.copyWith(
|
emit(state.copyWith(
|
||||||
isLoading: false,
|
isLoading: false,
|
||||||
@ -1422,15 +1419,17 @@ class RoutineBloc extends Bloc<RoutineEvent, RoutineState> {
|
|||||||
event.automationId, event.automationStatusUpdate, projectId);
|
event.automationId, event.automationStatusUpdate, projectId);
|
||||||
|
|
||||||
if (success) {
|
if (success) {
|
||||||
final updatedAutomations = await SceneApi.getAutomationByUnitId(
|
// 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,
|
||||||
@ -1452,4 +1451,24 @@ class RoutineBloc extends Bloc<RoutineEvent, RoutineState> {
|
|||||||
));
|
));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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: 46,
|
height: 40,
|
||||||
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: 33,
|
width: 44,
|
||||||
child: const Icon(
|
child: const Icon(
|
||||||
Icons.keyboard_arrow_down,
|
Icons.keyboard_arrow_down,
|
||||||
color: ColorsManager.textGray,
|
color: ColorsManager.textGray,
|
||||||
|
@ -44,144 +44,156 @@ class _CreateNewRoutinesDialogState extends State<CreateNewRoutinesDialog> {
|
|||||||
_selectedSpace = null;
|
_selectedSpace = null;
|
||||||
_selectedCommunity = _selectedId;
|
_selectedCommunity = _selectedId;
|
||||||
}
|
}
|
||||||
return AlertDialog(
|
return Dialog(
|
||||||
backgroundColor: Colors.white,
|
backgroundColor: Colors.white,
|
||||||
insetPadding: EdgeInsets.zero,
|
insetPadding: const EdgeInsets.symmetric(
|
||||||
contentPadding: EdgeInsets.zero,
|
horizontal: 20,
|
||||||
|
),
|
||||||
shape: RoundedRectangleBorder(
|
shape: RoundedRectangleBorder(
|
||||||
borderRadius: BorderRadius.circular(12)),
|
borderRadius: BorderRadius.circular(12)),
|
||||||
title: Text(
|
child: Container(
|
||||||
'Create New Routines',
|
width: 450,
|
||||||
textAlign: TextAlign.center,
|
child: Stack(
|
||||||
style: Theme.of(context).textTheme.bodyMedium!.copyWith(
|
children: [
|
||||||
color: ColorsManager.spaceColor,
|
Column(
|
||||||
fontSize: 20,
|
mainAxisSize: MainAxisSize.min,
|
||||||
fontWeight: FontWeight.w700,
|
children: [
|
||||||
),
|
const SizedBox(height: 20),
|
||||||
),
|
Text(
|
||||||
content: Stack(
|
'Create New Routines',
|
||||||
children: [
|
textAlign: TextAlign.center,
|
||||||
Column(
|
style:
|
||||||
mainAxisSize: MainAxisSize.min,
|
Theme.of(context).textTheme.bodyMedium!.copyWith(
|
||||||
children: [
|
color: ColorsManager.spaceColor,
|
||||||
const Divider(),
|
fontSize: 20,
|
||||||
const SizedBox(height: 20),
|
fontWeight: FontWeight.w700,
|
||||||
Column(
|
),
|
||||||
children: [
|
),
|
||||||
Padding(
|
const Divider(),
|
||||||
padding:
|
const SizedBox(height: 20),
|
||||||
const EdgeInsets.only(left: 13, right: 8),
|
Column(
|
||||||
child: Column(
|
children: [
|
||||||
children: [
|
Column(
|
||||||
SpaceTreeDropdown(
|
children: [
|
||||||
selectedSpaceId: _selectedId,
|
Padding(
|
||||||
|
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(() => _selectedId = newValue!);
|
setState(() {
|
||||||
if (_selectedId != null) {
|
_selectedSpace = newValue;
|
||||||
_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 SizedBox(height: 20),
|
const Divider(),
|
||||||
const Divider(),
|
Row(
|
||||||
Row(
|
mainAxisAlignment: MainAxisAlignment.spaceAround,
|
||||||
mainAxisAlignment: MainAxisAlignment.spaceAround,
|
children: [
|
||||||
children: [
|
Padding(
|
||||||
Padding(
|
padding: const EdgeInsets.only(
|
||||||
padding: const EdgeInsets.only(
|
left: 20,
|
||||||
left: 20,
|
right: 20,
|
||||||
right: 20,
|
),
|
||||||
),
|
child: TextButton(
|
||||||
child: TextButton(
|
onPressed: () {
|
||||||
onPressed: () {
|
Navigator.of(context).pop();
|
||||||
Navigator.of(context).pop();
|
},
|
||||||
},
|
child: Text(
|
||||||
child: Text(
|
'Cancel',
|
||||||
'Cancel',
|
style: Theme.of(context)
|
||||||
style: Theme.of(context)
|
.textTheme
|
||||||
.textTheme
|
.bodyMedium!
|
||||||
.bodyMedium!
|
.copyWith(
|
||||||
.copyWith(
|
fontWeight: FontWeight.w400,
|
||||||
fontWeight: FontWeight.w400,
|
fontSize: 14,
|
||||||
fontSize: 14,
|
color: ColorsManager.blackColor,
|
||||||
color: ColorsManager.blackColor,
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
Padding(
|
||||||
Padding(
|
padding: const EdgeInsets.only(
|
||||||
padding: const EdgeInsets.only(
|
left: 20,
|
||||||
left: 20,
|
right: 20,
|
||||||
right: 20,
|
),
|
||||||
),
|
child: TextButton(
|
||||||
child: TextButton(
|
onPressed: _selectedCommunity != null &&
|
||||||
onPressed: _selectedCommunity != null &&
|
_selectedSpace != null
|
||||||
_selectedSpace != null
|
? () {
|
||||||
? () {
|
Navigator.of(context).pop({
|
||||||
Navigator.of(context).pop({
|
'community': _selectedCommunity,
|
||||||
'community': _selectedCommunity,
|
'space': _selectedSpace,
|
||||||
'space': _selectedSpace,
|
});
|
||||||
});
|
}
|
||||||
}
|
: null,
|
||||||
: null,
|
child: Text(
|
||||||
child: Text(
|
'Next',
|
||||||
'Next',
|
style: Theme.of(context)
|
||||||
style: Theme.of(context)
|
.textTheme
|
||||||
.textTheme
|
.bodyMedium!
|
||||||
.bodyMedium!
|
.copyWith(
|
||||||
.copyWith(
|
fontWeight: FontWeight.w400,
|
||||||
fontWeight: FontWeight.w400,
|
fontSize: 14,
|
||||||
fontSize: 14,
|
color: _selectedCommunity != null &&
|
||||||
color: _selectedCommunity != null &&
|
_selectedSpace != null
|
||||||
_selectedSpace != null
|
? ColorsManager.blueColor
|
||||||
? ColorsManager.blueColor
|
: Colors.blue.shade100,
|
||||||
: Colors.blue.shade100,
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
],
|
||||||
],
|
),
|
||||||
),
|
const SizedBox(height: 10),
|
||||||
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,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
),
|
),
|
||||||
],
|
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,7 +34,9 @@ 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>(
|
||||||
@ -45,7 +47,7 @@ class SpaceDropdown extends StatelessWidget {
|
|||||||
value: space.uuid,
|
value: space.uuid,
|
||||||
child: Column(
|
child: Column(
|
||||||
crossAxisAlignment: CrossAxisAlignment.start,
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
mainAxisAlignment: MainAxisAlignment.start,
|
mainAxisAlignment: MainAxisAlignment.center,
|
||||||
children: [
|
children: [
|
||||||
Text(
|
Text(
|
||||||
' ${space.name}',
|
' ${space.name}',
|
||||||
@ -88,7 +90,7 @@ class SpaceDropdown extends StatelessWidget {
|
|||||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||||
children: [
|
children: [
|
||||||
Expanded(
|
Expanded(
|
||||||
flex: 6,
|
flex: 8,
|
||||||
child: Padding(
|
child: Padding(
|
||||||
padding: const EdgeInsets.only(left: 10),
|
padding: const EdgeInsets.only(left: 10),
|
||||||
child: Text(
|
child: Text(
|
||||||
@ -129,6 +131,7 @@ 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),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
@ -118,6 +118,7 @@ class DeviceDialogHelper {
|
|||||||
uniqueCustomId: data['uniqueCustomId'],
|
uniqueCustomId: data['uniqueCustomId'],
|
||||||
deviceSelectedFunctions: deviceSelectedFunctions,
|
deviceSelectedFunctions: deviceSelectedFunctions,
|
||||||
device: data['device'],
|
device: data['device'],
|
||||||
|
dialogType: dialogType,
|
||||||
);
|
);
|
||||||
case 'NCPS':
|
case 'NCPS':
|
||||||
return FlushPresenceSensor.showFlushFunctionsDialog(
|
return FlushPresenceSensor.showFlushFunctionsDialog(
|
||||||
|
@ -17,9 +17,10 @@ class SaveRoutineHelper {
|
|||||||
builder: (context) {
|
builder: (context) {
|
||||||
return BlocBuilder<RoutineBloc, RoutineState>(
|
return BlocBuilder<RoutineBloc, RoutineState>(
|
||||||
builder: (context, state) {
|
builder: (context, state) {
|
||||||
final selectedConditionLabel = state.selectedAutomationOperator == 'and'
|
final selectedConditionLabel =
|
||||||
? 'All Conditions are met'
|
state.selectedAutomationOperator == 'and'
|
||||||
: 'Any Condition is met';
|
? 'All Conditions are met'
|
||||||
|
: 'Any Condition is met';
|
||||||
|
|
||||||
return AlertDialog(
|
return AlertDialog(
|
||||||
contentPadding: EdgeInsets.zero,
|
contentPadding: EdgeInsets.zero,
|
||||||
@ -37,10 +38,11 @@ class SaveRoutineHelper {
|
|||||||
Text(
|
Text(
|
||||||
'Create a scene: ${state.routineName ?? ""}',
|
'Create a scene: ${state.routineName ?? ""}',
|
||||||
textAlign: TextAlign.center,
|
textAlign: TextAlign.center,
|
||||||
style: Theme.of(context).textTheme.headlineMedium!.copyWith(
|
style:
|
||||||
color: ColorsManager.primaryColorWithOpacity,
|
Theme.of(context).textTheme.headlineMedium!.copyWith(
|
||||||
fontWeight: FontWeight.bold,
|
color: ColorsManager.primaryColorWithOpacity,
|
||||||
),
|
fontWeight: FontWeight.bold,
|
||||||
|
),
|
||||||
),
|
),
|
||||||
const SizedBox(height: 18),
|
const SizedBox(height: 18),
|
||||||
_buildDivider(),
|
_buildDivider(),
|
||||||
@ -58,7 +60,8 @@ class SaveRoutineHelper {
|
|||||||
_buildIfConditions(state, context),
|
_buildIfConditions(state, context),
|
||||||
Container(
|
Container(
|
||||||
width: 1,
|
width: 1,
|
||||||
color: ColorsManager.greyColor.withValues(alpha: 0.8),
|
color: ColorsManager.greyColor
|
||||||
|
.withValues(alpha: 0.8),
|
||||||
),
|
),
|
||||||
_buildThenActions(state, context),
|
_buildThenActions(state, context),
|
||||||
],
|
],
|
||||||
@ -97,7 +100,8 @@ class SaveRoutineHelper {
|
|||||||
child: Row(
|
child: Row(
|
||||||
spacing: 16,
|
spacing: 16,
|
||||||
children: [
|
children: [
|
||||||
Expanded(child: Text('IF: $selectedConditionLabel', style: textStyle)),
|
Expanded(
|
||||||
|
child: Text('IF: $selectedConditionLabel', style: textStyle)),
|
||||||
const Expanded(child: Text('THEN:', style: textStyle)),
|
const Expanded(child: Text('THEN:', style: textStyle)),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
@ -109,7 +113,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),
|
||||||
),
|
),
|
||||||
@ -143,7 +147,8 @@ class SaveRoutineHelper {
|
|||||||
child: ListView(
|
child: ListView(
|
||||||
// shrinkWrap: true,
|
// shrinkWrap: true,
|
||||||
children: state.thenItems.map((item) {
|
children: state.thenItems.map((item) {
|
||||||
final functions = state.selectedFunctions[item['uniqueCustomId']] ?? [];
|
final functions =
|
||||||
|
state.selectedFunctions[item['uniqueCustomId']] ?? [];
|
||||||
return functionRow(item, context, functions);
|
return functionRow(item, context, functions);
|
||||||
}).toList(),
|
}).toList(),
|
||||||
),
|
),
|
||||||
@ -203,19 +208,20 @@ class SaveRoutineHelper {
|
|||||||
),
|
),
|
||||||
),
|
),
|
||||||
child: Center(
|
child: Center(
|
||||||
child: item['type'] == 'tap_to_run' || item['type'] == 'scene'
|
child:
|
||||||
? Image.memory(
|
item['type'] == 'tap_to_run' || item['type'] == 'scene'
|
||||||
base64Decode(item['icon']),
|
? Image.memory(
|
||||||
width: 12,
|
base64Decode(item['icon']),
|
||||||
height: 22,
|
width: 12,
|
||||||
fit: BoxFit.scaleDown,
|
height: 22,
|
||||||
)
|
fit: BoxFit.scaleDown,
|
||||||
: SvgPicture.asset(
|
)
|
||||||
item['imagePath'],
|
: SvgPicture.asset(
|
||||||
width: 12,
|
item['imagePath'],
|
||||||
height: 12,
|
width: 12,
|
||||||
fit: BoxFit.scaleDown,
|
height: 12,
|
||||||
),
|
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.00,
|
min: 0.0,
|
||||||
max: 1.00,
|
max: 1.0,
|
||||||
step: 0.1,
|
step: 0.1,
|
||||||
unit: "",
|
unit: "",
|
||||||
);
|
);
|
||||||
|
@ -65,7 +65,9 @@ class ACHelper {
|
|||||||
child: Column(
|
child: Column(
|
||||||
mainAxisSize: MainAxisSize.min,
|
mainAxisSize: MainAxisSize.min,
|
||||||
children: [
|
children: [
|
||||||
const DialogHeader('AC Functions'),
|
DialogHeader(dialogType == 'THEN'
|
||||||
|
? 'AC Functions'
|
||||||
|
: 'AC Conditions'),
|
||||||
Expanded(
|
Expanded(
|
||||||
child: Row(
|
child: Row(
|
||||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||||
@ -115,10 +117,22 @@ 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(
|
||||||
state.addedFunctions,
|
[selectedFunctionData],
|
||||||
uniqueCustomId,
|
uniqueCustomId,
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
@ -78,12 +78,22 @@ 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(
|
||||||
functions,
|
[selectedFunctionData],
|
||||||
'${widget.uniqueCustomId}',
|
'${widget.uniqueCustomId}',
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
@ -96,7 +96,9 @@ class _WallPresenceSensorState extends State<FlushPresenceSensor> {
|
|||||||
child: Column(
|
child: Column(
|
||||||
mainAxisSize: MainAxisSize.min,
|
mainAxisSize: MainAxisSize.min,
|
||||||
children: [
|
children: [
|
||||||
const DialogHeader('Presence Sensor Condition'),
|
DialogHeader(widget.dialogType == 'THEN'
|
||||||
|
? 'Presence Sensor Functions'
|
||||||
|
: 'Presence Sensor Condition'),
|
||||||
Expanded(child: _buildMainContent(context, state)),
|
Expanded(child: _buildMainContent(context, state)),
|
||||||
_buildDialogFooter(context, state),
|
_buildDialogFooter(context, state),
|
||||||
],
|
],
|
||||||
@ -190,9 +192,18 @@ 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(
|
||||||
state.addedFunctions,
|
[selectedFunctionData],
|
||||||
widget.uniqueCustomId!,
|
widget.uniqueCustomId!,
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
@ -16,9 +16,10 @@ class GatewayDialog extends StatefulWidget {
|
|||||||
required this.functions,
|
required this.functions,
|
||||||
required this.deviceSelectedFunctions,
|
required this.deviceSelectedFunctions,
|
||||||
required this.device,
|
required this.device,
|
||||||
|
required this.dialogType,
|
||||||
super.key,
|
super.key,
|
||||||
});
|
});
|
||||||
|
final String dialogType;
|
||||||
final String? uniqueCustomId;
|
final String? uniqueCustomId;
|
||||||
final List<DeviceFunction> functions;
|
final List<DeviceFunction> functions;
|
||||||
final List<DeviceFunctionData> deviceSelectedFunctions;
|
final List<DeviceFunctionData> deviceSelectedFunctions;
|
||||||
@ -55,7 +56,9 @@ class _GatewayDialogState extends State<GatewayDialog> {
|
|||||||
child: Column(
|
child: Column(
|
||||||
mainAxisSize: MainAxisSize.min,
|
mainAxisSize: MainAxisSize.min,
|
||||||
children: [
|
children: [
|
||||||
const DialogHeader('Gateway Conditions'),
|
DialogHeader(widget.dialogType == 'THEN'
|
||||||
|
? 'Gateway Functions'
|
||||||
|
: 'Gateway Conditions'),
|
||||||
Expanded(child: _buildMainContent(context, state)),
|
Expanded(child: _buildMainContent(context, state)),
|
||||||
_buildDialogFooter(context, state),
|
_buildDialogFooter(context, state),
|
||||||
],
|
],
|
||||||
@ -112,9 +115,18 @@ 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(
|
||||||
state.addedFunctions,
|
[selectedFunctionData],
|
||||||
widget.uniqueCustomId ?? '-1',
|
widget.uniqueCustomId ?? '-1',
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
@ -14,6 +14,7 @@ abstract final class GatewayHelper {
|
|||||||
required String? uniqueCustomId,
|
required String? uniqueCustomId,
|
||||||
required List<DeviceFunctionData> deviceSelectedFunctions,
|
required List<DeviceFunctionData> deviceSelectedFunctions,
|
||||||
required AllDevicesModel? device,
|
required AllDevicesModel? device,
|
||||||
|
required String dialogType,
|
||||||
}) async {
|
}) async {
|
||||||
return showDialog(
|
return showDialog(
|
||||||
context: context,
|
context: context,
|
||||||
@ -27,6 +28,7 @@ abstract final class GatewayHelper {
|
|||||||
functions: functions,
|
functions: functions,
|
||||||
deviceSelectedFunctions: deviceSelectedFunctions,
|
deviceSelectedFunctions: deviceSelectedFunctions,
|
||||||
device: device,
|
device: device,
|
||||||
|
dialogType:dialogType,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
@ -59,7 +59,9 @@ class OneGangSwitchHelper {
|
|||||||
child: Column(
|
child: Column(
|
||||||
mainAxisSize: MainAxisSize.min,
|
mainAxisSize: MainAxisSize.min,
|
||||||
children: [
|
children: [
|
||||||
const DialogHeader('1 Gang Light Switch Condition'),
|
DialogHeader(dialogType == 'THEN'
|
||||||
|
? '1 Gang Light Switch Functions'
|
||||||
|
: '1 Gang Light Switch Condition'),
|
||||||
Expanded(
|
Expanded(
|
||||||
child: Row(
|
child: Row(
|
||||||
children: [
|
children: [
|
||||||
@ -145,7 +147,7 @@ class OneGangSwitchHelper {
|
|||||||
// }
|
// }
|
||||||
context.read<RoutineBloc>().add(
|
context.read<RoutineBloc>().add(
|
||||||
AddFunctionToRoutine(
|
AddFunctionToRoutine(
|
||||||
state.addedFunctions,
|
[selectedFunctionData],
|
||||||
uniqueCustomId,
|
uniqueCustomId,
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
@ -246,9 +248,9 @@ class OneGangSwitchHelper {
|
|||||||
withSpecialChar: false,
|
withSpecialChar: false,
|
||||||
currentCondition: selectedFunctionData?.condition,
|
currentCondition: selectedFunctionData?.condition,
|
||||||
dialogType: dialogType,
|
dialogType: dialogType,
|
||||||
sliderRange: (0, 43200),
|
sliderRange: (0, 43200),
|
||||||
displayedValue: (initialValue ?? 0).toString(),
|
displayedValue: (initialValue ?? 0).toString(),
|
||||||
initialValue: (initialValue ?? 0).toString(),
|
initialValue: (initialValue ?? 0).toString(),
|
||||||
onConditionChanged: (condition) {
|
onConditionChanged: (condition) {
|
||||||
context.read<FunctionBloc>().add(
|
context.read<FunctionBloc>().add(
|
||||||
AddFunction(
|
AddFunction(
|
||||||
|
@ -98,7 +98,9 @@ class _EnergyClampDialogState extends State<EnergyClampDialog> {
|
|||||||
child: Column(
|
child: Column(
|
||||||
mainAxisSize: MainAxisSize.min,
|
mainAxisSize: MainAxisSize.min,
|
||||||
children: [
|
children: [
|
||||||
const DialogHeader('Energy Clamp Conditions'),
|
DialogHeader(widget.dialogType == 'THEN'
|
||||||
|
? 'Energy Clamp Functions'
|
||||||
|
: 'Energy Clamp Conditions'),
|
||||||
Expanded(
|
Expanded(
|
||||||
child: Visibility(
|
child: Visibility(
|
||||||
visible: _functions.isNotEmpty,
|
visible: _functions.isNotEmpty,
|
||||||
@ -248,9 +250,18 @@ 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(
|
||||||
state.addedFunctions,
|
[selectedFunctionData],
|
||||||
widget.uniqueCustomId!,
|
widget.uniqueCustomId!,
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
@ -27,17 +27,16 @@ class EnergyValueSelectorWidget extends StatelessWidget {
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
final selectedFn =
|
final selectedFn = functions.firstWhere((f) => f.code == selectedFunction);
|
||||||
functions.firstWhere((f) => f.code == selectedFunction);
|
|
||||||
final values = selectedFn.getOperationalValues();
|
final values = selectedFn.getOperationalValues();
|
||||||
final step = selectedFn.step ?? 1.0;
|
final step = selectedFn.step;
|
||||||
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: false,
|
withSpecialChar: true,
|
||||||
currentCondition: functionData.condition,
|
currentCondition: functionData.condition,
|
||||||
dialogType: dialogType,
|
dialogType: dialogType,
|
||||||
sliderRange: sliderRange,
|
sliderRange: sliderRange,
|
||||||
@ -60,14 +59,14 @@ class EnergyValueSelectorWidget extends StatelessWidget {
|
|||||||
entityId: device?.uuid ?? '',
|
entityId: device?.uuid ?? '',
|
||||||
functionCode: selectedFunction,
|
functionCode: selectedFunction,
|
||||||
operationName: functionData.operationName,
|
operationName: functionData.operationName,
|
||||||
value: value.toInt(),
|
value: value,
|
||||||
condition: functionData.condition,
|
condition: functionData.condition,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
unit: _unit,
|
unit: _unit,
|
||||||
dividendOfRange: 1,
|
dividendOfRange: 1,
|
||||||
stepIncreaseAmount: step,
|
stepIncreaseAmount: step!,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -58,7 +58,9 @@ class ThreeGangSwitchHelper {
|
|||||||
child: Column(
|
child: Column(
|
||||||
mainAxisSize: MainAxisSize.min,
|
mainAxisSize: MainAxisSize.min,
|
||||||
children: [
|
children: [
|
||||||
const DialogHeader('3 Gangs Light Switch Condition'),
|
DialogHeader(dialogType == 'THEN'
|
||||||
|
? '3 Gangs Light Switch Functions'
|
||||||
|
: '3 Gangs Light Switch Condition'),
|
||||||
Expanded(
|
Expanded(
|
||||||
child: Row(
|
child: Row(
|
||||||
children: [
|
children: [
|
||||||
|
@ -59,7 +59,9 @@ class TwoGangSwitchHelper {
|
|||||||
child: Column(
|
child: Column(
|
||||||
mainAxisSize: MainAxisSize.min,
|
mainAxisSize: MainAxisSize.min,
|
||||||
children: [
|
children: [
|
||||||
const DialogHeader('2 Gangs Light Switch Condition'),
|
DialogHeader(dialogType == 'THEN'
|
||||||
|
? '2 Gangs Light Switch Functions'
|
||||||
|
: '2 Gangs Light Switch Condition'),
|
||||||
Expanded(
|
Expanded(
|
||||||
child: Row(
|
child: Row(
|
||||||
children: [
|
children: [
|
||||||
@ -143,9 +145,22 @@ 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(
|
||||||
state.addedFunctions,
|
[selectedFunctionData],
|
||||||
uniqueCustomId,
|
uniqueCustomId,
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
@ -63,7 +63,8 @@ class _WallPresenceSensorState extends State<WallPresenceSensor> {
|
|||||||
@override
|
@override
|
||||||
void initState() {
|
void initState() {
|
||||||
super.initState();
|
super.initState();
|
||||||
_wpsFunctions = widget.functions.whereType<WpsFunctions>().where((function) {
|
_wpsFunctions =
|
||||||
|
widget.functions.whereType<WpsFunctions>().where((function) {
|
||||||
if (widget.dialogType == 'THEN') {
|
if (widget.dialogType == 'THEN') {
|
||||||
return function.type == 'THEN' || function.type == 'BOTH';
|
return function.type == 'THEN' || function.type == 'BOTH';
|
||||||
}
|
}
|
||||||
@ -97,7 +98,9 @@ class _WallPresenceSensorState extends State<WallPresenceSensor> {
|
|||||||
child: Column(
|
child: Column(
|
||||||
mainAxisSize: MainAxisSize.min,
|
mainAxisSize: MainAxisSize.min,
|
||||||
children: [
|
children: [
|
||||||
const DialogHeader('Presence Sensor Condition'),
|
DialogHeader(widget.dialogType == 'THEN'
|
||||||
|
? 'Presence Sensor Functions'
|
||||||
|
: 'Presence Sensor Condition'),
|
||||||
Expanded(child: _buildMainContent(context, state)),
|
Expanded(child: _buildMainContent(context, state)),
|
||||||
_buildDialogFooter(context, state),
|
_buildDialogFooter(context, state),
|
||||||
],
|
],
|
||||||
@ -207,9 +210,18 @@ 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(
|
||||||
state.addedFunctions,
|
[selectedFunctionData],
|
||||||
widget.uniqueCustomId!,
|
widget.uniqueCustomId!,
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
@ -93,7 +93,9 @@ class _WaterHeaterDialogRoutinesState extends State<WaterHeaterDialogRoutines> {
|
|||||||
child: Column(
|
child: Column(
|
||||||
mainAxisSize: MainAxisSize.min,
|
mainAxisSize: MainAxisSize.min,
|
||||||
children: [
|
children: [
|
||||||
const DialogHeader('Water Heater Condition'),
|
DialogHeader(widget.dialogType == 'THEN'
|
||||||
|
? 'Water Heater Funtions'
|
||||||
|
: 'Water Heater Condition'),
|
||||||
Expanded(child: _buildMainContent(context, state)),
|
Expanded(child: _buildMainContent(context, state)),
|
||||||
_buildDialogFooter(context, state),
|
_buildDialogFooter(context, state),
|
||||||
],
|
],
|
||||||
@ -186,9 +188,18 @@ 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(
|
||||||
state.addedFunctions,
|
[selectedFunctionData],
|
||||||
widget.uniqueCustomId!,
|
widget.uniqueCustomId!,
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
@ -0,0 +1,34 @@
|
|||||||
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,27 @@
|
|||||||
|
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];
|
||||||
|
}
|
@ -0,0 +1,30 @@
|
|||||||
|
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];
|
||||||
|
}
|
@ -0,0 +1,3 @@
|
|||||||
|
class LoadCommunitiesParam {
|
||||||
|
const LoadCommunitiesParam();
|
||||||
|
}
|
@ -0,0 +1,6 @@
|
|||||||
|
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);
|
||||||
|
}
|
@ -0,0 +1,50 @@
|
|||||||
|
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(),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,17 @@
|
|||||||
|
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];
|
||||||
|
}
|
@ -0,0 +1,18 @@
|
|||||||
|
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];
|
||||||
|
}
|
@ -0,0 +1,39 @@
|
|||||||
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,10 @@
|
|||||||
|
import 'package:equatable/equatable.dart';
|
||||||
|
|
||||||
|
class CreateCommunityParam extends Equatable {
|
||||||
|
const CreateCommunityParam({required this.name});
|
||||||
|
|
||||||
|
final String name;
|
||||||
|
|
||||||
|
@override
|
||||||
|
List<Object> get props => [name];
|
||||||
|
}
|
@ -0,0 +1,6 @@
|
|||||||
|
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);
|
||||||
|
}
|
@ -0,0 +1,36 @@
|
|||||||
|
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()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,17 @@
|
|||||||
|
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];
|
||||||
|
}
|
@ -0,0 +1,30 @@
|
|||||||
|
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];
|
||||||
|
}
|
@ -0,0 +1,46 @@
|
|||||||
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,28 @@
|
|||||||
|
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];
|
||||||
|
}
|
@ -0,0 +1,11 @@
|
|||||||
|
class LoadProductsParam {
|
||||||
|
final String spaceUuid;
|
||||||
|
final String? type;
|
||||||
|
final String? status;
|
||||||
|
|
||||||
|
const LoadProductsParam({
|
||||||
|
required this.spaceUuid,
|
||||||
|
this.type,
|
||||||
|
this.status,
|
||||||
|
});
|
||||||
|
}
|
@ -0,0 +1,6 @@
|
|||||||
|
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);
|
||||||
|
}
|
@ -0,0 +1,32 @@
|
|||||||
|
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()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,17 @@
|
|||||||
|
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];
|
||||||
|
}
|
@ -0,0 +1,30 @@
|
|||||||
|
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];
|
||||||
|
}
|
@ -0,0 +1,40 @@
|
|||||||
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,108 @@
|
|||||||
|
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];
|
||||||
|
}
|
@ -0,0 +1,3 @@
|
|||||||
|
class LoadSpacesParam {
|
||||||
|
const LoadSpacesParam();
|
||||||
|
}
|
@ -0,0 +1,6 @@
|
|||||||
|
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);
|
||||||
|
}
|
@ -0,0 +1,34 @@
|
|||||||
|
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()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,17 @@
|
|||||||
|
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];
|
||||||
|
}
|
@ -0,0 +1,30 @@
|
|||||||
|
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];
|
||||||
|
}
|
@ -0,0 +1,49 @@
|
|||||||
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,36 @@
|
|||||||
|
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];
|
||||||
|
}
|
@ -0,0 +1,5 @@
|
|||||||
|
class LoadTagsParam {
|
||||||
|
final String? projectUuid;
|
||||||
|
|
||||||
|
const LoadTagsParam({this.projectUuid});
|
||||||
|
}
|
@ -0,0 +1,6 @@
|
|||||||
|
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);
|
||||||
|
}
|
@ -0,0 +1,32 @@
|
|||||||
|
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()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,17 @@
|
|||||||
|
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];
|
||||||
|
}
|
@ -0,0 +1,30 @@
|
|||||||
|
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];
|
||||||
|
}
|
@ -0,0 +1,39 @@
|
|||||||
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,10 @@
|
|||||||
|
import 'package:equatable/equatable.dart';
|
||||||
|
|
||||||
|
class UpdateCommunityParam extends Equatable {
|
||||||
|
const UpdateCommunityParam({required this.name});
|
||||||
|
|
||||||
|
final String name;
|
||||||
|
|
||||||
|
@override
|
||||||
|
List<Object> get props => [name];
|
||||||
|
}
|
@ -0,0 +1,6 @@
|
|||||||
|
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);
|
||||||
|
}
|
@ -0,0 +1,36 @@
|
|||||||
|
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()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,17 @@
|
|||||||
|
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];
|
||||||
|
}
|
@ -0,0 +1,30 @@
|
|||||||
|
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];
|
||||||
|
}
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user