Initial commit.

This commit is contained in:
Yaro Kasear 2025-06-11 09:10:41 -05:00
commit 189f73b7c2
34 changed files with 1064 additions and 0 deletions

View file

@ -0,0 +1,75 @@
{% macro render_table(headers, rows, entry_route=None, title=None) %}
<div class="table-responsive">
<table
class="table table-bordered table-sm table-hover table-striped table-light m-0{% if title %} caption-top{% endif %}">
{% if title %}
<caption>{{ title }}</caption>
{% endif %}
<thead class="sticky-top">
<tr>
{% for h in headers %}
<th>{{ h }}</th>
{% endfor %}
</tr>
</thead>
<tbody>
{% for row in rows %}
<tr {% if entry_route %}onclick="window.location='{{ url_for('main.' + entry_route, id=row.id) }}'"
style="cursor: pointer;" {% endif %}>
{% for cell in row.cells %}
<td {% if cell.type=='bool' %}class="text-center" {% endif %}>
{% if cell.type == 'bool' %}
{{ cell.html | safe }}
{% elif cell.url %}
<a href="{{ cell.url }}">{{ cell.text }}</a>
{% else %}
{{ cell.text or '-' }}
{% endif %}
</td>
{% endfor %}
</tr>
{% endfor %}
</tbody>
</table>
</div>
{% endmacro %}
{% macro render_pagination(endpoint, page, has_prev, has_next, total_pages, page_variable='page', extra_args={}) %}
{% set prev_args = extra_args.copy() %}
{% set next_args = extra_args.copy() %}
{% set first_args = extra_args.copy() %}
{% set last_args = extra_args.copy() %}
{% set _ = prev_args.update({page_variable: page - 1}) %}
{% set _ = next_args.update({page_variable: page + 1}) %}
{% set _ = first_args.update({page_variable: 1}) %}
{% set _ = last_args.update({page_variable: total_pages}) %}
<div class="d-flex justify-content-between pt-3 px-5 align-items-center">
<div>
<a href="{{ url_for(endpoint, **first_args) }}"
class="btn btn-primary{% if not has_prev %} disabled{% endif %}">&laquo; First</a>
<a href="{{ url_for(endpoint, **prev_args) }}"
class="btn btn-primary{% if not has_prev %} disabled{% endif %}">&lt; Prev</a>
</div>
<div class="d-flex flex-column align-items-center text-center pt-3">
<div>Page {{ page }} of {{ total_pages }}</div>
<div>
{% for number in range(page - 2, page + 3) if number > 0 and number <= total_pages %} {% set
args=extra_args.copy() %} {% set _=args.update({page_variable: number}) %} <a
href="{{ url_for(endpoint, **args) }}"
class="btn btn-sm {% if number == page %}btn-primary{% else %}btn-outline-primary{% endif %} mx-1">
{{ number }}
</a>
{% endfor %}
</div>
</div>
<div>
<a href="{{ url_for(endpoint, **next_args) }}"
class="btn btn-primary{% if not has_next %} disabled{% endif %}">Next &gt;</a>
<a href="{{ url_for(endpoint, **last_args) }}"
class="btn btn-primary{% if not has_next %} disabled{% endif %}">Last &raquo;</a>
</div>
</div>
{% endmacro %}

21
templates/index.html Normal file
View file

@ -0,0 +1,21 @@
<!-- templates/index.html -->
{% extends "layout.html" %}
{% import "_table_fragment.html" as tables %}
{% block title %}{{ title }}{% endblock %}
{% block content %}
<h1 class="text-center display-3">Table of Contents</h1>
<div class="row text-center m-5">
<div class="col">
<a class="link-success link-underline-opacity-0" href="{{ url_for('main.list_inventory') }}">Inventory</a>
</div>
<div class="col">
<a class="link-success link-underline-opacity-0" href="{{ url_for('main.list_users') }}">Users</a>
</div>
<div class="col">
<a class="link-success link-underline-opacity-0" href="{{ url_for('main.list_worklog') }}">Work Log</a>
</div>
</div>
{% endblock %}

