mirror of
https://github.com/FoggedLens/deflock-app.git
synced 2026-02-12 16:52:51 +00:00
216 lines
7.4 KiB
Dart
216 lines
7.4 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:provider/provider.dart';
|
|
|
|
import '../app_state.dart';
|
|
import '../models/node_profile.dart';
|
|
import '../models/operator_profile.dart';
|
|
import '../state/settings_state.dart';
|
|
import 'refine_tags_sheet.dart';
|
|
|
|
class EditNodeSheet extends StatelessWidget {
|
|
const EditNodeSheet({super.key, required this.session});
|
|
|
|
final EditNodeSession session;
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
final appState = context.watch<AppState>();
|
|
|
|
void _commit() {
|
|
appState.commitEditSession();
|
|
Navigator.pop(context);
|
|
ScaffoldMessenger.of(context).showSnackBar(
|
|
const SnackBar(content: Text('Node edit queued for upload')),
|
|
);
|
|
}
|
|
|
|
void _cancel() {
|
|
appState.cancelEditSession();
|
|
Navigator.pop(context);
|
|
}
|
|
|
|
final submittableProfiles = appState.enabledProfiles.where((p) => p.isSubmittable).toList();
|
|
final isSandboxMode = appState.uploadMode == UploadMode.sandbox;
|
|
final allowSubmit = appState.isLoggedIn && submittableProfiles.isNotEmpty && session.profile.isSubmittable && !isSandboxMode;
|
|
|
|
void _openRefineTags() async {
|
|
final result = await Navigator.push<OperatorProfile?>(
|
|
context,
|
|
MaterialPageRoute(
|
|
builder: (context) => RefineTagsSheet(
|
|
selectedOperatorProfile: session.operatorProfile,
|
|
),
|
|
fullscreenDialog: true,
|
|
),
|
|
);
|
|
if (result != session.operatorProfile) {
|
|
appState.updateEditSession(operatorProfile: result);
|
|
}
|
|
}
|
|
|
|
return Padding(
|
|
padding:
|
|
EdgeInsets.only(bottom: MediaQuery.of(context).viewInsets.bottom),
|
|
child: Column(
|
|
mainAxisSize: MainAxisSize.min,
|
|
children: [
|
|
const SizedBox(height: 12),
|
|
Container(
|
|
width: 40,
|
|
height: 4,
|
|
decoration: BoxDecoration(
|
|
color: Colors.grey.shade400,
|
|
borderRadius: BorderRadius.circular(2),
|
|
),
|
|
),
|
|
const SizedBox(height: 8),
|
|
Text(
|
|
'Edit Node #${session.originalNode.id}',
|
|
style: Theme.of(context).textTheme.titleMedium,
|
|
),
|
|
const SizedBox(height: 16),
|
|
ListTile(
|
|
title: const Text('Profile'),
|
|
trailing: DropdownButton<NodeProfile>(
|
|
value: session.profile,
|
|
items: submittableProfiles
|
|
.map((p) => DropdownMenuItem(value: p, child: Text(p.name)))
|
|
.toList(),
|
|
onChanged: (p) =>
|
|
appState.updateEditSession(profile: p ?? session.profile),
|
|
),
|
|
),
|
|
ListTile(
|
|
title: Text('Direction ${session.directionDegrees.round()}°'),
|
|
subtitle: Slider(
|
|
min: 0,
|
|
max: 359,
|
|
divisions: 359,
|
|
value: session.directionDegrees,
|
|
label: session.directionDegrees.round().toString(),
|
|
onChanged: session.profile.requiresDirection
|
|
? (v) => appState.updateEditSession(directionDeg: v)
|
|
: null, // Disables slider when requiresDirection is false
|
|
),
|
|
),
|
|
if (!session.profile.requiresDirection)
|
|
Padding(
|
|
padding: const EdgeInsets.fromLTRB(16, 0, 16, 12),
|
|
child: Row(
|
|
children: [
|
|
Icon(Icons.info_outline, color: Colors.grey, size: 16),
|
|
SizedBox(width: 6),
|
|
Expanded(
|
|
child: Text(
|
|
'This profile does not require a direction.',
|
|
style: TextStyle(color: Colors.grey, fontSize: 12),
|
|
),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
if (!appState.isLoggedIn)
|
|
Padding(
|
|
padding: const EdgeInsets.fromLTRB(16, 0, 16, 12),
|
|
child: Row(
|
|
children: [
|
|
Icon(Icons.info_outline, color: Colors.red, size: 20),
|
|
SizedBox(width: 6),
|
|
Expanded(
|
|
child: Text(
|
|
'You must be logged in to edit nodes. Please log in via Settings.',
|
|
style: TextStyle(color: Colors.red, fontSize: 13),
|
|
),
|
|
),
|
|
],
|
|
),
|
|
)
|
|
else if (isSandboxMode)
|
|
Padding(
|
|
padding: const EdgeInsets.fromLTRB(16, 0, 16, 12),
|
|
child: Row(
|
|
children: [
|
|
Icon(Icons.info_outline, color: Colors.blue, size: 20),
|
|
SizedBox(width: 6),
|
|
Expanded(
|
|
child: Text(
|
|
'Cannot submit edits on production nodes to sandbox. Switch to Production mode in Settings to edit nodes.',
|
|
style: TextStyle(color: Colors.blue, fontSize: 13),
|
|
),
|
|
),
|
|
],
|
|
),
|
|
)
|
|
else if (submittableProfiles.isEmpty)
|
|
Padding(
|
|
padding: const EdgeInsets.fromLTRB(16, 0, 16, 12),
|
|
child: Row(
|
|
children: [
|
|
Icon(Icons.info_outline, color: Colors.red, size: 20),
|
|
SizedBox(width: 6),
|
|
Expanded(
|
|
child: Text(
|
|
'Enable a submittable profile in Settings to edit nodes.',
|
|
style: TextStyle(color: Colors.red, fontSize: 13),
|
|
),
|
|
),
|
|
],
|
|
),
|
|
)
|
|
else if (!session.profile.isSubmittable)
|
|
Padding(
|
|
padding: const EdgeInsets.fromLTRB(16, 0, 16, 12),
|
|
child: Row(
|
|
children: [
|
|
Icon(Icons.info_outline, color: Colors.orange, size: 20),
|
|
SizedBox(width: 6),
|
|
Expanded(
|
|
child: Text(
|
|
'This profile is for map viewing only. Please select a submittable profile to edit nodes.',
|
|
style: TextStyle(color: Colors.orange, fontSize: 13),
|
|
),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
const SizedBox(height: 8),
|
|
Padding(
|
|
padding: const EdgeInsets.symmetric(horizontal: 16.0),
|
|
child: SizedBox(
|
|
width: double.infinity,
|
|
child: OutlinedButton.icon(
|
|
onPressed: _openRefineTags,
|
|
icon: const Icon(Icons.tune),
|
|
label: Text(session.operatorProfile != null
|
|
? 'Refine Tags (${session.operatorProfile!.name})'
|
|
: 'Refine Tags'),
|
|
),
|
|
),
|
|
),
|
|
const SizedBox(height: 8),
|
|
Padding(
|
|
padding: const EdgeInsets.symmetric(horizontal: 16.0),
|
|
child: Row(
|
|
children: [
|
|
Expanded(
|
|
child: OutlinedButton(
|
|
onPressed: _cancel,
|
|
child: const Text('Cancel'),
|
|
),
|
|
),
|
|
const SizedBox(width: 12),
|
|
Expanded(
|
|
child: ElevatedButton(
|
|
onPressed: allowSubmit ? _commit : null,
|
|
child: const Text('Save Edit'),
|
|
),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
const SizedBox(height: 20),
|
|
],
|
|
),
|
|
);
|
|
}
|
|
} |