feat(dialog): 상세 팝업 SuperportDetailDialog 통합
- SuperportDetailDialog 위젯과 showSuperportDetailDialog 헬퍼를 추가하고 metadata/섹션 패턴을 표준화 - 결재/재고/마스터 각 상세 다이얼로그를 dialogs 디렉터리에 신설하고 기존 페이지를 신규 팝업으로 전환 - SuperportTable 행 선택과 우편번호 검색 다이얼로그 onRowTap 보정을 통해 헤더 오프셋 버그를 제거 - 상세 다이얼로그 및 트랜잭션/상세 뷰 전용 위젯 테스트와 tester_extensions 유틸을 추가하여 회귀를 방지 - detail_dialog_unification_plan.md로 작업 배경과 필드 통합 계획을 문서화
This commit is contained in:
@@ -0,0 +1,589 @@
|
||||
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 '../../domain/entities/menu.dart';
|
||||
|
||||
/// 메뉴 상세 다이얼로그에서 발생한 액션 종류이다.
|
||||
enum MenuDetailDialogAction { created, updated, deleted, restored }
|
||||
|
||||
/// 메뉴 상세 다이얼로그 결과를 표현한다.
|
||||
class MenuDetailDialogResult {
|
||||
const MenuDetailDialogResult({required this.action, required this.message});
|
||||
|
||||
final MenuDetailDialogAction action;
|
||||
final String message;
|
||||
}
|
||||
|
||||
typedef MenuCreateCallback = Future<MenuItem?> Function(MenuInput input);
|
||||
typedef MenuUpdateCallback =
|
||||
Future<MenuItem?> Function(int id, MenuInput input);
|
||||
typedef MenuDeleteCallback = Future<bool> Function(int id);
|
||||
typedef MenuRestoreCallback = Future<MenuItem?> Function(int id);
|
||||
|
||||
/// 메뉴 상세 다이얼로그를 띄워 CRUD 플로우를 통합한다.
|
||||
Future<MenuDetailDialogResult?> showMenuDetailDialog({
|
||||
required BuildContext context,
|
||||
required intl.DateFormat dateFormat,
|
||||
MenuItem? menu,
|
||||
required List<MenuItem> parents,
|
||||
required bool isLoadingParents,
|
||||
required MenuCreateCallback onCreate,
|
||||
required MenuUpdateCallback onUpdate,
|
||||
required MenuDeleteCallback onDelete,
|
||||
required MenuRestoreCallback onRestore,
|
||||
}) {
|
||||
final menuValue = menu;
|
||||
final isEdit = menuValue != null;
|
||||
final title = isEdit ? '메뉴 상세' : '메뉴 등록';
|
||||
final description = isEdit
|
||||
? '메뉴 계층과 경로, 권한 관련 메타데이터를 확인합니다.'
|
||||
: '신규 메뉴를 등록할 정보를 입력하세요.';
|
||||
final parentLabel = menuValue?.parent?.menuName ?? '최상위';
|
||||
|
||||
return showSuperportDetailDialog<MenuDetailDialogResult>(
|
||||
context: context,
|
||||
title: title,
|
||||
description: description,
|
||||
summary: menuValue == null
|
||||
? null
|
||||
: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
menuValue.menuName,
|
||||
style: ShadTheme.of(context).textTheme.h4,
|
||||
),
|
||||
const SizedBox(height: 4),
|
||||
Text(
|
||||
menuValue.path?.isEmpty ?? true ? '경로 없음' : menuValue.path!,
|
||||
style: ShadTheme.of(context).textTheme.muted,
|
||||
),
|
||||
],
|
||||
),
|
||||
summaryBadges: menuValue == null
|
||||
? const []
|
||||
: [
|
||||
ShadBadge.outline(child: Text('상위: $parentLabel')),
|
||||
if (menuValue.isActive)
|
||||
const ShadBadge(child: Text('사용중'))
|
||||
else
|
||||
const ShadBadge.outline(child: Text('미사용')),
|
||||
if (menuValue.isDeleted)
|
||||
const ShadBadge.destructive(child: Text('삭제됨')),
|
||||
],
|
||||
metadata: menuValue == null
|
||||
? const []
|
||||
: [
|
||||
SuperportDetailMetadata.text(
|
||||
label: 'ID',
|
||||
value: menuValue.id?.toString() ?? '-',
|
||||
),
|
||||
SuperportDetailMetadata.text(
|
||||
label: '메뉴코드',
|
||||
value: menuValue.menuCode,
|
||||
),
|
||||
SuperportDetailMetadata.text(
|
||||
label: '표시순서',
|
||||
value: menuValue.displayOrder?.toString() ?? '-',
|
||||
),
|
||||
SuperportDetailMetadata.text(
|
||||
label: '비고',
|
||||
value: menuValue.note?.isEmpty ?? true ? '-' : menuValue.note!,
|
||||
),
|
||||
SuperportDetailMetadata.text(
|
||||
label: '생성일시',
|
||||
value: menuValue.createdAt == null
|
||||
? '-'
|
||||
: dateFormat.format(menuValue.createdAt!.toLocal()),
|
||||
),
|
||||
SuperportDetailMetadata.text(
|
||||
label: '변경일시',
|
||||
value: menuValue.updatedAt == null
|
||||
? '-'
|
||||
: dateFormat.format(menuValue.updatedAt!.toLocal()),
|
||||
),
|
||||
],
|
||||
sections: [
|
||||
_MenuEditSection(
|
||||
id: isEdit ? _MenuDetailSections.edit : _MenuDetailSections.create,
|
||||
label: isEdit ? '수정' : '등록',
|
||||
menu: menuValue,
|
||||
parents: parents,
|
||||
isLoadingParents: isLoadingParents,
|
||||
onSubmit: (input) async {
|
||||
if (menuValue == null) {
|
||||
final created = await onCreate(input);
|
||||
if (created == null) {
|
||||
return null;
|
||||
}
|
||||
return const MenuDetailDialogResult(
|
||||
action: MenuDetailDialogAction.created,
|
||||
message: '메뉴를 등록했습니다.',
|
||||
);
|
||||
}
|
||||
final menuId = menuValue.id;
|
||||
if (menuId == null) {
|
||||
return null;
|
||||
}
|
||||
final updated = await onUpdate(menuId, input);
|
||||
if (updated == null) {
|
||||
return null;
|
||||
}
|
||||
return const MenuDetailDialogResult(
|
||||
action: MenuDetailDialogAction.updated,
|
||||
message: '메뉴를 수정했습니다.',
|
||||
);
|
||||
},
|
||||
),
|
||||
if (menuValue != null)
|
||||
SuperportDetailDialogSection(
|
||||
id: menuValue.isDeleted
|
||||
? _MenuDetailSections.restore
|
||||
: _MenuDetailSections.delete,
|
||||
label: menuValue.isDeleted ? '복구' : '삭제',
|
||||
icon: menuValue.isDeleted ? LucideIcons.history : LucideIcons.trash2,
|
||||
builder: (_) => _MenuDangerSection(
|
||||
menu: menuValue,
|
||||
onDelete: () async {
|
||||
final menuId = menuValue.id;
|
||||
if (menuId == null) {
|
||||
return null;
|
||||
}
|
||||
final success = await onDelete(menuId);
|
||||
if (!success) {
|
||||
return null;
|
||||
}
|
||||
return const MenuDetailDialogResult(
|
||||
action: MenuDetailDialogAction.deleted,
|
||||
message: '메뉴를 삭제했습니다.',
|
||||
);
|
||||
},
|
||||
onRestore: () async {
|
||||
final menuId = menuValue.id;
|
||||
if (menuId == null) {
|
||||
return null;
|
||||
}
|
||||
final restored = await onRestore(menuId);
|
||||
if (restored == null) {
|
||||
return null;
|
||||
}
|
||||
return const MenuDetailDialogResult(
|
||||
action: MenuDetailDialogAction.restored,
|
||||
message: '메뉴를 복구했습니다.',
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
],
|
||||
emptyPlaceholder: const Text('표시할 메뉴 정보가 없습니다.'),
|
||||
initialSectionId: menuValue == null
|
||||
? _MenuDetailSections.create
|
||||
: _MenuDetailSections.edit,
|
||||
);
|
||||
}
|
||||
|
||||
/// 메뉴 상세 다이얼로그 섹션 식별자 모음이다.
|
||||
class _MenuDetailSections {
|
||||
static const edit = 'edit';
|
||||
static const delete = 'delete';
|
||||
static const restore = 'restore';
|
||||
static const create = 'create';
|
||||
}
|
||||
|
||||
/// 메뉴 입력 섹션을 정의한다.
|
||||
class _MenuEditSection extends SuperportDetailDialogSection {
|
||||
_MenuEditSection({
|
||||
required super.id,
|
||||
required super.label,
|
||||
required MenuItem? menu,
|
||||
required List<MenuItem> parents,
|
||||
required bool isLoadingParents,
|
||||
required Future<MenuDetailDialogResult?> Function(MenuInput input) onSubmit,
|
||||
}) : super(
|
||||
icon: LucideIcons.pencil,
|
||||
builder: (context) => _MenuForm(
|
||||
menu: menu,
|
||||
parents: parents,
|
||||
isLoadingParents: isLoadingParents,
|
||||
onSubmit: onSubmit,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/// 메뉴 삭제/복구 경고 및 실행을 담당한다.
|
||||
class _MenuDangerSection extends StatelessWidget {
|
||||
const _MenuDangerSection({
|
||||
required this.menu,
|
||||
required this.onDelete,
|
||||
required this.onRestore,
|
||||
});
|
||||
|
||||
final MenuItem menu;
|
||||
final Future<MenuDetailDialogResult?> Function() onDelete;
|
||||
final Future<MenuDetailDialogResult?> Function() onRestore;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final theme = ShadTheme.of(context);
|
||||
final description = menu.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 (menu.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 _MenuForm extends StatefulWidget {
|
||||
const _MenuForm({
|
||||
required this.menu,
|
||||
required this.parents,
|
||||
required this.isLoadingParents,
|
||||
required this.onSubmit,
|
||||
});
|
||||
|
||||
final MenuItem? menu;
|
||||
final List<MenuItem> parents;
|
||||
final bool isLoadingParents;
|
||||
final Future<MenuDetailDialogResult?> Function(MenuInput input) onSubmit;
|
||||
|
||||
bool get _isEdit => menu != null;
|
||||
|
||||
@override
|
||||
State<_MenuForm> createState() => _MenuFormState();
|
||||
}
|
||||
|
||||
class _MenuFormState extends State<_MenuForm> {
|
||||
late final TextEditingController _codeController;
|
||||
late final TextEditingController _nameController;
|
||||
late final TextEditingController _pathController;
|
||||
late final TextEditingController _orderController;
|
||||
late final TextEditingController _noteController;
|
||||
late bool _isActive;
|
||||
int? _selectedParent;
|
||||
String? _codeError;
|
||||
String? _nameError;
|
||||
String? _orderError;
|
||||
String? _submitError;
|
||||
bool _isSubmitting = false;
|
||||
|
||||
bool get _isEdit => widget._isEdit;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
final menu = widget.menu;
|
||||
_codeController = TextEditingController(text: menu?.menuCode ?? '');
|
||||
_nameController = TextEditingController(text: menu?.menuName ?? '');
|
||||
_pathController = TextEditingController(text: menu?.path ?? '');
|
||||
_orderController = TextEditingController(
|
||||
text: menu?.displayOrder?.toString() ?? '',
|
||||
);
|
||||
_noteController = TextEditingController(text: menu?.note ?? '');
|
||||
_isActive = menu?.isActive ?? true;
|
||||
_selectedParent = menu?.parent?.id;
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_codeController.dispose();
|
||||
_nameController.dispose();
|
||||
_pathController.dispose();
|
||||
_orderController.dispose();
|
||||
_noteController.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final theme = ShadTheme.of(context);
|
||||
|
||||
return Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
_MenuFormField(
|
||||
label: '메뉴코드',
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
ShadInput(
|
||||
controller: _codeController,
|
||||
readOnly: _isEdit,
|
||||
onChanged: (_) {
|
||||
if (_codeController.text.trim().isNotEmpty) {
|
||||
setState(() {
|
||||
_codeError = null;
|
||||
});
|
||||
}
|
||||
},
|
||||
),
|
||||
if (_codeError != null)
|
||||
Padding(
|
||||
padding: const EdgeInsets.only(top: 6),
|
||||
child: Text(
|
||||
_codeError!,
|
||||
style: theme.textTheme.small.copyWith(
|
||||
color: theme.colorScheme.destructive,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
_MenuFormField(
|
||||
label: '메뉴명',
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
ShadInput(
|
||||
controller: _nameController,
|
||||
onChanged: (_) {
|
||||
if (_nameController.text.trim().isNotEmpty) {
|
||||
setState(() {
|
||||
_nameError = null;
|
||||
});
|
||||
}
|
||||
},
|
||||
),
|
||||
if (_nameError != null)
|
||||
Padding(
|
||||
padding: const EdgeInsets.only(top: 6),
|
||||
child: Text(
|
||||
_nameError!,
|
||||
style: theme.textTheme.small.copyWith(
|
||||
color: theme.colorScheme.destructive,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
_MenuFormField(
|
||||
label: '상위메뉴',
|
||||
child: ShadSelect<int?>(
|
||||
initialValue: _selectedParent,
|
||||
placeholder: Text(widget.isLoadingParents ? '상위 로딩중...' : '최상위'),
|
||||
selectedOptionBuilder: (_, value) {
|
||||
if (value == null) {
|
||||
return Text(widget.isLoadingParents ? '상위 로딩중...' : '최상위');
|
||||
}
|
||||
final menu = widget.parents.firstWhere(
|
||||
(item) => item.id == value,
|
||||
orElse: () => MenuItem(id: value, menuCode: '', menuName: ''),
|
||||
);
|
||||
final label = menu.menuName.isEmpty ? '최상위' : menu.menuName;
|
||||
return Text(label);
|
||||
},
|
||||
onChanged: _isSubmitting || widget.isLoadingParents
|
||||
? null
|
||||
: (next) {
|
||||
setState(() {
|
||||
_selectedParent = next;
|
||||
});
|
||||
},
|
||||
options: [
|
||||
const ShadOption<int?>(value: null, child: Text('최상위')),
|
||||
...widget.parents
|
||||
.where((item) => item.id != widget.menu?.id)
|
||||
.map(
|
||||
(item) => ShadOption<int?>(
|
||||
value: item.id,
|
||||
child: Text(item.menuName),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
_MenuFormField(
|
||||
label: '경로',
|
||||
child: ShadInput(controller: _pathController),
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
_MenuFormField(
|
||||
label: '표시순서',
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
ShadInput(
|
||||
controller: _orderController,
|
||||
keyboardType: TextInputType.number,
|
||||
),
|
||||
if (_orderError != null)
|
||||
Padding(
|
||||
padding: const EdgeInsets.only(top: 6),
|
||||
child: Text(
|
||||
_orderError!,
|
||||
style: theme.textTheme.small.copyWith(
|
||||
color: theme.colorScheme.destructive,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
_MenuFormField(
|
||||
label: '사용 여부',
|
||||
child: Row(
|
||||
children: [
|
||||
ShadSwitch(
|
||||
value: _isActive,
|
||||
onChanged: _isSubmitting
|
||||
? null
|
||||
: (next) {
|
||||
setState(() {
|
||||
_isActive = next;
|
||||
});
|
||||
},
|
||||
),
|
||||
const SizedBox(width: 8),
|
||||
Text(_isActive ? '사용' : '미사용'),
|
||||
],
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
_MenuFormField(
|
||||
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 {
|
||||
final code = _codeController.text.trim();
|
||||
final name = _nameController.text.trim();
|
||||
final orderText = _orderController.text.trim();
|
||||
|
||||
int? orderValue;
|
||||
if (orderText.isNotEmpty) {
|
||||
orderValue = int.tryParse(orderText);
|
||||
}
|
||||
|
||||
setState(() {
|
||||
_codeError = code.isEmpty ? '메뉴코드를 입력하세요.' : null;
|
||||
_nameError = name.isEmpty ? '메뉴명을 입력하세요.' : null;
|
||||
_orderError = orderText.isEmpty || orderValue != null
|
||||
? null
|
||||
: '표시순서는 숫자여야 합니다.';
|
||||
_submitError = null;
|
||||
});
|
||||
|
||||
if (_codeError != null || _nameError != null || _orderError != null) {
|
||||
return;
|
||||
}
|
||||
|
||||
setState(() {
|
||||
_isSubmitting = true;
|
||||
});
|
||||
|
||||
final path = _pathController.text.trim();
|
||||
final note = _noteController.text.trim();
|
||||
final input = MenuInput(
|
||||
menuCode: code,
|
||||
menuName: name,
|
||||
parentMenuId: _selectedParent,
|
||||
path: path.isEmpty ? null : path,
|
||||
displayOrder: orderValue,
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// 메뉴 폼 필드 레이아웃을 제공한다.
|
||||
class _MenuFormField extends StatelessWidget {
|
||||
const _MenuFormField({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,
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/// 개요 섹션에서 사용하는 키-값 구조체이다.
|
||||
@@ -5,14 +5,15 @@ 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 '../../../../../widgets/spec_page.dart';
|
||||
import '../../domain/entities/menu.dart';
|
||||
import '../../domain/repositories/menu_repository.dart';
|
||||
import '../controllers/menu_controller.dart' as menu;
|
||||
import '../dialogs/menu_detail_dialog.dart';
|
||||
|
||||
/// 메뉴 관리 페이지. 기능 플래그에 따라 사양/실제 화면을 전환한다.
|
||||
class MenuPage extends StatelessWidget {
|
||||
@@ -173,7 +174,7 @@ class _MenuEnabledPageState extends State<_MenuEnabledPage> {
|
||||
leading: const Icon(LucideIcons.plus, size: 16),
|
||||
onPressed: _controller.isSubmitting
|
||||
? null
|
||||
: () => _openMenuForm(context),
|
||||
: _openMenuCreateDialog,
|
||||
child: const Text('신규 등록'),
|
||||
),
|
||||
],
|
||||
@@ -330,11 +331,9 @@ class _MenuEnabledPageState extends State<_MenuEnabledPage> {
|
||||
: _MenuTable(
|
||||
menus: menus,
|
||||
dateFormat: _dateFormat,
|
||||
onEdit: _controller.isSubmitting
|
||||
onRowTap: _controller.isSubmitting
|
||||
? null
|
||||
: (menuItem) => _openMenuForm(context, menu: menuItem),
|
||||
onDelete: _controller.isSubmitting ? null : _confirmDelete,
|
||||
onRestore: _controller.isSubmitting ? null : _restoreMenu,
|
||||
: _openMenuDetailDialog,
|
||||
),
|
||||
),
|
||||
);
|
||||
@@ -358,377 +357,41 @@ class _MenuEnabledPageState extends State<_MenuEnabledPage> {
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> _openMenuForm(BuildContext context, {MenuItem? menu}) async {
|
||||
final existingMenu = menu;
|
||||
final isEdit = existingMenu != null;
|
||||
final menuId = existingMenu?.id;
|
||||
if (isEdit && menuId == null) {
|
||||
_showSnack('ID 정보가 없어 수정할 수 없습니다.');
|
||||
Future<void> _openMenuCreateDialog() async {
|
||||
final result = await showMenuDetailDialog(
|
||||
context: context,
|
||||
dateFormat: _dateFormat,
|
||||
parents: _controller.parents,
|
||||
isLoadingParents: _controller.isLoadingParents,
|
||||
onCreate: _controller.create,
|
||||
onUpdate: _controller.update,
|
||||
onDelete: _controller.delete,
|
||||
onRestore: _controller.restore,
|
||||
);
|
||||
if (result != null && mounted) {
|
||||
_showSnack(result.message);
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> _openMenuDetailDialog(MenuItem menu) async {
|
||||
final menuId = menu.id;
|
||||
if (menuId == null) {
|
||||
_showSnack('ID 정보가 없어 상세를 열 수 없습니다.');
|
||||
return;
|
||||
}
|
||||
|
||||
final codeController = TextEditingController(
|
||||
text: existingMenu?.menuCode ?? '',
|
||||
);
|
||||
final nameController = TextEditingController(
|
||||
text: existingMenu?.menuName ?? '',
|
||||
);
|
||||
final pathController = TextEditingController(
|
||||
text: existingMenu?.path ?? '',
|
||||
);
|
||||
final orderController = TextEditingController(
|
||||
text: existingMenu?.displayOrder?.toString() ?? '',
|
||||
);
|
||||
final noteController = TextEditingController(
|
||||
text: existingMenu?.note ?? '',
|
||||
);
|
||||
final parentNotifier = ValueNotifier<int?>(existingMenu?.parent?.id);
|
||||
final isActiveNotifier = ValueNotifier<bool>(
|
||||
existingMenu?.isActive ?? true,
|
||||
);
|
||||
final saving = ValueNotifier<bool>(false);
|
||||
final codeError = ValueNotifier<String?>(null);
|
||||
final nameError = ValueNotifier<String?>(null);
|
||||
final orderError = ValueNotifier<String?>(null);
|
||||
|
||||
await SuperportDialog.show<bool>(
|
||||
final result = await showMenuDetailDialog(
|
||||
context: context,
|
||||
dialog: SuperportDialog(
|
||||
title: isEdit ? '메뉴 수정' : '메뉴 등록',
|
||||
description: '메뉴 정보를 ${isEdit ? '수정' : '입력'}하세요.',
|
||||
constraints: const BoxConstraints(maxWidth: 560),
|
||||
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 code = codeController.text.trim();
|
||||
final name = nameController.text.trim();
|
||||
final path = pathController.text.trim();
|
||||
final orderText = orderController.text.trim();
|
||||
final note = noteController.text.trim();
|
||||
|
||||
codeError.value = code.isEmpty ? '메뉴코드를 입력하세요.' : null;
|
||||
nameError.value = name.isEmpty ? '메뉴명을 입력하세요.' : null;
|
||||
|
||||
int? orderValue;
|
||||
if (orderText.isNotEmpty) {
|
||||
orderValue = int.tryParse(orderText);
|
||||
orderError.value = orderValue == null
|
||||
? '표시순서는 숫자여야 합니다.'
|
||||
: null;
|
||||
} else {
|
||||
orderError.value = null;
|
||||
}
|
||||
|
||||
if (codeError.value != null ||
|
||||
nameError.value != null ||
|
||||
orderError.value != null) {
|
||||
return;
|
||||
}
|
||||
|
||||
saving.value = true;
|
||||
final input = MenuInput(
|
||||
menuCode: code,
|
||||
menuName: name,
|
||||
parentMenuId: parentNotifier.value,
|
||||
path: path.isEmpty ? null : path,
|
||||
displayOrder: orderValue,
|
||||
isActive: isActiveNotifier.value,
|
||||
note: note.isEmpty ? null : note,
|
||||
);
|
||||
final navigator = Navigator.of(
|
||||
dialogContext,
|
||||
rootNavigator: true,
|
||||
);
|
||||
final response = isEdit
|
||||
? await _controller.update(menuId!, 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: codeError,
|
||||
builder: (_, errorText, __) {
|
||||
return _FormField(
|
||||
label: '메뉴코드',
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
ShadInput(
|
||||
controller: codeController,
|
||||
readOnly: isEdit,
|
||||
onChanged: (_) {
|
||||
if (codeController.text.trim().isNotEmpty) {
|
||||
codeError.value = null;
|
||||
}
|
||||
},
|
||||
),
|
||||
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: nameError,
|
||||
builder: (_, errorText, __) {
|
||||
return _FormField(
|
||||
label: '메뉴명',
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
ShadInput(
|
||||
controller: nameController,
|
||||
onChanged: (_) {
|
||||
if (nameController.text.trim().isNotEmpty) {
|
||||
nameError.value = null;
|
||||
}
|
||||
},
|
||||
),
|
||||
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<int?>(
|
||||
valueListenable: parentNotifier,
|
||||
builder: (_, value, __) {
|
||||
return _FormField(
|
||||
label: '상위메뉴',
|
||||
child: ShadSelect<int?>(
|
||||
initialValue: value,
|
||||
placeholder: const Text('최상위'),
|
||||
selectedOptionBuilder: (context, selected) {
|
||||
if (selected == null) {
|
||||
return const Text('최상위');
|
||||
}
|
||||
final target = _controller.parents.firstWhere(
|
||||
(item) => item.id == selected,
|
||||
orElse: () => MenuItem(
|
||||
id: selected,
|
||||
menuCode: '',
|
||||
menuName: '',
|
||||
),
|
||||
);
|
||||
final label = target.menuName.isEmpty
|
||||
? '최상위'
|
||||
: target.menuName;
|
||||
return Text(label);
|
||||
},
|
||||
onChanged: isSaving
|
||||
? null
|
||||
: (next) => parentNotifier.value = next,
|
||||
options: [
|
||||
const ShadOption<int?>(
|
||||
value: null,
|
||||
child: Text('최상위'),
|
||||
),
|
||||
..._controller.parents
|
||||
.where((item) => item.id != menuId)
|
||||
.map(
|
||||
(menuItem) => ShadOption<int?>(
|
||||
value: menuItem.id,
|
||||
child: Text(menuItem.menuName),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
_FormField(
|
||||
label: '경로',
|
||||
child: ShadInput(controller: pathController),
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
ValueListenableBuilder<String?>(
|
||||
valueListenable: orderError,
|
||||
builder: (_, errorText, __) {
|
||||
return _FormField(
|
||||
label: '표시순서',
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
ShadInput(
|
||||
controller: orderController,
|
||||
keyboardType: TextInputType.number,
|
||||
),
|
||||
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<bool>(
|
||||
valueListenable: isActiveNotifier,
|
||||
builder: (_, value, __) {
|
||||
return _FormField(
|
||||
label: '사용여부',
|
||||
child: Row(
|
||||
children: [
|
||||
ShadSwitch(
|
||||
value: value,
|
||||
onChanged: isSaving
|
||||
? null
|
||||
: (next) => isActiveNotifier.value = next,
|
||||
),
|
||||
const SizedBox(width: 8),
|
||||
Text(value ? '사용' : '미사용'),
|
||||
],
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
_FormField(
|
||||
label: '비고',
|
||||
child: ShadTextarea(controller: noteController),
|
||||
),
|
||||
if (existingMenu != null) ...[
|
||||
const SizedBox(height: 20),
|
||||
Text(
|
||||
'생성일시: ${_formatDateTime(existingMenu.createdAt)}',
|
||||
style: theme.textTheme.small,
|
||||
),
|
||||
const SizedBox(height: 4),
|
||||
Text(
|
||||
'수정일시: ${_formatDateTime(existingMenu.updatedAt)}',
|
||||
style: theme.textTheme.small,
|
||||
),
|
||||
],
|
||||
],
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
dateFormat: _dateFormat,
|
||||
menu: menu,
|
||||
parents: _controller.parents,
|
||||
isLoadingParents: _controller.isLoadingParents,
|
||||
onCreate: _controller.create,
|
||||
onUpdate: _controller.update,
|
||||
onDelete: _controller.delete,
|
||||
onRestore: _controller.restore,
|
||||
);
|
||||
|
||||
codeController.dispose();
|
||||
nameController.dispose();
|
||||
pathController.dispose();
|
||||
orderController.dispose();
|
||||
noteController.dispose();
|
||||
parentNotifier.dispose();
|
||||
isActiveNotifier.dispose();
|
||||
saving.dispose();
|
||||
codeError.dispose();
|
||||
nameError.dispose();
|
||||
orderError.dispose();
|
||||
}
|
||||
|
||||
Future<void> _confirmDelete(MenuItem menu) async {
|
||||
final confirmed = await SuperportDialog.show<bool>(
|
||||
context: context,
|
||||
dialog: SuperportDialog(
|
||||
title: '메뉴 삭제',
|
||||
description: '"${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 && menu.id != null) {
|
||||
final success = await _controller.delete(menu.id!);
|
||||
if (success && mounted) {
|
||||
_showSnack('메뉴를 삭제했습니다.');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> _restoreMenu(MenuItem menu) async {
|
||||
if (menu.id == null) return;
|
||||
final restored = await _controller.restore(menu.id!);
|
||||
if (restored != null && mounted) {
|
||||
_showSnack('메뉴를 복구했습니다.');
|
||||
if (result != null && mounted) {
|
||||
_showSnack(result.message);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -742,131 +405,73 @@ class _MenuEnabledPageState extends State<_MenuEnabledPage> {
|
||||
}
|
||||
messenger.showSnackBar(SnackBar(content: Text(message)));
|
||||
}
|
||||
|
||||
String _formatDateTime(DateTime? value) {
|
||||
if (value == null) {
|
||||
return '-';
|
||||
}
|
||||
return _dateFormat.format(value.toLocal());
|
||||
}
|
||||
}
|
||||
|
||||
class _MenuTable extends StatelessWidget {
|
||||
const _MenuTable({
|
||||
required this.menus,
|
||||
required this.onEdit,
|
||||
required this.onDelete,
|
||||
required this.onRestore,
|
||||
required this.dateFormat,
|
||||
required this.onRowTap,
|
||||
});
|
||||
|
||||
final List<MenuItem> menus;
|
||||
final void Function(MenuItem menu)? onEdit;
|
||||
final void Function(MenuItem menu)? onDelete;
|
||||
final void Function(MenuItem menu)? onRestore;
|
||||
final DateFormat dateFormat;
|
||||
final void Function(MenuItem menu)? 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('변경일시'),
|
||||
];
|
||||
|
||||
final rows = menus.map((item) {
|
||||
final cells = [
|
||||
item.id?.toString() ?? '-',
|
||||
item.menuCode,
|
||||
item.menuName,
|
||||
item.parent?.menuName ?? '-',
|
||||
item.path?.isEmpty ?? true ? '-' : item.path!,
|
||||
item.isActive ? 'Y' : 'N',
|
||||
item.isDeleted ? 'Y' : '-',
|
||||
item.note?.isEmpty ?? true ? '-' : item.note!,
|
||||
item.updatedAt == null
|
||||
? '-'
|
||||
: dateFormat.format(item.updatedAt!.toLocal()),
|
||||
].map((text) => ShadTableCell(child: Text(text))).toList();
|
||||
final rows = menus
|
||||
.map(
|
||||
(item) => <Widget>[
|
||||
Text(item.id?.toString() ?? '-'),
|
||||
Text(item.menuCode),
|
||||
Text(item.menuName),
|
||||
Text(item.parent?.menuName ?? '-'),
|
||||
Text(item.path?.isEmpty ?? true ? '-' : item.path!),
|
||||
Text(item.isActive ? 'Y' : 'N'),
|
||||
Text(item.isDeleted ? 'Y' : '-'),
|
||||
Text(item.note?.isEmpty ?? true ? '-' : item.note!),
|
||||
Text(
|
||||
item.updatedAt == null
|
||||
? '-'
|
||||
: dateFormat.format(item.updatedAt!.toLocal()),
|
||||
),
|
||||
],
|
||||
)
|
||||
.toList();
|
||||
|
||||
cells.add(
|
||||
ShadTableCell(
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.end,
|
||||
children: [
|
||||
ShadButton.ghost(
|
||||
size: ShadButtonSize.sm,
|
||||
onPressed: onEdit == null ? null : () => onEdit!(item),
|
||||
child: const Icon(LucideIcons.pencil, size: 16),
|
||||
),
|
||||
const SizedBox(width: 8),
|
||||
item.isDeleted
|
||||
? ShadButton.ghost(
|
||||
size: ShadButtonSize.sm,
|
||||
onPressed: onRestore == null
|
||||
? null
|
||||
: () => onRestore!(item),
|
||||
child: const Icon(LucideIcons.history, size: 16),
|
||||
)
|
||||
: ShadButton.ghost(
|
||||
size: ShadButtonSize.sm,
|
||||
onPressed: onDelete == null
|
||||
? null
|
||||
: () => onDelete!(item),
|
||||
child: const Icon(LucideIcons.trash2, size: 16),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
return cells;
|
||||
}).toList();
|
||||
|
||||
return SizedBox(
|
||||
height: 56.0 * (menus.length + 1),
|
||||
child: ShadTable.list(
|
||||
header: header,
|
||||
children: rows,
|
||||
columnSpanExtent: (index) {
|
||||
switch (index) {
|
||||
case 4:
|
||||
return const FixedTableSpanExtent(200);
|
||||
case 7:
|
||||
return const FixedTableSpanExtent(200);
|
||||
case 9:
|
||||
return const FixedTableSpanExtent(160);
|
||||
default:
|
||||
return const FixedTableSpanExtent(120);
|
||||
}
|
||||
},
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
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,
|
||||
],
|
||||
return SuperportTable(
|
||||
columns: columns,
|
||||
rows: rows,
|
||||
rowHeight: 56,
|
||||
maxHeight: 56.0 * (menus.length + 1),
|
||||
onRowTap: onRowTap == null
|
||||
? null
|
||||
: (index) {
|
||||
if (index < 0 || index >= menus.length) {
|
||||
return;
|
||||
}
|
||||
onRowTap!(menus[index]);
|
||||
},
|
||||
columnSpanExtent: (index) => switch (index) {
|
||||
3 => const FixedTableSpanExtent(180),
|
||||
4 => const FixedTableSpanExtent(200),
|
||||
7 => const FixedTableSpanExtent(200),
|
||||
8 => const FixedTableSpanExtent(160),
|
||||
_ => const FixedTableSpanExtent(120),
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user