feat(dialog): 상세 팝업 SuperportDetailDialog 통합
- SuperportDetailDialog 위젯과 showSuperportDetailDialog 헬퍼를 추가하고 metadata/섹션 패턴을 표준화 - 결재/재고/마스터 각 상세 다이얼로그를 dialogs 디렉터리에 신설하고 기존 페이지를 신규 팝업으로 전환 - SuperportTable 행 선택과 우편번호 검색 다이얼로그 onRowTap 보정을 통해 헤더 오프셋 버그를 제거 - 상세 다이얼로그 및 트랜잭션/상세 뷰 전용 위젯 테스트와 tester_extensions 유틸을 추가하여 회귀를 방지 - detail_dialog_unification_plan.md로 작업 배경과 필드 통합 계획을 문서화
This commit is contained in:
@@ -0,0 +1,708 @@
|
||||
import 'dart:async';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:intl/intl.dart' as intl;
|
||||
import 'package:shadcn_ui/shadcn_ui.dart';
|
||||
|
||||
import '../../../../../widgets/components/superport_detail_dialog.dart';
|
||||
import '../../../group/domain/entities/group.dart';
|
||||
import '../../../menu/domain/entities/menu.dart';
|
||||
import '../../domain/entities/group_permission.dart';
|
||||
|
||||
/// 그룹 권한 상세 다이얼로그 결과 유형이다.
|
||||
enum GroupPermissionDetailDialogAction { created, updated, deleted, restored }
|
||||
|
||||
/// 그룹 권한 상세 다이얼로그에서 반환되는 결과이다.
|
||||
class GroupPermissionDetailDialogResult {
|
||||
const GroupPermissionDetailDialogResult({
|
||||
required this.action,
|
||||
required this.message,
|
||||
});
|
||||
|
||||
final GroupPermissionDetailDialogAction action;
|
||||
final String message;
|
||||
}
|
||||
|
||||
typedef GroupPermissionCreateCallback =
|
||||
Future<GroupPermission?> Function(GroupPermissionInput input);
|
||||
typedef GroupPermissionUpdateCallback =
|
||||
Future<GroupPermission?> Function(int id, GroupPermissionInput input);
|
||||
typedef GroupPermissionDeleteCallback = Future<bool> Function(int id);
|
||||
typedef GroupPermissionRestoreCallback =
|
||||
Future<GroupPermission?> Function(int id);
|
||||
|
||||
/// 그룹 권한 상세 다이얼로그를 표시한다.
|
||||
Future<GroupPermissionDetailDialogResult?> showGroupPermissionDetailDialog({
|
||||
required BuildContext context,
|
||||
required intl.DateFormat dateFormat,
|
||||
GroupPermission? permission,
|
||||
required List<Group> groups,
|
||||
required bool isLoadingGroups,
|
||||
required List<MenuItem> menus,
|
||||
required bool isLoadingMenus,
|
||||
required GroupPermissionCreateCallback onCreate,
|
||||
required GroupPermissionUpdateCallback onUpdate,
|
||||
required GroupPermissionDeleteCallback onDelete,
|
||||
required GroupPermissionRestoreCallback onRestore,
|
||||
}) {
|
||||
final permissionValue = permission;
|
||||
final isEdit = permissionValue != null;
|
||||
final title = isEdit ? '그룹 권한 상세' : '그룹 권한 등록';
|
||||
final description = isEdit
|
||||
? '그룹과 메뉴에 부여된 CRUD 권한을 확인하고 변경합니다.'
|
||||
: '그룹-메뉴 권한을 신규로 연결하세요.';
|
||||
|
||||
List<Widget> buildSummaryBadges(GroupPermission? value) {
|
||||
if (value == null) {
|
||||
return const [];
|
||||
}
|
||||
Widget badge(String label, bool enabled, {bool destructive = false}) {
|
||||
if (enabled) {
|
||||
if (destructive) {
|
||||
return ShadBadge.destructive(child: Text(label));
|
||||
}
|
||||
return ShadBadge(child: Text(label));
|
||||
}
|
||||
return ShadBadge.outline(child: Text(label));
|
||||
}
|
||||
|
||||
return [
|
||||
badge('사용중', value.isActive),
|
||||
if (value.isDeleted) const ShadBadge.destructive(child: Text('삭제됨')),
|
||||
badge('생성', value.canCreate),
|
||||
badge('조회', value.canRead),
|
||||
badge('수정', value.canUpdate),
|
||||
badge('삭제', value.canDelete, destructive: true),
|
||||
];
|
||||
}
|
||||
|
||||
final metadata = permissionValue == null
|
||||
? const <SuperportDetailMetadata>[]
|
||||
: [
|
||||
SuperportDetailMetadata.text(
|
||||
label: 'ID',
|
||||
value: permissionValue.id?.toString() ?? '-',
|
||||
),
|
||||
SuperportDetailMetadata.text(
|
||||
label: '그룹',
|
||||
value: permissionValue.group.groupName,
|
||||
),
|
||||
SuperportDetailMetadata.text(
|
||||
label: '메뉴',
|
||||
value: permissionValue.menu.menuName,
|
||||
),
|
||||
SuperportDetailMetadata.text(
|
||||
label: '메뉴 경로',
|
||||
value: permissionValue.menu.path?.isEmpty ?? true
|
||||
? '-'
|
||||
: permissionValue.menu.path!,
|
||||
),
|
||||
SuperportDetailMetadata.text(
|
||||
label: '생성 권한',
|
||||
value: permissionValue.canCreate ? '허용' : '차단',
|
||||
),
|
||||
SuperportDetailMetadata.text(
|
||||
label: '조회 권한',
|
||||
value: permissionValue.canRead ? '허용' : '차단',
|
||||
),
|
||||
SuperportDetailMetadata.text(
|
||||
label: '수정 권한',
|
||||
value: permissionValue.canUpdate ? '허용' : '차단',
|
||||
),
|
||||
SuperportDetailMetadata.text(
|
||||
label: '삭제 권한',
|
||||
value: permissionValue.canDelete ? '허용' : '차단',
|
||||
),
|
||||
SuperportDetailMetadata.text(
|
||||
label: '사용 여부',
|
||||
value: permissionValue.isActive ? '사용중' : '미사용',
|
||||
),
|
||||
SuperportDetailMetadata.text(
|
||||
label: '삭제 여부',
|
||||
value: permissionValue.isDeleted ? '삭제됨' : '정상',
|
||||
),
|
||||
SuperportDetailMetadata.text(
|
||||
label: '비고',
|
||||
value: permissionValue.note?.isEmpty ?? true
|
||||
? '-'
|
||||
: permissionValue.note!,
|
||||
),
|
||||
SuperportDetailMetadata.text(
|
||||
label: '생성일시',
|
||||
value: permissionValue.createdAt == null
|
||||
? '-'
|
||||
: dateFormat.format(permissionValue.createdAt!.toLocal()),
|
||||
),
|
||||
SuperportDetailMetadata.text(
|
||||
label: '변경일시',
|
||||
value: permissionValue.updatedAt == null
|
||||
? '-'
|
||||
: dateFormat.format(permissionValue.updatedAt!.toLocal()),
|
||||
),
|
||||
];
|
||||
|
||||
return showSuperportDetailDialog<GroupPermissionDetailDialogResult>(
|
||||
context: context,
|
||||
title: title,
|
||||
description: description,
|
||||
summary: permissionValue == null
|
||||
? null
|
||||
: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
permissionValue.group.groupName,
|
||||
style: ShadTheme.of(context).textTheme.h4,
|
||||
),
|
||||
const SizedBox(height: 4),
|
||||
Text(
|
||||
'→ ${permissionValue.menu.menuName}',
|
||||
style: ShadTheme.of(context).textTheme.muted,
|
||||
),
|
||||
],
|
||||
),
|
||||
summaryBadges: buildSummaryBadges(permissionValue),
|
||||
metadata: metadata,
|
||||
sections: [
|
||||
_GroupPermissionEditSection(
|
||||
id: isEdit
|
||||
? _GroupPermissionDetailSections.edit
|
||||
: _GroupPermissionDetailSections.create,
|
||||
label: isEdit ? '수정' : '등록',
|
||||
permission: permissionValue,
|
||||
groups: groups,
|
||||
menus: menus,
|
||||
isLoadingGroups: isLoadingGroups,
|
||||
isLoadingMenus: isLoadingMenus,
|
||||
onSubmit: (input) async {
|
||||
if (permissionValue == null) {
|
||||
final created = await onCreate(input);
|
||||
if (created == null) {
|
||||
return null;
|
||||
}
|
||||
return const GroupPermissionDetailDialogResult(
|
||||
action: GroupPermissionDetailDialogAction.created,
|
||||
message: '권한을 등록했습니다.',
|
||||
);
|
||||
}
|
||||
final permissionId = permissionValue.id;
|
||||
if (permissionId == null) {
|
||||
return null;
|
||||
}
|
||||
final updated = await onUpdate(permissionId, input);
|
||||
if (updated == null) {
|
||||
return null;
|
||||
}
|
||||
return const GroupPermissionDetailDialogResult(
|
||||
action: GroupPermissionDetailDialogAction.updated,
|
||||
message: '권한을 수정했습니다.',
|
||||
);
|
||||
},
|
||||
),
|
||||
if (permissionValue != null)
|
||||
SuperportDetailDialogSection(
|
||||
id: permissionValue.isDeleted
|
||||
? _GroupPermissionDetailSections.restore
|
||||
: _GroupPermissionDetailSections.delete,
|
||||
label: permissionValue.isDeleted ? '복구' : '삭제',
|
||||
icon: permissionValue.isDeleted
|
||||
? LucideIcons.history
|
||||
: LucideIcons.trash2,
|
||||
builder: (_) => _GroupPermissionDangerSection(
|
||||
permission: permissionValue,
|
||||
onDelete: () async {
|
||||
final permissionId = permissionValue.id;
|
||||
if (permissionId == null) {
|
||||
return null;
|
||||
}
|
||||
final success = await onDelete(permissionId);
|
||||
if (!success) {
|
||||
return null;
|
||||
}
|
||||
return const GroupPermissionDetailDialogResult(
|
||||
action: GroupPermissionDetailDialogAction.deleted,
|
||||
message: '권한을 삭제했습니다.',
|
||||
);
|
||||
},
|
||||
onRestore: () async {
|
||||
final permissionId = permissionValue.id;
|
||||
if (permissionId == null) {
|
||||
return null;
|
||||
}
|
||||
final restored = await onRestore(permissionId);
|
||||
if (restored == null) {
|
||||
return null;
|
||||
}
|
||||
return const GroupPermissionDetailDialogResult(
|
||||
action: GroupPermissionDetailDialogAction.restored,
|
||||
message: '권한을 복구했습니다.',
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
],
|
||||
emptyPlaceholder: const Text('표시할 권한 정보가 없습니다.'),
|
||||
initialSectionId: permissionValue == null
|
||||
? _GroupPermissionDetailSections.create
|
||||
: _GroupPermissionDetailSections.edit,
|
||||
);
|
||||
}
|
||||
|
||||
/// 그룹 권한 상세 섹션 식별자.
|
||||
class _GroupPermissionDetailSections {
|
||||
static const edit = 'edit';
|
||||
static const delete = 'delete';
|
||||
static const restore = 'restore';
|
||||
static const create = 'create';
|
||||
}
|
||||
|
||||
/// 그룹 권한 입력 섹션이다.
|
||||
class _GroupPermissionEditSection extends SuperportDetailDialogSection {
|
||||
_GroupPermissionEditSection({
|
||||
required super.id,
|
||||
required super.label,
|
||||
required GroupPermission? permission,
|
||||
required List<Group> groups,
|
||||
required List<MenuItem> menus,
|
||||
required bool isLoadingGroups,
|
||||
required bool isLoadingMenus,
|
||||
required Future<GroupPermissionDetailDialogResult?> Function(
|
||||
GroupPermissionInput input,
|
||||
)
|
||||
onSubmit,
|
||||
}) : super(
|
||||
icon: LucideIcons.pencil,
|
||||
builder: (context) => _GroupPermissionForm(
|
||||
permission: permission,
|
||||
groups: groups,
|
||||
menus: menus,
|
||||
isLoadingGroups: isLoadingGroups,
|
||||
isLoadingMenus: isLoadingMenus,
|
||||
onSubmit: onSubmit,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/// 권한 삭제/복구용 위험 섹션이다.
|
||||
class _GroupPermissionDangerSection extends StatelessWidget {
|
||||
const _GroupPermissionDangerSection({
|
||||
required this.permission,
|
||||
required this.onDelete,
|
||||
required this.onRestore,
|
||||
});
|
||||
|
||||
final GroupPermission permission;
|
||||
final Future<GroupPermissionDetailDialogResult?> Function() onDelete;
|
||||
final Future<GroupPermissionDetailDialogResult?> Function() onRestore;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final theme = ShadTheme.of(context);
|
||||
final description = permission.isDeleted
|
||||
? '복구하면 권한이 다시 활성화되고 권한 동기화가 진행됩니다.'
|
||||
: '삭제하면 권한이 비활성화되어 접근이 차단됩니다.';
|
||||
|
||||
return Padding(
|
||||
padding: const EdgeInsets.only(top: 8),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(description, style: theme.textTheme.small),
|
||||
const SizedBox(height: 16),
|
||||
if (permission.isDeleted)
|
||||
ShadButton(
|
||||
onPressed: () async {
|
||||
final navigator = Navigator.of(context, rootNavigator: true);
|
||||
final result = await onRestore();
|
||||
if (result != null && navigator.mounted) {
|
||||
navigator.pop(result);
|
||||
}
|
||||
},
|
||||
child: const Text('복구'),
|
||||
)
|
||||
else
|
||||
ShadButton.destructive(
|
||||
onPressed: () async {
|
||||
final navigator = Navigator.of(context, rootNavigator: true);
|
||||
final result = await onDelete();
|
||||
if (result != null && navigator.mounted) {
|
||||
navigator.pop(result);
|
||||
}
|
||||
},
|
||||
child: const Text('삭제'),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/// 그룹 권한 입력 폼을 담당한다.
|
||||
class _GroupPermissionForm extends StatefulWidget {
|
||||
const _GroupPermissionForm({
|
||||
required this.permission,
|
||||
required this.groups,
|
||||
required this.menus,
|
||||
required this.isLoadingGroups,
|
||||
required this.isLoadingMenus,
|
||||
required this.onSubmit,
|
||||
});
|
||||
|
||||
final GroupPermission? permission;
|
||||
final List<Group> groups;
|
||||
final List<MenuItem> menus;
|
||||
final bool isLoadingGroups;
|
||||
final bool isLoadingMenus;
|
||||
final Future<GroupPermissionDetailDialogResult?> Function(
|
||||
GroupPermissionInput input,
|
||||
)
|
||||
onSubmit;
|
||||
|
||||
bool get _isEdit => permission != null;
|
||||
|
||||
@override
|
||||
State<_GroupPermissionForm> createState() => _GroupPermissionFormState();
|
||||
}
|
||||
|
||||
class _GroupPermissionFormState extends State<_GroupPermissionForm> {
|
||||
int? _selectedGroup;
|
||||
int? _selectedMenu;
|
||||
late bool _canCreate;
|
||||
late bool _canRead;
|
||||
late bool _canUpdate;
|
||||
late bool _canDelete;
|
||||
late bool _isActive;
|
||||
late final TextEditingController _noteController;
|
||||
String? _groupError;
|
||||
String? _menuError;
|
||||
String? _submitError;
|
||||
bool _isSubmitting = false;
|
||||
|
||||
bool get _isEdit => widget._isEdit;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
final permission = widget.permission;
|
||||
_selectedGroup = permission?.group.id;
|
||||
_selectedMenu = permission?.menu.id;
|
||||
_canCreate = permission?.canCreate ?? false;
|
||||
_canRead = permission?.canRead ?? true;
|
||||
_canUpdate = permission?.canUpdate ?? false;
|
||||
_canDelete = permission?.canDelete ?? false;
|
||||
_isActive = permission?.isActive ?? true;
|
||||
_noteController = TextEditingController(text: permission?.note ?? '');
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_noteController.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final theme = ShadTheme.of(context);
|
||||
|
||||
return Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
_GroupPermissionFormField(
|
||||
label: '그룹',
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
ShadSelect<int>(
|
||||
initialValue: _selectedGroup,
|
||||
placeholder: Text(
|
||||
widget.isLoadingGroups ? '그룹 로딩중...' : '그룹 선택',
|
||||
),
|
||||
selectedOptionBuilder: (_, value) {
|
||||
final label = _resolveGroupLabel(value);
|
||||
return Text(label);
|
||||
},
|
||||
onChanged: _isSubmitting || widget.isLoadingGroups
|
||||
? null
|
||||
: (value) {
|
||||
setState(() {
|
||||
_selectedGroup = value;
|
||||
_groupError = null;
|
||||
});
|
||||
},
|
||||
options: widget.groups
|
||||
.map(
|
||||
(group) => ShadOption<int>(
|
||||
value: group.id!,
|
||||
child: Text(group.groupName),
|
||||
),
|
||||
)
|
||||
.toList(),
|
||||
),
|
||||
if (_groupError != null)
|
||||
Padding(
|
||||
padding: const EdgeInsets.only(top: 6),
|
||||
child: Text(
|
||||
_groupError!,
|
||||
style: theme.textTheme.small.copyWith(
|
||||
color: theme.colorScheme.destructive,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
_GroupPermissionFormField(
|
||||
label: '메뉴',
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
ShadSelect<int>(
|
||||
initialValue: _selectedMenu,
|
||||
placeholder: Text(
|
||||
widget.isLoadingMenus ? '메뉴 로딩중...' : '메뉴 선택',
|
||||
),
|
||||
selectedOptionBuilder: (_, value) {
|
||||
final label = _resolveMenuLabel(value);
|
||||
return Text(label);
|
||||
},
|
||||
onChanged: _isSubmitting || widget.isLoadingMenus
|
||||
? null
|
||||
: (value) {
|
||||
setState(() {
|
||||
_selectedMenu = value;
|
||||
_menuError = null;
|
||||
});
|
||||
},
|
||||
options: widget.menus
|
||||
.map(
|
||||
(menu) => ShadOption<int>(
|
||||
value: menu.id!,
|
||||
child: Text(menu.menuName),
|
||||
),
|
||||
)
|
||||
.toList(),
|
||||
),
|
||||
if (_menuError != null)
|
||||
Padding(
|
||||
padding: const EdgeInsets.only(top: 6),
|
||||
child: Text(
|
||||
_menuError!,
|
||||
style: theme.textTheme.small.copyWith(
|
||||
color: theme.colorScheme.destructive,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
_GroupPermissionToggleRow(
|
||||
label: '생성 권한',
|
||||
value: _canCreate,
|
||||
onChanged: _isSubmitting
|
||||
? null
|
||||
: (value) {
|
||||
setState(() {
|
||||
_canCreate = value;
|
||||
});
|
||||
},
|
||||
),
|
||||
const SizedBox(height: 12),
|
||||
_GroupPermissionToggleRow(
|
||||
label: '조회 권한',
|
||||
value: _canRead,
|
||||
onChanged: _isSubmitting
|
||||
? null
|
||||
: (value) {
|
||||
setState(() {
|
||||
_canRead = value;
|
||||
});
|
||||
},
|
||||
),
|
||||
const SizedBox(height: 12),
|
||||
_GroupPermissionToggleRow(
|
||||
label: '수정 권한',
|
||||
value: _canUpdate,
|
||||
onChanged: _isSubmitting
|
||||
? null
|
||||
: (value) {
|
||||
setState(() {
|
||||
_canUpdate = value;
|
||||
});
|
||||
},
|
||||
),
|
||||
const SizedBox(height: 12),
|
||||
_GroupPermissionToggleRow(
|
||||
label: '삭제 권한',
|
||||
value: _canDelete,
|
||||
onChanged: _isSubmitting
|
||||
? null
|
||||
: (value) {
|
||||
setState(() {
|
||||
_canDelete = value;
|
||||
});
|
||||
},
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
_GroupPermissionFormField(
|
||||
label: '사용 여부',
|
||||
child: Row(
|
||||
children: [
|
||||
ShadSwitch(
|
||||
value: _isActive,
|
||||
onChanged: _isSubmitting
|
||||
? null
|
||||
: (value) {
|
||||
setState(() {
|
||||
_isActive = value;
|
||||
});
|
||||
},
|
||||
),
|
||||
const SizedBox(width: 8),
|
||||
Text(_isActive ? '사용' : '미사용'),
|
||||
],
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
_GroupPermissionFormField(
|
||||
label: '비고',
|
||||
child: ShadTextarea(
|
||||
controller: _noteController,
|
||||
minHeight: 96,
|
||||
maxHeight: 220,
|
||||
),
|
||||
),
|
||||
if (_submitError != null) ...[
|
||||
const SizedBox(height: 16),
|
||||
Text(
|
||||
_submitError!,
|
||||
style: theme.textTheme.small.copyWith(
|
||||
color: theme.colorScheme.destructive,
|
||||
),
|
||||
),
|
||||
],
|
||||
const SizedBox(height: 20),
|
||||
Align(
|
||||
alignment: Alignment.centerRight,
|
||||
child: ShadButton(
|
||||
onPressed: _isSubmitting ? null : _handleSubmit,
|
||||
child: Text(_isEdit ? '저장' : '등록'),
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
Future<void> _handleSubmit() async {
|
||||
setState(() {
|
||||
_groupError = _selectedGroup == null ? '그룹을 선택하세요.' : null;
|
||||
_menuError = _selectedMenu == null ? '메뉴를 선택하세요.' : null;
|
||||
_submitError = null;
|
||||
});
|
||||
|
||||
if (_groupError != null || _menuError != null) {
|
||||
return;
|
||||
}
|
||||
|
||||
setState(() {
|
||||
_isSubmitting = true;
|
||||
});
|
||||
|
||||
final note = _noteController.text.trim();
|
||||
final input = GroupPermissionInput(
|
||||
groupId: _selectedGroup!,
|
||||
menuId: _selectedMenu!,
|
||||
canCreate: _canCreate,
|
||||
canRead: _canRead,
|
||||
canUpdate: _canUpdate,
|
||||
canDelete: _canDelete,
|
||||
isActive: _isActive,
|
||||
note: note.isEmpty ? null : note,
|
||||
);
|
||||
final navigator = Navigator.of(context, rootNavigator: true);
|
||||
final result = await widget.onSubmit(input);
|
||||
|
||||
if (!mounted) {
|
||||
return;
|
||||
}
|
||||
|
||||
setState(() {
|
||||
_isSubmitting = false;
|
||||
_submitError = result == null ? '요청 처리에 실패했습니다.' : null;
|
||||
});
|
||||
|
||||
if (result != null && navigator.mounted) {
|
||||
navigator.pop(result);
|
||||
}
|
||||
}
|
||||
|
||||
String _resolveGroupLabel(int? id) {
|
||||
if (id == null) {
|
||||
return widget.isLoadingGroups ? '그룹 로딩중...' : '그룹 선택';
|
||||
}
|
||||
final group = widget.groups.firstWhere(
|
||||
(item) => item.id == id,
|
||||
orElse: () => Group(id: id, groupName: '알 수 없음'),
|
||||
);
|
||||
return group.groupName;
|
||||
}
|
||||
|
||||
String _resolveMenuLabel(int? id) {
|
||||
if (id == null) {
|
||||
return widget.isLoadingMenus ? '메뉴 로딩중...' : '메뉴 선택';
|
||||
}
|
||||
final menu = widget.menus.firstWhere(
|
||||
(item) => item.id == id,
|
||||
orElse: () => MenuItem(id: id, menuCode: '', menuName: '알 수 없음'),
|
||||
);
|
||||
return menu.menuName;
|
||||
}
|
||||
}
|
||||
|
||||
/// 폼 필드 레이아웃을 제공하는 위젯이다.
|
||||
class _GroupPermissionFormField extends StatelessWidget {
|
||||
const _GroupPermissionFormField({required this.label, required this.child});
|
||||
|
||||
final String label;
|
||||
final Widget child;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final theme = ShadTheme.of(context);
|
||||
return Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(label, style: theme.textTheme.small),
|
||||
const SizedBox(height: 6),
|
||||
child,
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/// 토글 행을 그리는 위젯이다.
|
||||
class _GroupPermissionToggleRow extends StatelessWidget {
|
||||
const _GroupPermissionToggleRow({
|
||||
required this.label,
|
||||
required this.value,
|
||||
required this.onChanged,
|
||||
});
|
||||
|
||||
final String label;
|
||||
final bool value;
|
||||
final ValueChanged<bool>? onChanged;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
Text(label),
|
||||
ShadSwitch(value: value, onChanged: onChanged),
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/// 개요 섹션에서 사용하는 키-값 구조체이다.
|
||||
@@ -6,8 +6,8 @@ import 'package:shadcn_ui/shadcn_ui.dart';
|
||||
import 'package:superport_v2/core/constants/app_sections.dart';
|
||||
import 'package:superport_v2/widgets/app_layout.dart';
|
||||
import 'package:superport_v2/widgets/components/filter_bar.dart';
|
||||
import 'package:superport_v2/widgets/components/superport_dialog.dart';
|
||||
import 'package:superport_v2/widgets/components/superport_pagination_controls.dart';
|
||||
import 'package:superport_v2/widgets/components/superport_table.dart';
|
||||
|
||||
import '../../../../../core/config/environment.dart';
|
||||
import '../../../../../core/permissions/permission_manager.dart';
|
||||
@@ -19,6 +19,7 @@ import '../../../menu/domain/repositories/menu_repository.dart';
|
||||
import '../../domain/entities/group_permission.dart';
|
||||
import '../../domain/repositories/group_permission_repository.dart';
|
||||
import '../controllers/group_permission_controller.dart';
|
||||
import '../dialogs/group_permission_detail_dialog.dart';
|
||||
|
||||
String _menuDisplayLabelFromPath(String? path, String fallback) {
|
||||
if (path != null && path.isNotEmpty) {
|
||||
@@ -216,7 +217,7 @@ class _GroupPermissionEnabledPageState
|
||||
leading: const Icon(LucideIcons.plus, size: 16),
|
||||
onPressed: _controller.isSubmitting
|
||||
? null
|
||||
: () => _openPermissionForm(context),
|
||||
: _openPermissionCreateDialog,
|
||||
child: const Text('신규 등록'),
|
||||
),
|
||||
],
|
||||
@@ -399,16 +400,9 @@ class _GroupPermissionEnabledPageState
|
||||
: _PermissionTable(
|
||||
permissions: permissions,
|
||||
dateFormat: _dateFormat,
|
||||
onEdit: _controller.isSubmitting
|
||||
onRowTap: _controller.isSubmitting
|
||||
? null
|
||||
: (permission) => _openPermissionForm(
|
||||
context,
|
||||
permission: permission,
|
||||
),
|
||||
onDelete: _controller.isSubmitting ? null : _confirmDelete,
|
||||
onRestore: _controller.isSubmitting
|
||||
? null
|
||||
: _restorePermission,
|
||||
: _openPermissionDetailDialog,
|
||||
),
|
||||
),
|
||||
);
|
||||
@@ -435,368 +429,45 @@ class _GroupPermissionEnabledPageState
|
||||
return _menuDisplayLabelFromPath(menu.path, menu.menuName);
|
||||
}
|
||||
|
||||
Future<void> _openPermissionForm(
|
||||
BuildContext context, {
|
||||
GroupPermission? permission,
|
||||
}) async {
|
||||
final existingPermission = permission;
|
||||
final isEdit = existingPermission != null;
|
||||
final permissionId = existingPermission?.id;
|
||||
if (isEdit && permissionId == null) {
|
||||
_showSnack('ID 정보가 없어 수정할 수 없습니다.');
|
||||
Future<void> _openPermissionCreateDialog() async {
|
||||
final result = await showGroupPermissionDetailDialog(
|
||||
context: context,
|
||||
dateFormat: _dateFormat,
|
||||
groups: _controller.groups,
|
||||
isLoadingGroups: _controller.isLoadingGroups,
|
||||
menus: _controller.menus,
|
||||
isLoadingMenus: _controller.isLoadingMenus,
|
||||
onCreate: _controller.create,
|
||||
onUpdate: _controller.update,
|
||||
onDelete: _controller.delete,
|
||||
onRestore: _controller.restore,
|
||||
);
|
||||
if (result != null && mounted) {
|
||||
_showSnack(result.message);
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> _openPermissionDetailDialog(GroupPermission permission) async {
|
||||
final permissionId = permission.id;
|
||||
if (permissionId == null) {
|
||||
_showSnack('ID 정보가 없어 상세를 열 수 없습니다.');
|
||||
return;
|
||||
}
|
||||
|
||||
final groupNotifier = ValueNotifier<int?>(existingPermission?.group.id);
|
||||
final menuNotifier = ValueNotifier<int?>(existingPermission?.menu.id);
|
||||
final createNotifier = ValueNotifier<bool>(
|
||||
existingPermission?.canCreate ?? false,
|
||||
);
|
||||
final readNotifier = ValueNotifier<bool>(
|
||||
existingPermission?.canRead ?? true,
|
||||
);
|
||||
final updateNotifier = ValueNotifier<bool>(
|
||||
existingPermission?.canUpdate ?? false,
|
||||
);
|
||||
final deleteNotifier = ValueNotifier<bool>(
|
||||
existingPermission?.canDelete ?? false,
|
||||
);
|
||||
final activeNotifier = ValueNotifier<bool>(
|
||||
existingPermission?.isActive ?? true,
|
||||
);
|
||||
final noteController = TextEditingController(
|
||||
text: existingPermission?.note ?? '',
|
||||
);
|
||||
final saving = ValueNotifier<bool>(false);
|
||||
final groupError = ValueNotifier<String?>(null);
|
||||
final menuError = ValueNotifier<String?>(null);
|
||||
|
||||
await SuperportDialog.show<bool>(
|
||||
final result = await showGroupPermissionDetailDialog(
|
||||
context: context,
|
||||
dialog: SuperportDialog(
|
||||
title: isEdit ? '권한 수정' : '권한 등록',
|
||||
description: '그룹과 메뉴의 권한을 ${isEdit ? '수정' : '등록'}하세요.',
|
||||
constraints: const BoxConstraints(maxWidth: 600),
|
||||
secondaryAction: ValueListenableBuilder<bool>(
|
||||
valueListenable: saving,
|
||||
builder: (dialogContext, isSaving, __) {
|
||||
return ShadButton.ghost(
|
||||
onPressed: isSaving
|
||||
? null
|
||||
: () => Navigator.of(
|
||||
dialogContext,
|
||||
rootNavigator: true,
|
||||
).pop(false),
|
||||
child: const Text('취소'),
|
||||
);
|
||||
},
|
||||
),
|
||||
primaryAction: ValueListenableBuilder<bool>(
|
||||
valueListenable: saving,
|
||||
builder: (dialogContext, isSaving, __) {
|
||||
return ShadButton(
|
||||
onPressed: isSaving
|
||||
? null
|
||||
: () async {
|
||||
final groupId = groupNotifier.value;
|
||||
final menuId = menuNotifier.value;
|
||||
groupError.value = groupId == null ? '그룹을 선택하세요.' : null;
|
||||
menuError.value = menuId == null ? '메뉴를 선택하세요.' : null;
|
||||
if (groupError.value != null || menuError.value != null) {
|
||||
return;
|
||||
}
|
||||
|
||||
saving.value = true;
|
||||
final trimmedNote = noteController.text.trim();
|
||||
final input = GroupPermissionInput(
|
||||
groupId: groupId!,
|
||||
menuId: menuId!,
|
||||
canCreate: createNotifier.value,
|
||||
canRead: readNotifier.value,
|
||||
canUpdate: updateNotifier.value,
|
||||
canDelete: deleteNotifier.value,
|
||||
isActive: activeNotifier.value,
|
||||
note: trimmedNote.isEmpty ? null : trimmedNote,
|
||||
);
|
||||
final navigator = Navigator.of(
|
||||
dialogContext,
|
||||
rootNavigator: true,
|
||||
);
|
||||
final response = isEdit
|
||||
? await _controller.update(permissionId!, input)
|
||||
: await _controller.create(input);
|
||||
saving.value = false;
|
||||
if (response != null) {
|
||||
if (!navigator.mounted) {
|
||||
return;
|
||||
}
|
||||
if (mounted) {
|
||||
_showSnack(isEdit ? '권한을 수정했습니다.' : '권한을 등록했습니다.');
|
||||
}
|
||||
navigator.pop(true);
|
||||
}
|
||||
},
|
||||
child: Text(isEdit ? '저장' : '등록'),
|
||||
);
|
||||
},
|
||||
),
|
||||
child: ValueListenableBuilder<bool>(
|
||||
valueListenable: saving,
|
||||
builder: (dialogContext, isSaving, __) {
|
||||
final theme = ShadTheme.of(dialogContext);
|
||||
final materialTheme = Theme.of(dialogContext);
|
||||
return SingleChildScrollView(
|
||||
padding: const EdgeInsets.only(right: 12),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
ValueListenableBuilder<String?>(
|
||||
valueListenable: groupError,
|
||||
builder: (_, errorText, __) {
|
||||
return _FormField(
|
||||
label: '그룹',
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
ShadSelect<int?>(
|
||||
initialValue: groupNotifier.value,
|
||||
placeholder: const Text('그룹을 선택하세요'),
|
||||
selectedOptionBuilder: (context, value) {
|
||||
if (value == null) {
|
||||
return const Text('그룹을 선택하세요');
|
||||
}
|
||||
final groupId = value;
|
||||
final group = _controller.groups.firstWhere(
|
||||
(g) => g.id == groupId,
|
||||
orElse: () =>
|
||||
Group(id: groupId, groupName: ''),
|
||||
);
|
||||
return Text(
|
||||
group.groupName.isEmpty
|
||||
? '그룹을 선택하세요'
|
||||
: group.groupName,
|
||||
);
|
||||
},
|
||||
onChanged: isSaving || isEdit
|
||||
? null
|
||||
: (value) {
|
||||
groupNotifier.value = value;
|
||||
if (value != null) {
|
||||
groupError.value = null;
|
||||
}
|
||||
},
|
||||
options: [
|
||||
..._controller.groups.map(
|
||||
(group) => ShadOption<int?>(
|
||||
value: group.id,
|
||||
child: Text(group.groupName),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
if (errorText != null)
|
||||
Padding(
|
||||
padding: const EdgeInsets.only(top: 6),
|
||||
child: Text(
|
||||
errorText,
|
||||
style: theme.textTheme.small.copyWith(
|
||||
color: materialTheme.colorScheme.error,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
ValueListenableBuilder<String?>(
|
||||
valueListenable: menuError,
|
||||
builder: (_, errorText, __) {
|
||||
return _FormField(
|
||||
label: '메뉴',
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
ShadSelect<int?>(
|
||||
initialValue: menuNotifier.value,
|
||||
placeholder: const Text('메뉴를 선택하세요'),
|
||||
selectedOptionBuilder: (context, value) {
|
||||
if (value == null) {
|
||||
return const Text('메뉴를 선택하세요');
|
||||
}
|
||||
final menuId = value;
|
||||
final menu = _controller.menus.firstWhere(
|
||||
(m) => m.id == menuId,
|
||||
orElse: () => MenuItem(
|
||||
id: menuId,
|
||||
menuCode: '',
|
||||
menuName: '',
|
||||
),
|
||||
);
|
||||
return Text(
|
||||
menu.menuName.isEmpty
|
||||
? '메뉴를 선택하세요'
|
||||
: menu.menuName,
|
||||
);
|
||||
},
|
||||
onChanged: isSaving || isEdit
|
||||
? null
|
||||
: (value) {
|
||||
menuNotifier.value = value;
|
||||
if (value != null) {
|
||||
menuError.value = null;
|
||||
}
|
||||
},
|
||||
options: [
|
||||
..._controller.menus.map(
|
||||
(menu) => ShadOption<int?>(
|
||||
value: menu.id,
|
||||
child: Text(menu.menuName),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
if (errorText != null)
|
||||
Padding(
|
||||
padding: const EdgeInsets.only(top: 6),
|
||||
child: Text(
|
||||
errorText,
|
||||
style: theme.textTheme.small.copyWith(
|
||||
color: materialTheme.colorScheme.error,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
const SizedBox(height: 20),
|
||||
_PermissionToggleRow(
|
||||
label: '생성권한',
|
||||
notifier: createNotifier,
|
||||
enabled: !isSaving,
|
||||
),
|
||||
const SizedBox(height: 12),
|
||||
_PermissionToggleRow(
|
||||
label: '조회권한',
|
||||
notifier: readNotifier,
|
||||
enabled: !isSaving,
|
||||
),
|
||||
const SizedBox(height: 12),
|
||||
_PermissionToggleRow(
|
||||
label: '수정권한',
|
||||
notifier: updateNotifier,
|
||||
enabled: !isSaving,
|
||||
),
|
||||
const SizedBox(height: 12),
|
||||
_PermissionToggleRow(
|
||||
label: '삭제권한',
|
||||
notifier: deleteNotifier,
|
||||
enabled: !isSaving,
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
ValueListenableBuilder<bool>(
|
||||
valueListenable: activeNotifier,
|
||||
builder: (_, value, __) {
|
||||
return _FormField(
|
||||
label: '사용여부',
|
||||
child: Row(
|
||||
children: [
|
||||
ShadSwitch(
|
||||
value: value,
|
||||
onChanged: isSaving
|
||||
? null
|
||||
: (next) => activeNotifier.value = next,
|
||||
),
|
||||
const SizedBox(width: 8),
|
||||
Text(value ? '사용' : '미사용'),
|
||||
],
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
_FormField(
|
||||
label: '비고',
|
||||
child: ShadTextarea(controller: noteController),
|
||||
),
|
||||
if (existingPermission != null) ...[
|
||||
const SizedBox(height: 20),
|
||||
Text(
|
||||
'생성일시: ${_formatDateTime(existingPermission.createdAt)}',
|
||||
style: theme.textTheme.small,
|
||||
),
|
||||
const SizedBox(height: 4),
|
||||
Text(
|
||||
'수정일시: ${_formatDateTime(existingPermission.updatedAt)}',
|
||||
style: theme.textTheme.small,
|
||||
),
|
||||
],
|
||||
],
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
dateFormat: _dateFormat,
|
||||
permission: permission,
|
||||
groups: _controller.groups,
|
||||
isLoadingGroups: _controller.isLoadingGroups,
|
||||
menus: _controller.menus,
|
||||
isLoadingMenus: _controller.isLoadingMenus,
|
||||
onCreate: _controller.create,
|
||||
onUpdate: _controller.update,
|
||||
onDelete: _controller.delete,
|
||||
onRestore: _controller.restore,
|
||||
);
|
||||
|
||||
groupNotifier.dispose();
|
||||
menuNotifier.dispose();
|
||||
createNotifier.dispose();
|
||||
readNotifier.dispose();
|
||||
updateNotifier.dispose();
|
||||
deleteNotifier.dispose();
|
||||
activeNotifier.dispose();
|
||||
noteController.dispose();
|
||||
saving.dispose();
|
||||
groupError.dispose();
|
||||
menuError.dispose();
|
||||
}
|
||||
|
||||
Future<void> _confirmDelete(GroupPermission permission) async {
|
||||
final confirmed = await SuperportDialog.show<bool>(
|
||||
context: context,
|
||||
dialog: SuperportDialog(
|
||||
title: '권한 삭제',
|
||||
description:
|
||||
'"${permission.group.groupName}" → "${permission.menu.menuName}" 권한을 삭제하시겠습니까?',
|
||||
secondaryAction: Builder(
|
||||
builder: (dialogContext) {
|
||||
return ShadButton.ghost(
|
||||
onPressed: () =>
|
||||
Navigator.of(dialogContext, rootNavigator: true).pop(false),
|
||||
child: const Text('취소'),
|
||||
);
|
||||
},
|
||||
),
|
||||
primaryAction: Builder(
|
||||
builder: (dialogContext) {
|
||||
return ShadButton.destructive(
|
||||
onPressed: () =>
|
||||
Navigator.of(dialogContext, rootNavigator: true).pop(true),
|
||||
child: const Text('삭제'),
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
if (confirmed == true && permission.id != null) {
|
||||
final success = await _controller.delete(permission.id!);
|
||||
if (success && mounted) {
|
||||
_showSnack('권한을 삭제했습니다.');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> _restorePermission(GroupPermission permission) async {
|
||||
if (permission.id == null) return;
|
||||
final restored = await _controller.restore(permission.id!);
|
||||
if (restored != null && mounted) {
|
||||
_showSnack('권한을 복구했습니다.');
|
||||
if (result != null && mounted) {
|
||||
_showSnack(result.message);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -810,179 +481,84 @@ class _GroupPermissionEnabledPageState
|
||||
}
|
||||
messenger.showSnackBar(SnackBar(content: Text(message)));
|
||||
}
|
||||
|
||||
String _formatDateTime(DateTime? value) {
|
||||
if (value == null) {
|
||||
return '-';
|
||||
}
|
||||
return _dateFormat.format(value.toLocal());
|
||||
}
|
||||
}
|
||||
|
||||
class _PermissionTable extends StatelessWidget {
|
||||
const _PermissionTable({
|
||||
required this.permissions,
|
||||
required this.dateFormat,
|
||||
required this.onEdit,
|
||||
required this.onDelete,
|
||||
required this.onRestore,
|
||||
required this.onRowTap,
|
||||
});
|
||||
|
||||
final List<GroupPermission> permissions;
|
||||
final intl.DateFormat dateFormat;
|
||||
final void Function(GroupPermission permission)? onEdit;
|
||||
final void Function(GroupPermission permission)? onDelete;
|
||||
final void Function(GroupPermission permission)? onRestore;
|
||||
final void Function(GroupPermission permission)? onRowTap;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final header = [
|
||||
'ID',
|
||||
'그룹명',
|
||||
'메뉴명',
|
||||
'라우트 경로',
|
||||
'생성',
|
||||
'조회',
|
||||
'수정',
|
||||
'삭제',
|
||||
'사용',
|
||||
'삭제',
|
||||
'비고',
|
||||
'변경일시',
|
||||
'동작',
|
||||
].map((text) => ShadTableCell.header(child: Text(text))).toList();
|
||||
final columns = const [
|
||||
Text('ID'),
|
||||
Text('그룹명'),
|
||||
Text('메뉴명'),
|
||||
Text('라우트 경로'),
|
||||
Text('생성'),
|
||||
Text('조회'),
|
||||
Text('수정'),
|
||||
Text('삭제'),
|
||||
Text('사용'),
|
||||
Text('삭제'),
|
||||
Text('비고'),
|
||||
Text('변경일시'),
|
||||
];
|
||||
|
||||
final rows = permissions.map((permission) {
|
||||
final cells = [
|
||||
permission.id?.toString() ?? '-',
|
||||
permission.group.groupName,
|
||||
_menuDisplayLabelFromPath(
|
||||
permission.menu.path,
|
||||
permission.menu.menuName,
|
||||
),
|
||||
permission.menu.path ?? '-',
|
||||
permission.canCreate ? 'Y' : '-',
|
||||
permission.canRead ? 'Y' : '-',
|
||||
permission.canUpdate ? 'Y' : '-',
|
||||
permission.canDelete ? 'Y' : '-',
|
||||
permission.isActive ? 'Y' : 'N',
|
||||
permission.isDeleted ? 'Y' : '-',
|
||||
permission.note?.isEmpty ?? true ? '-' : permission.note!,
|
||||
permission.updatedAt == null
|
||||
? '-'
|
||||
: dateFormat.format(permission.updatedAt!.toLocal()),
|
||||
].map((text) => ShadTableCell(child: Text(text))).toList();
|
||||
|
||||
cells.add(
|
||||
ShadTableCell(
|
||||
child: Align(
|
||||
alignment: Alignment.centerRight,
|
||||
child: Row(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
ShadButton.ghost(
|
||||
size: ShadButtonSize.sm,
|
||||
onPressed: onEdit == null ? null : () => onEdit!(permission),
|
||||
child: const Icon(LucideIcons.pencil, size: 16),
|
||||
),
|
||||
const SizedBox(width: 8),
|
||||
permission.isDeleted
|
||||
? ShadButton.ghost(
|
||||
size: ShadButtonSize.sm,
|
||||
onPressed: onRestore == null
|
||||
? null
|
||||
: () => onRestore!(permission),
|
||||
child: const Icon(LucideIcons.history, size: 16),
|
||||
)
|
||||
: ShadButton.ghost(
|
||||
size: ShadButtonSize.sm,
|
||||
onPressed: onDelete == null
|
||||
? null
|
||||
: () => onDelete!(permission),
|
||||
child: const Icon(LucideIcons.trash2, size: 16),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
return cells;
|
||||
}).toList();
|
||||
|
||||
return SizedBox(
|
||||
height: 56.0 * (permissions.length + 1),
|
||||
child: ShadTable.list(
|
||||
header: header,
|
||||
children: rows,
|
||||
columnSpanExtent: (index) {
|
||||
switch (index) {
|
||||
case 1:
|
||||
case 2:
|
||||
return const FixedTableSpanExtent(180);
|
||||
case 9:
|
||||
return const FixedTableSpanExtent(220);
|
||||
case 11:
|
||||
return const FixedTableSpanExtent(200);
|
||||
default:
|
||||
return const FixedTableSpanExtent(110);
|
||||
}
|
||||
},
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class _FormField extends StatelessWidget {
|
||||
const _FormField({required this.label, required this.child});
|
||||
|
||||
final String label;
|
||||
final Widget child;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final theme = ShadTheme.of(context);
|
||||
return Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(label, style: theme.textTheme.small),
|
||||
const SizedBox(height: 6),
|
||||
child,
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class _PermissionToggleRow extends StatelessWidget {
|
||||
const _PermissionToggleRow({
|
||||
required this.label,
|
||||
required this.notifier,
|
||||
required this.enabled,
|
||||
});
|
||||
|
||||
final String label;
|
||||
final ValueNotifier<bool> notifier;
|
||||
final bool enabled;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final theme = ShadTheme.of(context);
|
||||
return ValueListenableBuilder<bool>(
|
||||
valueListenable: notifier,
|
||||
builder: (_, value, __) {
|
||||
return _FormField(
|
||||
label: label,
|
||||
child: Row(
|
||||
children: [
|
||||
ShadSwitch(
|
||||
value: value,
|
||||
onChanged: !enabled ? null : (next) => notifier.value = next,
|
||||
final rows = permissions
|
||||
.map(
|
||||
(permission) => <Widget>[
|
||||
Text(permission.id?.toString() ?? '-'),
|
||||
Text(permission.group.groupName),
|
||||
Text(
|
||||
_menuDisplayLabelFromPath(
|
||||
permission.menu.path,
|
||||
permission.menu.menuName,
|
||||
),
|
||||
const SizedBox(width: 8),
|
||||
Text(value ? '허용' : '차단', style: theme.textTheme.small),
|
||||
],
|
||||
),
|
||||
);
|
||||
),
|
||||
Text(permission.menu.path ?? '-'),
|
||||
Text(permission.canCreate ? 'Y' : '-'),
|
||||
Text(permission.canRead ? 'Y' : '-'),
|
||||
Text(permission.canUpdate ? 'Y' : '-'),
|
||||
Text(permission.canDelete ? 'Y' : '-'),
|
||||
Text(permission.isActive ? 'Y' : 'N'),
|
||||
Text(permission.isDeleted ? 'Y' : '-'),
|
||||
Text(permission.note?.isEmpty ?? true ? '-' : permission.note!),
|
||||
Text(
|
||||
permission.updatedAt == null
|
||||
? '-'
|
||||
: dateFormat.format(permission.updatedAt!.toLocal()),
|
||||
),
|
||||
],
|
||||
)
|
||||
.toList();
|
||||
|
||||
return SuperportTable(
|
||||
columns: columns,
|
||||
rows: rows,
|
||||
rowHeight: 56,
|
||||
maxHeight: 56.0 * (permissions.length + 1),
|
||||
onRowTap: onRowTap == null
|
||||
? null
|
||||
: (index) {
|
||||
if (index < 0 || index >= permissions.length) {
|
||||
return;
|
||||
}
|
||||
onRowTap!(permissions[index]);
|
||||
},
|
||||
columnSpanExtent: (index) => switch (index) {
|
||||
1 => const FixedTableSpanExtent(180),
|
||||
2 => const FixedTableSpanExtent(200),
|
||||
3 => const FixedTableSpanExtent(220),
|
||||
10 => const FixedTableSpanExtent(220),
|
||||
11 => const FixedTableSpanExtent(200),
|
||||
_ => const FixedTableSpanExtent(110),
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user