Initial front end setup.

This commit is contained in:
James Pace 2025-12-27 09:08:25 -05:00
parent c263886829
commit 415b2007ce
9 changed files with 90 additions and 34 deletions

20
CMakeLists.txt Normal file
View File

@ -0,0 +1,20 @@
cmake_minimum_required(VERSION 3.20)
project(am_i_up)
find_package(ament_cmake REQUIRED)
find_package(ament_cmake_python REQUIRED)
ament_python_install_package(${PROJECT_NAME})
install(DIRECTORY
front_end
DESTINATION share/${PROJECT_NAME}/
)
install(DIRECTORY
scripts/
DESTINATION lib/${PROJECT_NAME}/lib
USE_SOURCE_PERMISSIONS
)
ament_package()

View File

@ -15,10 +15,13 @@ import yaml
import ipaddress import ipaddress
import subprocess import subprocess
import os import os
from jinja2 import Environment, FileSystemLoader, select_autoescape
def main(): def main():
facts = Facts() facts = Facts()
routes = Routes(facts) view = View()
routes = Routes(facts, view)
app = web.Application() app = web.Application()
app.add_routes([ app.add_routes([
@ -30,6 +33,24 @@ def main():
]) ])
web.run_app(app) web.run_app(app)
class View:
def __init__(self):
# TODO: Make global for the script directory.
self._env = Environment(
loader=FileSystemLoader(self._find_template_dirs()),
autoescape=select_autoescape()
)
def render_root(self):
return self._env.get_template('base.html').render()
def _find_template_dirs(self):
package_dir = get_package_share_directory('am_i_up')
template_dir = "{}/front_end/templates".format(package_dir)
if not os.path.exists(template_dir):
raise RuntimeError("Could not find template_dir: {}".format(template_dir))
return [template_dir]
class Facts: class Facts:
def __init__(self): def __init__(self):
self._start_time = time.monotonic() self._start_time = time.monotonic()
@ -84,12 +105,13 @@ class Facts:
return project_state_content return project_state_content
class Routes: class Routes:
def __init__(self, facts): def __init__(self, facts, view):
self._facts = facts self._facts = facts
self._view = view
async def root(self, request): async def root(self, request):
text = 'hello!' text = self._view.render_root()
return web.Response(text=text) return web.Response(text=text, content_type='text/html')
async def ping(self, request): async def ping(self, request):
request_dict = await request.json() request_dict = await request.json()

View File

@ -0,0 +1,32 @@
<!doctype html>
<html lang="en">
<head>
<!-- Required meta tags -->
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<!-- Bootstrap CSS -->
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.0.2/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-EVSTQN3/azprG1Anm3QDgpJLIm9Nao0Yz1ztcQTwFspd3yD65VohhpuuCOmLASjC" crossorigin="anonymous">
<title>{% block title %}Robot Status UI{% endblock %}</title>
</head>
<body>
<!-- NavBar -->
<!-- Content -->
<div class="container">
{% block content %}
<div>Hello World!</div>
{% endblock %}
</div>
<!-- Load JS -->
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.0.2/dist/js/bootstrap.bundle.min.js" integrity="sha384-MrcW6ZMFYlzcLA8Nl+NtUVF0sA7MsXsP1UyJoMp4YLEuNSfAP+JcXn/tWtIaxVXM" crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/htmx.org@2.0.8/dist/htmx.min.js"></script>
{% block js %}{% endblock %}
</body>
</html>

View File

@ -8,11 +8,14 @@
<author email="jpace121@gmail.com">James Pace</author> <author email="jpace121@gmail.com">James Pace</author>
<maintainer email="jpace121@gmail.com">James Pace</maintainer> <maintainer email="jpace121@gmail.com">James Pace</maintainer>
<buildtool_depend>ament_cmake_python</buildtool_depend>
<depend>python3-aiohttp</depend> <depend>python3-aiohttp</depend>
<depend>python3-jinja2</depend>
<!-- TODO: Run time dep on ping -->
<exec_depend>rclpy</exec_depend> <exec_depend>rclpy</exec_depend>
<export> <export>
<build_type>ament_python</build_type> <build_type>ament_cmake</build_type>
</export> </export>
</package> </package>

View File

4
scripts/client Executable file
View File

@ -0,0 +1,4 @@
#!/usr/bin/env python3
from am_i_up import client
client.main()

4
scripts/server Executable file
View File

@ -0,0 +1,4 @@
#!/usr/bin/env python3
from am_i_up import server
server.main()

View File

@ -1,4 +0,0 @@
[develop]
script_dir=$base/lib/am_i_up
[install]
install_scripts=$base/lib/am_i_up

View File

@ -1,25 +0,0 @@
from setuptools import setup
package_name = 'am_i_up'
setup(
name=package_name,
version='0.0.1',
packages=[package_name],
data_files=[
('share/ament_index/resource_index/packages', ['resource/' + package_name]),
('share/' + package_name, ['package.xml']),
],
install_requires=['setuptools', 'aiohttp'],
zip_safe=True,
author='James Pace',
author_email='jpace121@gmail.com',
description='TODO',
license='MPL 2.0',
entry_points={
'console_scripts': [
'server = am_i_up.server:main',
'client = am_i_up.client:main'
],
},
)