127
templates/inventory.html Normal file
View file

@ -0,0 +1,127 @@
<!-- templates/inventory.html -->
{% extends "layout.html" %}
{% import "_table_fragment.html" as tables %}
{% block title %}{{ title }}{% endblock %}
{% block content %}
<nav>
<ol class="breadcrumb">
<li class="breadcrumb-item"><a href="{{ url_for('index') }}">
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-house" viewBox="0 0 16 16">
<path d="M8.707 1.5a1 1 0 0 0-1.414 0L.646 8.146a.5.5 0 0 0 .708.708L2 8.207V13.5A1.5 1.5 0 0 0 3.5 15h9a1.5 1.5 0 0 0 1.5-1.5V8.207l.646.647a.5.5 0 0 0 .708-.708L13 5.793V2.5a.5.5 0 0 0-.5-.5h-1a.5.5 0 0 0-.5.5v1.293zM13 7.207V13.5a.5.5 0 0 1-.5.5h-9a.5.5 0 0 1-.5-.5V7.207l5-5z"/>
</svg>
</a></li>
<li class="breadcrumb-item"><a href="{{ url_for('main.list_inventory') }}">Inventory</a></li>
<li class="breadcrumb-item active">{{ item.identifier }}</li>
</ol>
</nav>
<div class="container">
<form action="POST">
<div class="row">
<div class="col-6">
<label for="timestamp" class="form-label">Date Entered</label>
<input type="date" class="form-control" name="timestamp" value="{{ item.timestamp.date().isoformat() }}">
</div>
<div class="col-6">
<label for="identifier" class="form-label">Identifier</label>
<input type="text" class="form-control-plaintext" value="{{ item.identifier }}" readonly>
</div>
</div>
<div class="row">
<div class="col-4">
<label for="inventory_name" class="form-label">Inventory #</label>
<input type="text" class="form-control" name="inventory_name" placeholder="-" value="{{ item.inventory_name if item.inventory_name else '' }}">
</div>
<div class="col-4">
<label for="serial" class="form-label">Serial #</label>
<input type="text" class="form-control" name="serial" placeholder="-" value="{{ item.serial if item.serial else '' }}">
</div>
<div class="col-4">
<label for="barcode" class="form-label">Bar Code #</label>
<input type="text" class="form-control" name="barcode" placeholder="-" value="{{ item.barcode if item.barcode else '' }}">
</div>
</div>
<div class="row">
<div class="col-4">
<label for="brand" class="form-label">Brand</label>
<input list="brandList" id="brand" name="brand" class="form-control" placeholder="-" value="{{ item.brand.name }}">
<input type="hidden" id="brandId">
<datalist id="brandList">
{% for brand in brands %}
<option data-id="{{ brand.id }}" value="{{ brand.name }}"></option>
{% endfor %}
</datalist>
</div>
<div class="col-4">
<label for="model" class="form-label">Model</label>
<input type="text" class="form-control" name="model" placeholder="-" value="{{ item.model }}">
</div>
<div class="col-4">
<label for="category" class="form-label">Category</label>
<input type="text" class="form-control" name="category" placeholder="-" value="{{ item.item.description }}">
</div>
</div>
<div class="row">
<div class="col-4">
<label for="owner" class="form-label">Contact</label>
<input list="userList" id="owner" class="form-control" name="owner" placeholder="-" value="{{ item.owner.full_name }}">
<input type="hidden" id="userId">
<datalist id="userList">
{% for user in users %}
<option data-id="{{ user.id }}" value="{{ user.full_name }}"></option>
{% endfor %}
</datalist>
</div>
<div class="col-4">
<label for="location" class="form-label">Location</label>
<input list="roomList" id="location" class="form-control" name="location" placeholder="-" value="{{ item.location.full_name }}">
<input type="hidden" id="roomId">
<datalist id="roomList">
{% for room in rooms %}
<option data-id="{{ room.id }}" value="{{ room.full_name }}"></option>
{% endfor %}
</datalist>
</div>
<div class="col-2">
<label for="condition" class="form-label">Condition</label>
<select name="condition" id="" class="form-select" value="{{ item.condition }}">
{% for condition in ["Working", "Deployed", "Partially Inoperable", "Inoperable", "Unverified", "Removed", "Disposed"] %}
<option value="{{ condition }}">{{ condition }}</option>
{% endfor %}
</select>
</div>
<div class="col-2 d-flex align-items-center justify-content-center" style="margin-top: 1.9rem;">
<div class="form-check mb-0">
<input type="checkbox" class="form-check-input" id="shared" name="shared" {% if item.shared %}checked{% endif %}>
<label for="shared" class="form-check-label">Shared?</label>
</div>
</div>
</div>
<div class="row">
<div class="col-{% if worklog %}6{% else %}12{% endif %}">
<label for="notes" class="form-label">Notes &amp; Comments</label>
<textarea name="notes" id="notes" class="form-control" rows="10">{{ item.notes if item.notes else '' }}</textarea>
</div>
{% if worklog %}
<div class="col-6">
{{ tables.render_table(worklog_headers, worklog_rows, 'worklog_entry', 'Work Log') }}
{% if worklog_pagination['total_pages'] > 1 %}
{{ tables.render_pagination(
page=worklog_pagination['page'],
has_prev=worklog_pagination['has_prev'],
has_next=worklog_pagination['has_next'],
total_pages=worklog_pagination['total_pages'],
endpoint='main.inventory_item',
page_variable='worklog_page',
extra_args={'id': item.id, 'worklog_page': worklog_page}
) }}
{% endif %}
</div>
{% endif %}
</div>
</form>
</div>
{% endblock %}

