Add Programmer Tasks module (work-log + time tracking)
Separate feature for the `programmer` role to record dev work by category, distinct from the IT help-desk `tasks` feature. Modeled on the IT Service Requests pattern (Brick offline-first model -> Riverpod stream/controller -> list/detail screens); seed of a future Project Management workflow. - programmer_tasks + programmer_task_activity_logs (category enum, RLS, realtime) via supabase migration - single assignee, self-logged or lead-assigned; assign/reassign logged - pause-on-switch: starting a task while another runs prompts to pause the running one, keeping one active task per user for accurate time attribution - worked-duration math shared with help-desk tasks via a generic core in task_duration.dart (existing callers unchanged) - list distinguishes running vs paused with a per-task Resume shortcut - accessible dialog labels; route /programmer-tasks + nav gated to admin/programmer - unit/widget tests: controller lifecycle, duration math, pause-switch dialog Co-Authored-By: claude-flow <ruv@ruv.net>
This commit is contained in:
@@ -0,0 +1,63 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
|
||||
import '../../models/programmer_task.model.dart';
|
||||
import '../../providers/programmer_tasks_provider.dart';
|
||||
|
||||
/// Starts (or resumes) [task] for the current user, enforcing the single-active
|
||||
/// task discipline: if the user already has a *running* task, they are prompted
|
||||
/// to pause it first. This is the headline "proper time management" behavior and
|
||||
/// is shared by the list and detail screens.
|
||||
///
|
||||
/// Returns true if the task was started/resumed, false if the user cancelled.
|
||||
Future<bool> startProgrammerTaskWithPausePrompt(
|
||||
BuildContext context,
|
||||
WidgetRef ref,
|
||||
ProgrammerTask task,
|
||||
) async {
|
||||
final controller = ref.read(programmerTasksControllerProvider);
|
||||
final messenger = ScaffoldMessenger.of(context);
|
||||
|
||||
final running = await controller.findRunningTaskForCurrentUser();
|
||||
if (running != null && running.id != task.id) {
|
||||
if (!context.mounted) return false;
|
||||
final confirmed = await showDialog<bool>(
|
||||
context: context,
|
||||
builder: (context) => AlertDialog(
|
||||
semanticLabel: 'Pause current task',
|
||||
title: const Text('Pause current task?'),
|
||||
content: Text(
|
||||
"You're currently working on \"${running.title}\". "
|
||||
'Pause it and start "${task.title}"?',
|
||||
),
|
||||
actions: [
|
||||
TextButton(
|
||||
onPressed: () => Navigator.of(context).pop(false),
|
||||
child: const Text('Cancel'),
|
||||
),
|
||||
FilledButton(
|
||||
onPressed: () => Navigator.of(context).pop(true),
|
||||
child: const Text('Pause & Start'),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
if (confirmed != true) return false;
|
||||
await controller.pauseTask(taskId: running.id);
|
||||
}
|
||||
|
||||
try {
|
||||
if (task.status == ProgrammerTaskStatus.queued) {
|
||||
await controller.startTask(taskId: task.id);
|
||||
} else if (task.status == ProgrammerTaskStatus.inProgress) {
|
||||
await controller.resumeTask(taskId: task.id);
|
||||
}
|
||||
messenger.showSnackBar(
|
||||
SnackBar(content: Text('Started "${task.title}"')),
|
||||
);
|
||||
return true;
|
||||
} catch (e) {
|
||||
messenger.showSnackBar(SnackBar(content: Text('Could not start task: $e')));
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,475 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
|
||||
import '../../models/profile.model.dart';
|
||||
import '../../models/programmer_task.model.dart';
|
||||
import '../../models/programmer_task_activity_log.model.dart';
|
||||
import '../../providers/profile_provider.dart';
|
||||
import '../../providers/programmer_tasks_provider.dart';
|
||||
import '../../utils/app_time.dart';
|
||||
import '../../utils/task_duration.dart';
|
||||
import '../../widgets/app_section_header.dart';
|
||||
import '../../widgets/m3_card.dart';
|
||||
import '../../widgets/responsive_body.dart';
|
||||
import '../../widgets/status_pill.dart';
|
||||
import '../../widgets/tech_chip.dart';
|
||||
import 'programmer_task_actions.dart';
|
||||
import 'programmer_task_status_kind.dart';
|
||||
|
||||
/// Lifecycle events, newest-first, that determine the live running/paused state.
|
||||
const _lifecycleActions = ['started', 'paused', 'resumed', 'completed', 'cancelled'];
|
||||
|
||||
class ProgrammerTaskDetailScreen extends ConsumerWidget {
|
||||
const ProgrammerTaskDetailScreen({super.key, required this.taskId});
|
||||
|
||||
final String taskId;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context, WidgetRef ref) {
|
||||
final task = ref.watch(programmerTaskByIdProvider(taskId));
|
||||
final logsAsync = ref.watch(programmerTaskActivityLogsProvider(taskId));
|
||||
final userId = ref.watch(currentUserIdProvider);
|
||||
final role = ref.watch(currentProfileProvider).valueOrNull?.role;
|
||||
final profiles = ref.watch(profilesProvider).valueOrNull ?? const <Profile>[];
|
||||
final profileById = {for (final p in profiles) p.id: p};
|
||||
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
title: Text(task?.title ?? 'Programmer Task'),
|
||||
actions: [
|
||||
if (task != null && !task.isTerminal && _canAct(task, userId, role))
|
||||
IconButton(
|
||||
tooltip: 'Reassign',
|
||||
icon: const Icon(Icons.person_add_alt_1_outlined),
|
||||
onPressed: () => _reassign(context, ref, task, profiles, userId),
|
||||
),
|
||||
],
|
||||
),
|
||||
body: task == null
|
||||
? const Center(child: CircularProgressIndicator())
|
||||
: _DetailBody(
|
||||
task: task,
|
||||
logs: logsAsync.valueOrNull ?? const [],
|
||||
profileById: profileById,
|
||||
userId: userId,
|
||||
role: role,
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
bool _canAct(ProgrammerTask task, String? userId, String? role) =>
|
||||
task.assigneeId == userId || role == 'admin' || role == 'programmer';
|
||||
|
||||
class _DetailBody extends ConsumerWidget {
|
||||
const _DetailBody({
|
||||
required this.task,
|
||||
required this.logs,
|
||||
required this.profileById,
|
||||
required this.userId,
|
||||
required this.role,
|
||||
});
|
||||
|
||||
final ProgrammerTask task;
|
||||
final List<ProgrammerTaskActivityLog> logs;
|
||||
final Map<String, Profile> profileById;
|
||||
final String? userId;
|
||||
final String? role;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context, WidgetRef ref) {
|
||||
final tt = Theme.of(context).textTheme;
|
||||
final cs = Theme.of(context).colorScheme;
|
||||
|
||||
// Live running/paused state from the newest lifecycle event.
|
||||
String latest = '';
|
||||
for (final l in logs) {
|
||||
if (_lifecycleActions.contains(l.actionType)) {
|
||||
latest = l.actionType;
|
||||
break;
|
||||
}
|
||||
}
|
||||
final isPaused =
|
||||
task.status == ProgrammerTaskStatus.inProgress && latest == 'paused';
|
||||
final isRunning =
|
||||
task.status == ProgrammerTaskStatus.inProgress && !isPaused;
|
||||
|
||||
final endAt = switch (task.status) {
|
||||
ProgrammerTaskStatus.completed => task.completedAt ?? AppTime.now(),
|
||||
ProgrammerTaskStatus.cancelled => task.cancelledAt ?? AppTime.now(),
|
||||
_ => AppTime.now(),
|
||||
};
|
||||
final worked = computeEffectiveDuration(
|
||||
fallbackStartedAt: task.startedAt,
|
||||
endAt: endAt,
|
||||
events: logs
|
||||
.map((l) => (createdAt: l.createdAt, actionType: l.actionType))
|
||||
.toList(),
|
||||
);
|
||||
|
||||
final assignee =
|
||||
task.assigneeId == null ? null : profileById[task.assigneeId];
|
||||
final canAct = _canAct(task, userId, role);
|
||||
|
||||
return ResponsiveBody(
|
||||
child: ListView(
|
||||
padding: const EdgeInsets.symmetric(vertical: 16),
|
||||
children: [
|
||||
M3Card.elevated(
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(16),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Row(
|
||||
children: [
|
||||
Expanded(
|
||||
child: Text(
|
||||
task.title,
|
||||
style: tt.titleLarge
|
||||
?.copyWith(fontWeight: FontWeight.w700),
|
||||
),
|
||||
),
|
||||
StatusPill.kind(
|
||||
programmerTaskStatusKind(task.status),
|
||||
label: isPaused
|
||||
? 'Paused'
|
||||
: ProgrammerTaskStatus.label(task.status),
|
||||
),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 12),
|
||||
Wrap(
|
||||
spacing: 12,
|
||||
runSpacing: 8,
|
||||
crossAxisAlignment: WrapCrossAlignment.center,
|
||||
children: [
|
||||
TechChip(task.category, icon: Icons.category_outlined),
|
||||
if (assignee != null)
|
||||
Row(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
Icon(Icons.person_outline,
|
||||
size: 15, color: cs.onSurfaceVariant),
|
||||
const SizedBox(width: 4),
|
||||
Text(
|
||||
assignee.fullName,
|
||||
style: tt.bodyMedium
|
||||
?.copyWith(color: cs.onSurfaceVariant),
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
if (task.description != null &&
|
||||
task.description!.trim().isNotEmpty) ...[
|
||||
const SizedBox(height: 14),
|
||||
Text(task.description!, style: tt.bodyMedium),
|
||||
],
|
||||
const SizedBox(height: 14),
|
||||
Row(
|
||||
children: [
|
||||
Icon(Icons.timer_outlined, size: 18, color: cs.primary),
|
||||
const SizedBox(width: 8),
|
||||
Text(
|
||||
'Worked: ${_fmtDuration(worked)}',
|
||||
style: tt.titleSmall
|
||||
?.copyWith(fontWeight: FontWeight.w600),
|
||||
),
|
||||
if (isRunning) ...[
|
||||
const SizedBox(width: 8),
|
||||
Text('· running',
|
||||
style: tt.bodySmall
|
||||
?.copyWith(color: cs.onSurfaceVariant)),
|
||||
],
|
||||
],
|
||||
),
|
||||
if (task.cancellationReason != null) ...[
|
||||
const SizedBox(height: 10),
|
||||
Text(
|
||||
'Cancelled: ${task.cancellationReason}',
|
||||
style: tt.bodySmall?.copyWith(color: cs.error),
|
||||
),
|
||||
],
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
if (canAct && !task.isTerminal) ...[
|
||||
const SizedBox(height: 16),
|
||||
_ActionBar(
|
||||
task: task,
|
||||
isRunning: isRunning,
|
||||
isPaused: isPaused,
|
||||
),
|
||||
],
|
||||
const SizedBox(height: 24),
|
||||
const AppSectionHeader('Activity'),
|
||||
if (logs.isEmpty)
|
||||
Text('No activity yet.',
|
||||
style: tt.bodySmall?.copyWith(color: cs.onSurfaceVariant))
|
||||
else
|
||||
...logs.map((l) => _ActivityRow(log: l, profileById: profileById)),
|
||||
const SizedBox(height: 32),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class _ActionBar extends ConsumerWidget {
|
||||
const _ActionBar({
|
||||
required this.task,
|
||||
required this.isRunning,
|
||||
required this.isPaused,
|
||||
});
|
||||
|
||||
final ProgrammerTask task;
|
||||
final bool isRunning;
|
||||
final bool isPaused;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context, WidgetRef ref) {
|
||||
final controller = ref.read(programmerTasksControllerProvider);
|
||||
final isQueued = task.status == ProgrammerTaskStatus.queued;
|
||||
|
||||
return Wrap(
|
||||
spacing: 10,
|
||||
runSpacing: 10,
|
||||
children: [
|
||||
if (isQueued)
|
||||
FilledButton.icon(
|
||||
onPressed: () =>
|
||||
startProgrammerTaskWithPausePrompt(context, ref, task),
|
||||
icon: const Icon(Icons.play_arrow_rounded),
|
||||
label: const Text('Start'),
|
||||
),
|
||||
if (isPaused)
|
||||
FilledButton.icon(
|
||||
onPressed: () =>
|
||||
startProgrammerTaskWithPausePrompt(context, ref, task),
|
||||
icon: const Icon(Icons.play_arrow_rounded),
|
||||
label: const Text('Resume'),
|
||||
),
|
||||
if (isRunning)
|
||||
FilledButton.tonalIcon(
|
||||
onPressed: () async {
|
||||
final messenger = ScaffoldMessenger.of(context);
|
||||
await controller.pauseTask(taskId: task.id);
|
||||
messenger.showSnackBar(const SnackBar(content: Text('Paused')));
|
||||
},
|
||||
icon: const Icon(Icons.pause_rounded),
|
||||
label: const Text('Pause'),
|
||||
),
|
||||
if (isRunning || isPaused)
|
||||
OutlinedButton.icon(
|
||||
onPressed: () => _complete(context, ref, task),
|
||||
icon: const Icon(Icons.check_rounded),
|
||||
label: const Text('Complete'),
|
||||
),
|
||||
OutlinedButton.icon(
|
||||
onPressed: () => _cancel(context, ref, task),
|
||||
icon: const Icon(Icons.close_rounded),
|
||||
label: const Text('Cancel'),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class _ActivityRow extends StatelessWidget {
|
||||
const _ActivityRow({required this.log, required this.profileById});
|
||||
|
||||
final ProgrammerTaskActivityLog log;
|
||||
final Map<String, Profile> profileById;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final tt = Theme.of(context).textTheme;
|
||||
final cs = Theme.of(context).colorScheme;
|
||||
final actor = log.actorId == null ? null : profileById[log.actorId];
|
||||
|
||||
return Padding(
|
||||
padding: const EdgeInsets.symmetric(vertical: 6),
|
||||
child: Row(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Icon(_iconFor(log.actionType), size: 16, color: cs.onSurfaceVariant),
|
||||
const SizedBox(width: 10),
|
||||
Expanded(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
'${actor?.fullName ?? 'Someone'} · ${_labelFor(log.actionType)}',
|
||||
style: tt.bodyMedium,
|
||||
),
|
||||
Text(
|
||||
AppTime.relative(log.createdAt),
|
||||
style: tt.bodySmall?.copyWith(color: cs.onSurfaceVariant),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
String _fmtDuration(Duration d) {
|
||||
final h = d.inHours;
|
||||
final m = d.inMinutes.remainder(60);
|
||||
if (h > 0) return '${h}h ${m}m';
|
||||
return '${m}m';
|
||||
}
|
||||
|
||||
String _labelFor(String action) => switch (action) {
|
||||
'created' => 'created the task',
|
||||
'started' => 'started work',
|
||||
'paused' => 'paused',
|
||||
'resumed' => 'resumed',
|
||||
'completed' => 'completed the task',
|
||||
'cancelled' => 'cancelled the task',
|
||||
'assigned' => 'assigned the task',
|
||||
'reassigned' => 'reassigned the task',
|
||||
'updated' => 'updated details',
|
||||
_ => action,
|
||||
};
|
||||
|
||||
IconData _iconFor(String action) => switch (action) {
|
||||
'created' => Icons.add_task,
|
||||
'started' => Icons.play_arrow_rounded,
|
||||
'paused' => Icons.pause_rounded,
|
||||
'resumed' => Icons.play_arrow_rounded,
|
||||
'completed' => Icons.check_circle_outline,
|
||||
'cancelled' => Icons.cancel_outlined,
|
||||
'assigned' || 'reassigned' => Icons.person_add_alt_1_outlined,
|
||||
'updated' => Icons.edit_outlined,
|
||||
_ => Icons.circle_outlined,
|
||||
};
|
||||
|
||||
Future<void> _complete(
|
||||
BuildContext context,
|
||||
WidgetRef ref,
|
||||
ProgrammerTask task,
|
||||
) async {
|
||||
final messenger = ScaffoldMessenger.of(context);
|
||||
final ok = await showDialog<bool>(
|
||||
context: context,
|
||||
builder: (context) => AlertDialog(
|
||||
semanticLabel: 'Complete task',
|
||||
title: const Text('Complete task?'),
|
||||
content: Text('Mark "${task.title}" as completed?'),
|
||||
actions: [
|
||||
TextButton(
|
||||
onPressed: () => Navigator.of(context).pop(false),
|
||||
child: const Text('Cancel'),
|
||||
),
|
||||
FilledButton(
|
||||
onPressed: () => Navigator.of(context).pop(true),
|
||||
child: const Text('Complete'),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
if (ok != true) return;
|
||||
await ref.read(programmerTasksControllerProvider).completeTask(taskId: task.id);
|
||||
messenger.showSnackBar(const SnackBar(content: Text('Task completed')));
|
||||
}
|
||||
|
||||
Future<void> _cancel(
|
||||
BuildContext context,
|
||||
WidgetRef ref,
|
||||
ProgrammerTask task,
|
||||
) async {
|
||||
final reasonCtrl = TextEditingController();
|
||||
final reason = await showDialog<String>(
|
||||
context: context,
|
||||
builder: (context) => AlertDialog(
|
||||
semanticLabel: 'Cancel task',
|
||||
title: const Text('Cancel task?'),
|
||||
content: TextField(
|
||||
controller: reasonCtrl,
|
||||
autofocus: true,
|
||||
textCapitalization: TextCapitalization.sentences,
|
||||
decoration: const InputDecoration(
|
||||
labelText: 'Reason',
|
||||
hintText: 'Why is this being cancelled?',
|
||||
),
|
||||
),
|
||||
actions: [
|
||||
TextButton(
|
||||
onPressed: () => Navigator.of(context).pop(),
|
||||
child: const Text('Back'),
|
||||
),
|
||||
FilledButton(
|
||||
onPressed: () => Navigator.of(context).pop(reasonCtrl.text.trim()),
|
||||
child: const Text('Cancel Task'),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
reasonCtrl.dispose();
|
||||
if (reason == null || reason.isEmpty) return;
|
||||
if (!context.mounted) return;
|
||||
final messenger = ScaffoldMessenger.of(context);
|
||||
await ref
|
||||
.read(programmerTasksControllerProvider)
|
||||
.cancelTask(taskId: task.id, reason: reason);
|
||||
messenger.showSnackBar(const SnackBar(content: Text('Task cancelled')));
|
||||
}
|
||||
|
||||
Future<void> _reassign(
|
||||
BuildContext context,
|
||||
WidgetRef ref,
|
||||
ProgrammerTask task,
|
||||
List<Profile> profiles,
|
||||
String? userId,
|
||||
) async {
|
||||
final eligible = profiles
|
||||
.where((p) => p.role == 'programmer' || p.role == 'admin')
|
||||
.toList()
|
||||
..sort((a, b) => a.fullName.compareTo(b.fullName));
|
||||
if (eligible.isEmpty) return;
|
||||
|
||||
var selected = task.assigneeId ?? userId;
|
||||
final chosen = await showDialog<String>(
|
||||
context: context,
|
||||
builder: (context) => StatefulBuilder(
|
||||
builder: (context, setDialogState) => AlertDialog(
|
||||
semanticLabel: 'Reassign task',
|
||||
title: const Text('Reassign task'),
|
||||
content: DropdownButtonFormField<String>(
|
||||
initialValue: eligible.any((p) => p.id == selected) ? selected : null,
|
||||
decoration: const InputDecoration(labelText: 'Assignee'),
|
||||
items: [
|
||||
for (final p in eligible)
|
||||
DropdownMenuItem(
|
||||
value: p.id,
|
||||
child: Text(p.id == userId ? '${p.fullName} (me)' : p.fullName),
|
||||
),
|
||||
],
|
||||
onChanged: (v) => setDialogState(() => selected = v),
|
||||
),
|
||||
actions: [
|
||||
TextButton(
|
||||
onPressed: () => Navigator.of(context).pop(),
|
||||
child: const Text('Cancel'),
|
||||
),
|
||||
FilledButton(
|
||||
onPressed: () => Navigator.of(context).pop(selected),
|
||||
child: const Text('Reassign'),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
if (chosen == null || chosen == task.assigneeId) return;
|
||||
if (!context.mounted) return;
|
||||
final messenger = ScaffoldMessenger.of(context);
|
||||
await ref
|
||||
.read(programmerTasksControllerProvider)
|
||||
.reassign(taskId: task.id, newAssigneeId: chosen);
|
||||
messenger.showSnackBar(const SnackBar(content: Text('Task reassigned')));
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
import '../../models/programmer_task.model.dart';
|
||||
import '../../theme/app_status_colors.dart';
|
||||
|
||||
/// Maps a programmer-task status to a semantic [StatusKind] so its color carries
|
||||
/// consistent meaning across the list and detail screens
|
||||
/// (grey=queued, blue=in progress, green=completed, grey=cancelled).
|
||||
StatusKind programmerTaskStatusKind(String status) => switch (status) {
|
||||
ProgrammerTaskStatus.queued => StatusKind.neutral,
|
||||
ProgrammerTaskStatus.inProgress => StatusKind.info,
|
||||
ProgrammerTaskStatus.completed => StatusKind.success,
|
||||
ProgrammerTaskStatus.cancelled => StatusKind.neutral,
|
||||
_ => StatusKind.neutral,
|
||||
};
|
||||
@@ -0,0 +1,354 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
import 'package:go_router/go_router.dart';
|
||||
|
||||
import '../../models/profile.model.dart';
|
||||
import '../../models/programmer_task.model.dart';
|
||||
import '../../providers/profile_provider.dart';
|
||||
import '../../providers/programmer_tasks_provider.dart';
|
||||
import '../../theme/app_status_colors.dart';
|
||||
import '../../theme/m3_motion.dart';
|
||||
import '../../utils/app_time.dart';
|
||||
import '../../widgets/app_page_header.dart';
|
||||
import '../../widgets/app_state_view.dart';
|
||||
import '../../widgets/m3_card.dart';
|
||||
import '../../widgets/reconnect_overlay.dart';
|
||||
import '../../widgets/responsive_body.dart';
|
||||
import '../../widgets/status_pill.dart';
|
||||
import '../../widgets/tech_chip.dart';
|
||||
import 'programmer_task_actions.dart';
|
||||
import 'programmer_task_status_kind.dart';
|
||||
|
||||
class ProgrammerTasksListScreen extends ConsumerStatefulWidget {
|
||||
const ProgrammerTasksListScreen({super.key});
|
||||
|
||||
@override
|
||||
ConsumerState<ProgrammerTasksListScreen> createState() =>
|
||||
_ProgrammerTasksListScreenState();
|
||||
}
|
||||
|
||||
class _ProgrammerTasksListScreenState
|
||||
extends ConsumerState<ProgrammerTasksListScreen>
|
||||
with SingleTickerProviderStateMixin {
|
||||
late final TabController _tabController;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_tabController = TabController(length: 2, vsync: this);
|
||||
_tabController.addListener(() {
|
||||
if (mounted) setState(() {});
|
||||
});
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_tabController.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final tasksAsync = ref.watch(programmerTasksProvider);
|
||||
final userId = ref.watch(currentUserIdProvider);
|
||||
final profilesAsync = ref.watch(profilesProvider);
|
||||
|
||||
final profileById = <String, Profile>{
|
||||
for (final p in profilesAsync.valueOrNull ?? <Profile>[]) p.id: p,
|
||||
};
|
||||
|
||||
return Stack(
|
||||
children: [
|
||||
ResponsiveBody(
|
||||
maxWidth: double.infinity,
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: [
|
||||
const AppPageHeader(
|
||||
title: 'Programmer Tasks',
|
||||
subtitle: 'Log and track development work',
|
||||
),
|
||||
TabBar(
|
||||
controller: _tabController,
|
||||
tabs: const [Tab(text: 'Mine'), Tab(text: 'All')],
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
Expanded(
|
||||
child: Builder(
|
||||
builder: (context) {
|
||||
if (tasksAsync.hasError && !tasksAsync.hasValue) {
|
||||
return AppErrorView(
|
||||
error: tasksAsync.error!,
|
||||
onRetry: () =>
|
||||
ref.invalidate(programmerTasksProvider),
|
||||
);
|
||||
}
|
||||
if (!tasksAsync.hasValue && tasksAsync.isLoading) {
|
||||
return const Center(child: CircularProgressIndicator());
|
||||
}
|
||||
final all = tasksAsync.valueOrNull ?? const [];
|
||||
final showMine = _tabController.index == 0;
|
||||
final tasks = showMine
|
||||
? all.where((t) => t.assigneeId == userId).toList()
|
||||
: all;
|
||||
|
||||
if (tasks.isEmpty) {
|
||||
return AppEmptyView(
|
||||
icon: Icons.developer_mode_outlined,
|
||||
title: showMine ? 'No tasks assigned to you' : 'No tasks yet',
|
||||
subtitle: showMine
|
||||
? 'Tasks you log or that are assigned to you appear here.'
|
||||
: 'Create the first programmer task with the + button.',
|
||||
);
|
||||
}
|
||||
|
||||
return ListView.separated(
|
||||
padding: const EdgeInsets.symmetric(vertical: 8),
|
||||
itemCount: tasks.length,
|
||||
separatorBuilder: (_, _) => const SizedBox(height: 10),
|
||||
itemBuilder: (context, i) {
|
||||
final task = tasks[i];
|
||||
return _TaskCard(
|
||||
task: task,
|
||||
assignee: task.assigneeId == null
|
||||
? null
|
||||
: profileById[task.assigneeId],
|
||||
isMine: task.assigneeId == userId,
|
||||
);
|
||||
},
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
Positioned(
|
||||
right: 16,
|
||||
bottom: 16,
|
||||
child: M3ExpandedFab(
|
||||
heroTag: 'create_programmer_task',
|
||||
onPressed: () => _showCreateDialog(context),
|
||||
icon: const Icon(Icons.add),
|
||||
label: const Text('New Task'),
|
||||
),
|
||||
),
|
||||
const ReconnectIndicator(),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
Future<void> _showCreateDialog(BuildContext context) async {
|
||||
final userId = ref.read(currentUserIdProvider);
|
||||
final profiles = ref.read(profilesProvider).valueOrNull ?? const <Profile>[];
|
||||
final eligible = profiles
|
||||
.where((p) => p.role == 'programmer' || p.role == 'admin')
|
||||
.toList()
|
||||
..sort((a, b) => a.fullName.compareTo(b.fullName));
|
||||
|
||||
final titleCtrl = TextEditingController();
|
||||
final descCtrl = TextEditingController();
|
||||
var category = ProgrammerTaskCategory.softwareDevelopment;
|
||||
var assigneeId = userId;
|
||||
|
||||
final created = await showDialog<bool>(
|
||||
context: context,
|
||||
builder: (context) {
|
||||
return StatefulBuilder(
|
||||
builder: (context, setDialogState) {
|
||||
return AlertDialog(
|
||||
semanticLabel: 'New programmer task',
|
||||
title: const Text('New Programmer Task'),
|
||||
content: SingleChildScrollView(
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
TextField(
|
||||
controller: titleCtrl,
|
||||
autofocus: true,
|
||||
textCapitalization: TextCapitalization.sentences,
|
||||
decoration: const InputDecoration(
|
||||
labelText: 'Title',
|
||||
hintText: 'What are you working on?',
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 12),
|
||||
TextField(
|
||||
controller: descCtrl,
|
||||
minLines: 2,
|
||||
maxLines: 4,
|
||||
textCapitalization: TextCapitalization.sentences,
|
||||
decoration: const InputDecoration(
|
||||
labelText: 'Description (optional)',
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 12),
|
||||
DropdownButtonFormField<String>(
|
||||
initialValue: category,
|
||||
decoration: const InputDecoration(labelText: 'Category'),
|
||||
items: [
|
||||
for (final c in ProgrammerTaskCategory.all)
|
||||
DropdownMenuItem(value: c, child: Text(c)),
|
||||
],
|
||||
onChanged: (v) =>
|
||||
setDialogState(() => category = v ?? category),
|
||||
),
|
||||
if (eligible.isNotEmpty) ...[
|
||||
const SizedBox(height: 12),
|
||||
DropdownButtonFormField<String>(
|
||||
initialValue: assigneeId,
|
||||
decoration: const InputDecoration(labelText: 'Assignee'),
|
||||
items: [
|
||||
for (final p in eligible)
|
||||
DropdownMenuItem(
|
||||
value: p.id,
|
||||
child: Text(
|
||||
p.id == userId ? '${p.fullName} (me)' : p.fullName,
|
||||
),
|
||||
),
|
||||
],
|
||||
onChanged: (v) =>
|
||||
setDialogState(() => assigneeId = v ?? assigneeId),
|
||||
),
|
||||
],
|
||||
],
|
||||
),
|
||||
),
|
||||
actions: [
|
||||
TextButton(
|
||||
onPressed: () => Navigator.of(context).pop(false),
|
||||
child: const Text('Cancel'),
|
||||
),
|
||||
FilledButton(
|
||||
onPressed: () => Navigator.of(context).pop(true),
|
||||
child: const Text('Create'),
|
||||
),
|
||||
],
|
||||
);
|
||||
},
|
||||
);
|
||||
},
|
||||
);
|
||||
|
||||
if (created != true) {
|
||||
titleCtrl.dispose();
|
||||
descCtrl.dispose();
|
||||
return;
|
||||
}
|
||||
|
||||
final title = titleCtrl.text.trim();
|
||||
titleCtrl.dispose();
|
||||
final description = descCtrl.text.trim();
|
||||
descCtrl.dispose();
|
||||
if (title.isEmpty) return;
|
||||
if (!context.mounted) return;
|
||||
|
||||
final messenger = ScaffoldMessenger.of(context);
|
||||
try {
|
||||
final id = await ref.read(programmerTasksControllerProvider).createTask(
|
||||
title: title,
|
||||
category: category,
|
||||
description: description.isEmpty ? null : description,
|
||||
assigneeId: assigneeId,
|
||||
);
|
||||
if (!context.mounted) return;
|
||||
context.go('/programmer-tasks/$id');
|
||||
} catch (e) {
|
||||
messenger.showSnackBar(SnackBar(content: Text('Could not create task: $e')));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class _TaskCard extends ConsumerWidget {
|
||||
const _TaskCard({required this.task, required this.assignee, required this.isMine});
|
||||
|
||||
final ProgrammerTask task;
|
||||
final Profile? assignee;
|
||||
final bool isMine;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context, WidgetRef ref) {
|
||||
final tt = Theme.of(context).textTheme;
|
||||
final cs = Theme.of(context).colorScheme;
|
||||
|
||||
// Distinguish a *paused* task from a *running* one (both share the
|
||||
// `in_progress` status) using the current user's running-task id.
|
||||
final runningId = ref.watch(myRunningProgrammerTaskIdProvider).valueOrNull;
|
||||
final isInProgress = task.status == ProgrammerTaskStatus.inProgress;
|
||||
final isPaused = isInProgress && isMine && task.id != runningId;
|
||||
|
||||
final canStart = isMine && task.status == ProgrammerTaskStatus.queued;
|
||||
final canResume = isPaused;
|
||||
|
||||
final pillKind =
|
||||
isPaused ? StatusKind.warning : programmerTaskStatusKind(task.status);
|
||||
final pillLabel =
|
||||
isPaused ? 'Paused' : ProgrammerTaskStatus.label(task.status);
|
||||
|
||||
return M3Card.outlined(
|
||||
onTap: () => context.go('/programmer-tasks/${task.id}'),
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(14),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Row(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Expanded(
|
||||
child: Text(
|
||||
task.title,
|
||||
style: tt.titleMedium?.copyWith(fontWeight: FontWeight.w600),
|
||||
maxLines: 2,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 8),
|
||||
StatusPill.kind(pillKind, label: pillLabel),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 10),
|
||||
Wrap(
|
||||
spacing: 8,
|
||||
runSpacing: 8,
|
||||
crossAxisAlignment: WrapCrossAlignment.center,
|
||||
children: [
|
||||
TechChip(task.category, icon: Icons.category_outlined, dense: true),
|
||||
if (assignee != null && !isMine)
|
||||
Row(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
Icon(Icons.person_outline,
|
||||
size: 14, color: cs.onSurfaceVariant),
|
||||
const SizedBox(width: 4),
|
||||
Text(
|
||||
assignee!.fullName,
|
||||
style:
|
||||
tt.bodySmall?.copyWith(color: cs.onSurfaceVariant),
|
||||
),
|
||||
],
|
||||
),
|
||||
Text(
|
||||
AppTime.relative(task.createdAt),
|
||||
style: tt.bodySmall?.copyWith(color: cs.onSurfaceVariant),
|
||||
),
|
||||
],
|
||||
),
|
||||
if (canStart || canResume) ...[
|
||||
const SizedBox(height: 12),
|
||||
Align(
|
||||
alignment: Alignment.centerRight,
|
||||
child: FilledButton.tonalIcon(
|
||||
onPressed: () =>
|
||||
startProgrammerTaskWithPausePrompt(context, ref, task),
|
||||
icon: const Icon(Icons.play_arrow_rounded, size: 18),
|
||||
label: Text(canResume ? 'Resume' : 'Start'),
|
||||
),
|
||||
),
|
||||
],
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user