Home Information - Your home, your data, organized.
Python
Fix controller dialog action to stay in modal context (Issue #31) (#67)
cassandra-ai-agentb4aced5dfbb1
diff --git a/docs/CLAUDE.md b/docs/CLAUDE.mdindex 425d082c..e7e54224 100644--- a/docs/CLAUDE.md+++ b/docs/CLAUDE.md@@ -8,7 +8,13 @@ When working on GitHub issues, follow this development workflow:1. **Read the GitHub issue and all its comments** - Understand the requirements, context, and any discussion-2. **Investigate and plan the implementation** - MANDATORY step for all issues:+2. **Ensure you're on the latest staging branch** - MANDATORY step before any work:+ - If coming from a merged PR, run Post-PR Cleanup first (see step 10)+ - Switch to staging branch: `git checkout staging`+ - Pull latest changes: `git pull origin staging`+ - Verify you're on the correct branch: `git status`++3. **Investigate and plan the implementation** - MANDATORY step for all issues:- Assign the issue to yourself: `gh issue edit <issue-number> --add-assignee @me`- Research the codebase to understand current implementation- Identify files, functions, and components that need changes@@ -26,28 +32,43 @@ When working on GitHub issues, follow this development workflow:- The proposed changes have significant architectural implications- Otherwise, proceed directly to implementation-3. **Ensure staging branch is in sync with GitHub** - Make sure you have the latest changes-4. **Create a dev branch off the staging branch** - Follow naming conventions from `docs/dev/Workflow.md`-5. **Do development changes** - Commit to git at logical checkpoints during development-6. **After first commit, push the branch to GitHub** - Use the same branch name as the local one-7. **Once issue is complete and all changes pushed** - Create a pull request using the template-8. **Before creating the pull request** - Run full test validation (see Testing Workflow below)+4. **Initialize development environment** - MANDATORY before any development work:+ - Run environment setup: `. ./init-env-dev.sh`+ - This sets up the virtual environment and all necessary environment variables++5. **Create a dev branch off the staging branch** - Use proper naming convention:+ - **Bug fixes**: `bugfix/##-description` (e.g., `bugfix/31-controller-modal-fix`)+ - **New features**: `feature/##-description` (e.g., `feature/45-weather-alerts`)+ - **Documentation**: `docs/##-description` (e.g., `docs/22-api-documentation`)+ - **Operations**: `ops/##-description` (e.g., `ops/18-docker-improvements`)+ - **Refactoring**: `refactor/##-description` (e.g., `refactor/33-cleanup-views`)+ - See `docs/dev/Workflow.md` for complete conventions including test-only and tweak branches+6. **Do development changes** - Commit to git at logical checkpoints during development+7. **After first commit, push the branch to GitHub** - Use the same branch name as the local one+8. **Once issue is complete and all changes pushed** - Create a pull request using the template+9. **Before creating the pull request** - Run full test validation (see Testing Workflow below)+10. **After pull request is merged** - Clean up and prepare for next work (see Post-PR Cleanup below)### Testing Workflow (Required Before Pull Requests)**MANDATORY**: Before creating any pull request, you must run and pass all of these checks:+**NOTE**: All commands run from PROJECT ROOT directory for consistency.+```bash+# First ensure environment is initialized (if not already done in step 4)+. ./init-env-dev.sh+# 1. Run full unit test suite-./manage.py test+src/manage.py test# Must show: "OK" with all tests passing# 2. Run code quality check (only if source code was modified)-flake8 --config=.flake8-ci hi/+flake8 --config=src/.flake8-ci src/hi/# Must show: no output (clean)# 3. Verify Django configuration-./manage.py check+src/manage.py check# Must show: "System check identified no issues"```@@ -57,15 +78,63 @@ flake8 --config=.flake8-ci hi/Before any pull request can be merged, the following requirements must be met:-1. **Unit Tests**: All unit tests must pass (`./manage.py test`)-2. **Code Quality**: flake8 linting with `.flake8-ci` configuration must pass with no violations (if source code modified)-3. **Django Check**: Django system check must pass with no issues (`./manage.py check`)+1. **Unit Tests**: All unit tests must pass (`src/manage.py test`)+2. **Code Quality**: flake8 linting with `.flake8-ci` configuration must pass with no violations (if source code modified) (`flake8 --config=src/.flake8-ci src/hi/`)+3. **Django Check**: Django system check must pass with no issues (`src/manage.py check`)4. **GitHub CI**: GitHub Actions will automatically verify these requirements and will block PR merging if they failThese requirements are enforced by GitHub branch protection rules and cannot be bypassed.For detailed branching conventions and additional workflow information, see `docs/dev/Workflow.md`.+### Post-PR Cleanup (After Pull Request Merged)++**HUMAN INITIATED**: This workflow must be triggered manually when you confirm a PR has been merged. Never run without explicit confirmation that the PR is merged.++**MANDATORY Safety Checks** - Execute these verification steps before any cleanup actions:++```bash+# 1. Verify current branch is a feature branch (not staging/master)+git branch --show-current+# Must show a feature branch pattern like: bugfix/##-description, feature/##-description, etc.+# STOP if output shows: staging, master, main++# 2. Verify working directory is clean (no uncommitted changes)+git status+# Must show: "nothing to commit, working tree clean"+# STOP if there are uncommitted changes - commit or stash them first++# 3. Verify the PR is actually merged+gh pr view --json state,mergedAt+# Must show: "state": "MERGED" and "mergedAt": with a timestamp+# STOP if state is not "MERGED"+```++**Cleanup Actions** - Only proceed if all safety checks pass:++```bash+# 4. Switch to staging branch+git checkout staging++# 5. Sync with latest remote changes+git pull origin staging++# 6. Delete the merged feature branch (use branch name from step 1)+git branch -d <feature-branch-name>+# Example: git branch -d bugfix/31-controller-modal-fix++# 7. Verify clean final state+git status+# Should show: "On branch staging" and "nothing to commit, working tree clean"+```++**If any safety check fails:**+- **DO NOT proceed** with cleanup actions+- **Address the issue** (commit changes, wait for PR merge, etc.)+- **Re-run verification** before attempting cleanup++This process ensures you're ready for the next issue while preventing accidental data loss.+### Work Documentation for Non-Trivial IssuesWhen working on complex issues that involve significant planning or multi-step implementation:@@ -89,10 +158,10 @@ For detailed setup and daily commands, see [Development Setup](dev/Setup.md).# Daily development setup. ./init-env-dev.sh-# Common commands-cd src && ./manage.py test-cd src && flake8 --config=.flake8-ci src/-./manage.py runserver # http://127.0.0.1:8411+# Common commands (all run from PROJECT ROOT)+src/manage.py test+flake8 --config=src/.flake8-ci src/hi/+src/manage.py runserver # http://127.0.0.1:8411```## Project Documentation References@@ -144,7 +213,7 @@ All generated code must comply with the `.flake8-ci` configuration rules. Common4. **Line Continuation**: Proper indentation for multi-line statements following PEP 85. **Line Length**: Respect maximum line length limits defined in `.flake8-ci`-Before submitting code, always run: `cd src && flake8 --config=.flake8-ci src/` to verify compliance.+Before submitting code, always run: `flake8 --config=src/.flake8-ci src/hi/` to verify compliance.## Commit Message Guidelines (Claude-Specific)diff --git a/docs/dev/Guidelines.md b/docs/dev/Guidelines.mdindex f6b12c6d..9768431a 100644--- a/docs/dev/Guidelines.md+++ b/docs/dev/Guidelines.md@@ -136,6 +136,16 @@ def simple_function():- Follow existing code patterns and conventions in the codebase- Use descriptive variable and function names- Maintain consistency with Django and Python best practices+- **Boolean expressions**: When assigning or returning boolean values, wrap expressions in `bool()` to make intent explicit and improve readability:+ ```python+ # Good - explicit boolean conversion+ is_active = bool(user.last_login)+ in_modal_context = bool(request.POST.get('context') == 'modal')++ # Avoid - implicit boolean conversion+ is_active = user.last_login+ in_modal_context = request.POST.get('context') == 'modal'+ ```## Testing Conventionsdiff --git a/init-env-dev.sh b/init-env-dev.shindex 460f8d85..4e830e8f 100644--- a/init-env-dev.sh+++ b/init-env-dev.sh@@ -1,2 +1,25 @@-. venv/bin/activate-. .private/env/development.sh+# Only activate virtual environment if not already active+# This prevents shell prompt nesting and makes the script idempotent+if [ -z "$VIRTUAL_ENV" ]; then+ if [ -f "venv/bin/activate" ]; then+ . venv/bin/activate+ echo "✓ Virtual environment activated"+ else+ echo "ERROR: Virtual environment not found at venv/bin/activate"+ echo "Please create it first: python3.11 -m venv venv"+ return 1+ fi+else+ echo "✓ Virtual environment already active: $VIRTUAL_ENV"+ echo " (Hint: run 'deactivate' first if you need to switch environments)"+fi++# Source development environment variables+if [ -f ".private/env/development.sh" ]; then+ . .private/env/development.sh+ echo "✓ Development environment variables loaded"+else+ echo "ERROR: Environment file not found at .private/env/development.sh"+ echo "Please create it first: make env-build-dev"+ return 1+fidiff --git a/src/hi/apps/control/templates/control/panes/controller_data.html b/src/hi/apps/control/templates/control/panes/controller_data.htmlindex 2025131d..72c32243 100644--- a/src/hi/apps/control/templates/control/panes/controller_data.html+++ b/src/hi/apps/control/templates/control/panes/controller_data.html@@ -4,8 +4,9 @@class="{{ controller_data.css_class }}" ><form action="{% url 'control_controller' controller_id=controller_data.controller.id %}"method="post"- class="form" data-async="#hi-controller-{{ controller_data.controller.id }}-{{ unique_id }}" data-mode="replace">+ class="form" data-async="#hi-controller-{{ controller_data.controller.id }}-{{ unique_id }}" data-mode="replace"{% if in_modal_context %} data-stay-in-modal="true"{% endif %}>{% csrf_token %}+ <input type="hidden" name="response_context" value="{% if in_modal_context %}modal{% else %}page{% endif %}">{% include_with_fallback controller_data.controller.entity_state.entity_state_type.controller_template_name "control/panes/controller_default.html" %}{% if controller_data.error_list %}diff --git a/src/hi/apps/control/view_mixins.py b/src/hi/apps/control/view_mixins.pyindex c7592a79..4fdb5782 100644--- a/src/hi/apps/control/view_mixins.py+++ b/src/hi/apps/control/view_mixins.py@@ -27,7 +27,8 @@ class ControlViewMixin:request : HttpRequest,controller : Controller,error_list : List[ str ],- override_sensor_value : str = None ) -> HttpResponse:+ override_sensor_value : str = None,+ in_modal_context : bool = False ) -> HttpResponse:latest_sensor_response = StatusDisplayManager().get_latest_sensor_response(entity_state = controller.entity_state,@@ -42,5 +43,6 @@ class ControlViewMixin:context = {'controller_data': controller_data,+ 'in_modal_context': in_modal_context,}return render( request, 'control/panes/controller_data.html', context )diff --git a/src/hi/apps/control/views.py b/src/hi/apps/control/views.pyindex d53de164..4249f8b2 100644--- a/src/hi/apps/control/views.py+++ b/src/hi/apps/control/views.py@@ -71,11 +71,15 @@ class ControllerView( View, ControlViewMixin, ControllerMixin ):value = control_value,)+ response_context = request.POST.get('response_context', 'page')+ in_modal_context = bool(response_context == 'modal')+return self.controller_data_response(request = request,controller = controller,error_list = control_result.error_list,override_sensor_value = override_sensor_value,+ in_modal_context = in_modal_context,)def _get_value_for_missing_input( self, controller : Controller ) -> str:diff --git a/src/hi/apps/entity/templates/entity/panes/entity_state_status_card.html b/src/hi/apps/entity/templates/entity/panes/entity_state_status_card.htmlindex 6970b3dc..4bb45059 100644--- a/src/hi/apps/entity/templates/entity/panes/entity_state_status_card.html+++ b/src/hi/apps/entity/templates/entity/panes/entity_state_status_card.html@@ -6,7 +6,7 @@{% if entity_state_status_data.controller_data_list %}{% for controller_data in entity_state_status_data.controller_data_list %}- {% include "control/panes/controller_data.html" with controller_data=controller_data %}+ {% include "control/panes/controller_data.html" with controller_data=controller_data in_modal_context=True %}{% endfor %}{% else %}diff --git a/src/hi/static/js/antinode.js b/src/hi/static/js/antinode.jsindex 137c0f1e..6fc991be 100644--- a/src/hi/static/js/antinode.js+++ b/src/hi/static/js/antinode.js@@ -557,7 +557,10 @@ function doAutofocusIfNeeded( contentObj ) {function beforeAsyncCall( $node ) {// If the content lies in a modal, then close the modal.- hideModalIfNeeded( $node );+ // Unless the form has data-stay-in-modal attribute.+ if ( ! $node.attr('data-stay-in-modal') ) {+ hideModalIfNeeded( $node );+ }saveScrollBarPositions();};