diff --git a/docker/routlin-dash/app/pages/actions/action.py b/docker/routlin-dash/app/pages/actions/action.py index 7c9b5b5..9b37b75 100644 --- a/docker/routlin-dash/app/pages/actions/action.py +++ b/docker/routlin-dash/app/pages/actions/action.py @@ -55,23 +55,36 @@ def history_revert(): @bp.route('/action/actions/history_clear', methods=['POST']) @require_level('manager') def history_clear(): + selected_uuids = request.form.getlist('selected_uuids') + if not selected_uuids: + flash('No items selected.', 'info') + return redirect(f'/{_PAGE}') count = 0 for fname in os.listdir(SNAPSHOTS_DIR): - fpath = os.path.join(SNAPSHOTS_DIR, fname) - if os.path.isfile(fpath): - os.remove(fpath) - count += 1 + if not fname.endswith('.json'): + continue + if any(fname.endswith(f'-{uuid}.json') for uuid in selected_uuids): + fpath = os.path.join(SNAPSHOTS_DIR, fname) + if os.path.isfile(fpath): + os.remove(fpath) + count += 1 plural = 's' if count != 1 else '' - flash(f'History cleared ({count} record{plural} removed).', 'success') + flash(f'{count} history record{plural} cleared.', 'success') return redirect(f'/{_PAGE}') @bp.route('/action/actions/pending_dismiss', methods=['POST']) @require_level('manager') def pending_dismiss(): - if not get_dashboard_pending(): + pending = get_dashboard_pending() + dismissible = [(u, t, c, usr) for u, t, c, usr in pending if c != 'fix problems'] + if not dismissible: flash('No pending changes to dismiss.', 'info') return redirect(f'/{_PAGE}') - open(DASHBOARD_PENDING, 'w').close() - flash('Pending changes dismissed.', 'success') + keep = [(u, t, c, usr) for u, t, c, usr in pending if c == 'fix problems'] + with open(DASHBOARD_PENDING, 'w') as f: + for u, t, c, usr in keep: + f.write(f'{u} {t} [{c}] ({usr})\n') + plural = 's' if len(dismissible) != 1 else '' + flash(f'{len(dismissible)} pending change{plural} dismissed.', 'success') return redirect(f'/{_PAGE}') diff --git a/docker/routlin-dash/app/pages/actions/content.json b/docker/routlin-dash/app/pages/actions/content.json index cb8feca..e03fdaa 100644 --- a/docker/routlin-dash/app/pages/actions/content.json +++ b/docker/routlin-dash/app/pages/actions/content.json @@ -47,9 +47,8 @@ { "type": "button_danger", "text": "Dismiss All", - "action": "/action/actions/pending_dismiss", - "method": "post", - "disabled": "%NO_PENDING%", + "formaction": "/action/actions/pending_dismiss", + "disabled": "%NO_DISMISSIBLE_PENDING%", "client_requirement": "client_is_manager=" } ] @@ -116,9 +115,8 @@ }, { "type": "button_danger", - "text": "Clear History", - "action": "/action/actions/history_clear", - "method": "post", + "text": "Clear Selected History", + "formaction": "/action/actions/history_clear", "disabled": "%NO_HISTORY%", "client_requirement": "client_is_manager=" } diff --git a/docker/routlin-dash/app/view_page.py b/docker/routlin-dash/app/view_page.py index c4c9ca5..2c72bd5 100644 --- a/docker/routlin-dash/app/view_page.py +++ b/docker/routlin-dash/app/view_page.py @@ -680,7 +680,8 @@ def collect_tokens(): pending_html = '

No pending actions.

' tokens['PENDING_ACTIONS_HTML'] = pending_html - tokens['NO_PENDING'] = 'true' if not pending_items else '' + tokens['NO_PENDING'] = 'true' if not pending_items else '' + tokens['NO_DISMISSIBLE_PENDING'] = 'true' if not any(c != 'fix problems' for _, _, c, _ in pending_items) else '' tokens['APPLY_WARNING'] = ( f'' f'{_load_icon("arrow-right")}'