Full agent admin via API and UI
This commit is contained in:
1 parent
5351144edf
commit
08f0668997
7 files changed
+389
-32
No files matched your search
@@ -0,0 +1,105 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'app_menu.dart';
|
||||
import 'backend.dart';
|
||||
import 'chat_screen.dart';
|
||||
|
||||
class ConfigField {
|
||||
final String name;
|
||||
final String type;
|
||||
final TextEditingController controller;
|
||||
|
||||
ConfigField({required this.name, required this.type, required this.controller});
|
||||
}
|
||||
|
||||
class AgentScreen extends StatefulWidget {
|
||||
final int agentId;
|
||||
|
||||
AgentScreen({required this.agentId});
|
||||
|
||||
@override
|
||||
_AgentScreenState createState() => _AgentScreenState();
|
||||
}
|
||||
|
||||
class _AgentScreenState extends State<AgentScreen> {
|
||||
String? _title;
|
||||
final TextEditingController nameController = TextEditingController();
|
||||
List<ConfigField> configFields = [];
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_loadConfigFields();
|
||||
}
|
||||
|
||||
void _loadConfigFields() async {
|
||||
final response = await Backend.sendAction('get-agent-config-fields', {'agentId': widget.agentId});
|
||||
setState(() {
|
||||
configFields = response['fields'].map((jsonField) {
|
||||
return ConfigField(
|
||||
name: jsonField['name'],
|
||||
type: jsonField['type'],
|
||||
controller: TextEditingController(text: jsonField['value']),
|
||||
);
|
||||
}).toList();
|
||||
});
|
||||
}
|
||||
|
||||
void _saveChanges() async {
|
||||
// Backend.invalidateCache(agent: true);
|
||||
final dataObject = {};
|
||||
for (var configField in configFields) {
|
||||
dataObject[configField.name] = configField.controller.text;
|
||||
}
|
||||
await Backend.sendAction("update-agent", {
|
||||
'agentId': widget.agentId,
|
||||
'data': dataObject,
|
||||
});
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(content: Text('Agent Updated.')),
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
title: Text(_title?? 'Agent ${widget.agentId}'),
|
||||
actions: [
|
||||
IconButton(icon: Icon(Icons.settings), onPressed: () {
|
||||
Navigator.push(context, MaterialPageRoute(builder: (_) => AppMenu()));
|
||||
}),
|
||||
],
|
||||
),
|
||||
body: Center(
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(16.0),
|
||||
child: Column(
|
||||
children: [
|
||||
ListView.builder(
|
||||
shrinkWrap: true,
|
||||
itemCount: configFields.length,
|
||||
itemBuilder: (context, index) {
|
||||
return Padding(
|
||||
padding: const EdgeInsets.only(bottom: 8.0),
|
||||
child: TextField(
|
||||
keyboardType: TextInputType.multiline,
|
||||
minLines: 1,
|
||||
maxLines: 8,
|
||||
controller: configFields[index].controller,
|
||||
decoration: InputDecoration(labelText: configFields[index].name),
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
SizedBox(height: 20),
|
||||
ElevatedButton(
|
||||
onPressed: _saveChanges,
|
||||
child: Text('Save'),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user