53
templates/layout.html Normal file
View file

@ -0,0 +1,53 @@
<!-- templates/layout.html -->
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>{% block title %}Inventory{% endblock %}</title>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.6/dist/css/bootstrap.min.css" rel="stylesheet"
integrity="sha384-4Q6Gf2aSP4eDXB8Miphtr37CMZZQ5oXLH2yaXMJ2w8e2ZtHTl7GptT4jmndRuHDT" crossorigin="anonymous">
<style>
{% block style %}
.sticky-top {
position: sticky;
top: 0;
z-index: 1020;
}
table td,
th {
white-space: nowrap;
}
input[type="checkbox"][disabled] {
pointer-events: none;
opacity: 1;
filter: none;
appearance: auto;
-webkit-appearance: checkbox;
background-color: white !important;
color: black !important;
}
input[type="checkbox"][disabled]::-moz-checkbox {
background-color: white;
}
{% endblock %}
</style>
</head>
<body class="bg-tertiary text-primary-emphasis">
<header class="bg-success text-light p-2">
<h1>{{ title }}</h1>
</header>
<main class="container-flex m-5">{% block content %}{% endblock %}</main>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.6/dist/js/bootstrap.bundle.min.js"
integrity="sha384-j1CDi7MgGQ12Z7Qab0qlWQ/Qqz24Gc6BM0thvEMVjHnfYGF0rmFCozFSxQBxwHKO"
crossorigin="anonymous"></script>
<script>{% block script %}{% endblock %}</script>
</body>
</html>

20
templates/table.html Normal file
View file

@ -0,0 +1,20 @@
<!-- templates/table.html -->
{% extends "layout.html" %}
{% block title %}{{ title }}{% endblock %}
{% block content %}
<ol class="breadcrumb">
<li class="breadcrumb-item"><a href="{{ url_for('index') }}">
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-house" viewBox="0 0 16 16">
<path d="M8.707 1.5a1 1 0 0 0-1.414 0L.646 8.146a.5.5 0 0 0 .708.708L2 8.207V13.5A1.5 1.5 0 0 0 3.5 15h9a1.5 1.5 0 0 0 1.5-1.5V8.207l.646.647a.5.5 0 0 0 .708-.708L13 5.793V2.5a.5.5 0 0 0-.5-.5h-1a.5.5 0 0 0-.5.5v1.293zM13 7.207V13.5a.5.5 0 0 1-.5.5h-9a.5.5 0 0 1-.5-.5V7.207l5-5z"/>
</svg>
</a></li>
<li class="breadcrumb-item active">{{ title }}</li>
</ol>
{% import "_table_fragment.html" as tables %}
{{ tables.render_table(header, rows, entry_route) }}
{{ tables.render_pagination(endpoint, page, has_prev, has_next, total_pages) }}
{% endblock %}

