Initial commit: add compliance_checks table, per-check metadata on assets, and compliance audit trail
This commit is contained in:
453
app/templates/assets/detail.html
Normal file
453
app/templates/assets/detail.html
Normal file
@@ -0,0 +1,453 @@
|
||||
{% extends 'base.html' %}
|
||||
{% block title %}{{ asset.serial_number }} – 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('assets.index') }}">Assets</a></li>
|
||||
<li class="breadcrumb-item active">{{ asset.serial_number }}</li>
|
||||
{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
<div class="page-header d-flex align-items-center justify-content-between mb-4">
|
||||
<h1>
|
||||
<i class="bi bi-laptop me-2"></i>{{ asset.brand or '' }} {{ asset.model or '' }}
|
||||
<span class="badge badge-{{ asset.status }} fs-6 align-middle ms-2">{{ asset.status | title }}</span>
|
||||
</h1>
|
||||
<div class="d-flex gap-2">
|
||||
<a href="{{ url_for('assets.edit', asset_id=asset.id) }}" class="btn btn-sm btn-outline-primary">
|
||||
<i class="bi bi-pencil me-1"></i>Edit
|
||||
</a>
|
||||
{% if asset.status == 'available' %}
|
||||
<a href="{{ url_for('assignments.create', asset_id=asset.id) }}" class="btn btn-sm btn-outline-success">
|
||||
<i class="bi bi-plus-circle me-1"></i>Assign
|
||||
</a>
|
||||
{% endif %}
|
||||
{% if asset.current_user %}
|
||||
<a href="{{ url_for('paperwork.create', asset_id=asset.id, user_id=asset.current_user.id) }}"
|
||||
class="btn btn-sm btn-outline-info">
|
||||
<i class="bi bi-file-earmark-plus me-1"></i>New Doc
|
||||
</a>
|
||||
{% endif %}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="row g-3">
|
||||
<!-- Asset details -->
|
||||
<div class="col-md-4">
|
||||
<div class="card border-0 shadow-sm mb-3">
|
||||
<div class="card-header bg-white fw-semibold py-3">
|
||||
<i class="bi bi-info-circle me-2 text-primary"></i>Asset Details
|
||||
</div>
|
||||
<div class="card-body">
|
||||
<dl class="row mb-0">
|
||||
<dt class="col-5 text-muted small">Type</dt>
|
||||
<dd class="col-7"><span class="badge bg-secondary">{{ asset.asset_type }}</span></dd>
|
||||
|
||||
<dt class="col-5 text-muted small">Brand</dt>
|
||||
<dd class="col-7">{{ asset.brand or '—' }}</dd>
|
||||
|
||||
<dt class="col-5 text-muted small">Model</dt>
|
||||
<dd class="col-7">{{ asset.model or '—' }}</dd>
|
||||
|
||||
<dt class="col-5 text-muted small">Serial No.</dt>
|
||||
<dd class="col-7"><code>{{ asset.serial_number }}</code></dd>
|
||||
|
||||
<dt class="col-5 text-muted small">Service Tag</dt>
|
||||
<dd class="col-7"><code>{{ asset.service_tag or '—' }}</code></dd>
|
||||
|
||||
<dt class="col-5 text-muted small">Asset Tag</dt>
|
||||
<dd class="col-7">{{ asset.asset_tag or '—' }}</dd>
|
||||
|
||||
<dt class="col-5 text-muted small">OS</dt>
|
||||
<dd class="col-7">{{ asset.operating_system or '—' }}</dd>
|
||||
|
||||
{% if asset.processor %}
|
||||
<dt class="col-5 text-muted small">CPU</dt>
|
||||
<dd class="col-7">{{ asset.processor }}</dd>
|
||||
{% endif %}
|
||||
|
||||
{% if asset.ram_gb %}
|
||||
<dt class="col-5 text-muted small">RAM</dt>
|
||||
<dd class="col-7">{{ asset.ram_gb }} GB</dd>
|
||||
{% endif %}
|
||||
|
||||
{% if asset.storage_gb %}
|
||||
<dt class="col-5 text-muted small">Storage</dt>
|
||||
<dd class="col-7">{{ asset.storage_gb }} GB</dd>
|
||||
{% endif %}
|
||||
|
||||
{% if asset.mac_address %}
|
||||
<dt class="col-5 text-muted small">MAC</dt>
|
||||
<dd class="col-7"><code>{{ asset.mac_address }}</code></dd>
|
||||
{% endif %}
|
||||
</dl>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="card border-0 shadow-sm">
|
||||
<div class="card-header bg-white fw-semibold py-3">
|
||||
<i class="bi bi-receipt me-2 text-primary"></i>Procurement
|
||||
</div>
|
||||
<div class="card-body">
|
||||
<dl class="row mb-0">
|
||||
<dt class="col-5 text-muted small">Purchased</dt>
|
||||
<dd class="col-7">{{ asset.purchase_date.strftime('%d/%m/%Y') if asset.purchase_date else '—' }}</dd>
|
||||
|
||||
<dt class="col-5 text-muted small">Warranty</dt>
|
||||
<dd class="col-7">{{ asset.warranty_expiry.strftime('%d/%m/%Y') if asset.warranty_expiry else '—' }}</dd>
|
||||
|
||||
<dt class="col-5 text-muted small">Price</dt>
|
||||
<dd class="col-7">{{ '%.2f'|format(asset.purchase_price) if asset.purchase_price else '—' }}</dd>
|
||||
|
||||
<dt class="col-5 text-muted small">Supplier</dt>
|
||||
<dd class="col-7">{{ asset.supplier or '—' }}</dd>
|
||||
|
||||
<dt class="col-5 text-muted small">PO #</dt>
|
||||
<dd class="col-7">{{ asset.po_number or '—' }}</dd>
|
||||
|
||||
<dt class="col-5 text-muted small">Location</dt>
|
||||
<dd class="col-7">{{ asset.location or '—' }}</dd>
|
||||
</dl>
|
||||
{% if asset.notes %}
|
||||
<hr class="my-2">
|
||||
<p class="small text-muted mb-0">{{ asset.notes }}</p>
|
||||
{% endif %}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- History + Docs -->
|
||||
<div class="col-md-8">
|
||||
<!-- Assignment history -->
|
||||
<div class="card border-0 shadow-sm mb-3">
|
||||
<div class="card-header bg-white fw-semibold py-3 d-flex justify-content-between align-items-center">
|
||||
<span><i class="bi bi-clock-history me-2 text-primary"></i>Assignment History</span>
|
||||
</div>
|
||||
<div class="table-responsive">
|
||||
<table class="table table-sm table-hover mb-0">
|
||||
<thead class="table-light">
|
||||
<tr>
|
||||
<th>User</th>
|
||||
<th>Windows ID</th>
|
||||
<th>From</th>
|
||||
<th>Until</th>
|
||||
<th>Status</th>
|
||||
<th></th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{% for a in history %}
|
||||
<tr {% if a.user.is_masked %}class="masked-row"{% endif %}>
|
||||
<td>{{ a.user.display_name }}</td>
|
||||
<td><code>{{ a.user.windows_id }}</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> Return
|
||||
</button>
|
||||
{% endif %}
|
||||
</td>
|
||||
</tr>
|
||||
{% else %}
|
||||
<tr><td colspan="6" class="text-center text-muted py-3">No assignment history.</td></tr>
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Documents -->
|
||||
<div class="card border-0 shadow-sm">
|
||||
<div class="card-header bg-white fw-semibold py-3 d-flex justify-content-between align-items-center">
|
||||
<span><i class="bi bi-file-earmark-text me-2 text-primary"></i>Documents</span>
|
||||
{% if asset.current_user %}
|
||||
<a href="{{ url_for('paperwork.create', asset_id=asset.id, user_id=asset.current_user.id) }}"
|
||||
class="btn btn-sm btn-outline-info py-0 px-2">
|
||||
<i class="bi bi-plus"></i> New
|
||||
</a>
|
||||
{% endif %}
|
||||
</div>
|
||||
<div class="table-responsive">
|
||||
<table class="table table-sm table-hover mb-0">
|
||||
<thead class="table-light">
|
||||
<tr><th>Title</th><th>Type</th><th>User</th><th>Date</th><th></th></tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{% for d in docs %}
|
||||
<tr>
|
||||
<td><a href="{{ url_for('paperwork.detail', doc_id=d.id) }}">{{ d.title }}</a></td>
|
||||
<td><span class="badge bg-info text-dark">{{ d.doc_type_label }}</span></td>
|
||||
<td>{{ d.user.display_name }}</td>
|
||||
<td>{{ d.created_at.strftime('%d/%m/%Y') if d.created_at else '—' }}</td>
|
||||
<td>
|
||||
{% if d.pdf_filename %}
|
||||
<a href="{{ url_for('paperwork.download', doc_id=d.id) }}"
|
||||
class="btn btn-sm btn-outline-secondary py-0 px-2">
|
||||
<i class="bi bi-download"></i>
|
||||
</a>
|
||||
{% endif %}
|
||||
</td>
|
||||
</tr>
|
||||
{% else %}
|
||||
<tr><td colspan="5" class="text-center text-muted py-3">No documents.</td></tr>
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{% if asset.asset_type in ('Laptop', 'Desktop') %}
|
||||
<!-- Compliance card — Laptop / Desktop only -->
|
||||
<div class="card border-0 shadow-sm mt-3">
|
||||
<div class="card-header bg-white fw-semibold py-3 d-flex justify-content-between align-items-center">
|
||||
<span><i class="bi bi-shield-check me-2 text-success"></i>IT Compliance & Inventory</span>
|
||||
<button class="btn btn-sm btn-outline-primary" type="button"
|
||||
data-bs-toggle="collapse" data-bs-target="#complianceEdit">
|
||||
<i class="bi bi-pencil me-1"></i>Edit
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<!-- Read-only summary -->
|
||||
<div class="card-body pb-2">
|
||||
<div class="row g-2">
|
||||
<div class="col-md-4 col-6">
|
||||
<div class="small text-muted">Inventory #</div>
|
||||
<div class="fw-semibold">{{ asset.inventory_number or '—' }}</div>
|
||||
</div>
|
||||
<div class="col-md-4 col-6">
|
||||
<div class="small text-muted">AD Device Name</div>
|
||||
<div class="fw-semibold"><code>{{ asset.ad_device_name or '—' }}</code></div>
|
||||
</div>
|
||||
<div class="col-md-4 col-12">
|
||||
<div class="small text-muted">Location Note</div>
|
||||
<div class="fw-semibold">{{ asset.location_note or '—' }}</div>
|
||||
</div>
|
||||
<div class="col-md-4 col-4 mt-2">
|
||||
{% if asset.encryption_checked %}
|
||||
<span class="badge bg-success"><i class="bi bi-lock-fill me-1"></i>Encrypted</span>
|
||||
{% else %}
|
||||
<span class="badge bg-danger"><i class="bi bi-lock me-1"></i>Not Encrypted</span>
|
||||
{% endif %}
|
||||
{% if asset.encryption_checked_by %}
|
||||
<div class="small text-muted mt-1">
|
||||
by <strong>{{ asset.encryption_checked_by.username }}</strong>
|
||||
{% if asset.encryption_checked_at %}
|
||||
— {{ asset.encryption_checked_at.strftime('%d/%m/%Y %H:%M') }}
|
||||
{% endif %}
|
||||
</div>
|
||||
{% endif %}
|
||||
</div>
|
||||
<div class="col-md-4 col-4 mt-2">
|
||||
{% if asset.backup_checked %}
|
||||
<span class="badge bg-success"><i class="bi bi-cloud-check me-1"></i>Backup OK</span>
|
||||
{% else %}
|
||||
<span class="badge bg-warning text-dark"><i class="bi bi-cloud me-1"></i>No Backup</span>
|
||||
{% endif %}
|
||||
{% if asset.backup_checked_by %}
|
||||
<div class="small text-muted mt-1">
|
||||
by <strong>{{ asset.backup_checked_by.username }}</strong>
|
||||
{% if asset.backup_checked_at %}
|
||||
— {{ asset.backup_checked_at.strftime('%d/%m/%Y %H:%M') }}
|
||||
{% endif %}
|
||||
</div>
|
||||
{% endif %}
|
||||
</div>
|
||||
<div class="col-md-4 col-4 mt-2">
|
||||
{% if asset.hr_notified %}
|
||||
<span class="badge bg-success"><i class="bi bi-person-check me-1"></i>HR Notified</span>
|
||||
{% else %}
|
||||
<span class="badge bg-secondary"><i class="bi bi-person me-1"></i>HR Pending</span>
|
||||
{% endif %}
|
||||
{% if asset.hr_notified_by %}
|
||||
<div class="small text-muted mt-1">
|
||||
by <strong>{{ asset.hr_notified_by.username }}</strong>
|
||||
{% if asset.hr_notified_at %}
|
||||
— {{ asset.hr_notified_at.strftime('%d/%m/%Y %H:%M') }}
|
||||
{% endif %}
|
||||
</div>
|
||||
{% endif %}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Collapsible edit form -->
|
||||
<div class="collapse" id="complianceEdit">
|
||||
<div class="card-body border-top pt-3">
|
||||
<form method="POST" action="{{ url_for('assets.update_compliance', asset_id=asset.id) }}">
|
||||
<div class="row g-3">
|
||||
<div class="col-md-4">
|
||||
<label class="form-label small fw-semibold">Inventory Number</label>
|
||||
<input type="text" name="inventory_number" class="form-control form-control-sm"
|
||||
value="{{ asset.inventory_number or '' }}" placeholder="INV-0001">
|
||||
</div>
|
||||
<div class="col-md-4">
|
||||
<label class="form-label small fw-semibold">AD Device Name</label>
|
||||
<input type="text" name="ad_device_name" class="form-control form-control-sm"
|
||||
value="{{ asset.ad_device_name or '' }}" placeholder="DESKTOP-AB1234">
|
||||
</div>
|
||||
<div class="col-md-4">
|
||||
<label class="form-label small fw-semibold">Current User in AD</label>
|
||||
{% if asset.current_user %}
|
||||
<div class="form-control form-control-sm bg-light text-muted">
|
||||
{{ asset.current_user.display_name }} ({{ asset.current_user.windows_id }})
|
||||
</div>
|
||||
{% else %}
|
||||
<div class="form-control form-control-sm bg-light text-muted">Not assigned</div>
|
||||
{% endif %}
|
||||
</div>
|
||||
<div class="col-12">
|
||||
<label class="form-label small fw-semibold">Location Note</label>
|
||||
<textarea name="location_note" class="form-control form-control-sm" rows="2"
|
||||
placeholder="e.g. Building A, Room 102, Desk 5">{{ asset.location_note or '' }}</textarea>
|
||||
</div>
|
||||
<div class="col-12">
|
||||
<div class="d-flex gap-4 flex-wrap mt-1">
|
||||
<div class="form-check form-switch">
|
||||
<input class="form-check-input" type="checkbox" name="encryption_checked"
|
||||
id="chkEncrypt" value="1"
|
||||
{% if asset.encryption_checked %}checked{% endif %}>
|
||||
<label class="form-check-label fw-semibold" for="chkEncrypt">
|
||||
<i class="bi bi-lock-fill me-1 text-success"></i>Encryption Verified
|
||||
</label>
|
||||
</div>
|
||||
<div class="form-check form-switch">
|
||||
<input class="form-check-input" type="checkbox" name="backup_checked"
|
||||
id="chkBackup" value="1"
|
||||
{% if asset.backup_checked %}checked{% endif %}>
|
||||
<label class="form-check-label fw-semibold" for="chkBackup">
|
||||
<i class="bi bi-cloud-check me-1 text-primary"></i>Backup Configured
|
||||
</label>
|
||||
</div>
|
||||
<div class="form-check form-switch">
|
||||
<input class="form-check-input" type="checkbox" name="hr_notified"
|
||||
id="chkHR" value="1"
|
||||
{% if asset.hr_notified %}checked{% endif %}>
|
||||
<label class="form-check-label fw-semibold" for="chkHR">
|
||||
<i class="bi bi-person-check me-1 text-warning"></i>HR Send / Notified
|
||||
</label>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-12">
|
||||
<label class="form-label small fw-semibold" for="compliance_notes">
|
||||
<i class="bi bi-chat-left-text me-1 text-secondary"></i>Note
|
||||
<span class="text-muted fw-normal">(reason for check / uncheck — saved with each change)</span>
|
||||
</label>
|
||||
<textarea name="compliance_notes" id="compliance_notes"
|
||||
class="form-control form-control-sm" rows="2"
|
||||
placeholder="e.g. BitLocker verified on site visit, backup re-enabled after restore…"></textarea>
|
||||
</div>
|
||||
</div>
|
||||
<div class="d-flex gap-2 mt-3">
|
||||
<button type="submit" class="btn btn-sm btn-success">
|
||||
<i class="bi bi-check2 me-1"></i>Save Changes
|
||||
</button>
|
||||
<button type="button" class="btn btn-sm btn-outline-secondary"
|
||||
data-bs-toggle="collapse" data-bs-target="#complianceEdit">
|
||||
Cancel
|
||||
</button>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Compliance change history -->
|
||||
{% if compliance_log %}
|
||||
<div class="card border-0 shadow-sm mt-2">
|
||||
<div class="card-header bg-white fw-semibold py-3 d-flex justify-content-between align-items-center">
|
||||
<!-- Compliance per-check history -->
|
||||
{% if check_history %}
|
||||
<div class="card border-0 shadow-sm mt-2">
|
||||
<div class="card-header bg-white fw-semibold py-3 d-flex justify-content-between align-items-center">
|
||||
<span><i class="bi bi-shield-exclamation me-2 text-secondary"></i>Compliance Check History</span>
|
||||
<button class="btn btn-sm btn-outline-secondary" type="button"
|
||||
data-bs-toggle="collapse" data-bs-target="#checkHistory">
|
||||
Show / Hide
|
||||
</button>
|
||||
</div>
|
||||
<div class="collapse" id="checkHistory">
|
||||
<div class="table-responsive">
|
||||
<table class="table table-sm table-hover mb-0 small">
|
||||
<thead class="table-light">
|
||||
<tr>
|
||||
<th style="width:160px">Date & Time</th>
|
||||
<th style="width:140px">Check</th>
|
||||
<th style="width:90px">Result</th>
|
||||
<th style="width:130px">Performed by</th>
|
||||
<th>Note</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{% for entry in check_history %}
|
||||
<tr>
|
||||
<td class="text-nowrap">{{ entry.performed_at.strftime('%d/%m/%Y %H:%M') }}</td>
|
||||
<td>{{ entry.check_type_label }}</td>
|
||||
<td>
|
||||
{% if entry.checked %}
|
||||
<span class="badge bg-success">Verified</span>
|
||||
{% else %}
|
||||
<span class="badge bg-danger">Cleared</span>
|
||||
{% endif %}
|
||||
</td>
|
||||
<td>
|
||||
{% if entry.performed_by %}
|
||||
<span class="fw-semibold">{{ entry.performed_by.username }}</span>
|
||||
{% else %}
|
||||
<span class="text-muted">—</span>
|
||||
{% endif %}
|
||||
</td>
|
||||
<td>{{ entry.notes or '—' }}</td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{% endif %}
|
||||
|
||||
{% endif %}{# end asset_type in Laptop/Desktop #}
|
||||
|
||||
<!-- Return modals -->
|
||||
{% for a in history %}{% 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">
|
||||
<div class="mb-3">
|
||||
<label class="form-label">Return Date</label>
|
||||
<input type="date" name="returned_date" class="form-control"
|
||||
value="{{ today_date }}" required>
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<label class="form-label">Notes (optional)</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 %}
|
||||
160
app/templates/assets/form.html
Normal file
160
app/templates/assets/form.html
Normal file
@@ -0,0 +1,160 @@
|
||||
{% extends 'base.html' %}
|
||||
{% block title %}{{ 'Edit Asset' if asset else 'New 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('assets.index') }}">Assets</a></li>
|
||||
<li class="breadcrumb-item active">{{ 'Edit' if asset else 'New Asset' }}</li>
|
||||
{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
<div class="page-header mb-4">
|
||||
<h1><i class="bi bi-laptop me-2"></i>{{ 'Edit Asset' if asset else 'Add Asset' }}</h1>
|
||||
</div>
|
||||
|
||||
<div class="card border-0 shadow-sm" style="max-width:800px;">
|
||||
<div class="card-body">
|
||||
{% if not asset and prefill and prefill.service_tag %}
|
||||
<div class="alert alert-info py-2 mb-3 small">
|
||||
<i class="bi bi-cloud-check me-1"></i>
|
||||
Pre-filled from Dell service tag <strong>{{ prefill.service_tag }}</strong>. Review the details below before saving.
|
||||
</div>
|
||||
{% endif %}
|
||||
<form method="POST" action="{{ url_for('assets.edit', asset_id=asset.id) if asset else url_for('assets.create') }}">
|
||||
|
||||
<h6 class="text-uppercase text-muted mb-3 small">Identifiers</h6>
|
||||
<div class="row g-3 mb-3">
|
||||
<div class="col-md-4">
|
||||
<label class="form-label">Serial Number <span class="text-danger">*</span></label>
|
||||
<input type="text" name="serial_number" class="form-control"
|
||||
value="{{ asset.serial_number if asset else (prefill.serial_number if prefill else '') }}" required>
|
||||
</div>
|
||||
<div class="col-md-4">
|
||||
<label class="form-label">Service Tag</label>
|
||||
<input type="text" name="service_tag" class="form-control"
|
||||
value="{{ asset.service_tag or '' if asset else (prefill.service_tag if prefill else '') }}"
|
||||
placeholder="e.g. Dell service tag">
|
||||
</div>
|
||||
<div class="col-md-4">
|
||||
<label class="form-label">Asset Tag</label>
|
||||
<input type="text" name="asset_tag" class="form-control"
|
||||
value="{{ asset.asset_tag or '' if asset else '' }}"
|
||||
placeholder="Internal barcode/tag">
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<h6 class="text-uppercase text-muted mb-3 small">Classification</h6>
|
||||
<div class="row g-3 mb-3">
|
||||
<div class="col-md-4">
|
||||
<label class="form-label">Asset Type <span class="text-danger">*</span></label>
|
||||
<select name="asset_type" class="form-select" required>
|
||||
{% for t in asset_types %}
|
||||
<option value="{{ t }}"
|
||||
{% if asset and asset.asset_type == t %}selected
|
||||
{% elif not asset and prefill and prefill.asset_type == t %}selected
|
||||
{% elif not asset and not prefill and t == 'Laptop' %}selected
|
||||
{% endif %}>{{ t }}</option>
|
||||
{% endfor %}
|
||||
</select>
|
||||
</div>
|
||||
<div class="col-md-4">
|
||||
<label class="form-label">Brand</label>
|
||||
<input type="text" name="brand" class="form-control"
|
||||
value="{{ asset.brand or '' if asset else (prefill.brand if prefill else '') }}"
|
||||
placeholder="e.g. Dell, Lenovo, HP">
|
||||
</div>
|
||||
<div class="col-md-4">
|
||||
<label class="form-label">Model</label>
|
||||
<input type="text" name="model" class="form-control"
|
||||
value="{{ asset.model or '' if asset else (prefill.model if prefill else '') }}"
|
||||
placeholder="e.g. Latitude 5540">
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<h6 class="text-uppercase text-muted mb-3 small">Technical Specs</h6>
|
||||
<div class="row g-3 mb-3">
|
||||
<div class="col-md-6">
|
||||
<label class="form-label">Processor</label>
|
||||
<input type="text" name="processor" class="form-control"
|
||||
value="{{ asset.processor or '' if asset else '' }}"
|
||||
placeholder="e.g. Intel Core i5-1345U">
|
||||
</div>
|
||||
<div class="col-md-3">
|
||||
<label class="form-label">RAM (GB)</label>
|
||||
<input type="number" name="ram_gb" class="form-control" min="0"
|
||||
value="{{ asset.ram_gb or '' if asset else '' }}">
|
||||
</div>
|
||||
<div class="col-md-3">
|
||||
<label class="form-label">Storage (GB)</label>
|
||||
<input type="number" name="storage_gb" class="form-control" min="0"
|
||||
value="{{ asset.storage_gb or '' if asset else '' }}">
|
||||
</div>
|
||||
<div class="col-md-4">
|
||||
<label class="form-label">Operating System</label>
|
||||
<input type="text" name="operating_system" class="form-control"
|
||||
value="{{ asset.operating_system or '' if asset else (prefill.operating_system if prefill else 'Windows 11 Pro') }}"
|
||||
placeholder="e.g. Windows 11 Pro">
|
||||
</div>
|
||||
<div class="col-md-4">
|
||||
<label class="form-label">MAC Address</label>
|
||||
<input type="text" name="mac_address" class="form-control"
|
||||
value="{{ asset.mac_address or '' if asset else '' }}">
|
||||
</div>
|
||||
<div class="col-md-4">
|
||||
<label class="form-label">Location</label>
|
||||
<input type="text" name="location" class="form-control"
|
||||
value="{{ asset.location or '' if asset else '' }}">
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<h6 class="text-uppercase text-muted mb-3 small">Procurement</h6>
|
||||
<div class="row g-3 mb-3">
|
||||
<div class="col-md-3">
|
||||
<label class="form-label">Purchase Date</label>
|
||||
<input type="date" name="purchase_date" class="form-control"
|
||||
value="{{ asset.purchase_date.isoformat() if asset and asset.purchase_date else (prefill.purchase_date if prefill else '') }}">
|
||||
</div>
|
||||
<div class="col-md-3">
|
||||
<label class="form-label">Warranty Expiry</label>
|
||||
<input type="date" name="warranty_expiry" class="form-control"
|
||||
value="{{ asset.warranty_expiry.isoformat() if asset and asset.warranty_expiry else (prefill.warranty_expiry if prefill else '') }}">
|
||||
</div>
|
||||
<div class="col-md-3">
|
||||
<label class="form-label">Purchase Price</label>
|
||||
<input type="number" name="purchase_price" class="form-control" step="0.01" min="0"
|
||||
value="{{ asset.purchase_price or '' if asset else '' }}">
|
||||
</div>
|
||||
<div class="col-md-3">
|
||||
<label class="form-label">Status</label>
|
||||
<select name="status" class="form-select">
|
||||
{% for val, label in asset_statuses %}
|
||||
<option value="{{ val }}" {% if asset and asset.status == val %}selected{% elif not asset and val == 'available' %}selected{% endif %}>{{ label }}</option>
|
||||
{% endfor %}
|
||||
</select>
|
||||
</div>
|
||||
<div class="col-md-4">
|
||||
<label class="form-label">Supplier</label>
|
||||
<input type="text" name="supplier" class="form-control"
|
||||
value="{{ asset.supplier or '' if asset else '' }}">
|
||||
</div>
|
||||
<div class="col-md-4">
|
||||
<label class="form-label">PO Number</label>
|
||||
<input type="text" name="po_number" class="form-control"
|
||||
value="{{ asset.po_number or '' if asset else '' }}">
|
||||
</div>
|
||||
<div class="col-12">
|
||||
<label class="form-label">Notes</label>
|
||||
<textarea name="notes" class="form-control" rows="2">{{ asset.notes or '' if asset else '' }}</textarea>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="d-flex gap-2">
|
||||
<button type="submit" class="btn btn-primary">
|
||||
<i class="bi bi-check-lg me-1"></i>{{ 'Save Changes' if asset else 'Create Asset' }}
|
||||
</button>
|
||||
<a href="{{ url_for('assets.detail', asset_id=asset.id) if asset else url_for('assets.index') }}"
|
||||
class="btn btn-outline-secondary">Cancel</a>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
{% endblock %}
|
||||
300
app/templates/assets/index.html
Normal file
300
app/templates/assets/index.html
Normal file
@@ -0,0 +1,300 @@
|
||||
{% extends 'base.html' %}
|
||||
{% block title %}Assets – IT Asset Management{% endblock %}
|
||||
{% block breadcrumb %}
|
||||
<li class="breadcrumb-item"><a href="{{ url_for('dashboard.index') }}">Home</a></li>
|
||||
<li class="breadcrumb-item active">Assets</li>
|
||||
{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
<div class="page-header d-flex align-items-center justify-content-between mb-4">
|
||||
<h1><i class="bi bi-laptop me-2"></i>Assets</h1>
|
||||
<a href="{{ url_for('assets.create') }}" class="btn btn-primary btn-sm">
|
||||
<i class="bi bi-plus-circle me-1"></i>Add Asset
|
||||
</a>
|
||||
</div>
|
||||
|
||||
<!-- Dell Service Tag Quick Import -->
|
||||
<div class="card border-0 shadow-sm mb-4" id="dellLookupCard">
|
||||
<div class="card-body py-3">
|
||||
<div class="d-flex align-items-center gap-2 flex-wrap">
|
||||
<span class="fw-semibold text-nowrap">
|
||||
<i class="bi bi-search me-1 text-primary"></i>Dell Quick Import
|
||||
</span>
|
||||
<span class="text-muted small text-nowrap">Enter a service tag to open the asset form pre-filled:</span>
|
||||
<div class="input-group input-group-sm" style="max-width:220px;">
|
||||
<input type="text" id="dellTagInput" class="form-control text-uppercase"
|
||||
placeholder="e.g. ABC1234" maxlength="20"
|
||||
style="text-transform:uppercase; letter-spacing:.05em;">
|
||||
<button class="btn btn-outline-primary" id="dellLookupBtn" type="button">
|
||||
<i class="bi bi-cloud-download me-1"></i>Lookup
|
||||
</button>
|
||||
</div>
|
||||
<div id="dellLookupSpinner" class="spinner-border spinner-border-sm text-primary d-none" role="status">
|
||||
<span class="visually-hidden">Loading…</span>
|
||||
</div>
|
||||
<span class="text-muted small ms-auto">
|
||||
<i class="bi bi-info-circle me-1"></i>
|
||||
Full auto-fill available with a
|
||||
<a href="https://tdm.dell.com" target="_blank" class="text-decoration-none">free Dell TechDirect API key</a>
|
||||
</span>
|
||||
</div>
|
||||
|
||||
<!-- Result preview (hidden until data arrives) -->
|
||||
<div id="dellLookupResult" class="mt-3 d-none">
|
||||
<div class="alert mb-2 py-2 d-flex align-items-start gap-3" id="dellResultBody">
|
||||
<i class="bi bi-pc-display-horizontal fs-4 flex-shrink-0 mt-1" id="dellResultIcon"></i>
|
||||
<div class="flex-grow-1">
|
||||
<div class="fw-semibold mb-1" id="dellResultTitle"></div>
|
||||
<div class="row row-cols-2 row-cols-md-4 g-1 small" id="dellResultMeta"></div>
|
||||
</div>
|
||||
<div class="d-flex flex-column gap-1 flex-shrink-0">
|
||||
<a id="dellCreateBtn" href="#" class="btn btn-sm btn-primary">
|
||||
<i class="bi bi-plus-circle me-1"></i>Create Asset
|
||||
</a>
|
||||
<a id="dellSupportLink" href="#" target="_blank" class="btn btn-sm btn-outline-secondary d-none">
|
||||
<i class="bi bi-box-arrow-up-right me-1"></i>View on Dell
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Error area -->
|
||||
<div id="dellLookupError" class="alert alert-warning mt-2 py-2 d-none small mb-0"></div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Filters -->
|
||||
<form method="GET" class="row g-2 mb-3">
|
||||
<div class="col-md-4">
|
||||
<div class="input-group input-group-sm">
|
||||
<span class="input-group-text"><i class="bi bi-search"></i></span>
|
||||
<input type="text" name="q" class="form-control" placeholder="Search SN, service tag, brand, model…" value="{{ q }}">
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-md-2">
|
||||
<select name="status" class="form-select form-select-sm">
|
||||
<option value="">All statuses</option>
|
||||
{% for val, label in asset_statuses %}
|
||||
<option value="{{ val }}" {% if status_filter == val %}selected{% endif %}>{{ label }}</option>
|
||||
{% endfor %}
|
||||
</select>
|
||||
</div>
|
||||
<div class="col-md-2">
|
||||
<select name="asset_type" class="form-select form-select-sm">
|
||||
<option value="">All types</option>
|
||||
{% for t in asset_types %}
|
||||
<option value="{{ t }}" {% if type_filter == t %}selected{% endif %}>{{ t }}</option>
|
||||
{% endfor %}
|
||||
</select>
|
||||
</div>
|
||||
<div class="col-auto">
|
||||
<button type="submit" class="btn btn-sm btn-primary">Filter</button>
|
||||
<a href="{{ url_for('assets.index') }}" class="btn btn-sm btn-outline-secondary">Clear</a>
|
||||
</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>Type</th>
|
||||
<th>Brand / Model</th>
|
||||
<th>Serial Number</th>
|
||||
<th>Service Tag</th>
|
||||
<th>Status</th>
|
||||
<th>Assigned To</th>
|
||||
<th>Warranty</th>
|
||||
<th></th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{% for a in pagination.items %}
|
||||
<tr>
|
||||
<td><span class="badge bg-secondary">{{ a.asset_type }}</span></td>
|
||||
<td>{{ a.brand or '' }} {{ a.model or '' }}</td>
|
||||
<td><code>{{ a.serial_number }}</code></td>
|
||||
<td><code>{{ a.service_tag or '—' }}</code></td>
|
||||
<td>
|
||||
<span class="badge badge-{{ a.status }}">{{ a.status | title }}</span>
|
||||
</td>
|
||||
<td>
|
||||
{% if a.current_user %}
|
||||
<a href="{{ url_for('users.detail', user_id=a.current_user.id) }}">
|
||||
{{ a.current_user.display_name }}
|
||||
</a>
|
||||
{% else %}
|
||||
<span class="text-muted">—</span>
|
||||
{% endif %}
|
||||
</td>
|
||||
<td>
|
||||
{% if a.warranty_expiry %}
|
||||
<span class="{% if a.warranty_expiry < today %}text-danger{% else %}text-success{% endif %}">
|
||||
{{ a.warranty_expiry.strftime('%d/%m/%Y') }}
|
||||
</span>
|
||||
{% else %}—{% endif %}
|
||||
</td>
|
||||
<td>
|
||||
<a href="{{ url_for('assets.detail', asset_id=a.id) }}"
|
||||
class="btn btn-sm btn-outline-secondary py-0 px-2">
|
||||
<i class="bi bi-eye"></i>
|
||||
</a>
|
||||
</td>
|
||||
</tr>
|
||||
{% else %}
|
||||
<tr><td colspan="8" class="text-center text-muted py-4">No assets 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('assets.index', page=pagination.prev_num, q=q, status=status_filter, asset_type=type_filter) }}">‹</a>
|
||||
</li>
|
||||
{% endif %}
|
||||
{% for p in pagination.iter_pages(left_edge=1, right_edge=1, left_current=2, right_current=2) %}
|
||||
{% if p %}
|
||||
<li class="page-item {% if p == pagination.page %}active{% endif %}">
|
||||
<a class="page-link" href="{{ url_for('assets.index', page=p, q=q, status=status_filter, asset_type=type_filter) }}">{{ 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('assets.index', page=pagination.next_num, q=q, status=status_filter, asset_type=type_filter) }}">›</a>
|
||||
</li>
|
||||
{% endif %}
|
||||
</ul>
|
||||
</nav>
|
||||
</div>
|
||||
{% endif %}
|
||||
</div>
|
||||
{% endblock %}
|
||||
|
||||
{% block extra_head %}
|
||||
<script>
|
||||
// make today available for warranty colour
|
||||
const today = new Date().toISOString().slice(0, 10);
|
||||
</script>
|
||||
{% endblock %}
|
||||
|
||||
{% block extra_js %}
|
||||
<script>
|
||||
(function () {
|
||||
const input = document.getElementById('dellTagInput');
|
||||
const btn = document.getElementById('dellLookupBtn');
|
||||
const spinner = document.getElementById('dellLookupSpinner');
|
||||
const result = document.getElementById('dellLookupResult');
|
||||
const errBox = document.getElementById('dellLookupError');
|
||||
const title = document.getElementById('dellResultTitle');
|
||||
const meta = document.getElementById('dellResultMeta');
|
||||
const createBtn = document.getElementById('dellCreateBtn');
|
||||
|
||||
function setLoading(on) {
|
||||
btn.disabled = on;
|
||||
spinner.classList.toggle('d-none', !on);
|
||||
}
|
||||
|
||||
function showError(msg) {
|
||||
errBox.textContent = msg;
|
||||
errBox.classList.remove('d-none');
|
||||
result.classList.add('d-none');
|
||||
}
|
||||
|
||||
function doLookup() {
|
||||
const tag = input.value.trim().toUpperCase();
|
||||
if (!tag) { input.focus(); return; }
|
||||
|
||||
result.classList.add('d-none');
|
||||
errBox.classList.add('d-none');
|
||||
setLoading(true);
|
||||
|
||||
fetch(`{{ url_for('assets.dell_lookup') }}?tag=${encodeURIComponent(tag)}`)
|
||||
.then(r => r.json().then(d => ({ ok: r.ok, status: r.status, data: d })))
|
||||
.then(({ ok, status, data }) => {
|
||||
setLoading(false);
|
||||
if (!ok) {
|
||||
if (status === 409 && data.existing_id) {
|
||||
errBox.innerHTML = `⚠ ${data.error} — <a href="/assets/${data.existing_id}">View asset</a>`;
|
||||
errBox.classList.remove('d-none');
|
||||
} else {
|
||||
showError(data.error || 'Lookup failed.');
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
// Build preview
|
||||
const isPartial = data.source === 'partial';
|
||||
const resultBody = document.getElementById('dellResultBody');
|
||||
const resultIcon = document.getElementById('dellResultIcon');
|
||||
const supportLink = document.getElementById('dellSupportLink');
|
||||
|
||||
resultBody.className = `alert mb-2 py-2 d-flex align-items-start gap-3 ${isPartial ? 'alert-warning' : 'alert-info'}`;
|
||||
resultIcon.className = `bi bi-pc-display-horizontal fs-4 flex-shrink-0 mt-1 ${isPartial ? 'text-warning' : 'text-primary'}`;
|
||||
|
||||
if (isPartial) {
|
||||
// Auto-open Dell's warranty page in a new tab so the user can read model + warranty
|
||||
if (data.support_url) window.open(data.support_url, '_blank', 'noopener');
|
||||
title.innerHTML = `Dell service tag <strong>${data.service_tag}</strong> — Dell’s page opened in a new tab. Copy model & warranty date into the form below.`;
|
||||
meta.innerHTML = `
|
||||
<div><span class="fw-medium">Brand:</span> Dell</div>
|
||||
<div><span class="fw-medium">OS:</span> ${data.operating_system}</div>
|
||||
<div><span class="fw-medium">Model:</span> <em class="text-muted">fill from Dell tab →</em></div>
|
||||
<div><span class="fw-medium">Warranty:</span> <em class="text-muted">fill from Dell tab →</em></div>`;
|
||||
supportLink.href = data.support_url;
|
||||
supportLink.classList.remove('d-none');
|
||||
createBtn.textContent = '';
|
||||
createBtn.innerHTML = '<i class="bi bi-plus-circle me-1"></i>Open Form';
|
||||
} else {
|
||||
title.textContent = `Dell ${data.model || data.service_tag}`;
|
||||
supportLink.href = data.support_url || '#';
|
||||
supportLink.classList.remove('d-none');
|
||||
const fields = [
|
||||
['Type', data.asset_type],
|
||||
['Service Tag', data.service_tag],
|
||||
['Serial', data.serial_number || '—'],
|
||||
['Warranty', data.warranty_expiry || '—'],
|
||||
['Purchased', data.purchase_date || '—'],
|
||||
['OS', data.operating_system],
|
||||
];
|
||||
meta.innerHTML = fields
|
||||
.map(([k, v]) => `<div><span class="fw-medium">${k}:</span> ${v || '—'}</div>`)
|
||||
.join('');
|
||||
}
|
||||
|
||||
// Build "Create Asset" URL with pre-filled params
|
||||
const params = new URLSearchParams({
|
||||
service_tag: data.service_tag || '',
|
||||
serial_number: data.serial_number || '',
|
||||
brand: data.brand || 'Dell',
|
||||
model: data.model || '',
|
||||
asset_type: data.asset_type || '',
|
||||
operating_system: data.operating_system || '',
|
||||
warranty_expiry: data.warranty_expiry || '',
|
||||
purchase_date: data.purchase_date || '',
|
||||
});
|
||||
createBtn.href = `{{ url_for('assets.create') }}?${params.toString()}`;
|
||||
result.classList.remove('d-none');
|
||||
})
|
||||
.catch(() => {
|
||||
setLoading(false);
|
||||
showError('Network error – could not reach the server.');
|
||||
});
|
||||
}
|
||||
|
||||
btn.addEventListener('click', doLookup);
|
||||
input.addEventListener('keydown', e => { if (e.key === 'Enter') doLookup(); });
|
||||
input.addEventListener('input', () => {
|
||||
input.value = input.value.toUpperCase();
|
||||
});
|
||||
})();
|
||||
</script>
|
||||
{% endblock %}
|
||||
Reference in New Issue
Block a user