diff --git a/src/howitz/endpoints.py b/src/howitz/endpoints.py index b475deb..fb996bd 100644 --- a/src/howitz/endpoints.py +++ b/src/howitz/endpoints.py @@ -16,7 +16,7 @@ from datetime import datetime, timezone -from werkzeug.exceptions import BadRequest, MethodNotAllowed +from werkzeug.exceptions import BadRequest, InternalServerError, MethodNotAllowed from zinolib.controllers.zino1 import Zino1EventManager, RetryError, EventClosedError, UpdateHandler from zinolib.event_types import Event, AdmState, PortState, BFDState, ReachabilityState, LogEntry, HistoryEntry from zinolib.compat import StrEnum @@ -499,6 +499,49 @@ def show_update_events_status_modal(): return render_template('/components/popups/modals/update-event-status-modal.html', current_state='open') +@main.route('/event//poll', methods=["POST"]) +def poll(i): + selected_events = session.get("selected_events", {}) + event_id = int(i) + + poll_res = current_app.event_manager.poll(event_id) + + if poll_res: + event_attr, event_logs, event_history, event_msgs = get_event_details(event_id) + event = create_table_event(current_app.event_manager.create_event_from_id(event_id))["event"] + + return render_template('/responses/update-event-response.html', event=event, id=event_id, event_attr=event_attr, + event_logs=event_logs, + event_history=event_history, event_msgs=event_msgs, + is_selected=str(event_id) in selected_events) + else: + raise InternalServerError(description=f"Unexpected error when polling event #{event_id}") + + +@main.route('/event/bulk_poll', methods=['POST']) +def bulk_poll(): + selected_events = session.get("selected_events", {}) + expanded_events = session.get("expanded_events", {}) + current_app.logger.debug('SELECTED EVENTS %s', selected_events) + current_app.logger.debug('EXPANDED EVENTS %s', expanded_events) + + # Update each selected event with new values + for event_id in selected_events: + poll_res = current_app.event_manager.poll(int(event_id)) + + if not poll_res: + raise InternalServerError(description=f"Unexpected error when polling event #{event_id}") + + # Clear selected events + session["selected_events"] = {} + session.modified = True # Necessary when modifying arrays/dicts/etc in flask session + current_app.logger.debug("SELECTED EVENTS %s", session["selected_events"]) + + # Rerender whole events table + event_list = get_current_events() + return render_template('/responses/bulk-update-events-status.html', event_list=event_list) + + @main.route('/event//unselect', methods=["POST"]) def unselect_event(event_id): session["selected_events"].pop(event_id, None) diff --git a/src/howitz/templates/components/accordion/event-actions-buttons.html b/src/howitz/templates/components/accordion/event-actions-buttons.html index 94a6d49..674689f 100644 --- a/src/howitz/templates/components/accordion/event-actions-buttons.html +++ b/src/howitz/templates/components/accordion/event-actions-buttons.html @@ -6,9 +6,12 @@ {% include "/components/accordion/update-state-btn.html" %} diff --git a/src/howitz/templates/components/popups/bulk-update-menu/bulk-update-buttons.html b/src/howitz/templates/components/popups/bulk-update-menu/bulk-update-buttons.html index 43ae741..6b9fa69 100644 --- a/src/howitz/templates/components/popups/bulk-update-menu/bulk-update-buttons.html +++ b/src/howitz/templates/components/popups/bulk-update-menu/bulk-update-buttons.html @@ -11,10 +11,13 @@