130
templates/user.html Normal file
View file

@ -0,0 +1,130 @@
<!-- templates/user.html -->
{% extends "layout.html" %}
{% import "_table_fragment.html" as tables %}
{% block title %}{{ title }}{% endblock %}
{% block content %}
<nav>
<ol class="breadcrumb">
<li class="breadcrumb-item"><a href="{{ url_for('index') }}">
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-house" viewBox="0 0 16 16">
<path d="M8.707 1.5a1 1 0 0 0-1.414 0L.646 8.146a.5.5 0 0 0 .708.708L2 8.207V13.5A1.5 1.5 0 0 0 3.5 15h9a1.5 1.5 0 0 0 1.5-1.5V8.207l.646.647a.5.5 0 0 0 .708-.708L13 5.793V2.5a.5.5 0 0 0-.5-.5h-1a.5.5 0 0 0-.5.5v1.293zM13 7.207V13.5a.5.5 0 0 1-.5.5h-9a.5.5 0 0 1-.5-.5V7.207l5-5z"/>
</svg>
</a></li>
<li class="breadcrumb-item"><a href="{{ url_for('main.list_users') }}">Users</a></li>
<li class="breadcrumb-item active">{{ user.full_name }}</li>
</ol>
</nav>
<div class="container">
<form action="POST">
<div class="row">
<div class="col-6">
<label for="lastName" class="form-label">Last Name</label>
<input type="text" class="form-control" id="lastName" placeholder="Doe" value="{{ user.last_name }}">
</div>
<div class="col-6">
<label for="firstName" class="form-label">First Name</label>
<input type="text" class="form-control" id="firstName" placeholder="John" value="{{ user.first_name }}">
</div>
</div>
<div class="row mt-2">
<div class="col-6">
<label for="supervisor" class="form-label">Supervisor</label>
<input list="supervisorList" id="supervisor" name="supervisorName" class="form-control"
value="{{ user.supervisor.full_name }}">
<input type="hidden" id="supervisorId">
<datalist id="supervisorList">
{% for supervisor in users %}
<option data-id="{{ supervisor.id }}" value="{{ supervisor.full_name }}"></option>
{% endfor %}
</datalist>
</div>
<div class="col-6">
<label for="location" class="form-label">Location</label>
<input list="locationList" id="location" name="locationName" class="form-control"
value="{{ user.location.full_name }}">
<input type="hidden" id="locationId">
<datalist id="locationList">
{% for location in rooms %}
<option data-id="{{ location.id }}" value="{{ location.full_name }}"></option>
{% endfor %}
</datalist>
</div>
</div>
<div class="row mt-4">
<div class="col-6">
<input type="checkbox" class="form-check-input" id="activeCheck" {% if user.active %}checked{% endif %}>
<label for="activeCheck" class="form-check-label">Active</label>
</div>
<div class="col-6">
<input type="checkbox" class="form-check-input" id="staffCheck" {% if user.staff %}checked{% endif %}>
<label for="staffCheck" class="form-check-label">Staff</label>
</div>
</div>
</form>
<div class="row mt-3">
{% if inventory_rows %}
<div class="col-6">
<div class="row">
{{ tables.render_table(inventory_headers, inventory_rows, 'inventory_item', title='Assets') }}
</div>
</div>
{% endif %}
{% if worklog_rows %}
<div class="col-6">
<div class="row">
{{ tables.render_table(worklog_headers, worklog_rows, 'worklog_entry', title='Work Done') }}
</div>
</div>
{% endif %}
</div>
<div class="row">
{% if inventory_pagination['total_pages'] > 1 %}
<div class="col-6">
{{ tables.render_pagination(
page=inventory_pagination['page'],
has_prev=inventory_pagination['has_prev'],
has_next=inventory_pagination['has_next'],
total_pages=inventory_pagination['total_pages'],
endpoint='main.user',
page_variable='asset_page',
extra_args={'id': user.id, 'worklog_page': worklog_page}
) }}
</div>
{% endif %}
{% if worklog_pagination['total_pages'] > 1 %}
<div class="col-6">
{{ tables.render_pagination(
page=worklog_pagination['page'],
has_prev=worklog_pagination['has_prev'],
has_next=worklog_pagination['has_next'],
total_pages=worklog_pagination['total_pages'],
endpoint='main.user',
page_variable='worklog_page',
extra_args={'id': user.id, 'worklog_page': worklog_page}
) }}
</div>
{% endif %}
</div>
</div>
{% endblock %}
{% block script %}
document.getElementById('supervisor').addEventListener('input', function() {
const input = this.value;
const options = document.querySelectorAll('#supervisorList option');
let foundId = '';
options.forEach(option => {
if (option.value === input) {
foundId = option.dataset.id;
}
})
document.getElementById('supervisorId').value = foundId;
});
{% endblock %}

