Files
Kifi/scratch/patch_edit_project.py

53 lines
3.3 KiB
Python

import re
with open('kifi-app/lib/features/projects/presentation/widgets/add_project_sheet.dart', 'r') as f:
content = f.read()
# Make AddProjectSheet take a project
content = content.replace("class AddProjectSheet extends ConsumerStatefulWidget {\n const AddProjectSheet({super.key});", "class AddProjectSheet extends ConsumerStatefulWidget {\n final Project? project;\n const AddProjectSheet({super.key, this.project});")
content = content.replace(" String _name = '';\n String _description = '';\n int? _selectedCustomerId;\n double _budget = 0;", """ String _name = '';
String _description = '';
int? _selectedCustomerId;
double _budget = 0;
@override
void initState() {
super.initState();
if (widget.project != null) {
_name = widget.project!.name;
_description = widget.project!.description ?? '';
_selectedCustomerId = widget.project!.customerId;
_budget = widget.project!.budget ?? 0;
}
}""")
content = content.replace("labelText: 'Project Name',\n prefixIcon: const Icon(LucideIcons.folder),", "labelText: 'Project Name',\n initialValue: _name,\n prefixIcon: const Icon(LucideIcons.folder),")
content = content.replace("labelText: 'Description (Optional)',\n prefixIcon: const Icon(LucideIcons.alignLeft),", "labelText: 'Description (Optional)',\n initialValue: _description,\n prefixIcon: const Icon(LucideIcons.alignLeft),")
content = content.replace("labelText: 'Budget (Optional)',\n prefixIcon: const Icon(LucideIcons.indianRupee),", "labelText: 'Budget (Optional)',\n initialValue: _budget > 0 ? _budget.toString() : '',\n prefixIcon: const Icon(LucideIcons.indianRupee),")
content = content.replace("await repo.createProject(\n name: _name,\n description: _description.isNotEmpty ? _description : null,\n customerId: _selectedCustomerId,\n budget: _budget,\n );", """if (widget.project != null) {
await repo.updateProject(
id: widget.project!.id,
name: _name,
description: _description.isNotEmpty ? _description : null,
customerId: _selectedCustomerId,
budget: _budget,
status: widget.project!.status,
);
} else {
await repo.createProject(
name: _name,
description: _description.isNotEmpty ? _description : null,
customerId: _selectedCustomerId,
budget: _budget,
);
}""")
content = content.replace("child: _isLoading ? const CircularProgressIndicator(color: Colors.white) : const Text('Create Project', style: TextStyle(fontSize: 16, fontWeight: FontWeight.bold)),", "child: _isLoading ? const CircularProgressIndicator(color: Colors.white) : Text(widget.project == null ? 'Create Project' : 'Save Changes', style: const TextStyle(fontSize: 16, fontWeight: FontWeight.bold)),")
content = content.replace("const Text('New Project', style: TextStyle(fontSize: 20, fontWeight: FontWeight.bold)),", "Text(widget.project == null ? 'New Project' : 'Edit Project', style: const TextStyle(fontSize: 20, fontWeight: FontWeight.bold)),")
with open('kifi-app/lib/features/projects/presentation/widgets/add_project_sheet.dart', 'w') as f:
f.write(content)