기존엔 "많은 시간요청 학생" 팝업에서만 2시간 기준으로 걸러냈는데, 메인 목록 카드 자체에도 (대기중/승인/거절 등 상태 무관하게) 빨간 테두리를 씌워서 바로 눈에 띄게 함. 기준을 2시간 → 1시간 59분(119분)으로 낮춰서 두 기능이 같은 기준을 쓰도록 통일. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
500 lines
22 KiB
Dart
500 lines
22 KiB
Dart
// 📋 선생님용 "스마트기기 반출 대장" 화면 (UI 전용). 오늘 신청된 반출 요청을 보여주고 승인/거절한다.
|
|
// 서버 통신/상태는 lib/function/device_checkout_ledger_controller.dart가 담당한다.
|
|
import 'package:flutter/material.dart';
|
|
import '../function/device_checkout_ledger_controller.dart';
|
|
import '../theme/app_palette.dart';
|
|
import 'app_notice.dart';
|
|
import 'title_pill.dart';
|
|
|
|
class DeviceCheckoutLedgerPage extends StatefulWidget {
|
|
final String? teacherId;
|
|
final String? teacherName;
|
|
|
|
const DeviceCheckoutLedgerPage({super.key, this.teacherId, this.teacherName});
|
|
|
|
@override
|
|
State<DeviceCheckoutLedgerPage> createState() =>
|
|
_DeviceCheckoutLedgerPageState();
|
|
}
|
|
|
|
class _DeviceCheckoutLedgerPageState extends State<DeviceCheckoutLedgerPage> {
|
|
final DeviceCheckoutLedgerController _controller =
|
|
DeviceCheckoutLedgerController();
|
|
|
|
@override
|
|
void initState() {
|
|
super.initState();
|
|
_controller.init();
|
|
}
|
|
|
|
@override
|
|
void dispose() {
|
|
_controller.dispose();
|
|
super.dispose();
|
|
}
|
|
|
|
Future<void> _approve(int id) async {
|
|
final (_, message) = await _controller.approve(
|
|
id,
|
|
teacherId: widget.teacherId ?? '간편인증',
|
|
teacherName: widget.teacherName ?? '간편인증 선생',
|
|
);
|
|
if (!mounted) return;
|
|
AppNotice.show(context, message);
|
|
}
|
|
|
|
Future<void> _reject(int id) async {
|
|
final (_, message) = await _controller.reject(id);
|
|
if (!mounted) return;
|
|
AppNotice.show(context, message);
|
|
}
|
|
|
|
// 🙌 [전체 학생 허용] 한 명씩 누르기 귀찮을 때, 대기 중인 요청을 한 번에 전부 승인한다.
|
|
void _showApproveAllConfirmDialog() {
|
|
final pendingCount = _controller.requests
|
|
.where((r) => r['status'] == 'PENDING')
|
|
.length;
|
|
if (pendingCount == 0) {
|
|
AppNotice.show(context, '승인 대기 중인 요청이 없습니다.');
|
|
return;
|
|
}
|
|
showDialog(
|
|
context: context,
|
|
builder: (dialogContext) => AlertDialog(
|
|
title: const Text('전체 학생 허용'),
|
|
content: Text('대기 중인 요청 $pendingCount건을 한 번에 전부 승인하시겠습니까?'),
|
|
actions: [
|
|
TextButton(
|
|
onPressed: () => Navigator.pop(dialogContext),
|
|
child: const Text('취소', style: TextStyle(color: Colors.grey)),
|
|
),
|
|
ElevatedButton(
|
|
style: ElevatedButton.styleFrom(
|
|
backgroundColor: AppPalette.ink,
|
|
foregroundColor: AppPalette.paper,
|
|
),
|
|
onPressed: () async {
|
|
Navigator.pop(dialogContext);
|
|
final (_, message) = await _controller.approveAllPending(
|
|
teacherId: widget.teacherId ?? '간편인증',
|
|
teacherName: widget.teacherName ?? '간편인증 선생',
|
|
);
|
|
if (!mounted) return;
|
|
AppNotice.show(context, message);
|
|
},
|
|
child: const Text('전체 승인'),
|
|
),
|
|
],
|
|
),
|
|
);
|
|
}
|
|
|
|
// 🚨 [많은 시간요청 학생] 1시간 59분 넘게 신청한 대기 중인 요청만 따로 모아 보여준다.
|
|
// 학생이 시간을 비정상적으로 길게 적어냈을 수 있으니, 전체 승인 전에 훑어보는 용도.
|
|
void _showLongRequestsDialog() {
|
|
showDialog(
|
|
context: context,
|
|
builder: (dialogContext) => AlertDialog(
|
|
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(20)),
|
|
title: const Row(
|
|
children: [
|
|
Icon(Icons.warning_amber_rounded, color: Colors.orange),
|
|
SizedBox(width: 8),
|
|
Text('많은 시간요청 학생'),
|
|
],
|
|
),
|
|
content: SizedBox(
|
|
width: 380,
|
|
child: ListenableBuilder(
|
|
listenable: _controller,
|
|
builder: (context, _) {
|
|
final longRequests = _controller.longPendingRequests;
|
|
if (longRequests.isEmpty) {
|
|
return const Padding(
|
|
padding: EdgeInsets.symmetric(vertical: 16),
|
|
child: Text(
|
|
'1시간 59분 넘게 신청한 대기 중인 요청이 없습니다.',
|
|
style: TextStyle(color: Colors.grey),
|
|
),
|
|
);
|
|
}
|
|
return ConstrainedBox(
|
|
constraints: const BoxConstraints(maxHeight: 400),
|
|
child: ListView.separated(
|
|
shrinkWrap: true,
|
|
itemCount: longRequests.length,
|
|
separatorBuilder: (_, _) => const Divider(height: 20),
|
|
itemBuilder: (context, index) {
|
|
final r = longRequests[index];
|
|
final hours = _controller.durationHours(r);
|
|
return Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
Text(
|
|
'${r['studentName']} (${r['studentId']})',
|
|
style: const TextStyle(fontWeight: FontWeight.bold),
|
|
),
|
|
const SizedBox(height: 4),
|
|
Text(
|
|
'${_timeRange(r['requestedStart'], r['requestedEnd'])} '
|
|
'(약 ${hours?.toStringAsFixed(1)}시간)',
|
|
style: const TextStyle(
|
|
color: Colors.orange,
|
|
fontWeight: FontWeight.bold,
|
|
fontSize: 13,
|
|
),
|
|
),
|
|
const SizedBox(height: 2),
|
|
Text(
|
|
r['purpose'],
|
|
style: TextStyle(
|
|
color: Colors.grey[700],
|
|
fontSize: 13,
|
|
),
|
|
),
|
|
const SizedBox(height: 8),
|
|
Row(
|
|
children: [
|
|
Expanded(
|
|
child: OutlinedButton(
|
|
onPressed: _controller.isWorking
|
|
? null
|
|
: () {
|
|
Navigator.pop(dialogContext);
|
|
_reject(r['id']);
|
|
},
|
|
style: OutlinedButton.styleFrom(
|
|
foregroundColor: Colors.red,
|
|
side: const BorderSide(color: Colors.red),
|
|
),
|
|
child: const Text('거절'),
|
|
),
|
|
),
|
|
const SizedBox(width: 8),
|
|
Expanded(
|
|
child: ElevatedButton(
|
|
onPressed: _controller.isWorking
|
|
? null
|
|
: () {
|
|
Navigator.pop(dialogContext);
|
|
_approve(r['id']);
|
|
},
|
|
style: ElevatedButton.styleFrom(
|
|
backgroundColor: AppPalette.ink,
|
|
foregroundColor: AppPalette.paper,
|
|
),
|
|
child: const Text('승인'),
|
|
),
|
|
),
|
|
],
|
|
),
|
|
],
|
|
);
|
|
},
|
|
),
|
|
);
|
|
},
|
|
),
|
|
),
|
|
actions: [
|
|
TextButton(
|
|
onPressed: () => Navigator.pop(dialogContext),
|
|
child: const Text('닫기'),
|
|
),
|
|
],
|
|
),
|
|
);
|
|
}
|
|
|
|
// 🖐️ [하드웨어 자동 감지 전까지 임시] 기기를 실제로 돌려받았을 때 누르는 버튼.
|
|
Future<void> _confirmReturn(int id) async {
|
|
final (_, message) = await _controller.confirmReturn(id);
|
|
if (!mounted) return;
|
|
AppNotice.show(context, message);
|
|
}
|
|
|
|
({Color color, String label}) _statusInfo(String status) {
|
|
switch (status) {
|
|
case 'PENDING':
|
|
return (color: Colors.orange, label: '대기중');
|
|
case 'APPROVED':
|
|
return (color: Colors.blue, label: '승인됨');
|
|
case 'RETURNED':
|
|
return (color: Colors.grey, label: '반납완료');
|
|
case 'REJECTED':
|
|
return (color: Colors.red, label: '거절됨');
|
|
default:
|
|
return (color: Colors.grey, label: status);
|
|
}
|
|
}
|
|
|
|
String _timeRange(String start, String end) {
|
|
// "YYYY-MM-DD HH:MM:SS" -> "HH:MM"
|
|
String hm(String full) => full.length >= 16 ? full.substring(11, 16) : full;
|
|
return '${hm(start)} ~ ${hm(end)}';
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return ListenableBuilder(
|
|
listenable: _controller,
|
|
builder: (context, _) {
|
|
final requests = _controller.requests;
|
|
final pendingCount = requests
|
|
.where((r) => r['status'] == 'PENDING')
|
|
.length;
|
|
final longCount = _controller.longPendingRequests.length;
|
|
|
|
return Scaffold(
|
|
backgroundColor: AppPalette.mist,
|
|
appBar: AppBar(
|
|
backgroundColor: Colors.transparent,
|
|
foregroundColor: AppPalette.ink,
|
|
elevation: 0,
|
|
centerTitle: true,
|
|
title: const TitlePill('스마트기기 반출 대장'),
|
|
actions: [
|
|
IconButton(
|
|
icon: const Icon(Icons.refresh_rounded),
|
|
onPressed: _controller.fetchAll,
|
|
tooltip: '새로고침',
|
|
),
|
|
IconButton(
|
|
icon: const Icon(Icons.done_all_rounded),
|
|
onPressed: _showApproveAllConfirmDialog,
|
|
tooltip: '전체 학생 허용',
|
|
),
|
|
IconButton(
|
|
icon: Badge(
|
|
isLabelVisible: longCount > 0,
|
|
label: Text('$longCount'),
|
|
backgroundColor: Colors.red,
|
|
child: const Icon(Icons.warning_amber_rounded),
|
|
),
|
|
onPressed: _showLongRequestsDialog,
|
|
tooltip: '많은 시간요청 학생',
|
|
),
|
|
],
|
|
),
|
|
body: _controller.isLoading
|
|
? const Center(child: CircularProgressIndicator())
|
|
: Column(
|
|
children: [
|
|
if (pendingCount > 0)
|
|
Container(
|
|
width: double.infinity,
|
|
margin: const EdgeInsets.all(16),
|
|
padding: const EdgeInsets.symmetric(
|
|
horizontal: 16,
|
|
vertical: 10,
|
|
),
|
|
decoration: BoxDecoration(
|
|
color: Colors.orange[100],
|
|
borderRadius: BorderRadius.circular(12),
|
|
border: Border.all(color: Colors.orange[400]!),
|
|
),
|
|
child: Text(
|
|
'승인 대기 중인 요청이 $pendingCount건 있습니다.',
|
|
style: TextStyle(
|
|
color: Colors.orange[900],
|
|
fontWeight: FontWeight.bold,
|
|
),
|
|
),
|
|
),
|
|
Expanded(
|
|
child: requests.isEmpty
|
|
? const Center(
|
|
child: Text(
|
|
'오늘 신청된 반출 요청이 없습니다.',
|
|
style: TextStyle(color: Colors.grey),
|
|
),
|
|
)
|
|
: ListView.builder(
|
|
padding: const EdgeInsets.symmetric(
|
|
horizontal: 16,
|
|
vertical: 8,
|
|
),
|
|
itemCount: requests.length,
|
|
itemBuilder: (context, index) {
|
|
final r = requests[index];
|
|
final String status = r['status'];
|
|
final info = _statusInfo(status);
|
|
final bool isPending = status == 'PENDING';
|
|
// 🚨 1시간 59분 넘게 신청했으면 상태와 무관하게 빨간 테두리로 눈에 띄게.
|
|
final bool isLong = _controller.isLongRequest(
|
|
r,
|
|
);
|
|
|
|
return Card(
|
|
elevation: 0,
|
|
color: AppPalette.paper,
|
|
margin: const EdgeInsets.only(bottom: 10),
|
|
shape: RoundedRectangleBorder(
|
|
borderRadius: BorderRadius.circular(16),
|
|
side: isLong
|
|
? BorderSide(
|
|
color: Colors.red[400]!,
|
|
width: 2,
|
|
)
|
|
: (isPending
|
|
? BorderSide(
|
|
color: Colors.orange[300]!,
|
|
)
|
|
: BorderSide(
|
|
color: AppPalette.sage,
|
|
)),
|
|
),
|
|
child: Padding(
|
|
padding: const EdgeInsets.all(16),
|
|
child: Column(
|
|
crossAxisAlignment:
|
|
CrossAxisAlignment.start,
|
|
children: [
|
|
Row(
|
|
children: [
|
|
Expanded(
|
|
child: Text(
|
|
'${r['studentName']} (${r['studentId']})',
|
|
style: const TextStyle(
|
|
fontWeight: FontWeight.bold,
|
|
fontSize: 15,
|
|
),
|
|
),
|
|
),
|
|
Container(
|
|
padding:
|
|
const EdgeInsets.symmetric(
|
|
horizontal: 10,
|
|
vertical: 4,
|
|
),
|
|
decoration: BoxDecoration(
|
|
color: info.color.withValues(
|
|
alpha: 0.12,
|
|
),
|
|
borderRadius:
|
|
BorderRadius.circular(20),
|
|
),
|
|
child: Text(
|
|
info.label,
|
|
style: TextStyle(
|
|
color: info.color,
|
|
fontWeight: FontWeight.bold,
|
|
fontSize: 12,
|
|
),
|
|
),
|
|
),
|
|
],
|
|
),
|
|
const SizedBox(height: 6),
|
|
Text(
|
|
_timeRange(
|
|
r['requestedStart'],
|
|
r['requestedEnd'],
|
|
),
|
|
style: TextStyle(
|
|
color: Colors.grey[700],
|
|
fontSize: 13,
|
|
),
|
|
),
|
|
const SizedBox(height: 2),
|
|
Text(
|
|
r['purpose'],
|
|
style: TextStyle(
|
|
color: Colors.grey[700],
|
|
fontSize: 13,
|
|
),
|
|
),
|
|
if (status == 'APPROVED' &&
|
|
r['approvedByTeacherName'] !=
|
|
null) ...[
|
|
const SizedBox(height: 2),
|
|
Text(
|
|
'${r['approvedByTeacherName']} 선생님이 허용했습니다',
|
|
style: TextStyle(
|
|
color: Colors.blue[700],
|
|
fontSize: 12,
|
|
fontWeight: FontWeight.w600,
|
|
),
|
|
),
|
|
],
|
|
if (isPending) ...[
|
|
const SizedBox(height: 12),
|
|
Row(
|
|
children: [
|
|
Expanded(
|
|
child: OutlinedButton(
|
|
onPressed:
|
|
_controller.isWorking
|
|
? null
|
|
: () => _reject(r['id']),
|
|
style:
|
|
OutlinedButton.styleFrom(
|
|
foregroundColor:
|
|
Colors.red,
|
|
side: const BorderSide(
|
|
color: Colors.red,
|
|
),
|
|
),
|
|
child: const Text('거절'),
|
|
),
|
|
),
|
|
const SizedBox(width: 8),
|
|
Expanded(
|
|
child: ElevatedButton(
|
|
onPressed:
|
|
_controller.isWorking
|
|
? null
|
|
: () => _approve(r['id']),
|
|
style:
|
|
ElevatedButton.styleFrom(
|
|
backgroundColor:
|
|
AppPalette.ink,
|
|
foregroundColor:
|
|
AppPalette.paper,
|
|
),
|
|
child: const Text('승인'),
|
|
),
|
|
),
|
|
],
|
|
),
|
|
],
|
|
if (status == 'APPROVED') ...[
|
|
const SizedBox(height: 12),
|
|
SizedBox(
|
|
width: double.infinity,
|
|
child: OutlinedButton.icon(
|
|
onPressed: _controller.isWorking
|
|
? null
|
|
: () =>
|
|
_confirmReturn(r['id']),
|
|
style: OutlinedButton.styleFrom(
|
|
foregroundColor:
|
|
Colors.grey[800],
|
|
side: BorderSide(
|
|
color: Colors.grey[400]!,
|
|
),
|
|
),
|
|
icon: const Icon(
|
|
Icons
|
|
.assignment_turned_in_outlined,
|
|
size: 18,
|
|
),
|
|
label: const Text('기기 반납 확인'),
|
|
),
|
|
),
|
|
],
|
|
],
|
|
),
|
|
),
|
|
);
|
|
},
|
|
),
|
|
),
|
|
],
|
|
),
|
|
);
|
|
},
|
|
);
|
|
}
|
|
}
|