Added Agent Availability screen

This commit is contained in:
2026-08-31 15:27:26 +02:00
parent e7508a4c8e
commit 0561109e3c
8 changed files with 171 additions and 30 deletions
@@ -0,0 +1,77 @@
import 'package:ac_web/Api/AcApi.dart';
import 'package:ac_web/Api/Dtos/AgentDto.dart';
import 'package:ac_web/Widgets/AgentStatusIndicator.dart';
import 'package:flutter/material.dart';
/// Fetches all agents from the AgentsController and lists them with a colored
/// status indicator in front of their name.
class AgentAvailabilityColumn extends StatefulWidget{
const AgentAvailabilityColumn({super.key});
@override
State<AgentAvailabilityColumn> createState() => _AgentAvailabilityColumnState();
}
class _AgentAvailabilityColumnState extends State<AgentAvailabilityColumn>{
late Future<List<AgentDto>> mAgentsFuture;
@override
void initState() {
super.initState();
mAgentsFuture = AcApi.instance.agents.getAgents();
}
void ReloadAgents(){
setState(() {
mAgentsFuture = AcApi.instance.agents.getAgents();
});
}
@override
Widget build(BuildContext context) {
return FutureBuilder<List<AgentDto>>(
future: mAgentsFuture,
builder: (context, snapshot) {
if (snapshot.connectionState != ConnectionState.done) {
return const Center(child: CircularProgressIndicator());
}
if (snapshot.hasError) {
return Center(child: Text('Could not load agents: ${snapshot.error}'));
}
// The list of agents fetched from the AgentsController.
final List<AgentDto> agents = snapshot.data ?? <AgentDto>[];
return _buildList(agents);
},
);
}
Widget _buildList(List<AgentDto> agents) {
if (agents.isEmpty) {
return const Center(child: Text("No agents available"));
}
return RefreshIndicator(
onRefresh: () async => ReloadAgents(),
child: ListView.builder(
padding: const EdgeInsets.all(8),
itemCount: agents.length,
itemBuilder: (context, index) {
final AgentDto agent = agents[index];
return ListTile(
leading: AgentStatusIndicator(status: agent.status),
title: Text(agent.name),
subtitle: Text("${agent.type.displayName} - ${agent.status.displayName}"),
);
},
),
);
}
}
@@ -0,0 +1,39 @@
import 'package:ac_web/Api/Dtos/EAgentStatus.dart';
import 'package:flutter/material.dart';
/// Small colored circle that visualizes the current [EAgentStatus] of an agent.
///
/// Green = available, blue = working, red = error, white = unavailable.
class AgentStatusIndicator extends StatelessWidget {
const AgentStatusIndicator({super.key, required this.status, this.size = 16});
final EAgentStatus status;
final double size;
static Color colorOf(EAgentStatus status) {
switch (status) {
case EAgentStatus.available:
return Colors.green;
case EAgentStatus.working:
return Colors.blue;
case EAgentStatus.error:
return Colors.red;
case EAgentStatus.offline:
case EAgentStatus.unknown:
return Colors.white;
}
}
@override
Widget build(BuildContext context) {
return Container(
width: size,
height: size,
decoration: BoxDecoration(
color: colorOf(status),
shape: BoxShape.circle,
border: Border.all(color: Colors.black26),
),
);
}
}