78 lines
2.1 KiB
Dart
78 lines
2.1 KiB
Dart
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}"),
|
|
);
|
|
},
|
|
),
|
|
);
|
|
}
|
|
}
|