mirror of
https://github.com/SyncrowIOT/web.git
synced 2025-07-11 15:47:44 +00:00
Compare commits
23 Commits
feat/use-p
...
SP-1151-FE
Author | SHA1 | Date | |
---|---|---|---|
9f75ce817e | |||
aa23daa0b4 | |||
61f0c3ad2b | |||
27fef7ddaa | |||
010176cc25 | |||
d08a1d1037 | |||
e634154fb3 | |||
c0f59aba61 | |||
7ee7681e09 | |||
57c5f4752c | |||
ad4f2ae382 | |||
eafb811d2e | |||
2d0dcc41df | |||
d89e3fac8e | |||
25acd67351 | |||
0c2a092f4d | |||
b968b5a6eb | |||
05edc7641a | |||
b8204f1015 | |||
d87fec796b | |||
b00b0c82dc | |||
0aa029a2fc | |||
dec3a25639 |
6
assets/icons/delete_space_model.svg
Normal file
6
assets/icons/delete_space_model.svg
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
<svg width="16" height="18" viewBox="0 0 16 18" fill="none" xmlns="http://www.w3.org/2000/svg">
|
||||||
|
<path d="M14.4 2.10938H11.7333V1.58203C11.7333 0.709699 11.0156 0 10.1333 0H5.86667C4.98443 0 4.26667 0.709699 4.26667 1.58203V2.10938H1.6C0.71776 2.10938 0 2.81907 0 3.69141C0 4.392 0.463111 4.9873 1.1024 5.19472L2.05369 16.5493C2.1222 17.3628 2.82258 18 3.64814 18H12.3519C13.1775 18 13.8778 17.3628 13.9464 16.5491L14.8976 5.19469C15.5369 4.9873 16 4.392 16 3.69141C16 2.81907 15.2822 2.10938 14.4 2.10938ZM5.33333 1.58203C5.33333 1.29125 5.57259 1.05469 5.86667 1.05469H10.1333C10.4274 1.05469 10.6667 1.29125 10.6667 1.58203V2.10938H5.33333V1.58203ZM12.8833 16.4618C12.8605 16.7329 12.6271 16.9453 12.3519 16.9453H3.64814C3.37298 16.9453 3.13952 16.7329 3.11673 16.462L2.17934 5.27344H13.8207L12.8833 16.4618ZM14.4 4.21875H1.6C1.30592 4.21875 1.06667 3.98218 1.06667 3.69141C1.06667 3.40063 1.30592 3.16406 1.6 3.16406H14.4C14.6941 3.16406 14.9333 3.40063 14.9333 3.69141C14.9333 3.98218 14.6941 4.21875 14.4 4.21875Z" fill="#999999"/>
|
||||||
|
<path d="M5.86561 15.3307L5.33228 6.82286C5.31404 6.53215 5.05957 6.31106 4.76698 6.32916C4.47297 6.3472 4.24943 6.59744 4.26764 6.88811L4.80097 15.396C4.8185 15.6756 5.05331 15.8907 5.33278 15.8907C5.64165 15.8907 5.88456 15.6335 5.86561 15.3307Z" fill="#999999"/>
|
||||||
|
<path d="M7.99989 6.32812C7.70534 6.32812 7.46655 6.56423 7.46655 6.85547V15.3633C7.46655 15.6545 7.70534 15.8906 7.99989 15.8906C8.29443 15.8906 8.53322 15.6545 8.53322 15.3633V6.85547C8.53322 6.56423 8.29443 6.32812 7.99989 6.32812Z" fill="#999999"/>
|
||||||
|
<path d="M11.233 6.32915C10.9396 6.31112 10.6859 6.53215 10.6677 6.82285L10.1343 15.3307C10.1162 15.6213 10.3397 15.8716 10.6337 15.8896C10.9278 15.9076 11.1808 15.6865 11.199 15.3959L11.7323 6.8881C11.7505 6.5974 11.527 6.34715 11.233 6.32915Z" fill="#999999"/>
|
||||||
|
</svg>
|
After Width: | Height: | Size: 1.8 KiB |
@ -20,15 +20,22 @@ class DialogTextfieldDropdown extends StatefulWidget {
|
|||||||
|
|
||||||
class _DialogTextfieldDropdownState extends State<DialogTextfieldDropdown> {
|
class _DialogTextfieldDropdownState extends State<DialogTextfieldDropdown> {
|
||||||
bool _isOpen = false;
|
bool _isOpen = false;
|
||||||
late OverlayEntry _overlayEntry;
|
OverlayEntry? _overlayEntry;
|
||||||
final TextEditingController _controller = TextEditingController();
|
final TextEditingController _controller = TextEditingController();
|
||||||
late List<String> _filteredItems; // Filtered items list
|
final FocusNode _focusNode = FocusNode();
|
||||||
|
List<String> _filteredItems = [];
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void initState() {
|
void initState() {
|
||||||
super.initState();
|
super.initState();
|
||||||
_controller.text = widget.initialValue ?? 'Select Tag';
|
_controller.text = widget.initialValue ?? '';
|
||||||
_filteredItems = List.from(widget.items); // Initialize filtered items
|
_filteredItems = List.from(widget.items);
|
||||||
|
|
||||||
|
_focusNode.addListener(() {
|
||||||
|
if (!_focusNode.hasFocus) {
|
||||||
|
_closeDropdown();
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
void _toggleDropdown() {
|
void _toggleDropdown() {
|
||||||
@ -41,14 +48,17 @@ class _DialogTextfieldDropdownState extends State<DialogTextfieldDropdown> {
|
|||||||
|
|
||||||
void _openDropdown() {
|
void _openDropdown() {
|
||||||
_overlayEntry = _createOverlayEntry();
|
_overlayEntry = _createOverlayEntry();
|
||||||
Overlay.of(context).insert(_overlayEntry);
|
Overlay.of(context).insert(_overlayEntry!);
|
||||||
_isOpen = true;
|
_isOpen = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void _closeDropdown() {
|
void _closeDropdown() {
|
||||||
_overlayEntry.remove();
|
if (_isOpen && _overlayEntry != null) {
|
||||||
|
_overlayEntry!.remove();
|
||||||
|
_overlayEntry = null;
|
||||||
_isOpen = false;
|
_isOpen = false;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
OverlayEntry _createOverlayEntry() {
|
OverlayEntry _createOverlayEntry() {
|
||||||
final renderBox = context.findRenderObject() as RenderBox;
|
final renderBox = context.findRenderObject() as RenderBox;
|
||||||
@ -58,9 +68,7 @@ class _DialogTextfieldDropdownState extends State<DialogTextfieldDropdown> {
|
|||||||
return OverlayEntry(
|
return OverlayEntry(
|
||||||
builder: (context) {
|
builder: (context) {
|
||||||
return GestureDetector(
|
return GestureDetector(
|
||||||
onTap: () {
|
onTap: _closeDropdown,
|
||||||
_closeDropdown();
|
|
||||||
},
|
|
||||||
behavior: HitTestBehavior.translucent,
|
behavior: HitTestBehavior.translucent,
|
||||||
child: Stack(
|
child: Stack(
|
||||||
children: [
|
children: [
|
||||||
@ -72,14 +80,15 @@ class _DialogTextfieldDropdownState extends State<DialogTextfieldDropdown> {
|
|||||||
elevation: 4.0,
|
elevation: 4.0,
|
||||||
child: Container(
|
child: Container(
|
||||||
color: ColorsManager.whiteColors,
|
color: ColorsManager.whiteColors,
|
||||||
constraints: const BoxConstraints(
|
constraints: const BoxConstraints(maxHeight: 200.0),
|
||||||
maxHeight: 200.0,
|
child: StatefulBuilder(
|
||||||
),
|
builder: (context, setStateDropdown) {
|
||||||
child: ListView.builder(
|
return ListView.builder(
|
||||||
shrinkWrap: true,
|
shrinkWrap: true,
|
||||||
itemCount: _filteredItems.length,
|
itemCount: _filteredItems.length,
|
||||||
itemBuilder: (context, index) {
|
itemBuilder: (context, index) {
|
||||||
final item = _filteredItems[index];
|
final item = _filteredItems[index];
|
||||||
|
|
||||||
return Container(
|
return Container(
|
||||||
decoration: const BoxDecoration(
|
decoration: const BoxDecoration(
|
||||||
border: Border(
|
border: Border(
|
||||||
@ -95,7 +104,8 @@ class _DialogTextfieldDropdownState extends State<DialogTextfieldDropdown> {
|
|||||||
.textTheme
|
.textTheme
|
||||||
.bodyMedium
|
.bodyMedium
|
||||||
?.copyWith(
|
?.copyWith(
|
||||||
color: ColorsManager.textPrimaryColor)),
|
color: ColorsManager
|
||||||
|
.textPrimaryColor)),
|
||||||
onTap: () {
|
onTap: () {
|
||||||
_controller.text = item;
|
_controller.text = item;
|
||||||
widget.onSelected(item);
|
widget.onSelected(item);
|
||||||
@ -108,6 +118,8 @@ class _DialogTextfieldDropdownState extends State<DialogTextfieldDropdown> {
|
|||||||
),
|
),
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
|
);
|
||||||
|
},
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
@ -122,7 +134,8 @@ class _DialogTextfieldDropdownState extends State<DialogTextfieldDropdown> {
|
|||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return GestureDetector(
|
return GestureDetector(
|
||||||
onTap: _toggleDropdown,
|
onTap: () => FocusScope.of(context).unfocus(),
|
||||||
|
behavior: HitTestBehavior.opaque,
|
||||||
child: Container(
|
child: Container(
|
||||||
padding: const EdgeInsets.symmetric(horizontal: 12.0, vertical: 8.0),
|
padding: const EdgeInsets.symmetric(horizontal: 12.0, vertical: 8.0),
|
||||||
decoration: BoxDecoration(
|
decoration: BoxDecoration(
|
||||||
@ -135,23 +148,26 @@ class _DialogTextfieldDropdownState extends State<DialogTextfieldDropdown> {
|
|||||||
Expanded(
|
Expanded(
|
||||||
child: TextFormField(
|
child: TextFormField(
|
||||||
controller: _controller,
|
controller: _controller,
|
||||||
onChanged: (value) {
|
focusNode: _focusNode,
|
||||||
setState(() {
|
onFieldSubmitted: (value) {
|
||||||
_filteredItems = widget.items
|
|
||||||
.where((item) =>
|
|
||||||
item.toLowerCase().contains(value.toLowerCase()))
|
|
||||||
.toList(); // Filter items dynamically
|
|
||||||
});
|
|
||||||
widget.onSelected(value);
|
widget.onSelected(value);
|
||||||
|
_closeDropdown();
|
||||||
|
},
|
||||||
|
onTapOutside: (event) {
|
||||||
|
widget.onSelected(_controller.text);
|
||||||
|
_closeDropdown();
|
||||||
},
|
},
|
||||||
style: Theme.of(context).textTheme.bodyMedium,
|
style: Theme.of(context).textTheme.bodyMedium,
|
||||||
decoration: const InputDecoration(
|
decoration: const InputDecoration(
|
||||||
hintText: 'Enter or Select tag',
|
hintText: 'Enter or Select a tag',
|
||||||
border: InputBorder.none,
|
border: InputBorder.none,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
const Icon(Icons.arrow_drop_down),
|
GestureDetector(
|
||||||
|
onTap: _toggleDropdown,
|
||||||
|
child: const Icon(Icons.arrow_drop_down),
|
||||||
|
),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
@ -3,18 +3,33 @@ import 'package:flutter_svg/svg.dart';
|
|||||||
import 'package:syncrow_web/utils/color_manager.dart';
|
import 'package:syncrow_web/utils/color_manager.dart';
|
||||||
import 'package:syncrow_web/utils/constants/assets.dart';
|
import 'package:syncrow_web/utils/constants/assets.dart';
|
||||||
|
|
||||||
class CustomSearchBar extends StatelessWidget {
|
class CustomSearchBar extends StatefulWidget {
|
||||||
final TextEditingController? controller;
|
final TextEditingController? controller;
|
||||||
final String hintText;
|
final String hintText;
|
||||||
|
final String? searchQuery;
|
||||||
final Function(String)? onSearchChanged; // Callback for search input changes
|
final Function(String)? onSearchChanged; // Callback for search input changes
|
||||||
|
|
||||||
const CustomSearchBar({
|
const CustomSearchBar({
|
||||||
super.key,
|
super.key,
|
||||||
this.controller,
|
this.controller,
|
||||||
|
this.searchQuery = '',
|
||||||
this.hintText = 'Search',
|
this.hintText = 'Search',
|
||||||
this.onSearchChanged,
|
this.onSearchChanged,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@override
|
||||||
|
State<CustomSearchBar> createState() => _CustomSearchBarState();
|
||||||
|
}
|
||||||
|
|
||||||
|
class _CustomSearchBarState extends State<CustomSearchBar> {
|
||||||
|
@override
|
||||||
|
void dispose() {
|
||||||
|
if (widget.controller != null) {
|
||||||
|
widget.controller!.dispose();
|
||||||
|
}
|
||||||
|
super.dispose();
|
||||||
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return Container(
|
return Container(
|
||||||
@ -36,16 +51,17 @@ class CustomSearchBar extends StatelessWidget {
|
|||||||
decoration: BoxDecoration(
|
decoration: BoxDecoration(
|
||||||
borderRadius: BorderRadius.circular(12),
|
borderRadius: BorderRadius.circular(12),
|
||||||
),
|
),
|
||||||
child: TextField(
|
child: TextFormField(
|
||||||
controller: controller,
|
controller: widget.controller,
|
||||||
|
initialValue: widget.searchQuery,
|
||||||
style: const TextStyle(
|
style: const TextStyle(
|
||||||
color: Colors.black,
|
color: Colors.black,
|
||||||
),
|
),
|
||||||
onChanged: onSearchChanged, // Call the callback on text change
|
onChanged: widget.onSearchChanged, // Call the callback on text change
|
||||||
decoration: InputDecoration(
|
decoration: InputDecoration(
|
||||||
filled: true,
|
filled: true,
|
||||||
fillColor: ColorsManager.textFieldGreyColor,
|
fillColor: ColorsManager.textFieldGreyColor,
|
||||||
hintText: hintText,
|
hintText: widget.hintText,
|
||||||
hintStyle: Theme.of(context).textTheme.bodyLarge!.copyWith(
|
hintStyle: Theme.of(context).textTheme.bodyLarge!.copyWith(
|
||||||
color: ColorsManager.lightGrayColor,
|
color: ColorsManager.lightGrayColor,
|
||||||
fontSize: 12,
|
fontSize: 12,
|
||||||
|
@ -1,25 +0,0 @@
|
|||||||
import 'package:flutter/material.dart';
|
|
||||||
import 'package:syncrow_web/pages/spaces_management/all_spaces/model/community_model.dart';
|
|
||||||
|
|
||||||
class SpacesSideTree extends StatefulWidget {
|
|
||||||
final List<CommunityModel> communities;
|
|
||||||
final String? selectedSpaceUuid;
|
|
||||||
const SpacesSideTree({
|
|
||||||
super.key,
|
|
||||||
required this.communities,
|
|
||||||
this.selectedSpaceUuid,
|
|
||||||
});
|
|
||||||
|
|
||||||
@override
|
|
||||||
State<SpacesSideTree> createState() => _SpacesSideTreeState();
|
|
||||||
}
|
|
||||||
|
|
||||||
class _SpacesSideTreeState extends State<SpacesSideTree> {
|
|
||||||
String _searchQuery = '';
|
|
||||||
String? _selectedSpaceUuid;
|
|
||||||
String? _selectedId;
|
|
||||||
@override
|
|
||||||
Widget build(BuildContext context) {
|
|
||||||
return const Placeholder();
|
|
||||||
}
|
|
||||||
}
|
|
@ -2,10 +2,8 @@ import 'package:flutter/gestures.dart';
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||||
import 'package:flutter_dotenv/flutter_dotenv.dart';
|
import 'package:flutter_dotenv/flutter_dotenv.dart';
|
||||||
import 'package:flutter_secure_storage/flutter_secure_storage.dart';
|
|
||||||
import 'package:go_router/go_router.dart';
|
import 'package:go_router/go_router.dart';
|
||||||
import 'package:syncrow_web/pages/auth/bloc/auth_bloc.dart';
|
import 'package:syncrow_web/pages/auth/bloc/auth_bloc.dart';
|
||||||
import 'package:syncrow_web/pages/common/bloc/project_cubit.dart';
|
|
||||||
import 'package:syncrow_web/pages/home/bloc/home_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/bloc/home_event.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';
|
||||||
@ -15,25 +13,22 @@ import 'package:syncrow_web/pages/visitor_password/bloc/visitor_password_bloc.da
|
|||||||
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';
|
||||||
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';
|
||||||
import 'package:syncrow_web/utils/theme/theme.dart';
|
import 'package:syncrow_web/utils/theme/theme.dart';
|
||||||
|
|
||||||
Future<void> main() async {
|
Future<void> main() async {
|
||||||
try {
|
try {
|
||||||
const environment =
|
const environment = String.fromEnvironment('FLAVOR', defaultValue: 'development');
|
||||||
String.fromEnvironment('FLAVOR', defaultValue: 'development');
|
|
||||||
await dotenv.load(fileName: '.env.$environment');
|
await dotenv.load(fileName: '.env.$environment');
|
||||||
WidgetsFlutterBinding.ensureInitialized();
|
WidgetsFlutterBinding.ensureInitialized();
|
||||||
initialSetup();
|
initialSetup();
|
||||||
} catch (_) {}
|
} catch (_) {}
|
||||||
final storage = FlutterSecureStorage();
|
runApp(MyApp());
|
||||||
final projectCubit = ProjectCubit(storage);
|
|
||||||
runApp(MyApp(projectCubit: projectCubit));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
class MyApp extends StatelessWidget {
|
class MyApp extends StatelessWidget {
|
||||||
final ProjectCubit projectCubit;
|
|
||||||
|
|
||||||
MyApp({super.key, required this.projectCubit});
|
MyApp({super.key});
|
||||||
|
|
||||||
final GoRouter _router = GoRouter(
|
final GoRouter _router = GoRouter(
|
||||||
initialLocation: RoutesConst.auth,
|
initialLocation: RoutesConst.auth,
|
||||||
@ -54,17 +49,15 @@ class MyApp extends StatelessWidget {
|
|||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return MultiBlocProvider(
|
return MultiBlocProvider(
|
||||||
providers: [
|
providers: [
|
||||||
BlocProvider(create: (context) => projectCubit),
|
BlocProvider(create: (context) => HomeBloc()..add(const FetchUserInfo())),
|
||||||
BlocProvider(
|
|
||||||
create: (context) => HomeBloc(projectCubit)..add(const FetchUserInfo())),
|
|
||||||
BlocProvider<VisitorPasswordBloc>(
|
BlocProvider<VisitorPasswordBloc>(
|
||||||
create: (context) => VisitorPasswordBloc(projectCubit),
|
create: (context) => VisitorPasswordBloc(),
|
||||||
),
|
),
|
||||||
BlocProvider<RoutineBloc>(
|
BlocProvider<RoutineBloc>(
|
||||||
create: (context) => RoutineBloc(projectCubit),
|
create: (context) => RoutineBloc(),
|
||||||
),
|
),
|
||||||
BlocProvider<SpaceTreeBloc>(
|
BlocProvider<SpaceTreeBloc>(
|
||||||
create: (context) => SpaceTreeBloc(projectCubit)..add(InitialEvent()),
|
create: (context) => SpaceTreeBloc()..add(InitialEvent()),
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
child: MaterialApp.router(
|
child: MaterialApp.router(
|
||||||
@ -77,6 +70,8 @@ class MyApp extends StatelessWidget {
|
|||||||
PointerDeviceKind.unknown,
|
PointerDeviceKind.unknown,
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
|
key: NavigationService.navigatorKey,
|
||||||
|
// scaffoldMessengerKey: NavigationService.snackbarKey,
|
||||||
theme: myTheme,
|
theme: myTheme,
|
||||||
routerConfig: _router,
|
routerConfig: _router,
|
||||||
));
|
));
|
||||||
|
@ -3,18 +3,18 @@ import 'package:flutter_bloc/flutter_bloc.dart';
|
|||||||
import 'package:syncrow_web/pages/access_management/bloc/access_event.dart';
|
import 'package:syncrow_web/pages/access_management/bloc/access_event.dart';
|
||||||
import 'package:syncrow_web/pages/access_management/bloc/access_state.dart';
|
import 'package:syncrow_web/pages/access_management/bloc/access_state.dart';
|
||||||
import 'package:syncrow_web/pages/access_management/model/password_model.dart';
|
import 'package:syncrow_web/pages/access_management/model/password_model.dart';
|
||||||
import 'package:syncrow_web/pages/common/bloc/project_cubit.dart';
|
import 'package:syncrow_web/pages/common/bloc/project_manager.dart';
|
||||||
import 'package:syncrow_web/pages/common/hour_picker_dialog.dart';
|
import 'package:syncrow_web/pages/common/hour_picker_dialog.dart';
|
||||||
import 'package:syncrow_web/services/access_mang_api.dart';
|
import 'package:syncrow_web/services/access_mang_api.dart';
|
||||||
import 'package:syncrow_web/utils/color_manager.dart';
|
import 'package:syncrow_web/utils/color_manager.dart';
|
||||||
import 'package:syncrow_web/utils/constants/app_enum.dart';
|
import 'package:syncrow_web/utils/constants/app_enum.dart';
|
||||||
|
import 'package:syncrow_web/utils/constants/strings_manager.dart';
|
||||||
import 'package:syncrow_web/utils/constants/temp_const.dart';
|
import 'package:syncrow_web/utils/constants/temp_const.dart';
|
||||||
|
import 'package:syncrow_web/utils/helpers/shared_preferences_helper.dart';
|
||||||
import 'package:syncrow_web/utils/snack_bar.dart';
|
import 'package:syncrow_web/utils/snack_bar.dart';
|
||||||
|
|
||||||
class AccessBloc extends Bloc<AccessEvent, AccessState> {
|
class AccessBloc extends Bloc<AccessEvent, AccessState> {
|
||||||
final ProjectCubit projectCubit;
|
AccessBloc() : super((AccessInitial())) {
|
||||||
|
|
||||||
AccessBloc(this.projectCubit) : super((AccessInitial())) {
|
|
||||||
on<FetchTableData>(_onFetchTableData);
|
on<FetchTableData>(_onFetchTableData);
|
||||||
on<SelectTime>(selectTime);
|
on<SelectTime>(selectTime);
|
||||||
on<FilterDataEvent>(_filterData);
|
on<FilterDataEvent>(_filterData);
|
||||||
@ -34,10 +34,9 @@ class AccessBloc extends Bloc<AccessEvent, AccessState> {
|
|||||||
Future<void> _onFetchTableData(
|
Future<void> _onFetchTableData(
|
||||||
FetchTableData event, Emitter<AccessState> emit) async {
|
FetchTableData event, Emitter<AccessState> emit) async {
|
||||||
try {
|
try {
|
||||||
final projectUuid = projectCubit.state;
|
final projectUuid = await ProjectManager.getProjectUUID() ?? '';
|
||||||
emit(AccessLoaded());
|
emit(AccessLoaded());
|
||||||
data = await AccessMangApi()
|
data = await AccessMangApi().fetchVisitorPassword(projectUuid);
|
||||||
.fetchVisitorPassword(projectUuid ?? TempConst.projectId);
|
|
||||||
filteredData = data;
|
filteredData = data;
|
||||||
updateTabsCount();
|
updateTabsCount();
|
||||||
emit(TableLoaded(data));
|
emit(TableLoaded(data));
|
||||||
|
@ -3,7 +3,7 @@ import 'package:flutter_bloc/flutter_bloc.dart';
|
|||||||
import 'package:syncrow_web/pages/access_management/bloc/access_bloc.dart';
|
import 'package:syncrow_web/pages/access_management/bloc/access_bloc.dart';
|
||||||
import 'package:syncrow_web/pages/access_management/bloc/access_event.dart';
|
import 'package:syncrow_web/pages/access_management/bloc/access_event.dart';
|
||||||
import 'package:syncrow_web/pages/access_management/bloc/access_state.dart';
|
import 'package:syncrow_web/pages/access_management/bloc/access_state.dart';
|
||||||
import 'package:syncrow_web/pages/common/bloc/project_cubit.dart';
|
import 'package:syncrow_web/pages/common/bloc/project_manager.dart';
|
||||||
import 'package:syncrow_web/pages/common/buttons/default_button.dart';
|
import 'package:syncrow_web/pages/common/buttons/default_button.dart';
|
||||||
import 'package:syncrow_web/pages/common/buttons/search_reset_buttons.dart';
|
import 'package:syncrow_web/pages/common/buttons/search_reset_buttons.dart';
|
||||||
import 'package:syncrow_web/pages/common/custom_table.dart';
|
import 'package:syncrow_web/pages/common/custom_table.dart';
|
||||||
@ -28,7 +28,8 @@ class AccessManagementPage extends StatelessWidget with HelperResponsiveLayout {
|
|||||||
final isLargeScreen = isLargeScreenSize(context);
|
final isLargeScreen = isLargeScreenSize(context);
|
||||||
final isSmallScreen = isSmallScreenSize(context);
|
final isSmallScreen = isSmallScreenSize(context);
|
||||||
final isHalfMediumScreen = isHafMediumScreenSize(context);
|
final isHalfMediumScreen = isHafMediumScreenSize(context);
|
||||||
final padding = isLargeScreen ? const EdgeInsets.all(30) : const EdgeInsets.all(15);
|
final padding =
|
||||||
|
isLargeScreen ? const EdgeInsets.all(30) : const EdgeInsets.all(15);
|
||||||
|
|
||||||
return WebScaffold(
|
return WebScaffold(
|
||||||
enableMenuSidebar: false,
|
enableMenuSidebar: false,
|
||||||
@ -40,7 +41,8 @@ class AccessManagementPage extends StatelessWidget with HelperResponsiveLayout {
|
|||||||
),
|
),
|
||||||
rightBody: const NavigateHomeGridView(),
|
rightBody: const NavigateHomeGridView(),
|
||||||
scaffoldBody: BlocProvider(
|
scaffoldBody: BlocProvider(
|
||||||
create: (BuildContext context) => AccessBloc(context.read<ProjectCubit>())..add(FetchTableData()),
|
create: (BuildContext context) =>
|
||||||
|
AccessBloc()..add(FetchTableData()),
|
||||||
child: BlocConsumer<AccessBloc, AccessState>(
|
child: BlocConsumer<AccessBloc, AccessState>(
|
||||||
listener: (context, state) {},
|
listener: (context, state) {},
|
||||||
builder: (context, state) {
|
builder: (context, state) {
|
||||||
@ -94,11 +96,14 @@ class AccessManagementPage extends StatelessWidget with HelperResponsiveLayout {
|
|||||||
return [
|
return [
|
||||||
item.passwordName,
|
item.passwordName,
|
||||||
item.passwordType.value,
|
item.passwordType.value,
|
||||||
accessBloc.timestampToDate(item.effectiveTime),
|
accessBloc
|
||||||
accessBloc.timestampToDate(item.invalidTime),
|
.timestampToDate(item.effectiveTime),
|
||||||
|
accessBloc
|
||||||
|
.timestampToDate(item.invalidTime),
|
||||||
item.deviceName.toString(),
|
item.deviceName.toString(),
|
||||||
item.authorizerEmail.toString(),
|
item.authorizerEmail.toString(),
|
||||||
accessBloc.timestampToDate(item.invalidTime),
|
accessBloc
|
||||||
|
.timestampToDate(item.invalidTime),
|
||||||
item.passwordStatus.value,
|
item.passwordStatus.value,
|
||||||
];
|
];
|
||||||
}).toList(),
|
}).toList(),
|
||||||
@ -109,7 +114,8 @@ class AccessManagementPage extends StatelessWidget with HelperResponsiveLayout {
|
|||||||
})));
|
})));
|
||||||
}
|
}
|
||||||
|
|
||||||
Wrap _buildVisitorAdminPasswords(BuildContext context, AccessBloc accessBloc) {
|
Wrap _buildVisitorAdminPasswords(
|
||||||
|
BuildContext context, AccessBloc accessBloc) {
|
||||||
return Wrap(
|
return Wrap(
|
||||||
spacing: 10,
|
spacing: 10,
|
||||||
runSpacing: 10,
|
runSpacing: 10,
|
||||||
@ -135,7 +141,8 @@ class AccessManagementPage extends StatelessWidget with HelperResponsiveLayout {
|
|||||||
borderRadius: 8,
|
borderRadius: 8,
|
||||||
child: Text(
|
child: Text(
|
||||||
'Create Visitor Password ',
|
'Create Visitor Password ',
|
||||||
style: context.textTheme.titleSmall!.copyWith(color: Colors.white, fontSize: 12),
|
style: context.textTheme.titleSmall!
|
||||||
|
.copyWith(color: Colors.white, fontSize: 12),
|
||||||
)),
|
)),
|
||||||
),
|
),
|
||||||
// Container(
|
// Container(
|
||||||
@ -173,8 +180,10 @@ class AccessManagementPage extends StatelessWidget with HelperResponsiveLayout {
|
|||||||
description: '',
|
description: '',
|
||||||
onSubmitted: (value) {
|
onSubmitted: (value) {
|
||||||
accessBloc.add(FilterDataEvent(
|
accessBloc.add(FilterDataEvent(
|
||||||
emailAuthorizer: accessBloc.emailAuthorizer.text.toLowerCase(),
|
emailAuthorizer:
|
||||||
selectedTabIndex: BlocProvider.of<AccessBloc>(context).selectedIndex,
|
accessBloc.emailAuthorizer.text.toLowerCase(),
|
||||||
|
selectedTabIndex:
|
||||||
|
BlocProvider.of<AccessBloc>(context).selectedIndex,
|
||||||
passwordName: accessBloc.passwordName.text.toLowerCase(),
|
passwordName: accessBloc.passwordName.text.toLowerCase(),
|
||||||
startTime: accessBloc.effectiveTimeTimeStamp,
|
startTime: accessBloc.effectiveTimeTimeStamp,
|
||||||
endTime: accessBloc.expirationTimeTimeStamp));
|
endTime: accessBloc.expirationTimeTimeStamp));
|
||||||
@ -192,8 +201,10 @@ class AccessManagementPage extends StatelessWidget with HelperResponsiveLayout {
|
|||||||
description: '',
|
description: '',
|
||||||
onSubmitted: (value) {
|
onSubmitted: (value) {
|
||||||
accessBloc.add(FilterDataEvent(
|
accessBloc.add(FilterDataEvent(
|
||||||
emailAuthorizer: accessBloc.emailAuthorizer.text.toLowerCase(),
|
emailAuthorizer:
|
||||||
selectedTabIndex: BlocProvider.of<AccessBloc>(context).selectedIndex,
|
accessBloc.emailAuthorizer.text.toLowerCase(),
|
||||||
|
selectedTabIndex:
|
||||||
|
BlocProvider.of<AccessBloc>(context).selectedIndex,
|
||||||
passwordName: accessBloc.passwordName.text.toLowerCase(),
|
passwordName: accessBloc.passwordName.text.toLowerCase(),
|
||||||
startTime: accessBloc.effectiveTimeTimeStamp,
|
startTime: accessBloc.effectiveTimeTimeStamp,
|
||||||
endTime: accessBloc.expirationTimeTimeStamp));
|
endTime: accessBloc.expirationTimeTimeStamp));
|
||||||
@ -222,7 +233,8 @@ class AccessManagementPage extends StatelessWidget with HelperResponsiveLayout {
|
|||||||
onSearch: () {
|
onSearch: () {
|
||||||
accessBloc.add(FilterDataEvent(
|
accessBloc.add(FilterDataEvent(
|
||||||
emailAuthorizer: accessBloc.emailAuthorizer.text.toLowerCase(),
|
emailAuthorizer: accessBloc.emailAuthorizer.text.toLowerCase(),
|
||||||
selectedTabIndex: BlocProvider.of<AccessBloc>(context).selectedIndex,
|
selectedTabIndex:
|
||||||
|
BlocProvider.of<AccessBloc>(context).selectedIndex,
|
||||||
passwordName: accessBloc.passwordName.text.toLowerCase(),
|
passwordName: accessBloc.passwordName.text.toLowerCase(),
|
||||||
startTime: accessBloc.effectiveTimeTimeStamp,
|
startTime: accessBloc.effectiveTimeTimeStamp,
|
||||||
endTime: accessBloc.expirationTimeTimeStamp));
|
endTime: accessBloc.expirationTimeTimeStamp));
|
||||||
@ -250,8 +262,10 @@ class AccessManagementPage extends StatelessWidget with HelperResponsiveLayout {
|
|||||||
description: '',
|
description: '',
|
||||||
onSubmitted: (value) {
|
onSubmitted: (value) {
|
||||||
accessBloc.add(FilterDataEvent(
|
accessBloc.add(FilterDataEvent(
|
||||||
emailAuthorizer: accessBloc.emailAuthorizer.text.toLowerCase(),
|
emailAuthorizer:
|
||||||
selectedTabIndex: BlocProvider.of<AccessBloc>(context).selectedIndex,
|
accessBloc.emailAuthorizer.text.toLowerCase(),
|
||||||
|
selectedTabIndex:
|
||||||
|
BlocProvider.of<AccessBloc>(context).selectedIndex,
|
||||||
passwordName: accessBloc.passwordName.text.toLowerCase(),
|
passwordName: accessBloc.passwordName.text.toLowerCase(),
|
||||||
startTime: accessBloc.effectiveTimeTimeStamp,
|
startTime: accessBloc.effectiveTimeTimeStamp,
|
||||||
endTime: accessBloc.expirationTimeTimeStamp));
|
endTime: accessBloc.expirationTimeTimeStamp));
|
||||||
@ -275,7 +289,8 @@ class AccessManagementPage extends StatelessWidget with HelperResponsiveLayout {
|
|||||||
onSearch: () {
|
onSearch: () {
|
||||||
accessBloc.add(FilterDataEvent(
|
accessBloc.add(FilterDataEvent(
|
||||||
emailAuthorizer: accessBloc.emailAuthorizer.text.toLowerCase(),
|
emailAuthorizer: accessBloc.emailAuthorizer.text.toLowerCase(),
|
||||||
selectedTabIndex: BlocProvider.of<AccessBloc>(context).selectedIndex,
|
selectedTabIndex:
|
||||||
|
BlocProvider.of<AccessBloc>(context).selectedIndex,
|
||||||
passwordName: accessBloc.passwordName.text.toLowerCase(),
|
passwordName: accessBloc.passwordName.text.toLowerCase(),
|
||||||
startTime: accessBloc.effectiveTimeTimeStamp,
|
startTime: accessBloc.effectiveTimeTimeStamp,
|
||||||
endTime: accessBloc.expirationTimeTimeStamp));
|
endTime: accessBloc.expirationTimeTimeStamp));
|
||||||
|
@ -9,10 +9,13 @@ import 'package:syncrow_web/pages/auth/model/login_with_email_model.dart';
|
|||||||
import 'package:syncrow_web/pages/auth/model/region_model.dart';
|
import 'package:syncrow_web/pages/auth/model/region_model.dart';
|
||||||
import 'package:syncrow_web/pages/auth/model/token.dart';
|
import 'package:syncrow_web/pages/auth/model/token.dart';
|
||||||
import 'package:syncrow_web/pages/auth/model/user_model.dart';
|
import 'package:syncrow_web/pages/auth/model/user_model.dart';
|
||||||
import 'package:syncrow_web/pages/common/bloc/project_cubit.dart';
|
import 'package:syncrow_web/pages/common/bloc/project_manager.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/auth_api.dart';
|
import 'package:syncrow_web/services/auth_api.dart';
|
||||||
import 'package:syncrow_web/utils/constants/strings_manager.dart';
|
import 'package:syncrow_web/utils/constants/strings_manager.dart';
|
||||||
import 'package:syncrow_web/utils/helpers/shared_preferences_helper.dart';
|
import 'package:syncrow_web/utils/helpers/shared_preferences_helper.dart';
|
||||||
|
import 'package:syncrow_web/utils/navigation_service.dart';
|
||||||
import 'package:syncrow_web/utils/snack_bar.dart';
|
import 'package:syncrow_web/utils/snack_bar.dart';
|
||||||
|
|
||||||
class AuthBloc extends Bloc<AuthEvent, AuthState> {
|
class AuthBloc extends Bloc<AuthEvent, AuthState> {
|
||||||
@ -32,8 +35,7 @@ class AuthBloc extends Bloc<AuthEvent, AuthState> {
|
|||||||
|
|
||||||
////////////////////////////// forget password //////////////////////////////////
|
////////////////////////////// forget password //////////////////////////////////
|
||||||
final TextEditingController forgetEmailController = TextEditingController();
|
final TextEditingController forgetEmailController = TextEditingController();
|
||||||
final TextEditingController forgetPasswordController =
|
final TextEditingController forgetPasswordController = TextEditingController();
|
||||||
TextEditingController();
|
|
||||||
final TextEditingController forgetOtp = TextEditingController();
|
final TextEditingController forgetOtp = TextEditingController();
|
||||||
final forgetFormKey = GlobalKey<FormState>();
|
final forgetFormKey = GlobalKey<FormState>();
|
||||||
final forgetEmailKey = GlobalKey<FormState>();
|
final forgetEmailKey = GlobalKey<FormState>();
|
||||||
@ -50,8 +52,7 @@ class AuthBloc extends Bloc<AuthEvent, AuthState> {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
_remainingTime = 1;
|
_remainingTime = 1;
|
||||||
add(UpdateTimerEvent(
|
add(UpdateTimerEvent(remainingTime: _remainingTime, isButtonEnabled: false));
|
||||||
remainingTime: _remainingTime, isButtonEnabled: false));
|
|
||||||
try {
|
try {
|
||||||
forgetEmailValidate = '';
|
forgetEmailValidate = '';
|
||||||
_remainingTime = (await AuthenticationAPI.sendOtp(
|
_remainingTime = (await AuthenticationAPI.sendOtp(
|
||||||
@ -88,8 +89,7 @@ class AuthBloc extends Bloc<AuthEvent, AuthState> {
|
|||||||
_timer?.cancel();
|
_timer?.cancel();
|
||||||
add(const UpdateTimerEvent(remainingTime: 0, isButtonEnabled: true));
|
add(const UpdateTimerEvent(remainingTime: 0, isButtonEnabled: true));
|
||||||
} else {
|
} else {
|
||||||
add(UpdateTimerEvent(
|
add(UpdateTimerEvent(remainingTime: _remainingTime, isButtonEnabled: false));
|
||||||
remainingTime: _remainingTime, isButtonEnabled: false));
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -99,8 +99,7 @@ class AuthBloc extends Bloc<AuthEvent, AuthState> {
|
|||||||
emit(const TimerState(isButtonEnabled: true, remainingTime: 0));
|
emit(const TimerState(isButtonEnabled: true, remainingTime: 0));
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> changePassword(
|
Future<void> changePassword(ChangePasswordEvent event, Emitter<AuthState> emit) async {
|
||||||
ChangePasswordEvent event, Emitter<AuthState> emit) async {
|
|
||||||
emit(LoadingForgetState());
|
emit(LoadingForgetState());
|
||||||
try {
|
try {
|
||||||
var response = await AuthenticationAPI.verifyOtp(
|
var response = await AuthenticationAPI.verifyOtp(
|
||||||
@ -116,8 +115,7 @@ class AuthBloc extends Bloc<AuthEvent, AuthState> {
|
|||||||
}
|
}
|
||||||
} on DioException catch (e) {
|
} on DioException catch (e) {
|
||||||
final errorData = e.response!.data;
|
final errorData = e.response!.data;
|
||||||
String errorMessage =
|
String errorMessage = errorData['error']['message'] ?? 'something went wrong';
|
||||||
errorData['error']['message'] ?? 'something went wrong';
|
|
||||||
validate = errorMessage;
|
validate = errorMessage;
|
||||||
emit(AuthInitialState());
|
emit(AuthInitialState());
|
||||||
}
|
}
|
||||||
@ -131,9 +129,7 @@ class AuthBloc extends Bloc<AuthEvent, AuthState> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void _onUpdateTimer(UpdateTimerEvent event, Emitter<AuthState> emit) {
|
void _onUpdateTimer(UpdateTimerEvent event, Emitter<AuthState> emit) {
|
||||||
emit(TimerState(
|
emit(TimerState(isButtonEnabled: event.isButtonEnabled, remainingTime: event.remainingTime));
|
||||||
isButtonEnabled: event.isButtonEnabled,
|
|
||||||
remainingTime: event.remainingTime));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
///////////////////////////////////// login /////////////////////////////////////
|
///////////////////////////////////// login /////////////////////////////////////
|
||||||
@ -183,15 +179,13 @@ class AuthBloc extends Bloc<AuthEvent, AuthState> {
|
|||||||
|
|
||||||
if (token.accessTokenIsNotEmpty) {
|
if (token.accessTokenIsNotEmpty) {
|
||||||
FlutterSecureStorage storage = const FlutterSecureStorage();
|
FlutterSecureStorage storage = const FlutterSecureStorage();
|
||||||
await storage.write(
|
await storage.write(key: Token.loginAccessTokenKey, value: token.accessToken);
|
||||||
key: Token.loginAccessTokenKey, value: token.accessToken);
|
|
||||||
const FlutterSecureStorage().write(
|
const FlutterSecureStorage().write(
|
||||||
key: UserModel.userUuidKey,
|
key: UserModel.userUuidKey,
|
||||||
value: Token.decodeToken(token.accessToken)['uuid'].toString());
|
value: Token.decodeToken(token.accessToken)['uuid'].toString());
|
||||||
user = UserModel.fromToken(token);
|
user = UserModel.fromToken(token);
|
||||||
loginEmailController.clear();
|
loginEmailController.clear();
|
||||||
loginPasswordController.clear();
|
loginPasswordController.clear();
|
||||||
debugPrint("token " + token.accessToken);
|
|
||||||
emit(LoginSuccess());
|
emit(LoginSuccess());
|
||||||
} else {
|
} else {
|
||||||
emit(const LoginFailure(error: 'Something went wrong'));
|
emit(const LoginFailure(error: 'Something went wrong'));
|
||||||
@ -342,14 +336,12 @@ class AuthBloc extends Bloc<AuthEvent, AuthState> {
|
|||||||
static Future<String> getTokenAndValidate() async {
|
static Future<String> getTokenAndValidate() async {
|
||||||
try {
|
try {
|
||||||
const storage = FlutterSecureStorage();
|
const storage = FlutterSecureStorage();
|
||||||
final firstLaunch = await SharedPreferencesHelper.readBoolFromSP(
|
final firstLaunch =
|
||||||
StringsManager.firstLaunch) ??
|
await SharedPreferencesHelper.readBoolFromSP(StringsManager.firstLaunch) ?? true;
|
||||||
true;
|
|
||||||
if (firstLaunch) {
|
if (firstLaunch) {
|
||||||
storage.deleteAll();
|
storage.deleteAll();
|
||||||
}
|
}
|
||||||
await SharedPreferencesHelper.saveBoolToSP(
|
await SharedPreferencesHelper.saveBoolToSP(StringsManager.firstLaunch, false);
|
||||||
StringsManager.firstLaunch, false);
|
|
||||||
final value = await storage.read(key: Token.loginAccessTokenKey) ?? '';
|
final value = await storage.read(key: Token.loginAccessTokenKey) ?? '';
|
||||||
if (value.isEmpty) {
|
if (value.isEmpty) {
|
||||||
return 'Token not found';
|
return 'Token not found';
|
||||||
@ -402,9 +394,7 @@ class AuthBloc extends Bloc<AuthEvent, AuthState> {
|
|||||||
final String formattedTime = [
|
final String formattedTime = [
|
||||||
if (days > 0) '${days}d', // Append 'd' for days
|
if (days > 0) '${days}d', // Append 'd' for days
|
||||||
if (days > 0 || hours > 0)
|
if (days > 0 || hours > 0)
|
||||||
hours
|
hours.toString().padLeft(2, '0'), // Show hours if there are days or hours
|
||||||
.toString()
|
|
||||||
.padLeft(2, '0'), // Show hours if there are days or hours
|
|
||||||
minutes.toString().padLeft(2, '0'),
|
minutes.toString().padLeft(2, '0'),
|
||||||
seconds.toString().padLeft(2, '0'),
|
seconds.toString().padLeft(2, '0'),
|
||||||
].join(':');
|
].join(':');
|
||||||
@ -442,13 +432,10 @@ class AuthBloc extends Bloc<AuthEvent, AuthState> {
|
|||||||
emit(LoginInitial());
|
emit(LoginInitial());
|
||||||
}
|
}
|
||||||
|
|
||||||
static Future<void> logout(
|
static Future<void> logout(BuildContext context) async {
|
||||||
BuildContext context, ProjectCubit projectCubit) async {
|
|
||||||
final storage = FlutterSecureStorage();
|
final storage = FlutterSecureStorage();
|
||||||
|
ProjectManager.clearProjectUUID();
|
||||||
await storage.delete(key: ProjectCubit.projectKey);
|
context.read<SpaceTreeBloc>().add(ClearAllData());
|
||||||
|
|
||||||
projectCubit.clearProjectUUID();
|
|
||||||
storage.deleteAll();
|
storage.deleteAll();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,19 +0,0 @@
|
|||||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
|
||||||
import 'package:flutter_secure_storage/flutter_secure_storage.dart';
|
|
||||||
|
|
||||||
class ProjectCubit extends Cubit<String?> {
|
|
||||||
final FlutterSecureStorage storage;
|
|
||||||
static const String projectKey = "selected_project_uuid";
|
|
||||||
|
|
||||||
ProjectCubit(this.storage) : super(null);
|
|
||||||
|
|
||||||
Future<void> setProjectUUID(String newUUID) async {
|
|
||||||
await storage.write(key: projectKey, value: newUUID);
|
|
||||||
emit(newUUID);
|
|
||||||
}
|
|
||||||
|
|
||||||
Future<void> clearProjectUUID() async {
|
|
||||||
await storage.delete(key: projectKey);
|
|
||||||
emit(null);
|
|
||||||
}
|
|
||||||
}
|
|
19
lib/pages/common/bloc/project_manager.dart
Normal file
19
lib/pages/common/bloc/project_manager.dart
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
import 'package:syncrow_web/utils/constants/strings_manager.dart';
|
||||||
|
import 'package:syncrow_web/utils/helpers/shared_preferences_helper.dart';
|
||||||
|
|
||||||
|
class ProjectManager {
|
||||||
|
static Future<String?> getProjectUUID() async {
|
||||||
|
final projectUuid = await SharedPreferencesHelper.readStringFromSP(
|
||||||
|
StringsManager.projectKey);
|
||||||
|
return projectUuid.isNotEmpty ? projectUuid : null;
|
||||||
|
}
|
||||||
|
|
||||||
|
static Future<void> setProjectUUID(String newUUID) async {
|
||||||
|
await SharedPreferencesHelper.saveStringToSP(
|
||||||
|
StringsManager.projectKey, newUUID);
|
||||||
|
}
|
||||||
|
|
||||||
|
static Future<void> clearProjectUUID() async {
|
||||||
|
await SharedPreferencesHelper.removeValueFromSP(StringsManager.projectKey);
|
||||||
|
}
|
||||||
|
}
|
@ -1,11 +1,13 @@
|
|||||||
import 'package:equatable/equatable.dart';
|
import 'package:equatable/equatable.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||||
import 'package:syncrow_web/pages/common/bloc/project_cubit.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/space_tree/bloc/space_tree_bloc.dart';
|
import 'package:syncrow_web/pages/space_tree/bloc/space_tree_bloc.dart';
|
||||||
import 'package:syncrow_web/services/devices_mang_api.dart';
|
import 'package:syncrow_web/services/devices_mang_api.dart';
|
||||||
|
import 'package:syncrow_web/utils/constants/strings_manager.dart';
|
||||||
import 'package:syncrow_web/utils/constants/temp_const.dart';
|
import 'package:syncrow_web/utils/constants/temp_const.dart';
|
||||||
|
import 'package:syncrow_web/utils/helpers/shared_preferences_helper.dart';
|
||||||
|
|
||||||
part 'device_managment_event.dart';
|
part 'device_managment_event.dart';
|
||||||
part 'device_managment_state.dart';
|
part 'device_managment_state.dart';
|
||||||
@ -22,9 +24,8 @@ class DeviceManagementBloc
|
|||||||
String currentProductName = '';
|
String currentProductName = '';
|
||||||
String? currentCommunity;
|
String? currentCommunity;
|
||||||
String? currentUnitName;
|
String? currentUnitName;
|
||||||
final ProjectCubit projectCubit;
|
|
||||||
|
|
||||||
DeviceManagementBloc(this.projectCubit) : super(DeviceManagementInitial()) {
|
DeviceManagementBloc() : super(DeviceManagementInitial()) {
|
||||||
on<FetchDevices>(_onFetchDevices);
|
on<FetchDevices>(_onFetchDevices);
|
||||||
on<FilterDevices>(_onFilterDevices);
|
on<FilterDevices>(_onFilterDevices);
|
||||||
on<SelectedFilterChanged>(_onSelectedFilterChanged);
|
on<SelectedFilterChanged>(_onSelectedFilterChanged);
|
||||||
@ -42,18 +43,18 @@ class DeviceManagementBloc
|
|||||||
List<AllDevicesModel> devices = [];
|
List<AllDevicesModel> devices = [];
|
||||||
_devices.clear();
|
_devices.clear();
|
||||||
var spaceBloc = event.context.read<SpaceTreeBloc>();
|
var spaceBloc = event.context.read<SpaceTreeBloc>();
|
||||||
final projectUuid = projectCubit.state;
|
final projectUuid = await ProjectManager.getProjectUUID() ?? '';
|
||||||
|
|
||||||
if (spaceBloc.state.selectedCommunities.isEmpty) {
|
if (spaceBloc.state.selectedCommunities.isEmpty) {
|
||||||
devices = await DevicesManagementApi()
|
devices = await DevicesManagementApi()
|
||||||
.fetchDevices('', '', projectUuid ?? TempConst.projectId);
|
.fetchDevices('', '', projectUuid );
|
||||||
} else {
|
} else {
|
||||||
for (var community in spaceBloc.state.selectedCommunities) {
|
for (var community in spaceBloc.state.selectedCommunities) {
|
||||||
List<String> spacesList =
|
List<String> spacesList =
|
||||||
spaceBloc.state.selectedCommunityAndSpaces[community] ?? [];
|
spaceBloc.state.selectedCommunityAndSpaces[community] ?? [];
|
||||||
for (var space in spacesList) {
|
for (var space in spacesList) {
|
||||||
devices.addAll(await DevicesManagementApi().fetchDevices(
|
devices.addAll(await DevicesManagementApi().fetchDevices(
|
||||||
community, space, projectUuid ?? TempConst.projectId));
|
community, space, projectUuid));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||||
import 'package:syncrow_web/pages/common/bloc/project_cubit.dart';
|
import 'package:syncrow_web/pages/common/bloc/project_manager.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/bloc/device_mgmt_bloc/device_managment_bloc.dart';
|
||||||
import 'package:syncrow_web/pages/device_managment/all_devices/widgets/device_managment_body.dart';
|
import 'package:syncrow_web/pages/device_managment/all_devices/widgets/device_managment_body.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';
|
||||||
@ -20,7 +20,8 @@ class DeviceManagementPage extends StatelessWidget with HelperResponsiveLayout {
|
|||||||
return MultiBlocProvider(
|
return MultiBlocProvider(
|
||||||
providers: [
|
providers: [
|
||||||
BlocProvider(
|
BlocProvider(
|
||||||
create: (context) => DeviceManagementBloc(context.read<ProjectCubit>())..add(FetchDevices(context)),
|
create: (context) =>
|
||||||
|
DeviceManagementBloc()..add(FetchDevices(context)),
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
child: WebScaffold(
|
child: WebScaffold(
|
||||||
@ -42,6 +43,7 @@ class DeviceManagementPage extends StatelessWidget with HelperResponsiveLayout {
|
|||||||
context
|
context
|
||||||
.read<RoutineBloc>()
|
.read<RoutineBloc>()
|
||||||
.add(const TriggerSwitchTabsEvent(isRoutineTab: false));
|
.add(const TriggerSwitchTabsEvent(isRoutineTab: false));
|
||||||
|
context.read<DeviceManagementBloc>().add(FetchDevices(context));
|
||||||
},
|
},
|
||||||
child: Text(
|
child: Text(
|
||||||
'Devices',
|
'Devices',
|
||||||
|
@ -2,17 +2,19 @@ import 'package:flutter/widgets.dart';
|
|||||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||||
import 'package:flutter_secure_storage/flutter_secure_storage.dart';
|
import 'package:flutter_secure_storage/flutter_secure_storage.dart';
|
||||||
import 'package:go_router/go_router.dart';
|
import 'package:go_router/go_router.dart';
|
||||||
// import 'package:graphview/GraphView.dart';
|
|
||||||
import 'package:syncrow_web/pages/auth/model/user_model.dart';
|
import 'package:syncrow_web/pages/auth/model/user_model.dart';
|
||||||
import 'package:syncrow_web/pages/common/bloc/project_cubit.dart';
|
import 'package:syncrow_web/pages/common/bloc/project_manager.dart';
|
||||||
import 'package:syncrow_web/pages/home/bloc/home_event.dart';
|
import 'package:syncrow_web/pages/home/bloc/home_event.dart';
|
||||||
import 'package:syncrow_web/pages/home/bloc/home_state.dart';
|
import 'package:syncrow_web/pages/home/bloc/home_state.dart';
|
||||||
import 'package:syncrow_web/pages/home/home_model/home_item_model.dart';
|
import 'package:syncrow_web/pages/home/home_model/home_item_model.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_event.dart';
|
||||||
import 'package:syncrow_web/services/home_api.dart';
|
import 'package:syncrow_web/services/home_api.dart';
|
||||||
import 'package:syncrow_web/utils/color_manager.dart';
|
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/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> {
|
||||||
// final Graph graph = Graph()..isTree = true;
|
// final Graph graph = Graph()..isTree = true;
|
||||||
@ -22,9 +24,8 @@ class HomeBloc extends Bloc<HomeEvent, HomeState> {
|
|||||||
UserModel? user;
|
UserModel? user;
|
||||||
String terms = '';
|
String terms = '';
|
||||||
String policy = '';
|
String policy = '';
|
||||||
final ProjectCubit projectCubit;
|
|
||||||
|
|
||||||
HomeBloc(this.projectCubit) : super((HomeInitial())) {
|
HomeBloc() : super((HomeInitial())) {
|
||||||
// on<CreateNewNode>(_createNode);
|
// on<CreateNewNode>(_createNode);
|
||||||
on<FetchUserInfo>(_fetchUserInfo);
|
on<FetchUserInfo>(_fetchUserInfo);
|
||||||
on<FetchTermEvent>(_fetchTerms);
|
on<FetchTermEvent>(_fetchTerms);
|
||||||
@ -50,12 +51,12 @@ class HomeBloc extends Bloc<HomeEvent, HomeState> {
|
|||||||
|
|
||||||
Future _fetchUserInfo(FetchUserInfo event, Emitter<HomeState> emit) async {
|
Future _fetchUserInfo(FetchUserInfo event, Emitter<HomeState> emit) async {
|
||||||
try {
|
try {
|
||||||
var uuid =
|
var uuid = await const FlutterSecureStorage().read(key: UserModel.userUuidKey);
|
||||||
await const FlutterSecureStorage().read(key: UserModel.userUuidKey);
|
|
||||||
user = await HomeApi().fetchUserInfo(uuid);
|
user = await HomeApi().fetchUserInfo(uuid);
|
||||||
|
|
||||||
if (user != null && user!.project != null) {
|
if (user != null && user!.project != null) {
|
||||||
projectCubit.setProjectUUID(user!.project!.uuid);
|
await ProjectManager.setProjectUUID(user!.project!.uuid);
|
||||||
|
NavigationService.navigatorKey.currentContext!.read<SpaceTreeBloc>().add(InitialEvent());
|
||||||
}
|
}
|
||||||
add(FetchTermEvent());
|
add(FetchTermEvent());
|
||||||
add(FetchPolicyEvent());
|
add(FetchPolicyEvent());
|
||||||
@ -91,12 +92,10 @@ class HomeBloc extends Bloc<HomeEvent, HomeState> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Future _confirmUserAgreement(
|
Future _confirmUserAgreement(ConfirmUserAgreementEvent event, Emitter<HomeState> emit) async {
|
||||||
ConfirmUserAgreementEvent event, Emitter<HomeState> emit) async {
|
|
||||||
try {
|
try {
|
||||||
emit(LoadingHome());
|
emit(LoadingHome());
|
||||||
var uuid =
|
var uuid = await const FlutterSecureStorage().read(key: UserModel.userUuidKey);
|
||||||
await const FlutterSecureStorage().read(key: UserModel.userUuidKey);
|
|
||||||
policy = await HomeApi().confirmUserAgreements(uuid);
|
policy = await HomeApi().confirmUserAgreements(uuid);
|
||||||
emit(PolicyAgreement());
|
emit(PolicyAgreement());
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
@ -120,6 +119,7 @@ class HomeBloc extends Bloc<HomeEvent, HomeState> {
|
|||||||
icon: Assets.accessIcon,
|
icon: Assets.accessIcon,
|
||||||
active: true,
|
active: true,
|
||||||
onPress: (context) {
|
onPress: (context) {
|
||||||
|
context.read<SpaceTreeBloc>().add(ClearCachedData());
|
||||||
context.go(RoutesConst.accessManagementPage);
|
context.go(RoutesConst.accessManagementPage);
|
||||||
},
|
},
|
||||||
color: null,
|
color: null,
|
||||||
@ -129,6 +129,7 @@ class HomeBloc extends Bloc<HomeEvent, HomeState> {
|
|||||||
icon: Assets.spaseManagementIcon,
|
icon: Assets.spaseManagementIcon,
|
||||||
active: true,
|
active: true,
|
||||||
onPress: (context) {
|
onPress: (context) {
|
||||||
|
context.read<SpaceTreeBloc>().add(ClearCachedData());
|
||||||
context.go(RoutesConst.spacesManagementPage);
|
context.go(RoutesConst.spacesManagementPage);
|
||||||
},
|
},
|
||||||
color: ColorsManager.primaryColor,
|
color: ColorsManager.primaryColor,
|
||||||
@ -138,6 +139,7 @@ class HomeBloc extends Bloc<HomeEvent, HomeState> {
|
|||||||
icon: Assets.devicesIcon,
|
icon: Assets.devicesIcon,
|
||||||
active: true,
|
active: true,
|
||||||
onPress: (context) {
|
onPress: (context) {
|
||||||
|
context.read<SpaceTreeBloc>().add(ClearCachedData());
|
||||||
BlocProvider.of<RoutineBloc>(context)
|
BlocProvider.of<RoutineBloc>(context)
|
||||||
.add(const TriggerSwitchTabsEvent(isRoutineTab: false));
|
.add(const TriggerSwitchTabsEvent(isRoutineTab: false));
|
||||||
context.go(RoutesConst.deviceManagementPage);
|
context.go(RoutesConst.deviceManagementPage);
|
||||||
|
@ -3,7 +3,7 @@ import 'package:flutter_bloc/flutter_bloc.dart';
|
|||||||
import 'package:flutter_html/flutter_html.dart';
|
import 'package:flutter_html/flutter_html.dart';
|
||||||
import 'package:go_router/go_router.dart';
|
import 'package:go_router/go_router.dart';
|
||||||
import 'package:syncrow_web/pages/auth/bloc/auth_bloc.dart';
|
import 'package:syncrow_web/pages/auth/bloc/auth_bloc.dart';
|
||||||
import 'package:syncrow_web/pages/common/bloc/project_cubit.dart';
|
import 'package:syncrow_web/pages/common/bloc/project_manager.dart';
|
||||||
import 'package:syncrow_web/utils/color_manager.dart';
|
import 'package:syncrow_web/utils/color_manager.dart';
|
||||||
import 'package:syncrow_web/utils/constants/routes_const.dart';
|
import 'package:syncrow_web/utils/constants/routes_const.dart';
|
||||||
import 'package:url_launcher/url_launcher.dart';
|
import 'package:url_launcher/url_launcher.dart';
|
||||||
@ -164,8 +164,7 @@ class _AgreementAndPrivacyDialogState extends State<AgreementAndPrivacyDialog> {
|
|||||||
children: [
|
children: [
|
||||||
InkWell(
|
InkWell(
|
||||||
onTap: () {
|
onTap: () {
|
||||||
final projectCubit = BlocProvider.of<ProjectCubit>(context);
|
AuthBloc.logout(context);
|
||||||
AuthBloc.logout(context, projectCubit);
|
|
||||||
context.go(RoutesConst.auth);
|
context.go(RoutesConst.auth);
|
||||||
},
|
},
|
||||||
child: const Text("Cancel"),
|
child: const Text("Cancel"),
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
import 'package:bloc/bloc.dart';
|
import 'package:bloc/bloc.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:syncrow_web/pages/common/bloc/project_cubit.dart';
|
import 'package:syncrow_web/pages/common/bloc/project_manager.dart';
|
||||||
import 'package:syncrow_web/pages/common/custom_dialog.dart';
|
import 'package:syncrow_web/pages/common/custom_dialog.dart';
|
||||||
import 'package:syncrow_web/pages/roles_and_permission/model/edit_user_model.dart';
|
import 'package:syncrow_web/pages/roles_and_permission/model/edit_user_model.dart';
|
||||||
import 'package:syncrow_web/pages/roles_and_permission/model/role_type_model.dart';
|
import 'package:syncrow_web/pages/roles_and_permission/model/role_type_model.dart';
|
||||||
@ -13,12 +13,12 @@ import 'package:syncrow_web/pages/spaces_management/all_spaces/model/space_model
|
|||||||
import 'package:syncrow_web/services/space_mana_api.dart';
|
import 'package:syncrow_web/services/space_mana_api.dart';
|
||||||
import 'package:syncrow_web/services/user_permission.dart';
|
import 'package:syncrow_web/services/user_permission.dart';
|
||||||
import 'package:syncrow_web/utils/constants/assets.dart';
|
import 'package:syncrow_web/utils/constants/assets.dart';
|
||||||
|
import 'package:syncrow_web/utils/constants/strings_manager.dart';
|
||||||
import 'package:syncrow_web/utils/constants/temp_const.dart';
|
import 'package:syncrow_web/utils/constants/temp_const.dart';
|
||||||
|
import 'package:syncrow_web/utils/helpers/shared_preferences_helper.dart';
|
||||||
|
|
||||||
class UsersBloc extends Bloc<UsersEvent, UsersState> {
|
class UsersBloc extends Bloc<UsersEvent, UsersState> {
|
||||||
final ProjectCubit projectCubit;
|
UsersBloc() : super(UsersInitial()) {
|
||||||
|
|
||||||
UsersBloc(this.projectCubit) : super(UsersInitial()) {
|
|
||||||
on<CheckStepStatus>(isCompleteBasicsFun);
|
on<CheckStepStatus>(isCompleteBasicsFun);
|
||||||
on<LoadCommunityAndSpacesEvent>(_onLoadCommunityAndSpaces);
|
on<LoadCommunityAndSpacesEvent>(_onLoadCommunityAndSpaces);
|
||||||
on<SearchAnode>(searchTreeNode);
|
on<SearchAnode>(searchTreeNode);
|
||||||
@ -78,10 +78,10 @@ class UsersBloc extends Bloc<UsersEvent, UsersState> {
|
|||||||
|
|
||||||
Future<List<SpaceModel>> _fetchSpacesForCommunity(
|
Future<List<SpaceModel>> _fetchSpacesForCommunity(
|
||||||
String communityUuid) async {
|
String communityUuid) async {
|
||||||
final projectUuid = projectCubit.state;
|
final projectUuid = await ProjectManager.getProjectUUID() ?? '';
|
||||||
|
|
||||||
return await CommunitySpaceManagementApi()
|
return await CommunitySpaceManagementApi()
|
||||||
.getSpaceHierarchy(communityUuid, projectUuid ?? TempConst.projectId);
|
.getSpaceHierarchy(communityUuid, projectUuid);
|
||||||
}
|
}
|
||||||
|
|
||||||
List<TreeNode> updatedCommunities = [];
|
List<TreeNode> updatedCommunities = [];
|
||||||
@ -91,9 +91,10 @@ class UsersBloc extends Bloc<UsersEvent, UsersState> {
|
|||||||
LoadCommunityAndSpacesEvent event, Emitter<UsersState> emit) async {
|
LoadCommunityAndSpacesEvent event, Emitter<UsersState> emit) async {
|
||||||
try {
|
try {
|
||||||
emit(UsersLoadingState());
|
emit(UsersLoadingState());
|
||||||
final projectUuid = projectCubit.state;
|
final projectUuid = await ProjectManager.getProjectUUID() ?? '';
|
||||||
List<CommunityModel> communities = await CommunitySpaceManagementApi()
|
|
||||||
.fetchCommunities(projectUuid ?? TempConst.projectId);
|
List<CommunityModel> communities =
|
||||||
|
await CommunitySpaceManagementApi().fetchCommunities(projectUuid);
|
||||||
communityIds = communities.map((community) => community.uuid).toList();
|
communityIds = communities.map((community) => community.uuid).toList();
|
||||||
updatedCommunities = await Future.wait(
|
updatedCommunities = await Future.wait(
|
||||||
communities.map((community) async {
|
communities.map((community) async {
|
||||||
@ -336,7 +337,7 @@ class UsersBloc extends Bloc<UsersEvent, UsersState> {
|
|||||||
|
|
||||||
void _sendInvitUser(SendInviteUsers event, Emitter<UsersState> emit) async {
|
void _sendInvitUser(SendInviteUsers event, Emitter<UsersState> emit) async {
|
||||||
try {
|
try {
|
||||||
final projectUuid = projectCubit.state;
|
final projectUuid = await ProjectManager.getProjectUUID() ?? '';
|
||||||
|
|
||||||
emit(UsersLoadingState());
|
emit(UsersLoadingState());
|
||||||
List<String> selectedIds = getSelectedIds(updatedCommunities)
|
List<String> selectedIds = getSelectedIds(updatedCommunities)
|
||||||
@ -351,7 +352,7 @@ class UsersBloc extends Bloc<UsersEvent, UsersState> {
|
|||||||
phoneNumber: phoneController.text,
|
phoneNumber: phoneController.text,
|
||||||
roleUuid: roleSelected,
|
roleUuid: roleSelected,
|
||||||
spaceUuids: selectedIds,
|
spaceUuids: selectedIds,
|
||||||
projectUuid: projectUuid ?? TempConst.projectId);
|
projectUuid: projectUuid);
|
||||||
|
|
||||||
if (res) {
|
if (res) {
|
||||||
showCustomDialog(
|
showCustomDialog(
|
||||||
@ -386,7 +387,7 @@ class UsersBloc extends Bloc<UsersEvent, UsersState> {
|
|||||||
List<String> selectedIds = getSelectedIds(updatedCommunities)
|
List<String> selectedIds = getSelectedIds(updatedCommunities)
|
||||||
.where((id) => !communityIds.contains(id))
|
.where((id) => !communityIds.contains(id))
|
||||||
.toList();
|
.toList();
|
||||||
final projectUuid = projectCubit.state;
|
final projectUuid = await ProjectManager.getProjectUUID() ?? '';
|
||||||
|
|
||||||
bool res = await UserPermissionApi().editInviteUser(
|
bool res = await UserPermissionApi().editInviteUser(
|
||||||
userId: event.userId,
|
userId: event.userId,
|
||||||
@ -396,7 +397,7 @@ class UsersBloc extends Bloc<UsersEvent, UsersState> {
|
|||||||
phoneNumber: phoneController.text,
|
phoneNumber: phoneController.text,
|
||||||
roleUuid: roleSelected,
|
roleUuid: roleSelected,
|
||||||
spaceUuids: selectedIds,
|
spaceUuids: selectedIds,
|
||||||
projectUuid: projectUuid ?? TempConst.projectId);
|
projectUuid: projectUuid);
|
||||||
if (res == true) {
|
if (res == true) {
|
||||||
showCustomDialog(
|
showCustomDialog(
|
||||||
barrierDismissible: false,
|
barrierDismissible: false,
|
||||||
@ -501,11 +502,11 @@ class UsersBloc extends Bloc<UsersEvent, UsersState> {
|
|||||||
emit(UsersLoadingState());
|
emit(UsersLoadingState());
|
||||||
|
|
||||||
try {
|
try {
|
||||||
final projectUuid = projectCubit.state;
|
final projectUuid = await ProjectManager.getProjectUUID() ?? '';
|
||||||
|
|
||||||
if (event.uuid?.isNotEmpty ?? false) {
|
if (event.uuid?.isNotEmpty ?? false) {
|
||||||
final res = await UserPermissionApi()
|
final res =
|
||||||
.fetchUserById(event.uuid, projectUuid ?? TempConst.projectId);
|
await UserPermissionApi().fetchUserById(event.uuid, projectUuid);
|
||||||
|
|
||||||
if (res != null) {
|
if (res != null) {
|
||||||
// Populate the text controllers
|
// Populate the text controllers
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||||
import 'package:flutter_svg/flutter_svg.dart';
|
import 'package:flutter_svg/flutter_svg.dart';
|
||||||
import 'package:syncrow_web/pages/common/bloc/project_cubit.dart';
|
import 'package:syncrow_web/pages/common/bloc/project_manager.dart';
|
||||||
import 'package:syncrow_web/pages/roles_and_permission/users_page/add_user_dialog/bloc/users_bloc.dart';
|
import 'package:syncrow_web/pages/roles_and_permission/users_page/add_user_dialog/bloc/users_bloc.dart';
|
||||||
import 'package:syncrow_web/pages/roles_and_permission/users_page/add_user_dialog/bloc/users_event.dart';
|
import 'package:syncrow_web/pages/roles_and_permission/users_page/add_user_dialog/bloc/users_event.dart';
|
||||||
import 'package:syncrow_web/pages/roles_and_permission/users_page/add_user_dialog/bloc/users_status.dart';
|
import 'package:syncrow_web/pages/roles_and_permission/users_page/add_user_dialog/bloc/users_status.dart';
|
||||||
@ -24,7 +24,7 @@ class _AddNewUserDialogState extends State<AddNewUserDialog> {
|
|||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return BlocProvider(
|
return BlocProvider(
|
||||||
create: (BuildContext context) => UsersBloc(context.read<ProjectCubit>())
|
create: (BuildContext context) => UsersBloc()
|
||||||
..add(const LoadCommunityAndSpacesEvent())
|
..add(const LoadCommunityAndSpacesEvent())
|
||||||
..add(const RoleEvent()),
|
..add(const RoleEvent()),
|
||||||
child: BlocConsumer<UsersBloc, UsersState>(
|
child: BlocConsumer<UsersBloc, UsersState>(
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter_bloc/flutter_bloc.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/common/bloc/project_cubit.dart';
|
import 'package:syncrow_web/pages/common/bloc/project_manager.dart';
|
||||||
import 'package:syncrow_web/pages/roles_and_permission/users_page/add_user_dialog/bloc/users_bloc.dart';
|
import 'package:syncrow_web/pages/roles_and_permission/users_page/add_user_dialog/bloc/users_bloc.dart';
|
||||||
import 'package:syncrow_web/pages/roles_and_permission/users_page/add_user_dialog/bloc/users_event.dart';
|
import 'package:syncrow_web/pages/roles_and_permission/users_page/add_user_dialog/bloc/users_event.dart';
|
||||||
import 'package:syncrow_web/pages/roles_and_permission/users_page/add_user_dialog/bloc/users_status.dart';
|
import 'package:syncrow_web/pages/roles_and_permission/users_page/add_user_dialog/bloc/users_status.dart';
|
||||||
@ -22,7 +22,7 @@ class TreeView extends StatelessWidget {
|
|||||||
final _blocRole = BlocProvider.of<UsersBloc>(context);
|
final _blocRole = BlocProvider.of<UsersBloc>(context);
|
||||||
debugPrint('TreeView constructed with userId = $userId');
|
debugPrint('TreeView constructed with userId = $userId');
|
||||||
return BlocProvider(
|
return BlocProvider(
|
||||||
create: (_) => UsersBloc(context.read<ProjectCubit>()),
|
create: (_) => UsersBloc(),
|
||||||
// ..add(const LoadCommunityAndSpacesEvent()),
|
// ..add(const LoadCommunityAndSpacesEvent()),
|
||||||
child: BlocConsumer<UsersBloc, UsersState>(
|
child: BlocConsumer<UsersBloc, UsersState>(
|
||||||
listener: (context, state) {
|
listener: (context, state) {
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||||
import 'package:flutter_svg/flutter_svg.dart';
|
import 'package:flutter_svg/flutter_svg.dart';
|
||||||
import 'package:syncrow_web/pages/common/bloc/project_cubit.dart';
|
import 'package:syncrow_web/pages/common/bloc/project_manager.dart';
|
||||||
import 'package:syncrow_web/pages/roles_and_permission/users_page/add_user_dialog/bloc/users_bloc.dart';
|
import 'package:syncrow_web/pages/roles_and_permission/users_page/add_user_dialog/bloc/users_bloc.dart';
|
||||||
import 'package:syncrow_web/pages/roles_and_permission/users_page/add_user_dialog/bloc/users_event.dart';
|
import 'package:syncrow_web/pages/roles_and_permission/users_page/add_user_dialog/bloc/users_event.dart';
|
||||||
import 'package:syncrow_web/pages/roles_and_permission/users_page/add_user_dialog/bloc/users_status.dart';
|
import 'package:syncrow_web/pages/roles_and_permission/users_page/add_user_dialog/bloc/users_status.dart';
|
||||||
@ -25,7 +25,7 @@ class _EditUserDialogState extends State<EditUserDialog> {
|
|||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return BlocProvider(
|
return BlocProvider(
|
||||||
create: (BuildContext context) => UsersBloc(context.read<ProjectCubit>())
|
create: (BuildContext context) => UsersBloc()
|
||||||
..add(const LoadCommunityAndSpacesEvent())
|
..add(const LoadCommunityAndSpacesEvent())
|
||||||
..add(const RoleEvent())
|
..add(const RoleEvent())
|
||||||
..add(GetUserByIdEvent(uuid: widget.userId)),
|
..add(GetUserByIdEvent(uuid: widget.userId)),
|
||||||
|
@ -1,17 +1,16 @@
|
|||||||
import 'dart:async';
|
import 'dart:async';
|
||||||
import 'package:bloc/bloc.dart';
|
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:syncrow_web/pages/common/bloc/project_cubit.dart';
|
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||||
|
import 'package:syncrow_web/pages/common/bloc/project_manager.dart';
|
||||||
import 'package:syncrow_web/pages/roles_and_permission/model/roles_user_model.dart';
|
import 'package:syncrow_web/pages/roles_and_permission/model/roles_user_model.dart';
|
||||||
import 'package:syncrow_web/pages/roles_and_permission/users_page/users_table/bloc/user_table_event.dart';
|
import 'package:syncrow_web/pages/roles_and_permission/users_page/users_table/bloc/user_table_event.dart';
|
||||||
import 'package:syncrow_web/pages/roles_and_permission/users_page/users_table/bloc/user_table_state.dart';
|
import 'package:syncrow_web/pages/roles_and_permission/users_page/users_table/bloc/user_table_state.dart';
|
||||||
import 'package:syncrow_web/services/user_permission.dart';
|
import 'package:syncrow_web/services/user_permission.dart';
|
||||||
import 'package:syncrow_web/utils/constants/temp_const.dart';
|
import 'package:syncrow_web/utils/constants/strings_manager.dart';
|
||||||
|
import 'package:syncrow_web/utils/helpers/shared_preferences_helper.dart';
|
||||||
|
|
||||||
class UserTableBloc extends Bloc<UserTableEvent, UserTableState> {
|
class UserTableBloc extends Bloc<UserTableEvent, UserTableState> {
|
||||||
final ProjectCubit _projectCubit;
|
UserTableBloc() : super(TableInitial()) {
|
||||||
|
|
||||||
UserTableBloc(this._projectCubit) : super(TableInitial()) {
|
|
||||||
on<GetUsers>(_getUsers);
|
on<GetUsers>(_getUsers);
|
||||||
on<ChangeUserStatus>(_changeUserStatus);
|
on<ChangeUserStatus>(_changeUserStatus);
|
||||||
on<SortUsersByNameAsc>(_toggleSortUsersByNameAsc);
|
on<SortUsersByNameAsc>(_toggleSortUsersByNameAsc);
|
||||||
@ -50,13 +49,12 @@ class UserTableBloc extends Bloc<UserTableEvent, UserTableState> {
|
|||||||
Future<void> _getUsers(GetUsers event, Emitter<UserTableState> emit) async {
|
Future<void> _getUsers(GetUsers event, Emitter<UserTableState> emit) async {
|
||||||
emit(UsersLoadingState());
|
emit(UsersLoadingState());
|
||||||
try {
|
try {
|
||||||
final projectUuid = _projectCubit.state;
|
final projectUuid = await ProjectManager.getProjectUUID() ?? '';
|
||||||
|
|
||||||
roleTypes.clear();
|
roleTypes.clear();
|
||||||
jobTitle.clear();
|
jobTitle.clear();
|
||||||
createdBy.clear();
|
createdBy.clear();
|
||||||
users = await UserPermissionApi()
|
users = await UserPermissionApi().fetchUsers(projectUuid);
|
||||||
.fetchUsers(projectUuid ?? TempConst.projectId);
|
|
||||||
users.sort((a, b) {
|
users.sort((a, b) {
|
||||||
final dateA = _parseDateTime(a.createdDate);
|
final dateA = _parseDateTime(a.createdDate);
|
||||||
final dateB = _parseDateTime(b.createdDate);
|
final dateB = _parseDateTime(b.createdDate);
|
||||||
@ -103,13 +101,11 @@ class UserTableBloc extends Bloc<UserTableEvent, UserTableState> {
|
|||||||
Future<void> _changeUserStatus(
|
Future<void> _changeUserStatus(
|
||||||
ChangeUserStatus event, Emitter<UserTableState> emit) async {
|
ChangeUserStatus event, Emitter<UserTableState> emit) async {
|
||||||
try {
|
try {
|
||||||
final projectUuid = _projectCubit.state;
|
final projectUuid = await ProjectManager.getProjectUUID() ?? '';
|
||||||
|
|
||||||
emit(UsersLoadingState());
|
emit(UsersLoadingState());
|
||||||
bool res = await UserPermissionApi().changeUserStatusById(
|
bool res = await UserPermissionApi().changeUserStatusById(event.userId,
|
||||||
event.userId,
|
event.newStatus == "disabled" ? false : true, projectUuid);
|
||||||
event.newStatus == "disabled" ? false : true,
|
|
||||||
projectUuid ?? TempConst.projectId);
|
|
||||||
if (res == true) {
|
if (res == true) {
|
||||||
add(const GetUsers());
|
add(const GetUsers());
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||||
import 'package:syncrow_web/pages/common/bloc/project_cubit.dart';
|
import 'package:syncrow_web/pages/common/bloc/project_manager.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/roles_and_permission/bloc/roles_permission_bloc.dart';
|
import 'package:syncrow_web/pages/roles_and_permission/bloc/roles_permission_bloc.dart';
|
||||||
import 'package:syncrow_web/pages/roles_and_permission/bloc/roles_permission_state.dart';
|
import 'package:syncrow_web/pages/roles_and_permission/bloc/roles_permission_state.dart';
|
||||||
@ -77,7 +77,7 @@ class RolesAndPermissionPage extends StatelessWidget {
|
|||||||
],
|
],
|
||||||
),
|
),
|
||||||
scaffoldBody: BlocProvider<UserTableBloc>(
|
scaffoldBody: BlocProvider<UserTableBloc>(
|
||||||
create: (context) => UserTableBloc(context.read<ProjectCubit>())..add(const GetUsers()),
|
create: (context) => UserTableBloc()..add(const GetUsers()),
|
||||||
child: UsersPage(),
|
child: UsersPage(),
|
||||||
)
|
)
|
||||||
// _blocRole.tapSelect == false
|
// _blocRole.tapSelect == false
|
||||||
|
@ -3,7 +3,8 @@ import 'dart:async';
|
|||||||
import 'package:bloc/bloc.dart';
|
import 'package:bloc/bloc.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_cubit.dart';
|
import 'package:syncrow_web/pages/common/bloc/project_manager.dart';
|
||||||
|
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||||
import 'package:syncrow_web/pages/device_managment/all_devices/models/devices_model.dart';
|
import 'package:syncrow_web/pages/device_managment/all_devices/models/devices_model.dart';
|
||||||
import 'package:syncrow_web/pages/routines/models/create_scene_and_autoamtion/create_automation_model.dart';
|
import 'package:syncrow_web/pages/routines/models/create_scene_and_autoamtion/create_automation_model.dart';
|
||||||
import 'package:syncrow_web/pages/routines/models/create_scene_and_autoamtion/create_scene_model.dart';
|
import 'package:syncrow_web/pages/routines/models/create_scene_and_autoamtion/create_scene_model.dart';
|
||||||
@ -11,23 +12,25 @@ import 'package:syncrow_web/pages/routines/models/delay/delay_fucntions.dart';
|
|||||||
import 'package:syncrow_web/pages/routines/models/device_functions.dart';
|
import 'package:syncrow_web/pages/routines/models/device_functions.dart';
|
||||||
import 'package:syncrow_web/pages/routines/models/routine_details_model.dart';
|
import 'package:syncrow_web/pages/routines/models/routine_details_model.dart';
|
||||||
import 'package:syncrow_web/pages/routines/models/routine_model.dart';
|
import 'package:syncrow_web/pages/routines/models/routine_model.dart';
|
||||||
|
import 'package:syncrow_web/pages/space_tree/bloc/space_tree_bloc.dart';
|
||||||
import 'package:syncrow_web/services/devices_mang_api.dart';
|
import 'package:syncrow_web/services/devices_mang_api.dart';
|
||||||
import 'package:syncrow_web/services/routines_api.dart';
|
import 'package:syncrow_web/services/routines_api.dart';
|
||||||
import 'package:syncrow_web/utils/constants/assets.dart';
|
import 'package:syncrow_web/utils/constants/assets.dart';
|
||||||
|
import 'package:syncrow_web/utils/constants/strings_manager.dart';
|
||||||
import 'package:syncrow_web/utils/constants/temp_const.dart';
|
import 'package:syncrow_web/utils/constants/temp_const.dart';
|
||||||
|
import 'package:syncrow_web/utils/helpers/shared_preferences_helper.dart';
|
||||||
|
import 'package:syncrow_web/utils/navigation_service.dart';
|
||||||
import 'package:syncrow_web/utils/snack_bar.dart';
|
import 'package:syncrow_web/utils/snack_bar.dart';
|
||||||
import 'package:uuid/uuid.dart';
|
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 spaceId = '25c96044-fadf-44bb-93c7-3c079e527ce6';
|
||||||
String communityId = 'aff21a57-2f91-4e5c-b99b-0182c3ab65a9';
|
// String communityId = 'aff21a57-2f91-4e5c-b99b-0182c3ab65a9';
|
||||||
|
|
||||||
class RoutineBloc extends Bloc<RoutineEvent, RoutineState> {
|
class RoutineBloc extends Bloc<RoutineEvent, RoutineState> {
|
||||||
final ProjectCubit projectCubit;
|
RoutineBloc() : super(const RoutineState()) {
|
||||||
|
|
||||||
RoutineBloc(this.projectCubit) : super(const RoutineState()) {
|
|
||||||
on<AddToIfContainer>(_onAddToIfContainer);
|
on<AddToIfContainer>(_onAddToIfContainer);
|
||||||
on<AddToThenContainer>(_onAddToThenContainer);
|
on<AddToThenContainer>(_onAddToThenContainer);
|
||||||
on<LoadScenes>(_onLoadScenes);
|
on<LoadScenes>(_onLoadScenes);
|
||||||
@ -62,8 +65,8 @@ class RoutineBloc extends Bloc<RoutineEvent, RoutineState> {
|
|||||||
routineTab: event.isRoutineTab, createRoutineView: false));
|
routineTab: event.isRoutineTab, createRoutineView: false));
|
||||||
add(ResetRoutineState());
|
add(ResetRoutineState());
|
||||||
if (event.isRoutineTab) {
|
if (event.isRoutineTab) {
|
||||||
add(LoadScenes(spaceId, communityId));
|
add(const LoadScenes());
|
||||||
add(LoadAutomation(spaceId));
|
add(const LoadAutomation());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -169,18 +172,21 @@ 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));
|
||||||
|
|
||||||
try {
|
|
||||||
final projectUuid = projectCubit.state;
|
|
||||||
|
|
||||||
spaceId = event.spaceId;
|
|
||||||
communityId = event.communityId;
|
|
||||||
|
|
||||||
List<ScenesModel> scenes = [];
|
List<ScenesModel> scenes = [];
|
||||||
|
try {
|
||||||
|
final projectUuid = await ProjectManager.getProjectUUID() ?? '';
|
||||||
|
|
||||||
if (communityId.isNotEmpty && spaceId.isNotEmpty) {
|
BuildContext context = NavigationService.navigatorKey.currentContext!;
|
||||||
scenes = await SceneApi.getScenes(event.spaceId, event.communityId, projectUuid ?? TempConst.projectId);
|
var spaceBloc = context.read<SpaceTreeBloc>();
|
||||||
|
for (var communityId in spaceBloc.state.selectedCommunities) {
|
||||||
|
List<String> spacesList =
|
||||||
|
spaceBloc.state.selectedCommunityAndSpaces[communityId] ?? [];
|
||||||
|
for (var spaceId in spacesList) {
|
||||||
|
scenes.addAll(
|
||||||
|
await SceneApi.getScenes(spaceId, communityId, projectUuid));
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
emit(state.copyWith(
|
emit(state.copyWith(
|
||||||
scenes: scenes,
|
scenes: scenes,
|
||||||
isLoading: false,
|
isLoading: false,
|
||||||
@ -191,19 +197,24 @@ class RoutineBloc extends Bloc<RoutineEvent, RoutineState> {
|
|||||||
loadScenesErrorMessage: 'Failed to load scenes',
|
loadScenesErrorMessage: 'Failed to load scenes',
|
||||||
errorMessage: '',
|
errorMessage: '',
|
||||||
loadAutomationErrorMessage: '',
|
loadAutomationErrorMessage: '',
|
||||||
scenes: []));
|
scenes: scenes));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> _onLoadAutomation(
|
Future<void> _onLoadAutomation(
|
||||||
LoadAutomation event, Emitter<RoutineState> emit) async {
|
LoadAutomation event, Emitter<RoutineState> emit) async {
|
||||||
emit(state.copyWith(isLoading: true, errorMessage: null));
|
emit(state.copyWith(isLoading: true, errorMessage: null));
|
||||||
|
List<ScenesModel> automations = [];
|
||||||
|
|
||||||
try {
|
try {
|
||||||
spaceId = event.spaceId;
|
BuildContext context = NavigationService.navigatorKey.currentContext!;
|
||||||
List<ScenesModel> automations = [];
|
var spaceBloc = context.read<SpaceTreeBloc>();
|
||||||
if (spaceId.isNotEmpty) {
|
for (var communityId in spaceBloc.state.selectedCommunities) {
|
||||||
automations = await SceneApi.getAutomation(event.spaceId);
|
List<String> spacesList =
|
||||||
|
spaceBloc.state.selectedCommunityAndSpaces[communityId] ?? [];
|
||||||
|
for (var spaceId in spacesList) {
|
||||||
|
automations.addAll(await SceneApi.getAutomation(spaceId));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
emit(state.copyWith(
|
emit(state.copyWith(
|
||||||
automations: automations,
|
automations: automations,
|
||||||
@ -215,7 +226,7 @@ class RoutineBloc extends Bloc<RoutineEvent, RoutineState> {
|
|||||||
loadAutomationErrorMessage: 'Failed to load automations',
|
loadAutomationErrorMessage: 'Failed to load automations',
|
||||||
errorMessage: '',
|
errorMessage: '',
|
||||||
loadScenesErrorMessage: '',
|
loadScenesErrorMessage: '',
|
||||||
automations: []));
|
automations: automations));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -302,8 +313,11 @@ class RoutineBloc extends Bloc<RoutineEvent, RoutineState> {
|
|||||||
});
|
});
|
||||||
}).toList();
|
}).toList();
|
||||||
|
|
||||||
|
BuildContext context = NavigationService.navigatorKey.currentContext!;
|
||||||
|
var spaceBloc = context.read<SpaceTreeBloc>();
|
||||||
|
|
||||||
final createSceneModel = CreateSceneModel(
|
final createSceneModel = CreateSceneModel(
|
||||||
spaceUuid: spaceId,
|
spaceUuid: spaceBloc.state.selectedSpaces[0],
|
||||||
iconId: state.selectedIcon ?? '',
|
iconId: state.selectedIcon ?? '',
|
||||||
showInDevice: true,
|
showInDevice: true,
|
||||||
sceneName: state.routineName ?? '',
|
sceneName: state.routineName ?? '',
|
||||||
@ -314,8 +328,8 @@ class RoutineBloc extends Bloc<RoutineEvent, RoutineState> {
|
|||||||
final result = await SceneApi.createScene(createSceneModel);
|
final result = await SceneApi.createScene(createSceneModel);
|
||||||
if (result['success']) {
|
if (result['success']) {
|
||||||
add(ResetRoutineState());
|
add(ResetRoutineState());
|
||||||
add(LoadScenes(spaceId, communityId));
|
add(const LoadScenes());
|
||||||
add(LoadAutomation(spaceId));
|
add(const LoadAutomation());
|
||||||
} else {
|
} else {
|
||||||
emit(state.copyWith(
|
emit(state.copyWith(
|
||||||
isLoading: false,
|
isLoading: false,
|
||||||
@ -428,9 +442,11 @@ class RoutineBloc extends Bloc<RoutineEvent, RoutineState> {
|
|||||||
);
|
);
|
||||||
});
|
});
|
||||||
}).toList();
|
}).toList();
|
||||||
|
BuildContext context = NavigationService.navigatorKey.currentContext!;
|
||||||
|
var spaceBloc = context.read<SpaceTreeBloc>();
|
||||||
|
|
||||||
final createAutomationModel = CreateAutomationModel(
|
final createAutomationModel = CreateAutomationModel(
|
||||||
spaceUuid: spaceId,
|
spaceUuid: spaceBloc.state.selectedSpaces[0],
|
||||||
automationName: state.routineName ?? '',
|
automationName: state.routineName ?? '',
|
||||||
decisionExpr: state.selectedAutomationOperator,
|
decisionExpr: state.selectedAutomationOperator,
|
||||||
effectiveTime: EffectiveTime(
|
effectiveTime: EffectiveTime(
|
||||||
@ -445,8 +461,8 @@ class RoutineBloc extends Bloc<RoutineEvent, RoutineState> {
|
|||||||
final result = await SceneApi.createAutomation(createAutomationModel);
|
final result = await SceneApi.createAutomation(createAutomationModel);
|
||||||
if (result['success']) {
|
if (result['success']) {
|
||||||
add(ResetRoutineState());
|
add(ResetRoutineState());
|
||||||
add(LoadAutomation(spaceId));
|
add(const LoadAutomation());
|
||||||
add(LoadScenes(spaceId, communityId));
|
add(const LoadScenes());
|
||||||
} else {
|
} else {
|
||||||
emit(state.copyWith(
|
emit(state.copyWith(
|
||||||
isLoading: false,
|
isLoading: false,
|
||||||
@ -821,18 +837,24 @@ class RoutineBloc extends Bloc<RoutineEvent, RoutineState> {
|
|||||||
createRoutineView: false));
|
createRoutineView: false));
|
||||||
}
|
}
|
||||||
|
|
||||||
FutureOr<void> _deleteScene(DeleteScene event, Emitter<RoutineState> emit) {
|
FutureOr<void> _deleteScene(
|
||||||
|
DeleteScene event, Emitter<RoutineState> emit) async {
|
||||||
try {
|
try {
|
||||||
emit(state.copyWith(isLoading: true));
|
emit(state.copyWith(isLoading: true));
|
||||||
|
BuildContext context = NavigationService.navigatorKey.currentContext!;
|
||||||
|
var spaceBloc = context.read<SpaceTreeBloc>();
|
||||||
if (state.isTabToRun) {
|
if (state.isTabToRun) {
|
||||||
SceneApi.deleteScene(unitUuid: spaceId, sceneId: state.sceneId ?? '');
|
await SceneApi.deleteScene(
|
||||||
|
unitUuid: spaceBloc.state.selectedSpaces[0],
|
||||||
|
sceneId: state.sceneId ?? '');
|
||||||
} else {
|
} else {
|
||||||
SceneApi.deleteAutomation(
|
await SceneApi.deleteAutomation(
|
||||||
unitUuid: spaceId, automationId: state.automationId ?? '');
|
unitUuid: spaceBloc.state.selectedSpaces[0],
|
||||||
|
automationId: state.automationId ?? '');
|
||||||
}
|
}
|
||||||
|
|
||||||
add(LoadScenes(spaceId, communityId));
|
add(const LoadScenes());
|
||||||
add(LoadAutomation(spaceId));
|
add(const LoadAutomation());
|
||||||
add(ResetRoutineState());
|
add(ResetRoutineState());
|
||||||
emit(state.copyWith(isLoading: false, createRoutineView: false));
|
emit(state.copyWith(isLoading: false, createRoutineView: false));
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
@ -861,9 +883,20 @@ class RoutineBloc extends Bloc<RoutineEvent, RoutineState> {
|
|||||||
FetchDevicesInRoutine event, Emitter<RoutineState> emit) async {
|
FetchDevicesInRoutine event, Emitter<RoutineState> emit) async {
|
||||||
emit(state.copyWith(isLoading: true));
|
emit(state.copyWith(isLoading: true));
|
||||||
try {
|
try {
|
||||||
final projectUuid = projectCubit.state;
|
final projectUuid = await ProjectManager.getProjectUUID() ?? '';
|
||||||
final devices = await DevicesManagementApi()
|
|
||||||
.fetchDevices('', '', projectUuid ?? TempConst.projectId);
|
List<AllDevicesModel> devices = [];
|
||||||
|
|
||||||
|
BuildContext context = NavigationService.navigatorKey.currentContext!;
|
||||||
|
var spaceBloc = context.read<SpaceTreeBloc>();
|
||||||
|
for (var communityId in spaceBloc.state.selectedCommunities) {
|
||||||
|
List<String> spacesList =
|
||||||
|
spaceBloc.state.selectedCommunityAndSpaces[communityId] ?? [];
|
||||||
|
for (var spaceId in spacesList) {
|
||||||
|
devices.addAll(await DevicesManagementApi()
|
||||||
|
.fetchDevices(communityId, spaceId, projectUuid));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
emit(state.copyWith(isLoading: false, devices: devices));
|
emit(state.copyWith(isLoading: false, devices: devices));
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
@ -944,8 +977,8 @@ class RoutineBloc extends Bloc<RoutineEvent, RoutineState> {
|
|||||||
await SceneApi.updateScene(createSceneModel, state.sceneId ?? '');
|
await SceneApi.updateScene(createSceneModel, state.sceneId ?? '');
|
||||||
if (result['success']) {
|
if (result['success']) {
|
||||||
add(ResetRoutineState());
|
add(ResetRoutineState());
|
||||||
add(LoadScenes(spaceId, communityId));
|
add(const LoadScenes());
|
||||||
add(LoadAutomation(spaceId));
|
add(const LoadAutomation());
|
||||||
} else {
|
} else {
|
||||||
emit(state.copyWith(
|
emit(state.copyWith(
|
||||||
isLoading: false,
|
isLoading: false,
|
||||||
@ -1056,8 +1089,11 @@ class RoutineBloc extends Bloc<RoutineEvent, RoutineState> {
|
|||||||
});
|
});
|
||||||
}).toList();
|
}).toList();
|
||||||
|
|
||||||
|
BuildContext context = NavigationService.navigatorKey.currentContext!;
|
||||||
|
var spaceBloc = context.read<SpaceTreeBloc>();
|
||||||
|
|
||||||
final createAutomationModel = CreateAutomationModel(
|
final createAutomationModel = CreateAutomationModel(
|
||||||
spaceUuid: spaceId,
|
spaceUuid: spaceBloc.state.selectedSpaces[0],
|
||||||
automationName: state.routineName ?? '',
|
automationName: state.routineName ?? '',
|
||||||
decisionExpr: state.selectedAutomationOperator,
|
decisionExpr: state.selectedAutomationOperator,
|
||||||
effectiveTime: EffectiveTime(
|
effectiveTime: EffectiveTime(
|
||||||
@ -1074,8 +1110,8 @@ class RoutineBloc extends Bloc<RoutineEvent, RoutineState> {
|
|||||||
|
|
||||||
if (result['success']) {
|
if (result['success']) {
|
||||||
add(ResetRoutineState());
|
add(ResetRoutineState());
|
||||||
add(LoadAutomation(spaceId));
|
add(LoadAutomation());
|
||||||
add(LoadScenes(spaceId, communityId));
|
add(LoadScenes());
|
||||||
} else {
|
} else {
|
||||||
emit(state.copyWith(
|
emit(state.copyWith(
|
||||||
isLoading: false,
|
isLoading: false,
|
||||||
|
@ -27,22 +27,24 @@ class AddToThenContainer extends RoutineEvent {
|
|||||||
}
|
}
|
||||||
|
|
||||||
class LoadScenes extends RoutineEvent {
|
class LoadScenes extends RoutineEvent {
|
||||||
final String spaceId;
|
// final String spaceId;
|
||||||
final String communityId;
|
// final String communityId;
|
||||||
|
// final BuildContext context;
|
||||||
|
|
||||||
const LoadScenes(this.spaceId, this.communityId);
|
const LoadScenes();
|
||||||
|
|
||||||
@override
|
@override
|
||||||
List<Object> get props => [spaceId, communityId];
|
List<Object> get props => [];
|
||||||
}
|
}
|
||||||
|
|
||||||
class LoadAutomation extends RoutineEvent {
|
class LoadAutomation extends RoutineEvent {
|
||||||
final String spaceId;
|
// final String spaceId;
|
||||||
|
// final BuildContext context;
|
||||||
|
|
||||||
const LoadAutomation(this.spaceId);
|
const LoadAutomation();
|
||||||
|
|
||||||
@override
|
@override
|
||||||
List<Object> get props => [spaceId];
|
List<Object> get props => [];
|
||||||
}
|
}
|
||||||
|
|
||||||
class AddFunctionToRoutine extends RoutineEvent {
|
class AddFunctionToRoutine extends RoutineEvent {
|
||||||
|
@ -20,7 +20,7 @@ class _RoutinesViewState extends State<RoutinesView> {
|
|||||||
@override
|
@override
|
||||||
void initState() {
|
void initState() {
|
||||||
super.initState();
|
super.initState();
|
||||||
context.read<RoutineBloc>().add(FetchDevicesInRoutine());
|
// context.read<RoutineBloc>().add(FetchDevicesInRoutine());
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
@ -32,9 +32,12 @@ class _RoutinesViewState extends State<RoutinesView> {
|
|||||||
}
|
}
|
||||||
return Row(
|
return Row(
|
||||||
children: [
|
children: [
|
||||||
Expanded(
|
Expanded(child: SpaceTreeView(
|
||||||
child: SpaceTreeView(
|
onSelect: () {
|
||||||
onSelect: () {},
|
context.read<RoutineBloc>()
|
||||||
|
..add(const LoadScenes())
|
||||||
|
..add(const LoadAutomation());
|
||||||
|
},
|
||||||
)),
|
)),
|
||||||
Expanded(
|
Expanded(
|
||||||
flex: 4,
|
flex: 4,
|
||||||
@ -59,8 +62,8 @@ class _RoutinesViewState extends State<RoutinesView> {
|
|||||||
),
|
),
|
||||||
RoutineViewCard(
|
RoutineViewCard(
|
||||||
onTap: () {
|
onTap: () {
|
||||||
if (context.read<SpaceTreeBloc>().selectedCommunityId.isNotEmpty &&
|
if (context.read<SpaceTreeBloc>().state.selectedCommunities.length == 1 &&
|
||||||
context.read<SpaceTreeBloc>().selectedSpaceId.isNotEmpty) {
|
context.read<SpaceTreeBloc>().state.selectedSpaces.length == 1) {
|
||||||
context.read<RoutineBloc>().add(
|
context.read<RoutineBloc>().add(
|
||||||
(ResetRoutineState()),
|
(ResetRoutineState()),
|
||||||
);
|
);
|
||||||
@ -68,7 +71,18 @@ class _RoutinesViewState extends State<RoutinesView> {
|
|||||||
const CreateNewRoutineViewEvent(createRoutineView: true),
|
const CreateNewRoutineViewEvent(createRoutineView: true),
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
CustomSnackBar.redSnackBar('Please select a space');
|
ScaffoldMessenger.of(context).showSnackBar(
|
||||||
|
SnackBar(
|
||||||
|
content: Text(
|
||||||
|
context.read<SpaceTreeBloc>().state.selectedSpaces.isEmpty
|
||||||
|
? 'Please select a space'
|
||||||
|
: 'Please select only one space to proceed'),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
// CustomSnackBar.redSnackBar(
|
||||||
|
// context.read<SpaceTreeBloc>().state.selectedSpaces.isEmpty
|
||||||
|
// ? 'Please select a space'
|
||||||
|
// : 'Please select only one space to proceed');
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
icon: Icons.add,
|
icon: Icons.add,
|
||||||
|
@ -20,10 +20,6 @@ class _FetchRoutineScenesState extends State<FetchRoutineScenesAutomation>
|
|||||||
@override
|
@override
|
||||||
void initState() {
|
void initState() {
|
||||||
super.initState();
|
super.initState();
|
||||||
context.read<RoutineBloc>()
|
|
||||||
..add(LoadScenes(context.read<SpaceTreeBloc>().selectedSpaceId,
|
|
||||||
context.read<SpaceTreeBloc>().selectedCommunityId))
|
|
||||||
..add(LoadAutomation(context.read<SpaceTreeBloc>().selectedSpaceId));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
|
@ -4,9 +4,20 @@ import 'package:syncrow_web/pages/device_managment/all_devices/models/devices_mo
|
|||||||
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/widgets/dragable_card.dart';
|
import 'package:syncrow_web/pages/routines/widgets/dragable_card.dart';
|
||||||
|
|
||||||
class RoutineDevices extends StatelessWidget {
|
class RoutineDevices extends StatefulWidget {
|
||||||
const RoutineDevices({super.key});
|
const RoutineDevices({super.key});
|
||||||
|
|
||||||
|
@override
|
||||||
|
State<RoutineDevices> createState() => _RoutineDevicesState();
|
||||||
|
}
|
||||||
|
|
||||||
|
class _RoutineDevicesState extends State<RoutineDevices> {
|
||||||
|
@override
|
||||||
|
void initState() {
|
||||||
|
super.initState();
|
||||||
|
context.read<RoutineBloc>().add(FetchDevicesInRoutine());
|
||||||
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return BlocBuilder<RoutineBloc, RoutineState>(
|
return BlocBuilder<RoutineBloc, RoutineState>(
|
||||||
|
@ -2,7 +2,6 @@ import 'package:flutter/material.dart';
|
|||||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||||
import 'package:syncrow_web/pages/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/widgets/dragable_card.dart';
|
import 'package:syncrow_web/pages/routines/widgets/dragable_card.dart';
|
||||||
import 'package:syncrow_web/pages/space_tree/bloc/space_tree_bloc.dart';
|
|
||||||
import 'package:syncrow_web/utils/constants/assets.dart';
|
import 'package:syncrow_web/utils/constants/assets.dart';
|
||||||
|
|
||||||
class ScenesAndAutomations extends StatefulWidget {
|
class ScenesAndAutomations extends StatefulWidget {
|
||||||
@ -19,9 +18,8 @@ class _ScenesAndAutomationsState extends State<ScenesAndAutomations> {
|
|||||||
void initState() {
|
void initState() {
|
||||||
super.initState();
|
super.initState();
|
||||||
context.read<RoutineBloc>()
|
context.read<RoutineBloc>()
|
||||||
..add(LoadScenes(context.read<SpaceTreeBloc>().selectedSpaceId,
|
..add(const LoadScenes())
|
||||||
context.read<SpaceTreeBloc>().selectedCommunityId))
|
..add(const LoadAutomation());
|
||||||
..add(LoadAutomation(context.read<SpaceTreeBloc>().selectedSpaceId));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
|
@ -1,39 +1,35 @@
|
|||||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||||
import 'package:syncrow_web/pages/common/bloc/project_cubit.dart';
|
import 'package:syncrow_web/pages/common/bloc/project_manager.dart';
|
||||||
import 'package:syncrow_web/pages/space_tree/bloc/space_tree_event.dart';
|
import 'package:syncrow_web/pages/space_tree/bloc/space_tree_event.dart';
|
||||||
import 'package:syncrow_web/pages/space_tree/bloc/space_tree_state.dart';
|
import 'package:syncrow_web/pages/space_tree/bloc/space_tree_state.dart';
|
||||||
import 'package:syncrow_web/pages/spaces_management/all_spaces/model/community_model.dart';
|
import 'package:syncrow_web/pages/spaces_management/all_spaces/model/community_model.dart';
|
||||||
import 'package:syncrow_web/pages/spaces_management/all_spaces/model/space_model.dart';
|
import 'package:syncrow_web/pages/spaces_management/all_spaces/model/space_model.dart';
|
||||||
import 'package:syncrow_web/services/space_mana_api.dart';
|
import 'package:syncrow_web/services/space_mana_api.dart';
|
||||||
import 'package:syncrow_web/utils/constants/temp_const.dart';
|
|
||||||
|
|
||||||
class SpaceTreeBloc extends Bloc<SpaceTreeEvent, SpaceTreeState> {
|
class SpaceTreeBloc extends Bloc<SpaceTreeEvent, SpaceTreeState> {
|
||||||
String selectedCommunityId = 'aff21a57-2f91-4e5c-b99b-0182c3ab65a9';
|
SpaceTreeBloc() : super(const SpaceTreeState()) {
|
||||||
String selectedSpaceId = '25c96044-fadf-44bb-93c7-3c079e527ce6';
|
|
||||||
final ProjectCubit projectCubit;
|
|
||||||
|
|
||||||
SpaceTreeBloc(this.projectCubit) : super(const SpaceTreeState()) {
|
|
||||||
on<InitialEvent>(_fetchSpaces);
|
on<InitialEvent>(_fetchSpaces);
|
||||||
on<OnCommunityExpanded>(_onCommunityExpanded);
|
on<OnCommunityExpanded>(_onCommunityExpanded);
|
||||||
on<OnSpaceExpanded>(_onSpaceExpanded);
|
on<OnSpaceExpanded>(_onSpaceExpanded);
|
||||||
on<OnCommunitySelected>(_onCommunitySelected);
|
on<OnCommunitySelected>(_onCommunitySelected);
|
||||||
on<OnSpaceSelected>(_onSpaceSelected);
|
on<OnSpaceSelected>(_onSpaceSelected);
|
||||||
on<SearchQueryEvent>(_onSearch);
|
on<SearchQueryEvent>(_onSearch);
|
||||||
|
on<ClearAllData>(_clearAllData);
|
||||||
|
on<ClearCachedData>(_clearCachedData);
|
||||||
}
|
}
|
||||||
|
|
||||||
_fetchSpaces(InitialEvent event, Emitter<SpaceTreeState> emit) async {
|
_fetchSpaces(InitialEvent event, Emitter<SpaceTreeState> emit) async {
|
||||||
emit(SpaceTreeLoadingState());
|
emit(SpaceTreeLoadingState());
|
||||||
try {
|
try {
|
||||||
final projectUuid = projectCubit.state;
|
final projectUuid = await ProjectManager.getProjectUUID() ?? '';
|
||||||
|
|
||||||
List<CommunityModel> communities = await CommunitySpaceManagementApi()
|
List<CommunityModel> communities =
|
||||||
.fetchCommunities(projectUuid ?? TempConst.projectId);
|
await CommunitySpaceManagementApi().fetchCommunities(projectUuid);
|
||||||
|
|
||||||
List<CommunityModel> updatedCommunities = await Future.wait(
|
List<CommunityModel> updatedCommunities = await Future.wait(
|
||||||
communities.map((community) async {
|
communities.map((community) async {
|
||||||
List<SpaceModel> spaces = await CommunitySpaceManagementApi()
|
List<SpaceModel> spaces =
|
||||||
.getSpaceHierarchy(
|
await CommunitySpaceManagementApi().getSpaceHierarchy(community.uuid, projectUuid);
|
||||||
community.uuid, projectUuid ?? TempConst.projectId);
|
|
||||||
|
|
||||||
return CommunityModel(
|
return CommunityModel(
|
||||||
uuid: community.uuid,
|
uuid: community.uuid,
|
||||||
@ -48,19 +44,15 @@ class SpaceTreeBloc extends Bloc<SpaceTreeEvent, SpaceTreeState> {
|
|||||||
);
|
);
|
||||||
|
|
||||||
emit(state.copyWith(
|
emit(state.copyWith(
|
||||||
communitiesList: updatedCommunities,
|
communitiesList: updatedCommunities, expandedCommunity: [], expandedSpaces: []));
|
||||||
expandedCommunity: [],
|
|
||||||
expandedSpaces: []));
|
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
emit(SpaceTreeErrorState('Error loading communities and spaces: $e'));
|
emit(SpaceTreeErrorState('Error loading communities and spaces: $e'));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
_onCommunityExpanded(
|
_onCommunityExpanded(OnCommunityExpanded event, Emitter<SpaceTreeState> emit) async {
|
||||||
OnCommunityExpanded event, Emitter<SpaceTreeState> emit) async {
|
|
||||||
try {
|
try {
|
||||||
List<String> updatedExpandedCommunityList =
|
List<String> updatedExpandedCommunityList = List.from(state.expandedCommunities);
|
||||||
List.from(state.expandedCommunities);
|
|
||||||
|
|
||||||
if (updatedExpandedCommunityList.contains(event.communityId)) {
|
if (updatedExpandedCommunityList.contains(event.communityId)) {
|
||||||
updatedExpandedCommunityList.remove(event.communityId);
|
updatedExpandedCommunityList.remove(event.communityId);
|
||||||
@ -92,17 +84,13 @@ class SpaceTreeBloc extends Bloc<SpaceTreeEvent, SpaceTreeState> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
_onCommunitySelected(
|
_onCommunitySelected(OnCommunitySelected event, Emitter<SpaceTreeState> emit) async {
|
||||||
OnCommunitySelected event, Emitter<SpaceTreeState> emit) async {
|
|
||||||
try {
|
try {
|
||||||
List<String> updatedSelectedCommunities =
|
List<String> updatedSelectedCommunities =
|
||||||
List.from(state.selectedCommunities.toSet().toList());
|
List.from(state.selectedCommunities.toSet().toList());
|
||||||
List<String> updatedSelectedSpaces =
|
List<String> updatedSelectedSpaces = List.from(state.selectedSpaces.toSet().toList());
|
||||||
List.from(state.selectedSpaces.toSet().toList());
|
List<String> updatedSoldChecks = List.from(state.soldCheck.toSet().toList());
|
||||||
List<String> updatedSoldChecks =
|
Map<String, List<String>> communityAndSpaces = Map.from(state.selectedCommunityAndSpaces);
|
||||||
List.from(state.soldCheck.toSet().toList());
|
|
||||||
Map<String, List<String>> communityAndSpaces =
|
|
||||||
Map.from(state.selectedCommunityAndSpaces);
|
|
||||||
|
|
||||||
List<String> childrenIds = _getAllChildIds(event.children);
|
List<String> childrenIds = _getAllChildIds(event.children);
|
||||||
|
|
||||||
@ -133,12 +121,9 @@ class SpaceTreeBloc extends Bloc<SpaceTreeEvent, SpaceTreeState> {
|
|||||||
try {
|
try {
|
||||||
List<String> updatedSelectedCommunities =
|
List<String> updatedSelectedCommunities =
|
||||||
List.from(state.selectedCommunities.toSet().toList());
|
List.from(state.selectedCommunities.toSet().toList());
|
||||||
List<String> updatedSelectedSpaces =
|
List<String> updatedSelectedSpaces = List.from(state.selectedSpaces.toSet().toList());
|
||||||
List.from(state.selectedSpaces.toSet().toList());
|
List<String> updatedSoldChecks = List.from(state.soldCheck.toSet().toList());
|
||||||
List<String> updatedSoldChecks =
|
Map<String, List<String>> communityAndSpaces = Map.from(state.selectedCommunityAndSpaces);
|
||||||
List.from(state.soldCheck.toSet().toList());
|
|
||||||
Map<String, List<String>> communityAndSpaces =
|
|
||||||
Map.from(state.selectedCommunityAndSpaces);
|
|
||||||
|
|
||||||
List<String> childrenIds = _getAllChildIds(event.children);
|
List<String> childrenIds = _getAllChildIds(event.children);
|
||||||
bool isChildSelected = false;
|
bool isChildSelected = false;
|
||||||
@ -153,16 +138,14 @@ class SpaceTreeBloc extends Bloc<SpaceTreeEvent, SpaceTreeState> {
|
|||||||
!updatedSoldChecks.contains(event.spaceId)) {
|
!updatedSoldChecks.contains(event.spaceId)) {
|
||||||
// First click: Select the space and all its children
|
// First click: Select the space and all its children
|
||||||
updatedSelectedSpaces.add(event.spaceId);
|
updatedSelectedSpaces.add(event.spaceId);
|
||||||
updatedSelectedCommunities.add(event.communityId);
|
updatedSelectedCommunities.add(event.communityModel.uuid);
|
||||||
if (childrenIds.isNotEmpty) {
|
if (childrenIds.isNotEmpty) {
|
||||||
updatedSelectedSpaces.addAll(childrenIds);
|
updatedSelectedSpaces.addAll(childrenIds);
|
||||||
}
|
}
|
||||||
|
|
||||||
List<String> spaces =
|
List<String> spaces = _getThePathToChild(event.communityModel.uuid, event.spaceId);
|
||||||
_getThePathToChild(event.communityId, event.spaceId);
|
|
||||||
for (String space in spaces) {
|
for (String space in spaces) {
|
||||||
if (!updatedSelectedSpaces.contains(space) &&
|
if (!updatedSelectedSpaces.contains(space) && !updatedSoldChecks.contains(space)) {
|
||||||
!updatedSoldChecks.contains(space)) {
|
|
||||||
updatedSoldChecks.add(space);
|
updatedSoldChecks.add(space);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -182,20 +165,30 @@ class SpaceTreeBloc extends Bloc<SpaceTreeEvent, SpaceTreeState> {
|
|||||||
updatedSoldChecks.remove(event.spaceId);
|
updatedSoldChecks.remove(event.spaceId);
|
||||||
|
|
||||||
List<String> parents =
|
List<String> parents =
|
||||||
_getThePathToChild(event.communityId, event.spaceId);
|
_getThePathToChild(event.communityModel.uuid, event.spaceId).toSet().toList();
|
||||||
if (!_parentSelected(parents, updatedSelectedSpaces)) {
|
|
||||||
|
if (updatedSelectedSpaces.isEmpty) {
|
||||||
updatedSoldChecks.removeWhere(parents.contains);
|
updatedSoldChecks.removeWhere(parents.contains);
|
||||||
}
|
updatedSelectedCommunities.remove(event.communityModel.uuid);
|
||||||
if (!_anySpacesSelectedInCommunity(
|
} else {
|
||||||
event.communityId, updatedSelectedSpaces, updatedSoldChecks)) {
|
// Check if any parent has selected children
|
||||||
updatedSelectedCommunities.remove(event.communityId);
|
for (String space in parents) {
|
||||||
|
if (!_noChildrenSelected(event.communityModel, space, updatedSelectedSpaces, parents)) {
|
||||||
|
updatedSoldChecks.remove(space);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
communityAndSpaces[event.communityId] = updatedSelectedSpaces;
|
if (!_anySpacesSelectedInCommunity(
|
||||||
|
event.communityModel, updatedSelectedSpaces, updatedSoldChecks)) {
|
||||||
|
updatedSelectedCommunities.remove(event.communityModel.uuid);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
communityAndSpaces[event.communityModel.uuid] = updatedSelectedSpaces;
|
||||||
|
|
||||||
emit(state.copyWith(
|
emit(state.copyWith(
|
||||||
selectedCommunities: updatedSelectedCommunities,
|
selectedCommunities: updatedSelectedCommunities.toSet().toList(),
|
||||||
selectedSpaces: updatedSelectedSpaces,
|
selectedSpaces: updatedSelectedSpaces,
|
||||||
soldCheck: updatedSoldChecks,
|
soldCheck: updatedSoldChecks,
|
||||||
selectedCommunityAndSpaces: communityAndSpaces));
|
selectedCommunityAndSpaces: communityAndSpaces));
|
||||||
@ -205,12 +198,24 @@ class SpaceTreeBloc extends Bloc<SpaceTreeEvent, SpaceTreeState> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
_parentSelected(List<String> parents, List<String> selectedSpaces) {
|
_noChildrenSelected(
|
||||||
for (String space in parents) {
|
CommunityModel community, String spaceId, List<String> selectedSpaces, List<String> parents) {
|
||||||
if (selectedSpaces.contains(space)) {
|
if (selectedSpaces.contains(spaceId)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
List<SpaceModel> children = _getAllChildSpaces(community.spaces);
|
||||||
|
for (var child in children) {
|
||||||
|
if (spaceId == child.uuid) {
|
||||||
|
List<String> ids = _getAllChildIds(child.children);
|
||||||
|
for (var id in ids) {
|
||||||
|
if (selectedSpaces.contains(id)) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -221,18 +226,54 @@ class SpaceTreeBloc extends Bloc<SpaceTreeEvent, SpaceTreeState> {
|
|||||||
|
|
||||||
// Filter communities and expand only those that match the query
|
// Filter communities and expand only those that match the query
|
||||||
filteredCommunity = communities.where((community) {
|
filteredCommunity = communities.where((community) {
|
||||||
final containsQueryInCommunity = community.name
|
final containsQueryInCommunity =
|
||||||
.toLowerCase()
|
community.name.toLowerCase().contains(event.searchQuery.toLowerCase());
|
||||||
.contains(event.searchQuery.toLowerCase());
|
final containsQueryInSpaces =
|
||||||
final containsQueryInSpaces = community.spaces.any(
|
community.spaces.any((space) => _containsQuery(space, event.searchQuery.toLowerCase()));
|
||||||
(space) => _containsQuery(space, event.searchQuery.toLowerCase()));
|
|
||||||
|
|
||||||
return containsQueryInCommunity || containsQueryInSpaces;
|
return containsQueryInCommunity || containsQueryInSpaces;
|
||||||
}).toList();
|
}).toList();
|
||||||
|
|
||||||
emit(state.copyWith(
|
emit(state.copyWith(
|
||||||
filteredCommunity: filteredCommunity,
|
filteredCommunity: filteredCommunity,
|
||||||
isSearching: event.searchQuery.isNotEmpty));
|
isSearching: event.searchQuery.isNotEmpty,
|
||||||
|
searchQuery: event.searchQuery));
|
||||||
|
} catch (e) {
|
||||||
|
emit(const SpaceTreeErrorState('Something went wrong'));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
_clearAllData(ClearAllData event, Emitter<SpaceTreeState> emit) async {
|
||||||
|
try {
|
||||||
|
emit(state.copyWith(
|
||||||
|
communitiesList: [],
|
||||||
|
filteredCommunity: [],
|
||||||
|
isSearching: false,
|
||||||
|
soldCheck: [],
|
||||||
|
selectedSpaces: [],
|
||||||
|
selectedCommunities: [],
|
||||||
|
selectedCommunityAndSpaces: {},
|
||||||
|
searchQuery: '',
|
||||||
|
expandedSpaces: [],
|
||||||
|
expandedCommunity: []));
|
||||||
|
} catch (e) {
|
||||||
|
emit(const SpaceTreeErrorState('Something went wrong'));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
_clearCachedData(ClearCachedData event, Emitter<SpaceTreeState> emit) async {
|
||||||
|
try {
|
||||||
|
emit(state.copyWith(
|
||||||
|
communitiesList: state.communityList,
|
||||||
|
filteredCommunity: [],
|
||||||
|
isSearching: false,
|
||||||
|
soldCheck: [],
|
||||||
|
selectedSpaces: [],
|
||||||
|
selectedCommunities: [],
|
||||||
|
selectedCommunityAndSpaces: {},
|
||||||
|
searchQuery: '',
|
||||||
|
expandedSpaces: [],
|
||||||
|
expandedCommunity: []));
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
emit(const SpaceTreeErrorState('Something went wrong'));
|
emit(const SpaceTreeErrorState('Something went wrong'));
|
||||||
}
|
}
|
||||||
@ -241,8 +282,8 @@ class SpaceTreeBloc extends Bloc<SpaceTreeEvent, SpaceTreeState> {
|
|||||||
// Helper function to determine if any space or its children match the search query
|
// Helper function to determine if any space or its children match the search query
|
||||||
bool _containsQuery(SpaceModel space, String query) {
|
bool _containsQuery(SpaceModel space, String query) {
|
||||||
final matchesSpace = space.name.toLowerCase().contains(query);
|
final matchesSpace = space.name.toLowerCase().contains(query);
|
||||||
final matchesChildren = space.children.any((child) =>
|
final matchesChildren =
|
||||||
_containsQuery(child, query)); // Recursive check for children
|
space.children.any((child) => _containsQuery(child, query)); // Recursive check for children
|
||||||
|
|
||||||
return matchesSpace || matchesChildren;
|
return matchesSpace || matchesChildren;
|
||||||
}
|
}
|
||||||
@ -253,24 +294,28 @@ class SpaceTreeBloc extends Bloc<SpaceTreeEvent, SpaceTreeState> {
|
|||||||
ids.add(child.uuid!);
|
ids.add(child.uuid!);
|
||||||
ids.addAll(_getAllChildIds(child.children));
|
ids.addAll(_getAllChildIds(child.children));
|
||||||
}
|
}
|
||||||
return ids;
|
return ids.toSet().toList();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool _anySpacesSelectedInCommunity(String communityId,
|
List<SpaceModel> _getAllChildSpaces(List<SpaceModel> spaces) {
|
||||||
List<String> selectedSpaces, List<String> partialCheckedList) {
|
List<SpaceModel> children = [];
|
||||||
|
for (var child in spaces) {
|
||||||
|
children.add(child);
|
||||||
|
children.addAll(_getAllChildSpaces(child.children));
|
||||||
|
}
|
||||||
|
return children;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool _anySpacesSelectedInCommunity(
|
||||||
|
CommunityModel community, List<String> selectedSpaces, List<String> partialCheckedList) {
|
||||||
bool result = false;
|
bool result = false;
|
||||||
for (var community in state.communityList) {
|
|
||||||
if (community.uuid == communityId) {
|
|
||||||
List<String> ids = _getAllChildIds(community.spaces);
|
List<String> ids = _getAllChildIds(community.spaces);
|
||||||
for (var id in ids) {
|
for (var id in ids) {
|
||||||
result =
|
result = selectedSpaces.contains(id) || partialCheckedList.contains(id);
|
||||||
selectedSpaces.contains(id) || partialCheckedList.contains(id);
|
|
||||||
if (result) {
|
if (result) {
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -291,8 +336,7 @@ class SpaceTreeBloc extends Bloc<SpaceTreeEvent, SpaceTreeState> {
|
|||||||
return ids;
|
return ids;
|
||||||
}
|
}
|
||||||
|
|
||||||
List<String> _getAllParentsIds(
|
List<String> _getAllParentsIds(SpaceModel child, String spaceId, List<String> listIds) {
|
||||||
SpaceModel child, String spaceId, List<String> listIds) {
|
|
||||||
List<String> ids = listIds;
|
List<String> ids = listIds;
|
||||||
|
|
||||||
ids.add(child.uuid ?? '');
|
ids.add(child.uuid ?? '');
|
||||||
@ -313,4 +357,9 @@ class SpaceTreeBloc extends Bloc<SpaceTreeEvent, SpaceTreeState> {
|
|||||||
ids.removeLast();
|
ids.removeLast();
|
||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
Future<void> close() async {
|
||||||
|
super.close();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
import 'package:equatable/equatable.dart';
|
import 'package:equatable/equatable.dart';
|
||||||
|
import 'package:syncrow_web/pages/spaces_management/all_spaces/model/community_model.dart';
|
||||||
import 'package:syncrow_web/pages/spaces_management/all_spaces/model/space_model.dart';
|
import 'package:syncrow_web/pages/spaces_management/all_spaces/model/space_model.dart';
|
||||||
|
|
||||||
class SpaceTreeEvent extends Equatable {
|
class SpaceTreeEvent extends Equatable {
|
||||||
@ -49,14 +50,14 @@ class OnSpaceExpanded extends SpaceTreeEvent {
|
|||||||
}
|
}
|
||||||
|
|
||||||
class OnSpaceSelected extends SpaceTreeEvent {
|
class OnSpaceSelected extends SpaceTreeEvent {
|
||||||
final String communityId;
|
|
||||||
final String spaceId;
|
final String spaceId;
|
||||||
final List<SpaceModel> children;
|
final List<SpaceModel> children;
|
||||||
|
final CommunityModel communityModel;
|
||||||
|
|
||||||
const OnSpaceSelected(this.communityId, this.spaceId, this.children);
|
const OnSpaceSelected(this.communityModel, this.spaceId, this.children);
|
||||||
|
|
||||||
@override
|
@override
|
||||||
List<Object> get props => [communityId, spaceId, children];
|
List<Object> get props => [communityModel, spaceId, children];
|
||||||
}
|
}
|
||||||
|
|
||||||
class SearchQueryEvent extends SpaceTreeEvent {
|
class SearchQueryEvent extends SpaceTreeEvent {
|
||||||
@ -67,3 +68,7 @@ class SearchQueryEvent extends SpaceTreeEvent {
|
|||||||
@override
|
@override
|
||||||
List<Object> get props => [searchQuery];
|
List<Object> get props => [searchQuery];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class ClearAllData extends SpaceTreeEvent {}
|
||||||
|
|
||||||
|
class ClearCachedData extends SpaceTreeEvent {}
|
||||||
|
@ -11,6 +11,7 @@ class SpaceTreeState extends Equatable {
|
|||||||
final List<String> selectedSpaces;
|
final List<String> selectedSpaces;
|
||||||
final List<String> soldCheck;
|
final List<String> soldCheck;
|
||||||
final bool isSearching;
|
final bool isSearching;
|
||||||
|
final String searchQuery;
|
||||||
|
|
||||||
const SpaceTreeState(
|
const SpaceTreeState(
|
||||||
{this.communityList = const [],
|
{this.communityList = const [],
|
||||||
@ -21,7 +22,8 @@ class SpaceTreeState extends Equatable {
|
|||||||
this.selectedSpaces = const [],
|
this.selectedSpaces = const [],
|
||||||
this.soldCheck = const [],
|
this.soldCheck = const [],
|
||||||
this.isSearching = false,
|
this.isSearching = false,
|
||||||
this.selectedCommunityAndSpaces = const {}});
|
this.selectedCommunityAndSpaces = const {},
|
||||||
|
this.searchQuery = ''});
|
||||||
|
|
||||||
SpaceTreeState copyWith(
|
SpaceTreeState copyWith(
|
||||||
{List<CommunityModel>? communitiesList,
|
{List<CommunityModel>? communitiesList,
|
||||||
@ -32,7 +34,8 @@ class SpaceTreeState extends Equatable {
|
|||||||
List<String>? selectedSpaces,
|
List<String>? selectedSpaces,
|
||||||
List<String>? soldCheck,
|
List<String>? soldCheck,
|
||||||
bool? isSearching,
|
bool? isSearching,
|
||||||
Map<String, List<String>>? selectedCommunityAndSpaces}) {
|
Map<String, List<String>>? selectedCommunityAndSpaces,
|
||||||
|
String? searchQuery}) {
|
||||||
return SpaceTreeState(
|
return SpaceTreeState(
|
||||||
communityList: communitiesList ?? this.communityList,
|
communityList: communitiesList ?? this.communityList,
|
||||||
filteredCommunity: filteredCommunity ?? this.filteredCommunity,
|
filteredCommunity: filteredCommunity ?? this.filteredCommunity,
|
||||||
@ -42,7 +45,8 @@ class SpaceTreeState extends Equatable {
|
|||||||
selectedSpaces: selectedSpaces ?? this.selectedSpaces,
|
selectedSpaces: selectedSpaces ?? this.selectedSpaces,
|
||||||
soldCheck: soldCheck ?? this.soldCheck,
|
soldCheck: soldCheck ?? this.soldCheck,
|
||||||
isSearching: isSearching ?? this.isSearching,
|
isSearching: isSearching ?? this.isSearching,
|
||||||
selectedCommunityAndSpaces: selectedCommunityAndSpaces ?? this.selectedCommunityAndSpaces);
|
selectedCommunityAndSpaces: selectedCommunityAndSpaces ?? this.selectedCommunityAndSpaces,
|
||||||
|
searchQuery: searchQuery ?? this.searchQuery);
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
@ -55,7 +59,8 @@ class SpaceTreeState extends Equatable {
|
|||||||
selectedSpaces,
|
selectedSpaces,
|
||||||
soldCheck,
|
soldCheck,
|
||||||
isSearching,
|
isSearching,
|
||||||
selectedCommunityAndSpaces
|
selectedCommunityAndSpaces,
|
||||||
|
searchQuery
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -39,6 +39,7 @@ class _SpaceTreeViewState extends State<SpaceTreeView> {
|
|||||||
: Column(
|
: Column(
|
||||||
children: [
|
children: [
|
||||||
CustomSearchBar(
|
CustomSearchBar(
|
||||||
|
searchQuery: state.searchQuery,
|
||||||
onSearchChanged: (query) {
|
onSearchChanged: (query) {
|
||||||
context.read<SpaceTreeBloc>().add(SearchQueryEvent(query));
|
context.read<SpaceTreeBloc>().add(SearchQueryEvent(query));
|
||||||
},
|
},
|
||||||
@ -99,8 +100,8 @@ class _SpaceTreeViewState extends State<SpaceTreeView> {
|
|||||||
state.expandedSpaces.contains(space.uuid),
|
state.expandedSpaces.contains(space.uuid),
|
||||||
onItemSelected: () {
|
onItemSelected: () {
|
||||||
context.read<SpaceTreeBloc>().add(
|
context.read<SpaceTreeBloc>().add(
|
||||||
OnSpaceSelected(community.uuid,
|
OnSpaceSelected(community, space.uuid ?? '',
|
||||||
space.uuid ?? '', space.children));
|
space.children));
|
||||||
widget.onSelect();
|
widget.onSelect();
|
||||||
},
|
},
|
||||||
onExpansionChanged: () {
|
onExpansionChanged: () {
|
||||||
@ -113,7 +114,7 @@ class _SpaceTreeViewState extends State<SpaceTreeView> {
|
|||||||
state.soldCheck.contains(space.uuid),
|
state.soldCheck.contains(space.uuid),
|
||||||
isSoldCheck: state.soldCheck.contains(space.uuid),
|
isSoldCheck: state.soldCheck.contains(space.uuid),
|
||||||
children: _buildNestedSpaces(
|
children: _buildNestedSpaces(
|
||||||
context, state, space, community.uuid),
|
context, state, space, community),
|
||||||
);
|
);
|
||||||
}).toList(),
|
}).toList(),
|
||||||
),
|
),
|
||||||
@ -196,7 +197,7 @@ class _SpaceTreeViewState extends State<SpaceTreeView> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
List<Widget> _buildNestedSpaces(
|
List<Widget> _buildNestedSpaces(
|
||||||
BuildContext context, SpaceTreeState state, SpaceModel space, String communityId) {
|
BuildContext context, SpaceTreeState state, SpaceModel space, CommunityModel community) {
|
||||||
return space.children.map((child) {
|
return space.children.map((child) {
|
||||||
return CustomExpansionTileSpaceTree(
|
return CustomExpansionTileSpaceTree(
|
||||||
isSelected:
|
isSelected:
|
||||||
@ -207,13 +208,13 @@ class _SpaceTreeViewState extends State<SpaceTreeView> {
|
|||||||
onItemSelected: () {
|
onItemSelected: () {
|
||||||
context
|
context
|
||||||
.read<SpaceTreeBloc>()
|
.read<SpaceTreeBloc>()
|
||||||
.add(OnSpaceSelected(communityId, child.uuid ?? '', child.children));
|
.add(OnSpaceSelected(community, child.uuid ?? '', child.children));
|
||||||
widget.onSelect();
|
widget.onSelect();
|
||||||
},
|
},
|
||||||
onExpansionChanged: () {
|
onExpansionChanged: () {
|
||||||
context.read<SpaceTreeBloc>().add(OnSpaceExpanded(communityId, child.uuid ?? ''));
|
context.read<SpaceTreeBloc>().add(OnSpaceExpanded(community.uuid, child.uuid ?? ''));
|
||||||
},
|
},
|
||||||
children: _buildNestedSpaces(context, state, child, communityId),
|
children: _buildNestedSpaces(context, state, child, community),
|
||||||
);
|
);
|
||||||
}).toList();
|
}).toList();
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,8 @@
|
|||||||
|
import 'dart:developer';
|
||||||
|
|
||||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||||
import 'package:syncrow_web/pages/common/bloc/project_cubit.dart';
|
import 'package:shared_preferences/shared_preferences.dart';
|
||||||
|
import 'package:syncrow_web/pages/common/bloc/project_manager.dart';
|
||||||
import 'package:syncrow_web/pages/spaces_management/all_spaces/model/community_model.dart';
|
import 'package:syncrow_web/pages/spaces_management/all_spaces/model/community_model.dart';
|
||||||
import 'package:syncrow_web/pages/spaces_management/all_spaces/model/create_subspace_model.dart';
|
import 'package:syncrow_web/pages/spaces_management/all_spaces/model/create_subspace_model.dart';
|
||||||
import 'package:syncrow_web/pages/spaces_management/all_spaces/model/product_model.dart';
|
import 'package:syncrow_web/pages/spaces_management/all_spaces/model/product_model.dart';
|
||||||
@ -15,19 +18,19 @@ import 'package:syncrow_web/services/product_api.dart';
|
|||||||
import 'package:syncrow_web/services/space_mana_api.dart';
|
import 'package:syncrow_web/services/space_mana_api.dart';
|
||||||
import 'package:syncrow_web/services/space_model_mang_api.dart';
|
import 'package:syncrow_web/services/space_model_mang_api.dart';
|
||||||
import 'package:syncrow_web/utils/constants/action_enum.dart';
|
import 'package:syncrow_web/utils/constants/action_enum.dart';
|
||||||
|
import 'package:syncrow_web/utils/constants/strings_manager.dart';
|
||||||
import 'package:syncrow_web/utils/constants/temp_const.dart';
|
import 'package:syncrow_web/utils/constants/temp_const.dart';
|
||||||
|
import 'package:syncrow_web/utils/helpers/shared_preferences_helper.dart';
|
||||||
|
|
||||||
class SpaceManagementBloc
|
class SpaceManagementBloc
|
||||||
extends Bloc<SpaceManagementEvent, SpaceManagementState> {
|
extends Bloc<SpaceManagementEvent, SpaceManagementState> {
|
||||||
final CommunitySpaceManagementApi _api;
|
final CommunitySpaceManagementApi _api;
|
||||||
final ProductApi _productApi;
|
final ProductApi _productApi;
|
||||||
final SpaceModelManagementApi _spaceModelApi;
|
final SpaceModelManagementApi _spaceModelApi;
|
||||||
final ProjectCubit projectCubit;
|
|
||||||
|
|
||||||
List<ProductModel>? _cachedProducts;
|
List<ProductModel>? _cachedProducts;
|
||||||
|
|
||||||
SpaceManagementBloc(
|
SpaceManagementBloc(this._api, this._productApi, this._spaceModelApi)
|
||||||
this._api, this._productApi, this._spaceModelApi, this.projectCubit)
|
|
||||||
: super(SpaceManagementInitial()) {
|
: super(SpaceManagementInitial()) {
|
||||||
on<LoadCommunityAndSpacesEvent>(_onLoadCommunityAndSpaces);
|
on<LoadCommunityAndSpacesEvent>(_onLoadCommunityAndSpaces);
|
||||||
on<UpdateSpacePositionEvent>(_onUpdateSpacePosition);
|
on<UpdateSpacePositionEvent>(_onUpdateSpacePosition);
|
||||||
@ -43,17 +46,23 @@ class SpaceManagementBloc
|
|||||||
on<SpaceModelLoadEvent>(_onLoadSpaceModel);
|
on<SpaceModelLoadEvent>(_onLoadSpaceModel);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void _logEvent(String eventName) {
|
||||||
|
log('Event Triggered: $eventName');
|
||||||
|
}
|
||||||
|
|
||||||
void _onUpdateCommunity(
|
void _onUpdateCommunity(
|
||||||
UpdateCommunityEvent event,
|
UpdateCommunityEvent event,
|
||||||
Emitter<SpaceManagementState> emit,
|
Emitter<SpaceManagementState> emit,
|
||||||
) async {
|
) async {
|
||||||
|
_logEvent('UpdateCommunityEvent');
|
||||||
|
|
||||||
final previousState = state;
|
final previousState = state;
|
||||||
try {
|
try {
|
||||||
final projectUuid = projectCubit.state;
|
final projectUuid = await ProjectManager.getProjectUUID() ?? '';
|
||||||
|
|
||||||
emit(SpaceManagementLoading());
|
emit(SpaceManagementLoading());
|
||||||
final success = await _api.updateCommunity(
|
final success = await _api.updateCommunity(
|
||||||
event.communityUuid, event.name, projectUuid ?? TempConst.projectId);
|
event.communityUuid, event.name, projectUuid);
|
||||||
if (success) {
|
if (success) {
|
||||||
if (previousState is SpaceManagementLoaded) {
|
if (previousState is SpaceManagementLoaded) {
|
||||||
final updatedCommunities =
|
final updatedCommunities =
|
||||||
@ -85,7 +94,7 @@ class SpaceManagementBloc
|
|||||||
Future<List<SpaceTemplateModel>> fetchSpaceModels(
|
Future<List<SpaceTemplateModel>> fetchSpaceModels(
|
||||||
SpaceManagementState previousState) async {
|
SpaceManagementState previousState) async {
|
||||||
try {
|
try {
|
||||||
final projectUuid = projectCubit.state;
|
final projectUuid = await ProjectManager.getProjectUUID() ?? '';
|
||||||
|
|
||||||
List<SpaceTemplateModel> allSpaces = [];
|
List<SpaceTemplateModel> allSpaces = [];
|
||||||
List<SpaceTemplateModel> prevSpaceModels = [];
|
List<SpaceTemplateModel> prevSpaceModels = [];
|
||||||
@ -104,7 +113,7 @@ class SpaceManagementBloc
|
|||||||
|
|
||||||
while (hasNext) {
|
while (hasNext) {
|
||||||
final spaces = await _spaceModelApi.listSpaceModels(
|
final spaces = await _spaceModelApi.listSpaceModels(
|
||||||
page: page, projectId: projectUuid ?? TempConst.projectId);
|
page: page, projectId: projectUuid);
|
||||||
if (spaces.isNotEmpty) {
|
if (spaces.isNotEmpty) {
|
||||||
allSpaces.addAll(spaces);
|
allSpaces.addAll(spaces);
|
||||||
page++;
|
page++;
|
||||||
@ -113,7 +122,7 @@ class SpaceManagementBloc
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
prevSpaceModels = await _spaceModelApi.listSpaceModels(
|
prevSpaceModels = await _spaceModelApi.listSpaceModels(
|
||||||
page: 1, projectId: projectUuid ?? TempConst.projectId);
|
page: 1, projectId: projectUuid);
|
||||||
}
|
}
|
||||||
|
|
||||||
return allSpaces;
|
return allSpaces;
|
||||||
@ -142,10 +151,9 @@ class SpaceManagementBloc
|
|||||||
|
|
||||||
Future<List<SpaceModel>> _fetchSpacesForCommunity(
|
Future<List<SpaceModel>> _fetchSpacesForCommunity(
|
||||||
String communityUuid) async {
|
String communityUuid) async {
|
||||||
final projectUuid = projectCubit.state;
|
final projectUuid = await ProjectManager.getProjectUUID() ?? '';
|
||||||
|
|
||||||
return await _api.getSpaceHierarchy(
|
return await _api.getSpaceHierarchy(communityUuid, projectUuid);
|
||||||
communityUuid, projectUuid ?? TempConst.projectId);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> _onNewCommunity(
|
Future<void> _onNewCommunity(
|
||||||
@ -176,7 +184,7 @@ class SpaceManagementBloc
|
|||||||
BlankStateEvent event, Emitter<SpaceManagementState> emit) async {
|
BlankStateEvent event, Emitter<SpaceManagementState> emit) async {
|
||||||
try {
|
try {
|
||||||
final previousState = state;
|
final previousState = state;
|
||||||
final projectUuid = projectCubit.state;
|
final projectUuid = await ProjectManager.getProjectUUID() ?? '';
|
||||||
|
|
||||||
var prevSpaceModels = await fetchSpaceModels(previousState);
|
var prevSpaceModels = await fetchSpaceModels(previousState);
|
||||||
|
|
||||||
@ -191,8 +199,7 @@ class SpaceManagementBloc
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
final communities =
|
final communities = await _api.fetchCommunities(projectUuid);
|
||||||
await _api.fetchCommunities(projectUuid ?? TempConst.projectId);
|
|
||||||
final updatedCommunities =
|
final updatedCommunities =
|
||||||
await Future.wait(communities.map((community) async {
|
await Future.wait(communities.map((community) async {
|
||||||
final spaces = await _fetchSpacesForCommunity(community.uuid);
|
final spaces = await _fetchSpacesForCommunity(community.uuid);
|
||||||
@ -222,14 +229,16 @@ class SpaceManagementBloc
|
|||||||
LoadCommunityAndSpacesEvent event,
|
LoadCommunityAndSpacesEvent event,
|
||||||
Emitter<SpaceManagementState> emit,
|
Emitter<SpaceManagementState> emit,
|
||||||
) async {
|
) async {
|
||||||
|
_logEvent('LoadCommunityAndSpacesEvent');
|
||||||
|
|
||||||
var prevState = state;
|
var prevState = state;
|
||||||
emit(SpaceManagementLoading());
|
emit(SpaceManagementLoading());
|
||||||
try {
|
try {
|
||||||
final projectUuid = projectCubit.state;
|
final projectUuid = await ProjectManager.getProjectUUID() ?? '';
|
||||||
|
|
||||||
_onloadProducts();
|
_onloadProducts();
|
||||||
List<CommunityModel> communities =
|
List<CommunityModel> communities =
|
||||||
await _api.fetchCommunities(projectUuid ?? TempConst.projectId);
|
await _api.fetchCommunities(projectUuid);
|
||||||
|
|
||||||
List<CommunityModel> updatedCommunities = await Future.wait(
|
List<CommunityModel> updatedCommunities = await Future.wait(
|
||||||
communities.map((community) async {
|
communities.map((community) async {
|
||||||
@ -263,10 +272,10 @@ class SpaceManagementBloc
|
|||||||
) async {
|
) async {
|
||||||
try {
|
try {
|
||||||
emit(SpaceManagementLoading());
|
emit(SpaceManagementLoading());
|
||||||
final projectUuid = projectCubit.state;
|
final projectUuid = await ProjectManager.getProjectUUID() ?? '';
|
||||||
|
|
||||||
final success = await _api.deleteCommunity(
|
final success =
|
||||||
event.communityUuid, projectUuid ?? TempConst.projectId);
|
await _api.deleteCommunity(event.communityUuid, projectUuid);
|
||||||
if (success) {
|
if (success) {
|
||||||
add(LoadCommunityAndSpacesEvent());
|
add(LoadCommunityAndSpacesEvent());
|
||||||
} else {
|
} else {
|
||||||
@ -291,9 +300,10 @@ class SpaceManagementBloc
|
|||||||
emit(SpaceManagementLoading());
|
emit(SpaceManagementLoading());
|
||||||
|
|
||||||
try {
|
try {
|
||||||
final projectUuid = projectCubit.state;
|
final projectUuid = await ProjectManager.getProjectUUID() ?? '';
|
||||||
|
|
||||||
CommunityModel? newCommunity = await _api.createCommunity(
|
CommunityModel? newCommunity = await _api.createCommunity(
|
||||||
event.name, event.description, projectUuid ?? TempConst.projectId);
|
event.name, event.description, projectUuid);
|
||||||
var prevSpaceModels = await fetchSpaceModels(previousState);
|
var prevSpaceModels = await fetchSpaceModels(previousState);
|
||||||
|
|
||||||
if (newCommunity != null) {
|
if (newCommunity != null) {
|
||||||
@ -436,7 +446,7 @@ class SpaceManagementBloc
|
|||||||
Future<List<SpaceModel>> saveSpacesHierarchically(
|
Future<List<SpaceModel>> saveSpacesHierarchically(
|
||||||
List<SpaceModel> spaces, String communityUuid) async {
|
List<SpaceModel> spaces, String communityUuid) async {
|
||||||
final orderedSpaces = flattenHierarchy(spaces);
|
final orderedSpaces = flattenHierarchy(spaces);
|
||||||
final projectUuid = projectCubit.state;
|
final projectUuid = await ProjectManager.getProjectUUID() ?? '';
|
||||||
|
|
||||||
final parentsToDelete = orderedSpaces.where((space) =>
|
final parentsToDelete = orderedSpaces.where((space) =>
|
||||||
space.status == SpaceStatus.deleted &&
|
space.status == SpaceStatus.deleted &&
|
||||||
@ -445,8 +455,7 @@ class SpaceManagementBloc
|
|||||||
for (var parent in parentsToDelete) {
|
for (var parent in parentsToDelete) {
|
||||||
try {
|
try {
|
||||||
if (parent.uuid != null) {
|
if (parent.uuid != null) {
|
||||||
await _api.deleteSpace(
|
await _api.deleteSpace(communityUuid, parent.uuid!, projectUuid);
|
||||||
communityUuid, parent.uuid!, projectUuid ?? TempConst.projectId);
|
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
rethrow;
|
rethrow;
|
||||||
@ -459,8 +468,8 @@ class SpaceManagementBloc
|
|||||||
if (space.uuid != null && space.uuid!.isNotEmpty) {
|
if (space.uuid != null && space.uuid!.isNotEmpty) {
|
||||||
List<TagModelUpdate> tagUpdates = [];
|
List<TagModelUpdate> tagUpdates = [];
|
||||||
|
|
||||||
final prevSpace = await _api.getSpace(
|
final prevSpace =
|
||||||
communityUuid, space.uuid!, projectUuid ?? TempConst.projectId);
|
await _api.getSpace(communityUuid, space.uuid!, projectUuid);
|
||||||
final List<UpdateSubspaceTemplateModel> subspaceUpdates = [];
|
final List<UpdateSubspaceTemplateModel> subspaceUpdates = [];
|
||||||
final List<SubspaceModel>? prevSubspaces = prevSpace?.subspaces;
|
final List<SubspaceModel>? prevSubspaces = prevSpace?.subspaces;
|
||||||
final List<SubspaceModel>? newSubspaces = space.subspaces;
|
final List<SubspaceModel>? newSubspaces = space.subspaces;
|
||||||
@ -539,7 +548,7 @@ class SpaceManagementBloc
|
|||||||
subspaces: subspaceUpdates,
|
subspaces: subspaceUpdates,
|
||||||
tags: tagUpdates,
|
tags: tagUpdates,
|
||||||
direction: space.incomingConnection?.direction,
|
direction: space.incomingConnection?.direction,
|
||||||
projectId: projectUuid ?? TempConst.projectId);
|
projectId: projectUuid);
|
||||||
} else {
|
} else {
|
||||||
// Call create if the space does not have a UUID
|
// Call create if the space does not have a UUID
|
||||||
final List<CreateTagBodyModel> tagBodyModels = space.tags != null
|
final List<CreateTagBodyModel> tagBodyModels = space.tags != null
|
||||||
@ -568,7 +577,7 @@ class SpaceManagementBloc
|
|||||||
spaceModelUuid: space.spaceModel?.uuid,
|
spaceModelUuid: space.spaceModel?.uuid,
|
||||||
tags: tagBodyModels,
|
tags: tagBodyModels,
|
||||||
subspaces: createSubspaceBodyModels,
|
subspaces: createSubspaceBodyModels,
|
||||||
projectId: projectUuid ?? TempConst.projectId);
|
projectId: projectUuid);
|
||||||
space.uuid = response?.uuid;
|
space.uuid = response?.uuid;
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
@ -608,10 +617,10 @@ class SpaceManagementBloc
|
|||||||
emit(SpaceManagementLoading());
|
emit(SpaceManagementLoading());
|
||||||
try {
|
try {
|
||||||
var prevState = state;
|
var prevState = state;
|
||||||
final projectUuid = projectCubit.state;
|
final projectUuid = await ProjectManager.getProjectUUID() ?? '';
|
||||||
|
|
||||||
List<CommunityModel> communities =
|
List<CommunityModel> communities =
|
||||||
await _api.fetchCommunities(projectUuid ?? TempConst.projectId);
|
await _api.fetchCommunities(projectUuid);
|
||||||
|
|
||||||
List<CommunityModel> updatedCommunities = await Future.wait(
|
List<CommunityModel> updatedCommunities = await Future.wait(
|
||||||
communities.map((community) async {
|
communities.map((community) async {
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||||
import 'package:syncrow_web/pages/common/bloc/project_cubit.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/spaces_management/structure_selector/bloc/center_body_bloc.dart';
|
import 'package:syncrow_web/pages/spaces_management/structure_selector/bloc/center_body_bloc.dart';
|
||||||
import 'package:syncrow_web/pages/spaces_management/all_spaces/bloc/space_management_bloc.dart';
|
import 'package:syncrow_web/pages/spaces_management/all_spaces/bloc/space_management_bloc.dart';
|
||||||
@ -33,7 +32,6 @@ class SpaceManagementPageState extends State<SpaceManagementPage> {
|
|||||||
_api,
|
_api,
|
||||||
_productApi,
|
_productApi,
|
||||||
_spaceModelApi,
|
_spaceModelApi,
|
||||||
context.read<ProjectCubit>(),
|
|
||||||
)..add(LoadCommunityAndSpacesEvent()),
|
)..add(LoadCommunityAndSpacesEvent()),
|
||||||
),
|
),
|
||||||
BlocProvider(
|
BlocProvider(
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||||
import 'package:syncrow_web/pages/common/bloc/project_cubit.dart';
|
import 'package:syncrow_web/pages/space_tree/view/space_tree_view.dart';
|
||||||
import 'package:syncrow_web/pages/spaces_management/all_spaces/model/community_model.dart';
|
import 'package:syncrow_web/pages/spaces_management/all_spaces/model/community_model.dart';
|
||||||
import 'package:syncrow_web/pages/spaces_management/all_spaces/model/product_model.dart';
|
import 'package:syncrow_web/pages/spaces_management/all_spaces/model/product_model.dart';
|
||||||
import 'package:syncrow_web/pages/spaces_management/all_spaces/model/space_model.dart';
|
import 'package:syncrow_web/pages/spaces_management/all_spaces/model/space_model.dart';
|
||||||
@ -75,20 +75,14 @@ class _LoadedSpaceViewState extends State<LoadedSpaceView> {
|
|||||||
return Stack(
|
return Stack(
|
||||||
clipBehavior: Clip.none,
|
clipBehavior: Clip.none,
|
||||||
children: [
|
children: [
|
||||||
Row(
|
|
||||||
children: [
|
|
||||||
SidebarWidget(
|
|
||||||
communities: widget.communities,
|
|
||||||
selectedSpaceUuid: widget.selectedSpace?.uuid ??
|
|
||||||
widget.selectedCommunity?.uuid ??
|
|
||||||
'',
|
|
||||||
),
|
|
||||||
widget.shouldNavigateToSpaceModelPage
|
widget.shouldNavigateToSpaceModelPage
|
||||||
? Expanded(
|
? Row(
|
||||||
|
children: [
|
||||||
|
SizedBox(width: 300, child: SpaceTreeView(onSelect: () {})),
|
||||||
|
Expanded(
|
||||||
child: BlocProvider(
|
child: BlocProvider(
|
||||||
create: (context) => SpaceModelBloc(
|
create: (context) => SpaceModelBloc(
|
||||||
api: SpaceModelManagementApi(),
|
api: SpaceModelManagementApi(),
|
||||||
projectCubit: context.read<ProjectCubit>(),
|
|
||||||
initialSpaceModels: _spaceModels,
|
initialSpaceModels: _spaceModels,
|
||||||
),
|
),
|
||||||
child: SpaceModelPage(
|
child: SpaceModelPage(
|
||||||
@ -96,8 +90,17 @@ class _LoadedSpaceViewState extends State<LoadedSpaceView> {
|
|||||||
onSpaceModelsUpdated: _onSpaceModelsUpdated,
|
onSpaceModelsUpdated: _onSpaceModelsUpdated,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
)
|
)
|
||||||
: CommunityStructureArea(
|
: Row(
|
||||||
|
children: [
|
||||||
|
SidebarWidget(
|
||||||
|
communities: widget.communities,
|
||||||
|
selectedSpaceUuid:
|
||||||
|
widget.selectedSpace?.uuid ?? widget.selectedCommunity?.uuid ?? '',
|
||||||
|
),
|
||||||
|
CommunityStructureArea(
|
||||||
selectedCommunity: widget.selectedCommunity,
|
selectedCommunity: widget.selectedCommunity,
|
||||||
selectedSpace: widget.selectedSpace,
|
selectedSpace: widget.selectedSpace,
|
||||||
spaces: widget.selectedCommunity?.spaces ?? [],
|
spaces: widget.selectedCommunity?.spaces ?? [],
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||||
import 'package:syncrow_web/pages/common/bloc/project_cubit.dart';
|
import 'package:syncrow_web/pages/common/bloc/project_manager.dart';
|
||||||
import 'package:syncrow_web/pages/spaces_management/space_model/bloc/create_space_model_event.dart';
|
import 'package:syncrow_web/pages/spaces_management/space_model/bloc/create_space_model_event.dart';
|
||||||
import 'package:syncrow_web/pages/spaces_management/space_model/bloc/create_space_model_state.dart';
|
import 'package:syncrow_web/pages/spaces_management/space_model/bloc/create_space_model_state.dart';
|
||||||
import 'package:syncrow_web/pages/spaces_management/space_model/models/create_space_template_body_model.dart';
|
import 'package:syncrow_web/pages/spaces_management/space_model/models/create_space_template_body_model.dart';
|
||||||
@ -9,20 +9,21 @@ import 'package:syncrow_web/pages/spaces_management/space_model/models/tag_model
|
|||||||
import 'package:syncrow_web/pages/spaces_management/space_model/models/tag_update_model.dart';
|
import 'package:syncrow_web/pages/spaces_management/space_model/models/tag_update_model.dart';
|
||||||
import 'package:syncrow_web/services/space_model_mang_api.dart';
|
import 'package:syncrow_web/services/space_model_mang_api.dart';
|
||||||
import 'package:syncrow_web/utils/constants/action_enum.dart';
|
import 'package:syncrow_web/utils/constants/action_enum.dart';
|
||||||
|
import 'package:syncrow_web/utils/constants/strings_manager.dart';
|
||||||
import 'package:syncrow_web/utils/constants/temp_const.dart';
|
import 'package:syncrow_web/utils/constants/temp_const.dart';
|
||||||
|
import 'package:syncrow_web/utils/helpers/shared_preferences_helper.dart';
|
||||||
|
|
||||||
class CreateSpaceModelBloc
|
class CreateSpaceModelBloc
|
||||||
extends Bloc<CreateSpaceModelEvent, CreateSpaceModelState> {
|
extends Bloc<CreateSpaceModelEvent, CreateSpaceModelState> {
|
||||||
SpaceTemplateModel? _space;
|
SpaceTemplateModel? _space;
|
||||||
|
|
||||||
final SpaceModelManagementApi _api;
|
final SpaceModelManagementApi _api;
|
||||||
final ProjectCubit _projectCubit;
|
|
||||||
|
|
||||||
CreateSpaceModelBloc(this._api, this._projectCubit)
|
CreateSpaceModelBloc(this._api) : super(CreateSpaceModelInitial()) {
|
||||||
: super(CreateSpaceModelInitial()) {
|
|
||||||
on<CreateSpaceTemplate>((event, emit) async {
|
on<CreateSpaceTemplate>((event, emit) async {
|
||||||
try {
|
try {
|
||||||
final projectUuid = _projectCubit.state;
|
final projectUuid = await ProjectManager.getProjectUUID() ?? '';
|
||||||
|
|
||||||
late SpaceTemplateModel spaceTemplate = event.spaceTemplate;
|
late SpaceTemplateModel spaceTemplate = event.spaceTemplate;
|
||||||
|
|
||||||
final tagBodyModels =
|
final tagBodyModels =
|
||||||
@ -45,8 +46,8 @@ class CreateSpaceModelBloc
|
|||||||
tags: tagBodyModels,
|
tags: tagBodyModels,
|
||||||
subspaceModels: subspaceTemplateBodyModels);
|
subspaceModels: subspaceTemplateBodyModels);
|
||||||
|
|
||||||
final newSpaceTemplate = await _api.createSpaceModel(
|
final newSpaceTemplate =
|
||||||
spaceModelBody, projectUuid ?? TempConst.projectId);
|
await _api.createSpaceModel(spaceModelBody, projectUuid);
|
||||||
spaceTemplate.uuid = newSpaceTemplate?.uuid ?? '';
|
spaceTemplate.uuid = newSpaceTemplate?.uuid ?? '';
|
||||||
|
|
||||||
if (newSpaceTemplate != null) {
|
if (newSpaceTemplate != null) {
|
||||||
@ -207,12 +208,11 @@ class CreateSpaceModelBloc
|
|||||||
|
|
||||||
on<ModifySpaceTemplate>((event, emit) async {
|
on<ModifySpaceTemplate>((event, emit) async {
|
||||||
try {
|
try {
|
||||||
final projectUuid = _projectCubit.state;
|
final projectUuid = await ProjectManager.getProjectUUID() ?? '';
|
||||||
|
|
||||||
if (event.spaceTemplate.uuid != null) {
|
if (event.spaceTemplate.uuid != null) {
|
||||||
final prevSpaceModel = await _api.getSpaceModel(
|
final prevSpaceModel = await _api.getSpaceModel(
|
||||||
event.spaceTemplate.uuid ?? '',
|
event.spaceTemplate.uuid ?? '', projectUuid);
|
||||||
projectUuid ?? TempConst.projectId);
|
|
||||||
|
|
||||||
final newSpaceModel = event.updatedSpaceTemplate;
|
final newSpaceModel = event.updatedSpaceTemplate;
|
||||||
String? spaceModelName;
|
String? spaceModelName;
|
||||||
@ -295,8 +295,8 @@ class CreateSpaceModelBloc
|
|||||||
tags: tagUpdates,
|
tags: tagUpdates,
|
||||||
subspaceModels: subspaceUpdates);
|
subspaceModels: subspaceUpdates);
|
||||||
|
|
||||||
final res = await _api.updateSpaceModel(spaceModelBody,
|
final res = await _api.updateSpaceModel(
|
||||||
prevSpaceModel?.uuid ?? '', projectUuid ?? TempConst.projectId);
|
spaceModelBody, prevSpaceModel?.uuid ?? '', projectUuid);
|
||||||
|
|
||||||
if (res != null) {
|
if (res != null) {
|
||||||
emit(CreateSpaceModelLoaded(newSpaceModel));
|
emit(CreateSpaceModelLoaded(newSpaceModel));
|
||||||
|
@ -1,22 +1,20 @@
|
|||||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||||
import 'package:syncrow_web/pages/common/bloc/project_cubit.dart';
|
import 'package:syncrow_web/pages/common/bloc/project_manager.dart';
|
||||||
import 'package:syncrow_web/pages/spaces_management/space_model/bloc/space_model_event.dart';
|
import 'package:syncrow_web/pages/spaces_management/space_model/bloc/space_model_event.dart';
|
||||||
import 'package:syncrow_web/pages/spaces_management/space_model/bloc/space_model_state.dart';
|
import 'package:syncrow_web/pages/spaces_management/space_model/bloc/space_model_state.dart';
|
||||||
import 'package:syncrow_web/pages/spaces_management/space_model/models/space_template_model.dart';
|
import 'package:syncrow_web/pages/spaces_management/space_model/models/space_template_model.dart';
|
||||||
import 'package:syncrow_web/services/space_model_mang_api.dart';
|
import 'package:syncrow_web/services/space_model_mang_api.dart';
|
||||||
import 'package:syncrow_web/utils/constants/temp_const.dart';
|
|
||||||
|
|
||||||
class SpaceModelBloc extends Bloc<SpaceModelEvent, SpaceModelState> {
|
class SpaceModelBloc extends Bloc<SpaceModelEvent, SpaceModelState> {
|
||||||
final SpaceModelManagementApi api;
|
final SpaceModelManagementApi api;
|
||||||
final ProjectCubit projectCubit;
|
|
||||||
|
|
||||||
SpaceModelBloc({
|
SpaceModelBloc({
|
||||||
required this.api,
|
required this.api,
|
||||||
required this.projectCubit,
|
|
||||||
required List<SpaceTemplateModel> initialSpaceModels,
|
required List<SpaceTemplateModel> initialSpaceModels,
|
||||||
}) : super(SpaceModelLoaded(spaceModels: initialSpaceModels)) {
|
}) : super(SpaceModelLoaded(spaceModels: initialSpaceModels)) {
|
||||||
on<CreateSpaceModel>(_onCreateSpaceModel);
|
on<CreateSpaceModel>(_onCreateSpaceModel);
|
||||||
on<UpdateSpaceModel>(_onUpdateSpaceModel);
|
on<UpdateSpaceModel>(_onUpdateSpaceModel);
|
||||||
|
on<DeleteSpaceModel>(_onDeleteSpaceModel);
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> _onCreateSpaceModel(
|
Future<void> _onCreateSpaceModel(
|
||||||
@ -25,9 +23,10 @@ class SpaceModelBloc extends Bloc<SpaceModelEvent, SpaceModelState> {
|
|||||||
|
|
||||||
if (currentState is SpaceModelLoaded) {
|
if (currentState is SpaceModelLoaded) {
|
||||||
try {
|
try {
|
||||||
final projectUuid = projectCubit.state;
|
final projectUuid = await ProjectManager.getProjectUUID() ?? '';
|
||||||
|
|
||||||
final newSpaceModel = await api.getSpaceModel(
|
final newSpaceModel = await api.getSpaceModel(
|
||||||
event.newSpaceModel.uuid ?? '', projectUuid ?? TempConst.projectId);
|
event.newSpaceModel.uuid ?? '', projectUuid);
|
||||||
|
|
||||||
if (newSpaceModel != null) {
|
if (newSpaceModel != null) {
|
||||||
final updatedSpaceModels =
|
final updatedSpaceModels =
|
||||||
@ -46,10 +45,10 @@ class SpaceModelBloc extends Bloc<SpaceModelEvent, SpaceModelState> {
|
|||||||
final currentState = state;
|
final currentState = state;
|
||||||
if (currentState is SpaceModelLoaded) {
|
if (currentState is SpaceModelLoaded) {
|
||||||
try {
|
try {
|
||||||
final projectUuid = projectCubit.state;
|
final projectUuid = await ProjectManager.getProjectUUID() ?? '';
|
||||||
|
|
||||||
final newSpaceModel = await api.getSpaceModel(
|
final newSpaceModel =
|
||||||
event.spaceModelUuid ?? '', projectUuid ?? TempConst.projectId);
|
await api.getSpaceModel(event.spaceModelUuid, projectUuid);
|
||||||
if (newSpaceModel != null) {
|
if (newSpaceModel != null) {
|
||||||
final updatedSpaceModels = currentState.spaceModels.map((model) {
|
final updatedSpaceModels = currentState.spaceModels.map((model) {
|
||||||
return model.uuid == event.spaceModelUuid ? newSpaceModel : model;
|
return model.uuid == event.spaceModelUuid ? newSpaceModel : model;
|
||||||
@ -61,4 +60,28 @@ class SpaceModelBloc extends Bloc<SpaceModelEvent, SpaceModelState> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Future<void> _onDeleteSpaceModel(
|
||||||
|
DeleteSpaceModel event, Emitter<SpaceModelState> emit) async {
|
||||||
|
final currentState = state;
|
||||||
|
|
||||||
|
if (currentState is SpaceModelLoaded) {
|
||||||
|
try {
|
||||||
|
final projectUuid = await ProjectManager.getProjectUUID() ?? '';
|
||||||
|
|
||||||
|
final deletedSuccessfully =
|
||||||
|
await api.deleteSpaceModel(event.spaceModelUuid, projectUuid);
|
||||||
|
|
||||||
|
if (deletedSuccessfully) {
|
||||||
|
final updatedSpaceModels = currentState.spaceModels
|
||||||
|
.where((model) => model.uuid != event.spaceModelUuid)
|
||||||
|
.toList();
|
||||||
|
|
||||||
|
emit(SpaceModelLoaded(spaceModels: updatedSpaceModels));
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
emit(SpaceModelError(message: e.toString()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -34,3 +34,12 @@ class UpdateSpaceModel extends SpaceModelEvent {
|
|||||||
@override
|
@override
|
||||||
List<Object?> get props => [spaceModelUuid];
|
List<Object?> get props => [spaceModelUuid];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class DeleteSpaceModel extends SpaceModelEvent {
|
||||||
|
final String spaceModelUuid;
|
||||||
|
|
||||||
|
DeleteSpaceModel({required this.spaceModelUuid});
|
||||||
|
|
||||||
|
@override
|
||||||
|
List<Object?> get props => [spaceModelUuid];
|
||||||
|
}
|
||||||
|
@ -90,7 +90,11 @@ class SpaceModelPage extends StatelessWidget {
|
|||||||
},
|
},
|
||||||
child: Container(
|
child: Container(
|
||||||
margin: const EdgeInsets.all(8.0),
|
margin: const EdgeInsets.all(8.0),
|
||||||
child: SpaceModelCardWidget(model: model),
|
child: SpaceModelCardWidget(
|
||||||
|
model: model,
|
||||||
|
pageContext: context,
|
||||||
|
topActionsDisabled: false,
|
||||||
|
),
|
||||||
));
|
));
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||||
import 'package:syncrow_web/pages/common/bloc/project_cubit.dart';
|
|
||||||
import 'package:syncrow_web/pages/common/buttons/cancel_button.dart';
|
import 'package:syncrow_web/pages/common/buttons/cancel_button.dart';
|
||||||
import 'package:syncrow_web/pages/common/buttons/default_button.dart';
|
import 'package:syncrow_web/pages/common/buttons/default_button.dart';
|
||||||
import 'package:syncrow_web/pages/spaces_management/all_spaces/model/product_model.dart';
|
import 'package:syncrow_web/pages/spaces_management/all_spaces/model/product_model.dart';
|
||||||
@ -53,7 +52,6 @@ class CreateSpaceModelDialog extends StatelessWidget {
|
|||||||
create: (_) {
|
create: (_) {
|
||||||
final bloc = CreateSpaceModelBloc(
|
final bloc = CreateSpaceModelBloc(
|
||||||
_spaceModelApi,
|
_spaceModelApi,
|
||||||
context.read<ProjectCubit>(),
|
|
||||||
);
|
);
|
||||||
if (spaceModel != null) {
|
if (spaceModel != null) {
|
||||||
bloc.add(UpdateSpaceTemplate(spaceModel!, otherSpaceModels));
|
bloc.add(UpdateSpaceTemplate(spaceModel!, otherSpaceModels));
|
||||||
|
@ -0,0 +1,85 @@
|
|||||||
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:syncrow_web/pages/common/buttons/cancel_button.dart';
|
||||||
|
import 'package:syncrow_web/pages/common/buttons/default_button.dart';
|
||||||
|
import 'package:syncrow_web/utils/color_manager.dart';
|
||||||
|
|
||||||
|
class DeleteSpaceModelDialog extends StatelessWidget {
|
||||||
|
final VoidCallback onConfirmDelete;
|
||||||
|
|
||||||
|
const DeleteSpaceModelDialog({Key? key, required this.onConfirmDelete})
|
||||||
|
: super(key: key);
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
final screenWidth = MediaQuery.of(context).size.width;
|
||||||
|
|
||||||
|
return AlertDialog(
|
||||||
|
shape: RoundedRectangleBorder(
|
||||||
|
borderRadius: BorderRadius.circular(20),
|
||||||
|
),
|
||||||
|
backgroundColor: ColorsManager.whiteColors,
|
||||||
|
title: Center(
|
||||||
|
child: Text(
|
||||||
|
"Delete Space Model",
|
||||||
|
textAlign: TextAlign.center,
|
||||||
|
style: Theme.of(context)
|
||||||
|
.textTheme
|
||||||
|
.headlineLarge
|
||||||
|
?.copyWith(color: ColorsManager.blackColor),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
content: SizedBox(
|
||||||
|
width: screenWidth * 0.4,
|
||||||
|
child: Column(
|
||||||
|
mainAxisSize: MainAxisSize.min,
|
||||||
|
children: [
|
||||||
|
Text(
|
||||||
|
"Are you sure you want to delete?",
|
||||||
|
textAlign: TextAlign.center,
|
||||||
|
style: Theme.of(context).textTheme.headlineSmall,
|
||||||
|
),
|
||||||
|
const SizedBox(height: 15),
|
||||||
|
Text(
|
||||||
|
"The existing sub-spaces, devices, and routines will remain associated with the spaces, but the connection will be removed.",
|
||||||
|
textAlign: TextAlign.center,
|
||||||
|
style: Theme.of(context)
|
||||||
|
.textTheme
|
||||||
|
.bodyMedium
|
||||||
|
?.copyWith(color: ColorsManager.lightGrayColor),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
actions: [
|
||||||
|
Row(
|
||||||
|
mainAxisAlignment: MainAxisAlignment.center,
|
||||||
|
children: [
|
||||||
|
SizedBox(
|
||||||
|
width: 200,
|
||||||
|
child: CancelButton(
|
||||||
|
onPressed: () {
|
||||||
|
Navigator.of(context).pop(); // Close dialog
|
||||||
|
},
|
||||||
|
label: "Cancel",
|
||||||
|
),
|
||||||
|
),
|
||||||
|
const SizedBox(width: 10),
|
||||||
|
SizedBox(
|
||||||
|
width: 200,
|
||||||
|
child: DefaultButton(
|
||||||
|
onPressed: () {
|
||||||
|
Navigator.of(context).pop(); // Close dialog
|
||||||
|
onConfirmDelete(); // Execute delete action
|
||||||
|
},
|
||||||
|
backgroundColor: ColorsManager.semiTransparentRed,
|
||||||
|
borderRadius: 10,
|
||||||
|
foregroundColor: ColorsManager.whiteColors,
|
||||||
|
child: const Text('Delete'),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
],
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
@ -1,13 +1,30 @@
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||||
|
|
||||||
|
import 'package:flutter_svg/svg.dart';
|
||||||
|
import 'package:syncrow_web/pages/common/buttons/cancel_button.dart';
|
||||||
|
import 'package:syncrow_web/pages/common/buttons/default_button.dart';
|
||||||
|
import 'package:syncrow_web/pages/spaces_management/space_model/bloc/space_model_bloc.dart';
|
||||||
|
|
||||||
|
import 'package:syncrow_web/pages/spaces_management/space_model/bloc/space_model_event.dart';
|
||||||
import 'package:syncrow_web/pages/spaces_management/space_model/models/space_template_model.dart';
|
import 'package:syncrow_web/pages/spaces_management/space_model/models/space_template_model.dart';
|
||||||
|
import 'package:syncrow_web/pages/spaces_management/space_model/widgets/dialog/delete_space_model_dialog.dart';
|
||||||
import 'package:syncrow_web/pages/spaces_management/space_model/widgets/dynamic_product_widget.dart';
|
import 'package:syncrow_web/pages/spaces_management/space_model/widgets/dynamic_product_widget.dart';
|
||||||
import 'package:syncrow_web/pages/spaces_management/space_model/widgets/dynamic_room_widget.dart';
|
import 'package:syncrow_web/pages/spaces_management/space_model/widgets/dynamic_room_widget.dart';
|
||||||
import 'package:syncrow_web/utils/color_manager.dart';
|
import 'package:syncrow_web/utils/color_manager.dart';
|
||||||
|
import 'package:syncrow_web/utils/constants/assets.dart';
|
||||||
|
|
||||||
class SpaceModelCardWidget extends StatelessWidget {
|
class SpaceModelCardWidget extends StatelessWidget {
|
||||||
final SpaceTemplateModel model;
|
final SpaceTemplateModel model;
|
||||||
|
final BuildContext? pageContext;
|
||||||
|
final bool topActionsDisabled;
|
||||||
|
|
||||||
const SpaceModelCardWidget({Key? key, required this.model}) : super(key: key);
|
const SpaceModelCardWidget({
|
||||||
|
Key? key,
|
||||||
|
required this.model,
|
||||||
|
this.pageContext,
|
||||||
|
this.topActionsDisabled = true,
|
||||||
|
}) : super(key: key);
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
@ -51,15 +68,51 @@ class SpaceModelCardWidget extends StatelessWidget {
|
|||||||
child: Column(
|
child: Column(
|
||||||
crossAxisAlignment: CrossAxisAlignment.start,
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
children: [
|
children: [
|
||||||
Text(
|
Row(
|
||||||
|
children: [
|
||||||
|
Expanded(
|
||||||
|
child: Text(
|
||||||
model.modelName,
|
model.modelName,
|
||||||
style: Theme.of(context).textTheme.headlineMedium?.copyWith(
|
style:
|
||||||
|
Theme.of(context).textTheme.headlineMedium?.copyWith(
|
||||||
color: Colors.black,
|
color: Colors.black,
|
||||||
fontWeight: FontWeight.bold,
|
fontWeight: FontWeight.bold,
|
||||||
),
|
),
|
||||||
maxLines: 1,
|
maxLines: 1,
|
||||||
overflow: TextOverflow.ellipsis,
|
overflow: TextOverflow.ellipsis,
|
||||||
),
|
),
|
||||||
|
),
|
||||||
|
if (!topActionsDisabled)
|
||||||
|
GestureDetector(
|
||||||
|
onTap: () => _showDeleteDialog(context),
|
||||||
|
child: Container(
|
||||||
|
width: 36, // Adjust size as needed
|
||||||
|
height: 36,
|
||||||
|
decoration: BoxDecoration(
|
||||||
|
shape: BoxShape.circle,
|
||||||
|
color: Colors.white,
|
||||||
|
boxShadow: [
|
||||||
|
BoxShadow(
|
||||||
|
color: Colors.black.withOpacity(0.1),
|
||||||
|
spreadRadius: 2,
|
||||||
|
blurRadius: 5,
|
||||||
|
offset: const Offset(0, 2),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
child: Center(
|
||||||
|
child: SvgPicture.asset(
|
||||||
|
Assets.deleteSpaceModel, // Your actual SVG path
|
||||||
|
width: 20,
|
||||||
|
height: 20,
|
||||||
|
colorFilter: const ColorFilter.mode(
|
||||||
|
Colors.grey, BlendMode.srcIn),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
if (!showOnlyName) ...[
|
if (!showOnlyName) ...[
|
||||||
const SizedBox(height: 10),
|
const SizedBox(height: 10),
|
||||||
Expanded(
|
Expanded(
|
||||||
@ -117,4 +170,22 @@ class SpaceModelCardWidget extends StatelessWidget {
|
|||||||
},
|
},
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void _showDeleteDialog(BuildContext context) {
|
||||||
|
showDialog(
|
||||||
|
context: context,
|
||||||
|
barrierDismissible: true,
|
||||||
|
builder: (BuildContext dialogContext) {
|
||||||
|
return DeleteSpaceModelDialog(
|
||||||
|
onConfirmDelete: () {
|
||||||
|
if (pageContext != null) {
|
||||||
|
pageContext!.read<SpaceModelBloc>().add(
|
||||||
|
DeleteSpaceModel(spaceModelUuid: model.uuid ?? ''),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
);
|
||||||
|
},
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -3,7 +3,7 @@ import 'package:dio/dio.dart';
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||||
import 'package:intl/intl.dart';
|
import 'package:intl/intl.dart';
|
||||||
import 'package:syncrow_web/pages/common/bloc/project_cubit.dart';
|
import 'package:syncrow_web/pages/common/bloc/project_manager.dart';
|
||||||
import 'package:syncrow_web/pages/common/custom_dialog.dart';
|
import 'package:syncrow_web/pages/common/custom_dialog.dart';
|
||||||
import 'package:syncrow_web/pages/common/hour_picker_dialog.dart';
|
import 'package:syncrow_web/pages/common/hour_picker_dialog.dart';
|
||||||
import 'package:syncrow_web/pages/visitor_password/bloc/visitor_password_event.dart';
|
import 'package:syncrow_web/pages/visitor_password/bloc/visitor_password_event.dart';
|
||||||
@ -14,14 +14,15 @@ import 'package:syncrow_web/pages/visitor_password/model/schedule_model.dart';
|
|||||||
import 'package:syncrow_web/services/access_mang_api.dart';
|
import 'package:syncrow_web/services/access_mang_api.dart';
|
||||||
import 'package:syncrow_web/utils/color_manager.dart';
|
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/constants/strings_manager.dart';
|
||||||
import 'package:syncrow_web/utils/constants/temp_const.dart';
|
import 'package:syncrow_web/utils/constants/temp_const.dart';
|
||||||
|
import 'package:syncrow_web/utils/helpers/shared_preferences_helper.dart';
|
||||||
import 'package:syncrow_web/utils/snack_bar.dart';
|
import 'package:syncrow_web/utils/snack_bar.dart';
|
||||||
|
|
||||||
class VisitorPasswordBloc
|
class VisitorPasswordBloc
|
||||||
extends Bloc<VisitorPasswordEvent, VisitorPasswordState> {
|
extends Bloc<VisitorPasswordEvent, VisitorPasswordState> {
|
||||||
final ProjectCubit projectCubit;
|
|
||||||
|
|
||||||
VisitorPasswordBloc(this.projectCubit) : super(VisitorPasswordInitial()) {
|
VisitorPasswordBloc() : super(VisitorPasswordInitial()) {
|
||||||
on<SelectUsageFrequency>(selectUsageFrequency);
|
on<SelectUsageFrequency>(selectUsageFrequency);
|
||||||
on<FetchDevice>(_onFetchDevice);
|
on<FetchDevice>(_onFetchDevice);
|
||||||
on<SelectPasswordType>(selectAccessType);
|
on<SelectPasswordType>(selectAccessType);
|
||||||
@ -191,10 +192,9 @@ class VisitorPasswordBloc
|
|||||||
FetchDevice event, Emitter<VisitorPasswordState> emit) async {
|
FetchDevice event, Emitter<VisitorPasswordState> emit) async {
|
||||||
try {
|
try {
|
||||||
emit(DeviceLoaded());
|
emit(DeviceLoaded());
|
||||||
final projectUuid = projectCubit.state;
|
final projectUuid = await ProjectManager.getProjectUUID() ?? '';
|
||||||
|
|
||||||
data = await AccessMangApi()
|
data = await AccessMangApi().fetchDevices(projectUuid);
|
||||||
.fetchDevices(projectUuid ?? TempConst.projectId);
|
|
||||||
emit(TableLoaded(data));
|
emit(TableLoaded(data));
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
emit(FailedState(e.toString()));
|
emit(FailedState(e.toString()));
|
||||||
|
@ -23,6 +23,7 @@ class DeviceModel {
|
|||||||
dynamic timeZone;
|
dynamic timeZone;
|
||||||
dynamic updateTime;
|
dynamic updateTime;
|
||||||
dynamic uuid;
|
dynamic uuid;
|
||||||
|
dynamic spaceName;
|
||||||
|
|
||||||
DeviceModel({
|
DeviceModel({
|
||||||
required this.productUuid,
|
required this.productUuid,
|
||||||
@ -45,6 +46,7 @@ class DeviceModel {
|
|||||||
required this.timeZone,
|
required this.timeZone,
|
||||||
required this.updateTime,
|
required this.updateTime,
|
||||||
required this.uuid,
|
required this.uuid,
|
||||||
|
required this.spaceName,
|
||||||
});
|
});
|
||||||
|
|
||||||
// Deserialize from JSON
|
// Deserialize from JSON
|
||||||
@ -53,7 +55,8 @@ class DeviceModel {
|
|||||||
DeviceType type = devicesTypesMap[json['productType']] ?? DeviceType.Other;
|
DeviceType type = devicesTypesMap[json['productType']] ?? DeviceType.Other;
|
||||||
if (type == DeviceType.LightBulb) {
|
if (type == DeviceType.LightBulb) {
|
||||||
tempIcon = Assets.lightBulb;
|
tempIcon = Assets.lightBulb;
|
||||||
} else if (type == DeviceType.CeilingSensor || type == DeviceType.WallSensor) {
|
} else if (type == DeviceType.CeilingSensor ||
|
||||||
|
type == DeviceType.WallSensor) {
|
||||||
tempIcon = Assets.sensors;
|
tempIcon = Assets.sensors;
|
||||||
} else if (type == DeviceType.AC) {
|
} else if (type == DeviceType.AC) {
|
||||||
tempIcon = Assets.ac;
|
tempIcon = Assets.ac;
|
||||||
@ -102,6 +105,7 @@ class DeviceModel {
|
|||||||
timeZone: json['timeZone'],
|
timeZone: json['timeZone'],
|
||||||
updateTime: json['updateTime'],
|
updateTime: json['updateTime'],
|
||||||
uuid: json['uuid'],
|
uuid: json['uuid'],
|
||||||
|
spaceName: json['spaceName'],
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -128,6 +132,7 @@ class DeviceModel {
|
|||||||
'timeZone': timeZone,
|
'timeZone': timeZone,
|
||||||
'updateTime': updateTime,
|
'updateTime': updateTime,
|
||||||
'uuid': uuid,
|
'uuid': uuid,
|
||||||
|
'spaceName': spaceName
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2,7 +2,7 @@ import 'package:flutter/material.dart';
|
|||||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||||
import 'package:flutter_svg/flutter_svg.dart';
|
import 'package:flutter_svg/flutter_svg.dart';
|
||||||
import 'package:syncrow_web/pages/common/access_device_table.dart';
|
import 'package:syncrow_web/pages/common/access_device_table.dart';
|
||||||
import 'package:syncrow_web/pages/common/bloc/project_cubit.dart';
|
import 'package:syncrow_web/pages/common/bloc/project_manager.dart';
|
||||||
import 'package:syncrow_web/pages/common/text_field/custom_web_textfield.dart';
|
import 'package:syncrow_web/pages/common/text_field/custom_web_textfield.dart';
|
||||||
import 'package:syncrow_web/pages/common/buttons/default_button.dart';
|
import 'package:syncrow_web/pages/common/buttons/default_button.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';
|
||||||
@ -20,7 +20,8 @@ class AddDeviceDialog extends StatelessWidget {
|
|||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
Size size = MediaQuery.of(context).size;
|
Size size = MediaQuery.of(context).size;
|
||||||
return BlocProvider(
|
return BlocProvider(
|
||||||
create: (context) => VisitorPasswordBloc(context.read<ProjectCubit>())..add(FetchDevice()),
|
create: (context) =>
|
||||||
|
VisitorPasswordBloc()..add(FetchDevice()),
|
||||||
child: BlocBuilder<VisitorPasswordBloc, VisitorPasswordState>(
|
child: BlocBuilder<VisitorPasswordBloc, VisitorPasswordState>(
|
||||||
builder: (BuildContext context, VisitorPasswordState state) {
|
builder: (BuildContext context, VisitorPasswordState state) {
|
||||||
final visitorBloc = BlocProvider.of<VisitorPasswordBloc>(context);
|
final visitorBloc = BlocProvider.of<VisitorPasswordBloc>(context);
|
||||||
@ -36,10 +37,10 @@ class AddDeviceDialog extends StatelessWidget {
|
|||||||
backgroundColor: Colors.white,
|
backgroundColor: Colors.white,
|
||||||
title: Text(
|
title: Text(
|
||||||
'Add Accessible Device',
|
'Add Accessible Device',
|
||||||
style: Theme.of(context)
|
style: Theme.of(context).textTheme.headlineLarge!.copyWith(
|
||||||
.textTheme
|
fontWeight: FontWeight.w400,
|
||||||
.headlineLarge!
|
fontSize: 24,
|
||||||
.copyWith(fontWeight: FontWeight.w400, fontSize: 24, color: Colors.black),
|
color: Colors.black),
|
||||||
),
|
),
|
||||||
content: SizedBox(
|
content: SizedBox(
|
||||||
height: MediaQuery.of(context).size.height / 1.7,
|
height: MediaQuery.of(context).size.height / 1.7,
|
||||||
@ -69,7 +70,10 @@ class AddDeviceDialog extends StatelessWidget {
|
|||||||
),
|
),
|
||||||
Text(
|
Text(
|
||||||
'Only online accessible devices can be added',
|
'Only online accessible devices can be added',
|
||||||
style: Theme.of(context).textTheme.bodySmall!.copyWith(
|
style: Theme.of(context)
|
||||||
|
.textTheme
|
||||||
|
.bodySmall!
|
||||||
|
.copyWith(
|
||||||
fontWeight: FontWeight.w400,
|
fontWeight: FontWeight.w400,
|
||||||
fontSize: 12,
|
fontSize: 12,
|
||||||
color: ColorsManager.grayColor),
|
color: ColorsManager.grayColor),
|
||||||
@ -153,7 +157,8 @@ class AddDeviceDialog extends StatelessWidget {
|
|||||||
visitorBloc.deviceNameController.clear();
|
visitorBloc.deviceNameController.clear();
|
||||||
visitorBloc.deviceIdController.clear();
|
visitorBloc.deviceIdController.clear();
|
||||||
visitorBloc.unitNameController.clear();
|
visitorBloc.unitNameController.clear();
|
||||||
visitorBloc.add(FetchDevice()); // Reset to original list
|
visitorBloc.add(
|
||||||
|
FetchDevice()); // Reset to original list
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
@ -173,7 +178,8 @@ class AddDeviceDialog extends StatelessWidget {
|
|||||||
selectAll: (p0) {
|
selectAll: (p0) {
|
||||||
visitorBloc.selectedDeviceIds.clear();
|
visitorBloc.selectedDeviceIds.clear();
|
||||||
for (var item in state.data) {
|
for (var item in state.data) {
|
||||||
visitorBloc.add(SelectDeviceEvent(item.uuid));
|
visitorBloc
|
||||||
|
.add(SelectDeviceEvent(item.uuid));
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
onRowSelected: (index, isSelected, row) {
|
onRowSelected: (index, isSelected, row) {
|
||||||
@ -194,7 +200,7 @@ class AddDeviceDialog extends StatelessWidget {
|
|||||||
item.name.toString(),
|
item.name.toString(),
|
||||||
item.uuid.toString(),
|
item.uuid.toString(),
|
||||||
item.productType.toString(),
|
item.productType.toString(),
|
||||||
'',
|
item.spaceName.toString(),
|
||||||
item.online.value.toString(),
|
item.online.value.toString(),
|
||||||
];
|
];
|
||||||
}).toList(),
|
}).toList(),
|
||||||
|
@ -2,7 +2,7 @@ import 'package:flutter/cupertino.dart';
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter_bloc/flutter_bloc.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/common/bloc/project_cubit.dart';
|
import 'package:syncrow_web/pages/common/bloc/project_manager.dart';
|
||||||
import 'package:syncrow_web/pages/common/buttons/default_button.dart';
|
import 'package:syncrow_web/pages/common/buttons/default_button.dart';
|
||||||
import 'package:syncrow_web/pages/common/date_time_widget.dart';
|
import 'package:syncrow_web/pages/common/date_time_widget.dart';
|
||||||
import 'package:syncrow_web/pages/common/text_field/custom_web_textfield.dart';
|
import 'package:syncrow_web/pages/common/text_field/custom_web_textfield.dart';
|
||||||
@ -23,7 +23,7 @@ class VisitorPasswordDialog extends StatelessWidget {
|
|||||||
Size size = MediaQuery.of(context).size;
|
Size size = MediaQuery.of(context).size;
|
||||||
var text = Theme.of(context).textTheme.bodySmall!.copyWith(color: Colors.black, fontSize: 13);
|
var text = Theme.of(context).textTheme.bodySmall!.copyWith(color: Colors.black, fontSize: 13);
|
||||||
return BlocProvider(
|
return BlocProvider(
|
||||||
create: (context) => VisitorPasswordBloc(context.read<ProjectCubit>()),
|
create: (context) => VisitorPasswordBloc(),
|
||||||
child: BlocListener<VisitorPasswordBloc, VisitorPasswordState>(
|
child: BlocListener<VisitorPasswordBloc, VisitorPasswordState>(
|
||||||
listener: (context, state) {
|
listener: (context, state) {
|
||||||
final visitorBloc = BlocProvider.of<VisitorPasswordBloc>(context);
|
final visitorBloc = BlocProvider.of<VisitorPasswordBloc>(context);
|
||||||
|
@ -60,4 +60,17 @@ class SpaceModelManagementApi {
|
|||||||
);
|
);
|
||||||
return response;
|
return response;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Future<bool> deleteSpaceModel(String spaceModelUuid, String projectId) async {
|
||||||
|
final response = await HTTPService().delete(
|
||||||
|
path: ApiEndpoints.getSpaceModel
|
||||||
|
.replaceAll('{projectId}', projectId)
|
||||||
|
.replaceAll('{spaceModelUuid}', spaceModelUuid),
|
||||||
|
showServerMessage: true,
|
||||||
|
expectedResponseModel: (json) {
|
||||||
|
return json['success'] ?? false;
|
||||||
|
},
|
||||||
|
);
|
||||||
|
return response;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -14,7 +14,7 @@ class UserPermissionApi {
|
|||||||
Future<List<RolesUserModel>> fetchUsers(String projectId) async {
|
Future<List<RolesUserModel>> fetchUsers(String projectId) async {
|
||||||
try {
|
try {
|
||||||
final response = await _httpService.get(
|
final response = await _httpService.get(
|
||||||
path: ApiEndpoints.getUsers.replaceAll('{projectUuid}', projectId),
|
path: ApiEndpoints.getUsers.replaceAll('{projectId}', projectId),
|
||||||
showServerMessage: true,
|
showServerMessage: true,
|
||||||
expectedResponseModel: (json) {
|
expectedResponseModel: (json) {
|
||||||
debugPrint('fetchUsers Response: $json');
|
debugPrint('fetchUsers Response: $json');
|
||||||
|
@ -71,4 +71,5 @@ abstract class ColorsManager {
|
|||||||
static const Color lightGrayBorderColor = Color(0xB2D5D5D5);
|
static const Color lightGrayBorderColor = Color(0xB2D5D5D5);
|
||||||
//background: #F8F8F8;
|
//background: #F8F8F8;
|
||||||
static const Color vividBlue = Color(0xFF023DFE);
|
static const Color vividBlue = Color(0xFF023DFE);
|
||||||
|
static const Color semiTransparentRed = Color(0x99FF0000);
|
||||||
}
|
}
|
||||||
|
@ -25,7 +25,7 @@ abstract class ApiEndpoints {
|
|||||||
|
|
||||||
////// Devices Management ////////////////
|
////// Devices Management ////////////////
|
||||||
|
|
||||||
static const String getAllDevices = '/projects/{projectId}/device';
|
static const String getAllDevices = '/projects/{projectId}/devices';
|
||||||
static const String getSpaceDevices =
|
static const String getSpaceDevices =
|
||||||
'/projects/{projectId}/communities/{communityUuid}/spaces/{spaceUuid}/devices';
|
'/projects/{projectId}/communities/{communityUuid}/spaces/{spaceUuid}/devices';
|
||||||
static const String getDeviceStatus = '/device/{uuid}/functions/status';
|
static const String getDeviceStatus = '/device/{uuid}/functions/status';
|
||||||
@ -95,8 +95,8 @@ abstract class ApiEndpoints {
|
|||||||
static const String inviteUser = '/invite-user';
|
static const String inviteUser = '/invite-user';
|
||||||
|
|
||||||
static const String checkEmail = '/invite-user/check-email';
|
static const String checkEmail = '/invite-user/check-email';
|
||||||
static const String getUsers = '/projects/{projectUuid}/user';
|
static const String getUsers = '/projects/{projectId}/user';
|
||||||
static const String getUserById = '/projects/{projectUuid}/user/{userUuid}';
|
static const String getUserById = '/projects/{projectId}/user/{userUuid}';
|
||||||
static const String editUser = '/invite-user/{inviteUserUuid}';
|
static const String editUser = '/invite-user/{inviteUserUuid}';
|
||||||
static const String deleteUser = '/invite-user/{inviteUserUuid}';
|
static const String deleteUser = '/invite-user/{inviteUserUuid}';
|
||||||
static const String changeUserStatus = '/invite-user/{invitedUserUuid}/disable';
|
static const String changeUserStatus = '/invite-user/{invitedUserUuid}/disable';
|
||||||
|
@ -258,6 +258,7 @@ class Assets {
|
|||||||
static const String doorSensor = 'assets/icons/door_sensor.svg';
|
static const String doorSensor = 'assets/icons/door_sensor.svg';
|
||||||
|
|
||||||
static const String delete = 'assets/icons/delete.svg';
|
static const String delete = 'assets/icons/delete.svg';
|
||||||
|
static const String deleteSpaceModel = 'assets/icons/delete_space_model.svg';
|
||||||
static const String edit = 'assets/icons/edit.svg';
|
static const String edit = 'assets/icons/edit.svg';
|
||||||
static const String editSpace = 'assets/icons/edit_space.svg';
|
static const String editSpace = 'assets/icons/edit_space.svg';
|
||||||
//assets/icons/routine/tab_to_run.svg
|
//assets/icons/routine/tab_to_run.svg
|
||||||
|
@ -40,4 +40,5 @@ class StringsManager {
|
|||||||
static const String firstLaunch = "firstLaunch";
|
static const String firstLaunch = "firstLaunch";
|
||||||
static const String deleteScene = 'Delete Scene';
|
static const String deleteScene = 'Delete Scene';
|
||||||
static const String deleteAutomation = 'Delete Automation';
|
static const String deleteAutomation = 'Delete Automation';
|
||||||
|
static const String projectKey = 'selected_project_uuid';
|
||||||
}
|
}
|
||||||
|
@ -4,7 +4,7 @@ import 'package:flutter_svg/svg.dart';
|
|||||||
import 'package:go_router/go_router.dart';
|
import 'package:go_router/go_router.dart';
|
||||||
import 'package:syncrow_web/pages/auth/bloc/auth_bloc.dart';
|
import 'package:syncrow_web/pages/auth/bloc/auth_bloc.dart';
|
||||||
import 'package:syncrow_web/pages/auth/model/user_model.dart';
|
import 'package:syncrow_web/pages/auth/model/user_model.dart';
|
||||||
import 'package:syncrow_web/pages/common/bloc/project_cubit.dart';
|
import 'package:syncrow_web/pages/common/bloc/project_manager.dart';
|
||||||
import 'package:syncrow_web/pages/common/buttons/default_button.dart';
|
import 'package:syncrow_web/pages/common/buttons/default_button.dart';
|
||||||
import 'package:syncrow_web/utils/color_manager.dart';
|
import 'package:syncrow_web/utils/color_manager.dart';
|
||||||
import 'package:syncrow_web/utils/constants/assets.dart';
|
import 'package:syncrow_web/utils/constants/assets.dart';
|
||||||
@ -220,10 +220,7 @@ class _UserDropdownMenuState extends State<UserDropdownMenu> {
|
|||||||
),
|
),
|
||||||
GestureDetector(
|
GestureDetector(
|
||||||
onTap: () {
|
onTap: () {
|
||||||
final projectCubit =
|
AuthBloc.logout(context);
|
||||||
BlocProvider.of<ProjectCubit>(context);
|
|
||||||
|
|
||||||
AuthBloc.logout(context, projectCubit);
|
|
||||||
context.go(RoutesConst.auth);
|
context.go(RoutesConst.auth);
|
||||||
},
|
},
|
||||||
child: SizedBox(
|
child: SizedBox(
|
||||||
|
Reference in New Issue
Block a user