mirror of
https://github.com/SyncrowIOT/web.git
synced 2025-07-10 15:17:31 +00:00
use assign table as widget
This commit is contained in:
@ -12,6 +12,7 @@ import 'package:syncrow_web/pages/spaces_management/all_spaces/model/tag.dart';
|
||||
import 'package:syncrow_web/pages/spaces_management/assign_tag/bloc/assign_tag_bloc.dart';
|
||||
import 'package:syncrow_web/pages/spaces_management/assign_tag/bloc/assign_tag_event.dart';
|
||||
import 'package:syncrow_web/pages/spaces_management/assign_tag/bloc/assign_tag_state.dart';
|
||||
import 'package:syncrow_web/pages/spaces_management/assign_tag_models/views/widgets/assign_tags_tables_widget.dart';
|
||||
import 'package:syncrow_web/pages/spaces_management/helper/tag_helper.dart';
|
||||
import 'package:syncrow_web/utils/color_manager.dart';
|
||||
import 'package:uuid/uuid.dart';
|
||||
@ -44,8 +45,10 @@ class AssignTagDialog extends StatelessWidget {
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final List<String> locations =
|
||||
(subspaces ?? []).map((subspace) => subspace.subspaceName).toList()..add('Main Space');
|
||||
final List<String> locations = (subspaces ?? [])
|
||||
.map((subspace) => subspace.subspaceName)
|
||||
.toList()
|
||||
..add('Main Space');
|
||||
|
||||
return BlocProvider(
|
||||
create: (_) => AssignTagBloc(projectTags)
|
||||
@ -67,131 +70,31 @@ class AssignTagDialog extends StatelessWidget {
|
||||
content: SingleChildScrollView(
|
||||
child: Column(
|
||||
children: [
|
||||
ClipRRect(
|
||||
borderRadius: BorderRadius.circular(20),
|
||||
child: DataTable(
|
||||
headingRowColor: WidgetStateProperty.all(ColorsManager.dataHeaderGrey),
|
||||
key: ValueKey(state.tags.length),
|
||||
border: TableBorder.all(
|
||||
color: ColorsManager.dataHeaderGrey,
|
||||
width: 1,
|
||||
borderRadius: BorderRadius.circular(20),
|
||||
),
|
||||
columns: [
|
||||
DataColumn(
|
||||
label: Text('#', style: Theme.of(context).textTheme.bodyMedium)),
|
||||
DataColumn(
|
||||
label: Text('Device', style: Theme.of(context).textTheme.bodyMedium)),
|
||||
DataColumn(
|
||||
numeric: false,
|
||||
label: Text('Tag', style: Theme.of(context).textTheme.bodyMedium)),
|
||||
DataColumn(
|
||||
label:
|
||||
Text('Location', style: Theme.of(context).textTheme.bodyMedium)),
|
||||
],
|
||||
rows: state.tags.isEmpty
|
||||
? [
|
||||
DataRow(cells: [
|
||||
DataCell(
|
||||
Center(
|
||||
child: Text('No Data Available',
|
||||
style: Theme.of(context).textTheme.bodyMedium?.copyWith(
|
||||
color: ColorsManager.lightGrayColor,
|
||||
)),
|
||||
),
|
||||
),
|
||||
const DataCell(SizedBox()),
|
||||
const DataCell(SizedBox()),
|
||||
const DataCell(SizedBox()),
|
||||
])
|
||||
]
|
||||
: List.generate(state.tags.length, (index) {
|
||||
final tag = state.tags[index];
|
||||
final controller = controllers[index];
|
||||
|
||||
return DataRow(
|
||||
cells: [
|
||||
DataCell(Text((index + 1).toString())),
|
||||
DataCell(
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
Expanded(
|
||||
child: Text(
|
||||
tag.product?.name ?? 'Unknown',
|
||||
overflow: TextOverflow.ellipsis,
|
||||
)),
|
||||
const SizedBox(width: 10),
|
||||
Container(
|
||||
width: 20.0,
|
||||
height: 20.0,
|
||||
decoration: BoxDecoration(
|
||||
shape: BoxShape.circle,
|
||||
border: Border.all(
|
||||
color: ColorsManager.lightGrayColor,
|
||||
width: 1.0,
|
||||
),
|
||||
),
|
||||
child: IconButton(
|
||||
icon: const Icon(
|
||||
Icons.close,
|
||||
color: ColorsManager.lightGreyColor,
|
||||
size: 16,
|
||||
),
|
||||
onPressed: () {
|
||||
context.read<AssignTagBloc>().add(
|
||||
DeleteTag(tagToDelete: tag, tags: state.tags));
|
||||
AssignTagsTable(
|
||||
controllers: controllers,
|
||||
locations: locations,
|
||||
tags: state.tags,
|
||||
updatedTags: state.updatedTags,
|
||||
onDeleteDevice: ({required index, required tag}) {
|
||||
context
|
||||
.read<AssignTagBloc>()
|
||||
.add(DeleteTag(tagToDelete: tag, tags: state.tags));
|
||||
|
||||
controllers.removeAt(index);
|
||||
},
|
||||
tooltip: 'Delete Tag',
|
||||
padding: EdgeInsets.zero,
|
||||
constraints: const BoxConstraints(),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
DataCell(
|
||||
Container(
|
||||
alignment:
|
||||
Alignment.centerLeft, // Align cell content to the left
|
||||
child: SizedBox(
|
||||
width: double.infinity,
|
||||
child: TagDialogTextfieldDropdown(
|
||||
key: ValueKey('dropdown_${const Uuid().v4()}_$index'),
|
||||
items: state.updatedTags,
|
||||
product: tag.product?.uuid ?? 'Unknown',
|
||||
initialValue: tag,
|
||||
onSelected: (value) {
|
||||
controller.text = value.tag ?? '';
|
||||
onTagDropDownSelected: ({required index, required tag}) {
|
||||
context.read<AssignTagBloc>().add(UpdateTagEvent(
|
||||
index: index,
|
||||
tag: value,
|
||||
tag: tag,
|
||||
));
|
||||
},
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
DataCell(
|
||||
SizedBox(
|
||||
width: double.infinity,
|
||||
child: DialogDropdown(
|
||||
items: locations,
|
||||
selectedValue: tag.location ?? 'Main Space',
|
||||
onSelected: (value) {
|
||||
onLocationDropDownSelected: (
|
||||
{required index, required location}) {
|
||||
context.read<AssignTagBloc>().add(UpdateLocation(
|
||||
index: index,
|
||||
location: value,
|
||||
location: location,
|
||||
));
|
||||
},
|
||||
)),
|
||||
),
|
||||
],
|
||||
);
|
||||
}),
|
||||
),
|
||||
),
|
||||
if (state.errorMessage != null)
|
||||
Text(state.errorMessage!,
|
||||
@ -213,11 +116,13 @@ class AssignTagDialog extends StatelessWidget {
|
||||
label: 'Add New Device',
|
||||
onPressed: () async {
|
||||
final updatedTags = List<Tag>.from(state.tags);
|
||||
final result = TagHelper.processTags(updatedTags, subspaces);
|
||||
final result =
|
||||
TagHelper.processTags(updatedTags, subspaces);
|
||||
|
||||
final processedTags = result['updatedTags'] as List<Tag>;
|
||||
final processedSubspaces =
|
||||
List<SubspaceModel>.from(result['subspaces'] as List<dynamic>);
|
||||
final processedTags =
|
||||
result['updatedTags'] as List<Tag>;
|
||||
final processedSubspaces = List<SubspaceModel>.from(
|
||||
result['subspaces'] as List<dynamic>);
|
||||
|
||||
Navigator.of(context).pop();
|
||||
|
||||
@ -227,8 +132,8 @@ class AssignTagDialog extends StatelessWidget {
|
||||
products: products,
|
||||
subspaces: processedSubspaces,
|
||||
projectTags: projectTags,
|
||||
initialSelectedProducts:
|
||||
TagHelper.createInitialSelectedProductsForTags(
|
||||
initialSelectedProducts: TagHelper
|
||||
.createInitialSelectedProductsForTags(
|
||||
processedTags, processedSubspaces),
|
||||
spaceName: spaceName,
|
||||
spaceTags: processedTags,
|
||||
@ -252,11 +157,14 @@ class AssignTagDialog extends StatelessWidget {
|
||||
onPressed: state.isSaveEnabled
|
||||
? () async {
|
||||
final updatedTags = List<Tag>.from(state.tags);
|
||||
final result = TagHelper.processTags(updatedTags, subspaces);
|
||||
final result = TagHelper.processTags(
|
||||
updatedTags, subspaces);
|
||||
|
||||
final processedTags = result['updatedTags'] as List<Tag>;
|
||||
final processedTags =
|
||||
result['updatedTags'] as List<Tag>;
|
||||
final processedSubspaces =
|
||||
List<SubspaceModel>.from(result['subspaces'] as List<dynamic>);
|
||||
List<SubspaceModel>.from(
|
||||
result['subspaces'] as List<dynamic>);
|
||||
onSave?.call(processedTags, processedSubspaces);
|
||||
Navigator.of(context).pop();
|
||||
}
|
||||
|
@ -78,6 +78,35 @@ class AssignTagModelsDialog extends StatelessWidget {
|
||||
AssignTagsTable(
|
||||
controllers: controllers,
|
||||
locations: locations,
|
||||
tags: state.tags,
|
||||
updatedTags: state.updatedTags,
|
||||
onDeleteDevice: ({required index, required tag}) {
|
||||
context
|
||||
.read<AssignTagModelBloc>()
|
||||
.add(DeleteTagModel(
|
||||
tagToDelete: tag,
|
||||
tags: state.tags,
|
||||
));
|
||||
controllers.removeAt(index);
|
||||
},
|
||||
onTagDropDownSelected: (
|
||||
{required index, required tag}) {
|
||||
context.read<AssignTagModelBloc>().add(
|
||||
UpdateTag(
|
||||
index: index,
|
||||
tag: tag,
|
||||
),
|
||||
);
|
||||
},
|
||||
onLocationDropDownSelected: (
|
||||
{required index, required location}) {
|
||||
context.read<AssignTagModelBloc>().add(
|
||||
UpdateLocation(
|
||||
index: index,
|
||||
location: location,
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
if (state.errorMessage != null)
|
||||
Text(state.errorMessage!,
|
||||
|
@ -1,35 +1,39 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:syncrow_web/pages/spaces_management/all_spaces/model/tag.dart';
|
||||
import 'package:uuid/uuid.dart';
|
||||
|
||||
import '../../../../../common/dialog_dropdown.dart';
|
||||
import '../../../../../common/tag_dialog_textfield_dropdown.dart';
|
||||
import '../../../../../utils/color_manager.dart';
|
||||
import '../../bloc/assign_tag_model_bloc.dart';
|
||||
import '../../bloc/assign_tag_model_event.dart';
|
||||
import '../../bloc/assign_tag_model_state.dart';
|
||||
|
||||
class AssignTagsTable extends StatelessWidget {
|
||||
const AssignTagsTable({
|
||||
super.key,
|
||||
required this.controllers,
|
||||
required this.locations,
|
||||
required this.tags,
|
||||
required this.updatedTags,
|
||||
required this.onDeleteDevice,
|
||||
required this.onLocationDropDownSelected,
|
||||
required this.onTagDropDownSelected,
|
||||
});
|
||||
|
||||
final void Function({required Tag tag, required int index})
|
||||
onTagDropDownSelected;
|
||||
final void Function({required String location, required int index})
|
||||
onLocationDropDownSelected;
|
||||
final void Function({required Tag tag, required int index}) onDeleteDevice;
|
||||
final List<Tag> tags;
|
||||
final List<Tag> updatedTags;
|
||||
final List<TextEditingController> controllers;
|
||||
final List<String> locations;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return BlocBuilder<AssignTagModelBloc, AssignTagModelState>(
|
||||
builder: (context, state) {
|
||||
if (state is AssignTagModelLoaded) {
|
||||
return ClipRRect(
|
||||
borderRadius: BorderRadius.circular(20),
|
||||
child: DataTable(
|
||||
headingRowColor:
|
||||
WidgetStateProperty.all(ColorsManager.dataHeaderGrey),
|
||||
key: ValueKey(state.tags.length),
|
||||
headingRowColor: WidgetStateProperty.all(ColorsManager.dataHeaderGrey),
|
||||
key: ValueKey(tags.length),
|
||||
border: TableBorder.all(
|
||||
color: ColorsManager.dataHeaderGrey,
|
||||
width: 1,
|
||||
@ -37,29 +41,26 @@ class AssignTagsTable extends StatelessWidget {
|
||||
),
|
||||
columns: [
|
||||
DataColumn(
|
||||
label: Text('#',
|
||||
style: Theme.of(context).textTheme.bodyMedium)),
|
||||
label: Text('#', style: Theme.of(context).textTheme.bodyMedium)),
|
||||
DataColumn(
|
||||
label: Text('Device',
|
||||
style: Theme.of(context).textTheme.bodyMedium)),
|
||||
DataColumn(
|
||||
numeric: false,
|
||||
label: Text('Tag',
|
||||
style: Theme.of(context).textTheme.bodyMedium)),
|
||||
label:
|
||||
Text('Tag', style: Theme.of(context).textTheme.bodyMedium)),
|
||||
DataColumn(
|
||||
label: Text('Location',
|
||||
style: Theme.of(context).textTheme.bodyMedium)),
|
||||
],
|
||||
rows: state.tags.isEmpty
|
||||
rows: tags.isEmpty
|
||||
? [
|
||||
DataRow(cells: [
|
||||
DataCell(
|
||||
Center(
|
||||
child: Text('No Devices Available',
|
||||
style: Theme.of(context)
|
||||
.textTheme
|
||||
.bodyMedium
|
||||
?.copyWith(
|
||||
style:
|
||||
Theme.of(context).textTheme.bodyMedium?.copyWith(
|
||||
color: ColorsManager.lightGrayColor,
|
||||
)),
|
||||
),
|
||||
@ -69,8 +70,8 @@ class AssignTagsTable extends StatelessWidget {
|
||||
const DataCell(SizedBox()),
|
||||
])
|
||||
]
|
||||
: List.generate(state.tags.length, (index) {
|
||||
final tag = state.tags[index];
|
||||
: List.generate(tags.length, (index) {
|
||||
final tag = tags[index];
|
||||
final controller = controllers[index];
|
||||
|
||||
return DataRow(
|
||||
@ -103,11 +104,7 @@ class AssignTagsTable extends StatelessWidget {
|
||||
size: 16,
|
||||
),
|
||||
onPressed: () {
|
||||
context.read<AssignTagModelBloc>().add(
|
||||
DeleteTagModel(
|
||||
tagToDelete: tag,
|
||||
tags: state.tags));
|
||||
controllers.removeAt(index);
|
||||
onDeleteDevice(tag: tag, index: index);
|
||||
},
|
||||
tooltip: 'Delete Tag',
|
||||
padding: EdgeInsets.zero,
|
||||
@ -127,16 +124,11 @@ class AssignTagsTable extends StatelessWidget {
|
||||
key: ValueKey(
|
||||
'dropdown_${const Uuid().v4()}_$index'),
|
||||
product: tag.product?.uuid ?? 'Unknown',
|
||||
items: state.updatedTags,
|
||||
items: updatedTags,
|
||||
initialValue: tag,
|
||||
onSelected: (value) {
|
||||
controller.text = value.tag ?? '';
|
||||
context
|
||||
.read<AssignTagModelBloc>()
|
||||
.add(UpdateTag(
|
||||
index: index,
|
||||
tag: value,
|
||||
));
|
||||
onTagDropDownSelected(tag: value, index: index);
|
||||
},
|
||||
),
|
||||
),
|
||||
@ -149,12 +141,8 @@ class AssignTagsTable extends StatelessWidget {
|
||||
items: locations,
|
||||
selectedValue: tag.location ?? 'Main Space',
|
||||
onSelected: (value) {
|
||||
context
|
||||
.read<AssignTagModelBloc>()
|
||||
.add(UpdateLocation(
|
||||
index: index,
|
||||
location: value,
|
||||
));
|
||||
onLocationDropDownSelected(
|
||||
location: value, index: index);
|
||||
},
|
||||
)),
|
||||
),
|
||||
@ -163,10 +151,5 @@ class AssignTagsTable extends StatelessWidget {
|
||||
}),
|
||||
),
|
||||
);
|
||||
} else {
|
||||
return const SizedBox();
|
||||
}
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user