Initial commit: add compliance_checks table, per-check metadata on assets, and compliance audit trail
This commit is contained in:
133
app/templates/assignments/form.html
Normal file
133
app/templates/assignments/form.html
Normal file
@@ -0,0 +1,133 @@
|
||||
{% extends 'base.html' %}
|
||||
{% block title %}Assign Asset – IT Asset Management{% endblock %}
|
||||
{% block breadcrumb %}
|
||||
<li class="breadcrumb-item"><a href="{{ url_for('dashboard.index') }}">Home</a></li>
|
||||
<li class="breadcrumb-item"><a href="{{ url_for('assignments.index') }}">Assignments</a></li>
|
||||
<li class="breadcrumb-item active">New Assignment</li>
|
||||
{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
<div class="page-header mb-4">
|
||||
<h1><i class="bi bi-arrow-left-right me-2"></i>Assign Asset to User</h1>
|
||||
</div>
|
||||
|
||||
<div class="card border-0 shadow-sm" style="max-width:600px;">
|
||||
<div class="card-body">
|
||||
<form method="POST" action="{{ url_for('assignments.create') }}">
|
||||
<div class="mb-3">
|
||||
<label class="form-label">User <span class="text-danger">*</span></label>
|
||||
<input type="hidden" name="user_id" id="userId" value="{{ preselect_user_id or '' }}">
|
||||
<input type="text" id="userSearch" class="form-control"
|
||||
placeholder="Search by name or Windows ID…"
|
||||
value="" autocomplete="off">
|
||||
<div id="userDropdown" class="list-group position-absolute shadow" style="z-index:1000;display:none;min-width:350px;"></div>
|
||||
<div id="userDisplay" class="form-text text-success fw-semibold"></div>
|
||||
</div>
|
||||
|
||||
<div class="mb-3">
|
||||
<label class="form-label">Asset <span class="text-danger">*</span></label>
|
||||
<input type="hidden" name="asset_id" id="assetId" value="{{ preselect_asset_id or '' }}">
|
||||
<input type="text" id="assetSearch" class="form-control"
|
||||
placeholder="Search by serial number or service tag…"
|
||||
value="" autocomplete="off">
|
||||
<div id="assetDropdown" class="list-group position-absolute shadow" style="z-index:1000;display:none;min-width:350px;"></div>
|
||||
<div id="assetDisplay" class="form-text text-success fw-semibold"></div>
|
||||
</div>
|
||||
|
||||
<div class="mb-3">
|
||||
<label class="form-label">Assigned Date</label>
|
||||
<input type="date" name="assigned_date" class="form-control" id="assignedDate">
|
||||
</div>
|
||||
|
||||
<div class="mb-4">
|
||||
<label class="form-label">Notes</label>
|
||||
<textarea name="notes" class="form-control" rows="2"></textarea>
|
||||
</div>
|
||||
|
||||
<div class="d-flex gap-2">
|
||||
<button type="submit" class="btn btn-primary">
|
||||
<i class="bi bi-check-lg me-1"></i>Create Assignment
|
||||
</button>
|
||||
<a href="{{ url_for('assignments.index') }}" class="btn btn-outline-secondary">Cancel</a>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
{% endblock %}
|
||||
|
||||
{% block extra_js %}
|
||||
<script>
|
||||
// Set today's date as default
|
||||
document.getElementById('assignedDate').value = new Date().toISOString().slice(0,10);
|
||||
|
||||
// ── Generic live-search helper ───────────────────────────────────
|
||||
function liveSearch(inputId, dropdownId, hiddenId, displayId, endpoint, labelField) {
|
||||
const input = document.getElementById(inputId);
|
||||
const dropdown = document.getElementById(dropdownId);
|
||||
const hidden = document.getElementById(hiddenId);
|
||||
const display = document.getElementById(displayId);
|
||||
let timer;
|
||||
|
||||
input.addEventListener('input', () => {
|
||||
clearTimeout(timer);
|
||||
timer = setTimeout(() => {
|
||||
const q = input.value.trim();
|
||||
if (q.length < 2) { dropdown.style.display = 'none'; return; }
|
||||
fetch(`${endpoint}?q=${encodeURIComponent(q)}`)
|
||||
.then(r => r.json())
|
||||
.then(items => {
|
||||
dropdown.innerHTML = '';
|
||||
if (!items.length) { dropdown.style.display = 'none'; return; }
|
||||
items.forEach(item => {
|
||||
const a = document.createElement('a');
|
||||
a.className = 'list-group-item list-group-item-action py-2';
|
||||
a.textContent = item.text || item[labelField];
|
||||
// colour disabled assets
|
||||
if (item.status && item.status !== 'available') {
|
||||
a.className += ' text-muted';
|
||||
a.textContent += ` [${item.status}]`;
|
||||
}
|
||||
a.addEventListener('click', () => {
|
||||
hidden.value = item.id;
|
||||
input.value = item.text || item[labelField];
|
||||
display.textContent = '✓ Selected: ' + (item.windows_id || item.serial_number || '');
|
||||
dropdown.style.display = 'none';
|
||||
});
|
||||
dropdown.appendChild(a);
|
||||
});
|
||||
dropdown.style.display = 'block';
|
||||
});
|
||||
}, 250);
|
||||
});
|
||||
|
||||
document.addEventListener('click', e => {
|
||||
if (!input.contains(e.target)) dropdown.style.display = 'none';
|
||||
});
|
||||
}
|
||||
|
||||
liveSearch('userSearch', 'userDropdown', 'userId', 'userDisplay',
|
||||
'{{ url_for("users.search") }}', 'text');
|
||||
liveSearch('assetSearch', 'assetDropdown', 'assetId', 'assetDisplay',
|
||||
'{{ url_for("assets.search") }}', 'text');
|
||||
|
||||
// Pre-fill labels if IDs were passed via URL
|
||||
{% if preselect_user_id %}
|
||||
fetch('{{ url_for("users.search") }}?q={{ preselect_user_id }}')
|
||||
.then(r => r.json()).then(items => {
|
||||
if (items.length) {
|
||||
document.getElementById('userSearch').value = items[0].text;
|
||||
document.getElementById('userDisplay').textContent = '✓ Pre-selected';
|
||||
}
|
||||
});
|
||||
{% endif %}
|
||||
{% if preselect_asset_id %}
|
||||
fetch('{{ url_for("assets.search") }}?q={{ preselect_asset_id }}')
|
||||
.then(r => r.json()).then(items => {
|
||||
if (items.length) {
|
||||
document.getElementById('assetSearch').value = items[0].text;
|
||||
document.getElementById('assetDisplay').textContent = '✓ Pre-selected';
|
||||
}
|
||||
});
|
||||
{% endif %}
|
||||
</script>
|
||||
{% endblock %}
|
||||
144
app/templates/assignments/index.html
Normal file
144
app/templates/assignments/index.html
Normal file
@@ -0,0 +1,144 @@
|
||||
{% extends 'base.html' %}
|
||||
{% block title %}Assignments – IT Asset Management{% endblock %}
|
||||
{% block breadcrumb %}
|
||||
<li class="breadcrumb-item"><a href="{{ url_for('dashboard.index') }}">Home</a></li>
|
||||
<li class="breadcrumb-item active">Assignments</li>
|
||||
{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
<div class="page-header d-flex align-items-center justify-content-between mb-4">
|
||||
<h1><i class="bi bi-arrow-left-right me-2"></i>Assignments</h1>
|
||||
<a href="{{ url_for('assignments.create') }}" class="btn btn-primary btn-sm">
|
||||
<i class="bi bi-plus-circle me-1"></i>Assign Asset
|
||||
</a>
|
||||
</div>
|
||||
|
||||
<form method="GET" class="row g-2 mb-3">
|
||||
<div class="col-auto">
|
||||
<div class="form-check form-check-inline mt-1">
|
||||
<input class="form-check-input" type="checkbox" name="active" value="0" id="chkAll"
|
||||
{% if not active_only %}checked{% endif %} onchange="this.form.submit()">
|
||||
<label class="form-check-label" for="chkAll">Show returned</label>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
|
||||
<div class="card border-0 shadow-sm">
|
||||
<div class="table-responsive">
|
||||
<table class="table table-hover mb-0">
|
||||
<thead class="table-light">
|
||||
<tr>
|
||||
<th>User</th>
|
||||
<th>Windows ID</th>
|
||||
<th>Asset</th>
|
||||
<th>Serial Number</th>
|
||||
<th>Assigned</th>
|
||||
<th>Returned</th>
|
||||
<th>Status</th>
|
||||
<th></th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{% for a in pagination.items %}
|
||||
<tr {% if a.user.is_masked %}class="masked-row"{% endif %}>
|
||||
<td>
|
||||
<a href="{{ url_for('users.detail', user_id=a.user.id) }}">{{ a.user.display_name }}</a>
|
||||
</td>
|
||||
<td><code>{{ a.user.windows_id }}</code></td>
|
||||
<td>
|
||||
<a href="{{ url_for('assets.detail', asset_id=a.asset.id) }}">
|
||||
{{ a.asset.brand or '' }} {{ a.asset.model or '' }}
|
||||
</a>
|
||||
</td>
|
||||
<td><code>{{ a.asset.serial_number }}</code></td>
|
||||
<td>{{ a.assigned_date.strftime('%d/%m/%Y') if a.assigned_date else '—' }}</td>
|
||||
<td>{{ a.returned_date.strftime('%d/%m/%Y') if a.returned_date else '—' }}</td>
|
||||
<td>
|
||||
{% if a.is_active %}
|
||||
<span class="badge bg-success">Active</span>
|
||||
{% else %}
|
||||
<span class="badge bg-secondary">Returned</span>
|
||||
{% endif %}
|
||||
</td>
|
||||
<td>
|
||||
{% if a.is_active %}
|
||||
<button class="btn btn-sm btn-outline-warning py-0 px-2"
|
||||
data-bs-toggle="modal" data-bs-target="#returnModal{{ a.id }}">
|
||||
<i class="bi bi-arrow-return-left"></i>
|
||||
</button>
|
||||
{% endif %}
|
||||
<a href="{{ url_for('paperwork.create', assignment_id=a.id, user_id=a.user.id, asset_id=a.asset.id) }}"
|
||||
class="btn btn-sm btn-outline-info py-0 px-2" title="Create document">
|
||||
<i class="bi bi-file-earmark-plus"></i>
|
||||
</a>
|
||||
</td>
|
||||
</tr>
|
||||
{% else %}
|
||||
<tr><td colspan="8" class="text-center text-muted py-4">No assignments found.</td></tr>
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
|
||||
{% if pagination.pages > 1 %}
|
||||
<div class="card-footer bg-white d-flex justify-content-between align-items-center py-2">
|
||||
<small class="text-muted">Showing {{ pagination.first }}–{{ pagination.last }} of {{ pagination.total }}</small>
|
||||
<nav>
|
||||
<ul class="pagination pagination-sm mb-0">
|
||||
{% if pagination.has_prev %}
|
||||
<li class="page-item">
|
||||
<a class="page-link" href="{{ url_for('assignments.index', page=pagination.prev_num, active='0' if not active_only else '1') }}">‹</a>
|
||||
</li>
|
||||
{% endif %}
|
||||
{% for p in pagination.iter_pages() %}
|
||||
{% if p %}
|
||||
<li class="page-item {% if p == pagination.page %}active{% endif %}">
|
||||
<a class="page-link" href="{{ url_for('assignments.index', page=p, active='0' if not active_only else '1') }}">{{ p }}</a>
|
||||
</li>
|
||||
{% else %}
|
||||
<li class="page-item disabled"><span class="page-link">…</span></li>
|
||||
{% endif %}
|
||||
{% endfor %}
|
||||
{% if pagination.has_next %}
|
||||
<li class="page-item">
|
||||
<a class="page-link" href="{{ url_for('assignments.index', page=pagination.next_num, active='0' if not active_only else '1') }}">›</a>
|
||||
</li>
|
||||
{% endif %}
|
||||
</ul>
|
||||
</nav>
|
||||
</div>
|
||||
{% endif %}
|
||||
</div>
|
||||
|
||||
<!-- Return modals -->
|
||||
{% for a in pagination.items %}{% if a.is_active %}
|
||||
<div class="modal fade" id="returnModal{{ a.id }}" tabindex="-1">
|
||||
<div class="modal-dialog">
|
||||
<div class="modal-content">
|
||||
<div class="modal-header">
|
||||
<h5 class="modal-title">Return Asset</h5>
|
||||
<button type="button" class="btn-close" data-bs-dismiss="modal"></button>
|
||||
</div>
|
||||
<form method="POST" action="{{ url_for('assignments.return_asset', assignment_id=a.id) }}">
|
||||
<div class="modal-body">
|
||||
<p>Returning <strong>{{ a.asset.serial_number }}</strong> from
|
||||
<strong>{{ a.user.display_name }}</strong>.</p>
|
||||
<div class="mb-3">
|
||||
<label class="form-label">Return Date</label>
|
||||
<input type="date" name="returned_date" class="form-control" required>
|
||||
</div>
|
||||
<div class="mb-0">
|
||||
<label class="form-label">Notes</label>
|
||||
<textarea name="return_notes" class="form-control" rows="2"></textarea>
|
||||
</div>
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Cancel</button>
|
||||
<button type="submit" class="btn btn-warning">Confirm Return</button>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{% endif %}{% endfor %}
|
||||
{% endblock %}
|
||||
Reference in New Issue
Block a user