mirror of
https://github.com/SyncrowIOT/web.git
synced 2025-07-10 15:17:31 +00:00
Merge branch 'feat/space-creation-update' into bugfix/space-edit
This commit is contained in:
@ -49,12 +49,11 @@ class AssignTagModelBloc
|
||||
emit(AssignTagModelLoaded(
|
||||
tags: allTags,
|
||||
isSaveEnabled: _validateTags(allTags),
|
||||
));
|
||||
errorMessage: ''));
|
||||
});
|
||||
|
||||
on<UpdateTag>((event, emit) {
|
||||
final currentState = state;
|
||||
|
||||
if (currentState is AssignTagModelLoaded &&
|
||||
currentState.tags.isNotEmpty) {
|
||||
final tags = List<TagModel>.from(currentState.tags);
|
||||
@ -122,9 +121,7 @@ class AssignTagModelBloc
|
||||
}
|
||||
|
||||
bool _validateTags(List<TagModel> tags) {
|
||||
if (tags.isEmpty) {
|
||||
return false;
|
||||
}
|
||||
|
||||
final uniqueTags = tags.map((tag) => tag.tag?.trim() ?? '').toSet();
|
||||
final hasEmptyTag = tags.any((tag) => (tag.tag?.trim() ?? '').isEmpty);
|
||||
final isValid = uniqueTags.length == tags.length && !hasEmptyTag;
|
||||
@ -133,7 +130,11 @@ class AssignTagModelBloc
|
||||
|
||||
String? _getValidationError(List<TagModel> tags) {
|
||||
final hasEmptyTag = tags.any((tag) => (tag.tag?.trim() ?? '').isEmpty);
|
||||
if (hasEmptyTag) return 'Tags cannot be empty.';
|
||||
if (hasEmptyTag) {
|
||||
return 'Tags cannot be empty.';
|
||||
}
|
||||
|
||||
// Check for duplicate tags
|
||||
final duplicateTags = tags
|
||||
.map((tag) => tag.tag?.trim() ?? '')
|
||||
.fold<Map<String, int>>({}, (map, tag) {
|
||||
|
@ -5,7 +5,7 @@ abstract class AssignTagModelState extends Equatable {
|
||||
const AssignTagModelState();
|
||||
|
||||
@override
|
||||
List<Object> get props => [];
|
||||
List<Object?> get props => [];
|
||||
}
|
||||
|
||||
class AssignTagModelInitial extends AssignTagModelState {}
|
||||
@ -24,7 +24,7 @@ class AssignTagModelLoaded extends AssignTagModelState {
|
||||
});
|
||||
|
||||
@override
|
||||
List<Object> get props => [tags, isSaveEnabled];
|
||||
List<Object?> get props => [tags, isSaveEnabled, errorMessage];
|
||||
}
|
||||
|
||||
class AssignTagModelError extends AssignTagModelState {
|
||||
@ -33,5 +33,5 @@ class AssignTagModelError extends AssignTagModelState {
|
||||
const AssignTagModelError(this.errorMessage);
|
||||
|
||||
@override
|
||||
List<Object> get props => [errorMessage];
|
||||
List<Object?> get props => [errorMessage];
|
||||
}
|
||||
|
@ -52,6 +52,8 @@ class AssignTagModelsDialog extends StatelessWidget {
|
||||
initialTags: initialTags,
|
||||
addedProducts: addedProducts,
|
||||
)),
|
||||
child: BlocListener<AssignTagModelBloc, AssignTagModelState>(
|
||||
listener: (context, state) {},
|
||||
child: BlocBuilder<AssignTagModelBloc, AssignTagModelState>(
|
||||
builder: (context, state) {
|
||||
if (state is AssignTagModelLoaded) {
|
||||
@ -79,22 +81,26 @@ class AssignTagModelsDialog extends StatelessWidget {
|
||||
columns: [
|
||||
DataColumn(
|
||||
label: Text('#',
|
||||
style:
|
||||
Theme.of(context).textTheme.bodyMedium)),
|
||||
style: Theme.of(context)
|
||||
.textTheme
|
||||
.bodyMedium)),
|
||||
DataColumn(
|
||||
label: Text('Device',
|
||||
style:
|
||||
Theme.of(context).textTheme.bodyMedium)),
|
||||
style: Theme.of(context)
|
||||
.textTheme
|
||||
.bodyMedium)),
|
||||
DataColumn(
|
||||
numeric: false,
|
||||
headingRowAlignment: MainAxisAlignment.start,
|
||||
label: Text('Tag',
|
||||
style:
|
||||
Theme.of(context).textTheme.bodyMedium)),
|
||||
style: Theme.of(context)
|
||||
.textTheme
|
||||
.bodyMedium)),
|
||||
DataColumn(
|
||||
label: Text('Location',
|
||||
style:
|
||||
Theme.of(context).textTheme.bodyMedium)),
|
||||
style: Theme.of(context)
|
||||
.textTheme
|
||||
.bodyMedium)),
|
||||
],
|
||||
rows: state.tags.isEmpty
|
||||
? [
|
||||
@ -105,7 +111,8 @@ class AssignTagModelsDialog extends StatelessWidget {
|
||||
'No Data Available',
|
||||
style: TextStyle(
|
||||
fontSize: 14,
|
||||
color: ColorsManager.lightGrayColor,
|
||||
color:
|
||||
ColorsManager.lightGrayColor,
|
||||
),
|
||||
),
|
||||
),
|
||||
@ -155,7 +162,8 @@ class AssignTagModelsDialog extends StatelessWidget {
|
||||
),
|
||||
onPressed: () {
|
||||
context
|
||||
.read<AssignTagModelBloc>()
|
||||
.read<
|
||||
AssignTagModelBloc>()
|
||||
.add(DeleteTagModel(
|
||||
tagToDelete: tag,
|
||||
tags: state.tags));
|
||||
@ -182,7 +190,8 @@ class AssignTagModelsDialog extends StatelessWidget {
|
||||
onSelected: (value) {
|
||||
controller.text = value;
|
||||
context
|
||||
.read<AssignTagModelBloc>()
|
||||
.read<
|
||||
AssignTagModelBloc>()
|
||||
.add(UpdateTag(
|
||||
index: index,
|
||||
tag: value,
|
||||
@ -201,7 +210,8 @@ class AssignTagModelsDialog extends StatelessWidget {
|
||||
tag.location ?? 'None',
|
||||
onSelected: (value) {
|
||||
context
|
||||
.read<AssignTagModelBloc>()
|
||||
.read<
|
||||
AssignTagModelBloc>()
|
||||
.add(UpdateLocation(
|
||||
index: index,
|
||||
location: value,
|
||||
@ -217,7 +227,8 @@ class AssignTagModelsDialog extends StatelessWidget {
|
||||
if (state.errorMessage != null)
|
||||
Text(
|
||||
state.errorMessage!,
|
||||
style: const TextStyle(color: ColorsManager.warningRed),
|
||||
style: const TextStyle(
|
||||
color: ColorsManager.warningRed),
|
||||
),
|
||||
],
|
||||
),
|
||||
@ -233,23 +244,28 @@ class AssignTagModelsDialog extends StatelessWidget {
|
||||
label: 'Add New Device',
|
||||
onPressed: () async {
|
||||
for (var tag in state.tags) {
|
||||
if (tag.location == null || subspaces == null) {
|
||||
if (tag.location == null ||
|
||||
subspaces == null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
final previousTagSubspace =
|
||||
checkTagExistInSubspace(tag, subspaces ?? []);
|
||||
checkTagExistInSubspace(
|
||||
tag, subspaces ?? []);
|
||||
|
||||
if (tag.location == 'Main Space') {
|
||||
removeTagFromSubspace(tag, previousTagSubspace);
|
||||
removeTagFromSubspace(
|
||||
tag, previousTagSubspace);
|
||||
} else if (tag.location !=
|
||||
previousTagSubspace?.subspaceName) {
|
||||
removeTagFromSubspace(tag, previousTagSubspace);
|
||||
removeTagFromSubspace(
|
||||
tag, previousTagSubspace);
|
||||
moveToNewSubspace(tag, subspaces ?? []);
|
||||
state.tags.removeWhere(
|
||||
(t) => t.internalId == tag.internalId);
|
||||
} else {
|
||||
updateTagInSubspace(tag, previousTagSubspace);
|
||||
updateTagInSubspace(
|
||||
tag, previousTagSubspace);
|
||||
state.tags.removeWhere(
|
||||
(t) => t.internalId == tag.internalId);
|
||||
}
|
||||
@ -308,13 +324,13 @@ class AssignTagModelsDialog extends StatelessWidget {
|
||||
removeTagFromSubspace(
|
||||
tag, previousTagSubspace);
|
||||
moveToNewSubspace(tag, subspaces ?? []);
|
||||
state.tags.removeWhere(
|
||||
(t) => t.internalId == tag.internalId);
|
||||
state.tags.removeWhere((t) =>
|
||||
t.internalId == tag.internalId);
|
||||
} else {
|
||||
updateTagInSubspace(
|
||||
tag, previousTagSubspace);
|
||||
state.tags.removeWhere(
|
||||
(t) => t.internalId == tag.internalId);
|
||||
state.tags.removeWhere((t) =>
|
||||
t.internalId == tag.internalId);
|
||||
}
|
||||
}
|
||||
|
||||
@ -336,7 +352,7 @@ class AssignTagModelsDialog extends StatelessWidget {
|
||||
}
|
||||
},
|
||||
),
|
||||
);
|
||||
));
|
||||
}
|
||||
|
||||
List<String> getAvailableTags(
|
||||
|
@ -3,7 +3,6 @@ import 'package:syncrow_web/pages/spaces_management/space_model/bloc/create_spac
|
||||
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/space_template_model.dart';
|
||||
import 'package:syncrow_web/pages/spaces_management/space_model/models/subspace_template_model.dart';
|
||||
import 'package:syncrow_web/pages/spaces_management/space_model/models/tag_model.dart';
|
||||
import 'package:syncrow_web/services/space_model_mang_api.dart';
|
||||
|
||||
@ -53,6 +52,8 @@ class CreateSpaceModelBloc
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
|
||||
on<LoadSpaceTemplate>((event, emit) {
|
||||
emit(CreateSpaceModelLoading());
|
||||
Future.delayed(const Duration(seconds: 1), () {
|
||||
|
@ -166,6 +166,10 @@ class CreateSpaceModelDialog extends StatelessWidget {
|
||||
modelName:
|
||||
spaceNameController.text.trim(),
|
||||
);
|
||||
if(updatedSpaceTemplate.uuid != null){
|
||||
|
||||
}
|
||||
|
||||
context.read<CreateSpaceModelBloc>().add(
|
||||
CreateSpaceTemplate(
|
||||
spaceTemplate:
|
||||
|
Reference in New Issue
Block a user