Statuses import, an icon picker, folder-scoped CSV import, and site name

- Statuses can now be bulk-imported/updated via CSV (Name, Color columns;
  matches and updates existing statuses by name). New
  internal/statuses/csv.go, tested.
- Icon fields (folder create/rename, item type form) are now a searchable
  dropdown of the 50 most common Bootstrap Icons instead of a free-text
  box, via a small reusable .icon-picker widget in app.js/app.css.
- CSV asset import is now folder-scoped when triggered from the tree:
  right-click a folder (or its background) > Import CSV... imports every
  row directly into that folder, so the CSV needs no Folder column at
  all, and the option no longer appears at the top level. The original
  global, Folder-path-aware import (with auto-create-missing-folders)
  moved to a new admin-only Settings > Import / Export page, alongside
  the new Statuses import and format examples for both. assets.Import
  gained ImportOptions.TargetFolderID to drive the folder-scoped mode.
- Site Name (Settings > General) now actually renders in the navbar
  brand and <title>, via a per-App "siteName" template func bound in
  loadTemplates. The brand is plain text now, not a link to /inventory.
This commit is contained in:
Owen
2026-08-17 15:57:59 -05:00
parent 8d9106542c
commit 42e7b2a21c
16 changed files with 657 additions and 39 deletions
+77 -9
View File
@@ -154,23 +154,91 @@ ul.tree-children {
cursor: default;
}
.stat-card .card-body {
text-align: center;
.panel-content {
max-width: 1100px;
}
.stat-value {
font-size: 1.4rem;
font-weight: 600;
line-height: 1.2;
.panel-blank {
max-width: none;
}
.stat-label {
/* Icon picker: a searchable dropdown of common Bootstrap Icons, standing
in for a free-text icon class field. */
.icon-picker {
position: relative;
}
.icon-picker-toggle {
display: flex;
align-items: center;
gap: 0.5rem;
text-align: left;
}
.icon-picker-preview {
font-size: 1.1rem;
width: 1.1rem;
flex-shrink: 0;
}
.icon-picker-label {
flex: 1 1 auto;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
.icon-picker-caret {
flex-shrink: 0;
font-size: 0.75rem;
color: #6c757d;
}
.panel-content {
max-width: 1100px;
.icon-picker-menu {
display: none;
position: absolute;
z-index: 1085;
top: 100%;
left: 0;
margin-top: 0.25rem;
width: 280px;
max-width: 90vw;
background-color: #fff;
border: 1px solid rgba(0, 0, 0, 0.15);
border-radius: 0.375rem;
box-shadow: 0 0.5rem 1rem rgba(0, 0, 0, 0.15);
padding: 0.5rem;
}
.icon-picker-menu.show {
display: block;
}
.icon-picker-grid {
display: grid;
grid-template-columns: repeat(6, 1fr);
gap: 0.25rem;
max-height: 190px;
overflow-y: auto;
margin-top: 0.5rem;
}
.icon-picker-item {
border: 1px solid transparent;
background: none;
border-radius: 0.25rem;
padding: 0.4rem;
font-size: 1.1rem;
display: flex;
align-items: center;
justify-content: center;
color: #212529;
}
.icon-picker-item:hover,
.icon-picker-item:focus {
background-color: #f1f3f5;
border-color: rgba(0, 0, 0, 0.1);
}
.asset-row, .folder-link, .asset-link {
+119 -7
View File
@@ -240,6 +240,7 @@
items.push({ divider: true });
items.push({ label: 'Rename', icon: 'bi-pencil', action: function () { openRenameFolder(id); } });
items.push({ divider: true });
items.push({ label: 'Import CSV…', icon: 'bi-upload', action: function () { openImportModal(id); } });
}
items.push({ label: 'Export CSV', icon: 'bi-download', action: function () { window.location = '/export/assets.csv?folder_id=' + id + '&recursive=1'; } });
if (isAdmin) {
@@ -261,6 +262,9 @@
return items;
}
// Import is intentionally folder-scoped only (see openImportModal) - it
// never appears at the top level, since a global admin import with
// folder-path resolution lives under Settings > Import / Export instead.
function treeBackgroundMenuItems() {
var items = [];
if (isAdmin) {
@@ -271,9 +275,6 @@
items.push({ label: 'Expand All', icon: 'bi-arrows-expand', action: expandAllHandler });
items.push({ label: 'Collapse All', icon: 'bi-arrows-collapse', action: collapseAllHandler });
items.push({ divider: true });
if (isAdmin) {
items.push({ label: 'Import CSV…', icon: 'bi-upload', action: function () { if (importModal) importModal.show(); } });
}
items.push({ label: 'Export CSV', icon: 'bi-download', action: function () { window.location = '/export/assets.csv'; } });
return items;
}
@@ -283,10 +284,13 @@
if (isAdmin) {
items.push({ label: folderId ? 'New Subfolder' : 'New Folder', icon: 'bi-folder-plus', action: function () { openFolderModal({ parentId: folderId }); } });
items.push({ label: 'Add Asset', icon: 'bi-plus-lg', action: function () { loadAssetForm({ folderId: folderId }); } });
items.push({ divider: true });
items.push({ label: 'Import CSV…', icon: 'bi-upload', action: function () { if (importModal) importModal.show(); } });
if (folderId) {
items.push({ divider: true });
items.push({ label: 'Import CSV…', icon: 'bi-upload', action: function () { openImportModal(folderId); } });
}
}
var exportUrl = folderId ? ('/export/assets.csv?folder_id=' + folderId + '&recursive=1') : '/export/assets.csv';
items.push({ divider: true });
items.push({ label: 'Export CSV', icon: 'bi-download', action: function () { window.location = exportUrl; } });
return items;
}
@@ -344,6 +348,105 @@
});
}
// ---------------------------------------------------------------------
// Icon picker: a searchable dropdown of common Bootstrap Icons standing
// in for a free-text icon-class input (used by the folder modal and the
// item type form).
// ---------------------------------------------------------------------
var COMMON_ICONS = [
'bi-folder-fill', 'bi-folder', 'bi-archive', 'bi-box-seam', 'bi-boxes',
'bi-laptop', 'bi-pc-display', 'bi-pc', 'bi-display', 'bi-tv', 'bi-projector',
'bi-phone', 'bi-telephone', 'bi-tablet', 'bi-smartwatch',
'bi-camera-video', 'bi-camera', 'bi-printer', 'bi-keyboard', 'bi-mouse',
'bi-hdd', 'bi-hdd-rack', 'bi-hdd-stack', 'bi-server', 'bi-cpu', 'bi-memory',
'bi-disc', 'bi-usb-drive', 'bi-usb-plug', 'bi-ethernet', 'bi-router', 'bi-wifi',
'bi-shield-lock', 'bi-shield-check', 'bi-lock', 'bi-unlock', 'bi-plug',
'bi-battery', 'bi-battery-charging', 'bi-gear', 'bi-gear-fill', 'bi-tools',
'bi-wrench', 'bi-tag', 'bi-tags', 'bi-bookmark', 'bi-house-door-fill',
'bi-building', 'bi-person', 'bi-people',
];
function setIconPickerValue(input, val) {
input.value = val || '';
var container = input.closest('.icon-picker');
if (!container) return;
var preview = container.querySelector('.icon-picker-preview');
var label = container.querySelector('.icon-picker-label');
if (val) {
preview.className = 'bi ' + val + ' icon-picker-preview';
label.textContent = val;
label.classList.remove('text-body-secondary');
} else {
preview.className = 'bi icon-picker-preview';
label.textContent = 'Choose icon…';
label.classList.add('text-body-secondary');
}
}
function closeAllIconPickers() {
document.querySelectorAll('.icon-picker-menu.show').forEach(function (m) { m.classList.remove('show'); });
}
function initIconPickers() {
document.querySelectorAll('[data-icon-picker]').forEach(function (container) {
if (container.dataset.iconPickerInit) return;
container.dataset.iconPickerInit = '1';
var input = container.querySelector('input[type="hidden"]');
var toggle = container.querySelector('.icon-picker-toggle');
var menu = container.querySelector('.icon-picker-menu');
var search = container.querySelector('.icon-picker-search');
var grid = container.querySelector('.icon-picker-grid');
var clearBtn = container.querySelector('.icon-picker-clear');
function renderGrid(filter) {
filter = (filter || '').toLowerCase();
var list = COMMON_ICONS.filter(function (ic) { return !filter || ic.indexOf(filter) !== -1; });
grid.innerHTML = list.map(function (ic) {
return '<button type="button" class="icon-picker-item" data-icon="' + ic + '" title="' + ic + '"><i class="bi ' + ic + '"></i></button>';
}).join('') || '<div class="text-body-secondary small p-2">No matches</div>';
}
toggle.addEventListener('click', function (e) {
e.stopPropagation();
var isOpen = menu.classList.contains('show');
closeAllIconPickers();
if (!isOpen) {
menu.classList.add('show');
search.value = '';
renderGrid('');
search.focus();
}
});
search.addEventListener('input', function () { renderGrid(search.value.trim()); });
grid.addEventListener('click', function (e) {
var btn = e.target.closest('.icon-picker-item');
if (!btn) return;
setIconPickerValue(input, btn.dataset.icon);
menu.classList.remove('show');
});
if (clearBtn) {
clearBtn.addEventListener('click', function () {
setIconPickerValue(input, '');
menu.classList.remove('show');
});
}
renderGrid('');
setIconPickerValue(input, input.value);
});
}
document.addEventListener('click', function (e) {
if (!e.target.closest('.icon-picker')) closeAllIconPickers();
});
initIconPickers();
// ---------------------------------------------------------------------
// Folder create / rename modal
// ---------------------------------------------------------------------
@@ -357,7 +460,7 @@
document.getElementById('folderFormParentId').value = (opts && opts.parentId) || '';
document.getElementById('folderFormName').value = '';
document.getElementById('folderFormDescription').value = '';
document.getElementById('folderFormIcon').value = '';
setIconPickerValue(document.getElementById('folderFormIcon'), '');
document.getElementById('folderFormSortOrder').value = '0';
document.getElementById('folderModalTitle').textContent = 'New Folder';
document.getElementById('folderFormError').classList.add('d-none');
@@ -372,7 +475,7 @@
document.getElementById('folderFormParentId').value = '';
document.getElementById('folderFormName').value = f.Name;
document.getElementById('folderFormDescription').value = f.Description;
document.getElementById('folderFormIcon').value = f.Icon;
setIconPickerValue(document.getElementById('folderFormIcon'), f.Icon);
document.getElementById('folderFormSortOrder').value = f.SortOrder;
document.getElementById('folderModalTitle').textContent = 'Rename Folder';
document.getElementById('folderFormError').classList.add('d-none');
@@ -658,6 +761,15 @@
var importModalEl = document.getElementById('importModal');
var importModal = (importModalEl && window.bootstrap) ? new bootstrap.Modal(importModalEl) : null;
function openImportModal(folderId) {
if (!importModal) return;
document.getElementById('importFolderId').value = folderId || '';
document.getElementById('importResult').innerHTML = '';
var fileInput = document.getElementById('importFile');
if (fileInput) fileInput.value = '';
importModal.show();
}
var importFormEl = document.getElementById('importForm');
if (importFormEl) {
importFormEl.addEventListener('submit', async function (e) {
+4 -4
View File
@@ -3,16 +3,16 @@
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>inventree</title>
<title>{{siteName}}</title>
<link rel="stylesheet" href="/static/css/bootstrap.min.css">
<link rel="stylesheet" href="/static/icons/bootstrap-icons.css">
<link rel="stylesheet" href="/static/css/app.css">
</head>
<body class="role-{{.User.Role}}">
<nav class="navbar navbar-expand-lg app-navbar border-bottom px-3">
<a class="navbar-brand fw-semibold d-flex align-items-center gap-2" href="/inventory">
<i class="bi bi-diagram-3-fill"></i> inventree
</a>
<span class="navbar-brand fw-semibold d-flex align-items-center gap-2 mb-0">
<i class="bi bi-diagram-3-fill"></i> {{siteName}}
</span>
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navMain">
<span class="navbar-toggler-icon"></span>
</button>
+14 -2
View File
@@ -22,8 +22,20 @@
<input type="text" class="form-control" name="name" value="{{if .ItemType}}{{.ItemType.Name}}{{end}}" required>
</div>
<div class="col-md-6">
<label class="form-label">Icon <span class="text-body-secondary">(Bootstrap Icons class)</span></label>
<input type="text" class="form-control" name="icon" value="{{if .ItemType}}{{.ItemType.Icon}}{{end}}" placeholder="bi-box-seam">
<label class="form-label">Icon</label>
<div class="icon-picker" data-icon-picker>
<input type="hidden" name="icon" value="{{if .ItemType}}{{.ItemType.Icon}}{{end}}">
<button type="button" class="btn btn-outline-secondary icon-picker-toggle w-100">
<i class="bi icon-picker-preview"></i>
<span class="icon-picker-label text-body-secondary">Choose icon&hellip;</span>
<i class="bi bi-chevron-down icon-picker-caret"></i>
</button>
<div class="icon-picker-menu">
<input type="search" class="form-control form-control-sm icon-picker-search" placeholder="Search icons&hellip;">
<div class="icon-picker-grid"></div>
<button type="button" class="btn btn-sm btn-link p-0 mt-2 icon-picker-clear">Clear</button>
</div>
</div>
</div>
<div class="col-12">
<label class="form-label">Description</label>
+94
View File
@@ -0,0 +1,94 @@
{{define "content"}}
<div class="container-fluid p-3">
<h4 class="mb-3">Settings</h4>
<div class="row g-3">
<div class="col-md-3 col-lg-2">
{{template "settings_nav" "import"}}
</div>
<div class="col-md-9 col-lg-10" style="max-width: 900px">
{{if .Error}}
<div class="alert alert-danger">{{.Error}}</div>
{{else if eq .Kind "assets"}}
<div class="alert alert-success">Imported {{.Imported}} asset(s), updated {{.Updated}}.{{if .Errs}} {{.Errs}} row(s) had warnings.{{end}}</div>
{{else if eq .Kind "statuses"}}
<div class="alert alert-success">Imported {{.Imported}} status(es), updated {{.Updated}}.{{if .Errs}} {{.Errs}} row(s) had warnings.{{end}}</div>
{{end}}
<p class="text-body-secondary">
This page is for bulk, admin-level imports that can reference any folder path (and create missing
folders along the way). To import assets straight into one specific folder without a Folder column,
right-click that folder in the Inventory tree and choose <strong>Import CSV&hellip;</strong> instead.
</p>
<div class="card mb-4">
<div class="card-header py-2 fw-semibold">Import Assets</div>
<div class="card-body">
<form method="post" action="/settings/import/assets" enctype="multipart/form-data" class="mb-3">
<div class="mb-3">
<label class="form-label">CSV File</label>
<input type="file" class="form-control" name="file" accept=".csv" required>
</div>
<div class="form-check mb-3">
<input class="form-check-input" type="checkbox" name="create_missing_folders" id="createMissingFolders" value="1" checked>
<label class="form-check-label" for="createMissingFolders">Create missing folders referenced in the Folder column</label>
</div>
<button type="submit" class="btn btn-primary">Import Assets</button>
</form>
<p class="mb-1 fw-semibold small">Format</p>
<p class="text-body-secondary small mb-2">
Required: <code>Name</code>, <code>Item Type</code>, <code>Status</code>. Optional:
<code>Asset ID</code> (auto-generated if blank; matches an existing asset to update it),
<code>Folder</code> (a <code>/</code>-separated path such as <code>Main Office/Network</code>),
<code>Assigned User</code>, <code>Notes</code>, and one <code>cf_&lt;field_key&gt;</code> column
per custom field (e.g. <code>cf_serial_number</code>).
</p>
<div class="table-responsive">
<table class="table table-sm table-bordered mb-0 small">
<thead>
<tr><th>Asset ID</th><th>Name</th><th>Item Type</th><th>Folder</th><th>Status</th><th>Assigned User</th><th>Notes</th><th>cf_serial_number</th></tr>
</thead>
<tbody>
<tr><td></td><td>Core Switch</td><td>Switch</td><td>Main Office/Network</td><td>In Use</td><td></td><td></td><td>SN-12345</td></tr>
<tr><td>IT-000042</td><td>Front Desk PC</td><td>Desktop</td><td>Main Office/Workstations</td><td>In Use</td><td>jdoe</td><td>Loaner unit</td><td></td></tr>
</tbody>
</table>
</div>
</div>
</div>
<div class="card">
<div class="card-header py-2 fw-semibold">Import Statuses</div>
<div class="card-body">
<form method="post" action="/settings/import/statuses" enctype="multipart/form-data" class="mb-3">
<div class="mb-3">
<label class="form-label">CSV File</label>
<input type="file" class="form-control" name="file" accept=".csv" required>
</div>
<button type="submit" class="btn btn-primary">Import Statuses</button>
</form>
<p class="mb-1 fw-semibold small">Format</p>
<p class="text-body-secondary small mb-2">
Required: <code>Name</code>. Optional: <code>Color</code> (any Bootstrap color name -
<code>primary</code>, <code>secondary</code>, <code>success</code>, <code>danger</code>,
<code>warning</code>, <code>info</code>, or <code>dark</code>; defaults to <code>secondary</code>).
A row whose name matches an existing status updates its color instead of creating a duplicate.
</p>
<div class="table-responsive">
<table class="table table-sm table-bordered mb-0 small">
<thead><tr><th>Name</th><th>Color</th></tr></thead>
<tbody>
<tr><td>In Use</td><td>success</td></tr>
<tr><td>Awaiting Parts</td><td>warning</td></tr>
</tbody>
</table>
</div>
</div>
</div>
</div>
</div>
</div>
{{end}}
+20 -9
View File
@@ -22,8 +22,20 @@
</div>
<div class="row g-2">
<div class="col">
<label class="form-label">Icon <span class="text-body-secondary">(Bootstrap Icons class, optional)</span></label>
<input type="text" class="form-control" name="icon" id="folderFormIcon" placeholder="bi-folder-fill">
<label class="form-label">Icon <span class="text-body-secondary">(optional)</span></label>
<div class="icon-picker" data-icon-picker>
<input type="hidden" name="icon" id="folderFormIcon" value="">
<button type="button" class="btn btn-outline-secondary icon-picker-toggle w-100">
<i class="bi icon-picker-preview"></i>
<span class="icon-picker-label text-body-secondary">Choose icon&hellip;</span>
<i class="bi bi-chevron-down icon-picker-caret"></i>
</button>
<div class="icon-picker-menu">
<input type="search" class="form-control form-control-sm icon-picker-search" placeholder="Search icons&hellip;">
<div class="icon-picker-grid"></div>
<button type="button" class="btn btn-sm btn-link p-0 mt-2 icon-picker-clear">Clear</button>
</div>
</div>
</div>
<div class="col-4">
<label class="form-label">Sort Order</label>
@@ -116,26 +128,25 @@
</div>
</div>
<!-- Import CSV -->
<!-- Import CSV into a specific folder (right-click a folder > Import CSV...) -->
<div class="modal fade" id="importModal" tabindex="-1">
<div class="modal-dialog">
<div class="modal-content">
<form id="importForm">
<div class="modal-header">
<h5 class="modal-title">Import Assets from CSV</h5>
<h5 class="modal-title" id="importModalTitle">Import CSV</h5>
<button type="button" class="btn-close" data-bs-dismiss="modal"></button>
</div>
<div class="modal-body">
<input type="hidden" name="folder_id" id="importFolderId">
<div class="mb-3">
<label class="form-label">CSV File</label>
<input type="file" class="form-control" name="file" id="importFile" accept=".csv" required>
</div>
<div class="form-check mb-2">
<input class="form-check-input" type="checkbox" name="create_missing_folders" id="importCreateFolders" value="1" checked>
<label class="form-check-label" for="importCreateFolders">Create missing folders referenced in the Folder column</label>
</div>
<p class="text-body-secondary small mb-0">
Columns: Asset ID, Name, Item Type, Folder, Status, Assigned User, Notes, plus <code>cf_&lt;field_key&gt;</code> for custom fields.
Every row imports into this folder. Columns: <code>Name</code>, <code>Item Type</code>,
<code>Status</code>. Optional: <code>Asset ID</code>, <code>Assigned User</code>, <code>Notes</code>,
plus <code>cf_&lt;field_key&gt;</code> for custom fields. No Folder column needed.
</p>
<div id="importResult" class="mt-3"></div>
</div>
+3
View File
@@ -12,5 +12,8 @@
<a href="/settings/users" class="list-group-item list-group-item-action{{if eq . "users"}} active{{end}}">
<i class="bi bi-people me-2"></i>Users
</a>
<a href="/settings/import" class="list-group-item list-group-item-action{{if eq . "import"}} active{{end}}">
<i class="bi bi-upload me-2"></i>Import / Export
</a>
</div>
{{end}}