diff --git a/src/howitz/endpoints.py b/src/howitz/endpoints.py index 33d7ac2c..bbce2f61 100644 --- a/src/howitz/endpoints.py +++ b/src/howitz/endpoints.py @@ -235,12 +235,14 @@ def get_events(): @main.route('/events//expand_row', methods=["GET"]) def expand_event_row(event_id): - event_id = int(event_id) selected_events = session.get("selected_events", []) or [] + session["expanded_events"].append(event_id) + session.modified = True expanded_events = session.get("expanded_events", []) or [] - expanded_events.append(event_id) current_app.logger.debug('EXPANDED EVENTS %s', expanded_events) + event_id = int(event_id) + 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)) @@ -250,16 +252,20 @@ def expand_event_row(event_id): @main.route('/events//collapse_row', methods=["GET"]) def collapse_event_row(event_id): - event_id = int(event_id) - selected_events = session.get("selected_events", []) or [] - expanded_events = session.get("expanded_events", []) or [] + + selected_events = session["selected_events"] + try: - expanded_events.remove(event_id) + session["expanded_events"].remove(event_id) + session.modified = True except ValueError: pass - session["expanded_events"] = expanded_events + # session["expanded_events"] = expanded_events + expanded_events = session.get("expanded_events", []) or [] current_app.logger.debug('EXPANDED EVENTS %s', expanded_events) + event_id = int(event_id) + event = create_table_event(current_app.event_manager.create_event_from_id(event_id)) return render_template('/responses/collapse-row.html', event=event, id=event_id, is_selected=str(event_id) in selected_events) @@ -268,6 +274,7 @@ def collapse_event_row(event_id): @main.route('/event//update_status', methods=['GET', 'POST']) def update_event_status(event_id): event_id = int(event_id) + selected_events = session.get("selected_events", []) or [] event = current_app.event_manager.create_event_from_id(int(event_id)) current_state = event.adm_state @@ -286,7 +293,7 @@ def update_event_status(event_id): return render_template('/components/row/expanded-row.html', event=event, id=event_id, event_attr=event_attr, event_logs=event_logs, - event_history=event_history, event_msgs=event_msgs) + event_history=event_history, event_msgs=event_msgs, is_selected=str(event_id) in selected_events) elif request.method == 'GET': return render_template('/responses/get-update-event-status-form.html', id=event_id, current_state=current_state) @@ -307,7 +314,30 @@ def unselect_event(i): except ValueError: pass - return render_template('/components/row/event-unchecked-box.html', id=i) + event_id = int(i) + + 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)) + + # expanded_events = session.get("expanded_events", []) or [] + # is_expanded = str(i) in session["expanded_events"] + # current_app.logger.debug("EXPANDED EVENTS %s", session["expanded_events"]) + # current_app.logger.debug("is Expanded %s", is_expanded) + + # return render_template('/components/responses/select-expanded-row.html', event=event, id=event_id, + # is_selected=False) + + # if is_expanded: + # return render_template('/responses/unselect-expanded-row.html', event=event, id=event_id, is_selected=False) + # else: + # return render_template('/components/row/event-row.html', event=event, id=event_id, is_selected=False) + + return render_template('/responses/row-toggle-select.html', event=event, id=event_id, event_attr=event_attr, + event_logs=event_logs, + event_history=event_history, event_msgs=event_msgs, is_selected=False, is_expanded=str(i) in session["expanded_events"]) + + + # return render_template('/components/row/event-unchecked-box.html', id=i) @main.route('/event//select', methods=["GET"]) @@ -322,7 +352,31 @@ def select_event(i): # print("SELECTED EVENTS", session["selected_events"]) - return render_template('/components/row/event-checked-box.html', id=i) + event_id = int(i) + + 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)) + + # is_expanded = str(i) in session["expanded_events"] + # current_app.logger.debug("EXPANDED EVENTS %s", session["expanded_events"]) + # current_app.logger.debug("is Expanded %s", is_expanded) + # + # # return render_template('/components/responses/select-expanded-row.html', event=event, id=event_id, + # # is_selected=False) + # + # if is_expanded: + # return render_template('/responses/unselect-expanded-row.html', event=event, id=event_id, is_selected=True) + # else: + # return render_template('/components/row/selected-event-row.html', event=event, id=event_id, is_selected=True) + + # # 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)) + # + return render_template('/responses/row-toggle-select.html', event=event, id=event_id, event_attr=event_attr, + event_logs=event_logs, + event_history=event_history, event_msgs=event_msgs, is_selected=True, is_expanded=str(i) in session["expanded_events"]) + # + # # return render_template('/components/row/event-checked-box.html', id=i) # TODO: replace this with some other HTMX pattern diff --git a/src/howitz/templates/components/row/collapse-btn.html b/src/howitz/templates/components/row/collapse-btn.html index 78228f23..b36041c7 100644 --- a/src/howitz/templates/components/row/collapse-btn.html +++ b/src/howitz/templates/components/row/collapse-btn.html @@ -1,6 +1,6 @@ - +
{{ event.op_state }} @@ -13,7 +13,7 @@
- +
{{ event.adm_state }} diff --git a/src/howitz/templates/components/row/data-cells.html b/src/howitz/templates/components/row/data-cells.html index d38435a6..3f121e58 100644 --- a/src/howitz/templates/components/row/data-cells.html +++ b/src/howitz/templates/components/row/data-cells.html @@ -3,14 +3,14 @@ {% include "/components/row/colored-data-cells.html" %} {% endwith %} {% else %} -{{ event.id }} -{{ +{{ event.id }} +{{ event.op_state }} -{{ event.adm_state }} +{{ event.adm_state }} {% endif %} -{{ event.age }} -{{ event.downtime }} -{{ event.router }} -{{ event.port }} -{{ event.description }} +{{ event.age }} +{{ event.downtime }} +{{ event.router }} +{{ event.port }} +{{ event.description }} diff --git a/src/howitz/templates/components/row/event-checked-box.html b/src/howitz/templates/components/row/event-checked-box.html index 46971dfe..ce61cccc 100644 --- a/src/howitz/templates/components/row/event-checked-box.html +++ b/src/howitz/templates/components/row/event-checked-box.html @@ -6,7 +6,7 @@ checked hx-get="/event/{{ id }}/unselect" hx-trigger='click from:#unselect-event-{{ id }}, dblclick from:#unselect-event-{{ id }} consume' - hx-target="closest td" + hx-target="#event-accordion-row-{{ id }}" hx-swap="outerHTML" > diff --git a/src/howitz/templates/components/row/event-unchecked-box.html b/src/howitz/templates/components/row/event-unchecked-box.html index 4bfdf66d..43c65a3e 100644 --- a/src/howitz/templates/components/row/event-unchecked-box.html +++ b/src/howitz/templates/components/row/event-unchecked-box.html @@ -5,8 +5,9 @@ class="w-4 h-4 rounded focus:ring-blue-600 ring-offset-gray-800 focus:ring-offset-gray-800 focus:ring-2 bg-gray-700 border-gray-500" hx-get="/event/{{ id }}/select" hx-trigger='click from:#select-event-{{ id }}, dblclick from:#select-event-{{ id }} consume' - hx-target="closest td" + hx-target="#event-accordion-row-{{ id }}" hx-swap="outerHTML" + >
diff --git a/src/howitz/templates/components/row/expand-btn.html b/src/howitz/templates/components/row/expand-btn.html index be7d66f8..16c23823 100644 --- a/src/howitz/templates/components/row/expand-btn.html +++ b/src/howitz/templates/components/row/expand-btn.html @@ -1,6 +1,6 @@ + {% if is_selected %} + - {% with padding='px-3 py-2' %} + {% with padding='px-3 py-2' %} - {% if is_selected %} - {% include "/components/row/event-checked-box.html" %} + {% if is_selected %} + {% include "/components/row/event-checked-box.html" %} + {% else %} + {% include "/components/row/event-unchecked-box.html" %} + {% endif %} + + {% with event=event, border_color_level = '500' if is_selected else '700' %} + {% include "/components/row/data-cells.html" %} + {% endwith %} + + {% with id=id, color=event.color, border_color_level = '500' if is_selected else '700' %} + {% include "/components/row/collapse-btn.html" %} + {% endwith %} + + {% endwith %} + + {% else %} - {% include "/components/row/event-unchecked-box.html" %} - {% endif %} + + + {% with padding='px-3 py-2' %} + + {% if is_selected %} + {% include "/components/row/event-checked-box.html" %} + {% else %} + {% include "/components/row/event-unchecked-box.html" %} + {% endif %} - {% with event=event %} - {% include "/components/row/data-cells.html" %} - {% endwith %} + {% with event=event %} + {% include "/components/row/data-cells.html" %} + {% endwith %} - {% with id=id, color=event.color %} - {% include "/components/row/collapse-btn.html" %} - {% endwith %} + {% with id=id, color=event.color %} + {% include "/components/row/collapse-btn.html" %} + {% endwith %} + + {% endwith %} + + + {% endif %} - {% endwith %} - -{% include "/components/accordion/event-details.html" %} + {% include "/components/accordion/event-details.html" %} {% endblock content %} diff --git a/src/howitz/templates/components/row/selected-event-row.html b/src/howitz/templates/components/row/selected-event-row.html new file mode 100644 index 00000000..ad2f2331 --- /dev/null +++ b/src/howitz/templates/components/row/selected-event-row.html @@ -0,0 +1,28 @@ + + {% with padding='px-3 py-2' %} + + {% if is_selected %} + {% include "/components/row/event-checked-box.html" %} + {% else %} + {% include "/components/row/event-unchecked-box.html" %} + {% endif %} + + {% with event=event, border_color_level = '500' if is_selected else '700' %} + {% include "/components/row/data-cells.html" %} + {% endwith %} + + {% with id=id, color=event.color, border_color_level = '500' if is_selected else '700' %} + {% include "/components/row/expand-btn.html" %} + {% endwith %} + + {% endwith %} + + + diff --git a/src/howitz/templates/components/row/selected-expanded-row.html b/src/howitz/templates/components/row/selected-expanded-row.html new file mode 100644 index 00000000..182dc431 --- /dev/null +++ b/src/howitz/templates/components/row/selected-expanded-row.html @@ -0,0 +1,65 @@ +{% block content %} + + {% if is_selected %} + + + {% with padding='px-3 py-2' %} + + {% if is_selected %} + {% include "/components/row/event-checked-box.html" %} + {% else %} + {% include "/components/row/event-unchecked-box.html" %} + {% endif %} + + {% with event=event, border_color_level = '500' if is_selected else '700' %} + {% include "/components/row/data-cells.html" %} + {% endwith %} + + {% with id=id, color=event.color, border_color_level = '500' if is_selected else '700' %} + {% include "/components/row/collapse-btn.html" %} + {% endwith %} + + {% endwith %} + + + {% else %} + + + {% with padding='px-3 py-2' %} + + {% if is_selected %} + {% include "/components/row/event-checked-box.html" %} + {% else %} + {% include "/components/row/event-unchecked-box.html" %} + {% endif %} + + {% with event=event %} + {% include "/components/row/data-cells.html" %} + {% endwith %} + + {% with id=id, color=event.color %} + {% include "/components/row/collapse-btn.html" %} + {% endwith %} + + {% endwith %} + + + {% endif %} + + + + {% include "/components/accordion/event-details.html" %} + +{% endblock content %} \ No newline at end of file diff --git a/src/howitz/templates/components/table/events-table.html b/src/howitz/templates/components/table/events-table.html index 7d9c13aa..f41d4047 100644 --- a/src/howitz/templates/components/table/events-table.html +++ b/src/howitz/templates/components/table/events-table.html @@ -1,5 +1,5 @@ - \ No newline at end of file + diff --git a/src/howitz/templates/responses/row-toggle-select.html b/src/howitz/templates/responses/row-toggle-select.html new file mode 100644 index 00000000..d099899e --- /dev/null +++ b/src/howitz/templates/responses/row-toggle-select.html @@ -0,0 +1,39 @@ +{% if is_selected %} + {% if is_expanded %} + {% with id=id, event=event %} + {% include "/components/row/selected-expanded-row.html" %} + + + {% endwith %} + {% else %} + {% with id=id, event=event %} + {% include "/components/row/selected-event-row.html" %} + {% endwith %} + {% endif %} + + +{% else %} + {% if is_expanded %} + {% with id=id, event=event %} + {% include "/components/row/expanded-row.html" %} + {% endwith %} + + + {% else %} + {% with id=id, event=event %} + {% include "/components/row/event-row.html" %} + {% endwith %} + {% endif %} + +{% endif %} + diff --git a/src/howitz/templates/responses/unselect-expanded-row.html b/src/howitz/templates/responses/unselect-expanded-row.html new file mode 100644 index 00000000..5e54f23d --- /dev/null +++ b/src/howitz/templates/responses/unselect-expanded-row.html @@ -0,0 +1,121 @@ +{% block content %} + + {% if is_selected %} + + + {% with padding='px-3 py-2' %} + + {% if is_selected %} + + {% else %} + + {% endif %} + + {% with event=event, border_color_level = '500' if is_selected else '700' %} + {% include "/components/row/data-cells.html" %} + {% endwith %} + + {% with id=id, color=event.color, border_color_level = '500' if is_selected else '700' %} + {% include "/components/row/collapse-btn.html" %} + {% endwith %} + + {% endwith %} + + + {% else %} + + + {% with padding='px-3 py-2' %} + + {% if is_selected %} + {% include "/components/row/event-checked-box.html" %} + {% else %} + {% include "/components/row/event-unchecked-box.html" %} + {% endif %} + + {% with event=event %} + {% include "/components/row/data-cells.html" %} + {% endwith %} + + {% with id=id, color=event.color %} + {% include "/components/row/collapse-btn.html" %} + {% endwith %} + + {% endwith %} + + + {% endif %} + + + + {% include "/components/accordion/event-details.html" %} + +{% endblock content %} + + + + + +
+
+ + +
+
+
+ + +
+
+ + {% include "/components/row/row-toggle-spinner.html" %} + + + + + +