Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added the ability to generate custom_labels with custom ranges. #141

Merged
Merged
Show file tree
Hide file tree
Changes from 10 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ jobs:
uses: "actions/checkout@v4"
- name: "Setup environment"
uses: "networktocode/gh-action-setup-poetry-environment@v6"
with:
poetry-version: "1.8.4"
- name: "Linting: ruff format"
run: "poetry run invoke ruff --action format"
ruff-lint:
Expand All @@ -36,6 +38,8 @@ jobs:
uses: "actions/checkout@v4"
- name: "Setup environment"
uses: "networktocode/gh-action-setup-poetry-environment@v6"
with:
poetry-version: "1.8.4"
- name: "Linting: ruff"
run: "poetry run invoke ruff --action lint"
check-docs-build:
Expand All @@ -47,6 +51,8 @@ jobs:
uses: "actions/checkout@v4"
- name: "Setup environment"
uses: "networktocode/gh-action-setup-poetry-environment@v6"
with:
poetry-version: "1.8.4"
- name: "Check Docs Build"
run: "poetry run invoke build-and-check-docs"
poetry:
Expand All @@ -58,6 +64,8 @@ jobs:
uses: "actions/checkout@v4"
- name: "Setup environment"
uses: "networktocode/gh-action-setup-poetry-environment@v6"
with:
poetry-version: "1.8.4"
- name: "Checking: poetry lock file"
run: "poetry run invoke lock --check"
yamllint:
Expand All @@ -69,6 +77,8 @@ jobs:
uses: "actions/checkout@v4"
- name: "Setup environment"
uses: "networktocode/gh-action-setup-poetry-environment@v6"
with:
poetry-version: "1.8.4"
- name: "Linting: yamllint"
run: "poetry run invoke yamllint"
check-in-docker:
Expand All @@ -91,6 +101,8 @@ jobs:
uses: "actions/checkout@v4"
- name: "Setup environment"
uses: "networktocode/gh-action-setup-poetry-environment@v6"
with:
poetry-version: "1.8.4"
- name: "Constrain Nautobot version and regenerate lock file"
env:
INVOKE_NAUTOBOT_FLOOR_PLAN_LOCAL: "true"
Expand Down Expand Up @@ -146,6 +158,8 @@ jobs:
uses: "actions/checkout@v4"
- name: "Setup environment"
uses: "networktocode/gh-action-setup-poetry-environment@v6"
with:
poetry-version: "1.8.4"
- name: "Constrain Nautobot version and regenerate lock file"
env:
INVOKE_NAUTOBOT_FLOOR_PLAN_LOCAL: "true"
Expand Down Expand Up @@ -187,6 +201,8 @@ jobs:
fetch-depth: "0"
- name: "Setup environment"
uses: "networktocode/gh-action-setup-poetry-environment@v6"
with:
poetry-version: "1.8.4"
- name: "Check for changelog entry"
run: |
git fetch --no-tags origin +refs/heads/${{ github.base_ref }}:refs/remotes/origin/${{ github.base_ref }}
Expand Down
1 change: 1 addition & 0 deletions changes/141.added
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Added boolean option to allow tiles to be moved or not once placed.
1 change: 1 addition & 0 deletions changes/8.added
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Added support for defining custom grid label ranges.
126 changes: 102 additions & 24 deletions docs/admin/install.md
Original file line number Diff line number Diff line change
@@ -1,21 +1,24 @@
# Installing the App in Nautobot

Here you will find detailed instructions on how to **install** and **configure** the App within your Nautobot environment.
This section provides detailed instructions on how to **install** and **configure** the app in your Nautobot environment.

## Prerequisites

- The app is compatible with Nautobot 2.0.0 and higher.
- Databases supported: PostgreSQL, MySQL
- Compatible with Nautobot **2.0.0 and higher**.
- Supported databases: **PostgreSQL** and **MySQL**.

!!! note
Please check the [dedicated page](compatibility_matrix.md) for a full compatibility matrix and the deprecation policy.
For a full compatibility matrix and details about the deprecation policy, refer to the [Compatibility Matrix](compatibility_matrix.md).

## Install Guide