60
templates/worklog.html Normal file
View file

@ -0,0 +1,60 @@
<!-- templates/worklog.html -->
{% extends "layout.html" %}
{% import "_table_fragment.html" as tables %}
{% block title %}{{ title }}{% endblock %}
{% block content %}
<nav>
<ol class="breadcrumb">
<li class="breadcrumb-item"><a href="{{ url_for('index') }}">
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-house" viewBox="0 0 16 16">
<path d="M8.707 1.5a1 1 0 0 0-1.414 0L.646 8.146a.5.5 0 0 0 .708.708L2 8.207V13.5A1.5 1.5 0 0 0 3.5 15h9a1.5 1.5 0 0 0 1.5-1.5V8.207l.646.647a.5.5 0 0 0 .708-.708L13 5.793V2.5a.5.5 0 0 0-.5-.5h-1a.5.5 0 0 0-.5.5v1.293zM13 7.207V13.5a.5.5 0 0 1-.5.5h-9a.5.5 0 0 1-.5-.5V7.207l5-5z"/>
</svg>
</a></li>
<li class="breadcrumb-item"><a href="{{ url_for('main.list_worklog') }}">Work Log</a></li>
<li class="breadcrumb-item active">{{ title }}</li>
</ol>
<div class="container">
<form action="POST">
<div class="row">
<div class="col-6">
<label for="start" class="form-label">Start Timestamp</label>
<input type="date" class="form-control" name="start" placeholder="-" value="{{ log.start_time.date().isoformat() if log.start_time }}">
</div>
<div class="col-6">
<label for="end" class="form-label">End Timestamp</label>
<input type="date" class="form-control" name="end" placeholder="-" value="{{ log.end_time.date().isoformat() if log.end_time }}">
</div>
</div>
<div class="row">
<div class="col-4">
<label for="contact" class="form-label">Contact</label>
<input list="contactList" class="form-control" id="contact" value="{{ log.contact.full_name }}">
<input type="hidden" id="contactId">
<datalist id="contactList">
{% for contact in users %}
<option data-id="{{ contact.id }}" value="{{ contact.full_name }}">{{ contact.full_name }}</option>
{% endfor %}
</datalist>
</div>
<div class="col-4">
<label for="item" class="form-label">Work Item</label>
<input list="itemList" class="form-control" id="item" placeholder="-" value="{{ log.work_item.identifier }}">
<input type="hidden" id="itemId">
<datalist id="itemList">
{% for item in items %}
<option data-id="{{ item.id }}" value="{{ item.identifier }}">{{ item.identifier }}</option>
{% endfor %}
</datalist>
</div>
<div class="col-4">
</div>
</div>
</form>
</div>
</nav>
{% endblock %}