Skip to content

Commit

Permalink
Allow deletion of the last remaining Dashboard
Browse files Browse the repository at this point in the history
  • Loading branch information
kizniche committed Oct 1, 2024
1 parent 267fba8 commit e284399
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@
- Fix restoring mycodo/user_scripts during upgrade
- Fix documentation generation

### Miscellaneous

- Allow deletion of the last remaining Dashboard


## 8.16.0 (2024.09.29)

Expand Down
9 changes: 7 additions & 2 deletions mycodo/mycodo_flask/utils/utils_dashboard.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,11 +129,11 @@ def dashboard_del(form):
action=TRANSLATIONS['delete']['title'],
controller=TRANSLATIONS['dashboard']['title'])
error = []
create_new_dash = False

dashboards = Dashboard.query.all()
if len(dashboards) == 1:
flash('Cannot delete the only remaining dashboard.', 'error')
return
create_new_dash = True

widgets = Widget.query.filter(
Widget.dashboard_id == form.dashboard_id.data).all()
Expand All @@ -142,6 +142,11 @@ def dashboard_del(form):

delete_entry_with_id(Dashboard, form.dashboard_id.data)

if create_new_dash:
new_dash = Dashboard()
new_dash.name = 'New Dashboard'
new_dash.save()

flash_success_errors(
error, action, url_for('routes_dashboard.page_dashboard_default'))

Expand Down

0 comments on commit e284399

Please sign in to comment.