!!! note
Apps can be installed from the [Python Package Index](https://pypi.org/) or locally. See the [Nautobot documentation](https://docs.nautobot.com/projects/core/en/stable/user-guide/administration/installation/app-install/) for more details. The pip package name for this app is [`nautobot-floor-plan`](https://pypi.org/project/nautobot-floor-plan/).
Apps can be installed from the [Python Package Index (PyPI)](https://pypi.org/) or locally. For more details, see the official [Nautobot App Installation Guide](https://docs.nautobot.com/projects/core/en/stable/user-guide/administration/installation/app-install/).
The pip package name for this app is [`nautobot-floor-plan`](https://pypi.org/project/nautobot-floor-plan/).

The app is available as a Python package via PyPI and can be installed with `pip`:
### Step 1: Install the App

Install the app via PyPI using `pip`:

```shell
pip install nautobot-floor-plan
Expand All @@ -27,6 +30,8 @@ To ensure Nautobot Floor Plan is automatically re-installed during future upgrad
echo nautobot-floor-plan >> local_requirements.txt
```

### Step 2: Configure the App

Once installed, the app needs to be enabled in your Nautobot configuration. The following block of code below shows the additional configuration required to be added to your `nautobot_config.py` file:

- Append `"nautobot_floor_plan"` to the `PLUGINS` list.
Expand Down Expand Up @@ -62,30 +67,103 @@ Then restart the Nautobot services which may include:
```shell
sudo systemctl restart nautobot nautobot-worker nautobot-scheduler
```
# Nautobot Floor Plan App Configuration and Customization

If the App has been installed successfully, the Nautobot web UI should now show a new "Location Floor Plans" menu item under the "Organization" menu.
## Verifying Installation

## App Configuration
Once the app is successfully installed, the Nautobot web UI will display a new "Location Floor Plans" menu item under the **Organization** menu.

The app behavior can be controlled with the following list of settings:
## App Configuration Details

| Key | Example | Default | Description |
|--------------------|-----------|----------|------------------------------------------------------------------------------------------------------------------------------------------------|
| default_x_axis_labels | "letters" | "numbers" | Label style for the floor plan grid. Can use `numbers` or `letters` in order. This setting will set the default selected value in the create form. |
| default_y_axis_labels | "numbers" | "numbers" | Label style for the floor plan grid. Can use `numbers` or `letters` in order. This setting will set the default selected value in the create form. |
| default_statuses| "name": "Active", "color": "4caf50"| See Note Below | A list of name and color key value pairs for the FloorPlanTile model|
The app behavior can be customized with the following configuration settings:

| Key | Example | Default | Description |
|------------------------|-------------------------------------------|-------------|------------------------------------------------------------------------------------------------------------------------------------------------|
| `default_x_axis_labels` | `"letters"` | `"numbers"` | Defines the label style for the X-axis of the floor plan grid. Options are `numbers` or `letters`. This sets the default value in the create form. |
| `default_y_axis_labels` | `"numbers"` | `"numbers"` | Defines the label style for the Y-axis of the floor plan grid. Options are `numbers` or `letters`. This sets the default value in the create form. |
| `default_statuses` | `{"name": "Active", "color": "4caf50"}` | See note below | A list of name and color key-value pairs for the **FloorPlanTile** model. |

!!! note
Defaults for statuses are as follows:
Default statuses are configured as follows:

```python
"default_statuses": {
"FloorPlanTile": [
{"name": "Active", "color": "4caf50"},
{"name": "Reserved", "color": "00bcd4"},
{"name": "Decommissioning", "color": "ffc107"},
{"name": "Unavailable", "color": "111111"},
{"name": "Planned", "color": "00bcd4"},
],
},
"default_statuses": {
"FloorPlanTile": [
{"name": "Active", "color": "4caf50"},
{"name": "Reserved", "color": "00bcd4"},
{"name": "Decommissioning", "color": "ffc107"},
{"name": "Unavailable", "color": "111111"},
{"name": "Planned", "color": "00bcd4"},
],
}
```

## Custom Labels

The app supports custom label types, defined in `choices.py`:

```python
class CustomAxisLabelsChoices(ChoiceSet):
"""Choices for custom axis label types."""

ROMAN = "roman"
GREEK = "greek"
BINARY = "binary"
HEX = "hex"
NUMALPHA = "numalpha"
LETTERS = "letters"
ALPHANUMERIC = "alphanumeric"
NUMBERS = "numbers"

CHOICES = (
(ROMAN, "Roman (e.g., I, II, III)"),
(GREEK, "Greek (e.g., α, β, γ)"),
(BINARY, "Binary (e.g., 1, 10, 11)"),
(HEX, "Hexadecimal (e.g., 1, A, F)"),
(NUMALPHA, "numalpha (e.g., 02A)"),
(LETTERS, "Letters (e.g., A, B, C)"),
(ALPHANUMERIC, "Alphanumeric (e.g., A01, B02)"),
(NUMBERS, "Numbers (e.g., 1, 2, 3)"),
)
```

### Adding New Custom Labels

To define new custom label types:

1. Add the new choice to the `CustomAxisLabelsChoices` class in `choices.py`.
2. Implement a corresponding converter class in `label_converters.py`.

#### Label Converter Base Class

All label converters inherit from the base `LabelConverter` class:

```python
class LabelConverter:
"""Base class for label conversion."""

def __init__(self):
"""Initialize converter."""
self.current_label = None

def to_numeric(self, label: str) -> int:
"""Convert label to numeric value."""
raise NotImplementedError

def from_numeric(self, number: int) -> str:
"""Convert numeric value to label."""
raise NotImplementedError
```

The to_numeric and from_numeric methods handle:

- Converting database integer values to display labels on the Floor Plan grid.
- Converting labels back to the corresponding integer values for database storage.

### Label Factory

LabelConverterFactory located in label_converters.py is used to lookup the correct converter that will be used based off of the CustomAxisLabelsChoices class from choices.py to the proper converter class in label_converters.py.

### Validation Logic

Custom label validation is handled in custom_validators.py, ensuring that the labels meet the required format and rules before being applied to the Floor Plan.
3 changes: 0 additions & 3 deletions docs/admin/uninstall.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,6 @@ Prior to removing the app from the `nautobot_config.py`, run the following comma
nautobot-server migrate nautobot_floor_plan zero
```

!!! warning "Developer Note - Remove Me!"
Any other cleanup operations to ensure the database is clean after the app is removed. Is there anything else that needs cleaning up, such as CFs, relationships, etc. if they're no longer desired?

## Remove App configuration

Remove the configuration you added in `nautobot_config.py` from `PLUGINS` & `PLUGINS_CONFIG`.
Expand Down
Binary file modified docs/images/add-floor-plan-form.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/images/add-tile-axis-default.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/images/add-tile-axis-numalpha.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/images/add-tile-axis-roman.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/images/custom-label-examples.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading